package org.jeecg.modules.eam.aspect;
|
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.reflect.MethodSignature;
|
import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
|
import org.jeecg.modules.eam.constant.*;
|
import org.jeecg.modules.eam.entity.*;
|
import org.jeecg.modules.eam.service.IEamEquipmentHistoryLogService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.lang.reflect.Method;
|
|
/**
|
* 设备履历 切面实现
|
*/
|
@Aspect
|
@Component
|
@Slf4j
|
public class EquipmentHistoryLogAspect {
|
|
@Autowired
|
private IEamEquipmentHistoryLogService equipmentHistoryLogService;
|
|
@Pointcut("@annotation(org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog)")
|
public void logPointCut() {
|
|
}
|
|
// 环绕通知:计算执行时间
|
@Around("logPointCut()")
|
public Object logMethodExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
long start_time = System.currentTimeMillis();
|
Object result = joinPoint.proceed();
|
long end_time = System.currentTimeMillis();
|
saveLog(joinPoint, result);
|
log.info("[请求耗时:{}ms]", end_time - start_time);
|
return result;
|
}
|
|
private void saveLog(JoinPoint joinPoint, Object result) {
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
Method method = signature.getMethod();
|
|
EamEquipmentHistoryLog log = new EamEquipmentHistoryLog();
|
|
EquipmentHistoryLog syslog = method.getAnnotation(EquipmentHistoryLog.class);
|
|
if (syslog != null) {
|
log.setBusinessTable(syslog.businessTable());
|
log.setOperationTag(syslog.operationTag().name());
|
convertResult(log, syslog.operationTag(), result);
|
if (StringUtils.isNotBlank(log.getEquipmentId())) {
|
equipmentHistoryLogService.save(log);
|
}
|
}
|
}
|
|
|
private void convertResult(EamEquipmentHistoryLog log, EquipmentOperationTagEnum operationTag, Object result) {
|
switch (operationTag) {
|
case ACCEPTANCE:
|
if (result instanceof EamEquipment) {
|
EamEquipment equipment = (EamEquipment) result;
|
log.setEquipmentId(equipment.getId());
|
log.setBusinessId(equipment.getId());
|
log.setOperator(equipment.getCreateBy());
|
log.setDescription(equipment.getRemark());
|
log.setCreateTime(equipment.getAcceptanceCheckDate());
|
}
|
break;
|
case POINT_INSPECTION:
|
if (result instanceof EamInspectionOrder) {
|
EamInspectionOrder order = (EamInspectionOrder) result;
|
if (InspectionStatus.COMPLETE.name().equals(order.getInspectionStatus())) {
|
log.setEquipmentId(order.getEquipmentId());
|
log.setBusinessId(order.getId());
|
log.setOperator(order.getOperator());
|
log.setDescription(order.getConfirmComment());
|
log.setCreateTime(order.getOperateTime());
|
}
|
}
|
break;
|
case WEEK_MAINTENANCE:
|
if (result instanceof EamWeekMaintenanceOrder) {
|
EamWeekMaintenanceOrder order = (EamWeekMaintenanceOrder) result;
|
if (WeekMaintenanceStatusEnum.COMPLETE.name().equals(order.getMaintenanceStatus())) {
|
log.setEquipmentId(order.getEquipmentId());
|
log.setBusinessId(order.getId());
|
log.setOperator(order.getOperator());
|
log.setDescription(order.getFinalAcceptanceComment());
|
log.setCreateTime(order.getActualEndTime());
|
}
|
}
|
break;
|
case SECOND_MAINTENANCE:
|
if (result instanceof EamSecondMaintenanceOrder) {
|
EamSecondMaintenanceOrder order = (EamSecondMaintenanceOrder) result;
|
if (SecondMaintenanceStatusEnum.COMPLETE.name().equals(order.getMaintenanceStatus())) {
|
log.setEquipmentId(order.getEquipmentId());
|
log.setBusinessId(order.getId());
|
log.setOperator(order.getOperator());
|
log.setDescription(order.getConfirmComment());
|
log.setCreateTime(order.getActualEndTime());
|
}
|
}
|
break;
|
case THIRD_MAINTENANCE:
|
if (result instanceof EamThirdMaintenanceOrder) {
|
EamThirdMaintenanceOrder order = (EamThirdMaintenanceOrder) result;
|
if (ThirdMaintenanceStatusEnum.COMPLETE.name().equals(order.getMaintenanceStatus())) {
|
log.setEquipmentId(order.getEquipmentId());
|
log.setBusinessId(order.getId());
|
log.setOperator(order.getOperator());
|
log.setDescription(order.getProblemDescription());
|
log.setCreateTime(order.getActualEndTime());
|
}
|
}
|
break;
|
case REPORT_REPAIR:
|
if (result instanceof EamReportRepair) {
|
EamReportRepair repair = (EamReportRepair) result;
|
log.setEquipmentId(repair.getEquipmentId());
|
log.setBusinessId(repair.getId());
|
log.setOperator(repair.getCreateBy());
|
log.setDescription(repair.getFaultDescription());
|
log.setCreateTime(repair.getFaultStartTime());
|
}
|
break;
|
case REPAIRED:
|
if (result instanceof EamRepairOrder) {
|
EamRepairOrder order = (EamRepairOrder) result;
|
if (ReportRepairEnum.COMPLETE.name().equals(order.getRepairStatus())) {
|
log.setEquipmentId(order.getEquipmentId());
|
log.setBusinessId(order.getId());
|
log.setOperator(order.getRepairer());
|
log.setDescription(order.getRepairDescription());
|
log.setCreateTime(order.getActualEndTime());
|
}
|
}
|
break;
|
case MAJOR_REPAIR:
|
break;
|
case PARTIAL_REPAIR:
|
break;
|
case LEAN_OUT:
|
if (result instanceof EamEquipmentLeanOut) {
|
EamEquipmentLeanOut order = (EamEquipmentLeanOut) result;
|
if (EquipmentLeanOutStatusEnum.COMPLETE.name().equals(order.getLeanStatus())) {
|
log.setEquipmentId(order.getEquipmentId());
|
log.setBusinessId(order.getId());
|
log.setOperator(order.getLeanPerson());
|
log.setDescription(order.getLeanReason());
|
log.setCreateTime(order.getLeanStartTime());
|
}
|
}
|
break;
|
case GIVE_BACK:
|
break;
|
case SEAL_UP:
|
if (result instanceof EamEquipmentSealUp) {
|
EamEquipmentSealUp order = (EamEquipmentSealUp) result;
|
if (EquipmentSealUpStatusEnum.COMPLETE.name().equals(order.getSealStatus())) {
|
log.setEquipmentId(order.getEquipmentId());
|
log.setBusinessId(order.getId());
|
log.setOperator(order.getReportUser());
|
log.setDescription(order.getSealUpReason());
|
log.setCreateTime(order.getSealEndTime());
|
}
|
}
|
break;
|
case UNSEALED:
|
break;
|
case TRANSFERRED:
|
if (result instanceof EamEquipmentTransfer) {
|
EamEquipmentTransfer order = (EamEquipmentTransfer) result;
|
if (EquipmentTransferStatusEnum.COMPLETE.name().equals(order.getTransferStatus())) {
|
log.setEquipmentId(order.getEquipmentId());
|
log.setBusinessId(order.getId());
|
log.setOperator(order.getReportUser());
|
log.setDescription(order.getTransferReason());
|
log.setCreateTime(order.getTransferTime());
|
}
|
}
|
break;
|
case SCRAPPED:
|
if (result instanceof EamEquipmentScrap) {
|
EamEquipmentScrap order = (EamEquipmentScrap) result;
|
if (EquipmentScrapStatusEnum.COMPLETE.name().equals(order.getScrapStatus())) {
|
log.setEquipmentId(order.getEquipmentId());
|
log.setBusinessId(order.getId());
|
log.setOperator(order.getReportUser());
|
log.setDescription(order.getScrapReason());
|
log.setCreateTime(order.getScrapTime());
|
}
|
}
|
break;
|
default:
|
break;
|
}
|
}
|
|
// private long calculateExecutionTime(JoinPoint joinPoint) {
|
// // 通过环绕通知获取精确时间
|
// // (实际应使用环绕通知中的start_time和end_time计算)
|
// return System.currentTimeMillis() - joinPoint.getArgs()[0].hashCode();
|
// // 此处仅为示例,正确做法参见环绕通知实现
|
// }
|
|
|
}
|