feat(device): 修改设备服务代理商编码功能支持批量操作
- 将 ChangeServiceAgentCodeQuery 中的 deviceId 字段改为 deviceIds 列表 - 添加 List 类型和 NotEmpty 注解支持批量设备ID验证 - 更新 Controller 层逻辑以支持批量处理设备代理商编码变更 - 添加设备存在性检查避免无效操作 - 仅对代理商编码不同的设备执行更新操作 - 批量为每个符合条件的设备创建代理商变更记录
This commit is contained in:
parent
8ba7ca24b1
commit
3f063a29cd
|
|
@ -785,25 +785,35 @@ public class DeviceController extends ControllerBase {
|
|||
@Transactional
|
||||
@PostMapping("changeServiceAgentCode")
|
||||
public ApiResult<Void> changeServiceAgentCode(@RequestBody ChangeServiceAgentCodeQuery query) {
|
||||
List<Device> devices = deviceService.lambdaQuery()
|
||||
.in(Device::getId, query.getDeviceIds())
|
||||
.list();
|
||||
if (CollectionUtil.isEmpty(devices)){
|
||||
return ApiResult.error("没有需要修改的设备");
|
||||
}
|
||||
TBaseCustomer customer = customerService.lambdaQuery()
|
||||
.eq(TBaseCustomer::getDelIs, 0)
|
||||
.eq(TBaseCustomer::getEnableState, 1)
|
||||
.eq(TBaseCustomer::getAgencyCompanyCode, query.getServiceAgentCode())
|
||||
.one();
|
||||
VUtils.trueThrowBusinessError(Objects.isNull(customer)).throwMessage("代理商公司不存在");
|
||||
deviceService.lambdaUpdate()
|
||||
.set(Device::getServiceAgentCode, query.getServiceAgentCode())
|
||||
.set(Device::getServiceAgentName, customer.getAgencyCompanyName())
|
||||
.eq(Device::getId, query.getDeviceId())
|
||||
.update();
|
||||
deviceAgentRecordService.save(new DeviceAgentRecord()
|
||||
.setDeviceId(query.getDeviceId())
|
||||
.setAgentCode(query.getServiceAgentCode())
|
||||
.setAgentName(customer.getAgencyCompanyName())
|
||||
.setCreateById(AdminUserUtil.getUserId())
|
||||
.setCreateBy(AdminUserUtil.getUserName())
|
||||
.setCreateTime(LocalDateTime.now())
|
||||
);
|
||||
devices.forEach(device -> {
|
||||
if (!StrUtil.equals(device.getServiceAgentCode(), query.getServiceAgentCode())){
|
||||
deviceService.lambdaUpdate()
|
||||
.set(Device::getServiceAgentCode, query.getServiceAgentCode())
|
||||
.set(Device::getServiceAgentName, customer.getAgencyCompanyName())
|
||||
.eq(Device::getId, device.getId())
|
||||
.update();
|
||||
deviceAgentRecordService.save(new DeviceAgentRecord()
|
||||
.setDeviceId(device.getId())
|
||||
.setAgentCode(query.getServiceAgentCode())
|
||||
.setAgentName(customer.getAgencyCompanyName())
|
||||
.setCreateById(AdminUserUtil.getUserId())
|
||||
.setCreateBy(AdminUserUtil.getUserName())
|
||||
.setCreateTime(LocalDateTime.now())
|
||||
);
|
||||
}
|
||||
});
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,18 @@ package com.nflg.mobilebroken.admin.pojo.query;
|
|||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ChangeServiceAgentCodeQuery {
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
* 设备ID列表
|
||||
*/
|
||||
@NotNull
|
||||
private Integer deviceId;
|
||||
@NotEmpty
|
||||
private List<Long> deviceIds;
|
||||
|
||||
/**
|
||||
* 服务代理商编码
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.nflg.mobilebroken.gongfu.pojo.query;
|
|||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -10,9 +11,9 @@ import java.util.List;
|
|||
public class ChangeServiceAgentCodeQuery {
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
* 设备ID列表
|
||||
*/
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private List<Long> deviceIds;
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue