Explorar o código

批次录入自检

su-lmstack %!s(int64=3) %!d(string=hai) anos
pai
achega
9704388acd

+ 24 - 0
src/main/java/cn/fastfun/service/impl/AppDeviceServiceImp.java

@@ -17,7 +17,10 @@ import com.bridge.dto.QueryParamExp;
 import com.bridge.exception.ApiRuntimeException;
 import com.bridge.service.impl.JpaServiceImp;
 
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
 
@@ -39,6 +42,8 @@ public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implem
     @Resource
     ProductService productService;
 
+    @Resource
+    JdbcTemplate jdbcTemplate;
     @Resource
     UtilService utilService;
 
@@ -47,6 +52,8 @@ public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implem
         List<AppDevice> devices = new ArrayList<>();
         DeviceAttrDTO diffAttrDTO = null;
 
+        Map<String, Object> bmsData = new HashMap<>();
+        Map<String, Object> gpsData = new HashMap<>();
         // 查询当前操作id的最大值
         StringBuffer sql = new StringBuffer();
         sql.append("SELECT COALESCE(MAX(operate_id),0) as max_opid from app_device where operate_id is not null");
@@ -89,6 +96,23 @@ public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implem
                 throw new ApiRuntimeException("imei:" + device.getImei() + "校验未通过:" + checkSnResult);
             }
 
+            // 电池产生数据检查
+
+            try{
+                bmsData = jdbcTemplate.queryForMap("select devcode from ff_battery_status where devcode='"+device.getSn()+"'");
+            }catch (EmptyResultDataAccessException e) {
+                bmsData.put("devcode",null);
+            }
+            try{
+                gpsData = jdbcTemplate.queryForMap("select devcode from ff_location where devcode='"+device.getSn()+"'");
+            }catch (EmptyResultDataAccessException e) {
+                gpsData.put("devcode",null);
+            }
+
+            if(StringUtils.isEmpty(bmsData.get("devcode")) && StringUtils.isEmpty(gpsData.get("devcode"))){
+                throw new ApiRuntimeException("sn:" + device.getSn() + "未产生过数据,批次导入失败");
+            }
+
             // 批量导入时由于没有x-token, 无法确定操作者
 //            device.setOperator(utilService.getUserName());
             devices.add(device);