/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.sg.settActivi.service;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.sg.managementcenter.project.entity.Project1;
import com.jeeplus.modules.sg.settActivi.entity.SettActivi;
import com.jeeplus.modules.sg.settActivi.entity.SettList;
import com.jeeplus.modules.sg.settActivi.mapper.SettActiviMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 模块显示Service
 *
 * @author
 * @version 2019-11-08
 */
@Service
@Transactional(readOnly = true)
public class SettActiviService extends CrudService<SettActiviMapper, SettActivi> {

	@Autowired
	private SettActiviMapper settActiviMapper;

	@Override
	public SettActivi get(SettActivi entity) {
		return super.get(entity);
	}

	@Override
	public Page<SettActivi> findPage(Page<SettActivi> page, SettActivi entity) {
		return super.findPage(page, entity);
	}

	public Page<SettList> useQuantityData(Page<SettList> page, SettList entity) {
		dataRuleFilter(entity);
		entity.setPage(page);
		page.setList(settActiviMapper.findUseQuantityData(entity));
		return page;
	}


	public List<SettList> findUseQuantityData(SettList settList) {
		return settActiviMapper.findUseQuantityData(settList);
	}


	//根据项目idList查询项目信息
	public List<Project1> findByIdList(List<String> projectId) {
		return settActiviMapper.findByIdList(projectId);
	}

	//插入settlist表中
	@Transactional(readOnly = false)
	public void insertSettList(List<SettList> settLists) {
		for (SettList s : settLists) {
			s.preInsert();
		}
		settActiviMapper.insertSettList(settLists);
	}

	@Transactional(readOnly = false)
	public void insertSettActivi(List<Project1> projectList) {
		for (Project1 p : projectList) {
			p.preInsert();
		}
		settActiviMapper.insertSettActivi(projectList);
	}

	public List<SettActivi> findAllSett(List<Project1> projectList) {
		return settActiviMapper.findAllSett(projectList);
	}

	@Transactional(readOnly = false)
	public void updateSetStatus(List<SettActivi> settActivis) {
		settActiviMapper.updateSetStatus(settActivis);
	}

	@Transactional(readOnly = false)
	public void finSetStatus(String procInsId) {
		settActiviMapper.finSetStatus(procInsId);
	}

	/**
	 * 修改项目的
	 */
	@Transactional(readOnly = false)
	public void updateUsed(SettList settList) {
		settActiviMapper.updateUsed(settList);
	}

	@Transactional(readOnly = false)
	public void updateReviewQuantity(SettList settList) {
		String outgoingQuantity = settActiviMapper.findOutgoingQuantity(settList);
		Double reviewQuantity = settList.getReviewQuantity();
		Double aDouble = Double.valueOf(outgoingQuantity);
		double v = reviewQuantity - aDouble;
		settList.setOverUnder(v);
		settActiviMapper.updateReviewQuantity(settList);
	}

	@Transactional(readOnly = false)
	public void updateSettMark(SettList settList) {
		settActiviMapper.updateSettMark(settList);
	}

	@Transactional(readOnly = false)
	public SettActivi exportFind(String procInsId) {
		return settActiviMapper.exportFind(procInsId);
	}

	@Transactional(readOnly = false)
	public void insertSett(SettActivi settActivi) {
		settActivi.preInsert();
		settActiviMapper.insertSett(settActivi);
	}
}