Ver Fonte

自定义设备id模板修改

李进 há 2 anos atrás
pai
commit
296798eaa6

+ 41 - 14
device-api-service/src/main/java/com/xy/service/DeviceCreateIdsServiceImpl.java

@@ -214,11 +214,11 @@ public class DeviceCreateIdsServiceImpl extends ServiceImpl<DeviceCreateIdsMappe
 
     @ApiOperation("批量添加自定义机器号")
     @PostMapping("uploadSaveCustom")
-    public R uploadSaveCustom(@RequestParam("file") MultipartFile file, @RequestParam("deviceType") Integer deviceType, @RequestParam("doorType") String doorType, @RequestParam("createPc") String createPc) {
+    public R uploadSaveCustom(@RequestParam("file") MultipartFile file) {
         ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_COMMON_POLL, 1)
                 .execute(() -> {
                     try {
-                        EasyExcel.read(file.getInputStream(), UploadSaveCustom.class, new UploadSaveCustomListener(deviceType, doorType, createPc, AuthorizeUtils.getLoginId(Long.class), this)).sheet().doRead();
+                        EasyExcel.read(file.getInputStream(), UploadSaveCustom.class, new UploadSaveCustomListener(AuthorizeUtils.getLoginId(Long.class), this)).sheet().doRead();
                     } catch (IOException e) {
                         log.error("", e);
                     }
@@ -245,12 +245,6 @@ public class DeviceCreateIdsServiceImpl extends ServiceImpl<DeviceCreateIdsMappe
     @RequiredArgsConstructor
     public static class UploadSaveCustomListener implements ReadListener<UploadSaveCustom> {
 
-        private final Integer deviceType;
-
-        private final String doorType;
-
-        private final String createPc;
-
         private final Long loginId;
 
         private final DeviceCreateIdsServiceImpl deviceCreateIdsService;
@@ -265,6 +259,23 @@ public class DeviceCreateIdsServiceImpl extends ServiceImpl<DeviceCreateIdsMappe
          */
         @Override
         public void invoke(UploadSaveCustom data, AnalysisContext context) {
+            String deviceType = data.getDeviceType();
+            if (deviceType == null) {
+                return;
+            }
+            Integer deviceTypeValue = deviceType.equals("动态视觉柜(单门)") ? 1
+                    : deviceType.equals("动态视觉柜(双门)") ? 2
+                    : deviceType.equals("重力柜(单门)") ? 3
+                    : deviceType.equals("重力柜(双门)") ? 4
+                    : deviceType.equals("支付宝视动态觉柜") ? 5
+                    : null;
+            if (deviceTypeValue == null) {
+                return;
+            }
+            if (!Emptys.check(data.getDevicePc())) {
+                return;
+            }
+            data.setDeviceTypeValue(deviceTypeValue);
             deviceIds.put(data.getDeviceId(), data);
         }
 
@@ -284,14 +295,12 @@ public class DeviceCreateIdsServiceImpl extends ServiceImpl<DeviceCreateIdsMappe
             }
             if (Emptys.check(deviceIds)) {
                 LocalDateTime now = LocalDateTime.now();
-                JList<Long> deviceIds2 = deviceIds.toList().key();
-                List<DeviceCreateIds> saves = new ArrayList<>(deviceIds2.size());
-                deviceIds2.forEach(deviceId -> {
+                List<DeviceCreateIds> saves = new ArrayList<>(deviceIds.size());
+                deviceIds.forEach((deviceId, uploadSaveCustom) -> {
                     DeviceCreateIds deviceCreateIdsInfo = new DeviceCreateIds()
                             .setDeviceId(deviceId)
-                            .setDeviceType(deviceType)
-                            .setDoorType(doorType)
-                            .setCreatePc(createPc)
+                            .setDeviceType(uploadSaveCustom.getDeviceTypeValue())
+                            .setCreatePc(uploadSaveCustom.getDevicePc())
                             .setCreateUserId(loginId)
                             .setIsCustom(true)
                             .setCreateTime(now);
@@ -306,6 +315,24 @@ public class DeviceCreateIdsServiceImpl extends ServiceImpl<DeviceCreateIdsMappe
     @Data
     public static class UploadSaveCustom {
 
+        /**
+         * 设备id
+         */
         private Long deviceId;
+
+        /**
+         * 设备类型
+         */
+        private String deviceType;
+
+        /**
+         * 批次号
+         */
+        private String devicePc;
+
+        /**
+         * 设备类型值
+         */
+        private Integer deviceTypeValue;
     }
 }

BIN
device-start/src/main/resources/id_templet.xlsx