| 
					
				 | 
			
			
				@ -8,18 +8,21 @@ import com.yihu.iot.service.common.ElasticSearchQueryGenerator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.device.LocationDataDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.iot.device.IotPatientDeviceDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.MixEnvelop; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.rm.iot.IotRequestMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.common.LatitudeUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.mysql.query.BaseJpaService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.searchbox.client.JestResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import iot.device.LocationDataVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.elasticsearch.search.builder.SearchSourceBuilder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -275,16 +278,91 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return count; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<IotPatientDeviceVO> createRepairDevice(String deviceSn, Integer status, String damageDescription, String damageImages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 新增编辑维修记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param deviceSn 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param status 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param damageDescription 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param damageImages 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param repairDescription 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<IotPatientDeviceVO> createRepairDevice(String deviceSn, Integer status, String damageDescription, String damageImages, String repairDescription) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<IotPatientDeviceDO> patientDeviceDOList = iotPatientDeviceDao.findByDeviceSn(deviceSn); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for(IotPatientDeviceDO patientDeviceDO : patientDeviceDOList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            patientDeviceDO.setStatus(status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            patientDeviceDO.setDamageDescription(damageDescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            patientDeviceDO.setDamageImages(damageImages); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(StringUtils.isNotBlank(damageDescription)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                patientDeviceDO.setDamageDescription(damageDescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(StringUtils.isNotBlank(damageImages)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                patientDeviceDO.setDamageImages(damageImages); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(StringUtils.isNotBlank(repairDescription)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                patientDeviceDO.setRepairDescription(repairDescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            patientDeviceDO.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        iotPatientDeviceDao.save(patientDeviceDOList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<IotPatientDeviceVO> patientDeviceVOS = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return convertToModels(patientDeviceDOList, patientDeviceVOS, IotPatientDeviceVO.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 根据设备码获取相关厂商信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param deviceSn 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<IotPatientDeviceVO> getDeviceInfoByDeviceSn(String deviceSn) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT p.id,p.device_sn,p.device_id,p.device_name, GROUP_CONCAT(p.patient_name) as patientName,p.idcard,p.mobile,d.manufacturer_id, c.`name` manufacturerName,c.contacts_name, c.contacts_mobile " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "FROM `iot_patient_device` p, iot_device d LEFT JOIN iot_company c on d.manufacturer_id = c.id and c.status = 1 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "where p.device_sn = '" + deviceSn + "' and p.del =  1 and p.device_id= d.id GROUP BY p.device_sn "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<IotPatientDeviceVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取设备维修记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param deviceSn 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param status 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param manufacturerId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param pageSize 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MixEnvelop<IotPatientDeviceVO, IotPatientDeviceVO> getRepairDeviceList(String deviceSn, Integer status, String manufacturerId, Integer page, Integer pageSize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql ="SELECT p.device_sn,p.device_id,p.device_name,GROUP_CONCAT(p.patient_name) as patientName,p.idcard,p.mobile,p.`status`,p.damage_description,p.damage_images,p.repair_description,d.manufacturer_id, c.`name` manufacturerName,c.contacts_name, c.contacts_mobile " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "FROM `iot_patient_device` p, iot_device d LEFT JOIN iot_company c on d.manufacturer_id = c.id and c.status = 1 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "where  p.del =  1 and p.`status` is not null and p.`status` > 0 and p.device_id= d.id "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(deviceSn)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += " and p.device_sn like '%" + deviceSn + "%' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(manufacturerId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql +=" and d.manufacturer_id = '" +manufacturerId + "' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(status != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += " and p.status = " +status; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if(StringUtils.isNotBlank(manufacturerId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql +=" and p.status in (2,3,4) ";//厂商只展示三种维修状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql +=" GROUP BY p.device_sn ORDER BY p.update_time desc "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (page != null && pageSize != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sqlCount = "SELECT count(DISTINCT p.device_sn) " + sql.substring(sql.indexOf("FROM"), sql.length()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Long count = jdbcTemplate.queryForObject(sqlCount, Long.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += "limit " +(page-1)* pageSize + "," +pageSize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<IotPatientDeviceVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Device.message_success_find, list,page, pageSize,count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<IotPatientDeviceVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return MixEnvelop.getSuccessList(IotRequestMapping.Device.message_success_find, list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void deleteRepairDevice(String deviceSn) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<IotPatientDeviceDO> patientDeviceDOList = iotPatientDeviceDao.findByDeviceSn(deviceSn); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for(IotPatientDeviceDO patientDeviceDO : patientDeviceDOList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            patientDeviceDO.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            patientDeviceDO.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        iotPatientDeviceDao.save(patientDeviceDOList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |