Bläddra i källkod

添加自助退号退费

lighter 2 år sedan
förälder
incheckning
476fcc5d25

+ 8 - 3
src/main/java/thyyxxk/wxservice_server/controller/AppointmentController.java

@@ -81,13 +81,18 @@ public class AppointmentController {
         return service.getPaidMzGhList(patientId);
     }
 
-    @PostMapping("/listMzyReqrecUnPay")
-    public ResultVo<List<MzyReqrec>> listMzyReqrecUnPay(@RequestBody BriefPatInfo patInfo) {
-        return service.listMzyReqrecUnPay(patInfo);
+    @PostMapping("/listMzyReqrec")
+    public ResultVo<List<MzyReqrec>> listMzyReqrec(@RequestBody BriefPatInfo patInfo) {
+        return service.listMzyReqrec(patInfo);
     }
 
     @PostMapping("/getMzyReqrecInfo")
     public ResultVo<MzyReqrec> getMzyReqrecInfo(@RequestBody BriefPatInfo patInfo) {
         return service.getMzyReqrecInfo(patInfo);
     }
+
+    @PostMapping("/cancelReqrec")
+    public ResultVo<String> cancelReqrec(@RequestBody MzyReqrec mzyReq) {
+        return service.cancelReqrec(mzyReq);
+    }
 }

+ 8 - 0
src/main/java/thyyxxk/wxservice_server/entity/BriefPatInfo.java

@@ -6,4 +6,12 @@ import lombok.Data;
 public class BriefPatInfo {
     private String patientId;
     private Integer times;
+
+    // 5 未缴费  0 已缴费   1 已退费
+    private String payMark;
+    private Boolean filterUnpaidReq;
+
+    public Boolean filterUnpaidReq() {
+        return null != filterUnpaidReq && filterUnpaidReq;
+    }
 }

+ 20 - 0
src/main/java/thyyxxk/wxservice_server/entity/appointment/MzyReqrec.java

@@ -1,6 +1,7 @@
 package thyyxxk.wxservice_server.entity.appointment;
 
 import lombok.Data;
+import thyyxxk.wxservice_server.utils.StringUtil;
 
 import java.math.BigDecimal;
 
@@ -27,6 +28,13 @@ public class MzyReqrec {
     private Integer serialNo;
     private String opDay;
     private BigDecimal amount;
+
+    //  0 未接诊  1 已经接诊
+    private String visitedMark;
+
+    // 0 未退费  1 已退费
+    private String cancelMark;
+
     private String paymode;
     /**
      * 订单号
@@ -36,4 +44,16 @@ public class MzyReqrec {
      * 流水号
      * */
     private String agtordnum;
+
+    public String getPaymode() {
+        return StringUtil.isBlank(paymode) ? null : paymode;
+    }
+
+    public String getVisitedMark() {
+        return StringUtil.isBlank(visitedMark) ? "0" : visitedMark;
+    }
+
+    public String getCancelMark() {
+        return StringUtil.isBlank(cancelMark) ? "0" : cancelMark;
+    }
 }

+ 34 - 4
src/main/java/thyyxxk/wxservice_server/service/AppointmentService.java

@@ -32,15 +32,17 @@ public class AppointmentService {
     private final AppointmentDao dao;
     private final RedisLikeService redis;
     private final ElectronicHealthCardService healthCardService;
+    private final WxRefundService wxRefundService;
 
     @Value("${hrgApiUrl}")
     private String hrgApiUrl;
 
     @Autowired
-    public AppointmentService(AppointmentDao dao, RedisLikeService redis, ElectronicHealthCardService healthCardService) {
+    public AppointmentService(AppointmentDao dao, RedisLikeService redis, ElectronicHealthCardService healthCardService, WxRefundService wxRefundService) {
         this.dao = dao;
         this.redis = redis;
         this.healthCardService = healthCardService;
+        this.wxRefundService = wxRefundService;
     }
 
     public ResultVo<List<MzClass>> getAllDepartments() {
@@ -249,8 +251,8 @@ public class AppointmentService {
         return ThmzUtil.getResultVoCompletableFuture(hrgResponse);
     }
 
-    public ResultVo<List<MzyReqrec>> listMzyReqrecUnPay(BriefPatInfo patInfo) {
-        String url = hrgApiUrl + "/listMzyReqrecUnPay?patientId=" + patInfo.getPatientId();
+    public ResultVo<List<MzyReqrec>> listMzyReqrec(BriefPatInfo patInfo) {
+        String url = hrgApiUrl + "/listMzyReqrec?patientId=" + patInfo.getPatientId() + "&payMark=" + patInfo.getPayMark();
         JSONObject response = new RestTemplate().getForObject(url, JSONObject.class);
         if (null == response) {
             return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
@@ -297,7 +299,7 @@ public class AppointmentService {
             return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
         }
         MzyReqrec mzyReqrec = JSONObject.parseObject(JSONObject.toJSONString(data), MzyReqrec.class);
-        if (StringUtil.notBlank(mzyReqrec.getPaymode())) {
+        if (patInfo.filterUnpaidReq() && StringUtil.notBlank(mzyReqrec.getPaymode())) {
             return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
         }
         mzyReqrec.setDoctorCode(redis.getEmployeeName(mzyReqrec.getDoctorCode()));
@@ -305,4 +307,32 @@ public class AppointmentService {
         mzyReqrec.setAmpm(redis.getAmpmName(mzyReqrec.getAmpm()));
         return ResultVoUtil.success(mzyReqrec);
     }
+
+    public ResultVo<String> cancelReqrec(MzyReqrec mzyReq) {
+        if (invalidCancelReqrec(mzyReq)) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "仅支持最近15天内尚未就诊的微信自助挂号。");
+        }
+        String url = hrgApiUrl + "/cancelReqrec";
+        JSONObject params = new JSONObject();
+        params.put("patientId", mzyReq.getPatientId());
+        params.put("times", mzyReq.getTimes());
+        JSONObject response = new RestTemplate().postForObject(url, params, JSONObject.class);
+        log.info("自助退号:参数:{};结果:{}", params, response);
+        if (null == response) {
+            return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
+        }
+        Integer rescode = response.getInteger("code");
+        if (null == rescode) {
+            return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
+        }
+        if (rescode != 0) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, response.getString("message"));
+        }
+        return wxRefundService.autoRefund(mzyReq.getPsordnum(), "自助退号。");
+    }
+
+    private boolean invalidCancelReqrec(MzyReqrec mzyReq) {
+        return DateUtil.dateDiff(mzyReq.getRequestDayStr()) > 15 || null == mzyReq.getPaymode()
+                || mzyReq.getVisitedMark().equals("1") || mzyReq.getCancelMark().equals("1");
+    }
 }

+ 10 - 0
src/main/java/thyyxxk/wxservice_server/utils/DateUtil.java

@@ -123,4 +123,14 @@ public class DateUtil {
         }
         return null;
     }
+
+    public static Integer dateDiff(String source) {
+        try {
+            Date sdate = new SimpleDateFormat("yyyy-MM-dd").parse(source);
+            long offset = System.currentTimeMillis() - sdate.getTime();
+            return Math.toIntExact(offset / 1000 / 60 / 60 / 24);
+        } catch (Exception e) {
+            return -1;
+        }
+    }
 }