package com.unis.detectionnum.server.domain;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.unis.common.utils.LsBeanUtils;
import com.unis.detectionnum.common.vo.AlarmParamVO;
import com.unis.detectionnum.server.dao.AlarmParamDao;
import com.unis.detectionnum.server.entity.AlarmParamDO;

@Component
public class AlarmParamDomain extends BaseDomain{

	@Autowired
    private AlarmParamDao alarmParamDao;

	/** 
	 * @Title: saveAlarmParam 
	 * @Description: 添加告警参数
	 * @param alarmParamVO
	 * @return int
	 * @throws 
	 */
	public int saveAlarmParam(AlarmParamVO alarmParamVO) {
		// TODO Auto-generated method stub
		AlarmParamDO alarmParamDO = new AlarmParamDO();
		LsBeanUtils.copyAllProperties(alarmParamVO, alarmParamDO);
		//若总数开关为开则添加粮食总量
		if(alarmParamDO.getTotalStatus() == 1){
			AlarmParamDO alarmParamDO1 = alarmParamDao.selecttotalStatus(alarmParamDO.getCfbh());
			if(alarmParamDO1 ==null){
				alarmParamDO.setTotalStatus(0);
			}else{
				alarmParamDO.setLsZl(alarmParamDO1.getLsZl());
			}
		}
		return alarmParamDao.insertSelective(alarmParamDO);
	}

	/** 
	 * @Title: alarmParamDomain 
	 * @Description: 修改告警参数
	 * @param alarmParamVO
	 * @return int
	 * @throws 
	 */
	public int alarmParamDomain(AlarmParamVO alarmParamVO) {
		
		AlarmParamDO alarmParamDO = new AlarmParamDO();
		LsBeanUtils.copyAllProperties(alarmParamVO, alarmParamDO);
		//若总数开关为开则添加粮食总量
		if(alarmParamDO.getTotalStatus() == 1){
			AlarmParamDO alarmParamDO1 = alarmParamDao.selecttotalStatus(alarmParamDO.getCfbh());
			if(alarmParamDO1 !=null) {
				alarmParamDO.setLsZl(alarmParamDO1.getLsZl());
			}
		}
		return alarmParamDao.updateByPrimaryKeySelective(alarmParamDO);
	}

	/** 
	 * @Title: getAlarmParamByCfbh 
	 * @Description: 根据仓房编号查询
	 * @param cfbh
	 * @return AlarmParamVO
	 * @throws 
	 */
	public AlarmParamVO getAlarmParamByCfbh(String cfbh) {
		
		AlarmParamVO alarmParamVO = null;
		
		AlarmParamDO alarmParamDO = alarmParamDao.selectByCfbh(cfbh);
		if(alarmParamDO != null) {
			alarmParamVO = new AlarmParamVO();
			LsBeanUtils.copyAllProperties(alarmParamDO, alarmParamVO);
		}
		return alarmParamVO;
	}

	/** 
	 * @Title: getAlarmParamBySbCode 
	 * @Description: 根据设备code获取所在仓房的告警参数
	 * @param sbCode
	 * @return AlarmParamVO
	 * @throws 
	 */
	public AlarmParamVO getAlarmParamBySbCode(String sbCode) {
		
		AlarmParamVO alarmParamVO = null;
		
		AlarmParamDO alarmParamDO = alarmParamDao.selectBySbCode(sbCode);
		if(alarmParamDO != null) {
			alarmParamVO = new AlarmParamVO();
			LsBeanUtils.copyAllProperties(alarmParamDO, alarmParamVO);
		}
		return alarmParamVO;
	}



}
