Commit e9d97a35 by HlQ

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

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