lighter 3 years ago
parent
commit
76e9893c74

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>wxservice-server</artifactId>
-    <version>7.9</version>
+    <version>8.0</version>
     <name>wxservice-server</name>
     <description>server for wxservice-web</description>
 

+ 0 - 4
src/main/java/thyyxxk/wxservice_server/constant/Constants.java

@@ -15,10 +15,6 @@ public class Constants {
         public static final int ELEVEN = 11;
     }
 
-    public static class Sex {
-        public static final String MALE = "1";
-    }
-
     public static class MzClass {
         public static final String GYNAECOLOGY = "03";
     }

+ 16 - 0
src/main/java/thyyxxk/wxservice_server/constant/Gender.java

@@ -0,0 +1,16 @@
+package thyyxxk.wxservice_server.constant;
+
+public enum Gender {
+    MALE(1),
+    FEMALE(2);
+
+    private final int code;
+
+    Gender(int code) {
+        this.code = code;
+    }
+
+    public int getCode() {
+        return this.code;
+    }
+}

+ 3 - 3
src/main/java/thyyxxk/wxservice_server/dao/AppointmentDao.java

@@ -38,14 +38,14 @@ public interface AppointmentDao {
             "datediff(day, date, getdate()) <= 3 order by date desc")
     CovidQuestionnaire validCovidAssessment(@Param("patientId") String patientId);
 
-    @Select("select isnull(sex,9) as code,rtrim(social_no) as name from mz_patient_mi with(nolock) where patient_id=#{patientId}")
-    PureCodeName selectSexAndSocialNo(@Param("patientId") String patientId);
+    @Select("select rtrim(social_no) from mz_patient_mi with(nolock) where patient_id=#{patientId}")
+    String selectPatientIdCard(@Param("patientId") String patientId);
 
     @Select("select rtrim(mz_class) from zd_unit_code with(nolock) where code=#{code}")
     String selectMzClass(@Param("code") String code);
 
     @Select("select rtrim(code_rs) from a_employee_mi with(nolock) where code=#{code}")
-    String getCodeRsByCode(@Param("code") String code);
+    String selectCodeRsByCode(@Param("code") String code);
 
     @Update("update mz_patient_mi set social_no=#{socialNo} where patient_id=#{patientId}")
     void updateMzPatientMiSocialNo(@Param("patientId") String patientId,

+ 11 - 0
src/main/java/thyyxxk/wxservice_server/entity/appointment/PatientBriefInfo.java

@@ -0,0 +1,11 @@
+package thyyxxk.wxservice_server.entity.appointment;
+
+import lombok.Data;
+
+@Data
+public class PatientBriefInfo {
+    private String patientId;
+    private String name;
+    private String idCard;
+    private String gender;
+}

+ 43 - 25
src/main/java/thyyxxk/wxservice_server/service/AppointmentService.java

@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
 import thyyxxk.wxservice_server.constant.Constants;
+import thyyxxk.wxservice_server.constant.Gender;
 import thyyxxk.wxservice_server.dao.AppointmentDao;
 import thyyxxk.wxservice_server.entity.PureCodeName;
 import thyyxxk.wxservice_server.entity.ResultVo;
@@ -39,7 +40,7 @@ public class AppointmentService {
     }
 
     public ResultVo<List<MzClass>> getAllDepartments() {
-        if (null != mzClasses && !mzClasses.isEmpty()) {
+        if (ListUtil.notEmpty(mzClasses)) {
             return ResultVoUtil.success(mzClasses);
         }
         log.info("重新获取门诊科室并缓存。");
@@ -202,39 +203,56 @@ public class AppointmentService {
     }
 
     public ResultVo<String> hasValidCovidAssessment(String patientId, String deptCode) {
-        PureCodeName sexSocial = dao.selectSexAndSocialNo(patientId);
-        String mzClass = dao.selectMzClass(deptCode);
-        if (Constants.Sex.MALE.equals(sexSocial.getCode()) && Constants.MzClass.GYNAECOLOGY.equals(mzClass)) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "男性无法在妇产科挂号,请选择其他科室。");
+        ResultVo<String> appointmentRequirements = checkAppointmentRequirements(patientId, deptCode);
+        if (appointmentRequirements.getCode() != ExceptionEnum.SUCCESS.getCode()) {
+            return appointmentRequirements;
         }
-        int age = IdCardUtil.calAgeBySocialNo(sexSocial.getName());
-        if (age == -1) {
+        return checkCovidQuestionnaire(patientId);
+    }
+
+    private ResultVo<String> checkAppointmentRequirements(String patientId, String deptCode) {
+        String idCard = dao.selectPatientIdCard(patientId);
+        if (!IdCardUtil.isValidatedIdCard(idCard)) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您在我院绑定的身份证号不是有效的身份证号," +
                     "请前往【个人中心 - 我的就诊人 - 就诊人信息】进行修改。");
         }
-        if (Constants.MzDept.PEDIATRICS.equals(deptCode) && age >= 18) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "成年人无法在儿科挂号,请选择其他科室。");
+        String mzClass = dao.selectMzClass(deptCode);
+        if (Constants.MzClass.GYNAECOLOGY.equals(mzClass)) {
+            if (IdCardUtil.getGenderByIdCard(idCard) == Gender.MALE) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "男性无法在妇产科挂号,请选择其他科室。");
+            }
+        }
+        if (Constants.MzDept.PEDIATRICS.equals(deptCode)) {
+            if (IdCardUtil.getAgeByIdCard(idCard) >= 18) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "成年人无法在儿科挂号,请选择其他科室。");
+            }
         }
+        return ResultVoUtil.success();
+    }
+
+    private ResultVo<String> checkCovidQuestionnaire(String patientId) {
         CovidQuestionnaire covid = dao.validCovidAssessment(patientId);
         if (null == covid) {
             return ResultVoUtil.success("no valid assessment");
-        } else {
-            if (covid.getTemperature() == 2 ||
-                    covid.getItem1() != 14 ||
-                    covid.getItem2() != 24 ||
-                    covid.getItem3() != 32 ||
-                    covid.getItem4() != 42) {
-                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您新型冠状病毒感染流行病学史问卷未通过,请挂发热门诊。");
-            } else {
-                return ResultVoUtil.success("valid assessment");
-            }
         }
+        if (isDangerousCovidQuestionnaire(covid)) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您新型冠状病毒感染流行病学史问卷未通过,请挂发热门诊。");
+        }
+        return ResultVoUtil.success("valid assessment");
+    }
+
+    private boolean isDangerousCovidQuestionnaire(CovidQuestionnaire covid) {
+        return covid.getTemperature() == 2 ||
+                covid.getItem1() != 14 ||
+                covid.getItem2() != 24 ||
+                covid.getItem3() != 32 ||
+                covid.getItem4() != 42;
     }
 
     public ResultVo<String> getDoctorQrCode(String doctorCode) {
-        final String token = PropertiesUtil.getProperty("qywxToken");
-        final String url = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=" + token +
-                "&userid=" + dao.getCodeRsByCode(doctorCode);
+        final String qywxToken = PropertiesUtil.getProperty("qywxToken");
+        final String userid = dao.selectCodeRsByCode(doctorCode);
+        final String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=%s&userid=%s", qywxToken, userid);
         RestTemplate restTemplate = new RestTemplate();
         final String result = restTemplate.getForObject(url, String.class);
         JSONObject json = JSONObject.parseObject(result);
@@ -244,9 +262,9 @@ public class AppointmentService {
     public ResultVo<List<Map<String, String>>> getPaidMzGhList(String patientId) {
         log.info("获取门诊挂号记录列表:{}", patientId);
         RestTemplate template = new RestTemplate();
-        JSONObject obj = new JSONObject();
-        obj.put("patientId", patientId);
-        SourcesResponse hrgResponse = template.postForObject(hrgApiUrl + "/getRegistrationForPaid", obj, SourcesResponse.class);
+        JSONObject params = new JSONObject();
+        params.put("patientId", patientId);
+        SourcesResponse hrgResponse = template.postForObject(hrgApiUrl + "/getRegistrationForPaid", params, SourcesResponse.class);
         return ThmzUtil.getResultVoCompletableFuture(hrgResponse);
     }
 

+ 3 - 3
src/main/java/thyyxxk/wxservice_server/service/CovidVaccinateAppointmentService.java

@@ -95,17 +95,17 @@ public class CovidVaccinateAppointmentService {
 
     public ResultVo<String> submitVaccinateAppointment(CovidVaccinate param) {
         param.setCreateDatetime(new Date());
-        int age = IdCardUtil.calAgeBySocialNo(param.getSocialNo());
-        if (age == -1) {
+        if (!IdCardUtil.isValidatedIdCard(param.getSocialNo())) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您在我院绑定的身份证号不是有效的身份证号," +
                     "请前往【个人中心 - 我的就诊人 - 就诊人信息】进行修改。");
         }
+        int age = IdCardUtil.getAgeByIdCard(param.getSocialNo());
         if (age < 18 || age > 70) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "可接种的年龄区间为【18岁 - 70岁】," +
                     "您的年龄不满足此条件,敬请谅解。");
         }
         param.setAge(age);
-        param.setSex(IdCardUtil.calSexByIdCard(param.getSocialNo()));
+        param.setSex(IdCardUtil.getGenderByIdCard(param.getSocialNo()).getCode());
         String dateFormatted = DateUtil.formatDatetime(param.getExecuteDate(), "yyyy-MM-dd");
         if (dao.selectValidAppointment(param.getSocialNo(), param.getExecuteDate()) > 0) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您在【" + dateFormatted + "】已存在有效的预约,请勿重复预约。");

+ 1 - 1
src/main/java/thyyxxk/wxservice_server/service/WxApiService.java

@@ -175,7 +175,7 @@ public class WxApiService {
                 return ResultVoUtil.success(order);
             }
             final String message = root.element("return_msg").getStringValue();
-            log.info("微信统一下单失败:{}", message);
+            log.error("微信统一下单失败:{}", message);
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, message);
         } catch (DocumentException e) {
             e.printStackTrace();

+ 11 - 2
src/main/java/thyyxxk/wxservice_server/utils/DateUtil.java

@@ -1,5 +1,7 @@
 package thyyxxk.wxservice_server.utils;
 
+import lombok.extern.slf4j.Slf4j;
+
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -9,6 +11,7 @@ import java.util.Date;
 /**
  * @author dj
  */
+@Slf4j
 public class DateUtil {
     public static String formatDatetime(Date date, String pattern) {
         if (null == date) {
@@ -64,12 +67,18 @@ public class DateUtil {
     }
 
     public static String calculateSex(String socialNo) {
+        socialNo = socialNo.trim();
         char c = socialNo.length() == 18 ? socialNo.charAt(socialNo.length() - 2) : socialNo.charAt(socialNo.length() - 1);
         if (StringUtil.isBlank(String.valueOf(c))) {
             return null;
         }
-        int gender = Integer.parseInt(String.valueOf(c));
-        return gender % 2 == 1 ? "M" : "F";
+        try {
+            int gender = Integer.parseInt(String.valueOf(c));
+            return gender % 2 == 1 ? "M" : "F";
+        } catch (Exception e) {
+            log.error("无法从身份证 {} 中解析出性别。", socialNo);
+            return null;
+        }
     }
 
     private static final String[] TEMPLATE_PATTERNS = {"yyyyMMdd", "yyyy.MM.dd", "yyyy-MM-dd",

+ 5 - 6
src/main/java/thyyxxk/wxservice_server/utils/IdCardUtil.java

@@ -1,5 +1,7 @@
 package thyyxxk.wxservice_server.utils;
 
+import thyyxxk.wxservice_server.constant.Gender;
+
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
@@ -201,10 +203,7 @@ public class IdCardUtil {
     /**
      * 根据身份证号计算年龄
      * */
-    public static int calAgeBySocialNo(String idCard) {
-        if (null == idCard || idCard.startsWith("K") || idCard.length() != 18 || idCard.contains("-")) {
-            return -1;
-        }
+    public static int getAgeByIdCard(String idCard) {
         String birthDay = idCard.substring(6, 14);
         String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
         String yearStr = time.split("-")[0];
@@ -235,8 +234,8 @@ public class IdCardUtil {
         return --age;
     }
 
-    public static int calSexByIdCard(String idCard) {
+    public static Gender getGenderByIdCard(String idCard) {
         String gender = idCard.substring(16, 17);
-        return Integer.parseInt(gender) % 2 == 0 ? 2 : 1;
+        return Integer.parseInt(gender) % 2 == 0 ? Gender.FEMALE : Gender.MALE;
     }
 }

+ 13 - 0
src/main/java/thyyxxk/wxservice_server/utils/ListUtil.java

@@ -0,0 +1,13 @@
+package thyyxxk.wxservice_server.utils;
+
+import java.util.List;
+
+public class ListUtil {
+    public static boolean isEmpty(List<?> list) {
+        return null == list || list.size() == 0;
+    }
+
+    public static boolean notEmpty(List<?> list) {
+        return null != list && list.size() > 0;
+    }
+}