Ver Fonte

添加订单支付状态查询,绑定就诊卡时添加就诊卡号

lighter há 4 anos atrás
pai
commit
ebb9343c52

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>wxservice-server</artifactId>
-    <version>1.7</version>
+    <version>1.9</version>
     <name>wxservice-server</name>
     <description>vue3 web server</description>
 

+ 10 - 0
src/main/java/thyyxxk/wxservice_server/controller/WxApiController.java

@@ -35,4 +35,14 @@ public class WxApiController {
         param.setClientIp(request.getRemoteAddr());
         return service.createPayOrder(param);
     }
+
+    @GetMapping("/queryOrderState")
+    public ResultVo<String> queryOrderState(@RequestParam("tradeNo") String tradeNo) throws Exception {
+        return service.queryOrderState(tradeNo);
+    }
+
+    @PostMapping("pushMessage")
+    public ResultVo<String> pushMessage(@RequestBody @Validated PushMessageParam param) {
+        return service.pushMessage(param);
+    }
 }

+ 6 - 6
src/main/java/thyyxxk/wxservice_server/dao/PatientCardsDao.java

@@ -11,17 +11,17 @@ public interface PatientCardsDao {
     List<BindPatientIdParam> getBindPatientCard(@Param("openId") String openId);
 
     @Select("select rtrim(name) name, rtrim(patient_id) patientId, rtrim(social_no) socialNo, " +
-            "convert(varchar(10), lv_date, 21) lvDate " +
+            "convert(varchar(10), lv_date, 21) lvDate, rtrim(ic_card_no) icCardNo " +
             "from mz_patient_mi where patient_id=#{cardNo}")
     List<BindPatientIdParam> getPatientBaseInfoByPatientId(@Param("cardNo") String cardNo);
 
     @Select("select rtrim(name) name, rtrim(patient_id) patientId, rtrim(social_no) socialNo, " +
-            "convert(varchar(10), lv_date, 21) lvDate " +
+            "convert(varchar(10), lv_date, 21) lvDate, rtrim(ic_card_no) icCardNo " +
             "from mz_patient_mi where ic_card_no=#{cardNo}")
     List<BindPatientIdParam> getPatientBaseInfoByMzCardNo(@Param("cardNo") String cardNo);
 
     @Select("select rtrim(name) name, rtrim(patient_id) patientId, rtrim(social_no) socialNo, " +
-            "convert(varchar(10), lv_date, 21) lvDate " +
+            "convert(varchar(10), lv_date, 21) lvDate, rtrim(ic_card_no) icCardNo " +
             "from mz_patient_mi where social_no=#{cardNo}")
     List<BindPatientIdParam> getPatientBaseInfoBySocialNo(@Param("cardNo") String cardNo);
 
@@ -31,10 +31,10 @@ public interface PatientCardsDao {
     @Select("select count(1) from t_wechat_patient_bind where open_id=#{openId} and del_flag=0")
     Integer validBindCount(@Param("openId") String openId);
 
-    @Insert("insert into t_wechat_patient_bind " +
-            "(name, patient_id, social_no, phone, province, city, district, street, open_id, del_flag, is_default) " +
+    @Insert("insert into t_wechat_patient_bind (name, patient_id, social_no, phone, province, " +
+            "city, district, street, open_id, del_flag, is_default, ic_card_no) " +
             "values (#{name}, #{patientId}, #{socialNo}, #{phone}, #{province}, #{city}, " +
-            "#{district}, #{street}, #{openId}, 0, #{isDefault})")
+            "#{district}, #{street}, #{openId}, 0, #{isDefault}, #{icCardNo})")
     void bindPatientCard(BindPatientIdParam param);
 
     @Select("update t_wechat_patient_bind set is_default=#{isDefault} where " +

+ 1 - 0
src/main/java/thyyxxk/wxservice_server/pojo/patientcards/BindPatientIdParam.java

@@ -19,6 +19,7 @@ public class BindPatientIdParam {
     private Integer isDefault;
 
     private String patientId;
+    private String icCardNo;
     private String socialNo;
     private String lvDate;
 }

+ 17 - 0
src/main/java/thyyxxk/wxservice_server/pojo/wxapi/PushMessageParam.java

@@ -0,0 +1,17 @@
+package thyyxxk.wxservice_server.pojo.wxapi;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+public class PushMessageParam {
+    private String serviceCode;
+    @NotBlank(message = "诊疗卡号不能为空。")
+    private String cardNo;
+    private String templateId;
+    @NotBlank(message = "消息内容不能为空。")
+    private String msgContext;
+    private String url;
+    private String channel;
+}

+ 1 - 3
src/main/java/thyyxxk/wxservice_server/service/AppointmentService.java

@@ -165,8 +165,7 @@ public class AppointmentService {
                     covid.getItem1() != 14 ||
                     covid.getItem2() != 24 ||
                     covid.getItem3() != 32 ||
-                    covid.getItem4() != 42 ||
-                    covid.getItem5() != 52) {
+                    covid.getItem4() != 42) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您新型冠状病毒感染流行病学史问卷未通过,请挂发热门诊。");
             } else {
                 return ResultVoUtil.success("valid assessment");
@@ -182,7 +181,6 @@ public class AppointmentService {
         String tradeNo = param.getMzyReqrec().getPsordnum();
         String datetime = DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss");
         if (null != data && data.getResultCode() == 0) {
-            wxApiDao.updatePayStatus(tradeNo, 1, datetime);
             return ResultVoUtil.success("保存挂号信息成功。");
         }
         log.info("保存挂号信息失败,将自动退款。");

+ 5 - 2
src/main/java/thyyxxk/wxservice_server/service/IdCardAnalyzeService.java

@@ -71,8 +71,10 @@ public class IdCardAnalyzeService {
                 String provinceName = dao.selectRegionName(provinceCode);
                 idCard.setAddress(provinceName + "/" + cityName + "/" + districtName);
                 String longStreet = result.getJSONObject("住址").getString("words");
-                String shortStreet = longStreet.split(districtName)[1];
-                idCard.setStreet(shortStreet);
+                String[] shortStreets = longStreet.split(districtName);
+                if (shortStreets.length > 1) {
+                    idCard.setStreet(shortStreets[1]);
+                }
             }
             return ResultVoUtil.success(idCard);
         } else {
@@ -122,6 +124,7 @@ public class IdCardAnalyzeService {
         toBeBound.setDistrict(param.getDistrict());
         toBeBound.setStreet(param.getStreet());
         toBeBound.setOpenId(param.getOpenId());
+        toBeBound.setIcCardNo(toBeBound.getPatientId());
         cardsDao.bindPatientCard(toBeBound);
         return ResultVoUtil.success(hrgResponse.getData());
     }

+ 1 - 4
src/main/java/thyyxxk/wxservice_server/service/InpatientService.java

@@ -25,12 +25,10 @@ import java.util.Map;
 @Service
 public class InpatientService {
     private final InpatientDao dao;
-    private final WxApiDao wxApiDao;
 
     @Autowired
-    public InpatientService(InpatientDao dao, WxApiDao wxApiDao) {
+    public InpatientService(InpatientDao dao) {
         this.dao = dao;
-        this.wxApiDao = wxApiDao;
     }
 
     public ResultVo<InpatientInfo> getInpatientInfo(String patientId) {
@@ -79,7 +77,6 @@ public class InpatientService {
         String datetime = DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss");
         dao.payZyYjjSuccessful(param.getInpatientNo(), param.getAdmissTimes(), param.getTotalFee(),
                 datetime, param.getTradeNo(), param.getSerialNo(), "");
-        wxApiDao.updatePayStatus(param.getTradeNo(), 1, datetime);
         log.info("缴纳住院预交金成功:{}", JSON.toJSONStringWithDateFormat(param, "yyyy-MM-dd HH:mm:ss"));
         return ResultVoUtil.success("缴纳住院预交金成功。");
     }

+ 1 - 0
src/main/java/thyyxxk/wxservice_server/service/PatientCardsService.java

@@ -63,6 +63,7 @@ public class PatientCardsService {
                 BindPatientIdParam temp = list.get(0);
                 if (param.getName().trim().equals(temp.getName())) {
                     param.setPatientId(temp.getPatientId());
+                    param.setIcCardNo(temp.getIcCardNo());
                     param.setSocialNo(temp.getSocialNo());
                     final int count = dao.isThisCardBindBefore(param.getPatientId(), param.getOpenId());
                     if (count > 0) {

+ 0 - 1
src/main/java/thyyxxk/wxservice_server/service/PayMzFeeService.java

@@ -67,7 +67,6 @@ public class PayMzFeeService {
                 hrgParam, HrgResponse.class);
         log.info("保存门诊缴费信息结果:{}", response);
         if (null != response && response.getResultCode() == 0) {
-            dao.updatePayStatus(tradeNo, 1, payTime);
             return ResultVoUtil.success("保存门诊缴费信息成功。");
         }
         log.info("保存门诊缴费信息失败,将自动退款。");

+ 49 - 0
src/main/java/thyyxxk/wxservice_server/service/WxApiService.java

@@ -16,6 +16,7 @@ import thyyxxk.wxservice_server.dao.WxApiDao;
 import thyyxxk.wxservice_server.pojo.ResultVo;
 import thyyxxk.wxservice_server.pojo.wxapi.JsApiSHA1;
 import thyyxxk.wxservice_server.pojo.appointment.WeChatPayParam;
+import thyyxxk.wxservice_server.pojo.wxapi.PushMessageParam;
 import thyyxxk.wxservice_server.pojo.wxapi.WxPayOrderPojo;
 import thyyxxk.wxservice_server.utils.*;
 
@@ -136,6 +137,45 @@ public class WxApiService {
         }
     }
 
+    public ResultVo<String> queryOrderState(String tradeNo) throws Exception {
+        String url = "http://webhis.thyy.cn:8706/mzPayQrCode/queryOrderState?tradeNo=" + tradeNo;
+        String ret = getRestTemplate().getForObject(url, String.class);
+        JSONObject obj = JSONObject.parseObject(ret);
+        log.info("查询订单状态:{}", obj);
+        String tradeState = obj.getString("trade_state");
+        if (null == tradeState || tradeState.equals("ACCEPT")) {
+            Thread.sleep(2000);
+            ret = getRestTemplate().getForObject(url, String.class);
+            obj = JSONObject.parseObject(ret);
+            log.info("再次查询订单状态:{}", obj);
+            tradeState = obj.getString("trade_state");
+            if (null == tradeState || tradeState.equals("ACCEPT")) {
+                Thread.sleep(2000);
+                ret = getRestTemplate().getForObject(url, String.class);
+                obj = JSONObject.parseObject(ret);
+                log.info("最后一次查询订单状态:{}", obj);
+                tradeState = obj.getString("trade_state");
+            }
+        }
+        switch (tradeState) {
+            case "SUCCESS":
+                String successTime = obj.getString("success_time")
+                        .split("\\+")[0].replace("T", " ");
+                dao.updatePayStatus(tradeNo, 1, successTime);
+                break;
+            case "PAYERROR":
+                dao.updatePayStatus(tradeNo, 3, DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss"));
+                break;
+            case "REFUND":
+                dao.updatePayStatus(tradeNo, 4, DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss"));
+                break;
+            case "REVOKED":
+                dao.updatePayStatus(tradeNo, 2, DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss"));
+                break;
+        }
+        return ResultVoUtil.success(tradeState);
+    }
+
     public ResultVo<String> autoRefund(String tradeNo, String reason) {
         WxPayOrderPojo order = dao.selectOrderByTradeNo(tradeNo);
         if (null == order) {
@@ -154,6 +194,15 @@ public class WxApiService {
         return template.postForObject(url, param, ResultVo.class);
     }
 
+    public ResultVo<String> pushMessage(PushMessageParam param) {
+        if (null == param.getUrl()) {
+            param.setUrl("");
+        }
+
+
+        return ResultVoUtil.success("消息推送成功。");
+    }
+
     private RestTemplate getRestTemplate() {
         RestTemplate restTemplate = new RestTemplate();
         List<HttpMessageConverter<?>> list = restTemplate.getMessageConverters();