From fd6dca0c559c08129b7e0abdf67093b1a728ffd3 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期五, 29 十一月 2024 17:21:00 +0800
Subject: [PATCH] 代码提交

---
 ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java |  226 +++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 164 insertions(+), 62 deletions(-)

diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
index f55613d..32064d9 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
@@ -12,11 +12,13 @@
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.enums.ServiceFromEnum;
 import com.ruoyi.common.utils.DtoConversionUtils;
+import com.ruoyi.common.utils.HttpUtil;
 import com.ruoyi.common.utils.RSAPublicKeyExample;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.http.HttpUtils;
 import com.smartor.common.SendService;
 import com.smartor.domain.*;
+import com.smartor.mapper.ServiceSubtaskMapper;
 import com.smartor.mapper.ServiceTaskMapper;
 import com.smartor.mapper.SysUserImportMapper;
 import com.smartor.service.*;
@@ -28,6 +30,8 @@
 import org.springframework.transaction.PlatformTransactionManager;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Type;
@@ -55,6 +59,9 @@
     private IServiceThirdDataService iServiceThirdDataService;
 
     @Autowired
+    private IServiceOutPathService iServiceOutPathService;
+
+    @Autowired
     private IServiceSubtaskAnswerService serviceSubtaskAnswerService;
 
     @Autowired
@@ -72,6 +79,9 @@
     @Value("${localIP}")
     private String localIP;
 
+    @Value("${xhsmsPath}")
+    private String xhsmsPath;
+
     @Value("${pub_key}")
     private String pub_key;
 
@@ -85,7 +95,7 @@
     private ServiceTaskMapper serviceTaskMapper;
 
     @Autowired
-    private SendService sendService;
+    private ServiceSubtaskMapper serviceSubtaskMapper;
 
     @Autowired
     private RedisCache redisCache;
@@ -277,85 +287,147 @@
                 ivrTaskcall.setSendstate(2L);
                 List<ServiceSubtask> selectServiceSubtaskList = iServiceSubtaskService.selectServiceSubtaskList(ivrTaskcall);
                 if (descByCode.equals("鐢佃瘽")) {
+                    String value = "";
                     for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) {
                         ServiceTask ivrTask = serviceTaskMapper.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
                         if (ivrTask.getSendState() != null && ivrTask.getSendState() == 3 || ivrTask.getSendState() != null && ivrTask.getSendState() == 4) {
                             //濡備綍浠诲姟琚�滄殏鍋溾�濇垨鈥滅粓姝⑩��
                             break;
                         }
-                        //鑾峰彇鍒皏alue鍊兼渶灏戠殑key
-                        String key = getKey();
-                        if (commonTaskcallMQ.getSendType().equals("2")) {
-                            //璇存槑鏄珛鍗冲彂閫�
-                            String value = redisCache.getCacheObject("cache-0");
-                            ServiceSubtaskVO serviceSubtask1 = new ServiceSubtaskVO();
-                            serviceSubtask1.setTaskid(commonTaskcallMQ.getTaskid());
-                            List<ServiceSubtask> selectServiceSubtaskList1 = iServiceSubtaskService.selectServiceSubtaskList(serviceSubtask1);
-                            for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) {
-                                if (StringUtils.isEmpty(value)) {
-                                    value = "," + serviceSubtask2.getId().toString() + ",";
-                                } else {
-                                    value = value + "," + serviceSubtask2.getId().toString() + ",";
-                                }
+                        boolean dateToday = isDateToday(serviceSubtask.getLongSendTime());
+                        //璇存槑鏄珛鍗冲彂閫�(鍏堟妸娑堟伅鏀惧埌cache-0涓紝   displayNo涓嶇煡閬撴�庝箞閰嶇疆)
+                        if (dateToday) {
+                            try {
+//                                ServiceSubtaskVO serviceSubtask1 = new ServiceSubtaskVO();
+//                                serviceSubtask1.setTaskid(ivrTask.getTaskid());
+//                                List<ServiceSubtask> selectServiceSubtaskList1 = iServiceSubtaskService.selectServiceSubtaskList(serviceSubtask1);
+//                                for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) {
+                                    if (StringUtils.isEmpty(value)) {
+                                        value = "," + serviceSubtask.getId().toString() + ",";
+                                    } else {
+                                        if (!value.contains("," + serviceSubtask.getId().toString()))
+                                            value = value + "," + serviceSubtask.getId().toString() + ",";
+                                    }
+//                                }
+                            } catch (Exception e) {
+                                String guid = UUID.randomUUID().toString();
+                                log.error("闀挎湡浠诲姟锛岀數璇濆彂閫佸け璐ュ師鍥狅細{},{}", e.getMessage(), guid);
+                                serviceSubtask.setResult("error");
+                                serviceSubtask.setRemark("绯荤粺閿欒");
+                                serviceSubtask.setSendstate(3L);
+                                serviceSubtask.setFinishtime(new Date());
+                                serviceSubtask.setGuid(guid);
+                                iServiceSubtaskService.updateServiceSubtask(serviceSubtask);
                             }
-                            redisCache.setCacheObject("cache-0", value);
-                        } else {
-                            //闈炵珛鍗冲彂閫�
-                            String value = redisCache.getCacheObject(key);
-                            ServiceSubtaskVO serviceSubtask1 = new ServiceSubtaskVO();
-                            serviceSubtask1.setTaskid(commonTaskcallMQ.getTaskid());
-                            List<ServiceSubtask> selectServiceSubtaskList1 = iServiceSubtaskService.selectServiceSubtaskList(serviceSubtask1);
-                            for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) {
-                                if (StringUtils.isEmpty(value)) {
-                                    value = "," + serviceSubtask2.getId().toString() + ",";
-                                } else {
-                                    value = value + "," + serviceSubtask2.getId().toString() + ",";
-                                }
-                            }
-                            redisCache.setCacheObject(key, value);
+
+                            //鍦ㄥ瓙浠诲姟琛ㄩ噷璁板綍涓�涓�
+                            String uuid = UUID.randomUUID().toString();
+                            serviceSubtask.setResult("success");
+                            serviceSubtask.setRemark("闀挎湡浠诲姟锛岀數璇濊繘鍏ラ槦鍒楁垚鍔�");
+                            serviceSubtask.setGuid(uuid);
+                            serviceSubtask.setSendstate(3L);
+                            serviceSubtask.setFinishtime(new Date());
+                            serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
+
+                            //浠诲姟鍙戦�佽褰�
+                            ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
+                            serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString());
+                            serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId());
+                            serviceSubtaskRecord.setUuid(uuid);
+                            serviceSubtaskRecord.setTasktype(serviceSubtask.getType());
+                            serviceSubtaskRecord.setPreachform("3");
+                            serviceSubtaskRecord.setStartTime(System.currentTimeMillis());
+                            serviceSubtaskRecord.setRemark("闀挎湡浠诲姟锛岀數璇濊繘鍏ラ槦鍒楁垚鍔�");
+                            serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord);
+
                         }
-
-                        //浠诲姟鍙戦�佽褰曪紙杩欎釜浠g爜搴旇鍐欏湪phoneTask涓紝鍏堝啓鍦ㄨ繖锛屽悗闈㈠啀鏀癸級
-                        ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
-                        serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString());
-                        serviceSubtaskRecord.setUuid(UUID.randomUUID().toString());
-                        serviceSubtaskRecord.setTasktype(serviceSubtask.getType());
-                        serviceSubtaskRecord.setPreachform("3");
-                        serviceSubtaskRecord.setStartTime(System.currentTimeMillis());
-                        serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord);
-
-//                        //閫氳繃澶氱嚎绋嬬殑鏂瑰紡鍘绘墦鐢佃瘽
+//                        //閫氳繃澶氱嚎绋嬬殑鏂瑰紡鍘绘墦鐢佃瘽锛堣繖涓槸涓婃捣鐨勬柟娉曪級
 //                        executorService.submit(new PhoneTask(serviceSubtask, ivrTaskTemplateVO1, redisCache, sendService, phonePath, robotPhoneUtils));
+                    }
+                    //灏嗚鎵ц鐨勬斁鍒扮紦瀛樹腑
+                    String cache0 = redisCache.getCacheObject("cache-0");
+                    if (StringUtils.isNotEmpty(cache0)) {
+                        redisCache.setCacheObject("cache-0", cache0 + value);
+                    } else if (StringUtils.isEmpty(cache0) && StringUtils.isNotEmpty(value)) {
+                        redisCache.setCacheObject("cache-0", value);
                     }
                 } else if (descByCode.equals("澶氬獟浣�")) {
                     //澶氬獟浣�
                 } else if (descByCode.equals("绾歌川")) {
                     //绾歌川
                 } else if (descByCode.equals("鐭俊")) {
-                    //鐭俊
-//                        http://localhost:8099/followvisit/particty?param1=3&param2=348
-                    //瀵箄rl涓袱涓弬鏁板姞瀵�
                     RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
                     String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key);
-
                     for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) {
-                        String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key);
-                        SendMagParam sendMagParam = new SendMagParam();
-                        sendMagParam.setType("4");
-                        sendMagParam.setPhone(serviceSubtask.getPhone());
-                        sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "&param2=" + patid + "&param5=false");
-                        Boolean aBoolean = sendService.sendMsg(sendMagParam);
+                        log.error("鐭俊闀挎湡浠诲姟鍙戦��---------杩涙潵浜嗗悧锛焮}", serviceSubtask);
+                        boolean dateToday = isDateToday(serviceSubtask.getLongSendTime());
+                        if (dateToday) {
+                            try {
+                                //鍏堝垽鏂偅鑰呮槸涓嶆槸杩樿鍙戦��
+                                PatArchive patArchive = patArchiveService.selectPatArchiveByPatid(serviceSubtask.getPatid());
+                                if (!Objects.isNull(patArchive) && patArchive.getNotrequiredFlag() == "1") {
+                                    //涓嶉渶瑕佸彂閫�
+                                    serviceSubtask.setResult("error");
+                                    serviceSubtask.setRemark(patArchive.getNotrequiredreason());
+                                    serviceSubtask.setSendstate(4L);
+                                    serviceSubtask.setFinishtime(new Date());
+                                    iServiceSubtaskService.insertServiceSubtask(serviceSubtask);
+                                    continue;
+                                }
+                                String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key);
+                                SendMagParam sendMagParam = new SendMagParam();
+                                sendMagParam.setType("4");
+                                ServiceOutPath serviceOutPath = new ServiceOutPath();
+                                serviceOutPath.setParam1(taskId);
+                                serviceOutPath.setParam2(patid);
+                                serviceOutPath.setParam3(ivrTask1.getTaskName());
+                                serviceOutPath.setCreateTime(new Date());
+                                iServiceOutPathService.insertServiceOutPath(serviceOutPath);
+                                String format = String.format("%03X", serviceOutPath.getId());
+                                serviceOutPath.setRadix(format);
+                                serviceOutPath.setUpdateTime(new Date());
+                                iServiceOutPathService.updateServiceOutPath(serviceOutPath);
+                                sendMagParam.setPhone(serviceSubtask.getPhone());
+                                sendMagParam.setUrl(ip + ":" + req_path + "/wt?p=" + format);
+                                sendMagParam.setContent("銆愭柊鍗庡尰闄€�戞偍濂斤紝閭�璇锋偍濉啓鍑洪櫌璋冩煡琛紝璇风偣鍑�" + sendMagParam.getUrl() + "濉啓銆傛劅璋㈡偍閰嶅悎锛�");
+                                Map<String, String> req = new HashMap<>();
+                                req.put("phone", sendMagParam.getPhone());
+                                req.put("content", sendMagParam.getContent());
+                                String isSuccess = HttpUtil.postJsonRequest(xhsmsPath, new Gson().toJson(req));
+                                //浠诲姟鍙戦�佽褰�
+                                ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
+                                serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString());
+                                serviceSubtaskRecord.setUuid(UUID.randomUUID().toString());
+                                serviceSubtaskRecord.setTasktype(serviceSubtask.getType());
+                                serviceSubtaskRecord.setPreachform("4");
+                                serviceSubtaskRecord.setStartTime(System.currentTimeMillis());
+                                serviceSubtaskRecord.setResult("success");
+                                if (StringUtils.isNotEmpty(isSuccess) && !isSuccess.equals("true"))
+                                    serviceSubtaskRecord.setResult("error");
+                                serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord);
 
-                        //浠诲姟鍙戦�佽褰�
-                        ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
-                        serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString());
-                        serviceSubtaskRecord.setUuid(UUID.randomUUID().toString());
-                        serviceSubtaskRecord.setTasktype(serviceSubtask.getType());
-                        serviceSubtaskRecord.setPreachform("4");
-                        serviceSubtaskRecord.setStartTime(System.currentTimeMillis());
-                        serviceSubtaskRecord.setResult(aBoolean == true ? "鎴愬姛" : "澶辫触");
-                        serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord);
-
+                                //鍙戦�佸畬鎴愬悗锛屼慨鏀圭姸鎬�
+                                serviceSubtask.setSendstate(3L);
+                                if (StringUtils.isNotEmpty(isSuccess) && !isSuccess.equals("true")) {
+                                    serviceSubtask.setResult("success");
+                                    serviceSubtask.setRemark("鐭俊鍙戦�佹垚鍔�");
+                                } else {
+                                    serviceSubtask.setResult("error");
+                                    serviceSubtask.setSendstate(5L);
+                                    serviceSubtask.setRemark("鐭俊鍙戦�佸け璐�");
+                                }
+                                iServiceSubtaskService.updateServiceSubtask(serviceSubtask);
+                            } catch (Exception e) {
+                                String guid = UUID.randomUUID().toString();
+                                log.error("闀挎湡浠诲姟锛岀煭淇″彂閫佸け璐ュ師鍥狅細{},{}", e.getMessage(), guid);
+                                serviceSubtask.setResult("error");
+                                serviceSubtask.setRemark("绯荤粺閿欒");
+                                serviceSubtask.setSendstate(5L);
+                                serviceSubtask.setFinishtime(new Date());
+                                serviceSubtask.setGuid(guid);
+                                iServiceSubtaskService.updateServiceSubtask(serviceSubtask);
+                            }
+                        }
                     }
                 } else if (descByCode.equals("鍏紬鍙�")) {
                     log.error("鍏紬鍙疯繘鏉ヤ簡鍚楋紵{}", descByCode);
@@ -402,12 +474,13 @@
                                     serviceSubtask.setResult("success");
                                 } else {
                                     serviceSubtask.setResult("error");
+                                    serviceSubtask.setSendstate(5L);
                                     serviceSubtask.setRemark(map.get("msg").toString());
                                 }
                                 iServiceSubtaskService.updateServiceSubtask(serviceSubtask);
                             } catch (Exception e) {
                                 String guid = UUID.randomUUID().toString();
-                                log.error("闀挎湡浠诲姟锛屽彂閫佸け璐ュ師鍥狅細{},{}", e.getMessage(), guid);
+                                log.error("闀挎湡浠诲姟锛屽叕浼楀彿鍙戦�佸け璐ュ師鍥狅細{},{}", e.getMessage(), guid);
                                 serviceSubtask.setResult("error");
                                 serviceSubtask.setRemark("绯荤粺閿欒");
                                 serviceSubtask.setSendstate(5L);
@@ -456,6 +529,32 @@
         Type resultType = new TypeToken<List<ThiedInhospInfo>>() {
         }.getType();
         List<ThiedInhospInfo> thiedInhospInfoList = gson.fromJson(resultArray, resultType);
+
+        // 鍒涘缓涓�涓柊鏂囦欢
+        String filename = null;
+        if (cry.equals("0")) filename = "鍏ラ櫌淇℃伅" + System.currentTimeMillis();
+        if (cry.equals("1")) filename = "鍑洪櫌淇℃伅" + System.currentTimeMillis();
+        File file = new File("D:\\public\\鍗庡崜闆嗘垚骞冲彴鏁版嵁\\" + filename);
+        if (!file.exists()) {
+            // 濡傛灉鏂囦欢涓嶅瓨鍦紝鍒欏垱寤烘柊鏂囦欢
+            try {
+                if (file.createNewFile()) {
+                    System.out.println("鎴愬姛鍒涘缓浜嗘柊鏂囦欢!");
+                } else {
+                    System.out.println("澶辫触锛佹枃浠舵棤娉曞垱寤猴紒");
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        // 灏嗘暟鎹啓鍏ュ埌鏂囦欢涓�
+        try {
+            FileWriter writer = new FileWriter(file);
+            writer.write(result);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
         if (CollectionUtils.isNotEmpty(thiedInhospInfoList)) {
             for (ThiedInhospInfo thiedInhospInfo : thiedInhospInfoList) {
                 //閫氳繃韬唤璇佸彿鏌ヨ璇ユ偅鑰呭湪鎮h�呰〃鏄惁瀛樺湪
@@ -565,7 +664,9 @@
                 inhosp.setPatno(patArchive.getPatientno());
                 inhosp.setSerialnum(patMedInhosp.getSerialnum());
                 List<PatMedInhosp> patMedInhosps = patMedInhospService.selectPatMedInhospList(inhosp);
+                log.error("鏄惁闇�瑕佹洿鏂帮細{}", patMedInhosps.size());
                 if (CollectionUtils.isNotEmpty(patMedInhosps)) {
+                    patMedInhosp.setInhospid(patMedInhosps.get(0).getInhospid());
                     patMedInhospService.updatePatMedInhosp(patMedInhosp);
                 } else {
                     patMedInhospService.insertPatMedInhosp(patMedInhosp);
@@ -615,6 +716,7 @@
 
         String result = HttpUtils.sendPost(thirdWXUrl, new Gson().toJson(xinHuaWXReq));
         JSONObject jsonObject = JSONObject.parseObject(result);
+        log.error("jsonObject鐨勬暟鎹负锛歿}", jsonObject.toString());
 //        String code = (String) jsonObject.get("code");
         return jsonObject.toString();
     }

--
Gitblit v1.9.3