su-lmstack преди 3 години
родител
ревизия
81457aacf1
променени са 1 файла, в които са добавени 22 реда и са изтрити 0 реда
  1. 22 0
      src/main/java/cn/fastfun/controller/api/ApiAppDeviceController.java

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

@@ -17,7 +17,9 @@ import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.springframework.dao.EmptyResultDataAccessException;
 import org.springframework.data.domain.Page;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -52,6 +54,9 @@ public class ApiAppDeviceController {
     @Resource
     SysExcelFieldService sysExcelFieldService;
 
+    @Resource
+    JdbcTemplate jdbcTemplate;
+
     /**
      * 数据保存
      */
@@ -72,6 +77,23 @@ public class ApiAppDeviceController {
         if (!checkDuplicatedResultOnSn.isEmpty()) {
             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);
+        }
+        try{
+            gpsData = jdbcTemplate.queryForMap("select devcode from ff_location where devcode='"+param.getSn()+"'");
+        }catch (EmptyResultDataAccessException e) {
+            gpsData.put("devcode",null);
+        }
+
+        if(StringUtils.isEmpty(bmsData.get("devcode")) && StringUtils.isEmpty(gpsData.get("devcode"))){
+            return ApiDTO.error(500, "该电池未产生过数据,禁止录入");
+        }
         if (checkSnResult.equals("passed")) {
             // 查询当前操作id的最大值
             StringBuffer sql = new StringBuffer();