Browse Source

添加企业微信群发接口。

lighter 3 years ago
parent
commit
7a61c3fb8c

+ 12 - 0
src/main/java/thyyxxk/webserver/controller/wxapi/SendWxInfoController.java

@@ -36,4 +36,16 @@ public class SendWxInfoController {
         return "success";
     }
 
+    @PassToken
+    @GetMapping("/createGroupChat")
+    public JSONObject createGroupChat(@RequestParam("name") String name) {
+        return service.createGroupChat(name);
+    }
+
+    @PassToken
+    @GetMapping("/sendGroupMsg")
+    public JSONObject sendGroupMsg(@RequestParam("chatid") String chatid,
+                                   @RequestParam("content") String content) {
+        return service.sendGroupMsg(chatid, content);
+    }
 }

+ 30 - 0
src/main/java/thyyxxk/webserver/dao/his/scheduled/DailyPatientCountDao.java

@@ -0,0 +1,30 @@
+package thyyxxk.webserver.dao.his.scheduled;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import thyyxxk.webserver.entity.scheduled.DailyPatientCount;
+
+@Mapper
+public interface DailyPatientCountDao {
+    @Select("select inHospCount=(select count(1) from zy_actpatient with(nolock)), " +
+            "admissCount=(select count(1) from zy_actpatient with(nolock) where datediff(day,admiss_date,getdate())=1), " +
+            "dismissCount=((select count(1) from yz_act_order with(nolock) where status_flag > '2' and " +
+            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code in ('06026','06053','05973')) " +
+            "+ (select count(1) from yz_inact_order with(nolock) where status_flag > '2' and " +
+            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code in ('06026','06053','05973'))), " +
+            "heavyCount=(select count(1) from yz_act_order with(nolock) where status_flag > '2' and " +
+            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code='05888'), " +
+            "dangerCount=(select count(1) from yz_act_order with(nolock) where status_flag > '2' and " +
+            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code='05887'), " +
+            "operationCount=(select count(1) from op_record with(nolock) where datediff(day,op_datetime,getdate())=1), " +
+            "clinicCount=(select count(1) from mzy_reqrec with(nolock) where datediff(day,visit_date,getdate())=1), " +
+            "rescueCount=((select count(1) from yz_act_order with(nolock) where status_flag > '2' and " +
+            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code in " +
+            "('05202','04311','08893','08894','01535','01537','05243','02628','05240','05242','05241','04313','01446','06383', " +
+            "'08897','08898','05011','01445','04312','08895','08896')) " +
+            "+ (select count(1) from yz_inact_order with(nolock) where status_flag > '2' and " +
+            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code in " +
+            "('05202','04311','08893','08894','01535','01537','05243','02628','05240','05242','05241','04313','01446','06383', " +
+            "'08897','08898','05011','01445','04312','08895','08896')))")
+    DailyPatientCount selectDailyCount();
+}

+ 23 - 0
src/main/java/thyyxxk/webserver/entity/scheduled/DailyPatientCount.java

@@ -0,0 +1,23 @@
+package thyyxxk.webserver.entity.scheduled;
+
+import lombok.Data;
+import thyyxxk.webserver.utils.DateUtil;
+
+@Data
+public class DailyPatientCount {
+    private Integer inHospCount;
+    private Integer admissCount;
+    private Integer dismissCount;
+    private Integer heavyCount;
+    private Integer dangerCount;
+    private Integer operationCount;
+    private Integer clinicCount;
+    private Integer rescueCount;
+
+    public String getDescription() {
+        return String.format("%s总值班情况汇报如下:住院总人数:%d,入院人数:%d,出院人数:%d,病重人数:%d,病危人数:%d," +
+                "手术台次:%d,挂号人数:%d,抢救人次:%d。",
+                DateUtil.getYesterday(), inHospCount, admissCount, dismissCount, heavyCount, dangerCount,
+                operationCount, clinicCount, rescueCount);
+    }
+}

+ 33 - 0
src/main/java/thyyxxk/webserver/scheduled/DailyPatientCountTask.java

@@ -0,0 +1,33 @@
+package thyyxxk.webserver.scheduled;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import thyyxxk.webserver.dao.his.scheduled.DailyPatientCountDao;
+import thyyxxk.webserver.entity.scheduled.DailyPatientCount;
+import thyyxxk.webserver.service.wxapi.SendWxInfoService;
+
+@Component
+public class DailyPatientCountTask {
+    private final DailyPatientCountDao dao;
+    private final SendWxInfoService service;
+    @Value("${execute-scheduled}")
+    private Boolean executeScheduled;
+
+    @Autowired
+    public DailyPatientCountTask(DailyPatientCountDao dao, SendWxInfoService service) {
+        this.dao = dao;
+        this.service = service;
+    }
+
+    @Scheduled(cron = "0 0 6 * * ?")
+    public void notifyDailyCount() {
+        if (executeScheduled) {
+            DailyPatientCount count = dao.selectDailyCount();
+            if (null != count) {
+                service.sendGroupMsg("740552821090355200", count.getDescription());
+            }
+        }
+    }
+}

+ 4 - 4
src/main/java/thyyxxk/webserver/scheduled/FeiYongJieShouChongSuan.java

@@ -27,8 +27,8 @@ public class FeiYongJieShouChongSuan {
     private final PatientService patientService;
     private final PublicServer publicServer;
 
-    @Value("${fei-yong-jie-shou}")
-    private Boolean feiYongJieShou;
+    @Value("${execute-scheduled}")
+    private Boolean executeScheduled;
 
     public FeiYongJieShouChongSuan(JieShouFeiYongDao dao, PatientService patientService, PublicServer publicServer) {
         this.dao = dao;
@@ -39,7 +39,7 @@ public class FeiYongJieShouChongSuan {
     @Scheduled(cron = "0 30 23 * * ?")
     public void jieShouFeiYong() {
         // 每天 23 点 执行
-        if (feiYongJieShou) {
+        if (executeScheduled) {
             List<Patient> xuYaoJieShouDeFeiYong = dao.xuYaoJieShouFeiYong();
             for (Patient item : xuYaoJieShouDeFeiYong) {
                 try {
@@ -57,7 +57,7 @@ public class FeiYongJieShouChongSuan {
 
     @Scheduled(cron = "59 59 23 * * ?")
     public void chongZhiYaoDanHao() {
-        if (feiYongJieShou) {
+        if (executeScheduled) {
             dao.chongZhiYaoDanHao();
         }
     }

+ 24 - 24
src/main/java/thyyxxk/webserver/scheduled/FetchClockinDataTask.java

@@ -3,8 +3,8 @@ package thyyxxk.webserver.scheduled;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.logging.log4j.util.PropertiesUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.web.client.RestTemplate;
@@ -25,6 +25,8 @@ import java.util.List;
 public class FetchClockinDataTask {
     private final ClockinDao dao;
     private static final String GET_CLOCKIN_URL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata?access_token=ACCESS_TOKEN";
+    @Value("${execute-scheduled}")
+    private Boolean executeScheduled;
 
     @Autowired
     public FetchClockinDataTask(ClockinDao dao) {
@@ -33,31 +35,29 @@ public class FetchClockinDataTask {
 
     @Scheduled(cron = "0 0 8 ? * *")
     public void queryClockInData() {
-        String osName = PropertiesUtil.getSystemProperties().getProperty("os.name");
-        if ("Windows 10".equals(osName)) {
-            return;
-        }
-        final String yesterday = getYesterdayDate();
-        Clockin param = new Clockin();
-        param.setTimes(yesterday, yesterday);
-        try {
-            List<String> codeRsList = dao.getAllEmployeeExceptItDept();
-            for (int i = 0; i < codeRsList.size(); i += 30) {
-                int index = Math.min(i + 30, codeRsList.size());
-                List<String> useridlist = codeRsList.subList(i, index);
-                param.setUseridlist(useridlist);
-                log.info("getting... " + yesterday + " - " + useridlist.toString());
+        if ((executeScheduled)) {
+            final String yesterday = getYesterdayDate();
+            Clockin param = new Clockin();
+            param.setTimes(yesterday, yesterday);
+            try {
+                List<String> codeRsList = dao.getAllEmployeeExceptItDept();
+                for (int i = 0; i < codeRsList.size(); i += 30) {
+                    int index = Math.min(i + 30, codeRsList.size());
+                    List<String> useridlist = codeRsList.subList(i, index);
+                    param.setUseridlist(useridlist);
+                    log.info("getting... " + yesterday + " - " + useridlist.toString());
+                    getSignInfo(param);
+                }
+                codeRsList.clear();
+                codeRsList = dao.getAllEmployeeInItDept();
+                param.setFlag(true);
+                param.setUseridlist(codeRsList);
+                log.info("getting... " + yesterday + " - " + codeRsList.toString());
                 getSignInfo(param);
+                log.info("over.");
+            } catch (Exception e) {
+                log.error("获取clock-in数据出错", e);
             }
-            codeRsList.clear();
-            codeRsList = dao.getAllEmployeeInItDept();
-            param.setFlag(true);
-            param.setUseridlist(codeRsList);
-            log.info("getting... " + yesterday + " - " + codeRsList.toString());
-            getSignInfo(param);
-            log.info("over.");
-        } catch (Exception e) {
-            log.error("获取clock-in数据出错", e);
         }
     }
 

+ 28 - 28
src/main/java/thyyxxk/webserver/scheduled/QueryNotifiedPatients.java

@@ -2,8 +2,8 @@ package thyyxxk.webserver.scheduled;
 
 import com.alibaba.fastjson.JSON;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.logging.log4j.util.PropertiesUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import thyyxxk.webserver.dao.his.triage.TriageDao;
@@ -21,6 +21,8 @@ import java.util.concurrent.ConcurrentMap;
 @Component
 public class QueryNotifiedPatients {
     private final TriageDao dao;
+    @Value("${execute-scheduled}")
+    private Boolean executeScheduled;
 
     @Autowired
     public QueryNotifiedPatients(TriageDao dao) {
@@ -29,34 +31,32 @@ public class QueryNotifiedPatients {
 
     @Scheduled(fixedRate = 6000)
     public void query() {
-        String osName = PropertiesUtil.getSystemProperties().getProperty("os.name");
-        if ("Windows 10".equals(osName)) {
-            return;
-        }
-        ConcurrentMap<Integer, String> map = PatientSidContainer.getInstance().getSidPatientsMap();
-        if (map.isEmpty()) return;
-        List<PureCodeName> list = dao.getNotifiedSerialNos(map);
-        if (list == null || list.isEmpty()) return;
-        for (PureCodeName item : list) {
-            MzfzPatientOrder patient = dao.getPatientTriageInfo(Integer.parseInt(item.getCode()));
-            MessageForPush param = new MessageForPush();
-            param.setAction(1);
-            param.setSerialNo(patient.getSerialNo());
-            param.setFzNo(patient.getFzNo());
-            param.setName(patient.getName());
-            param.setDeptName(patient.getDeptName());
-            param.setRoomNo(patient.getRoomNo());
-            param.setRoomCode(patient.getRoomCode());
-            final String msg = JSON.toJSONString(param);
-            String text = String.format("请%s号%s,到%s%s号诊室就诊。", param.getFzNo(), param.getName(),
-                    param.getDeptName(), param.getRoomNo());
-            VoiceUtil.textToSpeech(text, String.valueOf(param.getSerialNo()));
-            String userCode = map.get(Integer.parseInt(item.getCode()));
-            int code1 = WebSocketServer.sendFloorTriageMessage(userCode, msg);
-            int code2 = WebSocketServer.sendRoomTriageMessage(item.getName(), msg);
+        if (executeScheduled) {
+            ConcurrentMap<Integer, String> map = PatientSidContainer.getInstance().getSidPatientsMap();
+            if (map.isEmpty()) return;
+            List<PureCodeName> list = dao.getNotifiedSerialNos(map);
+            if (list == null || list.isEmpty()) return;
+            for (PureCodeName item : list) {
+                MzfzPatientOrder patient = dao.getPatientTriageInfo(Integer.parseInt(item.getCode()));
+                MessageForPush param = new MessageForPush();
+                param.setAction(1);
+                param.setSerialNo(patient.getSerialNo());
+                param.setFzNo(patient.getFzNo());
+                param.setName(patient.getName());
+                param.setDeptName(patient.getDeptName());
+                param.setRoomNo(patient.getRoomNo());
+                param.setRoomCode(patient.getRoomCode());
+                final String msg = JSON.toJSONString(param);
+                String text = String.format("请%s号%s,到%s%s号诊室就诊。", param.getFzNo(), param.getName(),
+                        param.getDeptName(), param.getRoomNo());
+                VoiceUtil.textToSpeech(text, String.valueOf(param.getSerialNo()));
+                String userCode = map.get(Integer.parseInt(item.getCode()));
+                int code1 = WebSocketServer.sendFloorTriageMessage(userCode, msg);
+                int code2 = WebSocketServer.sendRoomTriageMessage(item.getName(), msg);
 
-            if (code1 != 200 || code2 != 200) {
-                PatientSidContainer.getInstance().delete(param.getSerialNo());
+                if (code1 != 200 || code2 != 200) {
+                    PatientSidContainer.getInstance().delete(param.getSerialNo());
+                }
             }
         }
     }

+ 5 - 5
src/main/java/thyyxxk/webserver/scheduled/ResetPatientNum.java

@@ -1,7 +1,7 @@
 package thyyxxk.webserver.scheduled;
 
-import org.apache.logging.log4j.util.PropertiesUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import thyyxxk.webserver.dao.his.triage.TriageDao;
@@ -9,6 +9,8 @@ import thyyxxk.webserver.dao.his.triage.TriageDao;
 @Component
 public class ResetPatientNum {
     private final TriageDao dao;
+    @Value("${execute-scheduled}")
+    private Boolean executeScheduled;
 
     @Autowired
     public ResetPatientNum(TriageDao dao) {
@@ -17,11 +19,9 @@ public class ResetPatientNum {
 
     @Scheduled(cron = "0 0 0 * * ?")
     public void resetPatientNum() {
-        String osName = PropertiesUtil.getSystemProperties().getProperty("os.name");
-        if ("Windows 10".equals(osName)) {
-            return;
+        if (executeScheduled) {
+            dao.resetPatientNum();
         }
-        dao.resetPatientNum();
     }
 
 }

+ 40 - 0
src/main/java/thyyxxk/webserver/service/wxapi/SendWxInfoService.java

@@ -1,9 +1,12 @@
 package thyyxxk.webserver.service.wxapi;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.utils.SnowFlakeId;
 import thyyxxk.webserver.utils.TokenUtil;
 
 @Service
@@ -11,6 +14,8 @@ import thyyxxk.webserver.utils.TokenUtil;
 public class SendWxInfoService {
 
     private static final String SEND_MSG_URL = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN";
+    private static final String CREATE_GROUP_URL = "https://qyapi.weixin.qq.com/cgi-bin/appchat/create?access_token=ACCESS_TOKEN";
+    private static final String SEND_GROUP_MSG = "https://qyapi.weixin.qq.com/cgi-bin/appchat/send?access_token=ACCESS_TOKEN";
     private static final int AGENT_ID = 1000041;
     private static final int SAFE_MODE = 0;
 
@@ -33,4 +38,39 @@ public class SendWxInfoService {
         log.info("推送企业信息消息结果 >>> {}", result);
         return result;
     }
+
+    public JSONObject createGroupChat(String name) {
+        String url = CREATE_GROUP_URL.replace("ACCESS_TOKEN", TokenUtil.getWeComSendMsgToken());
+        JSONObject msgobj = new JSONObject();
+        msgobj.put("name", name);
+        msgobj.put("owner", "1038");
+        JSONArray userlist = new JSONArray();
+        userlist.add("1038");
+        userlist.add("2801");
+        msgobj.put("userlist", userlist);
+        msgobj.put("chatid", SnowFlakeId.instance().nextId());
+        log.info("创建企业微信群聊 >>> {}", msgobj);
+        RestTemplate restTemplate = new RestTemplate();
+        String response = restTemplate.postForObject(url, msgobj, String.class);
+        JSONObject result = JSONObject.parseObject(response);
+        log.info("创建企业微信群聊结果 >>> {}", result);
+        return result;
+    }
+
+    public JSONObject sendGroupMsg(String chatid, String content) {
+        String url = SEND_GROUP_MSG.replace("ACCESS_TOKEN", TokenUtil.getWeComSendMsgToken());
+        JSONObject msgobj = new JSONObject();
+        msgobj.put("chatid", chatid);
+        msgobj.put("msgtype", "text");
+        JSONObject text = new JSONObject();
+        text.put("content", content);
+        msgobj.put("text", text);
+        msgobj.put("safe", 0);
+        log.info("发送企业微信群聊消息 >>> {}", msgobj);
+        RestTemplate restTemplate = new RestTemplate();
+        String response = restTemplate.postForObject(url, msgobj, String.class);
+        JSONObject result = JSONObject.parseObject(response);
+        log.info("发送企业微信群聊消息结果 >>> {}", result);
+        return result;
+    }
 }

+ 9 - 0
src/main/java/thyyxxk/webserver/utils/DateUtil.java

@@ -106,6 +106,15 @@ public class DateUtil {
         return cal.getTime();
     }
 
+    public static String getYesterday() {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(new Date());
+        cal.add(Calendar.DATE, -1);
+        Date yesterday = cal.getTime();
+        DateFormat df = new SimpleDateFormat("yyyy年MM月dd日");
+        return df.format(yesterday);
+    }
+
     public static Integer calculateAge(Date birthDate) {
         if (null == birthDate) {
             return null;

+ 5 - 6
src/main/java/thyyxxk/webserver/utils/Test.java

@@ -7,12 +7,11 @@
 //
 //public class Test {
 //    public static void main(String[] args) throws Exception {
-//        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-//        Date begntime = df.parse("2021-10-31 23:59:59");
 //        Calendar cal = Calendar.getInstance();
-//        cal.setTime(begntime);
-//        cal.add(Calendar.SECOND, 1);
-//        Date endtime = cal.getTime();
-//        System.out.println(df.format(endtime));
+//        cal.setTime(new Date());
+//        cal.add(Calendar.DATE, -1);
+//        Date yesterday = cal.getTime();
+//        DateFormat df = new SimpleDateFormat("yyyy年MM月dd日");
+//        System.out.println(df.format(yesterday));
 //    }
 //}

+ 1 - 1
src/main/resources/application-prod.yml

@@ -59,4 +59,4 @@ si-tj-url: http://jkglcsx.server.zhongmeihealth.com/openInter
 si-access-key: 04eMGRg7beAO6vqwrZiLacV8Uy3jNn7QGDUcBO
 si-secret-key: SK3Oip3a2R3NLz2xm58Mpmi69oFu96KrdKNRKglN
 
-fei-yong-jie-shou: true
+execute-scheduled: true

+ 2 - 2
src/main/resources/application.yml

@@ -8,7 +8,7 @@ spring:
     cache: false
   datasource:
     dynamic:
-      primary: dev
+      primary: his
       strict: false
       datasource:
         his:
@@ -71,7 +71,7 @@ si-tj-url: http://jkglcsx.server.zhongmeihealth.com/openInter
 si-access-key: 04eMGRg7beAO6vqwrZiLacV8Uy3jNn7QGDUcBO
 si-secret-key: SK3Oip3a2R3NLz2xm58Mpmi69oFu96KrdKNRKglN
 
-fei-yong-jie-shou: false
+execute-scheduled: false
 
 #logging:
 #  level: