package com.unis.base.server.domain;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.unis.base.common.constant.FilingStatusConstant;
import com.unis.base.common.vo.PersonnelRecordsHisVO;
import com.unis.base.common.vo.DRyxxsjyVO;
import com.unis.base.common.vo.EnterpriseQualificationInformationHisVO;
import com.unis.base.common.vo.EnterpriseQualificationInformationHisqueryVO;
import com.unis.base.common.vo.QyzgQyzgxxVO;
import com.unis.base.server.dao.DRyxxsjyDao;
import com.unis.base.server.dao.DRyxxsjyHisDao;
import com.unis.base.server.dao.QyzgQyzgxxDao;
import com.unis.base.server.dao.QyzgQyzgxxHisDao;
import com.unis.base.server.entity.DRyxxsjyDO;
import com.unis.base.server.entity.DRyxxsjyHisDO;
import com.unis.base.server.entity.QyzgQyzgxxDO;
import com.unis.base.server.entity.QyzgQyzgxxHisDO;
import com.unis.common.utils.DateUtil;
import com.unis.common.utils.LsBeanUtils;
import org.springframework.stereotype.Component;
/**
 * 企业资格信息历史
 * @author liuweilong
 *
 */
@Component
public class EnterpriseQualificationInformationHisDomain extends BaseDomain {

	@Autowired
	private QyzgQyzgxxHisDao qyzgQyzgxxHisDao;
	
	//审核通过
	private static final Long Y=(long) 3;
	
	//审核驳回
	private static final Long N=(long) 4;

	/**
	 * 新增企业历史
	 * @param dAjxxsjyVO
	 * @return
	 */
	public int insert(EnterpriseQualificationInformationHisVO qyzgQyzgxxHisVO) {
		//获取备案状态
		Long sfba = qyzgQyzgxxHisVO.getSfba();
		//通过或者驳回状态
		if (Y==(sfba) || N==(sfba)) {
			if (Y==sfba) {
				//驳回必须有审批意见
				if (StringUtils.isEmpty(qyzgQyzgxxHisVO.getSpyj())){
					return -2;
				}
			}
			//新增企业资格历史信息
			QyzgQyzgxxHisDO qyzgQyzgxxHisDO=new QyzgQyzgxxHisDO();
			LsBeanUtils.copyAllProperties(qyzgQyzgxxHisVO, qyzgQyzgxxHisDO);
			
			//设置主键
			String id = getMaxCodeById(qyzgQyzgxxHisDao.getMaxCodeById("QY" + DateUtil.getDate()),
					"QY" + DateUtil.getDate(), 3);
			qyzgQyzgxxHisDO.setId(id);
			
			return qyzgQyzgxxHisDao.insertSelective(qyzgQyzgxxHisDO);
		}else{
			//备案状态不是通过或者驳回
			return -1;
		}
	}
	
	/**
	 * 企业历史分页
	 * @return
	 */
	public PageInfo<EnterpriseQualificationInformationHisVO> getpageList(EnterpriseQualificationInformationHisqueryVO qyzgQyzgxxHisqueryVO,Integer pageNum,Integer pageSize){
		PageHelper.startPage(pageNum,pageSize);
		List<QyzgQyzgxxHisDO> list = qyzgQyzgxxHisDao.getList(qyzgQyzgxxHisqueryVO);
		PageInfo<QyzgQyzgxxHisDO> pageInfo=new PageInfo<QyzgQyzgxxHisDO>(list);
		
		PageInfo<EnterpriseQualificationInformationHisVO> Info=new PageInfo<EnterpriseQualificationInformationHisVO>();
		
		LsBeanUtils.copyAllProperties(pageInfo, Info);
		
		return Info;
		
	}
	
	/**
	 * 查询企业资格历史信息
	 * @param id
	 * @return
	 */
	public EnterpriseQualificationInformationHisVO selectByPerimKey(String id){
		
		QyzgQyzgxxHisDO selectByPrimaryKey = qyzgQyzgxxHisDao.selectUsePrimaryKey(id);
		if (selectByPrimaryKey != null) {
			EnterpriseQualificationInformationHisVO enterpriseQualificationInformationHisVO=new EnterpriseQualificationInformationHisVO();
			LsBeanUtils.copyAllProperties(selectByPrimaryKey, enterpriseQualificationInformationHisVO);
			return enterpriseQualificationInformationHisVO;
		}
		
		return null;
		
	}
	

	
}
