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

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProject;
import com.jeeplus.modules.sg.managementcenter.constructionProject.mapper.ConstructionProjectMapper;
import com.jeeplus.modules.sg.managementcenter.constructionProject.util.TreeTableUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


@Service
@Transactional(readOnly = true)
public class ConstructionProjectService extends CrudService<ConstructionProjectMapper, ConstructionProject> {

	@Autowired
	private ConstructionProjectMapper constructionProjectMapper;

	public ConstructionProject get(String id) {
		return super.get(id);
	}
	
	public List<ConstructionProject> findList(ConstructionProject constructionProject) {
		return super.findList(constructionProject);
	}

	public Page<ConstructionProject> findPage(Page<ConstructionProject> page, ConstructionProject constructionProject) {
		return super.findPage(page, constructionProject);
	}
	
	@Transactional(readOnly = false)
	public void save(ConstructionProject constructionProject) {
		super.save(constructionProject);
	}

	//文件导入
	@Transactional(readOnly = false)
	public void savaList(List<ConstructionProject> list){
		for (ConstructionProject constructionProject:list){
			constructionProject.preInsert();
		}
		constructionProjectMapper.insertList(list);
	}
	//修改计划安排事件状态
	@Transactional(readOnly = false)
	public void updateStatus(ConstructionProject constructionProject){
		constructionProjectMapper.updateStatus(constructionProject);
	}

	//安排具体时间
	@Transactional(readOnly = false)
	public void updateSpecificTime(ConstructionProject constructionProject,Date historyTime){
		String status = TreeTableUtil.getConstructionId(constructionProject);
		if ("".equals(status)){
			constructionProject.preUpdate();
			constructionProjectMapper.updateSpecificTime(constructionProject);
		}
		if ("line".equals(status)){
			Date specificTime = constructionProject.getSpecificTime();
			constructionProject.setId("");
			constructionProject.setArrangeTime(null);
			List<ConstructionProject> list = findList(constructionProject);
			for (ConstructionProject constructionProject1:list){
				constructionProject1.preUpdate();
				constructionProject1.setSpecificTime(specificTime);
			}
			constructionProjectMapper.updateSpecificLine(list);
		}
	}

}