|  | @ -0,0 +1,345 @@
 | 
												
													
														
															|  | 
 |  | package com.yihu.iot.service.device;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | import com.yihu.iot.service.common.OrgUserService;
 | 
												
													
														
															|  | 
 |  | import com.yihu.iot.service.useragent.UserAgent;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.restmodel.iot.device.DeviceHealthIndexVO;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.restmodel.iot.device.WlyyDeviceVO;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.restmodel.iot.device.WlyyHealthStandardVO;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.restmodel.iot.device.WlyyPatientDeviceVO;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.restmodel.web.MixEnvelop;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.rm.iot.IotRequestMapping;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.util.date.DateUtil;
 | 
												
													
														
															|  | 
 |  | import org.apache.commons.lang3.StringUtils;
 | 
												
													
														
															|  | 
 |  | import org.json.JSONObject;
 | 
												
													
														
															|  | 
 |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
												
													
														
															|  | 
 |  | import org.springframework.data.domain.Page;
 | 
												
													
														
															|  | 
 |  | import org.springframework.data.domain.PageImpl;
 | 
												
													
														
															|  | 
 |  | import org.springframework.data.domain.PageRequest;
 | 
												
													
														
															|  | 
 |  | import org.springframework.data.domain.Pageable;
 | 
												
													
														
															|  | 
 |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
												
													
														
															|  | 
 |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
												
													
														
															|  | 
 |  | import org.springframework.stereotype.Service;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | import java.util.*;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | /**
 | 
												
													
														
															|  | 
 |  |  * Created by ysj on 2020/07/29
 | 
												
													
														
															|  | 
 |  |  * device数据库
 | 
												
													
														
															|  | 
 |  |  */
 | 
												
													
														
															|  | 
 |  | @Service
 | 
												
													
														
															|  | 
 |  | public class WlyyDeviceService {
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     // 血糖餐前最小值
 | 
												
													
														
															|  | 
 |  |     public static final double HEALTH_STANDARD_ST_MIN_BEFORE = 4;//3.9
 | 
												
													
														
															|  | 
 |  |     // 血糖餐前最大值
 | 
												
													
														
															|  | 
 |  |     public static final double HEALTH_STANDARD_ST_MAX_BEFORE = 7;//6.1
 | 
												
													
														
															|  | 
 |  |     // 血糖餐后最小值
 | 
												
													
														
															|  | 
 |  |     public static final double HEALTH_STANDARD_ST_MIN_AFTER = 4;//4.4
 | 
												
													
														
															|  | 
 |  |     // 血糖餐后最大值
 | 
												
													
														
															|  | 
 |  |     public static final double HEALTH_STANDARD_ST_MAX_AFTER = 11.1;//7.8
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     // 舒张压最小值
 | 
												
													
														
															|  | 
 |  |     public static final double HEALTH_STANDARD_SZY_MIN = 60;//60
 | 
												
													
														
															|  | 
 |  |     // 舒张压最大值
 | 
												
													
														
															|  | 
 |  |     public static final double HEALTH_STANDARD_SZY_MAX = 90;//89
 | 
												
													
														
															|  | 
 |  |     // 收缩压最小值
 | 
												
													
														
															|  | 
 |  |     public static final double HEALTH_STANDARD_SSY_MIN = 90;//90
 | 
												
													
														
															|  | 
 |  |     // 收缩压最大值
 | 
												
													
														
															|  | 
 |  |     public static final double HEALTH_STANDARD_SSY_MAX = 140;//139
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private JdbcTemplate jdbcTemplate;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private UserAgent userAgent;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private OrgUserService orgUserService;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public MixEnvelop<WlyyDeviceVO,WlyyDeviceVO> searchDeviceList(String deviceName,String deviceCode,String orgName,String linkman,Integer page,Integer pageSize){
 | 
												
													
														
															|  | 
 |  |         String sql = "select * from device.wlyy_devices where 1=1 ";
 | 
												
													
														
															|  | 
 |  |         if(!StringUtils.isEmpty(orgName)){
 | 
												
													
														
															|  | 
 |  |             sql +=" and org_name like '%"+orgName+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if(!StringUtils.isEmpty(deviceCode)){
 | 
												
													
														
															|  | 
 |  |             sql +=" and device_code = '"+deviceCode+"' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if(!StringUtils.isEmpty(deviceName)){
 | 
												
													
														
															|  | 
 |  |             sql +=" and device_name like '%"+deviceName+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if(!StringUtils.isEmpty(linkman)){
 | 
												
													
														
															|  | 
 |  |             sql +=" and linkmam like '%"+linkman+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         //数据权限过滤
 | 
												
													
														
															|  | 
 |  |         List<String> orgList = orgUserService.getUserOrgNameById(userAgent.getUID());
 | 
												
													
														
															|  | 
 |  |         if(!orgList.contains(userAgent.commonHospitalName)){
 | 
												
													
														
															|  | 
 |  |             sql += " and org_name in ("+orgUserService.getUserOrg(orgList)+") ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         sql += " order by id desc ";
 | 
												
													
														
															|  | 
 |  |         Long count = Long.valueOf(jdbcTemplate.queryForList(sql).size());
 | 
												
													
														
															|  | 
 |  |         sql += "limit " + (page - 1) * pageSize + "," + pageSize;
 | 
												
													
														
															|  | 
 |  |         List<WlyyDeviceVO> deviceVOList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(WlyyDeviceVO.class));
 | 
												
													
														
															|  | 
 |  |         return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find, deviceVOList, page, pageSize, count);
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public MixEnvelop<WlyyDeviceVO,WlyyDeviceVO> findById(Long id){
 | 
												
													
														
															|  | 
 |  |         String sql = "select * from device.wlyy_devices where id = "+id;
 | 
												
													
														
															|  | 
 |  |         List<WlyyDeviceVO> deviceVOList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(WlyyDeviceVO.class));
 | 
												
													
														
															|  | 
 |  |         return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_find,deviceVOList.get(0));
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public Page<DeviceHealthIndexVO> searchList(String deviceSn, String date, String idcard, String userName, String indexType, Integer page, Integer pageSize,
 | 
												
													
														
															|  | 
 |  |                                                  Double indexTypeMin1, Double indexTypeMax1, Double indexTypeMin2, Double indexTypeMax2, String doctorName)throws Exception{
 | 
												
													
														
															|  | 
 |  |         if (page == null){
 | 
												
													
														
															|  | 
 |  |             page = 1;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if(pageSize == null){
 | 
												
													
														
															|  | 
 |  |             pageSize = 15;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         Pageable pageRequest = new PageRequest(page-1,pageSize);
 | 
												
													
														
															|  | 
 |  |         StringBuilder filter = new StringBuilder();
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         String sql =" SELECT i.* ,p.name userName FROM device.wlyy_patient_health_index i left join wlyy.wlyy_sign_family s on i.`user` = s. patient and s.`status`>0, wlyy.wlyy_patient p WHERE i.user=p.code ";
 | 
												
													
														
															|  | 
 |  |         String countSql =" SELECT count(1) as num FROM device.wlyy_patient_health_index i left join wlyy.wlyy_sign_family s on i.`user` = s. patient and s.`status`>0, wlyy.wlyy_patient p WHERE i.user=p.code ";
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         //根据患者名称过滤
 | 
												
													
														
															|  | 
 |  |         if(!StringUtils.isEmpty(userName)){
 | 
												
													
														
															|  | 
 |  |             filter.append(" AND p.name LIKE '%"+userName+"%' ");
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if(!StringUtils.isEmpty(deviceSn)){
 | 
												
													
														
															|  | 
 |  |             filter.append(" and i.device_sn='"+deviceSn+"' ");
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if(!StringUtils.isEmpty(idcard)){
 | 
												
													
														
															|  | 
 |  |             filter.append(" and i.idcard='"+idcard+"' ");
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //体征数据创建时间
 | 
												
													
														
															|  | 
 |  |         if(!StringUtils.isEmpty(date)){
 | 
												
													
														
															|  | 
 |  |             Date startTimeTemp  =  DateUtil.simpleDateParse(date);
 | 
												
													
														
															|  | 
 |  |             Calendar calendar = new GregorianCalendar();
 | 
												
													
														
															|  | 
 |  |             calendar.setTime(startTimeTemp);
 | 
												
													
														
															|  | 
 |  |             calendar.set(Calendar.HOUR,23);
 | 
												
													
														
															|  | 
 |  |             calendar.set(Calendar.MINUTE,59);
 | 
												
													
														
															|  | 
 |  |             calendar.set(Calendar.SECOND,59);
 | 
												
													
														
															|  | 
 |  |             calendar.set(Calendar.MILLISECOND,999);
 | 
												
													
														
															|  | 
 |  |             Date endTimeTemp = calendar.getTime();
 | 
												
													
														
															|  | 
 |  |             filter.append(" and i.czrq>='" + DateUtil.simpleDateTimeFormat(startTimeTemp)+"'");
 | 
												
													
														
															|  | 
 |  |             filter.append(" and i.czrq<='" + DateUtil.simpleDateTimeFormat(endTimeTemp)+"'");
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //指标类型
 | 
												
													
														
															|  | 
 |  |         if(!StringUtils.isEmpty(indexType)){
 | 
												
													
														
															|  | 
 |  |             filter.append(" and i.type="+indexType);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //体征数据
 | 
												
													
														
															|  | 
 |  |         if(indexTypeMin1!=null){
 | 
												
													
														
															|  | 
 |  |             filter.append(" and value1>="+indexTypeMin1);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if(indexTypeMax1!=null){
 | 
												
													
														
															|  | 
 |  |             filter.append(" and value1<="+indexTypeMax1);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if(indexTypeMin2!=null){
 | 
												
													
														
															|  | 
 |  |             filter.append(" and value2>="+indexTypeMin2);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if(indexTypeMax2!=null){
 | 
												
													
														
															|  | 
 |  |             filter.append(" and value2<="+indexTypeMax2);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         //数据权限过滤
 | 
												
													
														
															|  | 
 |  |         List<String> orgList = orgUserService.getUserOrgById(userAgent.getUID());
 | 
												
													
														
															|  | 
 |  |         if(!orgList.contains(userAgent.commonHospital)){
 | 
												
													
														
															|  | 
 |  |             sql += " and s.hospital in ("+orgUserService.getUserOrg(orgList)+") ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         String f = filter.toString();
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql+f+" order by i.czrq desc "+" limit "+(page-1)*pageSize+","+pageSize);
 | 
												
													
														
															|  | 
 |  |         if(resultList.size()<=0){
 | 
												
													
														
															|  | 
 |  |             return new PageImpl<DeviceHealthIndexVO>(new ArrayList<>(), pageRequest, 0);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         long count = 0;
 | 
												
													
														
															|  | 
 |  |         String regex = "(\\w{3})(\\w+)(\\w{3})";
 | 
												
													
														
															|  | 
 |  |         List<DeviceHealthIndexVO> listTemp = new ArrayList<>();
 | 
												
													
														
															|  | 
 |  |         if(resultList !=null && resultList.size()>0){
 | 
												
													
														
															|  | 
 |  | //            count = getCount(filter.toString());
 | 
												
													
														
															|  | 
 |  |             count = jdbcTemplate.queryForObject(countSql+filter.toString(),Long.class);
 | 
												
													
														
															|  | 
 |  |             for (Map<String, Object> info : resultList){
 | 
												
													
														
															|  | 
 |  |                 DeviceHealthIndexVO bean = new DeviceHealthIndexVO();
 | 
												
													
														
															|  | 
 |  |                 bean.setId(Long.getLong(info.get("id")+""));
 | 
												
													
														
															|  | 
 |  |                 bean.setCzrq(info.get("czrq")!=null?(Date)info.get("czrq"):null);
 | 
												
													
														
															|  | 
 |  |                 bean.setDel(info.get("del")!=null?info.get("del")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setDeviceSn(info.get("device_sn")!=null?info.get("device_sn")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setIdcard(info.get("idcard")!=null?info.get("idcard")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setIntervene(info.get("intervene")!=null?info.get("intervene")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setRecordDate(info.get("record_date")!=null?(Date)info.get("record_date"):null);
 | 
												
													
														
															|  | 
 |  |                 bean.setSortDate(info.get("sort_date")!=null?(Date)info.get("sort_date"):null);
 | 
												
													
														
															|  | 
 |  |                 bean.setStatus(info.get("status")!=null?(Integer)info.get("status"):null);
 | 
												
													
														
															|  | 
 |  |                 bean.setType(info.get("type")!=null?(Integer)info.get("type"):0);
 | 
												
													
														
															|  | 
 |  |                 bean.setUser(info.get("user")!=null?info.get("user")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setUserName(info.get("userName")!=null?info.get("userName")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setValue1(info.get("value1")!=null?info.get("value1")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setValue2(info.get("value2")!=null?info.get("value2")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setValue3(info.get("value3")!=null?info.get("value3")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setValue4(info.get("value4")!=null?info.get("value4")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setValue5(info.get("value5")!=null?info.get("value5")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setValue6(info.get("value6")!=null?info.get("value6")+"":null);
 | 
												
													
														
															|  | 
 |  |                 bean.setValue7(info.get("value7")!=null?info.get("value7")+"":null);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |                 if(StringUtils.isNotBlank(bean.getIdcard())){
 | 
												
													
														
															|  | 
 |  |                     bean.setIdcard(bean.getIdcard().replaceAll(regex, "$1****$3"));
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |                 bean.setHealthStandard(gethealthStandard(bean.getType(),bean.getUser()).toString());
 | 
												
													
														
															|  | 
 |  |                 listTemp.add(bean);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return new PageImpl<DeviceHealthIndexVO>(listTemp,pageRequest,count);
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     private WlyyHealthStandardVO findStandard(String patient,Integer type){
 | 
												
													
														
															|  | 
 |  |         String sql = "select id,type,patient,min_value_1 minValue1,doctor,czrq,max_value_1 maxValue1,min_value_2 minValue2,max_value_2 maxValue2" +
 | 
												
													
														
															|  | 
 |  |                 " from wlyy.wlyy_patient_health_standard where patient = '"+patient+"' and type = "+type;
 | 
												
													
														
															|  | 
 |  |         List<WlyyHealthStandardVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(WlyyHealthStandardVO.class));
 | 
												
													
														
															|  | 
 |  |         if(list.size()>0){
 | 
												
													
														
															|  | 
 |  |             return list.get(0);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return null;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public JSONObject gethealthStandard(Integer type, String patientCode) {
 | 
												
													
														
															|  | 
 |  |         //血糖校验
 | 
												
													
														
															|  | 
 |  |         JSONObject json = new JSONObject();
 | 
												
													
														
															|  | 
 |  |         if (type == 1) {
 | 
												
													
														
															|  | 
 |  |             // 血糖记录,查询患者血糖预警值
 | 
												
													
														
															|  | 
 |  |             WlyyHealthStandardVO standard = findStandard(patientCode, 1);
 | 
												
													
														
															|  | 
 |  |             Double maxValueBefore = HEALTH_STANDARD_ST_MAX_BEFORE;
 | 
												
													
														
															|  | 
 |  |             Double minValueBefore = HEALTH_STANDARD_ST_MIN_BEFORE;
 | 
												
													
														
															|  | 
 |  |             Double maxValueAfter = HEALTH_STANDARD_ST_MAX_AFTER;
 | 
												
													
														
															|  | 
 |  |             Double minValueAfter = HEALTH_STANDARD_ST_MIN_AFTER;
 | 
												
													
														
															|  | 
 |  |             if (standard != null) {
 | 
												
													
														
															|  | 
 |  |                 if (standard.getMaxValue1() > 0) {
 | 
												
													
														
															|  | 
 |  |                     maxValueBefore = standard.getMaxValue1();
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |                 if (standard.getMinValue1() > 0) {
 | 
												
													
														
															|  | 
 |  |                     minValueBefore = standard.getMinValue1();
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |                 if (standard.getMaxValue2() > 0) {
 | 
												
													
														
															|  | 
 |  |                     maxValueAfter = standard.getMaxValue2();
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |                 if (standard.getMinValue2() > 0) {
 | 
												
													
														
															|  | 
 |  |                     minValueAfter = standard.getMinValue2();
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             json.put("maxValueAfter", maxValueAfter);
 | 
												
													
														
															|  | 
 |  |             json.put("maxValueBefore", maxValueBefore);
 | 
												
													
														
															|  | 
 |  |             json.put("minValueBefore", minValueBefore);
 | 
												
													
														
															|  | 
 |  |             json.put("minValueAfter", minValueAfter);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //血压校验
 | 
												
													
														
															|  | 
 |  |         else if (type == 2) {
 | 
												
													
														
															|  | 
 |  |             // 血压记录,查询患者血压预警值
 | 
												
													
														
															|  | 
 |  |             WlyyHealthStandardVO standard = findStandard(patientCode, 2);
 | 
												
													
														
															|  | 
 |  |             Double maxValueSSY = HEALTH_STANDARD_SSY_MAX;
 | 
												
													
														
															|  | 
 |  |             Double minValueSSY = HEALTH_STANDARD_SSY_MIN;
 | 
												
													
														
															|  | 
 |  |             Double maxValueSZY = HEALTH_STANDARD_SZY_MAX;
 | 
												
													
														
															|  | 
 |  |             Double minValueSZY = HEALTH_STANDARD_SZY_MIN;
 | 
												
													
														
															|  | 
 |  |             if (standard != null) {
 | 
												
													
														
															|  | 
 |  |                 if (standard.getMaxValue1() > 0) {
 | 
												
													
														
															|  | 
 |  |                     maxValueSSY = standard.getMaxValue1();
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |                 if (standard.getMinValue1() > 0) {
 | 
												
													
														
															|  | 
 |  |                     minValueSSY = standard.getMinValue1();
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |                 if (standard.getMaxValue2() > 0) {
 | 
												
													
														
															|  | 
 |  |                     maxValueSZY = standard.getMaxValue2();
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |                 if (standard.getMinValue2() > 0) {
 | 
												
													
														
															|  | 
 |  |                     minValueSZY = standard.getMinValue2();
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             json.put("minValueSZY", minValueSZY);
 | 
												
													
														
															|  | 
 |  |             json.put("maxValueSZY", maxValueSZY);
 | 
												
													
														
															|  | 
 |  |             json.put("minValueSSY", minValueSSY);
 | 
												
													
														
															|  | 
 |  |             json.put("maxValueSSY", maxValueSSY);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return json;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public List<WlyyPatientDeviceVO> searchListNew(String deviceName,
 | 
												
													
														
															|  | 
 |  |                                                    String categoryCode,
 | 
												
													
														
															|  | 
 |  |                                                    String deviceSn,
 | 
												
													
														
															|  | 
 |  |                                                    String userName,
 | 
												
													
														
															|  | 
 |  |                                                    String doctorName,
 | 
												
													
														
															|  | 
 |  |                                                    String hospitalName,
 | 
												
													
														
															|  | 
 |  |                                                    String hospitalCode,
 | 
												
													
														
															|  | 
 |  |                                                    Integer page, Integer pageSize) throws Exception{
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         List<WlyyPatientDeviceVO> list = new ArrayList<>();
 | 
												
													
														
															|  | 
 |  |         String sql = "SELECT d.id as id,d.device_id as deviceId,d.user as user,p.name as userName,d.category_code as categoryCode,d.device_name as deviceName," +
 | 
												
													
														
															|  | 
 |  |                 "d.device_sn as deviceSn,d.sim as sim,d.user_type as userType,p.mobile," +
 | 
												
													
														
															|  | 
 |  |                 "CONCAT(LEFT (p.idcard,6),'**********',RIGHT (p.idcard,2)) userIdcard,d.czrq as czrq,s.doctor,s.doctor_name doctorName " +
 | 
												
													
														
															|  | 
 |  |                 "FROM wlyy.wlyy_patient_device d left join wlyy.wlyy_sign_family s on d.`user` = s. patient and s.`status`>0,wlyy.wlyy_patient p " +
 | 
												
													
														
															|  | 
 |  |                 "WHERE d.`user`=p.CODE ";
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isNotBlank(userName)){
 | 
												
													
														
															|  | 
 |  |             sql = sql + "AND p.name like '%"+userName+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isNotBlank(deviceSn)){
 | 
												
													
														
															|  | 
 |  |             sql = sql + "AND d.device_sn like '%"+deviceSn+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isNotBlank(categoryCode)){
 | 
												
													
														
															|  | 
 |  |             sql = sql + "AND d.category_code like '%"+categoryCode+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isNotBlank(deviceName)){
 | 
												
													
														
															|  | 
 |  |             sql = sql + "AND d.device_name like '%"+deviceName+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         //数据权限过滤
 | 
												
													
														
															|  | 
 |  |         List<String> orgList = orgUserService.getUserOrgById(userAgent.getUID());
 | 
												
													
														
															|  | 
 |  |         if(!orgList.contains(userAgent.commonHospital)){
 | 
												
													
														
															|  | 
 |  |             sql += " and s.hospital in ("+orgUserService.getUserOrg(orgList)+") ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         sql = sql+"ORDER BY d.id DESC limit " + (page-1)*pageSize+", "+pageSize;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         list =  jdbcTemplate.query(sql,new BeanPropertyRowMapper(WlyyPatientDeviceVO.class));
 | 
												
													
														
															|  | 
 |  |         return list ;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public Long getCountSearchListNew(String deviceName, String categoryCode, String deviceSn, String userName, String doctorName, String hospitalName,String hospitalCode) {
 | 
												
													
														
															|  | 
 |  |         String sql  = "SELECT count(d.id) " +
 | 
												
													
														
															|  | 
 |  |                 "FROM " +
 | 
												
													
														
															|  | 
 |  |                 " wlyy.wlyy_patient_device d left join wlyy.wlyy_sign_family s on d.`user` = s. patient and s.`status`>0," +
 | 
												
													
														
															|  | 
 |  |                 " wlyy.wlyy_patient p " +
 | 
												
													
														
															|  | 
 |  |                 "WHERE " +
 | 
												
													
														
															|  | 
 |  |                 " d.`user`=p.CODE ";
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isNotBlank(userName)){
 | 
												
													
														
															|  | 
 |  |             sql = sql + "AND p.name like '%"+doctorName+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isNotBlank(deviceSn)){
 | 
												
													
														
															|  | 
 |  |             sql = sql + "AND d.device_sn like '%"+deviceSn+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isNotBlank(categoryCode)){
 | 
												
													
														
															|  | 
 |  |             sql = sql + "AND d.category_code like '%"+categoryCode+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isNotBlank(deviceName)){
 | 
												
													
														
															|  | 
 |  |             sql = sql + "AND d.device_name like '%"+deviceName+"%' ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         //数据权限过滤
 | 
												
													
														
															|  | 
 |  |         List<String> orgList = orgUserService.getUserOrgById(userAgent.getUID());
 | 
												
													
														
															|  | 
 |  |         if(!orgList.contains(userAgent.commonHospital)){
 | 
												
													
														
															|  | 
 |  |             sql += " and s.hospital in ("+orgUserService.getUserOrg(orgList)+") ";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         Long total = jdbcTemplate.queryForObject(sql, Long.class);
 | 
												
													
														
															|  | 
 |  |         return total ;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | }
 |