/**
 * 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.common.utils.StringUtils;
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.mapper.ApprovalStageMapper;
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 ApprovalStageService extends CrudService<ApprovalStageMapper, ApprovalStage> {


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

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

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

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

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



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

	@Override
	@Transactional(readOnly = false)
	public void save(ApprovalStage 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(ApprovalStage entity) {
		return mapper.findByCode(entity);
	}

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