Commit e9d97a35 by HlQ

[fix] 设备状态流转问题修改

1 parent 24057cc6
...@@ -41,15 +41,15 @@ public class DeviceController { ...@@ -41,15 +41,15 @@ public class DeviceController {
} }
@PostMapping("/single") @PostMapping("/single")
@SaCheckPermission(value = "device:save", orRole = "admin") @SaCheckPermission(value = "device:circulate", orRole = "admin")
public String save(@RequestBody DeviceDTO dto) { public String circulate(@RequestBody DeviceDTO dto) {
return deviceService.save(dto); return deviceService.circulate(dto);
} }
@PostMapping("/batch") @PostMapping("/batch")
@SaCheckPermission(value = "device:saveBatch", orRole = "admin") @SaCheckPermission(value = "device:circulateBatch", orRole = "admin")
public String saveBatch(@RequestBody List<DeviceDTO> dtoList) { public String circulateBatch(@RequestBody List<DeviceDTO> dtoList) {
return deviceService.saveBatch(dtoList); return deviceService.circulateBatch(dtoList);
} }
} }
...@@ -20,7 +20,7 @@ public interface IDeviceService extends MPJBaseService<Device> { ...@@ -20,7 +20,7 @@ public interface IDeviceService extends MPJBaseService<Device> {
String update(List<DeviceDTO> dtoList); String update(List<DeviceDTO> dtoList);
String save(DeviceDTO dto); String circulate(DeviceDTO dto);
String saveBatch(List<DeviceDTO> dtoList); String circulateBatch(List<DeviceDTO> dtoList);
} }
...@@ -75,45 +75,41 @@ public class IDeviceServiceImpl extends MPJBaseServiceImpl<DeviceMapper, Device> ...@@ -75,45 +75,41 @@ public class IDeviceServiceImpl extends MPJBaseServiceImpl<DeviceMapper, Device>
} }
@Override @Override
public String save(DeviceDTO dto) { public String circulate(DeviceDTO dto) {
// 只有出库才允许单个设备录入 // 只有出库才允许单个设备录入
if (ObjUtil.notEquals(dto.getStatus(), 2)) { if (ObjUtil.notEquals(dto.getStatus(), 2)) {
return "该设备状态限制,不支持录入"; return "该设备状态限制,不支持录入";
} }
var device = converter.convert(dto, Device.class); var device = converter.convert(dto, Device.class);
if (this.save(device)) { if (this.updateById(device)) {
var deviceLog = new DeviceLog(); var deviceLog = new DeviceLog();
deviceLog.setDeviceId(device.getId()); deviceLog.setDeviceId(device.getId());
deviceLog.setOperator(dto.getUserId()); deviceLog.setOperator(dto.getUserId());
deviceLog.setContent(getStatusStr(dto.getStatus())); deviceLog.setContent(getStatusStr(dto.getStatus()));
deviceLogService.save(deviceLog); deviceLogService.save(deviceLog);
return "保存成功"; return "出库成功";
} }
return "保存失败"; return "出库失败";
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public String saveBatch(List<DeviceDTO> dtoList) { public String circulateBatch(List<DeviceDTO> dtoList) {
if (CollUtil.isEmpty(dtoList)) { if (CollUtil.isEmpty(dtoList)) {
return "录入设备为空"; return "录入设备为空";
} }
var userId = dtoList.getFirst().getUserId(); var userId = dtoList.getFirst().getUserId();
var deviceList = converter.convert(dtoList, Device.class); var deviceList = converter.convert(dtoList, Device.class);
if (this.saveBatch(deviceList)) { deviceList.forEach(d -> {
var logList = deviceList.stream() this.lambdaUpdate().eq(Device::getSerialNum, d.getSerialNum()).update(d);
.map(d -> {
var deviceLog = new DeviceLog(); var deviceLog = new DeviceLog();
deviceLog.setDeviceId(d.getId()); deviceLog.setDeviceId(d.getId());
deviceLog.setOperator(userId); deviceLog.setOperator(userId);
deviceLog.setContent(getStatusStr(d.getStatus())); deviceLog.setContent(getStatusStr(d.getStatus()));
return deviceLog; deviceLogService.save(deviceLog);
}).toList(); });
deviceLogService.saveBatch(logList);
return "保存成功"; return "保存成功";
} }
return "保存失败";
}
private String getStatusStr(Integer status) { private String getStatusStr(Integer status) {
return switch (status) { return switch (status) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!