feat(gongfu): 修改设备批量操作功能

- 将ChangeServiceAgentCodeQuery中的deviceId字段改为deviceIds列表
- 移除Controller中的@Valid注解并优化参数验证逻辑
- 实现设备批量修改代理商编码功能,支持多个设备同时处理
- 修复部署脚本中的文件路径处理逻辑
- 添加空值检查和业务逻辑优化
This commit is contained in:
曹鹏飞 2026-02-02 17:43:57 +08:00
parent 24dcb9df96
commit 8ba7ca24b1
8 changed files with 43 additions and 37 deletions

View File

@ -40,9 +40,9 @@ public class DeployTest {
private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception { private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception {
printInfo("处理目录:" + dirName); printInfo("处理目录:" + dirName);
List<Path> files = getFileList(localPath + "lib"); List<Path> files = getFileList(localPath + dirName);
for (Path file : files) { for (Path file : files) {
handleFile(sshUtil, file.toString(), remotePath + "lib/" + file.getFileName().toString()); handleFile(sshUtil, file.toString(), remotePath +dirName+ "/" + file.getFileName().toString());
} }
printInfo("处理目录完成"); printInfo("处理目录完成");
} }

View File

@ -41,9 +41,9 @@ public class DeployTest {
private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception { private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception {
printInfo("处理目录:" + dirName); printInfo("处理目录:" + dirName);
List<Path> files = getFileList(localPath + "lib"); List<Path> files = getFileList(localPath + dirName);
for (Path file : files) { for (Path file : files) {
handleFile(sshUtil, file.toString(), remotePath + "lib/" + file.getFileName().toString()); handleFile(sshUtil, file.toString(), remotePath + dirName + "/" + file.getFileName().toString());
} }
printInfo("处理目录完成"); printInfo("处理目录完成");
} }

View File

@ -40,9 +40,9 @@ public class DeployTest {
private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception { private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception {
printInfo("处理目录:" + dirName); printInfo("处理目录:" + dirName);
List<Path> files = getFileList(localPath + "lib"); List<Path> files = getFileList(localPath + dirName);
for (Path file : files) { for (Path file : files) {
handleFile(sshUtil, file.toString(), remotePath + "lib/" + file.getFileName().toString()); handleFile(sshUtil, file.toString(), remotePath + dirName+ "/" + file.getFileName().toString());
} }
printInfo("处理目录完成"); printInfo("处理目录完成");
} }

View File

@ -31,6 +31,7 @@ import com.nflg.mobilebroken.repository.service.*;
import com.nflg.mobilebroken.starter.annotation.MethodInfoMark; import com.nflg.mobilebroken.starter.annotation.MethodInfoMark;
import com.nflg.mobilebroken.starter.service.FileUploadService; import com.nflg.mobilebroken.starter.service.FileUploadService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@ -43,8 +44,6 @@ import org.ttzero.excel.entity.Workbook;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -172,7 +171,7 @@ public class DeviceController extends ControllerBase {
@PostMapping("add") @PostMapping("add")
@MethodInfoMark(value = "新增", menuName = "设备管理") @MethodInfoMark(value = "新增", menuName = "设备管理")
@ApiMark(moduleName = "设备管理", apiName = "新增") @ApiMark(moduleName = "设备管理", apiName = "新增")
public ApiResult<Boolean> add(@Valid @RequestBody DeviceDTO deviceDTO) { public ApiResult<Boolean> add(@RequestBody DeviceDTO deviceDTO) {
VUtils.trueThrow(deviceService.lambdaQuery() VUtils.trueThrow(deviceService.lambdaQuery()
.eq(GongfuDevice::getDeviceNo, deviceDTO.getDeviceNo()) .eq(GongfuDevice::getDeviceNo, deviceDTO.getDeviceNo())
.eq(GongfuDevice::getDeviceState, deviceDTO.getDeviceState()) .eq(GongfuDevice::getDeviceState, deviceDTO.getDeviceState())
@ -187,7 +186,7 @@ public class DeviceController extends ControllerBase {
@PostMapping("update") @PostMapping("update")
@MethodInfoMark(value = "编辑", menuName = "设备管理") @MethodInfoMark(value = "编辑", menuName = "设备管理")
@ApiMark(moduleName = "设备管理", apiName = "编辑") @ApiMark(moduleName = "设备管理", apiName = "编辑")
public ApiResult<Boolean> update(@Valid @RequestBody DeviceDTO deviceDTO) { public ApiResult<Boolean> update(@RequestBody DeviceDTO deviceDTO) {
VUtils.trueThrow(deviceDTO.getId() <= 0).throwMessage(STATE.ParamErr, "编辑时ID参数不能<=0"); VUtils.trueThrow(deviceDTO.getId() <= 0).throwMessage(STATE.ParamErr, "编辑时ID参数不能<=0");
adminDeviceService.update(deviceDTO); adminDeviceService.update(deviceDTO);
return ApiResult.success(true); return ApiResult.success(true);
@ -498,7 +497,7 @@ public class DeviceController extends ControllerBase {
*/ */
@PostMapping("exportSelect") @PostMapping("exportSelect")
@ApiMark(moduleName = "设备管理", apiName = "导出选中的设备") @ApiMark(moduleName = "设备管理", apiName = "导出选中的设备")
public void exportSelect(HttpServletResponse response, @Valid @RequestBody @NotEmpty List<Long> ids) throws Exception { public void exportSelect(HttpServletResponse response, @RequestBody @NotEmpty List<Long> ids) throws Exception {
List<GongfuDevice> devices = deviceService.listByIds(ids); List<GongfuDevice> devices = deviceService.listByIds(ids);
List<DictionaryItem> states = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE); List<DictionaryItem> states = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE);
List<DeviceUpdateImportDTO> datas = devices.stream().map(d -> { List<DeviceUpdateImportDTO> datas = devices.stream().map(d -> {
@ -750,7 +749,7 @@ public class DeviceController extends ControllerBase {
* @param request 请求参数 * @param request 请求参数
*/ */
@PostMapping("getQRCode") @PostMapping("getQRCode")
public ApiResult<List<DeviceQRCodeVO>> getQRCode(@Valid @RequestBody IdPostRequest request) { public ApiResult<List<DeviceQRCodeVO>> getQRCode(@RequestBody IdPostRequest request) {
List<GongfuDevice> devices = deviceService.listByIds(request.getIds()); List<GongfuDevice> devices = deviceService.listByIds(request.getIds());
List<DeviceQRCodeVO> vos = new ArrayList<>(); List<DeviceQRCodeVO> vos = new ArrayList<>();
devices.forEach(device -> { devices.forEach(device -> {
@ -772,7 +771,7 @@ public class DeviceController extends ControllerBase {
* @param request 请求参数 * @param request 请求参数
*/ */
@PostMapping("exportImages") @PostMapping("exportImages")
public ResponseEntity<byte[]> exportImages(@Valid @RequestBody IdPostRequest request) { public ResponseEntity<byte[]> exportImages(@RequestBody IdPostRequest request) {
List<GongfuDevice> devices = deviceService.listByIds(request.getIds()); List<GongfuDevice> devices = deviceService.listByIds(request.getIds());
if (CollUtil.isNotEmpty(devices)) { if (CollUtil.isNotEmpty(devices)) {
try { try {
@ -825,29 +824,35 @@ public class DeviceController extends ControllerBase {
@Transactional @Transactional
@PostMapping("changeServiceAgentCode") @PostMapping("changeServiceAgentCode")
public ApiResult<Void> changeServiceAgentCode(@RequestBody ChangeServiceAgentCodeQuery query) { public ApiResult<Void> changeServiceAgentCode(@RequestBody ChangeServiceAgentCodeQuery query) {
GongfuDevice device=deviceService.getById(query.getDeviceId()); List<GongfuDevice> devices = deviceService.lambdaQuery()
VUtils.trueThrowBusinessError(Objects.isNull(device)).throwMessage("设备不存在"); .in(GongfuDevice::getId, query.getDeviceIds())
VUtils.trueThrowBusinessError(StrUtil.equals(device.getServiceAgentCode(), query.getServiceAgentCode())) .list();
.throwMessage("代理商未修改"); if (CollectionUtil.isEmpty(devices)){
return ApiResult.error("没有需要修改的设备");
}
TBaseCustomer customer = customerService.lambdaQuery() TBaseCustomer customer = customerService.lambdaQuery()
.eq(TBaseCustomer::getDelIs, 0) .eq(TBaseCustomer::getDelIs, 0)
.eq(TBaseCustomer::getEnableState, 1) .eq(TBaseCustomer::getEnableState, 1)
.eq(TBaseCustomer::getAgencyCompanyCode, query.getServiceAgentCode()) .eq(TBaseCustomer::getAgencyCompanyCode, query.getServiceAgentCode())
.one(); .one();
VUtils.trueThrowBusinessError(Objects.isNull(customer)).throwMessage("代理商公司不存在"); VUtils.trueThrowBusinessError(Objects.isNull(customer)).throwMessage("代理商公司不存在");
deviceService.lambdaUpdate() devices.forEach(device -> {
.set(GongfuDevice::getServiceAgentCode, query.getServiceAgentCode()) if (!StrUtil.equals(device.getServiceAgentCode(), query.getServiceAgentCode())){
.set(GongfuDevice::getServiceAgentName, customer.getAgencyCompanyName()) deviceService.lambdaUpdate()
.eq(GongfuDevice::getId, query.getDeviceId()) .set(GongfuDevice::getServiceAgentCode, query.getServiceAgentCode())
.update(); .set(GongfuDevice::getServiceAgentName, customer.getAgencyCompanyName())
gongfuDeviceAgentRecordService.save(new GongfuDeviceAgentRecord() .eq(GongfuDevice::getId, device.getId())
.setDeviceId(query.getDeviceId()) .update();
.setAgentCode(query.getServiceAgentCode()) gongfuDeviceAgentRecordService.save(new GongfuDeviceAgentRecord()
.setAgentName(customer.getAgencyCompanyName()) .setDeviceId(device.getId())
.setCreateById(AdminUserUtil.getUserId()) .setAgentCode(query.getServiceAgentCode())
.setCreateBy(AdminUserUtil.getUserName()) .setAgentName(customer.getAgencyCompanyName())
.setCreateTime(LocalDateTime.now()) .setCreateById(AdminUserUtil.getUserId())
); .setCreateBy(AdminUserUtil.getUserName())
.setCreateTime(LocalDateTime.now())
);
}
});
return ApiResult.success(); return ApiResult.success();
} }

View File

@ -4,6 +4,7 @@ import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.List;
@Data @Data
public class ChangeServiceAgentCodeQuery { public class ChangeServiceAgentCodeQuery {
@ -12,7 +13,7 @@ public class ChangeServiceAgentCodeQuery {
* 设备ID * 设备ID
*/ */
@NotNull @NotNull
private Long deviceId; private List<Long> deviceIds;
/** /**
* 服务代理商编码 * 服务代理商编码

View File

@ -40,9 +40,9 @@ public class DeployTest {
private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception { private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception {
printInfo("处理目录:" + dirName); printInfo("处理目录:" + dirName);
List<Path> files = getFileList(localPath + "lib"); List<Path> files = getFileList(localPath + dirName);
for (Path file : files) { for (Path file : files) {
handleFile(sshUtil, file.toString(), remotePath + "lib/" + file.getFileName().toString()); handleFile(sshUtil, file.toString(), remotePath + dirName + "/" + file.getFileName().toString());
} }
printInfo("处理目录完成"); printInfo("处理目录完成");
} }

View File

@ -40,9 +40,9 @@ public class DeployTest {
private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception { private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception {
printInfo("处理目录:" + dirName); printInfo("处理目录:" + dirName);
List<Path> files = getFileList(localPath + "lib"); List<Path> files = getFileList(localPath + dirName);
for (Path file : files) { for (Path file : files) {
handleFile(sshUtil, file.toString(), remotePath + "lib/" + file.getFileName().toString()); handleFile(sshUtil, file.toString(), remotePath + dirName + "/" + file.getFileName().toString());
} }
printInfo("处理目录完成"); printInfo("处理目录完成");
} }

View File

@ -41,9 +41,9 @@ public class DeployTest {
private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception { private void handleDir(SSHUtil sshUtil, String localPath, String remotePath, String dirName) throws Exception {
printInfo("处理目录:" + dirName); printInfo("处理目录:" + dirName);
List<Path> files = getFileList(localPath + "lib"); List<Path> files = getFileList(localPath + dirName);
for (Path file : files) { for (Path file : files) {
handleFile(sshUtil, file.toString(), remotePath + "lib/" + file.getFileName().toString()); handleFile(sshUtil, file.toString(), remotePath + dirName + "/" + file.getFileName().toString());
} }
printInfo("处理目录完成"); printInfo("处理目录完成");
} }