Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud
# Conflicts: # yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/filter/TokenAuthenticationFilter.java # yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApi.java # yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java # yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImplTest.java # yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteBatchReqVO.java # yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteReqVO.java # yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplateRespVO.java # yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java # yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java # yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.javapull/180/MERGE
commit
393d7b728c
|
|
@ -11,6 +11,7 @@ import java.util.function.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static cn.hutool.core.convert.Convert.toCollection;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -335,4 +336,17 @@ public class CollectionUtils {
|
||||||
return list.stream().filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
|
return list.stream().filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换为 LinkedHashSet
|
||||||
|
*
|
||||||
|
* @param <T> 元素类型
|
||||||
|
* @param elementType 集合中元素类型
|
||||||
|
* @param value 被转换的值
|
||||||
|
* @return {@link LinkedHashSet}
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> LinkedHashSet<T> toLinkedHashSet(Class<T> elementType, Object value) {
|
||||||
|
return (LinkedHashSet<T>) toCollection(LinkedHashSet.class, elementType, value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +1,9 @@
|
||||||
package cn.iocoder.yudao.framework.common.util.io;
|
package cn.iocoder.yudao.framework.common.util.io;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileTypeUtil;
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.file.FileNameUtil;
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import cn.hutool.crypto.digest.DigestUtil;
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -63,22 +58,4 @@ public class FileUtils {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成文件路径
|
|
||||||
*
|
|
||||||
* @param content 文件内容
|
|
||||||
* @param originalName 原始文件名
|
|
||||||
* @return path,唯一不可重复
|
|
||||||
*/
|
|
||||||
public static String generatePath(byte[] content, String originalName) {
|
|
||||||
String sha256Hex = DigestUtil.sha256Hex(content);
|
|
||||||
// 情况一:如果存在 name,则优先使用 name 的后缀
|
|
||||||
if (StrUtil.isNotBlank(originalName)) {
|
|
||||||
String extName = FileNameUtil.extName(originalName);
|
|
||||||
return StrUtil.isBlank(extName) ? sha256Hex : sha256Hex + "." + extName;
|
|
||||||
}
|
|
||||||
// 情况二:基于 content 计算
|
|
||||||
return sha256Hex + '.' + FileTypeUtil.getType(new ByteArrayInputStream(content));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import cn.hutool.system.SystemUtil;
|
||||||
import cn.iocoder.yudao.framework.common.enums.DocumentEnum;
|
import cn.iocoder.yudao.framework.common.enums.DocumentEnum;
|
||||||
import cn.iocoder.yudao.framework.mq.redis.core.RedisMQTemplate;
|
import cn.iocoder.yudao.framework.mq.redis.core.RedisMQTemplate;
|
||||||
import cn.iocoder.yudao.framework.mq.redis.core.job.RedisPendingMessageResendJob;
|
import cn.iocoder.yudao.framework.mq.redis.core.job.RedisPendingMessageResendJob;
|
||||||
|
import cn.iocoder.yudao.framework.mq.redis.core.job.RedisStreamMessageCleanupJob;
|
||||||
import cn.iocoder.yudao.framework.mq.redis.core.pubsub.AbstractRedisChannelMessageListener;
|
import cn.iocoder.yudao.framework.mq.redis.core.pubsub.AbstractRedisChannelMessageListener;
|
||||||
import cn.iocoder.yudao.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
|
import cn.iocoder.yudao.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
|
||||||
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
|
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
|
||||||
|
|
@ -73,6 +74,17 @@ public class YudaoRedisMQConsumerAutoConfiguration {
|
||||||
return new RedisPendingMessageResendJob(listeners, redisTemplate, groupName, redissonClient);
|
return new RedisPendingMessageResendJob(listeners, redisTemplate, groupName, redissonClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建 Redis Stream 消息清理任务
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnBean(AbstractRedisStreamMessageListener.class)
|
||||||
|
public RedisStreamMessageCleanupJob redisStreamMessageCleanupJob(List<AbstractRedisStreamMessageListener<?>> listeners,
|
||||||
|
RedisMQTemplate redisTemplate,
|
||||||
|
RedissonClient redissonClient) {
|
||||||
|
return new RedisStreamMessageCleanupJob(listeners, redisTemplate, redissonClient);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建 Redis Stream 集群消费的容器
|
* 创建 Redis Stream 集群消费的容器
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@ import java.util.Objects;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class RedisPendingMessageResendJob {
|
public class RedisPendingMessageResendJob {
|
||||||
|
|
||||||
private static final String LOCK_KEY = "redis:pending:msg:lock";
|
private static final String LOCK_KEY = "redis:stream:pending-message-resend:lock";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息超时时间,默认 5 分钟
|
* 消息超时时间,默认 5 分钟
|
||||||
*
|
*
|
||||||
* 1. 超时的消息才会被重新投递
|
* 1. 超时的消息才会被重新投递
|
||||||
* 2. 由于定时任务 1 分钟一次,消息超时后不会被立即重投,极端情况下消息5分钟过期后,再等 1 分钟才会被扫瞄到
|
* 2. 由于定时任务 1 分钟一次,消息超时后不会被立即重投,极端情况下消息 5 分钟过期后,再等 1 分钟才会被扫瞄到
|
||||||
*/
|
*/
|
||||||
private static final int EXPIRE_TIME = 5 * 60;
|
private static final int EXPIRE_TIME = 5 * 60;
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class RedisPendingMessageResendJob {
|
||||||
private final RedissonClient redissonClient;
|
private final RedissonClient redissonClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一分钟执行一次,这里选择每分钟的35秒执行,是为了避免整点任务过多的问题
|
* 一分钟执行一次,这里选择每分钟的 35 秒执行,是为了避免整点任务过多的问题
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "35 * * * * ?")
|
@Scheduled(cron = "35 * * * * ?")
|
||||||
public void messageResend() {
|
public void messageResend() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
package cn.iocoder.yudao.framework.mq.redis.core.job;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mq.redis.core.RedisMQTemplate;
|
||||||
|
import cn.iocoder.yudao.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.redisson.api.RLock;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
import org.springframework.data.redis.core.StreamOperations;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redis Stream 消息清理任务
|
||||||
|
* 用于定期清理已消费的消息,防止内存占用过大
|
||||||
|
*
|
||||||
|
* @see <a href="https://www.cnblogs.com/nanxiang/p/16179519.html">记一次 redis stream 数据类型内存不释放问题</a>
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class RedisStreamMessageCleanupJob {
|
||||||
|
|
||||||
|
private static final String LOCK_KEY = "redis:stream:message-cleanup:lock";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保留的消息数量,默认保留最近 10000 条消息
|
||||||
|
*/
|
||||||
|
private static final long MAX_COUNT = 10000;
|
||||||
|
|
||||||
|
private final List<AbstractRedisStreamMessageListener<?>> listeners;
|
||||||
|
private final RedisMQTemplate redisTemplate;
|
||||||
|
private final RedissonClient redissonClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每小时执行一次清理任务
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 * * * ?")
|
||||||
|
public void cleanup() {
|
||||||
|
RLock lock = redissonClient.getLock(LOCK_KEY);
|
||||||
|
// 尝试加锁
|
||||||
|
if (lock.tryLock()) {
|
||||||
|
try {
|
||||||
|
execute();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("[cleanup][执行异常]", ex);
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行清理逻辑
|
||||||
|
*/
|
||||||
|
private void execute() {
|
||||||
|
StreamOperations<String, Object, Object> ops = redisTemplate.getRedisTemplate().opsForStream();
|
||||||
|
listeners.forEach(listener -> {
|
||||||
|
try {
|
||||||
|
// 使用 XTRIM 命令清理消息,只保留最近的 MAX_LEN 条消息
|
||||||
|
Long trimCount = ops.trim(listener.getStreamKey(), MAX_COUNT, true);
|
||||||
|
if (trimCount != null && trimCount > 0) {
|
||||||
|
log.info("[execute][Stream({}) 清理消息数量({})]", listener.getStreamKey(), trimCount);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("[execute][Stream({}) 清理异常]", listener.getStreamKey(), ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,16 +13,15 @@ import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler;
|
||||||
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
||||||
import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
|
import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
|
||||||
import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
|
import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
|
||||||
|
import jakarta.servlet.FilterChain;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
import javax.servlet.FilterChain;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
@ -129,15 +128,24 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||||
.setTenantId(WebFrameworkUtils.getTenantId(request));
|
.setTenantId(WebFrameworkUtils.getTenantId(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
private LoginUser buildLoginUserByHeader(HttpServletRequest request) {
|
private LoginUser buildLoginUserByHeader(HttpServletRequest request) {
|
||||||
String loginUserStr = request.getHeader(SecurityFrameworkUtils.LOGIN_USER_HEADER);
|
String loginUserStr = request.getHeader(SecurityFrameworkUtils.LOGIN_USER_HEADER);
|
||||||
if (StrUtil.isEmpty(loginUserStr)) {
|
if (StrUtil.isEmpty(loginUserStr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
loginUserStr = URLDecoder.decode(loginUserStr, StandardCharsets.UTF_8.name()); // 解码,解决中文乱码问题
|
loginUserStr = URLDecoder.decode(loginUserStr, StandardCharsets.UTF_8); // 解码,解决中文乱码问题
|
||||||
return JsonUtils.parseObject(loginUserStr, LoginUser.class);
|
LoginUser loginUser = JsonUtils.parseObject(loginUserStr, LoginUser.class);
|
||||||
|
// 用户类型不匹配,无权限
|
||||||
|
// 注意:只有 /admin-api/* 和 /app-api/* 有 userType,才需要比对用户类型
|
||||||
|
// 类似 WebSocket 的 /ws/* 连接地址,是不需要比对用户类型的
|
||||||
|
Integer userType = WebFrameworkUtils.getLoginUserType(request);
|
||||||
|
if (userType != null
|
||||||
|
&& loginUser != null
|
||||||
|
&& ObjectUtil.notEqual(loginUser.getUserType(), userType)) {
|
||||||
|
throw new AccessDeniedException("错误的用户类型");
|
||||||
|
}
|
||||||
|
return loginUser;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("[buildLoginUserByHeader][解析 LoginUser({}) 发生异常]", loginUserStr, ex); ;
|
log.error("[buildLoginUserByHeader][解析 LoginUser({}) 发生异常]", loginUserStr, ex); ;
|
||||||
throw ex;
|
throw ex;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.form;
|
package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.form;
|
||||||
|
|
||||||
import cn.hutool.core.convert.Convert;
|
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.user.BpmTaskCandidateUserStrategy;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.user.BpmTaskCandidateUserStrategy;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
|
||||||
|
|
@ -33,7 +33,7 @@ public class BpmTaskCandidateFormUserStrategy implements BpmTaskCandidateStrateg
|
||||||
@Override
|
@Override
|
||||||
public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
|
public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
|
||||||
Object result = execution.getVariable(param);
|
Object result = execution.getVariable(param);
|
||||||
return Convert.toSet(Long.class, result);
|
return CollectionUtils.toLinkedHashSet(Long.class, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -41,7 +41,7 @@ public class BpmTaskCandidateFormUserStrategy implements BpmTaskCandidateStrateg
|
||||||
String param, Long startUserId, String processDefinitionId,
|
String param, Long startUserId, String processDefinitionId,
|
||||||
Map<String, Object> processVariables) {
|
Map<String, Object> processVariables) {
|
||||||
Object result = processVariables == null ? null : processVariables.get(param);
|
Object result = processVariables == null ? null : processVariables.get(param);
|
||||||
return Convert.toSet(Long.class, result);
|
return CollectionUtils.toLinkedHashSet(Long.class, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.other;
|
package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.other;
|
||||||
|
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
|
||||||
|
|
@ -37,7 +37,7 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat
|
||||||
@Override
|
@Override
|
||||||
public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
|
public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
|
||||||
Object result = FlowableUtils.getExpressionValue(execution, param);
|
Object result = FlowableUtils.getExpressionValue(execution, param);
|
||||||
return Convert.toSet(Long.class, result);
|
return CollectionUtils.toLinkedHashSet(Long.class, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -46,7 +46,7 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat
|
||||||
Map<String, Object> variables = processVariables == null ? new HashMap<>() : processVariables;
|
Map<String, Object> variables = processVariables == null ? new HashMap<>() : processVariables;
|
||||||
try {
|
try {
|
||||||
Object result = FlowableUtils.getExpressionValue(variables, param);
|
Object result = FlowableUtils.getExpressionValue(variables, param);
|
||||||
return Convert.toSet(Long.class, result);
|
return CollectionUtils.toLinkedHashSet(Long.class, result);
|
||||||
} catch (FlowableException ex) {
|
} catch (FlowableException ex) {
|
||||||
// 预测未运行的节点时候,表达式如果包含 execution 或者不存在的流程变量会抛异常,
|
// 预测未运行的节点时候,表达式如果包含 execution 或者不存在的流程变量会抛异常,
|
||||||
log.warn("[calculateUsersByActivity][表达式({}) 变量({}) 解析报错", param, variables, ex);
|
log.warn("[calculateUsersByActivity][表达式({}) 变量({}) 解析报错", param, variables, ex);
|
||||||
|
|
|
||||||
|
|
@ -873,12 +873,14 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
List<UserTask> returnUserTaskList = BpmnModelUtils.iteratorFindChildUserTasks(targetElement, runTaskKeyList, null, null);
|
List<UserTask> returnUserTaskList = BpmnModelUtils.iteratorFindChildUserTasks(targetElement, runTaskKeyList, null, null);
|
||||||
List<String> returnTaskKeyList = convertList(returnUserTaskList, UserTask::getId);
|
List<String> returnTaskKeyList = convertList(returnUserTaskList, UserTask::getId);
|
||||||
|
|
||||||
|
List<String> runExecutionIds = new ArrayList<>();
|
||||||
// 2. 给当前要被退回的 task 数组,设置退回意见
|
// 2. 给当前要被退回的 task 数组,设置退回意见
|
||||||
taskList.forEach(task -> {
|
taskList.forEach(task -> {
|
||||||
// 需要排除掉,不需要设置退回意见的任务
|
// 需要排除掉,不需要设置退回意见的任务
|
||||||
if (!returnTaskKeyList.contains(task.getTaskDefinitionKey())) {
|
if (!returnTaskKeyList.contains(task.getTaskDefinitionKey())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
runExecutionIds.add(task.getExecutionId());
|
||||||
|
|
||||||
// 判断是否分配给自己任务,因为会签任务,一个节点会有多个任务
|
// 判断是否分配给自己任务,因为会签任务,一个节点会有多个任务
|
||||||
if (isAssignUserTask(userId, task)) { // 情况一:自己的任务,进行 RETURN 标记
|
if (isAssignUserTask(userId, task)) { // 情况一:自己的任务,进行 RETURN 标记
|
||||||
|
|
@ -898,7 +900,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
// 4. 执行驳回
|
// 4. 执行驳回
|
||||||
// 使用 moveExecutionsToSingleActivityId 替换 moveActivityIdsToSingleActivityId 原因:
|
// 使用 moveExecutionsToSingleActivityId 替换 moveActivityIdsToSingleActivityId 原因:
|
||||||
// 当多实例任务回退的时候有问题。相关 issue: https://github.com/flowable/flowable-engine/issues/3944
|
// 当多实例任务回退的时候有问题。相关 issue: https://github.com/flowable/flowable-engine/issues/3944
|
||||||
List<String> runExecutionIds = convertList(taskList, Task::getExecutionId);
|
|
||||||
runtimeService.createChangeActivityStateBuilder()
|
runtimeService.createChangeActivityStateBuilder()
|
||||||
.processInstanceId(currentTask.getProcessInstanceId())
|
.processInstanceId(currentTask.getProcessInstanceId())
|
||||||
.moveExecutionsToSingleActivityId(runExecutionIds, reqVO.getTargetTaskDefinitionKey())
|
.moveExecutionsToSingleActivityId(runExecutionIds, reqVO.getTargetTaskDefinitionKey())
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,13 @@ package cn.iocoder.yudao.module.infra.api.file;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.module.infra.api.file.dto.FileCreateReqDTO;
|
import cn.iocoder.yudao.module.infra.api.file.dto.FileCreateReqDTO;
|
||||||
import cn.iocoder.yudao.module.infra.enums.ApiConstants;
|
import cn.iocoder.yudao.module.infra.enums.ApiConstants;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
|
|
||||||
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿:fallbackFactory =
|
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿:fallbackFactory =
|
||||||
@Tag(name = "RPC 服务 - 文件")
|
@Tag(name = "RPC 服务 - 文件")
|
||||||
|
|
@ -25,32 +24,32 @@ public interface FileApi {
|
||||||
* @return 文件路径
|
* @return 文件路径
|
||||||
*/
|
*/
|
||||||
default String createFile(byte[] content) {
|
default String createFile(byte[] content) {
|
||||||
return createFile(null, null, content);
|
return createFile(content, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存文件,并返回文件的访问路径
|
* 保存文件,并返回文件的访问路径
|
||||||
*
|
*
|
||||||
* @param path 文件路径
|
|
||||||
* @param content 文件内容
|
* @param content 文件内容
|
||||||
|
* @param name 文件名称,允许空
|
||||||
* @return 文件路径
|
* @return 文件路径
|
||||||
*/
|
*/
|
||||||
default String createFile(String path, byte[] content) {
|
default String createFile(byte[] content, String name) {
|
||||||
return createFile(null, path, content);
|
return createFile(content, name, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存文件,并返回文件的访问路径
|
* 保存文件,并返回文件的访问路径
|
||||||
*
|
*
|
||||||
* @param name 原文件名称
|
|
||||||
* @param path 文件路径
|
|
||||||
* @param content 文件内容
|
* @param content 文件内容
|
||||||
|
* @param name 文件名称,允许空
|
||||||
|
* @param directory 目录,允许空
|
||||||
|
* @param type 文件的 MIME 类型,允许空
|
||||||
* @return 文件路径
|
* @return 文件路径
|
||||||
*/
|
*/
|
||||||
default String createFile(@RequestParam("name") String name,
|
default String createFile(@NotEmpty(message = "文件内容不能为空") byte[] content,
|
||||||
@RequestParam("path") String path,
|
String name, String directory, String type) {
|
||||||
@RequestParam("content") byte[] content) {
|
return createFile(new FileCreateReqDTO().setName(name).setDirectory(directory).setType(type).setContent(content)).getCheckedData();
|
||||||
return createFile(new FileCreateReqDTO().setName(name).setPath(path).setContent(content)).getCheckedData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(PREFIX + "/create")
|
@PostMapping(PREFIX + "/create")
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,11 @@ public class FileCreateReqDTO {
|
||||||
@Schema(description = "原文件名称", example = "xxx.png")
|
@Schema(description = "原文件名称", example = "xxx.png")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "文件路径", example = "xxx.png")
|
@Schema(description = "文件目录", example = "xxx")
|
||||||
private String path;
|
private String directory;
|
||||||
|
|
||||||
|
@Schema(description = "文件的 MIME 类型", example = "image/png")
|
||||||
|
private String type;
|
||||||
|
|
||||||
@Schema(description = "文件内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "文件内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@NotEmpty(message = "文件内容不能为空")
|
@NotEmpty(message = "文件内容不能为空")
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ public class FileApiImpl implements FileApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<String> createFile(FileCreateReqDTO createReqDTO) {
|
public CommonResult<String> createFile(FileCreateReqDTO createReqDTO) {
|
||||||
return success(fileService.createFile(createReqDTO.getName(), createReqDTO.getPath(),
|
return success(fileService.createFile(createReqDTO.getContent(), createReqDTO.getName(),
|
||||||
createReqDTO.getContent()));
|
createReqDTO.getDirectory(), createReqDTO.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
||||||
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.annotation.security.PermitAll;
|
import javax.annotation.security.PermitAll;
|
||||||
|
|
@ -41,14 +42,21 @@ public class FileController {
|
||||||
@Operation(summary = "上传文件", description = "模式一:后端上传文件")
|
@Operation(summary = "上传文件", description = "模式一:后端上传文件")
|
||||||
public CommonResult<String> uploadFile(FileUploadReqVO uploadReqVO) throws Exception {
|
public CommonResult<String> uploadFile(FileUploadReqVO uploadReqVO) throws Exception {
|
||||||
MultipartFile file = uploadReqVO.getFile();
|
MultipartFile file = uploadReqVO.getFile();
|
||||||
String path = uploadReqVO.getPath();
|
byte[] content = IoUtil.readBytes(file.getInputStream());
|
||||||
return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
|
return success(fileService.createFile(content, file.getOriginalFilename(),
|
||||||
|
uploadReqVO.getDirectory(), file.getContentType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/presigned-url")
|
@GetMapping("/presigned-url")
|
||||||
@Operation(summary = "获取文件预签名地址", description = "模式二:前端上传文件:用于前端直接上传七牛、阿里云 OSS 等文件存储器")
|
@Operation(summary = "获取文件预签名地址", description = "模式二:前端上传文件:用于前端直接上传七牛、阿里云 OSS 等文件存储器")
|
||||||
public CommonResult<FilePresignedUrlRespVO> getFilePresignedUrl(@RequestParam("path") String path) throws Exception {
|
@Parameters({
|
||||||
return success(fileService.getFilePresignedUrl(path));
|
@Parameter(name = "name", description = "文件名称", required = true),
|
||||||
|
@Parameter(name = "directory", description = "文件目录")
|
||||||
|
})
|
||||||
|
public CommonResult<FilePresignedUrlRespVO> getFilePresignedUrl(
|
||||||
|
@RequestParam("name") String name,
|
||||||
|
@RequestParam(value = "directory", required = false) String directory) {
|
||||||
|
return success(fileService.getFilePresignedUrl(name, directory));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ public class FilePresignedUrlRespVO {
|
||||||
@Schema(description = "配置编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11")
|
@Schema(description = "配置编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11")
|
||||||
private Long configId;
|
private Long configId;
|
||||||
|
|
||||||
@Schema(description = "文件上传 URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://s3.cn-south-1.qiniucs.com/ruoyi-vue-pro/758d3a5387507358c7236de4c8f96de1c7f5097ff6a7722b34772fb7b76b140f.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=3TvrJ70gl2Gt6IBe7_IZT1F6i_k0iMuRtyEv4EyS%2F20240217%2Fcn-south-1%2Fs3%2Faws4_request&X-Amz-Date=20240217T123222Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=a29f33770ab79bf523ccd4034d0752ac545f3c2a3b17baa1eb4e280cfdccfda5")
|
@Schema(description = "文件上传 URL", requiredMode = Schema.RequiredMode.REQUIRED,
|
||||||
|
example = "https://s3.cn-south-1.qiniucs.com/ruoyi-vue-pro/758d3a5387507358c7236de4c8f96de1c7f5097ff6a7722b34772fb7b76b140f.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=3TvrJ70gl2Gt6IBe7_IZT1F6i_k0iMuRtyEv4EyS%2F20240217%2Fcn-south-1%2Fs3%2Faws4_request&X-Amz-Date=20240217T123222Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=a29f33770ab79bf523ccd4034d0752ac545f3c2a3b17baa1eb4e280cfdccfda5")
|
||||||
private String uploadUrl;
|
private String uploadUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,4 +27,12 @@ public class FilePresignedUrlRespVO {
|
||||||
example = "https://test.yudao.iocoder.cn/758d3a5387507358c7236de4c8f96de1c7f5097ff6a7722b34772fb7b76b140f.png")
|
example = "https://test.yudao.iocoder.cn/758d3a5387507358c7236de4c8f96de1c7f5097ff6a7722b34772fb7b76b140f.png")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为什么要返回 path 字段?
|
||||||
|
*
|
||||||
|
* 前端上传完文件后,需要调用 createFile 记录下 path 路径
|
||||||
|
*/
|
||||||
|
@Schema(description = "文件路径", requiredMode = Schema.RequiredMode.REQUIRED, example = "xxx.png")
|
||||||
|
private String path;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public class FileUploadReqVO {
|
||||||
@NotNull(message = "文件附件不能为空")
|
@NotNull(message = "文件附件不能为空")
|
||||||
private MultipartFile file;
|
private MultipartFile file;
|
||||||
|
|
||||||
@Schema(description = "文件附件", example = "yudaoyuanma.png")
|
@Schema(description = "文件目录", example = "XXX/YYY")
|
||||||
private String path;
|
private String directory;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePresigned
|
||||||
import cn.iocoder.yudao.module.infra.controller.app.file.vo.AppFileUploadReqVO;
|
import cn.iocoder.yudao.module.infra.controller.app.file.vo.AppFileUploadReqVO;
|
||||||
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
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 io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
@ -34,15 +36,21 @@ public class AppFileController {
|
||||||
@PermitAll
|
@PermitAll
|
||||||
public CommonResult<String> uploadFile(AppFileUploadReqVO uploadReqVO) throws Exception {
|
public CommonResult<String> uploadFile(AppFileUploadReqVO uploadReqVO) throws Exception {
|
||||||
MultipartFile file = uploadReqVO.getFile();
|
MultipartFile file = uploadReqVO.getFile();
|
||||||
String path = uploadReqVO.getPath();
|
byte[] content = IoUtil.readBytes(file.getInputStream());
|
||||||
return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
|
return success(fileService.createFile(content, file.getOriginalFilename(),
|
||||||
|
uploadReqVO.getDirectory(), file.getContentType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/presigned-url")
|
@GetMapping("/presigned-url")
|
||||||
@Operation(summary = "获取文件预签名地址", description = "模式二:前端上传文件:用于前端直接上传七牛、阿里云 OSS 等文件存储器")
|
@Operation(summary = "获取文件预签名地址", description = "模式二:前端上传文件:用于前端直接上传七牛、阿里云 OSS 等文件存储器")
|
||||||
@PermitAll
|
@Parameters({
|
||||||
public CommonResult<FilePresignedUrlRespVO> getFilePresignedUrl(@RequestParam("path") String path) throws Exception {
|
@Parameter(name = "name", description = "文件名称", required = true),
|
||||||
return success(fileService.getFilePresignedUrl(path));
|
@Parameter(name = "directory", description = "文件目录")
|
||||||
|
})
|
||||||
|
public CommonResult<FilePresignedUrlRespVO> getFilePresignedUrl(
|
||||||
|
@RequestParam("name") String name,
|
||||||
|
@RequestParam(value = "directory", required = false) String directory) {
|
||||||
|
return success(fileService.getFilePresignedUrl(name, directory));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public class AppFileUploadReqVO {
|
||||||
@NotNull(message = "文件附件不能为空")
|
@NotNull(message = "文件附件不能为空")
|
||||||
private MultipartFile file;
|
private MultipartFile file;
|
||||||
|
|
||||||
@Schema(description = "文件附件", example = "yudaoyuanma.png")
|
@Schema(description = "文件目录", example = "XXX/YYY")
|
||||||
private String path;
|
private String directory;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,14 @@ import lombok.Getter;
|
||||||
public enum CodegenFrontTypeEnum {
|
public enum CodegenFrontTypeEnum {
|
||||||
|
|
||||||
VUE2_ELEMENT_UI(10), // Vue2 Element UI 标准模版
|
VUE2_ELEMENT_UI(10), // Vue2 Element UI 标准模版
|
||||||
|
|
||||||
VUE3_ELEMENT_PLUS(20), // Vue3 Element Plus 标准模版
|
VUE3_ELEMENT_PLUS(20), // Vue3 Element Plus 标准模版
|
||||||
|
|
||||||
VUE3_VBEN2_ANTD_SCHEMA(30), // Vue3 VBEN2 + ANTD + Schema 模版
|
VUE3_VBEN2_ANTD_SCHEMA(30), // Vue3 VBEN2 + ANTD + Schema 模版
|
||||||
|
|
||||||
VUE3_VBEN5_ANTD_SCHEMA(40), // Vue3 VBEN5 + ANTD + schema 模版
|
VUE3_VBEN5_ANTD_SCHEMA(40), // Vue3 VBEN5 + ANTD + schema 模版
|
||||||
|
|
||||||
|
VUE3_VBEN5_ANTD_GENERAL(41), // Vue3 VBEN5 + ANTD 标准模版
|
||||||
;
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,6 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doInit() {
|
protected void doInit() {
|
||||||
// 把配置的 \ 替换成 /, 如果路径配置 \a\test, 替换成 /a/test, 替换方法已经处理 null 情况
|
|
||||||
config.setBasePath(StrUtil.replace(config.getBasePath(), StrUtil.BACKSLASH, StrUtil.SLASH));
|
|
||||||
// ftp的路径是 / 结尾
|
|
||||||
if (!config.getBasePath().endsWith(StrUtil.SLASH)) {
|
|
||||||
config.setBasePath(config.getBasePath() + StrUtil.SLASH);
|
|
||||||
}
|
|
||||||
// 初始化 Ftp 对象
|
// 初始化 Ftp 对象
|
||||||
this.ftp = new Ftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(),
|
this.ftp = new Ftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(),
|
||||||
CharsetUtil.CHARSET_UTF_8, null, null, FtpMode.valueOf(config.getMode()));
|
CharsetUtil.CHARSET_UTF_8, null, null, FtpMode.valueOf(config.getMode()));
|
||||||
|
|
@ -43,8 +37,8 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
||||||
String filePath = getFilePath(path);
|
String filePath = getFilePath(path);
|
||||||
String fileName = FileUtil.getName(filePath);
|
String fileName = FileUtil.getName(filePath);
|
||||||
String dir = StrUtil.removeSuffix(filePath, fileName);
|
String dir = StrUtil.removeSuffix(filePath, fileName);
|
||||||
ftp.reconnectIfTimeout();
|
reconnectIfTimeout();
|
||||||
boolean success = ftp.upload(dir, fileName, new ByteArrayInputStream(content));
|
boolean success = ftp.upload(dir, fileName, new ByteArrayInputStream(content)); // 不需要主动创建目录,ftp 内部已经处理(见源码)
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath));
|
throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath));
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +49,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
||||||
@Override
|
@Override
|
||||||
public void delete(String path) {
|
public void delete(String path) {
|
||||||
String filePath = getFilePath(path);
|
String filePath = getFilePath(path);
|
||||||
ftp.reconnectIfTimeout();
|
reconnectIfTimeout();
|
||||||
ftp.delFile(filePath);
|
ftp.delFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,13 +59,17 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
||||||
String fileName = FileUtil.getName(filePath);
|
String fileName = FileUtil.getName(filePath);
|
||||||
String dir = StrUtil.removeSuffix(filePath, fileName);
|
String dir = StrUtil.removeSuffix(filePath, fileName);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ftp.reconnectIfTimeout();
|
reconnectIfTimeout();
|
||||||
ftp.download(dir, fileName, out);
|
ftp.download(dir, fileName, out);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFilePath(String path) {
|
private String getFilePath(String path) {
|
||||||
return config.getBasePath() + path;
|
return config.getBasePath() + StrUtil.SLASH + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void reconnectIfTimeout() {
|
||||||
|
ftp.reconnectIfTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -18,10 +18,6 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doInit() {
|
protected void doInit() {
|
||||||
// 补全风格。例如说 Linux 是 /,Windows 是 \
|
|
||||||
if (!config.getBasePath().endsWith(File.separator)) {
|
|
||||||
config.setBasePath(config.getBasePath() + File.separator);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -46,7 +42,7 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFilePath(String path) {
|
private String getFilePath(String path) {
|
||||||
return config.getBasePath() + path;
|
return config.getBasePath() + File.separator + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,9 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
||||||
AwsBasicCredentials.create(config.getAccessKey(), config.getAccessSecret()));
|
AwsBasicCredentials.create(config.getAccessKey(), config.getAccessSecret()));
|
||||||
URI endpoint = URI.create(buildEndpoint());
|
URI endpoint = URI.create(buildEndpoint());
|
||||||
S3Configuration serviceConfiguration = S3Configuration.builder() // Path-style 访问
|
S3Configuration serviceConfiguration = S3Configuration.builder() // Path-style 访问
|
||||||
.pathStyleAccessEnabled(Boolean.TRUE.equals(config.getEnablePathStyleAccess())).build();
|
.pathStyleAccessEnabled(Boolean.TRUE.equals(config.getEnablePathStyleAccess()))
|
||||||
|
.chunkedEncodingEnabled(false) // 禁用分块编码,参见 https://t.zsxq.com/kBy57
|
||||||
|
.build();
|
||||||
client = S3Client.builder()
|
client = S3Client.builder()
|
||||||
.credentialsProvider(credentialsProvider)
|
.credentialsProvider(credentialsProvider)
|
||||||
.region(region)
|
.region(region)
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,6 @@ public class SftpFileClient extends AbstractFileClient<SftpFileClientConfig> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doInit() {
|
protected void doInit() {
|
||||||
// 补全风格。例如说 Linux 是 /,Windows 是 \
|
|
||||||
if (!config.getBasePath().endsWith(File.separator)) {
|
|
||||||
config.setBasePath(config.getBasePath() + File.separator);
|
|
||||||
}
|
|
||||||
// 初始化 Ftp 对象
|
// 初始化 Ftp 对象
|
||||||
this.sftp = new Sftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword());
|
this.sftp = new Sftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword());
|
||||||
}
|
}
|
||||||
|
|
@ -35,6 +31,8 @@ public class SftpFileClient extends AbstractFileClient<SftpFileClientConfig> {
|
||||||
// 执行写入
|
// 执行写入
|
||||||
String filePath = getFilePath(path);
|
String filePath = getFilePath(path);
|
||||||
File file = FileUtils.createTempFile(content);
|
File file = FileUtils.createTempFile(content);
|
||||||
|
reconnectIfTimeout();
|
||||||
|
sftp.mkDirs(FileUtil.getParent(filePath, 1)); // 需要创建父目录,不然会报错
|
||||||
sftp.upload(filePath, file);
|
sftp.upload(filePath, file);
|
||||||
// 拼接返回路径
|
// 拼接返回路径
|
||||||
return super.formatFileUrl(config.getDomain(), path);
|
return super.formatFileUrl(config.getDomain(), path);
|
||||||
|
|
@ -43,6 +41,7 @@ public class SftpFileClient extends AbstractFileClient<SftpFileClientConfig> {
|
||||||
@Override
|
@Override
|
||||||
public void delete(String path) {
|
public void delete(String path) {
|
||||||
String filePath = getFilePath(path);
|
String filePath = getFilePath(path);
|
||||||
|
reconnectIfTimeout();
|
||||||
sftp.delFile(filePath);
|
sftp.delFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,12 +49,17 @@ public class SftpFileClient extends AbstractFileClient<SftpFileClientConfig> {
|
||||||
public byte[] getContent(String path) {
|
public byte[] getContent(String path) {
|
||||||
String filePath = getFilePath(path);
|
String filePath = getFilePath(path);
|
||||||
File destFile = FileUtils.createTempFile();
|
File destFile = FileUtils.createTempFile();
|
||||||
|
reconnectIfTimeout();
|
||||||
sftp.download(filePath, destFile);
|
sftp.download(filePath, destFile);
|
||||||
return FileUtil.readBytes(destFile);
|
return FileUtil.readBytes(destFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFilePath(String path) {
|
private String getFilePath(String path) {
|
||||||
return config.getBasePath() + path;
|
return config.getBasePath() + File.separator + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void reconnectIfTimeout() {
|
||||||
|
sftp.reconnectIfTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,10 @@ import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
|
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
|
||||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.tika.Tika;
|
import org.apache.tika.Tika;
|
||||||
|
import org.apache.tika.mime.MimeTypeException;
|
||||||
|
import org.apache.tika.mime.MimeTypes;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -15,12 +18,13 @@ import java.io.IOException;
|
||||||
*
|
*
|
||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class FileTypeUtils {
|
public class FileTypeUtils {
|
||||||
|
|
||||||
private static final ThreadLocal<Tika> TIKA = TransmittableThreadLocal.withInitial(Tika::new);
|
private static final ThreadLocal<Tika> TIKA = TransmittableThreadLocal.withInitial(Tika::new);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得文件的 mineType,对于doc,jar等文件会有误差
|
* 获得文件的 mineType,对于 doc,jar 等文件会有误差
|
||||||
*
|
*
|
||||||
* @param data 文件内容
|
* @param data 文件内容
|
||||||
* @return mineType 无法识别时会返回“application/octet-stream”
|
* @return mineType 无法识别时会返回“application/octet-stream”
|
||||||
|
|
@ -31,7 +35,7 @@ public class FileTypeUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 已知文件名,获取文件类型,在某些情况下比通过字节数组准确,例如使用jar文件时,通过名字更为准确
|
* 已知文件名,获取文件类型,在某些情况下比通过字节数组准确,例如使用 jar 文件时,通过名字更为准确
|
||||||
*
|
*
|
||||||
* @param name 文件名
|
* @param name 文件名
|
||||||
* @return mineType 无法识别时会返回“application/octet-stream”
|
* @return mineType 无法识别时会返回“application/octet-stream”
|
||||||
|
|
@ -51,6 +55,23 @@ public class FileTypeUtils {
|
||||||
return TIKA.get().detect(data, name);
|
return TIKA.get().detect(data, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 mineType 获得文件后缀
|
||||||
|
*
|
||||||
|
* 注意:如果获取不到,或者发生异常,都返回 null
|
||||||
|
*
|
||||||
|
* @param mineType 类型
|
||||||
|
* @return 后缀,例如说 .pdf
|
||||||
|
*/
|
||||||
|
public static String getExtension(String mineType) {
|
||||||
|
try {
|
||||||
|
return MimeTypes.getDefaultMimeTypes().forName(mineType).getExtension();
|
||||||
|
} catch (MimeTypeException e) {
|
||||||
|
log.warn("[getExtension][获取文件后缀({}) 失败]", mineType, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回附件
|
* 返回附件
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,25 @@ public class CodegenEngine {
|
||||||
vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-list.vue"))
|
vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-list.vue"))
|
||||||
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_SCHEMA.getType(), vue3Vben5AntdSchemaTemplatePath("views/modules/list_sub_erp.vue"), // 特殊:主子表专属逻辑
|
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_SCHEMA.getType(), vue3Vben5AntdSchemaTemplatePath("views/modules/list_sub_erp.vue"), // 特殊:主子表专属逻辑
|
||||||
vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-list.vue"))
|
vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-list.vue"))
|
||||||
|
// VUE3_VBEN5_ANTD
|
||||||
|
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_GENERAL.getType(), vue3Vben5AntdGeneralTemplatePath("views/data.ts"),
|
||||||
|
vue3FilePath("views/${table.moduleName}/${table.businessName}/data.ts"))
|
||||||
|
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_GENERAL.getType(), vue3Vben5AntdGeneralTemplatePath("views/index.vue"),
|
||||||
|
vue3FilePath("views/${table.moduleName}/${table.businessName}/index.vue"))
|
||||||
|
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_GENERAL.getType(), vue3Vben5AntdGeneralTemplatePath("views/form.vue"),
|
||||||
|
vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/form.vue"))
|
||||||
|
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_GENERAL.getType(), vue3Vben5AntdGeneralTemplatePath("api/api.ts"),
|
||||||
|
vue3FilePath("api/${table.moduleName}/${table.businessName}/index.ts"))
|
||||||
|
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_GENERAL.getType(), vue3Vben5AntdGeneralTemplatePath("views/modules/form_sub_normal.vue"), // 特殊:主子表专属逻辑
|
||||||
|
vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-form.vue"))
|
||||||
|
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_GENERAL.getType(), vue3Vben5AntdGeneralTemplatePath("views/modules/form_sub_inner.vue"), // 特殊:主子表专属逻辑
|
||||||
|
vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-form.vue"))
|
||||||
|
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_GENERAL.getType(), vue3Vben5AntdGeneralTemplatePath("views/modules/form_sub_erp.vue"), // 特殊:主子表专属逻辑
|
||||||
|
vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-form.vue"))
|
||||||
|
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_GENERAL.getType(), vue3Vben5AntdGeneralTemplatePath("views/modules/list_sub_inner.vue"), // 特殊:主子表专属逻辑
|
||||||
|
vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-list.vue"))
|
||||||
|
.put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_GENERAL.getType(), vue3Vben5AntdGeneralTemplatePath("views/modules/list_sub_erp.vue"), // 特殊:主子表专属逻辑
|
||||||
|
vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-list.vue"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileCreateReq
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePresignedUrlRespVO;
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePresignedUrlRespVO;
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件 Service 接口
|
* 文件 Service 接口
|
||||||
|
|
@ -24,12 +25,24 @@ public interface FileService {
|
||||||
/**
|
/**
|
||||||
* 保存文件,并返回文件的访问路径
|
* 保存文件,并返回文件的访问路径
|
||||||
*
|
*
|
||||||
* @param name 文件名称
|
|
||||||
* @param path 文件路径
|
|
||||||
* @param content 文件内容
|
* @param content 文件内容
|
||||||
|
* @param name 文件名称,允许空
|
||||||
|
* @param directory 目录,允许空
|
||||||
|
* @param type 文件的 MIME 类型,允许空
|
||||||
* @return 文件路径
|
* @return 文件路径
|
||||||
*/
|
*/
|
||||||
String createFile(String name, String path, byte[] content);
|
String createFile(@NotEmpty(message = "文件内容不能为空") byte[] content,
|
||||||
|
String name, String directory, String type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成文件预签名地址信息
|
||||||
|
*
|
||||||
|
* @param name 文件名
|
||||||
|
* @param directory 目录
|
||||||
|
* @return 预签名地址信息
|
||||||
|
*/
|
||||||
|
FilePresignedUrlRespVO getFilePresignedUrl(@NotEmpty(message = "文件名不能为空") String name,
|
||||||
|
String directory);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建文件
|
* 创建文件
|
||||||
|
|
@ -55,12 +68,4 @@ public interface FileService {
|
||||||
*/
|
*/
|
||||||
byte[] getFileContent(Long configId, String path) throws Exception;
|
byte[] getFileContent(Long configId, String path) throws Exception;
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成文件预签名地址信息
|
|
||||||
*
|
|
||||||
* @param path 文件路径
|
|
||||||
* @return 预签名地址信息
|
|
||||||
*/
|
|
||||||
FilePresignedUrlRespVO getFilePresignedUrl(String path) throws Exception;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package cn.iocoder.yudao.module.infra.service.file;
|
package cn.iocoder.yudao.module.infra.service.file;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileCreateReqVO;
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
||||||
|
|
@ -13,11 +15,12 @@ import cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper;
|
||||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient;
|
||||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.FilePresignedUrlRespDTO;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.FilePresignedUrlRespDTO;
|
||||||
import cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils;
|
import cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils;
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS;
|
||||||
|
|
||||||
|
|
@ -29,6 +32,20 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EX
|
||||||
@Service
|
@Service
|
||||||
public class FileServiceImpl implements FileService {
|
public class FileServiceImpl implements FileService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件的前缀,是否包含日期(yyyyMMdd)
|
||||||
|
*
|
||||||
|
* 目的:按照日期,进行分目录
|
||||||
|
*/
|
||||||
|
static boolean PATH_PREFIX_DATE_ENABLE = true;
|
||||||
|
/**
|
||||||
|
* 上传文件的后缀,是否包含时间戳
|
||||||
|
*
|
||||||
|
* 目的:保证文件的唯一性,避免覆盖
|
||||||
|
* 定制:可按需调整成 UUID、或者其他方式
|
||||||
|
*/
|
||||||
|
static boolean PATH_SUFFIX_TIMESTAMP_ENABLE = true;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FileConfigService fileConfigService;
|
private FileConfigService fileConfigService;
|
||||||
|
|
||||||
|
|
@ -42,34 +59,82 @@ public class FileServiceImpl implements FileService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public String createFile(String name, String path, byte[] content) {
|
public String createFile(byte[] content, String name, String directory, String type) {
|
||||||
// 计算默认的 path 名
|
// 1.1 处理 type 为空的情况
|
||||||
String type = FileTypeUtils.getMineType(content, name);
|
if (StrUtil.isEmpty(type)) {
|
||||||
if (StrUtil.isEmpty(path)) {
|
type = FileTypeUtils.getMineType(content, name);
|
||||||
path = FileUtils.generatePath(content, name);
|
|
||||||
}
|
}
|
||||||
// 如果 name 为空,则使用 path 填充
|
// 1.2 处理 name 为空的情况
|
||||||
if (StrUtil.isEmpty(name)) {
|
if (StrUtil.isEmpty(name)) {
|
||||||
name = path;
|
name = DigestUtil.sha256Hex(content);
|
||||||
|
}
|
||||||
|
if (StrUtil.isEmpty(FileUtil.extName(name))) {
|
||||||
|
// 如果 name 没有后缀 type,则补充后缀
|
||||||
|
String extension = FileTypeUtils.getExtension(type);
|
||||||
|
if (StrUtil.isNotEmpty(extension)) {
|
||||||
|
name = name + extension;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上传到文件存储器
|
// 2.1 生成上传的 path,需要保证唯一
|
||||||
|
String path = generateUploadPath(name, directory);
|
||||||
|
// 2.2 上传到文件存储器
|
||||||
FileClient client = fileConfigService.getMasterFileClient();
|
FileClient client = fileConfigService.getMasterFileClient();
|
||||||
Assert.notNull(client, "客户端(master) 不能为空");
|
Assert.notNull(client, "客户端(master) 不能为空");
|
||||||
String url = client.upload(content, path, type);
|
String url = client.upload(content, path, type);
|
||||||
|
|
||||||
// 保存到数据库
|
// 3. 保存到数据库
|
||||||
FileDO file = new FileDO();
|
fileMapper.insert(new FileDO().setConfigId(client.getId())
|
||||||
file.setConfigId(client.getId());
|
.setName(name).setPath(path).setUrl(url)
|
||||||
file.setName(name);
|
.setType(type).setSize(content.length));
|
||||||
file.setPath(path);
|
|
||||||
file.setUrl(url);
|
|
||||||
file.setType(type);
|
|
||||||
file.setSize(content.length);
|
|
||||||
fileMapper.insert(file);
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
String generateUploadPath(String name, String directory) {
|
||||||
|
// 1. 生成前缀、后缀
|
||||||
|
String prefix = null;
|
||||||
|
if (PATH_PREFIX_DATE_ENABLE) {
|
||||||
|
prefix = LocalDateTimeUtil.format(LocalDateTimeUtil.now(), PURE_DATE_PATTERN);
|
||||||
|
}
|
||||||
|
String suffix = null;
|
||||||
|
if (PATH_SUFFIX_TIMESTAMP_ENABLE) {
|
||||||
|
suffix = String.valueOf(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.1 先拼接 suffix 后缀
|
||||||
|
if (StrUtil.isNotEmpty(suffix)) {
|
||||||
|
String ext = FileUtil.extName(name);
|
||||||
|
if (StrUtil.isNotEmpty(ext)) {
|
||||||
|
name = FileUtil.mainName(name) + StrUtil.C_UNDERLINE + suffix + StrUtil.DOT + ext;
|
||||||
|
} else {
|
||||||
|
name = name + StrUtil.C_UNDERLINE + suffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2.2 再拼接 prefix 前缀
|
||||||
|
if (StrUtil.isNotEmpty(prefix)) {
|
||||||
|
name = prefix + StrUtil.SLASH + name;
|
||||||
|
}
|
||||||
|
// 2.3 最后拼接 directory 目录
|
||||||
|
if (StrUtil.isNotEmpty(directory)) {
|
||||||
|
name = directory + StrUtil.SLASH + name;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public FilePresignedUrlRespVO getFilePresignedUrl(String name, String directory) {
|
||||||
|
// 1. 生成上传的 path,需要保证唯一
|
||||||
|
String path = generateUploadPath(name, directory);
|
||||||
|
|
||||||
|
// 2. 获取文件预签名地址
|
||||||
|
FileClient fileClient = fileConfigService.getMasterFileClient();
|
||||||
|
FilePresignedUrlRespDTO presignedObjectUrl = fileClient.getPresignedObjectUrl(path);
|
||||||
|
return BeanUtils.toBean(presignedObjectUrl, FilePresignedUrlRespVO.class,
|
||||||
|
object -> object.setConfigId(fileClient.getId()).setPath(path));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createFile(FileCreateReqVO createReqVO) {
|
public Long createFile(FileCreateReqVO createReqVO) {
|
||||||
FileDO file = BeanUtils.toBean(createReqVO, FileDO.class);
|
FileDO file = BeanUtils.toBean(createReqVO, FileDO.class);
|
||||||
|
|
@ -106,12 +171,4 @@ public class FileServiceImpl implements FileService {
|
||||||
return client.getContent(path);
|
return client.getContent(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public FilePresignedUrlRespVO getFilePresignedUrl(String path) throws Exception {
|
|
||||||
FileClient fileClient = fileConfigService.getMasterFileClient();
|
|
||||||
FilePresignedUrlRespDTO presignedObjectUrl = fileClient.getPresignedObjectUrl(path);
|
|
||||||
return BeanUtils.toBean(presignedObjectUrl, FilePresignedUrlRespVO.class,
|
|
||||||
object -> object.setConfigId(fileClient.getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,349 @@
|
||||||
|
import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
|
||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { OnActionClickFn } from '#/adapter/vxe-table';
|
||||||
|
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
|
||||||
|
import { z } from '#/adapter/form';
|
||||||
|
#if(${table.templateType} == 2)## 树表需要导入这些
|
||||||
|
import { get${simpleClassName}List } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
import { handleTree } from '#/utils/tree';
|
||||||
|
#end
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
||||||
|
import { getRangePickerDefaultProps } from '#/utils/date';
|
||||||
|
import { useAccess } from '@vben/access';
|
||||||
|
|
||||||
|
const { hasAccessByCodes } = useAccess();
|
||||||
|
|
||||||
|
/** 列表的搜索表单 */
|
||||||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "number")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "string")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "boolean")
|
||||||
|
#end
|
||||||
|
{
|
||||||
|
fieldName: '${javaField}',
|
||||||
|
label: '${comment}',
|
||||||
|
#if ($column.htmlType == "input" || $column.htmlType == "textarea" || $column.htmlType == "editor")
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入${comment}',
|
||||||
|
},
|
||||||
|
#elseif ($column.htmlType == "select" || $column.htmlType == "radio")
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
||||||
|
#else## 未设置 dictType 数据字典的情况
|
||||||
|
options: [],
|
||||||
|
#end
|
||||||
|
placeholder: '请选择${comment}',
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "datetime")
|
||||||
|
component: 'RangePicker',
|
||||||
|
componentProps: {
|
||||||
|
...getRangePickerDefaultProps(),
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function useGridColumns(
|
||||||
|
onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>,
|
||||||
|
): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] {
|
||||||
|
return [
|
||||||
|
#if ($table.templateType == 12) ## 内嵌情况
|
||||||
|
{ type: 'expand', width: 80, slots: { content: 'expand_content' } },
|
||||||
|
#end
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
{
|
||||||
|
field: '${javaField}',
|
||||||
|
title: '${comment}',
|
||||||
|
minWidth: 120,
|
||||||
|
#if ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
#elseif("" != $dictType)## 数据字典
|
||||||
|
cellRender: {
|
||||||
|
name: 'CellDict',
|
||||||
|
props: { type: DICT_TYPE.$dictType.toUpperCase() },
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#if (${table.templateType} == 2 && $column.id == $treeNameColumn.id)## 树表特有:标记树节点列
|
||||||
|
treeNode: true,
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
{
|
||||||
|
field: 'operation',
|
||||||
|
title: '操作',
|
||||||
|
minWidth: 200,
|
||||||
|
align: 'center',
|
||||||
|
fixed: 'right',
|
||||||
|
headerAlign: 'center',
|
||||||
|
showOverflow: false,
|
||||||
|
cellRender: {
|
||||||
|
attrs: {
|
||||||
|
nameField: '${columns[0].javaField}',
|
||||||
|
nameTitle: '${table.classComment}',
|
||||||
|
onClick: onActionClick,
|
||||||
|
},
|
||||||
|
name: 'CellOperation',
|
||||||
|
options: [
|
||||||
|
#if (${table.templateType} == 2)## 树表特有操作
|
||||||
|
{
|
||||||
|
code: 'append',
|
||||||
|
text: '新增下级',
|
||||||
|
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:create']),
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
{
|
||||||
|
code: 'edit',
|
||||||
|
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:update']),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: 'delete',
|
||||||
|
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:delete']),
|
||||||
|
#if (${table.templateType} == 2)## 树表禁止删除带有子节点的数据
|
||||||
|
disabled: (row: ${simpleClassName}Api.${simpleClassName}) => {
|
||||||
|
return !!(row.children && row.children.length > 0);
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
## 标准模式和内嵌模式时,主子关系一对一则生成表单schema,一对多则生成列表schema(内嵌模式时表单schema也要生成)。erp 模式时都生成
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subColumns = $subColumnsList.get($index))##当前字段数组
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||||
|
// ==================== 子表($subTable.classComment) ====================
|
||||||
|
|
||||||
|
#if ($table.templateType == 11) ## erp 情况
|
||||||
|
/** 列表的搜索表单 */
|
||||||
|
export function use${subSimpleClassName}GridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "number")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "string")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "boolean")
|
||||||
|
#end
|
||||||
|
{
|
||||||
|
fieldName: '${javaField}',
|
||||||
|
label: '${comment}',
|
||||||
|
#if ($column.htmlType == "input" || $column.htmlType == "textarea" || $column.htmlType == "editor")
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请输入${comment}',
|
||||||
|
},
|
||||||
|
#elseif ($column.htmlType == "select" || $column.htmlType == "radio")
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
||||||
|
#else## 未设置 dictType 数据字典的情况
|
||||||
|
options: [],
|
||||||
|
#end
|
||||||
|
placeholder: '请选择${comment}',
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "datetime")
|
||||||
|
component: 'RangePicker',
|
||||||
|
componentProps: {
|
||||||
|
...getRangePickerDefaultProps(),
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function use${subSimpleClassName}GridColumns(
|
||||||
|
onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>,
|
||||||
|
): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] {
|
||||||
|
return [
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
{
|
||||||
|
field: '${javaField}',
|
||||||
|
title: '${comment}',
|
||||||
|
minWidth: 120,
|
||||||
|
#if ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
#elseif("" != $dictType)## 数据字典
|
||||||
|
cellRender: {
|
||||||
|
name: 'CellDict',
|
||||||
|
props: { type: DICT_TYPE.$dictType.toUpperCase() },
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
{
|
||||||
|
field: 'operation',
|
||||||
|
title: '操作',
|
||||||
|
minWidth: 200,
|
||||||
|
align: 'center',
|
||||||
|
fixed: 'right',
|
||||||
|
headerAlign: 'center',
|
||||||
|
showOverflow: false,
|
||||||
|
cellRender: {
|
||||||
|
attrs: {
|
||||||
|
nameField: '${columns[0].javaField}',
|
||||||
|
nameTitle: '${subTable.classComment}',
|
||||||
|
onClick: onActionClick,
|
||||||
|
},
|
||||||
|
name: 'CellOperation',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
code: 'edit',
|
||||||
|
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:update']),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: 'delete',
|
||||||
|
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:delete']),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#if ($subTable.subJoinMany) ## 一对多
|
||||||
|
/** 新增/修改列表的字段 */
|
||||||
|
export function use${subSimpleClassName}GridEditColumns(
|
||||||
|
onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>,
|
||||||
|
): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] {
|
||||||
|
return [
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if (!$column.primaryKey && $column.listOperationResult && $column.id != $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "number")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "string")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "boolean")
|
||||||
|
#end
|
||||||
|
{
|
||||||
|
field: '${javaField}',
|
||||||
|
title: '${comment}',
|
||||||
|
minWidth: 120,
|
||||||
|
slots: { default: '${javaField}' },
|
||||||
|
#if ($column.htmlType == "select" || $column.htmlType == "checkbox" || $column.htmlType == "radio")
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
params: {
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
||||||
|
},
|
||||||
|
#else
|
||||||
|
params: {
|
||||||
|
options: [],
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
{
|
||||||
|
field: 'operation',
|
||||||
|
title: '操作',
|
||||||
|
minWidth: 60,
|
||||||
|
align: 'center',
|
||||||
|
fixed: 'right',
|
||||||
|
headerAlign: 'center',
|
||||||
|
showOverflow: false,
|
||||||
|
cellRender: {
|
||||||
|
attrs: {
|
||||||
|
nameField: '${columns[0].javaField}',
|
||||||
|
nameTitle: '${table.classComment}',
|
||||||
|
onClick: onActionClick,
|
||||||
|
},
|
||||||
|
name: 'CellOperation',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
code: 'delete',
|
||||||
|
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:delete']),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#if ($table.templateType == 12) ## 内嵌情况
|
||||||
|
/** 列表的字段 */
|
||||||
|
export function use${subSimpleClassName}GridColumns(): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] {
|
||||||
|
return [
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
{
|
||||||
|
field: '${javaField}',
|
||||||
|
title: '${comment}',
|
||||||
|
minWidth: 120,
|
||||||
|
#if ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
#elseif("" != $dictType)## 数据字典
|
||||||
|
cellRender: {
|
||||||
|
name: 'CellDict',
|
||||||
|
props: { type: DICT_TYPE.$dictType.toUpperCase() },
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
@ -0,0 +1,313 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
import type { Rule } from 'ant-design-vue/es/form';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { Tinymce as RichTextarea } from '#/components/tinymce';
|
||||||
|
import { ImageUpload, FileUpload } from "#/components/upload";
|
||||||
|
import { message, Tabs, Form, Input, Textarea, Select, RadioGroup, Radio, CheckboxGroup, Checkbox, DatePicker } from 'ant-design-vue';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
||||||
|
#if($table.templateType == 2)## 树表需要导入这些
|
||||||
|
import { get${simpleClassName}List } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
import { handleTree } from '#/utils/tree';
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||||
|
import ${subSimpleClassName}Form from './${subSimpleClassName_strikeCase}-form.vue'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { get${simpleClassName}, create${simpleClassName}, update${simpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formRef = ref();
|
||||||
|
const labelCol = { span: 5 };
|
||||||
|
const wrapperCol = { span: 13 };
|
||||||
|
const formData = ref<Partial<${simpleClassName}Api.${simpleClassName}>>({
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
});
|
||||||
|
const rules: Record<string, Rule[]> = {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
$column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
};
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
const ${classNameVar}Tree = ref<any[]>([]) // 树形结构
|
||||||
|
#end
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['${table.classComment}'])
|
||||||
|
: $t('ui.actionTitle.create', ['${table.classComment}']);
|
||||||
|
});
|
||||||
|
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
/** 子表的表单 */
|
||||||
|
const subTabsName = ref('$subClassNameVars.get(0)')
|
||||||
|
#foreach ($subClassNameVar in $subClassNameVars)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
const ${subClassNameVar}FormRef = ref<InstanceType<typeof ${subSimpleClassName}Form>>()
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
};
|
||||||
|
formRef.value?.resetFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
/** 获得${table.classComment}树 */
|
||||||
|
const get${simpleClassName}Tree = async () => {
|
||||||
|
${classNameVar}Tree.value = []
|
||||||
|
const data = await get${simpleClassName}List()
|
||||||
|
const root: Tree = { id: 0, name: '顶级${table.classComment}', children: [] }
|
||||||
|
root.children = handleTree(data, 'id', '${treeParentColumn.javaField}')
|
||||||
|
${classNameVar}Tree.value.push(root)
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
await formRef.value?.validate();
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
// 校验子表单
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#if ($subTable.subJoinMany) ## 一对多
|
||||||
|
## TODO 列表值校验?
|
||||||
|
#else
|
||||||
|
const ${subClassNameVar}Valid = await ${subClassNameVar}FormRef.value?.validate();
|
||||||
|
if (!${subClassNameVar}Valid) {
|
||||||
|
subTabsName.value = '${subClassNameVar}';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = formData.value as ${simpleClassName}Api.${simpleClassName};
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
// 拼接子表的数据
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#if ($subTable.subJoinMany)
|
||||||
|
data.${subClassNameVar}s = ${subClassNameVar}FormRef.value?.getData();
|
||||||
|
#else
|
||||||
|
data.${subClassNameVar} = await ${subClassNameVar}FormRef.value?.getValues();
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
try {
|
||||||
|
await (formData.value?.id ? update${simpleClassName}(data) : create${simpleClassName}(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
message.success({
|
||||||
|
content: $t('ui.actionMessage.operationSuccess'),
|
||||||
|
key: 'action_process_msg',
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
resetForm()
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<${simpleClassName}Api.${simpleClassName}>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await get${simpleClassName}(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
formData.value = data;
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
// 加载树数据
|
||||||
|
await get${simpleClassName}Tree()
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<Form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
:label-col="labelCol"
|
||||||
|
:wrapper-col="wrapperCol"
|
||||||
|
>
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "number")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "string")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "boolean")
|
||||||
|
#end
|
||||||
|
#if ( $table.templateType == 2 && $column.id == $treeParentColumn.id )
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<TreeSelect
|
||||||
|
v-model:value="formData.${javaField}"
|
||||||
|
:treeData="${classNameVar}Tree"
|
||||||
|
#if ($treeNameColumn.javaField == "name")
|
||||||
|
:fieldNames="defaultProps"
|
||||||
|
#else
|
||||||
|
:fieldNames="{...defaultProps, label: '$treeNameColumn.javaField'}"
|
||||||
|
#end
|
||||||
|
checkable
|
||||||
|
treeDefaultExpandAll
|
||||||
|
placeholder="请选择${comment}"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<Input v-model:value="formData.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</Form.Item>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<ImageUpload v-model:value="formData.${javaField}" />
|
||||||
|
</Form.Item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<FileUpload v-model:value="formData.${javaField}" />
|
||||||
|
</Form.Item>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<RichTextarea v-model="formData.${javaField}" height="500px" />
|
||||||
|
</Form.Item>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<Select v-model:value="formData.${javaField}" placeholder="请选择${comment}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<Select.Option
|
||||||
|
v-for="dict in getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod')"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else##没数据字典
|
||||||
|
<Select.Option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<CheckboxGroup v-model:value="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<Checkbox
|
||||||
|
v-for="dict in getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod')"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else##没数据字典
|
||||||
|
<Checkbox label="请选择字典生成" />
|
||||||
|
#end
|
||||||
|
</CheckboxGroup>
|
||||||
|
</Form.Item>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<RadioGroup v-model:value="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<Radio
|
||||||
|
v-for="dict in getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod')"
|
||||||
|
:key="dict.value"
|
||||||
|
:value="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</Radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<Radio value="1">请选择字典生成</Radio>
|
||||||
|
#end
|
||||||
|
</RadioGroup>
|
||||||
|
</Form.Item>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<DatePicker
|
||||||
|
v-model:value="formData.${javaField}"
|
||||||
|
valueFormat="x"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<Textarea v-model:value="formData.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</Form.Item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</Form>
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<Tabs v-model:active-key="subTabsName">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<Tabs.TabPane key="$subClassNameVar" tab="${subTable.classComment}" force-render>
|
||||||
|
<${subSimpleClassName}Form ref="${subClassNameVar}FormRef" :${subJoinColumn_strikeCase}="formData?.id" />
|
||||||
|
</Tabs.TabPane>
|
||||||
|
#end
|
||||||
|
</Tabs>
|
||||||
|
#end
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,357 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { formatDateTime } from '@vben/utils';
|
||||||
|
import { Button, message,Tabs,Pagination,Form,RangePicker,DatePicker,Select,Input } from 'ant-design-vue';
|
||||||
|
import { DictTag } from '#/components/dict-tag';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
||||||
|
import ${simpleClassName}Form from './modules/form.vue';
|
||||||
|
import { Download, Plus, RefreshCw, Search } from '@vben/icons';
|
||||||
|
import { ContentWrap } from "#/components/content-wrap";
|
||||||
|
import { VxeColumn, VxeTable } from 'vxe-table';
|
||||||
|
import { getRangePickerDefaultProps } from '#/utils/date';
|
||||||
|
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 || $table.templateType == 12 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||||
|
import ${subSimpleClassName}List from './modules/${subSimpleClassName_strikeCase}-list.vue'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
import { ref, h, reactive,onMounted } from 'vue';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
#if (${table.templateType} == 2)## 树表接口
|
||||||
|
import { handleTree } from '@/utils/tree'
|
||||||
|
import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
#else## 标准表接口
|
||||||
|
import { get${simpleClassName}Page, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
#end
|
||||||
|
import { downloadByData } from '#/utils/download';
|
||||||
|
|
||||||
|
#if ($table.templateType == 12 || $table.templateType == 11) ## 内嵌和erp情况
|
||||||
|
/** 子表的列表 */
|
||||||
|
const subTabsName = ref('$subClassNameVars.get(0)')
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
const select${simpleClassName} = ref<${simpleClassName}Api.${simpleClassName}>();
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
const loading = ref(true) // 列表的加载中
|
||||||
|
const list = ref<${simpleClassName}Api.${simpleClassName}[]>([]) // 列表的数据
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
const total = ref(0) // 列表的总页数
|
||||||
|
#end
|
||||||
|
const queryParams = reactive({
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
#end
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#if ($column.listOperationCondition != 'BETWEEN')
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#if ($column.htmlType == "datetime" || $column.listOperationCondition == "BETWEEN")
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const queryFormRef = ref() // 搜索的表单
|
||||||
|
const exportLoading = ref(false) // 导出的加载中
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
const data = await get${simpleClassName}List(queryParams)
|
||||||
|
list.value = handleTree(data, 'id', '${treeParentColumn.javaField}')
|
||||||
|
#else
|
||||||
|
const data = await get${simpleClassName}Page(queryParams)
|
||||||
|
list.value = data.list
|
||||||
|
total.value = data.total
|
||||||
|
#end
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields()
|
||||||
|
handleQuery()
|
||||||
|
}
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: ${simpleClassName}Form,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建${table.classComment} */
|
||||||
|
function onCreate() {
|
||||||
|
formModalApi.setData({}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑${table.classComment} */
|
||||||
|
function onEdit(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (${table.templateType} == 2)## 树表特有:新增下级
|
||||||
|
/** 新增下级${table.classComment} */
|
||||||
|
function onAppend(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||||
|
formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open();
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** 删除${table.classComment} */
|
||||||
|
async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||||
|
const hideLoading = message.loading({
|
||||||
|
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||||
|
duration: 0,
|
||||||
|
key: 'action_process_msg',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await delete${simpleClassName}(row.id as number);
|
||||||
|
message.success({
|
||||||
|
content: $t('ui.actionMessage.deleteSuccess', [row.id]),
|
||||||
|
key: 'action_process_msg',
|
||||||
|
});
|
||||||
|
await getList();
|
||||||
|
} catch {
|
||||||
|
hideLoading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出表格 */
|
||||||
|
async function onExport() {
|
||||||
|
try {
|
||||||
|
exportLoading.value = true;
|
||||||
|
const data = await export${simpleClassName}(queryParams);
|
||||||
|
downloadByData(data, '${table.classComment}.xls');
|
||||||
|
}finally {
|
||||||
|
exportLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始化 **/
|
||||||
|
onMounted(() => {
|
||||||
|
getList()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<FormModal @success="getList" />
|
||||||
|
|
||||||
|
<ContentWrap>
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<Form
|
||||||
|
class="-mb-15px"
|
||||||
|
:model="queryParams"
|
||||||
|
ref="queryFormRef"
|
||||||
|
layout="inline"
|
||||||
|
>
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "number")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "string")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "boolean")
|
||||||
|
#end
|
||||||
|
#if ($column.htmlType == "input")
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<Input
|
||||||
|
v-model:value="queryParams.${javaField}"
|
||||||
|
placeholder="请输入${comment}"
|
||||||
|
allowClear
|
||||||
|
@pressEnter="handleQuery"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
#elseif ($column.htmlType == "select" || $column.htmlType == "radio" || $column.htmlType == "checkbox")
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<Select
|
||||||
|
v-model:value="queryParams.${javaField}"
|
||||||
|
placeholder="请选择${comment}"
|
||||||
|
allowClear
|
||||||
|
class="!w-240px"
|
||||||
|
>
|
||||||
|
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
||||||
|
<Select.Option
|
||||||
|
v-for="dict in getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod')"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else## 未设置 dictType 数据字典的情况
|
||||||
|
<Select.Option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
#elseif($column.htmlType == "datetime")
|
||||||
|
#if ($column.listOperationCondition != "BETWEEN")## 非范围
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<DatePicker
|
||||||
|
v-model:value="queryParams.${javaField}"
|
||||||
|
valueFormat="YYYY-MM-DD"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
allowClear
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
#else## 范围
|
||||||
|
<Form.Item label="${comment}" name="${javaField}">
|
||||||
|
<RangePicker
|
||||||
|
v-model:value="queryParams.${javaField}"
|
||||||
|
v-bind="getRangePickerDefaultProps()"
|
||||||
|
class="!w-220px"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<Form.Item>
|
||||||
|
<Button class="ml-2" @click="handleQuery" :icon="h(Search)">搜索</Button>
|
||||||
|
<Button class="ml-2" @click="resetQuery" :icon="h(RefreshCw)">重置</Button>
|
||||||
|
<Button
|
||||||
|
class="ml-2"
|
||||||
|
:icon="h(Plus)"
|
||||||
|
type="primary"
|
||||||
|
@click="onCreate"
|
||||||
|
v-access:code="['${permissionPrefix}:create']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.create', ['示例联系人']) }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
:icon="h(Download)"
|
||||||
|
type="primary"
|
||||||
|
class="ml-2"
|
||||||
|
:loading="exportLoading"
|
||||||
|
@click="onExport"
|
||||||
|
v-access:code="['${permissionPrefix}:export']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.export') }}
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap>
|
||||||
|
<vxe-table :data="list" show-overflow :loading="loading">
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
|
||||||
|
<!-- 子表的列表 -->
|
||||||
|
<vxe-column type="expand" width="60">
|
||||||
|
<template #content="{ row }">
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<Tabs v-model:active-key="subTabsName" class="mx-8">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<Tabs.TabPane key="$subClassNameVar" tab="${subTable.classComment}" force-render>
|
||||||
|
<${subSimpleClassName}List :${subJoinColumn_strikeCase}="row?.id" />
|
||||||
|
</Tabs.TabPane>
|
||||||
|
#end
|
||||||
|
</Tabs>
|
||||||
|
</template>
|
||||||
|
</vxe-column>
|
||||||
|
#end
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#set ($dictType=$column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment=$column.columnComment)
|
||||||
|
#if ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
|
<vxe-column field="${javaField}" title="${comment}" align="center">
|
||||||
|
<template #default="{row}">
|
||||||
|
{{formatDateTime(row.${javaField})}}
|
||||||
|
</template>
|
||||||
|
</vxe-column>
|
||||||
|
#elseif($column.dictType && "" != $column.dictType)## 数据字典
|
||||||
|
<vxe-column field="${javaField}" title="${comment}" align="center">
|
||||||
|
<template #default="{row}">
|
||||||
|
<dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="row.${javaField}" />
|
||||||
|
</template>
|
||||||
|
</vxe-column>
|
||||||
|
#else
|
||||||
|
<vxe-column field="${javaField}" title="${comment}" align="center" />
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<vxe-column field="operation" title="操作" align="center">
|
||||||
|
<template #default="{row}">
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
type="link"
|
||||||
|
@click="onEdit(row as any)"
|
||||||
|
v-access:code="['${permissionPrefix}:update']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.edit') }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
type="link"
|
||||||
|
class="ml-2"
|
||||||
|
@click="onDelete(row as any)"
|
||||||
|
v-access:code="['${permissionPrefix}:delete']"
|
||||||
|
>
|
||||||
|
{{ $t('ui.actionTitle.delete') }}
|
||||||
|
</Button>
|
||||||
|
</template>
|
||||||
|
</vxe-column>
|
||||||
|
</vxe-table>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<div class="mt-2 flex justify-end">
|
||||||
|
<Pagination
|
||||||
|
:total="total"
|
||||||
|
v-model:current="queryParams.pageNo"
|
||||||
|
v-model:page-size="queryParams.pageSize"
|
||||||
|
show-size-changer
|
||||||
|
@change="getList"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
#if ($table.templateType == 11) ## erp情况
|
||||||
|
<ContentWrap>
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<Tabs v-model:active-key="subTabsName">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<Tabs.TabPane key="$subClassNameVar" tab="${subTable.classComment}" force-render>
|
||||||
|
<${subSimpleClassName}List :${subJoinColumn_strikeCase}="select${simpleClassName}?.id" />
|
||||||
|
</Tabs.TabPane>
|
||||||
|
#end
|
||||||
|
</Tabs>
|
||||||
|
</ContentWrap>
|
||||||
|
#end
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
#set ($subTable = $subTables.get($subIndex))##当前表
|
||||||
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import { get${subSimpleClassName}, create${subSimpleClassName}, update${subSimpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
|
||||||
|
import { use${subSimpleClassName}FormSchema } from '../data';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<${simpleClassName}Api.${subSimpleClassName}>();
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return formData.value?.id
|
||||||
|
? $t('ui.actionTitle.edit', ['${subTable.classComment}'])
|
||||||
|
: $t('ui.actionTitle.create', ['${subTable.classComment}']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: use${subSimpleClassName}FormSchema(),
|
||||||
|
showDefaultActions: false
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
const data = (await formApi.getValues()) as ${simpleClassName}Api.${subSimpleClassName};
|
||||||
|
data.${subJoinColumn.javaField} = formData.value?.${subJoinColumn.javaField};
|
||||||
|
try {
|
||||||
|
await (formData.value?.id ? update${subSimpleClassName}(data) : create${subSimpleClassName}(data));
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
message.success({
|
||||||
|
content: $t('ui.actionMessage.operationSuccess'),
|
||||||
|
key: 'action_process_msg',
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
formData.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载数据
|
||||||
|
let data = modalApi.getData<${simpleClassName}Api.${subSimpleClassName}>();
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.id) {
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
data = await get${subSimpleClassName}(data.id);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle">
|
||||||
|
<Form class="mx-4" />
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
## 主表的 normal 和 inner 使用相同的 form 表单
|
||||||
|
#parse("codegen/vue3_vben5_antd/schema/views/modules/form_sub_normal.vue.vm")
|
||||||
|
|
@ -0,0 +1,199 @@
|
||||||
|
#set ($subTable = $subTables.get($subIndex))##当前表
|
||||||
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($subIndex))
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
|
||||||
|
import { computed, ref, h, onMounted,watch,nextTick } from 'vue';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
#if ($subTable.subJoinMany) ## 一对多
|
||||||
|
import { Plus } from "@vben/icons";
|
||||||
|
import { Button, Tabs, Checkbox, Input, Textarea, Select,RadioGroup,CheckboxGroup, DatePicker } from 'ant-design-vue';
|
||||||
|
import type { OnActionClickParams } from '#/adapter/vxe-table';
|
||||||
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import { use${subSimpleClassName}GridEditColumns } from '../data';
|
||||||
|
import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
#else
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import { use${subSimpleClassName}FormSchema } from '../data';
|
||||||
|
import { get${subSimpleClassName}By${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
#end
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段)
|
||||||
|
}>()
|
||||||
|
|
||||||
|
#if ($subTable.subJoinMany) ## 一对多
|
||||||
|
/** 表格操作按钮的回调函数 */
|
||||||
|
function onActionClick({
|
||||||
|
code,
|
||||||
|
row,
|
||||||
|
}: OnActionClickParams<${simpleClassName}Api.${subSimpleClassName}>) {
|
||||||
|
switch (code) {
|
||||||
|
case 'delete': {
|
||||||
|
onDelete(row);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
gridOptions: {
|
||||||
|
columns: use${subSimpleClassName}GridEditColumns(onActionClick),
|
||||||
|
border: true,
|
||||||
|
showOverflow: true,
|
||||||
|
autoResize: true,
|
||||||
|
keepSource: true,
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
},
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 添加${subTable.classComment} */
|
||||||
|
const onAdd = async () => {
|
||||||
|
await gridApi.grid.insertAt({} as ${simpleClassName}Api.${subSimpleClassName}, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除${subTable.classComment} */
|
||||||
|
const onDelete = async (row: ${simpleClassName}Api.${subSimpleClassName}) => {
|
||||||
|
await gridApi.grid.remove(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 提供获取表格数据的方法供父组件调用 */
|
||||||
|
defineExpose({
|
||||||
|
getData: (): ${simpleClassName}Api.${subSimpleClassName}[] => {
|
||||||
|
const data = gridApi.grid.getData() as ${simpleClassName}Api.${subSimpleClassName}[];
|
||||||
|
const removeRecords = gridApi.grid.getRemoveRecords() as ${simpleClassName}Api.${subSimpleClassName}[];
|
||||||
|
const insertRecords = gridApi.grid.getInsertRecords() as ${simpleClassName}Api.${subSimpleClassName}[];
|
||||||
|
return data
|
||||||
|
.filter((row) => !removeRecords.some((removed) => removed.id === row.id))
|
||||||
|
.concat(insertRecords.map((row: any) => ({ ...row, id: undefined })));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.${subJoinColumn.javaField},
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await gridApi.grid.loadData(await get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField}!));
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
#else
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: use${subSimpleClassName}FormSchema(),
|
||||||
|
showDefaultActions: false
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 暴露出表单校验方法和表单值获取方法 */
|
||||||
|
defineExpose({
|
||||||
|
validate: async () => {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
return valid;
|
||||||
|
},
|
||||||
|
getValues: formApi.getValues,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.${subJoinColumn.javaField},
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await formApi.setValues(await get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField}!));
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
#end
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
#if ($subTable.subJoinMany) ## 一对多
|
||||||
|
<Grid class="mx-4">
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<template #${javaField}="{ row }">
|
||||||
|
<Input v-model:value="row.${javaField}" />
|
||||||
|
</template>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
<template #${javaField}="{ row }">
|
||||||
|
<UploadImg v-model:value="row.${javaField}" />
|
||||||
|
</template>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
<template #${javaField}="{ row }">
|
||||||
|
<UploadFile v-model:value="row.${javaField}" />
|
||||||
|
</template>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
<template #${javaField}="{ row }">
|
||||||
|
<Textarea v-model:value="row.${javaField}" />
|
||||||
|
</template>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<template #${javaField}="{ row, column }">
|
||||||
|
<Select v-model:value="row.${javaField}" class="w-full">
|
||||||
|
<Select.Option v-for="option in column.params.options" :key="option.value" :value="option.value">
|
||||||
|
{{ option.label }}
|
||||||
|
</Select.Option>
|
||||||
|
</Select>
|
||||||
|
</template>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<template #${javaField}="{ row, column }">
|
||||||
|
<CheckboxGroup v-model:value="row.${javaField}" :options="column.params.options" />
|
||||||
|
</template>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<template #${javaField}="{ row, column }">
|
||||||
|
<RadioGroup v-model:value="row.${javaField}" :options="column.params.options" />
|
||||||
|
</template>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<template #${javaField}="{ row }">
|
||||||
|
<DatePicker
|
||||||
|
v-model:value="row.${javaField}"
|
||||||
|
:showTime="true"
|
||||||
|
format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
valueFormat='x'
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<template #${javaField}="{ row }">
|
||||||
|
<Textarea v-model:value="row.${javaField}" />
|
||||||
|
</template>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</Grid>
|
||||||
|
<div class="flex justify-center -mt-4">
|
||||||
|
<Button :icon="h(Plus)" type="primary" ghost @click="onAdd" v-access:code="['${subTable.moduleName}:${simpleClassName_strikeCase}:create']">
|
||||||
|
{{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
#else
|
||||||
|
<Form class="mx-4" />
|
||||||
|
#end
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,184 @@
|
||||||
|
#set ($subTable = $subTables.get($subIndex))##当前表
|
||||||
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($subIndex))
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
|
||||||
|
#if ($table.templateType == 11) ## erp
|
||||||
|
import ${subSimpleClassName}Form from './${subSimpleClassName_strikeCase}-form.vue'
|
||||||
|
#end
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { Button, message } from 'ant-design-vue';
|
||||||
|
import { Plus } from '@vben/icons';
|
||||||
|
import { #if($table.templateType != 11)ref,#end h, nextTick,watch } from 'vue';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
|
||||||
|
|
||||||
|
#if ($table.templateType == 11) ## erp
|
||||||
|
import { delete${subSimpleClassName}, get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data';
|
||||||
|
#else
|
||||||
|
#if ($subTable.subJoinMany) ## 一对多
|
||||||
|
import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
#else
|
||||||
|
import { get${subSimpleClassName}By${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
#end
|
||||||
|
import { use${subSimpleClassName}GridColumns } from '../data';
|
||||||
|
#end
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段)
|
||||||
|
}>()
|
||||||
|
|
||||||
|
#if ($table.templateType == 11) ## erp
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: ${subSimpleClassName}Form,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 创建${subTable.classComment} */
|
||||||
|
function onCreate() {
|
||||||
|
if (!props.${subJoinColumn.javaField}){
|
||||||
|
message.warning("请先选择一个${table.classComment}!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
formModalApi.setData({${subJoinColumn.javaField}: props.${subJoinColumn.javaField}}).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑${subTable.classComment} */
|
||||||
|
function onEdit(row: ${simpleClassName}Api.${subSimpleClassName}) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除${subTable.classComment} */
|
||||||
|
async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) {
|
||||||
|
const hideLoading = message.loading({
|
||||||
|
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||||
|
duration: 0,
|
||||||
|
key: 'action_process_msg',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await delete${subSimpleClassName}(row.id as number);
|
||||||
|
message.success({
|
||||||
|
content: $t('ui.actionMessage.deleteSuccess', [row.id]),
|
||||||
|
key: 'action_process_msg',
|
||||||
|
});
|
||||||
|
onRefresh();
|
||||||
|
} catch {
|
||||||
|
hideLoading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 表格操作按钮的回调函数 */
|
||||||
|
function onActionClick({
|
||||||
|
code,
|
||||||
|
row,
|
||||||
|
}: OnActionClickParams<${simpleClassName}Api.${subSimpleClassName}>) {
|
||||||
|
switch (code) {
|
||||||
|
case 'edit': {
|
||||||
|
onEdit(row);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'delete': {
|
||||||
|
onDelete(row);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
formOptions: {
|
||||||
|
schema: use${subSimpleClassName}GridFormSchema(),
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
gridOptions: {
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
columns: use${subSimpleClassName}GridColumns(onActionClick),
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
if (!props.${subJoinColumn.javaField}){
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return await get${subSimpleClassName}Page({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
${subJoinColumn.javaField}: props.${subJoinColumn.javaField},
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: { code: 'query' },
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
#else
|
||||||
|
columns: use${subSimpleClassName}GridColumns(),
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
height: '600px',
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
const onRefresh = async ()=> {
|
||||||
|
#if ($table.templateType == 11) ## erp
|
||||||
|
await gridApi.query();
|
||||||
|
#else
|
||||||
|
#if ($subTable.subJoinMany) ## 一对多
|
||||||
|
await gridApi.grid.loadData(await get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField}!));
|
||||||
|
#else
|
||||||
|
await gridApi.grid.loadData([await get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField}!)]);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.${subJoinColumn.javaField},
|
||||||
|
async (val) => {
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
await onRefresh()
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
#if ($table.templateType == 11) ## erp
|
||||||
|
<FormModal @success="onRefresh" />
|
||||||
|
<Grid table-title="${subTable.classComment}列表">
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']">
|
||||||
|
{{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }}
|
||||||
|
</Button>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
#else
|
||||||
|
<Grid table-title="${subTable.classComment}列表" />
|
||||||
|
#end
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
## 子表的 erp 和 inner 使用相似的 list 列表,差异主要两点:
|
||||||
|
## 1)inner 使用 list 不分页,erp 使用 page 分页
|
||||||
|
## 2)erp 支持单个子表的新增、修改、删除,inner 不支持
|
||||||
|
#parse("codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm")
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
|
|
||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
import type { OnActionClickFn } from '#/adapter/vxe-table';
|
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
||||||
|
|
||||||
import { z } from '#/adapter/form';
|
import { z } from '#/adapter/form';
|
||||||
|
|
@ -40,7 +39,6 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||||
});
|
});
|
||||||
return handleTree(data);
|
return handleTree(data);
|
||||||
},
|
},
|
||||||
class: 'w-full',
|
|
||||||
labelField: '${treeNameColumn.javaField}',
|
labelField: '${treeNameColumn.javaField}',
|
||||||
valueField: 'id',
|
valueField: 'id',
|
||||||
childrenField: 'children',
|
childrenField: 'children',
|
||||||
|
|
@ -75,18 +73,10 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: '请输入${comment}',
|
placeholder: '请输入${comment}',
|
||||||
},
|
},
|
||||||
#elseif($column.htmlType == "imageUpload")## 图片上传 TODO @puhui999:目前分成了图片和文件上传,可以不用 fileType 之类哈,可以用下;
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
component: 'FileUpload',
|
component: 'ImageUpload',
|
||||||
componentProps: {
|
|
||||||
fileType: 'image',
|
|
||||||
maxCount: 1,
|
|
||||||
},
|
|
||||||
#elseif($column.htmlType == "fileUpload")## 文件上传
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
component: 'FileUpload',
|
component: 'FileUpload',
|
||||||
componentProps: {
|
|
||||||
fileType: 'file',
|
|
||||||
maxCount: 1,
|
|
||||||
},
|
|
||||||
#elseif($column.htmlType == "editor")## 文本编辑器
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
component: 'RichTextarea',
|
component: 'RichTextarea',
|
||||||
#elseif($column.htmlType == "select")## 下拉框
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
|
@ -98,7 +88,6 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||||
options: [],
|
options: [],
|
||||||
#end
|
#end
|
||||||
placeholder: '请选择${comment}',
|
placeholder: '请选择${comment}',
|
||||||
class: 'w-full',
|
|
||||||
},
|
},
|
||||||
#elseif($column.htmlType == "checkbox")## 多选框
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
component: 'Checkbox',
|
component: 'Checkbox',
|
||||||
|
|
@ -136,7 +125,6 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||||
component: 'InputNumber',
|
component: 'InputNumber',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
min: 0,
|
min: 0,
|
||||||
class: 'w-full',
|
|
||||||
controlsPosition: 'right',
|
controlsPosition: 'right',
|
||||||
placeholder: '请输入${comment}',
|
placeholder: '请输入${comment}',
|
||||||
},
|
},
|
||||||
|
|
@ -320,17 +308,9 @@ export function use${subSimpleClassName}FormSchema(): VbenFormSchema[] {
|
||||||
placeholder: '请输入${comment}',
|
placeholder: '请输入${comment}',
|
||||||
},
|
},
|
||||||
#elseif($column.htmlType == "imageUpload")## 图片上传
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
component: 'FileUpload',
|
component: 'ImageUpload',
|
||||||
componentProps: {
|
|
||||||
fileType: 'image',
|
|
||||||
maxCount: 1,
|
|
||||||
},
|
|
||||||
#elseif($column.htmlType == "fileUpload")## 文件上传
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
component: 'FileUpload',
|
component: 'FileUpload',
|
||||||
componentProps: {
|
|
||||||
fileType: 'file',
|
|
||||||
maxCount: 1,
|
|
||||||
},
|
|
||||||
#elseif($column.htmlType == "editor")## 文本编辑器
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
component: 'RichTextarea',
|
component: 'RichTextarea',
|
||||||
#elseif($column.htmlType == "select")## 下拉框
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
|
@ -342,7 +322,6 @@ export function use${subSimpleClassName}FormSchema(): VbenFormSchema[] {
|
||||||
options: [],
|
options: [],
|
||||||
#end
|
#end
|
||||||
placeholder: '请选择${comment}',
|
placeholder: '请选择${comment}',
|
||||||
class: 'w-full',
|
|
||||||
},
|
},
|
||||||
#elseif($column.htmlType == "checkbox")## 多选框
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
component: 'Checkbox',
|
component: 'Checkbox',
|
||||||
|
|
@ -380,7 +359,6 @@ export function use${subSimpleClassName}FormSchema(): VbenFormSchema[] {
|
||||||
component: 'InputNumber',
|
component: 'InputNumber',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
min: 0,
|
min: 0,
|
||||||
class: 'w-full',
|
|
||||||
controlsPosition: 'right',
|
controlsPosition: 'right',
|
||||||
placeholder: '请输入${comment}',
|
placeholder: '请输入${comment}',
|
||||||
},
|
},
|
||||||
|
|
@ -603,17 +581,9 @@ export function use${subSimpleClassName}GridColumns(
|
||||||
placeholder: '请输入${comment}',
|
placeholder: '请输入${comment}',
|
||||||
},
|
},
|
||||||
#elseif($column.htmlType == "imageUpload")## 图片上传
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
component: 'FileUpload',
|
component: 'ImageUpload',
|
||||||
componentProps: {
|
|
||||||
fileType: 'image',
|
|
||||||
maxCount: 1,
|
|
||||||
},
|
|
||||||
#elseif($column.htmlType == "fileUpload")## 文件上传
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
component: 'FileUpload',
|
component: 'FileUpload',
|
||||||
componentProps: {
|
|
||||||
fileType: 'file',
|
|
||||||
maxCount: 1,
|
|
||||||
},
|
|
||||||
#elseif($column.htmlType == "editor")## 文本编辑器
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
component: 'RichTextarea',
|
component: 'RichTextarea',
|
||||||
#elseif($column.htmlType == "select")## 下拉框
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
|
@ -625,7 +595,6 @@ export function use${subSimpleClassName}GridColumns(
|
||||||
options: [],
|
options: [],
|
||||||
#end
|
#end
|
||||||
placeholder: '请选择${comment}',
|
placeholder: '请选择${comment}',
|
||||||
class: 'w-full',
|
|
||||||
},
|
},
|
||||||
#elseif($column.htmlType == "checkbox")## 多选框
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
component: 'Checkbox',
|
component: 'Checkbox',
|
||||||
|
|
@ -663,7 +632,6 @@ export function use${subSimpleClassName}GridColumns(
|
||||||
component: 'InputNumber',
|
component: 'InputNumber',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
min: 0,
|
min: 0,
|
||||||
class: 'w-full',
|
|
||||||
controlsPosition: 'right',
|
controlsPosition: 'right',
|
||||||
placeholder: '请输入${comment}',
|
placeholder: '请输入${comment}',
|
||||||
},
|
},
|
||||||
|
|
@ -706,4 +674,4 @@ export function use${subSimpleClassName}GridColumns(
|
||||||
|
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,13 @@ const getTitle = computed(() => {
|
||||||
#end
|
#end
|
||||||
|
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
layout: 'horizontal',
|
layout: 'horizontal',
|
||||||
schema: useFormSchema(),
|
schema: useFormSchema(),
|
||||||
showDefaultActions: false
|
showDefaultActions: false
|
||||||
|
|
@ -113,7 +120,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
key: 'action_process_msg',
|
key: 'action_process_msg',
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.lock(false);
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async onOpenChange(isOpen: boolean) {
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
|
@ -132,7 +139,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
try {
|
try {
|
||||||
data = await get${simpleClassName}(data.id);
|
data = await get${simpleClassName}(data.id);
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.lock(false);
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 设置到 values
|
// 设置到 values
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,13 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
layout: 'horizontal',
|
layout: 'horizontal',
|
||||||
schema: use${subSimpleClassName}FormSchema(),
|
schema: use${subSimpleClassName}FormSchema(),
|
||||||
showDefaultActions: false
|
showDefaultActions: false
|
||||||
|
|
@ -50,7 +57,7 @@
|
||||||
key: 'action_process_msg',
|
key: 'action_process_msg',
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.lock(false);
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async onOpenChange(isOpen: boolean) {
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
|
@ -69,7 +76,7 @@
|
||||||
try {
|
try {
|
||||||
data = await get${subSimpleClassName}(data.id);
|
data = await get${subSimpleClassName}(data.id);
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.lock(false);
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 设置到 values
|
// 设置到 values
|
||||||
|
|
|
||||||
|
|
@ -96,9 +96,16 @@ watch(
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
layout: 'horizontal',
|
commonConfig: {
|
||||||
schema: use${subSimpleClassName}FormSchema(),
|
componentProps: {
|
||||||
showDefaultActions: false
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: use${subSimpleClassName}FormSchema(),
|
||||||
|
showDefaultActions: false
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 暴露出表单校验方法和表单值获取方法 */
|
/** 暴露出表单校验方法和表单值获取方法 */
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,23 @@ import cn.iocoder.yudao.module.infra.framework.file.core.client.ftp.FtpFileClien
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link FtpFileClient} 集成测试
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
public class FtpFileClientTest {
|
public class FtpFileClientTest {
|
||||||
|
|
||||||
|
// docker run -d \
|
||||||
|
// -p 2121:21 -p 30000-30009:30000-30009 \
|
||||||
|
// -e FTP_USER=foo \
|
||||||
|
// -e FTP_PASS=pass \
|
||||||
|
// -e PASV_ADDRESS=127.0.0.1 \
|
||||||
|
// -e PASV_MIN_PORT=30000 \
|
||||||
|
// -e PASV_MAX_PORT=30009 \
|
||||||
|
// -v $(pwd)/ftp-data:/home/vsftpd \
|
||||||
|
// fauria/vsftpd
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
public void test() {
|
public void test() {
|
||||||
|
|
@ -17,10 +32,10 @@ public class FtpFileClientTest {
|
||||||
FtpFileClientConfig config = new FtpFileClientConfig();
|
FtpFileClientConfig config = new FtpFileClientConfig();
|
||||||
config.setDomain("http://127.0.0.1:48080");
|
config.setDomain("http://127.0.0.1:48080");
|
||||||
config.setBasePath("/home/ftp");
|
config.setBasePath("/home/ftp");
|
||||||
config.setHost("kanchai.club");
|
config.setHost("127.0.0.1");
|
||||||
config.setPort(221);
|
config.setPort(2121);
|
||||||
config.setUsername("");
|
config.setUsername("foo");
|
||||||
config.setPassword("");
|
config.setPassword("pass");
|
||||||
config.setMode(FtpMode.Passive.name());
|
config.setMode(FtpMode.Passive.name());
|
||||||
FtpFileClient client = new FtpFileClient(0L, config);
|
FtpFileClient client = new FtpFileClient(0L, config);
|
||||||
client.init();
|
client.init();
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,29 @@ import cn.iocoder.yudao.module.infra.framework.file.core.client.sftp.SftpFileCli
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link SftpFileClient} 集成测试
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
public class SftpFileClientTest {
|
public class SftpFileClientTest {
|
||||||
|
|
||||||
|
// docker run -p 2222:22 -d \
|
||||||
|
// -v $(pwd)/sftp-data:/home/foo/upload \
|
||||||
|
// atmoz/sftp \
|
||||||
|
// foo:pass:1001
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
public void test() {
|
public void test() {
|
||||||
// 创建客户端
|
// 创建客户端
|
||||||
SftpFileClientConfig config = new SftpFileClientConfig();
|
SftpFileClientConfig config = new SftpFileClientConfig();
|
||||||
config.setDomain("http://127.0.0.1:48080");
|
config.setDomain("http://127.0.0.1:48080");
|
||||||
config.setBasePath("/home/ftp");
|
config.setBasePath("/upload"); // 注意,这个是相对路径,不是实际 linux 上的路径!!!
|
||||||
config.setHost("kanchai.club");
|
config.setHost("127.0.0.1");
|
||||||
config.setPort(222);
|
config.setPort(2222);
|
||||||
config.setUsername("");
|
config.setUsername("foo");
|
||||||
config.setPassword("");
|
config.setPassword("pass");
|
||||||
SftpFileClient client = new SftpFileClient(0L, config);
|
SftpFileClient client = new SftpFileClient(0L, config);
|
||||||
client.init();
|
client.init();
|
||||||
// 上传文件
|
// 上传文件
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,14 @@ import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
||||||
import cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper;
|
import cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper;
|
||||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||||
|
|
@ -29,7 +30,7 @@ import static org.mockito.Mockito.*;
|
||||||
public class FileServiceImplTest extends BaseDbUnitTest {
|
public class FileServiceImplTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FileService fileService;
|
private FileServiceImpl fileService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FileMapper fileMapper;
|
private FileMapper fileMapper;
|
||||||
|
|
@ -37,6 +38,12 @@ public class FileServiceImplTest extends BaseDbUnitTest {
|
||||||
@MockBean
|
@MockBean
|
||||||
private FileConfigService fileConfigService;
|
private FileConfigService fileConfigService;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() {
|
||||||
|
FileServiceImpl.PATH_PREFIX_DATE_ENABLE = true;
|
||||||
|
FileServiceImpl.PATH_SUFFIX_TIMESTAMP_ENABLE = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFilePage() {
|
public void testGetFilePage() {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
|
|
@ -70,28 +77,69 @@ public class FileServiceImplTest extends BaseDbUnitTest {
|
||||||
AssertUtils.assertPojoEquals(dbFile, pageResult.getList().get(0));
|
AssertUtils.assertPojoEquals(dbFile, pageResult.getList().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* content、name、directory、type 都非空
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateFile_success() throws Exception {
|
public void testCreateFile_success_01() throws Exception {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
String path = randomString();
|
|
||||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||||
|
String name = "单测文件名";
|
||||||
|
String directory = randomString();
|
||||||
|
String type = "image/jpeg";
|
||||||
// mock Master 文件客户端
|
// mock Master 文件客户端
|
||||||
FileClient client = mock(FileClient.class);
|
FileClient client = mock(FileClient.class);
|
||||||
when(fileConfigService.getMasterFileClient()).thenReturn(client);
|
when(fileConfigService.getMasterFileClient()).thenReturn(client);
|
||||||
String url = randomString();
|
String url = randomString();
|
||||||
when(client.upload(same(content), same(path), eq("image/jpeg"))).thenReturn(url);
|
AtomicReference<String> pathRef = new AtomicReference<>();
|
||||||
|
when(client.upload(same(content), argThat(path -> {
|
||||||
|
assertTrue(path.matches(directory + "/\\d{8}/" + name + "_\\d+.jpg"));
|
||||||
|
pathRef.set(path);
|
||||||
|
return true;
|
||||||
|
}), eq(type))).thenReturn(url);
|
||||||
when(client.getId()).thenReturn(10L);
|
when(client.getId()).thenReturn(10L);
|
||||||
String name = "单测文件名";
|
|
||||||
// 调用
|
// 调用
|
||||||
String result = fileService.createFile(name, path, content);
|
String result = fileService.createFile(content, name, directory, type);
|
||||||
// 断言
|
// 断言
|
||||||
assertEquals(result, url);
|
assertEquals(result, url);
|
||||||
// 校验数据
|
// 校验数据
|
||||||
FileDO file = fileMapper.selectOne(FileDO::getPath, path);
|
FileDO file = fileMapper.selectOne(FileDO::getUrl, url);
|
||||||
assertEquals(10L, file.getConfigId());
|
assertEquals(10L, file.getConfigId());
|
||||||
assertEquals(path, file.getPath());
|
assertEquals(pathRef.get(), file.getPath());
|
||||||
assertEquals(url, file.getUrl());
|
assertEquals(url, file.getUrl());
|
||||||
assertEquals("image/jpeg", file.getType());
|
assertEquals(type, file.getType());
|
||||||
|
assertEquals(content.length, file.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* content 非空,其它都空
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCreateFile_success_02() throws Exception {
|
||||||
|
// 准备参数
|
||||||
|
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||||
|
// mock Master 文件客户端
|
||||||
|
String type = "image/jpeg";
|
||||||
|
FileClient client = mock(FileClient.class);
|
||||||
|
when(fileConfigService.getMasterFileClient()).thenReturn(client);
|
||||||
|
String url = randomString();
|
||||||
|
AtomicReference<String> pathRef = new AtomicReference<>();
|
||||||
|
when(client.upload(same(content), argThat(path -> {
|
||||||
|
assertTrue(path.matches("\\d{8}/6318848e882d8a7e7e82789d87608f684ee52d41966bfc8cad3ce15aad2b970e_\\d+\\.jpg"));
|
||||||
|
pathRef.set(path);
|
||||||
|
return true;
|
||||||
|
}), eq(type))).thenReturn(url);
|
||||||
|
when(client.getId()).thenReturn(10L);
|
||||||
|
// 调用
|
||||||
|
String result = fileService.createFile(content, null, null, null);
|
||||||
|
// 断言
|
||||||
|
assertEquals(result, url);
|
||||||
|
// 校验数据
|
||||||
|
FileDO file = fileMapper.selectOne(FileDO::getUrl, url);
|
||||||
|
assertEquals(10L, file.getConfigId());
|
||||||
|
assertEquals(pathRef.get(), file.getPath());
|
||||||
|
assertEquals(url, file.getUrl());
|
||||||
|
assertEquals(type, file.getType());
|
||||||
assertEquals(content.length, file.getSize());
|
assertEquals(content.length, file.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,4 +188,122 @@ public class FileServiceImplTest extends BaseDbUnitTest {
|
||||||
assertSame(result, content);
|
assertSame(result, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateUploadPath_AllEnabled() {
|
||||||
|
// 准备参数
|
||||||
|
String name = "test.jpg";
|
||||||
|
String directory = "avatar";
|
||||||
|
FileServiceImpl.PATH_PREFIX_DATE_ENABLE = true;
|
||||||
|
FileServiceImpl.PATH_SUFFIX_TIMESTAMP_ENABLE = true;
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
String path = fileService.generateUploadPath(name, directory);
|
||||||
|
|
||||||
|
// 断言
|
||||||
|
// 格式为:avatar/yyyyMMdd/test_timestamp.jpg
|
||||||
|
assertTrue(path.startsWith(directory + "/"));
|
||||||
|
// 包含日期格式:8 位数字,如 20240517
|
||||||
|
assertTrue(path.matches(directory + "/\\d{8}/test_\\d+\\.jpg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateUploadPath_PrefixEnabled_SuffixDisabled() {
|
||||||
|
// 准备参数
|
||||||
|
String name = "test.jpg";
|
||||||
|
String directory = "avatar";
|
||||||
|
FileServiceImpl.PATH_PREFIX_DATE_ENABLE = true;
|
||||||
|
FileServiceImpl.PATH_SUFFIX_TIMESTAMP_ENABLE = false;
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
String path = fileService.generateUploadPath(name, directory);
|
||||||
|
|
||||||
|
// 断言
|
||||||
|
// 格式为:avatar/yyyyMMdd/test.jpg
|
||||||
|
assertTrue(path.startsWith(directory + "/"));
|
||||||
|
// 包含日期格式:8 位数字,如 20240517
|
||||||
|
assertTrue(path.matches(directory + "/\\d{8}/test\\.jpg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateUploadPath_PrefixDisabled_SuffixEnabled() {
|
||||||
|
// 准备参数
|
||||||
|
String name = "test.jpg";
|
||||||
|
String directory = "avatar";
|
||||||
|
FileServiceImpl.PATH_PREFIX_DATE_ENABLE = false;
|
||||||
|
FileServiceImpl.PATH_SUFFIX_TIMESTAMP_ENABLE = true;
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
String path = fileService.generateUploadPath(name, directory);
|
||||||
|
|
||||||
|
// 断言
|
||||||
|
// 格式为:avatar/test_timestamp.jpg
|
||||||
|
assertTrue(path.startsWith(directory + "/"));
|
||||||
|
assertTrue(path.matches(directory + "/test_\\d+\\.jpg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateUploadPath_AllDisabled() {
|
||||||
|
// 准备参数
|
||||||
|
String name = "test.jpg";
|
||||||
|
String directory = "avatar";
|
||||||
|
FileServiceImpl.PATH_PREFIX_DATE_ENABLE = false;
|
||||||
|
FileServiceImpl.PATH_SUFFIX_TIMESTAMP_ENABLE = false;
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
String path = fileService.generateUploadPath(name, directory);
|
||||||
|
|
||||||
|
// 断言
|
||||||
|
// 格式为:avatar/test.jpg
|
||||||
|
assertEquals(directory + "/" + name, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateUploadPath_NoExtension() {
|
||||||
|
// 准备参数
|
||||||
|
String name = "test";
|
||||||
|
String directory = "avatar";
|
||||||
|
FileServiceImpl.PATH_PREFIX_DATE_ENABLE = true;
|
||||||
|
FileServiceImpl.PATH_SUFFIX_TIMESTAMP_ENABLE = true;
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
String path = fileService.generateUploadPath(name, directory);
|
||||||
|
|
||||||
|
// 断言
|
||||||
|
// 格式为:avatar/yyyyMMdd/test_timestamp
|
||||||
|
assertTrue(path.startsWith(directory + "/"));
|
||||||
|
assertTrue(path.matches(directory + "/\\d{8}/test_\\d+"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateUploadPath_DirectoryNull() {
|
||||||
|
// 准备参数
|
||||||
|
String name = "test.jpg";
|
||||||
|
String directory = null;
|
||||||
|
FileServiceImpl.PATH_PREFIX_DATE_ENABLE = true;
|
||||||
|
FileServiceImpl.PATH_SUFFIX_TIMESTAMP_ENABLE = true;
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
String path = fileService.generateUploadPath(name, directory);
|
||||||
|
|
||||||
|
// 断言
|
||||||
|
// 格式为:yyyyMMdd/test_timestamp.jpg
|
||||||
|
assertTrue(path.matches("\\d{8}/test_\\d+\\.jpg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateUploadPath_DirectoryEmpty() {
|
||||||
|
// 准备参数
|
||||||
|
String name = "test.jpg";
|
||||||
|
String directory = "";
|
||||||
|
FileServiceImpl.PATH_PREFIX_DATE_ENABLE = true;
|
||||||
|
FileServiceImpl.PATH_SUFFIX_TIMESTAMP_ENABLE = true;
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
String path = fileService.generateUploadPath(name, directory);
|
||||||
|
|
||||||
|
// 断言
|
||||||
|
// 格式为:yyyyMMdd/test_timestamp.jpg
|
||||||
|
assertTrue(path.matches("\\d{8}/test_\\d+\\.jpg"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||||
|
|
||||||
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿:fallbackFactory =
|
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿:fallbackFactory =
|
||||||
@Tag(name = "RPC 服务 - 商品 SKU")
|
@Tag(name = "RPC 服务 - 商品 SKU")
|
||||||
|
|
@ -33,6 +36,16 @@ public interface ProductSkuApi {
|
||||||
@Parameter(name = "ids", description = "SKU 编号列表", required = true, example = "1024,2048")
|
@Parameter(name = "ids", description = "SKU 编号列表", required = true, example = "1024,2048")
|
||||||
CommonResult<List<ProductSkuRespDTO>> getSkuList(@RequestParam("ids") Collection<Long> ids);
|
CommonResult<List<ProductSkuRespDTO>> getSkuList(@RequestParam("ids") Collection<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量查询 SKU MAP
|
||||||
|
*
|
||||||
|
* @param ids SKU 编号列表
|
||||||
|
* @return SKU MAP
|
||||||
|
*/
|
||||||
|
default Map<Long, ProductSkuRespDTO> getSkuMap(Collection<Long> ids) {
|
||||||
|
return convertMap(getSkuList(ids).getCheckedData(), ProductSkuRespDTO::getId);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping(PREFIX + "/list-by-spu-id")
|
@GetMapping(PREFIX + "/list-by-spu-id")
|
||||||
@Operation(summary = "批量查询 SKU 信息")
|
@Operation(summary = "批量查询 SKU 信息")
|
||||||
@Parameter(name = "spuIds", description = "SPU 编号列表", required = true, example = "1024,2048")
|
@Parameter(name = "spuIds", description = "SPU 编号列表", required = true, example = "1024,2048")
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ public interface ProductSpuApi {
|
||||||
* @param ids SPU 编号列表
|
* @param ids SPU 编号列表
|
||||||
* @return SPU MAP
|
* @return SPU MAP
|
||||||
*/
|
*/
|
||||||
default Map<Long, ProductSpuRespDTO> getSpusMap(Collection<Long> ids) {
|
default Map<Long, ProductSpuRespDTO> getSpuMap(Collection<Long> ids) {
|
||||||
return convertMap(getSpuList(ids).getCheckedData(), ProductSpuRespDTO::getId);
|
return convertMap(getSpuList(ids).getCheckedData(), ProductSpuRespDTO::getId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,15 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
|
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 商品浏览记录 Response VO")
|
@Schema(description = "管理后台 - 商品浏览记录 Response VO")
|
||||||
@Data
|
@Data
|
||||||
@ExcelIgnoreUnannotated
|
@ExcelIgnoreUnannotated
|
||||||
public class ProductBrowseHistoryRespVO {
|
public class ProductBrowseHistoryRespVO {
|
||||||
|
|
||||||
@Schema(description = "编号", requiredMode = REQUIRED, example = "1")
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502")
|
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29502")
|
||||||
private Long spuId;
|
private Long spuId;
|
||||||
|
|
||||||
// ========== 商品相关字段 ==========
|
// ========== 商品相关字段 ==========
|
||||||
|
|
@ -34,4 +32,4 @@ public class ProductBrowseHistoryRespVO {
|
||||||
@Schema(description = "库存", example = "100")
|
@Schema(description = "库存", example = "100")
|
||||||
private Integer stock;
|
private Integer stock;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,14 @@ package cn.iocoder.yudao.module.product.controller.app.favorite.vo;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
|
|
||||||
|
|
||||||
@Schema(description = "用户 APP - 商品收藏的批量 Request VO") // 用于收藏、取消收藏、获取收藏
|
@Schema(description = "用户 APP - 商品收藏的批量 Request VO") // 用于收藏、取消收藏、获取收藏
|
||||||
@Data
|
@Data
|
||||||
public class AppFavoriteBatchReqVO {
|
public class AppFavoriteBatchReqVO {
|
||||||
|
|
||||||
@Schema(description = "商品 SPU 编号数组", requiredMode = REQUIRED, example = "29502")
|
@Schema(description = "商品 SPU 编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "29502")
|
||||||
@NotEmpty(message = "商品 SPU 编号数组不能为空")
|
@NotEmpty(message = "商品 SPU 编号数组不能为空")
|
||||||
private List<Long> spuIds;
|
private List<Long> spuIds;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,13 @@ package cn.iocoder.yudao.module.product.controller.app.favorite.vo;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
|
|
||||||
|
|
||||||
@Schema(description = "用户 APP - 商品收藏的单个 Request VO") // 用于收藏、取消收藏、获取收藏
|
@Schema(description = "用户 APP - 商品收藏的单个 Request VO") // 用于收藏、取消收藏、获取收藏
|
||||||
@Data
|
@Data
|
||||||
public class AppFavoriteReqVO {
|
public class AppFavoriteReqVO {
|
||||||
|
|
||||||
@Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502")
|
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29502")
|
||||||
@NotNull(message = "商品 SPU 编号不能为空")
|
@NotNull(message = "商品 SPU 编号不能为空")
|
||||||
private Long spuId;
|
private Long spuId;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,14 @@ package cn.iocoder.yudao.module.product.controller.app.favorite.vo;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
|
|
||||||
|
|
||||||
@Schema(description = "用户 App - 商品收藏 Response VO")
|
@Schema(description = "用户 App - 商品收藏 Response VO")
|
||||||
@Data
|
@Data
|
||||||
public class AppFavoriteRespVO {
|
public class AppFavoriteRespVO {
|
||||||
|
|
||||||
@Schema(description = "编号", requiredMode = REQUIRED, example = "1")
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502")
|
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29502")
|
||||||
private Long spuId;
|
private Long spuId;
|
||||||
|
|
||||||
// ========== 商品相关字段 ==========
|
// ========== 商品相关字段 ==========
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,11 @@ import lombok.Data;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
|
|
||||||
|
|
||||||
@Schema(description = "用户 APP - 删除商品浏览记录的 Request VO")
|
@Schema(description = "用户 APP - 删除商品浏览记录的 Request VO")
|
||||||
@Data
|
@Data
|
||||||
public class AppProductBrowseHistoryDeleteReqVO {
|
public class AppProductBrowseHistoryDeleteReqVO {
|
||||||
|
|
||||||
@Schema(description = "商品 SPU 编号数组", requiredMode = REQUIRED, example = "29502")
|
@Schema(description = "商品 SPU 编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "29502")
|
||||||
@NotEmpty(message = "商品 SPU 编号数组不能为空")
|
@NotEmpty(message = "商品 SPU 编号数组不能为空")
|
||||||
private List<Long> spuIds;
|
private List<Long> spuIds;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,33 +3,31 @@ package cn.iocoder.yudao.module.product.controller.app.history.vo;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
|
|
||||||
|
|
||||||
@Schema(description = "用户 App - 商品浏览记录 Response VO")
|
@Schema(description = "用户 App - 商品浏览记录 Response VO")
|
||||||
@Data
|
@Data
|
||||||
public class AppProductBrowseHistoryRespVO {
|
public class AppProductBrowseHistoryRespVO {
|
||||||
|
|
||||||
@Schema(description = "编号", requiredMode = REQUIRED, example = "1")
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502")
|
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29502")
|
||||||
private Long spuId;
|
private Long spuId;
|
||||||
|
|
||||||
// ========== 商品相关字段 ==========
|
// ========== 商品相关字段 ==========
|
||||||
|
|
||||||
@Schema(description = "商品 SPU 名称", requiredMode = REQUIRED, example = "赵六")
|
@Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||||
private String spuName;
|
private String spuName;
|
||||||
|
|
||||||
@Schema(description = "商品封面图", requiredMode = REQUIRED, example = "https://www.iocoder.cn/pic.png")
|
@Schema(description = "商品封面图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/pic.png")
|
||||||
private String picUrl;
|
private String picUrl;
|
||||||
|
|
||||||
@Schema(description = "商品单价", requiredMode = REQUIRED, example = "50")
|
@Schema(description = "商品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
|
||||||
private Integer price;
|
private Integer price;
|
||||||
|
|
||||||
@Schema(description = "商品销量", requiredMode = REQUIRED, example = "60")
|
@Schema(description = "商品销量", requiredMode = Schema.RequiredMode.REQUIRED, example = "60")
|
||||||
private Integer salesCount;
|
private Integer salesCount;
|
||||||
|
|
||||||
@Schema(description = "库存", requiredMode = REQUIRED, example = "80")
|
@Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "80")
|
||||||
private Integer stock;
|
private Integer stock;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -13,6 +15,9 @@ import java.util.List;
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
|
public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
|
||||||
|
|
||||||
|
@Select("SELECT * FROM product_sku WHERE id = #{id}")
|
||||||
|
ProductSkuDO selectByIdIncludeDeleted(@Param("id") Long id);
|
||||||
|
|
||||||
default List<ProductSkuDO> selectListBySpuId(Long spuId) {
|
default List<ProductSkuDO> selectListBySpuId(Long spuId) {
|
||||||
return selectList(ProductSkuDO::getSpuId, spuId);
|
return selectList(ProductSkuDO::getSpuId, spuId);
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +40,7 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
|
||||||
Assert.isTrue(incrCount > 0);
|
Assert.isTrue(incrCount > 0);
|
||||||
LambdaUpdateWrapper<ProductSkuDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<ProductSkuDO>()
|
LambdaUpdateWrapper<ProductSkuDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<ProductSkuDO>()
|
||||||
.setSql(" stock = stock + " + incrCount
|
.setSql(" stock = stock + " + incrCount
|
||||||
+ ", sales_count = sales_count - " + incrCount)
|
+ ", sales_count = sales_count - " + incrCount)
|
||||||
.eq(ProductSkuDO::getId, id);
|
.eq(ProductSkuDO::getId, id);
|
||||||
update(null, lambdaUpdateWrapper);
|
update(null, lambdaUpdateWrapper);
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +57,7 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
|
||||||
incrCount = - incrCount; // 取正
|
incrCount = - incrCount; // 取正
|
||||||
LambdaUpdateWrapper<ProductSkuDO> updateWrapper = new LambdaUpdateWrapper<ProductSkuDO>()
|
LambdaUpdateWrapper<ProductSkuDO> updateWrapper = new LambdaUpdateWrapper<ProductSkuDO>()
|
||||||
.setSql(" stock = stock - " + incrCount
|
.setSql(" stock = stock - " + incrCount
|
||||||
+ ", sales_count = sales_count + " + incrCount)
|
+ ", sales_count = sales_count + " + incrCount)
|
||||||
.eq(ProductSkuDO::getId, id)
|
.eq(ProductSkuDO::getId, id)
|
||||||
.ge(ProductSkuDO::getStock, incrCount);
|
.ge(ProductSkuDO::getStock, incrCount);
|
||||||
return update(null, updateWrapper);
|
return update(null, updateWrapper);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import cn.iocoder.yudao.module.product.enums.ProductConstants;
|
||||||
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
|
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
@ -18,6 +20,9 @@ import java.util.Set;
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
|
public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
|
||||||
|
|
||||||
|
@Select("SELECT * FROM product_spu WHERE id = #{id}")
|
||||||
|
ProductSpuDO selectByIdIncludeDeleted(@Param("id") Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取商品 SPU 分页列表数据
|
* 获取商品 SPU 分页列表数据
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProductSkuDO validateSku(Long skuId) {
|
private ProductSkuDO validateSku(Long skuId) {
|
||||||
ProductSkuDO sku = productSkuService.getSku(skuId);
|
ProductSkuDO sku = productSkuService.getSku(skuId, true);
|
||||||
if (sku == null) {
|
if (sku == null) {
|
||||||
throw exception(SKU_NOT_EXISTS);
|
throw exception(SKU_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +99,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProductSpuDO validateSpu(Long spuId) {
|
private ProductSpuDO validateSpu(Long spuId) {
|
||||||
ProductSpuDO spu = productSpuService.getSpu(spuId);
|
ProductSpuDO spu = productSpuService.getSpu(spuId, true);
|
||||||
if (null == spu) {
|
if (null == spu) {
|
||||||
throw exception(SPU_NOT_EXISTS);
|
throw exception(SPU_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,15 @@ public interface ProductSkuService {
|
||||||
*/
|
*/
|
||||||
ProductSkuDO getSku(Long id);
|
ProductSkuDO getSku(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得商品 SKU 信息
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @param includeDeleted 是否包含已删除的
|
||||||
|
* @return 商品 SKU 信息
|
||||||
|
*/
|
||||||
|
ProductSkuDO getSku(Long id, boolean includeDeleted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得商品 SKU 列表
|
* 获得商品 SKU 列表
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,14 @@ public class ProductSkuServiceImpl implements ProductSkuService {
|
||||||
return productSkuMapper.selectById(id);
|
return productSkuMapper.selectById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProductSkuDO getSku(Long id, boolean includeDeleted) {
|
||||||
|
if (includeDeleted) {
|
||||||
|
return productSkuMapper.selectByIdIncludeDeleted(id);
|
||||||
|
}
|
||||||
|
return getSku(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProductSkuDO> getSkuList(Collection<Long> ids) {
|
public List<ProductSkuDO> getSkuList(Collection<Long> ids) {
|
||||||
if (CollUtil.isEmpty(ids)) {
|
if (CollUtil.isEmpty(ids)) {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,15 @@ public interface ProductSpuService {
|
||||||
*/
|
*/
|
||||||
ProductSpuDO getSpu(Long id);
|
ProductSpuDO getSpu(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得商品 SPU
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @param includeDeleted 是否包含已删除的
|
||||||
|
* @return 商品 SPU
|
||||||
|
*/
|
||||||
|
ProductSpuDO getSpu(Long id, boolean includeDeleted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得商品 SPU 列表
|
* 获得商品 SPU 列表
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,14 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||||
return productSpuMapper.selectById(id);
|
return productSpuMapper.selectById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProductSpuDO getSpu(Long id, boolean includeDeleted) {
|
||||||
|
if (includeDeleted) {
|
||||||
|
return productSpuMapper.selectByIdIncludeDeleted(id);
|
||||||
|
}
|
||||||
|
return getSpu(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProductSpuDO> getSpuList(Collection<Long> ids) {
|
public List<ProductSpuDO> getSpuList(Collection<Long> ids) {
|
||||||
if (CollUtil.isEmpty(ids)) {
|
if (CollUtil.isEmpty(ids)) {
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ public class PointActivityController {
|
||||||
List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds(
|
List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds(
|
||||||
convertSet(activityList, PointActivityDO::getId));
|
convertSet(activityList, PointActivityDO::getId));
|
||||||
Map<Long, List<PointProductDO>> productsMap = convertMultiMap(products, PointProductDO::getActivityId);
|
Map<Long, List<PointProductDO>> productsMap = convertMultiMap(products, PointProductDO::getActivityId);
|
||||||
Map<Long, ProductSpuRespDTO> spuMap = productSpuApi.getSpusMap(
|
Map<Long, ProductSpuRespDTO> spuMap = productSpuApi.getSpuMap(
|
||||||
convertSet(activityList, PointActivityDO::getSpuId));
|
convertSet(activityList, PointActivityDO::getSpuId));
|
||||||
List<PointActivityRespVO> result = BeanUtils.toBean(activityList, PointActivityRespVO.class);
|
List<PointActivityRespVO> result = BeanUtils.toBean(activityList, PointActivityRespVO.class);
|
||||||
result.forEach(activity -> {
|
result.forEach(activity -> {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template;
|
package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.Min;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -20,6 +20,9 @@ public class AppCouponTemplateRespVO {
|
||||||
@Schema(description = "优惠券说明", example = "优惠券使用说明")
|
@Schema(description = "优惠券说明", example = "优惠券使用说明")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@Schema(description = "发行总量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") // -1 - 则表示不限制发放数量
|
||||||
|
private Integer totalCount;
|
||||||
|
|
||||||
@Schema(description = "每人限领个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "66") // -1 - 则表示不限制
|
@Schema(description = "每人限领个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "66") // -1 - 则表示不限制
|
||||||
private Integer takeLimitCount;
|
private Integer takeLimitCount;
|
||||||
|
|
||||||
|
|
@ -62,6 +65,9 @@ public class AppCouponTemplateRespVO {
|
||||||
@Schema(description = "折扣上限", example = "100") // 单位:分,仅在 discountType 为 PERCENT 使用
|
@Schema(description = "折扣上限", example = "100") // 单位:分,仅在 discountType 为 PERCENT 使用
|
||||||
private Integer discountLimitPrice;
|
private Integer discountLimitPrice;
|
||||||
|
|
||||||
|
@Schema(description = "领取优惠券的数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||||
|
private Integer takeCount;
|
||||||
|
|
||||||
// ========== 用户相关字段 ==========
|
// ========== 用户相关字段 ==========
|
||||||
|
|
||||||
@Schema(description = "是否可以领取", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
@Schema(description = "是否可以领取", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ public class AppPointActivityController {
|
||||||
List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds(
|
List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds(
|
||||||
convertSet(activityList, PointActivityDO::getId));
|
convertSet(activityList, PointActivityDO::getId));
|
||||||
Map<Long, List<PointProductDO>> productsMap = convertMultiMap(products, PointProductDO::getActivityId);
|
Map<Long, List<PointProductDO>> productsMap = convertMultiMap(products, PointProductDO::getActivityId);
|
||||||
Map<Long, ProductSpuRespDTO> spuMap = productSpuApi.getSpusMap(
|
Map<Long, ProductSpuRespDTO> spuMap = productSpuApi.getSpuMap(
|
||||||
convertSet(activityList, PointActivityDO::getSpuId));
|
convertSet(activityList, PointActivityDO::getSpuId));
|
||||||
List<AppPointActivityRespVO> result = BeanUtils.toBean(activityList, AppPointActivityRespVO.class);
|
List<AppPointActivityRespVO> result = BeanUtils.toBean(activityList, AppPointActivityRespVO.class);
|
||||||
result.forEach(activity -> {
|
result.forEach(activity -> {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum;
|
||||||
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum;
|
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
|
@ -180,7 +181,7 @@ public class CouponServiceImpl implements CouponService {
|
||||||
* @param couponId 模版编号
|
* @param couponId 模版编号
|
||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) // 每次调用开启一个新的事务,避免在一个大的事务里面
|
||||||
public void invalidateCoupon(Long couponId, Long userId) {
|
public void invalidateCoupon(Long couponId, Long userId) {
|
||||||
if (couponId == null || couponId <= 0) {
|
if (couponId == null || couponId <= 0) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -270,13 +271,17 @@ public class CouponServiceImpl implements CouponService {
|
||||||
if (CollUtil.isEmpty(userIds)) {
|
if (CollUtil.isEmpty(userIds)) {
|
||||||
throw exception(COUPON_TEMPLATE_USER_ALREADY_TAKE);
|
throw exception(COUPON_TEMPLATE_USER_ALREADY_TAKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验模板
|
// 校验模板
|
||||||
if (couponTemplate == null) {
|
if (couponTemplate == null) {
|
||||||
throw exception(COUPON_TEMPLATE_NOT_EXISTS);
|
throw exception(COUPON_TEMPLATE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
// 校验剩余数量
|
// 校验领取方式
|
||||||
if (ObjUtil.notEqual(couponTemplate.getTakeLimitCount(), CouponTemplateDO.TIME_LIMIT_COUNT_MAX) // 非不限制
|
if (ObjUtil.notEqual(couponTemplate.getTakeType(), takeType.getType())) {
|
||||||
|
throw exception(COUPON_TEMPLATE_CANNOT_TAKE);
|
||||||
|
}
|
||||||
|
// 校验发放数量不能过小(仅在 CouponTakeTypeEnum.USER 用户领取时)
|
||||||
|
if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType())
|
||||||
|
&& ObjUtil.notEqual(couponTemplate.getTakeLimitCount(), CouponTemplateDO.TIME_LIMIT_COUNT_MAX) // 非不限制
|
||||||
&& couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) {
|
&& couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) {
|
||||||
throw exception(COUPON_TEMPLATE_NOT_ENOUGH);
|
throw exception(COUPON_TEMPLATE_NOT_ENOUGH);
|
||||||
}
|
}
|
||||||
|
|
@ -286,10 +291,6 @@ public class CouponServiceImpl implements CouponService {
|
||||||
throw exception(COUPON_TEMPLATE_EXPIRED);
|
throw exception(COUPON_TEMPLATE_EXPIRED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 校验领取方式
|
|
||||||
if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType.getType())) {
|
|
||||||
throw exception(COUPON_TEMPLATE_CANNOT_TAKE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
package cn.iocoder.yudao.module.trade.controller.app.aftersale;
|
package cn.iocoder.yudao.module.trade.controller.app.aftersale;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
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.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleDeliveryReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleDeliveryReqVO;
|
||||||
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSalePageReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleRespVO;
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleRespVO;
|
||||||
import cn.iocoder.yudao.module.trade.convert.aftersale.AfterSaleConvert;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
|
||||||
import cn.iocoder.yudao.module.trade.service.aftersale.AfterSaleService;
|
import cn.iocoder.yudao.module.trade.service.aftersale.AfterSaleService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
|
@ -32,16 +33,17 @@ public class AppAfterSaleController {
|
||||||
|
|
||||||
@GetMapping(value = "/page")
|
@GetMapping(value = "/page")
|
||||||
@Operation(summary = "获得售后分页")
|
@Operation(summary = "获得售后分页")
|
||||||
public CommonResult<PageResult<AppAfterSaleRespVO>> getAfterSalePage(PageParam pageParam) {
|
public CommonResult<PageResult<AppAfterSaleRespVO>> getAfterSalePage(AppAfterSalePageReqVO pageReqVO) {
|
||||||
return success(AfterSaleConvert.INSTANCE.convertPage02(
|
PageResult<AfterSaleDO> pageResult = afterSaleService.getAfterSalePage(getLoginUserId(), pageReqVO);
|
||||||
afterSaleService.getAfterSalePage(getLoginUserId(), pageParam)));
|
return success(BeanUtils.toBean(pageResult, AppAfterSaleRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/get")
|
@GetMapping(value = "/get")
|
||||||
@Operation(summary = "获得售后订单")
|
@Operation(summary = "获得售后订单")
|
||||||
@Parameter(name = "id", description = "售后编号", required = true, example = "1")
|
@Parameter(name = "id", description = "售后编号", required = true, example = "1")
|
||||||
public CommonResult<AppAfterSaleRespVO> getAfterSale(@RequestParam("id") Long id) {
|
public CommonResult<AppAfterSaleRespVO> getAfterSale(@RequestParam("id") Long id) {
|
||||||
return success(AfterSaleConvert.INSTANCE.convert(afterSaleService.getAfterSale(getLoginUserId(), id)));
|
AfterSaleDO afterSale = afterSaleService.getAfterSale(getLoginUserId(), id);
|
||||||
|
return success(BeanUtils.toBean(afterSale, AppAfterSaleRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/create")
|
@PostMapping(value = "/create")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package cn.iocoder.yudao.module.trade.controller.app.aftersale.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 java.util.Set;
|
||||||
|
|
||||||
|
@Schema(description = "用户 App - 交易售后分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class AppAfterSalePageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "售后状态", example = "10, 20")
|
||||||
|
private Set<Integer> statuses;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.trade.controller.app.base.spu;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品 SPU 基础 Response VO
|
* 商品 SPU 基础 Response VO
|
||||||
*
|
*
|
||||||
|
|
@ -25,4 +23,10 @@ public class AppProductSpuBaseRespVO {
|
||||||
@Schema(description = "商品分类编号", example = "1")
|
@Schema(description = "商品分类编号", example = "1")
|
||||||
private Long categoryId;
|
private Long categoryId;
|
||||||
|
|
||||||
|
@Schema(description = "商品库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "10000")
|
||||||
|
private Integer stock;
|
||||||
|
|
||||||
|
@Schema(description = "商品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
package cn.iocoder.yudao.module.trade.controller.app.delivery.vo.pickup;
|
package cn.iocoder.yudao.module.trade.controller.app.delivery.vo.pickup;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalTime;
|
||||||
|
|
||||||
@Schema(description = "用户 App - 自提门店 Response VO")
|
@Schema(description = "用户 App - 自提门店 Response VO")
|
||||||
@Data
|
@Data
|
||||||
public class AppDeliveryPickUpStoreRespVO {
|
public class AppDeliveryPickUpStoreRespVO {
|
||||||
|
|
@ -28,6 +32,16 @@ public class AppDeliveryPickUpStoreRespVO {
|
||||||
@Schema(description = "门店详细地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "复旦大学路 188 号")
|
@Schema(description = "门店详细地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "复旦大学路 188 号")
|
||||||
private String detailAddress;
|
private String detailAddress;
|
||||||
|
|
||||||
|
@Schema(description = "营业开始时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "营业开始时间不能为空")
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm")
|
||||||
|
private LocalTime openingTime;
|
||||||
|
|
||||||
|
@Schema(description = "营业结束时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "营业结束时间不能为空")
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm")
|
||||||
|
private LocalTime closingTime;
|
||||||
|
|
||||||
@Schema(description = "纬度", requiredMode = Schema.RequiredMode.REQUIRED, example = "5.88")
|
@Schema(description = "纬度", requiredMode = Schema.RequiredMode.REQUIRED, example = "5.88")
|
||||||
private Double latitude;
|
private Double latitude;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUse
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderBaseVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderBaseVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleRespVO;
|
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleLogDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleLogDO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
||||||
|
|
@ -63,10 +62,6 @@ public interface AfterSaleConvert {
|
||||||
|
|
||||||
ProductPropertyValueDetailRespVO convert(ProductPropertyValueDetailRespDTO bean);
|
ProductPropertyValueDetailRespVO convert(ProductPropertyValueDetailRespDTO bean);
|
||||||
|
|
||||||
AppAfterSaleRespVO convert(AfterSaleDO bean);
|
|
||||||
|
|
||||||
PageResult<AppAfterSaleRespVO> convertPage02(PageResult<AfterSaleDO> page);
|
|
||||||
|
|
||||||
default AfterSaleDetailRespVO convert(AfterSaleDO afterSale, TradeOrderDO order, TradeOrderItemDO orderItem,
|
default AfterSaleDetailRespVO convert(AfterSaleDO afterSale, TradeOrderDO order, TradeOrderItemDO orderItem,
|
||||||
MemberUserRespDTO user, List<AfterSaleLogDO> logs) {
|
MemberUserRespDTO user, List<AfterSaleLogDO> logs) {
|
||||||
AfterSaleDetailRespVO respVO = convert02(afterSale);
|
AfterSaleDetailRespVO respVO = convert02(afterSale);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package cn.iocoder.yudao.module.trade.convert.cart;
|
package cn.iocoder.yudao.module.trade.convert.cart;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
|
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
|
||||||
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
|
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
|
||||||
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
|
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
|
||||||
|
|
@ -33,21 +34,18 @@ public interface TradeCartConvert {
|
||||||
cartVO.setId(cart.getId()).setCount(cart.getCount()).setSelected(cart.getSelected());
|
cartVO.setId(cart.getId()).setCount(cart.getCount()).setSelected(cart.getSelected());
|
||||||
ProductSpuRespDTO spu = spuMap.get(cart.getSpuId());
|
ProductSpuRespDTO spu = spuMap.get(cart.getSpuId());
|
||||||
ProductSkuRespDTO sku = skuMap.get(cart.getSkuId());
|
ProductSkuRespDTO sku = skuMap.get(cart.getSkuId());
|
||||||
cartVO.setSpu(convert(spu)).setSku(convert(sku));
|
cartVO.setSpu(BeanUtils.toBean(spu, AppProductSpuBaseRespVO.class))
|
||||||
|
.setSku(BeanUtils.toBean(sku, AppProductSkuBaseRespVO.class));
|
||||||
// 如果 SPU 不存在,或者下架,或者库存不足,说明是无效的
|
// 如果 SPU 不存在,或者下架,或者库存不足,说明是无效的
|
||||||
if (spu == null
|
if (spu == null
|
||||||
|| !ProductSpuStatusEnum.isEnable(spu.getStatus())
|
|| !ProductSpuStatusEnum.isEnable(spu.getStatus())
|
||||||
|| spu.getStock() <= 0) {
|
|| spu.getStock() <= 0) {
|
||||||
cartVO.setSelected(false); // 强制设置成不可选中
|
|
||||||
invalidList.add(cartVO);
|
invalidList.add(cartVO);
|
||||||
} else {
|
} else {
|
||||||
// 虽然 SKU 可能也会不存在,但是可以通过购物车重新选择
|
|
||||||
validList.add(cartVO);
|
validList.add(cartVO);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return new AppCartListRespVO().setValidList(validList).setInvalidList(invalidList);
|
return new AppCartListRespVO().setValidList(validList).setInvalidList(invalidList);
|
||||||
}
|
}
|
||||||
AppProductSpuBaseRespVO convert(ProductSpuRespDTO spu);
|
|
||||||
AppProductSkuBaseRespVO convert(ProductSkuRespDTO sku);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package cn.iocoder.yudao.module.trade.dal.mysql.aftersale;
|
package cn.iocoder.yudao.module.trade.dal.mysql.aftersale;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSalePageReqVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSalePageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSalePageReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
@ -27,9 +27,10 @@ public interface AfterSaleMapper extends BaseMapperX<AfterSaleDO> {
|
||||||
.orderByDesc(AfterSaleDO::getId));
|
.orderByDesc(AfterSaleDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
default PageResult<AfterSaleDO> selectPage(Long userId, PageParam pageParam) {
|
default PageResult<AfterSaleDO> selectPage(Long userId, AppAfterSalePageReqVO pageReqVO) {
|
||||||
return selectPage(pageParam, new LambdaQueryWrapperX<AfterSaleDO>()
|
return selectPage(pageReqVO, new LambdaQueryWrapperX<AfterSaleDO>()
|
||||||
.eqIfPresent(AfterSaleDO::getUserId, userId)
|
.eq(AfterSaleDO::getUserId, userId)
|
||||||
|
.inIfPresent(AfterSaleDO::getStatus, pageReqVO.getStatuses())
|
||||||
.orderByDesc(AfterSaleDO::getId));
|
.orderByDesc(AfterSaleDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
package cn.iocoder.yudao.module.trade.service.aftersale;
|
package cn.iocoder.yudao.module.trade.service.aftersale;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleDisagreeReqVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleDisagreeReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSalePageReqVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSalePageReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleRefuseReqVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleRefuseReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleDeliveryReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleDeliveryReqVO;
|
||||||
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSalePageReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -28,10 +28,10 @@ public interface AfterSaleService {
|
||||||
* 【会员】获得售后订单分页
|
* 【会员】获得售后订单分页
|
||||||
*
|
*
|
||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @param pageParam 分页参数
|
* @param pageReqVO 分页参数
|
||||||
* @return 售后订单分页
|
* @return 售后订单分页
|
||||||
*/
|
*/
|
||||||
PageResult<AfterSaleDO> getAfterSalePage(Long userId, PageParam pageParam);
|
PageResult<AfterSaleDO> getAfterSalePage(Long userId, AppAfterSalePageReqVO pageReqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 【会员】获得售后单
|
* 【会员】获得售后单
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.service.aftersale;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||||
import cn.iocoder.yudao.module.pay.api.refund.PayRefundApi;
|
import cn.iocoder.yudao.module.pay.api.refund.PayRefundApi;
|
||||||
|
|
@ -16,6 +15,7 @@ import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSalePage
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleRefuseReqVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleRefuseReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleDeliveryReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleDeliveryReqVO;
|
||||||
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSalePageReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.convert.aftersale.AfterSaleConvert;
|
import cn.iocoder.yudao.module.trade.convert.aftersale.AfterSaleConvert;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO;
|
||||||
|
|
@ -87,8 +87,8 @@ public class AfterSaleServiceImpl implements AfterSaleService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<AfterSaleDO> getAfterSalePage(Long userId, PageParam pageParam) {
|
public PageResult<AfterSaleDO> getAfterSalePage(Long userId, AppAfterSalePageReqVO pageReqVO) {
|
||||||
return tradeAfterSaleMapper.selectPage(userId, pageParam);
|
return tradeAfterSaleMapper.selectPage(userId, pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -386,7 +386,7 @@ public class AfterSaleServiceImpl implements AfterSaleService {
|
||||||
public void afterCommit() {
|
public void afterCommit() {
|
||||||
// 创建退款单
|
// 创建退款单
|
||||||
PayRefundCreateReqDTO createReqDTO = AfterSaleConvert.INSTANCE.convert(userIp, afterSale, tradeOrderProperties)
|
PayRefundCreateReqDTO createReqDTO = AfterSaleConvert.INSTANCE.convert(userIp, afterSale, tradeOrderProperties)
|
||||||
.setReason(StrUtil.format("退款【{}】", afterSale.getSpuName()));;
|
.setReason(StrUtil.format("退款【{}】", afterSale.getSpuName()));
|
||||||
Long payRefundId = payRefundApi.createRefund(createReqDTO).getCheckedData();
|
Long payRefundId = payRefundApi.createRefund(createReqDTO).getCheckedData();
|
||||||
// 更新售后单的退款单号
|
// 更新售后单的退款单号
|
||||||
tradeAfterSaleMapper.updateById(new AfterSaleDO().setId(afterSale.getId()).setPayRefundId(payRefundId));
|
tradeAfterSaleMapper.updateById(new AfterSaleDO().setId(afterSale.getId()).setPayRefundId(payRefundId));
|
||||||
|
|
|
||||||
|
|
@ -545,6 +545,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||||
if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.UNPAID.getStatus())) {
|
if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.UNPAID.getStatus())) {
|
||||||
throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
|
throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
|
||||||
}
|
}
|
||||||
|
// 1.3 校验是否支持延迟(不允许取消)
|
||||||
|
if (TradeOrderStatusEnum.isUnpaid(order.getStatus())) {
|
||||||
|
PayOrderRespDTO payOrder = payOrderApi.getOrder(order.getPayOrderId()).getCheckedData();
|
||||||
|
if (payOrder != null && PayOrderStatusEnum.isSuccess(payOrder.getStatus())) {
|
||||||
|
log.warn("[cancelOrderByMember][order({}) 支付单已支付(支付回调延迟),不支持取消]", order.getId());
|
||||||
|
throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 2. 取消订单
|
// 2. 取消订单
|
||||||
cancelOrder0(order, TradeOrderCancelTypeEnum.MEMBER_CANCEL);
|
cancelOrder0(order, TradeOrderCancelTypeEnum.MEMBER_CANCEL);
|
||||||
|
|
@ -581,6 +589,15 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.SYSTEM_CANCEL)
|
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.SYSTEM_CANCEL)
|
||||||
public void cancelOrderBySystem(TradeOrderDO order) {
|
public void cancelOrderBySystem(TradeOrderDO order) {
|
||||||
|
// 校验是否支持延迟(不允许取消)
|
||||||
|
if (TradeOrderStatusEnum.isUnpaid(order.getStatus())) {
|
||||||
|
PayOrderRespDTO payOrder = payOrderApi.getOrder(order.getPayOrderId()).getCheckedData();
|
||||||
|
if (payOrder != null && PayOrderStatusEnum.isSuccess(payOrder.getStatus())) {
|
||||||
|
log.warn("[cancelOrderBySystem][order({}) 支付单已支付(支付回调延迟),不支持取消]", order.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cancelOrder0(order, TradeOrderCancelTypeEnum.PAY_TIMEOUT);
|
cancelOrder0(order, TradeOrderCancelTypeEnum.PAY_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -895,12 +912,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
throw exception(ORDER_NOT_FOUND);
|
throw exception(ORDER_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.3 校验订单是否支付
|
// 1.3 校验订单是否支付
|
||||||
if (!order.getPayStatus()) {
|
if (!order.getPayStatus()) {
|
||||||
throw exception(ORDER_CANCEL_PAID_FAIL, "已支付");
|
throw exception(ORDER_CANCEL_PAID_FAIL, "已支付");
|
||||||
}
|
}
|
||||||
// 1.3 校验订单是否未退款
|
// 1.4 校验订单是否未退款
|
||||||
if (ObjUtil.notEqual(TradeOrderRefundStatusEnum.NONE.getStatus(), order.getRefundStatus())) {
|
if (ObjUtil.notEqual(TradeOrderRefundStatusEnum.NONE.getStatus(), order.getRefundStatus())) {
|
||||||
throw exception(ORDER_CANCEL_PAID_FAIL, "未退款");
|
throw exception(ORDER_CANCEL_PAID_FAIL, "未退款");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
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.convertList;
|
||||||
|
|
||||||
|
|
@ -101,13 +102,17 @@ public class TradeBrokerageOrderHandler implements TradeOrderHandler {
|
||||||
protected void addBrokerage(Long userId, List<TradeOrderItemDO> orderItems) {
|
protected void addBrokerage(Long userId, List<TradeOrderItemDO> orderItems) {
|
||||||
MemberUserRespDTO user = memberUserApi.getUser(userId).getCheckedData();
|
MemberUserRespDTO user = memberUserApi.getUser(userId).getCheckedData();
|
||||||
Assert.notNull(user);
|
Assert.notNull(user);
|
||||||
ProductSpuRespDTO spu = productSpuApi.getSpu(orderItems.get(0).getSpuId()).getCheckedData();
|
Map<Long, ProductSpuRespDTO> spusMap = productSpuApi.getSpuMap(convertList(orderItems, TradeOrderItemDO::getSpuId));
|
||||||
Assert.notNull(spu);
|
Map<Long, ProductSkuRespDTO> skusMap = productSkuApi.getSkuMap(convertList(orderItems, TradeOrderItemDO::getSkuId));
|
||||||
ProductSkuRespDTO sku = productSkuApi.getSku(orderItems.get(0).getSkuId()).getCheckedData();
|
|
||||||
|
|
||||||
// 每一个订单项,都会去生成分销记录
|
// 每一个订单项,都会去生成分销记录
|
||||||
List<BrokerageAddReqBO> addList = convertList(orderItems,
|
List<BrokerageAddReqBO> addList = convertList(orderItems, item -> {
|
||||||
item -> TradeOrderConvert.INSTANCE.convert(user, item, spu, sku));
|
ProductSpuRespDTO spu = spusMap.get(item.getSpuId());
|
||||||
|
Assert.notNull(spu);
|
||||||
|
ProductSkuRespDTO sku = skusMap.get(item.getSkuId());
|
||||||
|
Assert.notNull(sku);
|
||||||
|
return TradeOrderConvert.INSTANCE.convert(user, item, spu, sku);
|
||||||
|
});
|
||||||
brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, addList);
|
brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, addList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,7 @@ public class MpMaterialServiceImpl implements MpMaterialService {
|
||||||
|
|
||||||
private String uploadFile(String mediaId, File file) {
|
private String uploadFile(String mediaId, File file) {
|
||||||
String path = mediaId + "." + FileTypeUtil.getType(file);
|
String path = mediaId + "." + FileTypeUtil.getType(file);
|
||||||
return fileApi.createFile(path, FileUtil.readBytes(file));
|
return fileApi.createFile(FileUtil.readBytes(file), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ public interface ErrorCodeConstants {
|
||||||
ErrorCode USER_COUNT_MAX = new ErrorCode(1_002_003_008, "创建用户失败,原因:超过租户最大租户配额({})!");
|
ErrorCode USER_COUNT_MAX = new ErrorCode(1_002_003_008, "创建用户失败,原因:超过租户最大租户配额({})!");
|
||||||
ErrorCode USER_IMPORT_INIT_PASSWORD = new ErrorCode(1_002_003_009, "初始密码不能为空");
|
ErrorCode USER_IMPORT_INIT_PASSWORD = new ErrorCode(1_002_003_009, "初始密码不能为空");
|
||||||
ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1_002_003_010, "该手机号尚未注册");
|
ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1_002_003_010, "该手机号尚未注册");
|
||||||
|
ErrorCode USER_REGISTER_DISABLED = new ErrorCode(1_002_003_011, "注册功能已关闭");
|
||||||
|
|
||||||
// ========== 部门模块 1-002-004-000 ==========
|
// ========== 部门模块 1-002-004-000 ==========
|
||||||
ErrorCode DEPT_NAME_DUPLICATE = new ErrorCode(1_002_004_000, "已经存在该名字的部门");
|
ErrorCode DEPT_NAME_DUPLICATE = new ErrorCode(1_002_004_000, "已经存在该名字的部门");
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,11 @@ import javax.validation.Valid;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
|
|
||||||
|
|
||||||
@Tag(name = "管理后台 - 用户个人中心")
|
@Tag(name = "管理后台 - 用户个人中心")
|
||||||
@RestController
|
@RestController
|
||||||
|
|
@ -79,16 +76,4 @@ public class UserProfileController {
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated // TODO @芋艿:逐步替换到 updateUserProfile 接口
|
|
||||||
@RequestMapping(value = "/update-avatar",
|
|
||||||
method = {RequestMethod.POST, RequestMethod.PUT}) // 解决 uni-app 不支持 Put 上传文件的问题
|
|
||||||
@Operation(summary = "上传用户个人头像")
|
|
||||||
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception {
|
|
||||||
if (file.isEmpty()) {
|
|
||||||
throw exception(FILE_IS_EMPTY);
|
|
||||||
}
|
|
||||||
String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream());
|
|
||||||
return success(avatar);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
||||||
import cn.iocoder.yudao.framework.tenant.config.TenantProperties;
|
import cn.iocoder.yudao.framework.tenant.config.TenantProperties;
|
||||||
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
||||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
||||||
|
|
@ -96,6 +97,7 @@ public class TenantServiceImpl implements TenantService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换
|
@DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换
|
||||||
|
@DataPermission(enable = false) // 参见 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1154 说明
|
||||||
public Long createTenant(TenantSaveReqVO createReqVO) {
|
public Long createTenant(TenantSaveReqVO createReqVO) {
|
||||||
// 校验租户名称是否重复
|
// 校验租户名称是否重复
|
||||||
validTenantNameDuplicate(createReqVO.getName(), null);
|
validTenantNameDuplicate(createReqVO.getName(), null);
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,8 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRe
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -73,14 +72,6 @@ public interface AdminUserService {
|
||||||
*/
|
*/
|
||||||
void updateUserPassword(Long id, @Valid UserProfileUpdatePasswordReqVO reqVO);
|
void updateUserPassword(Long id, @Valid UserProfileUpdatePasswordReqVO reqVO);
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户头像
|
|
||||||
*
|
|
||||||
* @param id 用户 id
|
|
||||||
* @param avatarFile 头像文件
|
|
||||||
*/
|
|
||||||
String updateUserAvatar(Long id, InputStream avatarFile) throws Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改密码
|
* 修改密码
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.system.service.user;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||||
|
|
@ -12,7 +12,6 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
||||||
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
||||||
import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
|
import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
|
||||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthRegisterReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthRegisterReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
|
||||||
|
|
@ -33,15 +32,14 @@ import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.mzt.logapi.context.LogRecordContext;
|
import com.mzt.logapi.context.LogRecordContext;
|
||||||
import com.mzt.logapi.service.impl.DiffParseFunction;
|
import com.mzt.logapi.service.impl.DiffParseFunction;
|
||||||
import com.mzt.logapi.starter.annotation.LogRecord;
|
import com.mzt.logapi.starter.annotation.LogRecord;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.ConstraintViolationException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.validation.ConstraintViolationException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
@ -61,6 +59,8 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||||
|
|
||||||
static final String USER_INIT_PASSWORD_KEY = "system.user.init-password";
|
static final String USER_INIT_PASSWORD_KEY = "system.user.init-password";
|
||||||
|
|
||||||
|
static final String USER_REGISTER_ENABLED_KEY = "system.user.register-enabled";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AdminUserMapper userMapper;
|
private AdminUserMapper userMapper;
|
||||||
|
|
||||||
|
|
@ -79,8 +79,6 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||||
@Resource
|
@Resource
|
||||||
private UserPostMapper userPostMapper;
|
private UserPostMapper userPostMapper;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private FileApi fileApi;
|
|
||||||
@Resource
|
@Resource
|
||||||
private ConfigApi configApi;
|
private ConfigApi configApi;
|
||||||
|
|
||||||
|
|
@ -117,14 +115,18 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long registerUser(AuthRegisterReqVO registerReqVO) {
|
public Long registerUser(AuthRegisterReqVO registerReqVO) {
|
||||||
// 1.1 校验账户配合
|
// 1.1 校验是否开启注册
|
||||||
|
if (ObjUtil.notEqual(configApi.getConfigValueByKey(USER_REGISTER_ENABLED_KEY), "true")) {
|
||||||
|
throw exception(USER_REGISTER_DISABLED);
|
||||||
|
}
|
||||||
|
// 1.2 校验账户配合
|
||||||
tenantService.handleTenantInfo(tenant -> {
|
tenantService.handleTenantInfo(tenant -> {
|
||||||
long count = userMapper.selectCount();
|
long count = userMapper.selectCount();
|
||||||
if (count >= tenant.getAccountCount()) {
|
if (count >= tenant.getAccountCount()) {
|
||||||
throw exception(USER_COUNT_MAX, tenant.getAccountCount());
|
throw exception(USER_COUNT_MAX, tenant.getAccountCount());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 1.2 校验正确性
|
// 1.3 校验正确性
|
||||||
validateUserForCreateOrUpdate(null, registerReqVO.getUsername(), null, null, null, null);
|
validateUserForCreateOrUpdate(null, registerReqVO.getUsername(), null, null, null, null);
|
||||||
|
|
||||||
// 2. 插入用户
|
// 2. 插入用户
|
||||||
|
|
@ -198,19 +200,6 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||||
userMapper.updateById(updateObj);
|
userMapper.updateById(updateObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String updateUserAvatar(Long id, InputStream avatarFile) {
|
|
||||||
validateUserExists(id);
|
|
||||||
// 存储文件
|
|
||||||
String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
|
|
||||||
// 更新路径
|
|
||||||
AdminUserDO sysUserDO = new AdminUserDO();
|
|
||||||
sysUserDO.setId(id);
|
|
||||||
sysUserDO.setAvatar(avatar);
|
|
||||||
userMapper.updateById(sysUserDO);
|
|
||||||
return avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_UPDATE_PASSWORD_SUB_TYPE, bizNo = "{{#id}}",
|
@LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_UPDATE_PASSWORD_SUB_TYPE, bizNo = "{{#id}}",
|
||||||
success = SYSTEM_USER_UPDATE_PASSWORD_SUCCESS)
|
success = SYSTEM_USER_UPDATE_PASSWORD_SUCCESS)
|
||||||
|
|
@ -353,7 +342,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private AdminUserDO validateUserForCreateOrUpdate(Long id, String username, String mobile, String email,
|
private AdminUserDO validateUserForCreateOrUpdate(Long id, String username, String mobile, String email,
|
||||||
Long deptId, Set<Long> postIds) {
|
Long deptId, Set<Long> postIds) {
|
||||||
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
||||||
return DataPermissionUtils.executeIgnore(() -> {
|
return DataPermissionUtils.executeIgnore(() -> {
|
||||||
// 校验用户存在
|
// 校验用户存在
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest {
|
||||||
public void testSendSmsCode() {
|
public void testSendSmsCode() {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
String mobile = randomString();
|
String mobile = randomString();
|
||||||
Integer scene = randomEle(SmsSceneEnum.values()).getScene();
|
Integer scene = SmsSceneEnum.ADMIN_MEMBER_LOGIN.getScene();
|
||||||
AuthSmsSendReqVO reqVO = new AuthSmsSendReqVO(mobile, scene);
|
AuthSmsSendReqVO reqVO = new AuthSmsSendReqVO(mobile, scene);
|
||||||
// mock 方法(用户信息)
|
// mock 方法(用户信息)
|
||||||
AdminUserDO user = randomPojo(AdminUserDO.class);
|
AdminUserDO user = randomPojo(AdminUserDO.class);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,10 @@ import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
|
||||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*;
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportExcelVO;
|
||||||
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRespVO;
|
||||||
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO;
|
||||||
|
|
@ -24,6 +27,7 @@ import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
||||||
import cn.iocoder.yudao.module.system.service.dept.PostService;
|
import cn.iocoder.yudao.module.system.service.dept.PostService;
|
||||||
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
||||||
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
|
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
@ -31,14 +35,11 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static cn.hutool.core.util.RandomUtil.randomBytes;
|
|
||||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;
|
import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;
|
||||||
|
|
@ -246,26 +247,6 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||||
assertEquals("encode:yuanma", user.getPassword());
|
assertEquals("encode:yuanma", user.getPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateUserAvatar_success() throws Exception {
|
|
||||||
// mock 数据
|
|
||||||
AdminUserDO dbUser = randomAdminUserDO();
|
|
||||||
userMapper.insert(dbUser);
|
|
||||||
// 准备参数
|
|
||||||
Long userId = dbUser.getId();
|
|
||||||
byte[] avatarFileBytes = randomBytes(10);
|
|
||||||
ByteArrayInputStream avatarFile = new ByteArrayInputStream(avatarFileBytes);
|
|
||||||
// mock 方法
|
|
||||||
String avatar = randomString();
|
|
||||||
when(fileApi.createFile(eq( avatarFileBytes))).thenReturn(avatar);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
userService.updateUserAvatar(userId, avatarFile);
|
|
||||||
// 断言
|
|
||||||
AdminUserDO user = userMapper.selectById(userId);
|
|
||||||
assertEquals(avatar, user.getAvatar());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateUserPassword02_success() {
|
public void testUpdateUserPassword02_success() {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue