| 
					
				 | 
			
			
				@ -2,13 +2,19 @@ package com.yihu.iot.service.device; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.elasticsearch.ElasticSearchHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.iot.dao.device.IotDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.iot.dao.device.IotDeviceOverhaulDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.iot.dao.device.IotPatientDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.iot.datainput.util.ConstantUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.iot.service.common.ElasticSearchQueryGenerator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.iot.service.dict.IotSystemDictService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.device.LocationDataDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.iot.device.IotDeviceOverhaulDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.iot.device.IotPatientDeviceDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.iot.dict.IotSystemDictDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.MixEnvelop; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.rm.base.BaseRequestMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.rm.iot.IotRequestMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.common.LatitudeUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.date.DateUtil; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -22,7 +28,9 @@ import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.data.domain.Pageable; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.BeanPropertyRowMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -40,17 +48,48 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private ElasticSearchHelper elasticSearchHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private ElasticSearchQueryGenerator elasticSearchQueryGenerator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private IotDeviceDao iotDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JdbcTemplate jdbcTempalte; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private IotSystemDictService iotSystemDictService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private IotDeviceOverhaulDao deviceOverhaulDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 新增 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param patientDevice 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public IotPatientDeviceDO create(IotPatientDeviceDO patientDevice) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        patientDevice.setSaasId(getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        patientDevice.setDel(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return iotPatientDeviceDao.save(patientDevice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        IotPatientDeviceDO patientDeviceDO = iotPatientDeviceDao.save(patientDevice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //更新设备绑定状态,减库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        iotDeviceDao.updateIsGrantById(patientDevice.getDeviceId(), 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //生成一年检修记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<IotSystemDictDO> systemDictDOS = iotSystemDictService.getListByDictName("OVERHAUL_FREQUENCY");//获取设备检修时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(systemDictDOS.size() == 1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<IotDeviceOverhaulDO> deviceOverhaulDOS = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            int day = Integer.parseInt(systemDictDOS.get(0).getValue());//检修间隔天数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            int count = 365/day; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for(int i = 0 ; i< count; i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                IotDeviceOverhaulDO deviceOverhaulDO = new IotDeviceOverhaulDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                deviceOverhaulDO.setSaasId(getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                deviceOverhaulDO.setPatientDeviceId(patientDeviceDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                deviceOverhaulDO.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                deviceOverhaulDO.setTime(DateUtil.dateToStr(DateUtil.getNextDay1(new Date(), day*(i+1)), "yyyy年MM月dd日")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                deviceOverhaulDO.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                deviceOverhaulDO.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                deviceOverhaulDOS.add(deviceOverhaulDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            deviceOverhaulDao.save(deviceOverhaulDOS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return patientDeviceDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -365,4 +404,37 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        iotPatientDeviceDao.save(patientDeviceDOList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void delPatientDevice(String id, Integer del) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        IotPatientDeviceDO patientDeviceDO = iotPatientDeviceDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        patientDeviceDO.setDel(del); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        iotPatientDeviceDao.save(patientDeviceDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //更新设备绑定状态,加库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        iotDeviceDao.updateIsGrantById(patientDeviceDO.getDeviceId(), 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(del == -1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //核销设备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            iotDeviceDao.updateDelById(patientDeviceDO.getDeviceId(), 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MixEnvelop<IotPatientDeviceVO,IotPatientDeviceVO> getOverhaulDeviceList(String deviceSn, String patientName, Integer page, Integer pageSize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT DISTINCT d.* FROM `iot_patient_device` d , iot_device_overhaul o where d.del= 1 and  d.id = o.patient_device_id "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(deviceSn)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += "and d.device_sn like '%" + deviceSn + "'% "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(patientName)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += "and d.patientName like '%" + patientName + "'% "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //判断是否需要分页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (page != null && pageSize != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Long count = Long.valueOf(jdbcTempalte.queryForList(sql).size()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += "limit " + (page - 1) * pageSize + "," + pageSize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<IotPatientDeviceVO> deviceVOList = jdbcTempalte.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find, deviceVOList, page, pageSize, count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<IotPatientDeviceVO> deviceVOList = jdbcTempalte.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return MixEnvelop.getSuccessList(IotRequestMapping.Common.message_success_find, deviceVOList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |