|  | @ -9,6 +9,7 @@ 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.IotDeviceDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.iot.device.IotDeviceOverhaulDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.iot.device.IotPatientDeviceDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.iot.dict.IotSystemDictDO;
 | 
	
	
		
			
				|  | @ -409,6 +410,7 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
 | 
	
		
			
				|  |  |     public void delPatientDevice(String id, Integer del) {
 | 
	
		
			
				|  |  |         IotPatientDeviceDO patientDeviceDO = iotPatientDeviceDao.findOne(id);
 | 
	
		
			
				|  |  |         patientDeviceDO.setDel(del);
 | 
	
		
			
				|  |  |         patientDeviceDO.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |         iotPatientDeviceDao.save(patientDeviceDO);
 | 
	
		
			
				|  |  |         //更新设备绑定状态,加库存
 | 
	
		
			
				|  |  |         iotDeviceDao.updateIsGrantById(patientDeviceDO.getDeviceId(), 0);
 | 
	
	
		
			
				|  | @ -421,10 +423,10 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
 | 
	
		
			
				|  |  |     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 + "'% ";
 | 
	
		
			
				|  |  |             sql += "and d.device_sn like '%" + deviceSn + "%' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(patientName)){
 | 
	
		
			
				|  |  |             sql += "and d.patientName like '%" + patientName + "'% ";
 | 
	
		
			
				|  |  |             sql += "and d.patient_name like '%" + patientName + "%' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //判断是否需要分页
 | 
	
		
			
				|  |  |         if (page != null && pageSize != null) {
 | 
	
	
		
			
				|  | @ -437,4 +439,66 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
 | 
	
		
			
				|  |  |             return MixEnvelop.getSuccessList(IotRequestMapping.Common.message_success_find, deviceVOList);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public MixEnvelop<IotPatientDeviceVO,IotPatientDeviceVO> getPatientDeviceList(String deviceSn, String deviceName, String categoryCode, String patientName, String hospitalName, Integer isDel, Integer page, Integer pageSize) {
 | 
	
		
			
				|  |  |         String sql = "SELECT DISTINCT d.* FROM `iot_patient_device` d  where 1=1  ";
 | 
	
		
			
				|  |  |         if(isDel != null &&isDel == 1){
 | 
	
		
			
				|  |  |             sql += "and d.del != 1 ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(deviceSn)){
 | 
	
		
			
				|  |  |             sql += "and d.device_sn like '%" + deviceSn + "%' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(patientName)){
 | 
	
		
			
				|  |  |             sql += "and d.patient_name like '%" + patientName + "%' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(deviceName)){
 | 
	
		
			
				|  |  |             sql += "and d.device_name like '%" + deviceName + "%' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(categoryCode)){
 | 
	
		
			
				|  |  |             sql += "and d.category_code = '" + categoryCode + "' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(hospitalName)){
 | 
	
		
			
				|  |  |             sql += "and d.hospital_name like '%" + hospitalName + "%' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //判断是否需要分页
 | 
	
		
			
				|  |  |         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);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Transactional
 | 
	
		
			
				|  |  |     public IotPatientDeviceDO changePatientDevice(String id, String newDeviceSn, String newDeviceId) {
 | 
	
		
			
				|  |  |         IotPatientDeviceDO patientDeviceDO = iotPatientDeviceDao.findOne(id);
 | 
	
		
			
				|  |  |         IotDeviceDO deviceDO = null;
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(newDeviceId)){
 | 
	
		
			
				|  |  |             deviceDO = iotDeviceDao.findById(newDeviceId);
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             deviceDO = iotDeviceDao.findByDeviceSn(newDeviceSn);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         patientDeviceDO.setDeviceId(deviceDO.getId());
 | 
	
		
			
				|  |  |         patientDeviceDO.setDeviceName(deviceDO.getName());
 | 
	
		
			
				|  |  |         patientDeviceDO.setDeviceSn(deviceDO.getDeviceSn());
 | 
	
		
			
				|  |  |         patientDeviceDO.setSim(deviceDO.getSimNo());
 | 
	
		
			
				|  |  |         patientDeviceDO.setCategoryCode(deviceDO.getCategoryCode());
 | 
	
		
			
				|  |  |         patientDeviceDO.setCategoryName(deviceDO.getCategoryName());
 | 
	
		
			
				|  |  |         patientDeviceDO.setHospital(deviceDO.getHospital());
 | 
	
		
			
				|  |  |         patientDeviceDO.setHospitalName(deviceDO.getHospitalName());
 | 
	
		
			
				|  |  |         patientDeviceDO.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |         iotPatientDeviceDao.save(patientDeviceDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //更新设备绑定状态,减库存
 | 
	
		
			
				|  |  |         iotDeviceDao.updateIsGrantById(deviceDO.getId(), 1);
 | 
	
		
			
				|  |  |         return patientDeviceDO;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //删除居民设备回收记录
 | 
	
		
			
				|  |  |     public void deleteDelPatientDevice(String id) {
 | 
	
		
			
				|  |  |         iotPatientDeviceDao.delete(id);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |