|  | @ -3,8 +3,10 @@ package com.yihu.jw.care.service.contacts;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.contacts.BasePatientContactsOrgDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.contacts.PatientSosContactsDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.device.PatientDeviceDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.family.PatientFamilyMemberDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.device.NetworkCardService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.device.PatientDeviceService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.family.PatientFamilyMemberService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.sign.ServicePackageService;
 | 
	
	
		
			
				|  | @ -12,18 +14,24 @@ import com.yihu.jw.entity.base.org.BaseOrgDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientFamilyMemberDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.contacts.BasePatientContactsOrgDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.device.DevicePatientDevice;
 | 
	
		
			
				|  |  | import com.yihu.jw.org.dao.BaseOrgDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.ResponseContant;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.LatitudeUtils;
 | 
	
		
			
				|  |  | import org.apache.commons.collections.map.HashedMap;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.assertj.core.util.DateUtil;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.security.core.parameters.P;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.xml.crypto.Data;
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -55,6 +63,10 @@ public class ContactsService {
 | 
	
		
			
				|  |  |     private BaseOrgDao baseOrgDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ServicePackageService servicePackageService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientSosContactsDao sosContactsDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private NetworkCardService networkCardService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查找居民联系服务站
 | 
	
	
		
			
				|  | @ -126,7 +138,7 @@ public class ContactsService {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 设置一键联系人
 | 
	
		
			
				|  |  |      * 设置一键联系人  未使用
 | 
	
		
			
				|  |  |      * @param fid
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      */
 | 
	
	
		
			
				|  | @ -202,4 +214,69 @@ public class ContactsService {
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取居民紧急联系人
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<PatientSosContactsDO> getPatientSosContacts(String patient){
 | 
	
		
			
				|  |  |         List<PatientSosContactsDO> sosContactsDOS = sosContactsDao.findByPatientAndDel(patient,1);
 | 
	
		
			
				|  |  |         for (PatientSosContactsDO tmp:sosContactsDOS){
 | 
	
		
			
				|  |  |             tmp.setRelationName(PatientFamilyMemberService.relations.get(tmp.getRelation()));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return sosContactsDOS;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *设置居民紧急联系人
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject updatePatientSosContacts(String patient,String num,Integer operType,String name,String relation){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         List<PatientSosContactsDO> list = sosContactsDao.findByPatientOrderByUpdateTimeDesc(patient);
 | 
	
		
			
				|  |  |         if (4==operType){//一个月只能删除一次
 | 
	
		
			
				|  |  |             if (list.size()>0){
 | 
	
		
			
				|  |  |                 Date updateTime = list.get(0).getUpdateTime();
 | 
	
		
			
				|  |  |                 Long timeDiffer = DateUtil.timeDifference(new Date(),updateTime);
 | 
	
		
			
				|  |  |                 if (timeDiffer<=(1000L*3600*24*30)){
 | 
	
		
			
				|  |  |                    Long day = timeDiffer/(1000L*3600*24)+1;
 | 
	
		
			
				|  |  |                    result.put(ResponseContant.resultFlag,ResponseContant.fail);
 | 
	
		
			
				|  |  |                    result.put(ResponseContant.resultMsg,"您本月删除紧急联系人次数已使用,请"+day+"天后再试");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 String[] numTmp = num.split("_");
 | 
	
		
			
				|  |  |                 String sql = " select wd.sim from  wlyy_patient_device pd inner join wlyy_devices wd  " +
 | 
	
		
			
				|  |  |                         "on pd.device_sn = wd.device_code and pd.del=0 and wd.sim is not null " +
 | 
	
		
			
				|  |  |                         "where pd.user='"+patient+"' ";
 | 
	
		
			
				|  |  |                 List<String> sims = jdbcTemplate.queryForList(sql,String.class);
 | 
	
		
			
				|  |  |                 for (String sim:sims){
 | 
	
		
			
				|  |  |                     try {
 | 
	
		
			
				|  |  |                         JSONArray respons = networkCardService.getPatientContacts(sim,null,null,null);
 | 
	
		
			
				|  |  |                     }catch (Exception e){
 | 
	
		
			
				|  |  |                         e.printStackTrace();
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 //接口实时删除
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag,ResponseContant.fail);
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg,"改用户已无紧急联系人");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (1==operType){//新增联系人
 | 
	
		
			
				|  |  |             if (list.size()<2){
 | 
	
		
			
				|  |  |                 PatientSosContactsDO contactsDO = new PatientSosContactsDO();
 | 
	
		
			
				|  |  |                 contactsDO.setPatient(patient);
 | 
	
		
			
				|  |  |                 contactsDO.setSosName(name);
 | 
	
		
			
				|  |  |                 contactsDO.setSosPhone(num);
 | 
	
		
			
				|  |  |                 contactsDO.setRelation(relation);
 | 
	
		
			
				|  |  |                 contactsDO.setSuccess_flag(0);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String sql = " select wd.sim from  wlyy_patient_device pd inner join wlyy_devices wd  " +
 | 
	
		
			
				|  |  |                     "on pd.device_sn = wd.device_code and pd.del=0 and wd.sim is not null " +
 | 
	
		
			
				|  |  |                     "where pd.user='"+patient+"' ";
 | 
	
		
			
				|  |  |             List<String> sims = jdbcTemplate.queryForList(sql,String.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |