Commit 4c64c91e39784bf68b0a1b3c6ab302a24249b829

Authored by wangqian
1 parent 814c8684

人机材导入修改

urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/costfee/vo/MechanicalCostImport.java
@@ -86,12 +86,10 @@ public class MechanicalCostImport { @@ -86,12 +86,10 @@ public class MechanicalCostImport {
86 private Long serviceLife; 86 private Long serviceLife;
87 87
88 /** 状态(0正常 1停用) */ 88 /** 状态(0正常 1停用) */
89 - @ExcelProperty(index = 10)  
90 - @NotNull(message = "当前状态不能为空")  
91 - @Min(value = 0, message = "状态只能为0(在用)或1(报废)")  
92 - @Max(value = 1, message = "状态只能为0(在用)或1(报废)")  
93 private Long status; 89 private Long status;
94 90
  91 + @ExcelProperty(index = 10)
  92 + @NotNull(message = "当前状态不能为空")
95 private String statusTxt; 93 private String statusTxt;
96 94
97 /** 归属公司 */ 95 /** 归属公司 */
@@ -110,27 +108,55 @@ public class MechanicalCostImport { @@ -110,27 +108,55 @@ public class MechanicalCostImport {
110 private String remark; 108 private String remark;
111 109
112 110
113 - // 设置status时自动更新statusTxt 111 + /**
  112 + * 1. 修改 statusTxt(文本状态)时,自动同步 status(数字状态)
  113 + * 支持 Excel 导入的文本值:“在用”“正常”→0;“报废”“停用”→1;其他→默认未知状态
  114 + */
  115 + public void setStatusTxt(String statusTxt) {
  116 + this.statusTxt = statusTxt; // 先赋值文本状态
  117 + this.status = parseStatusFromTxt(statusTxt); // 同步数字状态
  118 + }
  119 +
  120 + /**
  121 + * 2. 修改 status(数字状态)时,自动同步 statusTxt(文本状态)
  122 + * 保持双向联动:改数字→更文本,改文本→更数字
  123 + */
114 public void setStatus(Long status) { 124 public void setStatus(Long status) {
115 - this.status = status;  
116 - updateStatusTxt(); 125 + this.status = status; // 先赋值数字状态
  126 + this.statusTxt = parseTxtFromStatus(status); // 同步文本状态
117 } 127 }
118 128
119 - private void updateStatusTxt() {  
120 - if (status == null) {  
121 - statusTxt = null;  
122 - return; 129 + /**
  130 + * 辅助方法:将状态文本转为数字状态
  131 + */
  132 + private Long parseStatusFromTxt(String statusTxt) {
  133 + if (statusTxt == null || statusTxt.trim().isEmpty()) {
  134 + this.statusTxt = "未知状态"; // 空文本兜底
  135 + return null;
123 } 136 }
  137 + String trimmedTxt = statusTxt.trim();
  138 + // 支持多文本映射(兼容 Excel 中可能的不同写法)
  139 + return switch (trimmedTxt) {
  140 + case "在用", "正常", "0" -> 0L;
  141 + case "报废", "停用", "1" -> 1L;
  142 + default -> {
  143 + this.statusTxt = "未知状态"; // 非法文本兜底
  144 + yield null; // 非法状态返回 null,后续可做校验
  145 + }
  146 + };
  147 + }
124 148
125 - switch (status.intValue()) {  
126 - case 0:  
127 - statusTxt = "在用";  
128 - break;  
129 - case 1:  
130 - statusTxt = "报废";  
131 - break;  
132 - default:  
133 - statusTxt = "未知状态"; 149 + /**
  150 + * 辅助方法:将数字状态转为文本状态
  151 + */
  152 + private String parseTxtFromStatus(Long status) {
  153 + if (status == null) {
  154 + return "未知状态";
134 } 155 }
  156 + return switch (status.intValue()) {
  157 + case 0 -> "在用";
  158 + case 1 -> "报废";
  159 + default -> "未知状态";
  160 + };
135 } 161 }
136 } 162 }
urbanops-module-gloabl/src/main/resources/mapper/mechanicalcost/MechanicalCostMapper.xml renamed to urbanops-module-garden/src/main/resources/mapper/mechanicalcost/MechanicalCostMapper.xml
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 4
5 <select id="selectDuplicateIds" resultType="java.lang.Long"> 5 <select id="selectDuplicateIds" resultType="java.lang.Long">
6 SELECT id 6 SELECT id
7 - FROM td_mechanical_cost 7 + FROM garden_mechanical_cost
8 WHERE 8 WHERE
9 <foreach collection="keyList" item="key" separator="OR"> 9 <foreach collection="keyList" item="key" separator="OR">
10 mech_code =#{key.mechCode} 10 mech_code =#{key.mechCode}