Преглед на файлове

工装检测导入优化

DLC преди 1 година
родител
ревизия
7d48038fef

+ 24 - 41
cx-equipment/cx-equipment-common/src/main/java/com/rongwei/bscommon/sys/service/impl/EquFrockTestRecordServiceImpl.java

@@ -29,6 +29,7 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.regex.Pattern;
 
 @Service
 public class EquFrockTestRecordServiceImpl extends ServiceImpl<EquFrockTestRecordDao, EquFrockTestRecordDo> implements EquFrockTestRecordService {
@@ -57,6 +58,8 @@ public class EquFrockTestRecordServiceImpl extends ServiceImpl<EquFrockTestRecor
             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             SysUserVo currentUser = CommonUtils.getCurrentUser();
             Date date = new Date();
+            String regex = "^(\\-|\\+)?\\d+(\\.\\d+)?$";//只能是数字
+            Pattern pattern = Pattern.compile(regex);
 
             for (int i = 2; i <= lastRowNum; i++) {
                 StringBuilder stringBuilder = new StringBuilder();
@@ -115,55 +118,35 @@ public class EquFrockTestRecordServiceImpl extends ServiceImpl<EquFrockTestRecor
                 if (StringUtils.isBlank(state)) {
                     stringBuilder.append("状态不能为空 ");
                 }
-                if (StringUtils.isNotBlank(diameter)) {
-                    diameter = StringUtil.formatDecimal(diameter);
-                } else {
-                    stringBuilder.append("直径mm不能为空 ");
+                if (StringUtils.isBlank(diameter) || !pattern.matcher(diameter).matches()) {
+                    stringBuilder.append("直径mm不能为空且只能为数字 ");
                 }
-                if (StringUtils.isNotBlank(hs1)) {
-                    hs1 = StringUtil.formatDecimal(hs1);
-                } else {
-                    stringBuilder.append("检测硬度值(HS1)不能为空 ");
+                if (StringUtils.isBlank(hs1) || !pattern.matcher(hs1).matches()) {
+                    stringBuilder.append("检测硬度值(HS1)不能为空且只能为数字 ");
                 }
-                if (StringUtils.isNotBlank(hs2)) {
-                    hs2 = StringUtil.formatDecimal(hs2);
-                } else {
-                    stringBuilder.append("检测硬度值(HS2)不能为空 ");
+                if (StringUtils.isBlank(hs2) || !pattern.matcher(hs2).matches()) {
+                    stringBuilder.append("检测硬度值(HS2)不能为空且只能为数字 ");
                 }
-                if (StringUtils.isNotBlank(hs3)) {
-                    hs3 = StringUtil.formatDecimal(hs3);
-                } else {
-                    stringBuilder.append("检测硬度值(HS3)不能为空 ");
+                if (StringUtils.isBlank(hs3) || !pattern.matcher(hs3).matches()) {
+                    stringBuilder.append("检测硬度值(HS3)不能为空且只能为数字 ");
                 }
-                if (StringUtils.isNotBlank(hs4)) {
-                    hs4 = StringUtil.formatDecimal(hs4);
-                } else {
-                    stringBuilder.append("检测硬度值(HS4)不能为空 ");
+                if (StringUtils.isBlank(hs4) || !pattern.matcher(hs4).matches()) {
+                    stringBuilder.append("检测硬度值(HS4)不能为空且只能为数字 ");
                 }
-                if (StringUtils.isNotBlank(hs5)) {
-                    hs5 = StringUtil.formatDecimal(hs5);
-                } else {
-                    stringBuilder.append("检测硬度值(HS5)不能为空 ");
+                if (StringUtils.isBlank(hs5) || !pattern.matcher(hs5).matches()) {
+                    stringBuilder.append("检测硬度值(HS5)不能为空且只能为数字 ");
                 }
-                if (StringUtils.isNotBlank(hs6)) {
-                    hs6 = StringUtil.formatDecimal(hs6);
-                } else {
-                    stringBuilder.append("检测硬度值(HS6)不能为空 ");
+                if (StringUtils.isBlank(hs6) || !pattern.matcher(hs6).matches()) {
+                    stringBuilder.append("检测硬度值(HS6)不能为空且只能为数字 ");
                 }
-                if (StringUtils.isNotBlank(hs7)) {
-                    hs7 = StringUtil.formatDecimal(hs7);
-                } else {
-                    stringBuilder.append("检测硬度值(HS7)不能为空 ");
+                if (StringUtils.isBlank(hs7) || !pattern.matcher(hs7).matches()) {
+                    stringBuilder.append("检测硬度值(HS7)不能为空且只能为数字 ");
                 }
-                if (StringUtils.isNotBlank(hs8)) {
-                    hs8 = StringUtil.formatDecimal(hs8);
-                } else {
-                    stringBuilder.append("检测硬度值(HS8)不能为空 ");
+                if (StringUtils.isBlank(hs8) || !pattern.matcher(hs8).matches()) {
+                    stringBuilder.append("检测硬度值(HS8)不能为空且只能为数字 ");
                 }
-                if (StringUtils.isNotBlank(hs9)) {
-                    hs9 = StringUtil.formatDecimal(hs9);
-                } else {
-                    stringBuilder.append("检测硬度值(HS9)不能为空 ");
+                if (StringUtils.isBlank(hs9) || !pattern.matcher(hs9).matches()) {
+                    stringBuilder.append("检测硬度值(HS9)不能为空且只能为数字 ");
                 }
                 if (equFrockTestRecordDos.stream().anyMatch(item -> item.getFrocknum().equals(frocknum) && item.getTestdate().toString().equals(exctestdate))) {
                     stringBuilder.append("工装编号" + frocknum + "、检定日期" + testdate + "数据重复");
@@ -211,7 +194,7 @@ public class EquFrockTestRecordServiceImpl extends ServiceImpl<EquFrockTestRecor
         } else {
             if (equFrockTestRecordDos.size() > 0) {
                 if (equFrockTestRecordService.saveOrUpdateBatch(equFrockTestRecordDos)) {
-                    return R.ok();
+                    return R.ok("上传成功");
                 } else {
                     return R.error("上传失败");
                 }