Browse Source

优化。

lighter 3 years ago
parent
commit
b43d65da9d

+ 50 - 0
src/main/java/thyyxxk/wxservice_server/constant/TradeState.java

@@ -0,0 +1,50 @@
+package thyyxxk.wxservice_server.constant;
+
+import thyyxxk.wxservice_server.utils.StringUtil;
+
+public enum TradeState {
+    NEWORDER(99, "初值", "NEWORDER"),
+    NOTPAY(0, "订单未支付", "NOTPAY"),
+    SUCCESS(1, "订单支付成功", "SUCCESS"),
+    CLOSED(2, "订单已关闭", "CLOSED"),
+    PAYERROR(3, "订单支付失败", "PAYERROR"),
+    REFUND(4, "订单已退款", "REFUND"),
+    ACCEPT(5, "订单已接收,等待扣款", "ACCEPT"),
+    USERPAYING(6, "用户支付中", "USERPAYING"),
+    UNREACHABLE(100, "未知状态", "UNREACHABLE");
+
+    private final int code;
+    private final String label;
+    private final String value;
+
+    public int getCode() {
+        return code;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    TradeState(int code, String label, String value) {
+        this.code = code;
+        this.label = label;
+        this.value = value;
+    }
+
+    public static TradeState get(String value) {
+        if (StringUtil.isBlank(value)) {
+            return UNREACHABLE;
+        }
+        for (TradeState state : TradeState.values()) {
+            if (state.getValue().equals(value.trim())) {
+                return state;
+            }
+        }
+        return UNREACHABLE;
+    }
+
+}

+ 1 - 1
src/main/java/thyyxxk/wxservice_server/controller/WxApiController.java

@@ -61,7 +61,7 @@ public class WxApiController {
 
     @PostMapping("/genMzPayQrcode")
     public ResultVo<String> genMzPayQrcode(@RequestBody @Validated GenMzPayQrcodeParam param) throws Exception {
-        return service.genMzPayQrcode(param);
+        return service.generateMzGuideBillPayQrcode(param);
     }
 
     @PostMapping("/pushMessage")

+ 17 - 12
src/main/java/thyyxxk/wxservice_server/dao/WxApiDao.java

@@ -2,6 +2,7 @@ package thyyxxk.wxservice_server.dao;
 
 import org.apache.ibatis.annotations.*;
 import thyyxxk.wxservice_server.entity.appointment.DoctorInfo;
+import thyyxxk.wxservice_server.entity.scheduled.TradeNo;
 import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
 
 import java.util.List;
@@ -25,21 +26,28 @@ public interface WxApiDao {
     @Insert("insert into t_wechat_pay_order (body,open_id,total_fee,patient_id," +
             "patient_name,inpatient_no,admiss_times,app_id,mch_id,prepay_id," +
             "time_stamp,trade_no,create_order_sign,pay_sign,spbill_create_ip," +
-            "create_datetime,pay_status,serial_no,order_type,his_ord_num,mzy_request_id,yj_req_no) " +
+            "create_datetime,pay_status,serial_no,order_type,his_ord_num," +
+            "mzy_request_id,yj_req_no,his_status,query_state_times) " +
             "values (#{body},#{openId},#{totalFee},#{patientId},#{patientName},#{inpatientNo}," +
-            "#{admissTimes},#{appId},#{mchId},#{prepayId},#{timeStamp},#{tradeNo}," +
-            "#{createOrderSign},#{paySign},#{spbillCreateIp},#{createDatetime}," +
-            "#{payStatus},#{serialNo},#{orderType},#{hisOrdNum},#{mzyRequestId},#{yjReqNo})")
+            "#{admissTimes},#{appId},#{mchId},#{prepayId},#{timeStamp},#{tradeNo},#{createOrderSign}," +
+            "#{paySign},#{spbillCreateIp},#{createDatetime},#{payStatus},#{serialNo},#{orderType}," +
+            "#{hisOrdNum},#{mzyRequestId},#{yjReqNo},0,0)")
     void insertNewOrder(WxPayOrder param);
 
-    @Update("update t_wechat_pay_order set pay_status=#{status}, " +
-            "pay_datetime=#{successTime} where trade_no=#{tradeNo}")
+    @Update("update t_wechat_pay_order set pay_status=#{status}, pay_datetime=#{successTime}, " +
+            "query_state_times=(query_state_times+1) where trade_no=#{tradeNo}")
     void updatePayStatusAndPayTime(@Param("tradeNo") String tradeNo, @Param("status") Integer status,
                                    @Param("successTime") String successTime);
 
+    @Update("update t_wechat_pay_order set pay_status=#{status},query_state_times=(query_state_times+1) where trade_no=#{tradeNo}")
+    void updatePayStatusAndQueryTimes(@Param("tradeNo") String tradeNo, @Param("status") Integer status);
+
     @Update("update t_wechat_pay_order set pay_status=#{status} where trade_no=#{tradeNo}")
     void updatePayStatusOnly(@Param("tradeNo") String tradeNo, @Param("status") Integer status);
 
+    @Update("update t_wechat_pay_order set his_status=1 where trade_no=#{tradeNo}")
+    void updateSuccessHisStatus(@Param("tradeNo") String tradeNo);
+
     @Update("update t_wechat_pay_order set open_id=#{openId} where trade_no=#{tradeNo}")
     void updatePayOpenId(@Param("tradeNo") String tradeNo,
                                   @Param("openId") String openId);
@@ -47,9 +55,9 @@ public interface WxApiDao {
     @Select("select * from t_wechat_pay_order where trade_no=#{tradeNo}")
     WxPayOrder selectOrderByTradeNo(@Param("tradeNo") String tradeNo);
 
-    @Select("select * from t_wechat_pay_order where order_type<=3 and " +
-            "pay_status in (99, 0, 5, 6, 100) and isnull(query_state_times,0) < 10")
-    List<WxPayOrder> selectOrdersForScheduleTask();
+    @Select("select trade_no, query_state_times from t_wechat_pay_order where his_status=0 " +
+            "and order_type<=3 and pay_status in (99, 0, 5, 6, 100) ")
+    List<TradeNo> selectTradeNosForScheduleTask();
 
     @Select("select open_id from t_wechat_patient_bind where patient_id=#{cardNo} and del_flag=0")
     List<String> selectOpenIdByPatientId(@Param("cardNo") String cardNo);
@@ -57,9 +65,6 @@ public interface WxApiDao {
     @Select("select open_id from t_wechat_patient_bind where ic_card_no=#{cardNo} and del_flag=0")
     List<String> selectOpenIdByIcCardNo(@Param("cardNo") String cardNo);
 
-    @Update("update t_wechat_pay_order set query_state_times=(isnull(query_state_times,0)+1) where trade_no=#{tradeNo}")
-    void increaseQueryTimesByTradeNo(@Param("tradeNo") String tradeNo);
-
     @Select("select " +
             "rtrim(a.code) doctorCode, " +
             "rtrim(a.name) doctorName, " +

+ 10 - 0
src/main/java/thyyxxk/wxservice_server/entity/scheduled/TradeNo.java

@@ -0,0 +1,10 @@
+package thyyxxk.wxservice_server.entity.scheduled;
+
+import lombok.Data;
+
+@Data
+public class TradeNo {
+    private String tradeNo;
+    private Integer queryStateTimes;
+}
+

+ 1 - 0
src/main/java/thyyxxk/wxservice_server/entity/wxapi/WxPayOrder.java

@@ -54,6 +54,7 @@ public class WxPayOrder {
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
     private Date refundOpDatetime;
+    private Integer hisStatus;
     /**
      * 以下部分缴纳住院预交金会用到
      * */

+ 18 - 13
src/main/java/thyyxxk/wxservice_server/scheduled/QueryOrderStateTask.java

@@ -2,20 +2,19 @@ package thyyxxk.wxservice_server.scheduled;
 
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
-import thyyxxk.wxservice_server.constant.Constants;
 import thyyxxk.wxservice_server.constant.QuerySource;
 import thyyxxk.wxservice_server.dao.WxApiDao;
 import thyyxxk.wxservice_server.entity.ResultVo;
+import thyyxxk.wxservice_server.entity.scheduled.TradeNo;
 import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
 import thyyxxk.wxservice_server.service.WxApiService;
-import thyyxxk.wxservice_server.utils.PropertiesUtil;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
-import thyyxxk.wxservice_server.utils.TradeVectorUtil;
 
 import java.util.List;
 
@@ -29,6 +28,8 @@ public class QueryOrderStateTask {
     private final WxApiDao dao;
     private final WxApiService service;
     private static volatile boolean canScheduleRun = true;
+    @Value("${production}")
+    private Boolean production;
 
     @Autowired
     public QueryOrderStateTask(WxApiDao dao, WxApiService service) {
@@ -49,16 +50,20 @@ public class QueryOrderStateTask {
 
     @Scheduled(fixedRate = 180 * 1000)
     public void queryOrderState() throws Exception {
-        if (!canScheduleRun || Constants.WINDOWS_10.equals(PropertiesUtil.getProperty(Constants.OS_NAME))) {
-            return;
-        }
-        List<WxPayOrder> list = dao.selectOrdersForScheduleTask();
-        if (null == list || list.isEmpty()) {
-            return;
-        }
-        for (WxPayOrder order : list) {
-            if (!TradeVectorUtil.tradeNoBetweenQuery(order.getTradeNo())) {
-                service.queryOrderState(order.getTradeNo(), QuerySource.SCHEDULE);
+        if (canScheduleRun && production) {
+            List<TradeNo> tradeNos = dao.selectTradeNosForScheduleTask();
+            if (null == tradeNos || tradeNos.isEmpty()) {
+                return;
+            }
+            log.info("定时查询订单支付状态:{}", tradeNos);
+            for (TradeNo tradeNo : tradeNos) {
+                if (tradeNo.getQueryStateTimes() >= 60) {
+                    WxPayOrder order = new WxPayOrder();
+                    order.setTradeNo(tradeNo.getTradeNo());
+                    service.closeWxOrder(order);
+                } else {
+                    service.queryOrderState(tradeNo.getTradeNo(), QuerySource.SCHEDULE);
+                }
             }
         }
     }

+ 48 - 88
src/main/java/thyyxxk/wxservice_server/service/SavePayResultService.java

@@ -13,7 +13,6 @@ import thyyxxk.wxservice_server.dao.WxApiDao;
 import thyyxxk.wxservice_server.entity.ResultVo;
 import thyyxxk.wxservice_server.entity.appointment.MzyReqrec;
 import thyyxxk.wxservice_server.entity.appointment.SaveAppointmentParam;
-import thyyxxk.wxservice_server.entity.hrgresponse.QueryMzPayStatusResponse;
 import thyyxxk.wxservice_server.entity.hrgresponse.SaveGhFeeResponse;
 import thyyxxk.wxservice_server.entity.hrgresponse.SaveMzFeeResponse;
 import thyyxxk.wxservice_server.entity.inpatient.GetZyFeeParam;
@@ -42,7 +41,8 @@ public class SavePayResultService {
     private String hrgApiUrl;
 
     @Autowired
-    public SavePayResultService(WxApiDao dao, InpatientDao yjjDao, AutoRefundService refundService, PushWxMessageService pushWxMessageService) {
+    public SavePayResultService(WxApiDao dao, InpatientDao yjjDao, AutoRefundService refundService,
+                                PushWxMessageService pushWxMessageService) {
         this.dao = dao;
         this.yjjDao = yjjDao;
         this.refundService = refundService;
@@ -50,42 +50,22 @@ public class SavePayResultService {
     }
 
     public ResultVo<String> saveAppointment(WxPayOrder order) {
-        JSONObject obj = new JSONObject();
-        obj.put("psOrdNum", order.getTradeNo());
-        obj.put("payMode", "WX");
-        obj.put("payAmt", order.getTotalFee().toPlainString());
-        obj.put("agtOrdNum", order.getSerialNo());
-        obj.put("payTime", DateUtil.formatDatetime(order.getPayDatetime(), "yyyy-MM-dd HH:mm:ss"));
-        try {
-            RestTemplate template = new RestTemplate();
-            QueryMzPayStatusResponse response = template.postForObject(hrgApiUrl + "/ getPayStatusForRegistration",
-                    obj, QueryMzPayStatusResponse.class);
-            log.info("门诊挂号订单支付状态查询:参数:{},结果:{}", obj, response);
-            int hasSaved = 0;
-            if (null != response && response.getResultCode() == 0) {
-                hasSaved = response.getPayStatus();
-            }
-            if (hasSaved == 1) {
-                log.info("订单号:{} 的挂号信息已保存,无需再次保存。", order.getTradeNo());
-                return ResultVoUtil.success("保存挂号信息成功。");
-            }
-            SaveAppointmentParam param = new SaveAppointmentParam();
-            param.setMzyRequestId(order.getMzyRequestId());
-            param.setTotalFee(order.getTotalFee().doubleValue());
-            MzyReqrec mzyReqrec = new MzyReqrec();
-            mzyReqrec.setPatientId(order.getPatientId());
-            mzyReqrec.setPaymode("WX");
-            mzyReqrec.setPsordnum(order.getTradeNo());
-            mzyReqrec.setAgtordnum(order.getSerialNo());
-            param.setMzyReqrec(mzyReqrec);
-            SaveGhFeeResponse data = template.postForObject(hrgApiUrl + "/payRegistrationFormHaiCi",
-                    param, SaveGhFeeResponse.class);
-            log.info("保存挂号信息: 参数:{},结果:{}", param, data);
-            if (null != data && (data.getResultCode() == 0 || data.getMessage().contains("挂号成功"))) {
-                return ResultVoUtil.success("保存挂号信息成功。");
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
+        SaveAppointmentParam param = new SaveAppointmentParam();
+        param.setMzyRequestId(order.getMzyRequestId());
+        param.setTotalFee(order.getTotalFee().doubleValue());
+        MzyReqrec mzyReqrec = new MzyReqrec();
+        mzyReqrec.setPatientId(order.getPatientId());
+        mzyReqrec.setPaymode("WX");
+        mzyReqrec.setPsordnum(order.getTradeNo());
+        mzyReqrec.setAgtordnum(order.getSerialNo());
+        param.setMzyReqrec(mzyReqrec);
+        RestTemplate template = new RestTemplate();
+        SaveGhFeeResponse data = template.postForObject(hrgApiUrl + "/payRegistrationFormHaiCi",
+                param, SaveGhFeeResponse.class);
+        log.info("保存挂号信息: 参数:{},结果:{}", param, data);
+        if (null != data && (data.getResultCode() == 0 || data.getMessage().contains("挂号成功"))) {
+            dao.updateSuccessHisStatus(order.getTradeNo());
+            return ResultVoUtil.success("保存挂号信息成功。");
         }
         ResultVo<String> refund = refundService.autoRefund(order.getTradeNo(), "保存挂号信息失败,自动退款。");
         log.info("【订单号:{}】保存挂号信息失败,自动退款结果:{}", order.getTradeNo(), refund);
@@ -97,44 +77,23 @@ public class SavePayResultService {
     }
 
     public ResultVo<String> saveMzChargeInfo(WxPayOrder order) {
-        JSONObject obj = new JSONObject();
-        obj.put("hisOrdNum", order.getHisOrdNum());
-        obj.put("psOrdNum", order.getTradeNo());
-        obj.put("payMode", "WX");
-        obj.put("payAmt", order.getTotalFee().toPlainString());
-        obj.put("agtOrdNum", order.getSerialNo());
-        obj.put("payTime", DateUtil.formatDatetime(order.getPayDatetime(), "yyyy-MM-dd HH:mm:ss"));
-        try {
-            RestTemplate template = new RestTemplate();
-            QueryMzPayStatusResponse response = template.postForObject(hrgApiUrl + "/getPayStatus",
-                    obj, QueryMzPayStatusResponse.class);
-            log.info("门诊缴费订单支付状态查询:参数:{},结果:{}", obj, response);
-            int hasSaved = 0;
-            if (null != response && response.getResultCode() != -1) {
-                hasSaved = response.getPayStatus();
-            }
-            if (hasSaved == 1) {
-                log.info("订单号:{} 的门诊缴费信息已保存,无需再次保存。", order.getTradeNo());
-                return ResultVoUtil.success("保存门诊缴费信息成功。");
-            }
-            String payTime = DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss");
-            JSONObject hrgParam = new JSONObject();
-            hrgParam.put("patCardType", 1);
-            hrgParam.put("patCardNo", order.getPatientId());
-            hrgParam.put("hisOrdNum", order.getHisOrdNum());
-            hrgParam.put("psOrdNum", order.getTradeNo());
-            hrgParam.put("payMode", "WX");
-            hrgParam.put("payAmt", DecimalTool.moneyYuanToFen(order.getTotalFee()));
-            hrgParam.put("agtOrdNum", order.getSerialNo());
-            hrgParam.put("payTime", payTime);
-            SaveMzFeeResponse saveMzFeeResponse = template.postForObject(hrgApiUrl + "/payChargeDetailFormHaiCi",
-                    hrgParam, SaveMzFeeResponse.class);
-            log.info("保存门诊缴费信息:参数:{},结果:{}", hrgParam, saveMzFeeResponse);
-            if (saveMzFeeResponse != null && saveMzFeeResponse.getResultCode() == 0) {
-                return ResultVoUtil.success("保存门诊缴费信息成功。");
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
+        String payTime = DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss");
+        JSONObject hrgParam = new JSONObject();
+        hrgParam.put("patCardType", 1);
+        hrgParam.put("patCardNo", order.getPatientId());
+        hrgParam.put("hisOrdNum", order.getHisOrdNum());
+        hrgParam.put("psOrdNum", order.getTradeNo());
+        hrgParam.put("payMode", "WX");
+        hrgParam.put("payAmt", DecimalTool.moneyYuanToFen(order.getTotalFee()));
+        hrgParam.put("agtOrdNum", order.getSerialNo());
+        hrgParam.put("payTime", payTime);
+        RestTemplate template = new RestTemplate();
+        SaveMzFeeResponse saveMzFeeResponse = template.postForObject(hrgApiUrl + "/payChargeDetailFormHaiCi",
+                hrgParam, SaveMzFeeResponse.class);
+        log.info("保存门诊缴费信息:参数:{},结果:{}", hrgParam, saveMzFeeResponse);
+        if (saveMzFeeResponse != null && saveMzFeeResponse.getResultCode() == 0) {
+            dao.updateSuccessHisStatus(order.getTradeNo());
+            return ResultVoUtil.success("保存门诊缴费信息成功。");
         }
         ResultVo<String> refund = refundService.autoRefund(order.getTradeNo(), "保存门诊缴费信息失败,自动退款。");
         log.info("【订单号:{}】保存门诊缴费信息失败,自动退款结果:{}", order.getTradeNo(), refund);
@@ -145,35 +104,36 @@ public class SavePayResultService {
         return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存门诊缴费信息失败,自动退款失败,请联系服务中心进行退款。");
     }
 
-    public ResultVo<String> saveZyYjjInfo(WxPayOrder param) {
-        int savedCount = yjjDao.selectSavedCount(param.getTradeNo(), param.getSerialNo());
+    public ResultVo<String> saveZyYjjInfo(WxPayOrder order) {
+        int savedCount = yjjDao.selectSavedCount(order.getTradeNo(), order.getSerialNo());
         if (savedCount > 0) {
-            log.info("订单号:{} 的住院预交金信息已保存,无需再次保存。", param.getTradeNo());
+            log.info("订单号:{} 的住院预交金信息已保存,无需再次保存。", order.getTradeNo());
             return ResultVoUtil.success("保存住院预交金信息成功。");
         }
         String datetime = DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss");
-        yjjDao.payZyYjjSuccessful(param.getInpatientNo(), param.getAdmissTimes(), param.getTotalFee(),
-                datetime, param.getTradeNo(), param.getSerialNo(), "");
+        yjjDao.payZyYjjSuccessful(order.getInpatientNo(), order.getAdmissTimes(), order.getTotalFee(),
+                datetime, order.getTradeNo(), order.getSerialNo(), "");
         GetZyFeeParam getZyFeeParam = new GetZyFeeParam();
         String date = DateUtil.formatDatetime(new Date(), "yyyy-MM-dd");
-        getZyFeeParam.setInpatientNo(param.getInpatientNo());
-        getZyFeeParam.setAdmissTimes(param.getAdmissTimes());
+        getZyFeeParam.setInpatientNo(order.getInpatientNo());
+        getZyFeeParam.setAdmissTimes(order.getAdmissTimes());
         getZyFeeParam.setStart(date);
         getZyFeeParam.setEnd(date);
         yjjDao.selectZyFees(getZyFeeParam);
-        log.info("缴纳住院预交金成功:{}", JSON.toJSONStringWithDateFormat(param, "yyyy-MM-dd HH:mm:ss"));
+        log.info("缴纳住院预交金成功:{}", JSON.toJSONStringWithDateFormat(order, "yyyy-MM-dd HH:mm:ss"));
         String msgContent = "{\"touser\":\"\",\"data\":" +
-                "{\"keyword3\":{\"color\":\"#173177\",\"value\":\"" + param.getTotalFee() + "\"}," +
-                "\"keyword1\":{\"color\":\"#173177\",\"value\":\"" + param.getPatientName() + "\"}," +
-                "\"keyword2\":{\"color\":\"#173177\",\"value\":\"" + param.getInpatientNo() + "\"}," +
+                "{\"keyword3\":{\"color\":\"#173177\",\"value\":\"" + order.getTotalFee() + "\"}," +
+                "\"keyword1\":{\"color\":\"#173177\",\"value\":\"" + order.getPatientName() + "\"}," +
+                "\"keyword2\":{\"color\":\"#173177\",\"value\":\"" + order.getInpatientNo() + "\"}," +
                 "\"remark\":{\"color\":\"#FF0000\",\"value\":\"感谢您的使用,祝您健康!\"}," +
                 "\"first\":{\"color\":\"#FF0000\",\"value\":\"您好,您已成功支付住院预交金,详情如下:\"}}," +
                 "\"template_id\":\"6qWVpQopIe4a_fYYnZg_yaInPoMFduDDJ4hotv3Mtxo\"," +
                 "\"url\":\"\"}";
         PushMessageParam pojo = new PushMessageParam();
-        pojo.setCardNo(yjjDao.selectCardNoByPatientId(param.getPatientId()));
+        pojo.setCardNo(yjjDao.selectCardNoByPatientId(order.getPatientId()));
         pojo.setMsgContext(JSONObject.parseObject(msgContent));
         pushWxMessageService.pushMessage(pojo);
+        dao.updateSuccessHisStatus(order.getTradeNo());
         return ResultVoUtil.success("保存住院预交金信息成功。");
     }
 

+ 21 - 69
src/main/java/thyyxxk/wxservice_server/service/WxApiService.java

@@ -19,6 +19,7 @@ import org.springframework.web.client.RestTemplate;
 import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
 import thyyxxk.wxservice_server.constant.OrderType;
 import thyyxxk.wxservice_server.constant.QuerySource;
+import thyyxxk.wxservice_server.constant.TradeState;
 import thyyxxk.wxservice_server.dao.WxApiDao;
 import thyyxxk.wxservice_server.entity.ResultVo;
 import thyyxxk.wxservice_server.entity.appointment.DoctorInfo;
@@ -31,7 +32,6 @@ import thyyxxk.wxservice_server.utils.*;
 
 import java.nio.charset.StandardCharsets;
 import java.util.*;
-import java.util.concurrent.TimeUnit;
 
 /**
  * @author dj
@@ -70,11 +70,11 @@ public class WxApiService {
             existOrder = dao.selectSameMzPayOrder(param.getHisOrdNum());
         }
         if (null != existOrder) {
-            if (existOrder.getPayStatus() == 1) {
+            if (existOrder.getPayStatus() == TradeState.SUCCESS.getCode()) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您已成功支付过一笔相同金额的订单,请勿重复支付。");
             }
             if (StringUtil.notBlank(existOrder.getPaySign()) && StringUtil.notBlank(existOrder.getPrepayId())) {
-                if (existOrder.getPayStatus() == 99 || existOrder.getPayStatus() == 0) {
+                if (existOrder.getPayStatus() == TradeState.NEWORDER.getCode() || existOrder.getPayStatus() == TradeState.NOTPAY.getCode()) {
                     if (DateUtil.orderValid(existOrder.getCreateDatetime())) {
                         return ResultVoUtil.success(existOrder);
                     }
@@ -164,7 +164,7 @@ public class WxApiService {
                 order.setPaySign(paySign);
                 order.setSpbillCreateIp(param.getClientIp());
                 order.setCreateDatetime(new Date());
-                order.setPayStatus(99);
+                order.setPayStatus(TradeState.NEWORDER.getCode());
                 order.setHisOrdNum(param.getHisOrdNum());
                 order.setMzyRequestId(param.getMzyRequestId());
                 order.setYjReqNo(param.getYjReqNo());
@@ -184,82 +184,34 @@ public class WxApiService {
     }
 
     public ResultVo<String> queryOrderState(String tradeNo, QuerySource source) throws Exception {
-        while (TradeVectorUtil.tradeNoBetweenQuery(tradeNo)) {
-            TimeUnit.SECONDS.sleep(1);
-        }
-        TradeVectorUtil.add(tradeNo);
         WxPayOrder order = dao.selectOrderByTradeNo(tradeNo);
         OrderType orderType = OrderType.get(order.getOrderType());
         JSONObject obj = retryService.queryOrderStateFromTencent(tradeNo, orderType, source);
-        String tradeState = obj.getString("trade_state");
-        if ("SUCCESS".equals(tradeState)) {
+        String value = obj.getString("trade_state");
+        TradeState tradeState = TradeState.get(value);
+        if (tradeState.equals(TradeState.SUCCESS)) {
             String successTime = obj.getString("success_time")
                     .split("\\+")[0].replace("T", " ");
-            dao.updatePayStatusAndPayTime(tradeNo, 1, successTime);
-            ResultVo<String> saveRet;
+            dao.updatePayStatusAndPayTime(tradeNo, tradeState.getCode(), successTime);
             switch (orderType) {
                 case REGISTRATION:
-                    saveRet = savePayResultService.saveAppointment(order);
-                    break;
+                    return savePayResultService.saveAppointment(order);
                 case OUTPATIENT:
-                    saveRet = savePayResultService.saveMzChargeInfo(order);
-                    break;
+                    return savePayResultService.saveMzChargeInfo(order);
                 case INPATIENT_PRE_PAY:
-                    saveRet = savePayResultService.saveZyYjjInfo(order);
-                    break;
+                    return savePayResultService.saveZyYjjInfo(order);
                 case SELF_HELP_MACHINE:
                 case INSPECTIONS:
-                    saveRet = ResultVoUtil.success("订单已支付。");
-                    break;
+                    return ResultVoUtil.success("订单已支付。");
                 default:
-                    log.info("未识别到的订单类型:{},订单号:{}", order.getOrderType(), tradeNo);
-                    saveRet = ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未识别到的订单类型,请联系服务中心。");
-                    break;
+                    return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未识别到的订单类型,请联系服务中心。");
             }
-            TradeVectorUtil.remove(tradeNo);
-            dao.increaseQueryTimesByTradeNo(tradeNo);
-            return saveRet;
-        }
-        String message;
-        switch (tradeState) {
-            case "PAYERROR":
-                dao.updatePayStatusOnly(tradeNo, 3);
-                message = "订单支付失败";
-                break;
-            case "REFUND":
-                dao.updatePayStatusOnly(tradeNo, 4);
-                message = "订单已退款";
-                break;
-            case "NOTPAY":
-                dao.updatePayStatusOnly(tradeNo, 0);
-                message = "订单未支付";
-                break;
-            case "CLOSED":
-                dao.updatePayStatusOnly(tradeNo, 2);
-                message = "订单已关闭";
-                break;
-            case "ACCEPT":
-                dao.updatePayStatusOnly(tradeNo, 5);
-                message = "订单已接收,等待扣款";
-                break;
-            case "USERPAYING":
-                dao.updatePayStatusOnly(tradeNo, 6);
-                message = "用户支付中";
-                break;
-            case "UNREACHABLE":
-                dao.updatePayStatusOnly(tradeNo, 100);
-                message = "查询订单状态出现异常";
-                break;
-            default:
-                message = "未知状态";
-                break;
         }
-        TradeVectorUtil.remove(tradeNo);
-        dao.increaseQueryTimesByTradeNo(tradeNo);
-        return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, message);
+        dao.updatePayStatusAndQueryTimes(tradeNo, tradeState.getCode());
+        return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, tradeState.getLabel());
     }
 
-    public ResultVo<String> genMzPayQrcode(GenMzPayQrcodeParam param) throws Exception {
+    public ResultVo<String> generateMzGuideBillPayQrcode(GenMzPayQrcodeParam param) throws Exception {
         String outTradeNo = SnowFlakeId.instance().nextId();
         JSONObject body = new JSONObject();
         body.put("appid", PropertiesUtil.getProperty("appId"));
@@ -300,9 +252,9 @@ public class WxApiService {
             order.setTimeStamp(String.valueOf(timesStamp));
             order.setTradeNo(outTradeNo);
             order.setCreateDatetime(new Date());
-            order.setPayStatus(0);
+            order.setPayStatus(TradeState.NOTPAY.getCode());
             order.setSerialNo(SnowFlakeId.instance().nextId());
-            order.setOrderType(2);
+            order.setOrderType(OrderType.OUTPATIENT.getCode());
             order.setHisOrdNum(param.getHisOrdNum());
             dao.insertNewOrder(order);
             JSONObject retObj = JSONObject.parseObject(ret);
@@ -367,7 +319,7 @@ public class WxApiService {
             order.setTimeStamp(String.valueOf(timesStamp));
             order.setTradeNo(outTradeNo);
             order.setCreateDatetime(new Date());
-            order.setPayStatus(0);
+            order.setPayStatus(TradeState.NOTPAY.getCode());
             order.setSerialNo(SnowFlakeId.instance().nextId());
             order.setOrderType(prm.getOrderType());
             dao.insertNewOrder(order);
@@ -386,7 +338,7 @@ public class WxApiService {
         if (null == payStatus) {
             return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "订单不存在,请检查订单号是否正确。");
         }
-        if (2 == payStatus) {
+        if (payStatus == TradeState.CLOSED.getCode()) {
             return ResultVoUtil.success("订单已是关闭状态,请勿重复关闭订单。");
         }
         String url = "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/" + order.getTradeNo() + "/close";
@@ -406,7 +358,7 @@ public class WxApiService {
         log.info("关闭微信订单:{},结果:{}", order.getTradeNo(), statusCode);
         if (statusCode == 204) {
             httpClient.close();
-            dao.updatePayStatusOnly(order.getTradeNo(), 2);
+            dao.updatePayStatusOnly(order.getTradeNo(), TradeState.CLOSED.getCode());
             return ResultVoUtil.success("关闭订单成功。");
         }
         if (null != response.getEntity()) {

+ 0 - 33
src/main/java/thyyxxk/wxservice_server/utils/TradeVectorUtil.java

@@ -1,33 +0,0 @@
-package thyyxxk.wxservice_server.utils;
-
-import java.util.Vector;
-
-/**
- * @description: 正在查询的订单的容器
- * @author: DingJie
- * @create: 2021-06-21 08:41:35
- **/
-public class TradeVectorUtil {
-    private static Vector<String> tradeNosBetweenQuery;
-
-    public static void add(String tradeNo) {
-        if (null == tradeNosBetweenQuery) {
-            tradeNosBetweenQuery = new Vector<>();
-        }
-        tradeNosBetweenQuery.add(tradeNo);
-    }
-
-    public static void remove(String tradeNo) {
-        if (null != tradeNosBetweenQuery) {
-            tradeNosBetweenQuery.remove(tradeNo);
-        }
-    }
-
-    public static boolean tradeNoBetweenQuery(String tradeNo) {
-        if (null == tradeNosBetweenQuery) {
-            return false;
-        }
-        return tradeNosBetweenQuery.contains(tradeNo);
-    }
-
-}

+ 1 - 0
src/main/resources/application-8083.yml

@@ -34,3 +34,4 @@ mybatis:
 
 hrgApiUrl: http://webhis.thyy.cn:81/thmz/api/v1
 inspectionUrl: http://172.16.32.178:622/pushservice.asmx?wsdl
+production: true

+ 1 - 0
src/main/resources/application-8085.yml

@@ -34,3 +34,4 @@ mybatis:
 
 hrgApiUrl: http://webhis.thyy.cn:81/thmz/api/v1
 inspectionUrl: http://172.16.32.178:622/pushservice.asmx?wsdl
+production: true

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

@@ -33,3 +33,4 @@ mybatis:
 
 hrgApiUrl: http://172.16.30.33:8089/thmz/api/v1
 inspectionUrl: http://172.16.32.178:622/pushservice.asmx?wsdl
+production: false