ソースを参照

电池imei扩充

zyg 1 年間 前
コミット
e248c31556

+ 0 - 53
.drone.yml

@@ -1,53 +0,0 @@
-kind: pipeline
-name: default
-
-steps:
-  - name: restore-cache
-    image: drillster/drone-volume-cache
-    volumes:
-      - name: cache
-        path: /cache
-    settings:
-      restore: true
-      mount:
-        - .m2
-
-  - name: build
-    image: jaikuai/npm-mvn
-    pull: false
-    commands:
-      - mvn install -Dmaven.repo.local=/drone/src/.m2/repository -Dmaven.test.skip=true package
-
-  - name: rebuild-cache
-    image: drillster/drone-volume-cache
-    volumes:
-      - name: cache
-        path: /cache
-    settings:
-      rebuild: true
-      mount:
-        - .m2
-  - name: docker
-    image: plugins/docker
-    settings:
-      tags:
-        - latest
-        - 1.1.${DRONE_BUILD_NUMBER}
-      registry: nas.fast-fun.cn:5000
-      insecure: true
-      repo: nas.fast-fun.cn:5000/zhl/pdms-oss-api
-
-  - name: deploy
-    image: appleboy/drone-ssh
-    settings:
-      host: 192.168.0.41
-      username: zhl
-      password: 123456
-      script:
-        - docker rm -f oss-api
-        - docker rmi -f nas.fast-fun.cn:5000/zhl/pdms-oss-api
-        - docker run -d --name oss-api -l traefik.port=8082 --restart=always nas.fast-fun.cn:5000/zhl/pdms-oss-api
-volumes:
-  - name: cache
-    host:
-      path: /home/drone/cache

+ 8 - 8
src/main/java/cn/fastfun/controller/api/ApiAppDeviceController.java

@@ -126,8 +126,8 @@ public class ApiAppDeviceController {
             List<Map<String, Object>> data = (List<Map<String, Object>>) page.getData();
             BigInteger operateID = (BigInteger) data.get(0).get("max_opid");
             operateID = operateID.add(BigInteger.valueOf(1));
-
-            AppDevice entity = new AppDevice().fromFormParam(param);// 实体
+            // 实体
+            AppDevice entity = new AppDevice().fromFormParam(param);
             entity.setOperateID(operateID.intValue());
             entity.setOperator(utilService.getUserName());
             entity.setPackModel(param.getPackModel());
@@ -145,12 +145,12 @@ public class ApiAppDeviceController {
         AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", param.getSn()));
         if (!(appDevice.getCheckStatus().equals(1))) {
             Map<String, Boolean> checkRes = appDeviceLogService.selfCheck(param.getSn());
-            appDevice.setCheckStatus(BooleanUtils.toInteger(checkRes.get("checkResult"))); //自检
-            appDevice.setCheckStatusDataConnect(BooleanUtils.toInteger(checkRes.get("checkDataConnectResult"))); //自检
-            appDevice.setCheckStatusLocation(BooleanUtils.toInteger(checkRes.get("checkLocationResult"))); //自检
-            appDevice.setCheckStatusLock(BooleanUtils.toInteger(checkRes.get("checkLockResult"))); //自检
-            appDevice.setCheckStatusFault(BooleanUtils.toInteger(checkRes.get("checkFaultResult"))); //自检
-            appDevice.setCheckStatusVoltage(BooleanUtils.toInteger(checkRes.get("checkVoltageResult"))); //自检
+            appDevice.setCheckStatus(BooleanUtils.toInteger(checkRes.get("checkResult")));
+            appDevice.setCheckStatusDataConnect(BooleanUtils.toInteger(checkRes.get("checkDataConnectResult")));
+            appDevice.setCheckStatusLocation(BooleanUtils.toInteger(checkRes.get("checkLocationResult")));
+            appDevice.setCheckStatusLock(BooleanUtils.toInteger(checkRes.get("checkLockResult")));
+            appDevice.setCheckStatusFault(BooleanUtils.toInteger(checkRes.get("checkFaultResult")));
+            appDevice.setCheckStatusVoltage(BooleanUtils.toInteger(checkRes.get("checkVoltageResult")));
             appDeviceService.save(appDevice);
         }
         return ApiDTO.ok("200", appDevice.getCheckStatus());

+ 64 - 31
src/main/java/cn/fastfun/controller/api/ProductController.java

@@ -1,6 +1,7 @@
 package cn.fastfun.controller.api;
 
 
+import cn.fastfun.service.AppDeviceService;
 import cn.fastfun.service.ProductService;
 import cn.fastfun.service.entity.IdParamForStatus;
 import cn.fastfun.service.entity.Product;
@@ -10,10 +11,12 @@ import com.bridge.dto.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Api(tags = "设备类型记录(典表)")
 @RestController
@@ -22,48 +25,78 @@ public class ProductController {
 
     @Resource
     ProductService productService;
+    @Resource
+    AppDeviceService appDeviceService;
 
     @ApiOperation(value = "保存SN规则信息")
     @PostMapping("/save")
     public ApiDTO save(@RequestBody @ApiParam(name = "SN规则对象", value = "传入json格式", required = true) Product product) {
+        //已经使用过的imei对应的值不可以更改 M GM CL N 7 50 M 214L028,未被使用过的可以随便改
+        String sql = "select id from app_device where imei is not null ";
+        String condition = "";
+        if (product.getId() != null) {
+            Product p = productService.getOne(QueryParamExp.eq("id", product.getId()));
+            if (product.getSnTypeEn() != null) {
+                switch (product.getSnTypeEn()) {
+                    //(1位)=产品类型代码
+                    case 1:
+                        condition = "and substring(imei,1,1)='" + p.getSnTypeCode() + "'";
+                        break;
+                    //(2-3位)=PACK制造商简称
+                    case 2:
+                        condition = "and substring(imei,2,2)='" + p.getSnTypeCode() + "'";
+                        break;
+                    //(4-5位)=电芯厂家名称
+                    case 3:
+                        condition = "and substring(imei,4,2)='" + p.getSnTypeCode() + "'";
+                        break;
+                    //(6位)=产品规格代码 L化学成分
+                    case 4:
+                        condition = "and substring(imei,6,1)='" + p.getSnTypeCode() + "'";
+                        break;
+                    //(7位)=电压
+                    case 5:
+                        condition = "and substring(imei,7,1)='" + p.getSnTypeCode() + "'";
+                        break;
+                    //(8-9位)=电量
+                    case 6:
+                        condition = "and substring(imei,8,2)='" + p.getSnTypeCode() + "'";
+                        break;
+                    //(10位)=产品扩展代码
+                    case 7:
+                        condition = "and substring(imei,10,1)='" + p.getSnTypeCode() + "'";
+                        break;
+                    default:
+                        condition = "";
+                }
+                if (StringUtils.isNotBlank(condition)) {
+                    sql = sql.concat(condition);
+                }
 
-//        // 针对产品规格这一项进行操作
-//        if(product.getSnType().equals("产品规格")){
-//            String checkSnTypeCodeResult = VerifyUtil.checkSnTypeCode(product);
-//            if(!(checkSnTypeCodeResult.equals("passed"))){
-//                return ApiDTO.error(500,checkSnTypeCodeResult);
-//            }
-//            List<Product> productSpecificationResults = ResolveUtil.resolveProductSpecification(product);
-//            List<List<Product>> checkDuplicatedResults = new ArrayList<>();
-//
-//            for(Product productSpecificationResult:productSpecificationResults) {
-//                List<Product> checkDuplicatedResult = productService.findAll(
-//                        Arrays.asList(QueryParamExp.eq("snTypeCode", productSpecificationResult.getSnTypeCode()),
-//                                QueryParamExp.eq("snType", productSpecificationResult.getSnType())));
-//
-//                checkDuplicatedResults.add(checkDuplicatedResult);
-//
-//                String checkSnTypeCodeResultForEach = VerifyUtil.checkSnTypeCode(productSpecificationResult);
-//                if((checkSnTypeCodeResultForEach.equals("passed"))&(checkDuplicatedResult.isEmpty())){
-//                        productService.save(productSpecificationResult);
-//                    }
-//                else if(!(checkSnTypeCodeResultForEach.equals("passed"))){
-//                    return ApiDTO.error(500,checkSnTypeCodeResultForEach);
-//                }
-//            }
-//            if((!(checkDuplicatedResults.get(0).isEmpty()))&(!(checkDuplicatedResults.get(1).isEmpty()))&(!(checkDuplicatedResults.get(2).isEmpty()))){
-//                return ApiDTO.error(500,"该产品规格对应的三个规则行已存在,未进行任何保存",checkDuplicatedResults);
-//            }
-//            return ApiDTO.ok("保存成功,未保存的规则行id为null",productSpecificationResults);
-//        }
-
+                if (!p.getSnTypeCode().equals(product.getSnTypeCode())) {
+                    List<Map<String, Object>> mapList = appDeviceService.getListBySQL(sql, new HashMap<>());
+                    if (mapList.size() > 0) {
+                        return ApiDTO.error(500, "代码 " + p.getSnTypeCode() + " 已经被使用,不允许修改");
+                    }
+                }
+            }
+        }
         // 校验输入的SN类型对应的编号
         String checkSnTypeCodeResult = VerifyUtil.checkSnTypeCode(product);
         List<Product> checkDuplicatedResult = productService.findAll(
                 Arrays.asList(QueryParamExp.eq("snTypeCode", product.getSnTypeCode()),
                         QueryParamExp.eq("snType", product.getSnType())));
         if (!checkDuplicatedResult.isEmpty()) {
-            return ApiDTO.error(500, "该规则行已存在", checkDuplicatedResult);
+            if (product.getId() != null) {
+                List<Product> collect = checkDuplicatedResult.stream()
+                        .filter(o -> !o.getId().equals(product.getId()))
+                        .collect(Collectors.toList());
+                if (!collect.isEmpty()) {
+                    return ApiDTO.error(500, "该规则行已存在", checkDuplicatedResult);
+                }
+            } else {
+                return ApiDTO.error(500, "该规则行已存在", checkDuplicatedResult);
+            }
         }
         if (checkSnTypeCodeResult.equals("passed")) {
             Product tmp = productService.save(product);

+ 18 - 10
src/main/java/cn/fastfun/service/impl/AppDeviceLogServiceImpl.java

@@ -136,11 +136,20 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
             checkVoltageResult = false;
             checkDataConnectResult = false;
         } else {
-//            if (!StringUtils.isEmpty(bmsData.get("locked_state")) && bmsData.get("locked_state").equals(0)) { //如果该值为null, 则放过
-//                checkLockResult = false;
-//            }
-            if (!StringUtils.isEmpty(bmsData.get("error_code")) && !bmsData.get("error_code").equals(0)) {
-                checkFaultResult = false;
+            if (StringUtils.isEmpty(bmsData.get("locked_state"))) {
+                checkFaultResult = true;
+            } else {
+                //锁定 0=解锁,1=锁定
+                if (bmsData.get("locked_state").equals(0)) {
+                    checkFaultResult = true;
+                }
+            }
+            if (StringUtils.isEmpty(bmsData.get("error_code"))) {
+                checkFaultResult = true;
+            } else {
+                if (bmsData.get("error_code").equals(0)) {
+                    checkFaultResult = true;
+                }
             }
             List<Double> voltage = ObjectUtil.StringToArrayList((String) bmsData.get("cell_voltages"), ",");
             if (!StringUtils.isEmpty(bmsData.get("cell_voltages")) && (Collections.max(voltage) > 4.5 || Collections.min(voltage) < 2.5)) {
@@ -157,7 +166,8 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
             }
             new Timestamp(System.currentTimeMillis());
         }
-        if (StringUtils.isEmpty(gpsData.get("devcode"))) {
+        if (!StringUtils.isEmpty(gpsData.get("devcode"))
+                && Double.parseDouble(String.valueOf(gpsData.get("devcode"))) <= 0) {
             checkLocationResult = false;
         }
 
@@ -225,8 +235,7 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
                     appDeviceLog.setOperator(utilService.getUserName());
                     appDeviceLog.setOutCustomId(param.getCustomId());
                     save(appDeviceLog); // 记录划拨日志
-                }
-                else{
+                } else {
                     throw new ApiRuntimeException(p + "不是入库状态或自检未通过,不能调拨!");
                 }
             });
@@ -307,8 +316,7 @@ public class AppDeviceLogServiceImpl extends JpaServiceImp<AppDeviceLog, String>
                     AppDeviceLog appDeviceLog = new AppDeviceLog(p, appDevice.getImei()).outStorage(param, time, batchNum, finalOperateID);
                     appDeviceLog.setOperator(utilService.getUserName());
                     save(appDeviceLog); // 记录出库日志
-                }
-                else{
+                } else {
                     throw new ApiRuntimeException(p + "不是调拨状态,不能出库!");
                 }
             });

+ 1 - 1
src/main/java/cn/fastfun/service/impl/PackModelServiceImpl.java

@@ -242,7 +242,7 @@ public class PackModelServiceImpl extends JpaServiceImp<PackModel, String> imple
         Query q = this.getQueryBySQL(builder.toString(), new HashMap<>());
         long amount = ((BigInteger) q.getSingleResult()).longValue();
         if (amount <= 0) {
-            return "包型号-电芯厂家编码错误";
+            return "包型号-PACK制造商编码错误";
         }
         if(!(Pattern.matches("[0-9]{3}",model.substring(2,5)))) {
             return "包型号编号不符合规则,串联数,必须为0-9数字";

+ 46 - 10
src/main/java/cn/fastfun/util/VerifyUtil.java

@@ -18,9 +18,15 @@ public class VerifyUtil {
                 if(sntypecode.length() != 1) {
                     return "产品类型的编号长度必须为1";
                 }
-                if(!(Pattern.matches("[MCPS]+",sntypecode))){
-                    return "产品类型的编号不符合规则,必须是M,C,P的一种";
+                if(!(Pattern.matches("[A-Z]{1}",sntypecode))) {
+                    return "产品类型代码不符合规则,必须为一位大写字母";
+                }
+                if(!(Pattern.matches("[^IO]{1}",sntypecode))) {
+                    return "产品类型代码不符合规则,不能包含I或者O";
                 }
+/*                if(!(Pattern.matches("[MCPS]+",sntypecode))){
+                    return "产品类型的编号不符合规则,必须是M,C,P的一种";
+                }*/
                 break;
             case "PACK制造商":
                 if(sntypecode.length() != 2) {
@@ -61,17 +67,29 @@ public class VerifyUtil {
                 if(sntypecode.length() != 1) {
                     return "电池平台的编号长度必须为1";
                 }
-                if(!(Pattern.matches("[0-9]+",sntypecode))) {
-                    return "电池平台的编号不符合规则,必须是数字";
+                if(!(Pattern.matches("[0-9|A-Z]",sntypecode))) {
+                    return "电池平台的编号不符合规则,必须为一位数字或者大写字母";
                 }
+                if(!(Pattern.matches("[^IO]{1}",sntypecode))) {
+                    return "电池平台的编号不符合规则,不能包含I或者O";
+                }
+                /*if(!(Pattern.matches("[0-9]+",sntypecode))) {
+                    return "电池平台的编号不符合规则,必须是数字";
+                }*/
                 break;
             case "容量":
                 if(sntypecode.length() != 2) {
                     return "容量的编号长度必须为2";
                 }
-                if(!(Pattern.matches("[0-9]{2}",sntypecode))) {
-                    return "容量的编号不符合规则,必须是数字";
+                if(!(Pattern.matches("[0-9|A-Z]{2}",sntypecode))) {
+                    return "容量的编号不符合规则,必须为两位数字或者大写字母";
                 }
+                if(!(Pattern.matches("[^IO]{2}",sntypecode))) {
+                    return "容量的编号不符合规则,不能包含I或者O";
+                }
+                /*if(!(Pattern.matches("[0-9]{2}",sntypecode))) {
+                    return "容量的编号不符合规则,必须是数字";
+                }*/
                 break;
             case "产品扩展":
                 if(sntypecode.length() != 1) {
@@ -123,8 +141,14 @@ public class VerifyUtil {
 
         Map<String,String> splitSnResult = ResolveUtil.splitImei(imei);
 
-        if(!(Pattern.matches("[MCPS]",splitSnResult.get("产品类型代码")))){
+/*        if(!(Pattern.matches("[MCPS]",splitSnResult.get("产品类型代码")))){
             return "产品类型的编号不符合规则,必须是M,C,P的一种";
+        }*/
+        if(!(Pattern.matches("[A-Z]{1}",splitSnResult.get("产品类型代码")))) {
+            return "产品类型代码不符合规则,必须为一位大写字母";
+        }
+        if(!(Pattern.matches("[^IO]{1}",splitSnResult.get("产品类型代码")))) {
+            return "产品类型代码不符合规则,不能包含I或者O";
         }
         if(!(Pattern.matches("[A-Z]{2}",splitSnResult.get("pack制造商代码")))) {
             return "PACK制造商的编号不符合规则,必须为两位大写字母";
@@ -141,12 +165,24 @@ public class VerifyUtil {
         if(!(Pattern.matches("[L|N]",splitSnResult.get("化学体系代码")))) {
             return "化学体系的编号不符合规则,必须是L,N的一种";
         }
-        if(!(Pattern.matches("[0-9]",splitSnResult.get("电池平台代码")))) {
+        if(!(Pattern.matches("[0-9|A-Z]",splitSnResult.get("电池平台代码")))) {
+            return "电池平台的编号不符合规则,必须为一位数字或者大写字母";
+        }
+        if(!(Pattern.matches("[^IO]{1}",splitSnResult.get("电池平台代码")))) {
+            return "电池平台的编号不符合规则,不能包含I或者O";
+        }
+        /*if(!(Pattern.matches("[0-9]",splitSnResult.get("电池平台代码")))) {
             return "电池平台的编号不符合规则,必须是数字";
+        }*/
+        if(!(Pattern.matches("[0-9|A-Z]{2}",splitSnResult.get("容量代码")))) {
+            return "容量的编号不符合规则,必须为两位数字或者大写字母";
         }
-        if(!(Pattern.matches("[0-9]{2}",splitSnResult.get("容量代码")))) {
-            return "容量的编号不符合规则,必须是数字";
+        if(!(Pattern.matches("[^IO]{2}",splitSnResult.get("容量代码")))) {
+            return "容量的编号不符合规则,不能包含I或者O";
         }
+        /*if(!(Pattern.matches("[0-9]{2}",splitSnResult.get("容量代码")))) {
+            return "容量的编号不符合规则,必须是数字";
+        }*/
         if(!(Pattern.matches("[NMS]",splitSnResult.get("产品扩展代码")))) {
             return "产品扩展的编号不符合规则,必须是N,M,S的一种";
         }