From 84ba58b0e2b8d4e0f354a4651b6a1420fe08aa40 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期四, 20 三月 2025 17:20:15 +0800
Subject: [PATCH] art: 设备管理-设备履历添加 验收履历

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/constant/EquipmentOperationTagEnum.java    |   23 +++++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java  |    9 +
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/aspect/EquipmentHistoryLogAspect.java      |  118 +++++++++++++++++++++++++++++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/aspect/annotation/EquipmentHistoryLog.java |   26 ++++++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java          |    2 
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java     |    4 
 6 files changed, 176 insertions(+), 6 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/aspect/EquipmentHistoryLogAspect.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/aspect/EquipmentHistoryLogAspect.java
new file mode 100644
index 0000000..f6ee8f9
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/aspect/EquipmentHistoryLogAspect.java
@@ -0,0 +1,118 @@
+package org.jeecg.modules.eam.aspect;
+
+import lombok.extern.slf4j.Slf4j;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
+import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum;
+import org.jeecg.modules.eam.entity.EamEquipment;
+import org.jeecg.modules.eam.entity.EamEquipmentHistoryLog;
+import org.jeecg.modules.eam.service.IEamEquipmentHistoryLogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Date;
+
+/**
+ * 璁惧灞ュ巻 鍒囬潰瀹炵幇
+ */
+@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);
+            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:
+                break;
+            case SECOND_MAINTENANCE:
+                break;
+            case THIRD_MAINTENANCE:
+                break;
+            case REPORT_REPAIR:
+                break;
+            case REPAIRED:
+                break;
+            case MAJOR_REPAIR:
+                break;
+            case PARTIAL_REPAIR:
+                break;
+            case LEAN_OUT:
+                break;
+            case GIVE_BACK:
+                break;
+            case SEAL_UP:
+                break;
+            case UNSEALED:
+                break;
+            case TRANSFERRED:
+                break;
+            case SCRAPPED:
+                break;
+            default:
+                break;
+        }
+    }
+
+//    private long calculateExecutionTime(JoinPoint joinPoint) {
+//        // 閫氳繃鐜粫閫氱煡鑾峰彇绮剧‘鏃堕棿
+//        // 锛堝疄闄呭簲浣跨敤鐜粫閫氱煡涓殑start_time鍜宔nd_time璁$畻锛�
+//        return System.currentTimeMillis() - joinPoint.getArgs()[0].hashCode();
+//        // 姝ゅ浠呬负绀轰緥锛屾纭仛娉曞弬瑙佺幆缁曢�氱煡瀹炵幇
+//    }
+
+
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/aspect/annotation/EquipmentHistoryLog.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/aspect/annotation/EquipmentHistoryLog.java
new file mode 100644
index 0000000..b0c91d2
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/aspect/annotation/EquipmentHistoryLog.java
@@ -0,0 +1,26 @@
+package org.jeecg.modules.eam.aspect.annotation;
+
+import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum;
+
+import java.lang.annotation.*;
+
+/**
+ * 璁惧灞ュ巻娉ㄨВ
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface EquipmentHistoryLog {
+
+    /**
+     * 鎿嶄綔鏍囩 鏋氫妇
+     * @return
+     */
+    EquipmentOperationTagEnum operationTag() default EquipmentOperationTagEnum.OTHER;
+
+    /**
+     * 娑夊強鐨勪笟鍔′富琛�
+     * @return
+     */
+    String businessTable() default "";
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/constant/EquipmentOperationTagEnum.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/constant/EquipmentOperationTagEnum.java
new file mode 100644
index 0000000..d68826d
--- /dev/null
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/constant/EquipmentOperationTagEnum.java
@@ -0,0 +1,23 @@
+package org.jeecg.modules.eam.constant;
+
+/**
+ * 璁惧灞ュ巻
+ */
+public enum EquipmentOperationTagEnum {
+    ACCEPTANCE, //楠屾敹
+    POINT_INSPECTION,  //鐐规
+    SECOND_MAINTENANCE,  //浜屼繚
+    THIRD_MAINTENANCE,  //涓変繚
+    REPORT_REPAIR,  //鎶ヤ慨
+    REPAIRED,  //缁翠慨
+    MAJOR_REPAIR,  //澶т慨
+    PARTIAL_REPAIR,  //椤逛慨
+    LEAN_OUT,  //鍊熷嚭
+    GIVE_BACK,  //褰掕繕
+    SEAL_UP,  //灏佸瓨
+    UNSEALED,  //鍚皝
+    TRANSFERRED,  //杞
+    SCRAPPED, //鎶ュ簾
+    OTHER, //鍏跺畠
+    ;
+}
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
index fdb9c2a..584b493 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
@@ -66,8 +66,8 @@
     @ApiOperation(value = "璁惧鍙拌处-娣诲姞", notes = "璁惧鍙拌处-娣诲姞")
     @PostMapping(value = "/add")
     public Result<?> add(@RequestBody EamEquipment eamEquipment) {
-        boolean b = eamEquipmentService.saveEquipment(eamEquipment);
-        if (!b) {
+        EamEquipment entity = eamEquipmentService.saveEquipment(eamEquipment);
+        if (entity == null) {
             Result.OK("娣诲姞澶辫触锛�");
         }
         return Result.OK("娣诲姞鎴愬姛锛�");
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java
index 754a233..7c1f7d7 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java
@@ -15,5 +15,5 @@
      * 鍙拌处璁惧娣诲姞
      * @param eamEquipment
      */
-    boolean saveEquipment(EamEquipment eamEquipment);
+    EamEquipment saveEquipment(EamEquipment eamEquipment);
 }
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
index 77338b0..9122818 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
@@ -2,8 +2,10 @@
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
 import org.jeecg.modules.eam.constant.AssetStatusEnum;
 import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus;
+import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum;
 import org.jeecg.modules.eam.constant.EquipmentRepairStatus;
 import org.jeecg.modules.eam.entity.EamEquipment;
 import org.jeecg.modules.eam.entity.EamEquipmentExtend;
@@ -32,9 +34,10 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public boolean saveEquipment(EamEquipment eamEquipment) {
+    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.ACCEPTANCE, businessTable = "eam_equipment")
+    public EamEquipment saveEquipment(EamEquipment eamEquipment) {
         if (eamEquipment == null) {
-            return false;
+            return null;
         }
         //璧勪骇鐘舵�侀粯璁� 姝e父
         eamEquipment.setAssetStatus(AssetStatusEnum.NORMAL.name());
@@ -50,6 +53,6 @@
         equipmentExtendService.save(eamEquipmentExtend);
 
         //鎻掑叆璁惧灞ュ巻 TODO
-        return true;
+        return eamEquipment;
     }
 }

--
Gitblit v1.9.3