Browse Source

提供微信支付,查询,退款的接口给自助机和体检

lighter 4 years ago
parent
commit
dc9ea82d55

+ 1 - 1
pom.xml

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

+ 22 - 5
src/main/java/thyyxxk/wxservice_server/controller/WxApiController.java

@@ -1,39 +1,41 @@
 package thyyxxk.wxservice_server.controller;
 
-import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import thyyxxk.wxservice_server.entity.ResultVo;
+import thyyxxk.wxservice_server.entity.appointment.DoctorInfo;
 import thyyxxk.wxservice_server.entity.appointment.WeChatPayParam;
 import thyyxxk.wxservice_server.entity.wxapi.*;
+import thyyxxk.wxservice_server.service.AutoRefundService;
 import thyyxxk.wxservice_server.service.PushWxMessageService;
 import thyyxxk.wxservice_server.service.WxApiService;
 import thyyxxk.wxservice_server.utils.PropertiesUtil;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
 import java.util.concurrent.ExecutionException;
 
 /**
  * @author dj
  */
-@Slf4j
 @RestController
 @RequestMapping("/wxApi")
 public class WxApiController {
     private final WxApiService service;
+    private final AutoRefundService refundService;
     private final PushWxMessageService pushWxMessageService;
 
     @Autowired
-    public WxApiController(WxApiService payService, PushWxMessageService pushWxMessageService) {
+    public WxApiController(WxApiService payService, AutoRefundService refundService, PushWxMessageService pushWxMessageService) {
         this.service = payService;
+        this.refundService = refundService;
         this.pushWxMessageService = pushWxMessageService;
     }
 
     @GetMapping("/synchronizeAccessToken")
     public ResultVo<String> synchronizeAccessToken(@RequestParam("token") String token) {
-        log.info("同步本地服务与线上服务公众号ACCESS_TOKEN:{}", token);
         PropertiesUtil.writeAccessToken("access_token", token);
         return ResultVoUtil.success("同步成功。");
     }
@@ -55,7 +57,6 @@ public class WxApiController {
 
     @GetMapping("/queryOrderState")
     public ResultVo<String> queryOrderState(@RequestParam("tradeNo") String tradeNo) throws Exception {
-        log.info("前端回调查询订单状态:{}", tradeNo);
         return service.queryOrderState(tradeNo).get();
     }
 
@@ -68,4 +69,20 @@ public class WxApiController {
     public void pushMessage(@RequestBody @Validated PushMessageParam param) {
         pushWxMessageService.pushMessage(param);
     }
+
+    @PostMapping("/getWxPayQrcode")
+    public ResultVo<Map<String, String>> getWxPayQrcode(@RequestBody WxPyQrcdPrm prm) throws Exception {
+        return service.getWxPayQrcode(prm);
+    }
+
+    @PostMapping("/refund")
+    public ResultVo<String> refund(@RequestBody @Validated RfndPrm prm) {
+        return refundService.refund(prm);
+    }
+
+    @GetMapping("/getDoctorInfo")
+    public ResultVo<DoctorInfo> getDoctorInfo(@RequestParam("doctorCode") String doctorCode) {
+        return service.getDoctorInfo(doctorCode);
+    }
+
 }

+ 4 - 1
src/main/java/thyyxxk/wxservice_server/dao/AppointmentDao.java

@@ -58,6 +58,9 @@ public interface AppointmentDao {
     void updateWxBindSocialNo(@Param("patientId") String patientId,
                                @Param("socialNo") String socialNo);
 
-    @Select("select isnull(portrait,'') as code,isnull(introduction,'') as name from a_employee_mi where code=#{code}")
+//    @Select("select isnull(portrait,'') as code,isnull(introduction,'') as name from a_employee_mi where code=#{code}")
+//    PureCodeName selectPortraitAndIntroduction(@Param("code") String code);
+
+    @Select("select '' as code,isnull(introduction,'') as name from a_employee_mi where code=#{code}")
     PureCodeName selectPortraitAndIntroduction(@Param("code") String code);
 }

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

@@ -1,6 +1,7 @@
 package thyyxxk.wxservice_server.dao;
 
 import org.apache.ibatis.annotations.*;
+import thyyxxk.wxservice_server.entity.appointment.DoctorInfo;
 import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
 
 import java.util.List;
@@ -57,4 +58,20 @@ public interface WxApiDao {
 
     @Update("update t_wechat_pay_order set query_state_times=(isnull(query_state_times,0)+1) where trade_no=#{tradeNo}")
     void incrementQueryTimesByTradeNo(@Param("tradeNo") String tradeNo);
+
+    @Select("select " +
+            "rtrim(a.code) doctorCode, " +
+            "rtrim(a.name) doctorName, " +
+            "rtrim(b.name) doctorTitle, " +
+            "rtrim(a.dept_code) deptCode, " +
+            "deptName=(select rtrim(name) from zd_unit_code where code=a.dept_code), " +
+            "a.specialty, " +
+            "a.introduction, " +
+            "a.portrait " +
+            "from a_employee_mi a, zd_emp_title b " +
+            "where a.code=#{doctorCode} and " +
+            "a.emp_tit_code=b.code and " +
+            "a.code not in ('00000', '00026') and " +
+            "isnull(a.del_flag,0)<>1")
+    DoctorInfo selectDoctorInfo(@Param("doctorCode") String doctorCode);
 }

+ 20 - 0
src/main/java/thyyxxk/wxservice_server/entity/wxapi/RfndPrm.java

@@ -0,0 +1,20 @@
+package thyyxxk.wxservice_server.entity.wxapi;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @description: 退款参数
+ * @author: DingJie
+ * @create: 2021/8/511:04
+ */
+@Data
+public class RfndPrm {
+
+    @NotBlank(message = "订单号不能为空。")
+    private String tradeNo;
+
+    @NotBlank(message = "退款原因不能为空。")
+    private String refundReason;
+}

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

@@ -15,7 +15,7 @@ public class WxPayOrder {
     private Integer id;
     private String body;
     /**
-     * 订单类型,1:挂号费 2:门诊缴费 3:住院预交金
+     * 订单类型,1:挂号费 2:门诊缴费 3:住院预交金 4:自助机缴费 5:体检缴费
      * */
     private Integer orderType;
     private String openId;

+ 24 - 0
src/main/java/thyyxxk/wxservice_server/entity/wxapi/WxPyQrcdPrm.java

@@ -0,0 +1,24 @@
+package thyyxxk.wxservice_server.entity.wxapi;
+
+import lombok.Data;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @description: 自助机获取微信支付二维码参数
+ * @author: DingJie
+ * @create: 2021/8/510:47
+ */
+@Data
+public class WxPyQrcdPrm {
+    @Min(value = 0, message = "总金额需要大于零。")
+    private Integer totalAmt;
+    @NotBlank(message = "门诊id号不能为空。")
+    private String patientId;
+    @NotBlank(message = "订单描述不能为空。")
+    private String description;
+    @NotNull(message = "订单类型不能为空。")
+    private Integer orderType;
+}

+ 26 - 0
src/main/java/thyyxxk/wxservice_server/service/AutoRefundService.java

@@ -8,6 +8,7 @@ import org.springframework.web.client.RestTemplate;
 import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
 import thyyxxk.wxservice_server.dao.WxApiDao;
 import thyyxxk.wxservice_server.entity.ResultVo;
+import thyyxxk.wxservice_server.entity.wxapi.RfndPrm;
 import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
 import thyyxxk.wxservice_server.utils.DateUtil;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
@@ -54,4 +55,29 @@ public class AutoRefundService {
         return resultVo;
     }
 
+    public ResultVo<String> refund(RfndPrm prm) {
+        log.info("自助机退款:{}", prm);
+        WxPayOrder order = dao.selectOrderByTradeNo(prm.getTradeNo());
+        if (null == order) {
+            log.info("退款失败,未找到订单号为【{}】的订单。", prm.getTradeNo());
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到符合订单号的订单。");
+        }
+        String url = "http://webhis.thyy.cn:8706/wxRefund/refundOrder";
+        JSONObject param = new JSONObject();
+        param.put("id", order.getId());
+        param.put("refundOpDatetime", DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss"));
+        param.put("totalFee", order.getTotalFee());
+        param.put("tradeNo", prm.getTradeNo());
+        param.put("refundOpCode", "slf_srvc_mchn");
+        param.put("refundReason", prm.getRefundReason());
+        RestTemplate template = new RestTemplate();
+        ResultVo<String> resultVo;
+        try {
+            resultVo = template.postForObject(url, param, ResultVo.class);
+        } catch (Exception e) {
+            resultVo = ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR);
+        }
+        return resultVo;
+    }
+
 }

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

@@ -20,10 +20,12 @@ import org.springframework.web.client.RestTemplate;
 import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
 import thyyxxk.wxservice_server.dao.WxApiDao;
 import thyyxxk.wxservice_server.entity.ResultVo;
+import thyyxxk.wxservice_server.entity.appointment.DoctorInfo;
 import thyyxxk.wxservice_server.entity.appointment.WeChatPayParam;
 import thyyxxk.wxservice_server.entity.wxapi.JsApiSHA1;
 import thyyxxk.wxservice_server.entity.wxapi.GenMzPayQrcodeParam;
 import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
+import thyyxxk.wxservice_server.entity.wxapi.WxPyQrcdPrm;
 import thyyxxk.wxservice_server.utils.*;
 
 import java.nio.charset.StandardCharsets;
@@ -208,6 +210,9 @@ public class WxApiService {
                 case 3:
                     saveRet = savePayResultService.saveZyYjjInfo(order);
                     break;
+                case 4:
+                    saveRet = ResultVoUtil.success("订单已支付。");
+                    break;
                 default:
                     log.info("未识别到的订单类型:{},订单号:{}", order.getOrderType(), tradeNo);
                     saveRet = ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未识别到的订单类型,请联系服务中心。");
@@ -307,4 +312,70 @@ public class WxApiService {
         log.error("请求门诊指引单二维码失败:{}", ret);
         return CompletableFuture.completedFuture(ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请求微信支付二维码失败,请联系管理员。"));
     }
+
+    public ResultVo<Map<String, String>> getWxPayQrcode(WxPyQrcdPrm prm) throws Exception {
+        String patName = dao.selectPatientName(prm.getPatientId());
+        if (null == patName) {
+            return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有找到患者信息,请检查patientId是否正确!");
+        }
+        String outTradeNo = SnowFlakeId.instance().nextId();
+        JSONObject body = new JSONObject();
+        body.put("appid", PropertiesUtil.getProperty("appId"));
+        body.put("mchid", PropertiesUtil.getProperty("mchId"));
+        body.put("description", prm.getDescription());
+        body.put("attach", prm.getDescription());
+        body.put("out_trade_no", outTradeNo);
+        body.put("notify_url", PropertiesUtil.getProperty("notifyUrl"));
+        JSONObject cny = new JSONObject();
+        cny.put("total", prm.getTotalAmt());
+        cny.put("currency", "CNY");
+        body.put("amount", cny);
+        String reqdata = JSONObject.toJSONString(body);
+        HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/native");
+        StringEntity entity = new StringEntity(reqdata, StandardCharsets.UTF_8);
+        entity.setContentEncoding("UTF-8");
+        entity.setContentType("application/json");
+        httpPost.setEntity(entity);
+        httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
+        httpPost.addHeader("Accept", "application/json");
+        //完成签名并执行请求
+        CloseableHttpClient httpClient = WxHttpUtil.getClosableHttpClient();
+        CloseableHttpResponse response = httpClient.execute(httpPost);
+        int statusCode = response.getStatusLine().getStatusCode();
+        String ret = EntityUtils.toString(response.getEntity());
+        httpClient.close();
+        log.info("请求微信支付二维码:{},结果:{}", prm, ret);
+        if (statusCode == ExceptionEnum.SUCCESS.getCode()) {
+            long timesStamp = System.currentTimeMillis() / 1000;
+            WxPayOrder order = new WxPayOrder();
+            order.setAppId(PropertiesUtil.getProperty("appId"));
+            order.setBody(prm.getOrderType() == 4 ? "自助机缴费" : "体检缴费");
+            order.setOpenId("");
+            order.setTotalFee(DecimalTool.moneyFenToYuan(prm.getTotalAmt()));
+            order.setPatientId(prm.getPatientId());
+            order.setPatientName(patName);
+            order.setMchId(PropertiesUtil.getProperty("mchId"));
+            order.setTimeStamp(String.valueOf(timesStamp));
+            order.setTradeNo(outTradeNo);
+            order.setCreateDatetime(new Date());
+            order.setPayStatus(0);
+            order.setSerialNo(SnowFlakeId.instance().nextId());
+            order.setOrderType(4);
+            dao.insertNewOrder(order);
+            JSONObject retObj = JSONObject.parseObject(ret);
+            Map<String, String> map = new HashMap<>();
+            map.put("qrcodeUrl", retObj.getString("code_url"));
+            map.put("tradeNo", outTradeNo);
+            return ResultVoUtil.success(map);
+        }
+        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请求微信支付二维码失败,请联系管理员。");
+    }
+
+    public ResultVo<DoctorInfo> getDoctorInfo(String doctorCode) {
+        DoctorInfo doctorInfo = dao.selectDoctorInfo(doctorCode);
+        if (null == doctorInfo) {
+            return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "未找到医生信息!");
+        }
+        return ResultVoUtil.success(doctorInfo);
+    }
 }

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

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

+ 2 - 2
src/main/resources/application.yml

@@ -8,8 +8,8 @@ spring:
   thymeleaf:
     cache: false
   datasource:
-#    url: jdbc:jtds:sqlserver://172.16.32.179:1433/thxyhisdb
-    url: jdbc:jtds:sqlserver://172.16.32.168:1433/thxyhisdb
+    url: jdbc:jtds:sqlserver://172.16.32.179:1433/thxyhisdb
+#    url: jdbc:jtds:sqlserver://172.16.32.168:1433/thxyhisdb
     hikari:
       username: sa
       password: