|
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.github.yitter.idgen.YitIdHelper;
|
|
import com.xy.annotation.Lock;
|
|
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;
|
|
@@ -23,6 +24,7 @@ import io.swagger.annotations.ApiOperation;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.Data;
|
|
import lombok.Data;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
+import lombok.SneakyThrows;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
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;
|
|
@@ -32,9 +34,11 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.io.OutputStream;
|
|
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.*;
|
|
@@ -76,7 +80,7 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
@Lock(value = "save.deviceId", prefix = "device_register_")
|
|
@Lock(value = "save.deviceId", prefix = "device_register_")
|
|
public R save(@RequestBody @Validated DeviceRegisterDto.Save save) {
|
|
public R save(@RequestBody @Validated DeviceRegisterDto.Save save) {
|
|
//重复校验
|
|
//重复校验
|
|
- DeviceRegister deviceRegister = copy(DeviceRegister.class, save);
|
|
|
|
|
|
+ DeviceRegister deviceRegister = copy(DeviceRegister.class, save.setDeviceSn(save.getDeviceSn().toUpperCase()));
|
|
DeviceCreateIds deviceCreateIds = deviceCreateIdsMapper.selectById(deviceRegister.getDeviceId());
|
|
DeviceCreateIds deviceCreateIds = deviceCreateIdsMapper.selectById(deviceRegister.getDeviceId());
|
|
if (deviceCreateIds == null) {
|
|
if (deviceCreateIds == null) {
|
|
return R.fail("设备ID不存在");
|
|
return R.fail("设备ID不存在");
|
|
@@ -84,7 +88,7 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
if (deviceCreateIds.getBindState()) {
|
|
if (deviceCreateIds.getBindState()) {
|
|
return R.fail("设备ID已被绑定");
|
|
return R.fail("设备ID已被绑定");
|
|
}
|
|
}
|
|
- long count = count(new LambdaQueryWrapper<DeviceRegister>().eq(DeviceRegister::getDeviceSn, save.getDeviceSn()));
|
|
|
|
|
|
+ long count = count(new LambdaQueryWrapper<DeviceRegister>().eq(DeviceRegister::getDeviceSn, deviceRegister.getDeviceSn()));
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
return R.fail("设备SN已被绑定");
|
|
return R.fail("设备SN已被绑定");
|
|
}
|
|
}
|
|
@@ -147,6 +151,15 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
mqttUserInfo.setDeviceId(deviceRegister.getDeviceId());
|
|
mqttUserInfo.setDeviceId(deviceRegister.getDeviceId());
|
|
mqttUserService.save(mqttUserInfo);
|
|
mqttUserService.save(mqttUserInfo);
|
|
} else {
|
|
} else {
|
|
|
|
+ if (deviceType == 5) {
|
|
|
|
+ //支付宝设备注册
|
|
|
|
+ alipayDeviceService.deviceAssign(new DeviceAssignDTO()
|
|
|
|
+ .setTerminalId(String.valueOf(deviceRegister.getDeviceId()))
|
|
|
|
+ .setDeviceIdentifyType("DYNAMIC")
|
|
|
|
+ .setDeviceSn(deviceRegister.getDeviceSn())
|
|
|
|
+ .setDeviceName(String.valueOf(deviceRegister.getDeviceId()))
|
|
|
|
+ );
|
|
|
|
+ }
|
|
updateById(deviceRegister);
|
|
updateById(deviceRegister);
|
|
deviceSysinfoMapper.updateById(deviceSysinfo);
|
|
deviceSysinfoMapper.updateById(deviceSysinfo);
|
|
mqttUserService.update(new LambdaUpdateWrapper<MqttUser>()
|
|
mqttUserService.update(new LambdaUpdateWrapper<MqttUser>()
|
|
@@ -269,11 +282,11 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
|
|
|
|
@ApiOperation("上传sn注册设备")
|
|
@ApiOperation("上传sn注册设备")
|
|
@PostMapping("uploadSaveBySn")
|
|
@PostMapping("uploadSaveBySn")
|
|
- public R uploadSaveBySn(@RequestParam("file") MultipartFile file, @RequestParam("deviceType") Integer deviceType, @RequestParam("devicePc") String devicePc, @RequestParam("assetNo") String assetNo) {
|
|
|
|
|
|
+ public R uploadSaveBySn(@RequestParam("file") MultipartFile file) {
|
|
ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_COMMON_POLL, 1)
|
|
ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_COMMON_POLL, 1)
|
|
.execute(() -> {
|
|
.execute(() -> {
|
|
try {
|
|
try {
|
|
- EasyExcel.read(file.getInputStream(), UploadSaveBySn.class, new UploadSaveBySnListener(deviceCreateIdsService, this, alipayDeviceService, deviceType, devicePc, assetNo)).sheet().doRead();
|
|
|
|
|
|
+ EasyExcel.read(file.getInputStream(), UploadSaveBySn.class, new UploadSaveBySnListener(deviceCreateIdsService, this, alipayDeviceService)).sheet().doRead();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error("", e);
|
|
log.error("", e);
|
|
}
|
|
}
|
|
@@ -281,6 +294,21 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
return R.ok();
|
|
return R.ok();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
|
+ @ApiOperation("下载sn注册设备模板")
|
|
|
|
+ @PostMapping("downloadSnTemplet")
|
|
|
|
+ public void downloadSnTemplet(HttpServletResponse response) {
|
|
|
|
+ InputStream inputStream = IoUtils.inputStream("sn_templet.xlsx").get();
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + "sn_templet.xlsx");
|
|
|
|
+ response.setContentType("application/xlsx");
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
+ int bytesRead;
|
|
|
|
+ OutputStream outputStream = response.getOutputStream();
|
|
|
|
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Slf4j
|
|
@Slf4j
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
public static class UploadSaveBySnListener implements ReadListener<UploadSaveBySn> {
|
|
public static class UploadSaveBySnListener implements ReadListener<UploadSaveBySn> {
|
|
@@ -291,13 +319,7 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
|
|
|
|
private final AlipayDeviceService alipayDeviceService;
|
|
private final AlipayDeviceService alipayDeviceService;
|
|
|
|
|
|
- private final Integer deviceType;
|
|
|
|
-
|
|
|
|
- private final String devicePc;
|
|
|
|
-
|
|
|
|
- private final String assetNo;
|
|
|
|
-
|
|
|
|
- private List<UploadSaveBySn> sns = new ArrayList<>();
|
|
|
|
|
|
+ private JList<UploadSaveBySn> sns = new JArrayList<>();
|
|
|
|
|
|
/**
|
|
/**
|
|
* 这个每一条数据解析都会来调用
|
|
* 这个每一条数据解析都会来调用
|
|
@@ -307,6 +329,23 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public void invoke(UploadSaveBySn data, AnalysisContext context) {
|
|
public void invoke(UploadSaveBySn 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);
|
|
sns.add(data);
|
|
sns.add(data);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -317,50 +356,75 @@ public class DeviceRegisterServiceImpl extends ServiceImpl<DeviceRegisterMapper,
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public void doAfterAllAnalysed(AnalysisContext context) {
|
|
public void doAfterAllAnalysed(AnalysisContext context) {
|
|
- log.info("上传sn注册设备文件解析完毕,总数量:{},批次:{}", sns.size(), devicePc);
|
|
|
|
- //生成设备号
|
|
|
|
- JList<DeviceCreateIds> deviceCreateIds = deviceCreateIdsService.save(new DeviceCreateIdsDto.Save()
|
|
|
|
- .setDeviceType(deviceType)
|
|
|
|
- .setDoorType("1")
|
|
|
|
- .setCreatePc(devicePc)
|
|
|
|
- .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(devicePc)
|
|
|
|
- .setAssetNo(assetNo);
|
|
|
|
- R r = deviceRegisterService.save(save);
|
|
|
|
- if (r.getCode() == R.Enum.FAIL.getCode()) {
|
|
|
|
- log.error("{},{}", sn.getSn(), r.getMsg());
|
|
|
|
- } else {
|
|
|
|
- //初始化支付宝设备
|
|
|
|
- if (deviceType == 5) {
|
|
|
|
- alipayDeviceService.deviceAssign(new DeviceAssignDTO()
|
|
|
|
- .setTerminalId(String.valueOf(deviceId))
|
|
|
|
- .setDeviceIdentifyType("DYNAMIC")
|
|
|
|
- .setDeviceSn(sn.getSn())
|
|
|
|
- .setDeviceName(String.valueOf(deviceId))
|
|
|
|
- );
|
|
|
|
|
|
+ log.info("上传sn注册设备文件解析完毕,总数量:{}", sns.size());
|
|
|
|
+ JMap<Integer, List<UploadSaveBySn>> group = sns.toMap(UploadSaveBySn::getDeviceTypeValue).group();
|
|
|
|
+ group.forEach((deviceTypeValue, uploadSaveBySns) -> {
|
|
|
|
+ ThreadPoolUtils.Execute execute = ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_COMMON_POLL, uploadSaveBySns.size());
|
|
|
|
+ //生成设备号
|
|
|
|
+ JList<DeviceCreateIds> deviceCreateIds = deviceCreateIdsService.save(new DeviceCreateIdsDto.Save()
|
|
|
|
+ .setDeviceType(deviceTypeValue)
|
|
|
|
+ .setDoorType("1")
|
|
|
|
+ .setCreatePc(String.valueOf(YitIdHelper.nextId()))
|
|
|
|
+ .setNum(uploadSaveBySns.size())
|
|
|
|
+ ).getData();
|
|
|
|
+ //注册设备
|
|
|
|
+ for (int i = 0; i < uploadSaveBySns.size(); i++) {
|
|
|
|
+ UploadSaveBySn uploadSaveBySn = uploadSaveBySns.get(i);
|
|
|
|
+ Long deviceId = deviceCreateIds.get(i).getDeviceId();
|
|
|
|
+ execute.execute(() -> {
|
|
|
|
+ DeviceRegisterDto.Save save = new DeviceRegisterDto.Save()
|
|
|
|
+ .setDeviceId(deviceId)
|
|
|
|
+ .setDeviceSn(uploadSaveBySn.getSn())
|
|
|
|
+ .setDevicePc(uploadSaveBySn.getDevicePc())
|
|
|
|
+ .setAssetNo(uploadSaveBySn.getAssetNo());
|
|
|
|
+ R r = deviceRegisterService.save(save);
|
|
|
|
+ if (r.getCode() == R.Enum.FAIL.getCode()) {
|
|
|
|
+ log.error("{},{}", uploadSaveBySn.getSn(), r.getMsg());
|
|
|
|
+ } else {
|
|
|
|
+ //初始化支付宝设备
|
|
|
|
+ if (deviceTypeValue == 5) {
|
|
|
|
+ alipayDeviceService.deviceAssign(new DeviceAssignDTO()
|
|
|
|
+ .setTerminalId(String.valueOf(deviceId))
|
|
|
|
+ .setDeviceIdentifyType("DYNAMIC")
|
|
|
|
+ .setDeviceSn(uploadSaveBySn.getSn())
|
|
|
|
+ .setDeviceName(String.valueOf(deviceId))
|
|
|
|
+ );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- execute.end();
|
|
|
|
- log.info("上传sn注册设备注册完毕,批次:{}", devicePc);
|
|
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ execute.end();
|
|
|
|
+ });
|
|
|
|
+ log.info("上传sn注册设备注册完毕");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@Data
|
|
@Data
|
|
public static class UploadSaveBySn {
|
|
public static class UploadSaveBySn {
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * sn
|
|
|
|
+ */
|
|
private String sn;
|
|
private String sn;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 设备类型
|
|
|
|
+ */
|
|
|
|
+ private String deviceType;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 资产编号
|
|
|
|
+ */
|
|
|
|
+ private String assetNo;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批次号
|
|
|
|
+ */
|
|
|
|
+ private String devicePc;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 设备类型值
|
|
|
|
+ */
|
|
|
|
+ private Integer deviceTypeValue;
|
|
}
|
|
}
|
|
}
|
|
}
|