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

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.filing.constructionStage.entity.*;
import com.jeeplus.modules.filing.constructionStage.mapper.ConstructionStageMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 核准阶段Service
 *
 * @author qy
 * @version 2021-03-25
 */
@Service
@Transactional(readOnly = true)
public class ConstructionStageService extends CrudService<ConstructionStageMapper, ConstructionStage> {


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

	@Override
	public List<ConstructionStage> findList(ConstructionStage entity) {
		return super.findList(entity);
	}

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

	public Page<ConstructionStage> findAllPage(Page<ConstructionStage> page, ConstructionStage entity){
		dataRuleFilter(entity);
		entity.setPage(page);
		page.setList(mapper.findAllList(entity));
		return page;
	}

	public Page<ConstructionStage> findChildPage(Page<ConstructionStage> page, ConstructionStage entity) {
		dataRuleFilter(entity);
		entity.setPage(page);
		page.setList(mapper.findChildList(entity));
		return page;
	}



	@Override
	public void delete(ConstructionStage entity) {
		super.delete(entity);
	}

	@Override
	@Transactional(readOnly = false)
	public void save(ConstructionStage entity) {
		Integer byCode = mapper.findByCode(entity);
		if (0 == byCode || null == byCode) {
			entity.preInsert();
			mapper.insert(entity);
		} else {
			entity.preUpdate();
			mapper.update(entity);
		}
	}

	@Transactional(readOnly = false)
	public void startUpSave(StartUP entity) {
		Integer byCode = mapper.findCode(entity.getProjectCode());
		if (0 == byCode || null == byCode) {
			entity.preInsert();
			mapper.insertStartUp(entity);
		} else {
			entity.preUpdate();
			mapper.updateStartUp(entity);
		}
	}

	@Transactional(readOnly = false)
	public void projectScheduleSave(ProjectSchedule entity) {
		Integer byCode = mapper.findCode(entity.getProjectCode());
		if (0 == byCode || null == byCode) {
			entity.preInsert();
			mapper.insertProjectSchedule(entity);
		} else {
			entity.preUpdate();
			mapper.updateProjectSchedule(entity);
		}
	}

	@Transactional(readOnly = false)
	public void costManagmentSave(CostManagment entity) {
		Integer byCode = mapper.findCode(entity.getProjectCode());
		if (0 == byCode || null == byCode) {
			entity.preInsert();
			mapper.insertCostManagment(entity);
		} else {
			entity.preUpdate();
			mapper.updateCostManagment(entity);
		}
	}

	@Transactional(readOnly = false)
	public void projectOtherSave(ProjectOther entity) {
		Integer byCode = mapper.findCode(entity.getProjectCode());
		if (0 == byCode || null == byCode) {
			entity.preInsert();
			mapper.insertProjectOther(entity);
		} else {
			entity.preUpdate();
			mapper.updateProjectOther(entity);
		}
	}

	@Transactional(readOnly = false)
	public void qulityAssuranceSave(QulityAssurance entity) {
		Integer byCode = mapper.findCode(entity.getProjectCode());
		if (0 == byCode || null == byCode) {
			entity.preInsert();
			mapper.insertQulityAssurance(entity);
		} else {
			entity.preUpdate();
			mapper.updateQulityAssurance(entity);
		}
	}

	@Transactional(readOnly = false)
	public void safetyQualitySave(SafetyQuality entity) {
		Integer byCode = mapper.findCode(entity.getProjectCode());
		if (0 == byCode || null == byCode) {
			entity.preInsert();
			mapper.insertSafetyQuality(entity);
		} else {
			entity.preUpdate();
			mapper.updateSafetyQuality(entity);
		}
	}

	@Transactional(readOnly = false)
	public void securityManagmentSave(SecurityManagment entity) {
		Integer byCode = mapper.findCode(entity.getProjectCode());
		if (0 == byCode || null == byCode) {
			entity.preInsert();
			mapper.insertSecurityManagment(entity);
		} else {
			entity.preUpdate();
			mapper.updateSecurityManagment(entity);
		}
	}

	public List<ConstructionStage> findChildList(ConstructionStage entity) {
		return mapper.findChildList(entity);
	}

	public Integer findByCode(ConstructionStage entity) {
		return mapper.findByCode(entity);
	}
}