|  | @ -10,13 +10,17 @@ import com.yihu.jw.care.dao.security.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.sign.ServicePackageService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.util.MessageUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.servicePackage.ServicePackageRecordDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.device.PatientDevice;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.securitymonitoring.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.message.dao.SystemMessageDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.ResponseContant;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.base.BaseRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.entity.EntityUtils;
 | 
	
	
		
			
				|  | @ -62,6 +66,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |     private BaseDoctorDao baseDoctorDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SecurityMonitoringConclusionDao securityMonitoringConclusionDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorHospitalDao baseDoctorHospitalDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -114,14 +120,17 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //签约防走失服务包
 | 
	
		
			
				|  |  | //        List<ServicePackageRecordDO> signRecords = servicePackageService.servicePackageByPatient(orderDO.getPatient(),"3");
 | 
	
		
			
				|  |  | //        if (signRecords.size()==0) {
 | 
	
		
			
				|  |  | //            result.put("resultFlag", 0);
 | 
	
		
			
				|  |  | //            String failMsg = "当前服务对象未签约防走失服务,请签约后再发起预警!";
 | 
	
		
			
				|  |  | //            result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  | //            logger.error(failMsg);
 | 
	
		
			
				|  |  | //            return result;
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  |         String sql ="SELECT i.code from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i  \n" +
 | 
	
		
			
				|  |  |                 "where  sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id   and i.del = 1 and sr.`status`=1 \n" +
 | 
	
		
			
				|  |  |                 "and  sr.patient  = '"+orderDO.getPatient()+"' and i.code=8 ";
 | 
	
		
			
				|  |  |        List<String> items = jdbcTemplate.queryForList(sql,String.class);
 | 
	
		
			
				|  |  |         if (items.size()==0) {
 | 
	
		
			
				|  |  |             result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |             String failMsg = "当前服务对象未签约防走失服务,请签约后再发起预警!";
 | 
	
		
			
				|  |  |             result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //已取消的订单也可以申请
 | 
	
		
			
				|  |  |         boolean bool = securityMonitoringOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
 | 
	
	
		
			
				|  | @ -202,21 +211,24 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONArray getSecurityOrderList(String doctor, String patient, String status, Integer page, Integer pageSize){
 | 
	
		
			
				|  |  |     public JSONArray getSecurityOrderList(String doctor,String serverDoctor, String patient, String status, Integer page, Integer pageSize){
 | 
	
		
			
				|  |  |         String sql = " select p.id patientCode,p.name,p.sex,p.idcard,ord.id orderId,ord.number,ord.serve_desc,ord.create_time,ord.`status`,ord.doctor," +
 | 
	
		
			
				|  |  |                 "ord.doctor_name,ord.patient_phone,ord.conclusion_status from base_security_monitoring_order ord INNER JOIN base_patient p on p.id = ord.patient " +
 | 
	
		
			
				|  |  |                 "where 1=1 ";
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(doctor)){
 | 
	
		
			
				|  |  |             sql +=" and ord.doctor = '"+doctor+"' ";
 | 
	
		
			
				|  |  |         List<BaseDoctorHospitalDO> hospitalDOs = baseDoctorHospitalDao.findByDoctorCode(doctor);
 | 
	
		
			
				|  |  |         if (hospitalDOs.size()>0){
 | 
	
		
			
				|  |  |             sql += "and ord.hospital = '"+hospitalDOs.get(0).getOrgCode()+"' ";
 | 
	
		
			
				|  |  |         }else  {
 | 
	
		
			
				|  |  |             return new JSONArray();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(serverDoctor)){
 | 
	
		
			
				|  |  |             sql +=" and ord.doctor = '"+serverDoctor+"' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             sql+=" and ord.patient_name= like '%"+patient+"%' ";
 | 
	
		
			
				|  |  |             sql+=" and ord.patient_name= like '%"+patient+"%' or p.idcard='"+patient+"'  ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(status)){
 | 
	
		
			
				|  |  |             sql+=" and ord.status='"+Integer.parseInt(status)+"' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isBlank(status)||status.equals("1")){//状态为空或待处置时 查询该医生签约团队居民的预警
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql+=" order by ord.create_time desc limit " + (page*pageSize) + "," + pageSize;
 | 
	
		
			
				|  |  |         List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
	
		
			
				|  | @ -235,7 +247,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |             tmp.put("createTime", DateUtil.dateToStr(date,"yyyy-MM-dd hh:mm:ss"));
 | 
	
		
			
				|  |  |             tmp.put("status",one.get("status"));
 | 
	
		
			
				|  |  |             tmp.put("doctor",one.get("doctor"));
 | 
	
		
			
				|  |  |             tmp.put("doctorName",one.get("doctor_ame"));
 | 
	
		
			
				|  |  |             tmp.put("doctorName",one.get("doctor_name"));
 | 
	
		
			
				|  |  |             tmp.put("patientPhone",one.get("patient_phone"));
 | 
	
		
			
				|  |  |             tmp.put("conclusionStatus",one.get("conclusion_status"));
 | 
	
		
			
				|  |  |             Integer conclusionStatus = Integer.valueOf(one.get("conclusion_status")==null?"0":(one.get("conclusion_status")+""));
 | 
	
	
		
			
				|  | @ -272,6 +284,22 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> getSecurityOrderUnCompleteList(String doctor){
 | 
	
		
			
				|  |  |         List<BaseDoctorHospitalDO> hospitalDOs = baseDoctorHospitalDao.findByDoctorCode(doctor);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> result = new ArrayList<>();
 | 
	
		
			
				|  |  |         if (hospitalDOs.size()>0){
 | 
	
		
			
				|  |  |             for (BaseDoctorHospitalDO obj:hospitalDOs){
 | 
	
		
			
				|  |  |                 String sql = " select p.id patientCode,p.name,p.sex,p.idcard,ord.id orderId,ord.number,ord.serve_desc,DATE_FORMAT(ord.create_time,'%Y-%m-%d %H:%i:%S') create_time,ord.`status`,ord.doctor," +
 | 
	
		
			
				|  |  |                         "ord.doctor_name,ord.patient_phone,ord.conclusion_status from base_security_monitoring_order ord INNER JOIN base_patient p on p.id = ord.patient " +
 | 
	
		
			
				|  |  |                         "where ord.status <>-1 and ord.status<> 7  ";
 | 
	
		
			
				|  |  |                 sql += "and ord.hospital = '"+obj.getOrgCode()+"' ";
 | 
	
		
			
				|  |  |                 sql +=" order by ord.create_time asc ";
 | 
	
		
			
				|  |  |                 List<Map<String,Object>> tmp= jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 result.addAll(tmp);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 系统更新医生上门服务工单状态
 | 
	
	
		
			
				|  | @ -834,6 +862,27 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         return doorServiceOrder;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> getSecurityServerDoctor(String patient){
 | 
	
		
			
				|  |  |         //获取患者签约防走失服务的团队
 | 
	
		
			
				|  |  |         String sql="SELECT DISTINCT i.team_code from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i  \n" +
 | 
	
		
			
				|  |  |                 "where  sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id   and i.del = 1 and sr.`status`=1 \n" +
 | 
	
		
			
				|  |  |                 "and  sr.patient  = '"+patient+"' and i.code=8";
 | 
	
		
			
				|  |  |         List<String> teams = jdbcTemplate.queryForList(sql,String.class);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> result = new ArrayList<>();
 | 
	
		
			
				|  |  |         if (teams.size()==0){
 | 
	
		
			
				|  |  |             return new ArrayList<>();
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             for (String team:teams){
 | 
	
		
			
				|  |  |                 sql = "select DISTINCT doc.id doctor,CONCAT(doc.`name`,\n" +
 | 
	
		
			
				|  |  |                         "CASE WHEN doc.`level`=1 THEN '(社区医生)' ELSE '(助老员)' END) as name,doc.photo,doc.mobile from base_team_member mem " +
 | 
	
		
			
				|  |  |                         "INNER JOIN base_doctor doc on mem.doctor_code = doc.id and mem.del=1 and mem.team_code='"+team+"'";
 | 
	
		
			
				|  |  |                 List<Map<String,Object>>tmp = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 result.addAll(tmp);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private String getRandomIntStr(){
 | 
	
		
			
				|  |  |         Random rand = new Random();
 | 
	
		
			
				|  |  |         int i = rand.nextInt(); //int范围类的随机数
 |