package com.unis.base.server.domain;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.unis.base.common.vo.TyXzzyxxHisVO;
import com.unis.base.common.vo.TyXzzyxxVO;
import com.unis.base.server.dao.TyXzzyxxDao;
import com.unis.base.server.entity.TyXzzyxxDO;
import com.unis.common.utils.LsBeanUtils;
import org.springframework.stereotype.Component;
/**
 * @author huangxing
 * @version 1.0
 * @Title TyXzzyxxDomain
 * @ProjectName 持久化
 * @date 2019/07/22 17点26分
 */
@Component
public class TyXzzyxxDomain extends BaseDomain {

	@Autowired
	private TyXzzyxxDao tyXzzyxxMapper;
	@Autowired
	private TyXzzyxxHisDomain tyXzzyxxHisDomain;
	/**
	 * 
	 * @param
	 * @return
	 */
	public List<TyXzzyxxVO> getTyXzzyxxList(TyXzzyxxVO tyXzzyxxVO) {
		TyXzzyxxDO xzzyxxDO = new TyXzzyxxDO();
		//进行传递参数copy
		LsBeanUtils.copyAllProperties(tyXzzyxxVO, xzzyxxDO);
		//查询数据
		List<TyXzzyxxDO> xzzyxxDOs = tyXzzyxxMapper.selectAlls(xzzyxxDO);
		
		if (xzzyxxDOs==null) {
			return null;
		 }

		List<TyXzzyxxVO> PageInfoDO = new ArrayList<TyXzzyxxVO>();
		LsBeanUtils.copyCollection(xzzyxxDOs, PageInfoDO, TyXzzyxxVO.class);
		return PageInfoDO;
	}

	/**
	 * 
	 * @param
	 * @return
	 */
	public int insert(TyXzzyxxVO tyXzzyxxVO) {
		//进行传递参数copy
		TyXzzyxxDO tyXzzyxxDO = new TyXzzyxxDO();
		LsBeanUtils.copyAllProperties(tyXzzyxxVO, tyXzzyxxDO);
		return tyXzzyxxMapper.insert(tyXzzyxxDO);
	}

	/**
	 * 
	 * @param xzzyid
	 * @return
	 */
	public TyXzzyxxVO getTyXzzyxxById(String xzzyid) {
		TyXzzyxxVO tyXzzyxxVO = new TyXzzyxxVO();
		LsBeanUtils.copyAllProperties(tyXzzyxxMapper.selectByKey(xzzyid), tyXzzyxxVO);
		return tyXzzyxxVO;
	}

	/**
	 * 
	 * @param
	 * @return
	 */
	public int update(TyXzzyxxVO tyXzzyxxVO) {
		//进行传递参数copy
		TyXzzyxxDO tyXzzyxxDO = new TyXzzyxxDO();
		LsBeanUtils.copyAllProperties(tyXzzyxxVO, tyXzzyxxDO);
		return tyXzzyxxMapper.updateByPrimaryKey(tyXzzyxxDO);
	}

	/**
	 * 熏蒸作业信息-更改备案状态
	 * @param tyXzzyxxVO
	 * @return
	 */
	public Integer updateFumigationOperationStatus(TyXzzyxxHisVO tyXzzyxxHisVO) {
		Map<String, Object> updateMap = new HashMap<>();
		updateMap.put("xzzyid",tyXzzyxxHisVO.getXzzyid());
		updateMap.put("sfba",tyXzzyxxHisVO.getSfba());
    	int i = tyXzzyxxMapper.updateFumigationOperationStatus(updateMap);
		if (i == 0){
			return i;
		}
		return tyXzzyxxHisDomain.insert(tyXzzyxxHisVO);
	}

	/**
	 * @param tyXzzyxxVO
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public PageInfo<TyXzzyxxVO> getTyXzzyxxPage(TyXzzyxxVO tyXzzyxxVO, Integer pageNum, Integer pageSize) {
		PageInfo<TyXzzyxxVO> pageInfoVO = new PageInfo<TyXzzyxxVO>();
		PageHelper.startPage(pageNum, pageSize);
		TyXzzyxxDO xzzyxxDO = new TyXzzyxxDO();
		//进行传递参数copy
		LsBeanUtils.copyAllProperties(tyXzzyxxVO, xzzyxxDO);
		//查询数据
		List<TyXzzyxxDO> xzzyxxDOs = tyXzzyxxMapper.selectAlls(xzzyxxDO);
		
		if (xzzyxxDOs==null) {
			return null;
		 }
		PageInfo<TyXzzyxxDO> pageInfoDO = new PageInfo<TyXzzyxxDO>(xzzyxxDOs);
		LsBeanUtils.copyAllProperties(pageInfoDO,pageInfoVO);
		return pageInfoVO;
	}
	
}
