Compare commits
14 Commits
6b97685165
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 14c1d9dff0 | |||
| 5254a46de8 | |||
| 12ef1210bc | |||
| d1821bbfcf | |||
| 2fbbf9b0bb | |||
| 427e4b0c84 | |||
| 2404281bff | |||
| 2dafd44c26 | |||
| cfe36dfc8b | |||
| 0797785176 | |||
| 86adb47392 | |||
| 780cd56ffe | |||
| 8cf9140f56 | |||
| 2f56ca07cb |
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
package org.springblade.auth.config;
|
||||
|
||||
import org.springblade.auth.filter.LogoutLogFilter;
|
||||
import org.springblade.auth.granter.IamAwareTokenGranterFactory;
|
||||
import org.springblade.auth.handler.BladeAuthorizationHandler;
|
||||
import org.springblade.auth.handler.BladeLockHandler;
|
||||
@@ -53,9 +54,11 @@ import org.springblade.core.tenant.BladeTenantProperties;
|
||||
import org.springblade.system.feign.IUserClient;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.util.List;
|
||||
@@ -88,6 +91,16 @@ public class BladeAuthConfiguration {
|
||||
return new BladeLogHandler(authLogClient, bladeProperties, serverInfo);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<LogoutLogFilter> logoutLogFilter(BladeLogHandler logHandler) {
|
||||
FilterRegistrationBean<LogoutLogFilter> registration = new FilterRegistrationBean<>();
|
||||
registration.setFilter(new LogoutLogFilter(logHandler));
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("logoutLogFilter");
|
||||
registration.setOrder(Ordered.LOWEST_PRECEDENCE - 100);
|
||||
return registration;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PasswordHandler passwordHandler(OAuth2Properties properties) {
|
||||
return new BladePasswordHandler(properties);
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.auth.filter;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springblade.auth.handler.BladeLogHandler;
|
||||
import org.springblade.core.secure.BladeUser;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 退出登录日志过滤器
|
||||
* 在清除 Token 前解析当前用户并异步写入认证日志
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class LogoutLogFilter extends OncePerRequestFilter implements Ordered {
|
||||
|
||||
private static final String LOGOUT_PATH = "/oauth/logout";
|
||||
|
||||
private final BladeLogHandler logHandler;
|
||||
|
||||
@Override
|
||||
protected boolean shouldNotFilter(HttpServletRequest request) {
|
||||
String path = request.getRequestURI();
|
||||
return StringUtil.isBlank(path) || !path.contains(LOGOUT_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
// 必须在 logout 清 token 之前取用户,否则无法关联账号
|
||||
BladeUser user = AuthUtil.getUser();
|
||||
try {
|
||||
filterChain.doFilter(request, response);
|
||||
} finally {
|
||||
if (user != null) {
|
||||
logHandler.handleLogoutLog(user, request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE - 100;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,12 +29,15 @@ import org.springblade.core.launch.props.BladeProperties;
|
||||
import org.springblade.core.launch.server.ServerInfo;
|
||||
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||
import org.springblade.core.oauth2.service.OAuth2User;
|
||||
import org.springblade.core.secure.BladeUser;
|
||||
import org.springblade.core.tool.utils.DateUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.core.tool.utils.WebUtil;
|
||||
import org.springblade.system.pojo.entity.AuthLog;
|
||||
import org.springblade.system.feign.IAuthLogClient;
|
||||
import org.springblade.system.pojo.entity.AuthLog;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -42,7 +45,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 认证日志处理器
|
||||
* 在用户认证成功时异步记录登录日志
|
||||
* 在用户认证成功/退出时异步记录登录、退出日志
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@@ -50,6 +53,11 @@ import java.util.concurrent.CompletableFuture;
|
||||
@RequiredArgsConstructor
|
||||
public class BladeLogHandler {
|
||||
|
||||
/**
|
||||
* 退出登录授权类型标识
|
||||
*/
|
||||
public static final String GRANT_TYPE_LOGOUT = "logout";
|
||||
|
||||
private final IAuthLogClient authLogClient;
|
||||
private final BladeProperties bladeProperties;
|
||||
private final ServerInfo serverInfo;
|
||||
@@ -72,6 +80,26 @@ public class BladeLogHandler {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录退出登录日志
|
||||
*
|
||||
* @param user 当前登录用户
|
||||
* @param request HTTP 请求
|
||||
*/
|
||||
public void handleLogoutLog(BladeUser user, HttpServletRequest request) {
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
AuthLog authLog = buildLogoutLog(user, request);
|
||||
authLogClient.saveAuthLog(authLog);
|
||||
} catch (Exception exception) {
|
||||
log.error("记录退出日志异常:{}", exception.getMessage(), exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建认证日志实体
|
||||
*
|
||||
@@ -96,4 +124,38 @@ public class BladeLogHandler {
|
||||
return authLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建退出日志实体
|
||||
*
|
||||
* @param user 当前登录用户
|
||||
* @param request HTTP 请求
|
||||
* @return AuthLog
|
||||
*/
|
||||
private AuthLog buildLogoutLog(BladeUser user, HttpServletRequest request) {
|
||||
AuthLog authLog = new AuthLog();
|
||||
authLog.setUserId(user.getUserId());
|
||||
authLog.setTenantId(user.getTenantId());
|
||||
authLog.setServiceId(bladeProperties.getName());
|
||||
authLog.setServerIp(serverInfo.getIpWithPort());
|
||||
authLog.setServerHost(serverInfo.getHostName());
|
||||
authLog.setEnv(bladeProperties.getEnv());
|
||||
authLog.setAccount(user.getAccount());
|
||||
authLog.setRealName(resolveRealName(user));
|
||||
authLog.setGrantType(GRANT_TYPE_LOGOUT);
|
||||
authLog.setRemoteIp(WebUtil.getIP(request));
|
||||
authLog.setUserAgent(WebUtil.getUserAgent(request));
|
||||
authLog.setLoginTime(DateUtil.now());
|
||||
return authLog;
|
||||
}
|
||||
|
||||
private String resolveRealName(BladeUser user) {
|
||||
if (StringUtil.isNotBlank(user.getNickName())) {
|
||||
return user.getNickName();
|
||||
}
|
||||
if (StringUtil.isNotBlank(user.getUserName())) {
|
||||
return user.getUserName();
|
||||
}
|
||||
return user.getAccount();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,16 @@
|
||||
的 WebFlux 网关里启动即崩。业务服务经 blade-core-boot 自带 starter-log,运行时不受影响。 -->
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-auto</artifactId>
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.aspect;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springblade.core.log.annotation.ApiLog;
|
||||
import org.springblade.core.log.constant.EventConstant;
|
||||
import org.springblade.core.log.event.ApiLogEvent;
|
||||
import org.springblade.core.log.model.LogApi;
|
||||
import org.springblade.core.log.utils.LogAbstractUtil;
|
||||
import org.springblade.core.tool.constant.BladeConstant;
|
||||
import org.springblade.core.tool.utils.SpringUtil;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.core.tool.utils.WebUtil;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 增删改操作日志切面
|
||||
* 自动拦截 Controller 中的 save/submit/update/remove/delete 等方法,写入 blade_log_api
|
||||
* 已标注 {@link ApiLog} 的方法跳过,避免重复记录
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
public class OperationApiLogAspect {
|
||||
|
||||
@Around("""
|
||||
execution(* org.springblade..controller..*.save*(..))
|
||||
|| execution(* org.springblade..controller..*.submit*(..))
|
||||
|| execution(* org.springblade..controller..*.update*(..))
|
||||
|| execution(* org.springblade..controller..*.remove*(..))
|
||||
|| execution(* org.springblade..controller..*.delete*(..))
|
||||
""")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
if (!shouldRecord(method)) {
|
||||
return point.proceed();
|
||||
}
|
||||
|
||||
String className = point.getTarget().getClass().getName();
|
||||
String methodName = method.getName();
|
||||
String title = resolveTitle(point.getTarget().getClass(), method);
|
||||
long beginTime = System.currentTimeMillis();
|
||||
Object result = point.proceed();
|
||||
long time = System.currentTimeMillis() - beginTime;
|
||||
try {
|
||||
publishEvent(methodName, className, title, time);
|
||||
} catch (Exception e) {
|
||||
log.warn("记录操作日志失败: {}#{} - {}", className, methodName, e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean shouldRecord(Method method) {
|
||||
if (method.getAnnotation(ApiLog.class) != null) {
|
||||
return false;
|
||||
}
|
||||
HttpServletRequest request = WebUtil.getRequest();
|
||||
if (request == null) {
|
||||
return true;
|
||||
}
|
||||
String httpMethod = request.getMethod();
|
||||
return !"GET".equalsIgnoreCase(httpMethod)
|
||||
&& !"HEAD".equalsIgnoreCase(httpMethod)
|
||||
&& !"OPTIONS".equalsIgnoreCase(httpMethod);
|
||||
}
|
||||
|
||||
private String resolveTitle(Class<?> targetClass, Method method) {
|
||||
Tag tag = AnnotationUtils.findAnnotation(targetClass, Tag.class);
|
||||
Operation operation = AnnotationUtils.findAnnotation(method, Operation.class);
|
||||
String module = tag == null ? null : firstNonBlank(tag.name(), tag.description());
|
||||
String action = operation == null ? null : firstNonBlank(operation.summary(), operation.description());
|
||||
if (StringUtil.isNotBlank(module) && StringUtil.isNotBlank(action)) {
|
||||
return module + "-" + action;
|
||||
}
|
||||
if (StringUtil.isNotBlank(action)) {
|
||||
return action;
|
||||
}
|
||||
String simpleName = targetClass.getSimpleName().replace("Controller", "");
|
||||
return simpleName + "-" + method.getName();
|
||||
}
|
||||
|
||||
private String firstNonBlank(String... values) {
|
||||
if (values == null) {
|
||||
return null;
|
||||
}
|
||||
for (String value : values) {
|
||||
if (StringUtil.isNotBlank(value)) {
|
||||
return value.trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void publishEvent(String methodName, String methodClass, String title, long time) {
|
||||
HttpServletRequest request = WebUtil.getRequest();
|
||||
LogApi logApi = new LogApi();
|
||||
logApi.setType(BladeConstant.LOG_NORMAL_TYPE);
|
||||
logApi.setTitle(title);
|
||||
logApi.setTime(String.valueOf(time));
|
||||
logApi.setMethodClass(methodClass);
|
||||
logApi.setMethodName(methodName);
|
||||
LogAbstractUtil.addRequestInfoToLog(request, logApi);
|
||||
Map<String, Object> event = new HashMap<>(16);
|
||||
event.put(EventConstant.EVENT_LOG, logApi);
|
||||
SpringUtil.publishEvent(new ApiLogEvent(event));
|
||||
}
|
||||
|
||||
}
|
||||
+15
-4
@@ -26,16 +26,27 @@
|
||||
package org.springblade.common.config;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springblade.common.aspect.OperationApiLogAspect;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* 公共封装包配置类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@AllArgsConstructor
|
||||
@AutoConfiguration
|
||||
public class BladeCommonConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
||||
@ConditionalOnClass(name = "org.springblade.core.log.event.ApiLogEvent")
|
||||
@ConditionalOnProperty(value = "blade.log.operation.enabled", havingValue = "true", matchIfMissing = true)
|
||||
public OperationApiLogAspect operationApiLogAspect() {
|
||||
return new OperationApiLogAspect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.utils;
|
||||
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 登录密码强度规则工具
|
||||
* 规则:大于8位,同时包含字母、数字、特殊字符(.!@#$%^&*)
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public final class PasswordRuleUtil {
|
||||
|
||||
/**
|
||||
* 允许的特殊字符集合
|
||||
*/
|
||||
public static final String SPECIAL_CHARS = ".!@#$%^&*";
|
||||
|
||||
/**
|
||||
* 最小长度(大于 8 位 => 至少 9 位)
|
||||
*/
|
||||
public static final int MIN_LENGTH = 9;
|
||||
|
||||
/**
|
||||
* 自动生成密码长度
|
||||
*/
|
||||
public static final int GENERATE_LENGTH = 10;
|
||||
|
||||
/**
|
||||
* 规则提示文案
|
||||
*/
|
||||
public static final String RULE_MESSAGE = "密码须大于8位,且同时包含字母、数字和特殊字符(.!@#$%^&*)";
|
||||
|
||||
private static final String LETTERS = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
private static final String DIGITS = "23456789";
|
||||
private static final String ALL_CHARS = LETTERS + DIGITS + SPECIAL_CHARS;
|
||||
private static final Pattern PASSWORD_PATTERN = Pattern.compile(
|
||||
"^(?=.*[A-Za-z])(?=.*\\d)(?=.*[.!@#$%^&*]).{" + MIN_LENGTH + ",}$"
|
||||
);
|
||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
||||
|
||||
private PasswordRuleUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验密码是否符合强度规则
|
||||
*
|
||||
* @param password 明文密码
|
||||
* @return true-符合
|
||||
*/
|
||||
public static boolean isValid(String password) {
|
||||
return StringUtil.isNotBlank(password) && PASSWORD_PATTERN.matcher(password).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成符合规则的随机密码
|
||||
*
|
||||
* @return 随机密码
|
||||
*/
|
||||
public static String generate() {
|
||||
List<Character> chars = new ArrayList<>(GENERATE_LENGTH);
|
||||
chars.add(LETTERS.charAt(SECURE_RANDOM.nextInt(LETTERS.length())));
|
||||
chars.add(DIGITS.charAt(SECURE_RANDOM.nextInt(DIGITS.length())));
|
||||
chars.add(SPECIAL_CHARS.charAt(SECURE_RANDOM.nextInt(SPECIAL_CHARS.length())));
|
||||
for (int i = chars.size(); i < GENERATE_LENGTH; i++) {
|
||||
chars.add(ALL_CHARS.charAt(SECURE_RANDOM.nextInt(ALL_CHARS.length())));
|
||||
}
|
||||
Collections.shuffle(chars, SECURE_RANDOM);
|
||||
StringBuilder password = new StringBuilder(GENERATE_LENGTH);
|
||||
for (Character ch : chars) {
|
||||
password.append(ch);
|
||||
}
|
||||
return password.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.springblade.common.config.BladeCommonConfiguration
|
||||
+12
@@ -39,6 +39,7 @@ public interface IBusinessProcessClient {
|
||||
String QUERY_BUSINESS_PROCESS_SNAPSHOT = API_PREFIX + "/queryBusinessProcessSnapshot";
|
||||
String QUERY_APPROVED_RECORD_LIST = API_PREFIX + "/queryApprovedRecordsNoAttachments";
|
||||
String GET_CURRENT_NODES = API_PREFIX + "/getCurrentNodes";
|
||||
String GET_PROCESS_INFO = API_PREFIX + "/getProcessInfo";
|
||||
|
||||
/**
|
||||
* 提交业务流程
|
||||
@@ -114,4 +115,15 @@ public interface IBusinessProcessClient {
|
||||
@GetMapping(GET_CURRENT_NODES)
|
||||
FR<Object> getCurrentNodes(@RequestParam("processInstanceId") String processInstanceId,
|
||||
@RequestParam(value = "loginName", required = false) String loginName);
|
||||
|
||||
/**
|
||||
* 获取流程实例详情
|
||||
*
|
||||
* @param processInstanceId 流程实例id
|
||||
* @param loginName MK登录名(手机号)
|
||||
* @return 流程实例详情
|
||||
*/
|
||||
@GetMapping(GET_PROCESS_INFO)
|
||||
FR<Object> getProcessInfo(@RequestParam("processInstanceId") String processInstanceId,
|
||||
@RequestParam(value = "loginName", required = false) String loginName);
|
||||
}
|
||||
|
||||
+19
@@ -25,10 +25,13 @@
|
||||
*/
|
||||
package org.springblade.system.pojo.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -185,4 +188,20 @@ public class Dept extends TenantEntity {
|
||||
@Schema(description = "是否平台公司:0否,1是")
|
||||
private Integer isPlatformCompany;
|
||||
|
||||
/**
|
||||
* OA主键,仅同步记录,不对外展示
|
||||
*/
|
||||
@JsonIgnore
|
||||
@Schema(description = "OA主键", hidden = true)
|
||||
@TableField(updateStrategy = FieldStrategy.NOT_NULL)
|
||||
private String oaId;
|
||||
|
||||
/**
|
||||
* OA上级主键,仅同步记录,不对外展示
|
||||
*/
|
||||
@JsonIgnore
|
||||
@Schema(description = "OA上级主键", hidden = true)
|
||||
@TableField(updateStrategy = FieldStrategy.NOT_NULL)
|
||||
private String oaSupSubComId;
|
||||
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package org.springblade.transport.feign;
|
||||
|
||||
import org.springblade.core.tool.api.FR;
|
||||
import org.springblade.transport.pojo.dto.CustomerProcessNodeSyncDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* 客商档案 Feign接口
|
||||
*/
|
||||
@FeignClient(value = "blade-transport")
|
||||
public interface ICustomerArchiveClient {
|
||||
|
||||
String API_PREFIX = "/feign/client/customerArchive";
|
||||
String SYNC_PROCESS_NODE = API_PREFIX + "/syncProcessNode";
|
||||
|
||||
/**
|
||||
* 按 MK 当前节点同步客商当前节点、当前处理人和审批状态
|
||||
*
|
||||
* @param param 同步参数
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping(SYNC_PROCESS_NODE)
|
||||
FR<Boolean> syncProcessNode(@RequestBody CustomerProcessNodeSyncDTO param);
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package org.springblade.transport.feign;
|
||||
|
||||
import org.springblade.core.tool.api.FR;
|
||||
import org.springblade.transport.pojo.dto.MkProcessSyncDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* MK 业务流程同步 Feign
|
||||
*/
|
||||
@FeignClient(value = "blade-transport")
|
||||
public interface IMkProcessClient {
|
||||
|
||||
String API_PREFIX = "/feign/client/mkProcess";
|
||||
String APPLY = API_PREFIX + "/apply";
|
||||
|
||||
@PostMapping(APPLY)
|
||||
FR<Boolean> apply(@RequestBody MkProcessSyncDTO param);
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package org.springblade.transport.pojo.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 客商流程当前节点同步参数
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "客商流程当前节点同步参数")
|
||||
public class CustomerProcessNodeSyncDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "客商ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "当前节点")
|
||||
private String currentNode;
|
||||
|
||||
@Schema(description = "当前处理人")
|
||||
private String currentProcessor;
|
||||
|
||||
@Schema(description = "审批状态")
|
||||
private String approvalStatus;
|
||||
|
||||
@Schema(description = "MK 流程实例详情,传入后按 currentHandlers.fdName 和 handlerInfos.nodeName 回写")
|
||||
private Object processInfo;
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package org.springblade.transport.pojo.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* MK 流程节点同步参数
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "MK 流程节点同步参数")
|
||||
public class MkProcessSyncDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "业务类型,如 project-apply")
|
||||
private String bizType;
|
||||
|
||||
@Schema(description = "业务主键")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "动作:sync / approve / reject")
|
||||
private String action;
|
||||
|
||||
@Schema(description = "处理人姓名")
|
||||
private String processorName;
|
||||
|
||||
@Schema(description = "MK 流程实例详情")
|
||||
private Object processInfo;
|
||||
}
|
||||
+3
@@ -59,6 +59,9 @@ public class CustomerReceiptAccount extends TenantEntity {
|
||||
@Schema(description = "开户行名称")
|
||||
private String bankName;
|
||||
|
||||
@Schema(description = "联行号")
|
||||
private String cnapsCode;
|
||||
|
||||
@Schema(description = "银行账号")
|
||||
private String bankAccount;
|
||||
|
||||
|
||||
+14
@@ -30,6 +30,8 @@ import org.springblade.transport.pojo.entity.ProjectApply;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 项目立项视图实体类
|
||||
@@ -104,4 +106,16 @@ public class ProjectApplyVO extends ProjectApply {
|
||||
@Schema(description = "风险计算额度基数")
|
||||
private BigDecimal maxFundLimit;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "货物类型字典,公开页回显使用")
|
||||
private List<Map<String, String>> cargoTypeOptions;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "运输类型字典,公开页回显使用")
|
||||
private List<Map<String, String>> transportTypeOptions;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "结算方式字典,公开页回显使用")
|
||||
private List<Map<String, String>> settlementModeOptions;
|
||||
|
||||
}
|
||||
|
||||
@@ -62,6 +62,10 @@
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-mk-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-transport-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 其他依赖 -->
|
||||
<dependency>
|
||||
|
||||
+6
@@ -60,6 +60,12 @@ public class BusinessProcessController extends BladeController {
|
||||
return R.data(businessProcessService.processSubmit(param));
|
||||
}
|
||||
|
||||
@PostMapping("/processDelete")
|
||||
@ApiOperationSupport(order = 7)
|
||||
public R<Boolean> processDelete(@RequestBody MKProcessCreateDTO param) {
|
||||
return R.data(businessProcessService.processDelete(param == null ? null : param.getFormInstanceId()));
|
||||
}
|
||||
|
||||
@GetMapping("/isEditView")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(summary = "是否编辑页", description = "传入业务id")
|
||||
|
||||
+8
@@ -86,4 +86,12 @@ public class BusinessProcessClient implements IBusinessProcessClient {
|
||||
@RequestParam(value = "loginName", required = false) String loginName) {
|
||||
return FR.data(businessProcessService.getCurrentNodes(processInstanceId, loginName));
|
||||
}
|
||||
|
||||
@PreAuth(AuthConstant.PERMIT_ALL)
|
||||
@GetMapping(GET_PROCESS_INFO)
|
||||
@Override
|
||||
public FR<Object> getProcessInfo(@RequestParam("processInstanceId") String processInstanceId,
|
||||
@RequestParam(value = "loginName", required = false) String loginName) {
|
||||
return FR.data(businessProcessService.getProcessInfo(processInstanceId, loginName));
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -34,6 +34,14 @@ public interface IBusinessProcessService extends IService<BusinessProcess> {
|
||||
*/
|
||||
String processSubmit(MKProcessCreateDTO param);
|
||||
|
||||
/**
|
||||
* 按业务表单实例 id 删除 MK 流程(不删除本地业务流程记录,供驳回后重新提交使用)
|
||||
*
|
||||
* @param formInstanceId 业务表单实例 id
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean processDelete(String formInstanceId);
|
||||
|
||||
/**
|
||||
* 获取流程当前节点详情
|
||||
*
|
||||
@@ -43,6 +51,15 @@ public interface IBusinessProcessService extends IService<BusinessProcess> {
|
||||
*/
|
||||
List<?> getCurrentNodes(String processInstanceId, String loginName);
|
||||
|
||||
/**
|
||||
* 获取流程实例详情
|
||||
*
|
||||
* @param processInstanceId 流程实例id
|
||||
* @param loginName MK登录名(手机号),可为空,为空时按流程发起人解析
|
||||
* @return 流程实例详情
|
||||
*/
|
||||
Object getProcessInfo(String processInstanceId, String loginName);
|
||||
|
||||
/**
|
||||
* 修改业务流程状态
|
||||
* @param param
|
||||
|
||||
+166
-2
@@ -15,6 +15,7 @@ import org.springblade.process.pojo.enums.ApproveStatusEnum;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.log.utils.AssertUtils;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.api.FR;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.process.convert.ApprovalConvert;
|
||||
import org.springblade.process.convert.BusinessProcessConvert;
|
||||
@@ -41,12 +42,17 @@ import org.springblade.thirdparty.mk.pojo.dto.approval.MKProcessDTO;
|
||||
import org.springblade.thirdparty.mk.pojo.dto.sort.*;
|
||||
import org.springblade.thirdparty.mk.pojo.vo.*;
|
||||
import org.springblade.thirdparty.mk.service.IMKService;
|
||||
import org.springblade.transport.feign.ICustomerArchiveClient;
|
||||
import org.springblade.transport.feign.IMkProcessClient;
|
||||
import org.springblade.transport.pojo.dto.CustomerProcessNodeSyncDTO;
|
||||
import org.springblade.transport.pojo.dto.MkProcessSyncDTO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 业务流程关联表 服务实现类
|
||||
@@ -64,6 +70,8 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
private final MKProperties mkProperties;
|
||||
private final ApprovalConvert approvalConvert;
|
||||
private final IUserService userService;
|
||||
private final ICustomerArchiveClient customerArchiveClient;
|
||||
private final IMkProcessClient mkProcessClient;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
@@ -128,8 +136,17 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
AssertUtils.notBlank(loginName, "当前用户手机号为空,无法提交审核流");
|
||||
param.setSubmitIdentity(loginName);
|
||||
param.setLoginName(loginName);
|
||||
log.info("调用mk processSubmit 参数:{}", JSON.toJSONString(param));
|
||||
String processInstanceId = mkService.processSubmit(param);
|
||||
String bizType = param.getBizType();
|
||||
MKProcessCreateDTO mkParam = new MKProcessCreateDTO();
|
||||
mkParam.setFormInstanceId(param.getFormInstanceId());
|
||||
mkParam.setSubject(param.getSubject());
|
||||
mkParam.setSubmitIdentity(loginName);
|
||||
mkParam.setLoginName(loginName);
|
||||
mkParam.setTemplateCode(param.getTemplateCode());
|
||||
mkParam.setFormValues(param.getFormValues());
|
||||
mkParam.setTempVarData(param.getTempVarData());
|
||||
log.info("调用mk processSubmit 参数:{}", JSON.toJSONString(mkParam));
|
||||
String processInstanceId = mkService.processSubmit(mkParam);
|
||||
AssertUtils.notBlank(processInstanceId, "提交流程失败,未返回流程实例id");
|
||||
|
||||
Long bizId;
|
||||
@@ -164,9 +181,42 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
businessProcess.setApproveStatus(ApproveStatusEnum.APPROVING.getValue());
|
||||
this.saveOrUpdate(businessProcess);
|
||||
this.getCurrentNodes(processInstanceId, loginName);
|
||||
Object processInfo = this.getProcessInfo(processInstanceId, loginName);
|
||||
this.syncBizFromProcessInfo(bizType, param.getFormInstanceId(), processInfo);
|
||||
return processInstanceId;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean processDelete(String formInstanceId) {
|
||||
AssertUtils.notBlank(formInstanceId, "表单实例id不能为空");
|
||||
Long bizId;
|
||||
try {
|
||||
bizId = Long.valueOf(formInstanceId);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ServiceException("表单实例id格式不正确");
|
||||
}
|
||||
BusinessProcess businessProcess = this.getOne(Wrappers.<BusinessProcess>lambdaQuery()
|
||||
.eq(BusinessProcess::getBizId, bizId)
|
||||
);
|
||||
if (businessProcess == null || StringUtil.isBlank(businessProcess.getProcessInstanceId())) {
|
||||
log.warn("客商驳回后删除流程跳过,未找到流程实例 formInstanceId={}", formInstanceId);
|
||||
return true;
|
||||
}
|
||||
String loginName = businessProcess.getPromoterLoginName();
|
||||
if (StringUtil.isBlank(loginName)) {
|
||||
loginName = resolveCurrentUserPhone();
|
||||
}
|
||||
AssertUtils.notBlank(loginName, "当前用户手机号为空,无法删除审核流");
|
||||
log.info("调用mk processDelete processInstanceId={} loginName={} formInstanceId={}",
|
||||
businessProcess.getProcessInstanceId(), loginName, formInstanceId);
|
||||
boolean deleted = mkService.processDelete(businessProcess.getProcessInstanceId(), loginName);
|
||||
if (!deleted) {
|
||||
throw new ServiceException("删除MK流程失败");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> getCurrentNodes(String processInstanceId, String loginName) {
|
||||
if (StringUtils.isBlank(processInstanceId)) {
|
||||
@@ -193,6 +243,120 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProcessInfo(String processInstanceId, String loginName) {
|
||||
if (StringUtils.isBlank(processInstanceId)) {
|
||||
log.warn("查询流程实例详情失败,processInstanceId为空");
|
||||
return null;
|
||||
}
|
||||
String resolvedLoginName = loginName;
|
||||
if (StringUtils.isBlank(resolvedLoginName)) {
|
||||
BusinessProcess businessProcess = this.getBusinessProcessByProcessInstanceId(processInstanceId);
|
||||
resolvedLoginName = resolvePromoterLoginName(businessProcess, null);
|
||||
}
|
||||
if (StringUtils.isBlank(resolvedLoginName)) {
|
||||
log.warn("查询流程实例详情失败,loginName为空 processInstanceId={}", processInstanceId);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Object processInfo = mkService.getProcessInfo(processInstanceId, resolvedLoginName);
|
||||
log.info("获取流程实例详情 processInstanceId={} loginName={} result={}",
|
||||
processInstanceId, resolvedLoginName, JSON.toJSONString(processInfo));
|
||||
return processInfo;
|
||||
} catch (Exception e) {
|
||||
log.error("查询流程实例详情异常 processInstanceId={} loginName={}", processInstanceId, resolvedLoginName, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void syncBizFromProcessInfo(String bizType, String formInstanceId, Object processInfo) {
|
||||
if (StringUtils.isBlank(formInstanceId) || processInfo == null) {
|
||||
log.warn("同步业务当前节点跳过,formInstanceId或流程实例详情为空 formInstanceId={}", formInstanceId);
|
||||
return;
|
||||
}
|
||||
Long bizId;
|
||||
try {
|
||||
bizId = Long.valueOf(formInstanceId);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("同步业务当前节点失败,表单实例id不是数字:{}", formInstanceId);
|
||||
return;
|
||||
}
|
||||
String resolvedBizType = StringUtils.isBlank(bizType) ? "customer-archive" : bizType;
|
||||
if ("customer-archive".equals(resolvedBizType)) {
|
||||
this.syncCustomerArchiveFromProcessInfo(formInstanceId, processInfo);
|
||||
return;
|
||||
}
|
||||
MkProcessSyncDTO param = new MkProcessSyncDTO();
|
||||
param.setBizType(resolvedBizType);
|
||||
param.setId(bizId);
|
||||
param.setAction("sync");
|
||||
param.setProcessInfo(processInfo);
|
||||
try {
|
||||
FR<Boolean> result = mkProcessClient.apply(param);
|
||||
log.info("同步业务当前节点完成 bizType={} bizId={} result={}",
|
||||
resolvedBizType, bizId, JSON.toJSONString(result));
|
||||
} catch (Exception e) {
|
||||
log.error("同步业务当前节点异常 bizType={} bizId={}", resolvedBizType, bizId, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncCustomerArchiveFromProcessInfo(String formInstanceId, Object processInfo) {
|
||||
if (StringUtils.isBlank(formInstanceId) || processInfo == null) {
|
||||
log.warn("同步客商当前节点跳过,formInstanceId或流程实例详情为空 formInstanceId={}", formInstanceId);
|
||||
return;
|
||||
}
|
||||
Long customerId;
|
||||
try {
|
||||
customerId = Long.valueOf(formInstanceId);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("同步客商当前节点失败,表单实例id不是数字:{}", formInstanceId);
|
||||
return;
|
||||
}
|
||||
CustomerProcessNodeSyncDTO param = new CustomerProcessNodeSyncDTO();
|
||||
param.setId(customerId);
|
||||
param.setProcessInfo(processInfo);
|
||||
param.setApprovalStatus("reviewing");
|
||||
try {
|
||||
FR<Boolean> result = customerArchiveClient.syncProcessNode(param);
|
||||
log.info("同步客商当前节点完成 customerId={} result={}", customerId, JSON.toJSONString(result));
|
||||
} catch (Exception e) {
|
||||
log.error("同步客商当前节点异常 customerId={}", customerId, e);
|
||||
}
|
||||
}
|
||||
|
||||
private String readMkNodeName(Object node) {
|
||||
if (node instanceof MKNodeVO vo) {
|
||||
return vo.getNodeName();
|
||||
}
|
||||
if (node instanceof Map<?, ?> map) {
|
||||
Object value = map.get("nodeName");
|
||||
return value == null ? null : String.valueOf(value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Stream<String> readMkHandlerNames(Object node) {
|
||||
List<MKNodeHandlerVO> handlers = null;
|
||||
if (node instanceof MKNodeVO vo) {
|
||||
handlers = vo.getNodeHandlers();
|
||||
} else if (node instanceof Map<?, ?> map && map.get("nodeHandlers") instanceof List<?> list) {
|
||||
return list.stream().map(item -> {
|
||||
if (item instanceof MKNodeHandlerVO handler) {
|
||||
return handler.getHandlerName();
|
||||
}
|
||||
if (item instanceof Map<?, ?> handlerMap) {
|
||||
Object value = handlerMap.get("handlerName");
|
||||
return value == null ? null : String.valueOf(value);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
if (CollectionUtil.isEmpty(handlers)) {
|
||||
return Stream.empty();
|
||||
}
|
||||
return handlers.stream().map(MKNodeHandlerVO::getHandlerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从当前登录用户实体读取真实手机号(绕过接口返回脱敏)
|
||||
*/
|
||||
|
||||
+14
@@ -173,6 +173,20 @@ public class DeptController extends BladeController {
|
||||
return R.data(deptService.syncIamOrganizations());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除非顶级组织,供自动同步前确认后调用
|
||||
*/
|
||||
@IsAdmin
|
||||
@PostMapping("/clear-non-top")
|
||||
@ApiOperationSupport(order = 8)
|
||||
@Operation(summary = "清除非顶级组织")
|
||||
public R<Integer> clearNonTopDepts() {
|
||||
int clearedCount = deptService.clearNonTopDepts();
|
||||
CacheUtil.clear(SYS_CACHE);
|
||||
CacheUtil.clear(SYS_CACHE, Boolean.FALSE);
|
||||
return R.data(clearedCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从OA按页同步公司
|
||||
*/
|
||||
|
||||
+10
@@ -80,6 +80,9 @@ public interface DeptConvert {
|
||||
}
|
||||
// 公司所属公司编码就是他自己的部门编码
|
||||
dept.setBelongCompanyCode(dept.getDeptCode());
|
||||
// OA主键与上级OA主键,分批同步结束后用于重建层级
|
||||
dept.setOaId(company.getId());
|
||||
dept.setOaSupSubComId(company.getSupsubcomid());
|
||||
// 显示顺序处理
|
||||
dept.setSort(OAUtils.parseInt(company.getShoworder()));
|
||||
// 部门类型,公司
|
||||
@@ -100,6 +103,13 @@ public interface DeptConvert {
|
||||
Dept dept = this.baseConvert(oaDept);
|
||||
// 部门编码添加前缀
|
||||
dept.setDeptCode(OAConvertConstant.DEPARTMENT_OA_PREFIX + oaDept.getId());
|
||||
// OA主键;上级为根部门时记录所属公司OA主键,否则记录上级部门OA主键
|
||||
dept.setOaId(oaDept.getId());
|
||||
if (OAConstant.ROOT_COMPANY_ID.equals(oaDept.getSupdepid())) {
|
||||
dept.setOaSupSubComId(oaDept.getSubcompanyid1());
|
||||
} else {
|
||||
dept.setOaSupSubComId(oaDept.getSupdepid());
|
||||
}
|
||||
// 部门所属公司编码就是他所属公司编码加前缀
|
||||
dept.setBelongCompanyCode(OAConvertConstant.COMPANY_OA_PREFIX + dept.getBelongCompanyCode());
|
||||
String parentCode = dept.getParentCode();
|
||||
|
||||
+19
@@ -146,6 +146,13 @@ public interface IDeptService extends IService<Dept> {
|
||||
*/
|
||||
boolean removeDept(String ids);
|
||||
|
||||
/**
|
||||
* 删除非顶级组织,顶级组织(父级为 0)保留
|
||||
*
|
||||
* @return 删除数量
|
||||
*/
|
||||
int clearNonTopDepts();
|
||||
|
||||
/**
|
||||
* 新增或修改部门
|
||||
* <p>
|
||||
@@ -187,4 +194,16 @@ public interface IDeptService extends IService<Dept> {
|
||||
*/
|
||||
void updateAncestors(Date startTime);
|
||||
|
||||
/**
|
||||
* 按 OA 主键与上级 OA 主键重建组织、部门父子关系,并刷新祖级列表
|
||||
*/
|
||||
void rebuildOaHierarchy();
|
||||
|
||||
/**
|
||||
* 删除 OA 同步后无法挂到上级的组织(上级 OA 主键在本地不存在),并级联删除其子级
|
||||
*
|
||||
* @return 删除数量
|
||||
*/
|
||||
int removeOaOrphansWithoutParent();
|
||||
|
||||
}
|
||||
|
||||
+284
-29
@@ -46,6 +46,7 @@ import org.springblade.system.cache.SysCache;
|
||||
import org.springblade.system.mapper.DeptMapper;
|
||||
import org.springblade.system.pojo.entity.Dept;
|
||||
import org.springblade.system.pojo.entity.User;
|
||||
import org.springblade.system.pojo.enums.DeptCategory;
|
||||
import org.springblade.system.pojo.vo.DeptVO;
|
||||
import org.springblade.system.pojo.vo.UserVO;
|
||||
import org.springblade.system.props.IamSyncProperties;
|
||||
@@ -53,6 +54,7 @@ import org.springblade.system.service.IDeptService;
|
||||
import org.springblade.system.service.IUserService;
|
||||
import org.springblade.system.wrapper.DeptWrapper;
|
||||
import org.springblade.system.wrapper.UserWrapper;
|
||||
import org.springblade.thirdparty.oa.constant.OAConstant;
|
||||
import org.springblade.thirdparty.oa.constant.OAConvertConstant;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -232,6 +234,21 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
|
||||
return removeByIds(idList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int clearNonTopDepts() {
|
||||
Long nonTopCount = this.count(Wrappers.<Dept>lambdaQuery()
|
||||
.isNotNull(Dept::getParentId)
|
||||
.ne(Dept::getParentId, BladeConstant.TOP_PARENT_ID));
|
||||
if (nonTopCount == null || nonTopCount == 0L) {
|
||||
return 0;
|
||||
}
|
||||
this.remove(Wrappers.<Dept>lambdaQuery()
|
||||
.isNotNull(Dept::getParentId)
|
||||
.ne(Dept::getParentId, BladeConstant.TOP_PARENT_ID));
|
||||
return nonTopCount.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean submit(Dept dept) {
|
||||
@@ -451,8 +468,12 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
|
||||
}
|
||||
|
||||
private void validateDeptCategory(Dept dept, Dept parent) {
|
||||
// 顶级组织不要求选择上级组织
|
||||
if (parent == null) {
|
||||
throw new ServiceException("请选择上级组织");
|
||||
if (Integer.valueOf(6).equals(dept.getDeptCategory()) && Func.isEmpty(dept.getCarrierCustomerId())) {
|
||||
throw new ServiceException("请选择承运商");
|
||||
}
|
||||
return;
|
||||
}
|
||||
List<Integer> allowedCategories;
|
||||
if (BladeConstant.TOP_PARENT_ID.equals(parent.getParentId())) {
|
||||
@@ -483,13 +504,24 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
|
||||
if (deptCode.length() > 30) {
|
||||
throw new ServiceException("组织编码不能超过30个字符");
|
||||
}
|
||||
if (parent == null || StringUtil.isBlank(parent.getDeptCode())) {
|
||||
// 顶级组织不依赖上级编码
|
||||
if (parent == null) {
|
||||
this.ensureDeptCodeUnique(dept, deptCode);
|
||||
dept.setDeptCode(deptCode);
|
||||
return;
|
||||
}
|
||||
if (StringUtil.isBlank(parent.getDeptCode())) {
|
||||
throw new ServiceException("请选择已配置组织编码的上级组织");
|
||||
}
|
||||
String pattern = Pattern.quote(parent.getDeptCode()) + "-\\d+";
|
||||
if (!deptCode.matches(pattern)) {
|
||||
throw new ServiceException("组织编码格式应为:上级编码-分段数字");
|
||||
}
|
||||
this.ensureDeptCodeUnique(dept, deptCode);
|
||||
dept.setDeptCode(deptCode);
|
||||
}
|
||||
|
||||
private void ensureDeptCodeUnique(Dept dept, String deptCode) {
|
||||
LambdaQueryWrapper<Dept> queryWrapper = Wrappers.<Dept>lambdaQuery().eq(Dept::getDeptCode, deptCode);
|
||||
if (Func.isNotEmpty(dept.getId())) {
|
||||
queryWrapper.ne(Dept::getId, dept.getId());
|
||||
@@ -497,7 +529,6 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
|
||||
if (baseMapper.selectCount(queryWrapper) > 0) {
|
||||
throw new ServiceException("组织编码已存在");
|
||||
}
|
||||
dept.setDeptCode(deptCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -540,24 +571,243 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
|
||||
return UserWrapper.build().listVO(userList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一的租户范围过滤:超管放行,其他用户强制限定为当前会话租户。
|
||||
*/
|
||||
private void applyTenantScope(QueryWrapper<Dept> queryWrapper) {
|
||||
if (!AuthUtil.isAdministrator()) {
|
||||
queryWrapper.lambda().eq(Dept::getTenantId, AuthUtil.getTenantId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void updateAncestors(Date startTime) {
|
||||
// 1. 查询需要更新祖级列表的部门
|
||||
List<Dept> list = this.list(Wrappers.<Dept>lambdaQuery()
|
||||
// 祖级列表为空
|
||||
this.refreshAncestors(false, startTime);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void rebuildOaHierarchy() {
|
||||
List<Dept> oaDeptList = this.list(Wrappers.<Dept>lambdaQuery()
|
||||
.isNotNull(Dept::getOaId)
|
||||
.ne(Dept::getOaId, ""));
|
||||
if (CollectionUtil.isEmpty(oaDeptList)) {
|
||||
log.info("没有记录OA主键的组织,跳过层级重建");
|
||||
return;
|
||||
}
|
||||
Map<String, Dept> companyByOaId = this.indexByOaId(oaDeptList, DeptCategory.COMPANY.getCode());
|
||||
Map<String, Dept> departmentByOaId = this.indexByOaId(oaDeptList, DeptCategory.DEPT.getCode());
|
||||
Map<Long, Long> desiredParentIdMap = new LinkedHashMap<>();
|
||||
Map<Long, String> desiredParentCodeMap = new HashMap<>();
|
||||
for (Dept dept : oaDeptList) {
|
||||
OaParentLink parentLink = this.resolveOaParentLink(dept, companyByOaId, departmentByOaId);
|
||||
if (parentLink == null) {
|
||||
continue;
|
||||
}
|
||||
desiredParentIdMap.put(dept.getId(), parentLink.parentId());
|
||||
desiredParentCodeMap.put(dept.getId(), parentLink.parentCode());
|
||||
}
|
||||
Set<Long> cyclicIds = this.findCyclicDeptIds(desiredParentIdMap);
|
||||
if (CollectionUtil.isNotEmpty(cyclicIds)) {
|
||||
log.warn("检测到OA组织循环引用,跳过层级重建 ids={}", cyclicIds);
|
||||
cyclicIds.forEach(cyclicId -> {
|
||||
desiredParentIdMap.remove(cyclicId);
|
||||
desiredParentCodeMap.remove(cyclicId);
|
||||
});
|
||||
}
|
||||
List<Dept> updateList = new ArrayList<>();
|
||||
for (Dept dept : oaDeptList) {
|
||||
Long parentId = desiredParentIdMap.get(dept.getId());
|
||||
if (parentId == null) {
|
||||
continue;
|
||||
}
|
||||
String parentCode = desiredParentCodeMap.get(dept.getId());
|
||||
if (Objects.equals(parentId, dept.getParentId()) && StringUtil.equals(parentCode, dept.getParentCode())) {
|
||||
continue;
|
||||
}
|
||||
Dept updateParam = new Dept();
|
||||
updateParam.setId(dept.getId());
|
||||
updateParam.setParentId(parentId);
|
||||
updateParam.setParentCode(parentCode);
|
||||
updateList.add(updateParam);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(updateList)) {
|
||||
this.updateBatchById(updateList);
|
||||
log.info("按OA主键重建组织层级,更新父子关系{}条", updateList.size());
|
||||
} else {
|
||||
log.info("OA组织层级已是最新,无需调整父子关系");
|
||||
}
|
||||
this.refreshAncestors(true, null);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public int removeOaOrphansWithoutParent() {
|
||||
List<Dept> oaDeptList = this.list(Wrappers.<Dept>lambdaQuery()
|
||||
.isNotNull(Dept::getOaId)
|
||||
.ne(Dept::getOaId, ""));
|
||||
if (CollectionUtil.isEmpty(oaDeptList)) {
|
||||
return 0;
|
||||
}
|
||||
Map<String, Dept> companyByOaId = this.indexByOaId(oaDeptList, DeptCategory.COMPANY.getCode());
|
||||
Map<String, Dept> departmentByOaId = this.indexByOaId(oaDeptList, DeptCategory.DEPT.getCode());
|
||||
Set<Long> deleteIds = new HashSet<>();
|
||||
for (Dept dept : oaDeptList) {
|
||||
String parentOaId = dept.getOaSupSubComId();
|
||||
// 上级为空或为 0:视为本地锚点/根级,不作为孤儿删除
|
||||
if (StringUtil.isBlank(parentOaId) || OAConstant.ROOT_COMPANY_ID.equals(parentOaId)) {
|
||||
continue;
|
||||
}
|
||||
boolean parentExists;
|
||||
if (DeptCategory.COMPANY.getCode().equals(dept.getDeptCategory())) {
|
||||
parentExists = companyByOaId.containsKey(parentOaId);
|
||||
} else {
|
||||
parentExists = departmentByOaId.containsKey(parentOaId) || companyByOaId.containsKey(parentOaId);
|
||||
}
|
||||
if (!parentExists) {
|
||||
deleteIds.add(dept.getId());
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isEmpty(deleteIds)) {
|
||||
log.info("没有需要清理的OA孤儿组织");
|
||||
return 0;
|
||||
}
|
||||
// 按 OA 上级关系级联:上级被删则子级一并删除
|
||||
boolean oaCascadeChanged = true;
|
||||
while (oaCascadeChanged) {
|
||||
oaCascadeChanged = false;
|
||||
for (Dept dept : oaDeptList) {
|
||||
if (deleteIds.contains(dept.getId())) {
|
||||
continue;
|
||||
}
|
||||
String parentOaId = dept.getOaSupSubComId();
|
||||
if (StringUtil.isBlank(parentOaId) || OAConstant.ROOT_COMPANY_ID.equals(parentOaId)) {
|
||||
continue;
|
||||
}
|
||||
Dept parent = DeptCategory.COMPANY.getCode().equals(dept.getDeptCategory())
|
||||
? companyByOaId.get(parentOaId)
|
||||
: Optional.ofNullable(departmentByOaId.get(parentOaId)).orElse(companyByOaId.get(parentOaId));
|
||||
if (parent != null && deleteIds.contains(parent.getId())) {
|
||||
deleteIds.add(dept.getId());
|
||||
oaCascadeChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 按本地 parent_id 再级联一轮,清掉挂在已删节点下的子树
|
||||
List<Dept> allDeptList = this.list();
|
||||
boolean parentIdCascadeChanged = true;
|
||||
while (parentIdCascadeChanged) {
|
||||
parentIdCascadeChanged = false;
|
||||
for (Dept dept : allDeptList) {
|
||||
if (deleteIds.contains(dept.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (dept.getParentId() != null && deleteIds.contains(dept.getParentId())) {
|
||||
deleteIds.add(dept.getId());
|
||||
parentIdCascadeChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.removeByIds(deleteIds);
|
||||
log.info("删除OA层级无法挂载的组织{}条", deleteIds.size());
|
||||
return deleteIds.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按机构类型建立 OA 主键索引
|
||||
*/
|
||||
private Map<String, Dept> indexByOaId(List<Dept> oaDeptList, Integer deptCategory) {
|
||||
Map<String, Dept> oaIdMap = new HashMap<>();
|
||||
for (Dept dept : oaDeptList) {
|
||||
if (!Objects.equals(deptCategory, dept.getDeptCategory()) || StringUtil.isBlank(dept.getOaId())) {
|
||||
continue;
|
||||
}
|
||||
Dept previous = oaIdMap.put(dept.getOaId(), dept);
|
||||
if (previous != null) {
|
||||
log.warn("OA主键重复,层级重建使用后一条 category={} oaId={} id={} previousId={}",
|
||||
dept.getDeptCategory(), dept.getOaId(), dept.getId(), previous.getId());
|
||||
}
|
||||
}
|
||||
return oaIdMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 OA 上级主键解析本系统父级
|
||||
*/
|
||||
private OaParentLink resolveOaParentLink(Dept dept, Map<String, Dept> companyByOaId, Map<String, Dept> departmentByOaId) {
|
||||
String parentOaId = dept.getOaSupSubComId();
|
||||
boolean rootParent = StringUtil.isBlank(parentOaId) || OAConstant.ROOT_COMPANY_ID.equals(parentOaId);
|
||||
if (DeptCategory.COMPANY.getCode().equals(dept.getDeptCategory())) {
|
||||
if (rootParent) {
|
||||
return new OaParentLink(OAConvertConstant.ROOT_PARENT_ID, OAConstant.ROOT_COMPANY_ID);
|
||||
}
|
||||
Dept parent = companyByOaId.get(parentOaId);
|
||||
if (parent == null || parent.getId() == null || Objects.equals(parent.getId(), dept.getId())) {
|
||||
log.warn("未找到上级公司,跳过层级重建 oaId={} oaSupSubComId={} deptId={}",
|
||||
dept.getOaId(), parentOaId, dept.getId());
|
||||
return null;
|
||||
}
|
||||
return new OaParentLink(parent.getId(), this.resolveParentCode(parent, OAConvertConstant.COMPANY_OA_PREFIX, parentOaId));
|
||||
}
|
||||
if (!DeptCategory.DEPT.getCode().equals(dept.getDeptCategory())) {
|
||||
return null;
|
||||
}
|
||||
if (rootParent) {
|
||||
log.warn("部门缺少上级OA主键,跳过层级重建 oaId={} deptId={}", dept.getOaId(), dept.getId());
|
||||
return null;
|
||||
}
|
||||
boolean parentIsDepartment = StringUtil.isNotBlank(dept.getParentCode())
|
||||
&& dept.getParentCode().startsWith(OAConvertConstant.DEPARTMENT_OA_PREFIX);
|
||||
boolean parentIsCompany = StringUtil.isNotBlank(dept.getParentCode())
|
||||
&& dept.getParentCode().startsWith(OAConvertConstant.COMPANY_OA_PREFIX);
|
||||
Dept parent;
|
||||
if (parentIsDepartment) {
|
||||
parent = departmentByOaId.get(parentOaId);
|
||||
} else if (parentIsCompany) {
|
||||
parent = companyByOaId.get(parentOaId);
|
||||
} else {
|
||||
parent = departmentByOaId.get(parentOaId);
|
||||
if (parent == null) {
|
||||
parent = companyByOaId.get(parentOaId);
|
||||
}
|
||||
}
|
||||
if (parent == null || parent.getId() == null || Objects.equals(parent.getId(), dept.getId())) {
|
||||
log.warn("未找到上级组织,跳过层级重建 oaId={} oaSupSubComId={} deptId={}",
|
||||
dept.getOaId(), parentOaId, dept.getId());
|
||||
return null;
|
||||
}
|
||||
String prefix = DeptCategory.DEPT.getCode().equals(parent.getDeptCategory())
|
||||
? OAConvertConstant.DEPARTMENT_OA_PREFIX : OAConvertConstant.COMPANY_OA_PREFIX;
|
||||
return new OaParentLink(parent.getId(), this.resolveParentCode(parent, prefix, parentOaId));
|
||||
}
|
||||
|
||||
private String resolveParentCode(Dept parent, String prefix, String parentOaId) {
|
||||
if (StringUtil.isNotBlank(parent.getDeptCode())) {
|
||||
return parent.getDeptCode();
|
||||
}
|
||||
return prefix + parentOaId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 找出父子关系成环的部门
|
||||
*/
|
||||
private Set<Long> findCyclicDeptIds(Map<Long, Long> parentIdMap) {
|
||||
Set<Long> cyclicIds = new HashSet<>();
|
||||
for (Long deptId : parentIdMap.keySet()) {
|
||||
Set<Long> visiting = new HashSet<>();
|
||||
Long currentId = deptId;
|
||||
while (currentId != null && !OAConvertConstant.ROOT_PARENT_ID.equals(currentId)) {
|
||||
if (!visiting.add(currentId)) {
|
||||
cyclicIds.addAll(visiting);
|
||||
break;
|
||||
}
|
||||
currentId = parentIdMap.get(currentId);
|
||||
}
|
||||
}
|
||||
return cyclicIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新祖级列表
|
||||
*
|
||||
* @param refreshAll 是否刷新全部部门
|
||||
* @param startTime 增量起始时间,仅 refreshAll 为 false 时生效
|
||||
*/
|
||||
private void refreshAncestors(boolean refreshAll, Date startTime) {
|
||||
List<Dept> list = refreshAll ? this.list() : this.list(Wrappers.<Dept>lambdaQuery()
|
||||
.isNull(Dept::getAncestors)
|
||||
// 开始时间不为空,查询同步时间大于开始时间或修改时间大于开始时间的数据
|
||||
.or(startTime != null, wrapper -> wrapper.ge(Dept::getSyncTime, startTime))
|
||||
.or(startTime != null, wrapper -> wrapper.ge(Dept::getUpdateTime, startTime))
|
||||
);
|
||||
@@ -565,29 +815,19 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
|
||||
log.info("需要更新祖级列表的部门为空");
|
||||
return;
|
||||
}
|
||||
// 所有公司部门列表
|
||||
List<DeptVO> allList = this.list().stream()
|
||||
List<DeptVO> allList = (refreshAll ? list : this.list()).stream()
|
||||
.map(dept -> BeanUtil.copyProperties(dept, DeptVO.class))
|
||||
.toList();
|
||||
// id对应的部门map
|
||||
Map<Long, DeptVO> idDeptMap = allList.stream()
|
||||
.collect(Collectors.toMap(DeptVO::getId, Function.identity(), (a, b) -> b));
|
||||
// 获取根节点列表
|
||||
List<DeptVO> rootList = getRootList(allList, idDeptMap);
|
||||
// 计算祖级列表
|
||||
setAncestors(rootList);
|
||||
|
||||
// 3. 更新祖级列表
|
||||
List<Dept> updateParams = list.stream()
|
||||
.filter(dept -> {
|
||||
DeptVO vo = idDeptMap.get(dept.getId());
|
||||
if (vo == null) {
|
||||
if (vo == null || vo.getAncestors() == null) {
|
||||
return false;
|
||||
}
|
||||
if (vo.getAncestors() == null) {
|
||||
return false;
|
||||
}
|
||||
// 祖级列表和数据库的不一样的才需要更新
|
||||
return !StringUtil.equals(vo.getAncestors(), dept.getAncestors());
|
||||
})
|
||||
.map(dept -> {
|
||||
@@ -602,6 +842,21 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* OA 上级链接
|
||||
*/
|
||||
private record OaParentLink(Long parentId, String parentCode) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一的租户范围过滤:超管放行,其他用户强制限定为当前会话租户。
|
||||
*/
|
||||
private void applyTenantScope(QueryWrapper<Dept> queryWrapper) {
|
||||
if (!AuthUtil.isAdministrator()) {
|
||||
queryWrapper.lambda().eq(Dept::getTenantId, AuthUtil.getTenantId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取根节点列表
|
||||
* @param allList
|
||||
|
||||
+116
-46
@@ -74,10 +74,18 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
Date startTime = this.syncAndRecord(DataSyncRecordUtils::createOAOrgFetch, queryStartTime -> {
|
||||
// 1. 同步公司
|
||||
this.syncCompany(queryStartTime);
|
||||
// 公司分批入库后,重建层级并清理无法挂载的公司
|
||||
deptService.rebuildOaHierarchy();
|
||||
deptService.removeOaOrphansWithoutParent();
|
||||
// 2. 同步部门
|
||||
this.syncDept(queryStartTime);
|
||||
// 2. 更新部门祖级列表
|
||||
// 3. 分批写入完成后,按 OA 主键重建组织、部门层级
|
||||
deptService.rebuildOaHierarchy();
|
||||
deptService.removeOaOrphansWithoutParent();
|
||||
// 4. 更新部门祖级列表
|
||||
deptService.updateAncestors(queryStartTime);
|
||||
CacheUtil.clear(SYS_CACHE);
|
||||
CacheUtil.clear(SYS_CACHE, Boolean.FALSE);
|
||||
}, syncAll);
|
||||
// 2. 推送mk
|
||||
mkPushService.pushOrgAndRecord(startTime);
|
||||
@@ -196,7 +204,7 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
return new ServiceException("调用OA接口查询公司信息失败");
|
||||
}, 10000, ComposeLogUtil.getLastLog()::info).accept(list -> {
|
||||
// 处理数据
|
||||
OrgSyncCount syncCount = handleCompany(list);
|
||||
OrgSyncCount syncCount = handleCompany(list, false);
|
||||
notHandleList.addAll(syncCount.getNotHandledList());
|
||||
});
|
||||
// 3. 未处理的数据
|
||||
@@ -213,7 +221,7 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
* @param startTime 查询开始时间
|
||||
*/
|
||||
private void syncDept(Date startTime) {
|
||||
String subCompanyIds = getSubCompanyIds();
|
||||
String subCompanyIds = getOaSubCompanyIds(false);
|
||||
if (StringUtils.isEmpty(subCompanyIds)) {
|
||||
ComposeLogUtil.getLastLog().warn("未查询到子公司查询参数");
|
||||
return;
|
||||
@@ -228,7 +236,7 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
return new ServiceException("调用OA接口查询部门信息失败");
|
||||
}, 10000, ComposeLogUtil.getLastLog()::info).accept(list -> {
|
||||
// 处理数据
|
||||
OrgSyncCount syncCount = handleDept(list);
|
||||
OrgSyncCount syncCount = handleDept(list, false);
|
||||
notHandleList.addAll(syncCount.getNotHandledList());
|
||||
});
|
||||
// 3. 未处理的数据
|
||||
@@ -334,13 +342,18 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
List<OACompanyResponse> oaCompanies = responseData.getDataList() == null
|
||||
? Collections.emptyList() : responseData.getDataList();
|
||||
long totalSize = responseData.getTotalSize() == null ? 0L : responseData.getTotalSize();
|
||||
OrgSyncCount syncCount = handleCompany(oaCompanies);
|
||||
OrgSyncCount syncCount = handleCompany(oaCompanies, true);
|
||||
if (CollectionUtil.isNotEmpty(syncCount.getNotHandledList())) {
|
||||
ComposeLogUtil.getLastLog().warn("同步公司,本页未处理数据:{}", JSON.toJSONString(syncCount.getNotHandledList()));
|
||||
}
|
||||
OaOrgSyncPageVO pageVO = buildOrgSyncPageVO("company", pageNo, pageSize, totalSize, oaCompanies.size(), syncCount);
|
||||
if (Boolean.TRUE.equals(pageVO.getFinished())) {
|
||||
// 公司全部分批入库后:重建层级,并删除上级不存在的数据
|
||||
deptService.rebuildOaHierarchy();
|
||||
deptService.removeOaOrphansWithoutParent();
|
||||
}
|
||||
CacheUtil.clear(SYS_CACHE);
|
||||
CacheUtil.clear(SYS_CACHE, Boolean.FALSE);
|
||||
OaOrgSyncPageVO pageVO = buildOrgSyncPageVO("company", pageNo, pageSize, totalSize, oaCompanies.size(), syncCount);
|
||||
ComposeLogUtil.getLastLog().info("OA公司分页同步完成 {}/{},成功{},跳过{}",
|
||||
pageNo, totalSize, syncCount.getSyncedCount(), syncCount.getSkippedCount());
|
||||
return pageVO;
|
||||
@@ -356,9 +369,9 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
private OaOrgSyncPageVO syncDepartmentFromOaPage(int current, int size) {
|
||||
int pageNo = current < 1 ? 1 : current;
|
||||
int pageSize = size < 1 ? 20 : Math.min(size, 200);
|
||||
String subCompanyIds = getSubCompanyIds();
|
||||
String subCompanyIds = getOaSubCompanyIds(true);
|
||||
if (StringUtils.isEmpty(subCompanyIds)) {
|
||||
ComposeLogUtil.getLastLog().warn("未查询到子公司查询参数,跳过部门同步");
|
||||
ComposeLogUtil.getLastLog().warn("未查询到已同步的OA公司,跳过部门同步");
|
||||
OaOrgSyncPageVO emptyPageVO = buildOrgSyncPageVO("department", pageNo, pageSize, 0L, 0, OrgSyncCount.empty());
|
||||
emptyPageVO.setFinished(true);
|
||||
return emptyPageVO;
|
||||
@@ -375,17 +388,19 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
List<OADepartmentResponse> oaDepartments = responseData.getDataList() == null
|
||||
? Collections.emptyList() : responseData.getDataList();
|
||||
long totalSize = responseData.getTotalSize() == null ? 0L : responseData.getTotalSize();
|
||||
OrgSyncCount syncCount = handleDept(oaDepartments);
|
||||
OrgSyncCount syncCount = handleDept(oaDepartments, true);
|
||||
if (CollectionUtil.isNotEmpty(syncCount.getNotHandledList())) {
|
||||
ComposeLogUtil.getLastLog().warn("同步部门,本页未处理数据:{}", JSON.toJSONString(syncCount.getNotHandledList()));
|
||||
}
|
||||
CacheUtil.clear(SYS_CACHE);
|
||||
CacheUtil.clear(SYS_CACHE, Boolean.FALSE);
|
||||
OaOrgSyncPageVO pageVO = buildOrgSyncPageVO("department", pageNo, pageSize, totalSize, oaDepartments.size(), syncCount);
|
||||
if (Boolean.TRUE.equals(pageVO.getFinished())) {
|
||||
// 部门同步完成后更新祖级列表
|
||||
// 部门分批同步完成后,重建层级、清理无法挂载数据并刷新祖级列表
|
||||
deptService.rebuildOaHierarchy();
|
||||
deptService.removeOaOrphansWithoutParent();
|
||||
deptService.updateAncestors(null);
|
||||
}
|
||||
CacheUtil.clear(SYS_CACHE);
|
||||
CacheUtil.clear(SYS_CACHE, Boolean.FALSE);
|
||||
ComposeLogUtil.getLastLog().info("OA部门分页同步完成 {}/{},成功{},跳过{}",
|
||||
pageNo, totalSize, syncCount.getSyncedCount(), syncCount.getSkippedCount());
|
||||
return pageVO;
|
||||
@@ -469,19 +484,22 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
|
||||
/**
|
||||
* 处理oa公司
|
||||
* @param oaCompanies
|
||||
* @param oaCompanies OA公司列表
|
||||
* @param syncAll true=自动同步时不过滤字典白名单;false=仅同步配置的公司名称
|
||||
* @return 同步统计
|
||||
*/
|
||||
private OrgSyncCount handleCompany(List<OACompanyResponse> oaCompanies) {
|
||||
private OrgSyncCount handleCompany(List<OACompanyResponse> oaCompanies, boolean syncAll) {
|
||||
if (CollectionUtil.isEmpty(oaCompanies)) {
|
||||
return OrgSyncCount.empty();
|
||||
}
|
||||
// 获取需要的公司名称
|
||||
Set<String> companyNames = getCompanyNames();
|
||||
Set<String> companyNames = syncAll ? Collections.emptySet() : getCompanyNames();
|
||||
// 转换数据
|
||||
List<Dept> allParam = oaCompanies.stream()
|
||||
// 筛选只要需要的公司
|
||||
.filter(company -> companyNames.contains(company.getSubcompanyname()))
|
||||
// 强制跳过上级公司为 0 的数据
|
||||
.filter(company -> !OAConstant.ROOT_COMPANY_ID.equals(company.getSupsubcomid()))
|
||||
// 非全量同步时,筛选只要配置的公司
|
||||
.filter(company -> syncAll || companyNames.contains(company.getSubcompanyname()))
|
||||
.map(deptConvert::company2dept)
|
||||
.toList();
|
||||
int filteredSkipCount = oaCompanies.size() - allParam.size();
|
||||
@@ -501,10 +519,11 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
|
||||
/**
|
||||
* 处理oa部门
|
||||
* @param oaDepts
|
||||
* @param oaDepts OA部门列表
|
||||
* @param syncAll true=自动同步时不过滤根公司部门白名单;false=沿用原过滤规则
|
||||
* @return 同步统计
|
||||
*/
|
||||
private OrgSyncCount handleDept(List<OADepartmentResponse> oaDepts) {
|
||||
private OrgSyncCount handleDept(List<OADepartmentResponse> oaDepts, boolean syncAll) {
|
||||
if (CollectionUtil.isEmpty(oaDepts)) {
|
||||
return OrgSyncCount.empty();
|
||||
}
|
||||
@@ -512,31 +531,42 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
Map<String, Long> companyDeptMap = getAllCompanyDeptMap();
|
||||
// 根公司id
|
||||
String rootCompanyId = getRootCompanyId();
|
||||
if (rootCompanyId == null) {
|
||||
if (!syncAll && rootCompanyId == null) {
|
||||
return new OrgSyncCount(0, oaDepts.size(), Collections.emptyList());
|
||||
}
|
||||
// 根公司下要同步的部门名称
|
||||
Set<String> rootCompanyDeptNames = getRootCompanyDeptNames();
|
||||
Set<String> rootCompanyDeptNames = syncAll ? Collections.emptySet() : getRootCompanyDeptNames();
|
||||
// 转换数据
|
||||
List<Dept> allParam = oaDepts.stream()
|
||||
// 部门的公司不是根公司,或者部门名称在根公司下需要同步的部门列表中,且是根部门
|
||||
.filter(oaDept -> !rootCompanyId.equals(oaDept.getSubcompanyid1()) || (OAConstant.ROOT_COMPANY_ID.equals(oaDept.getSupdepid()) && rootCompanyDeptNames.contains(oaDept.getDepartmentname())))
|
||||
// 全量同步时不过滤;否则:部门的公司不是根公司,或者部门名称在根公司下需要同步的部门列表中,且是根部门
|
||||
.filter(oaDept -> syncAll
|
||||
|| rootCompanyId == null
|
||||
|| !rootCompanyId.equals(oaDept.getSubcompanyid1())
|
||||
|| (OAConstant.ROOT_COMPANY_ID.equals(oaDept.getSupdepid()) && rootCompanyDeptNames.contains(oaDept.getDepartmentname())))
|
||||
.map(dept -> deptConvert.dept2dept(dept, companyDeptMap))
|
||||
.toList();
|
||||
int filteredSkipCount = oaDepts.size() - allParam.size();
|
||||
if (CollectionUtil.isEmpty(allParam)) {
|
||||
return new OrgSyncCount(0, filteredSkipCount, Collections.emptyList());
|
||||
}
|
||||
Set<String> deptCodes = allParam.stream()
|
||||
.map(Dept::getDeptCode)
|
||||
.collect(Collectors.toSet());
|
||||
// 查询数据库的部门,转换成map
|
||||
Map<String, Long> deptMap = deptService.list(Wrappers.<Dept>lambdaQuery()
|
||||
Set<String> deptCodes = new HashSet<>();
|
||||
allParam.forEach(dept -> {
|
||||
if (StringUtils.isNotEmpty(dept.getDeptCode())) {
|
||||
deptCodes.add(dept.getDeptCode());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dept.getParentCode())) {
|
||||
deptCodes.add(dept.getParentCode());
|
||||
}
|
||||
});
|
||||
// 查询数据库的部门,转换成map。包含本页及上级编码,便于命中已入库的上级
|
||||
Map<String, Long> deptMap = deptCodes.isEmpty() ? new HashMap<>() : deptService.list(Wrappers.<Dept>lambdaQuery()
|
||||
.eq(Dept::getDeptCategory, DeptCategory.DEPT.getCode())
|
||||
.in(Dept::getDeptCode, deptCodes)
|
||||
).stream()
|
||||
.filter(dept -> StringUtils.isNotEmpty(dept.getDeptCode()))
|
||||
.collect(Collectors.toMap(Dept::getDeptCode, Dept::getId, (a, b) -> b));
|
||||
// 公司编码也放入 map,根部门挂到公司时才能解析父级
|
||||
companyDeptMap.forEach(deptMap::putIfAbsent);
|
||||
// 处理部门
|
||||
List<Dept> notHandledList = this.handleDept(allParam, deptMap, DeptCategory.DEPT);
|
||||
int syncedCount = allParam.size() - notHandledList.size();
|
||||
@@ -564,14 +594,30 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
}
|
||||
});
|
||||
|
||||
// 重新把没有父id的数据设置一下父id
|
||||
allParam.stream()
|
||||
.filter(dept -> dept.getParentId() == null && deptMap.containsKey(dept.getDeptCode()))
|
||||
.forEach(dept -> dept.setParentId(deptMap.get(dept.getParentCode())));
|
||||
// 重新把没有父id的数据设置一下父id;上级尚未入库时,新增记录先挂到根节点,全部分批完成后重建层级并清理无法挂载的数据
|
||||
int unresolvedParentCount = 0;
|
||||
for (Dept dept : allParam) {
|
||||
if (dept.getParentId() != null) {
|
||||
continue;
|
||||
}
|
||||
Long parentId = deptMap.get(dept.getParentCode());
|
||||
if (parentId != null) {
|
||||
dept.setParentId(parentId);
|
||||
continue;
|
||||
}
|
||||
unresolvedParentCount++;
|
||||
if (!existsDeptIds.contains(dept.getId())) {
|
||||
dept.setParentId(OAConvertConstant.ROOT_PARENT_ID);
|
||||
}
|
||||
}
|
||||
if (unresolvedParentCount > 0) {
|
||||
ComposeLogUtil.getLastLog().warn("同步{}时有{}条上级尚未入库,已先保存,分批结束后重建层级并清理无法挂载数据",
|
||||
deptCategory.getName(), unresolvedParentCount);
|
||||
}
|
||||
|
||||
// 父id不为空,保存数据
|
||||
// 父id不为空才新增;已存在的记录即使父id未解析也更新(空父id不会覆盖原值)
|
||||
List<Dept> list = allParam.stream()
|
||||
.filter(dept -> dept.getParentId() != null)
|
||||
.filter(dept -> dept.getParentId() != null || existsDeptIds.contains(dept.getId()))
|
||||
.toList();
|
||||
// 不存在的新增
|
||||
List<Dept> addList = list.stream()
|
||||
@@ -589,9 +635,9 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
ComposeLogUtil.getLastLog().info("批量修改{}:{}", deptCategory.getName(), updateList.size());
|
||||
deptService.updateBatchById(updateList);
|
||||
}
|
||||
// 返回未处理的
|
||||
// 返回仍未保存的数据
|
||||
return allParam.stream()
|
||||
.filter(dept -> dept.getParentId() == null)
|
||||
.filter(dept -> dept.getParentId() == null && !existsDeptIds.contains(dept.getId()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -627,26 +673,50 @@ public class OASyncServiceImpl implements IOASyncService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取oa查询参数,子公司id参数
|
||||
* @return
|
||||
* 获取 OA 部门查询使用的子公司 id
|
||||
*
|
||||
* @param syncAll true=取已同步的全部 OA 公司;false=仅取字典配置的公司
|
||||
* @return 逗号分隔的 OA 公司 id
|
||||
*/
|
||||
private String getSubCompanyIds() {
|
||||
private String getOaSubCompanyIds(boolean syncAll) {
|
||||
List<Dept> companyList;
|
||||
if (syncAll) {
|
||||
companyList = deptService.list(Wrappers.<Dept>lambdaQuery()
|
||||
.eq(Dept::getDeptCategory, DeptCategory.COMPANY.getCode())
|
||||
);
|
||||
} else {
|
||||
Set<String> companyNames = this.getCompanyNames();
|
||||
if (companyNames.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return deptService.list(Wrappers.<Dept>lambdaQuery()
|
||||
// 根据名称查询公司
|
||||
companyList = deptService.list(Wrappers.<Dept>lambdaQuery()
|
||||
.in(Dept::getDeptName, companyNames)
|
||||
.eq(Dept::getDeptCategory, DeptCategory.COMPANY.getCode())
|
||||
).stream()
|
||||
// 只要部门编码不为空,且包含了oa公司前缀的
|
||||
.filter(dept -> StringUtils.isNotBlank(dept.getDeptCode()) && dept.getDeptCode().contains(OAConvertConstant.COMPANY_OA_PREFIX))
|
||||
// 去掉oa公司前缀
|
||||
.map(dept -> dept.getDeptCode().replace(OAConvertConstant.COMPANY_OA_PREFIX, ""))
|
||||
);
|
||||
}
|
||||
return companyList.stream()
|
||||
.map(this::resolveOaCompanyId)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.distinct()
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析本地公司对应的 OA 公司 id
|
||||
*/
|
||||
private String resolveOaCompanyId(Dept dept) {
|
||||
if (dept == null) {
|
||||
return null;
|
||||
}
|
||||
if (StringUtils.isNotBlank(dept.getOaId())) {
|
||||
return dept.getOaId();
|
||||
}
|
||||
if (StringUtils.isNotBlank(dept.getDeptCode()) && dept.getDeptCode().startsWith(OAConvertConstant.COMPANY_OA_PREFIX)) {
|
||||
return dept.getDeptCode().replace(OAConvertConstant.COMPANY_OA_PREFIX, "");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认角色id
|
||||
*/
|
||||
|
||||
+11
-12
@@ -39,6 +39,7 @@ import org.springblade.common.constant.DataStatusEnum;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.springblade.common.constant.ParamConstant;
|
||||
import org.springblade.common.constant.TenantConstant;
|
||||
import org.springblade.common.utils.PasswordRuleUtil;
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
@@ -76,7 +77,6 @@ import org.springblade.system.wrapper.UserWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
@@ -106,9 +106,6 @@ import static org.springblade.core.tenant.TenantGuard.EntityType.USER;
|
||||
@Slf4j
|
||||
public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements IUserService {
|
||||
private static final String GUEST_NAME = "guest";
|
||||
private static final String PASSWORD_CHARS = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789";
|
||||
private static final int RANDOM_PASSWORD_LENGTH = 8;
|
||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
||||
private static final String IAM_DEFAULT_DICT_CODE = "iam_default";
|
||||
private static final String IAM_DEFAULT_ROLE_NAME = "默认角色";
|
||||
private static final String IAM_DEFAULT_DEPT_NAME = "默认部门";
|
||||
@@ -588,7 +585,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
||||
List<User> userList = TenantGuard.verifyBatch(this, idList, USER);
|
||||
Map<String, String> passwordMap = new LinkedHashMap<>();
|
||||
for (User user : userList) {
|
||||
String password = randomPassword();
|
||||
String password = PasswordRuleUtil.generate();
|
||||
User updateUser = new User();
|
||||
updateUser.setPassword(DigestUtil.encrypt(password));
|
||||
updateUser.setUpdateTime(DateUtil.now());
|
||||
@@ -604,6 +601,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
||||
if (!Objects.equals(password, password2)) {
|
||||
throw new ServiceException("两次输入密码不一致!");
|
||||
}
|
||||
validatePlainPassword(password);
|
||||
User user = TenantGuard.verify(this, userId, USER);
|
||||
User updateUser = new User();
|
||||
updateUser.setPassword(DigestUtil.encrypt(password));
|
||||
@@ -672,7 +670,8 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
||||
if (user.getId() != null) {
|
||||
this.updateUser(user);
|
||||
} else {
|
||||
user.setPassword(ParamCache.getValue(DEFAULT_PARAM_PASSWORD));
|
||||
// 空密码交由 saveUser 按规则填充(初始密码不合规时自动生成)
|
||||
user.setPassword(null);
|
||||
this.submit(user);
|
||||
}
|
||||
});
|
||||
@@ -1064,8 +1063,10 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
||||
}
|
||||
}
|
||||
if (Func.isEmpty(user.getPassword())) {
|
||||
user.setPassword(ParamCache.getValue(DEFAULT_PARAM_PASSWORD));
|
||||
String initPassword = ParamCache.getValue(DEFAULT_PARAM_PASSWORD);
|
||||
user.setPassword(PasswordRuleUtil.isValid(initPassword) ? initPassword : PasswordRuleUtil.generate());
|
||||
}
|
||||
validatePlainPassword(user.getPassword());
|
||||
user.setPassword(DigestUtil.encrypt(user.getPassword()));
|
||||
Long userCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, user.getAccount()));
|
||||
if (userCount > 0L && Func.isEmpty(user.getId())) {
|
||||
@@ -1147,12 +1148,10 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
||||
// }
|
||||
}
|
||||
|
||||
private String randomPassword() {
|
||||
StringBuilder password = new StringBuilder(RANDOM_PASSWORD_LENGTH);
|
||||
for (int index = 0; index < RANDOM_PASSWORD_LENGTH; index++) {
|
||||
password.append(PASSWORD_CHARS.charAt(SECURE_RANDOM.nextInt(PASSWORD_CHARS.length())));
|
||||
private void validatePlainPassword(String password) {
|
||||
if (!PasswordRuleUtil.isValid(password)) {
|
||||
throw new ServiceException(PasswordRuleUtil.RULE_MESSAGE);
|
||||
}
|
||||
return password.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-55
@@ -35,13 +35,11 @@ import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.secure.annotation.PreAuth;
|
||||
import org.springblade.core.secure.constant.AuthConstant;
|
||||
import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.api.FR;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.process.feign.IBusinessProcessClient;
|
||||
import org.springblade.transport.pojo.vo.CustomerArchiveVO;
|
||||
import org.springblade.transport.pojo.vo.CustomerChangeRecordVO;
|
||||
import org.springblade.transport.service.ICustomerArchiveService;
|
||||
import org.springblade.transport.service.impl.CustomerArchivePublicProcessService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -49,8 +47,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -68,7 +64,7 @@ import java.util.Map;
|
||||
public class CustomerArchivePublicController {
|
||||
|
||||
private final ICustomerArchiveService customerArchiveService;
|
||||
private final IBusinessProcessClient businessProcessClient;
|
||||
private final CustomerArchivePublicProcessService customerArchivePublicProcessService;
|
||||
|
||||
/**
|
||||
* 公开详情
|
||||
@@ -92,61 +88,15 @@ public class CustomerArchivePublicController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 公开接收流程页 postMessage 数据(当前仅打印,便于联调)
|
||||
* 公开接收流程页 postMessage 数据
|
||||
*/
|
||||
@PostMapping("/process-message")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(summary = "公开接收流程消息", description = "无需登录,接收后查询当前节点并打印")
|
||||
@Operation(summary = "公开接收流程消息", description = "无需登录,立即查询当前节点,5秒后查询流程实例详情并同步客商")
|
||||
public R processMessage(@RequestBody Map<String, Object> body) {
|
||||
log.info("客商公开页收到流程消息:{}", JSON.toJSONString(body));
|
||||
Map<String, Object> formValues = asMap(body == null ? null : body.get("formValues"));
|
||||
String processId = firstText(formValues, "processId");
|
||||
if (StringUtil.isBlank(processId) && body != null) {
|
||||
processId = firstText(body, "processId");
|
||||
}
|
||||
String loginName = firstText(formValues, "mkLoginName", "loginName");
|
||||
if (StringUtil.isBlank(processId)) {
|
||||
log.warn("客商公开页流程消息未找到 processId,跳过查询当前节点");
|
||||
customerArchivePublicProcessService.handleProcessMessage(body);
|
||||
return R.success("ok");
|
||||
}
|
||||
try {
|
||||
FR<Object> result = businessProcessClient.getCurrentNodes(processId, loginName);
|
||||
log.info("客商公开页流程消息当前节点详情 processId={} loginName={} result={}",
|
||||
processId, loginName, JSON.toJSONString(result == null ? null : result.getData()));
|
||||
} catch (Exception e) {
|
||||
log.error("客商公开页查询当前节点失败 processId={} loginName={}", processId, loginName, e);
|
||||
}
|
||||
return R.success("ok");
|
||||
}
|
||||
|
||||
private static Map<String, Object> asMap(Object value) {
|
||||
if (!(value instanceof Map<?, ?> map)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
map.forEach((key, nested) -> {
|
||||
if (key != null) {
|
||||
result.put(String.valueOf(key), nested);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String firstText(Map<String, Object> source, String... keys) {
|
||||
if (source == null || keys == null) {
|
||||
return null;
|
||||
}
|
||||
for (String key : keys) {
|
||||
Object value = source.get(key);
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
String text = String.valueOf(value).trim();
|
||||
if (StringUtil.isNotBlank(text) && !"null".equalsIgnoreCase(text)) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package org.springblade.transport.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.secure.annotation.PreAuth;
|
||||
import org.springblade.core.secure.constant.AuthConstant;
|
||||
import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.transport.mk.MkProcessMessageService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* MK 业务流程公开查看
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@TenantIgnore
|
||||
@PreAuth(AuthConstant.PERMIT_ALL)
|
||||
@RequestMapping("/mk-process/public")
|
||||
@Tag(name = "MK业务流程公开查看", description = "MK业务流程公开查看")
|
||||
public class MkProcessPublicController {
|
||||
|
||||
private final MkProcessMessageService mkProcessMessageService;
|
||||
|
||||
@GetMapping("/{bizType}/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "公开详情", description = "无需登录")
|
||||
public R detail(@PathVariable String bizType,
|
||||
@Parameter(description = "主键", required = true) @RequestParam Long id) {
|
||||
return R.data(mkProcessMessageService.handler(bizType).publicDetail(id));
|
||||
}
|
||||
|
||||
@PostMapping("/{bizType}/process-message")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "公开接收流程消息", description = "无需登录,立即查询当前节点,5秒后查询流程实例详情并同步业务")
|
||||
public R processMessage(@PathVariable String bizType, @RequestBody Map<String, Object> body) {
|
||||
log.info("公开页收到流程消息 bizType={} body={}", bizType, JSON.toJSONString(body));
|
||||
mkProcessMessageService.handleProcessMessage(bizType, body);
|
||||
return R.success("ok");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -105,7 +105,7 @@ public class ProjectApplyController extends BladeController {
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(summary = "新增或修改", description = "传入projectApply")
|
||||
public R submit(@RequestBody ProjectApply projectApply) {
|
||||
return R.status(projectApplyService.submit(projectApply));
|
||||
return projectApplyService.submit(projectApply) ? R.data(projectApply) : R.fail("保存失败");
|
||||
}
|
||||
|
||||
@PostMapping("/submit-approval")
|
||||
|
||||
+1
-1
@@ -213,7 +213,7 @@ public class WaybillController extends BladeController {
|
||||
@ApiOperationSupport(order = 9)
|
||||
@Operation(summary = "新增或修改", description = "传入waybill")
|
||||
public R submit(@RequestBody Waybill waybill) {
|
||||
return R.status(waybillService.submit(waybill));
|
||||
return waybillService.submit(waybill) ? R.data(waybill) : R.fail("保存失败");
|
||||
}
|
||||
|
||||
@PostMapping("/save-draft")
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package org.springblade.transport.feign;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.secure.annotation.PreAuth;
|
||||
import org.springblade.core.secure.constant.AuthConstant;
|
||||
import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.api.FR;
|
||||
import org.springblade.transport.pojo.dto.CustomerProcessNodeSyncDTO;
|
||||
import org.springblade.transport.service.ICustomerArchiveService;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 客商档案 Feign实现
|
||||
*/
|
||||
@Hidden
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
public class CustomerArchiveClient implements ICustomerArchiveClient {
|
||||
|
||||
private final ICustomerArchiveService customerArchiveService;
|
||||
|
||||
@TenantIgnore
|
||||
@PreAuth(AuthConstant.PERMIT_ALL)
|
||||
@PostMapping(SYNC_PROCESS_NODE)
|
||||
@Override
|
||||
public FR<Boolean> syncProcessNode(@RequestBody CustomerProcessNodeSyncDTO param) {
|
||||
if (param == null) {
|
||||
return FR.data(false);
|
||||
}
|
||||
if (param.getProcessInfo() != null) {
|
||||
return FR.data(customerArchiveService.syncProcessNodeFromProcessInfo(param.getId(), param.getProcessInfo()));
|
||||
}
|
||||
return FR.data(customerArchiveService.syncProcessNode(
|
||||
param.getId(), param.getCurrentNode(), param.getCurrentProcessor(), param.getApprovalStatus()));
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package org.springblade.transport.feign;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.secure.annotation.PreAuth;
|
||||
import org.springblade.core.secure.constant.AuthConstant;
|
||||
import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.api.FR;
|
||||
import org.springblade.transport.mk.IMkProcessBizHandler;
|
||||
import org.springblade.transport.mk.MkProcessMessageService;
|
||||
import org.springblade.transport.pojo.dto.MkProcessSyncDTO;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* MK 业务流程同步 Feign 实现
|
||||
*/
|
||||
@Hidden
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
public class MkProcessClient implements IMkProcessClient {
|
||||
|
||||
private final MkProcessMessageService mkProcessMessageService;
|
||||
|
||||
@TenantIgnore
|
||||
@PreAuth(AuthConstant.PERMIT_ALL)
|
||||
@PostMapping(APPLY)
|
||||
@Override
|
||||
public FR<Boolean> apply(@RequestBody MkProcessSyncDTO param) {
|
||||
if (param == null || param.getId() == null) {
|
||||
return FR.data(false);
|
||||
}
|
||||
IMkProcessBizHandler handler = mkProcessMessageService.handler(param.getBizType());
|
||||
String action = param.getAction() == null ? "sync" : param.getAction();
|
||||
return switch (action) {
|
||||
case "approve" -> FR.data(handler.approveFromProcess(param.getId(), param.getProcessorName()));
|
||||
case "reject" -> FR.data(handler.rejectFromProcess(param.getId(), param.getProcessorName()));
|
||||
default -> FR.data(handler.syncFromProcessInfo(param.getId(), param.getProcessInfo()));
|
||||
};
|
||||
}
|
||||
}
|
||||
+28
@@ -22,9 +22,15 @@
|
||||
*/
|
||||
package org.springblade.transport.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springblade.transport.pojo.entity.ProjectApply;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 项目立项 Mapper 接口
|
||||
*
|
||||
@@ -32,4 +38,26 @@ import org.springblade.transport.pojo.entity.ProjectApply;
|
||||
*/
|
||||
public interface ProjectApplyMapper extends BaseMapper<ProjectApply> {
|
||||
|
||||
/**
|
||||
* 按租户读取业务字典项,供未登录公开页回显下拉文案
|
||||
*/
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
@Select("""
|
||||
SELECT dict_key AS dictKey, dict_value AS dictValue
|
||||
FROM blade_dict_biz
|
||||
WHERE is_deleted = 0 AND parent_id <> 0 AND tenant_id = #{tenantId} AND code = #{code}
|
||||
""")
|
||||
List<Map<String, Object>> selectDictBizItems(@Param("tenantId") String tenantId, @Param("code") String code);
|
||||
|
||||
/**
|
||||
* 读取系统字典项,供未登录公开页回显下拉文案
|
||||
*/
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
@Select("""
|
||||
SELECT dict_key AS dictKey, dict_value AS dictValue
|
||||
FROM blade_dict
|
||||
WHERE is_deleted = 0 AND parent_id <> 0 AND code = #{code}
|
||||
""")
|
||||
List<Map<String, Object>> selectDictItems(@Param("code") String code);
|
||||
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package org.springblade.transport.mk;
|
||||
|
||||
/**
|
||||
* MK 业务流程处理器
|
||||
*/
|
||||
public interface IMkProcessBizHandler {
|
||||
|
||||
String bizType();
|
||||
|
||||
Object publicDetail(Long id);
|
||||
|
||||
boolean syncFromProcessInfo(Long id, Object processInfo);
|
||||
|
||||
boolean approveFromProcess(Long id, String processorName);
|
||||
|
||||
boolean rejectFromProcess(Long id, String processorName);
|
||||
}
|
||||
+439
@@ -0,0 +1,439 @@
|
||||
package org.springblade.transport.mk;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.transport.pojo.entity.ContractManage;
|
||||
import org.springblade.transport.pojo.entity.FormalSettlement;
|
||||
import org.springblade.transport.pojo.entity.PaymentApplication;
|
||||
import org.springblade.transport.pojo.entity.PreSettlement;
|
||||
import org.springblade.transport.pojo.entity.ProjectApply;
|
||||
import org.springblade.transport.pojo.entity.Waybill;
|
||||
import org.springblade.transport.service.IContractManageService;
|
||||
import org.springblade.transport.service.ICustomerArchiveService;
|
||||
import org.springblade.transport.service.IFormalSettlementService;
|
||||
import org.springblade.transport.service.IPaymentApplicationService;
|
||||
import org.springblade.transport.service.IPreSettlementService;
|
||||
import org.springblade.transport.service.IProjectApplyService;
|
||||
import org.springblade.transport.service.IWaybillService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 各业务 MK 流程处理器
|
||||
*/
|
||||
public final class MkProcessBizHandlers {
|
||||
|
||||
private MkProcessBizHandlers() {
|
||||
}
|
||||
|
||||
@Component
|
||||
@TenantIgnore
|
||||
@RequiredArgsConstructor
|
||||
public static class CustomerHandler implements IMkProcessBizHandler {
|
||||
private final ICustomerArchiveService service;
|
||||
|
||||
@Override
|
||||
public String bizType() {
|
||||
return "customer-archive";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object publicDetail(Long id) {
|
||||
return service.publicDetail(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean syncFromProcessInfo(Long id, Object processInfo) {
|
||||
return service.syncProcessNodeFromProcessInfo(id, processInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean approveFromProcess(Long id, String processorName) {
|
||||
return service.approveFromProcess(id, processorName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rejectFromProcess(Long id, String processorName) {
|
||||
return service.rejectFromProcess(id, processorName);
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
@TenantIgnore
|
||||
@RequiredArgsConstructor
|
||||
public static class ProjectHandler implements IMkProcessBizHandler {
|
||||
private final IProjectApplyService service;
|
||||
|
||||
@Override
|
||||
public String bizType() {
|
||||
return "project-apply";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object publicDetail(Long id) {
|
||||
return service.publicDetail(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean syncFromProcessInfo(Long id, Object processInfo) {
|
||||
ProjectApply entity = service.getById(id);
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
String node = MkProcessNodeHelper.currentNode(processInfo);
|
||||
String processor = MkProcessNodeHelper.currentProcessor(processInfo);
|
||||
if (Func.isEmpty(node) && Func.isEmpty(processor)) {
|
||||
return false;
|
||||
}
|
||||
if (Func.isNotEmpty(node)) {
|
||||
entity.setCurrentNode(node);
|
||||
}
|
||||
if (Func.isNotEmpty(processor)) {
|
||||
entity.setCurrentProcessor(processor);
|
||||
}
|
||||
if (!"change_reviewing".equals(entity.getApprovalStatus())) {
|
||||
entity.setApprovalStatus("reviewing");
|
||||
}
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean approveFromProcess(Long id, String processorName) {
|
||||
ProjectApply entity = service.getById(id);
|
||||
if (entity == null || "approved".equals(entity.getApprovalStatus())
|
||||
|| "change_approved".equals(entity.getApprovalStatus())) {
|
||||
return entity != null;
|
||||
}
|
||||
boolean change = "change_reviewing".equals(entity.getApprovalStatus());
|
||||
entity.setApprovalStatus(change ? "change_approved" : "approved");
|
||||
entity.setEffectiveType("formal");
|
||||
entity.setCurrentNode("审核通过");
|
||||
entity.setCurrentProcessor(MkProcessNodeHelper.text(processorName, "系统"));
|
||||
entity.setApprovedTime(LocalDateTime.now());
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rejectFromProcess(Long id, String processorName) {
|
||||
ProjectApply entity = service.getById(id);
|
||||
if (entity == null || "rejected".equals(entity.getApprovalStatus())
|
||||
|| "change_rejected".equals(entity.getApprovalStatus())) {
|
||||
return entity != null;
|
||||
}
|
||||
boolean change = "change_reviewing".equals(entity.getApprovalStatus());
|
||||
entity.setApprovalStatus(change ? "change_rejected" : "rejected");
|
||||
entity.setCurrentNode("审核不通过");
|
||||
entity.setCurrentProcessor(MkProcessNodeHelper.text(processorName, "系统"));
|
||||
return service.updateById(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
@TenantIgnore
|
||||
@RequiredArgsConstructor
|
||||
public static class ContractHandler implements IMkProcessBizHandler {
|
||||
private final IContractManageService service;
|
||||
|
||||
@Override
|
||||
public String bizType() {
|
||||
return "contract-manage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object publicDetail(Long id) {
|
||||
return service.publicDetail(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean syncFromProcessInfo(Long id, Object processInfo) {
|
||||
ContractManage entity = service.getById(id);
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
String node = MkProcessNodeHelper.currentNode(processInfo);
|
||||
String processor = MkProcessNodeHelper.currentProcessor(processInfo);
|
||||
if (Func.isEmpty(node) && Func.isEmpty(processor)) {
|
||||
return false;
|
||||
}
|
||||
if (Func.isNotEmpty(node)) {
|
||||
entity.setCurrentNode(node);
|
||||
}
|
||||
if (Func.isNotEmpty(processor)) {
|
||||
entity.setCurrentProcessor(processor);
|
||||
}
|
||||
if (!"change_reviewing".equals(entity.getApprovalStatus())) {
|
||||
entity.setApprovalStatus("reviewing");
|
||||
}
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean approveFromProcess(Long id, String processorName) {
|
||||
ContractManage entity = service.getById(id);
|
||||
if (entity == null || "approved".equals(entity.getApprovalStatus())
|
||||
|| "change_approved".equals(entity.getApprovalStatus())) {
|
||||
return entity != null;
|
||||
}
|
||||
boolean change = "change_reviewing".equals(entity.getApprovalStatus());
|
||||
entity.setApprovalStatus(change ? "change_approved" : "approved");
|
||||
entity.setCurrentNode("审核通过");
|
||||
entity.setCurrentProcessor(MkProcessNodeHelper.text(processorName, "系统"));
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rejectFromProcess(Long id, String processorName) {
|
||||
ContractManage entity = service.getById(id);
|
||||
if (entity == null || "rejected".equals(entity.getApprovalStatus())
|
||||
|| "change_rejected".equals(entity.getApprovalStatus())) {
|
||||
return entity != null;
|
||||
}
|
||||
boolean change = "change_reviewing".equals(entity.getApprovalStatus());
|
||||
entity.setApprovalStatus(change ? "change_rejected" : "rejected");
|
||||
entity.setCurrentNode("审核不通过");
|
||||
entity.setCurrentProcessor(MkProcessNodeHelper.text(processorName, "系统"));
|
||||
return service.updateById(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
@TenantIgnore
|
||||
@RequiredArgsConstructor
|
||||
public static class WaybillHandler implements IMkProcessBizHandler {
|
||||
private final IWaybillService service;
|
||||
|
||||
@Override
|
||||
public String bizType() {
|
||||
return "waybill-manage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object publicDetail(Long id) {
|
||||
return service.publicDetail(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean syncFromProcessInfo(Long id, Object processInfo) {
|
||||
Waybill entity = service.getById(id);
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
String node = MkProcessNodeHelper.currentNode(processInfo);
|
||||
if (Func.isEmpty(node)) {
|
||||
return false;
|
||||
}
|
||||
entity.setCurrentProcessNode(node);
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean approveFromProcess(Long id, String processorName) {
|
||||
Waybill entity = service.getById(id);
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
entity.setCurrentProcessNode("审核通过");
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rejectFromProcess(Long id, String processorName) {
|
||||
Waybill entity = service.getById(id);
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
entity.setCurrentProcessNode("审核不通过");
|
||||
return service.updateById(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
@TenantIgnore
|
||||
@RequiredArgsConstructor
|
||||
public static class PreSettlementHandler implements IMkProcessBizHandler {
|
||||
private final IPreSettlementService service;
|
||||
|
||||
@Override
|
||||
public String bizType() {
|
||||
return "pre-settlement";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object publicDetail(Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean syncFromProcessInfo(Long id, Object processInfo) {
|
||||
PreSettlement entity = service.getById(id);
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
String node = MkProcessNodeHelper.currentNode(processInfo);
|
||||
String processor = MkProcessNodeHelper.currentProcessor(processInfo);
|
||||
if (Func.isEmpty(node) && Func.isEmpty(processor)) {
|
||||
return false;
|
||||
}
|
||||
if (Func.isNotEmpty(node)) {
|
||||
entity.setCurrentNode(node);
|
||||
}
|
||||
if (Func.isNotEmpty(processor)) {
|
||||
entity.setCurrentProcessor(processor);
|
||||
}
|
||||
entity.setApprovalStatus("reviewing");
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean approveFromProcess(Long id, String processorName) {
|
||||
PreSettlement entity = service.getById(id);
|
||||
if (entity == null || "approved".equals(entity.getApprovalStatus())) {
|
||||
return entity != null;
|
||||
}
|
||||
entity.setApprovalStatus("approved");
|
||||
entity.setCurrentNode("审核通过");
|
||||
entity.setCurrentProcessor(MkProcessNodeHelper.text(processorName, "系统"));
|
||||
entity.setApprovedTime(LocalDateTime.now());
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rejectFromProcess(Long id, String processorName) {
|
||||
PreSettlement entity = service.getById(id);
|
||||
if (entity == null || "returned".equals(entity.getApprovalStatus())) {
|
||||
return entity != null;
|
||||
}
|
||||
entity.setApprovalStatus("returned");
|
||||
entity.setCurrentNode("审核不通过");
|
||||
entity.setCurrentProcessor(MkProcessNodeHelper.text(processorName, "系统"));
|
||||
return service.updateById(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
@TenantIgnore
|
||||
@RequiredArgsConstructor
|
||||
public static class FormalSettlementHandler implements IMkProcessBizHandler {
|
||||
private final IFormalSettlementService service;
|
||||
|
||||
@Override
|
||||
public String bizType() {
|
||||
return "formal-settlement";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object publicDetail(Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean syncFromProcessInfo(Long id, Object processInfo) {
|
||||
FormalSettlement entity = service.getById(id);
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
String node = MkProcessNodeHelper.currentNode(processInfo);
|
||||
String processor = MkProcessNodeHelper.currentProcessor(processInfo);
|
||||
if (Func.isEmpty(node) && Func.isEmpty(processor)) {
|
||||
return false;
|
||||
}
|
||||
if (Func.isNotEmpty(node)) {
|
||||
entity.setCurrentNode(node);
|
||||
}
|
||||
if (Func.isNotEmpty(processor)) {
|
||||
entity.setCurrentProcessor(processor);
|
||||
}
|
||||
entity.setApprovalStatus("reviewing");
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean approveFromProcess(Long id, String processorName) {
|
||||
FormalSettlement entity = service.getById(id);
|
||||
if (entity == null || "approved".equals(entity.getApprovalStatus())) {
|
||||
return entity != null;
|
||||
}
|
||||
entity.setApprovalStatus("approved");
|
||||
entity.setCurrentNode("审核通过");
|
||||
entity.setCurrentProcessor(MkProcessNodeHelper.text(processorName, "系统"));
|
||||
entity.setApprovedTime(LocalDateTime.now());
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rejectFromProcess(Long id, String processorName) {
|
||||
FormalSettlement entity = service.getById(id);
|
||||
if (entity == null || "returned".equals(entity.getApprovalStatus())) {
|
||||
return entity != null;
|
||||
}
|
||||
entity.setApprovalStatus("returned");
|
||||
entity.setCurrentNode("审核不通过");
|
||||
entity.setCurrentProcessor(MkProcessNodeHelper.text(processorName, "系统"));
|
||||
return service.updateById(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
@TenantIgnore
|
||||
@RequiredArgsConstructor
|
||||
public static class PaymentHandler implements IMkProcessBizHandler {
|
||||
private final IPaymentApplicationService service;
|
||||
|
||||
@Override
|
||||
public String bizType() {
|
||||
return "payment-application";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object publicDetail(Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean syncFromProcessInfo(Long id, Object processInfo) {
|
||||
PaymentApplication entity = service.getById(id);
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
String node = MkProcessNodeHelper.currentNode(processInfo);
|
||||
String processor = MkProcessNodeHelper.currentProcessor(processInfo);
|
||||
if (Func.isEmpty(node) && Func.isEmpty(processor)) {
|
||||
return false;
|
||||
}
|
||||
if (Func.isNotEmpty(node)) {
|
||||
entity.setCurrentNode(node);
|
||||
}
|
||||
if (Func.isNotEmpty(processor)) {
|
||||
entity.setCurrentProcessor(processor);
|
||||
}
|
||||
entity.setApprovalStatus("reviewing");
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean approveFromProcess(Long id, String processorName) {
|
||||
PaymentApplication entity = service.getById(id);
|
||||
if (entity == null || "approved".equals(entity.getApprovalStatus())) {
|
||||
return entity != null;
|
||||
}
|
||||
entity.setApprovalStatus("approved");
|
||||
entity.setCurrentNode("审核通过");
|
||||
entity.setCurrentProcessor(MkProcessNodeHelper.text(processorName, "系统"));
|
||||
return service.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rejectFromProcess(Long id, String processorName) {
|
||||
PaymentApplication entity = service.getById(id);
|
||||
if (entity == null || "returned".equals(entity.getApprovalStatus())) {
|
||||
return entity != null;
|
||||
}
|
||||
entity.setApprovalStatus("returned");
|
||||
entity.setCurrentNode("审核不通过");
|
||||
entity.setCurrentProcessor(MkProcessNodeHelper.text(processorName, "系统"));
|
||||
return service.updateById(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
package org.springblade.transport.mk;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.api.FR;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.process.feign.IBusinessProcessClient;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 公开页流程消息:当前节点立即查询,流程实例详情延迟 5 秒查询后同步业务状态。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@TenantIgnore
|
||||
@RequiredArgsConstructor
|
||||
public class MkProcessMessageService {
|
||||
|
||||
private static final long PROCESS_INFO_DELAY_SECONDS = 5L;
|
||||
|
||||
private final IBusinessProcessClient businessProcessClient;
|
||||
private final List<IMkProcessBizHandler> handlers;
|
||||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2, runnable -> {
|
||||
Thread thread = new Thread(runnable, "mk-process-info-" + THREAD_INDEX.incrementAndGet());
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
|
||||
private static final AtomicInteger THREAD_INDEX = new AtomicInteger();
|
||||
|
||||
@PreDestroy
|
||||
public void shutdown() {
|
||||
scheduler.shutdown();
|
||||
}
|
||||
|
||||
public IMkProcessBizHandler handler(String bizType) {
|
||||
Map<String, IMkProcessBizHandler> mapping = handlers.stream()
|
||||
.collect(Collectors.toMap(IMkProcessBizHandler::bizType, Function.identity(), (a, b) -> a));
|
||||
IMkProcessBizHandler handler = mapping.get(bizType);
|
||||
if (handler == null) {
|
||||
throw new IllegalArgumentException("不支持的MK业务类型:" + bizType);
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void handleProcessMessage(String bizType, Map<String, Object> body) {
|
||||
IMkProcessBizHandler handler = handler(bizType);
|
||||
Map<String, Object> formValues = asMap(body == null ? null : body.get("formValues"));
|
||||
String processId = firstText(formValues, "processId");
|
||||
if (StringUtil.isBlank(processId) && body != null) {
|
||||
processId = firstText(body, "processId");
|
||||
}
|
||||
String loginName = firstText(formValues, "mkLoginName", "loginName");
|
||||
if (StringUtil.isBlank(processId)) {
|
||||
log.warn("公开页流程消息未找到 processId,跳过查询当前节点 bizType={}", bizType);
|
||||
return;
|
||||
}
|
||||
String bizIdText = firstText(asMap(body == null ? null : body.get("formData")), "id", "formInstanceId");
|
||||
queryCurrentNodes(bizType, processId, loginName);
|
||||
scheduleProcessInfo(handler, bizType, processId, loginName, bizIdText, formValues);
|
||||
}
|
||||
|
||||
private void queryCurrentNodes(String bizType, String processId, String loginName) {
|
||||
try {
|
||||
FR<Object> result = businessProcessClient.getCurrentNodes(processId, loginName);
|
||||
Object nodeData = result == null ? null : result.getData();
|
||||
log.info("公开页流程消息当前节点详情 bizType={} processId={} loginName={} result={}",
|
||||
bizType, processId, loginName, JSON.toJSONString(nodeData));
|
||||
} catch (Exception e) {
|
||||
log.error("公开页查询当前节点失败 bizType={} processId={} loginName={}", bizType, processId, loginName, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleProcessInfo(IMkProcessBizHandler handler, String bizType, String processId,
|
||||
String loginName, String bizIdText, Map<String, Object> formValues) {
|
||||
Map<String, Object> formValuesCopy = new HashMap<>(formValues == null ? Map.of() : formValues);
|
||||
log.info("公开页将在{}秒后查询流程实例详情 bizType={} processId={}", PROCESS_INFO_DELAY_SECONDS, bizType, processId);
|
||||
scheduler.schedule(
|
||||
() -> queryProcessInfo(handler, bizType, processId, loginName, bizIdText, formValuesCopy),
|
||||
PROCESS_INFO_DELAY_SECONDS,
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
|
||||
private void queryProcessInfo(IMkProcessBizHandler handler, String bizType, String processId,
|
||||
String loginName, String bizIdText, Map<String, Object> formValues) {
|
||||
try {
|
||||
FR<Object> processInfoResult = businessProcessClient.getProcessInfo(processId, loginName);
|
||||
Object processInfo = processInfoResult == null ? null : processInfoResult.getData();
|
||||
log.info("公开页流程消息流程实例详情 bizType={} processId={} loginName={} result={}",
|
||||
bizType, processId, loginName, JSON.toJSONString(processInfo));
|
||||
if (isProcessFinished(processInfo)) {
|
||||
applyProcessResult(handler, bizType, bizIdText, processId, formValues, true);
|
||||
} else if (isProcessRejected(processInfo)) {
|
||||
applyProcessResult(handler, bizType, bizIdText, processId, formValues, false);
|
||||
} else if (StringUtil.isNotBlank(bizIdText)) {
|
||||
try {
|
||||
handler.syncFromProcessInfo(Long.valueOf(bizIdText), processInfo);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("公开页流程消息业务id格式不正确 bizType={} id={}", bizType, bizIdText);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("公开页查询流程实例详情失败 bizType={} processId={} loginName={}", bizType, processId, loginName, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isProcessFinished(Object processInfo) {
|
||||
return "30".equals(firstText(asMap(processInfo), "fdProcessStatus"));
|
||||
}
|
||||
|
||||
private static boolean isProcessRejected(Object processInfo) {
|
||||
Map<String, Object> info = asMap(processInfo);
|
||||
if (!"20".equals(firstText(info, "fdProcessStatus"))) {
|
||||
return false;
|
||||
}
|
||||
if (hasItems(info.get("currentHandlers"))) {
|
||||
return false;
|
||||
}
|
||||
return !hasItems(asMap(info.get("fdTaskInfo")).get("handlerInfos"));
|
||||
}
|
||||
|
||||
private static boolean hasItems(Object value) {
|
||||
return value instanceof Collection<?> collection && !collection.isEmpty();
|
||||
}
|
||||
|
||||
private void applyProcessResult(IMkProcessBizHandler handler, String bizType, String bizIdText,
|
||||
String processId, Map<String, Object> formValues, boolean approved) {
|
||||
String action = approved ? "审核通过" : "审核驳回";
|
||||
if (StringUtil.isBlank(bizIdText)) {
|
||||
log.warn("流程{}但未找到业务id,跳过同步 bizType={} processId={}", action, bizType, processId);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String processorName = firstText(formValues, "mkUserName", "mkLoginName");
|
||||
Long bizId = Long.valueOf(bizIdText);
|
||||
if (approved) {
|
||||
handler.approveFromProcess(bizId, processorName);
|
||||
} else {
|
||||
handler.rejectFromProcess(bizId, processorName);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("流程{}但业务id格式不正确 bizType={} id={}", action, bizType, bizIdText);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Object> asMap(Object value) {
|
||||
if (!(value instanceof Map<?, ?> map)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
map.forEach((key, nested) -> {
|
||||
if (key != null) {
|
||||
result.put(String.valueOf(key), nested);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String firstText(Map<String, Object> source, String... keys) {
|
||||
if (source == null || keys == null) {
|
||||
return null;
|
||||
}
|
||||
for (String key : keys) {
|
||||
Object value = source.get(key);
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
String text = String.valueOf(value).trim();
|
||||
if (StringUtil.isNotBlank(text) && !"null".equalsIgnoreCase(text)) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package org.springblade.transport.mk;
|
||||
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 解析 MK 流程实例详情中的当前节点、当前处理人
|
||||
*/
|
||||
public final class MkProcessNodeHelper {
|
||||
|
||||
private MkProcessNodeHelper() {
|
||||
}
|
||||
|
||||
public static String currentProcessor(Object processInfo) {
|
||||
return joinDistinct(extractTexts(asMap(processInfo).get("currentHandlers"), "fdName", "name"), "、");
|
||||
}
|
||||
|
||||
public static String currentNode(Object processInfo) {
|
||||
Map<String, Object> taskInfo = asMap(asMap(processInfo).get("fdTaskInfo"));
|
||||
return joinDistinct(extractTexts(taskInfo.get("handlerInfos"), "nodeName"), "、");
|
||||
}
|
||||
|
||||
public static String text(String value, String fallback) {
|
||||
return Func.isEmpty(value) ? fallback : value.trim();
|
||||
}
|
||||
|
||||
public static Map<String, Object> asMap(Object value) {
|
||||
if (value instanceof Map<?, ?> map) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
map.forEach((key, nested) -> {
|
||||
if (key != null) {
|
||||
result.put(String.valueOf(key), nested);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
if (value == null) {
|
||||
return Map.of();
|
||||
}
|
||||
try {
|
||||
Map<String, Object> parsed = JsonUtil.toMap(JsonUtil.toJson(value));
|
||||
return parsed == null ? Map.of() : parsed;
|
||||
} catch (Exception ignored) {
|
||||
return Map.of();
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> extractTexts(Object listObj, String... keys) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if (!(listObj instanceof Collection<?> collection) || keys == null) {
|
||||
return result;
|
||||
}
|
||||
for (Object item : collection) {
|
||||
Map<String, Object> map = asMap(item);
|
||||
for (String key : keys) {
|
||||
String text = Func.toStr(map.get(key), "").trim();
|
||||
if (Func.isNotEmpty(text)) {
|
||||
result.add(text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String joinDistinct(List<String> values, String delimiter) {
|
||||
return values.stream().filter(Func::isNotEmpty).distinct().collect(Collectors.joining(delimiter));
|
||||
}
|
||||
}
|
||||
+8
@@ -40,6 +40,14 @@ public interface IContractManageService extends BaseService<ContractManage> {
|
||||
|
||||
IPage<ContractManageVO> selectContractManagePage(IPage<ContractManage> page, ContractManageVO contractManage);
|
||||
ContractManageVO detail(Long id);
|
||||
|
||||
/**
|
||||
* 公开详情,不校验当前用户所属组织
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 合同详情
|
||||
*/
|
||||
ContractManageVO publicDetail(Long id);
|
||||
boolean saveDraft(ContractManage contractManage);
|
||||
boolean submit(ContractManage contractManage);
|
||||
boolean toTemporary(Long id);
|
||||
|
||||
+47
@@ -100,6 +100,53 @@ public interface ICustomerArchiveService extends BaseService<CustomerArchive> {
|
||||
*/
|
||||
boolean submitApproval(Long id);
|
||||
|
||||
/**
|
||||
* 按 MK 当前节点同步客商当前节点、当前处理人和审批状态
|
||||
*
|
||||
* @param id 客商ID
|
||||
* @param currentNode 当前节点
|
||||
* @param currentProcessor 当前处理人
|
||||
* @param approvalStatus 审批状态,可为空,为空时保持为审核中
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean syncProcessNode(Long id, String currentNode, String currentProcessor, String approvalStatus);
|
||||
|
||||
/**
|
||||
* 按 MK getCurrentNodes 返回结果同步客商当前节点
|
||||
*
|
||||
* @param id 客商ID
|
||||
* @param currentNodes MK 当前节点详情
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean syncProcessNodeFromMk(Long id, Object currentNodes);
|
||||
|
||||
/**
|
||||
* 按 MK 流程实例详情回写当前节点、当前处理人
|
||||
*
|
||||
* @param id 客商ID
|
||||
* @param processInfo MK getProcessInfo 返回数据
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean syncProcessNodeFromProcessInfo(Long id, Object processInfo);
|
||||
|
||||
/**
|
||||
* MK 流程结束(fdProcessStatus=30)时将客商置为审核通过
|
||||
*
|
||||
* @param id 客商ID
|
||||
* @param processorName 当前处理人,可为空
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean approveFromProcess(Long id, String processorName);
|
||||
|
||||
/**
|
||||
* MK 流程状态为 20 时将客商置为审核驳回
|
||||
*
|
||||
* @param id 客商ID
|
||||
* @param processorName 当前处理人,可为空
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean rejectFromProcess(Long id, String processorName);
|
||||
|
||||
/**
|
||||
* 撤回审批并恢复草稿状态
|
||||
*
|
||||
|
||||
+8
@@ -40,6 +40,14 @@ public interface IProjectApplyService extends BaseService<ProjectApply> {
|
||||
|
||||
IPage<ProjectApplyVO> selectProjectApplyPage(IPage<ProjectApply> page, ProjectApplyVO projectApply);
|
||||
ProjectApplyVO detail(Long id);
|
||||
|
||||
/**
|
||||
* 公开详情,不校验当前用户所属组织
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 项目立项详情
|
||||
*/
|
||||
ProjectApplyVO publicDetail(Long id);
|
||||
Map<String, Integer> fundRiskStats(ProjectApplyVO projectApply);
|
||||
Map<String, Object> changeRecordDetail(Long id, Integer recordIndex);
|
||||
boolean saveDraft(ProjectApply projectApply);
|
||||
|
||||
+7
@@ -37,6 +37,7 @@ import org.springblade.transport.pojo.vo.ReceivablePayableCargoFeeVO;
|
||||
import org.springblade.transport.pojo.vo.ReceivablePayableDetailVO;
|
||||
import org.springblade.transport.pojo.vo.ReceivablePayableFeeDetailVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
@@ -82,6 +83,12 @@ public interface IReceivablePayableDetailService extends BaseService<ReceivableP
|
||||
/** 完成运单后按合同系统计费模式自动生成应收、应付明细。 */
|
||||
void generateForCompletedWaybills(List<Long> waybillIds);
|
||||
|
||||
/**
|
||||
* 运单维护里程后,同步未挂结算单的应收应付明细里程;
|
||||
* 对按里程、按吨·公里计费的费用行按新里程重新计算。
|
||||
*/
|
||||
void syncMileageFromWaybill(Long waybillId, BigDecimal mileage);
|
||||
|
||||
/**
|
||||
* 批量导入完成运单后按合同系统计费模式生成应收、应付明细。
|
||||
* <p>与导入事务共用同一事务,运单尚未提交,因此直接传入实体而非主键。</p>
|
||||
|
||||
+8
@@ -46,6 +46,14 @@ public interface IWaybillService extends BaseService<Waybill> {
|
||||
IPage<WaybillVO> selectWaybillPage(IPage<Waybill> page, WaybillVO waybill);
|
||||
WaybillVO detail(Long id);
|
||||
|
||||
/**
|
||||
* 公开详情,不校验当前用户所属组织
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 运单详情
|
||||
*/
|
||||
WaybillVO publicDetail(Long id);
|
||||
|
||||
/**
|
||||
* 管理端:运单打卡记录 + 司机上传凭证图(label=节点-凭证类型)
|
||||
*/
|
||||
|
||||
+14
@@ -28,6 +28,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
@@ -97,6 +98,15 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
return contractManageVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
public ContractManageVO publicDetail(Long id) {
|
||||
ContractManageVO contractManageVO = ContractManageWrapper.build().entityVO(loadExists(id));
|
||||
normalizeOptionalIntegerFields(contractManageVO);
|
||||
contractManageVO.setReadonly(true);
|
||||
return contractManageVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean saveDraft(ContractManage contractManage) {
|
||||
@@ -647,6 +657,10 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
if (contractManage.getInvoiceCycle() != null && contractManage.getInvoiceCycle() <= 0) {
|
||||
contractManage.setInvoiceCycle(null);
|
||||
}
|
||||
BigDecimal contractAmount = contractManage.getContractAmount();
|
||||
if (contractAmount != null && contractAmount.compareTo(BigDecimal.valueOf(-1)) == 0) {
|
||||
contractManage.setContractAmount(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDraft(ContractManage contractManage) {
|
||||
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
*/
|
||||
package org.springblade.transport.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.api.FR;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.process.feign.IBusinessProcessClient;
|
||||
import org.springblade.transport.service.ICustomerArchiveService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 客商公开页流程消息处理:当前节点立即查询,流程实例详情延迟查询。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@TenantIgnore
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerArchivePublicProcessService {
|
||||
|
||||
private static final long PROCESS_INFO_DELAY_SECONDS = 5L;
|
||||
|
||||
private final ICustomerArchiveService customerArchiveService;
|
||||
private final IBusinessProcessClient businessProcessClient;
|
||||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2, runnable -> {
|
||||
Thread thread = new Thread(runnable, "customer-archive-process-info-" + THREAD_INDEX.incrementAndGet());
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
|
||||
private static final AtomicInteger THREAD_INDEX = new AtomicInteger();
|
||||
|
||||
@PreDestroy
|
||||
public void shutdown() {
|
||||
scheduler.shutdown();
|
||||
}
|
||||
|
||||
public void handleProcessMessage(Map<String, Object> body) {
|
||||
Map<String, Object> formValues = asMap(body == null ? null : body.get("formValues"));
|
||||
String processId = firstText(formValues, "processId");
|
||||
if (StringUtil.isBlank(processId) && body != null) {
|
||||
processId = firstText(body, "processId");
|
||||
}
|
||||
String loginName = firstText(formValues, "mkLoginName", "loginName");
|
||||
if (StringUtil.isBlank(processId)) {
|
||||
log.warn("客商公开页流程消息未找到 processId,跳过查询当前节点");
|
||||
return;
|
||||
}
|
||||
String customerIdText = firstText(asMap(body == null ? null : body.get("formData")), "id");
|
||||
queryCurrentNodes(processId, loginName);
|
||||
scheduleProcessInfo(processId, loginName, customerIdText, formValues);
|
||||
}
|
||||
|
||||
private void queryCurrentNodes(String processId, String loginName) {
|
||||
try {
|
||||
FR<Object> result = businessProcessClient.getCurrentNodes(processId, loginName);
|
||||
Object nodeData = result == null ? null : result.getData();
|
||||
log.info("客商公开页流程消息当前节点详情 processId={} loginName={} result={}",
|
||||
processId, loginName, JSON.toJSONString(nodeData));
|
||||
} catch (Exception e) {
|
||||
log.error("客商公开页查询当前节点失败 processId={} loginName={}", processId, loginName, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleProcessInfo(String processId, String loginName, String customerIdText,
|
||||
Map<String, Object> formValues) {
|
||||
Map<String, Object> formValuesCopy = new HashMap<>(formValues == null ? Map.of() : formValues);
|
||||
log.info("客商公开页将在{}秒后查询流程实例详情 processId={}", PROCESS_INFO_DELAY_SECONDS, processId);
|
||||
scheduler.schedule(
|
||||
() -> queryProcessInfo(processId, loginName, customerIdText, formValuesCopy),
|
||||
PROCESS_INFO_DELAY_SECONDS,
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
|
||||
private void queryProcessInfo(String processId, String loginName, String customerIdText,
|
||||
Map<String, Object> formValues) {
|
||||
try {
|
||||
FR<Object> processInfoResult = businessProcessClient.getProcessInfo(processId, loginName);
|
||||
Object processInfo = processInfoResult == null ? null : processInfoResult.getData();
|
||||
log.info("客商公开页流程消息流程实例详情 processId={} loginName={} result={}",
|
||||
processId, loginName, JSON.toJSONString(processInfo));
|
||||
if (isProcessFinished(processInfo)) {
|
||||
applyProcessResult(customerIdText, processId, formValues, true);
|
||||
} else if (isProcessRejected(processInfo)) {
|
||||
applyProcessResult(customerIdText, processId, formValues, false);
|
||||
} else if (StringUtil.isNotBlank(customerIdText)) {
|
||||
try {
|
||||
customerArchiveService.syncProcessNodeFromProcessInfo(Long.valueOf(customerIdText), processInfo);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("客商公开页流程消息客商id格式不正确:{}", customerIdText);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("客商公开页查询流程实例详情失败 processId={} loginName={}", processId, loginName, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isProcessFinished(Object processInfo) {
|
||||
return "30".equals(firstText(asMap(processInfo), "fdProcessStatus"));
|
||||
}
|
||||
|
||||
private static boolean isProcessRejected(Object processInfo) {
|
||||
Map<String, Object> info = asMap(processInfo);
|
||||
if (!"20".equals(firstText(info, "fdProcessStatus"))) {
|
||||
return false;
|
||||
}
|
||||
if (hasItems(info.get("currentHandlers"))) {
|
||||
return false;
|
||||
}
|
||||
return !hasItems(asMap(info.get("fdTaskInfo")).get("handlerInfos"));
|
||||
}
|
||||
|
||||
private static boolean hasItems(Object value) {
|
||||
return value instanceof Collection<?> collection && !collection.isEmpty();
|
||||
}
|
||||
|
||||
private void applyProcessResult(String customerIdText, String processId, Map<String, Object> formValues,
|
||||
boolean approved) {
|
||||
String action = approved ? "审核通过" : "审核驳回";
|
||||
if (StringUtil.isBlank(customerIdText)) {
|
||||
log.warn("流程{}但未找到客商id,跳过同步 processId={}", action, processId);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String processorName = firstText(formValues, "mkUserName", "mkLoginName");
|
||||
Long customerId = Long.valueOf(customerIdText);
|
||||
if (approved) {
|
||||
customerArchiveService.approveFromProcess(customerId, processorName);
|
||||
} else {
|
||||
customerArchiveService.rejectFromProcess(customerId, processorName);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("流程{}但客商id格式不正确:{}", action, customerIdText);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Object> asMap(Object value) {
|
||||
if (!(value instanceof Map<?, ?> map)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
map.forEach((key, nested) -> {
|
||||
if (key != null) {
|
||||
result.put(String.valueOf(key), nested);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String firstText(Map<String, Object> source, String... keys) {
|
||||
if (source == null || keys == null) {
|
||||
return null;
|
||||
}
|
||||
for (String key : keys) {
|
||||
Object value = source.get(key);
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
String text = String.valueOf(value).trim();
|
||||
if (StringUtil.isNotBlank(text) && !"null".equalsIgnoreCase(text)) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+226
@@ -29,6 +29,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
@@ -85,6 +86,7 @@ import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -101,6 +103,7 @@ import java.util.stream.Collectors;
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveMapper, CustomerArchive> implements ICustomerArchiveService {
|
||||
@@ -214,12 +217,151 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
CustomerArchive before = Objects.requireNonNull(BeanUtil.copyProperties(detail, CustomerArchive.class));
|
||||
CustomerArchive after = copyCustomer(before);
|
||||
after.setApprovalStatus(APPROVAL_REVIEWING);
|
||||
if (Func.isEmpty(after.getCurrentNode()) || Objects.equals(after.getCurrentNode(), "草稿")) {
|
||||
after.setCurrentNode("客商准入审批");
|
||||
after.setCurrentProcessor("待处理");
|
||||
}
|
||||
addChangeRecord(id, "提交客商准入审批", before, after);
|
||||
return updateById(after);
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean syncProcessNode(Long id, String currentNode, String currentProcessor, String approvalStatus) {
|
||||
if (Func.isEmpty(id)) {
|
||||
log.warn("同步客商当前节点失败,客商ID为空");
|
||||
return false;
|
||||
}
|
||||
CustomerArchive customer = getById(id);
|
||||
if (customer == null || Objects.equals(customer.getIsDeleted(), 1)) {
|
||||
log.warn("同步客商当前节点失败,客商不存在 id={}", id);
|
||||
return false;
|
||||
}
|
||||
String nextStatus = Func.isEmpty(approvalStatus) ? APPROVAL_REVIEWING : approvalStatus;
|
||||
boolean updated = this.lambdaUpdate()
|
||||
.eq(CustomerArchive::getId, id)
|
||||
.set(Func.isNotEmpty(currentNode), CustomerArchive::getCurrentNode, currentNode)
|
||||
.set(Func.isNotEmpty(currentProcessor), CustomerArchive::getCurrentProcessor, currentProcessor)
|
||||
.set(Func.isNotEmpty(nextStatus), CustomerArchive::getApprovalStatus, nextStatus)
|
||||
.update();
|
||||
log.info("同步客商当前节点 id={} currentNode={} currentProcessor={} approvalStatus={} result={}",
|
||||
id, currentNode, currentProcessor, nextStatus, updated);
|
||||
return updated;
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean syncProcessNodeFromMk(Long id, Object currentNodes) {
|
||||
if (Func.isEmpty(id) || currentNodes == null) {
|
||||
return false;
|
||||
}
|
||||
List<Map<String, Object>> nodes = normalizeMkNodeList(currentNodes);
|
||||
if (nodes.isEmpty()) {
|
||||
log.warn("同步客商当前节点跳过,节点详情为空 id={}", id);
|
||||
return false;
|
||||
}
|
||||
List<String> nodeNames = new ArrayList<>();
|
||||
List<String> handlerNames = new ArrayList<>();
|
||||
for (Map<String, Object> node : nodes) {
|
||||
String nodeName = Func.toStr(node.get("nodeName"), "").trim();
|
||||
if (Func.isNotEmpty(nodeName)) {
|
||||
nodeNames.add(nodeName);
|
||||
}
|
||||
Object handlers = node.get("nodeHandlers");
|
||||
if (!(handlers instanceof Collection<?> handlerList)) {
|
||||
continue;
|
||||
}
|
||||
for (Object handler : handlerList) {
|
||||
Map<String, Object> handlerMap = asStringObjectMap(handler);
|
||||
String handlerName = Func.toStr(handlerMap.get("handlerName"), "").trim();
|
||||
if (Func.isNotEmpty(handlerName)) {
|
||||
handlerNames.add(handlerName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return syncProcessNode(id, joinDistinct(nodeNames), joinDistinct(handlerNames), APPROVAL_REVIEWING);
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean syncProcessNodeFromProcessInfo(Long id, Object processInfo) {
|
||||
if (Func.isEmpty(id) || processInfo == null) {
|
||||
return false;
|
||||
}
|
||||
Map<String, Object> info = asStringObjectMap(processInfo);
|
||||
if (info.isEmpty()) {
|
||||
log.warn("同步客商当前节点跳过,流程实例详情为空 id={}", id);
|
||||
return false;
|
||||
}
|
||||
String currentProcessor = joinDistinct(extractTexts(info.get("currentHandlers"), "fdName", "name"), "、");
|
||||
Map<String, Object> taskInfo = asStringObjectMap(info.get("fdTaskInfo"));
|
||||
String currentNode = joinDistinct(extractTexts(taskInfo.get("handlerInfos"), "nodeName"), "、");
|
||||
if (Func.isEmpty(currentNode) && Func.isEmpty(currentProcessor)) {
|
||||
log.warn("同步客商当前节点跳过,未解析到节点名称或处理人 id={}", id);
|
||||
return false;
|
||||
}
|
||||
return syncProcessNode(id, currentNode, currentProcessor, APPROVAL_REVIEWING);
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean approveFromProcess(Long id, String processorName) {
|
||||
if (Func.isEmpty(id)) {
|
||||
log.warn("流程结束审核通过失败,客商ID为空");
|
||||
return false;
|
||||
}
|
||||
CustomerArchive before = getById(id);
|
||||
if (before == null || Objects.equals(before.getIsDeleted(), 1)) {
|
||||
log.warn("流程结束审核通过失败,客商不存在 id={}", id);
|
||||
return false;
|
||||
}
|
||||
if (Objects.equals(before.getApprovalStatus(), APPROVAL_APPROVED)) {
|
||||
log.info("流程结束审核通过跳过,客商已是审核通过 id={}", id);
|
||||
return true;
|
||||
}
|
||||
CustomerArchive after = copyCustomer(before);
|
||||
after.setAccessType(ACCESS_FORMAL);
|
||||
after.setApprovalStatus(APPROVAL_APPROVED);
|
||||
after.setCurrentNode("审核通过");
|
||||
after.setCurrentProcessor(Func.isEmpty(processorName) ? "系统" : processorName.trim());
|
||||
after.setApprovedTime(LocalDateTime.now());
|
||||
addChangeRecord(id, "客商准入审核通过", before, after);
|
||||
boolean updated = updateById(after);
|
||||
log.info("流程结束审核通过 id={} processor={} result={}", id, after.getCurrentProcessor(), updated);
|
||||
return updated;
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean rejectFromProcess(Long id, String processorName) {
|
||||
if (Func.isEmpty(id)) {
|
||||
log.warn("流程审核驳回失败,客商ID为空");
|
||||
return false;
|
||||
}
|
||||
CustomerArchive before = getById(id);
|
||||
if (before == null || Objects.equals(before.getIsDeleted(), 1)) {
|
||||
log.warn("流程审核驳回失败,客商不存在 id={}", id);
|
||||
return false;
|
||||
}
|
||||
if (Objects.equals(before.getApprovalStatus(), APPROVAL_REJECTED)) {
|
||||
log.info("流程审核驳回跳过,客商已是审核不通过 id={}", id);
|
||||
return true;
|
||||
}
|
||||
CustomerArchive after = copyCustomer(before);
|
||||
after.setApprovalStatus(APPROVAL_REJECTED);
|
||||
after.setCurrentNode("审核不通过");
|
||||
after.setCurrentProcessor(Func.isEmpty(processorName) ? "系统" : processorName.trim());
|
||||
addChangeRecord(id, "客商准入审核不通过", before, after);
|
||||
boolean updated = updateById(after);
|
||||
log.info("流程审核驳回 id={} processor={} result={}", id, after.getCurrentProcessor(), updated);
|
||||
return updated;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean withdrawApproval(Long id) {
|
||||
@@ -479,6 +621,23 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
if (Func.isEmpty(accountVO.getAccountName()) && Func.isEmpty(accountVO.getBankAccount())) {
|
||||
continue;
|
||||
}
|
||||
if (Func.isEmpty(accountVO.getAccountName())) {
|
||||
throw new ServiceException("收款单位名称不能为空");
|
||||
}
|
||||
if (Func.isEmpty(accountVO.getAccountHolderName())) {
|
||||
throw new ServiceException("开户人姓名不能为空");
|
||||
}
|
||||
if (Func.isEmpty(accountVO.getBankName())) {
|
||||
throw new ServiceException("开户行不能为空");
|
||||
}
|
||||
if (Func.isEmpty(accountVO.getCnapsCode())) {
|
||||
throw new ServiceException("联行号不能为空");
|
||||
}
|
||||
if (Func.isEmpty(accountVO.getBankAccount())) {
|
||||
throw new ServiceException("收款账号不能为空");
|
||||
}
|
||||
validateLength(accountVO.getCnapsCode(), 32, "联行号最多32个字符");
|
||||
validateLength(accountVO.getRemark(), 200, "收款信息备注最多200个字符");
|
||||
CustomerReceiptAccount account = Objects.requireNonNull(BeanUtil.copyProperties(accountVO, CustomerReceiptAccount.class));
|
||||
account.setId(IdWorker.getId());
|
||||
account.setCustomerId(customerId);
|
||||
@@ -1032,6 +1191,73 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
return Objects.requireNonNull(BeanUtil.copyProperties(customer, CustomerArchive.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> normalizeMkNodeList(Object currentNodes) {
|
||||
Object source = currentNodes;
|
||||
if (source instanceof String text && Func.isNotEmpty(text.trim())) {
|
||||
source = JsonUtil.parse(text, List.class);
|
||||
}
|
||||
if (source instanceof Collection<?> collection) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
for (Object item : collection) {
|
||||
Map<String, Object> map = asStringObjectMap(item);
|
||||
if (!map.isEmpty()) {
|
||||
result.add(map);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Map<String, Object> single = asStringObjectMap(source);
|
||||
return single.isEmpty() ? List.of() : List.of(single);
|
||||
}
|
||||
|
||||
private Map<String, Object> asStringObjectMap(Object value) {
|
||||
if (value instanceof Map<?, ?> map) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
map.forEach((key, nested) -> {
|
||||
if (key != null) {
|
||||
result.put(String.valueOf(key), nested);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
if (value == null) {
|
||||
return Map.of();
|
||||
}
|
||||
try {
|
||||
Map<String, Object> parsed = JsonUtil.toMap(JsonUtil.toJson(value));
|
||||
return parsed == null ? Map.of() : parsed;
|
||||
} catch (Exception ignored) {
|
||||
return Map.of();
|
||||
}
|
||||
}
|
||||
|
||||
private String joinDistinct(List<String> values) {
|
||||
return joinDistinct(values, ",");
|
||||
}
|
||||
|
||||
private String joinDistinct(List<String> values, String delimiter) {
|
||||
return values.stream().filter(Func::isNotEmpty).distinct().collect(Collectors.joining(delimiter));
|
||||
}
|
||||
|
||||
private List<String> extractTexts(Object listObj, String... keys) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if (!(listObj instanceof Collection<?> collection) || keys == null) {
|
||||
return result;
|
||||
}
|
||||
for (Object item : collection) {
|
||||
Map<String, Object> map = asStringObjectMap(item);
|
||||
for (String key : keys) {
|
||||
String text = Func.toStr(map.get(key), "").trim();
|
||||
if (Func.isNotEmpty(text)) {
|
||||
result.add(text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addChangeRecord(Long customerId, String content, CustomerArchive before, CustomerArchive after) {
|
||||
Map<String, Object> beforeSnapshot = customerSnapshot(before);
|
||||
Map<String, Object> afterSnapshot = customerSnapshot(after);
|
||||
|
||||
+1
-1
@@ -598,7 +598,7 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
|
||||
if (Func.isEmpty(request.getRows())) {
|
||||
throw new ServiceException("请填写需要调整的费用行");
|
||||
}
|
||||
String changeReason = requiredText(limitRemark(request.getChangeReason(), 200), "调整原因");
|
||||
String changeReason = limitRemark(request.getChangeReason(), 200);
|
||||
Map<Long, PreSettlementDetailFee> existingMap = detailFees(detail.getId()).stream()
|
||||
.collect(Collectors.toMap(PreSettlementDetailFee::getId, Function.identity()));
|
||||
if (request.getRows().size() != existingMap.size()) {
|
||||
|
||||
+69
@@ -26,9 +26,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
@@ -70,6 +72,7 @@ import java.util.stream.Collectors;
|
||||
* @author Chill
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class ProjectApplyServiceImpl extends BaseServiceImpl<ProjectApplyMapper, ProjectApply> implements IProjectApplyService {
|
||||
|
||||
@@ -109,6 +112,16 @@ public class ProjectApplyServiceImpl extends BaseServiceImpl<ProjectApplyMapper,
|
||||
return projectApplyVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
public ProjectApplyVO publicDetail(Long id) {
|
||||
ProjectApplyVO projectApplyVO = ProjectApplyWrapper.build().entityVO(loadExists(id));
|
||||
normalizeOptionalFields(projectApplyVO);
|
||||
projectApplyVO.setReadonly(true);
|
||||
fillPublicDictOptions(projectApplyVO);
|
||||
return projectApplyVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> fundRiskStats(ProjectApplyVO projectApply) {
|
||||
projectApply.setFundUseRisk(null);
|
||||
@@ -878,6 +891,62 @@ public class ProjectApplyServiceImpl extends BaseServiceImpl<ProjectApplyMapper,
|
||||
projectApplyVO.setReadonly(!canCurrentUserOperate(projectApplyVO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 公开页没有登录态,下拉字典接口无法访问,这里按项目租户把文案一并返回。
|
||||
*/
|
||||
private void fillPublicDictOptions(ProjectApplyVO projectApplyVO) {
|
||||
try {
|
||||
projectApplyVO.setCargoTypeOptions(loadSystemDictOptions("type_of_goods"));
|
||||
projectApplyVO.setTransportTypeOptions(loadBizDictOptions(projectApplyVO.getTenantId(), "transport_type"));
|
||||
projectApplyVO.setSettlementModeOptions(loadBizDictOptions(projectApplyVO.getTenantId(), "settle_method"));
|
||||
} catch (Exception exception) {
|
||||
log.warn("公开项目详情字典加载失败, id={}", projectApplyVO.getId(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Map<String, String>> loadSystemDictOptions(String code) {
|
||||
return toDictOptions(baseMapper.selectDictItems(code));
|
||||
}
|
||||
|
||||
private List<Map<String, String>> loadBizDictOptions(String tenantId, String code) {
|
||||
if (Func.isEmpty(tenantId)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return toDictOptions(baseMapper.selectDictBizItems(tenantId, code));
|
||||
}
|
||||
|
||||
private List<Map<String, String>> toDictOptions(List<Map<String, Object>> rows) {
|
||||
List<Map<String, String>> options = new ArrayList<>();
|
||||
if (rows == null) {
|
||||
return options;
|
||||
}
|
||||
for (Map<String, Object> row : rows) {
|
||||
String dictKey = dictColumn(row, "dictKey", "dictkey", "dict_key");
|
||||
if (Func.isEmpty(dictKey) || "-1".equals(dictKey)) {
|
||||
continue;
|
||||
}
|
||||
String dictValue = dictColumn(row, "dictValue", "dictvalue", "dict_value");
|
||||
Map<String, String> option = new LinkedHashMap<>();
|
||||
option.put("value", dictKey);
|
||||
option.put("label", Func.isEmpty(dictValue) ? dictKey : dictValue);
|
||||
options.add(option);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
private String dictColumn(Map<String, Object> row, String... names) {
|
||||
if (row == null) {
|
||||
return "";
|
||||
}
|
||||
for (String name : names) {
|
||||
Object value = row.get(name);
|
||||
if (value != null && Func.isNotEmpty(String.valueOf(value))) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private boolean canCurrentUserOperate(ProjectApply projectApply) {
|
||||
if (AuthUtil.isAdministrator()) {
|
||||
return true;
|
||||
|
||||
+280
-6
@@ -198,6 +198,209 @@ public class ReceivablePayableDetailServiceImpl
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void syncMileageFromWaybill(Long waybillId, BigDecimal mileage) {
|
||||
if (waybillId == null || mileage == null) {
|
||||
return;
|
||||
}
|
||||
Waybill waybill = waybillService.getById(waybillId);
|
||||
if (waybill == null || Objects.equals(waybill.getIsDeleted(), 1)) {
|
||||
return;
|
||||
}
|
||||
BigDecimal normalizedMileage = normalizeGeneratedMileage(mileage);
|
||||
Set<Long> detailIds = new LinkedHashSet<>();
|
||||
list(Wrappers.<ReceivablePayableDetail>lambdaQuery()
|
||||
.eq(ReceivablePayableDetail::getIsDeleted, 0)
|
||||
.eq(ReceivablePayableDetail::getWaybillId, waybillId)
|
||||
.eq(ReceivablePayableDetail::getSettlementStatus, "pending")
|
||||
.and(wrapper -> wrapper.isNull(ReceivablePayableDetail::getPreSettlementNo)
|
||||
.or().eq(ReceivablePayableDetail::getPreSettlementNo, ""))
|
||||
.and(wrapper -> wrapper.isNull(ReceivablePayableDetail::getFormalSettlementNo)
|
||||
.or().eq(ReceivablePayableDetail::getFormalSettlementNo, "")))
|
||||
.forEach(detail -> detailIds.add(detail.getId()));
|
||||
List<ReceivablePayableCargoFee> relatedFees = cargoFeeMapper.selectList(
|
||||
Wrappers.<ReceivablePayableCargoFee>lambdaQuery()
|
||||
.eq(ReceivablePayableCargoFee::getIsDeleted, 0)
|
||||
.eq(ReceivablePayableCargoFee::getWaybillId, waybillId));
|
||||
relatedFees.stream()
|
||||
.map(ReceivablePayableCargoFee::getDetailId)
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(detailIds::add);
|
||||
if (detailIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (Long detailId : detailIds) {
|
||||
ReceivablePayableDetail detail = getById(detailId);
|
||||
if (detail == null || Objects.equals(detail.getIsDeleted(), 1)
|
||||
|| !"pending".equals(detail.getSettlementStatus())
|
||||
|| Func.isNotEmpty(detail.getPreSettlementNo())
|
||||
|| Func.isNotEmpty(detail.getFormalSettlementNo())) {
|
||||
continue;
|
||||
}
|
||||
syncDetailMileage(detail, waybill, normalizedMileage);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncDetailMileage(ReceivablePayableDetail detail, Waybill waybill, BigDecimal mileage) {
|
||||
List<ReceivablePayableCargoFee> rows = activeCargoFees(detail.getId());
|
||||
if (rows.isEmpty()) {
|
||||
if (Objects.equals(detail.getWaybillId(), waybill.getId())) {
|
||||
detail.setMileage(mileage);
|
||||
updateById(detail);
|
||||
}
|
||||
return;
|
||||
}
|
||||
List<String> changes = new ArrayList<>();
|
||||
boolean feeChanged = false;
|
||||
for (ReceivablePayableCargoFee fee : rows) {
|
||||
boolean related = Objects.equals(fee.getWaybillId(), waybill.getId())
|
||||
|| (fee.getWaybillId() == null && Objects.equals(detail.getWaybillId(), waybill.getId()));
|
||||
if (!related) {
|
||||
continue;
|
||||
}
|
||||
BigDecimal oldMileage = normalizeGeneratedMileage(fee.getMileage());
|
||||
fee.setMileage(mileage);
|
||||
if (isMileageBasedElement(fee.getBillingFactor()) && !isManualFee(fee)
|
||||
&& recalculateMileageBasedFee(detail, fee, waybill, oldMileage)) {
|
||||
changes.add("【运单维护里程】按" + fee.getBillingFactor() + "重新计算费用");
|
||||
}
|
||||
cargoFeeMapper.updateById(fee);
|
||||
feeChanged = true;
|
||||
appendChange(changes, "里程", oldMileage, mileage);
|
||||
}
|
||||
if (!feeChanged && !Objects.equals(detail.getWaybillId(), waybill.getId())) {
|
||||
return;
|
||||
}
|
||||
refreshAdjustedDetail(detail, activeCargoFees(detail.getId()));
|
||||
if (Objects.equals(detail.getWaybillId(), waybill.getId())) {
|
||||
detail.setMileage(mileage);
|
||||
updateById(detail);
|
||||
}
|
||||
if (!changes.isEmpty()) {
|
||||
saveChangeRecord(detail, String.join(";", changes), "运单维护里程同步", "0001");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按最新运单里程重算「按里程 / 按吨·公里」费用行。
|
||||
*/
|
||||
private boolean recalculateMileageBasedFee(ReceivablePayableDetail detail, ReceivablePayableCargoFee fee,
|
||||
Waybill sourceWaybill, BigDecimal previousMileage) {
|
||||
Waybill calcWaybill = waybillForMileageRecalc(sourceWaybill, fee, previousMileage);
|
||||
List<Map<String, Object>> rules = parseList(fee.getBillingRulesJson());
|
||||
if (rules.isEmpty()) {
|
||||
ContractManage contract = contractManageService.getById(detail.getContractId());
|
||||
if (contract != null) {
|
||||
rules = matchingAdjustedRules(contract, fee, calcWaybill);
|
||||
if (!rules.isEmpty()) {
|
||||
fee.setBillingRulesJson(JsonUtil.toJson(rules));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rules.isEmpty()) {
|
||||
log.warn("运单维护里程重算跳过:未找到计费规则,detailId={}, feeId={}", detail.getId(), fee.getId());
|
||||
return false;
|
||||
}
|
||||
Map<String, BigDecimal> calculatedAmounts = new LinkedHashMap<>();
|
||||
BigDecimal calculatedFreight = BigDecimal.ZERO;
|
||||
boolean freightRuleMatched = false;
|
||||
Map<String, Object> measureRule = null;
|
||||
for (Map<String, Object> rule : rules) {
|
||||
BigDecimal amount = calculateRule(rule, calcWaybill);
|
||||
if (amount == null) {
|
||||
continue;
|
||||
}
|
||||
String feeItem = stringValue(rule, "feeItem", "费用");
|
||||
calculatedAmounts.merge(feeItem, amount, BigDecimal::add);
|
||||
if (measureRule == null || isFreightRule(rule)) {
|
||||
measureRule = rule;
|
||||
}
|
||||
if (isFreightRule(rule)) {
|
||||
calculatedFreight = calculatedFreight.add(amount);
|
||||
freightRuleMatched = true;
|
||||
}
|
||||
}
|
||||
if (calculatedAmounts.isEmpty() || measureRule == null) {
|
||||
log.warn("运单维护里程重算跳过:计费规则无法试算,detailId={}, feeId={}", detail.getId(), fee.getId());
|
||||
return false;
|
||||
}
|
||||
Map<String, BigDecimal> feeItems = new LinkedHashMap<>();
|
||||
parseMap(fee.getFeeItemsJson()).forEach((name, value) -> feeItems.put(name, decimal(value)));
|
||||
calculatedAmounts.forEach(feeItems::put);
|
||||
fee.setTransportQuantity(resolveStoredTransportQuantity(measureRule, calcWaybill));
|
||||
fee.setUnitPrice(resolveCalculatedUnitPrice(measureRule, calcWaybill));
|
||||
fee.setBillingFactor(stringValue(measureRule, "billingElement", fee.getBillingFactor()));
|
||||
fee.setBillingType(stringValue(measureRule, "billingType", fee.getBillingType()));
|
||||
fee.setPriceUnit(stringValue(measureRule, "billingUnit", fee.getPriceUnit()));
|
||||
if (freightRuleMatched) {
|
||||
fee.setFreightAmount(calculatedFreight);
|
||||
}
|
||||
fee.setFeeItemsJson(JsonUtil.toJson(feeItems));
|
||||
BigDecimal afterAmount = adjustedAfterAmount(money(fee.getFreightAmount()), feeItems);
|
||||
fee.setAdjustAmount(afterAmount.subtract(money(fee.getOriginalAmount())));
|
||||
fee.setAfterAmount(afterAmount);
|
||||
return true;
|
||||
}
|
||||
|
||||
private Waybill waybillForMileageRecalc(Waybill sourceWaybill, ReceivablePayableCargoFee fee,
|
||||
BigDecimal previousMileage) {
|
||||
Waybill calcWaybill = Objects.requireNonNull(BeanUtil.copyProperties(sourceWaybill, Waybill.class));
|
||||
calcWaybill.setMileage(sourceWaybill.getMileage());
|
||||
String element = fee.getBillingFactor();
|
||||
if (!"按吨·公里".equals(element) && !"按重量".equals(element)
|
||||
&& !"按数量".equals(element) && !"按体积".equals(element)) {
|
||||
return calcWaybill;
|
||||
}
|
||||
List<Map<String, Object>> matchedGoods = parseList(sourceWaybill.getGoodsJson()).stream()
|
||||
.filter(goods -> matchesFeeCargo(goods, fee))
|
||||
.toList();
|
||||
if (!matchedGoods.isEmpty()) {
|
||||
Map<String, Object> goods = matchedGoods.get(0);
|
||||
calcWaybill.setGoodsJson(JsonUtil.toJson(List.of(goods)));
|
||||
calcWaybill.setCargoName(stringValue(goods, "cargoName", fee.getCargoName()));
|
||||
calcWaybill.setCargoType(stringValue(goods, "cargoType", fee.getCargoType()));
|
||||
calcWaybill.setSpecification(stringValue(goods, "specification", fee.getSpecification()));
|
||||
calcWaybill.setModel(stringValue(goods, "model", fee.getModel()));
|
||||
calcWaybill.setQuantity(decimal(goods.get("quantity")));
|
||||
calcWaybill.setQuantityUnit(stringValue(goods, "quantityUnit", fee.getQuantityUnit()));
|
||||
return calcWaybill;
|
||||
}
|
||||
Map<String, Object> goods = new LinkedHashMap<>();
|
||||
goods.put("cargoName", fee.getCargoName());
|
||||
goods.put("cargoType", fee.getCargoType());
|
||||
goods.put("specification", fee.getSpecification());
|
||||
goods.put("model", fee.getModel());
|
||||
goods.put("quantityUnit", fee.getQuantityUnit());
|
||||
BigDecimal quantity = money(fee.getTransportQuantity());
|
||||
if ("按吨·公里".equals(element)) {
|
||||
BigDecimal baseMileage = money(previousMileage);
|
||||
if (baseMileage.signum() > 0) {
|
||||
quantity = quantity.divide(baseMileage, 8, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
goods.put("quantity", quantity);
|
||||
if ("按体积".equals(element)) {
|
||||
goods.put("volume", quantity);
|
||||
}
|
||||
calcWaybill.setGoodsJson(JsonUtil.toJson(List.of(goods)));
|
||||
calcWaybill.setCargoName(fee.getCargoName());
|
||||
calcWaybill.setCargoType(fee.getCargoType());
|
||||
calcWaybill.setSpecification(fee.getSpecification());
|
||||
calcWaybill.setModel(fee.getModel());
|
||||
calcWaybill.setQuantity(quantity);
|
||||
calcWaybill.setQuantityUnit(fee.getQuantityUnit());
|
||||
return calcWaybill;
|
||||
}
|
||||
|
||||
private boolean matchesFeeCargo(Map<String, Object> goods, ReceivablePayableCargoFee fee) {
|
||||
return Objects.equals(stringValue(goods, "cargoName", ""), Objects.toString(fee.getCargoName(), ""))
|
||||
&& Objects.equals(stringValue(goods, "cargoType", ""), Objects.toString(fee.getCargoType(), ""))
|
||||
&& Objects.equals(stringValue(goods, "specification", ""), Objects.toString(fee.getSpecification(), ""))
|
||||
&& Objects.equals(stringValue(goods, "model", ""), Objects.toString(fee.getModel(), ""))
|
||||
&& Objects.equals(stringValue(goods, "quantityUnit", ""), Objects.toString(fee.getQuantityUnit(), ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReceivablePayableFeeDetailVO feeDetail(Long id) {
|
||||
ReceivablePayableDetail detail = getExisting(id);
|
||||
@@ -890,11 +1093,68 @@ public class ReceivablePayableDetailServiceImpl
|
||||
Map<String, Object> plan = resolveDefaultBillingPlan(plans, waybill.getTransportType());
|
||||
if (plan == null) return null;
|
||||
if (!(plan.get("rules") instanceof List<?> rules)) return null;
|
||||
boolean matched = rules.stream().anyMatch(value -> value instanceof Map<?, ?> raw && matchesRule(raw, waybill));
|
||||
boolean matched = rules.stream().anyMatch(value -> {
|
||||
if (!(value instanceof Map<?, ?> raw)) return false;
|
||||
Map<String, Object> rule = toRuleMap(raw);
|
||||
return feeWaybills(rule, waybill).stream()
|
||||
.anyMatch(feeWaybill -> matchesBillingRule(raw, rule, feeWaybill));
|
||||
});
|
||||
if (!matched) return null;
|
||||
return "__matched__";
|
||||
}
|
||||
|
||||
private Map<String, Object> toRuleMap(Map<?, ?> raw) {
|
||||
Map<String, Object> rule = new LinkedHashMap<>();
|
||||
raw.forEach((key, item) -> rule.put(String.valueOf(key), item));
|
||||
return rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* 费用生成规则命中:
|
||||
* 1. 货物需满足匹配规则(始发/目的/货类/货名)
|
||||
* 2. 普通计费要素还要求货物数量单位与计费单位一致
|
||||
* 3. 按里程、按吨·公里按运单里程(×重量)另行计算,不校验数量单位
|
||||
*/
|
||||
private boolean matchesBillingRule(Map<?, ?> raw, Map<String, Object> rule, Waybill feeWaybill) {
|
||||
if (!matchesRule(raw, feeWaybill)) {
|
||||
return false;
|
||||
}
|
||||
String element = stringValue(rule, "billingElement", "");
|
||||
if (isMileageBasedElement(element)) {
|
||||
return true;
|
||||
}
|
||||
return matchesBillingUnit(rule, feeWaybill);
|
||||
}
|
||||
|
||||
private boolean isMileageBasedElement(String element) {
|
||||
return "按里程".equals(element) || "按吨·公里".equals(element);
|
||||
}
|
||||
|
||||
private boolean matchesBillingUnit(Map<String, Object> rule, Waybill feeWaybill) {
|
||||
String billingUnit = stringValue(rule, "billingUnit", "").trim();
|
||||
if (billingUnit.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
String quantityUnit = resolveQuantityUnit(feeWaybill);
|
||||
if (quantityUnit.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return billingUnit.equals(quantityUnit);
|
||||
}
|
||||
|
||||
private String resolveQuantityUnit(Waybill feeWaybill) {
|
||||
String quantityUnit = feeWaybill.getQuantityUnit() == null ? "" : feeWaybill.getQuantityUnit().trim();
|
||||
if (!quantityUnit.isEmpty()) {
|
||||
return quantityUnit;
|
||||
}
|
||||
List<Map<String, Object>> goods = parseList(feeWaybill.getGoodsJson());
|
||||
return goods.stream()
|
||||
.map(item -> stringValue(item, "quantityUnit", "").trim())
|
||||
.filter(Func::isNotEmpty)
|
||||
.findFirst()
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
private boolean matchesRule(Map<?, ?> raw, Waybill waybill) {
|
||||
Object conditionValue = raw.get("matchCondition");
|
||||
if (!(conditionValue instanceof Map<?, ?> condition) || !hasConfiguredMatchCondition(condition)) return true;
|
||||
@@ -1387,10 +1647,10 @@ public class ReceivablePayableDetailServiceImpl
|
||||
Set<List<String>> freightBillingCargoKeys = new LinkedHashSet<>();
|
||||
for (Object value : (List<?>) plan.get("rules")) {
|
||||
if (!(value instanceof Map<?, ?> raw)) continue;
|
||||
Map<String, Object> rule = new LinkedHashMap<>();
|
||||
raw.forEach((key, item) -> rule.put(String.valueOf(key), item));
|
||||
Map<String, Object> rule = toRuleMap(raw);
|
||||
for (Waybill feeWaybill : feeWaybills(rule, waybill)) {
|
||||
if (matchOnly && !matchesRule(raw, feeWaybill)) continue;
|
||||
// 统一生成:匹配规则内货物 + 数量单位一致;按里程/按吨·公里跳过单位匹配
|
||||
if (!matchesBillingRule(raw, rule, feeWaybill)) continue;
|
||||
BigDecimal amount = calculateRule(rule, feeWaybill);
|
||||
if (amount == null) continue;
|
||||
String feeItem = stringValue(rule, "feeItem", "费用");
|
||||
@@ -1446,13 +1706,25 @@ public class ReceivablePayableDetailServiceImpl
|
||||
|
||||
private void fillCalculatedBillingFields(ReceivablePayableCargoFee fee, Waybill feeWaybill,
|
||||
Map<String, Object> rule) {
|
||||
fee.setBillingFactor(stringValue(rule, "billingElement", ""));
|
||||
String element = stringValue(rule, "billingElement", "");
|
||||
fee.setBillingFactor(element);
|
||||
fee.setBillingType(stringValue(rule, "billingType", ""));
|
||||
fee.setTransportQuantity(measure(rule, feeWaybill));
|
||||
fee.setTransportQuantity(resolveStoredTransportQuantity(rule, feeWaybill));
|
||||
fee.setPriceUnit(stringValue(rule, "billingUnit", feeWaybill.getPriceUnit()));
|
||||
fee.setUnitPrice(resolveCalculatedUnitPrice(rule, feeWaybill));
|
||||
}
|
||||
|
||||
/**
|
||||
* 费用行运输量展示值:按车辆/固定金额的计费量仅试算用(为 1),不回写到运输量字段。
|
||||
*/
|
||||
private BigDecimal resolveStoredTransportQuantity(Map<String, Object> rule, Waybill waybill) {
|
||||
String element = stringValue(rule, "billingElement", "");
|
||||
if ("按车辆".equals(element) || "固定金额(整单一口价)".equals(element)) {
|
||||
return null;
|
||||
}
|
||||
return measure(rule, waybill);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析费用行展示用的实际命中单价。
|
||||
* 区间计费的规则默认单价仅用于兜底,费用行应展示当前计费量命中的区间单价。
|
||||
@@ -1635,7 +1907,9 @@ public class ReceivablePayableDetailServiceImpl
|
||||
return switch (element) {
|
||||
case "按体积" -> goods.stream().map(this::goodsVolume).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
case "按车辆", "固定金额(整单一口价)" -> BigDecimal.ONE;
|
||||
// 按里程:计费量=运单里程;固定单价/区间单价/阶梯等均基于该计费量
|
||||
case "按里程" -> money(waybill.getMileage());
|
||||
// 按吨·公里:计费量=货物重量数量 × 运单里程
|
||||
case "按吨·公里" -> goodsQuantity(goods).multiply(money(waybill.getMileage()));
|
||||
case "按数量" -> goodsQuantity(goods);
|
||||
default -> goodsQuantity(goods);
|
||||
|
||||
+22
-1
@@ -28,6 +28,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
@@ -138,6 +139,22 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
public WaybillVO publicDetail(Long id) {
|
||||
if (Func.isEmpty(id)) {
|
||||
throw new ServiceException("主键不能为空");
|
||||
}
|
||||
Waybill waybill = getById(id);
|
||||
if (Func.isEmpty(waybill) || Objects.equals(waybill.getIsDeleted(), 1)) {
|
||||
throw new ServiceException("运单管理不存在");
|
||||
}
|
||||
WaybillVO waybillVO = WaybillWrapper.build().entityVO(waybill);
|
||||
waybillVO.setReadonly(true);
|
||||
fillCustomerNameFromContract(waybillVO);
|
||||
return waybillVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaybillLocateVO locateVehicle(Long id) {
|
||||
Waybill waybill = requireWaybillWithVehicleNo(id, "无法实时定位");
|
||||
@@ -1028,7 +1045,11 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
|
||||
TransportBusinessSupport.validateLength(mileageRemark, 200, "里程维护备注不能超过200字");
|
||||
waybill.setMileage(mileage);
|
||||
waybill.setMileageRemark(mileageRemark);
|
||||
return updateById(waybill);
|
||||
boolean updated = updateById(waybill);
|
||||
if (updated) {
|
||||
receivablePayableDetailService.syncMileageFromWaybill(waybill.getId(), mileage);
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
@@ -27,6 +27,7 @@ import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.transport.pojo.entity.ContractManage;
|
||||
import org.springblade.transport.pojo.vo.ContractManageVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -47,6 +48,10 @@ public class ContractManageWrapper extends BaseEntityWrapper<ContractManage, Con
|
||||
contractManageVO.setUpdateUserName(org.springblade.system.cache.UserCache.getUserRealName(contractManage.getUpdateUser()));
|
||||
contractManageVO.setContractStageName(stageName(contractManage.getContractStage()));
|
||||
contractManageVO.setApprovalStatusName(statusName(contractManage.getApprovalStatus()));
|
||||
if (contractManageVO.getContractAmount() != null
|
||||
&& contractManageVO.getContractAmount().compareTo(BigDecimal.valueOf(-1)) == 0) {
|
||||
contractManageVO.setContractAmount(null);
|
||||
}
|
||||
return contractManageVO;
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -32,6 +32,7 @@ import org.springblade.transport.pojo.vo.WaybillVO;
|
||||
import org.springblade.transport.support.TransportBusinessSupport;
|
||||
import org.springblade.transport.support.WaybillProcessSupport;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -58,9 +59,23 @@ public class WaybillWrapper extends BaseEntityWrapper<Waybill, WaybillVO> {
|
||||
waybillVO.setBusinessStatus(displayStatus);
|
||||
waybillVO.setBusinessStatusName(businessStatusName(displayStatus));
|
||||
waybillVO.setRequireAccept(WaybillProcessSupport.requiresDriverAcceptConfirmation(waybill.getProcessJson()));
|
||||
// 未维护里程等占位值 -1 对外展示为空
|
||||
if (isSentinelMinusOne(waybillVO.getMileage())) {
|
||||
waybillVO.setMileage(null);
|
||||
}
|
||||
if (isSentinelMinusOne(waybillVO.getQuantity())) {
|
||||
waybillVO.setQuantity(null);
|
||||
}
|
||||
if (isSentinelMinusOne(waybillVO.getUnitPrice())) {
|
||||
waybillVO.setUnitPrice(null);
|
||||
}
|
||||
return waybillVO;
|
||||
}
|
||||
|
||||
private static boolean isSentinelMinusOne(BigDecimal value) {
|
||||
return value != null && value.compareTo(BigDecimal.valueOf(-1)) == 0;
|
||||
}
|
||||
|
||||
public static String businessStatusName(String status) {
|
||||
if (status == null) {
|
||||
return "未知";
|
||||
|
||||
Vendored
+9
@@ -65,6 +65,15 @@ public interface IMKClient {
|
||||
@PostMapping("${thirdParty.mk.getCurrentNodesUrl:/openapi/sys-lbpm/sysLbpmProcess/openSupport/getCurNodesInfo}")
|
||||
MKResultVO<List<MKNodeVO>> getCurrentNodes(@RequestBody MKCurrentNodesDTO param, @RequestParam("access_token") String accessToken);
|
||||
|
||||
/**
|
||||
* 获取流程实例详情
|
||||
* @param param
|
||||
* @param accessToken
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("${thirdParty.mk.getProcessInfoUrl:/openapi/sys-lbpm/sysLbpmProcess/openSupport/getProcessInfo}")
|
||||
MKResultVO<Object> getProcessInfo(@RequestBody MKCurrentNodesDTO param, @RequestParam("access_token") String accessToken);
|
||||
|
||||
/**
|
||||
* 获取节点处理人信息
|
||||
* @param param
|
||||
|
||||
+6
@@ -1,6 +1,7 @@
|
||||
package org.springblade.thirdparty.mk.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
@@ -44,4 +45,9 @@ public class MKProcessCreateDTO implements Serializable {
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Object tempVarData;
|
||||
/**
|
||||
* 业务类型,仅 ERP 内部使用,不传给 MK
|
||||
*/
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String bizType;
|
||||
}
|
||||
|
||||
+8
@@ -66,6 +66,14 @@ public interface IMKService {
|
||||
*/
|
||||
List<MKNodeVO> getCurrentNodes(String processInstanceId, String loginName);
|
||||
|
||||
/**
|
||||
* 获取流程实例详情
|
||||
* @param processInstanceId
|
||||
* @param loginName
|
||||
* @return
|
||||
*/
|
||||
Object getProcessInfo(String processInstanceId, String loginName);
|
||||
|
||||
/**
|
||||
* 获取节点处理人信息
|
||||
* @param processInstanceId
|
||||
|
||||
+15
@@ -246,6 +246,21 @@ public class MKServiceImpl implements IMKService {
|
||||
return nodesResult.getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProcessInfo(String processInstanceId, String loginName) {
|
||||
String accessToken = getToken();
|
||||
MKCurrentNodesDTO param = new MKCurrentNodesDTO();
|
||||
param.setProcessInstanceId(processInstanceId);
|
||||
param.setLoginName(loginName);
|
||||
MKResultVO<Object> processInfoResult = client.getProcessInfo(param, accessToken);
|
||||
log.info("调用mk接口 获取流程实例详情 :{}", JSONUtil.toJsonStr(processInfoResult));
|
||||
if (processInfoResult == null || !processInfoResult.isSuccess()) {
|
||||
log.error("调用mk接口 获取流程实例详情异常:{}", JSONUtil.toJsonStr(processInfoResult));
|
||||
return null;
|
||||
}
|
||||
return processInfoResult.getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MKAllHandlerVO getNodeHandlers(String processInstanceId, String loginName, String nodeId) {
|
||||
String accessToken = getToken();
|
||||
|
||||
@@ -118,6 +118,7 @@ thirdParty:
|
||||
processExecuteUrl: ${MK_PROCESS_EXECUTE_URL:/openapi/sys-lbpm/sysLbpmProcess/openSupport/execute}
|
||||
processDeleteUrl: ${MK_PROCESS_DELETE_URL:/openapi/sys-lbpm/sysLbpmProcess/openSupport/delete}
|
||||
getCurrentNodesUrl: ${MK_CURRENT_NODES_URL:/openapi/sys-lbpm/sysLbpmProcess/openSupport/getCurNodesInfo}
|
||||
getProcessInfoUrl: ${MK_PROCESS_INFO_URL:/openapi/sys-lbpm/sysLbpmProcess/openSupport/getProcessInfo}
|
||||
getNodeHandlersUrl: ${MK_NODE_HANDLERS_URL:/openapi/sys-lbpm/sysLbpmProcess/openSupport/getNodeHandlerInfos}
|
||||
getManualNodeUrl: ${MK_MANUAL_NODE_URL:/openapi/sys-lbpm/sysLbpmTemplate/openSupport/getManualNode}
|
||||
pushOrgDeptUrl: ${MK_PUSH_ORG_DEPT_URL:/openapi/sys-org/v2/push/orgDept}
|
||||
|
||||
@@ -91,6 +91,7 @@ thirdParty:
|
||||
processExecuteUrl: ${MK_PROCESS_EXECUTE_URL:/openapi/sys-lbpm/sysLbpmProcess/openSupport/execute}
|
||||
processDeleteUrl: ${MK_PROCESS_DELETE_URL:/openapi/sys-lbpm/sysLbpmProcess/openSupport/delete}
|
||||
getCurrentNodesUrl: ${MK_CURRENT_NODES_URL:/openapi/sys-lbpm/sysLbpmProcess/openSupport/getCurNodesInfo}
|
||||
getProcessInfoUrl: ${MK_PROCESS_INFO_URL:/openapi/sys-lbpm/sysLbpmProcess/openSupport/getProcessInfo}
|
||||
getNodeHandlersUrl: ${MK_NODE_HANDLERS_URL:/openapi/sys-lbpm/sysLbpmProcess/openSupport/getNodeHandlerInfos}
|
||||
getManualNodeUrl: ${MK_MANUAL_NODE_URL:/openapi/sys-lbpm/sysLbpmTemplate/openSupport/getManualNode}
|
||||
pushOrgDeptUrl: ${MK_PUSH_ORG_DEPT_URL:/openapi/sys-org/v2/push/orgDept}
|
||||
|
||||
@@ -197,6 +197,9 @@ blade:
|
||||
- /wechat/**
|
||||
#开启错误日志入库
|
||||
error-log: true
|
||||
#增删改操作日志自动入库(blade_log_api)
|
||||
operation:
|
||||
enabled: true
|
||||
#xss配置
|
||||
xss:
|
||||
enabled: true
|
||||
@@ -218,9 +221,14 @@ blade:
|
||||
- /blade-auth/oauth/logout/**
|
||||
- /blade-transport/customer-archive/public/**
|
||||
- /customer-archive/public/**
|
||||
- /blade-transport/mk-process/public/**
|
||||
- /mk-process/public/**
|
||||
- /blade-openapi/openApi/mk/process/commonCallback
|
||||
- /openApi/mk/process/commonCallback
|
||||
- /feign/client/businessProcess/getCurrentNodes
|
||||
- /feign/client/businessProcess/getProcessInfo
|
||||
- /feign/client/customerArchive/syncProcessNode
|
||||
- /feign/client/mkProcess/**
|
||||
#授权认证配置
|
||||
auth:
|
||||
- method: ALL
|
||||
|
||||
@@ -308,12 +308,15 @@ CREATE TABLE `blade_dept` (
|
||||
`mnemonic_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '助记码',
|
||||
`carrier_customer_id` bigint NULL DEFAULT NULL COMMENT '承运商客商档案主键',
|
||||
`is_platform_company` tinyint NOT NULL DEFAULT 0 COMMENT '是否平台公司:0否,1是',
|
||||
`oa_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'OA主键',
|
||||
`oa_sup_sub_com_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'OA上级主键',
|
||||
`sort` int NULL DEFAULT NULL COMMENT '排序',
|
||||
`remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`status` int NULL DEFAULT 1 COMMENT '状态',
|
||||
`is_deleted` int NULL DEFAULT 0 COMMENT '是否已删除',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_blade_dept_dept_code` (`dept_code`)
|
||||
UNIQUE KEY `uk_blade_dept_dept_code` (`dept_code`),
|
||||
INDEX `idx_blade_dept_oa_id` (`oa_id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '机构表';
|
||||
|
||||
-- ----------------------------
|
||||
|
||||
@@ -93,6 +93,7 @@ CREATE TABLE `blade_customer_receipt_account` (
|
||||
`account_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '收款方名称',
|
||||
`account_holder_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '开户人姓名',
|
||||
`bank_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '开户行名称',
|
||||
`cnaps_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '联行号',
|
||||
`bank_account` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '银行账号',
|
||||
`registered_phone` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '注册电话',
|
||||
`registered_address` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '注册地址',
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
-- 客商收款信息:新增联行号
|
||||
|
||||
ALTER TABLE `blade_customer_receipt_account`
|
||||
ADD COLUMN `cnaps_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '联行号' AFTER `bank_name`;
|
||||
@@ -0,0 +1,6 @@
|
||||
-- 机构表:记录 OA 主键与上级 OA 主键,仅用于同步后重建组织层级,不用于前端展示
|
||||
|
||||
ALTER TABLE `blade_dept`
|
||||
ADD COLUMN `oa_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'OA主键' AFTER `is_platform_company`,
|
||||
ADD COLUMN `oa_sup_sub_com_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'OA上级主键' AFTER `oa_id`,
|
||||
ADD INDEX `idx_blade_dept_oa_id` (`oa_id`);
|
||||
Reference in New Issue
Block a user