diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index ed4e39457..bb110f773 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -14,15 +14,14 @@ https://github.com/YunaiV/ruoyi-vue-pro - 2.0.1-jdk8-snapshot + 2.0.1-snapshot 1.5.0 - 2.7.18 - 2021.0.5 - 2021.0.4.0 + 3.2.1 + 2023.0.0 + 2022.0.0.0 - 2.5 - 1.6.15 + 2.2.0 4.3.0 1.2.21 @@ -31,33 +30,33 @@ 4.3.0 1.4.10 2.2.11 - 3.18.0 + 3.26.0 8.1.3.62 2.2.3 - 1.9.2 - 2.3.1 + 2.4.0 2.2.7 - 8.12.0 - 2.7.15 + 9.0.0 + 3.2.1 0.33.0 - 7.2.11.RELEASE + 8.0.1.RELEASE 1.0.13 - 4.11.0 + 5.2.0 - 6.8.0 + 7.0.1 - 1.0.8 + 2.0.3 1.17.2 1.18.30 1.5.5.Final - 5.8.25 + 5.8.25 + 6.0.0-M10 3.3.3 2.3 1.0.5 @@ -79,8 +78,8 @@ 4.6.4 2.2.1 3.1.880 - 1.0.8 - 1.6.6 + 2.0.5 + 1.6.6-beta2 2.12.2 4.6.0 @@ -172,14 +171,14 @@ - org.springdoc - springdoc-openapi-ui - ${springdoc.version} + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + ${knife4j.version} - com.github.xiaoymin - knife4j-openapi3-spring-boot-starter - ${knife4j.version} + org.springdoc + springdoc-openapi-starter-webmvc-api + ${springdoc.version} com.github.xiaoymin @@ -193,20 +192,15 @@ yudao-spring-boot-starter-mybatis ${revision} - - org.springdoc - springdoc-openapi-webflux-ui - ${springdoc.version} - com.alibaba - druid-spring-boot-starter + druid-spring-boot-3-starter ${druid.version} com.baomidou - mybatis-plus-boot-starter + mybatis-plus-spring-boot3-starter ${mybatis-plus.version} @@ -216,7 +210,7 @@ com.baomidou - dynamic-datasource-spring-boot-starter + dynamic-datasource-spring-boot3-starter ${dynamic-datasource.version} @@ -225,12 +219,6 @@ ${mybatis-plus-join.version} - - cn.iocoder.cloud - yudao-spring-boot-starter-redis - ${revision} - - com.fhs-opensource easy-trans-spring-boot-starter @@ -257,6 +245,12 @@ ${easy-trans.version} + + cn.iocoder.cloud + yudao-spring-boot-starter-redis + ${revision} + + org.redisson redisson-spring-boot-starter @@ -476,7 +470,12 @@ cn.hutool hutool-all - ${hutool.version} + ${hutool-5.version} + + + org.dromara.hutool + hutool-extra + ${hutool-6.version} @@ -509,22 +508,6 @@ ${fastjson.version} - - cn.smallbun.screw - screw-core - ${screw.version} - - - org.freemarker - freemarker - - - com.alibaba - fastjson - - - - com.google.guava guava @@ -654,7 +637,7 @@ org.jeecgframework.jimureport - jimureport-spring-boot-starter + jimureport-spring-boot3-starter ${jimureport.version} diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/DateIntervalEnum.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/DateIntervalEnum.java new file mode 100644 index 000000000..498b67124 --- /dev/null +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/DateIntervalEnum.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.framework.common.enums; + +import cn.hutool.core.util.ArrayUtil; +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 时间间隔的枚举 + * + * @author dhb52 + */ +@Getter +@AllArgsConstructor +public enum DateIntervalEnum implements IntArrayValuable { + + DAY(1, "天"), + WEEK(2, "周"), + MONTH(3, "月"), + QUARTER(4, "季度"), + YEAR(5, "年") + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DateIntervalEnum::getInterval).toArray(); + + /** + * 类型 + */ + private final Integer interval; + /** + * 名称 + */ + private final String name; + + @Override + public int[] array() { + return ARRAYS; + } + + public static DateIntervalEnum valueOf(Integer interval) { + return ArrayUtil.firstMatch(item -> item.getInterval().equals(interval), DateIntervalEnum.values()); + } + +} \ No newline at end of file diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/util/ServiceExceptionUtil.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/util/ServiceExceptionUtil.java index 966109fbf..03c085940 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/util/ServiceExceptionUtil.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/util/ServiceExceptionUtil.java @@ -6,74 +6,24 @@ import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstant import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - /** * {@link ServiceException} 工具类 * * 目的在于,格式化异常信息提示。 * 考虑到 String.format 在参数不正确时会报错,因此使用 {} 作为占位符,并使用 {@link #doFormat(int, String, Object...)} 方法来格式化 * - * 因为 {@link #MESSAGES} 里面默认是没有异常信息提示的模板的,所以需要使用方自己初始化进去。目前想到的有几种方式: - * - * 1. 异常提示信息,写在枚举类中,例如说,cn.iocoder.oceans.user.api.constants.ErrorCodeEnum 类 + ServiceExceptionConfiguration - * 2. 异常提示信息,写在 .properties 等等配置文件 - * 3. 异常提示信息,写在 Apollo 等等配置中心中,从而实现可动态刷新 - * 4. 异常提示信息,存储在 db 等等数据库中,从而实现可动态刷新 */ @Slf4j public class ServiceExceptionUtil { - /** - * 错误码提示模板 - */ - private static final ConcurrentMap MESSAGES = new ConcurrentHashMap<>(); - - public static void putAll(Map messages) { - ServiceExceptionUtil.MESSAGES.putAll(messages); - } - - public static void put(Integer code, String message) { - ServiceExceptionUtil.MESSAGES.put(code, message); - } - - public static void delete(Integer code, String message) { - ServiceExceptionUtil.MESSAGES.remove(code, message); - } - // ========== 和 ServiceException 的集成 ========== public static ServiceException exception(ErrorCode errorCode) { - String messagePattern = MESSAGES.getOrDefault(errorCode.getCode(), errorCode.getMsg()); - return exception0(errorCode.getCode(), messagePattern); + return exception0(errorCode.getCode(), errorCode.getMsg()); } public static ServiceException exception(ErrorCode errorCode, Object... params) { - String messagePattern = MESSAGES.getOrDefault(errorCode.getCode(), errorCode.getMsg()); - return exception0(errorCode.getCode(), messagePattern, params); - } - - /** - * 创建指定编号的 ServiceException 的异常 - * - * @param code 编号 - * @return 异常 - */ - public static ServiceException exception(Integer code) { - return exception0(code, MESSAGES.get(code)); - } - - /** - * 创建指定编号的 ServiceException 的异常 - * - * @param code 编号 - * @param params 消息提示的占位符对应的参数 - * @return 异常 - */ - public static ServiceException exception(Integer code, Object... params) { - return exception0(code, MESSAGES.get(code), params); + return exception0(errorCode.getCode(), errorCode.getMsg(), params); } public static ServiceException exception0(Integer code, String messagePattern, Object... params) { diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java index cb4ddec34..0d06bc799 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java @@ -78,7 +78,7 @@ public class CollectionUtils { if (CollUtil.isEmpty(from)) { return new ArrayList<>(); } - return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); + return from.stream().filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); } public static List convertListByFlatMap(Collection from, @@ -87,7 +87,7 @@ public class CollectionUtils { if (CollUtil.isEmpty(from)) { return new ArrayList<>(); } - return from.stream().map(mapper).flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); + return from.stream().map(mapper).filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); } public static List mergeValuesFromMap(Map> map) { @@ -123,7 +123,7 @@ public class CollectionUtils { if (CollUtil.isEmpty(from)) { return new HashSet<>(); } - return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); + return from.stream().filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); } public static Set convertSetByFlatMap(Collection from, @@ -132,7 +132,7 @@ public class CollectionUtils { if (CollUtil.isEmpty(from)) { return new HashSet<>(); } - return from.stream().map(mapper).flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); + return from.stream().map(mapper).filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); } public static Map convertMap(Collection from, Function keyFunc) { @@ -315,4 +315,4 @@ public class CollectionUtils { return list.stream().flatMap(Collection::stream).collect(Collectors.toList()); } -} +} \ No newline at end of file diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/MapUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/MapUtils.java index f4a17b523..a59b53fd4 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/MapUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/MapUtils.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.common.util.collection; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; @@ -40,6 +41,7 @@ public class MapUtils { /** * 从哈希表查找到 key 对应的 value,然后进一步处理 + * key 为 null 时, 不处理 * 注意,如果查找到的 value 为 null 时,不进行处理 * * @param map 哈希表 @@ -47,7 +49,7 @@ public class MapUtils { * @param consumer 进一步处理的逻辑 */ public static void findAndThen(Map map, K key, Consumer consumer) { - if (CollUtil.isEmpty(map)) { + if (ObjUtil.isNull(key) || CollUtil.isEmpty(map)) { return; } V value = map.get(key); diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java index 53b5574f9..b51a838c6 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java @@ -27,8 +27,6 @@ public class DateUtils { public static final String FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss"; - public static final String FORMAT_HOUR_MINUTE_SECOND = "HH:mm:ss"; - /** * 将 LocalDateTime 转换成 Date * @@ -67,19 +65,11 @@ public class DateUtils { return new Date(System.currentTimeMillis() + duration.toMillis()); } - public static boolean isExpired(Date time) { - return System.currentTimeMillis() > time.getTime(); - } - public static boolean isExpired(LocalDateTime time) { LocalDateTime now = LocalDateTime.now(); return now.isAfter(time); } - public static long diff(Date endTime, Date startTime) { - return endTime.getTime() - startTime.getTime(); - } - /** * 创建指定时间 * @@ -136,37 +126,6 @@ public class DateUtils { return a.isAfter(b) ? a : b; } - /** - * 计算当期时间相差的日期 - * - * @param field 日历字段.
eg:Calendar.MONTH,Calendar.DAY_OF_MONTH,
Calendar.HOUR_OF_DAY等. - * @param amount 相差的数值 - * @return 计算后的日志 - */ - public static Date addDate(int field, int amount) { - return addDate(null, field, amount); - } - - /** - * 计算当期时间相差的日期 - * - * @param date 设置时间 - * @param field 日历字段 例如说,{@link Calendar#DAY_OF_MONTH} 等 - * @param amount 相差的数值 - * @return 计算后的日志 - */ - public static Date addDate(Date date, int field, int amount) { - if (amount == 0) { - return date; - } - Calendar c = Calendar.getInstance(); - if (date != null) { - c.setTime(date); - } - c.add(field, amount); - return c.getTime(); - } - /** * 是否今天 * diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java index 87c20798e..acc93ad8c 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java @@ -1,13 +1,18 @@ package cn.iocoder.yudao.framework.common.util.date; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.common.enums.DateIntervalEnum; -import java.time.Duration; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; +import java.time.*; +import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAdjusters; +import java.util.ArrayList; +import java.util.List; /** * 时间工具类,用于 {@link java.time.LocalDateTime} @@ -21,6 +26,22 @@ public class LocalDateTimeUtils { */ public static LocalDateTime EMPTY = buildTime(1970, 1, 1); + /** + * 解析时间 + * + * 相比 {@link LocalDateTimeUtil#parse(CharSequence)} 方法来说,会尽量去解析,直到成功 + * + * @param time 时间 + * @return 时间字符串 + */ + public static LocalDateTime parse(String time) { + try { + return LocalDateTimeUtil.parse(time, DatePattern.NORM_DATE_PATTERN); + } catch (DateTimeParseException e) { + return LocalDateTimeUtil.parse(time); + } + } + public static LocalDateTime addTime(Duration duration) { return LocalDateTime.now().plus(duration); } @@ -54,6 +75,21 @@ public class LocalDateTimeUtils { return new LocalDateTime[]{buildTime(year1, mouth1, day1), buildTime(year2, mouth2, day2)}; } + /** + * 判指定断时间,是否在该时间范围内 + * + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param time 指定时间 + * @return 是否 + */ + public static boolean isBetween(LocalDateTime startTime, LocalDateTime endTime, String time) { + if (startTime == null || endTime == null || time == null) { + return false; + } + return LocalDateTimeUtil.isIn(parse(time), startTime, endTime); + } + /** * 判断当前时间是否在该时间范围内 * @@ -122,6 +158,16 @@ public class LocalDateTimeUtils { return date.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX); } + /** + * 获得指定日期所在季度 + * + * @param date 日期 + * @return 所在季度 + */ + public static int getQuarterOfYear(LocalDateTime date) { + return (date.getMonthValue() - 1) / 3 + 1; + } + /** * 获取指定日期到现在过了几天,如果指定日期在当前日期之后,获取结果为负 * @@ -168,4 +214,96 @@ public class LocalDateTimeUtils { return LocalDateTime.now().with(TemporalAdjusters.firstDayOfYear()).with(LocalTime.MIN); } + public static List getDateRangeList(LocalDateTime startTime, + LocalDateTime endTime, + Integer interval) { + // 1.1 找到枚举 + DateIntervalEnum intervalEnum = DateIntervalEnum.valueOf(interval); + Assert.notNull(intervalEnum, "interval({}} 找不到对应的枚举", interval); + // 1.2 将时间对齐 + startTime = LocalDateTimeUtil.beginOfDay(startTime); + endTime = LocalDateTimeUtil.endOfDay(endTime); + + // 2. 循环,生成时间范围 + List timeRanges = new ArrayList<>(); + switch (intervalEnum) { + case DateIntervalEnum.DAY: + while (startTime.isBefore(endTime)) { + timeRanges.add(new LocalDateTime[]{startTime, startTime.plusDays(1).minusNanos(1)}); + startTime = startTime.plusDays(1); + } + break; + case DateIntervalEnum.WEEK: + while (startTime.isBefore(endTime)) { + LocalDateTime endOfWeek = startTime.with(DayOfWeek.SUNDAY).plusDays(1).minusNanos(1); + timeRanges.add(new LocalDateTime[]{startTime, endOfWeek}); + startTime = endOfWeek.plusNanos(1); + } + break; + case DateIntervalEnum.MONTH: + while (startTime.isBefore(endTime)) { + LocalDateTime endOfMonth = startTime.with(TemporalAdjusters.lastDayOfMonth()).plusDays(1).minusNanos(1); + timeRanges.add(new LocalDateTime[]{startTime, endOfMonth}); + startTime = endOfMonth.plusNanos(1); + } + break; + case DateIntervalEnum.QUARTER: + while (startTime.isBefore(endTime)) { + int quarterOfYear = getQuarterOfYear(startTime); + LocalDateTime quarterEnd = quarterOfYear == 4 + ? startTime.with(TemporalAdjusters.lastDayOfYear()).plusDays(1).minusNanos(1) + : startTime.withMonth(quarterOfYear * 3 + 1).withDayOfMonth(1).minusNanos(1); + timeRanges.add(new LocalDateTime[]{startTime, quarterEnd}); + startTime = quarterEnd.plusNanos(1); + } + break; + case DateIntervalEnum.YEAR: + while (startTime.isBefore(endTime)) { + LocalDateTime endOfYear = startTime.with(TemporalAdjusters.lastDayOfYear()).plusDays(1).minusNanos(1); + timeRanges.add(new LocalDateTime[]{startTime, endOfYear}); + startTime = endOfYear.plusNanos(1); + } + break; + default: + throw new IllegalArgumentException("Invalid interval: " + interval); + } + // 3. 兜底,最后一个时间,需要保持在 endTime 之前 + LocalDateTime[] lastTimeRange = CollUtil.getLast(timeRanges); + if (lastTimeRange != null) { + lastTimeRange[1] = endTime; + } + return timeRanges; + } + + /** + * 格式化时间范围 + * + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param interval 时间间隔 + * @return 时间范围 + */ + public static String formatDateRange(LocalDateTime startTime, LocalDateTime endTime, Integer interval) { + // 1. 找到枚举 + DateIntervalEnum intervalEnum = DateIntervalEnum.valueOf(interval); + Assert.notNull(intervalEnum, "interval({}} 找不到对应的枚举", interval); + + // 2. 循环,生成时间范围 + switch (intervalEnum) { + case DateIntervalEnum.DAY: + return LocalDateTimeUtil.format(startTime, DatePattern.NORM_DATE_PATTERN); + case DateIntervalEnum.WEEK: + return LocalDateTimeUtil.format(startTime, DatePattern.NORM_DATE_PATTERN) + + StrUtil.format("(第 {} 周)", LocalDateTimeUtil.weekOfYear(startTime)); + case DateIntervalEnum.MONTH: + return LocalDateTimeUtil.format(startTime, DatePattern.NORM_MONTH_PATTERN); + case DateIntervalEnum.QUARTER: + return StrUtil.format("{}-Q{}", startTime.getYear(), getQuarterOfYear(startTime)); + case DateIntervalEnum.YEAR: + return LocalDateTimeUtil.format(startTime, DatePattern.NORM_YEAR_PATTERN); + default: + throw new IllegalArgumentException("Invalid interval: " + interval); + } + } + } diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/core/DictFrameworkUtils.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/core/DictFrameworkUtils.java index b827f4b0d..d964121ac 100644 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/core/DictFrameworkUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/core/DictFrameworkUtils.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.dict.core; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; +import cn.iocoder.yudao.framework.common.util.cache.CacheUtils; import cn.iocoder.yudao.module.system.api.dict.DictDataApi; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; import com.google.common.cache.CacheLoader; @@ -10,8 +11,7 @@ import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import java.time.Duration; - -import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; +import java.util.List; /** * 字典工具类 @@ -25,17 +25,31 @@ public class DictFrameworkUtils { private static final DictDataRespDTO DICT_DATA_NULL = new DictDataRespDTO(); + // TODO @puhui999:GET_DICT_DATA_CACHE、GET_DICT_DATA_LIST_CACHE、PARSE_DICT_DATA_CACHE 这 3 个缓存是有点重叠,可以思考下,有没可能减少 1 个。微信讨论好私聊,再具体改哈 /** * 针对 {@link #getDictDataLabel(String, String)} 的缓存 */ - private static final LoadingCache, DictDataRespDTO> GET_DICT_DATA_CACHE = buildAsyncReloadingCache( + private static final LoadingCache, DictDataRespDTO> GET_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache( Duration.ofMinutes(1L), // 过期时间 1 分钟 new CacheLoader, DictDataRespDTO>() { @Override public DictDataRespDTO load(KeyValue key) { - return ObjectUtil.defaultIfNull(dictDataApi.getDictData(key.getKey(), key.getValue()).getCheckedData(), - DICT_DATA_NULL); + return ObjectUtil.defaultIfNull(dictDataApi.getDictData(key.getKey(), key.getValue()).getCheckedData(), DICT_DATA_NULL); + } + + }); + + /** + * 针对 {@link #getDictDataLabelList(String)} 的缓存 + */ + private static final LoadingCache> GET_DICT_DATA_LIST_CACHE = CacheUtils.buildAsyncReloadingCache( + Duration.ofMinutes(1L), // 过期时间 1 分钟 + new CacheLoader>() { + + @Override + public List load(String dictType) { + return dictDataApi.getDictDataLabelList(dictType); } }); @@ -43,14 +57,13 @@ public class DictFrameworkUtils { /** * 针对 {@link #parseDictDataValue(String, String)} 的缓存 */ - private static final LoadingCache, DictDataRespDTO> PARSE_DICT_DATA_CACHE = buildAsyncReloadingCache( + private static final LoadingCache, DictDataRespDTO> PARSE_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache( Duration.ofMinutes(1L), // 过期时间 1 分钟 new CacheLoader, DictDataRespDTO>() { @Override public DictDataRespDTO load(KeyValue key) { - return ObjectUtil.defaultIfNull(dictDataApi.parseDictData(key.getKey(), key.getValue()).getCheckedData(), - DICT_DATA_NULL); + return ObjectUtil.defaultIfNull(dictDataApi.parseDictData(key.getKey(), key.getValue()).getCheckedData(), DICT_DATA_NULL); } }); @@ -70,6 +83,11 @@ public class DictFrameworkUtils { return GET_DICT_DATA_CACHE.get(new KeyValue<>(dictType, value)).getLabel(); } + @SneakyThrows + public static List getDictDataLabelList(String dictType) { + return GET_DICT_DATA_LIST_CACHE.get(dictType); + } + @SneakyThrows public static String parseDictDataValue(String dictType, String label) { return PARSE_DICT_DATA_CACHE.get(new KeyValue<>(dictType, label)).getValue(); diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/annotations/ExcelColumnSelect.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/annotations/ExcelColumnSelect.java new file mode 100644 index 000000000..b4ff140af --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/annotations/ExcelColumnSelect.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.framework.excel.core.annotations; + +import java.lang.annotation.*; + +/** + * 给 Excel 列添加下拉选择数据 + * + * 其中 {@link #dictType()} 和 {@link #functionName()} 二选一 + * + * @author HUIHUI + */ +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface ExcelColumnSelect { + + /** + * @return 字典类型 + */ + String dictType() default ""; + + /** + * @return 获取下拉数据源的方法名称 + */ + String functionName() default ""; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/enums/ExcelColumn.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/enums/ExcelColumn.java deleted file mode 100644 index dd8a8374c..000000000 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/enums/ExcelColumn.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.yudao.framework.excel.core.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -// TODO @puhui999:列表有办法通过 field name 么?主要考虑一个点,可能导入模版的顺序可能会变 -/** - * Excel 列名枚举 - * 默认枚举 26 列列名如果有需求更多的列名请自行补充 - * - * @author HUIHUI - */ -@Getter -@AllArgsConstructor -public enum ExcelColumn { - - A(0), B(1), C(2), D(3), E(4), F(5), G(6), H(7), I(8), - J(9), K(10), L(11), M(12), N(13), O(14), P(15), Q(16), - R(17), S(18), T(19), U(20), V(21), W(22), X(23), Y(24), - Z(25); - - /** - * 列索引 - */ - private final int colNum; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/function/ExcelColumnSelectFunction.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/function/ExcelColumnSelectFunction.java new file mode 100644 index 000000000..51953c463 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/function/ExcelColumnSelectFunction.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.framework.excel.core.function; + +import java.util.List; + +/** + * Excel 列下拉数据源获取接口 + * + * 为什么不直接解析字典还搞个接口?考虑到有的下拉数据不是从字典中获取的所有需要做一个兼容 + + * @author HUIHUI + */ +public interface ExcelColumnSelectFunction { + + /** + * 获得方法名称 + * + * @return 方法名称 + */ + String getName(); + + /** + * 获得列下拉数据源 + * + * @return 下拉数据源 + */ + List getOptions(); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java index 38d01bd87..22337f066 100644 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java @@ -2,25 +2,38 @@ package cn.iocoder.yudao.framework.excel.core.handler; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.spring.SpringUtil; +import cn.hutool.poi.excel.ExcelUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; -import cn.iocoder.yudao.framework.excel.core.enums.ExcelColumn; +import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils; +import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect; +import cn.iocoder.yudao.framework.excel.core.function.ExcelColumnSelectFunction; +import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.write.handler.SheetWriteHandler; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; +import lombok.extern.slf4j.Slf4j; import org.apache.poi.hssf.usermodel.HSSFDataValidation; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddressList; +import java.lang.reflect.Field; import java.util.Comparator; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; /** * 基于固定 sheet 实现下拉框 * * @author HUIHUI */ +@Slf4j public class SelectSheetWriteHandler implements SheetWriteHandler { /** @@ -36,21 +49,56 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { private static final String DICT_SHEET_NAME = "字典sheet"; - // TODO @puhui999:Map> 可以么?之前用 keyvalue 的原因,返回给前端,无法用 linkedhashmap,默认 key 会乱序 - private final List>> selectMap; + /** + * key: 列 value: 下拉数据源 + */ + private final Map> selectMap = new HashMap<>(); - public SelectSheetWriteHandler(List>> selectMap) { - if (CollUtil.isEmpty(selectMap)) { - this.selectMap = null; + public SelectSheetWriteHandler(Class head) { + // 加载下拉数据获取接口 + Map beansMap = SpringUtil.getBeanFactory().getBeansOfType(ExcelColumnSelectFunction.class); + if (MapUtil.isEmpty(beansMap)) { return; } - // 校验一下 key 是否唯一 - Map nameCounts = selectMap.stream() - .collect(Collectors.groupingBy(item -> item.getKey().name(), Collectors.counting())); - Assert.isFalse(nameCounts.entrySet().stream().allMatch(entry -> entry.getValue() > 1), "下拉数据 key 重复请排查!!!"); - selectMap.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错 - this.selectMap = selectMap; + // 解析下拉数据 + int colIndex = 0; + for (Field field : head.getDeclaredFields()) { + if (field.isAnnotationPresent(ExcelColumnSelect.class)) { + ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); + if (excelProperty != null && excelProperty.index() != -1) { + colIndex = excelProperty.index(); + } + getSelectDataList(colIndex, field); + } + colIndex++; + } + } + + /** + * 获得下拉数据,并添加到 {@link #selectMap} 中 + * + * @param colIndex 列索引 + * @param field 字段 + */ + private void getSelectDataList(int colIndex, Field field) { + ExcelColumnSelect columnSelect = field.getAnnotation(ExcelColumnSelect.class); + String dictType = columnSelect.dictType(); + String functionName = columnSelect.functionName(); + Assert.isTrue(ObjectUtil.isNotEmpty(dictType) || ObjectUtil.isNotEmpty(functionName), + "Field({}) 的 @ExcelColumnSelect 注解,dictType 和 functionName 不能同时为空", field.getName()); + + // 情况一:使用 dictType 获得下拉数据 + if (StrUtil.isNotEmpty(dictType)) { // 情况一: 字典数据 (默认) + selectMap.put(colIndex, DictFrameworkUtils.getDictDataLabelList(dictType)); + return; + } + + // 情况二:使用 functionName 获得下拉数据 + Map functionMap = SpringUtil.getApplicationContext().getBeansOfType(ExcelColumnSelectFunction.class); + ExcelColumnSelectFunction function = CollUtil.findOne(functionMap.values(), item -> item.getName().equals(functionName)); + Assert.notNull(function, "未找到对应的 function({})", functionName); + selectMap.put(colIndex, function.getOptions()); } @Override @@ -62,18 +110,20 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { // 1. 获取相应操作对象 DataValidationHelper helper = writeSheetHolder.getSheet().getDataValidationHelper(); // 需要设置下拉框的 sheet 页的数据验证助手 Workbook workbook = writeWorkbookHolder.getWorkbook(); // 获得工作簿 + List>> keyValues = convertList(selectMap.entrySet(), entry -> new KeyValue<>(entry.getKey(), entry.getValue())); + keyValues.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错 // 2. 创建数据字典的 sheet 页 Sheet dictSheet = workbook.createSheet(DICT_SHEET_NAME); - for (KeyValue> keyValue : selectMap) { + for (KeyValue> keyValue : keyValues) { int rowLength = keyValue.getValue().size(); - // 2.1 设置字典 sheet 页的值 每一列一个字典项 + // 2.1 设置字典 sheet 页的值,每一列一个字典项 for (int i = 0; i < rowLength; i++) { Row row = dictSheet.getRow(i); if (row == null) { row = dictSheet.createRow(i); } - row.createCell(keyValue.getKey().getColNum()).setCellValue(keyValue.getValue().get(i)); + row.createCell(keyValue.getKey()).setCellValue(keyValue.getValue().get(i)); } // 2.2 设置单元格下拉选择 setColumnSelect(writeSheetHolder, workbook, helper, keyValue); @@ -84,10 +134,10 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { * 设置单元格下拉选择 */ private static void setColumnSelect(WriteSheetHolder writeSheetHolder, Workbook workbook, DataValidationHelper helper, - KeyValue> keyValue) { + KeyValue> keyValue) { // 1.1 创建可被其他单元格引用的名称 Name name = workbook.createName(); - String excelColumn = keyValue.getKey().name(); + String excelColumn = ExcelUtil.indexToColName(keyValue.getKey()); // 1.2 下拉框数据来源 eg:字典sheet!$B1:$B2 String refers = DICT_SHEET_NAME + "!$" + excelColumn + "$1:$" + excelColumn + "$" + keyValue.getValue().size(); name.setNameName("dict" + keyValue.getKey()); // 设置名称的名字 @@ -97,7 +147,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { DataValidationConstraint constraint = helper.createFormulaListConstraint("dict" + keyValue.getKey()); // 设置引用约束 // 设置下拉单元格的首行、末行、首列、末列 CellRangeAddressList rangeAddressList = new CellRangeAddressList(FIRST_ROW, LAST_ROW, - keyValue.getKey().getColNum(), keyValue.getKey().getColNum()); + keyValue.getKey(), keyValue.getKey()); DataValidation validation = helper.createValidation(constraint, rangeAddressList); if (validation instanceof HSSFDataValidation) { validation.setSuppressDropDownArrow(false); diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java index c33cd8bf6..0bc59947f 100644 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java @@ -1,7 +1,5 @@ package cn.iocoder.yudao.framework.excel.core.util; -import cn.iocoder.yudao.framework.common.core.KeyValue; -import cn.iocoder.yudao.framework.excel.core.enums.ExcelColumn; import cn.iocoder.yudao.framework.excel.core.handler.SelectSheetWriteHandler; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.converters.longconverter.LongStringConverter; @@ -34,27 +32,11 @@ public class ExcelUtils { */ public static void write(HttpServletResponse response, String filename, String sheetName, Class head, List data) throws IOException { - write(response, filename, sheetName, head, data, null); - } - - /** - * 将列表以 Excel 响应给前端 - * - * @param response 响应 - * @param filename 文件名 - * @param sheetName Excel sheet 名 - * @param head Excel head 头 - * @param data 数据列表哦 - * @param selectMap 下拉选择数据 Map<下拉所对应的列表名,下拉数据> - * @throws IOException 写入失败的情况 - */ - public static void write(HttpServletResponse response, String filename, String sheetName, - Class head, List data, List>> selectMap) throws IOException { // 输出 Excel EasyExcel.write(response.getOutputStream(), head) .autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理 .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 基于 column 长度,自动适配。最大 255 宽度 - .registerWriteHandler(new SelectSheetWriteHandler(selectMap)) // 基于固定 sheet 实现下拉框 + .registerWriteHandler(new SelectSheetWriteHandler(head)) // 基于固定 sheet 实现下拉框 .registerConverter(new LongStringConverter()) // 避免 Long 类型丢失精度 .sheet(sheetName).doWrite(data); // 设置 header 和 contentType。写在最后的原因是,避免报错时,响应 contentType 已经被修改了 diff --git a/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/core/TimeoutRedisCacheManager.java b/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/core/TimeoutRedisCacheManager.java index 3e40c0be6..a835835de 100644 --- a/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/core/TimeoutRedisCacheManager.java +++ b/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/core/TimeoutRedisCacheManager.java @@ -40,12 +40,15 @@ public class TimeoutRedisCacheManager extends RedisCacheManager { // 核心:通过修改 cacheConfig 的过期时间,实现自定义过期时间 if (cacheConfig != null) { // 移除 # 后面的 : 以及后面的内容,避免影响解析 - names[1] = StrUtil.subBefore(names[1], StrUtil.COLON, false); + String ttlStr = StrUtil.subBefore(names[1], StrUtil.COLON, false); // 获得 ttlStr 时间部分 + names[1] = StrUtil.subAfter(names[1], ttlStr, false); // 移除掉 ttlStr 时间部分 // 解析时间 - Duration duration = parseDuration(names[1]); + Duration duration = parseDuration(ttlStr); cacheConfig = cacheConfig.entryTtl(duration); } - return super.createRedisCache(name, cacheConfig); + + // 创建 RedisCache 对象,需要忽略掉 ttlStr + return super.createRedisCache(names[0] + names[1], cacheConfig); } /** diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogV2Configuration.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogConfiguration.java similarity index 94% rename from yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogV2Configuration.java rename to yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogConfiguration.java index 866f94f78..eda6a1484 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogV2Configuration.java +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogConfiguration.java @@ -16,7 +16,7 @@ import org.springframework.context.annotation.Primary; @EnableLogRecord(tenant = "") // 貌似用不上 tenant 这玩意给个空好啦 @AutoConfiguration @Slf4j -public class YudaoOperateLogV2Configuration { +public class YudaoOperateLogConfiguration { @Bean @Primary diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogV2RpcAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogRpcAutoConfiguration.java similarity index 89% rename from yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogV2RpcAutoConfiguration.java rename to yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogRpcAutoConfiguration.java index 39e01dcc7..6518b7dac 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogV2RpcAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogRpcAutoConfiguration.java @@ -11,5 +11,5 @@ import org.springframework.cloud.openfeign.EnableFeignClients; */ @AutoConfiguration @EnableFeignClients(clients = {OperateLogApi.class}) // 主要是引入相关的 API 服务 -public class YudaoOperateLogV2RpcAutoConfiguration { +public class YudaoOperateLogRpcAutoConfiguration { } diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-framework/yudao-spring-boot-starter-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 939468e95..ef08215aa 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,5 +1,5 @@ cn.iocoder.yudao.framework.security.config.YudaoSecurityRpcAutoConfiguration cn.iocoder.yudao.framework.security.config.YudaoSecurityAutoConfiguration cn.iocoder.yudao.framework.security.config.YudaoWebSecurityConfigurerAdapter -cn.iocoder.yudao.framework.operatelog.config.YudaoOperateLogV2Configuration -cn.iocoder.yudao.framework.operatelog.config.YudaoOperateLogV2RpcAutoConfiguration \ No newline at end of file +cn.iocoder.yudao.framework.operatelog.config.YudaoOperateLogConfiguration +cn.iocoder.yudao.framework.operatelog.config.YudaoOperateLogRpcAutoConfiguration \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/config/ErrorCodeProperties.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/config/ErrorCodeProperties.java deleted file mode 100644 index 1c1d1b8a5..000000000 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/config/ErrorCodeProperties.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.framework.errorcode.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; - -import javax.validation.constraints.NotNull; -import java.util.List; - -/** - * 错误码的配置属性类 - * - * @author dlyan - */ -@ConfigurationProperties("yudao.error-code") -@Data -@Validated -public class ErrorCodeProperties { - - /** - * 是否开启 - */ - private Boolean enable = true; - /** - * 错误码枚举类 - */ - @NotNull(message = "错误码枚举类不能为空") - private List constantsClassList; - -} diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeAutoConfiguration.java deleted file mode 100644 index ed2c92fc2..000000000 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeAutoConfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.framework.errorcode.config; - -import cn.iocoder.yudao.framework.errorcode.core.generator.ErrorCodeAutoGenerator; -import cn.iocoder.yudao.framework.errorcode.core.generator.ErrorCodeAutoGeneratorImpl; -import cn.iocoder.yudao.framework.errorcode.core.loader.ErrorCodeLoader; -import cn.iocoder.yudao.framework.errorcode.core.loader.ErrorCodeLoaderImpl; -import cn.iocoder.yudao.module.system.api.errorcode.ErrorCodeApi; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.scheduling.annotation.EnableScheduling; - -/** - * 错误码配置类 - * - * @author 芋道源码 - */ -@AutoConfiguration -@ConditionalOnProperty(prefix = "yudao.error-code", value = "enable", matchIfMissing = true) // 允许使用 yudao.error-code.enable=false 禁用访问日志 -@EnableConfigurationProperties(ErrorCodeProperties.class) -@EnableScheduling // 开启调度任务的功能,因为 ErrorCodeRemoteLoader 通过定时刷新错误码 -public class YudaoErrorCodeAutoConfiguration { - - @Bean - public ErrorCodeAutoGenerator errorCodeAutoGenerator(@Value("${spring.application.name}") String applicationName, - ErrorCodeProperties errorCodeProperties, - ErrorCodeApi errorCodeApi) { - return new ErrorCodeAutoGeneratorImpl(applicationName, errorCodeProperties.getConstantsClassList(), errorCodeApi); - } - - @Bean - public ErrorCodeLoader errorCodeLoader(@Value("${spring.application.name}") String applicationName, - ErrorCodeApi errorCodeApi) { - return new ErrorCodeLoaderImpl(applicationName, errorCodeApi); - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeRpcAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeRpcAutoConfiguration.java deleted file mode 100644 index 8de68ca35..000000000 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/config/YudaoErrorCodeRpcAutoConfiguration.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.yudao.framework.errorcode.config; - -import cn.iocoder.yudao.module.system.api.errorcode.ErrorCodeApi; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.cloud.openfeign.EnableFeignClients; - -/** - * 错误码用到 Feign 的配置项 - * - * @author 芋道源码 - */ -@AutoConfiguration -@EnableFeignClients(clients = ErrorCodeApi.class) // 主要是引入相关的 API 服务 -public class YudaoErrorCodeRpcAutoConfiguration { -} diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/generator/ErrorCodeAutoGenerator.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/generator/ErrorCodeAutoGenerator.java deleted file mode 100644 index b13cacaa2..000000000 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/generator/ErrorCodeAutoGenerator.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.yudao.framework.errorcode.core.generator; - -/** - * 错误码的自动生成器 - * - * @author dylan - */ -public interface ErrorCodeAutoGenerator { - - /** - * 将配置类到错误码写入数据库 - */ - void execute(); - -} diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/generator/ErrorCodeAutoGeneratorImpl.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/generator/ErrorCodeAutoGeneratorImpl.java deleted file mode 100644 index f2131e5b7..000000000 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/generator/ErrorCodeAutoGeneratorImpl.java +++ /dev/null @@ -1,108 +0,0 @@ -package cn.iocoder.yudao.framework.errorcode.core.generator; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.exceptions.ExceptionUtil; -import cn.hutool.core.util.ClassUtil; -import cn.hutool.core.util.ReflectUtil; -import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import cn.iocoder.yudao.module.system.api.errorcode.ErrorCodeApi; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * ErrorCodeAutoGenerator 的实现类 - * 目的是,扫描指定的 {@link #constantsClassList} 类,写入到 system 服务中 - * - * @author dylan - */ -@RequiredArgsConstructor -@Slf4j -public class ErrorCodeAutoGeneratorImpl implements ErrorCodeAutoGenerator { - - /** - * 应用分组 - */ - private final String applicationName; - /** - * 错误码枚举类 - */ - private final List constantsClassList; - /** - * 错误码 Api - */ - private final ErrorCodeApi errorCodeApi; - - @Override - @EventListener(ApplicationReadyEvent.class) - @Async // 异步,保证项目的启动过程,毕竟非关键流程 - public void execute() { - // 第一步,解析错误码 - List autoGenerateDTOs = parseErrorCode(); - log.info("[execute][解析到错误码数量为 ({}) 个]", autoGenerateDTOs.size()); - - // 第二步,写入到 system 服务 - try { - errorCodeApi.autoGenerateErrorCodeList(autoGenerateDTOs).checkError(); - log.info("[execute][写入到 system 组件完成]"); - } catch (Exception ex) { - log.error("[execute][写入到 system 组件失败({})]", ExceptionUtil.getRootCauseMessage(ex)); - } - } - - /** - * 解析 constantsClassList 变量,转换成错误码数组 - * - * @return 错误码数组 - */ - private List parseErrorCode() { - // 校验 errorCodeConstantsClass 参数 - if (CollUtil.isEmpty(constantsClassList)) { - log.info("[execute][未配置 yudao.error-code.constants-class-list 配置项,不进行自动写入到 system 服务中]"); - return new ArrayList<>(); - } - - // 解析错误码 - List autoGenerateDTOs = new ArrayList<>(); - constantsClassList.forEach(constantsClass -> { - try { - // 解析错误码枚举类 - Class errorCodeConstantsClazz = ClassUtil.loadClass(constantsClass); - // 解析错误码 - autoGenerateDTOs.addAll(parseErrorCode(errorCodeConstantsClazz)); - } catch (Exception ex) { - log.warn("[parseErrorCode][constantsClass({}) 加载失败({})]", constantsClass, - ExceptionUtil.getRootCauseMessage(ex)); - } - }); - return autoGenerateDTOs; - } - - /** - * 解析错误码类,获得错误码数组 - * - * @return 错误码数组 - */ - private List parseErrorCode(Class constantsClass) { - List autoGenerateDTOs = new ArrayList<>(); - Arrays.stream(constantsClass.getFields()).forEach(field -> { - if (field.getType() != ErrorCode.class) { - return; - } - // 转换成 ErrorCodeAutoGenerateReqDTO 对象 - ErrorCode errorCode = (ErrorCode) ReflectUtil.getFieldValue(constantsClass, field); - autoGenerateDTOs.add(new ErrorCodeAutoGenerateReqDTO().setApplicationName(applicationName) - .setCode(errorCode.getCode()).setMessage(errorCode.getMsg())); - }); - return autoGenerateDTOs; - } - -} - diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/loader/ErrorCodeLoader.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/loader/ErrorCodeLoader.java deleted file mode 100644 index 0bf70211f..000000000 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/loader/ErrorCodeLoader.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.framework.errorcode.core.loader; - -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; - -/** - * 错误码加载器 - * - * 注意,错误码最终加载到 {@link ServiceExceptionUtil} 的 MESSAGES 变量中! - * - * @author dlyan - */ -public interface ErrorCodeLoader { - - /** - * 添加错误码 - * - * @param code 错误码的编号 - * @param msg 错误码的提示 - */ - default void putErrorCode(Integer code, String msg) { - ServiceExceptionUtil.put(code, msg); - } - - /** - * 刷新错误码 - */ - void refreshErrorCodes(); - - /** - * 加载错误码 - */ - void loadErrorCodes(); - -} diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/loader/ErrorCodeLoaderImpl.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/loader/ErrorCodeLoaderImpl.java deleted file mode 100644 index 64d08630d..000000000 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/core/loader/ErrorCodeLoaderImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -package cn.iocoder.yudao.framework.errorcode.core.loader; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.exceptions.ExceptionUtil; -import cn.iocoder.yudao.framework.common.util.date.DateUtils; -import cn.iocoder.yudao.module.system.api.errorcode.ErrorCodeApi; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * ErrorCodeLoader 的实现类,从 infra 的数据库中,加载错误码。 - * - * 考虑到错误码会刷新,所以按照 {@link #REFRESH_ERROR_CODE_PERIOD} 频率,增量加载错误码。 - * - * @author dlyan - */ -@RequiredArgsConstructor -@Slf4j -public class ErrorCodeLoaderImpl implements ErrorCodeLoader { - - /** - * 刷新错误码的频率,单位:毫秒 - */ - private static final int REFRESH_ERROR_CODE_PERIOD = 60 * 1000; - - /** - * 应用分组 - */ - private final String applicationName; - /** - * 错误码 Api - */ - private final ErrorCodeApi errorCodeApi; - - /** - * 缓存错误码的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - private LocalDateTime maxUpdateTime; - - @Override - @EventListener(ApplicationReadyEvent.class) - @Async // 异步,保证项目的启动过程,毕竟非关键流程 - public void loadErrorCodes() { - loadErrorCodes0(); - } - - @Override - @Scheduled(fixedDelay = REFRESH_ERROR_CODE_PERIOD, initialDelay = REFRESH_ERROR_CODE_PERIOD) - public void refreshErrorCodes() { - loadErrorCodes0(); - } - - private void loadErrorCodes0() { - try { - // 加载错误码 - List errorCodeRespDTOs = errorCodeApi.getErrorCodeList(applicationName, maxUpdateTime).getCheckedData(); - if (CollUtil.isEmpty(errorCodeRespDTOs)) { - return; - } - log.info("[loadErrorCodes0][加载到 ({}) 个错误码]", errorCodeRespDTOs.size()); - - // 刷新错误码的缓存 - errorCodeRespDTOs.forEach(errorCodeRespDTO -> { - // 写入到错误码的缓存 - putErrorCode(errorCodeRespDTO.getCode(), errorCodeRespDTO.getMessage()); - // 记录下更新时间,方便增量更新 - maxUpdateTime = DateUtils.max(maxUpdateTime, errorCodeRespDTO.getUpdateTime()); - }); - } catch (Exception ex) { - log.error("[loadErrorCodes0][加载错误码失败({})]", ExceptionUtil.getRootCauseMessage(ex)); - } - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/package-info.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/package-info.java deleted file mode 100644 index ddba4f78a..000000000 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * 错误码 ErrorCode 的自动配置功能,提供如下功能: - * - * 1. 远程读取:项目启动时,从 system-service 服务,读取数据库中的 ErrorCode 错误码,实现错误码的提水可配置; - * 2. 自动更新:管理员在管理后台修数据库中的 ErrorCode 错误码时,项目自动从 system-service 服务加载最新的 ErrorCode 错误码; - * 3. 自动写入:项目启动时,将项目本地的错误码写到 system-server 服务中,方便管理员在管理后台编辑; - * - * @author 芋道源码 - */ -package cn.iocoder.yudao.framework.errorcode; diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index c23f48ff3..a751bb458 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -3,6 +3,4 @@ cn.iocoder.yudao.framework.jackson.config.YudaoJacksonAutoConfiguration cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration cn.iocoder.yudao.framework.apilog.config.YudaoApiLogRpcAutoConfiguration -cn.iocoder.yudao.framework.banner.config.YudaoBannerAutoConfiguration -cn.iocoder.yudao.framework.errorcode.config.YudaoErrorCodeRpcAutoConfiguration -cn.iocoder.yudao.framework.errorcode.config.YudaoErrorCodeAutoConfiguration \ No newline at end of file +cn.iocoder.yudao.framework.banner.config.YudaoBannerAutoConfiguration \ No newline at end of file diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-local.yaml b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-local.yaml index 6b22d9a50..ee5ce30e0 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-local.yaml +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-local.yaml @@ -128,6 +128,4 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application.yaml b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application.yaml index da4749c57..bd377f272 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application.yaml +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application.yaml @@ -117,9 +117,6 @@ yudao: timeout: 5m width: 160 height: 60 - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java index a15a3211b..27fb6f9ce 100644 --- a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java +++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java @@ -15,6 +15,7 @@ public interface ErrorCodeConstants { ErrorCode CONTRACT_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_002, "合同提交审核失败,原因:合同没处在未提交状态"); ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是审核中状态"); ErrorCode CONTRACT_NO_EXISTS = new ErrorCode(1_020_000_004, "生成合同序列号重复,请重试"); + ErrorCode CONTRACT_DELETE_FAIL = new ErrorCode(1_020_000_005, "删除合同失败,原因:有被回款所使用"); // ========== 线索管理 1-020-001-000 ========== ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); @@ -40,6 +41,7 @@ public interface ErrorCodeConstants { ErrorCode RECEIVABLE_NO_EXISTS = new ErrorCode(1_020_004_005, "生成回款序列号重复,请重试"); ErrorCode RECEIVABLE_CREATE_FAIL_CONTRACT_NOT_APPROVE = new ErrorCode(1_020_004_006, "创建回款失败,原因:合同不是审核通过状态"); ErrorCode RECEIVABLE_CREATE_FAIL_PRICE_EXCEEDS_LIMIT = new ErrorCode(1_020_004_007, "创建回款失败,原因:回款金额超出合同金额,目前剩余可退:{} 元"); + ErrorCode RECEIVABLE_DELETE_FAIL_IS_APPROVE = new ErrorCode(1_020_004_008, "删除回款失败,原因:回款审批已通过"); // ========== 回款计划 1-020-005-000 ========== ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在"); @@ -72,6 +74,7 @@ public interface ErrorCodeConstants { ErrorCode CRM_PERMISSION_DELETE_DENIED = new ErrorCode(1_020_007_006, "删除数据权限失败,原因:没有权限"); ErrorCode CRM_PERMISSION_DELETE_SELF_PERMISSION_FAIL_EXIST_OWNER = new ErrorCode(1_020_007_007, "删除数据权限失败,原因:不能删除负责人"); ErrorCode CRM_PERMISSION_CREATE_FAIL = new ErrorCode(1_020_007_008, "创建数据权限失败,原因:所加用户已有权限"); + ErrorCode CRM_PERMISSION_CREATE_FAIL_EXISTS = new ErrorCode(1_020_007_009, "同时添加数据权限失败,原因:用户【{}】已有模块【{}】数据【{}】的【{}】权限"); // ========== 产品 1_020_008_000 ========== ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_020_008_000, "产品不存在"); @@ -100,4 +103,6 @@ public interface ErrorCodeConstants { ErrorCode FOLLOW_UP_RECORD_NOT_EXISTS = new ErrorCode(1_020_013_000, "跟进记录不存在"); ErrorCode FOLLOW_UP_RECORD_DELETE_DENIED = new ErrorCode(1_020_013_001, "删除跟进记录失败,原因:没有权限"); + // ========== 数据统计 1_020_014_000 ========== + } diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java index c2c835b7f..aeeed316d 100644 --- a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java +++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java @@ -142,11 +142,11 @@ public interface LogRecordConstants { String CRM_RECEIVABLE_TYPE = "CRM 回款"; String CRM_RECEIVABLE_CREATE_SUB_TYPE = "创建回款"; - String CRM_RECEIVABLE_CREATE_SUCCESS = "创建了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款"; + String CRM_RECEIVABLE_CREATE_SUCCESS = "创建了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款"; String CRM_RECEIVABLE_UPDATE_SUB_TYPE = "更新回款"; - String CRM_RECEIVABLE_UPDATE_SUCCESS = "更新了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款: {_DIFF{#updateReqVO}}"; + String CRM_RECEIVABLE_UPDATE_SUCCESS = "更新了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款: {_DIFF{#updateReqVO}}"; String CRM_RECEIVABLE_DELETE_SUB_TYPE = "删除回款"; - String CRM_RECEIVABLE_DELETE_SUCCESS = "删除了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款"; + String CRM_RECEIVABLE_DELETE_SUCCESS = "删除了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款"; String CRM_RECEIVABLE_SUBMIT_SUB_TYPE = "提交回款审批"; String CRM_RECEIVABLE_SUBMIT_SUCCESS = "提交编号为【{{#receivableNo}}】的回款审批成功"; diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java index 7b44fe962..f36e8cfff 100644 --- a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java +++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.crm.enums.permission; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; @@ -50,4 +51,10 @@ public enum CrmPermissionLevelEnum implements IntArrayValuable { return ObjUtil.equal(WRITE.level, level); } + public static String getNameByLevel(Integer level) { + CrmPermissionLevelEnum typeEnum = CollUtil.findOne(CollUtil.newArrayList(CrmPermissionLevelEnum.values()), + item -> ObjUtil.equal(item.level, level)); + return typeEnum == null ? null : typeEnum.getName(); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java index 971c0a4f4..43fc3d723 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java @@ -66,13 +66,13 @@ public class CrmBusinessSaveReqVO { private Long contactId; // 使用场景,在【联系人详情】添加商机时,如果需要关联两者,需要传递 contactId 字段 @Schema(description = "产品列表") - private List products; + private List businessProducts; @Schema(description = "产品列表") @Data @NoArgsConstructor @AllArgsConstructor - public static class Product { + public static class BusinessProduct { @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529") @NotNull(message = "产品编号不能为空") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java index 0b19f2f95..e26ddfa63 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java @@ -2,11 +2,15 @@ package cn.iocoder.yudao.module.crm.controller.admin.business.vo.business; import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; import io.swagger.v3.oas.annotations.media.Schema; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Schema(description = "管理后台 - 商机转移 Request VO") @Data +@NoArgsConstructor +@AllArgsConstructor public class CrmBusinessTransferReqVO { @Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java index 213c977db..8e11af932 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java @@ -2,12 +2,15 @@ package cn.iocoder.yudao.module.crm.controller.admin.contact.vo; import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Data; - -import javax.validation.constraints.NotNull; +import lombok.NoArgsConstructor; @Schema(description = "管理后台 - CRM 联系人转移 Request VO") @Data +@NoArgsConstructor +@AllArgsConstructor public class CrmContactTransferReqVO { @Schema(description = "联系人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java index 57c9fe65a..c42dcbfcc 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java @@ -3,12 +3,15 @@ package cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract; import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Data; - -import javax.validation.constraints.NotNull; +import lombok.NoArgsConstructor; @Schema(description = "管理后台 - CRM 合同转移 Request VO") @Data +@NoArgsConstructor +@AllArgsConstructor public class CrmContractTransferReqVO { @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java index 0d2031bd7..3b5116545 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; -import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; @@ -11,9 +10,7 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.excel.core.enums.ExcelColumn; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.ip.core.Area; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer.*; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; @@ -22,7 +19,6 @@ import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerPoolConfigService import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; -import cn.iocoder.yudao.module.system.api.dict.DictDataApi; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import io.swagger.v3.oas.annotations.Operation; @@ -38,7 +34,6 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -49,7 +44,6 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.*; import static java.util.Collections.singletonList; @Tag(name = "管理后台 - CRM 客户") @@ -67,8 +61,6 @@ public class CrmCustomerController { private DeptApi deptApi; @Resource private AdminUserApi adminUserApi; - @Resource - private DictDataApi dictDataApi; @PostMapping("/create") @Operation(summary = "创建客户") @@ -142,7 +134,7 @@ public class CrmCustomerController { return java.util.Collections.emptyList(); } // 1.1 获取创建人、负责人列表 - Map userMap = adminUserApi.getUserMap(convertListByFlatMap(list, + Map userMap = adminUserApi.getUserMap(convertSetByFlatMap(list, contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); // 1.2 获取距离进入公海的时间 @@ -265,25 +257,7 @@ public class CrmCustomerController { .areaId(null).detailAddress("").remark("").build() ); // 输出 - ExcelUtils.write(response, "客户导入模板.xls", "客户列表", CrmCustomerImportExcelVO.class, list, builderSelectMap()); - } - - private List>> builderSelectMap() { - List>> selectMap = new ArrayList<>(); - // 获取地区下拉数据 - // TODO @puhui999:嘿嘿,这里改成省份、城市、区域,三个选项,难度大么? - Area area = AreaUtils.getArea(Area.ID_CHINA); - selectMap.add(new KeyValue<>(ExcelColumn.G, AreaUtils.getAreaNodePathList(area.getChildren()))); - // 获取客户所属行业 - List customerIndustries = dictDataApi.getDictDataLabelList(CRM_CUSTOMER_INDUSTRY); - selectMap.add(new KeyValue<>(ExcelColumn.I, customerIndustries)); - // 获取客户等级 - List customerLevels = dictDataApi.getDictDataLabelList(CRM_CUSTOMER_LEVEL); - selectMap.add(new KeyValue<>(ExcelColumn.J, customerLevels)); - // 获取客户来源 - List customerSources = dictDataApi.getDictDataLabelList(CRM_CUSTOMER_SOURCE); - selectMap.add(new KeyValue<>(ExcelColumn.K, customerSources)); - return selectMap; + ExcelUtils.write(response, "客户导入模板.xls", "客户列表", CrmCustomerImportExcelVO.class, list); } @PostMapping("/import") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java index 2c39472fd..a45e9115f 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java @@ -1,8 +1,10 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect; import cn.iocoder.yudao.framework.excel.core.convert.AreaConvert; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.crm.framework.excel.core.AreaExcelColumnSelectFunction; import com.alibaba.excel.annotation.ExcelProperty; import lombok.AllArgsConstructor; import lombok.Builder; @@ -41,6 +43,7 @@ public class CrmCustomerImportExcelVO { private String email; @ExcelProperty(value = "地区", converter = AreaConvert.class) + @ExcelColumnSelect(functionName = AreaExcelColumnSelectFunction.NAME) private Integer areaId; @ExcelProperty("详细地址") @@ -48,14 +51,17 @@ public class CrmCustomerImportExcelVO { @ExcelProperty(value = "所属行业", converter = DictConvert.class) @DictFormat(CRM_CUSTOMER_INDUSTRY) + @ExcelColumnSelect(dictType = CRM_CUSTOMER_INDUSTRY) private Integer industryId; @ExcelProperty(value = "客户等级", converter = DictConvert.class) @DictFormat(CRM_CUSTOMER_LEVEL) + @ExcelColumnSelect(dictType = CRM_CUSTOMER_LEVEL) private Integer level; @ExcelProperty(value = "客户来源", converter = DictConvert.class) @DictFormat(CRM_CUSTOMER_SOURCE) + @ExcelColumnSelect(dictType = CRM_CUSTOMER_SOURCE) private Integer source; @ExcelProperty("备注") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java index 009933b8d..467ac8ad4 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java @@ -5,6 +5,8 @@ import io.swagger.v3.oas.annotations.media.Schema; import javax.validation.constraints.NotNull; import lombok.Data; +import java.util.List; + @Schema(description = "管理后台 - CRM 客户转移 Request VO") @Data public class CrmCustomerTransferReqVO { @@ -28,4 +30,10 @@ public class CrmCustomerTransferReqVO { @Schema(description = "老负责人加入团队后的权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") private Integer oldOwnerPermissionLevel; + /** + * 转移客户时,需要额外有【联系人】【商机】【合同】的 checkbox 选择。选中时,也一起转移 + */ + @Schema(description = "同时转移", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") + private List toBizTypes; + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java index e5d173c9d..e44980fec 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java @@ -5,14 +5,13 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO; import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionSaveReqVO; import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission; import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; -import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.PostApi; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; @@ -50,7 +49,6 @@ public class CrmPermissionController { @Resource private CrmPermissionService permissionService; - @Resource private AdminUserApi adminUserApi; @Resource @@ -61,9 +59,8 @@ public class CrmPermissionController { @PostMapping("/create") @Operation(summary = "创建数据权限") @PreAuthorize("@ss.hasPermission('crm:permission:create')") - @CrmPermission(bizTypeValue = "#reqVO.bizType", bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER) - public CommonResult addPermission(@Valid @RequestBody CrmPermissionCreateReqVO reqVO) { - permissionService.createPermission(BeanUtils.toBean(reqVO, CrmPermissionCreateReqBO.class)); + public CommonResult create(@Valid @RequestBody CrmPermissionSaveReqVO reqVO) { + permissionService.createPermission(reqVO, getLoginUserId()); return success(true); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionCreateReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionCreateReqVO.java deleted file mode 100644 index 99793389b..000000000 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.crm.controller.admin.permission.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - CRM 数据权限创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class CrmPermissionCreateReqVO extends CrmPermissionBaseVO { - -} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionRespVO.java index 10f1ce198..aeddf1a5d 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionRespVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionRespVO.java @@ -1,6 +1,10 @@ package cn.iocoder.yudao.module.crm.controller.admin.permission.vo; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; +import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; import lombok.Data; import java.time.LocalDateTime; @@ -8,11 +12,29 @@ import java.util.Set; @Schema(description = "管理后台 - CRM 数据权限 Response VO") @Data -public class CrmPermissionRespVO extends CrmPermissionBaseVO { +public class CrmPermissionRespVO { @Schema(description = "数据权限编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563") private Long id; + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") + @NotNull(message = "用户编号不能为空") + private Long userId; + + @Schema(description = "CRM 类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @InEnum(CrmBizTypeEnum.class) + @NotNull(message = "CRM 类型不能为空") + private Integer bizType; + + @Schema(description = "CRM 类型数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "CRM 类型数据编号不能为空") + private Long bizId; + + @Schema(description = "权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @InEnum(CrmPermissionLevelEnum.class) + @NotNull(message = "权限级别不能为空") + private Integer level; + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") private String nickname; diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionBaseVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionSaveReqVO.java similarity index 69% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionBaseVO.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionSaveReqVO.java index 1b56dde2e..0b7a53610 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionBaseVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionSaveReqVO.java @@ -4,18 +4,14 @@ import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; import lombok.Data; -import javax.validation.constraints.NotNull; +import java.util.List; -/** - * 数据权限 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - * - * @author HUIHUI - */ +@Schema(description = "管理后台 - CRM 数据权限创建/更新 Request VO") @Data -public class CrmPermissionBaseVO { +public class CrmPermissionSaveReqVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") @NotNull(message = "用户编号不能为空") @@ -35,4 +31,11 @@ public class CrmPermissionBaseVO { @NotNull(message = "权限级别不能为空") private Integer level; + /** + * 添加客户团队成员时,需要额外有【联系人】【商机】【合同】的 checkbox 选择。 + * 选中时,同时添加对应的权限 + */ + @Schema(description = "同时添加", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") + private List toBizTypes; + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/plan/CrmReceivablePlanRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/plan/CrmReceivablePlanRespVO.java index 1c58766e1..ad1ce3a7b 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/plan/CrmReceivablePlanRespVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/plan/CrmReceivablePlanRespVO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan; import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -8,53 +9,69 @@ import lombok.Data; import java.math.BigDecimal; import java.time.LocalDateTime; -// TODO @puhui999:缺导出 @Schema(description = "管理后台 - CRM 回款计划 Response VO") @Data +@ExcelIgnoreUnannotated public class CrmReceivablePlanRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty("编号") private Long id; @Schema(description = "期数", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty("期数") private Integer period; @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty("客户编号") private Long customerId; @Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test") + @ExcelProperty("客户名字") private String customerName; @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty("合同编号") private Long contractId; @Schema(description = "合同编号", example = "Q110") + @ExcelProperty("合同编号") private String contractNo; @Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty("负责人编号") private Long ownerUserId; @Schema(description = "负责人", example = "test") + @ExcelProperty("负责人") private String ownerUserName; @Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02") + @ExcelProperty("计划回款日期") private LocalDateTime returnTime; @Schema(description = "计划回款方式", example = "1") + @ExcelProperty("计划回款方式") private Integer returnType; @Schema(description = "计划回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000") + @ExcelProperty("计划回款金额") private BigDecimal price; @Schema(description = "回款编号", example = "19852") + @ExcelProperty("回款编号") private Long receivableId; @Schema(description = "回款信息") + @ExcelProperty("回款信息") private CrmReceivableRespVO receivable; @Schema(description = "提前几天提醒", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty("提前几天提醒") private Integer remindDays; @Schema(description = "提醒日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02") + @ExcelProperty("提醒日期") private LocalDateTime remindTime; @Schema(description = "备注", example = "备注") + @ExcelProperty("备注") private String remark; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/receivable/CrmReceivableRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/receivable/CrmReceivableRespVO.java index a9fcb1b8b..12dcbaa02 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/receivable/CrmReceivableRespVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/receivable/CrmReceivableRespVO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable; import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -8,37 +9,47 @@ import lombok.Data; import java.math.BigDecimal; import java.time.LocalDateTime; -// TODO 芋艿:导出的 VO,可以考虑使用 @Excel 注解,实现导出功能 @Schema(description = "管理后台 - CRM 回款 Response VO") @Data +@ExcelIgnoreUnannotated public class CrmReceivableRespVO { @Schema(description = "编号", example = "25787") + @ExcelProperty("编号") private Long id; @Schema(description = "回款编号", example = "31177") + @ExcelProperty("回款编号") private String no; @Schema(description = "回款计划编号", example = "1024") + @ExcelProperty("回款计划编号") private Long planId; @Schema(description = "回款方式", example = "2") + @ExcelProperty("回款方式") private Integer returnType; @Schema(description = "回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000") + @ExcelProperty("回款金额") private BigDecimal price; @Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02") + @ExcelProperty("计划回款日期") private LocalDateTime returnTime; @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty("客户编号") private Long customerId; @Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test") + @ExcelProperty("客户名字") private String customerName; @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty("合同编号") private Long contractId; @Schema(description = "合同信息") + @ExcelProperty("合同信息") private CrmContractRespVO contract; @Schema(description = "负责人的用户编号", example = "25682") @@ -56,20 +67,26 @@ public class CrmReceivableRespVO { private String processInstanceId; @Schema(description = "审批状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @ExcelProperty("审批状态") private Integer auditStatus; - @Schema(description = "备注", example = "备注") + @Schema(description = "工作流编号", example = "备注") + @ExcelProperty("工作流编号") private String remark; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime createTime; @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("更新时间") private LocalDateTime updateTime; @Schema(description = "创建人", example = "25682") + @ExcelProperty("创建人") private String creator; @Schema(description = "创建人名字", example = "test") + @ExcelProperty("创建人名字") private String creatorName; } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsCustomerController.http b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsCustomerController.http new file mode 100644 index 000000000..389bf4ac9 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsCustomerController.http @@ -0,0 +1,55 @@ +# == 1. 客户总量分析 == +### 1.1 客户总量分析(按日期) +GET {{baseUrl}}/crm/statistics-customer/get-customer-summary-by-date?deptId=100&interval=2×[0]=2024-01-01 00:00:00×[1]=2024-01-29 23:59:59 +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +### 1.2 客户总量统计(按用户) +GET {{baseUrl}}/crm/statistics-customer/get-customer-summary-by-user?deptId=100×[0]=2023-01-01 00:00:00×[1]=2024-12-12 23:59:59 +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +# == 2. 客户跟进次数分析 == +### 2.1 客户跟进次数分析(按日期) +GET {{baseUrl}}/crm/statistics-customer/get-follow-up-summary-by-date?deptId=100&interval=2×[0]=2024-01-01 00:00:00×[1]=2024-01-29 23:59:59 +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +### 2.2 客户总量统计(按用户) +GET {{baseUrl}}/crm/statistics-customer/get-follow-up-summary-by-user?deptId=100×[0]=2023-01-01 00:00:00×[1]=2024-12-12 23:59:59 +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +# == 3. 客户跟进方式分析 == +### 3.1 客户跟进方式分析 +GET {{baseUrl}}/crm/statistics-customer/get-follow-up-summary-by-type?deptId=100&interval=2×[0]=2023-01-01 00:00:00×[1]=2024-12-12 23:59:59 +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +# == 4. 客户成交周期 == +### 4.1 合同摘要信息(客户转化率页面) +GET {{baseUrl}}/crm/statistics-customer/get-contract-summary?deptId=100&interval=2×[0]=2023-01-01 00:00:00×[1]=2024-12-12 23:59:59 +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +# == 5. 客户成交周期 == +### 5.1 获取客户公海分析(按日期) +GET {{baseUrl}}/crm/statistics-customer/get-pool-summary-by-date?deptId=100&interval=2×[0]=2023-01-01 00:00:00×[1]=2024-12-12 23:59:59 +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +### 5.2 获取客户公海分析(按用户) +GET {{baseUrl}}/crm/statistics-customer/get-pool-summary-by-user?deptId=100×[0]=2023-01-01 00:00:00×[1]=2024-12-12 23:59:59 +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +# == 6. 客户成交周期 == +### 6.1 客户成交周期(按日期) +GET {{baseUrl}}/crm/statistics-customer/get-customer-deal-cycle-by-date?deptId=100&interval=2×[0]=2024-01-01 00:00:00×[1]=2024-01-29 23:59:59 +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +### 6.2 获取客户成交周期(按用户) +GET {{baseUrl}}/crm/statistics-customer/get-customer-deal-cycle-by-user?deptId=100×[0]=2023-01-01 00:00:00×[1]=2024-12-12 23:59:59 +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsCustomerController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsCustomerController.java new file mode 100644 index 000000000..51d149900 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsCustomerController.java @@ -0,0 +1,101 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; +import cn.iocoder.yudao.module.crm.service.statistics.CrmStatisticsCustomerService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - CRM 客户统计") +@RestController +@RequestMapping("/crm/statistics-customer") +@Validated +public class CrmStatisticsCustomerController { + + @Resource + private CrmStatisticsCustomerService customerService; + + @GetMapping("/get-customer-summary-by-date") + @Operation(summary = "获取客户总量分析(按日期)") + @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") + public CommonResult> getCustomerSummaryByDate(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(customerService.getCustomerSummaryByDate(reqVO)); + } + + @GetMapping("/get-customer-summary-by-user") + @Operation(summary = "获取客户总量分析(按用户)") + @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") + public CommonResult> getCustomerSummaryByUser(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(customerService.getCustomerSummaryByUser(reqVO)); + } + + @GetMapping("/get-follow-up-summary-by-date") + @Operation(summary = "获取客户跟进次数分析(按日期)") + @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") + public CommonResult> getFollowupSummaryByDate(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(customerService.getFollowUpSummaryByDate(reqVO)); + } + + @GetMapping("/get-follow-up-summary-by-user") + @Operation(summary = "获取客户跟进次数分析(按用户)") + @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") + public CommonResult> getFollowUpSummaryByUser(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(customerService.getFollowUpSummaryByUser(reqVO)); + } + + @GetMapping("/get-follow-up-summary-by-type") + @Operation(summary = "获取客户跟进次数分析(按类型)") + @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") + public CommonResult> getFollowUpSummaryByType(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(customerService.getFollowUpSummaryByType(reqVO)); + } + + @GetMapping("/get-contract-summary") + @Operation(summary = "获取客户的首次合同、回款信息列表", description = "用于【客户转化率】页面") + @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") + public CommonResult> getContractSummary(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(customerService.getContractSummary(reqVO)); + } + + @GetMapping("/get-pool-summary-by-date") + @Operation(summary = "获取公海客户分析(按日期)") + @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") + public CommonResult> getPoolSummaryByDate(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(customerService.getPoolSummaryByDate(reqVO)); + } + + @GetMapping("/get-pool-summary-by-user") + @Operation(summary = "获取公海客户分析(按用户)") + @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") + public CommonResult> getPoolSummaryByUser(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(customerService.getPoolSummaryByUser(reqVO)); + } + + @GetMapping("/get-customer-deal-cycle-by-date") + @Operation(summary = "获取客户成交周期(按日期)") + @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") + public CommonResult> getCustomerDealCycleByDate(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(customerService.getCustomerDealCycleByDate(reqVO)); + } + + @GetMapping("/get-customer-deal-cycle-by-user") + @Operation(summary = "获取客户成交周期(按用户)") + @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") + public CommonResult> getCustomerDealCycleByUser(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(customerService.getCustomerDealCycleByUser(reqVO)); + } + + // TODO dhb52:【成交周期分析】里,有按照员工(已实现)、地区(未实现)、产品(未实现),需要在看看哈;可以把 CustomerDealCycle 拆成 3 个 tab,员工客户成交周期分析、地区客户成交周期分析、产品客户成交周期分析; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPerformanceController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPerformanceController.java new file mode 100644 index 000000000..417cb0ff7 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPerformanceController.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; +import cn.iocoder.yudao.module.crm.service.statistics.CrmStatisticsPerformanceService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + + +@Tag(name = "管理后台 - CRM 员工业绩统计") +@RestController +@RequestMapping("/crm/statistics-performance") +@Validated +public class CrmStatisticsPerformanceController { + + @Resource + private CrmStatisticsPerformanceService performanceService; + + @GetMapping("/get-contract-count-performance") + @Operation(summary = "合同数量统计", description = "用于【合同数量分析】页面") + @PreAuthorize("@ss.hasPermission('crm:statistics-performance:query')") + public CommonResult> getContractCountPerformance(@Valid CrmStatisticsPerformanceReqVO performanceReqVO) { + return success(performanceService.getContractCountPerformance(performanceReqVO)); + } + + @GetMapping("/get-contract-price-performance") + @Operation(summary = "合同金额统计") + @PreAuthorize("@ss.hasPermission('crm:statistics-performance:query')") + public CommonResult> getContractPriceStaffPerformance(@Valid CrmStatisticsPerformanceReqVO performanceReqVO) { + return success(performanceService.getContractPricePerformance(performanceReqVO)); + } + + @GetMapping("/get-receivable-price-performance") + @Operation(summary = "回款金额统计") + @PreAuthorize("@ss.hasPermission('crm:statistics-performance:query')") + public CommonResult> getReceivablePriceStaffPerformance(@Valid CrmStatisticsPerformanceReqVO performanceReqVO) { + return success(performanceService.getReceivablePricePerformance(performanceReqVO)); + } + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPortraitController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPortraitController.java new file mode 100644 index 000000000..9a84adf77 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPortraitController.java @@ -0,0 +1,57 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.*; +import cn.iocoder.yudao.module.crm.service.statistics.CrmStatisticsPortraitService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - CRM 客户画像") +@RestController +@RequestMapping("/crm/statistics-portrait") +@Validated +public class CrmStatisticsPortraitController { + + @Resource + private CrmStatisticsPortraitService statisticsPortraitService; + + @GetMapping("/get-customer-area-summary") + @Operation(summary = "获取客户地区统计数据", description = "用于【城市分布分析】页面") + @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") + public CommonResult> getCustomerAreaSummary(@Valid CrmStatisticsPortraitReqVO reqVO) { + return success(statisticsPortraitService.getCustomerSummaryByArea(reqVO)); + } + + @GetMapping("/get-customer-industry-summary") + @Operation(summary = "获取客户行业统计数据", description = "用于【客户行业分析】页面") + @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") + public CommonResult> getCustomerIndustrySummary(@Valid CrmStatisticsPortraitReqVO reqVO) { + return success(statisticsPortraitService.getCustomerSummaryByIndustry(reqVO)); + } + + @GetMapping("/get-customer-level-summary") + @Operation(summary = "获取客户级别统计数据", description = "用于【客户级别分析】页面") + @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") + public CommonResult> getCustomerLevelSummary(@Valid CrmStatisticsPortraitReqVO reqVO) { + return success(statisticsPortraitService.getCustomerSummaryByLevel(reqVO)); + } + + @GetMapping("/get-customer-source-summary") + @Operation(summary = "获取客户来源统计数据", description = "用于【客户来源分析】页面") + @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") + public CommonResult> getCustomerSourceSummary(@Valid CrmStatisticsPortraitReqVO reqVO) { + return success(statisticsPortraitService.getCustomerSummaryBySource(reqVO)); + } + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsRankController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsRankController.java index d73d7637e..627b5961d 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsRankController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsRankController.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.crm.controller.admin.statistics; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.CrmStatisticsRanKRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.CrmStatisticsRankReqVO; -import cn.iocoder.yudao.module.crm.service.statistics.CrmStatisticsRankingService; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.rank.CrmStatisticsRankReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.rank.CrmStatisticsRankRespVO; +import cn.iocoder.yudao.module.crm.service.statistics.CrmStatisticsRankService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; @@ -18,7 +18,6 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - @Tag(name = "管理后台 - CRM 排行榜统计") @RestController @RequestMapping("/crm/statistics-rank") @@ -26,62 +25,62 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; public class CrmStatisticsRankController { @Resource - private CrmStatisticsRankingService rankingService; + private CrmStatisticsRankService rankService; @GetMapping("/get-contract-price-rank") @Operation(summary = "获得合同金额排行榜") @PreAuthorize("@ss.hasPermission('crm:statistics-rank:query')") - public CommonResult> getContractPriceRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { - return success(rankingService.getContractPriceRank(rankingReqVO)); + public CommonResult> getContractPriceRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { + return success(rankService.getContractPriceRank(rankingReqVO)); } @GetMapping("/get-receivable-price-rank") @Operation(summary = "获得回款金额排行榜") @PreAuthorize("@ss.hasPermission('crm:statistics-rank:query')") - public CommonResult> getReceivablePriceRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { - return success(rankingService.getReceivablePriceRank(rankingReqVO)); + public CommonResult> getReceivablePriceRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { + return success(rankService.getReceivablePriceRank(rankingReqVO)); } @GetMapping("/get-contract-count-rank") @Operation(summary = "获得签约合同数量排行榜") @PreAuthorize("@ss.hasPermission('crm:statistics-rank:query')") - public CommonResult> getContractCountRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { - return success(rankingService.getContractCountRank(rankingReqVO)); + public CommonResult> getContractCountRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { + return success(rankService.getContractCountRank(rankingReqVO)); } @GetMapping("/get-product-sales-rank") @Operation(summary = "获得产品销量排行榜") @PreAuthorize("@ss.hasPermission('crm:statistics-rank:query')") - public CommonResult> getProductSalesRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { - return success(rankingService.getProductSalesRank(rankingReqVO)); + public CommonResult> getProductSalesRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { + return success(rankService.getProductSalesRank(rankingReqVO)); } @GetMapping("/get-customer-count-rank") @Operation(summary = "获得新增客户数排行榜") @PreAuthorize("@ss.hasPermission('crm:statistics-rank:query')") - public CommonResult> getCustomerCountRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { - return success(rankingService.getCustomerCountRank(rankingReqVO)); + public CommonResult> getCustomerCountRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { + return success(rankService.getCustomerCountRank(rankingReqVO)); } @GetMapping("/get-contacts-count-rank") @Operation(summary = "获得新增联系人数排行榜") @PreAuthorize("@ss.hasPermission('crm:statistics-rank:query')") - public CommonResult> getContactsCountRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { - return success(rankingService.getContactsCountRank(rankingReqVO)); + public CommonResult> getContactsCountRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { + return success(rankService.getContactsCountRank(rankingReqVO)); } @GetMapping("/get-follow-count-rank") @Operation(summary = "获得跟进次数排行榜") @PreAuthorize("@ss.hasPermission('crm:statistics-rank:query')") - public CommonResult> getFollowCountRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { - return success(rankingService.getFollowCountRank(rankingReqVO)); + public CommonResult> getFollowCountRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { + return success(rankService.getFollowCountRank(rankingReqVO)); } @GetMapping("/get-follow-customer-count-rank") @Operation(summary = "获得跟进客户数排行榜") @PreAuthorize("@ss.hasPermission('crm:statistics-rank:query')") - public CommonResult> getFollowCustomerCountRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { - return success(rankingService.getFollowCustomerCountRank(rankingReqVO)); + public CommonResult> getFollowCustomerCountRank(@Valid CrmStatisticsRankReqVO rankingReqVO) { + return success(rankService.getFollowCustomerCountRank(rankingReqVO)); } } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerByUserBaseRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerByUserBaseRespVO.java new file mode 100644 index 000000000..bde0029c6 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerByUserBaseRespVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 用户客户统计响应 Base Response VO + * + * 目的:可以统一拼接子 VO 的 ownerUserId、ownerUserName 属性 + */ +@Data +public class CrmStatisticsCustomerByUserBaseRespVO { + + @Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long ownerUserId; + + @Schema(description = "负责人", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码") + private String ownerUserName; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerContractSummaryRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerContractSummaryRespVO.java new file mode 100644 index 000000000..fa03d4609 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerContractSummaryRespVO.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - CRM 客户转化率分析 VO") +@Data +public class CrmStatisticsCustomerContractSummaryRespVO { + + @Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码") + private String customerName; + + @Schema(description = "合同名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "演示合同") + private String contractName; + + @Schema(description = "合同总金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1200.00") + private BigDecimal totalPrice; + + @Schema(description = "回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1200.00") + private BigDecimal receivablePrice; + + @Schema(description = "客户行业编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + private Integer industryId; + + @Schema(description = "客户来源编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer source; + + @Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long ownerUserId; + @Schema(description = "负责人", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码") + private String ownerUserName; + + @Schema(description = "创建人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + private String creator; + @Schema(description = "创建人", requiredMode = Schema.RequiredMode.REQUIRED, example = "源码") + private String creatorUserName; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-01 13:24:26") + private LocalDateTime createTime; + + @Schema(description = "下单日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02 00:00:00") + private LocalDateTime orderDate; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerDealCycleByDateRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerDealCycleByDateRespVO.java new file mode 100644 index 000000000..62facb053 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerDealCycleByDateRespVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 客户成交周期分析(按日期) VO") +@Data +public class CrmStatisticsCustomerDealCycleByDateRespVO { + + @Schema(description = "时间轴", requiredMode = Schema.RequiredMode.REQUIRED, example = "202401") + private String time; + + @Schema(description = "成交周期", requiredMode = Schema.RequiredMode.REQUIRED, example = "1.0") + private Double customerDealCycle; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerDealCycleByUserRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerDealCycleByUserRespVO.java new file mode 100644 index 000000000..1c394b8b4 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerDealCycleByUserRespVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 成交周期分析(按用户) VO") +@Data +public class CrmStatisticsCustomerDealCycleByUserRespVO extends CrmStatisticsCustomerByUserBaseRespVO { + + @Schema(description = "成交周期", requiredMode = Schema.RequiredMode.REQUIRED, example = "1.0") + private Double customerDealCycle; + + @Schema(description = "成交客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerDealCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerReqVO.java new file mode 100644 index 000000000..b32a35ee9 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerReqVO.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + +import cn.iocoder.yudao.framework.common.enums.DateIntervalEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - CRM 数据统计的员工客户分析 Request VO") +@Data +public class CrmStatisticsCustomerReqVO { + + @Schema(description = "部门 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "部门 id 不能为空") + private Long deptId; + + /** + * 负责人用户 id, 当用户为空, 则计算部门下用户 + */ + @Schema(description = "负责人用户 id", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "1") + private Long userId; + + /** + * userIds 目前不用前端传递,目前是方便后端通过 deptId 读取编号后,设置回来 + * 后续,可能会支持选择部分用户进行查询 + */ + @Schema(description = "负责人用户 id 集合", hidden = true, example = "2") + private List userIds; + + @Schema(description = "时间间隔类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @InEnum(value = DateIntervalEnum.class, message = "时间间隔类型,必须是 {value}") + private Integer interval; + + @Schema(description = "时间范围", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @Size(min = 2, max = 2, message = "请选择时间范围") + private LocalDateTime[] times; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerSummaryByDateRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerSummaryByDateRespVO.java new file mode 100644 index 000000000..7ffcb20ff --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerSummaryByDateRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 客户总量分析(按日期) VO") +@Data +public class CrmStatisticsCustomerSummaryByDateRespVO { + + @Schema(description = "时间轴", requiredMode = Schema.RequiredMode.REQUIRED, example = "202401") + private String time; + + @Schema(description = "新建客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerCreateCount; + + @Schema(description = "成交客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerDealCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerSummaryByUserRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerSummaryByUserRespVO.java new file mode 100644 index 000000000..fa8372b8b --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerSummaryByUserRespVO.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.math.BigDecimal; + +@Schema(description = "管理后台 - CRM 客户总量分析(按用户) VO") +@Data +public class CrmStatisticsCustomerSummaryByUserRespVO extends CrmStatisticsCustomerByUserBaseRespVO { + + @Schema(description = "新建客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerCreateCount; + + @Schema(description = "成交客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerDealCount; + + @Schema(description = "合同总金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") + private BigDecimal contractPrice; + + @Schema(description = "回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") + private BigDecimal receivablePrice; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsFollowUpSummaryByDateRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsFollowUpSummaryByDateRespVO.java new file mode 100644 index 000000000..9040c1eab --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsFollowUpSummaryByDateRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 跟进次数分析(按日期) VO") +@Data +public class CrmStatisticsFollowUpSummaryByDateRespVO { + + @Schema(description = "时间轴", requiredMode = Schema.RequiredMode.REQUIRED, example = "202401") + private String time; + + @Schema(description = "跟进次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer followUpRecordCount; + + @Schema(description = "跟进客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer followUpCustomerCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsFollowUpSummaryByTypeRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsFollowUpSummaryByTypeRespVO.java new file mode 100644 index 000000000..d39f1cc0d --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsFollowUpSummaryByTypeRespVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 跟进次数分析(按类型) VO") +@Data +public class CrmStatisticsFollowUpSummaryByTypeRespVO { + + @Schema(description = "跟进类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer followUpType; + + @Schema(description = "跟进次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer followUpRecordCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsFollowUpSummaryByUserRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsFollowUpSummaryByUserRespVO.java new file mode 100644 index 000000000..065135626 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsFollowUpSummaryByUserRespVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 跟进次数分析(按用户) VO") +@Data +public class CrmStatisticsFollowUpSummaryByUserRespVO extends CrmStatisticsCustomerByUserBaseRespVO { + + @Schema(description = "跟进次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer followUpRecordCount; + + @Schema(description = "跟进客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer followUpCustomerCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsPoolSummaryByDateRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsPoolSummaryByDateRespVO.java new file mode 100644 index 000000000..ce09a9933 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsPoolSummaryByDateRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 公海客户分析(按日期) VO") +@Data +public class CrmStatisticsPoolSummaryByDateRespVO { + + @Schema(description = "时间轴", requiredMode = Schema.RequiredMode.REQUIRED, example = "202401") + private String time; + + @Schema(description = "进入公海客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerPutCount; + + @Schema(description = "公海领取客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerTakeCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsPoolSummaryByUserRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsPoolSummaryByUserRespVO.java new file mode 100644 index 000000000..fb59e8477 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsPoolSummaryByUserRespVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 公海客户分析(按用户) VO") +@Data +public class CrmStatisticsPoolSummaryByUserRespVO extends CrmStatisticsCustomerByUserBaseRespVO { + + @Schema(description = "进入公海客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerPutCount; + + @Schema(description = "公海领取客户数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerTakeCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/performance/CrmStatisticsPerformanceReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/performance/CrmStatisticsPerformanceReqVO.java new file mode 100644 index 000000000..d104e375b --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/performance/CrmStatisticsPerformanceReqVO.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - CRM 员工业绩统计 Request VO") +@Data +public class CrmStatisticsPerformanceReqVO { + + @Schema(description = "部门 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "部门 id 不能为空") + private Long deptId; + + /** + * 负责人用户 id, 当用户为空, 则计算部门下用户 + */ + @Schema(description = "负责人用户 id", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "1") + private Long userId; + + /** + * userIds 目前不用前端传递,目前是方便后端通过 deptId 读取编号后,设置回来 + *

+ * 后续,可能会支持选择部分用户进行查询 + */ + @Schema(description = "负责人用户 id 集合", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "2") + private List userIds; + + // TODO @scholar:应该传递的是 int year;年份 + @Schema(description = "时间范围", requiredMode = Schema.RequiredMode.REQUIRED) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @NotEmpty(message = "时间范围不能为空") + private LocalDateTime[] times; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/performance/CrmStatisticsPerformanceRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/performance/CrmStatisticsPerformanceRespVO.java new file mode 100644 index 000000000..f2cb9be60 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/performance/CrmStatisticsPerformanceRespVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.math.BigDecimal; + + +@Schema(description = "管理后台 - CRM 员工业绩统计 Response VO") +@Data +public class CrmStatisticsPerformanceRespVO { + + @Schema(description = "时间轴", requiredMode = Schema.RequiredMode.REQUIRED, example = "202401") + private String time; + + @Schema(description = "当月统计结果", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private BigDecimal currentMonthCount; + + @Schema(description = "上月统计结果", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + private BigDecimal lastMonthCount; + + @Schema(description = "去年同期统计结果", requiredMode = Schema.RequiredMode.REQUIRED, example = "3") + private BigDecimal lastYearCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerAreaRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerAreaRespVO.java new file mode 100644 index 000000000..3420e7e5b --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerAreaRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 客户省份分析 VO") +@Data +public class CrmStatisticCustomerAreaRespVO { + + @Schema(description = "省份编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer areaId; + @Schema(description = "省份名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "浙江省") + private String areaName; + + @Schema(description = "客户个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerCount; + + @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer dealCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerIndustryRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerIndustryRespVO.java new file mode 100644 index 000000000..84b8de70f --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerIndustryRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 客户行业分析 VO") +@Data +public class CrmStatisticCustomerIndustryRespVO { + + @Schema(description = "客户行业ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + private Integer industryId; + + @Schema(description = "客户个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerCount; + + @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer dealCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerLevelRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerLevelRespVO.java new file mode 100644 index 000000000..dea4eeb0c --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerLevelRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 客户级别分析 VO") +@Data +public class CrmStatisticCustomerLevelRespVO { + + @Schema(description = "客户级别编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + private Integer level; + + @Schema(description = "客户个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerCount; + + @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer dealCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerSourceRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerSourceRespVO.java new file mode 100644 index 000000000..61b9688ff --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerSourceRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - CRM 客户来源分析 VO") +@Data +public class CrmStatisticCustomerSourceRespVO { + + @Schema(description = "客户来源编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + private Integer source; + + @Schema(description = "客户个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer customerCount; + + @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer dealCount; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticsPortraitReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticsPortraitReqVO.java new file mode 100644 index 000000000..c284e7457 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticsPortraitReqVO.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - CRM 客户画像 Request VO") +@Data +public class CrmStatisticsPortraitReqVO { + + @Schema(description = "部门 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "部门 id 不能为空") + private Long deptId; + + /** + * 负责人用户 id, 当用户为空, 则计算部门下用户 + */ + @Schema(description = "负责人用户 id", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "1") + private Long userId; + + /** + * userIds 目前不用前端传递,目前是方便后端通过 deptId 读取编号后,设置回来 + * 后续,可能会支持选择部分用户进行查询 + */ + @Schema(description = "负责人用户 id 集合", hidden = true, example = "2") + private List userIds; + + /** + * 前端如果选择自定义时间, 那么前端传递起始-终止时间, 如果选择其他时间间隔类型, 则由后台计算起始-终止时间 + * 并作为参数传递给Mapper + */ + @Schema(description = "时间范围", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] times; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/CrmStatisticsRankReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/rank/CrmStatisticsRankReqVO.java similarity index 98% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/CrmStatisticsRankReqVO.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/rank/CrmStatisticsRankReqVO.java index 49167409d..c4a16ef55 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/CrmStatisticsRankReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/rank/CrmStatisticsRankReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo; +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.rank; import io.swagger.v3.oas.annotations.media.Schema; import javax.validation.constraints.NotEmpty; @@ -21,7 +21,7 @@ public class CrmStatisticsRankReqVO { /** * userIds 目前不用前端传递,目前是方便后端通过 deptId 读取编号后,设置回来 - * + *

* 后续,可能会支持选择部分用户进行查询 */ @Schema(description = "负责人用户 id 集合", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "2") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/CrmStatisticsRanKRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/rank/CrmStatisticsRankRespVO.java similarity index 80% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/CrmStatisticsRanKRespVO.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/rank/CrmStatisticsRankRespVO.java index d5c865fd3..feb2f3f2e 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/CrmStatisticsRanKRespVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/rank/CrmStatisticsRankRespVO.java @@ -1,12 +1,14 @@ -package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo; +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.rank; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import java.math.BigDecimal; -@Schema(description = "管理后台 - CRM BI 排行榜统计 Response VO") + +@Schema(description = "管理后台 - CRM 排行榜统计 Response VO") @Data -public class CrmStatisticsRanKRespVO { +public class CrmStatisticsRankRespVO { @Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Long ownerUserId; @@ -22,8 +24,10 @@ public class CrmStatisticsRanKRespVO { * * 1. 金额:合同金额排行、回款金额排行 * 2. 个数:签约合同排行、产品销量排行、产品销量排行、新增客户数排行、新增联系人排行、跟进次数排行、跟进客户数排行 + * + * 为什么使用 BigDecimal 的原因: */ @Schema(description = "数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer count; + private BigDecimal count; } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java index 4718a8d7a..769c5b485 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java @@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; +import java.util.List; /** * 商机 Mapper @@ -57,4 +58,10 @@ public interface CrmBusinessMapper extends BaseMapperX { return selectCount(CrmBusinessDO::getStatusTypeId, statusTypeId); } + default List selectListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId){ + return selectList(new LambdaQueryWrapperX() + .eq(CrmBusinessDO::getCustomerId, customerId) + .eq(CrmBusinessDO::getOwnerUserId, ownerUserId)); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java index 4a77665ad..75f2a750e 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java @@ -73,4 +73,9 @@ public interface CrmContactMapper extends BaseMapperX { return selectList(CrmContactDO::getCustomerId, customerId); } + default List selectListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) { + return selectList(CrmContactDO::getCustomerId, customerId, + CrmContactDO::getOwnerUserId, ownerUserId); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java index e06afb257..14d743291 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java @@ -117,4 +117,10 @@ public interface CrmContractMapper extends BaseMapperX { return selectCount(query); } + default List selectListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) { + return selectList(new LambdaQueryWrapperX() + .eq(CrmContractDO::getCustomerId, customerId) + .eq(CrmContractDO::getOwnerUserId, ownerUserId)); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java index 26f212e5e..07b7b6b1f 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java @@ -53,9 +53,11 @@ public interface CrmPermissionMapper extends BaseMapperX { CrmPermissionDO::getUserId, userId); } - default CrmPermissionDO selectByBizIdAndUserId(Long bizId, Long userId) { - return selectOne(CrmPermissionDO::getBizId, bizId, - CrmPermissionDO::getUserId, userId); + default CrmPermissionDO selectByBizAndUserId(Integer bizType, Long bizId, Long userId) { + return selectOne(new LambdaQueryWrapperX() + .eq(CrmPermissionDO::getBizType, bizType) + .eq(CrmPermissionDO::getBizId, bizId) + .eq(CrmPermissionDO::getUserId, userId)); } default int deletePermission(Integer bizType, Long bizId) { diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/receivable/CrmReceivableMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/receivable/CrmReceivableMapper.java index 5a5e9ce2b..0c821c8c2 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/receivable/CrmReceivableMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/receivable/CrmReceivableMapper.java @@ -99,4 +99,8 @@ public interface CrmReceivableMapper extends BaseMapperX { return convertMap(result, obj -> (Long) obj.get("contract_id"), obj -> (BigDecimal) obj.get("total_price")); } + default Long selectCountByContractId(Long contractId) { + return selectCount(CrmReceivableDO::getContractId, contractId); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsCustomerMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsCustomerMapper.java new file mode 100644 index 000000000..458ef79c3 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsCustomerMapper.java @@ -0,0 +1,194 @@ +package cn.iocoder.yudao.module.crm.dal.mysql.statistics; + +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.RandomUtil; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; +import org.apache.ibatis.annotations.Mapper; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; + +/** + * CRM 客户分析 Mapper + * + * @author dhb52 + */ +@Mapper +public interface CrmStatisticsCustomerMapper { + + /** + * 新建客户数(按日期) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectCustomerCreateCountGroupByDate(CrmStatisticsCustomerReqVO reqVO); + + /** + * 成交客户数(按日期) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectCustomerDealCountGroupByDate(CrmStatisticsCustomerReqVO reqVO); + + /** + * 新建客户数(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectCustomerCreateCountGroupByUser(CrmStatisticsCustomerReqVO reqVO); + + /** + * 成交客户数(按用户) + * + * @param reqVO 请求参数@param reqVO 请求参数@param reqVO 请求参数 + * @return 统计数据 + */ + List selectCustomerDealCountGroupByUser(CrmStatisticsCustomerReqVO reqVO); + + /** + * 合同总金额(按用户) + * @return 统计数据@return 统计数据@param reqVO 请求参数 + * @return 统计数据 + */ + List selectContractPriceGroupByUser(CrmStatisticsCustomerReqVO reqVO); + + /** + * 合同回款金额(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectReceivablePriceGroupByUser(CrmStatisticsCustomerReqVO reqVO); + + /** + * 跟进次数(按日期) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectFollowUpRecordCountGroupByDate(CrmStatisticsCustomerReqVO reqVO); + + /** + * 跟进客户数(按日期) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectFollowUpCustomerCountGroupByDate(CrmStatisticsCustomerReqVO reqVO); + + /** + * 跟进次数(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectFollowUpRecordCountGroupByUser(CrmStatisticsCustomerReqVO reqVO); + + /** + * 跟进客户数(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectFollowUpCustomerCountGroupByUser(CrmStatisticsCustomerReqVO reqVO); + + + /** + * 首次合同、回款信息(用于【客户转化率】页面) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectContractSummary(CrmStatisticsCustomerReqVO reqVO); + + /** + * 跟进次数(按类型) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectFollowUpRecordCountGroupByType(CrmStatisticsCustomerReqVO reqVO); + + + /** + * 进入公海客户数(按日期) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + // TODO: @芋艿 模拟数据, 需要增加 crm_owner_record 表 + default List selectPoolCustomerPutCountByDate(CrmStatisticsCustomerReqVO reqVO) { + LocalDateTime currrentDate = LocalDateTimeUtil.beginOfDay(reqVO.getTimes()[0]); + LocalDateTime endDate = LocalDateTimeUtil.endOfDay(reqVO.getTimes()[1]); + List voList = new ArrayList<>(); + while (currrentDate.isBefore(endDate)) { + voList.add(new CrmStatisticsPoolSummaryByDateRespVO() + .setTime(LocalDateTimeUtil.format(currrentDate, "yyyy-MM-dd")) + .setCustomerPutCount(RandomUtil.randomInt(0, 10)) + .setCustomerTakeCount(RandomUtil.randomInt(0, 10))); + currrentDate = currrentDate.plusDays(1); + } + + return voList; + } + + /** + * 公海领取客户数(按日期) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + // TODO: @芋艿 模拟数据, 需要增加 crm_owner_record 表 + default List selectPoolCustomerTakeCountByDate(CrmStatisticsCustomerReqVO reqVO) { + return selectPoolCustomerPutCountByDate(reqVO); + } + + /** + * 进入公海客户数(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + // TODO: @芋艿 模拟数据, 需要增加 crm_owner_record 表 + default List selectPoolCustomerPutCountByUser(CrmStatisticsCustomerReqVO reqVO) { + return convertList(reqVO.getUserIds(), userId -> + (CrmStatisticsPoolSummaryByUserRespVO) new CrmStatisticsPoolSummaryByUserRespVO() + .setCustomerPutCount(RandomUtil.randomInt(0, 10)) + .setCustomerTakeCount(RandomUtil.randomInt(0, 10)) + .setOwnerUserId(userId)); + } + + /** + * 公海领取客户数(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + // TODO: @芋艿 模拟数据, 需要增加 crm_owner_record 表 + default List selectPoolCustomerTakeCountByUser(CrmStatisticsCustomerReqVO reqVO) { + return selectPoolCustomerPutCountByUser(reqVO); + } + + /** + * 客户成交周期(按日期) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectCustomerDealCycleGroupByDate(CrmStatisticsCustomerReqVO reqVO); + + /** + * 客户成交周期(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List selectCustomerDealCycleGroupByUser(CrmStatisticsCustomerReqVO reqVO); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPerformanceMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPerformanceMapper.java new file mode 100644 index 000000000..6467a098d --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPerformanceMapper.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.crm.dal.mysql.statistics; + +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * CRM 员工业绩分析 Mapper + * + * @author scholar + */ +@Mapper +public interface CrmStatisticsPerformanceMapper { + + /** + * 员工签约合同数量 + * + * @param performanceReqVO 参数 + * @return 员工签约合同数量 + */ + List selectContractCountPerformance(CrmStatisticsPerformanceReqVO performanceReqVO); + + /** + * 员工签约合同金额 + * + * @param performanceReqVO 参数 + * @return 员工签约合同金额 + */ + List selectContractPricePerformance(CrmStatisticsPerformanceReqVO performanceReqVO); + + /** + * 员工回款金额 + * + * @param performanceReqVO 参数 + * @return 员工回款金额 + */ + List selectReceivablePricePerformance(CrmStatisticsPerformanceReqVO performanceReqVO); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPortraitMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPortraitMapper.java new file mode 100644 index 000000000..a7c942752 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPortraitMapper.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.crm.dal.mysql.statistics; + +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.*; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * CRM 数据画像 Mapper + * + * @author HUIHUI + */ +@Mapper +public interface CrmStatisticsPortraitMapper { + + List selectSummaryListGroupByAreaId(CrmStatisticsPortraitReqVO reqVO); + + List selectCustomerIndustryListGroupByIndustryId(CrmStatisticsPortraitReqVO reqVO); + + List selectCustomerSourceListGroupBySource(CrmStatisticsPortraitReqVO reqVO); + + List selectCustomerLevelListGroupByLevel(CrmStatisticsPortraitReqVO reqVO); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsRankingMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsRankMapper.java similarity index 72% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsRankingMapper.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsRankMapper.java index 4b51ab2fe..55062f57a 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsRankingMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsRankMapper.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.crm.dal.mysql.statistics; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.CrmStatisticsRanKRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.CrmStatisticsRankReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.rank.CrmStatisticsRankReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.rank.CrmStatisticsRankRespVO; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -12,7 +12,7 @@ import java.util.List; * @author anhaohao */ @Mapper -public interface CrmStatisticsRankingMapper { +public interface CrmStatisticsRankMapper { /** * 查询合同金额排行榜 @@ -20,7 +20,7 @@ public interface CrmStatisticsRankingMapper { * @param rankReqVO 参数 * @return 合同金额排行榜 */ - List selectContractPriceRank(CrmStatisticsRankReqVO rankReqVO); + List selectContractPriceRank(CrmStatisticsRankReqVO rankReqVO); /** * 查询回款金额排行榜 @@ -28,7 +28,7 @@ public interface CrmStatisticsRankingMapper { * @param rankReqVO 参数 * @return 回款金额排行榜 */ - List selectReceivablePriceRank(CrmStatisticsRankReqVO rankReqVO); + List selectReceivablePriceRank(CrmStatisticsRankReqVO rankReqVO); /** * 查询签约合同数量排行榜 @@ -36,7 +36,7 @@ public interface CrmStatisticsRankingMapper { * @param rankReqVO 参数 * @return 签约合同数量排行榜 */ - List selectContractCountRank(CrmStatisticsRankReqVO rankReqVO); + List selectContractCountRank(CrmStatisticsRankReqVO rankReqVO); /** * 查询产品销量排行榜 @@ -44,7 +44,7 @@ public interface CrmStatisticsRankingMapper { * @param rankReqVO 参数 * @return 产品销量排行榜 */ - List selectProductSalesRank(CrmStatisticsRankReqVO rankReqVO); + List selectProductSalesRank(CrmStatisticsRankReqVO rankReqVO); /** * 查询新增客户数排行榜 @@ -52,7 +52,7 @@ public interface CrmStatisticsRankingMapper { * @param rankReqVO 参数 * @return 新增客户数排行榜 */ - List selectCustomerCountRank(CrmStatisticsRankReqVO rankReqVO); + List selectCustomerCountRank(CrmStatisticsRankReqVO rankReqVO); /** * 查询联系人数量排行榜 @@ -60,7 +60,7 @@ public interface CrmStatisticsRankingMapper { * @param rankReqVO 参数 * @return 联系人数量排行榜 */ - List selectContactsCountRank(CrmStatisticsRankReqVO rankReqVO); + List selectContactsCountRank(CrmStatisticsRankReqVO rankReqVO); /** * 查询跟进次数排行榜 @@ -68,7 +68,7 @@ public interface CrmStatisticsRankingMapper { * @param rankReqVO 参数 * @return 跟进次数排行榜 */ - List selectFollowCountRank(CrmStatisticsRankReqVO rankReqVO); + List selectFollowCountRank(CrmStatisticsRankReqVO rankReqVO); /** * 查询跟进客户数排行榜 @@ -76,6 +76,6 @@ public interface CrmStatisticsRankingMapper { * @param rankReqVO 参数 * @return 跟进客户数排行榜 */ - List selectFollowCustomerCountRank(CrmStatisticsRankReqVO rankReqVO); + List selectFollowCustomerCountRank(CrmStatisticsRankReqVO rankReqVO); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunction.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunction.java new file mode 100644 index 000000000..8f0a88905 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunction.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.crm.framework.excel.core; + +import cn.iocoder.yudao.framework.excel.core.function.ExcelColumnSelectFunction; +import cn.iocoder.yudao.framework.ip.core.Area; +import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 地区下拉框数据源的 {@link ExcelColumnSelectFunction} 实现类 + * + * @author HUIHUI + */ +@Service +public class AreaExcelColumnSelectFunction implements ExcelColumnSelectFunction { + + public static final String NAME = "getCrmAreaNameList"; // 防止和别的模块重名 + + @Override + public String getName() { + return NAME; + } + + @Override + public List getOptions() { + // 获取地区下拉数据 + // TODO @puhui999:嘿嘿,这里改成省份、城市、区域,三个选项,难度大么? + Area area = AreaUtils.getArea(Area.ID_CHINA); + return AreaUtils.getAreaNodePathList(area.getChildren()); + } + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/package-info.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/package-info.java new file mode 100644 index 000000000..c2deef8b8 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/package-info.java @@ -0,0 +1,4 @@ +/** + * crm 模块的 excel 拓展封装 + */ +package cn.iocoder.yudao.module.crm.framework.excel; \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/operatelog/package-info.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/operatelog/package-info.java index 975a2eb51..413b652c1 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/operatelog/package-info.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/operatelog/package-info.java @@ -1 +1,4 @@ +/** + * crm 模块的 operatelog 拓展封装 + */ package cn.iocoder.yudao.module.crm.framework.operatelog; \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/permission/package-info.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/permission/package-info.java index 44f408016..97f76dbe1 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/permission/package-info.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/permission/package-info.java @@ -1 +1,4 @@ +/** + * crm 模块的 permission 拓展封装 + */ package cn.iocoder.yudao.module.crm.framework.permission; \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java index f71680acd..6f794e0f3 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java @@ -46,8 +46,8 @@ public interface CrmBusinessService { /** * 更新商机相关跟进信息 * - * @param id 编号 - * @param contactNextTime 下次联系时间 + * @param id 编号 + * @param contactNextTime 下次联系时间 * @param contactLastContent 最后联系内容 */ void updateBusinessFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent); @@ -55,7 +55,7 @@ public interface CrmBusinessService { /** * 更新商机的下次联系时间 * - * @param ids 编号数组 + * @param ids 编号数组 * @param contactNextTime 下次联系时间 */ void updateBusinessContactNextTime(Collection ids, LocalDateTime contactNextTime); @@ -185,4 +185,13 @@ public interface CrmBusinessService { return status.getName(); } + /** + * 获得商机列表 + * + * @param customerId 客户编号 + * @param ownerUserId 负责人编号 + * @return 商机列表 + */ + List getBusinessListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId); + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java index 47865c64f..142c9def9 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java @@ -88,7 +88,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { success = CRM_BUSINESS_CREATE_SUCCESS) public Long createBusiness(CrmBusinessSaveReqVO createReqVO, Long userId) { // 1.1 校验产品项的有效性 - List businessProducts = validateBusinessProducts(createReqVO.getProducts()); + List businessProducts = validateBusinessProducts(createReqVO.getBusinessProducts()); // 1.2 校验关联字段 validateRelationDataExists(createReqVO); @@ -129,7 +129,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { // 1.1 校验存在 CrmBusinessDO oldBusiness = validateBusinessExists(updateReqVO.getId()); // 1.2 校验产品项的有效性 - List businessProducts = validateBusinessProducts(updateReqVO.getProducts()); + List businessProducts = validateBusinessProducts(updateReqVO.getBusinessProducts()); // 1.3 校验关联字段 validateRelationDataExists(updateReqVO); @@ -202,9 +202,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { } } - private List validateBusinessProducts(List list) { + private List validateBusinessProducts(List list) { // 1. 校验产品存在 - productService.validProductList(convertSet(list, CrmBusinessSaveReqVO.Product::getProductId)); + productService.validProductList(convertSet(list, CrmBusinessSaveReqVO.BusinessProduct::getProductId)); // 2. 转化为 CrmBusinessProductDO 列表 return convertList(list, o -> BeanUtils.toBean(o, CrmBusinessProductDO.class, item -> item.setTotalPrice(MoneyUtils.priceMultiply(item.getBusinessPrice(), item.getCount())))); @@ -234,7 +234,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { } // 1.4 校验是不是状态没变更 if ((reqVO.getStatusId() != null && reqVO.getStatusId().equals(business.getStatusId())) - || (reqVO.getEndStatus() != null && reqVO.getEndStatus().equals(business.getEndStatus()))) { + || (reqVO.getEndStatus() != null && reqVO.getEndStatus().equals(business.getEndStatus()))) { throw exception(BUSINESS_UPDATE_STATUS_FAIL_STATUS_EQUALS); } @@ -301,7 +301,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { // 2.1 数据权限转移 permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_BUSINESS.getType(), - reqVO.getNewOwnerUserId(), reqVO.getId(), CrmPermissionLevelEnum.OWNER.getLevel())); + reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); // 2.2 设置新的负责人 businessMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId()); @@ -370,4 +370,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { return businessMapper.selectCountByStatusTypeId(statusTypeId); } + @Override + public List getBusinessListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) { + return businessMapper.selectListByCustomerIdOwnerUserId(customerId, ownerUserId); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java index 72ddd37bd..24273db2f 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java @@ -75,8 +75,8 @@ public interface CrmContactService { /** * 更新联系人的下次联系时间 * - * @param ids 编号数组 - * @param contactNextTime 下次联系时间 + * @param ids 编号数组 + * @param contactNextTime 下次联系时间 */ void updateContactContactNextTime(Collection ids, LocalDateTime contactNextTime); @@ -160,4 +160,13 @@ public interface CrmContactService { */ Long getContactCountByCustomerId(Long customerId); + /** + * 获得联系人列表 + * + * @param customerId 客户编号 + * @param ownerUserId 负责人编号 + * @return 联系人列表 + */ + List getContactListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId); + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java index bd230f902..d6eb2a83c 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java @@ -298,4 +298,9 @@ public class CrmContactServiceImpl implements CrmContactService { return contactMapper.selectCount(CrmContactDO::getCustomerId, customerId); } + @Override + public List getContactListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) { + return contactMapper.selectListByCustomerIdOwnerUserId(customerId, ownerUserId); + } + } \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java index 10be39142..f7a686759 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java @@ -58,8 +58,8 @@ public interface CrmContractService { /** * 更新合同相关的更进信息 * - * @param id 合同编号 - * @param contactNextTime 下次联系时间 + * @param id 合同编号 + * @param contactNextTime 下次联系时间 * @param contactLastContent 最后联系内容 */ void updateContractFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent); @@ -75,7 +75,7 @@ public interface CrmContractService { /** * 更新合同流程审批结果 * - * @param id 合同编号 + * @param id 合同编号 * @param bpmResult BPM 审批结果 */ void updateContractAuditStatus(Long id, Integer bpmResult); @@ -193,4 +193,13 @@ public interface CrmContractService { */ Long getRemindContractCount(Long userId); + /** + * 获得合同列表 + * + * @param customerId 客户编号 + * @param ownerUserId 负责人编号 + * @return 合同列表 + */ + List getContractListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId); + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java index 951828b7f..bcf5d9a9d 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java @@ -30,11 +30,13 @@ import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; import cn.iocoder.yudao.module.crm.service.product.CrmProductService; +import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import com.mzt.logapi.context.LogRecordContext; import com.mzt.logapi.service.impl.DiffParseFunction; import com.mzt.logapi.starter.annotation.LogRecord; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -86,7 +88,9 @@ public class CrmContractServiceImpl implements CrmContractService { private CrmContactService contactService; @Resource private CrmContractConfigService contractConfigService; - + @Resource + @Lazy // 延迟加载,避免循环依赖 + private CrmReceivableService receivableService; @Resource private AdminUserApi adminUserApi; @Resource @@ -222,15 +226,19 @@ public class CrmContractServiceImpl implements CrmContractService { success = CRM_CONTRACT_DELETE_SUCCESS) @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) public void deleteContract(Long id) { - // TODO @puhui999:如果被 CrmReceivableDO 所使用,则不允许删除 - // 校验存在 + // 1.1 校验存在 CrmContractDO contract = validateContractExists(id); - // 删除 + // 1.2 如果被 CrmReceivableDO 所使用,则不允许删除 + if (receivableService.getReceivableCountByContractId(contract.getId()) > 0) { + throw exception(CONTRACT_DELETE_FAIL); + } + + // 2.1 删除合同 contractMapper.deleteById(id); - // 删除数据权限 + // 2.2 删除数据权限 crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CONTRACT.getType(), id); - // 记录操作日志上下文 + // 3. 记录操作日志上下文 LogRecordContext.putVariable("contractName", contract.getName()); } @@ -399,4 +407,9 @@ public class CrmContractServiceImpl implements CrmContractService { return contractMapper.selectCountByRemind(userId, config); } + @Override + public List getContractListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) { + return contractMapper.selectListByCustomerIdOwnerUserId(customerId, ownerUserId); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java index 68d537582..2ca6c9cc2 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java @@ -9,7 +9,13 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractTransferReqVO; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer.*; +import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; +import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO; @@ -201,7 +207,6 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { CrmCustomerDO customer = validateCustomerExists(reqVO.getId()); // 1.2 校验拥有客户是否到达上限 validateCustomerExceedOwnerLimit(reqVO.getNewOwnerUserId(), 1); - // 2.1 数据权限转移 permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CUSTOMER.getType(), reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); @@ -209,10 +214,45 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { customerMapper.updateById(new CrmCustomerDO().setId(reqVO.getId()) .setOwnerUserId(reqVO.getNewOwnerUserId()).setOwnerTime(LocalDateTime.now())); + // 2.3 同时转移 + if (CollUtil.isNotEmpty(reqVO.getToBizTypes())) { + transfer(reqVO, userId); + } + // 3. 记录转移日志 LogRecordContext.putVariable("customer", customer); } + /** + * 转移客户时,需要额外有【联系人】【商机】【合同】 + * + * @param reqVO 请求 + * @param userId 用户编号 + */ + private void transfer(CrmCustomerTransferReqVO reqVO, Long userId) { + if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTACT.getType())) { + List contactList = contactService.getContactListByCustomerIdOwnerUserId(reqVO.getId(), userId); + contactList.forEach(item -> { + contactService.transferContact(new CrmContactTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(), + reqVO.getOldOwnerPermissionLevel()), userId); + }); + } + if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_BUSINESS.getType())) { + List businessList = businessService.getBusinessListByCustomerIdOwnerUserId(reqVO.getId(), userId); + businessList.forEach(item -> { + businessService.transferBusiness(new CrmBusinessTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(), + reqVO.getOldOwnerPermissionLevel()), userId); + }); + } + if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTRACT.getType())) { + List contractList = contractService.getContractListByCustomerIdOwnerUserId(reqVO.getId(), userId); + contractList.forEach(item -> { + contractService.transferContract(new CrmContractTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(), + reqVO.getOldOwnerPermissionLevel()), userId); + }); + } + } + @Override @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_LOCK_SUB_TYPE, bizNo = "{{#lockReqVO.id}}", success = CRM_CUSTOMER_LOCK_SUCCESS) diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java index caceb055c..c5a6b854c 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.crm.service.permission; +import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionSaveReqVO; import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; @@ -19,6 +20,14 @@ import java.util.List; */ public interface CrmPermissionService { + /** + * 创建数据权限 + * + * @param reqVO 创建信息 + * @param userId 用户编号 + */ + void createPermission(CrmPermissionSaveReqVO reqVO, Long userId); + /** * 创建数据权限 * @@ -111,10 +120,10 @@ public interface CrmPermissionService { /** * 校验是否有指定数据的操作权限 * - * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} - * @param bizId 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() - * @param userId 用户编号 - * @param level 权限级别 + * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} + * @param bizId 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() + * @param userId 用户编号 + * @param level 权限级别 * @return 是否有权限 */ boolean hasPermission(Integer bizType, Long bizId, Long userId, CrmPermissionLevelEnum level); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java index ba8c88c7c..cb1b6a1c6 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java @@ -4,28 +4,34 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionSaveReqVO; import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO; +import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; +import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; import cn.iocoder.yudao.module.crm.dal.mysql.permission.CrmPermissionMapper; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; +import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission; +import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; +import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; +import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; import cn.iocoder.yudao.module.crm.util.CrmPermissionUtils; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; -import javax.annotation.Resource; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; +import jakarta.annotation.Resource; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; +import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum.isOwner; @@ -40,18 +46,119 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { @Resource private CrmPermissionMapper permissionMapper; - + @Resource + @Lazy // 解决依赖循环 + private CrmContactService contactService; + @Resource + @Lazy // 解决依赖循环 + private CrmBusinessService businessService; + @Resource + @Lazy // 解决依赖循环 + private CrmContractService contractService; @Resource private AdminUserApi adminUserApi; + + @Override + @Transactional(rollbackFor = Exception.class) + @CrmPermission(bizTypeValue = "#reqVO.bizType", bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER) + public void createPermission(CrmPermissionSaveReqVO reqVO, Long userId) { + // 1. 创建数据权限 + createPermission0(BeanUtils.toBean(reqVO, CrmPermissionCreateReqBO.class)); + + // 2. 处理【同时添加至】的权限 + if (CollUtil.isEmpty(reqVO.getToBizTypes())) { + return; + } + List createPermissions = new ArrayList<>(); + buildContactPermissions(reqVO, userId, createPermissions); + buildBusinessPermissions(reqVO, userId, createPermissions); + buildContractPermissions(reqVO, userId, createPermissions); + if (CollUtil.isEmpty(createPermissions)) { + return; + } + createPermissionBatch(createPermissions); + } + + /** + * 处理同时添加至联系人 + * + * @param reqVO 请求 + * @param userId 操作人 + * @param createPermissions 待添加权限列表 + */ + private void buildContactPermissions(CrmPermissionSaveReqVO reqVO, Long userId, List createPermissions) { + // 1. 校验是否被同时添加 + Integer type = CrmBizTypeEnum.CRM_CONTACT.getType(); + if (!reqVO.getToBizTypes().contains(type)) { + return; + } + // 2. 添加数据权限 + List contactList = contactService.getContactListByCustomerIdOwnerUserId(reqVO.getBizId(), userId); + contactList.forEach(item -> createBizTypePermissions(reqVO, type, item.getId(), item.getName(), createPermissions)); + } + + /** + * 处理同时添加至商机 + * + * @param reqVO 请求 + * @param userId 操作人 + * @param createPermissions 待添加权限列表 + */ + private void buildBusinessPermissions(CrmPermissionSaveReqVO reqVO, Long userId, List createPermissions) { + // 1. 校验是否被同时添加 + Integer type = CrmBizTypeEnum.CRM_BUSINESS.getType(); + if (!reqVO.getToBizTypes().contains(type)) { + return; + } + // 2. 添加数据权限 + List businessList = businessService.getBusinessListByCustomerIdOwnerUserId(reqVO.getBizId(), userId); + businessList.forEach(item -> createBizTypePermissions(reqVO, type, item.getId(), item.getName(), createPermissions)); + } + + /** + * 处理同时添加至合同 + * + * @param reqVO 请求 + * @param userId 操作人 + * @param createPermissions 待添加权限列表 + */ + private void buildContractPermissions(CrmPermissionSaveReqVO reqVO, Long userId, List createPermissions) { + // 1. 校验是否被同时添加 + Integer type = CrmBizTypeEnum.CRM_CONTRACT.getType(); + if (!reqVO.getToBizTypes().contains(type)) { + return; + } + // 2. 添加数据权限 + List contractList = contractService.getContractListByCustomerIdOwnerUserId(reqVO.getBizId(), userId); + contractList.forEach(item -> createBizTypePermissions(reqVO, type, item.getId(), item.getName(), createPermissions)); + } + + private void createBizTypePermissions(CrmPermissionSaveReqVO reqVO, Integer type, Long bizId, String name, + List createPermissions) { + AdminUserRespDTO user = adminUserApi.getUser(reqVO.getUserId()).getCheckedData(); + // 1. 需要考虑,被添加人,是不是应该有对应的权限了; + CrmPermissionDO permission = hasAnyPermission(type, bizId, reqVO.getUserId()); + if (ObjUtil.isNotNull(permission)) { + throw exception(CRM_PERMISSION_CREATE_FAIL_EXISTS, user.getNickname(), CrmBizTypeEnum.getNameByType(type), + name, CrmPermissionLevelEnum.getNameByLevel(permission.getLevel())); + } + // 2. 添加数据权限 + createPermissions.add(new CrmPermissionCreateReqBO().setBizType(type) + .setBizId(bizId).setUserId(reqVO.getUserId()).setLevel(reqVO.getLevel())); + } + @Override @Transactional(rollbackFor = Exception.class) public Long createPermission(CrmPermissionCreateReqBO createReqBO) { + return createPermission0(createReqBO); + } + + private Long createPermission0(CrmPermissionCreateReqBO createReqBO) { validatePermissionNotExists(Collections.singletonList(createReqBO)); // 1. 校验用户是否存在 adminUserApi.validateUserList(Collections.singletonList(createReqBO.getUserId())); - - // 2. 创建 + // 2. 插入权限 CrmPermissionDO permission = BeanUtils.toBean(createReqBO, CrmPermissionDO.class); permissionMapper.insert(permission); return permission.getId(); @@ -170,7 +277,7 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { throw exception(CRM_PERMISSION_DELETE_FAIL); } // 校验操作人是否为负责人 - CrmPermissionDO permission = permissionMapper.selectByBizIdAndUserId(permissions.get(0).getBizId(), userId); + CrmPermissionDO permission = permissionMapper.selectByBizAndUserId(permissions.get(0).getBizType(), permissions.get(0).getBizId(), userId); if (permission == null) { throw exception(CRM_PERMISSION_DELETE_DENIED); } @@ -220,4 +327,9 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { ObjUtil.equal(permission.getUserId(), userId) && ObjUtil.equal(permission.getLevel(), level.getLevel())); } + public CrmPermissionDO hasAnyPermission(Integer bizType, Long bizId, Long userId) { + List permissionList = permissionMapper.selectByBizTypeAndBizId(bizType, bizId); + return findFirst(permissionList, permission -> ObjUtil.equal(permission.getUserId(), userId)); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivablePlanServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivablePlanServiceImpl.java index 21cfe9c69..dd3de19b1 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivablePlanServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivablePlanServiceImpl.java @@ -19,9 +19,7 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import com.mzt.logapi.context.LogRecordContext; import com.mzt.logapi.service.impl.DiffParseFunction; import com.mzt.logapi.starter.annotation.LogRecord; -import javax.annotation.Resource; - -import org.springframework.context.annotation.Lazy; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -47,9 +45,6 @@ public class CrmReceivablePlanServiceImpl implements CrmReceivablePlanService { @Resource private CrmReceivablePlanMapper receivablePlanMapper; - @Resource - @Lazy // 延迟加载,避免循环依赖 - private CrmReceivableService receivableService; @Resource private CrmContractService contractService; @Resource @@ -145,7 +140,7 @@ public class CrmReceivablePlanServiceImpl implements CrmReceivablePlanService { // 2. 删除 receivablePlanMapper.deleteById(id); // 3. 删除数据权限 - permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), id); + permissionService.deletePermission(CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(), id); // 4. 记录操作日志上下文 LogRecordContext.putVariable("receivablePlan", receivablePlan); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java index 74ee2407c..eec4cd550 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java @@ -122,4 +122,12 @@ public interface CrmReceivableService { */ Map getReceivablePriceMapByContractId(Collection contractIds); + /** + * 根据合同编号查询回款数量 + * + * @param contractId 合同编号 + * @return 回款数量 + */ + Long getReceivableCountByContractId(Long contractId); + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java index 565862792..83e68cce2 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java @@ -37,10 +37,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; @@ -81,7 +78,6 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { @Resource private BpmProcessInstanceApi bpmProcessInstanceApi; - // TODO @puhui999:操作日志没记录上 @Override @Transactional(rollbackFor = Exception.class) @LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_CREATE_SUB_TYPE, bizNo = "{{#receivable.id}}", @@ -115,6 +111,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { // 5. 记录操作日志上下文 LogRecordContext.putVariable("receivable", receivable); + LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId())); return receivable.getId(); } @@ -156,7 +153,6 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { } } - // TODO @puhui999:操作日志没记录上 @Override @Transactional(rollbackFor = Exception.class) @LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", @@ -164,11 +160,14 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { @CrmPermission(bizType = CrmBizTypeEnum.CRM_RECEIVABLE, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) public void updateReceivable(CrmReceivableSaveReqVO updateReqVO) { Assert.notNull(updateReqVO.getId(), "回款编号不能为空"); - // 1.1 校验可回款金额超过上限 - validateReceivablePriceExceedsLimit(updateReqVO); updateReqVO.setOwnerUserId(null).setCustomerId(null).setContractId(null).setPlanId(null); // 不允许修改的字段 - // 1.2 校验存在 + // 1.1 校验存在 CrmReceivableDO receivable = validateReceivableExists(updateReqVO.getId()); + updateReqVO.setOwnerUserId(receivable.getOwnerUserId()).setCustomerId(receivable.getCustomerId()) + .setContractId(receivable.getContractId()).setPlanId(receivable.getPlanId()); // 设置已存在的值 + // 1.2 校验可回款金额超过上限 + validateReceivablePriceExceedsLimit(updateReqVO); + // 1.3 只有草稿、审批中,可以编辑; if (!ObjectUtils.equalsAny(receivable.getAuditStatus(), CrmAuditStatusEnum.DRAFT.getStatus(), CrmAuditStatusEnum.PROCESS.getStatus())) { @@ -180,8 +179,17 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { receivableMapper.updateById(updateObj); // 3. 记录操作日志上下文 - LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(receivable, CrmReceivableSaveReqVO.class)); LogRecordContext.putVariable("receivable", receivable); + LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId())); + LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(receivable, CrmReceivableSaveReqVO.class)); + } + + private Integer getReceivablePeriod(Long planId) { + if (Objects.isNull(planId)) { + return null; + } + CrmReceivablePlanDO receivablePlan = receivablePlanService.getReceivablePlan(planId); + return receivablePlan.getPeriod(); } @Override @@ -212,15 +220,19 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { if (receivable.getPlanId() != null && receivablePlanService.getReceivablePlan(receivable.getPlanId()) != null) { throw exception(RECEIVABLE_DELETE_FAIL); } - // TODO @puhui999:审批通过时,不允许删除; + // 1.3 审批通过时,不允许删除 + if (ObjUtil.equal(receivable.getAuditStatus(), CrmAuditStatusEnum.APPROVE.getStatus())) { + throw exception(RECEIVABLE_DELETE_FAIL_IS_APPROVE); + } - // 2. 删除 + // 2.1 删除回款 receivableMapper.deleteById(id); - // 3. 删除数据权限 + // 2.2 删除数据权限 permissionService.deletePermission(CrmBizTypeEnum.CRM_RECEIVABLE.getType(), id); - // 4. 记录操作日志上下文 + // 3. 记录操作日志上下文 LogRecordContext.putVariable("receivable", receivable); + LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId())); } @Override @@ -289,4 +301,9 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { return receivableMapper.selectReceivablePriceMapByContractId(contractIds); } + @Override + public Long getReceivableCountByContractId(Long contractId) { + return receivableMapper.selectCountByContractId(contractId); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerService.java new file mode 100644 index 000000000..0e00e9c22 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerService.java @@ -0,0 +1,96 @@ +package cn.iocoder.yudao.module.crm.service.statistics; + +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; + +import java.util.List; + +/** + * CRM 客户分析 Service 接口 + * + * @author dhb52 + */ +public interface CrmStatisticsCustomerService { + + /** + * 总量分析(按日期) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerSummaryByDate(CrmStatisticsCustomerReqVO reqVO); + + /** + * 总量分析(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerSummaryByUser(CrmStatisticsCustomerReqVO reqVO); + + /** + * 跟进次数分析(按日期) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getFollowUpSummaryByDate(CrmStatisticsCustomerReqVO reqVO); + + /** + * 跟进次数分析(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getFollowUpSummaryByUser(CrmStatisticsCustomerReqVO reqVO); + + /** + * 客户跟进次数分析(按类型) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getFollowUpSummaryByType(CrmStatisticsCustomerReqVO reqVO); + + /** + * 获取客户的首次合同、回款信息列表,用于【客户转化率】页面 + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getContractSummary(CrmStatisticsCustomerReqVO reqVO); + + /** + * 公海客户分析(按日期) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getPoolSummaryByDate(CrmStatisticsCustomerReqVO reqVO); + + /** + * 公海客户分析(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getPoolSummaryByUser(CrmStatisticsCustomerReqVO reqVO); + + /** + * 客户成交周期(按日期) + * + * 成交周期的定义:客户 customer 在创建出来,到合同 contract 第一次成交的时间差 + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerDealCycleByDate(CrmStatisticsCustomerReqVO reqVO); + + /** + * 客户成交周期(按用户) + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerDealCycleByUser(CrmStatisticsCustomerReqVO reqVO); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerServiceImpl.java new file mode 100644 index 000000000..3801d90ad --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerServiceImpl.java @@ -0,0 +1,323 @@ +package cn.iocoder.yudao.module.crm.service.statistics; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; +import cn.iocoder.yudao.framework.common.util.number.NumberUtils; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; +import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsCustomerMapper; +import cn.iocoder.yudao.module.system.api.dept.DeptApi; +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; + +/** + * CRM 客户分析 Service 实现类 + * + * @author dhb52 + */ +@Service +@Validated +public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerService { + + @Resource + private CrmStatisticsCustomerMapper customerMapper; + + @Resource + private AdminUserApi adminUserApi; + @Resource + private DeptApi deptApi; + + @Override + public List getCustomerSummaryByDate(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + reqVO.setUserIds(getUserIds(reqVO)); + if (CollUtil.isEmpty(reqVO.getUserIds())) { + return Collections.emptyList(); + } + + // 2. 按天统计,获取分项统计数据 + List customerCreateCountList = customerMapper.selectCustomerCreateCountGroupByDate(reqVO); + List customerDealCountList = customerMapper.selectCustomerDealCountGroupByDate(reqVO); + + // 3. 按照日期间隔,合并数据 + List timeRanges = LocalDateTimeUtils.getDateRangeList(reqVO.getTimes()[0], reqVO.getTimes()[1], reqVO.getInterval()); + return convertList(timeRanges, times -> { + Integer customerCreateCount = customerCreateCountList.stream() + .filter(vo -> LocalDateTimeUtils.isBetween(times[0], times[1], vo.getTime())) + .mapToInt(CrmStatisticsCustomerSummaryByDateRespVO::getCustomerCreateCount).sum(); + Integer customerDealCount = customerDealCountList.stream() + .filter(vo -> LocalDateTimeUtils.isBetween(times[0], times[1], vo.getTime())) + .mapToInt(CrmStatisticsCustomerSummaryByDateRespVO::getCustomerDealCount).sum(); + return new CrmStatisticsCustomerSummaryByDateRespVO() + .setTime(LocalDateTimeUtils.formatDateRange(times[0], times[1], reqVO.getInterval())) + .setCustomerCreateCount(customerCreateCount).setCustomerDealCount(customerDealCount); + }); + } + + @Override + public List getCustomerSummaryByUser(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + reqVO.setUserIds(getUserIds(reqVO)); + if (CollUtil.isEmpty(reqVO.getUserIds())) { + return Collections.emptyList(); + } + + // 2. 按用户统计,获取分项统计数据 + List customerCreateCountList = customerMapper.selectCustomerCreateCountGroupByUser(reqVO); + List customerDealCountList = customerMapper.selectCustomerDealCountGroupByUser(reqVO); + List contractPriceList = customerMapper.selectContractPriceGroupByUser(reqVO); + List receivablePriceList = customerMapper.selectReceivablePriceGroupByUser(reqVO); + + // 3.1 按照用户,合并统计数据 + List summaryList = convertList(reqVO.getUserIds(), userId -> { + Integer customerCreateCount = customerCreateCountList.stream().filter(vo -> userId.equals(vo.getOwnerUserId())) + .mapToInt(CrmStatisticsCustomerSummaryByUserRespVO::getCustomerCreateCount).sum(); + Integer customerDealCount = customerDealCountList.stream().filter(vo -> userId.equals(vo.getOwnerUserId())) + .mapToInt(CrmStatisticsCustomerSummaryByUserRespVO::getCustomerDealCount).sum(); + BigDecimal contractPrice = contractPriceList.stream().filter(vo -> userId.equals(vo.getOwnerUserId())) + .reduce(BigDecimal.ZERO, (sum, vo) -> sum.add(vo.getContractPrice()), BigDecimal::add); + BigDecimal receivablePrice = receivablePriceList.stream().filter(vo -> userId.equals(vo.getOwnerUserId())) + .reduce(BigDecimal.ZERO, (sum, vo) -> sum.add(vo.getReceivablePrice()), BigDecimal::add); + return (CrmStatisticsCustomerSummaryByUserRespVO) new CrmStatisticsCustomerSummaryByUserRespVO() + .setCustomerCreateCount(customerCreateCount).setCustomerDealCount(customerDealCount) + .setContractPrice(contractPrice).setReceivablePrice(receivablePrice).setOwnerUserId(userId); + }); + // 3.2 拼接用户信息 + appendUserInfo(summaryList); + return summaryList; + } + + @Override + public List getFollowUpSummaryByDate(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + reqVO.setUserIds(getUserIds(reqVO)); + if (CollUtil.isEmpty(reqVO.getUserIds())) { + return Collections.emptyList(); + } + + // 2. 按天统计,获取分项统计数据 + List followUpRecordCountList = customerMapper.selectFollowUpRecordCountGroupByDate(reqVO); + List followUpCustomerCountList = customerMapper.selectFollowUpCustomerCountGroupByDate(reqVO); + + // 3. 按照时间间隔,合并统计数据 + List timeRanges = LocalDateTimeUtils.getDateRangeList(reqVO.getTimes()[0], reqVO.getTimes()[1], reqVO.getInterval()); + return convertList(timeRanges, times -> { + Integer followUpRecordCount = followUpRecordCountList.stream() + .filter(vo -> LocalDateTimeUtils.isBetween(times[0], times[1], vo.getTime())) + .mapToInt(CrmStatisticsFollowUpSummaryByDateRespVO::getFollowUpRecordCount).sum(); + Integer followUpCustomerCount = followUpCustomerCountList.stream() + .filter(vo -> LocalDateTimeUtils.isBetween(times[0], times[1], vo.getTime())) + .mapToInt(CrmStatisticsFollowUpSummaryByDateRespVO::getFollowUpCustomerCount).sum(); + return new CrmStatisticsFollowUpSummaryByDateRespVO() + .setTime(LocalDateTimeUtils.formatDateRange(times[0], times[1], reqVO.getInterval())) + .setFollowUpCustomerCount(followUpRecordCount).setFollowUpRecordCount(followUpCustomerCount); + }); + } + + @Override + public List getFollowUpSummaryByUser(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + reqVO.setUserIds(getUserIds(reqVO)); + if (CollUtil.isEmpty(reqVO.getUserIds())) { + return Collections.emptyList(); + } + + // 2. 按用户统计,获取分项统计数据 + List followUpRecordCountList = customerMapper.selectFollowUpRecordCountGroupByUser(reqVO); + List followUpCustomerCountList = customerMapper.selectFollowUpCustomerCountGroupByUser(reqVO); + + // 3.1 按照用户,合并统计数据 + List summaryList = convertList(reqVO.getUserIds(), userId -> { + Integer followUpRecordCount = followUpRecordCountList.stream().filter(vo -> userId.equals(vo.getOwnerUserId())) + .mapToInt(CrmStatisticsFollowUpSummaryByUserRespVO::getFollowUpRecordCount).sum(); + Integer followUpCustomerCount = followUpCustomerCountList.stream().filter(vo -> userId.equals(vo.getOwnerUserId())) + .mapToInt(CrmStatisticsFollowUpSummaryByUserRespVO::getFollowUpCustomerCount).sum(); + return (CrmStatisticsFollowUpSummaryByUserRespVO) new CrmStatisticsFollowUpSummaryByUserRespVO() + .setFollowUpCustomerCount(followUpRecordCount).setFollowUpRecordCount(followUpCustomerCount).setOwnerUserId(userId); + }); + // 3.2 拼接用户信息 + appendUserInfo(summaryList); + return summaryList; + } + + @Override + public List getFollowUpSummaryByType(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + reqVO.setUserIds(getUserIds(reqVO)); + if (CollUtil.isEmpty(reqVO.getUserIds())) { + return Collections.emptyList(); + } + + // 2. 获得跟进数据 + return customerMapper.selectFollowUpRecordCountGroupByType(reqVO); + } + + @Override + public List getContractSummary(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + reqVO.setUserIds(getUserIds(reqVO)); + if (CollUtil.isEmpty(reqVO.getUserIds())) { + return Collections.emptyList(); + } + + // 2. 按用户统计,获取统计数据 + List summaryList = customerMapper.selectContractSummary(reqVO); + + // 3. 拼接信息 + Map userMap = adminUserApi.getUserMap( + convertSetByFlatMap(summaryList, vo -> Stream.of(NumberUtils.parseLong(vo.getCreator()), vo.getOwnerUserId()))); + summaryList.forEach(vo -> { + findAndThen(userMap, NumberUtils.parseLong(vo.getCreator()), user -> vo.setCreatorUserName(user.getNickname())); + findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname())); + }); + return summaryList; + } + + @Override + public List getPoolSummaryByDate(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + reqVO.setUserIds(getUserIds(reqVO)); + if (CollUtil.isEmpty(reqVO.getUserIds())) { + return Collections.emptyList(); + } + + // 2. 按天统计,获取分项统计数据 + List customerPutCountList = customerMapper.selectPoolCustomerPutCountByDate(reqVO); + List customerTakeCountList = customerMapper.selectPoolCustomerTakeCountByDate(reqVO); + + // 3. 按照日期间隔,合并数据 + List timeRanges = LocalDateTimeUtils.getDateRangeList(reqVO.getTimes()[0], reqVO.getTimes()[1], reqVO.getInterval()); + return convertList(timeRanges, times -> { + Integer customerPutCount = customerPutCountList.stream() + .filter(vo -> LocalDateTimeUtils.isBetween(times[0], times[1], vo.getTime())) + .mapToInt(CrmStatisticsPoolSummaryByDateRespVO::getCustomerPutCount).sum(); + Integer customerTakeCount = customerTakeCountList.stream() + .filter(vo -> LocalDateTimeUtils.isBetween(times[0], times[1], vo.getTime())) + .mapToInt(CrmStatisticsPoolSummaryByDateRespVO::getCustomerTakeCount).sum(); + return new CrmStatisticsPoolSummaryByDateRespVO() + .setTime(LocalDateTimeUtils.formatDateRange(times[0], times[1], reqVO.getInterval())) + .setCustomerPutCount(customerPutCount).setCustomerTakeCount(customerTakeCount); + }); + } + + @Override + public List getPoolSummaryByUser(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + reqVO.setUserIds(getUserIds(reqVO)); + if (CollUtil.isEmpty(reqVO.getUserIds())) { + return Collections.emptyList(); + } + + // 2. 按用户统计,获取分项统计数据 + List customerPutCountList = customerMapper.selectPoolCustomerPutCountByUser(reqVO); + List customerTakeCountList = customerMapper.selectPoolCustomerTakeCountByUser(reqVO); + + // 3.1 按照用户,合并统计数据 + List summaryList = convertList(reqVO.getUserIds(), userId -> { + Integer customerPutCount = customerPutCountList.stream().filter(vo -> userId.equals(vo.getOwnerUserId())) + .mapToInt(CrmStatisticsPoolSummaryByUserRespVO::getCustomerPutCount).sum(); + Integer customerTakeCount = customerTakeCountList.stream().filter(vo -> userId.equals(vo.getOwnerUserId())) + .mapToInt(CrmStatisticsPoolSummaryByUserRespVO::getCustomerTakeCount).sum(); + return (CrmStatisticsPoolSummaryByUserRespVO) new CrmStatisticsPoolSummaryByUserRespVO() + .setCustomerPutCount(customerPutCount).setCustomerTakeCount(customerTakeCount) + .setOwnerUserId(userId); + }); + // 3.2 拼接用户信息 + appendUserInfo(summaryList); + return summaryList; + } + + @Override + public List getCustomerDealCycleByDate(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + reqVO.setUserIds(getUserIds(reqVO)); + if (CollUtil.isEmpty(reqVO.getUserIds())) { + return Collections.emptyList(); + } + + // 2. 按天统计,获取分项统计数据 + List customerDealCycleList = customerMapper.selectCustomerDealCycleGroupByDate(reqVO); + + // 3. 按照日期间隔,合并统计数据 + List timeRanges = LocalDateTimeUtils.getDateRangeList(reqVO.getTimes()[0], reqVO.getTimes()[1], reqVO.getInterval()); + return convertList(timeRanges, times -> { + Double customerDealCycle = customerDealCycleList.stream() + .filter(vo -> LocalDateTimeUtils.isBetween(times[0], times[1], vo.getTime())) + .mapToDouble(CrmStatisticsCustomerDealCycleByDateRespVO::getCustomerDealCycle).sum(); + return new CrmStatisticsCustomerDealCycleByDateRespVO() + .setTime(LocalDateTimeUtils.formatDateRange(times[0], times[1], reqVO.getInterval())) + .setCustomerDealCycle(customerDealCycle); + }); + } + + @Override + public List getCustomerDealCycleByUser(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + reqVO.setUserIds(getUserIds(reqVO)); + if (CollUtil.isEmpty(reqVO.getUserIds())) { + return Collections.emptyList(); + } + + // 2. 按用户统计,获取分项统计数据 + List customerDealCycleList = customerMapper.selectCustomerDealCycleGroupByUser(reqVO); + List customerDealCountList = customerMapper.selectCustomerDealCountGroupByUser(reqVO); + + // 3.1 按照用户,合并统计数据 + List summaryList = convertList(reqVO.getUserIds(), userId -> { + Double customerDealCycle = customerDealCycleList.stream().filter(vo -> userId.equals(vo.getOwnerUserId())) + .mapToDouble(CrmStatisticsCustomerDealCycleByUserRespVO::getCustomerDealCycle).sum(); + Integer customerDealCount = customerDealCountList.stream().filter(vo -> userId.equals(vo.getOwnerUserId())) + .mapToInt(CrmStatisticsCustomerSummaryByUserRespVO::getCustomerDealCount).sum(); + return (CrmStatisticsCustomerDealCycleByUserRespVO) new CrmStatisticsCustomerDealCycleByUserRespVO() + .setCustomerDealCycle(customerDealCycle).setCustomerDealCount(customerDealCount).setOwnerUserId(userId); + }); + // 3.2 拼接用户信息 + appendUserInfo(summaryList); + return summaryList; + } + + /** + * 拼接用户信息(昵称) + * + * @param voList 统计数据 + */ + private void appendUserInfo(List voList) { + Map userMap = adminUserApi.getUserMap( + convertSet(voList, CrmStatisticsCustomerByUserBaseRespVO::getOwnerUserId)); + voList.forEach(vo -> findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname()))); + } + + /** + * 获取用户编号数组。如果用户编号为空, 则获得部门下的用户编号数组,包括子部门的所有用户编号 + * + * @param reqVO 请求参数 + * @return 用户编号数组 + */ + private List getUserIds(CrmStatisticsCustomerReqVO reqVO) { + // 情况一:选中某个用户 + if (ObjUtil.isNotNull(reqVO.getUserId())) { + return List.of(reqVO.getUserId()); + } + // 情况二:选中某个部门 + // 2.1 获得部门列表 + List deptIds = convertList(deptApi.getChildDeptList(reqVO.getDeptId()).getCheckedData(), DeptRespDTO::getId); + deptIds.add(reqVO.getDeptId()); + // 2.2 获得用户编号 + return convertList(adminUserApi.getUserListByDeptIds(deptIds).getCheckedData(), AdminUserRespDTO::getId); + } + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceService.java new file mode 100644 index 000000000..15423af29 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceService.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.crm.service.statistics; + + + +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; + +import java.util.List; + +/** + * CRM 员工绩效统计 Service 接口 + * + * @author scholar + */ +public interface CrmStatisticsPerformanceService { + + /** + * 员工签约合同数量分析 + * + * @param performanceReqVO 排行参数 + * @return 员工签约合同数量排行分析 + */ + List getContractCountPerformance(CrmStatisticsPerformanceReqVO performanceReqVO); + + /** + * 员工签约合同金额分析 + * + * @param performanceReqVO 排行参数 + * @return 员工签约合同金额分析 + */ + List getContractPricePerformance(CrmStatisticsPerformanceReqVO performanceReqVO); + + /** + * 员工获得回款金额分析 + * + * @param performanceReqVO 排行参数 + * @return 员工获得回款金额分析 + */ + List getReceivablePricePerformance(CrmStatisticsPerformanceReqVO performanceReqVO); + + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java new file mode 100644 index 000000000..5f168a010 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java @@ -0,0 +1,102 @@ +package cn.iocoder.yudao.module.crm.service.statistics; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; +import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsPerformanceMapper; +import cn.iocoder.yudao.module.system.api.dept.DeptApi; +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.Collections; +import java.util.List; +import java.util.function.Function; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; + +/** + * CRM 员工业绩分析 Service 实现类 + * + * @author scholar + */ +@Service +@Validated +public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerformanceService { + + @Resource + private CrmStatisticsPerformanceMapper performanceMapper; + + @Resource + private AdminUserApi adminUserApi; + @Resource + private DeptApi deptApi; + + @Override + public List getContractCountPerformance(CrmStatisticsPerformanceReqVO performanceReqVO) { + // TODO @scholar:我们可以换个思路实现,减少数据库的计算量; + // 比如说,2024 年的合同数据,是不是 2022-12 到 2024-12-31,每个月的统计呢? + // 理解之后,我们可以数据 group by 年-月,20222-12 到 2024-12-31 的,然后内存在聚合出 CrmStatisticsPerformanceRespVO 这样 + // 这样,我们就可以减少数据库的计算量,提升性能;同时 SQL 也会很简单,开发者理解起来也简单哈; + return getPerformance(performanceReqVO, performanceMapper::selectContractCountPerformance); + } + + @Override + public List getContractPricePerformance(CrmStatisticsPerformanceReqVO performanceReqVO) { + return getPerformance(performanceReqVO, performanceMapper::selectContractPricePerformance); + } + + @Override + public List getReceivablePricePerformance(CrmStatisticsPerformanceReqVO performanceReqVO) { + return getPerformance(performanceReqVO, performanceMapper::selectReceivablePricePerformance); + } + + /** + * 获得员工业绩数据 + * + * @param performanceReqVO 参数 + * @param performanceFunction 排行榜方法 + * @return 排行版数据 + */ + private List getPerformance(CrmStatisticsPerformanceReqVO performanceReqVO, Function> performanceFunction) { + + // 1. 获得用户编号数组 + final List userIds = getUserIds(performanceReqVO); + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } + performanceReqVO.setUserIds(userIds); + // 2. 获得排行数据 + List performance = performanceFunction.apply(performanceReqVO); + if (CollUtil.isEmpty(performance)) { + return Collections.emptyList(); + } + return performance; + } + + /** + * 获取用户编号数组。如果用户编号为空, 则获得部门下的用户编号数组,包括子部门的所有用户编号 + * + * @param reqVO 请求参数 + * @return 用户编号数组 + */ + private List getUserIds(CrmStatisticsPerformanceReqVO reqVO) { + // 情况一:选中某个用户 + if (ObjUtil.isNotNull(reqVO.getUserId())) { + return List.of(reqVO.getUserId()); + } + // 情况二:选中某个部门 + // 2.1 获得部门列表 + final Long deptId = reqVO.getDeptId(); + List deptIds = convertList(deptApi.getChildDeptList(deptId).getCheckedData(), DeptRespDTO::getId); + deptIds.add(deptId); + // 2.2 获得用户编号 + return convertList(adminUserApi.getUserListByDeptIds(deptIds).getCheckedData(), AdminUserRespDTO::getId); + } + +} \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitService.java new file mode 100644 index 000000000..c568d3b4e --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitService.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.crm.service.statistics; + +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.*; + +import java.util.List; + +/** + * CRM 客户画像 Service 接口 + * + * @author HUIHUI + */ +public interface CrmStatisticsPortraitService { + + /** + * 获取客户地区统计数据 + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerSummaryByArea(CrmStatisticsPortraitReqVO reqVO); + + /** + * 获取客户行业统计数据 + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerSummaryByIndustry(CrmStatisticsPortraitReqVO reqVO); + + /** + * 获取客户级别统计数据 + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerSummaryByLevel(CrmStatisticsPortraitReqVO reqVO); + + /** + * 获取客户来源统计数据 + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerSummaryBySource(CrmStatisticsPortraitReqVO reqVO); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitServiceImpl.java new file mode 100644 index 000000000..8ce940a19 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitServiceImpl.java @@ -0,0 +1,128 @@ +package cn.iocoder.yudao.module.crm.service.statistics; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; +import cn.iocoder.yudao.framework.ip.core.Area; +import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum; +import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.*; +import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsPortraitMapper; +import cn.iocoder.yudao.module.system.api.dept.DeptApi; +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; + +/** + * CRM 客户画像 Service 实现类 + * + * @author HUIHUI + */ +@Service +public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitService { + + @Resource + private CrmStatisticsPortraitMapper portraitMapper; + + @Resource + private AdminUserApi adminUserApi; + @Resource + private DeptApi deptApi; + + @Override + public List getCustomerSummaryByArea(CrmStatisticsPortraitReqVO reqVO) { + // 1. 获得用户编号数组 + List userIds = getUserIds(reqVO); + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } + reqVO.setUserIds(userIds); + + // 2. 获取客户地区统计数据 + List list = portraitMapper.selectSummaryListGroupByAreaId(reqVO); + if (CollUtil.isEmpty(list)) { + return Collections.emptyList(); + } + + // 3. 拼接数据 + List areaList = AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area); + areaList.add(new Area().setId(null).setName("未知")); // TODO @puhui999:是不是 65 find 的逻辑改下;不用 findAndThen,直接从 areaMap 拿;拿到就设置,不拿到就设置 null 和 未知;这样,58 本行可以删除掉完事了;这样代码更简单和一致 + Map areaMap = convertMap(areaList, Area::getId); + return convertList(list, item -> { + Integer parentId = AreaUtils.getParentIdByType(item.getAreaId(), AreaTypeEnum.PROVINCE); + if (parentId == null) { // 找不到,归到未知 + return item.setAreaId(null).setAreaName("未知"); + } + findAndThen(areaMap, parentId, area -> item.setAreaId(parentId).setAreaName(area.getName())); + return item; + }); + } + + @Override + public List getCustomerSummaryByIndustry(CrmStatisticsPortraitReqVO reqVO) { + // 1. 获得用户编号数组 + List userIds = getUserIds(reqVO); + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } + reqVO.setUserIds(userIds); + + // 2. 获取客户行业统计数据 + return portraitMapper.selectCustomerIndustryListGroupByIndustryId(reqVO); + } + + @Override + public List getCustomerSummaryBySource(CrmStatisticsPortraitReqVO reqVO) { + // 1. 获得用户编号数组 + List userIds = getUserIds(reqVO); + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } + reqVO.setUserIds(userIds); + + // 2. 获取客户行业统计数据 + return portraitMapper.selectCustomerSourceListGroupBySource(reqVO); + } + + @Override + public List getCustomerSummaryByLevel(CrmStatisticsPortraitReqVO reqVO) { + // 1. 获得用户编号数组 + List userIds = getUserIds(reqVO); + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } + reqVO.setUserIds(userIds); + + // 2. 获取客户级别统计数据 + return portraitMapper.selectCustomerLevelListGroupByLevel(reqVO); + } + + /** + * 获取用户编号数组。如果用户编号为空, 则获得部门下的用户编号数组,包括子部门的所有用户编号 + * + * @param reqVO 请求参数 + * @return 用户编号数组 + */ + private List getUserIds(CrmStatisticsPortraitReqVO reqVO) { + // 情况一:选中某个用户 + if (ObjUtil.isNotNull(reqVO.getUserId())) { + return List.of(reqVO.getUserId()); + } + // 情况二:选中某个部门 + // 2.1 获得部门列表 + List deptIds = convertList(deptApi.getChildDeptList(reqVO.getDeptId()).getCheckedData(), DeptRespDTO::getId); + deptIds.add(reqVO.getDeptId()); + // 2.2 获得用户编号 + return convertList(adminUserApi.getUserListByDeptIds(deptIds).getCheckedData(), AdminUserRespDTO::getId); + } + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankingService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankService.java similarity index 71% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankingService.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankService.java index c9455708c..626e19247 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankingService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankService.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.crm.service.statistics; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.CrmStatisticsRanKRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.CrmStatisticsRankReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.rank.CrmStatisticsRankReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.rank.CrmStatisticsRankRespVO; import java.util.List; @@ -11,7 +11,7 @@ import java.util.List; * * @author anhaohao */ -public interface CrmStatisticsRankingService { +public interface CrmStatisticsRankService { /** * 获得合同金额排行榜 @@ -19,7 +19,7 @@ public interface CrmStatisticsRankingService { * @param rankReqVO 排行参数 * @return 合同金额排行榜 */ - List getContractPriceRank(CrmStatisticsRankReqVO rankReqVO); + List getContractPriceRank(CrmStatisticsRankReqVO rankReqVO); /** * 获得回款金额排行榜 @@ -27,7 +27,7 @@ public interface CrmStatisticsRankingService { * @param rankReqVO 排行参数 * @return 回款金额排行榜 */ - List getReceivablePriceRank(CrmStatisticsRankReqVO rankReqVO); + List getReceivablePriceRank(CrmStatisticsRankReqVO rankReqVO); /** * 获得签约合同数量排行榜 @@ -35,7 +35,7 @@ public interface CrmStatisticsRankingService { * @param rankReqVO 排行参数 * @return 签约合同数量排行榜 */ - List getContractCountRank(CrmStatisticsRankReqVO rankReqVO); + List getContractCountRank(CrmStatisticsRankReqVO rankReqVO); /** * 获得产品销量排行榜 @@ -43,7 +43,7 @@ public interface CrmStatisticsRankingService { * @param rankReqVO 排行参数 * @return 产品销量排行榜 */ - List getProductSalesRank(CrmStatisticsRankReqVO rankReqVO); + List getProductSalesRank(CrmStatisticsRankReqVO rankReqVO); /** * 获得新增客户数排行榜 @@ -51,7 +51,7 @@ public interface CrmStatisticsRankingService { * @param rankReqVO 排行参数 * @return 新增客户数排行榜 */ - List getCustomerCountRank(CrmStatisticsRankReqVO rankReqVO); + List getCustomerCountRank(CrmStatisticsRankReqVO rankReqVO); /** * 获得联系人数量排行榜 @@ -59,7 +59,7 @@ public interface CrmStatisticsRankingService { * @param rankReqVO 排行参数 * @return 联系人数量排行榜 */ - List getContactsCountRank(CrmStatisticsRankReqVO rankReqVO); + List getContactsCountRank(CrmStatisticsRankReqVO rankReqVO); /** * 获得跟进次数排行榜 @@ -67,7 +67,7 @@ public interface CrmStatisticsRankingService { * @param rankReqVO 排行参数 * @return 跟进次数排行榜 */ - List getFollowCountRank(CrmStatisticsRankReqVO rankReqVO); + List getFollowCountRank(CrmStatisticsRankReqVO rankReqVO); /** * 获得跟进客户数排行榜 @@ -75,6 +75,6 @@ public interface CrmStatisticsRankingService { * @param rankReqVO 排行参数 * @return 跟进客户数排行榜 */ - List getFollowCustomerCountRank(CrmStatisticsRankReqVO rankReqVO); + List getFollowCustomerCountRank(CrmStatisticsRankReqVO rankReqVO); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankingServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankServiceImpl.java similarity index 78% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankingServiceImpl.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankServiceImpl.java index 82ea9d8eb..7b2eb5463 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankingServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsRankServiceImpl.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.crm.service.statistics; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.CrmStatisticsRanKRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.CrmStatisticsRankReqVO; -import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsRankingMapper; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.rank.CrmStatisticsRankReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.rank.CrmStatisticsRankRespVO; +import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsRankMapper; import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; @@ -29,10 +29,10 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. */ @Service @Validated -public class CrmStatisticsRankingServiceImpl implements CrmStatisticsRankingService { +public class CrmStatisticsRankServiceImpl implements CrmStatisticsRankService { @Resource - private CrmStatisticsRankingMapper rankMapper; + private CrmStatisticsRankMapper rankMapper; @Resource private AdminUserApi adminUserApi; @@ -40,64 +40,64 @@ public class CrmStatisticsRankingServiceImpl implements CrmStatisticsRankingServ private DeptApi deptApi; @Override - public List getContractPriceRank(CrmStatisticsRankReqVO rankReqVO) { + public List getContractPriceRank(CrmStatisticsRankReqVO rankReqVO) { return getRank(rankReqVO, rankMapper::selectContractPriceRank); } @Override - public List getReceivablePriceRank(CrmStatisticsRankReqVO rankReqVO) { + public List getReceivablePriceRank(CrmStatisticsRankReqVO rankReqVO) { return getRank(rankReqVO, rankMapper::selectReceivablePriceRank); } @Override - public List getContractCountRank(CrmStatisticsRankReqVO rankReqVO) { + public List getContractCountRank(CrmStatisticsRankReqVO rankReqVO) { return getRank(rankReqVO, rankMapper::selectContractCountRank); } @Override - public List getProductSalesRank(CrmStatisticsRankReqVO rankReqVO) { + public List getProductSalesRank(CrmStatisticsRankReqVO rankReqVO) { return getRank(rankReqVO, rankMapper::selectProductSalesRank); } @Override - public List getCustomerCountRank(CrmStatisticsRankReqVO rankReqVO) { + public List getCustomerCountRank(CrmStatisticsRankReqVO rankReqVO) { return getRank(rankReqVO, rankMapper::selectCustomerCountRank); } @Override - public List getContactsCountRank(CrmStatisticsRankReqVO rankReqVO) { + public List getContactsCountRank(CrmStatisticsRankReqVO rankReqVO) { return getRank(rankReqVO, rankMapper::selectContactsCountRank); } @Override - public List getFollowCountRank(CrmStatisticsRankReqVO rankReqVO) { + public List getFollowCountRank(CrmStatisticsRankReqVO rankReqVO) { return getRank(rankReqVO, rankMapper::selectFollowCountRank); } @Override - public List getFollowCustomerCountRank(CrmStatisticsRankReqVO rankReqVO) { + public List getFollowCustomerCountRank(CrmStatisticsRankReqVO rankReqVO) { return getRank(rankReqVO, rankMapper::selectFollowCustomerCountRank); } /** * 获得排行版数据 * - * @param rankReqVO 参数 + * @param rankReqVO 参数 * @param rankFunction 排行榜方法 * @return 排行版数据 */ - private List getRank(CrmStatisticsRankReqVO rankReqVO, Function> rankFunction) { + private List getRank(CrmStatisticsRankReqVO rankReqVO, Function> rankFunction) { // 1. 获得用户编号数组 rankReqVO.setUserIds(getUserIds(rankReqVO.getDeptId())); if (CollUtil.isEmpty(rankReqVO.getUserIds())) { return Collections.emptyList(); } // 2. 获得排行数据 - List ranks = rankFunction.apply(rankReqVO); + List ranks = rankFunction.apply(rankReqVO); if (CollUtil.isEmpty(ranks)) { return Collections.emptyList(); } - ranks.sort(Comparator.comparing(CrmStatisticsRanKRespVO::getCount).reversed()); + ranks.sort(Comparator.comparing(CrmStatisticsRankRespVO::getCount).reversed()); // 3. 拼接用户信息 appendUserInfo(ranks); return ranks; @@ -108,8 +108,8 @@ public class CrmStatisticsRankingServiceImpl implements CrmStatisticsRankingServ * * @param ranks 排行榜数据 */ - private void appendUserInfo(List ranks) { - Map userMap = adminUserApi.getUserMap(convertSet(ranks, CrmStatisticsRanKRespVO::getOwnerUserId)); + private void appendUserInfo(List ranks) { + Map userMap = adminUserApi.getUserMap(convertSet(ranks, CrmStatisticsRankRespVO::getOwnerUserId)); Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); ranks.forEach(rank -> MapUtils.findAndThen(userMap, rank.getOwnerUserId(), user -> { rank.setNickname(user.getNickname()); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application-dev.yaml b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application-dev.yaml index f0d6069e0..7895075b7 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application-dev.yaml +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application-dev.yaml @@ -98,6 +98,4 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application-local.yaml b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application-local.yaml index 2295d6d1c..897686ebb 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application-local.yaml +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application-local.yaml @@ -124,6 +124,4 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application.yaml b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application.yaml index dfe866cd4..35175f57f 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application.yaml +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/application.yaml @@ -100,9 +100,6 @@ yudao: description: 提供管理员管理的所有功能 version: ${yudao.info.version} base-package: ${yudao.info.base-package} - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/bi/CrmBiRankingMapper.xml b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/bi/CrmBiRankingMapper.xml deleted file mode 100644 index d91d2ad64..000000000 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/bi/CrmBiRankingMapper.xml +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsCustomerMapper.xml b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsCustomerMapper.xml new file mode 100644 index 000000000..44c6c4b84 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsCustomerMapper.xml @@ -0,0 +1,224 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPerformanceMapper.xml b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPerformanceMapper.xml new file mode 100644 index 000000000..10b952bac --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPerformanceMapper.xml @@ -0,0 +1,152 @@ + + + + + + + + + + + diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPortraitMapper.xml b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPortraitMapper.xml new file mode 100644 index 000000000..42056a48b --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPortraitMapper.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsRankMapper.xml b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsRankMapper.xml new file mode 100644 index 000000000..abd63f27d --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsRankMapper.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/ErpPurchaseOrderController.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/ErpPurchaseOrderController.java index 7bced994e..10cbb6226 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/ErpPurchaseOrderController.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/ErpPurchaseOrderController.java @@ -61,14 +61,14 @@ public class ErpPurchaseOrderController { @PostMapping("/create") @Operation(summary = "创建采购订单") - @PreAuthorize("@ss.hasPermission('erp:purchase-create:create')") + @PreAuthorize("@ss.hasPermission('erp:purchase-order:create')") public CommonResult createPurchaseOrder(@Valid @RequestBody ErpPurchaseOrderSaveReqVO createReqVO) { return success(purchaseOrderService.createPurchaseOrder(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新采购订单") - @PreAuthorize("@ss.hasPermission('erp:purchase-create:update')") + @PreAuthorize("@ss.hasPermission('erp:purchase-order:update')") public CommonResult updatePurchaseOrder(@Valid @RequestBody ErpPurchaseOrderSaveReqVO updateReqVO) { purchaseOrderService.updatePurchaseOrder(updateReqVO); return success(true); @@ -76,9 +76,9 @@ public class ErpPurchaseOrderController { @PutMapping("/update-status") @Operation(summary = "更新采购订单的状态") - @PreAuthorize("@ss.hasPermission('erp:purchase-create:update-status')") + @PreAuthorize("@ss.hasPermission('erp:purchase-order:update-status')") public CommonResult updatePurchaseOrderStatus(@RequestParam("id") Long id, - @RequestParam("status") Integer status) { + @RequestParam("status") Integer status) { purchaseOrderService.updatePurchaseOrderStatus(id, status); return success(true); } @@ -86,7 +86,7 @@ public class ErpPurchaseOrderController { @DeleteMapping("/delete") @Operation(summary = "删除采购订单") @Parameter(name = "ids", description = "编号数组", required = true) - @PreAuthorize("@ss.hasPermission('erp:purchase-create:delete')") + @PreAuthorize("@ss.hasPermission('erp:purchase-order:delete')") public CommonResult deletePurchaseOrder(@RequestParam("ids") List ids) { purchaseOrderService.deletePurchaseOrder(ids); return success(true); @@ -95,7 +95,7 @@ public class ErpPurchaseOrderController { @GetMapping("/get") @Operation(summary = "获得采购订单") @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('erp:purchase-create:query')") + @PreAuthorize("@ss.hasPermission('erp:purchase-order:query')") public CommonResult getPurchaseOrder(@RequestParam("id") Long id) { ErpPurchaseOrderDO purchaseOrder = purchaseOrderService.getPurchaseOrder(id); if (purchaseOrder == null) { @@ -115,7 +115,7 @@ public class ErpPurchaseOrderController { @GetMapping("/page") @Operation(summary = "获得采购订单分页") - @PreAuthorize("@ss.hasPermission('erp:purchase-create:query')") + @PreAuthorize("@ss.hasPermission('erp:purchase-order:query')") public CommonResult> getPurchaseOrderPage(@Valid ErpPurchaseOrderPageReqVO pageReqVO) { PageResult pageResult = purchaseOrderService.getPurchaseOrderPage(pageReqVO); return success(buildPurchaseOrderVOPageResult(pageResult)); @@ -123,10 +123,10 @@ public class ErpPurchaseOrderController { @GetMapping("/export-excel") @Operation(summary = "导出采购订单 Excel") - @PreAuthorize("@ss.hasPermission('erp:purchase-create:export')") + @PreAuthorize("@ss.hasPermission('erp:purchase-order:export')") @ApiAccessLog(operateType = EXPORT) public void exportPurchaseOrderExcel(@Valid ErpPurchaseOrderPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { + HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = buildPurchaseOrderVOPageResult(purchaseOrderService.getPurchaseOrderPage(pageReqVO)).getList(); // 导出 Excel diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application-dev.yaml b/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application-dev.yaml index 03aa20967..42dd8c6f9 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application-dev.yaml +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application-dev.yaml @@ -98,6 +98,4 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application-local.yaml b/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application-local.yaml index 013dd0fcd..cf4703d62 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application-local.yaml +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application-local.yaml @@ -124,6 +124,4 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application.yaml b/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application.yaml index 25fc265a0..59a1f84b3 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application.yaml +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/resources/application.yaml @@ -100,9 +100,6 @@ yudao: description: 提供管理员管理的所有功能 version: ${yudao.info.version} base-package: ${yudao.info.base-package} - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: diff --git a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java index 19aa4e718..1b2a4514c 100644 --- a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java +++ b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java @@ -15,14 +15,6 @@ public interface ErrorCodeConstants { ErrorCode CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE = new ErrorCode(1_001_000_003, "不能删除类型为系统内置的参数配置"); ErrorCode CONFIG_GET_VALUE_ERROR_IF_VISIBLE = new ErrorCode(1_001_000_004, "获取参数配置失败,原因:不允许获取不可见配置"); - // ========== 定时任务 1-001-001-000 ========== - ErrorCode JOB_NOT_EXISTS = new ErrorCode(1_001_001_000, "定时任务不存在"); - ErrorCode JOB_HANDLER_EXISTS = new ErrorCode(1_001_001_001, "定时任务的处理器已经存在"); - ErrorCode JOB_CHANGE_STATUS_INVALID = new ErrorCode(1_001_001_002, "只允许修改为开启或者关闭状态"); - ErrorCode JOB_CHANGE_STATUS_EQUALS = new ErrorCode(1_001_001_003, "定时任务已经处于该状态,无需修改"); - ErrorCode JOB_UPDATE_ONLY_NORMAL_STATUS = new ErrorCode(1_001_001_004, "只有开启状态的任务,才可以修改"); - ErrorCode JOB_CRON_EXPRESSION_VALID = new ErrorCode(1_001_001_005, "CRON 表达式不正确"); - // ========== API 错误日志 1-001-002-000 ========== ErrorCode API_ERROR_LOG_NOT_FOUND = new ErrorCode(1_001_002_000, "API 错误日志不存在"); ErrorCode API_ERROR_LOG_PROCESSED = new ErrorCode(1_001_002_001, "API 错误日志已处理"); @@ -45,7 +37,6 @@ public interface ErrorCodeConstants { ErrorCode CODEGEN_MASTER_TABLE_NOT_EXISTS = new ErrorCode(1_001_004_010, "主表(id={})定义不存在,请检查"); ErrorCode CODEGEN_SUB_COLUMN_NOT_EXISTS = new ErrorCode(1_001_004_011, "子表的字段(id={})不存在,请检查"); ErrorCode CODEGEN_MASTER_GENERATION_FAIL_NO_SUB_TABLE = new ErrorCode(1_001_004_012, "主表生成代码失败,原因:它没有子表"); - ErrorCode CODEGEN_MASTER_GENERATION_FAIL_NO_SUB_COLUMN = new ErrorCode(1_001_004_013, "主表生成代码失败,原因:它的子表({})没有字段"); // ========== 文件配置 1-001-006-000 ========== ErrorCode FILE_CONFIG_NOT_EXISTS = new ErrorCode(1_001_006_000, "文件配置不存在"); @@ -55,9 +46,6 @@ public interface ErrorCodeConstants { ErrorCode DATA_SOURCE_CONFIG_NOT_EXISTS = new ErrorCode(1_001_007_000, "数据源配置不存在"); ErrorCode DATA_SOURCE_CONFIG_NOT_OK = new ErrorCode(1_001_007_001, "数据源配置不正确,无法进行连接"); - // ========== 数据源配置 1-001-107-000 ========== - ErrorCode DEMO_STUDENT_NOT_EXISTS = new ErrorCode(1_001_107_000, "学生不存在"); - // ========== 学生 1-001-201-000 ========== ErrorCode DEMO01_CONTACT_NOT_EXISTS = new ErrorCode(1_001_201_000, "示例联系人不存在"); ErrorCode DEMO02_CATEGORY_NOT_EXISTS = new ErrorCode(1_001_201_001, "示例分类不存在"); diff --git a/yudao-module-infra/yudao-module-infra-biz/pom.xml b/yudao-module-infra/yudao-module-infra-biz/pom.xml index 20eda8034..91e1386de 100644 --- a/yudao-module-infra/yudao-module-infra-biz/pom.xml +++ b/yudao-module-infra/yudao-module-infra-biz/pom.xml @@ -117,11 +117,6 @@ velocity-engine-core - - cn.smallbun.screw - screw-core - - cn.iocoder.cloud diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DatabaseDocController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DatabaseDocController.java deleted file mode 100644 index c5785db8d..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DatabaseDocController.java +++ /dev/null @@ -1,154 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.db; - -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.IdUtil; -import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; -import cn.smallbun.screw.core.Configuration; -import cn.smallbun.screw.core.engine.EngineConfig; -import cn.smallbun.screw.core.engine.EngineFileType; -import cn.smallbun.screw.core.engine.EngineTemplateType; -import cn.smallbun.screw.core.execute.DocumentationExecute; -import cn.smallbun.screw.core.process.ProcessConfig; -import com.baomidou.dynamic.datasource.creator.DataSourceProperty; -import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties; -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; - -@Tag(name = "管理后台 - 数据库文档") -@RestController -@RequestMapping("/infra/db-doc") -public class DatabaseDocController { - - @Resource - private DynamicDataSourceProperties dynamicDataSourceProperties; - - private static final String FILE_OUTPUT_DIR = System.getProperty("java.io.tmpdir") + File.separator - + "db-doc"; - private static final String DOC_FILE_NAME = "数据库文档"; - private static final String DOC_VERSION = "1.0.0"; - private static final String DOC_DESCRIPTION = "文档描述"; - - @GetMapping("/export-html") - @Operation(summary = "导出 html 格式的数据文档") - @Parameter(name = "deleteFile", description = "是否删除在服务器本地生成的数据库文档", example = "true") - public void exportHtml(@RequestParam(defaultValue = "true") Boolean deleteFile, - HttpServletResponse response) throws IOException { - doExportFile(EngineFileType.HTML, deleteFile, response); - } - - @GetMapping("/export-word") - @Operation(summary = "导出 word 格式的数据文档") - @Parameter(name = "deleteFile", description = "是否删除在服务器本地生成的数据库文档", example = "true") - public void exportWord(@RequestParam(defaultValue = "true") Boolean deleteFile, - HttpServletResponse response) throws IOException { - doExportFile(EngineFileType.WORD, deleteFile, response); - } - - @GetMapping("/export-markdown") - @Operation(summary = "导出 markdown 格式的数据文档") - @Parameter(name = "deleteFile", description = "是否删除在服务器本地生成的数据库文档", example = "true") - public void exportMarkdown(@RequestParam(defaultValue = "true") Boolean deleteFile, - HttpServletResponse response) throws IOException { - doExportFile(EngineFileType.MD, deleteFile, response); - } - - private void doExportFile(EngineFileType fileOutputType, Boolean deleteFile, - HttpServletResponse response) throws IOException { - String docFileName = DOC_FILE_NAME + "_" + IdUtil.fastSimpleUUID(); - String filePath = doExportFile(fileOutputType, docFileName); - String downloadFileName = DOC_FILE_NAME + fileOutputType.getFileSuffix(); //下载后的文件名 - try { - // 读取,返回 - ServletUtils.writeAttachment(response, downloadFileName, FileUtil.readBytes(filePath)); - } finally { - handleDeleteFile(deleteFile, filePath); - } - } - - /** - * 输出文件,返回文件路径 - * - * @param fileOutputType 文件类型 - * @param fileName 文件名, 无需 ".docx" 等文件后缀 - * @return 生成的文件所在路径 - */ - private String doExportFile(EngineFileType fileOutputType, String fileName) { - try (HikariDataSource dataSource = buildDataSource()) { - // 创建 screw 的配置 - Configuration config = Configuration.builder() - .version(DOC_VERSION) // 版本 - .description(DOC_DESCRIPTION) // 描述 - .dataSource(dataSource) // 数据源 - .engineConfig(buildEngineConfig(fileOutputType, fileName)) // 引擎配置 - .produceConfig(buildProcessConfig()) // 处理配置 - .build(); - - // 执行 screw,生成数据库文档 - new DocumentationExecute(config).execute(); - - return FILE_OUTPUT_DIR + File.separator + fileName + fileOutputType.getFileSuffix(); - } - } - - private void handleDeleteFile(Boolean deleteFile, String filePath) { - if (!deleteFile) { - return; - } - FileUtil.del(filePath); - } - - /** - * 创建数据源 - */ - // TODO 芋艿:screw 暂时不支持 druid,尴尬 - private HikariDataSource buildDataSource() { - // 获得 DataSource 数据源,目前只支持首个 - String primary = dynamicDataSourceProperties.getPrimary(); - DataSourceProperty dataSourceProperty = dynamicDataSourceProperties.getDatasource().get(primary); - // 创建 HikariConfig 配置类 - HikariConfig hikariConfig = new HikariConfig(); - hikariConfig.setJdbcUrl(dataSourceProperty.getUrl()); - hikariConfig.setUsername(dataSourceProperty.getUsername()); - hikariConfig.setPassword(dataSourceProperty.getPassword()); - hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息 - // 创建数据源 - return new HikariDataSource(hikariConfig); - } - - /** - * 创建 screw 的引擎配置 - */ - private static EngineConfig buildEngineConfig(EngineFileType fileOutputType, String docFileName) { - return EngineConfig.builder() - .fileOutputDir(FILE_OUTPUT_DIR) // 生成文件路径 - .openOutputDir(false) // 打开目录 - .fileType(fileOutputType) // 文件类型 - .produceType(EngineTemplateType.velocity) // 文件类型 - .fileName(docFileName) // 自定义文件名称 - .build(); - } - - /** - * 创建 screw 的处理配置,一般可忽略 - * 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置 - */ - private static ProcessConfig buildProcessConfig() { - return ProcessConfig.builder() - .ignoreTablePrefix(Arrays.asList("QRTZ_", "ACT_", "FLW_")) // 忽略表前缀 - .build(); - } - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml index af3b2cfa5..519ac6749 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml @@ -147,6 +147,4 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml index 2ca2a28c5..67971a7f7 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml @@ -143,9 +143,6 @@ yudao: base-package: cn.iocoder.yudao db-schemas: ${spring.datasource.dynamic.datasource.master.name} front-type: 10 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类 - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/list_sub_erp.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/list_sub_erp.vue.vm index 71a7511be..3f0710e01 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/list_sub_erp.vue.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/list_sub_erp.vue.vm @@ -94,7 +94,7 @@ const { t } = useI18n() // 国际化 const message = useMessage() // 消息弹窗 const props = defineProps<{ - ${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段) + ${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段) }>() const loading = ref(false) // 列表的加载中 const list = ref([]) // 列表的数据 @@ -103,17 +103,20 @@ const total = ref(0) // 列表的总页数 const queryParams = reactive({ pageNo: 1, pageSize: 10, - ${subJoinColumn.javaField}: undefined + ${subJoinColumn.javaField}: undefined as unknown }) /** 监听主表的关联字段的变化,加载对应的子表数据 */ watch( () => props.${subJoinColumn.javaField}, - (val) => { + (val: number) => { + if (!val) { + return + } queryParams.${subJoinColumn.javaField} = val handleQuery() }, - { immediate: false } + { immediate: true, deep: true } ) #end diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java index 1dcaec1ed..b1cfc69c5 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java @@ -101,7 +101,7 @@ public class AppProductSpuController { throw exception(SPU_NOT_EXISTS); } if (!ProductSpuStatusEnum.isEnable(spu.getStatus())) { - throw exception(SPU_NOT_ENABLE); + throw exception(SPU_NOT_ENABLE, spu.getName()); } // 获得商品 SKU List skus = productSkuService.getSkuListBySpuId(spu.getId()); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/resources/application-local.yaml b/yudao-module-mall/yudao-module-product-biz/src/main/resources/application-local.yaml index d935b65d8..aaa7a20db 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/resources/application-local.yaml +++ b/yudao-module-mall/yudao-module-product-biz/src/main/resources/application-local.yaml @@ -128,6 +128,4 @@ yudao: enable: false access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/resources/application.yaml b/yudao-module-mall/yudao-module-product-biz/src/main/resources/application.yaml index 9380dd226..dedaffc2e 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/resources/application.yaml +++ b/yudao-module-mall/yudao-module-product-biz/src/main/resources/application.yaml @@ -101,9 +101,6 @@ yudao: base-package: ${yudao.info.base-package} captcha: enable: true # 验证码的开关,默认为 true; - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.product.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/application-local.yaml b/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/application-local.yaml index d935b65d8..aaa7a20db 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/application-local.yaml +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/application-local.yaml @@ -128,6 +128,4 @@ yudao: enable: false access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/application.yaml b/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/application.yaml index 5cef5b381..b21ee163d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/application.yaml +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/application.yaml @@ -101,9 +101,6 @@ yudao: base-package: ${yudao.info.base-package} captcha: enable: true # 验证码的开关,默认为 true; - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/application-local.yaml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/application-local.yaml index d935b65d8..aaa7a20db 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/application-local.yaml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/application-local.yaml @@ -128,6 +128,4 @@ yudao: enable: false access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/application.yaml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/application.yaml index 9c38b215f..5c8477d46 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/application.yaml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/application.yaml @@ -101,9 +101,6 @@ yudao: base-package: ${yudao.info.base-package} captcha: enable: true # 验证码的开关,默认为 true; - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.statistics.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/vo/pickup/DeliveryPickUpStorePageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/vo/pickup/DeliveryPickUpStorePageReqVO.java index 45f0c87b9..ee3ce2e49 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/vo/pickup/DeliveryPickUpStorePageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/vo/pickup/DeliveryPickUpStorePageReqVO.java @@ -4,14 +4,11 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.validation.InEnum; import lombok.*; -import java.time.LocalTime; -import java.util.*; import io.swagger.v3.oas.annotations.media.Schema; import cn.iocoder.yudao.framework.common.pojo.PageParam; import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @Schema(description = "管理后台 - 自提门店分页 Request VO") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartAddReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartAddReqVO.java index b538f6174..0c33b8626 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartAddReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartAddReqVO.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.module.trade.controller.app.cart.vo; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; import lombok.Data; -import javax.validation.constraints.NotNull; - @Schema(description = "用户 App - 购物车添加购物项 Request VO") @Data public class AppCartAddReqVO { @@ -15,6 +15,7 @@ public class AppCartAddReqVO { @Schema(description = "新增商品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "数量不能为空") + @Min(value = 1, message = "商品数量必须大于等于 1") private Integer count; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderDetailRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderDetailRespVO.java index 3f5188bd4..b91bbf1a6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderDetailRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderDetailRespVO.java @@ -1,12 +1,10 @@ package cn.iocoder.yudao.module.trade.controller.app.order.vo; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; -import cn.iocoder.yudao.module.trade.enums.order.TradeOrderRefundStatusEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.time.LocalDateTime; -import java.util.Date; import java.util.List; @Schema(description = "用户 App - 订单交易的明细 Response VO") @@ -142,6 +140,9 @@ public class AppTradeOrderDetailRespVO { @Schema(description = "VIP 减免金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "888") private Integer vipPrice; + @Schema(description = "拼团记录编号", example = "100") + private Long combinationRecordId; + /** * 订单项数组 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderPageItemRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderPageItemRespVO.java index 647356d08..ba7b8138c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderPageItemRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderPageItemRespVO.java @@ -50,4 +50,9 @@ public class AppTradeOrderPageItemRespVO { */ private List items; + // ========== 营销基本信息 ========== + + @Schema(description = "拼团记录编号", example = "100") + private Long combinationRecordId; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java index e7a85868b..388f927ad 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java @@ -88,6 +88,7 @@ public interface BrokerageRecordMapper extends BaseMapperX { @Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + // TODO @芋艿:收敛掉 @Select 注解操作,统一成 MyBatis-Plus 的方式,或者 xml @Select("SELECT user_id AS id, SUM(price) AS brokeragePrice FROM trade_brokerage_record " + "WHERE biz_type = #{bizType} AND status = #{status} AND deleted = FALSE " + "AND unfreeze_time BETWEEN #{beginTime} AND #{endTime} " + diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index c206d6f29..64cb5e612 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -49,12 +49,12 @@ import cn.iocoder.yudao.module.trade.service.price.TradePriceService; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper; +import jakarta.annotation.Resource; +import jakarta.validation.constraints.NotNull; import lombok.extern.slf4j.Slf4j; -import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -624,7 +624,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_UPDATE_PRICE_FAIL_ALREADY); } // 1.3 支付价格不能为 0 - int newPayPrice = order.getPayPrice() + order.getAdjustPrice(); + int newPayPrice = order.getPayPrice() + reqVO.getAdjustPrice(); if (newPayPrice <= 0) { throw exception(ORDER_UPDATE_PRICE_FAIL_PRICE_ERROR); } @@ -635,12 +635,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 3. 更新 TradeOrderItem,需要做 adjustPrice 的分摊 List orderOrderItems = tradeOrderItemMapper.selectListByOrderId(order.getId()); - List dividePrices = TradePriceCalculatorHelper.dividePrice2(orderOrderItems, newPayPrice); + List dividePrices = TradePriceCalculatorHelper.dividePrice2(orderOrderItems, reqVO.getAdjustPrice()); List updateItems = new ArrayList<>(); for (int i = 0; i < orderOrderItems.size(); i++) { TradeOrderItemDO item = orderOrderItems.get(i); + // TODO puhui999: 已有分摊记录的情况下价格是否会不对,也就是说之前订单项 1 分摊了 10 块这次是 -100 + // 那么 setPayPrice 是否改为 (item.getPayPrice()-item.getAdjustPrice()) + dividePrices.get(i) 先减掉原来的价格再加上调价。经过验证可行,修改后订单价格增减都能正确分摊 updateItems.add(new TradeOrderItemDO().setId(item.getId()).setAdjustPrice(dividePrices.get(i)) - .setPayPrice(item.getPayPrice() + dividePrices.get(i))); + .setPayPrice((item.getPayPrice() - item.getAdjustPrice()) + dividePrices.get(i))); } tradeOrderItemMapper.updateBatch(updateItems); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java index be90a6f2b..930ed2160 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java @@ -83,7 +83,7 @@ public class TradeBrokerageOrderHandler implements TradeOrderHandler { if (order.getBrokerageUserId() == null) { return; } - cancelBrokerage(order.getBrokerageUserId(), orderItem.getOrderId()); + cancelBrokerage(order.getBrokerageUserId(), orderItem.getId()); } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java index 7def3e34e..850226fbb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java @@ -254,12 +254,15 @@ public class TradePriceCalculatorHelper { TradeOrderItemDO orderItem = items.get(i); int partPrice; if (i < items.size() - 1) { // 减一的原因,是因为拆分时,如果按照比例,可能会出现.所以最后一个,使用反减 - partPrice = (int) (price * (1.0D * orderItem.getPayPrice() / total)); + // partPrice = (int) (price * (1.0D * orderItem.getPayPrice() / total)); + // pr fix: 改为了使用订单原价来计算比例 + partPrice = (int) (price * (1.0D * orderItem.getPrice() / total)); remainPrice -= partPrice; } else { partPrice = remainPrice; } - Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0"); + // TODO puhui999: 如果是减价的情况这里过不了 + // Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0"); prices.add(partPrice); } return prices; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/application-local.yaml b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/application-local.yaml index 4dde16117..040bf4c84 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/application-local.yaml +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/application-local.yaml @@ -128,7 +128,5 @@ yudao: enable: false access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/application.yaml b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/application.yaml index 7e72ac59d..bc4ff8bc5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/application.yaml +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/application.yaml @@ -101,9 +101,6 @@ yudao: base-package: ${yudao.info.base-package} captcha: enable: true # 验证码的开关,默认为 true; - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: diff --git a/yudao-module-member/yudao-module-member-biz/src/main/resources/application-local.yaml b/yudao-module-member/yudao-module-member-biz/src/main/resources/application-local.yaml index d935b65d8..aaa7a20db 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/resources/application-local.yaml +++ b/yudao-module-member/yudao-module-member-biz/src/main/resources/application-local.yaml @@ -128,6 +128,4 @@ yudao: enable: false access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/resources/application.yaml b/yudao-module-member/yudao-module-member-biz/src/main/resources/application.yaml index 50bfa4e28..691b32f1b 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/resources/application.yaml +++ b/yudao-module-member/yudao-module-member-biz/src/main/resources/application.yaml @@ -101,9 +101,6 @@ yudao: base-package: ${yudao.info.base-package} captcha: enable: true # 验证码的开关,默认为 true; - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.member.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application-dev.yaml b/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application-dev.yaml index 738479353..899037940 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application-dev.yaml +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application-dev.yaml @@ -99,6 +99,4 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application-local.yaml b/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application-local.yaml index 928d8e705..ddec2c934 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application-local.yaml +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application-local.yaml @@ -120,6 +120,4 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application.yaml b/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application.yaml index 17678a342..509722ed5 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application.yaml +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/resources/application.yaml @@ -106,9 +106,6 @@ yudao: description: 提供管理员管理的所有功能 version: ${yudao.info.version} base-package: ${yudao.info.base-package} - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application-dev.yaml b/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application-dev.yaml index c8a07da65..50467063a 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application-dev.yaml +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application-dev.yaml @@ -99,8 +99,6 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false pay: order-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/order # 支付渠道的【支付】回调地址 refund-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/refund # 支付渠道的【退款】回调地址 diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application-local.yaml b/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application-local.yaml index db56479a3..62b4bb607 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application-local.yaml +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application-local.yaml @@ -125,8 +125,6 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false pay: order-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/order # 支付渠道的【支付】回调地址 refund-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/refund # 支付渠道的【退款】回调地址 diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application.yaml b/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application.yaml index 549908019..24eab6c32 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application.yaml +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/resources/application.yaml @@ -100,9 +100,6 @@ yudao: description: 提供管理员管理的所有功能 version: ${yudao.info.version} base-package: ${yudao.info.base-package} - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: diff --git a/yudao-module-report/yudao-module-report-biz/src/main/resources/application-local.yaml b/yudao-module-report/yudao-module-report-biz/src/main/resources/application-local.yaml index 134a08411..90e064f2a 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/resources/application-local.yaml +++ b/yudao-module-report/yudao-module-report-biz/src/main/resources/application-local.yaml @@ -121,6 +121,4 @@ yudao: - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 diff --git a/yudao-module-report/yudao-module-report-biz/src/main/resources/application.yaml b/yudao-module-report/yudao-module-report-biz/src/main/resources/application.yaml index 35771dbfa..f5e0022d7 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/resources/application.yaml +++ b/yudao-module-report/yudao-module-report-biz/src/main/resources/application.yaml @@ -100,9 +100,6 @@ yudao: description: 提供管理员管理的所有功能 version: ${yudao.info.version} base-package: ${yudao.info.base-package} - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.report.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/ErrorCodeApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/ErrorCodeApi.java deleted file mode 100644 index 7cd1b7217..000000000 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/ErrorCodeApi.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.iocoder.yudao.module.system.api.errorcode; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; -import cn.iocoder.yudao.module.system.enums.ApiConstants; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Parameters; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; - -import javax.validation.Valid; -import java.time.LocalDateTime; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@FeignClient(name = ApiConstants.NAME) // TODO 芋艿:fallbackFactory = -@Tag(name = "RPC 服务 - 错误码") -public interface ErrorCodeApi { - - String PREFIX = ApiConstants.PREFIX + "/error-code"; - - @PostMapping(PREFIX + "/auto-generate") - @Operation(summary = "自动创建错误码") - CommonResult autoGenerateErrorCodeList(@Valid @RequestBody List autoGenerateDTOs); - - @GetMapping(PREFIX + "/list") - @Operation(summary = "增量获得错误码数组", description = "如果 minUpdateTime 为空时,则获取所有错误码") - @Parameters({ - @Parameter(name = "applicationName", description = "应用名", example = "system-server", required = true), - @Parameter(name = "minUpdateTime", description = "最小更新时间") - }) - CommonResult> getErrorCodeList( - @RequestParam(value = "applicationName") String applicationName, - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @RequestParam(value = "minUpdateTime", required = false) LocalDateTime minUpdateTime); - -} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/dto/ErrorCodeAutoGenerateReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/dto/ErrorCodeAutoGenerateReqDTO.java deleted file mode 100644 index c209a516e..000000000 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/dto/ErrorCodeAutoGenerateReqDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.yudao.module.system.api.errorcode.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -@Schema(description = "RPC 服务 - 错误码自动生成 Request DTO") -@Data -public class ErrorCodeAutoGenerateReqDTO { - - @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") - @NotNull(message = "应用名不能为空") - private String applicationName; - - @Schema(description = "错误码编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - @NotNull(message = "错误码编码不能为空") - private Integer code; - - @Schema(description = "错误码错误提示", requiredMode = Schema.RequiredMode.REQUIRED, example = "业务不能为空") - @NotEmpty(message = "错误码错误提示不能为空") - private String message; - -} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/dto/ErrorCodeRespDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/dto/ErrorCodeRespDTO.java deleted file mode 100644 index e22dc3533..000000000 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/dto/ErrorCodeRespDTO.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.system.api.errorcode.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "RPC 服务 - 错误码 Response DTO") -@Data -public class ErrorCodeRespDTO { - - /** - * 错误码编码 - */ - @Schema(description = "错误码编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - private Integer code; - /** - * 错误码错误提示 - */ - @Schema(description = "错误码错误提示", requiredMode = Schema.RequiredMode.REQUIRED, example = "业务不能为空") - private String message; - /** - * 更新时间 - */ - @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime updateTime; - -} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/sensitiveword/SensitiveWordApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/sensitiveword/SensitiveWordApi.java deleted file mode 100644 index 35b6b3f5c..000000000 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/sensitiveword/SensitiveWordApi.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.module.system.api.sensitiveword; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.system.enums.ApiConstants; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Parameters; -import io.swagger.v3.oas.annotations.Operation; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import java.util.List; - -@FeignClient(name = ApiConstants.NAME) // TODO 芋艿:fallbackFacx`tory = -@Tag(name = "RPC 服务 - 敏感词") -public interface SensitiveWordApi { - - String PREFIX = ApiConstants.PREFIX + "/sensitive-word"; - - @GetMapping(PREFIX + "/validate-text") - @Operation(summary = "获得文本所包含的不合法的敏感词数组") - @Parameters({ - @Parameter(name = "text", description = "文本", example = "傻瓜", required = true), - @Parameter(name = "tags", description = "标签数组", example = "product,life", required = true) - }) - CommonResult> validateText(@RequestParam("text") String text, - @RequestParam("tags") List tags); - - @GetMapping(PREFIX + "/is-text-valid") - @Operation(summary = "判断文本是否包含敏感词") - @Parameters({ - @Parameter(name = "text", description = "文本", example = "傻瓜", required = true), - @Parameter(name = "tags", description = "标签数组", example = "product,life", required = true) - }) - CommonResult isTextValid(@RequestParam("text") String text, - @RequestParam("tags") List tags); - -} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 481c9be54..1b4c313c8 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -115,10 +115,6 @@ public interface ErrorCodeConstants { ErrorCode TENANT_PACKAGE_USED = new ErrorCode(1_002_016_001, "租户正在使用该套餐,请给租户重新设置套餐后再尝试删除"); ErrorCode TENANT_PACKAGE_DISABLE = new ErrorCode(1_002_016_002, "名字为【{}】的租户套餐已被禁用"); - // ========== 错误码模块 1-002-017-000 ========== - ErrorCode ERROR_CODE_NOT_EXISTS = new ErrorCode(1_002_017_000, "错误码不存在"); - ErrorCode ERROR_CODE_DUPLICATE = new ErrorCode(1_002_017_001, "已经存在编码为【{}】的错误码"); - // ========== 社交用户 1-002-018-000 ========== ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1_002_018_000, "社交授权失败,原因是:{}"); ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_001, "社交授权失败,找不到对应的用户"); @@ -127,10 +123,6 @@ public interface ErrorCodeConstants { ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_201, "社交客户端不存在"); ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_202, "社交客户端已存在配置"); - // ========== 系统敏感词 1-002-019-000 ========= - ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1_002_019_000, "系统敏感词在所有标签中都不存在"); - ErrorCode SENSITIVE_WORD_EXISTS = new ErrorCode(1_002_019_001, "系统敏感词已在标签中存在"); - // ========== OAuth2 客户端 1-002-020-000 ========= ErrorCode OAUTH2_CLIENT_NOT_EXISTS = new ErrorCode(1_002_020_000, "OAuth2 客户端不存在"); ErrorCode OAUTH2_CLIENT_EXISTS = new ErrorCode(1_002_020_001, "OAuth2 客户端编号已存在"); diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/errorcode/ErrorCodeTypeEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/errorcode/ErrorCodeTypeEnum.java deleted file mode 100644 index 97349e763..000000000 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/errorcode/ErrorCodeTypeEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.module.system.enums.errorcode; - -import cn.iocoder.yudao.framework.common.core.IntArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * 错误码的类型枚举 - * - * @author dylan - */ -@AllArgsConstructor -@Getter -public enum ErrorCodeTypeEnum implements IntArrayValuable { - - /** - * 自动生成 - */ - AUTO_GENERATION(1), - /** - * 手动编辑 - */ - MANUAL_OPERATION(2); - - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErrorCodeTypeEnum::getType).toArray(); - - /** - * 类型 - */ - private final Integer type; - - @Override - public int[] array() { - return ARRAYS; - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/pom.xml b/yudao-module-system/yudao-module-system-biz/pom.xml index 0282ea41f..9c0452332 100644 --- a/yudao-module-system/yudao-module-system-biz/pom.xml +++ b/yudao-module-system/yudao-module-system-biz/pom.xml @@ -164,6 +164,12 @@ com.xingyuv spring-boot-starter-captcha-plus + + + org.dromara.hutool + hutool-extra + + diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/ErrorCodeApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/ErrorCodeApiImpl.java deleted file mode 100644 index e57665b14..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/ErrorCodeApiImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.system.api.errorcode; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; -import cn.iocoder.yudao.module.system.service.errorcode.ErrorCodeService; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@RestController // 提供 RESTful API 接口,给 Feign 调用 -@Validated -public class ErrorCodeApiImpl implements ErrorCodeApi { - - @Resource - private ErrorCodeService errorCodeService; - - @Override - public CommonResult autoGenerateErrorCodeList(List autoGenerateDTOs) { - errorCodeService.autoGenerateErrorCodes(autoGenerateDTOs); - return success(true); - } - - @Override - public CommonResult> getErrorCodeList(String applicationName, LocalDateTime minUpdateTime) { - return success(errorCodeService.getErrorCodeList(applicationName, minUpdateTime)); - } -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/sensitiveword/SensitiveWordApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/sensitiveword/SensitiveWordApiImpl.java deleted file mode 100644 index 0e997a78c..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/sensitiveword/SensitiveWordApiImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.system.api.sensitiveword; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.system.service.sensitiveword.SensitiveWordService; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@RestController // 提供 RESTful API 接口,给 Feign 调用 -@Validated -public class SensitiveWordApiImpl implements SensitiveWordApi { - - @Resource - private SensitiveWordService sensitiveWordService; - - @Override - public CommonResult> validateText(String text, List tags) { - return success(sensitiveWordService.validateText(text, tags)); - } - - @Override - public CommonResult isTextValid(String text, List tags) { - return success(sensitiveWordService.isTextValid(text, tags)); - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.http b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.http deleted file mode 100644 index 06b872318..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.http +++ /dev/null @@ -1,13 +0,0 @@ -### 创建错误码 -POST {{baseUrl}}/inra/error-code/create -Authorization: Bearer {{token}} -Content-Type: application/json -tenant-id: {{adminTenentId}} - -{ - "code": 200, - "message": "成功", - "group": "test", - "type": 1 -} - diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.java deleted file mode 100644 index e87dd169c..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.java +++ /dev/null @@ -1,93 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.errorcode; - -import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeRespVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeSaveReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; -import cn.iocoder.yudao.module.system.service.errorcode.ErrorCodeService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import javax.validation.Valid; -import java.io.IOException; -import java.util.List; - -import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - 错误码") -@RestController -@RequestMapping("/system/error-code") -@Validated -public class ErrorCodeController { - - @Resource - private ErrorCodeService errorCodeService; - - @PostMapping("/create") - @Operation(summary = "创建错误码") - @PreAuthorize("@ss.hasPermission('system:error-code:create')") - public CommonResult createErrorCode(@Valid @RequestBody ErrorCodeSaveReqVO createReqVO) { - return success(errorCodeService.createErrorCode(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新错误码") - @PreAuthorize("@ss.hasPermission('system:error-code:update')") - public CommonResult updateErrorCode(@Valid @RequestBody ErrorCodeSaveReqVO updateReqVO) { - errorCodeService.updateErrorCode(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除错误码") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('system:error-code:delete')") - public CommonResult deleteErrorCode(@RequestParam("id") Long id) { - errorCodeService.deleteErrorCode(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得错误码") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('system:error-code:query')") - public CommonResult getErrorCode(@RequestParam("id") Long id) { - ErrorCodeDO errorCode = errorCodeService.getErrorCode(id); - return success(BeanUtils.toBean(errorCode, ErrorCodeRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得错误码分页") - @PreAuthorize("@ss.hasPermission('system:error-code:query')") - public CommonResult> getErrorCodePage(@Valid ErrorCodePageReqVO pageVO) { - PageResult pageResult = errorCodeService.getErrorCodePage(pageVO); - return success(BeanUtils.toBean(pageResult, ErrorCodeRespVO.class)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出错误码 Excel") - @PreAuthorize("@ss.hasPermission('system:error-code:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportErrorCodeExcel(@Valid ErrorCodePageReqVO exportReqVO, - HttpServletResponse response) throws IOException { - exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = errorCodeService.getErrorCodePage(exportReqVO).getList(); - // 导出 Excel - ExcelUtils.write(response, "错误码.xls", "数据", ErrorCodeRespVO.class, - BeanUtils.toBean(list, ErrorCodeRespVO.class)); - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodePageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodePageReqVO.java deleted file mode 100644 index ba565d94c..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodePageReqVO.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.errorcode.vo; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 错误码分页 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ErrorCodePageReqVO extends PageParam { - - @Schema(description = "错误码类型,参见 ErrorCodeTypeEnum 枚举类", example = "1") - private Integer type; - - @Schema(description = "应用名", example = "dashboard") - private String applicationName; - - @Schema(description = "错误码编码", example = "1234") - private Integer code; - - @Schema(description = "错误码错误提示", example = "帅气") - private String message; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "创建时间") - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java deleted file mode 100644 index 31f72bf93..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java +++ /dev/null @@ -1,47 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.errorcode.vo; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; -import com.alibaba.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 错误码 Response VO") -@Data -@ExcelIgnoreUnannotated -public class ErrorCodeRespVO { - - @Schema(description = "错误码编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @ExcelProperty("错误码编号") - private Long id; - - @Schema(description = "错误码类型,参见 ErrorCodeTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @ExcelProperty(value = "错误码类型", converter = DictConvert.class) - @DictFormat(DictTypeConstants.ERROR_CODE_TYPE) - private Integer type; - - @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") - @ExcelProperty("应用名") - private String applicationName; - - @Schema(description = "错误码编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1234") - @ExcelProperty("错误码编码") - private Integer code; - - @Schema(description = "错误码错误提示", requiredMode = Schema.RequiredMode.REQUIRED, example = "帅气") - @ExcelProperty("错误码错误提示") - private String message; - - @Schema(description = "备注", example = "哈哈哈") - @ExcelProperty("备注") - private String memo; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeSaveReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeSaveReqVO.java deleted file mode 100644 index d8b6b2125..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeSaveReqVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.errorcode.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 错误码创建/修改 Request VO") -@Data -public class ErrorCodeSaveReqVO { - - @Schema(description = "错误码编号", example = "1024") - private Long id; - - @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") - @NotNull(message = "应用名不能为空") - private String applicationName; - - @Schema(description = "错误码编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1234") - @NotNull(message = "错误码编码不能为空") - private Integer code; - - @Schema(description = "错误码错误提示", requiredMode = Schema.RequiredMode.REQUIRED, example = "帅气") - @NotNull(message = "错误码错误提示不能为空") - private String message; - - @Schema(description = "备注", example = "哈哈哈") - private String memo; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.http b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.http deleted file mode 100644 index cd97d2de5..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.http +++ /dev/null @@ -1,4 +0,0 @@ -### 请求 /system/sensitive-word/validate-text 接口 => 成功 -GET {{baseUrl}}/system/sensitive-word/validate-text?text=XXX&tags=短信&tags=蔬菜 -Authorization: Bearer {{token}} -tenant-id: {{adminTenentId}} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.java deleted file mode 100644 index 02e272ede..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.java +++ /dev/null @@ -1,108 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword; - -import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordRespVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; -import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; -import cn.iocoder.yudao.module.system.service.sensitiveword.SensitiveWordService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import javax.validation.Valid; -import java.io.IOException; -import java.util.List; -import java.util.Set; - -import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - 敏感词") -@RestController -@RequestMapping("/system/sensitive-word") -@Validated -public class SensitiveWordController { - - @Resource - private SensitiveWordService sensitiveWordService; - - @PostMapping("/create") - @Operation(summary = "创建敏感词") - @PreAuthorize("@ss.hasPermission('system:sensitive-word:create')") - public CommonResult createSensitiveWord(@Valid @RequestBody SensitiveWordSaveVO createReqVO) { - return success(sensitiveWordService.createSensitiveWord(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新敏感词") - @PreAuthorize("@ss.hasPermission('system:sensitive-word:update')") - public CommonResult updateSensitiveWord(@Valid @RequestBody SensitiveWordSaveVO updateReqVO) { - sensitiveWordService.updateSensitiveWord(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除敏感词") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('system:sensitive-word:delete')") - public CommonResult deleteSensitiveWord(@RequestParam("id") Long id) { - sensitiveWordService.deleteSensitiveWord(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得敏感词") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") - public CommonResult getSensitiveWord(@RequestParam("id") Long id) { - SensitiveWordDO sensitiveWord = sensitiveWordService.getSensitiveWord(id); - return success(BeanUtils.toBean(sensitiveWord, SensitiveWordRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得敏感词分页") - @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") - public CommonResult> getSensitiveWordPage(@Valid SensitiveWordPageReqVO pageVO) { - PageResult pageResult = sensitiveWordService.getSensitiveWordPage(pageVO); - return success(BeanUtils.toBean(pageResult, SensitiveWordRespVO.class)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出敏感词 Excel") - @PreAuthorize("@ss.hasPermission('system:sensitive-word:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportSensitiveWordExcel(@Valid SensitiveWordPageReqVO exportReqVO, - HttpServletResponse response) throws IOException { - exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = sensitiveWordService.getSensitiveWordPage(exportReqVO).getList(); - // 导出 Excel - ExcelUtils.write(response, "敏感词.xls", "数据", SensitiveWordRespVO.class, - BeanUtils.toBean(list, SensitiveWordRespVO.class)); - } - - @GetMapping("/get-tags") - @Operation(summary = "获取所有敏感词的标签数组") - @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") - public CommonResult> getSensitiveWordTagSet() { - return success(sensitiveWordService.getSensitiveWordTagSet()); - } - - @GetMapping("/validate-text") - @Operation(summary = "获得文本所包含的不合法的敏感词数组") - public CommonResult> validateText(@RequestParam("text") String text, - @RequestParam(value = "tags", required = false) List tags) { - return success(sensitiveWordService.validateText(text, tags)); - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordPageReqVO.java deleted file mode 100644 index 642773a55..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordPageReqVO.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 敏感词分页 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SensitiveWordPageReqVO extends PageParam { - - @Schema(description = "敏感词", example = "敏感词") - private String name; - - @Schema(description = "标签", example = "短信,评论") - private String tag; - - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", example = "1") - private Integer status; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "创建时间") - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordRespVO.java deleted file mode 100644 index 250a044a7..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordRespVO.java +++ /dev/null @@ -1,43 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.framework.excel.core.convert.JsonConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.List; - -@Schema(description = "管理后台 - 敏感词 Response VO") -@Data -public class SensitiveWordRespVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @ExcelProperty("编号") - private Long id; - - @Schema(description = "敏感词", requiredMode = Schema.RequiredMode.REQUIRED, example = "敏感词") - @ExcelProperty("敏感词") - private String name; - - @Schema(description = "标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "短信,评论") - @ExcelProperty(value = "标签", converter = JsonConvert.class) - private List tags; - - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @ExcelProperty(value = "状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.COMMON_STATUS) - private Integer status; - - @Schema(description = "描述", example = "污言秽语") - @ExcelProperty("描述") - private String description; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordSaveVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordSaveVO.java deleted file mode 100644 index c7b2fbd89..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordSaveVO.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotNull; -import java.util.List; - -@Schema(description = "管理后台 - 敏感词创建/修改 Request VO") -@Data -public class SensitiveWordSaveVO { - - @Schema(description = "编号", example = "1") - private Long id; - - @Schema(description = "敏感词", requiredMode = Schema.RequiredMode.REQUIRED, example = "敏感词") - @NotNull(message = "敏感词不能为空") - private String name; - - @Schema(description = "标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "短信,评论") - @NotNull(message = "标签不能为空") - private List tags; - - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "状态不能为空") - private Integer status; - - @Schema(description = "描述", example = "污言秽语") - private String description; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java deleted file mode 100644 index 5d20ac13d..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.mail; - -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.mail.MailAccount; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface MailAccountConvert { - - MailAccountConvert INSTANCE = Mappers.getMapper(MailAccountConvert.class); - - default MailAccount convert(MailAccountDO account, String nickname) { - String from = StrUtil.isNotEmpty(nickname) ? nickname + " <" + account.getMail() + ">" : account.getMail(); - return new MailAccount().setFrom(from).setAuth(true) - .setUser(account.getUsername()).setPass(account.getPassword()) - .setHost(account.getHost()).setPort(account.getPort()).setSslEnable(account.getSslEnable()); - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/errorcode/ErrorCodeDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/errorcode/ErrorCodeDO.java deleted file mode 100644 index 9ad563395..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/errorcode/ErrorCodeDO.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.iocoder.yudao.module.system.dal.dataobject.errorcode; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.system.enums.errorcode.ErrorCodeTypeEnum; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -/** - * 错误码表 - * - * @author 芋道源码 - */ -@TableName(value = "system_error_code") -@KeySequence("system_error_code_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ErrorCodeDO extends BaseDO { - - /** - * 错误码编号,自增 - */ - @TableId - private Long id; - /** - * 错误码类型 - * - * 枚举 {@link ErrorCodeTypeEnum} - */ - private Integer type; - /** - * 应用名 - */ - private String applicationName; - /** - * 错误码编码 - */ - private Integer code; - /** - * 错误码错误提示 - */ - private String message; - /** - * 错误码备注 - */ - private String memo; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/sensitiveword/SensitiveWordDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/sensitiveword/SensitiveWordDO.java deleted file mode 100644 index 37dc57968..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/sensitiveword/SensitiveWordDO.java +++ /dev/null @@ -1,58 +0,0 @@ -package cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.framework.mybatis.core.type.StringListTypeHandler; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -import java.util.List; - -/** - * 敏感词 DO - * - * @author 永不言败 - */ -@TableName(value = "system_sensitive_word", autoResultMap = true) -@KeySequence("system_sensitive_word_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class SensitiveWordDO extends BaseDO { - - /** - * 编号 - */ - @TableId - private Long id; - /** - * 敏感词 - */ - private String name; - /** - * 描述 - */ - private String description; - /** - * 标签数组 - * - * 用于实现不同的业务场景下,需要使用不同标签的敏感词。 - * 例如说,tag 有短信、论坛两种,敏感词 "推广" 在短信下是敏感词,在论坛下不是敏感词。 - * 此时,我们会存储一条敏感词记录,它的 name 为"推广",tag 为短信。 - */ - @TableField(typeHandler = StringListTypeHandler.class) - private List tags; - /** - * 状态 - * - * 枚举 {@link CommonStatusEnum} - */ - private Integer status; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java deleted file mode 100644 index 2e345e3ad..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.yudao.module.system.dal.mysql.errorcode; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; -import org.apache.ibatis.annotations.Mapper; - -import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; - -@Mapper -public interface ErrorCodeMapper extends BaseMapperX { - - default PageResult selectPage(ErrorCodePageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(ErrorCodeDO::getType, reqVO.getType()) - .likeIfPresent(ErrorCodeDO::getApplicationName, reqVO.getApplicationName()) - .eqIfPresent(ErrorCodeDO::getCode, reqVO.getCode()) - .likeIfPresent(ErrorCodeDO::getMessage, reqVO.getMessage()) - .betweenIfPresent(ErrorCodeDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(ErrorCodeDO::getCode)); - } - - default List selectListByCodes(Collection codes) { - return selectList(ErrorCodeDO::getCode, codes); - } - - default ErrorCodeDO selectByCode(Integer code) { - return selectOne(ErrorCodeDO::getCode, code); - } - - default List selectListByApplicationNameAndUpdateTimeGt(String applicationName, LocalDateTime minUpdateTime) { - return selectList(new LambdaQueryWrapperX().eq(ErrorCodeDO::getApplicationName, applicationName) - .gtIfPresent(ErrorCodeDO::getUpdateTime, minUpdateTime)); - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java deleted file mode 100644 index 229171145..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.system.dal.mysql.sensitiveword; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; - -import java.time.LocalDateTime; - -/** - * 敏感词 Mapper - * - * @author 永不言败 - */ -@Mapper -public interface SensitiveWordMapper extends BaseMapperX { - - default PageResult selectPage(SensitiveWordPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(SensitiveWordDO::getName, reqVO.getName()) - .likeIfPresent(SensitiveWordDO::getTags, reqVO.getTag()) - .eqIfPresent(SensitiveWordDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(SensitiveWordDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(SensitiveWordDO::getId)); - } - - default SensitiveWordDO selectByName(String name) { - return selectOne(SensitiveWordDO::getName, name); - } - - @Select("SELECT COUNT(*) FROM system_sensitive_word WHERE update_time > #{maxUpdateTime}") - Long selectCountByUpdateTimeGt(LocalDateTime maxTime); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeService.java deleted file mode 100644 index b3894582d..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeService.java +++ /dev/null @@ -1,77 +0,0 @@ -package cn.iocoder.yudao.module.system.service.errorcode; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeSaveReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; - -import javax.validation.Valid; -import java.time.LocalDateTime; -import java.util.List; - -/** - * 错误码 Service 接口 - * - * @author 芋道源码 - */ -public interface ErrorCodeService { - - /** - * 自动创建错误码 - * - * @param autoGenerateDTOs 错误码信息 - */ - void autoGenerateErrorCodes(@Valid List autoGenerateDTOs); - - /** - * 增量获得错误码数组 - * - * 如果 minUpdateTime 为空时,则获取所有错误码 - * - * @param applicationName 应用名 - * @param minUpdateTime 最小更新时间 - * @return 错误码数组 - */ - List getErrorCodeList(String applicationName, LocalDateTime minUpdateTime); - - /** - * 创建错误码 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createErrorCode(@Valid ErrorCodeSaveReqVO createReqVO); - - /** - * 更新错误码 - * - * @param updateReqVO 更新信息 - */ - void updateErrorCode(@Valid ErrorCodeSaveReqVO updateReqVO); - - /** - * 删除错误码 - * - * @param id 编号 - */ - void deleteErrorCode(Long id); - - /** - * 获得错误码 - * - * @param id 编号 - * @return 错误码 - */ - ErrorCodeDO getErrorCode(Long id); - - /** - * 获得错误码分页 - * - * @param pageReqVO 分页查询 - * @return 错误码分页 - */ - PageResult getErrorCodePage(ErrorCodePageReqVO pageReqVO); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java deleted file mode 100644 index 45dfb7c7d..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java +++ /dev/null @@ -1,167 +0,0 @@ -package cn.iocoder.yudao.module.system.service.errorcode; - -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeSaveReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; -import cn.iocoder.yudao.module.system.dal.mysql.errorcode.ErrorCodeMapper; -import cn.iocoder.yudao.module.system.enums.errorcode.ErrorCodeTypeEnum; -import com.google.common.annotations.VisibleForTesting; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.ERROR_CODE_DUPLICATE; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.ERROR_CODE_NOT_EXISTS; - -/** - * 错误码 Service 实现类 - * - * @author dlyan - */ -@Service -@Validated -@Slf4j -public class ErrorCodeServiceImpl implements ErrorCodeService { - - @Resource - private ErrorCodeMapper errorCodeMapper; - - @Override - public Long createErrorCode(ErrorCodeSaveReqVO createReqVO) { - // 校验 code 重复 - validateCodeDuplicate(createReqVO.getCode(), null); - - // 插入 - ErrorCodeDO errorCode = BeanUtils.toBean(createReqVO, ErrorCodeDO.class) - .setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()); - errorCodeMapper.insert(errorCode); - // 返回 - return errorCode.getId(); - } - - @Override - public void updateErrorCode(ErrorCodeSaveReqVO updateReqVO) { - // 校验存在 - validateErrorCodeExists(updateReqVO.getId()); - // 校验 code 重复 - validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId()); - - // 更新 - ErrorCodeDO updateObj = BeanUtils.toBean(updateReqVO, ErrorCodeDO.class) - .setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()); - errorCodeMapper.updateById(updateObj); - } - - @Override - public void deleteErrorCode(Long id) { - // 校验存在 - validateErrorCodeExists(id); - // 删除 - errorCodeMapper.deleteById(id); - } - - /** - * 校验错误码的唯一字段是否重复 - * - * 是否存在相同编码的错误码 - * - * @param code 错误码编码 - * @param id 错误码编号 - */ - @VisibleForTesting - public void validateCodeDuplicate(Integer code, Long id) { - ErrorCodeDO errorCodeDO = errorCodeMapper.selectByCode(code); - if (errorCodeDO == null) { - return; - } - // 如果 id 为空,说明不用比较是否为相同 id 的错误码 - if (id == null) { - throw exception(ERROR_CODE_DUPLICATE); - } - if (!errorCodeDO.getId().equals(id)) { - throw exception(ERROR_CODE_DUPLICATE); - } - } - - @VisibleForTesting - void validateErrorCodeExists(Long id) { - if (errorCodeMapper.selectById(id) == null) { - throw exception(ERROR_CODE_NOT_EXISTS); - } - } - - @Override - public ErrorCodeDO getErrorCode(Long id) { - return errorCodeMapper.selectById(id); - } - - @Override - public PageResult getErrorCodePage(ErrorCodePageReqVO pageReqVO) { - return errorCodeMapper.selectPage(pageReqVO); - } - - @Override - @Transactional - public void autoGenerateErrorCodes(List autoGenerateDTOs) { - if (CollUtil.isEmpty(autoGenerateDTOs)) { - return; - } - // 获得错误码 - List errorCodeDOs = errorCodeMapper.selectListByCodes( - convertSet(autoGenerateDTOs, ErrorCodeAutoGenerateReqDTO::getCode)); - Map errorCodeDOMap = convertMap(errorCodeDOs, ErrorCodeDO::getCode); - - // 遍历 autoGenerateBOs 数组,逐个插入或更新。考虑到每次量级不大,就不走批量了 - autoGenerateDTOs.forEach(autoGenerateDTO -> { - ErrorCodeDO errorCode = errorCodeDOMap.get(autoGenerateDTO.getCode()); - // 不存在,则进行新增 - if (errorCode == null) { - errorCode = BeanUtils.toBean(autoGenerateDTO, ErrorCodeDO.class) - .setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); - errorCodeMapper.insert(errorCode); - return; - } - // 存在,则进行更新。更新有三个前置条件: - // 条件 1. 只更新自动生成的错误码,即 Type 为 ErrorCodeTypeEnum.AUTO_GENERATION - if (!ErrorCodeTypeEnum.AUTO_GENERATION.getType().equals(errorCode.getType())) { - return; - } - // 条件 2. 分组 applicationName 必须匹配,避免存在错误码冲突的情况 - if (!autoGenerateDTO.getApplicationName().equals(errorCode.getApplicationName())) { - log.error("[autoGenerateErrorCodes][自动创建({}/{}) 错误码失败,数据库中已经存在({}/{})]", - autoGenerateDTO.getCode(), autoGenerateDTO.getApplicationName(), - errorCode.getCode(), errorCode.getApplicationName()); - return; - } - // 条件 3. 错误提示语存在差异 - if (autoGenerateDTO.getMessage().equals(errorCode.getMessage())) { - return; - } - // 最终匹配,进行更新 - errorCodeMapper.updateById(new ErrorCodeDO().setId(errorCode.getId()).setMessage(autoGenerateDTO.getMessage())); - }); - } - - @Override - public List getErrorCodeList(String applicationName, LocalDateTime minUpdateTime) { - List list = errorCodeMapper.selectListByApplicationNameAndUpdateTimeGt( - applicationName, minUpdateTime); - return BeanUtils.toBean(list, ErrorCodeRespDTO.class); - } - -} - diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImpl.java index aa93f101a..178a64aec 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImpl.java @@ -1,11 +1,8 @@ package cn.iocoder.yudao.module.system.service.mail; import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.mail.MailAccount; -import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; -import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; @@ -14,11 +11,12 @@ import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; import cn.iocoder.yudao.module.system.service.member.MemberService; import cn.iocoder.yudao.module.system.service.user.AdminUserService; import com.google.common.annotations.VisibleForTesting; +import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.dromara.hutool.extra.mail.*; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import javax.annotation.Resource; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -105,11 +103,11 @@ public class MailSendServiceImpl implements MailSendService { public void doSendMail(MailSendMessage message) { // 1. 创建发送账号 MailAccountDO account = validateMailAccount(message.getAccountId()); - MailAccount mailAccount = MailAccountConvert.INSTANCE.convert(account, message.getNickname()); + MailAccount mailAccount = buildMailAccount(account, message.getNickname()); // 2. 发送邮件 try { String messageId = MailUtil.send(mailAccount, message.getMail(), - message.getTitle(), message.getContent(),true); + message.getTitle(), message.getContent(), true); // 3. 更新结果(成功) mailLogService.updateMailSendResult(message.getLogId(), messageId, null); } catch (Exception e) { @@ -118,6 +116,13 @@ public class MailSendServiceImpl implements MailSendService { } } + private MailAccount buildMailAccount(MailAccountDO account, String nickname) { + String from = StrUtil.isNotEmpty(nickname) ? nickname + " <" + account.getMail() + ">" : account.getMail(); + return new MailAccount().setFrom(from).setAuth(true) + .setUser(account.getUsername()).setPass(account.getPassword().toCharArray()) + .setHost(account.getHost()).setPort(account.getPort()).setSslEnable(account.getSslEnable()); + } + @VisibleForTesting MailTemplateDO validateMailTemplate(String templateCode) { // 获得邮件模板。考虑到效率,从缓存中获取 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordService.java deleted file mode 100644 index 4f0363274..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordService.java +++ /dev/null @@ -1,89 +0,0 @@ -package cn.iocoder.yudao.module.system.service.sensitiveword; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; -import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; - -import javax.validation.Valid; -import java.util.List; -import java.util.Set; - -/** - * 敏感词 Service 接口 - * - * @author 永不言败 - */ -public interface SensitiveWordService { - - /** - * 创建敏感词 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createSensitiveWord(@Valid SensitiveWordSaveVO createReqVO); - - /** - * 更新敏感词 - * - * @param updateReqVO 更新信息 - */ - void updateSensitiveWord(@Valid SensitiveWordSaveVO updateReqVO); - - /** - * 删除敏感词 - * - * @param id 编号 - */ - void deleteSensitiveWord(Long id); - - /** - * 获得敏感词 - * - * @param id 编号 - * @return 敏感词 - */ - SensitiveWordDO getSensitiveWord(Long id); - - /** - * 获得敏感词列表 - * - * @return 敏感词列表 - */ - List getSensitiveWordList(); - - /** - * 获得敏感词分页 - * - * @param pageReqVO 分页查询 - * @return 敏感词分页 - */ - PageResult getSensitiveWordPage(SensitiveWordPageReqVO pageReqVO); - - /** - * 获得所有敏感词的标签数组 - * - * @return 标签数组 - */ - Set getSensitiveWordTagSet(); - - /** - * 获得文本所包含的不合法的敏感词数组 - * - * @param text 文本 - * @param tags 标签数组 - * @return 不合法的敏感词数组 - */ - List validateText(String text, List tags); - - /** - * 判断文本是否包含敏感词 - * - * @param text 文本 - * @param tags 标签数组 - * @return 是否包含敏感词 - */ - boolean isTextValid(String text, List tags); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java deleted file mode 100644 index 08ee30958..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java +++ /dev/null @@ -1,262 +0,0 @@ -package cn.iocoder.yudao.module.system.service.sensitiveword; - -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; -import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; -import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper; -import cn.iocoder.yudao.module.system.util.collection.SimpleTrie; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; -import org.springframework.validation.annotation.Validated; - -import javax.annotation.PostConstruct; -import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.*; -import java.util.concurrent.TimeUnit; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMaxValue; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_WORD_EXISTS; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_WORD_NOT_EXISTS; - -/** - * 敏感词 Service 实现类 - * - * @author 永不言败 - */ -@Service -@Slf4j -@Validated -public class SensitiveWordServiceImpl implements SensitiveWordService { - - /** - * 是否开启敏感词功能 - */ - public static Boolean ENABLED = false; - - /** - * 敏感词列表缓存 - */ - @Getter - private volatile List sensitiveWordCache = Collections.emptyList(); - /** - * 敏感词标签缓存 - * key:敏感词编号 {@link SensitiveWordDO#getId()} - *

- * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 - */ - @Getter - private volatile Set sensitiveWordTagsCache = Collections.emptySet(); - - @Resource - private SensitiveWordMapper sensitiveWordMapper; - - /** - * 默认的敏感词的字典树,包含所有敏感词 - */ - @Getter - private volatile SimpleTrie defaultSensitiveWordTrie = new SimpleTrie(Collections.emptySet()); - /** - * 标签与敏感词的字段数的映射 - */ - @Getter - private volatile Map tagSensitiveWordTries = Collections.emptyMap(); - - /** - * 初始化缓存 - */ - @PostConstruct - public void initLocalCache() { - if (!ENABLED) { - return; - } - - // 第一步:查询数据 - List sensitiveWords = sensitiveWordMapper.selectList(); - log.info("[initLocalCache][缓存敏感词,数量为:{}]", sensitiveWords.size()); - - // 第二步:构建缓存 - // 写入 sensitiveWordTagsCache 缓存 - Set tags = new HashSet<>(); - sensitiveWords.forEach(word -> tags.addAll(word.getTags())); - sensitiveWordTagsCache = tags; - sensitiveWordCache = sensitiveWords; - // 写入 defaultSensitiveWordTrie、tagSensitiveWordTries 缓存 - initSensitiveWordTrie(sensitiveWords); - } - - private void initSensitiveWordTrie(List wordDOs) { - // 过滤禁用的敏感词 - wordDOs = filterList(wordDOs, word -> word.getStatus().equals(CommonStatusEnum.ENABLE.getStatus())); - - // 初始化默认的 defaultSensitiveWordTrie - this.defaultSensitiveWordTrie = new SimpleTrie(CollectionUtils.convertList(wordDOs, SensitiveWordDO::getName)); - - // 初始化 tagSensitiveWordTries - Multimap tagWords = HashMultimap.create(); - for (SensitiveWordDO word : wordDOs) { - if (CollUtil.isEmpty(word.getTags())) { - continue; - } - word.getTags().forEach(tag -> tagWords.put(tag, word.getName())); - } - // 添加到 tagSensitiveWordTries 中 - Map tagSensitiveWordTries = new HashMap<>(); - tagWords.asMap().forEach((tag, words) -> tagSensitiveWordTries.put(tag, new SimpleTrie(words))); - this.tagSensitiveWordTries = tagSensitiveWordTries; - } - - /** - * 通过定时任务轮询,刷新缓存 - * - * 目的:多节点部署时,通过轮询”通知“所有节点,进行刷新 - */ - @Scheduled(initialDelay = 60, fixedRate = 60, timeUnit = TimeUnit.SECONDS) - public void refreshLocalCache() { - // 情况一:如果缓存里没有数据,则直接刷新缓存 - if (CollUtil.isEmpty(sensitiveWordCache)) { - initLocalCache(); - return; - } - - // 情况二,如果缓存里数据,则通过 updateTime 判断是否有数据变更,有变更则刷新缓存 - LocalDateTime maxTime = getMaxValue(sensitiveWordCache, SensitiveWordDO::getUpdateTime); - if (sensitiveWordMapper.selectCountByUpdateTimeGt(maxTime) > 0) { - initLocalCache(); - } - } - - @Override - public Long createSensitiveWord(SensitiveWordSaveVO createReqVO) { - // 校验唯一性 - validateSensitiveWordNameUnique(null, createReqVO.getName()); - - // 插入 - SensitiveWordDO sensitiveWord = BeanUtils.toBean(createReqVO, SensitiveWordDO.class); - sensitiveWordMapper.insert(sensitiveWord); - - // 刷新缓存 - initLocalCache(); - return sensitiveWord.getId(); - } - - @Override - public void updateSensitiveWord(SensitiveWordSaveVO updateReqVO) { - // 校验唯一性 - validateSensitiveWordExists(updateReqVO.getId()); - validateSensitiveWordNameUnique(updateReqVO.getId(), updateReqVO.getName()); - - // 更新 - SensitiveWordDO updateObj = BeanUtils.toBean(updateReqVO, SensitiveWordDO.class); - sensitiveWordMapper.updateById(updateObj); - - // 刷新缓存 - initLocalCache(); - } - - @Override - public void deleteSensitiveWord(Long id) { - // 校验存在 - validateSensitiveWordExists(id); - // 删除 - sensitiveWordMapper.deleteById(id); - - // 刷新缓存 - initLocalCache(); - } - - private void validateSensitiveWordNameUnique(Long id, String name) { - SensitiveWordDO word = sensitiveWordMapper.selectByName(name); - if (word == null) { - return; - } - // 如果 id 为空,说明不用比较是否为相同 id 的敏感词 - if (id == null) { - throw exception(SENSITIVE_WORD_EXISTS); - } - if (!word.getId().equals(id)) { - throw exception(SENSITIVE_WORD_EXISTS); - } - } - - private void validateSensitiveWordExists(Long id) { - if (sensitiveWordMapper.selectById(id) == null) { - throw exception(SENSITIVE_WORD_NOT_EXISTS); - } - } - - @Override - public SensitiveWordDO getSensitiveWord(Long id) { - return sensitiveWordMapper.selectById(id); - } - - @Override - public List getSensitiveWordList() { - return sensitiveWordMapper.selectList(); - } - - @Override - public PageResult getSensitiveWordPage(SensitiveWordPageReqVO pageReqVO) { - return sensitiveWordMapper.selectPage(pageReqVO); - } - - @Override - public Set getSensitiveWordTagSet() { - return sensitiveWordTagsCache; - } - - @Override - public List validateText(String text, List tags) { - Assert.isTrue(ENABLED, "敏感词功能未开启,请将 ENABLED 设置为 true"); - - // 无标签时,默认所有 - if (CollUtil.isEmpty(tags)) { - return defaultSensitiveWordTrie.validate(text); - } - // 有标签的情况 - Set result = new HashSet<>(); - tags.forEach(tag -> { - SimpleTrie trie = tagSensitiveWordTries.get(tag); - if (trie == null) { - return; - } - result.addAll(trie.validate(text)); - }); - return new ArrayList<>(result); - } - - @Override - public boolean isTextValid(String text, List tags) { - Assert.isTrue(ENABLED, "敏感词功能未开启,请将 ENABLED 设置为 true"); - - // 无标签时,默认所有 - if (CollUtil.isEmpty(tags)) { - return defaultSensitiveWordTrie.isValid(text); - } - // 有标签的情况 - for (String tag : tags) { - SimpleTrie trie = tagSensitiveWordTries.get(tag); - if (trie == null) { - continue; - } - // 如果有一个标签不合法,则返回 false 不合法 - if (!trie.isValid(text)) { - return false; - } - } - return true; - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/util/collection/SimpleTrie.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/util/collection/SimpleTrie.java deleted file mode 100644 index 8c3e4bc0f..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/util/collection/SimpleTrie.java +++ /dev/null @@ -1,152 +0,0 @@ -package cn.iocoder.yudao.module.system.util.collection; - -import cn.hutool.core.collection.CollUtil; - -import java.util.*; - -/** - * 基于前缀树,实现敏感词的校验 - *

- * 相比 Apache Common 提供的 PatriciaTrie 来说,性能可能会更加好一些。 - * - * @author 芋道源码 - */ -@SuppressWarnings("unchecked") -public class SimpleTrie { - - /** - * 一个敏感词结束后对应的 key - */ - private static final Character CHARACTER_END = '\0'; - - /** - * 使用敏感词,构建的前缀树 - */ - private final Map children; - - /** - * 基于字符串,构建前缀树 - * - * @param strs 字符串数组 - */ - public SimpleTrie(Collection strs) { - // 排序,优先使用较短的前缀 - strs = CollUtil.sort(strs, String::compareTo); - // 构建树 - children = new HashMap<>(); - for (String str : strs) { - Map child = children; - // 遍历每个字符 - for (Character c : str.toCharArray()) { - // 如果已经到达结束,就没必要在添加更长的敏感词。 - // 例如说,有两个敏感词是:吃饭啊、吃饭。输入一句话是 “我要吃饭啊”,则只要匹配到 “吃饭” 这个敏感词即可。 - if (child.containsKey(CHARACTER_END)) { - break; - } - if (!child.containsKey(c)) { - child.put(c, new HashMap<>()); - } - child = (Map) child.get(c); - } - // 结束 - child.put(CHARACTER_END, null); - } - } - - /** - * 验证文本是否合法,即不包含敏感词 - * - * @param text 文本 - * @return 是否 true-合法 false-不合法 - */ - public boolean isValid(String text) { - // 遍历 text,使用每一个 [i, n) 段的字符串,使用 children 前缀树匹配,是否包含敏感词 - for (int i = 0; i < text.length(); i++) { - Map child = (Map) children.get(text.charAt(i)); - if (child == null) { - continue; - } - boolean ok = recursion(text, i + 1, child); - if (!ok) { - return false; - } - } - return true; - } - - /** - * 验证文本从指定位置开始,是否不包含某个敏感词 - * - * @param text 文本 - * @param index 开始位置 - * @param child 节点(当前遍历到的) - * @return 是否不包含 true-不包含 false-包含 - */ - private boolean recursion(String text, int index, Map child) { - if (child.containsKey(CHARACTER_END)) { - return false; - } - if (index == text.length()) { - return true; - } - child = (Map) child.get(text.charAt(index)); - return child == null || !child.containsKey(CHARACTER_END) && recursion(text, ++index, child); - } - - /** - * 获得文本所包含的不合法的敏感词 - * - * 注意,才当即最短匹配原则。例如说:当敏感词存在 “煞笔”,“煞笔二货 ”时,只会返回 “煞笔”。 - * - * @param text 文本 - * @return 匹配的敏感词 - */ - public List validate(String text) { - Set results = new HashSet<>(); - for (int i = 0; i < text.length(); i++) { - Character c = text.charAt(i); - Map child = (Map) children.get(c); - if (child == null) { - continue; - } - StringBuilder result = new StringBuilder().append(c); - boolean ok = recursionWithResult(text, i + 1, child, result); - if (!ok) { - results.add(result.toString()); - } - } - return new ArrayList<>(results); - } - - /** - * 返回文本从 index 开始的敏感词,并使用 StringBuilder 参数进行返回 - * - * 逻辑和 {@link #recursion(String, int, Map)} 是一致,只是多了 result 返回结果 - * - * @param text 文本 - * @param index 开始未知 - * @param child 节点(当前遍历到的) - * @param result 返回敏感词 - * @return 是否有敏感词 - */ - @SuppressWarnings("unchecked") - private static boolean recursionWithResult(String text, int index, Map child, StringBuilder result) { - if (child.containsKey(CHARACTER_END)) { - return false; - } - if (index == text.length()) { - return true; - } - Character c = text.charAt(index); - child = (Map) child.get(c); - if (child == null) { - return true; - } - if (child.containsKey(CHARACTER_END)) { - result.append(c); - return false; - } - return recursionWithResult(text, ++index, child, result.append(c)); - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml index 4f3908c6c..cb10d711e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml +++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml @@ -175,8 +175,6 @@ yudao: refund-notify-url: http://niubi.natapp1.cc/api/pay/refund/notify access-log: # 访问日志的配置项 enable: false - error-code: # 错误码相关配置项 - enable: false demo: false # 关闭演示模式 justauth: diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml index 0e8545b90..fbb52c6ee 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml +++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml @@ -147,9 +147,6 @@ yudao: base-package: ${yudao.info.base-package} captcha: enable: true # 验证码的开关,默认为 true; - error-code: # 错误码相关配置项 - constants-class-list: - - cn.iocoder.yudao.module.system.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true ignore-urls: @@ -161,7 +158,6 @@ yudao: - /admin-api/system/sms/callback/* # 短信回调接口,无法带上租户编号 - /rpc-api/system/tenant/valid # 防止递归。避免调用 /rpc-api/system/tenant/valid 接口时,又去触发 /rpc-api/system/tenant/valid 去校验 - /rpc-api/system/tenant/id-list # 获得租户列表的时候,无需传递租户编号 - - /rpc-api/system/error-code/* # 错误码的自动创建与下载的接口,无法带上租户编号 - /rpc-api/system/oauth2/token/check # 访问令牌校验时,无需传递租户编号;主要解决上传文件的场景,前端不会传递 tenant-id! ignore-tables: - system_tenant diff --git a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/job/SchedulerManagerTest.java b/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/job/SchedulerManagerTest.java deleted file mode 100644 index 2d1d6f4c8..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/job/SchedulerManagerTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.iocoder.yudao.module.system.job; - -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.quartz.core.scheduler.SchedulerManager; -import cn.iocoder.yudao.module.system.job.auth.UserSessionTimeoutJob; -import cn.iocoder.yudao.module.system.test.BaseDbUnitTest; -import org.junit.jupiter.api.Test; -import org.quartz.SchedulerException; - -import javax.annotation.Resource; - -public class SchedulerManagerTest extends BaseDbUnitTest { - - @Resource - private SchedulerManager schedulerManager; - - @Test - public void testAddJob() throws SchedulerException { - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName()); - schedulerManager.addJob(1L, jobHandlerName, "test", "0/10 * * * * ? *", 0, 0); - } - - @Test - public void testUpdateJob() throws SchedulerException { - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName()); - schedulerManager.updateJob(jobHandlerName, "hahaha", "0/20 * * * * ? *", 0, 0); - } - - @Test - public void testDeleteJob() throws SchedulerException { - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName()); - schedulerManager.deleteJob(jobHandlerName); - } - - @Test - public void testPauseJob() throws SchedulerException { - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName()); - schedulerManager.pauseJob(jobHandlerName); - } - - @Test - public void testResumeJob() throws SchedulerException { - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName()); - schedulerManager.resumeJob(jobHandlerName); - } - - @Test - public void testTriggerJob() throws SchedulerException { - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName()); - schedulerManager.triggerJob(1L, jobHandlerName, "niubi!!!"); - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/mq/RedisStreamTest.java b/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/mq/RedisStreamTest.java deleted file mode 100644 index c94316a81..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/mq/RedisStreamTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package cn.iocoder.yudao.module.system.mq; - -import cn.hutool.core.thread.ThreadUtil; -import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate; -import cn.iocoder.yudao.module.system.mq.consumer.mail.MailSendConsumer; -import cn.iocoder.yudao.module.system.mq.consumer.sms.SmsSendConsumer; -import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; -import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; -import cn.iocoder.yudao.module.system.test.BaseRedisIntegrationTest; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.Import; -import org.springframework.data.redis.core.RedisTemplate; - -import javax.annotation.Resource; -import java.util.concurrent.TimeUnit; - -public class RedisStreamTest { - - @Import({SmsSendConsumer.class, MailSendConsumer.class}) - @Disabled - public static class ConsumerTest extends BaseRedisIntegrationTest { - - @Test - public void testConsumer() { - ThreadUtil.sleep(1, TimeUnit.DAYS); - } - - } - - @Disabled - public static class ProducerTest extends BaseRedisIntegrationTest { - - @Resource - private RedisMQTemplate redisMQTemplate; - - @Resource - private RedisTemplate redisTemplate; - - @Test - public void testProducer01() { - for (int i = 0; i < 100; i++) { - // 创建消息 - SmsSendMessage message = new SmsSendMessage(); - message.setMobile("15601691300").setApiTemplateId("test:" + i); - // 发送消息 - redisMQTemplate.send(message); - } - } - - @Test - public void testProducer02() { - // 创建消息 - MailSendMessage message = new MailSendMessage(); - message.setAddress("fangfang@mihayou.com").setTemplateCode("test"); - // 发送消息 - redisMQTemplate.send(message); - } - - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/service/package-info.java b/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/service/package-info.java deleted file mode 100644 index 7b475e53e..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/service/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 占位 - */ -package cn.iocoder.yudao.module.system.service; diff --git a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/service/sms/SmsServiceIntegrationTest.java b/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/service/sms/SmsServiceIntegrationTest.java deleted file mode 100644 index a8e57ccb5..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/service/sms/SmsServiceIntegrationTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.iocoder.yudao.module.system.service.sms; - -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.thread.ThreadUtil; -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; -import cn.iocoder.yudao.framework.sms.config.YudaoSmsAutoConfiguration; -import cn.iocoder.yudao.module.system.test.BaseDbAndRedisIntegrationTest; -import cn.iocoder.yudao.module.system.mq.consumer.sms.SmsSendConsumer; -import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer; -import cn.iocoder.yudao.module.system.service.user.AdminUserService; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; - -import javax.annotation.Resource; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -// TODO @芋艿:需要迁移 -@Import({YudaoSmsAutoConfiguration.class, - SmsChannelServiceImpl.class, SmsSendServiceImpl.class, SmsTemplateServiceImpl.class, SmsLogServiceImpl.class, - SmsProducer.class, SmsSendConsumer.class}) -public class SmsServiceIntegrationTest extends BaseDbAndRedisIntegrationTest { - - @Resource - private SmsSendServiceImpl smsService; - @Resource - private SmsChannelServiceImpl smsChannelService; - - @MockBean - private AdminUserService userService; - - @Test - public void testSendSingleSms_aliyunSuccess() { - // 参数准备 - String mobile = "15601691399"; - Long userId = 1L; - Integer userType = UserTypeEnum.ADMIN.getValue(); - String templateCode = "test_02"; - Map templateParams = MapUtil.builder() - .put("code", "1234").build(); - // 调用 - smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); - - // 等待 MQ 消费 - ThreadUtil.sleep(1, TimeUnit.HOURS); - } - -// @Test -// public void testDoSendSms() { -// // 等待 MQ 消费 -// ThreadUtil.sleep(1, TimeUnit.HOURS); -// } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/test/BaseDbAndRedisIntegrationTest.java b/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/test/BaseDbAndRedisIntegrationTest.java deleted file mode 100644 index 5b9b21ffd..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/test/BaseDbAndRedisIntegrationTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.system.test; - -import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration; -import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration; -import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; -import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration; -import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; -import org.redisson.spring.starter.RedissonAutoConfiguration; -import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.ActiveProfiles; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbAndRedisIntegrationTest.Application.class) -@ActiveProfiles("integration-test") // 设置使用 application-integration-test 配置文件 -public class BaseDbAndRedisIntegrationTest { - - @Import({ - // DB 配置类 - DynamicDataSourceAutoConfiguration.class, // Dynamic Datasource 配置类 - YudaoDataSourceAutoConfiguration.class, // 自己的 DB 配置类 - DataSourceAutoConfiguration.class, // Spring DB 自动配置类 - DataSourceTransactionManagerAutoConfiguration.class, // Spring 事务自动配置类 - // MyBatis 配置类 - YudaoMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类 - MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类 - - // Redis 配置类 - RedisAutoConfiguration.class, // Spring Redis 自动配置类 - YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类 - RedissonAutoConfiguration.class, // Redisson 自动高配置类 - }) - public static class Application { - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/test/BaseRedisIntegrationTest.java b/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/test/BaseRedisIntegrationTest.java deleted file mode 100644 index f48b2891d..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/test/BaseRedisIntegrationTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.module.system.test; - -import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; -import org.redisson.spring.starter.RedissonAutoConfiguration; -import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.ActiveProfiles; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseRedisIntegrationTest.Application.class) -@ActiveProfiles("integration-test") // 设置使用 application-integration-test 配置文件 -public class BaseRedisIntegrationTest { - - @Import({ - // Redis 配置类 - RedisAutoConfiguration.class, // Spring Redis 自动配置类 - YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类 - RedissonAutoConfiguration.class, // Redisson 自动高配置类 - }) - public static class Application { - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/test-integration/resources/application-integration-test.yaml b/yudao-module-system/yudao-module-system-biz/src/test-integration/resources/application-integration-test.yaml deleted file mode 100644 index 6b2fd822b..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/test-integration/resources/application-integration-test.yaml +++ /dev/null @@ -1,98 +0,0 @@ -spring: - main: - lazy-initialization: true # 开启懒加载,加快速度 - banner-mode: off # 单元测试,禁用 Banner - ---- #################### 数据库相关配置 #################### - -spring: - # 数据源配置项 - autoconfigure: - exclude: - - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源 - datasource: - druid: # Druid 【监控】相关的全局配置 - web-stat-filter: - enabled: true - stat-view-servlet: - enabled: true - allow: # 设置白名单,不填则允许所有访问 - url-pattern: /druid/* - login-username: # 控制台管理用户名和密码 - login-password: - filter: - stat: - enabled: true - log-slow-sql: true # 慢 SQL 记录 - slow-sql-millis: 100 - merge-sql: true - wall: - config: - multi-statement-allow: true - dynamic: # 多数据源配置 - druid: # Druid 【连接池】相关的全局配置 - initial-size: 5 # 初始连接数 - min-idle: 10 # 最小连接池数量 - max-active: 20 # 最大连接池数量 - max-wait: 600000 # 配置获取连接等待超时的时间,单位:毫秒 - time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位:毫秒 - min-evictable-idle-time-millis: 300000 # 配置一个连接在池中最小生存的时间,单位:毫秒 - max-evictable-idle-time-millis: 900000 # 配置一个连接在池中最大生存的时间,单位:毫秒 - validation-query: SELECT 1 FROM DUAL # 配置检测连接是否有效 - test-while-idle: true - test-on-borrow: false - test-on-return: false - primary: master - datasource: - master: - name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT - driver-class-name: com.mysql.jdbc.Driver - username: root - password: 123456 - slave: # 模拟从库,可根据自己需要修改 - name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT - driver-class-name: com.mysql.jdbc.Driver - username: root - password: 123456 - - # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 - redis: - host: 127.0.0.1 # 地址 - port: 6379 # 端口 - database: 0 # 数据库索引 - -mybatis: - lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试 - ---- #################### 定时任务相关配置 #################### - ---- #################### 配置中心相关配置 #################### - ---- #################### 服务保障相关配置 #################### - -# Lock4j 配置项(单元测试,禁用 Lock4j) - ---- #################### 监控相关配置 #################### - ---- #################### 芋道相关配置 #################### - -# 芋道配置项,设置当前项目所有自定义的配置 -yudao: - security: - token-header: Authorization - token-secret: abcdefghijklmnopqrstuvwxyz - token-timeout: 1d - session-timeout: 30m - mock-enable: true - mock-secret: test - swagger: - enable: false # 单元测试,禁用 Swagger - file: - base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/ - xss: - enable: false - exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系 - - ${spring.boot.admin.context-path}/** # 不处理 Spring Boot Admin 的请求 - - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java deleted file mode 100644 index d35ee7b3a..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java +++ /dev/null @@ -1,308 +0,0 @@ -package cn.iocoder.yudao.module.system.service.errorcode; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeSaveReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; -import cn.iocoder.yudao.module.system.dal.mysql.errorcode.ErrorCodeMapper; -import cn.iocoder.yudao.module.system.enums.errorcode.ErrorCodeTypeEnum; -import org.assertj.core.util.Lists; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.Import; - -import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.List; -import java.util.function.Consumer; - -import static cn.hutool.core.util.RandomUtil.randomEle; -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.ERROR_CODE_DUPLICATE; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.ERROR_CODE_NOT_EXISTS; -import static org.junit.jupiter.api.Assertions.*; - -@Import(ErrorCodeServiceImpl.class) -public class ErrorCodeServiceTest extends BaseDbUnitTest { - - @Resource - private ErrorCodeServiceImpl errorCodeService; - - @Resource - private ErrorCodeMapper errorCodeMapper; - - @Test - public void testCreateErrorCode_success() { - // 准备参数 - ErrorCodeSaveReqVO reqVO = randomPojo(ErrorCodeSaveReqVO.class) - .setId(null); // 防止 id 被赋值 - - // 调用 - Long errorCodeId = errorCodeService.createErrorCode(reqVO); - // 断言 - assertNotNull(errorCodeId); - // 校验记录的属性是否正确 - ErrorCodeDO errorCode = errorCodeMapper.selectById(errorCodeId); - assertPojoEquals(reqVO, errorCode, "id"); - assertEquals(ErrorCodeTypeEnum.MANUAL_OPERATION.getType(), errorCode.getType()); - } - - @Test - public void testUpdateErrorCode_success() { - // mock 数据 - ErrorCodeDO dbErrorCode = randomErrorCodeDO(); - errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 - // 准备参数 - ErrorCodeSaveReqVO reqVO = randomPojo(ErrorCodeSaveReqVO.class, o -> { - o.setId(dbErrorCode.getId()); // 设置更新的 ID - }); - - // 调用 - errorCodeService.updateErrorCode(reqVO); - // 校验是否更新正确 - ErrorCodeDO errorCode = errorCodeMapper.selectById(reqVO.getId()); // 获取最新的 - assertPojoEquals(reqVO, errorCode); - assertEquals(ErrorCodeTypeEnum.MANUAL_OPERATION.getType(), errorCode.getType()); - } - - @Test - public void testDeleteErrorCode_success() { - // mock 数据 - ErrorCodeDO dbErrorCode = randomErrorCodeDO(); - errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbErrorCode.getId(); - - // 调用 - errorCodeService.deleteErrorCode(id); - // 校验数据不存在了 - assertNull(errorCodeMapper.selectById(id)); - } - - @Test - public void testGetErrorCodePage() { - // mock 数据 - ErrorCodeDO dbErrorCode = initGetErrorCodePage(); - // 准备参数 - ErrorCodePageReqVO reqVO = new ErrorCodePageReqVO(); - reqVO.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); - reqVO.setApplicationName("tu"); - reqVO.setCode(1); - reqVO.setMessage("ma"); - reqVO.setCreateTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30)); - - // 调用 - PageResult pageResult = errorCodeService.getErrorCodePage(reqVO); - // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbErrorCode, pageResult.getList().get(0)); - } - - /** - * 初始化 getErrorCodePage 方法的测试数据 - */ - private ErrorCodeDO initGetErrorCodePage() { - ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> { // 等会查询到 - o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); - o.setApplicationName("tudou"); - o.setCode(1); - o.setMessage("yuanma"); - o.setCreateTime(buildTime(2020, 11, 11)); - }); - errorCodeMapper.insert(dbErrorCode); - // 测试 type 不匹配 - errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()))); - // 测试 applicationName 不匹配 - errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yuan"))); - // 测试 code 不匹配 - errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setCode(2))); - // 测试 message 不匹配 - errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setMessage("nai"))); - // 测试 createTime 不匹配 - errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setCreateTime(buildTime(2020, 12, 12)))); - return dbErrorCode; - } - - @Test - public void testValidateCodeDuplicate_codeDuplicateForCreate() { - // 准备参数 - Integer code = randomInteger(); - // mock 数据 - errorCodeMapper.insert(randomErrorCodeDO(o -> o.setCode(code))); - - // 调用,校验异常 - assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, null), - ERROR_CODE_DUPLICATE); - } - - @Test - public void testValidateCodeDuplicate_codeDuplicateForUpdate() { - // 准备参数 - Long id = randomLongId(); - Integer code = randomInteger(); - // mock 数据 - errorCodeMapper.insert(randomErrorCodeDO(o -> o.setCode(code))); - - // 调用,校验异常 - assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, id), - ERROR_CODE_DUPLICATE); - } - - @Test - public void testValidateErrorCodeExists_notExists() { - assertServiceException(() -> errorCodeService.validateErrorCodeExists(null), - ERROR_CODE_NOT_EXISTS); - } - - /** - * 情况 1,错误码不存在的情况 - */ - @Test - public void testAutoGenerateErrorCodes_01() { - // 准备参数 - ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class); - // mock 方法 - - // 调用 - errorCodeService.autoGenerateErrorCodes(Lists.newArrayList(generateReqDTO)); - // 断言 - ErrorCodeDO errorCode = errorCodeMapper.selectOne(null); - assertPojoEquals(generateReqDTO, errorCode); - assertEquals(ErrorCodeTypeEnum.AUTO_GENERATION.getType(), errorCode.getType()); - } - - /** - * 情况 2.1,错误码存在,但是是 ErrorCodeTypeEnum.MANUAL_OPERATION 类型 - */ - @Test - public void testAutoGenerateErrorCodes_021() { - // mock 数据 - ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType())); - errorCodeMapper.insert(dbErrorCode); - // 准备参数 - ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, - o -> o.setCode(dbErrorCode.getCode())); - // mock 方法 - - // 调用 - errorCodeService.autoGenerateErrorCodes(Lists.newArrayList(generateReqDTO)); - // 断言,相等,说明不会更新 - ErrorCodeDO errorCode = errorCodeMapper.selectById(dbErrorCode.getId()); - assertPojoEquals(dbErrorCode, errorCode); - } - - /** - * 情况 2.2,错误码存在,但是是 applicationName 不匹配 - */ - @Test - public void testAutoGenerateErrorCodes_022() { - // mock 数据 - ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); - errorCodeMapper.insert(dbErrorCode); - // 准备参数 - ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, - o -> o.setCode(dbErrorCode.getCode()).setApplicationName(randomString())); - // mock 方法 - - // 调用 - errorCodeService.autoGenerateErrorCodes(Lists.newArrayList(generateReqDTO)); - // 断言,相等,说明不会更新 - ErrorCodeDO errorCode = errorCodeMapper.selectById(dbErrorCode.getId()); - assertPojoEquals(dbErrorCode, errorCode); - } - - /** - * 情况 2.3,错误码存在,但是是 message 相同 - */ - @Test - public void testAutoGenerateErrorCodes_023() { - // mock 数据 - ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); - errorCodeMapper.insert(dbErrorCode); - // 准备参数 - ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, - o -> o.setCode(dbErrorCode.getCode()).setApplicationName(dbErrorCode.getApplicationName()) - .setMessage(dbErrorCode.getMessage())); - // mock 方法 - - // 调用 - errorCodeService.autoGenerateErrorCodes(Lists.newArrayList(generateReqDTO)); - // 断言,相等,说明不会更新 - ErrorCodeDO errorCode = errorCodeMapper.selectById(dbErrorCode.getId()); - assertPojoEquals(dbErrorCode, errorCode); - } - - /** - * 情况 2.3,错误码存在,但是是 message 不同,则进行更新 - */ - @Test - public void testAutoGenerateErrorCodes_024() { - // mock 数据 - ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); - errorCodeMapper.insert(dbErrorCode); - // 准备参数 - ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, - o -> o.setCode(dbErrorCode.getCode()).setApplicationName(dbErrorCode.getApplicationName())); - // mock 方法 - - // 调用 - errorCodeService.autoGenerateErrorCodes(Lists.newArrayList(generateReqDTO)); - // 断言,匹配 - ErrorCodeDO errorCode = errorCodeMapper.selectById(dbErrorCode.getId()); - assertPojoEquals(generateReqDTO, errorCode); - } - - @Test - public void testGetErrorCode() { - // 准备参数 - ErrorCodeDO errorCodeDO = randomErrorCodeDO(); - errorCodeMapper.insert(errorCodeDO); - // mock 方法 - Long id = errorCodeDO.getId(); - - // 调用 - ErrorCodeDO dbErrorCode = errorCodeService.getErrorCode(id); - // 断言 - assertPojoEquals(errorCodeDO, dbErrorCode); - } - - @Test - public void testGetErrorCodeList() { - // 准备参数 - ErrorCodeDO errorCodeDO01 = randomErrorCodeDO( - o -> o.setApplicationName("yunai_server").setUpdateTime(buildTime(2022, 1, 10))); - errorCodeMapper.insert(errorCodeDO01); - ErrorCodeDO errorCodeDO02 = randomErrorCodeDO( - o -> o.setApplicationName("yunai_server").setUpdateTime(buildTime(2022, 1, 12))); - errorCodeMapper.insert(errorCodeDO02); - // mock 方法 - String applicationName = "yunai_server"; - LocalDateTime minUpdateTime = buildTime(2022, 1, 11); - - // 调用 - List errorCodeList = errorCodeService.getErrorCodeList(applicationName, minUpdateTime); - // 断言 - assertEquals(1, errorCodeList.size()); - assertPojoEquals(errorCodeDO02, errorCodeList.get(0)); - } - - // ========== 随机对象 ========== - - @SafeVarargs - private static ErrorCodeDO randomErrorCodeDO(Consumer... consumers) { - Consumer consumer = (o) -> { - o.setType(randomEle(ErrorCodeTypeEnum.values()).getType()); // 保证 key 的范围 - }; - return randomPojo(ErrorCodeDO.class, ArrayUtils.append(consumer, consumers)); - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java deleted file mode 100644 index b5be5e5d1..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java +++ /dev/null @@ -1,303 +0,0 @@ -package cn.iocoder.yudao.module.system.service.sensitiveword; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.SetUtils; -import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; -import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; -import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.Import; - -import javax.annotation.Resource; -import java.time.Duration; -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_WORD_NOT_EXISTS; -import static java.util.Collections.singletonList; -import static org.junit.jupiter.api.Assertions.*; - -/** - * {@link SensitiveWordServiceImpl} 的单元测试类 - * - * @author 永不言败 - */ -@Import(SensitiveWordServiceImpl.class) -public class SensitiveWordServiceImplTest extends BaseDbUnitTest { - - @Resource - private SensitiveWordServiceImpl sensitiveWordService; - - @Resource - private SensitiveWordMapper sensitiveWordMapper; - - @BeforeEach - public void setUp() { - SensitiveWordServiceImpl.ENABLED = true; - } - - @Test - public void testInitLocalCache() { - SensitiveWordDO wordDO1 = randomPojo(SensitiveWordDO.class, o -> o.setName("傻瓜") - .setTags(singletonList("论坛")).setStatus(CommonStatusEnum.ENABLE.getStatus())); - sensitiveWordMapper.insert(wordDO1); - SensitiveWordDO wordDO2 = randomPojo(SensitiveWordDO.class, o -> o.setName("笨蛋") - .setTags(singletonList("蔬菜")).setStatus(CommonStatusEnum.ENABLE.getStatus())); - sensitiveWordMapper.insert(wordDO2); - SensitiveWordDO wordDO3 = randomPojo(SensitiveWordDO.class, o -> o.setName("白") - .setTags(singletonList("测试")).setStatus(CommonStatusEnum.ENABLE.getStatus())); - sensitiveWordMapper.insert(wordDO3); - SensitiveWordDO wordDO4 = randomPojo(SensitiveWordDO.class, o -> o.setName("白痴") - .setTags(singletonList("测试")).setStatus(CommonStatusEnum.ENABLE.getStatus())); - sensitiveWordMapper.insert(wordDO4); - - // 调用 - sensitiveWordService.initLocalCache(); - // 断言 sensitiveWordTagsCache 缓存 - assertEquals(SetUtils.asSet("论坛", "蔬菜", "测试"), sensitiveWordService.getSensitiveWordTagSet()); - // 断言 sensitiveWordCache - assertEquals(4, sensitiveWordService.getSensitiveWordCache().size()); - assertPojoEquals(wordDO1, sensitiveWordService.getSensitiveWordCache().get(0)); - assertPojoEquals(wordDO2, sensitiveWordService.getSensitiveWordCache().get(1)); - assertPojoEquals(wordDO3, sensitiveWordService.getSensitiveWordCache().get(2)); - // 断言 tagSensitiveWordTries 缓存 - assertNotNull(sensitiveWordService.getDefaultSensitiveWordTrie()); - assertEquals(3, sensitiveWordService.getTagSensitiveWordTries().size()); - assertNotNull(sensitiveWordService.getTagSensitiveWordTries().get("论坛")); - assertNotNull(sensitiveWordService.getTagSensitiveWordTries().get("蔬菜")); - assertNotNull(sensitiveWordService.getTagSensitiveWordTries().get("测试")); - } - - @Test - public void testRefreshLocalCache() { - // mock 数据 - SensitiveWordDO wordDO1 = randomPojo(SensitiveWordDO.class, o -> o.setName("傻瓜") - .setTags(singletonList("论坛")).setStatus(CommonStatusEnum.ENABLE.getStatus())); - wordDO1.setUpdateTime(LocalDateTime.now()); - sensitiveWordMapper.insert(wordDO1); - sensitiveWordService.initLocalCache(); - // mock 数据 ② - SensitiveWordDO wordDO2 = randomPojo(SensitiveWordDO.class, o -> o.setName("笨蛋") - .setTags(singletonList("蔬菜")).setStatus(CommonStatusEnum.ENABLE.getStatus())); - wordDO2.setUpdateTime(LocalDateTimeUtils.addTime(Duration.ofMinutes(1))); // 避免时间相同 - sensitiveWordMapper.insert(wordDO2); - - // 调用 - sensitiveWordService.refreshLocalCache(); - // 断言 sensitiveWordTagsCache 缓存 - assertEquals(SetUtils.asSet("论坛", "蔬菜"), sensitiveWordService.getSensitiveWordTagSet()); - // 断言 sensitiveWordCache - assertEquals(2, sensitiveWordService.getSensitiveWordCache().size()); - assertPojoEquals(wordDO1, sensitiveWordService.getSensitiveWordCache().get(0)); - assertPojoEquals(wordDO2, sensitiveWordService.getSensitiveWordCache().get(1)); - // 断言 tagSensitiveWordTries 缓存 - assertNotNull(sensitiveWordService.getDefaultSensitiveWordTrie()); - assertEquals(2, sensitiveWordService.getTagSensitiveWordTries().size()); - assertNotNull(sensitiveWordService.getTagSensitiveWordTries().get("论坛")); - assertNotNull(sensitiveWordService.getTagSensitiveWordTries().get("蔬菜")); - } - - @Test - public void testCreateSensitiveWord_success() { - // 准备参数 - SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class) - .setId(null); // 防止 id 被赋值 - - // 调用 - Long sensitiveWordId = sensitiveWordService.createSensitiveWord(reqVO); - // 断言 - assertNotNull(sensitiveWordId); - // 校验记录的属性是否正确 - SensitiveWordDO sensitiveWord = sensitiveWordMapper.selectById(sensitiveWordId); - assertPojoEquals(reqVO, sensitiveWord, "id"); - } - - @Test - public void testUpdateSensitiveWord_success() { - // mock 数据 - SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class); - sensitiveWordMapper.insert(dbSensitiveWord);// @Sql: 先插入出一条存在的数据 - // 准备参数 - SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class, o -> { - o.setId(dbSensitiveWord.getId()); // 设置更新的 ID - }); - - // 调用 - sensitiveWordService.updateSensitiveWord(reqVO); - // 校验是否更新正确 - SensitiveWordDO sensitiveWord = sensitiveWordMapper.selectById(reqVO.getId()); // 获取最新的 - assertPojoEquals(reqVO, sensitiveWord); - } - - @Test - public void testUpdateSensitiveWord_notExists() { - // 准备参数 - SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class); - - // 调用, 并断言异常 - assertServiceException(() -> sensitiveWordService.updateSensitiveWord(reqVO), SENSITIVE_WORD_NOT_EXISTS); - } - - @Test - public void testDeleteSensitiveWord_success() { - // mock 数据 - SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class); - sensitiveWordMapper.insert(dbSensitiveWord);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbSensitiveWord.getId(); - - // 调用 - sensitiveWordService.deleteSensitiveWord(id); - // 校验数据不存在了 - assertNull(sensitiveWordMapper.selectById(id)); - } - - @Test - public void testDeleteSensitiveWord_notExists() { - // 准备参数 - Long id = randomLongId(); - - // 调用, 并断言异常 - assertServiceException(() -> sensitiveWordService.deleteSensitiveWord(id), SENSITIVE_WORD_NOT_EXISTS); - } - - @Test - public void testGetSensitiveWord() { - // mock 数据 - SensitiveWordDO sensitiveWord = randomPojo(SensitiveWordDO.class); - sensitiveWordMapper.insert(sensitiveWord); - // 准备参数 - Long id = sensitiveWord.getId(); - - // 调用 - SensitiveWordDO dbSensitiveWord = sensitiveWordService.getSensitiveWord(id); - // 断言 - assertPojoEquals(sensitiveWord, dbSensitiveWord); - } - - @Test - public void testGetSensitiveWordList() { - // mock 数据 - SensitiveWordDO sensitiveWord01 = randomPojo(SensitiveWordDO.class); - sensitiveWordMapper.insert(sensitiveWord01); - SensitiveWordDO sensitiveWord02 = randomPojo(SensitiveWordDO.class); - sensitiveWordMapper.insert(sensitiveWord02); - - // 调用 - List list = sensitiveWordService.getSensitiveWordList(); - // 断言 - assertEquals(2, list.size()); - assertEquals(sensitiveWord01, list.get(0)); - assertEquals(sensitiveWord02, list.get(1)); - } - - @Test - public void testGetSensitiveWordPage() { - // mock 数据 - SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class, o -> { // 等会查询到 - o.setName("笨蛋"); - o.setTags(Arrays.asList("论坛", "蔬菜")); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setCreateTime(buildTime(2022, 2, 8)); - }); - sensitiveWordMapper.insert(dbSensitiveWord); - // 测试 name 不匹配 - sensitiveWordMapper.insert(cloneIgnoreId(dbSensitiveWord, o -> o.setName("傻瓜"))); - // 测试 tags 不匹配 - sensitiveWordMapper.insert(cloneIgnoreId(dbSensitiveWord, o -> o.setTags(Arrays.asList("短信", "日用品")))); - // 测试 createTime 不匹配 - sensitiveWordMapper.insert(cloneIgnoreId(dbSensitiveWord, o -> o.setCreateTime(buildTime(2022, 2, 16)))); - // 准备参数 - SensitiveWordPageReqVO reqVO = new SensitiveWordPageReqVO(); - reqVO.setName("笨"); - reqVO.setTag("论坛"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 12)); - - // 调用 - PageResult pageResult = sensitiveWordService.getSensitiveWordPage(reqVO); - // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbSensitiveWord, pageResult.getList().get(0)); - } - - @Test - public void testValidateText_noTag() { - testInitLocalCache(); - // 准备参数 - String text = "你是傻瓜,你是笨蛋"; - // 调用 - List result = sensitiveWordService.validateText(text, null); - // 断言 - assertEquals(Arrays.asList("傻瓜", "笨蛋"), result); - - // 准备参数 - String text2 = "你是傻瓜,你是笨蛋,你是白"; - // 调用 - List result2 = sensitiveWordService.validateText(text2, null); - // 断言 - assertEquals(Arrays.asList("傻瓜", "笨蛋","白"), result2); - } - - @Test - public void testValidateText_hasTag() { - testInitLocalCache(); - // 准备参数 - String text = "你是傻瓜,你是笨蛋"; - // 调用 - List result = sensitiveWordService.validateText(text, singletonList("论坛")); - // 断言 - assertEquals(singletonList("傻瓜"), result); - - - // 准备参数 - String text2 = "你是白"; - // 调用 - List result2 = sensitiveWordService.validateText(text2, singletonList("测试")); - // 断言 - assertEquals(singletonList("白"), result2); - } - - @Test - public void testIsTestValid_noTag() { - testInitLocalCache(); - // 准备参数 - String text = "你是傻瓜,你是笨蛋"; - // 调用,断言 - assertFalse(sensitiveWordService.isTextValid(text, null)); - - // 准备参数 - String text2 = "你是白"; - // 调用,断言 - assertFalse(sensitiveWordService.isTextValid(text2, null)); - } - - @Test - public void testIsTestValid_hasTag() { - testInitLocalCache(); - // 准备参数 - String text = "你是傻瓜,你是笨蛋"; - // 调用,断言 - assertFalse(sensitiveWordService.isTextValid(text, singletonList("论坛"))); - - // 准备参数 - String text2 = "你是白"; - // 调用,断言 - assertFalse(sensitiveWordService.isTextValid(text2, singletonList("测试"))); - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/test/resources/sql/clean.sql b/yudao-module-system/yudao-module-system-biz/src/test/resources/sql/clean.sql index 55778022e..e7946a105 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/resources/sql/clean.sql +++ b/yudao-module-system/yudao-module-system-biz/src/test/resources/sql/clean.sql @@ -16,13 +16,11 @@ DELETE FROM "system_sms_channel"; DELETE FROM "system_sms_template"; DELETE FROM "system_sms_log"; DELETE FROM "system_sms_code"; -DELETE FROM "system_error_code"; DELETE FROM "system_social_client"; DELETE FROM "system_social_user"; DELETE FROM "system_social_user_bind"; DELETE FROM "system_tenant"; DELETE FROM "system_tenant_package"; -DELETE FROM "system_sensitive_word"; DELETE FROM "system_oauth2_client"; DELETE FROM "system_oauth2_approve"; DELETE FROM "system_oauth2_access_token"; diff --git a/yudao-module-system/yudao-module-system-biz/src/test/resources/sql/create_tables.sql b/yudao-module-system/yudao-module-system-biz/src/test/resources/sql/create_tables.sql index 731b2850e..8f1ac5e0a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-system/yudao-module-system-biz/src/test/resources/sql/create_tables.sql @@ -332,21 +332,6 @@ CREATE TABLE IF NOT EXISTS "system_sms_code" ( PRIMARY KEY ("id") ) COMMENT '短信日志'; -CREATE TABLE IF NOT EXISTS "system_error_code" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "type" tinyint NOT NULL DEFAULT '0', - "application_name" varchar(50) NOT NULL, - "code" int NOT NULL DEFAULT '0', - "message" varchar(512) NOT NULL DEFAULT '', - "memo" varchar(512) DEFAULT '', - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '错误码表'; - CREATE TABLE IF NOT EXISTS "system_social_client" ( "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" varchar(255) NOT NULL, @@ -431,20 +416,6 @@ CREATE TABLE IF NOT EXISTS "system_tenant_package" ( PRIMARY KEY ("id") ) COMMENT '租户套餐表'; -CREATE TABLE IF NOT EXISTS "system_sensitive_word" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(255) NOT NULL, - "tags" varchar(1024) NOT NULL, - "status" bit NOT NULL DEFAULT FALSE, - "description" varchar(512), - "creator" varchar(64) DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '系统敏感词'; - CREATE TABLE IF NOT EXISTS "system_oauth2_client" ( "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "client_id" varchar NOT NULL,