package com.unis.base.server.domain;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.unis.base.common.constant.FilingStatusConstant;
import com.unis.base.common.vo.TyXzzyxxHisQueryVO;
import com.unis.base.common.vo.TyXzzyxxHisVO;
import com.unis.base.server.dao.TyXzzyxxHisDao;
import com.unis.base.server.entity.TyXzzyxxHisDO;
import com.unis.common.utils.DateUtil;
import com.unis.common.utils.LsBeanUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
 * @author 张琪
 * @date 2019年9月16日 下午5:48:17
 * @description 熏蒸作业Domain
 */
@Getter
@Setter
@ToString
@Component
public class TyXzzyxxHisDomain  extends BaseDomain{
	@Autowired
	private TyXzzyxxHisDao tyXzzyxxHisDao;
	/**
	 * 分页查询列表
	 * @param tyXzzyxxHisQueryVO
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public PageInfo<TyXzzyxxHisVO> getTyXzzyxxHisListByQuery(TyXzzyxxHisQueryVO tyXzzyxxHisQueryVO, Integer pageNum,Integer pageSize) {
		PageInfo<TyXzzyxxHisVO> pageInfoVO = new PageInfo<TyXzzyxxHisVO>();
		PageHelper.startPage(pageNum, pageSize);
		List<TyXzzyxxHisDO> tDOs =  tyXzzyxxHisDao.findPageList(tyXzzyxxHisQueryVO);
		PageInfo<TyXzzyxxHisDO> PageInfoDO = new PageInfo<TyXzzyxxHisDO>(tDOs);
		LsBeanUtils.copyAllProperties(PageInfoDO,pageInfoVO);
		return pageInfoVO;
	}

	/**
	 * 根据主键ID获取熏蒸作业历史信息
	 * @param lsId
	 * @return
	 */
	public TyXzzyxxHisVO getTyXzzyxxHisInfoByLsId(String lsId) {
		TyXzzyxxHisDO tyXzzyxxHisDO = tyXzzyxxHisDao.selectByPrimaryKey(lsId);
		if (tyXzzyxxHisDO==null) {
			return null;
		}

		TyXzzyxxHisVO tyXzzyxxHisVO=new TyXzzyxxHisVO();
		LsBeanUtils.copyAllProperties(tyXzzyxxHisDO,tyXzzyxxHisVO);
		return tyXzzyxxHisVO;
	}

	/**
	 * 新增熏蒸作业历史记录
	 * @param tyXzzyxxHisVO
	 * @return
	 */
	public int insert(TyXzzyxxHisVO tyXzzyxxHisVO) {
		String sfba = tyXzzyxxHisVO.getSfba().toString();
		if (FilingStatusConstant.FILING.getValue().equals(sfba)
				|| FilingStatusConstant.REJECTED.getValue().equals(sfba)) {
            //驳回的审批意见必填
			if (FilingStatusConstant.REJECTED.getValue().equals(sfba)) {
				if (StringUtils.isEmpty(tyXzzyxxHisVO.getSpyj()))
					return -2;
			     }
				TyXzzyxxHisDO tyXzzyxxHisDO=new TyXzzyxxHisDO();
				LsBeanUtils.copyAllProperties(tyXzzyxxHisVO,tyXzzyxxHisDO);
				tyXzzyxxHisDO.setId(this.getMaxCodeById(tyXzzyxxHisDao.getMaxCodeById("XZ" + DateUtil.getDate()),  "XZ" + DateUtil.getDate(), 4));
				tyXzzyxxHisDao.insert(tyXzzyxxHisDO);
				return 1;
		}else {
			return -1;
		}
	}

}
