2025-08-07 10:43:11 +00:00
|
|
|
|
package com.unisinsight.project.controller;
|
|
|
|
|
|
|
2025-08-11 10:55:20 +00:00
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
2025-08-07 10:43:11 +00:00
|
|
|
|
import cn.hutool.json.JSONUtil;
|
2025-08-11 10:55:20 +00:00
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
|
import com.unisinsight.project.entity.dao.DeviceImageMapping;
|
2025-08-07 10:43:11 +00:00
|
|
|
|
import com.unisinsight.project.entity.req.DeviceImageMappingReq;
|
|
|
|
|
|
import com.unisinsight.project.entity.res.DeviceImageMappingRes;
|
2025-08-11 10:55:20 +00:00
|
|
|
|
import com.unisinsight.project.entity.res.ListReq;
|
2025-08-07 10:43:11 +00:00
|
|
|
|
import com.unisinsight.project.exception.BaseErrorCode;
|
|
|
|
|
|
import com.unisinsight.project.exception.Result;
|
|
|
|
|
|
import com.unisinsight.project.service.DeviceImageMappingService;
|
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Objects;
|
2025-08-11 10:55:20 +00:00
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
2025-08-07 10:43:11 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @description:
|
|
|
|
|
|
* @author: rdpnr_puzhi
|
|
|
|
|
|
* @create: 2025/08/07
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("/api/nex/v1/device/image/mapping")
|
2025-08-08 10:10:47 +00:00
|
|
|
|
@Api(tags = "终端镜像映射关系类")
|
2025-08-07 10:43:11 +00:00
|
|
|
|
public class DeviceImageMappingController {
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private DeviceImageMappingService deviceImageMappingService;
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "终端镜像映射新增")
|
|
|
|
|
|
@PostMapping("/add")
|
2025-08-11 10:55:20 +00:00
|
|
|
|
public Result<?> insert(@RequestBody ListReq<DeviceImageMappingReq> deviceImageMappingReq) {
|
|
|
|
|
|
if (Objects.isNull(deviceImageMappingReq.getData())) {
|
2025-08-07 10:43:11 +00:00
|
|
|
|
return Result.errorResult(BaseErrorCode.PARAMS_CHK_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
log.info("终端镜像映射新增请求参数为:{}", JSONUtil.toJsonStr(deviceImageMappingReq));
|
2025-08-11 10:55:20 +00:00
|
|
|
|
|
|
|
|
|
|
List<DeviceImageMappingReq> reqData = deviceImageMappingReq.getData();
|
2025-08-12 08:14:10 +00:00
|
|
|
|
List<DeviceImageMappingReq> addList = reqData.stream().distinct().filter(e -> Objects.isNull(e.getId())).collect(Collectors.toList());
|
2025-08-11 10:55:20 +00:00
|
|
|
|
|
|
|
|
|
|
QueryWrapper<DeviceImageMapping> wrapper = new QueryWrapper<>();
|
|
|
|
|
|
wrapper.lambda().eq(DeviceImageMapping::getDeviceId, reqData.get(0).getDeviceId());
|
|
|
|
|
|
List<DeviceImageMapping> list = deviceImageMappingService.list(wrapper);
|
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(list)) {
|
|
|
|
|
|
Set<Long> requestIds = reqData.stream()
|
|
|
|
|
|
.map(DeviceImageMappingReq::getId)
|
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
|
|
List<Long> idsToDelete = list.stream()
|
|
|
|
|
|
.map(DeviceImageMapping::getId)
|
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
.filter(id -> !requestIds.contains(id))
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(idsToDelete)) {
|
|
|
|
|
|
deviceImageMappingService.removeByIds(idsToDelete);
|
|
|
|
|
|
log.info("删除了 {} 条不匹配的旧数据,ID列表: {}", idsToDelete.size(), idsToDelete);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(addList)) {
|
|
|
|
|
|
List<DeviceImageMapping> deviceImageMappings = BeanUtil.copyToList(addList, DeviceImageMapping.class);
|
|
|
|
|
|
List<DeviceImageMapping> deviceImageMappingList = deviceImageMappings.stream().peek(e -> {
|
|
|
|
|
|
e.setCreateUser("admin");
|
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
boolean insert = deviceImageMappingService.saveBatch(deviceImageMappingList);
|
|
|
|
|
|
log.info("终端镜像映射新增insert:{}", insert);
|
|
|
|
|
|
if (!insert) {
|
|
|
|
|
|
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Result.successResult();
|
2025-08-07 10:43:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "终端镜像映射查询")
|
|
|
|
|
|
@PostMapping("/select")
|
|
|
|
|
|
public Result<List<DeviceImageMappingRes>> select(@RequestBody DeviceImageMappingReq deviceImageMappingReq) {
|
|
|
|
|
|
if (Objects.isNull(deviceImageMappingReq)) {
|
|
|
|
|
|
return Result.errorResult(BaseErrorCode.PARAMS_CHK_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
log.info("终端镜像映射查询请求参数为:{}", JSONUtil.toJsonStr(deviceImageMappingReq));
|
|
|
|
|
|
return deviceImageMappingService.select(deviceImageMappingReq);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|