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

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.sg.managementcenter.activiti.entity.*;
import com.jeeplus.modules.sg.managementcenter.activiti.mapper.ConstructionMapper;
import com.jeeplus.modules.sg.managementcenter.activiti.utils.MyImportUtils;
import com.jeeplus.modules.sg.managementcenter.materialinfo.entity.MaterialInfo;
import com.jeeplus.modules.sg.managementcenter.project.entity.Project;
import com.jeeplus.modules.sg.managementcenter.project.entity.Project1;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.test.pic.entity.TestPic;
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 ConstructionService extends CrudService<ConstructionMapper, Construction> {

	@Autowired
	private ConstructionMapper constructionMapper;

	public Construction get(String id) {
		Construction construction = super.get(id);
		return MyImportUtils.getAddUnit(construction);
	}

	public List<Construction> findList(Construction construction) {
		return super.findList(construction);
	}

	public Page<Construction> findPage(Page<Construction> page, Construction construction) {
		return super.findPage(page, construction);
	}

	public Page<Construction> findDisclosePage(Page<Construction> page, Construction construction) {
		dataRuleFilter(construction);
		construction.setPage(page);
		page.setList(constructionMapper.findDisclosePage(construction));
		return page;
	}

	/**
	 * 修改交底结论
	 */
	@Transactional(readOnly = false)
	public void replaceDisclose(List<Construction> constructionList) {
		for (Construction c : constructionList) {
			c.preInsert();
		}
		constructionMapper.replaceDisclose(constructionList);
	}

	/**
	 * 修改项目工程量信息
	 */
	@Transactional(readOnly = false)
	public void quantityInsert(List<Construction> constructionList) {
		for (Construction c : constructionList) {
			c.preInsert();
		}
		constructionMapper.quantityInsert(constructionList);
	}

	/**
	 * 政处是否自己运行
	 */
	@Transactional(readOnly = false)
	public void updateIfSelf(Construction construction) {
		constructionMapper.updateIfSelf(construction);
	}

	@Transactional(readOnly = false)
	public void updateIfBorrow(Construction construction) {
		constructionMapper.updateIfBorrow(construction);
	}


	@Transactional(readOnly = false)
	public void save(Construction construction) {
		super.save(construction);
	}

	@Transactional(readOnly = false)
	public void delete(Construction construction) {
		super.delete(construction);
	}

	@Transactional(readOnly = false)
	public void newUpdate(Construction construction) {
		constructionMapper.newUpdate(construction);
	}

	public User queryPerson(String loginName) {
		return constructionMapper.queryPerson(loginName);
	}

	/**
	 * 根据登陆名查询角色
	 */
	public List<String> nameFindOffice(String loginName) {
		return constructionMapper.nameFindOffice(loginName);
	}

	/**
	 * 保存上传文件信息
	 */
	@Transactional(readOnly = false)
	public void uploadSave(UploadImages uploadImages) {
		uploadImages.preInsert();
		constructionMapper.uploadSave(uploadImages);
	}

	/**
	 * 文件数据显示列表
	 */
	public Page<UploadImages> findUploadPage(Page<UploadImages> page, UploadImages uploadImages) {
		dataRuleFilter(uploadImages);
		uploadImages.setPage(page);
		page.setList(constructionMapper.findUploadPage(uploadImages));
		return page;
	}

	@Transactional(readOnly = false)
	public void newSave(Construction construction) {
		construction.preInsert();
		constructionMapper.newSave(construction);
	}

	//根据储备项目暂定名称修改项目状态-开始状态
	@Transactional(readOnly = false)
	public void updateStatus(String reserveProjectName) {
		constructionMapper.updateStatus(reserveProjectName);
	}

	//根据储备项目暂定名称修改项目状态-结束状态
	@Transactional(readOnly = false)
	public void updateEndStatus(String reserveProjectName) {
		constructionMapper.updateEndStatus(reserveProjectName);
	}

	/**
	 * 根据项目定义号修改项目的土建流程状态
	 */
	@Transactional(readOnly = false)
	public void updateAdvStatus(String id) {
		constructionMapper.updateAdvStatus(id);
	}

	/**
	 * 根据流程定义修改项目关闭状态
	 */
	@Transactional(readOnly = false)
	public void updateCloseStatus(String procInsId) {
		constructionMapper.updateCloseStatus(procInsId);
	}

	//根据流程id查询项目的需求提出单位
	public String demandUnit(String procInsId) {
		return constructionMapper.demandUnit(procInsId);
	}

	public List<Construction> findByProcInsId(List<Construction> constructionList) {
		return constructionMapper.findByProcInsId(constructionList);
	}

	//根据流程定义号查询项目需求名称
	public String idProjectName(String procInsId) {
		String s = constructionMapper.idProjectName(procInsId);
		return s;
	}

	//根据流程定义号查询项目需求名称
	public String idProjectName2(String procInsId) {
		String s = constructionMapper.idProjectName2(procInsId);
		return s;
	}

	//根据流程定义号查询项目需求名称
	public String idProjectName3(String procInsId) {
		String s = constructionMapper.idProjectName3(procInsId);
		return s;
	}

	//根据流程定义号查询结算流程项目需求名称
	public String idProjectName4(String procInsId) {
		String s = constructionMapper.idProjectName4(procInsId);
		return s;
	}


	/**
	 * 联合查询通过现有流程表中的流程实例id，查询除流程的项目
	 */
	public Project procInsIdAllName(Project project) {
		return constructionMapper.procInsIdAllName(project);
	}

	public ReturnTodo findProcInsIDAll(Project project) {
		return constructionMapper.findProcInsIDAll(project);
	}

	//根据输入的项目名称，分别从流程表中查询对应的项目信息
	public List<String> insIdByName(String projectName) {
		List<String> strings = constructionMapper.insIdByName(projectName);
		List<String> strings1 = constructionMapper.insIdByName2(projectName);
		List<String> strings2 = constructionMapper.insIdByName3(projectName);
		List<String> strings3 = constructionMapper.insIdByName4(projectName);
		strings.addAll(strings1);
		strings.addAll(strings2);
		strings.addAll(strings3);
		return strings;
	}

	/**
	 * 根据流程定义号查询提前物料申请流程的项目名称
	 */
	public Project1 findNameByInsID(String procInsId) {
		return constructionMapper.findNameByInsID(procInsId);
	}


	/**
	 * 项目经理更新
	 */
	@Transactional(readOnly = false)
	public void updateOIPI(Construction construction) {
		constructionMapper.updateOIPI(construction);
	}

	/**
	 * 土建工程量信息
	 */
	public Page<EngineeringAmount> engineeringTable(Page<EngineeringAmount> page, EngineeringAmount engineeringAmount) {
		dataRuleFilter(engineeringAmount);
		engineeringAmount.setPage(page);
		page.setList(constructionMapper.engineeringTable(engineeringAmount));
		return page;
	}

	/**
	 * 其它工程量信息
	 */
	public Page<OtherAmount> otherTable(Page<OtherAmount> page, OtherAmount otherAmount) {
		dataRuleFilter(otherAmount);
		otherAmount.setPage(page);
		page.setList(constructionMapper.otherTable(otherAmount));
		return page;
	}

	/**
	 * 查找土建工程量信息
	 */
	public EngineeringAmount getEngAmount(EngineeringAmount engineeringAmount) {
		return constructionMapper.getEngAmount(engineeringAmount);
	}

	/**
	 * 查找其它工程量信息
	 */
	public OtherAmount getOtherAmount(OtherAmount otherAmount) {
		return constructionMapper.getOtherAmount(otherAmount);
	}


	/**
	 * 土建工程量修改
	 */
	@Transactional(readOnly = false)
	public void EngAmountSave(EngineeringAmount engineeringAmount) {
		if (engineeringAmount.getId() == null || "".equals(engineeringAmount.getId())) {
			engineeringAmount.preInsert();
		}
		constructionMapper.EngAmountSave(engineeringAmount);
	}

	/**
	 * 其它工程量修改
	 */
	@Transactional(readOnly = false)
	public void addOther(OtherAmount otherAmount) {
		if (otherAmount.getId() == null || "".equals(otherAmount.getId())) {
			otherAmount.preInsert();
		}
		constructionMapper.addOther(otherAmount);
	}

	/**
	 * 删除土建工程量信息
	 */
	@Transactional(readOnly = false)
	public void delEngAmount(String id) {
		constructionMapper.delEngAmount(id);
	}

	/**
	 * 删除其它工程量信息
	 */
	@Transactional(readOnly = false)
	public void delOtherAmount(String id) {
		constructionMapper.delOtherAmount(id);
	}

	/**
	 * 根据项目名称修改项目政策处理状态
	 */
	@Transactional(readOnly = false)
	public void updatePolicyStatus(String reserveProjectName, String policyStatus) {
		constructionMapper.updatePolicyStatus(reserveProjectName, policyStatus);
	}

	/**
	 * 通过流程定义号，删除本次领料流程中所有的领料单（新增2020-09-23）
	 */
	@Transactional(readOnly = false)
	public void delProcessList(String procInsId) {
		constructionMapper.delProcessList(procInsId);
	}
}