Jelajahi Sumber

优化新冠疫苗预约;显示疫苗余量。

lighter 4 tahun lalu
induk
melakukan
170f65cc99

+ 5 - 5
src/main/java/thyyxxk/wxservice_server/controller/CovidVaccinateAppointmentController.java

@@ -28,16 +28,16 @@ public class CovidVaccinateAppointmentController {
         return service.selectVaccinates();
     }
 
-    @GetMapping("/getVaccinateFactories")
-    public ResultVo<ZdCovidVaccinate> getVaccinateFactories(@RequestParam("id") Integer id) {
-        return service.getVaccinateFactories(id);
-    }
-
     @GetMapping("/getPatientInfoAndJobCategories")
     public ResultVo<CovidVaccinate> getPatientInfoAndJobCategories(@RequestParam("patientId") String patientId) {
         return service.getPatientInfoAndJobCategories(patientId);
     }
 
+    @GetMapping("/getNextSevenDaysSources")
+    public ResultVo<int[]> getNextSevenDaysSources(int code) {
+        return service.getNextSevenDaysSources(code);
+    }
+
     @PostMapping("/submitVaccinateAppointment")
     public synchronized ResultVo<String> submitVaccinateAppointment(@Validated @RequestBody CovidVaccinate param) {
         return service.submitVaccinateAppointment(param);

+ 15 - 3
src/main/java/thyyxxk/wxservice_server/dao/CovidVaccinateAppointmentDao.java

@@ -15,7 +15,12 @@ import java.util.List;
 @Mapper
 public interface CovidVaccinateAppointmentDao {
 
-    @Select("select * from t_zd_covid_vaccinate where enable_flag=1")
+    @Select("select name as vaccinateFactory, " +
+            "code as vaccinateCode, " +
+            "vaccinateName=(select name from t_zd_covid_vaccinate where id=vaccinate_id), " +
+            "bookTip=(select book_tip from t_zd_covid_vaccinate where id=vaccinate_id) " +
+            "from t_covid_vaccinate_factory " +
+            "where enable_flag=1")
     List<ZdCovidVaccinate> selectVaccinates();
 
     @Select("select * from t_zd_covid_vaccinate where id=#{id}")
@@ -47,9 +52,16 @@ public interface CovidVaccinateAppointmentDao {
                                @Param("executeDate") Date executeDate);
 
     @Select("select value from t_covid_vaccinate_threshold_new where date=#{date} and code=#{code}")
-    Integer selectThresholdByDateAndCode(@Param("date") Date date, @Param("code") Integer code);
+    Integer selectThresholdByDateAndCode(@Param("date") String date, @Param("code") Integer code);
 
     @Select("select count(1) from t_covid_vaccinate_appointment where execute_date=#{executeDate} and " +
             "isnull(del_flag,0)!=1 and vaccinate_code=#{code}")
-    int selectTotalCountByDateAndCode(@Param("executeDate") Date executeDate, @Param("code") Integer code);
+    Integer selectTotalCountByDateAndCode(@Param("executeDate") String executeDate, @Param("code") Integer code);
+
+    @Select("select value from t_covid_vaccinate_threshold_new where date=#{date} and code=#{code}")
+    Integer selectThresholdByDateAndCode2(@Param("date") Date date, @Param("code") Integer code);
+
+    @Select("select count(1) from t_covid_vaccinate_appointment where execute_date=#{executeDate} and " +
+            "isnull(del_flag,0)!=1 and vaccinate_code=#{code}")
+    Integer selectTotalCountByDateAndCode2(@Param("executeDate") Date executeDate, @Param("code") Integer code);
 }

+ 4 - 4
src/main/java/thyyxxk/wxservice_server/entity/covidvaccinate/ZdCovidVaccinate.java

@@ -10,9 +10,9 @@ import java.util.List;
  **/
 @Data
 public class ZdCovidVaccinate {
-    private Integer id;
-    private String name;
+    private Integer vaccinateCode;
+    private String vaccinateName;
     private String bookTip;
-    private ZdVaccinateFactory factory;
-    private List<ZdVaccinateFactory> factories;
+    private String vaccinateFactory;
+    private Integer minLeftNum;
 }

+ 51 - 32
src/main/java/thyyxxk/wxservice_server/service/CovidVaccinateAppointmentService.java

@@ -10,12 +10,9 @@ import thyyxxk.wxservice_server.dao.CovidVaccinateAppointmentDao;
 import thyyxxk.wxservice_server.entity.ResultVo;
 import thyyxxk.wxservice_server.entity.covidvaccinate.CovidVaccinate;
 import thyyxxk.wxservice_server.entity.covidvaccinate.ZdCovidVaccinate;
-import thyyxxk.wxservice_server.entity.covidvaccinate.ZdVaccinateFactory;
-import thyyxxk.wxservice_server.entity.wxapi.PushMessageParam;
 import thyyxxk.wxservice_server.utils.DateUtil;
 import thyyxxk.wxservice_server.utils.IdCardUtil;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
-import thyyxxk.wxservice_server.utils.StringUtil;
 
 import java.util.Date;
 import java.util.List;
@@ -36,17 +33,24 @@ public class CovidVaccinateAppointmentService {
     }
 
     public ResultVo<List<ZdCovidVaccinate>> selectVaccinates() {
-        return ResultVoUtil.success(dao.selectVaccinates());
-    }
-
-    public ResultVo<ZdCovidVaccinate> getVaccinateFactories(Integer id) {
-        ZdCovidVaccinate vaccinate = dao.selectVaccinatesById(id);
-        List<ZdVaccinateFactory> factories = dao.selectFactories(id);
-        vaccinate.setFactories(factories);
-        if (null != factories && factories.size() == 1) {
-            vaccinate.setFactory(factories.get(0));
+        List<ZdCovidVaccinate> list = dao.selectVaccinates();
+        if (null != list && list.size() > 0) {
+            String[] nextSevenDate = DateUtil.getDatesInOneWeek();
+            list.forEach(item -> {
+                for (String date : nextSevenDate) {
+                    Integer max = dao.selectThresholdByDateAndCode(date, item.getVaccinateCode());
+                    max = null == max ? 0 : max;
+                    Integer count = dao.selectTotalCountByDateAndCode(date, item.getVaccinateCode());
+                    count = null == count ? 0 : count;
+                    int offset = max - count;
+                    item.setMinLeftNum(offset);
+                    if (offset > 0) {
+                        break;
+                    }
+                }
+            });
         }
-        return ResultVoUtil.success(vaccinate);
+        return ResultVoUtil.success(list);
     }
 
     public ResultVo<CovidVaccinate> getPatientInfoAndJobCategories(String patientId) {
@@ -73,6 +77,20 @@ public class CovidVaccinateAppointmentService {
         return ResultVoUtil.success(info);
     }
 
+    public ResultVo<int[]> getNextSevenDaysSources(int code) {
+        int[] result = new int[7];
+        String[] nextSevenDate = DateUtil.getDatesInOneWeek();
+        for (int i = 0; i < nextSevenDate.length; i++) {
+            String date = nextSevenDate[i];
+            Integer max = dao.selectThresholdByDateAndCode(date, code);
+            max = null == max ? 0 : max;
+            Integer count = dao.selectTotalCountByDateAndCode(date, code);
+            count = null == count ? 0 : count;
+            result[i] = max - count;
+        }
+        return ResultVoUtil.success(result);
+    }
+
     public ResultVo<String> submitVaccinateAppointment(CovidVaccinate param) {
         param.setCreateDatetime(new Date());
         int age = IdCardUtil.calAgeBySocialNo(param.getSocialNo());
@@ -90,32 +108,33 @@ public class CovidVaccinateAppointmentService {
         if (dao.selectValidAppointment(param.getSocialNo(), param.getExecuteDate()) > 0) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您在【" + dateFormatted + "】已存在有效的预约,请勿重复预约。");
         }
-        Integer threshold = dao.selectThresholdByDateAndCode(param.getExecuteDate(), param.getVaccinateCode());
+        Integer threshold = dao.selectThresholdByDateAndCode2(param.getExecuteDate(), param.getVaccinateCode());
         if (null == threshold) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【" + dateFormatted + "】没有可预约的疫苗,请选择其他预约日期。");
         }
-        int count = dao.selectTotalCountByDateAndCode(param.getExecuteDate(), param.getVaccinateCode());
+        Integer count = dao.selectTotalCountByDateAndCode2(param.getExecuteDate(), param.getVaccinateCode());
+        count = null == count ? 0 : count;
         if (count >= threshold) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【" + dateFormatted + "】的预约名额已满,请选择其他预约日期。");
         }
         dao.insertNewAppointment(param);
-        if (StringUtil.notBlank(param.getPatientId())) {
-            dao.updatePhoneAndSocialNo(param.getPatientId(), param.getSocialNo(), param.getPhone());
-            String msgContent = "{\"touser\":\"\",\"data\":" +
-                    "{\"keyword2\":{\"color\":\"#173177\",\"value\":\"" + dateFormatted + "\"}," +
-                    "\"keyword1\":{\"color\":\"#173177\",\"value\":\"" + param.getName() + "\"}," +
-                    "\"keyword3\":{\"color\":\"#173177\",\"value\":\"" + (++count) + "\"}," +
-                    "\"remark\":{\"color\":\"#FF0000\",\"value\":\"感谢您的使用,祝您健康!\"}," +
-                    "\"first\":{\"color\":\"#FF0000\",\"value\":\"您已成功预约新冠疫苗接种服务。" +
-                    "请于【" + dateFormatted + "】凭本人身份证在【泰和医院门诊大楼五楼体检中心】接种新冠疫苗。\"}}," +
-                    "\"template_id\":\"zVSzbYLmdqq_h1IcTPSwi6X4qFm0j9aTVeLZPxR03Bs\"," +
-                    "\"url\":\"\"}";
-            PushMessageParam pojo = new PushMessageParam();
-            pojo.setCardNo(param.getPatientId());
-            pojo.setCardNoPatientId(true);
-            pojo.setMsgContext(JSONObject.parseObject(msgContent));
-            wxApiService.pushMessage(pojo);
-        }
+//        if (StringUtil.notBlank(param.getPatientId())) {
+//            dao.updatePhoneAndSocialNo(param.getPatientId(), param.getSocialNo(), param.getPhone());
+//            String msgContent = "{\"touser\":\"\",\"data\":" +
+//                    "{\"keyword2\":{\"color\":\"#173177\",\"value\":\"" + dateFormatted + "\"}," +
+//                    "\"keyword1\":{\"color\":\"#173177\",\"value\":\"" + param.getName() + "\"}," +
+//                    "\"keyword3\":{\"color\":\"#173177\",\"value\":\"" + (++count) + "\"}," +
+//                    "\"remark\":{\"color\":\"#FF0000\",\"value\":\"感谢您的使用,祝您健康!\"}," +
+//                    "\"first\":{\"color\":\"#FF0000\",\"value\":\"您已成功预约新冠疫苗接种服务。" +
+//                    "请于【" + dateFormatted + "】凭本人身份证在【泰和医院门诊大楼五楼体检中心】接种新冠疫苗。\"}}," +
+//                    "\"template_id\":\"zVSzbYLmdqq_h1IcTPSwi6X4qFm0j9aTVeLZPxR03Bs\"," +
+//                    "\"url\":\"\"}";
+//            PushMessageParam pojo = new PushMessageParam();
+//            pojo.setCardNo(param.getPatientId());
+//            pojo.setCardNoPatientId(true);
+//            pojo.setMsgContext(JSONObject.parseObject(msgContent));
+//            wxApiService.pushMessage(pojo);
+//        }
         log.info("预约新冠疫苗接种:{}", JSONObject.toJSONStringWithDateFormat(param, "yyyy-MM-dd HH:mm:ss"));
         return ResultVoUtil.success("您已成功预约新冠疫苗接种服务。请于【" + dateFormatted + "】" +
                 "凭本人身份证在【泰和医院门诊大楼五楼体检中心】接种新冠疫苗。");