库存日志
This commit is contained in:
parent
aabcf7d09e
commit
c49981a541
|
|
@ -0,0 +1,10 @@
|
|||
package com.bonus.sgzb.base.api.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HttpResult {
|
||||
private int code;
|
||||
private int data;
|
||||
private String msg;
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.bonus.sgzb.system.api;
|
||||
|
||||
import com.bonus.sgzb.base.api.domain.BmStorageLog;
|
||||
import com.bonus.sgzb.system.api.domain.BmNumLogs;
|
||||
import com.bonus.sgzb.system.api.domain.SysOperLog;
|
||||
import com.bonus.sgzb.system.api.factory.RemoteLogFallbackFactory;
|
||||
|
|
@ -12,6 +13,8 @@ import com.bonus.sgzb.common.core.constant.ServiceNameConstants;
|
|||
import com.bonus.sgzb.common.core.domain.R;
|
||||
import com.bonus.sgzb.system.api.domain.SysLogininfor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 日志服务
|
||||
*
|
||||
|
|
@ -41,6 +44,17 @@ public interface RemoteLogService
|
|||
public R<Boolean> saveNumberLog(@RequestBody BmNumLogs bmNumLogs, @RequestHeader(SecurityConstants.FROM_SOURCE) String source) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 保存物资记录日志
|
||||
* @param bmStorageLogList 物资信息
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
* @throws Exception 异常信息
|
||||
*/
|
||||
@PostMapping("/bm_storage_logs")
|
||||
public R<Boolean> batchInsert(@RequestBody List<BmStorageLog> bmStorageLogList, @RequestHeader(SecurityConstants.FROM_SOURCE) String source) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 保存访问记录
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,17 +1,24 @@
|
|||
package com.bonus.sgzb.common.log.aspect;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.bonus.sgzb.base.api.domain.BmStorageLog;
|
||||
import com.bonus.sgzb.base.api.domain.HttpResult;
|
||||
import com.bonus.sgzb.base.api.domain.LeaseOutDetails;
|
||||
import com.bonus.sgzb.common.core.constant.SecurityConstants;
|
||||
import com.bonus.sgzb.common.core.domain.R;
|
||||
import com.bonus.sgzb.common.log.annotation.Log;
|
||||
import com.bonus.sgzb.common.log.enums.BusinessType;
|
||||
import com.bonus.sgzb.common.log.filter.PropertyPreExcludeFilter;
|
||||
import com.bonus.sgzb.common.log.service.AsyncLogService;
|
||||
import com.bonus.sgzb.system.api.RemoteUserService;
|
||||
import com.bonus.sgzb.system.api.domain.BmNumLogs;
|
||||
import com.bonus.sgzb.system.api.model.LoginUser;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
|
|
@ -50,9 +57,14 @@ public class LogAspect
|
|||
/** 计算操作消耗时间 */
|
||||
private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
|
||||
|
||||
private static ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Autowired
|
||||
private AsyncLogService asyncLogService;
|
||||
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
/**
|
||||
* 处理请求前执行
|
||||
*/
|
||||
|
|
@ -139,32 +151,47 @@ public class LogAspect
|
|||
protected void handleMaterialLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) {
|
||||
try
|
||||
{
|
||||
// *========数据库物资日志=========*//
|
||||
BmNumLogs bmNumLogs = new BmNumLogs();
|
||||
bmNumLogs.setStatus(BusinessStatus.SUCCESS.ordinal());
|
||||
List<BmStorageLog> bmStorageLogList = new ArrayList<>();
|
||||
|
||||
// 请求的地址
|
||||
bmNumLogs.setMethod(StringUtils.substring(Objects.requireNonNull(ServletUtils.getRequest()).getRequestURI(), 0, 255));
|
||||
String username = SecurityUtils.getUsername();
|
||||
if (StringUtils.isNotBlank(username))
|
||||
{
|
||||
bmNumLogs.setCreator(username);
|
||||
}
|
||||
|
||||
if (e != null) {
|
||||
bmNumLogs.setStatus(BusinessStatus.FAIL.ordinal());
|
||||
bmNumLogs.setJsonResult(StringUtils.substring(e.getMessage(), 0, 2000));
|
||||
}
|
||||
// 设置方法名称
|
||||
String className = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
bmNumLogs.setModelTitle(className + "." + methodName + "()");
|
||||
// 设置请求方式
|
||||
bmNumLogs.setRequestMethod(ServletUtils.getRequest().getMethod());
|
||||
// 处理设置注解上的参数
|
||||
getControllerMethodDescriptionByMaterial(joinPoint, controllerLog, bmNumLogs, jsonResult);
|
||||
setRequestValue(joinPoint, bmStorageLogList);
|
||||
|
||||
for (BmStorageLog bmStorageLog : bmStorageLogList) {
|
||||
bmStorageLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
||||
|
||||
// 请求的地址
|
||||
bmStorageLog.setMethod(StringUtils.substring(Objects.requireNonNull(ServletUtils.getRequest()).getRequestURI(), 0, 255));
|
||||
String username = SecurityUtils.getUsername();
|
||||
R<LoginUser> userInfo = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||
if (ObjectUtils.isNotEmpty(userInfo))
|
||||
{
|
||||
bmStorageLog.setCreator(userInfo.getData().getSysUser().getNickName());
|
||||
}
|
||||
|
||||
if (e != null) {
|
||||
bmStorageLog.setStatus(BusinessStatus.FAIL.ordinal());
|
||||
bmStorageLog.setJsonResult(StringUtils.substring(e.getMessage(), 0, 2000));
|
||||
}
|
||||
// 设置方法名称
|
||||
String className = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
bmStorageLog.setModelTitle(className + "." + methodName + "()");
|
||||
// 设置请求方式
|
||||
bmStorageLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
||||
|
||||
bmStorageLog.setModelTitle(controllerLog.title());
|
||||
|
||||
if (StringUtils.isNotNull(jsonResult)) {
|
||||
bmStorageLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000));
|
||||
HttpResult msgCode = objectMapper.readValue(bmStorageLog.getJsonResult(), HttpResult.class);
|
||||
bmStorageLog.setResultCode(msgCode.getCode());
|
||||
bmStorageLog.setStatus(msgCode.getCode()==200 ? 0 : 1);
|
||||
bmStorageLog.setResultMsg(msgCode.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
// 保存数据库
|
||||
asyncLogService.saveNumLog(bmNumLogs);
|
||||
asyncLogService.batchInsert(bmStorageLogList);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
|
|
@ -206,6 +233,113 @@ public class LogAspect
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求的参数,放到log中
|
||||
*
|
||||
* @param bmStorageLogList 物资日志
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
private void setRequestValue(JoinPoint joinPoint, List<BmStorageLog> bmStorageLogList) throws Exception {
|
||||
String requestMethod = ServletUtils.getRequest().getMethod();
|
||||
Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
||||
if (StringUtils.isEmpty(paramsMap) && (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))) {
|
||||
// 盘点入库操作
|
||||
// if (joinPoint.getArgs()[0] instanceof SavePutInfoDto) {
|
||||
// SavePutInfoDto savePutInfoDto = (SavePutInfoDto) joinPoint.getArgs()[0];
|
||||
// for (MachIneDto machineDto : savePutInfoDto.getMachIneDtoList()) {
|
||||
// BmStorageLog bmStorageLog = new BmStorageLog();
|
||||
// bmStorageLog.setTypeId(Integer.parseInt(machineDto.getTypeId()));
|
||||
// bmStorageLog.setTypeName(machineDto.getMaCode());
|
||||
// bmStorageLog.setPreStoreNum(Objects.isNull(machineDto.getNum()) ? 0 : machineDto.getNum().intValue());
|
||||
// bmStorageLog.setInNum(Objects.isNull(machineDto.getPutInStoreNum()) ? 0 : machineDto.getPutInStoreNum().intValue());
|
||||
// bmStorageLog.setPostStoreNum(bmStorageLog.getPreStoreNum() + bmStorageLog.getInNum());
|
||||
// bmStorageLogList.add(bmStorageLog);
|
||||
// }
|
||||
// }
|
||||
// 新购验收任务 PurchaseMacodeInfoController.modifyManageStatus
|
||||
// if (joinPoint.getArgs()[0] instanceof MaInputVO) {
|
||||
// MaInputVO maInputVO = (MaInputVO) joinPoint.getArgs()[0];
|
||||
// for (MaInputRecord maInputRecord : maInputVO.getInputRecordList()) {
|
||||
// BmStorageLog bmStorageLog = new BmStorageLog();
|
||||
// bmStorageLog.setTypeId(Objects.isNull(maInputRecord.getTypeId()) ? 0 : maInputRecord.getTypeId().intValue());
|
||||
// bmStorageLog.setTypeName(maInputRecord.getMaCode());
|
||||
// bmStorageLog.setPreStoreNum(Objects.isNull(maInputRecord.getNum()) ? 0: maInputRecord.getNum().intValue());
|
||||
// bmStorageLog.setInNum(Objects.isNull(maInputRecord.getInputNum()) ? 0: maInputRecord.getInputNum().intValue());
|
||||
// bmStorageLog.setPostStoreNum(bmStorageLog.getPreStoreNum() + bmStorageLog.getInNum());
|
||||
// bmStorageLog.setTaskId(String.valueOf(maInputRecord.getTaskId()));
|
||||
// bmStorageLogList.add(bmStorageLog);
|
||||
// }
|
||||
// }
|
||||
// 新购配件入库审核 PurchaseAccessoryController.checkInput, 因为没有出入库闭环,暂时不加库存监控日志
|
||||
// if (joinPoint.getArgs()[0] instanceof MaInputVO) {
|
||||
// MaInputVO maInputVO = (MaInputVO) joinPoint.getArgs()[0];
|
||||
// for (MaInputRecord maInputRecord : maInputVO.getInputRecordList()) {
|
||||
// BmStorageLog bmStorageLog = new BmStorageLog();
|
||||
// bmStorageLog.setTypeId(Objects.isNull(maInputRecord.getTypeId()) ? 0 : maInputRecord.getTypeId().intValue());
|
||||
// bmStorageLog.setTypeName(maInputRecord.getMaCode());
|
||||
// bmStorageLog.setPreStoreNum(Objects.isNull(maInputRecord.getNum()) ? 0: maInputRecord.getNum().intValue());
|
||||
// bmStorageLog.setInNum(Objects.isNull(maInputRecord.getInputNum()) ? 0: maInputRecord.getInputNum().intValue());
|
||||
// bmStorageLog.setPostStoreNum(bmStorageLog.getPreStoreNum() + bmStorageLog.getInNum());
|
||||
// bmStorageLog.setTaskId(String.valueOf(maInputRecord.getTaskId()));
|
||||
// bmStorageLogList.add(bmStorageLog);
|
||||
// }
|
||||
// }
|
||||
// 领料出库
|
||||
// if (joinPoint.getArgs()[0] instanceof List &&
|
||||
// ((List) joinPoint.getArgs()[0]).stream().noneMatch((o -> !(o instanceof LeaseOutDetails)))) {
|
||||
// List<LeaseOutDetails> leaseOutDetails = (List<LeaseOutDetails>)joinPoint.getArgs()[0];
|
||||
// for (LeaseOutDetails lod : leaseOutDetails) {
|
||||
// BmStorageLog bmStorageLog = new BmStorageLog();
|
||||
// bmStorageLog.setTaskId(String.valueOf(lod.getTaskId()));
|
||||
// bmStorageLog.setTypeId(lod.getTypeId());
|
||||
// bmStorageLog.setTypeName(lod.getMaCode());
|
||||
// bmStorageLog.setPreStoreNum(lod.getNum());
|
||||
// bmStorageLog.setOutNum(Objects.isNull(lod.getInputNum()) ? 0 : lod.getInputNum().intValue());
|
||||
// bmStorageLog.setPostStoreNum(lod.getPostStoreNum());
|
||||
// bmStorageLogList.add(bmStorageLog);
|
||||
// }
|
||||
// }
|
||||
// if (joinPoint.getArgs()[0] instanceof LeaseOutDetails) {
|
||||
// LeaseOutDetails lod = (LeaseOutDetails)joinPoint.getArgs()[0];
|
||||
// BmStorageLog bmStorageLog = new BmStorageLog();
|
||||
// bmStorageLog.setTaskId(String.valueOf(lod.getTaskId()));
|
||||
// bmStorageLog.setTypeId(lod.getTypeId());
|
||||
// bmStorageLog.setTypeName(lod.getMaCode());
|
||||
// bmStorageLog.setPreStoreNum(lod.getNum());
|
||||
// bmStorageLog.setOutNum(Objects.isNull(lod.getInputNum()) ? 0 : lod.getInputNum().intValue());
|
||||
// bmStorageLog.setPostStoreNum(lod.getPostStoreNum());
|
||||
// bmStorageLogList.add(bmStorageLog);
|
||||
// }
|
||||
// 退料接收-完成退料
|
||||
// if (joinPoint.getArgs()[0] instanceof BackApplyInfo) {
|
||||
// BackApplyInfo bai = (BackApplyInfo)joinPoint.getArgs()[0];
|
||||
// BmStorageLog bmStorageLog = new BmStorageLog();
|
||||
// bmStorageLog.setTaskId(String.valueOf(bai.getTaskId()));
|
||||
// bmStorageLog.setTypeId(Integer.parseInt(bai.getTypeId()));
|
||||
// bmStorageLog.setTypeName(bai.getMaCode());
|
||||
// bmStorageLog.setPreStoreNum(Integer.parseInt(bai.getNum()));
|
||||
// bmStorageLog.setBackNum(bai.getBackNum());
|
||||
// bmStorageLog.setPassNum(bai.getPassNum());
|
||||
// bmStorageLog.setMaintenanceNum(bai.getMaintenanceNum());
|
||||
// bmStorageLog.setScrapNum(bai.getScrapNum());
|
||||
// bmStorageLog.setPostStoreNum(bai.getPostStoreNum());
|
||||
// bmStorageLogList.add(bmStorageLog);
|
||||
// }
|
||||
// 二级库出入库, 不影响ma_type库存变化,暂时不加库存监控日志
|
||||
// if (joinPoint.getArgs()[0] instanceof TeamLeaseInfo) {
|
||||
// TeamLeaseInfo tli = (TeamLeaseInfo)joinPoint.getArgs()[0];
|
||||
// BmStorageLog bmStorageLog = new BmStorageLog();
|
||||
// bmStorageLog.setAgreementId(Integer.parseInt(tli.getAgreementId()));
|
||||
// bmStorageLog.setTypeId(Integer.parseInt(tli.getTypeId()));
|
||||
// bmStorageLog.setTypeName(tli.getTypeName());
|
||||
// bmStorageLog.setPreStoreNum(1);
|
||||
// bmStorageLog.setPreStoreNum(Integer.parseInt(tli.getNum())); //出入库数量,type=1出库,type=2退库
|
||||
// bmStorageLog.setPostStoreNum(1);
|
||||
// bmStorageLogList.add(bmStorageLog);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取注解中对方法的描述信息 用于Controller层注解
|
||||
*
|
||||
|
|
@ -213,17 +347,17 @@ public class LogAspect
|
|||
* @param materialLog 物资日志
|
||||
* @throws Exception
|
||||
*/
|
||||
public void getControllerMethodDescriptionByMaterial(JoinPoint joinPoint, Log log, BmNumLogs materialLog, Object jsonResult) throws Exception
|
||||
{
|
||||
// 设置标题
|
||||
materialLog.setModelTitle(log.title());
|
||||
// 获取参数的信息,传入到数据库中。
|
||||
setRequestValue(joinPoint, materialLog, log.excludeParamNames());
|
||||
// 保存response,参数和值
|
||||
if (StringUtils.isNotNull(jsonResult)) {
|
||||
materialLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000));
|
||||
}
|
||||
}
|
||||
// public void getControllerMethodDescriptionByMaterial(JoinPoint joinPoint, Log log, BmNumLogs materialLog, Object jsonResult) throws Exception
|
||||
// {
|
||||
// // 设置标题
|
||||
// materialLog.setModelTitle(log.title());
|
||||
// // 获取参数的信息,传入到数据库中。
|
||||
// setRequestValue(joinPoint, materialLog, log.excludeParamNames());
|
||||
// // 保存response,参数和值
|
||||
// if (StringUtils.isNotNull(jsonResult)) {
|
||||
// materialLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000));
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取请求的参数,放到log中
|
||||
|
|
@ -250,35 +384,35 @@ public class LogAspect
|
|||
* @param numLog 物资日志
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
private void setRequestValue(JoinPoint joinPoint, BmNumLogs numLog, String[] excludeParamNames) throws Exception {
|
||||
String requestMethod = numLog.getRequestMethod();
|
||||
Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
||||
if (StringUtils.isEmpty(paramsMap)) {
|
||||
if ((HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))){
|
||||
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
|
||||
numLog.setDescription(StringUtils.substring(params, 0, 2000));
|
||||
}
|
||||
} else {
|
||||
if (paramsMap.containsKey("num")) {
|
||||
if (paramsMap.get("num") instanceof Integer) {
|
||||
numLog.setNum(String.valueOf(paramsMap.get("num")));
|
||||
} else if (paramsMap.get("num") instanceof String) {
|
||||
numLog.setNum((String) paramsMap.get("num"));
|
||||
}
|
||||
}
|
||||
if (paramsMap.containsKey("taskId")) {
|
||||
numLog.setTask(String.valueOf(paramsMap.get("taskId")));
|
||||
}
|
||||
if (paramsMap.containsKey("typeId")) {
|
||||
if (paramsMap.get("typeId") instanceof Integer) {
|
||||
numLog.setTypeId((Integer) paramsMap.get("typeId"));
|
||||
} else if (paramsMap.get("typeId") instanceof String) {
|
||||
numLog.setTypeId(Integer.valueOf((String) paramsMap.get("typeId")));
|
||||
}
|
||||
}
|
||||
numLog.setDescription(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter(excludeParamNames)), 0, 2000));
|
||||
}
|
||||
}
|
||||
// private void setRequestValue(JoinPoint joinPoint, BmNumLogs numLog, String[] excludeParamNames) throws Exception {
|
||||
// String requestMethod = numLog.getRequestMethod();
|
||||
// Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
||||
// if (StringUtils.isEmpty(paramsMap)) {
|
||||
// if ((HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))){
|
||||
// String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
|
||||
// numLog.setDescription(StringUtils.substring(params, 0, 2000));
|
||||
// }
|
||||
// } else {
|
||||
// if (paramsMap.containsKey("num")) {
|
||||
// if (paramsMap.get("num") instanceof Integer) {
|
||||
// numLog.setNum(String.valueOf(paramsMap.get("num")));
|
||||
// } else if (paramsMap.get("num") instanceof String) {
|
||||
// numLog.setNum((String) paramsMap.get("num"));
|
||||
// }
|
||||
// }
|
||||
// if (paramsMap.containsKey("taskId")) {
|
||||
// numLog.setTask(String.valueOf(paramsMap.get("taskId")));
|
||||
// }
|
||||
// if (paramsMap.containsKey("typeId")) {
|
||||
// if (paramsMap.get("typeId") instanceof Integer) {
|
||||
// numLog.setTypeId((Integer) paramsMap.get("typeId"));
|
||||
// } else if (paramsMap.get("typeId") instanceof String) {
|
||||
// numLog.setTypeId(Integer.valueOf((String) paramsMap.get("typeId")));
|
||||
// }
|
||||
// }
|
||||
// numLog.setDescription(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter(excludeParamNames)), 0, 2000));
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 参数拼装
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.bonus.sgzb.common.log.service;
|
||||
|
||||
import com.bonus.sgzb.base.api.domain.BmStorageLog;
|
||||
import com.bonus.sgzb.system.api.domain.BmNumLogs;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
|
@ -8,6 +9,8 @@ import com.bonus.sgzb.common.core.constant.SecurityConstants;
|
|||
import com.bonus.sgzb.system.api.RemoteLogService;
|
||||
import com.bonus.sgzb.system.api.domain.SysOperLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 异步调用日志服务
|
||||
*
|
||||
|
|
@ -35,4 +38,9 @@ public class AsyncLogService
|
|||
public void saveNumLog(BmNumLogs bmNumLogsLog) throws Exception {
|
||||
remoteLogService.saveNumberLog(bmNumLogsLog, SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
@Async
|
||||
public void batchInsert(List<BmStorageLog> bmStorageLogList) throws Exception {
|
||||
remoteLogService.batchInsert(bmStorageLogList, SecurityConstants.INNER);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue