소스 검색

代码修改

liubing 3 년 전
부모
커밋
dee354410d

+ 2 - 1
common/common-entity/sql记录

@ -1387,4 +1387,5 @@ CREATE TABLE `base_yxdevice_index` (
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='云芯拐杖设备上传记录';
-- 20210828
ALTER table base_patient_sos_contacts add column update_info VARCHAR(50) default null comment '同步信息 1成功,-1失败'

+ 10 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/care/contacts/PatientSosContactsDO.java

@ -21,9 +21,10 @@ public class PatientSosContactsDO extends IdEntity {
    private String sosPhone; //联系电话
    private Integer relation; //与联系人关系 同base_patient_family_member
    private Date updateTime; //修改日期
    private Integer successFlag;//联系人是否同步成功 -2删除失败 -1添加失败 0待同步 1添加成功 2删除成功
    private Integer successFlag;//联系人是否同步成功 -1失败 0待同步 1成功
    private Integer del;
    private Integer phoneSeqid;// 联系人序号 1 或2
    private String updateInfo;//同步信息 -1失败 1成功
    private String relationName;
@ -100,4 +101,12 @@ public class PatientSosContactsDO extends IdEntity {
    public void setPhoneSeqid(Integer phoneSeqid) {
        this.phoneSeqid = phoneSeqid;
    }
    public String getUpdateInfo() {
        return updateInfo;
    }
    public void setUpdateInfo(String updateInfo) {
        this.updateInfo = updateInfo;
    }
}

+ 6 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/contacts/PatientSosContactsDao.java

@ -2,6 +2,8 @@ package com.yihu.jw.care.dao.contacts;
import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
@ -17,4 +19,8 @@ public interface PatientSosContactsDao extends PagingAndSortingRepository<Patien
    List<PatientSosContactsDO> findByPatientOrderByUpdateTimeDesc(String patient);
    PatientSosContactsDO findByPatientAndSosPhone(String patient,String sosPhone);
    @Modifying
    @Query(" update PatientSosContactsDO a set a.successFlag = 0,a.updateInfo=null where a.patient=?1")
    void updateByPatient(String patient);
}

+ 4 - 2
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/PadDeviceController.java

@ -313,11 +313,13 @@ public class PadDeviceController extends BaseController {
    public String addPatientSosContacts(@ApiParam(name = "patient", value = "patient", defaultValue = "patient")
                                           @RequestParam(value = "patient", required = true) String patient,
                                        @ApiParam(name = "jsonStr", value = "patient", defaultValue = "patient")
                                        @RequestParam(value = "jsonStr", required = true) String jsonStr){
                                        @RequestParam(value = "jsonStr", required = true) String jsonStr,
                                        @ApiParam(name = "isUpdate", value = "是否有更新联系人 1是 0否", defaultValue = "isUpdate")
                                        @RequestParam(value = "isUpdate", defaultValue = "1") Integer isUpdate){
        try {
            JSONObject result = contactsService.addPatientSosContacts(patient,jsonStr);
            JSONObject result = contactsService.addPatientSosContacts(patient,jsonStr,isUpdate);
            if (ResponseContant.success == result.getInteger(ResponseContant.resultFlag)){
                return success("添加成功");
            }

+ 37 - 30
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/contacts/ContactsService.java

@ -276,6 +276,7 @@ public class ContactsService {
                contactsDO = new PatientSosContactsDO();
                contactsDO.setPhoneSeqid(1==seqid?2:1);
            }
            contactsDO.setUpdateInfo(null);
            contactsDO.setDel(1);
            contactsDO.setPatient(patient);
            contactsDO.setSosName(name);
@ -293,41 +294,47 @@ public class ContactsService {
    /**
     *设备绑定添加居民紧急联系人
     */
    public JSONObject addPatientSosContacts(String patient,String jsonStr) throws Exception {
    @Transactional(rollbackFor = Exception.class)
    public JSONObject addPatientSosContacts(String patient,String jsonStr,Integer isUpdate) throws Exception {
        JSONObject result = new JSONObject();
        List<PatientSosContactsDO> list = sosContactsDao.findByPatientOrderByUpdateTimeDesc(patient);
        JSONArray jsonArray = JSONArray.parseArray(jsonStr);
        for (int i=0;i<jsonArray.size();i++){
            list = sosContactsDao.findByPatientAndDel(patient,1);
            JSONObject obj = jsonArray.getJSONObject(i);
            String num = obj.getString("num");
            String name = obj.getString("name");
            String relation = obj.getString("relation");
            Integer seqid=0;
            if (list.size()>=2){
                List<String> sosContacts =list.stream().map(PatientSosContactsDO::getSosPhone).collect(Collectors.toList());
                if (!sosContacts.contains(num)){
                    result.put(ResponseContant.resultFlag,ResponseContant.fail);
                    result.put(ResponseContant.resultMsg,"该用户紧急联系人已上限");
                    return result;
        if (0==isUpdate){
            sosContactsDao.updateByPatient("updateByPatient");
        }else {
            for (int i=0;i<jsonArray.size();i++){
                list = sosContactsDao.findByPatientAndDel(patient,1);
                JSONObject obj = jsonArray.getJSONObject(i);
                String num = obj.getString("num");
                String name = obj.getString("name");
                String relation = obj.getString("relation");
                Integer seqid=0;
                if (list.size()>=2){
                    List<String> sosContacts =list.stream().map(PatientSosContactsDO::getSosPhone).collect(Collectors.toList());
                    if (!sosContacts.contains(num)){
                        result.put(ResponseContant.resultFlag,ResponseContant.fail);
                        result.put(ResponseContant.resultMsg,"该用户紧急联系人已上限");
                        return result;
                    }
                }
            }
            if (list.size()>0){
                seqid = list.get(0).getPhoneSeqid();
            }
            PatientSosContactsDO contactsDO = sosContactsDao.findByPatientAndSosPhone(patient,num);
            if(null==contactsDO){
                contactsDO = new PatientSosContactsDO();
                contactsDO.setPhoneSeqid(1==seqid?2:1);
            }
            contactsDO.setDel(1);
            contactsDO.setPatient(patient);
            contactsDO.setSosName(name);
            contactsDO.setSosPhone(num);
            contactsDO.setRelation(Integer.parseInt(relation));
            contactsDO.setSuccessFlag(0);
            sosContactsDao.save(contactsDO);
                if (list.size()>0){
                    seqid = list.get(0).getPhoneSeqid();
                }
                PatientSosContactsDO contactsDO = sosContactsDao.findByPatientAndSosPhone(patient,num);
                if(null==contactsDO){
                    contactsDO = new PatientSosContactsDO();
                    contactsDO.setPhoneSeqid(1==seqid?2:1);
                }
                contactsDO.setUpdateInfo(null);
                contactsDO.setDel(1);
                contactsDO.setPatient(patient);
                contactsDO.setSosName(name);
                contactsDO.setSosPhone(num);
                contactsDO.setRelation(Integer.parseInt(relation));
                contactsDO.setSuccessFlag(0);
                sosContactsDao.save(contactsDO);
            }
        }
        result.put(ResponseContant.resultFlag,ResponseContant.success);
        result.put(ResponseContant.resultMsg,"修改成功");

+ 43 - 16
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/job/device/PatientSosContactsJob.java

@ -35,44 +35,71 @@ public class PatientSosContactsJob implements Job {
    private NetworkCardService cardService;
    @Autowired
    private PatientDeviceService deviceService;
    @Autowired
    private YunXunDeviceService yunXunDeviceService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("PATIENT_SOS_CONTACTS_JOB start");
        String sql = " select pd.device_sn,wd.sim,sc.* from  wlyy_patient_device pd inner join wlyy_devices wd " +
        String sql = " select pd.device_sn,pd.category_code,wd.sim,sc.* 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 and pd.category_code in('7','4') " +
                "INNER JOIN base_patient_sos_contacts sc on sc.patient = pd.user and sc.del=1 and sc.success_flag=0 group by wd.sim";
        List<Map<String,Object>> sims = jdbcTemplate.queryForList(sql);
        List<PatientSosContactsDO> modify = new ArrayList<>();
        for(Map<String,Object> tmp:sims){//添加白名单,添加设备联系人
            String sim = tmp.get("sim").toString() ;
            String patient = tmp.get("patient").toString() ;
            String device_sn = tmp.get("device_sn").toString() ;
            String category_code = tmp.get("category_code").toString() ;
            String id = tmp.get("id").toString() ;
            String sos_name = tmp.get("sos_name").toString() ;
            String sos_phone = tmp.get("sos_phone").toString() ;
            String phone_seqid = tmp.get("phone_seqid").toString() ;
            try {
                PatientSosContactsDO sosContactsDO = sosContactsDao.findOne(Long.parseLong(id));
                if(null!=sosContactsDO){
                    JSONObject response = cardService.setPatientContacts(sim, null, null, "1", sos_phone, null);//移动白名单
                    //0成功 12102名单重复
                    if (response.getInteger("status")==0||response.getInteger("status")==12108){
                        sosContactsDO.setSuccessFlag(1);
                    }else {
                        sosContactsDO.setSuccessFlag(-1);
                        modify.add(sosContactsDO);
                    if (StringUtils.isNotBlank(sim)){
                        JSONObject response = cardService.setPatientContacts(sim, null, null, "1", sos_phone, null);//移动白名单
                        //0成功 12102名单重复
                        if (response.getInteger("status")==0||response.getInteger("status")==12108){
                            sosContactsDO.setSuccessFlag(1);
                            sosContactsDO.setUpdateInfo(" ,{"+sosContactsDO.getUpdateInfo()+"sim:"+sim+":"+1+"}");
                        }else {
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setUpdateInfo(" ,{"+sosContactsDO.getUpdateInfo()+"sim:"+sim+":"+-1+"}");
                        }
                    }
                    //设备修改
                    JSONObject response2 =  deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
                    System.out.println(response2.toString());
                    if (response2.getBoolean("success")){
                        if (1==sosContactsDO.getSuccessFlag()){
                            sosContactsDO.setSuccessFlag(1);
                    if ("4".equals(category_code)||"7".equals(category_code)){
                        JSONObject response2 =  deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
                        System.out.println(response2.toString());
                        if (response2.getBoolean("success")){
                            if (1==sosContactsDO.getSuccessFlag()){
                                sosContactsDO.setSuccessFlag(1);
                            }
                            sosContactsDO.setUpdateInfo(" ,{"+sosContactsDO.getUpdateInfo()+"deviceSn:"+device_sn+":"+1+"}");
                        }else {
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setUpdateInfo(" ,{"+sosContactsDO.getUpdateInfo()+"deviceSn:"+device_sn+":"+-1+"}");
                        }
                    }else if ("16".equals(category_code)){
                        sql =" select num from base_patient_sos_contacts where patient='"+patient+"' ";
                        List<String> nums = jdbcTemplate.queryForList(sql,String.class);
                        String phone1 = null;
                        String phone2 = null;
                        String phone3 = null;
                        for (int i=0;i<nums.size();i++){
                            if(i==0){
                                phone1 = nums.get(i);
                            }
                            if(i==2){
                                phone2 = nums.get(i);
                            }
                        }
                        sosContactsDO.setSuccessFlag(-1);
                    }else {
                        sosContactsDO.setSuccessFlag(-1);
                        yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
                        sosContactsDO.setUpdateInfo(" ,{"+sosContactsDO.getUpdateInfo()+"deviceSn:"+device_sn+":unknow}");
                    }
                    modify.add(sosContactsDO);

+ 71 - 0
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/job/device/YunXunDeviceService.java

@ -0,0 +1,71 @@
package com.yihu.jw.care.job.device;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Created with IntelliJ IDEA.
 * 云芯拐杖设备对接
 * @Author: yeshijie
 * @Date: 2021/8/27
 * @Description:
 */
@Service
public class YunXunDeviceService {
    private static Logger logger = LoggerFactory.getLogger(YunXunDeviceService.class);
    @Autowired
    private HttpClientUtil httpClientUtil;
    /**
     * 设置紧急联系人
     * @param sn
     * @param phone1
     * @param phone2
     * @param phone3
     */
    public void setSos(String sn,String phone1,String phone2,String phone3){
        if(StringUtil.isBlank(phone1)){
            return;
        }
        //[IC*334588000000156*0027*SOS,00000000000,00000000000]
        String order = "SOS,"+phone1;
        if(!StringUtil.isBlank(phone2)){
            order += ","+phone2;
        }
        if(!StringUtil.isBlank(phone3)){
            order += ","+phone3;
        }
        String instruction = "[IC*"+sn+"*"+hex10To16(order.length())+"]";
        sendInstruction(sn,instruction);
    }
    /**
     * 发送指令接口
     * @param instruction
     */
    public void sendInstruction(String sn,String instruction){
        try {
            String url = "http://117.24.13.79:43210/yunxin/sendMessage?deviceSN="+sn+"&message="+instruction;
            String response = httpClientUtil.get(url,"UTF-8");
            logger.info("sendInstruction="+response);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 保留4位 十进制转十六进制
     * @param ten
     * @return
     */
    public String hex10To16(int ten){
        return String.format("%04x",ten);
    }
}