Sfoglia il codice sorgente

代码规范化。

lighter 4 anni fa
parent
commit
b5e6fd1b72

+ 1 - 1
pom.xml

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

+ 6 - 3
src/main/java/thyyxxk/wxservice_server/controller/WxApiController.java

@@ -14,6 +14,9 @@ import thyyxxk.wxservice_server.utils.ResultVoUtil;
 import javax.servlet.http.HttpServletRequest;
 import java.util.concurrent.ExecutionException;
 
+/**
+ * @author dj
+ */
 @Slf4j
 @RestController
 @RequestMapping("/wxApi")
@@ -53,9 +56,9 @@ public class WxApiController {
         return service.queryOrderState(tradeNo).get();
     }
 
-    @PostMapping("/createOrderForMzGuideBill")
-    public ResultVo<String> createOrderForMzGuideBill(@RequestBody @Validated MzGuideBillParam param) throws Exception {
-        return service.createOrderForMzGuideBill(param).get();
+    @PostMapping("/genMzPayQrcode")
+    public ResultVo<String> genMzPayQrcode(@RequestBody @Validated GenMzPayQrcodeParam param) throws Exception {
+        return service.genMzPayQrcode(param).get();
     }
 
     @PostMapping("/pushMessage")

+ 5 - 1
src/main/java/thyyxxk/wxservice_server/pojo/inpatient/InpatientInfo.java

@@ -1,7 +1,11 @@
 package thyyxxk.wxservice_server.pojo.inpatient;
 
 import lombok.Data;
+import thyyxxk.wxservice_server.utils.StringUtil;
 
+/**
+ * @author dj
+ */
 @Data
 public class InpatientInfo {
     private String inpatientNo;
@@ -15,6 +19,6 @@ public class InpatientInfo {
     private String lastBalance;
 
     public String getFundPay() {
-        return (null == fundPay || fundPay.equals("")) ? "0.00" : fundPay;
+        return StringUtil.isBlank(fundPay) ? "0.00" : fundPay;
     }
 }

+ 4 - 1
src/main/java/thyyxxk/wxservice_server/pojo/wxapi/MzGuideBillParam.java → src/main/java/thyyxxk/wxservice_server/pojo/wxapi/GenMzPayQrcodeParam.java

@@ -5,8 +5,11 @@ import lombok.Data;
 import javax.validation.constraints.Min;
 import javax.validation.constraints.NotBlank;
 
+/**
+ * @author dj
+ */
 @Data
-public class MzGuideBillParam {
+public class GenMzPayQrcodeParam {
     @Min(value = 0, message = "总金额需要大于零。")
     private Integer totalAmt;
     @NotBlank(message = "门诊id号不能为空。")

+ 5 - 1
src/main/java/thyyxxk/wxservice_server/service/CovidVaccinateAppointmentService.java

@@ -12,9 +12,13 @@ import thyyxxk.wxservice_server.pojo.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;
 
+/**
+ * @author dj
+ */
 @Slf4j
 @Service
 public class CovidVaccinateAppointmentService {
@@ -77,7 +81,7 @@ public class CovidVaccinateAppointmentService {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【" + dateFormatted + "】的预约名额已满,请选择其他预约日期。");
         }
         dao.insertNewAppointment(param);
-        if (null != param.getPatientId() && !param.getPatientId().trim().equals("")) {
+        if (StringUtil.notBlank(param.getPatientId())) {
             dao.updatePhoneAndSocialNo(param.getPatientId(), param.getSocialNo(), param.getPhone());
             String msgContent = "{\"touser\":\"\",\"data\":" +
                     "{\"keyword2\":{\"color\":\"#173177\",\"value\":\"" + dateFormatted + "\"}," +

+ 13 - 9
src/main/java/thyyxxk/wxservice_server/service/HomePageService.java

@@ -8,16 +8,20 @@ import thyyxxk.wxservice_server.dao.HomePageDao;
 import thyyxxk.wxservice_server.pojo.ResultVo;
 import thyyxxk.wxservice_server.pojo.homepage.HomePageDoctor;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
+import thyyxxk.wxservice_server.utils.StringUtil;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 
+/**
+ * @author dj
+ */
 @Slf4j
 @Service
 public class HomePageService {
     private final HomePageDao dao;
-    private static final List<List<HomePageDoctor>> list = new Vector<>();
+    private static final List<List<HomePageDoctor>> HOME_PAGE_DOCTORS = new Vector<>();
 
     @Autowired
     public HomePageService(HomePageDao dao) {
@@ -25,36 +29,36 @@ public class HomePageService {
     }
 
     public ResultVo<List<List<HomePageDoctor>>> selectHomePageDoctors() {
-        if (list.size() > 0) {
-            return ResultVoUtil.success(list);
+        if (HOME_PAGE_DOCTORS.size() > 0) {
+            return ResultVoUtil.success(HOME_PAGE_DOCTORS);
         }
         List<HomePageDoctor> originList = dao.selectHomePageDoctors();
         List<HomePageDoctor> tempList = new ArrayList<>();
         for (HomePageDoctor doctor : originList) {
-            if (null == doctor.getIntroduction() || doctor.getIntroduction().equals("")) {
+            if (StringUtil.isBlank(doctor.getIntroduction())) {
                 continue;
             }
             tempList.add(doctor);
             if (tempList.size() == 3) {
-                list.add(tempList);
+                HOME_PAGE_DOCTORS.add(tempList);
                 tempList = new ArrayList<>();
             }
         }
         if (tempList.size() > 0) {
-            list.add(tempList);
+            HOME_PAGE_DOCTORS.add(tempList);
         }
-        return ResultVoUtil.success(list);
+        return ResultVoUtil.success(HOME_PAGE_DOCTORS);
     }
 
     @Scheduled(cron = "0 0 3 * * ?")
     public void autoRefreshHomePageDoctors() {
         log.info("首页滚动医生缓存已清空。");
-        list.clear();
+        HOME_PAGE_DOCTORS.clear();
     }
 
     public ResultVo<String> refreshHomePageDoctors() {
         log.info("首页滚动医生缓存已清空。");
-        list.clear();
+        HOME_PAGE_DOCTORS.clear();
         return ResultVoUtil.success("首页滚动医生缓存已清空。");
     }
 }

+ 13 - 13
src/main/java/thyyxxk/wxservice_server/service/InspectionsService.java

@@ -20,6 +20,7 @@ import thyyxxk.wxservice_server.pojo.inspections.CheckExamParam;
 import thyyxxk.wxservice_server.pojo.inspections.ExamIndexResult;
 import thyyxxk.wxservice_server.pojo.inspections.detail.*;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
+import thyyxxk.wxservice_server.utils.StringUtil;
 
 import javax.xml.namespace.QName;
 import java.lang.reflect.Field;
@@ -46,10 +47,10 @@ public class InspectionsService {
         String sendHead1 = "<message><PATIENT_TYPE>0</PATIENT_TYPE><PTNT_NO>" + param.getPatientId() + "</PTNT_NO>";
         String sendHead2 = null;
         String sendHead3 = null;
-        if (null != tjNo && !tjNo.equals("")) {
+        if (StringUtil.notBlank(tjNo)) {
             sendHead2 = "<message><PTNT_NO>" + tjNo + "</PTNT_NO>";
         }
-        if (null != inpatientNo && !inpatientNo.equals("")) {
+        if (StringUtil.notBlank(inpatientNo)) {
             sendHead3 = "<message><PATIENT_TYPE>1</PATIENT_TYPE><PTNT_NO>" + inpatientNo + "</PTNT_NO>";
         }
         String sendEnd = "<START_TIME>" + param.getStart() + "</START_TIME><END_TIME>" + param.getEnd() + "</END_TIME></message>";
@@ -125,7 +126,7 @@ public class InspectionsService {
 
     @Async("asyncTask")
     public CompletableFuture<ResultVo<ExamDetailResult>> getExamDetail(String orderId) {
-        if (orderId == null || orderId.trim().equals("") || orderId.trim().equals("undefined")) {
+        if (StringUtil.isBlank(orderId) || "undefined".equals(orderId.trim())) {
             return CompletableFuture.completedFuture(ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "报告ID不能为空!"));
         }
         String send = "<message><ORDR_ID>" + orderId + "</ORDR_ID></message>";
@@ -176,7 +177,7 @@ public class InspectionsService {
         }
         Element codeEl = retEle.element("Code");
         String code = codeEl.getStringValue();
-        if (code.equals("1")) {
+        if ("1".equals(code)) {
             List<ExamIndexResult> examList = new ArrayList<>();
             Element resEl = retEle.element("Result");
             List<Element> reports = resEl.elements("ReportList");
@@ -210,7 +211,7 @@ public class InspectionsService {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结果集为空!");
         }
         String code = retEle.elementTextTrim("Code");
-        if (code.equals("0")) {
+        if ("0".equals(code)) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, retEle.elementTextTrim("ErrorMsg"));
         }
         Element reportListEle = retEle.element("Result").element("ReportList");
@@ -236,30 +237,29 @@ public class InspectionsService {
                         });
                         bacteriaResult.setAntibioticResults(antibioticResults);
                     }
-                    if (notNull(bacteriaResult.getBAC_ID()))
+                    if (StringUtil.notBlank(bacteriaResult.getBAC_ID())) {
                         bacteriaResults.add(bacteriaResult);
+                    }
                 });
                 reportItem.setBacteriaResults(bacteriaResults);
             }
-            if (notNull(reportItem.getITM_VALUE()) || notNull(reportItem.getITM_STR_VALUE())
-                    || reportItem.getBacteriaResults().size() > 0)
+            if (StringUtil.notBlank(reportItem.getITM_VALUE()) || StringUtil.notBlank(reportItem.getITM_STR_VALUE())
+                    || reportItem.getBacteriaResults().size() > 0) {
                 reportItems.add(reportItem);
+            }
         });
         detail.setReportItems(reportItems);
         return ResultVoUtil.success(detail);
     }
 
-    private boolean notNull(String target) {
-        return target != null && !target.equals("");
-    }
-
     private Object reflect(Object pojo, Element element) {
         Field[] fields = pojo.getClass().getDeclaredFields();
         for (Field field : fields) {
             try {
                 String name = field.getName();
-                if (name.equals("bacteriaResults") || name.equals("antibioticResults"))
+                if ("bacteriaResults".equals(name) || "antibioticResults".equals(name)) {
                     continue;
+                }
                 Method m = pojo.getClass().getMethod("set" + name, String.class);
                 m.invoke(pojo, element.elementTextTrim(name));
             } catch (Exception e) {

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

@@ -30,7 +30,7 @@ import thyyxxk.wxservice_server.pojo.hrgresponse.SaveGhFeeRes;
 import thyyxxk.wxservice_server.pojo.hrgresponse.SaveMzFeeRes;
 import thyyxxk.wxservice_server.pojo.inpatient.GetZyFeeParam;
 import thyyxxk.wxservice_server.pojo.wxapi.JsApiSHA1;
-import thyyxxk.wxservice_server.pojo.wxapi.MzGuideBillParam;
+import thyyxxk.wxservice_server.pojo.wxapi.GenMzPayQrcodeParam;
 import thyyxxk.wxservice_server.pojo.wxapi.PushMessageParam;
 import thyyxxk.wxservice_server.pojo.wxapi.WxPayOrderPojo;
 import thyyxxk.wxservice_server.utils.*;
@@ -392,7 +392,7 @@ public class WxApiService {
     }
 
     @Async("asyncTask")
-    public CompletableFuture<ResultVo<String>> createOrderForMzGuideBill(MzGuideBillParam param) throws Exception {
+    public CompletableFuture<ResultVo<String>> genMzPayQrcode(GenMzPayQrcodeParam param) throws Exception {
         String outTradeNo = SnowFlakeId.instance().nextId();
         JSONObject body = new JSONObject();
         body.put("appid", PropertiesUtil.getProperty("appId"));
@@ -447,7 +447,7 @@ public class WxApiService {
 
     @Async("asyncTask")
     public void pushMessage(PushMessageParam param) {
-        if (null == param.getCardNo() || param.getCardNo().trim().equals("")) {
+        if (StringUtil.isBlank(param.getCardNo())) {
             return;
         }
         List<String> openIds = param.isCardNoPatientId() ?

+ 2 - 2
src/main/java/thyyxxk/wxservice_server/utils/IdCardUtil.java

@@ -14,13 +14,13 @@ public class IdCardUtil {
      * 验证所有的身份证的合法性
      */
     public static boolean isValidatedIdCard(String idCard) {
-        if (null == idCard || idCard.trim().equals("")) {
+        if (StringUtil.isBlank(idCard)) {
             return false;
         }
         if (idCard.length() == 15) {
             idCard = convertIdcarBy15bit(idCard);
         }
-        if (null == idCard || idCard.trim().equals("")) {
+        if (StringUtil.isBlank(idCard)) {
             return false;
         }
         return isValidate18IdCard(idCard);

+ 16 - 0
src/main/java/thyyxxk/wxservice_server/utils/StringUtil.java

@@ -0,0 +1,16 @@
+package thyyxxk.wxservice_server.utils;
+
+/**
+ * @description: 字符串工具类
+ * @author: DingJie
+ * @create: 2021-04-09 14:24:41
+ **/
+public class StringUtil {
+    public static boolean isBlank(String source) {
+        return null == source || "".equals(source.trim());
+    }
+
+    public static boolean notBlank(String source) {
+        return null != source && !"".equals(source.trim());
+    }
+}

+ 12 - 7
src/main/java/thyyxxk/wxservice_server/utils/WxPaySignUtil.java

@@ -8,11 +8,14 @@ import java.nio.charset.StandardCharsets;
 import java.security.*;
 import java.util.*;
 
+/**
+ * @author dj
+ */
 public class WxPaySignUtil {
     private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5',
             '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
     private static final int TAG_LENGTH_BIT = 128;
-    private static final byte[] aesKey = PropertiesUtil.getProperty("mchApiV3Key").getBytes(StandardCharsets.UTF_8);
+    private static final byte[] AES_KEY = PropertiesUtil.getProperty("mchApiV3Key").getBytes(StandardCharsets.UTF_8);
 
     /**
      * 生成签名,用于在微信支付前,获取预支付时候需要使用的参数sign
@@ -29,18 +32,18 @@ public class WxPaySignUtil {
         for (Map.Entry<String, String> item : infoIds) {
             String key = item.getKey();
             String val = item.getValue();
-            if (!val.equals("")) {
+            if (StringUtil.notBlank(val)) {
                 stringA.append(key).append("=").append(val).append("&");
             }
         }
         String stringSignTemp = stringA.substring(0, stringA.length() - 1) + "&key=" + PropertiesUtil.getProperty("mchKey");
-        return encryptByMD5(stringSignTemp).toUpperCase();
+        return encryptByMd5(stringSignTemp).toUpperCase();
     }
 
     /**
      * MD5加密
      */
-    private static String encryptByMD5(String sourceStr) {
+    private static String encryptByMd5(String sourceStr) {
         String result = "";
         try {
             MessageDigest md = MessageDigest.getInstance("MD5");
@@ -50,10 +53,12 @@ public class WxPaySignUtil {
             StringBuilder buf = new StringBuilder();
             for (byte value : b) {
                 i = value;
-                if (i < 0)
+                if (i < 0) {
                     i += 256;
-                if (i < 16)
+                }
+                if (i < 16) {
                     buf.append("0");
+                }
                 buf.append(Integer.toHexString(i));
             }
             result = buf.toString();
@@ -96,7 +101,7 @@ public class WxPaySignUtil {
     public static String decryptToString(byte[] associatedData, byte[] nonce, String ciphertext) throws GeneralSecurityException {
         try {
             Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
-            SecretKeySpec key = new SecretKeySpec(aesKey, "AES");
+            SecretKeySpec key = new SecretKeySpec(AES_KEY, "AES");
             GCMParameterSpec spec = new GCMParameterSpec(TAG_LENGTH_BIT, nonce);
             cipher.init(Cipher.DECRYPT_MODE, key, spec);
             cipher.updateAAD(associatedData);

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

@@ -1,5 +1,5 @@
 server:
-  port: 8085
+  port: 8083
   servlet:
     context-path: /wxserver
 spring: