浏览代码

药品申购订金功能

lighter 9 月之前
父节点
当前提交
e13aef9909

+ 2 - 0
src/main/java/thyyxxk/wxservice_server/constant/OrderType.java

@@ -19,6 +19,8 @@ public enum OrderType {
 
     AESTHETIC_MEDICINE(8, "医学美容"),
 
+    DRUG_PURCHASE(9, "药品申购"),
+
     UNDEFINED(99, "未说明的费用类型");
 
     private final int code;

+ 40 - 1
src/main/java/thyyxxk/wxservice_server/controller/ImportDrugController.java

@@ -1,5 +1,6 @@
 package thyyxxk.wxservice_server.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -9,9 +10,12 @@ import thyyxxk.wxservice_server.dao.ImportDrugDao;
 import thyyxxk.wxservice_server.entity.ResultVo;
 import thyyxxk.wxservice_server.entity.drugconsult.ImportDrugPurchase;
 import thyyxxk.wxservice_server.entity.drugconsult.OnShelfDrug;
+import thyyxxk.wxservice_server.entity.drugconsult.PrepayState;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
 import thyyxxk.wxservice_server.utils.SnowFlakeId;
+import thyyxxk.wxservice_server.utils.TokenUtil;
 
+import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.List;
 
@@ -30,14 +34,49 @@ public class ImportDrugController {
     @PostMapping("/importDrugPurchase")
     public ResultVo<String> importDrugPurchase(@RequestBody ImportDrugPurchase purchase) {
         purchase.setId(SnowFlakeId.instance().nextId());
+        purchase.setOpenid(TokenUtil.getInstance().getUserOpenid());
         purchase.setCreateTime(Calendar.getInstance().getTime());
         dao.insert(purchase);
         return ResultVoUtil.success("我院近期将与您联系,请保持手机畅通,谢谢。");
     }
 
+    @GetMapping("/getHistoryPurchase")
+    public ResultVo<List<ImportDrugPurchase>> getHistoryPurchase() {
+        QueryWrapper<ImportDrugPurchase> wrapper = new QueryWrapper<>();
+        wrapper.eq("openid", TokenUtil.getInstance().getUserOpenid());
+        wrapper.orderByDesc("create_time");
+        List<ImportDrugPurchase> list = dao.selectList(wrapper);
+        for (ImportDrugPurchase purchase : list) {
+            if (purchase.getPrepayAmt().compareTo(BigDecimal.ZERO) > 0) {
+                if (purchase.getPrepayState() == PrepayState.NOTPAY) {
+                    purchase.setTagType1("primary");
+                    purchase.setTagContent1("该药品需要支付订金");
+                    purchase.setShowPayButton(true);
+                } else if (purchase.getPrepayState() == PrepayState.SUCCESS) {
+                    purchase.setTagType1("success");
+                    purchase.setTagContent1("该药品订金已支付");
+                } else {
+                    purchase.setTagType1("warning");
+                    purchase.setTagContent1("该药品订金已退款");
+                }
+            } else {
+                purchase.setTagType1("success");
+                purchase.setTagContent1("该药品无需支付订金");
+            }
+            if (purchase.getDealFlag() == 0) {
+                purchase.setTagType2("primary");
+                purchase.setTagContent2("医院未处理");
+            } else {
+                purchase.setTagType2("success");
+                purchase.setTagContent2("医院已处理");
+            }
+        }
+        return ResultVoUtil.success(list);
+    }
+
     @GetMapping("/onShelfDrugInquiry")
     public ResultVo<List<OnShelfDrug>> onShelfDrugInquiry(@RequestParam("name") String name) {
-        List<OnShelfDrug> list = new RestTemplate().getForObject(API+name, List.class);
+        List<OnShelfDrug> list = new RestTemplate().getForObject(API + name, List.class);
         if (null == list || list.isEmpty()) {
             return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到数据。");
         }

+ 2 - 2
src/main/java/thyyxxk/wxservice_server/dao/WxApiDao.java

@@ -37,13 +37,13 @@ public interface WxApiDao {
             "create_datetime,trade_state,serial_no,order_type,his_ord_num," +
             "mzy_request_id,yj_req_no,his_status,query_state_times,ap_time," +
             "fundpay_amt,acctpay_amt,coupon_amt,cashpay_amt,coupon_id,sgl_check_id," +
-            "sgl_check_notified) " +
+            "sgl_check_notified,drug_purchase_id) " +
             "values (#{body},#{openid},#{totalFee},#{patientId},#{patientName},#{inpatientNo}," +
             "#{admissTimes},#{appId},#{mchId},#{prepayId},#{timeStamp},#{tradeNo},#{createOrderSign}," +
             "#{paySign},#{spbillCreateIp},#{createDatetime},#{tradeState},#{serialNo},#{orderType}," +
             "#{hisOrdNum},#{mzyRequestId},#{yjReqNo},0,0,#{apTime},#{fundpayAmt}," +
             "#{acctpayAmt},#{couponAmt},#{cashpayAmt},#{couponId},#{sglCheckId}," +
-            "#{sglCheckNotified})")
+            "#{sglCheckNotified},#{drugPurchaseId})")
     void insertNewOrder(WxPayOrder param);
 
     @Select("select * from t_si_setlinfo where pat_no=#{patNo} and times=#{times} and revoked=0")

+ 18 - 0
src/main/java/thyyxxk/wxservice_server/entity/drugconsult/ImportDrugPurchase.java

@@ -1,10 +1,12 @@
 package thyyxxk.wxservice_server.entity.drugconsult;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 @Data
@@ -12,6 +14,7 @@ import java.util.Date;
 public class ImportDrugPurchase {
     @TableId(type = IdType.INPUT)
     private String id;
+    private String openid;
     private String phoneNo;
     private String drugName;
     private Integer drugQuantity;
@@ -20,4 +23,19 @@ public class ImportDrugPurchase {
     private String expContent;
     private String drugImg;
     private Date createTime;
+    private Integer dealFlag;
+    private Date dealTime;
+    private BigDecimal prepayAmt;
+    private PrepayState prepayState;
+
+    @TableField(exist = false)
+    private String tagType1;
+    @TableField(exist = false)
+    private String tagContent1;
+    @TableField(exist = false)
+    private String tagType2;
+    @TableField(exist = false)
+    private String tagContent2;
+    @TableField(exist = false)
+    private boolean showPayButton = false;
 }

+ 7 - 0
src/main/java/thyyxxk/wxservice_server/entity/drugconsult/PrepayState.java

@@ -0,0 +1,7 @@
+package thyyxxk.wxservice_server.entity.drugconsult;
+
+public enum PrepayState {
+    NOTPAY,
+    SUCCESS,
+    REFUND
+}

+ 3 - 8
src/main/java/thyyxxk/wxservice_server/entity/wxapi/WxPayOrder.java

@@ -16,8 +16,8 @@ import java.util.Date;
 public class WxPayOrder {
     private String body;
     /**
-     * 订单类型,1:挂号费 2:门诊缴费 3:住院预交金 4:自助机缴费 5:体检缴费
-     *         6:小程序订单
+     * 订单类型
+     * @see OrderType
      * */
     private Integer orderType;
     private String openid;
@@ -51,22 +51,17 @@ public class WxPayOrder {
     private Transaction.TradeStateEnum tradeState;
     private String refundOpCode;
     private String refundReason;
-    /**
-     * 微信退款单号
-     * */
     private String refundId;
     @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;
-    /**
-     * 以下部分缴纳住院预交金会用到
-     * */
     private String inpatientNo;
     private Integer admissTimes;
     private String apTime;
     private String sglCheckId;
     private Boolean sglCheckNotified;
+    private String drugPurchaseId;
 
     public Boolean sglCheckNotNotified() {
         return orderType == OrderType.INSPECTIONS.getCode()

+ 16 - 0
src/main/java/thyyxxk/wxservice_server/service/RedisLikeService.java

@@ -16,6 +16,7 @@ public class RedisLikeService {
     private final static Map<String, String> regionParentMap = new HashMap<>();
     private final static Map<String, String> ampmMap = new HashMap<>();
     private final static Map<String, String> deptPosMap = new HashMap<>();
+    private final static Map<String, String> nightDeptPosMap = new HashMap<>();
     private final RedisLikeDao dao;
 
     public RedisLikeService(RedisLikeDao dao) {
@@ -108,8 +109,23 @@ public class RedisLikeService {
         return deptPos;
     }
 
+    public String getNightDeptPos(String code) {
+        if (StringUtil.isBlank(code)) {
+            return null;
+        }
+        String deptPos = nightDeptPosMap.get(code);
+        if (null == deptPos) {
+            deptPos = dao.selectDeptPosP4(code);
+            if (StringUtil.notBlank(deptPos)) {
+                nightDeptPosMap.put(code, deptPos);
+            }
+        }
+        return deptPos;
+    }
+
     public String clearDeptPos() {
         deptPosMap.clear();
+        nightDeptPosMap.clear();
         return "OK";
     }
 }

+ 19 - 1
src/main/java/thyyxxk/wxservice_server/service/SavePayResultService.java

@@ -11,6 +11,7 @@ import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
 import thyyxxk.wxservice_server.constant.CardCostTypes;
 import thyyxxk.wxservice_server.constant.OrderType;
 import thyyxxk.wxservice_server.dao.CouponDao;
+import thyyxxk.wxservice_server.dao.ImportDrugDao;
 import thyyxxk.wxservice_server.dao.InpatientDao;
 import thyyxxk.wxservice_server.dao.WxApiDao;
 import thyyxxk.wxservice_server.entity.PureCodeName;
@@ -18,6 +19,8 @@ import thyyxxk.wxservice_server.entity.ResultVo;
 import thyyxxk.wxservice_server.entity.coupon.CouponAttribute;
 import thyyxxk.wxservice_server.entity.coupon.CouponFactory;
 import thyyxxk.wxservice_server.entity.coupon.PatientCoupon;
+import thyyxxk.wxservice_server.entity.drugconsult.ImportDrugPurchase;
+import thyyxxk.wxservice_server.entity.drugconsult.PrepayState;
 import thyyxxk.wxservice_server.entity.electronichealthcard.HisRegister;
 import thyyxxk.wxservice_server.entity.inpatient.GetZyFeeParam;
 import thyyxxk.wxservice_server.entity.wxapi.PushMessageParam;
@@ -44,17 +47,19 @@ public class SavePayResultService {
     private final WxApiDao dao;
     private final InpatientDao yjjDao;
     private final CouponDao couponDao;
+    private final ImportDrugDao drugDao;
     private final ThmzService thmzService;
     private final WxRefundService refundService;
     private final PushWxMessageService pushWxMessageService;
     private final ElectronicHealthCardService healthCardService;
 
     @Autowired
-    public SavePayResultService(WxApiDao dao, InpatientDao yjjDao, CouponDao couponDao, ThmzService thmzService, WxRefundService refundService,
+    public SavePayResultService(WxApiDao dao, InpatientDao yjjDao, CouponDao couponDao, ImportDrugDao drugDao, ThmzService thmzService, WxRefundService refundService,
                                 PushWxMessageService pushWxMessageService, ElectronicHealthCardService healthCardService) {
         this.dao = dao;
         this.yjjDao = yjjDao;
         this.couponDao = couponDao;
+        this.drugDao = drugDao;
         this.thmzService = thmzService;
         this.refundService = refundService;
         this.pushWxMessageService = pushWxMessageService;
@@ -243,6 +248,19 @@ public class SavePayResultService {
         return "领取优惠券失败,请联系管理员。";
     }
 
+    public String saveDrugPurchase(WxPayOrder order, String payTime) {
+        ImportDrugPurchase purchase = drugDao.selectById(order.getDrugPurchaseId());
+        if (purchase.getPrepayState() == PrepayState.SUCCESS) {
+            log.info("订单号:{} 的药品申购订金已支付,无需再次保存。", order.getTradeNo());
+            return payTime;
+        }
+        dao.couponUsed(order.getCouponId());
+        purchase.setPrepayState(PrepayState.SUCCESS);
+        drugDao.updateById(purchase);
+        log.info("缴纳药品申购订金成功:{}", JSON.toJSONStringWithDateFormat(order, "yyyy-MM-dd HH:mm:ss"));
+        return payTime;
+    }
+
     public void notifyCytj(WxPayOrder order, String payTime) {
         CytjService cytjService = new CytjService();
         int rescode = cytjService.notifyPaymentSuccess(order, payTime);

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

@@ -193,6 +193,8 @@ public class WxApiService {
                         return "订单已支付。";
                     case COUPON_PURCHASE:
                         return savePayResultService.saveCouponPurchase(order, successTime);
+                    case DRUG_PURCHASE:
+                        return savePayResultService.saveDrugPurchase(order, successTime);
                     default:
                         return "ERROR:未识别到的订单类型,请联系服务中心。";
                 }