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

import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.modules.workhandbill.entity.WorkHandBillDetail;
import com.jeeplus.modules.workprojectcalc.dao.WorkProjectCalcBuildDao;
import com.jeeplus.modules.workprojectcalc.dao.WorkProjectCalcDecorDao;
import com.jeeplus.modules.workprojectcalc.entity.WorkProjectCalcBuild;
import com.jeeplus.modules.workprojectcalc.entity.WorkProjectCalcDecor;
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 2018-06-06
 */
@Service
@Transactional(readOnly = true)
public class WorkProjectCalcDecorService extends CrudService<WorkProjectCalcDecorDao, WorkProjectCalcDecor> {

	@Autowired
	private WorkProjectCalcBuildDao workProjectCalcBuildDao;
	@Autowired
	private WorkProjectCalcDecorDao workProjectCalcDecorDao;

	public WorkProjectCalcDecor get(String id) {
		return super.get(id);
	}
	
	public List<WorkProjectCalcDecor> findList(WorkProjectCalcDecor workProjectCalcDecor) {
		return super.findList(workProjectCalcDecor);
	}
	
	public Page<WorkProjectCalcDecor> findPage(Page<WorkProjectCalcDecor> page, WorkProjectCalcDecor workProjectCalcDecor) {
		return super.findPage(page, workProjectCalcDecor);
	}
	
	@Transactional(readOnly = false)
	public void save(WorkProjectCalcDecor workProjectCalcDecor) {
		List<WorkProjectCalcDecor> workProjectCalcDecorList = workProjectCalcDecor.getWorkProjectCalcDecorList();
		for (WorkProjectCalcDecor workProjectCalcDecor1 : workProjectCalcDecorList) {
			workProjectCalcDecor1.setProjectId(workProjectCalcDecor.getProjectId());
			if (WorkHandBillDetail.DEL_FLAG_NORMAL.equals(workProjectCalcDecor1.getDelFlag())) {
				if (workProjectCalcDecor1.getIsNewRecord()) {
					workProjectCalcDecor1.preInsert();
					workProjectCalcDecorDao.insert(workProjectCalcDecor1);
				} else {
					workProjectCalcDecor1.preUpdate();
					workProjectCalcDecorDao.update(workProjectCalcDecor1);
				}
			}else{
				workProjectCalcDecorDao.delete(workProjectCalcDecor1);
			}
		}

		List<WorkProjectCalcBuild> workProjectCalcBuildList = workProjectCalcDecor.getWorkProjectCalcBuildList();
		for (WorkProjectCalcBuild workProjectCalcBuild : workProjectCalcBuildList) {
			workProjectCalcBuild.setProjectId(workProjectCalcDecor.getProjectId());
			if (WorkHandBillDetail.DEL_FLAG_NORMAL.equals(workProjectCalcBuild.getDelFlag())) {
				if (workProjectCalcBuild.getIsNewRecord()) {
					workProjectCalcBuild.preInsert();
					workProjectCalcBuildDao.insert(workProjectCalcBuild);
				} else {
					workProjectCalcBuild.preUpdate();
					workProjectCalcBuildDao.update(workProjectCalcBuild);
				}
			}else{
				workProjectCalcBuildDao.delete(workProjectCalcBuild);
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(WorkProjectCalcDecor workProjectCalcDecor) {
		super.delete(workProjectCalcDecor);
	}
	
	
	
	
}