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

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.filing.approvalStage.entity.ApprovalStage;
import com.jeeplus.modules.filing.approvalStage.entity.EarlyStage;
import com.jeeplus.modules.filing.approvalStage.mapper.ApprovalStageMapper;
import com.jeeplus.modules.filing.approvalStage.mapper.EarlyStageMapper;
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 EarlyStageService extends CrudService<EarlyStageMapper, EarlyStage> {


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

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

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

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

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



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

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

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

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