Pārlūkot izejas kodu

包型号和单体型号

zyg 2 gadi atpakaļ
vecāks
revīzija
4716d564e1

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

@@ -2,16 +2,15 @@ package cn.fastfun.controller.api;
 
 import cn.fastfun.controller.dto.DevicePageStatDTO;
 import cn.fastfun.controller.param.*;
-import cn.fastfun.service.AppDeviceLogService;
-import cn.fastfun.service.AppDeviceService;
-import cn.fastfun.service.SysExcelFieldService;
-import cn.fastfun.service.UtilService;
+import cn.fastfun.service.*;
 import cn.fastfun.service.entity.AppDevice;
 import cn.fastfun.service.entity.AppDeviceLog;
+import cn.fastfun.service.entity.PackModel;
 import cn.fastfun.util.DateUtils;
 import cn.fastfun.util.ObjectUtil;
 import cn.fastfun.util.VerifyUtil;
 import com.bridge.dto.*;
+import com.bridge.exception.ApiRuntimeException;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -30,6 +29,7 @@ import javax.persistence.criteria.CriteriaBuilder;
 import javax.servlet.http.HttpServletResponse;
 import java.math.BigInteger;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -58,12 +58,15 @@ public class ApiAppDeviceController {
     @Resource
     JdbcTemplate jdbcTemplate;
 
+    @Resource
+    PackModelService packModelService;
+
     /**
      * 数据保存
      */
 
     @ApiOperation(value = "新增电池")
-    @RequestMapping(value = "save", method = RequestMethod.POST)
+    @PostMapping("save")
     public ApiDTO save(@RequestBody @ApiParam(name = "设备信息对象", value = "传入json格式", required = true) DeviceFormParam param) {
         // 此处定义的sn实际上是指的表中的imei,也就是实体类的属性imei
         String checkSnResult = VerifyUtil.checkImei(param.getImei());
@@ -91,6 +94,18 @@ public class ApiAppDeviceController {
         }catch (EmptyResultDataAccessException e) {
             gpsData.put("devcode",null);
         }
+        //pack和cell 校验
+        if (!org.apache.commons.lang3.StringUtils.isNotBlank(param.getCellModel())){
+            throw new ApiRuntimeException("单体型号缺失");
+        }
+        if (!org.apache.commons.lang3.StringUtils.isNotBlank(param.getPackModel())){
+            throw new ApiRuntimeException("包型号缺失");
+        }
+        PackModel packModel = packModelService.getOne(Arrays.asList(QueryParamExp.eq("cellModel", param.getCellModel()),
+                QueryParamExp.eq("packModel", param.getPackModel())));
+        if (packModel==null){
+            throw new ApiRuntimeException("包型号和单体型号配置错误");
+        }
 
         if(StringUtils.isEmpty(bmsData.get("devcode")) && StringUtils.isEmpty(gpsData.get("devcode"))){
             return ApiDTO.error(500, "该电池未产生过数据,禁止录入");
@@ -108,6 +123,8 @@ public class ApiAppDeviceController {
             AppDevice entity = new AppDevice().fromFormParam(param);// 实体
             entity.setOperateID(operateID.intValue());
             entity.setOperator(utilService.getUserName());
+            entity.setPackModel(param.getPackModel());
+            entity.setCellModel(param.getCellModel());
             appDeviceService.save(entity);
             return ApiDTO.ok("保存成功");
         } else {

+ 5 - 0
src/main/java/cn/fastfun/controller/param/DeviceFormParam.java

@@ -27,6 +27,11 @@ public class DeviceFormParam {
     @ApiModelProperty(value = "收货地", name = "receivedPlace", required = true, example = "")
     private String receivedPlace;
 
+    @ApiModelProperty(value = "包型号", name = "packModel", required = true, example = "")
+    private String packModel;
+
+    @ApiModelProperty(value = "单体型号", name = "cellModel", required = true, example = "")
+    private String cellModel;
 
     @ApiModelProperty(value = "发货时间", name = "deliverTime", required = true)
     @DateTimeFormat(pattern = "yyyy-MM-dd ")

+ 4 - 0
src/main/java/cn/fastfun/service/entity/AppDevice.java

@@ -177,6 +177,8 @@ public class AppDevice extends DateEntity {
         setImei(ObjectUtil.obj2String(param.get("imei")));
         setDeliverTime(ObjectUtil.obj2Date(param.get("deliverTime")));
         setReceivedPlace(ObjectUtil.obj2String(param.get("receivedPlace")));
+        setPackModel(ObjectUtil.obj2String(param.get("packModel")));
+        setCellModel(ObjectUtil.obj2String(param.get("cellModel")));
         setCheckStatus(0);
         setStatus(0);
     }
@@ -230,6 +232,8 @@ public class AppDevice extends DateEntity {
         setReceivedPlace(param.getReceivedPlace());
         setStatus(0);
         setCheckStatus(0);
+        setPackModel(param.getPackModel());
+        setCellModel(param.getCellModel());
         return this;
     }
 

+ 20 - 4
src/main/java/cn/fastfun/service/impl/AppDeviceServiceImp.java

@@ -1,11 +1,9 @@
 package cn.fastfun.service.impl;
 
 import cn.fastfun.controller.dto.DeviceAttrDTO;
-import cn.fastfun.service.AppDeviceLogService;
-import cn.fastfun.service.AppDeviceService;
-import cn.fastfun.service.ProductService;
-import cn.fastfun.service.UtilService;
+import cn.fastfun.service.*;
 import cn.fastfun.service.entity.AppDevice;
+import cn.fastfun.service.entity.PackModel;
 import cn.fastfun.service.entity.Product;
 import cn.fastfun.service.repository.AppDeviceRepository;
 
@@ -47,6 +45,11 @@ public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implem
     @Resource
     UtilService utilService;
 
+    @Resource
+    PackModelService packModelService;
+    @Resource
+    CellModelService cellModelService;
+
     @Override
     public void importDevice(List<Map<String, Object>> list) {
         List<AppDevice> devices = new ArrayList<>();
@@ -79,6 +82,19 @@ public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implem
             if (!temp.getReceivedPlace().equals(diffAttrDTO.getReceivedPlace()))
                 throw new ApiRuntimeException("存在不同的收货地");
 
+            //pack和cell 校验
+            if (!org.apache.commons.lang3.StringUtils.isNotBlank(device.getCellModel())){
+                throw new ApiRuntimeException("单体型号缺失");
+            }
+            if (!org.apache.commons.lang3.StringUtils.isNotBlank(device.getPackModel())){
+                throw new ApiRuntimeException("包型号缺失");
+            }
+            PackModel packModel = packModelService.getOne(Arrays.asList(QueryParamExp.eq("cellModel", device.getCellModel()),
+                    QueryParamExp.eq("packModel", device.getPackModel())));
+            if (packModel==null){
+                throw new ApiRuntimeException("包型号和单体型号配置错误");
+            }
+
             // 重复导入检查
             List<AppDevice> checkDuplicatedResultOnImei = appDeviceService.findAll(
                     QueryParamExp.eq("imei", device.getImei()));

+ 6 - 7
src/main/resources/application-dev.yml

@@ -3,18 +3,17 @@ server:
 spring:
   datasource:
     oss:
-      url: jdbc:mysql://47.111.243.220:9306/pdms_oss?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&tinyInt1isBit=false
+      url: jdbc:mysql://192.168.0.40:3306/pdms_oss?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&tinyInt1isBit=false
       username: root
       password: Qx123456
     runtime:
-      url: jdbc:mysql://172.16.121.236:3306/fastfun?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
-      username: readonly
-      password: Fast1234
+      url: jdbc:mysql://192.168.0.40:3306/fastfun?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+      username: root
+      password: Qx123456
       driverClassName: com.mysql.cj.jdbc.Driver
   redis:
-    host: 47.111.243.220
-
-    port: 9379
+    host: 192.168.0.41
+    port: 6379
   jpa:
     database: mysql
     hibernate: