|
@@ -1,5 +1,8 @@
|
|
package com.xy.service;
|
|
package com.xy.service;
|
|
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
|
+import com.alibaba.excel.read.listener.ReadListener;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
@@ -9,6 +12,8 @@ import com.xy.annotation.Lock;
|
|
import com.xy.collections.list.JArrayList;
|
|
import com.xy.collections.list.JArrayList;
|
|
import com.xy.collections.list.JList;
|
|
import com.xy.collections.list.JList;
|
|
import com.xy.collections.map.JMap;
|
|
import com.xy.collections.map.JMap;
|
|
|
|
+import com.xy.config.DeviceThreadPoolConfig;
|
|
|
|
+import com.xy.dto.DeviceCreateIdsDto;
|
|
import com.xy.dto.DeviceQualityDto;
|
|
import com.xy.dto.DeviceQualityDto;
|
|
import com.xy.dto.DeviceRegisterDto;
|
|
import com.xy.dto.DeviceRegisterDto;
|
|
import com.xy.dto.MqttUserDto;
|
|
import com.xy.dto.MqttUserDto;
|
|
@@ -19,13 +24,21 @@ import com.xy.utils.consts.CommConsts;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
+import lombok.Data;
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
+import lombok.SneakyThrows;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
import static com.xy.utils.PlusBeans.*;
|
|
import static com.xy.utils.PlusBeans.*;
|
|
@@ -245,4 +258,84 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
}
|
|
}
|
|
return R.ok();
|
|
return R.ok();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @ApiOperation("上传sn注册设备")
|
|
|
|
+ @PostMapping("uploadSaveBySn")
|
|
|
|
+ public R uploadSaveBySn(@RequestParam("file") MultipartFile file) {
|
|
|
|
+ ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_COMMON_POLL, 1)
|
|
|
|
+ .execute(() -> {
|
|
|
|
+ try {
|
|
|
|
+ EasyExcel.read(file.getInputStream(), UploadSaveBySn.class, new UploadSaveBySnListener(deviceCreateIdsService, this)).sheet().doRead();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.error("", e);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Slf4j
|
|
|
|
+ @RequiredArgsConstructor
|
|
|
|
+ public static class UploadSaveBySnListener implements ReadListener<UploadSaveBySn> {
|
|
|
|
+
|
|
|
|
+ private final DeviceCreateIdsServiceImpl deviceCreateIdsService;
|
|
|
|
+
|
|
|
|
+ private final DeviceRegisterServiceImpl deviceRegisterService;
|
|
|
|
+
|
|
|
|
+ private List<UploadSaveBySn> sns = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 这个每一条数据解析都会来调用
|
|
|
|
+ *
|
|
|
|
+ * @param data one row value. Is is same as {@link AnalysisContext#readRowHolder()}
|
|
|
|
+ * @param context
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void invoke(UploadSaveBySn data, AnalysisContext context) {
|
|
|
|
+ sns.add(data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 所有数据解析完成了 都会来调用
|
|
|
|
+ *
|
|
|
|
+ * @param context
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
|
+ String pc = DataTime.getSring("yyyyMMddHHmmss");
|
|
|
|
+ log.info("上传sn注册设备文件解析完毕,总数量:{},批次:{}", sns.size(), pc);
|
|
|
|
+ //生成设备号
|
|
|
|
+ JList<DeviceCreateIds> deviceCreateIds = deviceCreateIdsService.save(new DeviceCreateIdsDto.Save()
|
|
|
|
+ .setDeviceType(1)
|
|
|
|
+ .setDoorType("1")
|
|
|
|
+ .setCreatePc(pc)
|
|
|
|
+ .setNum(sns.size())
|
|
|
|
+ ).getData();
|
|
|
|
+ JList<Long> deviceIds = deviceCreateIds.getProperty(DeviceCreateIds::getDeviceId);
|
|
|
|
+ //注册设备
|
|
|
|
+ ThreadPoolUtils.Execute execute = ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_COMMON_POLL, sns.size());
|
|
|
|
+ for (int i = 0; i < sns.size(); i++) {
|
|
|
|
+ UploadSaveBySn sn = sns.get(i);
|
|
|
|
+ Long deviceId = deviceIds.get(i);
|
|
|
|
+ execute.execute(() -> {
|
|
|
|
+ DeviceRegisterDto.Save save = new DeviceRegisterDto.Save()
|
|
|
|
+ .setDeviceId(deviceId)
|
|
|
|
+ .setDeviceSn(sn.getSn())
|
|
|
|
+ .setDevicePc(pc)
|
|
|
|
+ .setAssetNo(pc);
|
|
|
|
+ R r = deviceRegisterService.save(save);
|
|
|
|
+ if (r.getCode() == R.Enum.FAIL.getCode()) {
|
|
|
|
+ log.error("{},{}", sn.getSn(), r.getMsg());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ execute.end();
|
|
|
|
+ log.info("上传sn注册设备注册完毕,批次:{}", pc);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Data
|
|
|
|
+ public static class UploadSaveBySn {
|
|
|
|
+
|
|
|
|
+ private String sn;
|
|
|
|
+ }
|
|
}
|
|
}
|