增加修改放一接口
This commit is contained in:
parent
7a50fdb1cf
commit
8c0b313b0b
@ -34,7 +34,13 @@ public class DeviceController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public boolean create(@RequestBody Device device) {
|
public boolean create(@RequestBody Device device) {
|
||||||
device.setModifier(currentUsername());
|
device.setModifier(currentUsername());
|
||||||
return deviceService.save(device);
|
return deviceService.createDevice(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/saveOrUpdate")
|
||||||
|
public boolean saveOrUpdate(@RequestBody Device device) {
|
||||||
|
device.setModifier(currentUsername());
|
||||||
|
return deviceService.saveOrUpdateByBusiness(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -9,5 +9,7 @@ public interface DeviceService extends IService<Device> {
|
|||||||
*/
|
*/
|
||||||
boolean importDevices(MultipartFile file, String deviceType);
|
boolean importDevices(MultipartFile file, String deviceType);
|
||||||
|
|
||||||
public boolean createDevice(Device device) ;
|
boolean createDevice(Device device) ;
|
||||||
|
|
||||||
|
boolean saveOrUpdateByBusiness(Device device);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,6 +68,28 @@ public class DeviceServiceImpl
|
|||||||
return this.save(device);
|
return this.save(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean saveOrUpdateByBusiness(Device device) {
|
||||||
|
|
||||||
|
String deviceId = device.getDeviceId();
|
||||||
|
|
||||||
|
// 情况 1:未传 deviceId → 直接新增
|
||||||
|
if (StrUtil.isBlank(deviceId)) {
|
||||||
|
return this.save(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 情况 2:传了 deviceId,判断是否存在
|
||||||
|
Device dbDevice = this.getById(deviceId);
|
||||||
|
|
||||||
|
if (dbDevice == null) {
|
||||||
|
// 数据库不存在 → 新增(使用传入的 deviceId)
|
||||||
|
return this.save(device);
|
||||||
|
} else {
|
||||||
|
// 数据库存在 → 更新
|
||||||
|
return this.updateById(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean importExcel(Workbook workbook, String deviceType) {
|
private boolean importExcel(Workbook workbook, String deviceType) {
|
||||||
try (Workbook wb = workbook) {
|
try (Workbook wb = workbook) {
|
||||||
Sheet sheet = wb.getSheetAt(0);
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user