|  | @ -7,12 +7,18 @@ import com.yihu.wlyy.repository.patient.PatientDeviceDao;
 | 
												
													
														
															|  | import com.yihu.wlyy.repository.patient.PatientDeviceLogDao;
 |  | import com.yihu.wlyy.repository.patient.PatientDeviceLogDao;
 | 
												
													
														
															|  | import com.yihu.wlyy.service.BaseService;
 |  | import com.yihu.wlyy.service.BaseService;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | import org.apache.commons.collections.map.HashedMap;
 | 
												
													
														
															|  | 
 |  | import org.apache.commons.lang3.StringUtils;
 | 
												
													
														
															|  | import org.springframework.beans.factory.annotation.Autowired;
 |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
												
													
														
															|  | 
 |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
												
													
														
															|  | import org.springframework.stereotype.Component;
 |  | import org.springframework.stereotype.Component;
 | 
												
													
														
															|  | import org.springframework.transaction.annotation.Transactional;
 |  | import org.springframework.transaction.annotation.Transactional;
 | 
												
													
														
															|  | import org.springside.modules.utils.Clock;
 |  | import org.springside.modules.utils.Clock;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | import java.util.ArrayList;
 | 
												
													
														
															|  | import java.util.Date;
 |  | import java.util.Date;
 | 
												
													
														
															|  | 
 |  | import java.util.List;
 | 
												
													
														
															|  | 
 |  | import java.util.Map;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | @Component
 |  | @Component
 | 
												
													
														
															|  | @Transactional(rollbackFor = Exception.class)
 |  | @Transactional(rollbackFor = Exception.class)
 | 
												
											
												
													
														
															|  | @ -24,9 +30,11 @@ public class PatientDeviceLogService extends BaseService {
 | 
												
													
														
															|  |     private PatientDeviceLogDao patientDeviceLogDao;
 |  |     private PatientDeviceLogDao patientDeviceLogDao;
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private PatientDeviceDao patientDeviceDao;
 |  |     private PatientDeviceDao patientDeviceDao;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private JdbcTemplate jdbcTemplate;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      *
 |  | 
 | 
												
													
														
															|  | 
 |  |      * 绑定和解绑的时候会保存一条数据
 | 
												
													
														
															|  |      * @param patientDevice
 |  |      * @param patientDevice
 | 
												
													
														
															|  |      * @param role
 |  |      * @param role
 | 
												
													
														
															|  |      * @param operateCode
 |  |      * @param operateCode
 | 
												
											
												
													
														
															|  | @ -37,19 +45,68 @@ public class PatientDeviceLogService extends BaseService {
 | 
												
													
														
															|  |            patientDevice = patientDeviceDao.findByDeviceSn(deviceSn).get(0);
 |  |            patientDevice = patientDeviceDao.findByDeviceSn(deviceSn).get(0);
 | 
												
													
														
															|  |        }
 |  |        }
 | 
												
													
														
															|  |         PatientDeviceLog patientDeviceLog = new PatientDeviceLog();
 |  |         PatientDeviceLog patientDeviceLog = new PatientDeviceLog();
 | 
												
													
														
															|  | 
 |  |         patientDeviceLog.setDeviceId(patientDevice.getDeviceId());
 | 
												
													
														
															|  |         patientDeviceLog.setPatient(patientDevice.getUser());
 |  |         patientDeviceLog.setPatient(patientDevice.getUser());
 | 
												
													
														
															|  |         patientDeviceLog.setCategoryCode(patientDevice.getCategoryCode());
 |  |         patientDeviceLog.setCategoryCode(patientDevice.getCategoryCode());
 | 
												
													
														
															|  |         patientDeviceLog.setDeviceName(patientDevice.getDeviceName());
 |  |         patientDeviceLog.setDeviceName(patientDevice.getDeviceName());
 | 
												
													
														
															|  |         patientDeviceLog.setDeviceSn(patientDevice.getDeviceSn());
 |  |         patientDeviceLog.setDeviceSn(patientDevice.getDeviceSn());
 | 
												
													
														
															|  |         patientDeviceLog.setRole(role);
 |  |         patientDeviceLog.setRole(role);
 | 
												
													
														
															|  |         patientDeviceLog.setOperateCode(operateCode);
 |  |         patientDeviceLog.setOperateCode(operateCode);
 | 
												
													
														
															|  | 
 |  |         patientDeviceLog.setAgreementPhoto(patientDevice.getAgreementPhoto());
 | 
												
													
														
															|  |         if (role==1){
 |  |         if (role==1){
 | 
												
													
														
															|  | 
 |  |             patientDeviceLog.setOperatorName(patientDevice.getDoctorName());
 | 
												
													
														
															|  |             patientDeviceLog.setOperator(patientDevice.getDoctor());
 |  |             patientDeviceLog.setOperator(patientDevice.getDoctor());
 | 
												
													
														
															|  |         }else if (role==2){
 |  |         }else if (role==2){
 | 
												
													
														
															|  | 
 |  |             patientDeviceLog.setOperatorName(patientDevice.getAgentName());
 | 
												
													
														
															|  |             patientDeviceLog.setOperator(patientDevice.getAgent());
 |  |             patientDeviceLog.setOperator(patientDevice.getAgent());
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         patientDeviceLog.setCreateTime(new Date());
 |  |         patientDeviceLog.setCreateTime(new Date());
 | 
												
													
														
															|  |         patientDeviceLogDao.save(patientDeviceLog);
 |  |         patientDeviceLogDao.save(patientDeviceLog);
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public Map<String,Object> getDevicesList(String noGaugeDay,String isBinding,String categoryCode,int pageNo,int pageSize){
 | 
												
													
														
															|  | 
 |  |         List<Map<String,Object>> resultList =  new ArrayList<>();
 | 
												
													
														
															|  | 
 |  |         Map<String,Object> resultMap = new HashedMap();
 | 
												
													
														
															|  | 
 |  |         int start = (pageNo-1)*pageSize;
 | 
												
													
														
															|  | 
 |  |         String sql ="SELECT b.*,dd.photo FROM (SELECT a.* FROM (" +
 | 
												
													
														
															|  | 
 |  |                 "  SELECT sf.name, pd.* FROM wlyy_patient_device_log pd" +
 | 
												
													
														
															|  | 
 |  |                 "  LEFT JOIN wlyy_sign_family sf ON pd.patient = sf.patient" +
 | 
												
													
														
															|  | 
 |  |                 "  WHERE" +
 | 
												
													
														
															|  | 
 |  |                 "   pd.is_del = 1" +
 | 
												
													
														
															|  | 
 |  |                 "  AND sf.`status` > 0" +
 | 
												
													
														
															|  | 
 |  |                 "  ORDER BY" +
 | 
												
													
														
															|  | 
 |  |                 "  create_time DESC) a" +
 | 
												
													
														
															|  | 
 |  |                 " GROUP BY a.device_sn) b" +
 | 
												
													
														
															|  | 
 |  |                 " LEFT JOIN dm_device dd ON b.device_id = dd.id where 1=1 ";
 | 
												
													
														
															|  | 
 |  |         resultList = jdbcTemplate.queryForList(sql);
 | 
												
													
														
															|  | 
 |  |         resultMap.put("tatalCount",resultList.size());
 | 
												
													
														
															|  | 
 |  |         //筛选条件--是否绑定
 | 
												
													
														
															|  | 
 |  |         if (!StringUtils.isEmpty(isBinding)){
 | 
												
													
														
															|  | 
 |  |             sql += " and b.operate_code= "+isBinding;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //筛选条件--设备类型
 | 
												
													
														
															|  | 
 |  |         if (!StringUtils.isEmpty(categoryCode)){
 | 
												
													
														
															|  | 
 |  |             sql += " and b.category_code= "+categoryCode;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //筛选条件--今日未测量
 | 
												
													
														
															|  | 
 |  |         if (!StringUtils.isEmpty(noGaugeDay) && StringUtils.equals("1",noGaugeDay)){
 | 
												
													
														
															|  | 
 |  |             sql += " and b.patient NOT IN (SELECT user FROM device.wlyy_patient_health_index WHERE TO_DAYS(record_date)=TO_DAYS(NOW()))";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //筛选条件--七天内未测量
 | 
												
													
														
															|  | 
 |  |         if (!StringUtils.isEmpty(noGaugeDay) && StringUtils.equals("2",noGaugeDay)){
 | 
												
													
														
															|  | 
 |  |             sql += " and b.patient NOT IN (SELECT user FROM device.wlyy_patient_health_index WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= DATE(record_date))";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //筛选条件--一个月内未测量
 | 
												
													
														
															|  | 
 |  |         if (!StringUtils.isEmpty(noGaugeDay) && StringUtils.equals("3",noGaugeDay)){
 | 
												
													
														
															|  | 
 |  |             sql += " and b.patient NOT IN (SELECT user FROM device.wlyy_patient_health_index WHERE DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= DATE(record_date))";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //筛选条件--超过一个月未测量
 | 
												
													
														
															|  | 
 |  |         if (!StringUtils.isEmpty(noGaugeDay) && StringUtils.equals("4",noGaugeDay)){
 | 
												
													
														
															|  | 
 |  |             sql += " and b.patient NOT IN (SELECT user FROM device.wlyy_patient_health_index WHERE  DATE_SUB(CURDATE(), INTERVAL 1 MONTH) > DATE(record_date))";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         resultList = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
 | 
												
													
														
															|  | 
 |  |         resultMap.put("data",resultList);
 | 
												
													
														
															|  | 
 |  |         return resultMap;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | }
 |  | }
 |