package com.unis.detectionnum.server.domain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageInfo;
import com.unis.detectionnum.server.entity.AlarmParamDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.unis.common.utils.LsBeanUtils;
import com.unis.detectionnum.common.vo.DeviceInfoQueryVO;
import com.unis.detectionnum.common.vo.DeviceOperateVO;
import com.unis.detectionnum.common.vo.ScanDataQueryVO;
import com.unis.detectionnum.common.vo.ScanDataRecordVO;
import com.unis.detectionnum.server.dao.DeviceOperateDao;
import com.unis.detectionnum.server.entity.DeviceOperateDO;

@Component
public class DeviceOperateDomain extends BaseDomain{

	@Autowired
    DeviceOperateDao deviceOperateDao;
	
	public String insert(DeviceOperateVO deviceOperateVO) {
		DeviceOperateDO deviceOperateDO = new DeviceOperateDO();
		LsBeanUtils.copyAllProperties(deviceOperateVO,deviceOperateDO);
		deviceOperateDao.insertSelective(deviceOperateDO);
		return deviceOperateDO.getId();
		
	}
	
	public List<DeviceOperateVO> getDeviceOperateList(DeviceInfoQueryVO deviceInfoQueryVO) {
		
		List<DeviceOperateVO> deviceOperateVOs = new ArrayList<>();
		List<DeviceOperateDO> deviceOperateDOs = deviceOperateDao.selectByDeviceInfo(deviceInfoQueryVO);
		for(DeviceOperateDO operateDO:deviceOperateDOs) {
			DeviceOperateVO deviceOperateVO = new DeviceOperateVO();
			LsBeanUtils.copyAllProperties(operateDO,deviceOperateVO);
			deviceOperateVOs.add(deviceOperateVO);
		}
		return deviceOperateVOs;
	}

	/** 
	 * @Title: recordList 
	 * @Description: 数据查询-扫描记录查询
	 * @param scanDataQueryVO
	 * @return List<ScanDataRecordVO>
	 * @throws 
	 */
	public List<ScanDataRecordVO> recordList(ScanDataQueryVO scanDataQueryVO) {

        return deviceOperateDao.selectRecordList(scanDataQueryVO);
    }


	/** 
	 * @Title: getLastOperate 
	 * @Description: 根据设备编号获取上次扫描数据
	 * @param sbCode
	 * @return DeviceOperateVO
	 * @throws 
	 */
	public DeviceOperateVO getLastOperate(String sbCode) {
		DeviceOperateVO operateVO = new DeviceOperateVO();
		// TODO Auto-generated method stub
		DeviceOperateDO operateDO = deviceOperateDao.selectLastOperate(sbCode);
		if(operateDO != null) {
			LsBeanUtils.copyAllProperties(operateDO, operateVO);
		}
		return operateVO;
	}

    public DeviceOperateDO selectByPrimaryKey(String operateId) {
		DeviceOperateDO deviceOperateDO = deviceOperateDao.selectByPrimaryKey(operateId);
		return deviceOperateDO;
    }

    public void updateTjAndZl(DeviceOperateVO currentOperate) {
	    deviceOperateDao.updateTjAndZl(currentOperate);
    }

    public Map<String,Object> selectByOperateId(String operateId) {
        return deviceOperateDao.selectByOperateId(operateId);
    }


    public void updateSmcsByOperateId(DeviceOperateVO currentOperate) {
	    DeviceOperateDO deviceOperateDO = new DeviceOperateDO();
        LsBeanUtils.copyAllProperties(currentOperate, deviceOperateDO);
        deviceOperateDao.updateSmcsByOperateId(deviceOperateDO);
    }

	public void updateFlagByOperateId(String operateId) {
		deviceOperateDao.updateFlagByOperateId(operateId);
	}

	public int findByOperateId(String operateId) {
		return deviceOperateDao.findByOperateId(operateId);
	}

	public double getsmcd(String operateId) {
		return deviceOperateDao.getsmcd(operateId);
	}

	public double getsmkd(String operateId) {
		return deviceOperateDao.getsmkd(operateId);
	}

	public double getsmax(String operateId) {
		return deviceOperateDao.getsmax(operateId);
	}

	public double getsmby(String operateId) {
		return deviceOperateDao.getsmby(operateId);
	}

	public void deleteByOperateId(String operateId) {
		deviceOperateDao.deleteByPrimaryKey(operateId);
	}

	public void updateByPrimaryKeySelective(DeviceOperateVO currentOperate) {
		DeviceOperateDO deviceOperateDO = new DeviceOperateDO();
		LsBeanUtils.copyAllProperties(currentOperate, deviceOperateDO);
		deviceOperateDao.updateByPrimaryKeySelective(deviceOperateDO);
	}

	public Map<String,Object> getByCfbn(String cfbm) {
		return deviceOperateDao.getByCfbn(cfbm);
	}

	public Map<String,Object> getCfByid(String id) {
		return deviceOperateDao.getCfByid(id);
	}
}
