feat(wms): 添加钢卷库区操作日志记录功能
- 在WmsMaterialCoilServiceImpl中注入WmsCoilWarehouseOperationLogMapper - 在钢卷发货出库操作后添加操作日志记录功能 - 新增recordWarehouseOperationLog方法用于记录库区操作日志 - 创建CoilWarehouseOperationLog注解用于标记需要记录操作日志的方法 - 实现CoilWarehouseOperationLogAspect切面自动记录操作日志 - 支持通过注解配置操作类型、出入库方向和备注信息 - 提供参数名映射功能自动获取钢卷ID和库区ID参数值
This commit is contained in:
@@ -71,6 +71,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
private final WmsProductMapper productMapper;
|
||||
private final WmsRawMaterialMapper rawMaterialMapper;
|
||||
private final WmsDeliveryWaybillDetailMapper deliveryWaybillDetailMapper;
|
||||
private final WmsCoilWarehouseOperationLogMapper wmsCoilWarehouseOperationLogMapper;
|
||||
|
||||
/**
|
||||
* 查询钢卷物料表
|
||||
@@ -2392,10 +2393,28 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
releaseBo.setIsEnabled(1); // 释放:设置为启用
|
||||
actualWarehouseService.updateByBo(releaseBo);
|
||||
}
|
||||
// 3. 记录操作日志
|
||||
recordWarehouseOperationLog(coilId, oldActualWarehouseId, 4, 2, "钢卷发货出库");
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录钢卷库区操作日志
|
||||
*/
|
||||
private void recordWarehouseOperationLog(Long coilId, Long warehouseId, Integer operationType, Integer inOutType, String remark) {
|
||||
try {
|
||||
WmsCoilWarehouseOperationLog operationLog = new WmsCoilWarehouseOperationLog();
|
||||
operationLog.setCoilId(coilId);
|
||||
operationLog.setActualWarehouseId(warehouseId);
|
||||
operationLog.setOperationType(operationType);
|
||||
operationLog.setInOutType(inOutType);
|
||||
operationLog.setRemark(remark);
|
||||
wmsCoilWarehouseOperationLogMapper.insert(operationLog);
|
||||
} catch (Exception e) {
|
||||
log.warn("记录钢卷库区操作日志失败:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 钢卷发货撤回
|
||||
* @param coilId
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.klp.wms.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface CoilWarehouseOperationLog {
|
||||
|
||||
/**
|
||||
* 操作类型:1=收货,2=加工,3=调拨,4=发货
|
||||
*/
|
||||
int operationType();
|
||||
|
||||
/**
|
||||
* 出入库方向:1=入库,2=出库
|
||||
*/
|
||||
int inOutType();
|
||||
|
||||
/**
|
||||
* 备注说明
|
||||
*/
|
||||
String remark() default "";
|
||||
|
||||
/**
|
||||
* 钢卷ID参数名(方法参数中的字段名)
|
||||
*/
|
||||
String coilIdParam() default "coilId";
|
||||
|
||||
/**
|
||||
* 库区ID参数名(方法参数中的字段名)
|
||||
*/
|
||||
String warehouseIdParam() default "warehouseId";
|
||||
|
||||
/**
|
||||
* 操作前的库区ID参数名(可选,用于记录变更前的库区)
|
||||
*/
|
||||
String oldWarehouseIdParam() default "";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.klp.wms.aspect;
|
||||
|
||||
import com.klp.wms.annotation.CoilWarehouseOperationLog;
|
||||
import com.klp.domain.WmsCoilWarehouseOperationLog;
|
||||
import com.klp.mapper.WmsCoilWarehouseOperationLogMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class CoilWarehouseOperationLogAspect {
|
||||
|
||||
private final WmsCoilWarehouseOperationLogMapper wmsCoilWarehouseOperationLogMapper;
|
||||
|
||||
@Around("@annotation(com.klp.wms.annotation.CoilWarehouseOperationLog)")
|
||||
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
CoilWarehouseOperationLog annotation = method.getAnnotation(CoilWarehouseOperationLog.class);
|
||||
|
||||
Long coilId = getParamValue(joinPoint, annotation.coilIdParam(), Long.class);
|
||||
Long warehouseId = getParamValue(joinPoint, annotation.warehouseIdParam(), Long.class);
|
||||
Long oldWarehouseId = null;
|
||||
if (!annotation.oldWarehouseIdParam().isEmpty()) {
|
||||
oldWarehouseId = getParamValue(joinPoint, annotation.oldWarehouseIdParam(), Long.class);
|
||||
}
|
||||
|
||||
Object result = joinPoint.proceed();
|
||||
|
||||
try {
|
||||
if (coilId != null) {
|
||||
WmsCoilWarehouseOperationLog operationLog = new WmsCoilWarehouseOperationLog();
|
||||
operationLog.setCoilId(coilId);
|
||||
operationLog.setActualWarehouseId(oldWarehouseId != null ? oldWarehouseId : warehouseId);
|
||||
operationLog.setOperationType(annotation.operationType());
|
||||
operationLog.setInOutType(annotation.inOutType());
|
||||
operationLog.setRemark(annotation.remark());
|
||||
wmsCoilWarehouseOperationLogMapper.insert(operationLog);
|
||||
log.info("记录钢卷库区操作日志:coilId={}, operationType={}, inOutType={}",
|
||||
coilId, annotation.operationType(), annotation.inOutType());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("记录钢卷库区操作日志失败:{}", e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private <T> T getParamValue(ProceedingJoinPoint joinPoint, String paramName, Class<T> type) {
|
||||
if (paramName == null || paramName.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Object[] args = joinPoint.getArgs();
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
String[] parameterNames = signature.getParameterNames();
|
||||
|
||||
if (parameterNames == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < parameterNames.length; i++) {
|
||||
if (paramName.equals(parameterNames[i]) && args[i] != null) {
|
||||
if (type.isInstance(args[i])) {
|
||||
return type.cast(args[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user