Commit b586a09b90a854879c7db01e8e3e26beecfafbcd

Authored by 芋道源码
Committed by Gitee
2 parents e95f69b6 8da08072

!1011 新增 mall 客服

Merge pull request !1011 from 芋道源码/develop
Showing 58 changed files with 1837 additions and 176 deletions
... ... @@ -16,12 +16,12 @@
16 16 <module>yudao-module-system</module>
17 17 <module>yudao-module-infra</module>
18 18 <!-- <module>yudao-module-member</module>-->
19   -<!-- <module>yudao-module-bpm</module>-->
  19 + <module>yudao-module-bpm</module>
20 20 <!-- <module>yudao-module-report</module>-->
21 21 <!-- <module>yudao-module-mp</module>-->
22 22 <!-- <module>yudao-module-pay</module>-->
23 23 <!-- <module>yudao-module-mall</module>-->
24   -<!-- <module>yudao-module-crm</module>-->
  24 + <module>yudao-module-crm</module>
25 25 <!-- <module>yudao-module-erp</module>-->
26 26 <!-- <module>yudao-module-ai</module>-->
27 27 </modules>
... ...
sql/mysql/mall-promotion-kefu.sql 0 → 100644
  1 +DROP TABLE IF EXISTS `promotion_kefu_conversation`;
  2 +CREATE TABLE `promotion_kefu_conversation` (
  3 + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
  4 + `user_id` bigint NOT NULL COMMENT '会话所属用户',
  5 + `last_message_time` datetime NOT NULL COMMENT '最后聊天时间',
  6 + `last_message_content` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '最后聊天内容',
  7 + `last_message_content_type` int NOT NULL COMMENT '最后发送的消息类型',
  8 + `admin_pinned` bit(1) NOT NULL DEFAULT b'0' COMMENT '管理端置顶',
  9 + `user_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '用户是否可见',
  10 + `admin_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '管理员是否可见',
  11 + `admin_unread_message_count` int NOT NULL COMMENT '管理员未读消息数',
  12 + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
  13 + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  14 + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
  15 + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  16 + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  17 + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  18 + PRIMARY KEY (`id`) USING BTREE
  19 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='客服会话';
  20 +
  21 +DROP TABLE IF EXISTS `promotion_kefu_message`;
  22 +CREATE TABLE `promotion_kefu_message` (
  23 + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
  24 + `conversation_id` bigint NOT NULL COMMENT '会话编号',
  25 + `sender_id` bigint NOT NULL COMMENT '发送人编号',
  26 + `sender_type` int NOT NULL COMMENT '发送人类型',
  27 + `receiver_id` bigint DEFAULT NULL COMMENT '接收人编号',
  28 + `receiver_type` int DEFAULT NULL COMMENT '接收人类型',
  29 + `content_type` int NOT NULL COMMENT '消息类型',
  30 + `content` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '消息',
  31 + `read_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已读',
  32 + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
  33 + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  34 + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
  35 + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  36 + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  37 + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  38 + PRIMARY KEY (`id`) USING BTREE
  39 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='客服消息';
0 40 \ No newline at end of file
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/performance/CrmStatisticsPerformanceReqVO.java
... ... @@ -33,7 +33,6 @@ public class CrmStatisticsPerformanceReqVO {
33 33 @Schema(description = "负责人用户 id 集合", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "2")
34 34 private List<Long> userIds;
35 35  
36   - // TODO @scholar:应该传递的是 int year;年份
37 36 @Schema(description = "时间范围", requiredMode = Schema.RequiredMode.REQUIRED)
38 37 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
39 38 @NotEmpty(message = "时间范围不能为空")
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java
1 1 package cn.iocoder.yudao.module.crm.service.statistics;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4   -import cn.hutool.core.collection.ListUtil;
5   -import cn.hutool.core.date.LocalDateTimeUtil;
6 4 import cn.hutool.core.util.ObjUtil;
7 5 import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO;
8 6 import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO;
... ... @@ -11,16 +9,20 @@ import cn.iocoder.yudao.module.system.api.dept.DeptApi;
11 9 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
12 10 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
13 11 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
  12 +import jakarta.annotation.Resource;
14 13 import org.springframework.stereotype.Service;
15 14 import org.springframework.validation.annotation.Validated;
16 15  
17   -import jakarta.annotation.Resource;
18   -
19 16 import java.math.BigDecimal;
20   -import java.util.*;
  17 +import java.time.LocalDateTime;
  18 +import java.util.ArrayList;
  19 +import java.util.Collections;
  20 +import java.util.List;
  21 +import java.util.Map;
21 22 import java.util.function.Function;
22 23  
23 24 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
  25 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
24 26  
25 27 /**
26 28 * CRM 员工业绩分析 Service 实现类
... ... @@ -41,10 +43,6 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
41 43  
42 44 @Override
43 45 public List<CrmStatisticsPerformanceRespVO> getContractCountPerformance(CrmStatisticsPerformanceReqVO performanceReqVO) {
44   - // TODO @scholar:可以把下面这个注释,你理解后,重新整理下,写到 getPerformance 里;
45   - // 比如说,2024 年的合同数据,是不是 2022-12 到 2024-12-31,每个月的统计呢?
46   - // 理解之后,我们可以数据 group by 年-月,20222-12 到 2024-12-31 的,然后内存在聚合出 CrmStatisticsPerformanceRespVO 这样
47   - // 这样,我们就可以减少数据库的计算量,提升性能;同时 SQL 也会很简单,开发者理解起来也简单哈;
48 46 return getPerformance(performanceReqVO, performanceMapper::selectContractCountPerformance);
49 47 }
50 48  
... ... @@ -58,99 +56,45 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
58 56 return getPerformance(performanceReqVO, performanceMapper::selectReceivablePricePerformance);
59 57 }
60 58  
61   - // TODO @scholar:代码注释,应该有 3 个变量哈;
62 59 /**
63 60 * 获得员工业绩数据
64 61 *
  62 + * 1. 获得今年 + 去年的数据
  63 + * 2. 遍历今年的月份,逐个拼接去年的月份数据
  64 + *
65 65 * @param performanceReqVO 参数
66 66 * @param performanceFunction 员工业绩统计方法
67 67 * @return 员工业绩数据
68 68 */
69   - // TODO @scholar:下面一行的变量,超过一行了,阅读不美观;可以考虑每一行一个变量;
70   - private List<CrmStatisticsPerformanceRespVO> getPerformance(CrmStatisticsPerformanceReqVO performanceReqVO, Function<CrmStatisticsPerformanceReqVO,
71   - List<CrmStatisticsPerformanceRespVO>> performanceFunction) {
72   -
73   - // TODO @scholar:没使用到的变量,建议删除;
74   - List<CrmStatisticsPerformanceRespVO> performanceRespVOList;
  69 + private List<CrmStatisticsPerformanceRespVO> getPerformance(CrmStatisticsPerformanceReqVO performanceReqVO,
  70 + Function<CrmStatisticsPerformanceReqVO, List<CrmStatisticsPerformanceRespVO>> performanceFunction) {
75 71  
76 72 // 1. 获得用户编号数组
77   - final List<Long> userIds = getUserIds(performanceReqVO);
  73 + List<Long> userIds = getUserIds(performanceReqVO);
78 74 if (CollUtil.isEmpty(userIds)) {
79 75 return Collections.emptyList();
80 76 }
81 77 performanceReqVO.setUserIds(userIds);
82   - // TODO @scholar:1. 和 2. 之间,可以考虑换一行;保证每一块逻辑的间隔;
83   - // 2. 获得业绩数据
84   - // TODO @scholar:复数变量,建议使用 s 或者 list 结果;这里用 performanceList 好列;
85   - List<CrmStatisticsPerformanceRespVO> performance = performanceFunction.apply(performanceReqVO);
86   -
87   - // 获取查询的年份
88   - // TODO @scholar:逻辑可以简化一下;
89   - // TODO 1)把 performance 转换成 map;key 是 time,value 是 count
90   - // TODO 2)当前年,遍历 1-12 月份,去 map 拿到 count;接着月份 -1,去 map 拿 count;再年份 -1,拿 count
91   - String currentYear = LocalDateTimeUtil.format(performanceReqVO.getTimes()[0],"yyyy");
92   -
93   - // 构造查询当年和前一年,每年12个月的年月组合
94   - List<String> allMonths = new ArrayList<>();
95   - for (int year = Integer.parseInt(currentYear)-1; year <= Integer.parseInt(currentYear); year++) {
96   - for (int month = 1; month <= 12; month++) {
97   - allMonths.add(String.format("%d%02d", year, month));
98   - }
99   - }
100   -
101   - List<CrmStatisticsPerformanceRespVO> computedList = new ArrayList<>();
102   - List<CrmStatisticsPerformanceRespVO> respVOList = new ArrayList<>();
103   -
104   - // 生成computedList基础数据
105   - // 构造完整的2*12个月的数据,如果某月数据缺失,需要补上0,一年12个月不能有缺失
106   - for (String month : allMonths) {
107   - CrmStatisticsPerformanceRespVO foundData = performance.stream()
108   - .filter(data -> data.getTime().equals(month))
109   - .findFirst()
110   - .orElse(null);
111   -
112   - if (foundData != null) {
113   - computedList.add(foundData);
114   - } else {
115   - CrmStatisticsPerformanceRespVO missingData = new CrmStatisticsPerformanceRespVO();
116   - missingData.setTime(month);
117   - missingData.setCurrentMonthCount(BigDecimal.ZERO);
118   - missingData.setLastMonthCount(BigDecimal.ZERO);
119   - missingData.setLastYearCount(BigDecimal.ZERO);
120   - computedList.add(missingData);
121   - }
122   - }
123   - //根据查询年份和前一年的数据,计算查询年份的同比环比数据
124   - for (CrmStatisticsPerformanceRespVO currentData : computedList) {
125   - String currentMonth = currentData.getTime();
126   -
127   - // 根据当年和前一年的月销售数据,计算currentYear的完整数据
128   - if (currentMonth.startsWith(currentYear)) {
129   - // 计算 LastMonthCount
130   - int currentIndex = computedList.indexOf(currentData);
131   - if (currentIndex > 0) {
132   - CrmStatisticsPerformanceRespVO lastMonthData = computedList.get(currentIndex - 1);
133   - currentData.setLastMonthCount(lastMonthData.getCurrentMonthCount());
134   - } else {
135   - currentData.setLastMonthCount(BigDecimal.ZERO); // 第一个月的 LastMonthCount 设为0
136   - }
137 78  
138   - // 计算 LastYearCount
139   - String lastYearMonth = String.valueOf(Integer.parseInt(currentMonth) - 100);
140   - CrmStatisticsPerformanceRespVO lastYearData = computedList.stream()
141   - .filter(data -> data.getTime().equals(lastYearMonth))
142   - .findFirst()
143   - .orElse(null);
144   -
145   - if (lastYearData != null) {
146   - currentData.setLastYearCount(lastYearData.getCurrentMonthCount());
147   - } else {
148   - currentData.setLastYearCount(BigDecimal.ZERO); // 如果去年同月数据不存在,设为0
149   - }
150   - respVOList.add(currentData);//给前端只需要返回查询当年的数据,不需要前一年数据
151   - }
  79 + // 2. 获得业绩数据
  80 + int year = performanceReqVO.getTimes()[0].getYear(); // 获取查询的年份
  81 + performanceReqVO.getTimes()[0] = performanceReqVO.getTimes()[0].minusYears(1);
  82 + List<CrmStatisticsPerformanceRespVO> performanceList = performanceFunction.apply(performanceReqVO);
  83 + Map<String, BigDecimal> performanceMap = convertMap(performanceList, CrmStatisticsPerformanceRespVO::getTime,
  84 + CrmStatisticsPerformanceRespVO::getCurrentMonthCount);
  85 +
  86 + // 3. 组装数据返回
  87 + List<CrmStatisticsPerformanceRespVO> result = new ArrayList<>();
  88 + for (int month = 1; month <= 12; month++) {
  89 + String currentMonth = String.format("%d%02d", year, month);
  90 + String lastMonth = month == 1 ? String.format("%d%02d", year - 1, 12) : String.format("%d%02d", year, month - 1);
  91 + String lastYear = String.format("%d%02d", year - 1, month);
  92 + result.add(new CrmStatisticsPerformanceRespVO().setTime(currentMonth)
  93 + .setCurrentMonthCount(performanceMap.getOrDefault(currentMonth, BigDecimal.ZERO))
  94 + .setLastMonthCount(performanceMap.getOrDefault(lastMonth, BigDecimal.ZERO))
  95 + .setLastYearCount(performanceMap.getOrDefault(lastYear, BigDecimal.ZERO)));
152 96 }
153   - return respVOList;
  97 + return result;
154 98 }
155 99  
156 100 /**
... ... @@ -162,7 +106,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
162 106 private List<Long> getUserIds(CrmStatisticsPerformanceReqVO reqVO) {
163 107 // 情况一:选中某个用户
164 108 if (ObjUtil.isNotNull(reqVO.getUserId())) {
165   - return ListUtil.of(reqVO.getUserId());
  109 + return List.of(reqVO.getUserId());
166 110 }
167 111 // 情况二:选中某个部门
168 112 // 2.1 获得部门列表
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPerformanceMapper.xml
... ... @@ -9,51 +9,47 @@
9 9 COUNT(1) AS currentMonthCount
10 10 FROM crm_contract
11 11 WHERE deleted = 0
12   - <!-- TODO @scholar:20 改成静态类引入 -->
13   - AND audit_status = 20
  12 + AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
14 13 AND owner_user_id in
15 14 <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
16 15 #{userId}
17 16 </foreach>
18   - <!-- TODO @scholar:CrmStatisticsPerformanceReqVO 传递 year,然后 java 代码里,转换出 times;这样,order_time 使用范围查询,避免使用函数 -->
19   - AND (DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime}, '%Y')
20   - or DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime}, '%Y') - 1)
  17 + AND order_date between #{times[0],javaType=java.time.LocalDateTime} and
  18 + #{times[1],javaType=java.time.LocalDateTime}
21 19 GROUP BY time
22 20 </select>
23 21  
24   - <!-- TODO @scholar:参考上面,调整下这个 SQL 的排版、和代码建议哈 -->
25 22 <select id="selectContractPricePerformance"
26 23 resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
27 24 SELECT
28   - DATE_FORMAT(order_date, '%Y%m') AS time,
29   - IFNULL(SUM(total_price), 0) AS currentMonthCount
30   - FROM crm_contract
  25 + DATE_FORMAT(order_date, '%Y%m') AS time,
  26 + IFNULL(SUM(total_price), 0) AS currentMonthCount
  27 + FROM crm_contract
31 28 WHERE deleted = 0
32   - AND audit_status = 20
  29 + AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
33 30 AND owner_user_id in
34   - <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
35   - #{userId}
36   - </foreach>
37   - AND (DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')
38   - or DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')-1)
  31 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  32 + #{userId}
  33 + </foreach>
  34 + AND order_date between #{times[0],javaType=java.time.LocalDateTime} and
  35 + #{times[1],javaType=java.time.LocalDateTime}
39 36 GROUP BY time
40 37 </select>
41 38  
42   - <!-- TODO @scholar:参考上面,调整下这个 SQL 的排版、和代码建议哈 -->
43 39 <select id="selectReceivablePricePerformance"
44 40 resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
45 41 SELECT
46   - DATE_FORMAT(return_time, '%Y%m') AS time,
47   - IFNULL(SUM(price), 0) AS currentMonthCount
48   - FROM crm_receivable
  42 + DATE_FORMAT(return_time, '%Y%m') AS time,
  43 + IFNULL(SUM(price), 0) AS currentMonthCount
  44 + FROM crm_receivable
49 45 WHERE deleted = 0
50   - AND audit_status = 20
  46 + AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
51 47 AND owner_user_id in
52   - <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
53   - #{userId}
54   - </foreach>
55   - AND (DATE_FORMAT(return_time, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')
56   - or DATE_FORMAT(return_time, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')-1)
  48 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  49 + #{userId}
  50 + </foreach>
  51 + AND return_time between #{times[0],javaType=java.time.LocalDateTime} and
  52 + #{times[1],javaType=java.time.LocalDateTime}
57 53 GROUP BY time
58 54 </select>
59 55  
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
... ... @@ -125,4 +125,10 @@ public interface ErrorCodeConstants {
125 125 ErrorCode DIY_PAGE_NOT_EXISTS = new ErrorCode(1_013_018_000, "装修页面不存在");
126 126 ErrorCode DIY_PAGE_NAME_USED = new ErrorCode(1_013_018_001, "装修页面名称({})已经被使用");
127 127  
  128 + // ========== 客服会话 1-013-019-000 ==========
  129 + ErrorCode KEFU_CONVERSATION_NOT_EXISTS = new ErrorCode(1_013_019_000, "客服会话不存在");
  130 +
  131 + // ========== 客服消息 1-013-020-000 ==========
  132 + ErrorCode KEFU_MESSAGE_NOT_EXISTS = new ErrorCode(1_013_020_000, "客服消息不存在");
  133 +
128 134 }
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/WebSocketMessageTypeConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.enums;
  2 +
  3 +/**
  4 + * Promotion 的 WebSocket 消息类型枚举类
  5 + *
  6 + * @author HUIHUI
  7 + */
  8 +public interface WebSocketMessageTypeConstants {
  9 +
  10 + // ======================= mall 客服 =======================
  11 +
  12 + String KEFU_MESSAGE_TYPE = "kefu_message_type"; // 客服消息类型
  13 + String KEFU_MESSAGE_ADMIN_READ = "kefu_message_read_status_change"; // 客服消息管理员已读
  14 +
  15 +}
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/kehu/KeFuMessageContentTypeEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.enums.kehu;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Getter;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +/**
  10 + * 客服消息的类型枚举
  11 + *
  12 + * @author HUIHUI
  13 + */
  14 +@AllArgsConstructor
  15 +@Getter
  16 +public enum KeFuMessageContentTypeEnum implements IntArrayValuable {
  17 +
  18 + TEXT(1, "文本消息"),
  19 + IMAGE(2, "图片消息"),
  20 + VOICE(3, "语音消息"),
  21 + VIDEO(4, "视频消息"),
  22 + SYSTEM(5, "系统消息"),
  23 +
  24 + // ========== 商城特殊消息 ==========
  25 + PRODUCT(10, "商品消息"),
  26 + ORDER(11, "订单消息");
  27 +
  28 + private static final int[] ARRAYS = Arrays.stream(values()).mapToInt(KeFuMessageContentTypeEnum::getType).toArray();
  29 +
  30 + /**
  31 + * 类型
  32 + */
  33 + private final Integer type;
  34 +
  35 + /**
  36 + * 名称
  37 + */
  38 + private final String name;
  39 +
  40 + @Override
  41 + public int[] array() {
  42 + return ARRAYS;
  43 + }
  44 +
  45 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.kefu;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  5 +import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
  6 +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
  7 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationRespVO;
  8 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationUpdatePinnedReqVO;
  9 +import cn.iocoder.yudao.module.promotion.service.kefu.KeFuConversationService;
  10 +import io.swagger.v3.oas.annotations.Operation;
  11 +import io.swagger.v3.oas.annotations.Parameter;
  12 +import io.swagger.v3.oas.annotations.tags.Tag;
  13 +import jakarta.annotation.Resource;
  14 +import jakarta.validation.Valid;
  15 +import org.springframework.security.access.prepost.PreAuthorize;
  16 +import org.springframework.validation.annotation.Validated;
  17 +import org.springframework.web.bind.annotation.*;
  18 +
  19 +import java.util.List;
  20 +import java.util.Map;
  21 +
  22 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  23 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  24 +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
  25 +
  26 +@Tag(name = "管理后台 - 客服会话")
  27 +@RestController
  28 +@RequestMapping("/promotion/kefu-conversation")
  29 +@Validated
  30 +public class KeFuConversationController {
  31 +
  32 + @Resource
  33 + private KeFuConversationService conversationService;
  34 + @Resource
  35 + private MemberUserApi memberUserApi;
  36 +
  37 + @PutMapping("/update-conversation-pinned")
  38 + @Operation(summary = "置顶/取消置顶客服会话")
  39 + @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:update')")
  40 + public CommonResult<Boolean> updateConversationPinned(@Valid @RequestBody KeFuConversationUpdatePinnedReqVO updateReqVO) {
  41 + conversationService.updateConversationPinnedByAdmin(updateReqVO);
  42 + return success(true);
  43 + }
  44 +
  45 + @DeleteMapping("/delete")
  46 + @Operation(summary = "删除客服会话")
  47 + @Parameter(name = "id", description = "编号", required = true)
  48 + @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:delete')")
  49 + public CommonResult<Boolean> deleteConversation(@RequestParam("id") Long id) {
  50 + conversationService.deleteKefuConversation(id);
  51 + return success(true);
  52 + }
  53 +
  54 + @GetMapping("/list")
  55 + @Operation(summary = "获得客服会话列表")
  56 + @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:query')")
  57 + public CommonResult<List<KeFuConversationRespVO>> getConversationList() {
  58 + // 查询会话列表
  59 + List<KeFuConversationRespVO> respList = BeanUtils.toBean(conversationService.getKefuConversationList(),
  60 + KeFuConversationRespVO.class);
  61 +
  62 + // 拼接数据
  63 + Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(convertSet(respList, KeFuConversationRespVO::getUserId));
  64 + respList.forEach(item-> findAndThen(userMap, item.getUserId(),
  65 + memberUser-> item.setUserAvatar(memberUser.getAvatar()).setUserNickname(memberUser.getNickname())));
  66 + return success(respList);
  67 + }
  68 +
  69 +}
0 70 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuMessageController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.kefu;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
  4 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  7 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessagePageReqVO;
  8 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageRespVO;
  9 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO;
  10 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
  11 +import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService;
  12 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  13 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
  14 +import io.swagger.v3.oas.annotations.Operation;
  15 +import io.swagger.v3.oas.annotations.Parameter;
  16 +import io.swagger.v3.oas.annotations.tags.Tag;
  17 +import jakarta.annotation.Resource;
  18 +import jakarta.validation.Valid;
  19 +import org.springframework.security.access.prepost.PreAuthorize;
  20 +import org.springframework.validation.annotation.Validated;
  21 +import org.springframework.web.bind.annotation.*;
  22 +
  23 +import java.util.Map;
  24 +
  25 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  26 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  27 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
  28 +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
  29 +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
  30 +
  31 +@Tag(name = "管理后台 - 客服消息")
  32 +@RestController
  33 +@RequestMapping("/promotion/kefu-message")
  34 +@Validated
  35 +public class KeFuMessageController {
  36 +
  37 + @Resource
  38 + private KeFuMessageService messageService;
  39 + @Resource
  40 + private AdminUserApi adminUserApi;
  41 +
  42 + @PostMapping("/send")
  43 + @Operation(summary = "发送客服消息")
  44 + @PreAuthorize("@ss.hasPermission('promotion:kefu-message:send')")
  45 + public CommonResult<Long> sendKeFuMessage(@Valid @RequestBody KeFuMessageSendReqVO sendReqVO) {
  46 + sendReqVO.setSenderId(getLoginUserId()).setSenderType(UserTypeEnum.ADMIN.getValue()); // 设置用户编号和类型
  47 + return success(messageService.sendKefuMessage(sendReqVO));
  48 + }
  49 +
  50 + @PutMapping("/update-read-status")
  51 + @Operation(summary = "更新客服消息已读状态")
  52 + @Parameter(name = "conversationId", description = "会话编号", required = true)
  53 + @PreAuthorize("@ss.hasPermission('promotion:kefu-message:update')")
  54 + public CommonResult<Boolean> updateKeFuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
  55 + messageService.updateKeFuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.ADMIN.getValue());
  56 + return success(true);
  57 + }
  58 +
  59 + @GetMapping("/page")
  60 + @Operation(summary = "获得客服消息分页")
  61 + @PreAuthorize("@ss.hasPermission('promotion:kefu-message:query')")
  62 + public CommonResult<PageResult<KeFuMessageRespVO>> getKeFuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) {
  63 + // 获得数据
  64 + PageResult<KeFuMessageDO> pageResult = messageService.getKeFuMessagePage(pageReqVO);
  65 +
  66 + // 拼接数据
  67 + PageResult<KeFuMessageRespVO> result = BeanUtils.toBean(pageResult, KeFuMessageRespVO.class);
  68 + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertSet(filterList(result.getList(),
  69 + item -> UserTypeEnum.ADMIN.getValue().equals(item.getSenderType())), KeFuMessageRespVO::getSenderId));
  70 + result.getList().forEach(item-> findAndThen(userMap, item.getSenderId(),
  71 + user -> item.setSenderAvatar(user.getAvatar())));
  72 + return success(result);
  73 + }
  74 +
  75 +}
0 76 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/conversation/KeFuConversationRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import java.time.LocalDateTime;
  7 +
  8 +@Schema(description = "管理后台 - 客服会话 Response VO")
  9 +@Data
  10 +public class KeFuConversationRespVO {
  11 +
  12 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24988")
  13 + private Long id;
  14 +
  15 + @Schema(description = "会话所属用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "8300")
  16 + private Long userId;
  17 + @Schema(description = "会话所属用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://yudao.com/images/avatar.jpg")
  18 + private String userAvatar;
  19 + @Schema(description = "会话所属用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
  20 + private String userNickname;
  21 +
  22 + @Schema(description = "最后聊天时间", requiredMode = Schema.RequiredMode.REQUIRED)
  23 + private LocalDateTime lastMessageTime;
  24 +
  25 + @Schema(description = "最后聊天内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "嗨,您好啊")
  26 + private String lastMessageContent;
  27 +
  28 + @Schema(description = "最后发送的消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  29 + private Integer lastMessageContentType;
  30 +
  31 + @Schema(description = "管理端置顶", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
  32 + private Boolean adminPinned;
  33 +
  34 + @Schema(description = "用户是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  35 + private Boolean userDeleted;
  36 +
  37 + @Schema(description = "管理员是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  38 + private Boolean adminDeleted;
  39 +
  40 + @Schema(description = "管理员未读消息数", requiredMode = Schema.RequiredMode.REQUIRED, example = "6")
  41 + private Integer adminUnreadMessageCount;
  42 +
  43 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  44 + private LocalDateTime createTime;
  45 +
  46 +}
0 47 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/conversation/KeFuConversationUpdatePinnedReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotNull;
  5 +import lombok.Data;
  6 +
  7 +@Schema(description = "管理后台 - 客服会话置顶 Request VO")
  8 +@Data
  9 +public class KeFuConversationUpdatePinnedReqVO {
  10 +
  11 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
  12 + @NotNull(message = "会话编号不能为空")
  13 + private Long id;
  14 +
  15 + @Schema(description = "管理端置顶", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
  16 + @NotNull(message = "管理端置顶不能为空")
  17 + private Boolean adminPinned;
  18 +
  19 +}
0 20 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/message/KeFuMessagePageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message;
  2 +
  3 +import lombok.*;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  6 +
  7 +@Schema(description = "管理后台 - 客服消息分页 Request VO")
  8 +@Data
  9 +@ToString(callSuper = true)
  10 +public class KeFuMessagePageReqVO extends PageParam {
  11 +
  12 + @Schema(description = "会话编号", example = "12580")
  13 + private Long conversationId;
  14 +
  15 +}
0 16 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/message/KeFuMessageRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.*;
  5 +
  6 +import java.time.LocalDateTime;
  7 +import com.alibaba.excel.annotation.*;
  8 +
  9 +@Schema(description = "管理后台 - 客服消息 Response VO")
  10 +@Data
  11 +public class KeFuMessageRespVO {
  12 +
  13 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
  14 + private Long id;
  15 +
  16 + @Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12580")
  17 + private Long conversationId;
  18 +
  19 + @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571")
  20 + private Long senderId;
  21 + @Schema(description = "发送人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://yudao.com/images/avatar.jpg")
  22 + private String senderAvatar;
  23 +
  24 + @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  25 + private Integer senderType;
  26 +
  27 + @Schema(description = "接收人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29124")
  28 + private Long receiverId;
  29 +
  30 + @Schema(description = "接收人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  31 + private Integer receiverType;
  32 +
  33 + @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  34 + private Integer contentType;
  35 +
  36 + @Schema(description = "消息", requiredMode = Schema.RequiredMode.REQUIRED)
  37 + private String content;
  38 +
  39 + @Schema(description = "是否已读", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  40 + private Boolean readStatus;
  41 +
  42 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  43 + private LocalDateTime createTime;
  44 +
  45 +}
0 46 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/message/KeFuMessageSendReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotEmpty;
  5 +import jakarta.validation.constraints.NotNull;
  6 +import lombok.Data;
  7 +
  8 +@Schema(description = "管理后台 - 发送客服消息 Request VO")
  9 +@Data
  10 +public class KeFuMessageSendReqVO {
  11 +
  12 + @Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12580")
  13 + @NotNull(message = "会话编号不能为空")
  14 + private Long conversationId;
  15 +
  16 + @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  17 + @NotNull(message = "消息类型不能为空")
  18 + private Integer contentType;
  19 +
  20 + @Schema(description = "消息", requiredMode = Schema.RequiredMode.REQUIRED)
  21 + @NotEmpty(message = "消息不能为空")
  22 + private String content;
  23 +
  24 + // ========== 后端设置的参数,前端无需传递 ==========
  25 +
  26 + @Schema(description = "发送人编号", example = "24571", hidden = true)
  27 + private Long senderId;
  28 + @Schema(description = "发送人类型", example = "1", hidden = true)
  29 + private Integer senderType;
  30 +
  31 +}
0 32 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillConfigController.java
... ... @@ -78,9 +78,9 @@ public class SeckillConfigController {
78 78 return success(SeckillConfigConvert.INSTANCE.convertList(list));
79 79 }
80 80  
81   - @GetMapping("/list-all-simple")
  81 + @GetMapping("/simple-list")
82 82 @Operation(summary = "获得所有开启状态的秒杀时段精简列表", description = "主要用于前端的下拉选项")
83   - public CommonResult<List<SeckillConfigSimpleRespVO>> getListAllSimple() {
  83 + public CommonResult<List<SeckillConfigSimpleRespVO>> getSeckillConfigSimpleList() {
84 84 List<SeckillConfigDO> list = seckillConfigService.getSeckillConfigListByStatus(
85 85 CommonStatusEnum.ENABLE.getStatus());
86 86 return success(SeckillConfigConvert.INSTANCE.convertList1(list));
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.app.kefu;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
  4 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  7 +import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
  8 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageRespVO;
  9 +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessagePageReqVO;
  10 +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessageSendReqVO;
  11 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
  12 +import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService;
  13 +import io.swagger.v3.oas.annotations.Operation;
  14 +import io.swagger.v3.oas.annotations.Parameter;
  15 +import io.swagger.v3.oas.annotations.tags.Tag;
  16 +import jakarta.annotation.Resource;
  17 +import jakarta.validation.Valid;
  18 +import org.springframework.validation.annotation.Validated;
  19 +import org.springframework.web.bind.annotation.*;
  20 +
  21 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  22 +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
  23 +
  24 +@Tag(name = "用户 APP - 客服消息")
  25 +@RestController
  26 +@RequestMapping("/promotion/kefu-message")
  27 +@Validated
  28 +public class AppKeFuMessageController {
  29 +
  30 + @Resource
  31 + private KeFuMessageService kefuMessageService;
  32 +
  33 + @PostMapping("/send")
  34 + @Operation(summary = "发送客服消息")
  35 + @PreAuthenticated
  36 + public CommonResult<Long> sendKefuMessage(@Valid @RequestBody AppKeFuMessageSendReqVO sendReqVO) {
  37 + sendReqVO.setSenderId(getLoginUserId()).setSenderType(UserTypeEnum.MEMBER.getValue()); // 设置用户编号和类型
  38 + return success(kefuMessageService.sendKefuMessage(sendReqVO));
  39 + }
  40 +
  41 + @PutMapping("/update-read-status")
  42 + @Operation(summary = "更新客服消息已读状态")
  43 + @Parameter(name = "conversationId", description = "会话编号", required = true)
  44 + @PreAuthenticated
  45 + public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
  46 + kefuMessageService.updateKeFuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.MEMBER.getValue());
  47 + return success(true);
  48 + }
  49 +
  50 + @GetMapping("/page")
  51 + @Operation(summary = "获得客服消息分页")
  52 + @PreAuthenticated
  53 + public CommonResult<PageResult<KeFuMessageRespVO>> getKefuMessagePage(@Valid AppKeFuMessagePageReqVO pageReqVO) {
  54 + PageResult<KeFuMessageDO> pageResult = kefuMessageService.getKeFuMessagePage(pageReqVO, getLoginUserId());
  55 + return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class));
  56 + }
  57 +
  58 +}
0 59 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/vo/message/AppKeFuMessagePageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +
  9 +@Schema(description = "用户 App - 客服消息分页 Request VO")
  10 +@Data
  11 +@ToString(callSuper = true)
  12 +public class AppKeFuMessagePageReqVO extends PageParam {
  13 +
  14 + @Schema(description = "会话编号", example = "12580")
  15 + private Long conversationId;
  16 +
  17 +}
0 18 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/vo/message/AppKeFuMessageRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import java.time.LocalDateTime;
  7 +
  8 +@Schema(description = "用户 App - 客服消息 Response VO")
  9 +@Data
  10 +public class AppKeFuMessageRespVO {
  11 +
  12 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
  13 + private Long id;
  14 +
  15 + @Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12580")
  16 + private Long conversationId;
  17 +
  18 + @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571")
  19 + private Long senderId;
  20 +
  21 + @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  22 + private Integer senderType;
  23 +
  24 + @Schema(description = "接收人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29124")
  25 + private Long receiverId;
  26 +
  27 + @Schema(description = "接收人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  28 + private Integer receiverType;
  29 +
  30 + @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  31 + private Integer contentType;
  32 +
  33 + @Schema(description = "消息", requiredMode = Schema.RequiredMode.REQUIRED)
  34 + private String content;
  35 +
  36 + @Schema(description = "是否已读", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  37 + private Boolean readStatus;
  38 +
  39 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  40 + private LocalDateTime createTime;
  41 +
  42 +}
0 43 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/vo/message/AppKeFuMessageSendReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotEmpty;
  5 +import jakarta.validation.constraints.NotNull;
  6 +import lombok.Data;
  7 +
  8 +@Schema(description = "用户 App - 发送客服消息 Request VO")
  9 +@Data
  10 +public class AppKeFuMessageSendReqVO {
  11 +
  12 + @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  13 + @NotNull(message = "消息类型不能为空")
  14 + private Integer contentType;
  15 + @Schema(description = "消息", requiredMode = Schema.RequiredMode.REQUIRED)
  16 + @NotEmpty(message = "消息不能为空")
  17 + private String content;
  18 +
  19 + // ========== 后端设置的参数,前端无需传递 ==========
  20 +
  21 + @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571", hidden = true)
  22 + private Long senderId;
  23 + @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1", hidden = true)
  24 + private Integer senderType;
  25 +
  26 +}
0 27 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/vo/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo;
0 2 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/kefu/KeFuConversationDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.dal.dataobject.kefu;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
  5 +import cn.iocoder.yudao.module.promotion.enums.kehu.KeFuMessageContentTypeEnum;
  6 +import com.baomidou.mybatisplus.annotation.KeySequence;
  7 +import com.baomidou.mybatisplus.annotation.TableId;
  8 +import com.baomidou.mybatisplus.annotation.TableName;
  9 +import lombok.*;
  10 +
  11 +import java.time.LocalDateTime;
  12 +
  13 +/**
  14 + * 客服会话 DO
  15 + *
  16 + * @author HUIHUI
  17 + */
  18 +@TableName("promotion_kefu_conversation")
  19 +@KeySequence("promotion_kefu_conversation_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  20 +@Data
  21 +@EqualsAndHashCode(callSuper = true)
  22 +@ToString(callSuper = true)
  23 +@Builder
  24 +@NoArgsConstructor
  25 +@AllArgsConstructor
  26 +public class KeFuConversationDO extends BaseDO {
  27 +
  28 + /**
  29 + * 编号
  30 + */
  31 + @TableId
  32 + private Long id;
  33 + /**
  34 + * 会话所属用户
  35 + *
  36 + * 关联 {@link MemberUserRespDTO#getId()}
  37 + */
  38 + private Long userId;
  39 +
  40 + /**
  41 + * 最后聊天时间
  42 + */
  43 + private LocalDateTime lastMessageTime;
  44 + /**
  45 + * 最后聊天内容
  46 + */
  47 + private String lastMessageContent;
  48 + /**
  49 + * 最后发送的消息类型
  50 + *
  51 + * 枚举 {@link KeFuMessageContentTypeEnum}
  52 + */
  53 + private Integer lastMessageContentType;
  54 +
  55 + //======================= 会话操作相关 =======================
  56 +
  57 + /**
  58 + * 管理端置顶
  59 + */
  60 + private Boolean adminPinned;
  61 + /**
  62 + * 用户是否可见
  63 + *
  64 + * false - 可见,默认值
  65 + * true - 不可见,用户删除时设置为 true
  66 + */
  67 + private Boolean userDeleted;
  68 + /**
  69 + * 管理员是否可见
  70 + *
  71 + * false - 可见,默认值
  72 + * true - 不可见,管理员删除时设置为 true
  73 + */
  74 + private Boolean adminDeleted;
  75 +
  76 + /**
  77 + * 管理员未读消息数
  78 + *
  79 + * 用户发送消息时增加,管理员查看后扣减
  80 + */
  81 + private Integer adminUnreadMessageCount;
  82 +
  83 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/kefu/KeFuMessageDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.dal.dataobject.kefu;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
  4 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  5 +import cn.iocoder.yudao.module.promotion.enums.kehu.KeFuMessageContentTypeEnum;
  6 +import com.baomidou.mybatisplus.annotation.KeySequence;
  7 +import com.baomidou.mybatisplus.annotation.TableId;
  8 +import com.baomidou.mybatisplus.annotation.TableName;
  9 +import lombok.*;
  10 +
  11 +/**
  12 + * 客服消息 DO
  13 + *
  14 + * @author HUIHUI
  15 + */
  16 +@TableName("promotion_kefu_message")
  17 +@KeySequence("promotion_kefu_message_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  18 +@Data
  19 +@EqualsAndHashCode(callSuper = true)
  20 +@ToString(callSuper = true)
  21 +@Builder
  22 +@NoArgsConstructor
  23 +@AllArgsConstructor
  24 +public class KeFuMessageDO extends BaseDO {
  25 +
  26 + /**
  27 + * 编号
  28 + */
  29 + @TableId
  30 + private Long id;
  31 + /**
  32 + * 会话编号
  33 + *
  34 + * 关联 {@link KeFuConversationDO#getId()}
  35 + */
  36 + private Long conversationId;
  37 +
  38 + /**
  39 + * 发送人编号
  40 + *
  41 + * 存储的是用户编号
  42 + */
  43 + private Long senderId;
  44 + /**
  45 + * 发送人类型
  46 + *
  47 + * 枚举,{@link UserTypeEnum}
  48 + */
  49 + private Integer senderType;
  50 + /**
  51 + * 接收人编号
  52 + *
  53 + * 存储的是用户编号
  54 + */
  55 + private Long receiverId;
  56 + /**
  57 + * 接收人类型
  58 + *
  59 + * 枚举,{@link UserTypeEnum}
  60 + */
  61 + private Integer receiverType;
  62 +
  63 + /**
  64 + * 消息类型
  65 + *
  66 + * 枚举 {@link KeFuMessageContentTypeEnum}
  67 + */
  68 + private Integer contentType;
  69 + /**
  70 + * 消息
  71 + */
  72 + private String content;
  73 +
  74 + //======================= 消息相关状态 =======================
  75 +
  76 + /**
  77 + * 是/否已读
  78 + */
  79 + private Boolean readStatus;
  80 +
  81 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuConversationMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.dal.mysql.kefu;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  4 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  5 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuConversationDO;
  6 +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  7 +import org.apache.ibatis.annotations.Mapper;
  8 +
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * 客服会话 Mapper
  13 + *
  14 + * @author HUIHUI
  15 + */
  16 +@Mapper
  17 +public interface KeFuConversationMapper extends BaseMapperX<KeFuConversationDO> {
  18 +
  19 + default List<KeFuConversationDO> selectConversationList() {
  20 + return selectList(new LambdaQueryWrapperX<KeFuConversationDO>()
  21 + .eq(KeFuConversationDO::getAdminDeleted, Boolean.FALSE)
  22 + .orderByDesc(KeFuConversationDO::getCreateTime));
  23 + }
  24 +
  25 + default void updateAdminUnreadMessageCountIncrement(Long id) {
  26 + update(new LambdaUpdateWrapper<KeFuConversationDO>()
  27 + .eq(KeFuConversationDO::getId, id)
  28 + .setSql("admin_unread_message_count = admin_unread_message_count + 1"));
  29 + }
  30 +
  31 + default KeFuConversationDO selectByUserId(Long userId) {
  32 + return selectOne(KeFuConversationDO::getUserId, userId);
  33 + }
  34 +
  35 +}
0 36 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuMessageMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.dal.mysql.kefu;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessagePageReqVO;
  7 +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessagePageReqVO;
  8 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
  9 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  10 +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  11 +import org.apache.ibatis.annotations.Mapper;
  12 +
  13 +import java.util.Collection;
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * 客服消息 Mapper
  18 + *
  19 + * @author HUIHUI
  20 + */
  21 +@Mapper
  22 +public interface KeFuMessageMapper extends BaseMapperX<KeFuMessageDO> {
  23 +
  24 + default PageResult<KeFuMessageDO> selectPage(KeFuMessagePageReqVO reqVO) {
  25 + return selectPage(reqVO, new LambdaQueryWrapperX<KeFuMessageDO>()
  26 + .eqIfPresent(KeFuMessageDO::getConversationId, reqVO.getConversationId())
  27 + .orderByDesc(KeFuMessageDO::getCreateTime));
  28 + }
  29 +
  30 + default List<KeFuMessageDO> selectListByConversationIdAndUserTypeAndReadStatus(Long conversationId, Integer userType,
  31 + Boolean readStatus) {
  32 + return selectList(new LambdaQueryWrapper<KeFuMessageDO>()
  33 + .eq(KeFuMessageDO::getConversationId, conversationId)
  34 + .ne(KeFuMessageDO::getSenderType, userType) // 管理员:查询出未读的会员消息,会员:查询出未读的客服消息
  35 + .eq(KeFuMessageDO::getReadStatus, readStatus));
  36 + }
  37 +
  38 + default void updateReadStatusBatchByIds(Collection<Long> ids, KeFuMessageDO keFuMessageDO) {
  39 + update(keFuMessageDO, new LambdaUpdateWrapper<KeFuMessageDO>()
  40 + .in(KeFuMessageDO::getId, ids));
  41 + }
  42 +
  43 + default PageResult<KeFuMessageDO> selectPage(AppKeFuMessagePageReqVO pageReqVO) {
  44 + return selectPage(pageReqVO, new LambdaQueryWrapperX<KeFuMessageDO>()
  45 + .eqIfPresent(KeFuMessageDO::getConversationId, pageReqVO.getConversationId())
  46 + .orderByDesc(KeFuMessageDO::getCreateTime));
  47 + }
  48 +
  49 +}
0 50 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.service.kefu;
  2 +
  3 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationUpdatePinnedReqVO;
  4 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuConversationDO;
  5 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * 客服会话 Service 接口
  11 + *
  12 + * @author HUIHUI
  13 + */
  14 +public interface KeFuConversationService {
  15 +
  16 + /**
  17 + * 【管理员】删除客服会话
  18 + *
  19 + * @param id 编号
  20 + */
  21 + void deleteKefuConversation(Long id);
  22 +
  23 + /**
  24 + * 【管理员】客服会话置顶
  25 + *
  26 + * @param updateReqVO 请求
  27 + */
  28 + void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO);
  29 +
  30 + /**
  31 + * 更新会话客服消息冗余信息
  32 + *
  33 + * @param kefuMessage 消息
  34 + */
  35 + void updateConversationLastMessage(KeFuMessageDO kefuMessage);
  36 +
  37 + /**
  38 + * 【管理员】将管理员未读消息计数更新为零
  39 + *
  40 + * @param id 编号
  41 + */
  42 + void updateAdminUnreadMessageCountToZero(Long id);
  43 +
  44 + /**
  45 + * 【管理员】更新会话对于管理员是否可见
  46 + *
  47 + * @param id 编号
  48 + * @param adminDeleted 管理员是否可见
  49 + */
  50 + void updateConversationAdminDeleted(Long id, Boolean adminDeleted);
  51 +
  52 + /**
  53 + * 【管理员】获得客服会话列表
  54 + *
  55 + * @return 会话列表
  56 + */
  57 + List<KeFuConversationDO> getKefuConversationList();
  58 +
  59 + /**
  60 + * 【会员】获得或创建会话
  61 + *
  62 + * 对于【会员】来说,有且仅有一个对话
  63 + *
  64 + * @param userId 用户编号
  65 + * @return 客服会话
  66 + */
  67 + KeFuConversationDO getOrCreateConversation(Long userId);
  68 +
  69 + /**
  70 + * 校验客服会话是否存在
  71 + *
  72 + * @param id 编号
  73 + * @return 客服会话
  74 + */
  75 + KeFuConversationDO validateKefuConversationExists(Long id);
  76 +
  77 + /**
  78 + * 【会员】获得客服会话
  79 + *
  80 + * @param userId 用户编号
  81 + * @return 客服会话
  82 + */
  83 + KeFuConversationDO getConversationByUserId(Long userId);
  84 +
  85 +}
0 86 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.service.kefu;
  2 +
  3 +import cn.hutool.core.util.StrUtil;
  4 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
  5 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationUpdatePinnedReqVO;
  6 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuConversationDO;
  7 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
  8 +import cn.iocoder.yudao.module.promotion.dal.mysql.kefu.KeFuConversationMapper;
  9 +import cn.iocoder.yudao.module.promotion.enums.kehu.KeFuMessageContentTypeEnum;
  10 +import jakarta.annotation.Resource;
  11 +import org.springframework.stereotype.Service;
  12 +import org.springframework.transaction.annotation.Transactional;
  13 +import org.springframework.validation.annotation.Validated;
  14 +
  15 +import java.time.LocalDateTime;
  16 +import java.util.List;
  17 +
  18 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  19 +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.KEFU_CONVERSATION_NOT_EXISTS;
  20 +
  21 +/**
  22 + * 客服会话 Service 实现类
  23 + *
  24 + * @author HUIHUI
  25 + */
  26 +@Service
  27 +@Validated
  28 +public class KeFuConversationServiceImpl implements KeFuConversationService {
  29 +
  30 + @Resource
  31 + private KeFuConversationMapper conversationMapper;
  32 +
  33 + @Override
  34 + public void deleteKefuConversation(Long id) {
  35 + // 校验存在
  36 + validateKefuConversationExists(id);
  37 +
  38 + // 只有管理员端可以删除会话,也不真的删,只是管理员端看不到啦
  39 + conversationMapper.updateById(new KeFuConversationDO().setId(id).setAdminDeleted(Boolean.TRUE));
  40 + }
  41 +
  42 + @Override
  43 + public void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO) {
  44 + // 校验存在
  45 + validateKefuConversationExists(updateReqVO.getId());
  46 +
  47 + // 更新管理员会话置顶状态
  48 + conversationMapper.updateById(new KeFuConversationDO().setId(updateReqVO.getId()).setAdminPinned(updateReqVO.getAdminPinned()));
  49 + }
  50 +
  51 + @Override
  52 + @Transactional(rollbackFor = Exception.class)
  53 + public void updateConversationLastMessage(KeFuMessageDO kefuMessage) {
  54 + // 1.1 校验会话是否存在
  55 + KeFuConversationDO conversation = validateKefuConversationExists(kefuMessage.getConversationId());
  56 + // 1.2 更新会话消息冗余
  57 + conversationMapper.updateById(new KeFuConversationDO().setId(kefuMessage.getConversationId())
  58 + .setLastMessageTime(kefuMessage.getCreateTime()).setLastMessageContent(kefuMessage.getContent())
  59 + .setLastMessageContentType(kefuMessage.getContentType()));
  60 +
  61 + // 2.1 更新管理员未读消息数
  62 + if (UserTypeEnum.MEMBER.getValue().equals(kefuMessage.getSenderType())) {
  63 + conversationMapper.updateAdminUnreadMessageCountIncrement(kefuMessage.getConversationId());
  64 + }
  65 + // 2.2 会员用户发送消息时,如果管理员删除过会话则进行恢复
  66 + if (Boolean.TRUE.equals(conversation.getAdminDeleted())) {
  67 + updateConversationAdminDeleted(kefuMessage.getConversationId(), Boolean.FALSE);
  68 + }
  69 + }
  70 +
  71 + @Override
  72 + public void updateAdminUnreadMessageCountToZero(Long id) {
  73 + // 校验存在
  74 + validateKefuConversationExists(id);
  75 +
  76 + // 管理员未读消息数归零
  77 + conversationMapper.updateById(new KeFuConversationDO().setId(id).setAdminUnreadMessageCount(0));
  78 + }
  79 +
  80 + @Override
  81 + public void updateConversationAdminDeleted(Long id, Boolean adminDeleted) {
  82 + conversationMapper.updateById(new KeFuConversationDO().setId(id).setAdminDeleted(adminDeleted));
  83 + }
  84 +
  85 + @Override
  86 + public List<KeFuConversationDO> getKefuConversationList() {
  87 + return conversationMapper.selectConversationList();
  88 + }
  89 +
  90 + @Override
  91 + public KeFuConversationDO getOrCreateConversation(Long userId) {
  92 + KeFuConversationDO conversation = conversationMapper.selectOne(KeFuConversationDO::getUserId, userId);
  93 + // 没有历史会话,则初始化一个新会话
  94 + if (conversation == null) {
  95 + conversation = new KeFuConversationDO().setUserId(userId).setLastMessageTime(LocalDateTime.now())
  96 + .setLastMessageContent(StrUtil.EMPTY).setLastMessageContentType(KeFuMessageContentTypeEnum.TEXT.getType())
  97 + .setAdminPinned(Boolean.FALSE).setUserDeleted(Boolean.FALSE).setAdminDeleted(Boolean.FALSE)
  98 + .setAdminUnreadMessageCount(0);
  99 + conversationMapper.insert(conversation);
  100 + }
  101 + return conversation;
  102 + }
  103 +
  104 + @Override
  105 + public KeFuConversationDO validateKefuConversationExists(Long id) {
  106 + KeFuConversationDO conversation = conversationMapper.selectById(id);
  107 + if (conversation == null) {
  108 + throw exception(KEFU_CONVERSATION_NOT_EXISTS);
  109 + }
  110 + return conversation;
  111 + }
  112 +
  113 + @Override
  114 + public KeFuConversationDO getConversationByUserId(Long userId) {
  115 + return conversationMapper.selectByUserId(userId);
  116 + }
  117 +
  118 +}
0 119 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.service.kefu;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessagePageReqVO;
  5 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO;
  6 +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessagePageReqVO;
  7 +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessageSendReqVO;
  8 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
  9 +import jakarta.validation.Valid;
  10 +
  11 +/**
  12 + * 客服消息 Service 接口
  13 + *
  14 + * @author HUIHUI
  15 + */
  16 +public interface KeFuMessageService {
  17 +
  18 + /**
  19 + * 【管理员】发送客服消息
  20 + *
  21 + * @param sendReqVO 信息
  22 + * @return 编号
  23 + */
  24 + Long sendKefuMessage(@Valid KeFuMessageSendReqVO sendReqVO);
  25 +
  26 + /**
  27 + * 【会员】发送客服消息
  28 + *
  29 + * @param sendReqVO 信息
  30 + * @return 编号
  31 + */
  32 + Long sendKefuMessage(AppKeFuMessageSendReqVO sendReqVO);
  33 +
  34 + /**
  35 + * 【管理员】更新消息已读状态
  36 + *
  37 + * @param conversationId 会话编号
  38 + * @param userId 用户编号
  39 + * @param userType 用户类型
  40 + */
  41 + void updateKeFuMessageReadStatus(Long conversationId, Long userId, Integer userType);
  42 +
  43 + /**
  44 + * 获得客服消息分页
  45 + *
  46 + * @param pageReqVO 分页查询
  47 + * @return 客服消息分页
  48 + */
  49 + PageResult<KeFuMessageDO> getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO);
  50 +
  51 + /**
  52 + * 【会员】获得客服消息分页
  53 + *
  54 + * @param pageReqVO 请求
  55 + * @param userId 用户编号
  56 + * @return 客服消息分页
  57 + */
  58 + PageResult<KeFuMessageDO> getKeFuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId);
  59 +
  60 +}
0 61 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.service.kefu;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.ObjUtil;
  5 +import cn.hutool.core.util.StrUtil;
  6 +import cn.hutool.extra.spring.SpringUtil;
  7 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
  8 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  9 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  10 +import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi;
  11 +import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
  12 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessagePageReqVO;
  13 +import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO;
  14 +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessagePageReqVO;
  15 +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessageSendReqVO;
  16 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuConversationDO;
  17 +import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
  18 +import cn.iocoder.yudao.module.promotion.dal.mysql.kefu.KeFuMessageMapper;
  19 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  20 +import jakarta.annotation.Resource;
  21 +import org.springframework.scheduling.annotation.Async;
  22 +import org.springframework.stereotype.Service;
  23 +import org.springframework.transaction.annotation.Transactional;
  24 +import org.springframework.validation.annotation.Validated;
  25 +
  26 +import java.util.List;
  27 +
  28 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  29 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
  30 +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.KEFU_CONVERSATION_NOT_EXISTS;
  31 +import static cn.iocoder.yudao.module.promotion.enums.WebSocketMessageTypeConstants.KEFU_MESSAGE_ADMIN_READ;
  32 +import static cn.iocoder.yudao.module.promotion.enums.WebSocketMessageTypeConstants.KEFU_MESSAGE_TYPE;
  33 +
  34 +/**
  35 + * 客服消息 Service 实现类
  36 + *
  37 + * @author HUIHUI
  38 + */
  39 +@Service
  40 +@Validated
  41 +public class KeFuMessageServiceImpl implements KeFuMessageService {
  42 +
  43 + @Resource
  44 + private KeFuMessageMapper keFuMessageMapper;
  45 + @Resource
  46 + private KeFuConversationService conversationService;
  47 + @Resource
  48 + private AdminUserApi adminUserApi;
  49 + @Resource
  50 + private MemberUserApi memberUserApi;
  51 + @Resource
  52 + private WebSocketSenderApi webSocketSenderApi;
  53 +
  54 + @Override
  55 + @Transactional(rollbackFor = Exception.class)
  56 + public Long sendKefuMessage(KeFuMessageSendReqVO sendReqVO) {
  57 + // 1.1 校验会话是否存在
  58 + KeFuConversationDO conversation = conversationService.validateKefuConversationExists(sendReqVO.getConversationId());
  59 + // 1.2 校验接收人是否存在
  60 + validateReceiverExist(conversation.getUserId(), UserTypeEnum.MEMBER.getValue());
  61 +
  62 + // 2.1 保存消息
  63 + KeFuMessageDO kefuMessage = BeanUtils.toBean(sendReqVO, KeFuMessageDO.class);
  64 + kefuMessage.setReceiverId(conversation.getUserId()).setReceiverType(UserTypeEnum.MEMBER.getValue()); // 设置接收人
  65 + keFuMessageMapper.insert(kefuMessage);
  66 + // 2.2 更新会话消息冗余
  67 + conversationService.updateConversationLastMessage(kefuMessage);
  68 +
  69 + // 3.1 发送消息给会员
  70 + getSelf().sendAsyncMessageToMember(conversation.getUserId(), KEFU_MESSAGE_TYPE, kefuMessage);
  71 + // 3.2 通知所有管理员更新对话
  72 + getSelf().sendAsyncMessageToAdmin(KEFU_MESSAGE_TYPE, kefuMessage);
  73 + return kefuMessage.getId();
  74 + }
  75 +
  76 + @Override
  77 + public Long sendKefuMessage(AppKeFuMessageSendReqVO sendReqVO) {
  78 + // 1.1 设置会话编号
  79 + KeFuMessageDO kefuMessage = BeanUtils.toBean(sendReqVO, KeFuMessageDO.class);
  80 + KeFuConversationDO conversation = conversationService.getOrCreateConversation(sendReqVO.getSenderId());
  81 + kefuMessage.setConversationId(conversation.getId());
  82 + // 1.2 保存消息
  83 + keFuMessageMapper.insert(kefuMessage);
  84 +
  85 + // 2. 更新会话消息冗余
  86 + conversationService.updateConversationLastMessage(kefuMessage);
  87 + // 3. 通知所有管理员更新对话
  88 + getSelf().sendAsyncMessageToAdmin(KEFU_MESSAGE_TYPE, kefuMessage);
  89 + return kefuMessage.getId();
  90 + }
  91 +
  92 + @Override
  93 + @Transactional(rollbackFor = Exception.class)
  94 + public void updateKeFuMessageReadStatus(Long conversationId, Long userId, Integer userType) {
  95 + // 1.1 校验会话是否存在
  96 + KeFuConversationDO conversation = conversationService.validateKefuConversationExists(conversationId);
  97 + // 1.2 如果是会员端处理已读,需要传递 userId;万一用户模拟一个 conversationId
  98 + if (UserTypeEnum.MEMBER.getValue().equals(userType) && ObjUtil.notEqual(conversation.getUserId(), userId)) {
  99 + throw exception(KEFU_CONVERSATION_NOT_EXISTS);
  100 + }
  101 + // 1.3 查询会话所有的未读消息 (tips: 多个客服,一个人点了,就都点了)
  102 + List<KeFuMessageDO> messageList = keFuMessageMapper.selectListByConversationIdAndUserTypeAndReadStatus(conversationId, userType, Boolean.FALSE);
  103 + if (CollUtil.isEmpty(messageList)) {
  104 + return;
  105 + }
  106 +
  107 + // 2.1 情况二:更新未读消息状态为已读
  108 + keFuMessageMapper.updateReadStatusBatchByIds(convertSet(messageList, KeFuMessageDO::getId),
  109 + new KeFuMessageDO().setReadStatus(Boolean.TRUE));
  110 + // 2.2 将管理员未读消息计数更新为零
  111 + conversationService.updateAdminUnreadMessageCountToZero(conversationId);
  112 +
  113 + // 2.3 发送消息通知会员,管理员已读 -> 会员更新发送的消息状态
  114 + KeFuMessageDO keFuMessage = getFirst(filterList(messageList, message -> UserTypeEnum.MEMBER.getValue().equals(message.getSenderType())));
  115 + assert keFuMessage != null; // 断言避免警告
  116 + getSelf().sendAsyncMessageToMember(keFuMessage.getSenderId(), KEFU_MESSAGE_ADMIN_READ, StrUtil.EMPTY);
  117 + // 2.4 通知所有管理员消息已读
  118 + getSelf().sendAsyncMessageToAdmin(KEFU_MESSAGE_ADMIN_READ, StrUtil.EMPTY);
  119 + }
  120 +
  121 + private void validateReceiverExist(Long receiverId, Integer receiverType) {
  122 + if (UserTypeEnum.ADMIN.getValue().equals(receiverType)) {
  123 + adminUserApi.validateUser(receiverId);
  124 + }
  125 + if (UserTypeEnum.MEMBER.getValue().equals(receiverType)) {
  126 + memberUserApi.validateUser(receiverId);
  127 + }
  128 + }
  129 +
  130 + @Async
  131 + public void sendAsyncMessageToMember(Long userId, String messageType, Object content) {
  132 + webSocketSenderApi.sendObject(UserTypeEnum.MEMBER.getValue(), userId, messageType, content);
  133 + }
  134 +
  135 + @Async
  136 + public void sendAsyncMessageToAdmin(String messageType, Object content) {
  137 + webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), messageType, content);
  138 + }
  139 +
  140 + @Override
  141 + public PageResult<KeFuMessageDO> getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO) {
  142 + return keFuMessageMapper.selectPage(pageReqVO);
  143 + }
  144 +
  145 + @Override
  146 + public PageResult<KeFuMessageDO> getKeFuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId) {
  147 + // 1. 获得客服会话
  148 + KeFuConversationDO conversation = conversationService.getConversationByUserId(userId);
  149 + if (conversation == null) {
  150 + return PageResult.empty();
  151 + }
  152 + // 2. 设置会话编号
  153 + pageReqVO.setConversationId(conversation.getId());
  154 + return keFuMessageMapper.selectPage(pageReqVO);
  155 + }
  156 +
  157 + private KeFuMessageServiceImpl getSelf() {
  158 + return SpringUtil.getBean(getClass());
  159 + }
  160 +
  161 +}
0 162 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java
... ... @@ -20,13 +20,13 @@ import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSumma
20 20 import io.swagger.v3.oas.annotations.Operation;
21 21 import io.swagger.v3.oas.annotations.Parameter;
22 22 import io.swagger.v3.oas.annotations.tags.Tag;
  23 +import jakarta.annotation.Resource;
  24 +import jakarta.validation.Valid;
23 25 import lombok.extern.slf4j.Slf4j;
24 26 import org.springframework.format.annotation.DateTimeFormat;
25 27 import org.springframework.validation.annotation.Validated;
26 28 import org.springframework.web.bind.annotation.*;
27 29  
28   -import jakarta.annotation.Resource;
29   -import jakarta.validation.Valid;
30 30 import java.time.LocalDateTime;
31 31 import java.util.Collections;
32 32 import java.util.Map;
... ... @@ -50,7 +50,6 @@ public class AppBrokerageUserController {
50 50 private BrokerageRecordService brokerageRecordService;
51 51 @Resource
52 52 private BrokerageWithdrawService brokerageWithdrawService;
53   -
54 53 @Resource
55 54 private MemberUserApi memberUserApi;
56 55  
... ... @@ -58,7 +57,7 @@ public class AppBrokerageUserController {
58 57 @Operation(summary = "获得个人分销信息")
59 58 @PreAuthenticated
60 59 public CommonResult<AppBrokerageUserRespVO> getBrokerageUser() {
61   - Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId()));
  60 + Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getOrCreateBrokerageUser(getLoginUserId()));
62 61 // 返回数据
63 62 AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO()
64 63 .setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false))
... ... @@ -79,21 +78,22 @@ public class AppBrokerageUserController {
79 78 @PreAuthenticated
80 79 public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() {
81 80 // 查询当前登录用户信息
82   - BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(getLoginUserId());
  81 + Long userId = getLoginUserId();
  82 + BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(userId);
83 83 // 统计用户昨日的佣金
84 84 LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
85 85 LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
86 86 LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
87   - Integer yesterdayPrice = brokerageRecordService.getSummaryPriceByUserId(brokerageUser.getId(),
  87 + Integer yesterdayPrice = brokerageRecordService.getSummaryPriceByUserId(userId,
88 88 BrokerageRecordBizTypeEnum.ORDER, BrokerageRecordStatusEnum.SETTLEMENT, beginTime, endTime);
89 89 // 统计用户提现的佣金
90   - Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryListByUserId(Collections.singleton(brokerageUser.getId()),
  90 + Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryListByUserId(Collections.singleton(userId),
91 91 BrokerageWithdrawStatusEnum.AUDIT_SUCCESS).stream()
92 92 .findFirst().map(BrokerageWithdrawSummaryRespBO::getPrice).orElse(0);
93 93 // 统计分销用户数量(一级)
94   - Long firstBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 1);
  94 + Long firstBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1);
95 95 // 统计分销用户数量(二级)
96   - Long secondBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 2);
  96 + Long secondBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2);
97 97  
98 98 // 拼接返回
99 99 return success(BrokerageUserConvert.INSTANCE.convert(yesterdayPrice, withdrawPrice, firstBrokerageUserCount, secondBrokerageUserCount, brokerageUser));
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserBindReqVO.java
... ... @@ -8,7 +8,7 @@ import jakarta.validation.constraints.NotNull;
8 8  
9 9 @Schema(description = "应用 App - 绑定推广员 Request VO")
10 10 @Data
11   -public class AppBrokerageUserBindReqVO extends PageParam {
  11 +public class AppBrokerageUserBindReqVO {
12 12  
13 13 @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
14 14 @NotNull(message = "推广员编号不能为空")
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java
... ... @@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokera
7 7 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO;
8 8 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
9 9 import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
10   -
11 10 import jakarta.validation.constraints.NotNull;
  11 +
12 12 import java.util.Collection;
13 13 import java.util.List;
14 14  
... ... @@ -68,6 +68,14 @@ public interface BrokerageUserService {
68 68 BrokerageUserDO getBindBrokerageUser(Long id);
69 69  
70 70 /**
  71 + * 获得或创建分销用户
  72 + *
  73 + * @param id 用户编号
  74 + * @return 分销用户
  75 + */
  76 + BrokerageUserDO getOrCreateBrokerageUser(Long id);
  77 +
  78 + /**
71 79 * 更新用户佣金
72 80 *
73 81 * @param id 用户编号
... ... @@ -104,8 +112,8 @@ public interface BrokerageUserService {
104 112 /**
105 113 * 【会员】绑定推广员
106 114 *
107   - * @param userId 用户编号
108   - * @param bindUserId 推广员编号
  115 + * @param userId 用户编号
  116 + * @param bindUserId 推广员编号
109 117 * @return 是否绑定
110 118 */
111 119 boolean bindBrokerageUser(@NotNull Long userId, @NotNull Long bindUserId);
... ... @@ -134,4 +142,5 @@ public interface BrokerageUserService {
134 142 * @return 下级分销统计分页
135 143 */
136 144 PageResult<AppBrokerageUserChildSummaryRespVO> getBrokerageUserChildSummaryPage(AppBrokerageUserChildSummaryPageReqVO pageReqVO, Long userId);
  145 +
137 146 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java
... ... @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.lang.Assert;
5 5 import cn.hutool.core.util.ArrayUtil;
6 6 import cn.hutool.core.util.BooleanUtil;
  7 +import cn.hutool.core.util.ObjUtil;
7 8 import cn.hutool.core.util.StrUtil;
8 9 import cn.iocoder.yudao.framework.common.pojo.PageResult;
9 10 import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
... ... @@ -25,10 +26,10 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
25 26 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
26 27 import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
27 28 import com.baomidou.mybatisplus.core.metadata.IPage;
  29 +import jakarta.annotation.Resource;
28 30 import org.springframework.stereotype.Service;
29 31 import org.springframework.validation.annotation.Validated;
30 32  
31   -import jakarta.annotation.Resource;
32 33 import java.time.LocalDateTime;
33 34 import java.util.*;
34 35  
... ... @@ -128,6 +129,19 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
128 129 }
129 130  
130 131 @Override
  132 + public BrokerageUserDO getOrCreateBrokerageUser(Long id) {
  133 + BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(id);
  134 + // 特殊:人人分销的情况下,如果分销人为空则创建分销人
  135 + if (brokerageUser == null && ObjUtil.equal(BrokerageEnabledConditionEnum.ALL.getCondition(),
  136 + tradeConfigService.getTradeConfig().getBrokerageEnabledCondition())) {
  137 + brokerageUser = new BrokerageUserDO().setId(id).setBrokerageEnabled(true).setBrokeragePrice(0)
  138 + .setBrokerageTime(LocalDateTime.now()).setFrozenPrice(0);
  139 + brokerageUserMapper.insert(brokerageUser);
  140 + }
  141 + return brokerageUser;
  142 + }
  143 +
  144 + @Override
131 145 public boolean updateUserPrice(Long id, Integer price) {
132 146 if (price > 0) {
133 147 brokerageUserMapper.updatePriceIncr(id, price);
... ... @@ -184,7 +198,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
184 198 if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格
185 199 brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now());
186 200 }
187   - brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now());
188 201 brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser));
189 202 } else {
190 203 brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId)));
... ... @@ -294,18 +307,23 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
294 307 }
295 308  
296 309 private void validateCanBindUser(BrokerageUserDO user, Long bindUserId) {
297   - // 校验要绑定的用户有无推广资格
298   - BrokerageUserDO bindUser = brokerageUserMapper.selectById(bindUserId);
  310 + // 1.1 校验推广人是否存在
  311 + MemberUserRespDTO bindUserInfo = memberUserApi.getUser(bindUserId);
  312 + if (bindUserInfo == null) {
  313 + throw exception(BROKERAGE_USER_NOT_EXISTS);
  314 + }
  315 + // 1.2 校验要绑定的用户有无推广资格
  316 + BrokerageUserDO bindUser = getOrCreateBrokerageUser(bindUserId);
299 317 if (bindUser == null || BooleanUtil.isFalse(bindUser.getBrokerageEnabled())) {
300 318 throw exception(BROKERAGE_BIND_USER_NOT_ENABLED);
301 319 }
302 320  
303   - // 校验绑定自己
  321 + // 2. 校验绑定自己
304 322 if (Objects.equals(user.getId(), bindUserId)) {
305 323 throw exception(BROKERAGE_BIND_SELF);
306 324 }
307 325  
308   - // 下级不能绑定自己的上级
  326 + // 3. 下级不能绑定自己的上级
309 327 for (int i = 0; i <= Short.MAX_VALUE; i++) {
310 328 if (Objects.equals(bindUser.getBindUserId(), user.getId())) {
311 329 throw exception(BROKERAGE_BIND_LOOP);
... ...
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java
... ... @@ -57,4 +57,12 @@ public interface MemberUserApi {
57 57 * @return 用户信息
58 58 */
59 59 MemberUserRespDTO getUserByMobile(String mobile);
  60 +
  61 + /**
  62 + * 校验用户是否存在
  63 + *
  64 + * @param id 用户编号
  65 + */
  66 + void validateUser(Long id);
  67 +
60 68 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java
... ... @@ -11,6 +11,9 @@ import jakarta.annotation.Resource;
11 11 import java.util.Collection;
12 12 import java.util.List;
13 13  
  14 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  15 +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.USER_MOBILE_NOT_EXISTS;
  16 +
14 17 /**
15 18 * 会员用户的 API 实现类
16 19 *
... ... @@ -44,4 +47,12 @@ public class MemberUserApiImpl implements MemberUserApi {
44 47 return MemberUserConvert.INSTANCE.convert2(userService.getUserByMobile(mobile));
45 48 }
46 49  
  50 + @Override
  51 + public void validateUser(Long id) {
  52 + MemberUserDO user = userService.getUser(id);
  53 + if (user == null) {
  54 + throw exception(USER_MOBILE_NOT_EXISTS);
  55 + }
  56 + }
  57 +
47 58 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
1 1 package cn.iocoder.yudao.module.member.controller.app.social;
2 2  
  3 +import cn.hutool.core.codec.Base64;
3 4 import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
4 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
... ... @@ -7,18 +8,20 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
7 8 import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBindReqVO;
8 9 import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserRespVO;
9 10 import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO;
  11 +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialWxQrcodeReqVO;
  12 +import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
10 13 import cn.iocoder.yudao.module.system.api.social.SocialUserApi;
11 14 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
12 15 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
13 16 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
  17 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
  18 +import io.swagger.v3.oas.annotations.Operation;
14 19 import io.swagger.v3.oas.annotations.Parameter;
15 20 import io.swagger.v3.oas.annotations.tags.Tag;
16   -import io.swagger.v3.oas.annotations.Operation;
17   -import org.springframework.validation.annotation.Validated;
18   -import org.springframework.web.bind.annotation.*;
19   -
20 21 import jakarta.annotation.Resource;
21 22 import jakarta.validation.Valid;
  23 +import org.springframework.validation.annotation.Validated;
  24 +import org.springframework.web.bind.annotation.*;
22 25  
23 26 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
24 27 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
... ... @@ -31,6 +34,8 @@ public class AppSocialUserController {
31 34  
32 35 @Resource
33 36 private SocialUserApi socialUserApi;
  37 + @Resource
  38 + private SocialClientApi socialClientApi;
34 39  
35 40 @PostMapping("/bind")
36 41 @Operation(summary = "社交绑定,使用 code 授权码")
... ... @@ -60,4 +65,11 @@ public class AppSocialUserController {
60 65 return success(BeanUtils.toBean(socialUser, AppSocialUserRespVO.class));
61 66 }
62 67  
  68 + @PostMapping("/wxa-qrcode")
  69 + @Operation(summary = "获得微信小程序码(base64 image)")
  70 + public CommonResult<String> getWxaQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
  71 + byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class));
  72 + return success(Base64.encode(wxQrcode));
  73 + }
  74 +
63 75 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxQrcodeReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.member.controller.app.social.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotEmpty;
  5 +import lombok.Data;
  6 +
  7 +
  8 +@Schema(description = "用户 APP - 获得获取小程序码 Request VO")
  9 +@Data
  10 +public class AppSocialWxQrcodeReqVO {
  11 +
  12 + /**
  13 + * 页面路径不能携带参数(参数请放在scene字段里)
  14 + */
  15 + @Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
  16 + private String scene;
  17 +
  18 + /**
  19 + * 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里),
  20 + * 如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置
  21 + */
  22 + @Schema(description = "页面路径", requiredMode = Schema.RequiredMode.REQUIRED, example = "pages/goods/index")
  23 + @NotEmpty(message = "页面路径不能为空")
  24 + private String path;
  25 +
  26 + @Schema(description = "二维码宽度", requiredMode = Schema.RequiredMode.REQUIRED, example = "430")
  27 + private Integer width;
  28 +
  29 + @Schema(description = "是/否自动配置线条颜色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  30 + private Boolean autoColor;
  31 +
  32 + @Schema(description = "是/否检查 page 是否存在", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  33 + private Boolean checkPath;
  34 +
  35 + @Schema(description = "是/否需要透明底色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  36 + private Boolean hyaline;
  37 +
  38 +}
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppMemberUserInfoRespVO.java
... ... @@ -11,6 +11,9 @@ import lombok.NoArgsConstructor;
11 11 @AllArgsConstructor
12 12 public class AppMemberUserInfoRespVO {
13 13  
  14 + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  15 + private Long id;
  16 +
14 17 @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
15 18 private String nickname;
16 19  
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java
... ... @@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO;
12 12 import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
13 13 import org.mapstruct.Mapper;
14 14 import org.mapstruct.Mapping;
  15 +import org.mapstruct.Mappings;
15 16 import org.mapstruct.factory.Mappers;
16 17  
17 18 import java.util.List;
... ... @@ -27,8 +28,12 @@ public interface MemberUserConvert {
27 28  
28 29 AppMemberUserInfoRespVO convert(MemberUserDO bean);
29 30  
30   - @Mapping(source = "level", target = "level")
31   - @Mapping(source = "bean.experience", target = "experience")
  31 +
  32 + @Mappings({
  33 + @Mapping(source = "level", target = "level"),
  34 + @Mapping(source = "bean.id", target = "id"),
  35 + @Mapping(source = "bean.experience", target = "experience")
  36 + })
32 37 AppMemberUserInfoRespVO convert(MemberUserDO bean, MemberLevelDO level);
33 38  
34 39 MemberUserRespDTO convert2(MemberUserDO bean);
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApi.java
... ... @@ -2,7 +2,9 @@ package cn.iocoder.yudao.module.system.api.social;
2 2  
3 3 import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO;
4 4 import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;
  5 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
5 6 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
  7 +import jakarta.validation.Valid;
6 8  
7 9 /**
8 10 * 社交应用的 API 接口
... ... @@ -39,4 +41,12 @@ public interface SocialClientApi {
39 41 */
40 42 SocialWxPhoneNumberInfoRespDTO getWxMaPhoneNumberInfo(Integer userType, String phoneCode);
41 43  
  44 + /**
  45 + * 获得小程序二维码
  46 + *
  47 + * @param reqVO 请求信息
  48 + * @return 小程序二维码
  49 + */
  50 + byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO);
  51 +
42 52 }
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java
... ... @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
4 4 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
5 5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
6 6 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
7   -
  7 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
8 8 import jakarta.validation.Valid;
9 9  
10 10 /**
... ... @@ -32,8 +32,8 @@ public interface SocialUserApi {
32 32 /**
33 33 * 获得社交用户,基于 userId
34 34 *
35   - * @param userType 用户类型
36   - * @param userId 用户编号
  35 + * @param userType 用户类型
  36 + * @param userId 用户编号
37 37 * @param socialType 社交平台的类型
38 38 * @return 社交用户
39 39 */
... ... @@ -44,10 +44,10 @@ public interface SocialUserApi {
44 44 *
45 45 * 在认证信息不正确的情况下,也会抛出 {@link ServiceException} 业务异常
46 46 *
47   - * @param userType 用户类型
  47 + * @param userType 用户类型
48 48 * @param socialType 社交平台的类型
49   - * @param code 授权码
50   - * @param state state
  49 + * @param code 授权码
  50 + * @param state state
51 51 * @return 社交用户
52 52 */
53 53 SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state);
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxQrcodeReqDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.api.social.dto;
  2 +
  3 +import jakarta.validation.constraints.NotEmpty;
  4 +import lombok.Data;
  5 +
  6 +/**
  7 + * 获取小程序码 Request DTO
  8 + *
  9 + * @author HUIHUI
  10 + * @see <a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html">获取不限制的小程序码</a>
  11 + */
  12 +@Data
  13 +public class SocialWxQrcodeReqDTO {
  14 +
  15 + /**
  16 + * 页面路径不能携带参数(参数请放在scene字段里)
  17 + */
  18 + public static final String SCENE = "";
  19 + /**
  20 + * 二维码宽度
  21 + */
  22 + public static final Integer WIDTH = 430;
  23 + /**
  24 + * 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
  25 + */
  26 + public static final Boolean AUTO_COLOR = true;
  27 + /**
  28 + * 检查 page 是否存在
  29 + */
  30 + public static final Boolean CHECK_PATH = true;
  31 + /**
  32 + * 是否需要透明底色
  33 + *
  34 + * hyaline 为 true 时,生成透明底色的小程序码
  35 + */
  36 + public static final Boolean HYALINE = true;
  37 +
  38 + /**
  39 + * 场景
  40 + */
  41 + @NotEmpty(message = "场景不能为空")
  42 + private String scene;
  43 + /**
  44 + * 页面路径
  45 + */
  46 + @NotEmpty(message = "页面路径不能为空")
  47 + private String path;
  48 + /**
  49 + * 二维码宽度
  50 + */
  51 + private Integer width;
  52 +
  53 + /**
  54 + * 是否需要透明底色
  55 + */
  56 + private Boolean autoColor;
  57 + /**
  58 + * 是否检查 page 是否存在
  59 + */
  60 + private Boolean checkPath;
  61 + /**
  62 + * 是否需要透明底色
  63 + */
  64 + private Boolean hyaline;
  65 +
  66 +}
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
... ... @@ -120,8 +120,10 @@ public interface ErrorCodeConstants {
120 120 ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_001, "社交授权失败,找不到对应的用户");
121 121  
122 122 ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败");
123   - ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_201, "社交客户端不存在");
124   - ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_202, "社交客户端已存在配置");
  123 + ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR = new ErrorCode(1_002_018_201, "获得小程序码失败");
  124 + ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_202, "社交客户端不存在");
  125 + ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_203, "社交客户端已存在配置");
  126 +
125 127  
126 128 // ========== OAuth2 客户端 1-002-020-000 =========
127 129 ErrorCode OAUTH2_CLIENT_NOT_EXISTS = new ErrorCode(1_002_020_000, "OAuth2 客户端不存在");
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java
... ... @@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
4 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 5 import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO;
6 6 import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;
  7 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
7 8 import cn.iocoder.yudao.module.system.service.social.SocialClientService;
8 9 import me.chanjar.weixin.common.bean.WxJsapiSignature;
9 10 import org.springframework.stereotype.Service;
... ... @@ -40,4 +41,9 @@ public class SocialClientApiImpl implements SocialClientApi {
40 41 return BeanUtils.toBean(info, SocialWxPhoneNumberInfoRespDTO.class);
41 42 }
42 43  
  44 + @Override
  45 + public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) {
  46 + return socialClientService.getWxaQrcode(reqVO);
  47 + }
  48 +
43 49 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java
... ... @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.api.social;
3 3 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
4 4 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
5 5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
  6 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
6 7 import cn.iocoder.yudao.module.system.service.social.SocialUserService;
7 8 import org.springframework.stereotype.Service;
8 9 import org.springframework.validation.annotation.Validated;
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsCallbackController.java
... ... @@ -42,4 +42,14 @@ public class SmsCallbackController {
42 42 return success(true);
43 43 }
44 44  
  45 +
  46 + @PostMapping("/huawei")
  47 + @PermitAll
  48 + @Operation(summary = "华为云短信的回调", description = "参见 https://support.huaweicloud.com/api-msgsms/sms_05_0003.html 文档")
  49 + public CommonResult<Boolean> receiveHuaweiSmsStatus(HttpServletRequest request) throws Throwable {
  50 + String text = ServletUtils.getBody(request);
  51 + smsSendService.receiveSmsStatus(SmsChannelEnum.HUAWEI.getCode(), text);
  52 + return success(true);
  53 + }
  54 +
45 55 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/HuaweiSmsClient.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.framework.sms.core.client.impl;
  2 +
  3 +import cn.hutool.core.lang.Assert;
  4 +import cn.hutool.core.util.HexUtil;
  5 +import cn.hutool.core.util.StrUtil;
  6 +import cn.hutool.crypto.SecureUtil;
  7 +import cn.hutool.crypto.digest.DigestUtil;
  8 +import cn.hutool.json.JSONArray;
  9 +import cn.iocoder.yudao.framework.common.core.KeyValue;
  10 +import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
  11 +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO;
  12 +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO;
  13 +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO;
  14 +import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum;
  15 +import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties;
  16 +import com.fasterxml.jackson.annotation.JsonFormat;
  17 +import com.fasterxml.jackson.annotation.JsonProperty;
  18 +import lombok.Data;
  19 +import lombok.extern.slf4j.Slf4j;
  20 +import org.apache.http.HttpResponse;
  21 +import org.apache.http.client.methods.HttpUriRequest;
  22 +import org.apache.http.client.methods.RequestBuilder;
  23 +import org.apache.http.entity.StringEntity;
  24 +import org.apache.http.impl.client.CloseableHttpClient;
  25 +import org.apache.http.impl.client.HttpClientBuilder;
  26 +
  27 +import java.net.URLEncoder;
  28 +import java.nio.charset.StandardCharsets;
  29 +import java.text.SimpleDateFormat;
  30 +import java.time.LocalDateTime;
  31 +import java.util.*;
  32 +
  33 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
  34 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  35 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT;
  36 +
  37 +/**
  38 + * 华为短信客户端的实现类
  39 + *
  40 + * @author scholar
  41 + * @since 2024/6/02 11:55
  42 + */
  43 +@Slf4j
  44 +public class HuaweiSmsClient extends AbstractSmsClient {
  45 +
  46 + /**
  47 + * 调用成功 code
  48 + */
  49 + public static final String API_CODE_SUCCESS = "OK";
  50 +
  51 + public HuaweiSmsClient(SmsChannelProperties properties) {
  52 + super(properties);
  53 + Assert.notEmpty(properties.getApiKey(), "apiKey 不能为空");
  54 + Assert.notEmpty(properties.getApiSecret(), "apiSecret 不能为空");
  55 + }
  56 +
  57 + @Override
  58 + protected void doInit() {
  59 + }
  60 +
  61 + @Override
  62 + public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId,
  63 + List<KeyValue<String, Object>> templateParams) throws Throwable {
  64 + // TODO @scholar:https://smsapi.cn-north-4.myhuaweicloud.com:443 是不是枚举成静态变量
  65 + String url = "https://smsapi.cn-north-4.myhuaweicloud.com:443/sms/batchSendSms/v1"; //APP接入地址+接口访问URI
  66 + // 相比较阿里短信,华为短信发送的时候需要额外的参数“通道号”,考虑到不破坏原有的的结构
  67 + // 所以将 通道号 拼接到 apiTemplateId 字段中,格式为 "apiTemplateId 通道号"。空格为分隔符。
  68 + // TODO @scholar:暂时只考虑中国大陆,所以不需要 sender 哈
  69 + String sender = StrUtil.subAfter(apiTemplateId, " ", true); //中国大陆短信签名通道号或全球短信通道号
  70 + String templateId = StrUtil.subBefore(apiTemplateId, " ", true); //模板ID
  71 +
  72 + // 选填,短信状态报告接收地址,推荐使用域名,为空或者不填表示不接收状态报告
  73 + String statusCallBack = properties.getCallbackUrl();
  74 +
  75 + // TODO @scholar:1)是不是用 LocalDateTimeUtil.format();这样 3 行变成一行
  76 + // TODO @scholar:singerDate 叫 sdkDate 会更合适哈,这样理解起来简单。另外,singer 应该是 signed 么?
  77 + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH);
  78 + sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
  79 + String singerDate = sdf.format(new Date());
  80 +
  81 + // TODO @scholar:整个处理加密的过程,是不是应该抽成一个 private 方法哈。这样整个调用的主干更清晰。
  82 + // ************* 步骤 1:拼接规范请求串 *************
  83 + String httpRequestMethod = "POST";
  84 + String canonicalUri = "/sms/batchSendSms/v1/";
  85 + String canonicalQueryString = ""; // 查询参数为空
  86 + String canonicalHeaders = "content-type:application/x-www-form-urlencoded\n"
  87 + + "host:smsapi.cn-north-4.myhuaweicloud.com:443\n"
  88 + + "x-sdk-date:" + singerDate + "\n";
  89 + // TODO @scholar:静态枚举了
  90 + String signedHeaders = "content-type;host;x-sdk-date";
  91 + // TODO @scholar:下面的注释,可以考虑去掉
  92 + /*
  93 + * 选填,使用无变量模板时请赋空值 String templateParas = "";
  94 + * 单变量模板示例:模板内容为"您的验证码是${NUM_6}"时,templateParas可填写为"[\"111111\"]"
  95 + * 双变量模板示例:模板内容为"您有${NUM_2}件快递请到${TXT_20}领取"时,templateParas可填写为"[\"3\",\"人民公园正门\"]"
  96 + */
  97 + // TODO @scholar:CollectionUtils.convertList 可以把 4 行变成 1 行。
  98 + // TODO @scholar:templateParams 拼写错误哈
  99 + List<String> templateParas = new ArrayList<>();
  100 + for (KeyValue<String, Object> kv : templateParams) {
  101 + templateParas.add(String.valueOf(kv.getValue()));
  102 + }
  103 +
  104 + // 请求Body,不携带签名名称时,signature请填null
  105 + String body = buildRequestBody(sender, mobile, templateId, templateParas, statusCallBack, null);
  106 + // TODO @scholar:Assert 断言,抛出异常
  107 + if (null == body || body.isEmpty()) {
  108 + return null;
  109 + }
  110 + String hashedRequestBody = HexUtil.encodeHexStr(DigestUtil.sha256(body));
  111 + String canonicalRequest = httpRequestMethod + "\n" + canonicalUri + "\n" + canonicalQueryString + "\n"
  112 + + canonicalHeaders + "\n" + signedHeaders + "\n" + hashedRequestBody;
  113 +
  114 + // ************* 步骤 2:拼接待签名字符串 *************
  115 + // TODO @scholar:sha256Hex 是不是更简洁哈
  116 + String hashedCanonicalRequest = HexUtil.encodeHexStr(DigestUtil.sha256(canonicalRequest));
  117 + String stringToSign = "SDK-HMAC-SHA256" + "\n" + singerDate + "\n" + hashedCanonicalRequest;
  118 +
  119 + // ************* 步骤 3:计算签名 *************
  120 + String signature = SecureUtil.hmacSha256(properties.getApiSecret()).digestHex(stringToSign);
  121 +
  122 + // ************* 步骤 4:拼接 Authorization *************
  123 + String authorization = "SDK-HMAC-SHA256" + " " + "Access=" + properties.getApiKey() + ", "
  124 + + "SignedHeaders=" + signedHeaders + ", " + "Signature=" + signature;
  125 +
  126 + // ************* 步骤 5:构造HttpRequest 并执行request请求,获得response *************
  127 + // TODO @scholar:考虑了下,还是换 hutool 的 httpUtils。因为未来 httpclient 我们可能会移除掉
  128 + HttpUriRequest postMethod = RequestBuilder.post()
  129 + .setUri(url)
  130 + .setEntity(new StringEntity(body, StandardCharsets.UTF_8))
  131 + .setHeader("Content-Type","application/x-www-form-urlencoded")
  132 + .setHeader("X-Sdk-Date", singerDate)
  133 + .setHeader("Authorization", authorization)
  134 + .build();
  135 + // TODO @scholar:这种不太适合一直 new 的哈
  136 + CloseableHttpClient client = HttpClientBuilder.create().build();
  137 + HttpResponse response = client.execute(postMethod);
  138 + // TODO @scholar:失败的情况下的处理
  139 + // TODO @scholar:setSerialNo(Integer.toString(response.getStatusLine().getStatusCode())) 这部分,空一行。一行代码太多了,阅读性不太好哈
  140 + return new SmsSendRespDTO().setSuccess(Objects.equals(response.getStatusLine().getReasonPhrase(), API_CODE_SUCCESS)).setSerialNo(Integer.toString(response.getStatusLine().getStatusCode()))
  141 + .setApiRequestId(null).setApiCode(null).setApiMsg(null);
  142 + }
  143 +
  144 + static String buildRequestBody(String sender, String receiver, String templateId, List<String> templateParas,
  145 + String statusCallBack, @SuppressWarnings("SameParameterValue") String signature) {
  146 + // TODO @scholar:参数不满足,是不是抛出异常更好哈;通过 hutool 的 Assert 去断言
  147 + if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty()
  148 + || templateId.isEmpty()) {
  149 + System.out.println("buildRequestBody(): sender, receiver or templateId is null.");
  150 + return null;
  151 + }
  152 +
  153 + StringBuilder body = new StringBuilder();
  154 + appendToBody(body, "from=", sender);
  155 + appendToBody(body, "&to=", receiver);
  156 + appendToBody(body, "&templateId=", templateId);
  157 + // TODO @scholar:new JSONArray(templateParas).toString(),是不是 JsonUtils.toString 呀?
  158 + appendToBody(body, "&templateParas=", new JSONArray(templateParas).toString());
  159 + appendToBody(body, "&statusCallback=", statusCallBack);
  160 + appendToBody(body, "&signature=", signature);
  161 + return body.toString();
  162 + }
  163 +
  164 + private static void appendToBody(StringBuilder body, String key, String val) {
  165 + // TODO @scholar:StrUtils.isNotEmpty(val),是不是更简洁哈
  166 + if (null != val && !val.isEmpty()) {
  167 + body.append(key).append(URLEncoder.encode(val, StandardCharsets.UTF_8));
  168 + }
  169 + }
  170 +
  171 + @Override
  172 + public List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) {
  173 + List<SmsReceiveStatus> statuses = JsonUtils.parseArray(text, SmsReceiveStatus.class);
  174 + return convertList(statuses, status -> new SmsReceiveRespDTO().setSuccess(Objects.equals(status.getStatus(),"DELIVRD"))
  175 + .setErrorCode(status.getStatus()).setErrorMsg(status.getStatus())
  176 + .setMobile(status.getPhoneNumber()).setReceiveTime(status.getUpdateTime())
  177 + .setSerialNo(status.getSmsMsgId()));
  178 + }
  179 +
  180 + @Override
  181 + public SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) throws Throwable {
  182 + // 华为短信模板查询和发送短信,是不同的两套 key 和 secret,与阿里、腾讯的区别较大,这里模板查询校验暂不实现
  183 + // 对应文档 https://support.huaweicloud.com/api-msgsms/sms_05_0040.html
  184 + return new SmsTemplateRespDTO().setId(apiTemplateId).setContent(null)
  185 + .setAuditStatus(SmsTemplateAuditStatusEnum.SUCCESS.getStatus()).setAuditReason(null);
  186 + }
  187 +
  188 + /**
  189 + * 短信接收状态
  190 + *
  191 + * 参见 <a href="https://support.huaweicloud.com/api-msgsms/sms_05_0003.html">文档</a>
  192 + *
  193 + * @author scholar
  194 + */
  195 + @Data
  196 + public static class SmsReceiveStatus {
  197 +
  198 + /**
  199 + * 本条状态报告对应的短信的接收方号码,仅当状态报告中携带了extend参数时才会同时携带该参数
  200 + */
  201 + @JsonProperty("to")
  202 + private String phoneNumber;
  203 +
  204 + /**
  205 + * 短信资源的更新时间,通常为短信平台接收短信状态报告的时间
  206 + */
  207 + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
  208 + private LocalDateTime updateTime;
  209 +
  210 + /**
  211 + * 短信状态报告枚举值
  212 + */
  213 + private String status;
  214 +
  215 + /**
  216 + * 发送短信成功时返回的短信唯一标识。
  217 + */
  218 + private String smsMsgId;
  219 + }
  220 +
  221 +}
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/SmsClientFactoryImpl.java
... ... @@ -78,6 +78,7 @@ public class SmsClientFactoryImpl implements SmsClientFactory {
78 78 case ALIYUN: return new AliyunSmsClient(properties);
79 79 case DEBUG_DING_TALK: return new DebugDingTalkSmsClient(properties);
80 80 case TENCENT: return new TencentSmsClient(properties);
  81 + case HUAWEI: return new HuaweiSmsClient(properties);
81 82 }
82 83 // 创建失败,错误日志 + 抛出异常
83 84 log.error("[createSmsClient][配置({}) 找不到合适的客户端实现]", properties);
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/sms/core/enums/SmsChannelEnum.java
... ... @@ -17,7 +17,7 @@ public enum SmsChannelEnum {
17 17 DEBUG_DING_TALK("DEBUG_DING_TALK", "调试(钉钉)"),
18 18 ALIYUN("ALIYUN", "阿里云"),
19 19 TENCENT("TENCENT", "腾讯云"),
20   -// HUA_WEI("HUA_WEI", "华为云"),
  20 + HUAWEI("HUAWEI", "华为云"),
21 21 ;
22 22  
23 23 /**
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java
... ... @@ -2,14 +2,14 @@ package cn.iocoder.yudao.module.system.service.social;
2 2  
3 3 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
5 6 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
6 7 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
7 8 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
8 9 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
9 10 import com.xingyuv.jushauth.model.AuthUser;
10   -import me.chanjar.weixin.common.bean.WxJsapiSignature;
11   -
12 11 import jakarta.validation.Valid;
  12 +import me.chanjar.weixin.common.bean.WxJsapiSignature;
13 13  
14 14 /**
15 15 * 社交应用 Service 接口
... ... @@ -21,8 +21,8 @@ public interface SocialClientService {
21 21 /**
22 22 * 获得社交平台的授权 URL
23 23 *
24   - * @param socialType 社交平台的类型 {@link SocialTypeEnum}
25   - * @param userType 用户类型
  24 + * @param socialType 社交平台的类型 {@link SocialTypeEnum}
  25 + * @param userType 用户类型
26 26 * @param redirectUri 重定向 URL
27 27 * @return 社交平台的授权 URL
28 28 */
... ... @@ -32,9 +32,9 @@ public interface SocialClientService {
32 32 * 请求社交平台,获得授权的用户
33 33 *
34 34 * @param socialType 社交平台的类型
35   - * @param userType 用户类型
36   - * @param code 授权码
37   - * @param state 授权 state
  35 + * @param userType 用户类型
  36 + * @param code 授权码
  37 + * @param state 授权 state
38 38 * @return 授权的用户
39 39 */
40 40 AuthUser getAuthUser(Integer socialType, Integer userType, String code, String state);
... ... @@ -45,7 +45,7 @@ public interface SocialClientService {
45 45 * 创建微信公众号的 JS SDK 初始化所需的签名
46 46 *
47 47 * @param userType 用户类型
48   - * @param url 访问的 URL 地址
  48 + * @param url 访问的 URL 地址
49 49 * @return 签名
50 50 */
51 51 WxJsapiSignature createWxMpJsapiSignature(Integer userType, String url);
... ... @@ -55,12 +55,20 @@ public interface SocialClientService {
55 55 /**
56 56 * 获得微信小程序的手机信息
57 57 *
58   - * @param userType 用户类型
  58 + * @param userType 用户类型
59 59 * @param phoneCode 手机授权码
60 60 * @return 手机信息
61 61 */
62 62 WxMaPhoneNumberInfo getWxMaPhoneNumberInfo(Integer userType, String phoneCode);
63 63  
  64 + /**
  65 + * 获得小程序二维码
  66 + *
  67 + * @param reqVO 请求信息
  68 + * @return 小程序二维码
  69 + */
  70 + byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO);
  71 +
64 72 // =================== 客户端管理 ===================
65 73  
66 74 /**
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
... ... @@ -9,10 +9,12 @@ import cn.hutool.core.lang.Assert;
9 9 import cn.hutool.core.util.ObjUtil;
10 10 import cn.hutool.core.util.ReflectUtil;
11 11 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  12 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
12 13 import cn.iocoder.yudao.framework.common.pojo.PageResult;
13 14 import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
14 15 import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
15 16 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  17 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
16 18 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
17 19 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
18 20 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
... ... @@ -39,6 +41,7 @@ import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
39 41 import me.chanjar.weixin.mp.api.WxMpService;
40 42 import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
41 43 import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
  44 +import org.springframework.beans.factory.annotation.Value;
42 45 import org.springframework.data.redis.core.StringRedisTemplate;
43 46 import org.springframework.stereotype.Service;
44 47  
... ... @@ -58,6 +61,12 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
58 61 @Slf4j
59 62 public class SocialClientServiceImpl implements SocialClientService {
60 63  
  64 + /**
  65 + * 小程序版本
  66 + */
  67 + @Value("${yudao.wxa-code.env-version}")
  68 + public String envVersion;
  69 +
61 70 @Resource
62 71 private AuthRequestFactory authRequestFactory;
63 72  
... ... @@ -139,7 +148,7 @@ public class SocialClientServiceImpl implements SocialClientService {
139 148 * 构建 AuthRequest 对象,支持多租户配置
140 149 *
141 150 * @param socialType 社交类型
142   - * @param userType 用户类型
  151 + * @param userType 用户类型
143 152 * @return AuthRequest 对象
144 153 */
145 154 @VisibleForTesting
... ... @@ -196,7 +205,7 @@ public class SocialClientServiceImpl implements SocialClientService {
196 205 /**
197 206 * 创建 clientId + clientSecret 对应的 WxMpService 对象
198 207 *
199   - * @param clientId 微信公众号 appId
  208 + * @param clientId 微信公众号 appId
200 209 * @param clientSecret 微信公众号 secret
201 210 * @return WxMpService 对象
202 211 */
... ... @@ -227,6 +236,25 @@ public class SocialClientServiceImpl implements SocialClientService {
227 236 }
228 237 }
229 238  
  239 + @Override
  240 + public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) {
  241 + WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
  242 + try {
  243 + return service.getQrcodeService().createWxaCodeUnlimitBytes(
  244 + ObjUtil.defaultIfEmpty(reqVO.getScene(), SocialWxQrcodeReqDTO.SCENE),
  245 + reqVO.getPath(),
  246 + ObjUtil.defaultIfNull(reqVO.getCheckPath(), SocialWxQrcodeReqDTO.CHECK_PATH),
  247 + envVersion,
  248 + ObjUtil.defaultIfNull(reqVO.getWidth(), SocialWxQrcodeReqDTO.WIDTH),
  249 + ObjUtil.defaultIfNull(reqVO.getAutoColor(), SocialWxQrcodeReqDTO.AUTO_COLOR),
  250 + null,
  251 + ObjUtil.defaultIfNull(reqVO.getHyaline(), SocialWxQrcodeReqDTO.HYALINE));
  252 + } catch (WxErrorException e) {
  253 + log.error("[getWxQrcode][reqVO({})) 获得小程序码失败]", reqVO, e);
  254 + throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR);
  255 + }
  256 + }
  257 +
230 258 /**
231 259 * 获得 clientId + clientSecret 对应的 WxMpService 对象
232 260 *
... ... @@ -248,7 +276,7 @@ public class SocialClientServiceImpl implements SocialClientService {
248 276 /**
249 277 * 创建 clientId + clientSecret 对应的 WxMaService 对象
250 278 *
251   - * @param clientId 微信小程序 appId
  279 + * @param clientId 微信小程序 appId
252 280 * @param clientSecret 微信小程序 secret
253 281 * @return WxMaService 对象
254 282 */
... ... @@ -310,8 +338,8 @@ public class SocialClientServiceImpl implements SocialClientService {
310 338 *
311 339 * 原因是,不同端(userType)选择某个社交登录(socialType)时,需要通过 {@link #buildAuthRequest(Integer, Integer)} 构建对应的请求
312 340 *
313   - * @param id 编号
314   - * @param userType 用户类型
  341 + * @param id 编号
  342 + * @param userType 用户类型
315 343 * @param socialType 社交类型
316 344 */
317 345 private void validateSocialClientUnique(Long id, Integer userType, Integer socialType) {
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java
... ... @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
6 6 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
  7 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
7 8 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
8 9 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
9 10 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java
... ... @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
6 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 7 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
8 8 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
  9 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
9 10 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
10 11 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO;
11 12 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
... ...
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/SmsClientTests.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.framework.sms.core.client.impl;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.KeyValue;
  4 +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO;
  5 +import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties;
  6 +import org.junit.jupiter.api.Disabled;
  7 +import org.junit.jupiter.api.Test;
  8 +
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * 各种 {@link SmsClientTests 集成测试
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +public class SmsClientTests {
  17 +
  18 + @Test
  19 + @Disabled
  20 + public void testHuaweiSmsClient() throws Throwable {
  21 + SmsChannelProperties properties = new SmsChannelProperties()
  22 + .setApiKey("123")
  23 + .setApiSecret("456");
  24 + HuaweiSmsClient client = new HuaweiSmsClient(properties);
  25 + // 准备参数
  26 + Long sendLogId = System.currentTimeMillis();
  27 + String mobile = "15601691323";
  28 + String apiTemplateId = "xx test01";
  29 + List<KeyValue<String, Object>> templateParams = List.of(new KeyValue<>("code", "1024"));
  30 + // 调用
  31 + SmsSendRespDTO smsSendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, templateParams);
  32 + // 打印结果
  33 + System.out.println(smsSendRespDTO);
  34 + }
  35 +
  36 +}
... ...
yudao-server/pom.xml
... ... @@ -46,11 +46,11 @@
46 46 <!-- <version>${revision}</version>-->
47 47 <!-- </dependency>-->
48 48 <!-- 工作流。默认注释,保证编译速度 -->
49   -<!-- <dependency>-->
50   -<!-- <groupId>cn.iocoder.boot</groupId>-->
51   -<!-- <artifactId>yudao-module-bpm-biz</artifactId>-->
52   -<!-- <version>${revision}</version>-->
53   -<!-- </dependency>-->
  49 + <dependency>
  50 + <groupId>cn.iocoder.boot</groupId>
  51 + <artifactId>yudao-module-bpm-biz</artifactId>
  52 + <version>${revision}</version>
  53 + </dependency>
54 54 <!-- 支付服务。默认注释,保证编译速度 -->
55 55 <!-- <dependency>-->
56 56 <!-- <groupId>cn.iocoder.boot</groupId>-->
... ... @@ -88,11 +88,11 @@
88 88 <!-- </dependency>-->
89 89  
90 90 <!-- CRM 相关模块。默认注释,保证编译速度 -->
91   -<!-- <dependency>-->
92   -<!-- <groupId>cn.iocoder.boot</groupId>-->
93   -<!-- <artifactId>yudao-module-crm-biz</artifactId>-->
94   -<!-- <version>${revision}</version>-->
95   -<!-- </dependency>-->
  91 + <dependency>
  92 + <groupId>cn.iocoder.boot</groupId>
  93 + <artifactId>yudao-module-crm-biz</artifactId>
  94 + <version>${revision}</version>
  95 + </dependency>
96 96  
97 97 <!-- ERP 相关模块。默认注释,保证编译速度 -->
98 98 <!-- <dependency>-->
... ...
yudao-server/src/main/resources/application-dev.yaml
... ... @@ -171,6 +171,8 @@ yudao:
171 171 order-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/order # 支付渠道的【支付】回调地址
172 172 refund-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/refund # 支付渠道的【退款】回调地址
173 173 demo: true # 开启演示模式
  174 + wxa-code:
  175 + env-version: release # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop"
174 176 tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
175 177  
176 178 justauth:
... ...
yudao-server/src/main/resources/application-local.yaml
... ... @@ -223,6 +223,8 @@ yudao:
223 223 access-log: # 访问日志的配置项
224 224 enable: false
225 225 demo: false # 关闭演示模式
  226 + wxa-code:
  227 + env-version: develop # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop"
226 228 tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
227 229  
228 230 justauth:
... ...
yudao-server/src/main/resources/application.yaml
... ... @@ -231,6 +231,8 @@ yudao:
231 231 license-url: https://gitee.com/zhijiantianya/ruoyi-vue-pro/blob/master/LICENSE
232 232 captcha:
233 233 enable: true # 验证码的开关,默认为 true
  234 + wxa-code:
  235 + env-version: release # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop"。默认为 release
234 236 codegen:
235 237 base-package: ${yudao.info.base-package}
236 238 db-schemas: ${spring.datasource.dynamic.datasource.master.name}
... ...