Commit 7c7bbaf1 by HlQ

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

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