Browse Source

增加飞书订单回调

xda 2 years ago
parent
commit
1babdd6a39

+ 33 - 0
src/main/java/com/winhc/repal/controller/CallbackController.java

@@ -0,0 +1,33 @@
+package com.winhc.repal.controller;
+
+import com.winhc.common.base.BeanResponse;
+import com.winhc.common.enums.CodeMsg;
+import com.winhc.repal.model.dto.FsCallbackDTO;
+import com.winhc.repal.service.CallbackService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Description: CallbackController
+ * @Author: xda
+ * @Date: 2022/6/13 09:02
+ */
+@Api("回调")
+@RestController
+@RequestMapping(value = "/callback")
+public class CallbackController {
+
+    @Autowired
+    private CallbackService callbackService;
+
+    @ApiOperation("飞书订单回调")
+    @RequestMapping(value = "/fs", method = RequestMethod.POST)
+    public BeanResponse<Boolean> fsOrderCallback(@RequestBody FsCallbackDTO dto) {
+        return BeanResponse.success(CodeMsg.SUCCESS, callbackService.processFsOrderCallback(dto));
+    }
+}

+ 96 - 0
src/main/java/com/winhc/repal/entity/RepalOrder.java

@@ -0,0 +1,96 @@
+package com.winhc.repal.entity;
+
+import java.math.BigDecimal;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
+
+/**
+ * @description RepalOrder实体对象
+ * @author Generator
+ * @date 2022-06-13
+ */
+@Data
+@Accessors(chain = true)
+@TableName("REPAL_ORDER")
+@ApiModel(value="RepalOrder实体对象", description="回款宝订单表")
+public class RepalOrder implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "主键")
+    @TableId(value = "ID", type = IdType.AUTO)
+    private Long id;
+
+    @ApiModelProperty(value = "第三方组织id")
+    @TableField("THIRD_PARTY_GROUP_ID")
+    private String thirdPartyGroupId;
+
+    @ApiModelProperty(value = "第三方应用id")
+    @TableField("THIRD_PARTY_APP_ID")
+    private String thirdPartyAppId;
+
+    @ApiModelProperty(value = "第三方购买订单id")
+    @TableField("ORDER_ID")
+    private String orderId;
+
+    @ApiModelProperty(value = "付费方案id/订单方案id")
+    @TableField("ORDER_PLAN_ID")
+    private String orderPlanId;
+
+    @ApiModelProperty(value = "用户购买类型")
+    @TableField("ORDER_PLAY_TYPE")
+    private String orderPlayType;
+
+    @ApiModelProperty(value = "购买人份")
+    @TableField("SEATS")
+    private Integer seats;
+
+    @ApiModelProperty(value = "订单创建时间")
+    @TableField("ORDER_TIME_CREATED")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime orderTimeCreated;
+
+    @ApiModelProperty(value = "支付时间")
+    @TableField("PAY_TIME")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime payTime;
+
+    @ApiModelProperty(value = "购买类型。buy普通购买。upgrade升级购买。renew续费购买")
+    @TableField("BUY_TYPE")
+    private String buyType;
+
+    @ApiModelProperty(value = "upgrade时,原订单id")
+    @TableField("SOURCE_ORDER_ID")
+    private String sourceOrderId;
+
+    @ApiModelProperty(value = "支付金额")
+    @TableField("PAY_AMT")
+    private BigDecimal payAmt;
+
+    @ApiModelProperty(value = "创建时间")
+    @TableField("TIME_CREATED")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime timeCreated;
+
+    @TableField("TIME_MODIFIED")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime timeModified;
+
+
+}

+ 42 - 0
src/main/java/com/winhc/repal/enums/FsBuyTypeEnum.java

@@ -0,0 +1,42 @@
+package com.winhc.repal.enums;
+
+/**
+ * @Description: FsBuyTypeEnum
+ * @Author: xda
+ * @Date: 2022/6/13 09:58
+ */
+public enum FsBuyTypeEnum {
+
+    /**
+     * 飞书订单购买类型
+     */
+    BUY("buy", "普通购买"),
+    UPGRADE("upgrade", "升级购买"),
+    RENEW("renew", "续费");
+
+    private final String code;
+
+    private final String msg;
+
+    FsBuyTypeEnum(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public static FsBuyTypeEnum getEnumByCode(String code) {
+        for (FsBuyTypeEnum fsBuyTypeEnum : FsBuyTypeEnum.values()) {
+            if (fsBuyTypeEnum.getCode().equals(code)) {
+                return fsBuyTypeEnum;
+            }
+        }
+        return null;
+    }
+}

+ 58 - 0
src/main/java/com/winhc/repal/model/dto/FsCallbackDTO.java

@@ -0,0 +1,58 @@
+package com.winhc.repal.model.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * @Description: DingTalkCallbackDTO
+ * @Author: xda
+ * @Date: 2022/6/13 09:20
+ */
+@Data
+@ApiModel("飞书订单回调")
+public class FsCallbackDTO {
+
+    @ApiModelProperty(value = "第三方组织id")
+    private String thirdPartyGroupId;
+
+    @ApiModelProperty(value = "第三方应用id")
+    private String thirdPartyAppId;
+
+    @ApiModelProperty(value = "第三方购买订单id")
+    private String orderId;
+
+    @ApiModelProperty(value = "付费方案id/订单方案id")
+    private String orderPlanId;
+
+    @ApiModelProperty(value = "用户购买类型")
+    private String orderPlayType;
+
+    @ApiModelProperty(value = "购买人份")
+    private Integer seats;
+
+    @ApiModelProperty(value = "订单创建时间,string,yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime orderTimeCreated;
+
+    @ApiModelProperty(value = "支付时间string, yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime payTime;
+
+    @ApiModelProperty(value = "购买类型。buy普通购买。upgrade升级购买。renew续费购买")
+    private String buyType;
+
+    @ApiModelProperty(value = "upgrade时,原订单id")
+    private String sourceOrderId;
+
+    @ApiModelProperty(value = "支付金额,元")
+    private BigDecimal payAmt;
+
+}

+ 13 - 0
src/main/java/com/winhc/repal/repository/RepalOrderMapper.java

@@ -0,0 +1,13 @@
+package com.winhc.repal.repository;
+
+import com.winhc.repal.entity.RepalOrder;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * @description RepalOrder Mapper 接口
+ * @author Generator
+ * @date 2022-06-13
+ */
+public interface RepalOrderMapper extends BaseMapper<RepalOrder> {
+
+}

+ 21 - 0
src/main/java/com/winhc/repal/service/CallbackService.java

@@ -0,0 +1,21 @@
+package com.winhc.repal.service;
+
+import com.winhc.repal.model.dto.FsCallbackDTO;
+
+/**
+ * @Description: CallbackService
+ * @Author: xda
+ * @Date: 2022/6/13 09:24
+ */
+public interface CallbackService {
+
+
+    /**
+     * 飞书订单回调处理
+     * @param dto dto
+     * @return java.lang.Boolean
+     * @author xda
+     * @date 2022/6/13 09:31
+     */
+    Boolean processFsOrderCallback(FsCallbackDTO dto);
+}

+ 7 - 25
src/main/java/com/winhc/repal/service/RepalOrderService.java

@@ -1,33 +1,15 @@
 package com.winhc.repal.service;
 
-import com.winhc.common.model.base.VOPage;
-import com.winhc.repal.model.dto.RepalOrderPageDTO;
-import com.winhc.repal.model.vo.RepalOrderVO;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.winhc.repal.entity.RepalOrder;
+
 
 /**
- * @Description: RepalOrderService
- * @Author: xda
- * @Date: 2022/5/19 19:48
+ * @description RepalOrder 接口类
+ * @author Generator
+ * @date 2022-06-13
  */
-public interface RepalOrderService {
-
-
-    /**
-     * 获取回款宝订单
-     * @param dto dto
-     * @return com.winhc.common.model.base.VOPage<com.winhc.repal.model.vo.RepalOrderVO>
-     * @author xda
-     * @date 2022/5/19 20:14
-     */
-    VOPage<RepalOrderVO> getRepalOrderPage(RepalOrderPageDTO dto);
+public interface RepalOrderService extends IService<RepalOrder> {
 
 
-    /**
-     * 获取短信催款详情
-     * @param orderId orderId
-     * @return com.winhc.repal.model.vo.RepalOrderVO
-     * @author xda
-     * @date 2022/5/22 09:05
-     */
-    RepalOrderVO getSmsDetail(String orderId);
 }

+ 52 - 0
src/main/java/com/winhc/repal/service/impl/CallbackServiceImpl.java

@@ -0,0 +1,52 @@
+package com.winhc.repal.service.impl;
+
+import com.winhc.common.enums.CodeMsg;
+import com.winhc.common.exception.CommonException;
+import com.winhc.repal.entity.RepalOrder;
+import com.winhc.repal.enums.FsBuyTypeEnum;
+import com.winhc.repal.model.dto.FsCallbackDTO;
+import com.winhc.repal.service.CallbackService;
+import com.winhc.repal.service.RepalOrderService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Objects;
+
+/**
+ * @Description: CallbackServiceImpl
+ * @Author: xda
+ * @Date: 2022/6/13 09:24
+ */
+@Service
+public class CallbackServiceImpl implements CallbackService {
+
+    @Autowired
+    private RepalOrderService repalOrderService;
+
+    @Override
+    public Boolean processFsOrderCallback(FsCallbackDTO dto) {
+        RepalOrder repalOrder = new RepalOrder();
+        BeanUtils.copyProperties(dto, repalOrder);
+        repalOrderService.save(repalOrder);
+        // 订单处理
+        FsBuyTypeEnum fsBuyTypeEnum = FsBuyTypeEnum.getEnumByCode(dto.getBuyType());
+        if (Objects.isNull(fsBuyTypeEnum)) {
+            throw new CommonException(CodeMsg.FAILED, "购买类型错误");
+        }
+        switch (fsBuyTypeEnum) {
+            case BUY:
+                // 新购买
+                break;
+            case UPGRADE:
+                // 升级
+                break;
+            case RENEW:
+                // 续费
+                break;
+            default:
+                break;
+        }
+        return true;
+    }
+}

+ 7 - 124
src/main/java/com/winhc/repal/service/impl/RepalOrderServiceImpl.java

@@ -1,134 +1,17 @@
 package com.winhc.repal.service.impl;
 
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.StrUtil;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.TypeReference;
-import com.module.login.usersession.UserBean;
-import com.winhc.common.base.BeanResponse;
-import com.winhc.common.model.base.VOPage;
-import com.winhc.repal.cloud.WinCoinService;
-import com.winhc.repal.cloud.vo.WinCoinOrderFormVO;
-import com.winhc.repal.enums.RepalDynamicTypeEnum;
-import com.winhc.repal.model.dto.RepalOrderPageDTO;
-import com.winhc.repal.model.vo.RepalLinkVO;
-import com.winhc.repal.model.vo.RepalOrderVO;
-import com.winhc.repal.service.RepalDynamicService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.winhc.repal.entity.RepalOrder;
+import com.winhc.repal.repository.RepalOrderMapper;
 import com.winhc.repal.service.RepalOrderService;
-import com.winhc.repal.util.UserContextUtil;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.*;
-import java.util.stream.Collectors;
-
 /**
- * @Description: RepalOrderServiceImpl
- * @Author: xda
- * @Date: 2022/5/19 19:48
+ * @description RepalOrder 接口实现类
+ * @author Generator
+ * @date 2022-06-13
  */
 @Service
-public class RepalOrderServiceImpl implements RepalOrderService {
-
-    @Autowired
-    private RepalDynamicService repalDynamicService;
-
-    @Autowired
-    private WinCoinService winCoinService;
-
-    @Override
-    public VOPage<RepalOrderVO> getRepalOrderPage(RepalOrderPageDTO dto) {
-        dto.setUserId(UserContextUtil.getUser().getUserId());
-        VOPage<RepalOrderVO> voPage = new VOPage<>();
-        voPage.setPageNum(dto.getPageNum());
-        voPage.setPageSize(dto.getPageSize());
-        BeanResponse<VOPage<WinCoinOrderFormVO>> beanResponse = winCoinService.getRepalOrderPage(dto);
-        if (Objects.isNull(beanResponse) || Objects.isNull(beanResponse.getBody()) || CollUtil.isEmpty(beanResponse.getBody().getDataList())) {
-            return voPage;
-        }
-        voPage.setTotalPage(beanResponse.getBody().getTotalPage());
-        voPage.setTotalNum(beanResponse.getBody().getTotalNum());
-        List<RepalOrderVO> voList = new ArrayList<>();
-        for (WinCoinOrderFormVO orderFormVO : beanResponse.getBody().getDataList()) {
-            RepalOrderVO vo = new RepalOrderVO();
-            LocalDateTime.parse(DateUtil.format(orderFormVO.getOrderTime(), "yyyy-MM-dd HH:mm:ss"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-            vo.setOrderTime(LocalDateTime.parse(DateUtil.format(orderFormVO.getOrderTime(), "yyyy-MM-dd HH:mm:ss"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
-            vo.setOrderId(orderFormVO.getOrderId());
-            vo.setStatus(orderFormVO.getStatus());
-            Map<String, String> map = JSONObject.parseObject(orderFormVO.getGoodsJson(), new TypeReference<HashMap<String, String>>(){});
-            // 短信催款
-            if ("sms_repal".equals(orderFormVO.getProductCode())) {
-                vo.setOrderType(RepalDynamicTypeEnum.短信.getCode());
-                vo.setCustName(String.valueOf(map.get("company")));
-                List<RepalLinkVO> links = JSONObject.parseObject(map.get("links"), new TypeReference<List<RepalLinkVO>>(){});
-                if (CollUtil.isNotEmpty(links)) {
-                    vo.setLinkman(links.stream().map(RepalLinkVO::getName).collect(Collectors.joining(",")));
-                }
-            }
-            // 律师函
-            if ("303".equals(orderFormVO.getProductCode())) {
-                vo.setOrderType(RepalDynamicTypeEnum.律师函.getCode());
-                vo.setCustName(String.valueOf(map.get("company")));
-                List<RepalLinkVO> links = JSONObject.parseObject(map.get("links"), new TypeReference<List<RepalLinkVO>>(){});
-                if (CollUtil.isNotEmpty(links)) {
-                    vo.setLinkman(links.stream().map(RepalLinkVO::getName).collect(Collectors.joining(",")));
-                }
-            }
-            // 咨询
-            if ("phone_consult".equals(orderFormVO.getProductCode())) {
-                vo.setOrderType(RepalDynamicTypeEnum.咨询.getCode());
-                vo.setServiceDesc(map.get("serviceDesc"));
-                vo.setServiceType(Integer.valueOf(map.get("serviceType")));
-                vo.setLawyerServiceSubType(Integer.valueOf(map.get("lawyerServiceSubType")));
-                vo.setLawyerServiceType(Integer.valueOf(map.get("lawyerServiceType")));
-            }
-            // 诉讼
-            if ("203".equals(orderFormVO.getProductCode()) || "205".equals(orderFormVO.getProductCode())) {
-                vo.setOrderType(RepalDynamicTypeEnum.诉讼.getCode());
-                vo.setServiceDesc(map.get("serviceDesc"));
-                if (StrUtil.isNotBlank(map.get("lawyerServiceSubType"))) {
-                    vo.setLawyerServiceSubType(Integer.valueOf(map.get("lawyerServiceSubType")));
-                }
-                if (StrUtil.isNotBlank(map.get("lawyerServiceType"))) {
-                    vo.setLawyerServiceType(Integer.valueOf(map.get("lawyerServiceType")));
-                }
-                vo.setCaseAmtStr(map.get("caseAmt"));
-                if (StrUtil.isNotBlank(map.get("caseStage"))) {
-                    vo.setCaseStage(Integer.valueOf(map.get("caseStage")));
-                }
-            }
-            voList.add(vo);
-        }
-        voPage.setDataList(voList);
-        return voPage;
-    }
-
-    @Override
-    public RepalOrderVO getSmsDetail(String orderId) {
-        UserBean userBean = new UserBean();
-        userBean.setUserId(UserContextUtil.getUser().getUserId());
-        BeanResponse<WinCoinOrderFormVO> beanResponse = winCoinService.getOrderForm(JSON.toJSONString(userBean), orderId);
-        if (Objects.isNull(beanResponse) || Objects.isNull(beanResponse.getBody())) {
-            return null;
-        }
-        RepalOrderVO vo = new RepalOrderVO();
-        LocalDateTime.parse(DateUtil.format(beanResponse.getBody().getOrderTime(), "yyyy-MM-dd HH:mm:ss"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+public class RepalOrderServiceImpl extends ServiceImpl<RepalOrderMapper, RepalOrder> implements RepalOrderService {
 
-        vo.setOrderTime(LocalDateTime.parse(DateUtil.format(beanResponse.getBody().getOrderTime(), "yyyy-MM-dd HH:mm:ss"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
-        vo.setOrderId(beanResponse.getBody().getOrderId());
-        vo.setStatus(beanResponse.getBody().getStatus());
-        vo.setOrderType("sms_repal".equals(beanResponse.getBody().getProductCode()) ? RepalDynamicTypeEnum.短信.getCode() : RepalDynamicTypeEnum.律师函.getCode());
-        Map<String, String> map = JSONObject.parseObject(beanResponse.getBody().getGoodsJson(), new TypeReference<HashMap<String, String>>(){});
-        vo.setCustName(String.valueOf(map.get("company")));
-        List<RepalLinkVO> links = JSONObject.parseObject(map.get("links"), new TypeReference<List<RepalLinkVO>>(){});
-        if (CollUtil.isNotEmpty(links)) {
-            vo.setLinks(links);
-        }
-        vo.setSmsDesc(map.get("content"));
-        return vo;
-    }
 }

+ 5 - 0
src/main/resources/mapper/RepalOrderMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.winhc.repal.repository.RepalOrderMapper">
+
+</mapper>