zyg před 2 roky
rodič
revize
5ee70f082c

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

@@ -82,32 +82,39 @@ public class ApiAppDeviceController {
             return ApiDTO.error(500, "该sn已经被录入", checkDuplicatedResultOnSn);
         }
         // 检查该sn号是否产生过数据
-        Map<String,Object> bmsData = new HashMap<>();
-        Map<String,Object> gpsData = new HashMap<>();
-        try{
-            bmsData = jdbcTemplate.queryForMap("select devcode from ff_battery_status where devcode='"+param.getSn()+"'");
-        }catch (EmptyResultDataAccessException e) {
-            bmsData.put("devcode",null);
+        Map<String, Object> bmsData = new HashMap<>();
+        Map<String, Object> gpsData = new HashMap<>();
+        try {
+            bmsData = jdbcTemplate.queryForMap("select devcode from ff_battery_status where devcode='" + param.getSn() + "'");
+        } catch (EmptyResultDataAccessException e) {
+            bmsData.put("devcode", null);
         }
-        try{
-            gpsData = jdbcTemplate.queryForMap("select devcode from ff_location where devcode='"+param.getSn()+"'");
-        }catch (EmptyResultDataAccessException e) {
-            gpsData.put("devcode",null);
+        try {
+            gpsData = jdbcTemplate.queryForMap("select devcode from ff_location where devcode='" + param.getSn() + "'");
+        } catch (EmptyResultDataAccessException e) {
+            gpsData.put("devcode", null);
         }
         //pack和cell 校验
-        if (!org.apache.commons.lang3.StringUtils.isNotBlank(param.getCellModel())){
+        if (!org.apache.commons.lang3.StringUtils.isNotBlank(param.getPackModel())) {
+            throw new ApiRuntimeException("包型号缺失");
+        }
+        if (!org.apache.commons.lang3.StringUtils.isNotBlank(param.getCellModel())) {
             throw new ApiRuntimeException("单体型号缺失");
         }
-        if (!org.apache.commons.lang3.StringUtils.isNotBlank(param.getPackModel())){
-            throw new ApiRuntimeException("包型号缺失");
+
+        if (!param.getImei().substring(3, 5).equals(param.getPackModel().substring(0, 2))) {
+            throw new ApiRuntimeException("包型号与imei对应关系错误");
+        }
+        if (!param.getImei().substring(3, 6).equals(param.getCellModel().substring(0, 3))) {
+            throw new ApiRuntimeException("单体型号与imei对应关系错误");
         }
         PackModel packModel = packModelService.getOne(Arrays.asList(QueryParamExp.eq("cellModel", param.getCellModel()),
                 QueryParamExp.eq("packModel", param.getPackModel())));
-        if (packModel==null){
+        if (packModel == null) {
             throw new ApiRuntimeException("包型号和单体型号配置错误");
         }
 
-        if(StringUtils.isEmpty(bmsData.get("devcode")) && StringUtils.isEmpty(gpsData.get("devcode"))){
+        if (StringUtils.isEmpty(bmsData.get("devcode")) && StringUtils.isEmpty(gpsData.get("devcode"))) {
             return ApiDTO.error(500, "该电池未产生过数据,禁止录入");
         }
         if (checkSnResult.equals("passed")) {
@@ -136,7 +143,7 @@ public class ApiAppDeviceController {
     @RequestMapping(value = "selfCheck", method = RequestMethod.POST)
     public ApiDTO selfCheck(@RequestBody BenchQueryDetailParam param) {
         AppDevice appDevice = appDeviceService.getOne(QueryParamExp.eq("sn", param.getSn()));
-        if (!(appDevice.getCheckStatus().equals(1))){
+        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"))); //自检
@@ -185,6 +192,7 @@ public class ApiAppDeviceController {
         dto.setHandle(handle);
         return ApiDTO.ok(dto);
     }
+
     @ApiOperation(value = "设备录入 搜索 & 重置")
     @RequestMapping(value = "pageQuery", method = RequestMethod.POST)
     public ApiPageDTO batchNumPageQuery(@RequestBody DeviceBatchQueryParam param) {