chenshudong пре 1 месец
родитељ
комит
57e6022f45

+ 30 - 0
airport-common/src/main/java/com/sundot/airport/common/enums/EquipmentColorTypeEnum.java

@@ -0,0 +1,30 @@
1
+package com.sundot.airport.common.enums;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Getter;
5
+
6
+/**
7
+ * 设备台账颜色类型枚举
8
+ */
9
+@Getter
10
+@AllArgsConstructor
11
+public enum EquipmentColorTypeEnum {
12
+
13
+    COLORLESS("COLORLESS", "无色"),
14
+    RED("RED", "红色"),
15
+    ORANGE("ORANGE", "橙色"),
16
+    YELLOW("YELLOW", "黄色");
17
+
18
+    private final String code;
19
+    private final String desc;
20
+
21
+    public static EquipmentColorTypeEnum getByCode(String code) {
22
+        for (EquipmentColorTypeEnum itemEnum : values()) {
23
+            if (itemEnum.getCode().equals(code)) {
24
+                return itemEnum;
25
+            }
26
+        }
27
+        return null;
28
+    }
29
+
30
+}

+ 32 - 0
airport-common/src/main/java/com/sundot/airport/common/enums/EquipmentUsageStatusEnum.java

@@ -0,0 +1,32 @@
1
+package com.sundot.airport.common.enums;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Getter;
5
+
6
+/**
7
+ * 设备台账使用状态枚举
8
+ */
9
+@Getter
10
+@AllArgsConstructor
11
+public enum EquipmentUsageStatusEnum {
12
+
13
+    IN_USE("IN_USE", "在用"),
14
+    SEND_FOR_REPAIR("SEND_FOR_REPAIR", "寄修"),
15
+    LEND("LEND", "借出"),
16
+    DEACTIVATE("DEACTIVATE", "停用"),
17
+    NOT_ENABLED("NOT_ENABLED", "未启用"),
18
+    SUSPEND_USE("SUSPEND_USE", "暂停使用");
19
+
20
+    private final String code;
21
+    private final String desc;
22
+
23
+    public static EquipmentUsageStatusEnum getByCode(String code) {
24
+        for (EquipmentUsageStatusEnum itemEnum : values()) {
25
+            if (itemEnum.getCode().equals(code)) {
26
+                return itemEnum;
27
+            }
28
+        }
29
+        return null;
30
+    }
31
+
32
+}

+ 73 - 0
airport-common/src/main/java/com/sundot/airport/common/utils/EquipmentDateUtils.java

@@ -0,0 +1,73 @@
1
+package com.sundot.airport.common.utils;
2
+
3
+import java.time.LocalDate;
4
+import java.time.ZoneId;
5
+import java.util.Date;
6
+
7
+/**
8
+ * 设备台账时间工具类
9
+ *
10
+ * @author ruoyi
11
+ */
12
+public class EquipmentDateUtils extends org.apache.commons.lang3.time.DateUtils {
13
+    // 定义时区,通常取系统默认或UTC
14
+    private static final ZoneId ZONE_ID = ZoneId.systemDefault();
15
+
16
+    /**
17
+     * 判断输入日期是否早于当前日期 (昨天及以前)
18
+     */
19
+    public static boolean isBeforeToday(Date inputDate) {
20
+        if (inputDate == null) return false;
21
+
22
+        LocalDate inputLocalDate = convertToLocalDate(inputDate);
23
+        LocalDate today = LocalDate.now(ZONE_ID);
24
+
25
+        // 严格早于今天 (昨天及以前)
26
+        return inputLocalDate.isBefore(today);
27
+    }
28
+
29
+    /**
30
+     * 判断输入日期是否晚于当前日期,且在两周(14天)以内
31
+     * 逻辑:输入日期 > 今天 且 输入日期 <= 今天+14天
32
+     */
33
+    public static boolean isWithinTwoWeeks(Date inputDate) {
34
+        if (inputDate == null) return false;
35
+
36
+        LocalDate inputLocalDate = convertToLocalDate(inputDate);
37
+        LocalDate today = LocalDate.now(ZONE_ID);
38
+        LocalDate twoWeeksLater = today.plusDays(14);
39
+
40
+        // isAfter 不包含等于,所以如果今天不算"晚于",用 isAfter
41
+        // 如果包含今天之后的第一天,逻辑如下:
42
+        boolean isAfterToday = inputLocalDate.isAfter(today);
43
+        boolean isWithinRange = !inputLocalDate.isAfter(twoWeeksLater); // 小于等于两周后
44
+
45
+        return isAfterToday && isWithinRange;
46
+    }
47
+
48
+    /**
49
+     * 判断输入日期是否晚于当前日期,且在一个月(30天)以内
50
+     * 逻辑:输入日期 > 今天 且 输入日期 <= 今天+30天
51
+     */
52
+    public static boolean isWithinOneMonth(Date inputDate) {
53
+        if (inputDate == null) return false;
54
+
55
+        LocalDate inputLocalDate = convertToLocalDate(inputDate);
56
+        LocalDate today = LocalDate.now(ZONE_ID);
57
+        LocalDate oneMonthLater = today.plusDays(30); // 或者 plusMonths(1),视业务需求定
58
+
59
+        boolean isAfterToday = inputLocalDate.isAfter(today);
60
+        boolean isWithinRange = !inputLocalDate.isAfter(oneMonthLater);
61
+
62
+        return isAfterToday && isWithinRange;
63
+    }
64
+
65
+    /**
66
+     * 辅助方法:将 java.util.Date 转换为 LocalDate
67
+     */
68
+    private static LocalDate convertToLocalDate(Date date) {
69
+        return date.toInstant()
70
+                .atZone(ZONE_ID)
71
+                .toLocalDate();
72
+    }
73
+}

+ 13 - 0
airport-equipment/src/main/java/com/sundot/airport/equipment/domain/EquipmentLedger.java

@@ -159,6 +159,10 @@ public class EquipmentLedger extends BaseEntity {
159 159
     @TableField(exist = false)
160 160
     private String inspectionTeamUserName;
161 161
 
162
+    /** 颜色*/
163
+    @TableField(exist = false)
164
+    private String colorType;
165
+
162 166
     public void setTenantId(String tenantId) {
163 167
         this.tenantId = tenantId;
164 168
     }
@@ -407,6 +411,14 @@ public class EquipmentLedger extends BaseEntity {
407 411
         this.inspectionTeamUserName = inspectionTeamUserName;
408 412
     }
409 413
 
414
+    public String getColorType() {
415
+        return colorType;
416
+    }
417
+
418
+    public void setColorType(String colorType) {
419
+        this.colorType = colorType;
420
+    }
421
+
410 422
     @Override
411 423
     public String toString() {
412 424
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
@@ -444,6 +456,7 @@ public class EquipmentLedger extends BaseEntity {
444 456
                 .append("inspectionTeamMember2Name", getInspectionTeamMember2Name())
445 457
                 .append("equipmentInspectionRecordList", getEquipmentInspectionRecordList())
446 458
                 .append("baseAttachmentList", getBaseAttachmentList())
459
+                .append("colorType", getColorType())
447 460
                 .toString();
448 461
     }
449 462
 }

+ 20 - 1
airport-equipment/src/main/java/com/sundot/airport/equipment/service/impl/EquipmentLedgerServiceImpl.java

@@ -4,13 +4,17 @@ import java.util.List;
4 4
 
5 5
 import cn.hutool.core.collection.CollUtil;
6 6
 import cn.hutool.core.util.ObjUtil;
7
+import cn.hutool.core.util.StrUtil;
7 8
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
8 9
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
9 10
 import com.sundot.airport.common.domain.BaseAttachment;
10 11
 import com.sundot.airport.common.enums.BaseAttachmentSourceTypeEnum;
12
+import com.sundot.airport.common.enums.EquipmentColorTypeEnum;
13
+import com.sundot.airport.common.enums.EquipmentUsageStatusEnum;
11 14
 import com.sundot.airport.common.exception.ServiceException;
12 15
 import com.sundot.airport.common.service.IBaseAttachmentService;
13 16
 import com.sundot.airport.common.utils.DateUtils;
17
+import com.sundot.airport.common.utils.EquipmentDateUtils;
14 18
 import com.sundot.airport.equipment.domain.EquipmentInspectionRecord;
15 19
 import com.sundot.airport.equipment.service.IEquipmentInspectionRecordService;
16 20
 import org.springframework.beans.factory.annotation.Autowired;
@@ -67,7 +71,22 @@ public class EquipmentLedgerServiceImpl extends ServiceImpl<EquipmentLedgerMappe
67 71
      */
68 72
     @Override
69 73
     public List<EquipmentLedger> selectEquipmentLedgerList(EquipmentLedger equipmentLedger) {
70
-        return equipmentLedgerMapper.selectEquipmentLedgerList(equipmentLedger);
74
+        List<EquipmentLedger> result = equipmentLedgerMapper.selectEquipmentLedgerList(equipmentLedger);
75
+        result.forEach(item -> {
76
+            item.setColorType(EquipmentColorTypeEnum.COLORLESS.getCode());
77
+            if (StrUtil.equals(EquipmentUsageStatusEnum.IN_USE.getCode(), item.getUsageStatus())) {
78
+                if (EquipmentDateUtils.isBeforeToday(item.getNextInspectionDueDate())) {
79
+                    item.setColorType(EquipmentColorTypeEnum.RED.getCode());
80
+                } else if (EquipmentDateUtils.isWithinTwoWeeks(item.getNextInspectionDueDate())) {
81
+                    item.setColorType(EquipmentColorTypeEnum.ORANGE.getCode());
82
+                } else if (EquipmentDateUtils.isWithinOneMonth(item.getNextInspectionDueDate())) {
83
+                    item.setColorType(EquipmentColorTypeEnum.YELLOW.getCode());
84
+                } else {
85
+                    item.setColorType(EquipmentColorTypeEnum.COLORLESS.getCode());
86
+                }
87
+            }
88
+        });
89
+        return result;
71 90
     }
72 91
 
73 92
     /**

+ 6 - 1
airport-equipment/src/main/resources/mapper/equipment/EquipmentLedgerMapper.xml

@@ -134,7 +134,12 @@
134 134
                 )
135 135
             </if>
136 136
         </where>
137
-        order by create_time desc
137
+        order by
138
+        case usage_status
139
+        when 'IN_USE' then 1
140
+        else 2
141
+        end,
142
+        next_inspection_due_date asc
138 143
     </select>
139 144
 
140 145
     <select id="selectEquipmentLedgerById" parameterType="Long" resultMap="EquipmentLedgerResult">