供应商-客户中间表引用表的新增修改删除修改

This commit is contained in:
2025-10-25 22:17:26 +08:00
parent 0b42c1d6a6
commit 6784eafe6e

View File

@ -1,5 +1,6 @@
package org.dromara.xzd.interceptor; package org.dromara.xzd.interceptor;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -27,11 +28,6 @@ public class RequestLogInterceptor implements HandlerInterceptor {
@Autowired @Autowired
private XzdCustomerSupplierYybMapper customerSupplierYybMapper; private XzdCustomerSupplierYybMapper customerSupplierYybMapper;
@Autowired
private AutoIncrementIdHolder autoIncrementIdHolder;
// 需要拦截的请求方法
private static final List<String> INTERCEPT_METHODS = Arrays.asList("POST", "PUT", "DELETE");
// 需要提取的请求体字段(根据实际需求修改) // 需要提取的请求体字段(根据实际需求修改)
private static final List<String> EXTRACT_FIELDS = Arrays.asList("id", private static final List<String> EXTRACT_FIELDS = Arrays.asList("id",
@ -130,7 +126,9 @@ public class RequestLogInterceptor implements HandlerInterceptor {
String uri = (String) cachedData.get("uri"); String uri = (String) cachedData.get("uri");
Map<String, Object> extractedParams = (Map<String, Object>) cachedData.get("extractedParams"); Map<String, Object> extractedParams = (Map<String, Object>) cachedData.get("extractedParams");
if (extractedParams == null || extractedParams.isEmpty()) {
return;
}
// 1. 尝试从请求参数获取ID前端传入的情况如非自增ID // 1. 尝试从请求参数获取ID前端传入的情况如非自增ID
Long newId = convertToLong(extractedParams.get("id")); Long newId = convertToLong(extractedParams.get("id"));
// 2. 从AOP存入的ThreadLocal获取ID数据库自增/雪花算法生成的情况) // 2. 从AOP存入的ThreadLocal获取ID数据库自增/雪花算法生成的情况)
@ -151,6 +149,12 @@ public class RequestLogInterceptor implements HandlerInterceptor {
if ("id".equals(k)){ if ("id".equals(k)){
continue; continue;
} }
if (ObjectUtil.isEmpty(v)) {
continue;
}
if (convertToLong(v) == null){
continue;
}
XzdCustomerSupplierYyb entity = new XzdCustomerSupplierYyb(); XzdCustomerSupplierYyb entity = new XzdCustomerSupplierYyb();
entity.setUri(uri); entity.setUri(uri);
entity.setCSId(convertToLong(v)); entity.setCSId(convertToLong(v));
@ -167,6 +171,9 @@ public class RequestLogInterceptor implements HandlerInterceptor {
private void handlePutOrDelete(HttpServletRequest request, String method) { private void handlePutOrDelete(HttpServletRequest request, String method) {
String uri = request.getRequestURI(); String uri = request.getRequestURI();
Map<String, Object> extractedParams = RequestParamExtractor.extractParams(request, method, EXTRACT_FIELDS); Map<String, Object> extractedParams = RequestParamExtractor.extractParams(request, method, EXTRACT_FIELDS);
if (extractedParams == null || extractedParams.isEmpty()) {
return;
}
if ("PUT".equals(method)) { if ("PUT".equals(method)) {
Long mainTableId = convertToLong(extractedParams.get("id")); Long mainTableId = convertToLong(extractedParams.get("id"));
customerSupplierYybMapper.delete(new LambdaQueryWrapper<XzdCustomerSupplierYyb>().eq(XzdCustomerSupplierYyb::getMainTableId, mainTableId)); customerSupplierYybMapper.delete(new LambdaQueryWrapper<XzdCustomerSupplierYyb>().eq(XzdCustomerSupplierYyb::getMainTableId, mainTableId));
@ -178,6 +185,12 @@ public class RequestLogInterceptor implements HandlerInterceptor {
if ("id".equals(k)){ if ("id".equals(k)){
continue; continue;
} }
if (ObjectUtil.isEmpty(v)) {
continue;
}
if (convertToLong(v) == null){
continue;
}
XzdCustomerSupplierYyb customerSupplierYyb = new XzdCustomerSupplierYyb(); XzdCustomerSupplierYyb customerSupplierYyb = new XzdCustomerSupplierYyb();
customerSupplierYyb.setUri(uri); customerSupplierYyb.setUri(uri);
customerSupplierYyb.setCSId(convertToLong(v)); customerSupplierYyb.setCSId(convertToLong(v));