Commit 7c7bbaf1 by HlQ

[fix] 设备批量录入和流转的逻辑修改

1 parent e9d97a35
......@@ -40,13 +40,13 @@ public class DeviceController {
return deviceService.update(dtoList);
}
@PostMapping("/single")
@SaCheckPermission(value = "device:circulate", orRole = "admin")
public String circulate(@RequestBody DeviceDTO dto) {
return deviceService.circulate(dto);
@PostMapping("/record")
@SaCheckPermission(value = "device:record", orRole = "admin")
public String circulate(@RequestBody List<DeviceDTO> dtoList) {
return deviceService.recordDevice(dtoList);
}
@PostMapping("/batch")
@PostMapping("/circulate")
@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 circulate(DeviceDTO dto);
String recordDevice(List<DeviceDTO> dtoList);
String circulateBatch(List<DeviceDTO> dtoList);
}
......@@ -7,7 +7,6 @@ import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vion.dto.DeviceDTO;
......@@ -20,6 +19,7 @@ import vion.service.IDeviceService;
import vion.vo.DeviceVO;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author HlQ
......@@ -75,28 +75,44 @@ public class IDeviceServiceImpl extends MPJBaseServiceImpl<DeviceMapper, Device>
}
@Override
public String circulate(DeviceDTO dto) {
// 只有出库才允许单个设备录入
if (ObjUtil.notEquals(dto.getStatus(), 2)) {
return "该设备状态限制,不支持录入";
@Transactional(rollbackFor = Exception.class)
public String recordDevice(List<DeviceDTO> dtoList) {
if (CollUtil.isEmpty(dtoList)) {
return "设备为空";
}
var statusSet = dtoList.stream().map(DeviceDTO::getStatus).collect(Collectors.toSet());
if (statusSet.size() > 1 || !statusSet.contains(1)) {
return "该操作仅支持设备入库";
}
var device = converter.convert(dto, Device.class);
if (this.updateById(device)) {
var userId = dtoList.getFirst().getUserId();
var deviceList = converter.convert(dtoList, Device.class);
if (this.saveBatch(deviceList)) {
var logList = deviceList.stream()
.map(d -> {
var deviceLog = new DeviceLog();
deviceLog.setDeviceId(device.getId());
deviceLog.setOperator(dto.getUserId());
deviceLog.setContent(getStatusStr(dto.getStatus()));
deviceLogService.save(deviceLog);
return "出库成功";
deviceLog.setDeviceId(d.getId());
deviceLog.setOperator(userId);
deviceLog.setContent(getStatusStr(d.getStatus()));
return deviceLog;
}).toList();
deviceLogService.saveBatch(logList);
return "保存成功";
}
return "出库失败";
return "保存失败";
}
@Override
@Transactional(rollbackFor = Exception.class)
public String circulateBatch(List<DeviceDTO> dtoList) {
if (CollUtil.isEmpty(dtoList)) {
return "录入设备为空";
return "设备为空";
}
var statusSet = dtoList.stream().map(DeviceDTO::getStatus).collect(Collectors.toSet());
if (statusSet.size() > 1) {
return "该操作不允许对设备进行不同处理";
}
if (statusSet.contains(1)) {
return "该操作不支持入库操作";
}
var userId = dtoList.getFirst().getUserId();
var deviceList = converter.convert(dtoList, Device.class);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!