处理后台新需求
This commit is contained in:
+148
-18
@@ -1,6 +1,8 @@
|
||||
package com.nanri.aiimage.modules.dedupe.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.admin.support.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.util.DownloadHeaderUtil;
|
||||
import com.nanri.aiimage.modules.dedupe.model.dto.DedupeTotalDataCreateRequest;
|
||||
import com.nanri.aiimage.modules.dedupe.model.dto.DedupeTotalDataUpdateRequest;
|
||||
@@ -10,6 +12,8 @@ import com.nanri.aiimage.modules.dedupe.model.vo.DedupeTotalDataImportVo;
|
||||
import com.nanri.aiimage.modules.dedupe.model.vo.DedupeTotalDataItemVo;
|
||||
import com.nanri.aiimage.modules.dedupe.model.vo.DedupeTotalDataPageVo;
|
||||
import com.nanri.aiimage.modules.dedupe.service.DedupeTotalDataService;
|
||||
import com.nanri.aiimage.modules.permission.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
@@ -17,6 +21,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -36,6 +42,10 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -43,9 +53,20 @@ import java.time.format.DateTimeFormatter;
|
||||
@Tag(name = "数据去重总数据", description = "维护数据去重模块的总数据列表,支持增删改查。")
|
||||
public class DedupeTotalDataController {
|
||||
|
||||
private static final String DEDUPE_TOTAL_DATA_COLUMN_KEY = "admin_dedupe_total_data";
|
||||
private static final String DEDUPE_TOTAL_DATA_ROUTE_PATH = "dedupe-total-data";
|
||||
|
||||
private static final DateTimeFormatter EXPORT_FILENAME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||
|
||||
private final DedupeTotalDataService dedupeTotalDataService;
|
||||
private final AdminAuthSupport adminAuthSupport;
|
||||
private final PermissionMenuService permissionMenuService;
|
||||
|
||||
@Value("${aiimage.security.internal-token:}")
|
||||
private String internalToken;
|
||||
|
||||
@Value("${aiimage.security.internal-token-file:}")
|
||||
private String internalTokenFile;
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "分页查询总数据", description = "分页查询数据去重总数据,支持按值模糊搜索。")
|
||||
@@ -61,9 +82,11 @@ public class DedupeTotalDataController {
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@Parameter(description = "结束日期(包含)")
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
|
||||
@Parameter(description = "当前操作人用户ID") @RequestParam Long operatorId) {
|
||||
@Parameter(description = "分组 ID") @RequestParam(required = false) Long groupId,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireDedupeTotalDataAccess(request);
|
||||
return ApiResponse.success(dedupeTotalDataService.page(
|
||||
page, pageSize, keyword, username, startDate, endDate, operatorId));
|
||||
page, pageSize, keyword, username, startDate, endDate, groupId, operator.id()));
|
||||
}
|
||||
|
||||
@GetMapping("/export")
|
||||
@@ -74,8 +97,10 @@ public class DedupeTotalDataController {
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@Parameter(description = "结束日期(包含)")
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
|
||||
@Parameter(description = "当前操作人用户ID") @RequestParam Long operatorId) {
|
||||
byte[] bytes = dedupeTotalDataService.export(username, startDate, endDate, operatorId);
|
||||
@Parameter(description = "分组 ID") @RequestParam(required = false) Long groupId,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireDedupeTotalDataAccess(request);
|
||||
byte[] bytes = dedupeTotalDataService.export(username, startDate, endDate, groupId, operator.id());
|
||||
String filename = "dedupe-total-data-" + LocalDateTime.now().format(EXPORT_FILENAME_FORMATTER) + ".xlsx";
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, DownloadHeaderUtil.contentDisposition(filename))
|
||||
@@ -91,9 +116,10 @@ public class DedupeTotalDataController {
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "参数不合法或数据重复")
|
||||
})
|
||||
public ApiResponse<DedupeTotalDataItemVo> create(
|
||||
@Parameter(description = "当前操作人用户ID") @RequestParam Long operatorId,
|
||||
HttpServletRequest httpRequest,
|
||||
@Valid @RequestBody DedupeTotalDataCreateRequest request) {
|
||||
return ApiResponse.success("创建成功", dedupeTotalDataService.create(request, operatorId));
|
||||
RequestOperator operator = requireDedupeTotalDataAccess(httpRequest);
|
||||
return ApiResponse.success("创建成功", dedupeTotalDataService.create(request, operator.id()));
|
||||
}
|
||||
|
||||
@PostMapping("/import")
|
||||
@@ -104,16 +130,19 @@ public class DedupeTotalDataController {
|
||||
})
|
||||
public ApiResponse<DedupeTotalDataImportStartVo> importExcel(
|
||||
@Parameter(description = "xlsx 文件", required = true) @RequestParam("file") MultipartFile file,
|
||||
@Parameter(description = "当前操作人用户ID") @RequestParam Long operatorId) {
|
||||
return ApiResponse.success("开始导入", dedupeTotalDataService.startImport(file, operatorId));
|
||||
@Parameter(description = "分组 ID", required = true) @RequestParam Long groupId,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireDedupeTotalDataAccess(request);
|
||||
return ApiResponse.success("开始导入", dedupeTotalDataService.startImport(file, groupId, operator.id()));
|
||||
}
|
||||
|
||||
@GetMapping("/import/{importId}")
|
||||
@Operation(summary = "查询导入进度", description = "根据导入任务 ID 查询当前进度。")
|
||||
public ApiResponse<DedupeTotalDataImportProgressVo> importProgress(
|
||||
@PathVariable String importId,
|
||||
@Parameter(description = "当前操作人用户ID") @RequestParam Long operatorId) {
|
||||
return ApiResponse.success(dedupeTotalDataService.getImportProgress(importId, operatorId));
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireDedupeTotalDataAccess(request);
|
||||
return ApiResponse.success(dedupeTotalDataService.getImportProgress(importId, operator.id()));
|
||||
}
|
||||
|
||||
@PostMapping("/delete-import")
|
||||
@@ -124,16 +153,19 @@ public class DedupeTotalDataController {
|
||||
})
|
||||
public ApiResponse<DedupeTotalDataImportStartVo> deleteImportExcel(
|
||||
@Parameter(description = "xlsx 文件", required = true) @RequestParam("file") MultipartFile file,
|
||||
@Parameter(description = "当前操作人用户ID") @RequestParam Long operatorId) {
|
||||
return ApiResponse.success("开始删除", dedupeTotalDataService.startDeleteImport(file, operatorId));
|
||||
@Parameter(description = "分组 ID", required = true) @RequestParam Long groupId,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireDedupeTotalDataAccess(request);
|
||||
return ApiResponse.success("开始删除", dedupeTotalDataService.startDeleteImport(file, groupId, operator.id()));
|
||||
}
|
||||
|
||||
@GetMapping("/delete-import/{importId}")
|
||||
@Operation(summary = "查询删除导入进度", description = "根据删除导入任务 ID 查询当前进度。")
|
||||
public ApiResponse<DedupeTotalDataImportProgressVo> deleteImportProgress(
|
||||
@PathVariable String importId,
|
||||
@Parameter(description = "当前操作人用户ID") @RequestParam Long operatorId) {
|
||||
return ApiResponse.success(dedupeTotalDataService.getDeleteImportProgress(importId, operatorId));
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireDedupeTotalDataAccess(request);
|
||||
return ApiResponse.success(dedupeTotalDataService.getDeleteImportProgress(importId, operator.id()));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
@@ -145,9 +177,10 @@ public class DedupeTotalDataController {
|
||||
})
|
||||
public ApiResponse<DedupeTotalDataItemVo> update(
|
||||
@Parameter(description = "主键ID", required = true) @PathVariable Long id,
|
||||
@Parameter(description = "当前操作人用户ID") @RequestParam Long operatorId,
|
||||
HttpServletRequest httpRequest,
|
||||
@Valid @RequestBody DedupeTotalDataUpdateRequest request) {
|
||||
return ApiResponse.success("更新成功", dedupeTotalDataService.update(id, request, operatorId));
|
||||
RequestOperator operator = requireDedupeTotalDataAccess(httpRequest);
|
||||
return ApiResponse.success("更新成功", dedupeTotalDataService.update(id, request, operator.id()));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@@ -158,8 +191,105 @@ public class DedupeTotalDataController {
|
||||
})
|
||||
public ApiResponse<Void> delete(
|
||||
@Parameter(description = "主键ID", required = true) @PathVariable Long id,
|
||||
@Parameter(description = "当前操作人用户ID") @RequestParam Long operatorId) {
|
||||
dedupeTotalDataService.delete(id, operatorId);
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireDedupeTotalDataAccess(request);
|
||||
dedupeTotalDataService.delete(id, operator.id());
|
||||
return ApiResponse.success("删除成功", null);
|
||||
}
|
||||
|
||||
private RequestOperator requireDedupeTotalDataAccess(HttpServletRequest request) {
|
||||
AdminUserEntity operator = resolveOperator(request);
|
||||
if (operator == null || operator.getId() == null || operator.getId() <= 0) {
|
||||
throw new BusinessException(403, "无权访问数据去重总数据");
|
||||
}
|
||||
boolean superAdmin = "super_admin".equals(adminAuthSupport.currentRole(operator));
|
||||
if (!superAdmin && !hasDedupeTotalDataPermission(operator)) {
|
||||
throw new BusinessException(403, "无权访问数据去重总数据");
|
||||
}
|
||||
return new RequestOperator(operator.getId(), superAdmin);
|
||||
}
|
||||
|
||||
private AdminUserEntity resolveOperator(HttpServletRequest request) {
|
||||
try {
|
||||
return adminAuthSupport.requireUser(request);
|
||||
} catch (BusinessException authFailure) {
|
||||
AdminUserEntity internalOperator = resolveInternalOperator(request);
|
||||
if (internalOperator != null) {
|
||||
return internalOperator;
|
||||
}
|
||||
throw authFailure;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasDedupeTotalDataPermission(AdminUserEntity operator) {
|
||||
return permissionMenuService.getUserColumnPermissions(operator.getId(), "admin")
|
||||
.stream()
|
||||
.anyMatch(item -> DEDUPE_TOTAL_DATA_COLUMN_KEY.equals(item.getColumnKey())
|
||||
|| DEDUPE_TOTAL_DATA_ROUTE_PATH.equals(item.getRoutePath()));
|
||||
}
|
||||
|
||||
private AdminUserEntity resolveInternalOperator(HttpServletRequest request) {
|
||||
if (!isTrustedInternalRequest(request.getHeader("X-Internal-Token"))) {
|
||||
return null;
|
||||
}
|
||||
String rawOperatorId = request.getParameter("operatorId");
|
||||
if (rawOperatorId == null || rawOperatorId.isBlank()) {
|
||||
rawOperatorId = request.getParameter("operator_id");
|
||||
}
|
||||
if (rawOperatorId == null || rawOperatorId.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return permissionMenuService.requireUserOperator(Long.parseLong(rawOperatorId.trim()));
|
||||
} catch (NumberFormatException | BusinessException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTrustedInternalRequest(String suppliedToken) {
|
||||
String expectedToken = resolveExpectedInternalToken();
|
||||
return !expectedToken.isBlank() && suppliedToken != null && !suppliedToken.isBlank()
|
||||
&& MessageDigest.isEqual(
|
||||
expectedToken.getBytes(StandardCharsets.UTF_8),
|
||||
suppliedToken.trim().getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private String resolveExpectedInternalToken() {
|
||||
if (internalToken != null && !internalToken.isBlank()) {
|
||||
return internalToken.trim();
|
||||
}
|
||||
Path path = resolveInternalTokenFile();
|
||||
if (path == null || !Files.isRegularFile(path)) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return Files.readString(path, StandardCharsets.UTF_8).trim();
|
||||
} catch (Exception ignored) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private Path resolveInternalTokenFile() {
|
||||
String configuredPath = internalTokenFile == null ? "" : internalTokenFile.trim();
|
||||
if (!configuredPath.isEmpty()) {
|
||||
if (configuredPath.equals("~") || configuredPath.startsWith("~/") || configuredPath.startsWith("~\\")) {
|
||||
String userHome = System.getProperty("user.home", "").trim();
|
||||
if (userHome.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
configuredPath = configuredPath.length() == 1
|
||||
? userHome
|
||||
: Path.of(userHome, configuredPath.substring(2)).toString();
|
||||
}
|
||||
Path configuredTokenPath = Path.of(configuredPath);
|
||||
return configuredTokenPath.isAbsolute() ? configuredTokenPath.normalize() : null;
|
||||
}
|
||||
String userHome = System.getProperty("user.home", "").trim();
|
||||
return userHome.isEmpty()
|
||||
? null
|
||||
: Path.of(userHome, ".aiimage", "internal-token").toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
private record RequestOperator(Long id, boolean superAdmin) {
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -2,6 +2,7 @@ package com.nanri.aiimage.modules.dedupe.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -13,4 +14,8 @@ public class DedupeTotalDataCreateRequest {
|
||||
@Size(max = 128, message = "数据长度不能超过128个字符")
|
||||
@Schema(description = "总数据值", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String dataValue;
|
||||
|
||||
@NotNull(message = "请选择分组")
|
||||
@Schema(description = "分组 ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Long groupId;
|
||||
}
|
||||
|
||||
+5
@@ -2,6 +2,7 @@ package com.nanri.aiimage.modules.dedupe.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -13,4 +14,8 @@ public class DedupeTotalDataUpdateRequest {
|
||||
@Size(max = 128, message = "数据长度不能超过128个字符")
|
||||
@Schema(description = "总数据值", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String dataValue;
|
||||
|
||||
@NotNull(message = "请选择分组")
|
||||
@Schema(description = "分组 ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Long groupId;
|
||||
}
|
||||
|
||||
+1
@@ -14,6 +14,7 @@ public class DedupeTotalDataEntity {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
private String dataValue;
|
||||
private Long groupId;
|
||||
private Long uploaderUserId;
|
||||
private String uploaderUsername;
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
+6
@@ -15,6 +15,12 @@ public class DedupeTotalDataItemVo {
|
||||
@Schema(description = "总数据值")
|
||||
private String dataValue;
|
||||
|
||||
@Schema(description = "分组 ID")
|
||||
private Long groupId;
|
||||
|
||||
@Schema(description = "分组名称")
|
||||
private String groupName;
|
||||
|
||||
@Schema(description = "上传用户ID")
|
||||
private Long uploaderUserId;
|
||||
|
||||
|
||||
+195
-41
@@ -15,6 +15,7 @@ import com.nanri.aiimage.modules.dedupe.model.vo.DedupeTotalDataPageVo;
|
||||
import com.nanri.aiimage.modules.permission.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.modules.permission.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopManageGroupMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.model.entity.ShopManageGroupEntity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
@@ -42,6 +43,7 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -65,6 +67,8 @@ public class DedupeTotalDataService {
|
||||
private final Map<String, DedupeTotalDataImportProgressVo> deleteImportProgressMap = new ConcurrentHashMap<>();
|
||||
private final Map<String, Long> importOwnerMap = new ConcurrentHashMap<>();
|
||||
private final Map<String, Long> deleteImportOwnerMap = new ConcurrentHashMap<>();
|
||||
private final Map<String, Long> importGroupMap = new ConcurrentHashMap<>();
|
||||
private final Map<String, Long> deleteImportGroupMap = new ConcurrentHashMap<>();
|
||||
private final Map<String, Long> importCompletedAtMap = new ConcurrentHashMap<>();
|
||||
private final Map<String, Long> deleteImportCompletedAtMap = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -76,6 +80,11 @@ public class DedupeTotalDataService {
|
||||
|
||||
public DedupeTotalDataPageVo page(long page, long pageSize, String keyword, String username,
|
||||
LocalDate startDate, LocalDate endDate, Long operatorId) {
|
||||
return page(page, pageSize, keyword, username, startDate, endDate, null, operatorId);
|
||||
}
|
||||
|
||||
public DedupeTotalDataPageVo page(long page, long pageSize, String keyword, String username,
|
||||
LocalDate startDate, LocalDate endDate, Long groupId, Long operatorId) {
|
||||
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
|
||||
throw new BusinessException("开始日期不能晚于结束日期");
|
||||
}
|
||||
@@ -86,17 +95,21 @@ public class DedupeTotalDataService {
|
||||
AccessScope scope = resolveAccessScope(operatorId);
|
||||
LambdaQueryWrapper<DedupeTotalDataEntity> query = new LambdaQueryWrapper<DedupeTotalDataEntity>()
|
||||
.like(!safeKeyword.isEmpty(), DedupeTotalDataEntity::getDataValue, safeKeyword)
|
||||
.in(!scope.allUsers(), DedupeTotalDataEntity::getUploaderUserId, scope.userIds())
|
||||
.like(!safeUsername.isEmpty(), DedupeTotalDataEntity::getUploaderUsername, safeUsername)
|
||||
.ge(startDate != null, DedupeTotalDataEntity::getCreatedAt,
|
||||
startDate == null ? null : startDate.atStartOfDay())
|
||||
.lt(endDate != null, DedupeTotalDataEntity::getCreatedAt,
|
||||
endDate == null ? null : endDate.plusDays(1).atStartOfDay())
|
||||
.orderByDesc(DedupeTotalDataEntity::getId);
|
||||
applyGroupScope(query, scope, groupId);
|
||||
Long total = dedupeTotalDataMapper.selectCount(query);
|
||||
List<DedupeTotalDataItemVo> items = dedupeTotalDataMapper.selectList(query.last("LIMIT " + ((safePage - 1) * safePageSize) + ", " + safePageSize))
|
||||
.stream()
|
||||
.map(this::toItemVo)
|
||||
List<DedupeTotalDataEntity> rows = dedupeTotalDataMapper.selectList(
|
||||
query.last("LIMIT " + ((safePage - 1) * safePageSize) + ", " + safePageSize));
|
||||
Map<Long, String> groupNames = loadGroupNames(rows);
|
||||
List<DedupeTotalDataItemVo> items = rows.stream()
|
||||
.map(row -> toItemVo(row, row.getGroupId() == null
|
||||
? ""
|
||||
: groupNames.getOrDefault(row.getGroupId(), "")))
|
||||
.toList();
|
||||
DedupeTotalDataPageVo vo = new DedupeTotalDataPageVo();
|
||||
vo.setItems(items);
|
||||
@@ -107,24 +120,29 @@ public class DedupeTotalDataService {
|
||||
}
|
||||
|
||||
public byte[] export(String username, LocalDate startDate, LocalDate endDate, Long operatorId) {
|
||||
return export(username, startDate, endDate, null, operatorId);
|
||||
}
|
||||
|
||||
public byte[] export(String username, LocalDate startDate, LocalDate endDate,
|
||||
Long groupId, Long operatorId) {
|
||||
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
|
||||
throw new BusinessException("开始日期不能晚于结束日期");
|
||||
}
|
||||
String safeUsername = username == null ? "" : username.trim();
|
||||
AccessScope scope = resolveAccessScope(operatorId);
|
||||
LambdaQueryWrapper<DedupeTotalDataEntity> query = new LambdaQueryWrapper<DedupeTotalDataEntity>()
|
||||
.in(!scope.allUsers(), DedupeTotalDataEntity::getUploaderUserId, scope.userIds())
|
||||
.like(!safeUsername.isEmpty(), DedupeTotalDataEntity::getUploaderUsername, safeUsername)
|
||||
.ge(startDate != null, DedupeTotalDataEntity::getCreatedAt,
|
||||
startDate == null ? null : startDate.atStartOfDay())
|
||||
.lt(endDate != null, DedupeTotalDataEntity::getCreatedAt,
|
||||
endDate == null ? null : endDate.plusDays(1).atStartOfDay())
|
||||
.orderByDesc(DedupeTotalDataEntity::getId);
|
||||
applyGroupScope(query, scope, groupId);
|
||||
List<DedupeTotalDataEntity> rows = dedupeTotalDataMapper.selectList(query);
|
||||
return buildExportWorkbook(rows);
|
||||
return buildExportWorkbook(rows, loadGroupNames(rows));
|
||||
}
|
||||
|
||||
private byte[] buildExportWorkbook(List<DedupeTotalDataEntity> rows) {
|
||||
private byte[] buildExportWorkbook(List<DedupeTotalDataEntity> rows, Map<Long, String> groupNames) {
|
||||
try (SXSSFWorkbook workbook = new SXSSFWorkbook(100);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||
Sheet sheet = workbook.createSheet("DedupeTotalData");
|
||||
@@ -132,19 +150,24 @@ public class DedupeTotalDataService {
|
||||
header.createCell(0).setCellValue("ID");
|
||||
header.createCell(1).setCellValue("ASIN值");
|
||||
header.createCell(2).setCellValue("用户名");
|
||||
header.createCell(3).setCellValue("创建时间");
|
||||
header.createCell(3).setCellValue("分组");
|
||||
header.createCell(4).setCellValue("创建时间");
|
||||
for (int index = 0; index < rows.size(); index++) {
|
||||
DedupeTotalDataEntity entity = rows.get(index);
|
||||
Row row = sheet.createRow(index + 1);
|
||||
row.createCell(0).setCellValue(entity.getId() == null ? "" : String.valueOf(entity.getId()));
|
||||
row.createCell(1).setCellValue(entity.getDataValue() == null ? "" : entity.getDataValue());
|
||||
row.createCell(2).setCellValue(entity.getUploaderUsername() == null ? "" : entity.getUploaderUsername());
|
||||
row.createCell(3).setCellValue(formatExportTime(entity.getCreatedAt()));
|
||||
row.createCell(3).setCellValue(entity.getGroupId() == null
|
||||
? ""
|
||||
: groupNames.getOrDefault(entity.getGroupId(), ""));
|
||||
row.createCell(4).setCellValue(formatExportTime(entity.getCreatedAt()));
|
||||
}
|
||||
sheet.setColumnWidth(0, 3600);
|
||||
sheet.setColumnWidth(1, 5200);
|
||||
sheet.setColumnWidth(2, 5200);
|
||||
sheet.setColumnWidth(3, 5600);
|
||||
sheet.setColumnWidth(3, 5200);
|
||||
sheet.setColumnWidth(4, 5600);
|
||||
workbook.write(outputStream);
|
||||
workbook.dispose();
|
||||
return outputStream.toByteArray();
|
||||
@@ -160,14 +183,16 @@ public class DedupeTotalDataService {
|
||||
@Transactional
|
||||
public DedupeTotalDataItemVo create(DedupeTotalDataCreateRequest request, Long operatorId) {
|
||||
AdminUserEntity uploader = getOperator(operatorId);
|
||||
ShopManageGroupEntity group = resolveWritableGroup(request.getGroupId(), uploader);
|
||||
String dataValue = normalizeComparableValue(request.getDataValue());
|
||||
ensureUnique(dataValue, null);
|
||||
DedupeTotalDataEntity entity = new DedupeTotalDataEntity();
|
||||
entity.setDataValue(dataValue);
|
||||
entity.setGroupId(group.getId());
|
||||
entity.setUploaderUserId(uploader.getId());
|
||||
entity.setUploaderUsername(uploader.getUsername());
|
||||
dedupeTotalDataMapper.insert(entity);
|
||||
return toItemVo(getById(entity.getId()));
|
||||
return toItemVo(getById(entity.getId()), group.getGroupName());
|
||||
}
|
||||
|
||||
public Set<String> listComparableValues() {
|
||||
@@ -204,11 +229,16 @@ public class DedupeTotalDataService {
|
||||
}
|
||||
|
||||
public DedupeTotalDataImportStartVo startImport(MultipartFile file, Long operatorId) {
|
||||
return startImport(file, null, operatorId);
|
||||
}
|
||||
|
||||
public DedupeTotalDataImportStartVo startImport(MultipartFile file, Long groupId, Long operatorId) {
|
||||
cleanupExpiredProgress();
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new BusinessException("请上传 xlsx 文件");
|
||||
}
|
||||
AdminUserEntity uploader = getOperator(operatorId);
|
||||
ShopManageGroupEntity group = resolveWritableGroup(groupId, uploader);
|
||||
String importId = IdUtil.fastSimpleUUID();
|
||||
DedupeTotalDataImportProgressVo progress = new DedupeTotalDataImportProgressVo();
|
||||
progress.setStatus("pending");
|
||||
@@ -219,15 +249,17 @@ public class DedupeTotalDataService {
|
||||
progress.setSkippedCount(0);
|
||||
importProgressMap.put(importId, progress);
|
||||
importOwnerMap.put(importId, uploader.getId());
|
||||
importGroupMap.put(importId, group.getId());
|
||||
|
||||
try {
|
||||
File tempFile = saveMultipartToTempFile(file);
|
||||
String filename = file.getOriginalFilename();
|
||||
Thread.ofVirtual().start(() -> runImportTask(
|
||||
importId, tempFile, filename, uploader.getId(), uploader.getUsername()));
|
||||
importId, tempFile, filename, uploader.getId(), uploader.getUsername(), group.getId()));
|
||||
} catch (Exception e) {
|
||||
importProgressMap.remove(importId);
|
||||
importOwnerMap.remove(importId);
|
||||
importGroupMap.remove(importId);
|
||||
throw new BusinessException("读取上传文件失败");
|
||||
}
|
||||
|
||||
@@ -240,19 +272,25 @@ public class DedupeTotalDataService {
|
||||
cleanupExpiredProgress();
|
||||
DedupeTotalDataImportProgressVo progress = importProgressMap.get(importId);
|
||||
Long ownerId = importOwnerMap.get(importId);
|
||||
if (progress == null || ownerId == null) {
|
||||
Long groupId = importGroupMap.get(importId);
|
||||
if (progress == null || ownerId == null || groupId == null) {
|
||||
throw new BusinessException("导入任务不存在");
|
||||
}
|
||||
ensureUploaderAccess(ownerId, resolveAccessScope(operatorId));
|
||||
ensureImportTaskAccess(groupId, resolveAccessScope(operatorId));
|
||||
return progress;
|
||||
}
|
||||
|
||||
public DedupeTotalDataImportStartVo startDeleteImport(MultipartFile file, Long operatorId) {
|
||||
return startDeleteImport(file, null, operatorId);
|
||||
}
|
||||
|
||||
public DedupeTotalDataImportStartVo startDeleteImport(MultipartFile file, Long groupId, Long operatorId) {
|
||||
cleanupExpiredProgress();
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new BusinessException("请上传 xlsx 文件");
|
||||
}
|
||||
AdminUserEntity operator = getOperator(operatorId);
|
||||
ShopManageGroupEntity group = resolveWritableGroup(groupId, operator);
|
||||
String importId = IdUtil.fastSimpleUUID();
|
||||
DedupeTotalDataImportProgressVo progress = new DedupeTotalDataImportProgressVo();
|
||||
progress.setStatus("pending");
|
||||
@@ -263,14 +301,17 @@ public class DedupeTotalDataService {
|
||||
progress.setSkippedCount(0);
|
||||
deleteImportProgressMap.put(importId, progress);
|
||||
deleteImportOwnerMap.put(importId, operator.getId());
|
||||
deleteImportGroupMap.put(importId, group.getId());
|
||||
|
||||
try {
|
||||
File tempFile = saveMultipartToTempFile(file);
|
||||
String filename = file.getOriginalFilename();
|
||||
Thread.ofVirtual().start(() -> runDeleteImportTask(importId, tempFile, filename, operator.getId()));
|
||||
Thread.ofVirtual().start(() -> runDeleteImportTask(
|
||||
importId, tempFile, filename, operator.getId(), group.getId()));
|
||||
} catch (Exception e) {
|
||||
deleteImportProgressMap.remove(importId);
|
||||
deleteImportOwnerMap.remove(importId);
|
||||
deleteImportGroupMap.remove(importId);
|
||||
throw new BusinessException("读取上传文件失败");
|
||||
}
|
||||
|
||||
@@ -283,14 +324,16 @@ public class DedupeTotalDataService {
|
||||
cleanupExpiredProgress();
|
||||
DedupeTotalDataImportProgressVo progress = deleteImportProgressMap.get(importId);
|
||||
Long ownerId = deleteImportOwnerMap.get(importId);
|
||||
if (progress == null || ownerId == null) {
|
||||
Long groupId = deleteImportGroupMap.get(importId);
|
||||
if (progress == null || ownerId == null || groupId == null) {
|
||||
throw new BusinessException("删除任务不存在");
|
||||
}
|
||||
ensureUploaderAccess(ownerId, resolveAccessScope(operatorId));
|
||||
ensureImportTaskAccess(groupId, resolveAccessScope(operatorId));
|
||||
return progress;
|
||||
}
|
||||
|
||||
private void runDeleteImportTask(String importId, File tempFile, String filename, Long operatorId) {
|
||||
private void runDeleteImportTask(String importId, File tempFile, String filename,
|
||||
Long operatorId, Long groupId) {
|
||||
DedupeTotalDataImportProgressVo progress = deleteImportProgressMap.get(importId);
|
||||
if (progress == null) {
|
||||
return;
|
||||
@@ -298,7 +341,8 @@ public class DedupeTotalDataService {
|
||||
progress.setStatus("running");
|
||||
try (InputStream inputStream = Files.newInputStream(tempFile.toPath())) {
|
||||
AccessScope scope = resolveAccessScope(operatorId);
|
||||
DedupeTotalDataImportVo result = deleteFromExcelInternal(inputStream, filename, progress, scope);
|
||||
DedupeTotalDataImportVo result = deleteFromExcelInternal(
|
||||
inputStream, filename, progress, scope, groupId);
|
||||
progress.setTotalRows(result.getTotalRows());
|
||||
progress.setAsinCount(result.getAsinCount());
|
||||
progress.setInsertedCount(result.getInsertedCount());
|
||||
@@ -315,7 +359,7 @@ public class DedupeTotalDataService {
|
||||
}
|
||||
|
||||
private void runImportTask(String importId, File tempFile, String filename,
|
||||
Long uploaderUserId, String uploaderUsername) {
|
||||
Long uploaderUserId, String uploaderUsername, Long groupId) {
|
||||
DedupeTotalDataImportProgressVo progress = importProgressMap.get(importId);
|
||||
if (progress == null) {
|
||||
return;
|
||||
@@ -323,7 +367,7 @@ public class DedupeTotalDataService {
|
||||
progress.setStatus("running");
|
||||
try (InputStream inputStream = Files.newInputStream(tempFile.toPath())) {
|
||||
DedupeTotalDataImportVo result = importFromExcelInternal(
|
||||
inputStream, filename, progress, uploaderUserId, uploaderUsername);
|
||||
inputStream, filename, progress, uploaderUserId, uploaderUsername, groupId);
|
||||
progress.setTotalRows(result.getTotalRows());
|
||||
progress.setAsinCount(result.getAsinCount());
|
||||
progress.setInsertedCount(result.getInsertedCount());
|
||||
@@ -364,13 +408,19 @@ public class DedupeTotalDataService {
|
||||
}
|
||||
|
||||
public DedupeTotalDataImportVo importFromExcel(MultipartFile file, Long operatorId) {
|
||||
return importFromExcel(file, null, operatorId);
|
||||
}
|
||||
|
||||
public DedupeTotalDataImportVo importFromExcel(MultipartFile file, Long groupId, Long operatorId) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new BusinessException("请上传 xlsx 文件");
|
||||
}
|
||||
AdminUserEntity uploader = getOperator(operatorId);
|
||||
ShopManageGroupEntity group = resolveWritableGroup(groupId, uploader);
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
return importFromExcelInternal(
|
||||
inputStream, file.getOriginalFilename(), null, uploader.getId(), uploader.getUsername());
|
||||
inputStream, file.getOriginalFilename(), null, uploader.getId(), uploader.getUsername(),
|
||||
group.getId());
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
@@ -379,12 +429,19 @@ public class DedupeTotalDataService {
|
||||
}
|
||||
|
||||
public DedupeTotalDataImportVo deleteFromExcel(MultipartFile file, Long operatorId) {
|
||||
return deleteFromExcel(file, null, operatorId);
|
||||
}
|
||||
|
||||
public DedupeTotalDataImportVo deleteFromExcel(MultipartFile file, Long groupId, Long operatorId) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new BusinessException("请上传 xlsx 文件");
|
||||
}
|
||||
AdminUserEntity operator = getOperator(operatorId);
|
||||
ShopManageGroupEntity group = resolveWritableGroup(groupId, operator);
|
||||
AccessScope scope = resolveAccessScope(operatorId);
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
return deleteFromExcelInternal(inputStream, file.getOriginalFilename(), null, scope);
|
||||
return deleteFromExcelInternal(
|
||||
inputStream, file.getOriginalFilename(), null, scope, group.getId());
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
@@ -394,7 +451,8 @@ public class DedupeTotalDataService {
|
||||
|
||||
private DedupeTotalDataImportVo importFromExcelInternal(InputStream inputStream, String filename,
|
||||
DedupeTotalDataImportProgressVo progress,
|
||||
Long uploaderUserId, String uploaderUsername) {
|
||||
Long uploaderUserId, String uploaderUsername,
|
||||
Long groupId) {
|
||||
String lowerFilename = filename == null ? "" : filename.toLowerCase();
|
||||
if (!(lowerFilename.endsWith(".xlsx") || lowerFilename.endsWith(".xls"))) {
|
||||
throw new BusinessException("仅支持 .xlsx 或 .xls 文件");
|
||||
@@ -490,6 +548,7 @@ public class DedupeTotalDataService {
|
||||
}
|
||||
DedupeTotalDataEntity entity = new DedupeTotalDataEntity();
|
||||
entity.setDataValue(pendingDataValue);
|
||||
entity.setGroupId(groupId);
|
||||
entity.setUploaderUserId(uploaderUserId);
|
||||
entity.setUploaderUsername(uploaderUsername);
|
||||
dedupeTotalDataMapper.insert(entity);
|
||||
@@ -526,7 +585,7 @@ public class DedupeTotalDataService {
|
||||
|
||||
private DedupeTotalDataImportVo deleteFromExcelInternal(InputStream inputStream, String filename,
|
||||
DedupeTotalDataImportProgressVo progress,
|
||||
AccessScope scope) {
|
||||
AccessScope scope, Long groupId) {
|
||||
String lowerFilename = filename == null ? "" : filename.toLowerCase();
|
||||
if (!(lowerFilename.endsWith(".xlsx") || lowerFilename.endsWith(".xls"))) {
|
||||
throw new BusinessException("仅支持 .xlsx 或 .xls 文件");
|
||||
@@ -604,7 +663,8 @@ public class DedupeTotalDataService {
|
||||
continue;
|
||||
}
|
||||
|
||||
int deletedThisRow = newRequiresNewTemplate().execute(status -> deleteByDataValue(dataValue, scope));
|
||||
int deletedThisRow = newRequiresNewTemplate().execute(
|
||||
status -> deleteByDataValue(dataValue, scope, groupId));
|
||||
if (deletedThisRow > 0) {
|
||||
deletedCount += deletedThisRow;
|
||||
} else {
|
||||
@@ -634,11 +694,14 @@ public class DedupeTotalDataService {
|
||||
@Transactional
|
||||
public DedupeTotalDataItemVo update(Long id, DedupeTotalDataUpdateRequest request, Long operatorId) {
|
||||
DedupeTotalDataEntity entity = getAccessibleById(id, operatorId);
|
||||
AdminUserEntity operator = getOperator(operatorId);
|
||||
String dataValue = normalizeComparableValue(request.getDataValue());
|
||||
ensureUnique(dataValue, id);
|
||||
entity.setDataValue(dataValue);
|
||||
ShopManageGroupEntity group = resolveWritableGroup(request.getGroupId(), operator);
|
||||
entity.setGroupId(group.getId());
|
||||
dedupeTotalDataMapper.updateById(entity);
|
||||
return toItemVo(getById(id));
|
||||
return toItemVo(getById(id), group.getGroupName());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -649,7 +712,7 @@ public class DedupeTotalDataService {
|
||||
|
||||
private DedupeTotalDataEntity getAccessibleById(Long id, Long operatorId) {
|
||||
DedupeTotalDataEntity entity = getById(id);
|
||||
ensureUploaderAccess(entity.getUploaderUserId(), resolveAccessScope(operatorId));
|
||||
ensureRecordAccess(entity, resolveAccessScope(operatorId));
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -690,26 +753,78 @@ public class DedupeTotalDataService {
|
||||
return dedupeTotalDataMapper.selectOne(query) != null;
|
||||
}
|
||||
|
||||
private int deleteByDataValue(String dataValue, AccessScope scope) {
|
||||
return dedupeTotalDataMapper.delete(new LambdaQueryWrapper<DedupeTotalDataEntity>()
|
||||
.eq(DedupeTotalDataEntity::getDataValue, dataValue)
|
||||
.in(!scope.allUsers(), DedupeTotalDataEntity::getUploaderUserId, scope.userIds()));
|
||||
private int deleteByDataValue(String dataValue, AccessScope scope, Long groupId) {
|
||||
LambdaQueryWrapper<DedupeTotalDataEntity> query = new LambdaQueryWrapper<DedupeTotalDataEntity>()
|
||||
.eq(DedupeTotalDataEntity::getDataValue, dataValue);
|
||||
applyGroupScope(query, scope, groupId);
|
||||
return dedupeTotalDataMapper.delete(query);
|
||||
}
|
||||
|
||||
private AccessScope resolveAccessScope(Long operatorId) {
|
||||
AdminUserEntity operator = getOperator(operatorId);
|
||||
if (isSuperAdmin(operator)) {
|
||||
return new AccessScope(true, Set.of());
|
||||
return new AccessScope(true, Set.of(), Set.of());
|
||||
}
|
||||
List<Long> accessibleGroupIds = shopManageGroupMapper.selectAccessibleGroupIds(operator.getId());
|
||||
LinkedHashSet<Long> visibleUserIds = new LinkedHashSet<>();
|
||||
visibleUserIds.add(operator.getId());
|
||||
if (accessibleGroupIds != null && !accessibleGroupIds.isEmpty()) {
|
||||
List<Long> groupUserIds = shopManageGroupMapper.selectUserIdsByGroupIds(accessibleGroupIds);
|
||||
if (groupUserIds != null) {
|
||||
groupUserIds.stream()
|
||||
.filter(id -> id != null && id > 0)
|
||||
.forEach(visibleUserIds::add);
|
||||
}
|
||||
}
|
||||
List<Long> memberUserIds = shopManageGroupMapper.selectManagedMemberUserIds(operator.getId());
|
||||
if (memberUserIds != null) {
|
||||
memberUserIds.stream()
|
||||
.filter(id -> id != null && id > 0)
|
||||
.forEach(visibleUserIds::add);
|
||||
}
|
||||
return new AccessScope(false, Set.copyOf(visibleUserIds));
|
||||
return new AccessScope(
|
||||
false,
|
||||
Set.copyOf(accessibleGroupIds == null ? List.of() : accessibleGroupIds),
|
||||
Set.copyOf(visibleUserIds));
|
||||
}
|
||||
|
||||
private void applyGroupScope(LambdaQueryWrapper<DedupeTotalDataEntity> query,
|
||||
AccessScope scope, Long groupId) {
|
||||
if (groupId != null && groupId > 0) {
|
||||
resolveAccessibleGroup(groupId, scope);
|
||||
query.eq(DedupeTotalDataEntity::getGroupId, groupId);
|
||||
return;
|
||||
}
|
||||
if (scope.allUsers()) {
|
||||
return;
|
||||
}
|
||||
query.and(wrapper -> {
|
||||
if (!scope.groupIds().isEmpty()) {
|
||||
wrapper.in(DedupeTotalDataEntity::getGroupId, scope.groupIds())
|
||||
.or();
|
||||
}
|
||||
wrapper.isNull(DedupeTotalDataEntity::getGroupId)
|
||||
.in(DedupeTotalDataEntity::getUploaderUserId, scope.userIds());
|
||||
});
|
||||
}
|
||||
|
||||
private ShopManageGroupEntity resolveWritableGroup(Long groupId, AdminUserEntity operator) {
|
||||
if (groupId == null || groupId <= 0) {
|
||||
throw new BusinessException("请选择分组");
|
||||
}
|
||||
AccessScope scope = resolveAccessScope(operator.getId());
|
||||
return resolveAccessibleGroup(groupId, scope);
|
||||
}
|
||||
|
||||
private ShopManageGroupEntity resolveAccessibleGroup(Long groupId, AccessScope scope) {
|
||||
ShopManageGroupEntity group = shopManageGroupMapper.selectById(groupId);
|
||||
if (group == null) {
|
||||
throw new BusinessException("分组不存在");
|
||||
}
|
||||
if (!scope.allUsers() && !scope.groupIds().contains(groupId)) {
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "无权操作该分组数据");
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
private AdminUserEntity getOperator(Long operatorId) {
|
||||
@@ -729,27 +844,46 @@ public class DedupeTotalDataService {
|
||||
|| (role.isEmpty() && Integer.valueOf(1).equals(user.getIsAdmin()) && user.getCreatedById() == null);
|
||||
}
|
||||
|
||||
private void ensureUploaderAccess(Long uploaderUserId, AccessScope scope) {
|
||||
if (!scope.allUsers() && (uploaderUserId == null || !scope.userIds().contains(uploaderUserId))) {
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "无权操作该总数据");
|
||||
private void ensureRecordAccess(DedupeTotalDataEntity entity, AccessScope scope) {
|
||||
if (scope.allUsers()) {
|
||||
return;
|
||||
}
|
||||
if (entity.getGroupId() != null && scope.groupIds().contains(entity.getGroupId())) {
|
||||
return;
|
||||
}
|
||||
if (entity.getGroupId() == null && entity.getUploaderUserId() != null
|
||||
&& scope.userIds().contains(entity.getUploaderUserId())) {
|
||||
return;
|
||||
}
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "无权操作该总数据");
|
||||
}
|
||||
|
||||
private void ensureImportTaskAccess(Long groupId, AccessScope scope) {
|
||||
if (!scope.allUsers() && !scope.groupIds().contains(groupId)) {
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "无权查看该导入任务");
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanupExpiredProgress() {
|
||||
long cutoff = System.currentTimeMillis() - COMPLETED_PROGRESS_RETENTION_MILLIS;
|
||||
cleanupExpiredProgressEntries(importCompletedAtMap, importProgressMap, importOwnerMap, cutoff);
|
||||
cleanupExpiredProgressEntries(deleteImportCompletedAtMap, deleteImportProgressMap, deleteImportOwnerMap, cutoff);
|
||||
cleanupExpiredProgressEntries(
|
||||
importCompletedAtMap, importProgressMap, importOwnerMap, importGroupMap, cutoff);
|
||||
cleanupExpiredProgressEntries(
|
||||
deleteImportCompletedAtMap, deleteImportProgressMap, deleteImportOwnerMap,
|
||||
deleteImportGroupMap, cutoff);
|
||||
}
|
||||
|
||||
private void cleanupExpiredProgressEntries(
|
||||
Map<String, Long> completedAtMap,
|
||||
Map<String, DedupeTotalDataImportProgressVo> progressMap,
|
||||
Map<String, Long> ownerMap,
|
||||
Map<String, Long> groupMap,
|
||||
long cutoff) {
|
||||
completedAtMap.forEach((id, completedAt) -> {
|
||||
if (completedAt != null && completedAt < cutoff && completedAtMap.remove(id, completedAt)) {
|
||||
progressMap.remove(id);
|
||||
ownerMap.remove(id);
|
||||
groupMap.remove(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -768,16 +902,36 @@ public class DedupeTotalDataService {
|
||||
.replaceAll("\\s+", " ");
|
||||
}
|
||||
|
||||
private DedupeTotalDataItemVo toItemVo(DedupeTotalDataEntity entity) {
|
||||
private Map<Long, String> loadGroupNames(List<DedupeTotalDataEntity> rows) {
|
||||
List<Long> groupIds = rows.stream()
|
||||
.map(DedupeTotalDataEntity::getGroupId)
|
||||
.filter(id -> id != null && id > 0)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (groupIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return shopManageGroupMapper.selectBatchIds(groupIds).stream()
|
||||
.filter(group -> group.getId() != null)
|
||||
.collect(java.util.stream.Collectors.toMap(
|
||||
ShopManageGroupEntity::getId,
|
||||
group -> group.getGroupName() == null ? "" : group.getGroupName(),
|
||||
(left, right) -> left,
|
||||
LinkedHashMap::new));
|
||||
}
|
||||
|
||||
private DedupeTotalDataItemVo toItemVo(DedupeTotalDataEntity entity, String groupName) {
|
||||
DedupeTotalDataItemVo vo = new DedupeTotalDataItemVo();
|
||||
vo.setId(entity.getId());
|
||||
vo.setDataValue(entity.getDataValue());
|
||||
vo.setGroupId(entity.getGroupId());
|
||||
vo.setGroupName(groupName == null ? "" : groupName);
|
||||
vo.setUploaderUserId(entity.getUploaderUserId());
|
||||
vo.setUsername(entity.getUploaderUsername());
|
||||
vo.setCreatedAt(entity.getCreatedAt());
|
||||
return vo;
|
||||
}
|
||||
|
||||
private record AccessScope(boolean allUsers, Set<Long> userIds) {
|
||||
private record AccessScope(boolean allUsers, Set<Long> groupIds, Set<Long> userIds) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user