处理后台新需求
This commit is contained in:
+139
-7
@@ -1,19 +1,25 @@
|
||||
package com.nanri.aiimage.modules.invalidasin.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.modules.invalidasin.model.dto.InvalidAsinDataCreateRequest;
|
||||
import com.nanri.aiimage.modules.invalidasin.model.dto.InvalidAsinDataUpdateRequest;
|
||||
import com.nanri.aiimage.modules.invalidasin.model.vo.InvalidAsinDataItemVo;
|
||||
import com.nanri.aiimage.modules.invalidasin.model.vo.InvalidAsinDataPageVo;
|
||||
import com.nanri.aiimage.modules.invalidasin.service.InvalidAsinDataService;
|
||||
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;
|
||||
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.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -24,13 +30,29 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/admin/invalid-asin-data")
|
||||
@Tag(name = "不符合ASIN数据", description = "维护不符合ASIN数据列表,支持增删改查。")
|
||||
public class InvalidAsinDataController {
|
||||
|
||||
private static final String INVALID_ASIN_DATA_COLUMN_KEY = "admin_invalid_asin_data";
|
||||
private static final String INVALID_ASIN_DATA_ROUTE_PATH = "invalid-asin-data";
|
||||
|
||||
@Value("${aiimage.security.internal-token:}")
|
||||
private String internalToken;
|
||||
|
||||
@Value("${aiimage.security.internal-token-file:}")
|
||||
private String internalTokenFile;
|
||||
|
||||
private final InvalidAsinDataService invalidAsinDataService;
|
||||
private final AdminAuthSupport adminAuthSupport;
|
||||
private final PermissionMenuService permissionMenuService;
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "分页查询不符合ASIN数据", description = "分页查询不符合ASIN数据,支持按 ASIN/品牌 模糊搜索。")
|
||||
@@ -40,8 +62,12 @@ public class InvalidAsinDataController {
|
||||
public ApiResponse<InvalidAsinDataPageVo> page(
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "15") Long pageSize,
|
||||
@Parameter(description = "模糊搜索关键字") @RequestParam(required = false) String keyword) {
|
||||
return ApiResponse.success(invalidAsinDataService.page(page, pageSize, keyword));
|
||||
@Parameter(description = "模糊搜索关键字") @RequestParam(required = false) String keyword,
|
||||
@Parameter(description = "分组 ID") @RequestParam(required = false) Long groupId,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireInvalidAsinDataAccess(request);
|
||||
return ApiResponse.success(invalidAsinDataService.page(
|
||||
page, pageSize, keyword, groupId, operator.id(), operator.superAdmin()));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@@ -50,8 +76,12 @@ public class InvalidAsinDataController {
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "创建成功", content = @Content(schema = @Schema(implementation = InvalidAsinDataItemVo.class))),
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "参数不合法或数据重复")
|
||||
})
|
||||
public ApiResponse<InvalidAsinDataItemVo> create(@Valid @RequestBody InvalidAsinDataCreateRequest request) {
|
||||
return ApiResponse.success("创建成功", invalidAsinDataService.create(request));
|
||||
public ApiResponse<InvalidAsinDataItemVo> create(
|
||||
HttpServletRequest httpRequest,
|
||||
@Valid @RequestBody InvalidAsinDataCreateRequest request) {
|
||||
RequestOperator operator = requireInvalidAsinDataAccess(httpRequest);
|
||||
return ApiResponse.success("创建成功", invalidAsinDataService.create(
|
||||
request, operator.id(), operator.superAdmin()));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
@@ -63,8 +93,11 @@ public class InvalidAsinDataController {
|
||||
})
|
||||
public ApiResponse<InvalidAsinDataItemVo> update(
|
||||
@Parameter(description = "主键ID", required = true) @PathVariable Long id,
|
||||
HttpServletRequest httpRequest,
|
||||
@Valid @RequestBody InvalidAsinDataUpdateRequest request) {
|
||||
return ApiResponse.success("更新成功", invalidAsinDataService.update(id, request));
|
||||
RequestOperator operator = requireInvalidAsinDataAccess(httpRequest);
|
||||
return ApiResponse.success("更新成功", invalidAsinDataService.update(
|
||||
id, request, operator.id(), operator.superAdmin()));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@@ -73,8 +106,107 @@ public class InvalidAsinDataController {
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "删除成功"),
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "数据不存在")
|
||||
})
|
||||
public ApiResponse<Void> delete(@Parameter(description = "主键ID", required = true) @PathVariable Long id) {
|
||||
invalidAsinDataService.delete(id);
|
||||
public ApiResponse<Void> delete(
|
||||
@Parameter(description = "主键ID", required = true) @PathVariable Long id,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireInvalidAsinDataAccess(request);
|
||||
invalidAsinDataService.delete(id, operator.id(), operator.superAdmin());
|
||||
return ApiResponse.success("删除成功", null);
|
||||
}
|
||||
|
||||
private RequestOperator requireInvalidAsinDataAccess(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 && !hasInvalidAsinDataPermission(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 hasInvalidAsinDataPermission(AdminUserEntity operator) {
|
||||
return permissionMenuService.getUserColumnPermissions(operator.getId(), "admin")
|
||||
.stream()
|
||||
.anyMatch(item -> INVALID_ASIN_DATA_COLUMN_KEY.equals(item.getColumnKey())
|
||||
|| INVALID_ASIN_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.invalidasin.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;
|
||||
|
||||
@@ -17,4 +18,8 @@ public class InvalidAsinDataCreateRequest {
|
||||
@Size(max = 128, message = "品牌长度不能超过128个字符")
|
||||
@Schema(description = "品牌名称")
|
||||
private String brand;
|
||||
|
||||
@NotNull(message = "请选择分组")
|
||||
@Schema(description = "分组 ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Long groupId;
|
||||
}
|
||||
|
||||
+3
@@ -17,4 +17,7 @@ public class InvalidAsinDataUpdateRequest {
|
||||
@Size(max = 128, message = "品牌长度不能超过128个字符")
|
||||
@Schema(description = "品牌名称")
|
||||
private String brand;
|
||||
|
||||
@Schema(description = "分组 ID;自动导入数据无需填写")
|
||||
private Long groupId;
|
||||
}
|
||||
|
||||
+2
@@ -15,6 +15,8 @@ public class InvalidAsinDataEntity {
|
||||
private Long id;
|
||||
private String dataValue;
|
||||
private String brand;
|
||||
private Long groupId;
|
||||
private String recordSource;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
|
||||
+9
@@ -18,6 +18,15 @@ public class InvalidAsinDataItemVo {
|
||||
@Schema(description = "品牌名称")
|
||||
private String brand;
|
||||
|
||||
@Schema(description = "分组 ID")
|
||||
private Long groupId;
|
||||
|
||||
@Schema(description = "分组名称")
|
||||
private String groupName;
|
||||
|
||||
@Schema(description = "记录来源:MANUAL/AUTO")
|
||||
private String recordSource;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
|
||||
+132
-12
@@ -8,20 +8,30 @@ import com.nanri.aiimage.modules.invalidasin.model.dto.InvalidAsinDataUpdateRequ
|
||||
import com.nanri.aiimage.modules.invalidasin.model.entity.InvalidAsinDataEntity;
|
||||
import com.nanri.aiimage.modules.invalidasin.model.vo.InvalidAsinDataItemVo;
|
||||
import com.nanri.aiimage.modules.invalidasin.model.vo.InvalidAsinDataPageVo;
|
||||
import com.nanri.aiimage.modules.shopkey.model.entity.ShopManageGroupEntity;
|
||||
import com.nanri.aiimage.modules.shopkey.service.ShopManageGroupService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class InvalidAsinDataService {
|
||||
|
||||
private final InvalidAsinDataMapper invalidAsinDataMapper;
|
||||
public static final String RECORD_SOURCE_MANUAL = "MANUAL";
|
||||
public static final String RECORD_SOURCE_AUTO = "AUTO";
|
||||
|
||||
public InvalidAsinDataPageVo page(long page, long pageSize, String keyword) {
|
||||
private final InvalidAsinDataMapper invalidAsinDataMapper;
|
||||
private final ShopManageGroupService shopManageGroupService;
|
||||
|
||||
public InvalidAsinDataPageVo page(long page, long pageSize, String keyword, Long groupId, Long operatorId, boolean superAdmin) {
|
||||
long safePage = Math.max(page, 1);
|
||||
long safePageSize = Math.min(Math.max(pageSize, 1), 100);
|
||||
String safeKeyword = keyword == null ? "" : keyword.trim();
|
||||
@@ -31,11 +41,28 @@ public class InvalidAsinDataService {
|
||||
.or()
|
||||
.like(InvalidAsinDataEntity::getBrand, safeKeyword))
|
||||
.orderByDesc(InvalidAsinDataEntity::getId);
|
||||
if (!superAdmin) {
|
||||
Long fixedGroupId = resolveFixedAccessibleGroupId(operatorId);
|
||||
if (fixedGroupId == null) {
|
||||
query.eq(InvalidAsinDataEntity::getId, -1L);
|
||||
} else {
|
||||
query.eq(InvalidAsinDataEntity::getRecordSource, RECORD_SOURCE_MANUAL)
|
||||
.eq(InvalidAsinDataEntity::getGroupId, fixedGroupId);
|
||||
}
|
||||
} else if (groupId != null && groupId > 0) {
|
||||
query.eq(InvalidAsinDataEntity::getGroupId, groupId);
|
||||
}
|
||||
Long total = invalidAsinDataMapper.selectCount(query);
|
||||
List<InvalidAsinDataItemVo> items = invalidAsinDataMapper
|
||||
.selectList(query.last("LIMIT " + ((safePage - 1) * safePageSize) + ", " + safePageSize))
|
||||
.stream()
|
||||
.map(this::toItemVo)
|
||||
List<InvalidAsinDataEntity> rows = invalidAsinDataMapper
|
||||
.selectList(query.last("LIMIT " + ((safePage - 1) * safePageSize) + ", " + safePageSize));
|
||||
Map<Long, String> groupNameById = shopManageGroupService.buildGroupNameMap(rows.stream()
|
||||
.map(InvalidAsinDataEntity::getGroupId)
|
||||
.filter(rowGroupId -> rowGroupId != null && rowGroupId > 0)
|
||||
.distinct()
|
||||
.toList());
|
||||
List<InvalidAsinDataItemVo> items = rows.stream()
|
||||
.map(entity -> toItemVo(entity,
|
||||
entity.getGroupId() == null ? "" : groupNameById.getOrDefault(entity.getGroupId(), "")))
|
||||
.toList();
|
||||
InvalidAsinDataPageVo vo = new InvalidAsinDataPageVo();
|
||||
vo.setItems(items);
|
||||
@@ -46,35 +73,63 @@ public class InvalidAsinDataService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public InvalidAsinDataItemVo create(InvalidAsinDataCreateRequest request) {
|
||||
public InvalidAsinDataItemVo create(InvalidAsinDataCreateRequest request, Long operatorId, boolean superAdmin) {
|
||||
ShopManageGroupEntity group = resolveManualWriteGroup(request.getGroupId(), operatorId, superAdmin);
|
||||
String dataValue = normalizeRequired(request.getDataValue(), "ASIN 不能为空");
|
||||
String brand = normalizeRequired(request.getBrand(), "品牌不能为空").toLowerCase(Locale.ROOT);
|
||||
ensureUnique(dataValue, null);
|
||||
InvalidAsinDataEntity entity = new InvalidAsinDataEntity();
|
||||
entity.setDataValue(dataValue);
|
||||
entity.setBrand(brand);
|
||||
entity.setGroupId(group.getId());
|
||||
entity.setRecordSource(RECORD_SOURCE_MANUAL);
|
||||
invalidAsinDataMapper.insert(entity);
|
||||
return toItemVo(getById(entity.getId()));
|
||||
return toItemVo(getById(entity.getId()), group.getGroupName());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public InvalidAsinDataItemVo update(Long id, InvalidAsinDataUpdateRequest request) {
|
||||
public InvalidAsinDataItemVo update(Long id, InvalidAsinDataUpdateRequest request, Long operatorId, boolean superAdmin) {
|
||||
InvalidAsinDataEntity entity = getById(id);
|
||||
ShopManageGroupEntity fixedGroup = ensureRecordAccess(entity, operatorId, superAdmin);
|
||||
ShopManageGroupEntity writeGroup = null;
|
||||
if (isManualRecord(entity)) {
|
||||
Long requestedGroupId = requireGroupId(request.getGroupId());
|
||||
writeGroup = superAdmin
|
||||
? shopManageGroupService.getAccessibleById(requestedGroupId, operatorId, true)
|
||||
: resolveLockedGroup(requestedGroupId, fixedGroup);
|
||||
}
|
||||
String dataValue = normalizeRequired(request.getDataValue(), "ASIN 不能为空");
|
||||
String brand = normalizeRequired(request.getBrand(), "品牌不能为空").toLowerCase(Locale.ROOT);
|
||||
ensureUnique(dataValue, id);
|
||||
entity.setDataValue(dataValue);
|
||||
entity.setBrand(brand);
|
||||
String groupName = "";
|
||||
if (writeGroup != null) {
|
||||
entity.setGroupId(writeGroup.getId());
|
||||
groupName = writeGroup.getGroupName();
|
||||
}
|
||||
invalidAsinDataMapper.updateById(entity);
|
||||
return toItemVo(getById(id));
|
||||
return toItemVo(getById(id), groupName);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void delete(Long id) {
|
||||
public void delete(Long id, Long operatorId, boolean superAdmin) {
|
||||
InvalidAsinDataEntity entity = getById(id);
|
||||
ensureRecordAccess(entity, operatorId, superAdmin);
|
||||
invalidAsinDataMapper.deleteById(entity.getId());
|
||||
}
|
||||
|
||||
private ShopManageGroupEntity resolveManualWriteGroup(Long requestedGroupId, Long operatorId, boolean superAdmin) {
|
||||
Long normalizedRequestedGroupId = requireGroupId(requestedGroupId);
|
||||
if (superAdmin) {
|
||||
return shopManageGroupService.getAccessibleById(
|
||||
normalizedRequestedGroupId, operatorId, true);
|
||||
}
|
||||
Long fixedGroupId = requireFixedAccessibleGroupId(operatorId);
|
||||
ensureRequestedLockedGroup(normalizedRequestedGroupId, fixedGroupId);
|
||||
return shopManageGroupService.getAccessibleById(fixedGroupId, operatorId, false);
|
||||
}
|
||||
|
||||
private InvalidAsinDataEntity getById(Long id) {
|
||||
InvalidAsinDataEntity entity = invalidAsinDataMapper.selectById(id);
|
||||
if (entity == null) {
|
||||
@@ -115,11 +170,76 @@ public class InvalidAsinDataService {
|
||||
.replaceAll("\\s+", " ");
|
||||
}
|
||||
|
||||
private InvalidAsinDataItemVo toItemVo(InvalidAsinDataEntity entity) {
|
||||
private ShopManageGroupEntity ensureRecordAccess(InvalidAsinDataEntity entity, Long operatorId, boolean superAdmin) {
|
||||
if (superAdmin) {
|
||||
return null;
|
||||
}
|
||||
if (!isManualRecord(entity) || entity.getGroupId() == null || entity.getGroupId() <= 0) {
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "无权操作该品牌数据");
|
||||
}
|
||||
Long fixedGroupId = resolveFixedAccessibleGroupId(operatorId);
|
||||
if (fixedGroupId == null || !fixedGroupId.equals(entity.getGroupId())) {
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "无权操作非固定分组数据");
|
||||
}
|
||||
try {
|
||||
return shopManageGroupService.getAccessibleById(fixedGroupId, operatorId, false);
|
||||
} catch (BusinessException exception) {
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "无权操作该品牌数据");
|
||||
}
|
||||
}
|
||||
|
||||
private Long requireFixedAccessibleGroupId(Long operatorId) {
|
||||
Long fixedGroupId = resolveFixedAccessibleGroupId(operatorId);
|
||||
if (fixedGroupId == null) {
|
||||
throw new BusinessException("当前用户没有可访问的分组");
|
||||
}
|
||||
return fixedGroupId;
|
||||
}
|
||||
|
||||
private Long resolveFixedAccessibleGroupId(Long operatorId) {
|
||||
Set<Long> accessibleGroupIds = shopManageGroupService.listAccessibleGroupIds(operatorId, false);
|
||||
if (accessibleGroupIds == null) {
|
||||
return null;
|
||||
}
|
||||
return accessibleGroupIds.stream()
|
||||
.filter(groupId -> groupId != null && groupId > 0)
|
||||
.min(Long::compareTo)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private ShopManageGroupEntity resolveLockedGroup(Long requestedGroupId, ShopManageGroupEntity fixedGroup) {
|
||||
if (fixedGroup == null || fixedGroup.getId() == null) {
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "无权操作非固定分组数据");
|
||||
}
|
||||
ensureRequestedLockedGroup(requestedGroupId, fixedGroup.getId());
|
||||
return fixedGroup;
|
||||
}
|
||||
|
||||
private void ensureRequestedLockedGroup(Long requestedGroupId, Long fixedGroupId) {
|
||||
if (fixedGroupId == null || !fixedGroupId.equals(requestedGroupId)) {
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "无权操作非固定分组数据");
|
||||
}
|
||||
}
|
||||
|
||||
private Long requireGroupId(Long groupId) {
|
||||
if (groupId == null || groupId <= 0) {
|
||||
throw new BusinessException("请选择分组");
|
||||
}
|
||||
return groupId;
|
||||
}
|
||||
|
||||
private boolean isManualRecord(InvalidAsinDataEntity entity) {
|
||||
return entity != null && RECORD_SOURCE_MANUAL.equalsIgnoreCase(normalizeText(entity.getRecordSource()));
|
||||
}
|
||||
|
||||
private InvalidAsinDataItemVo toItemVo(InvalidAsinDataEntity entity, String groupName) {
|
||||
InvalidAsinDataItemVo vo = new InvalidAsinDataItemVo();
|
||||
vo.setId(entity.getId());
|
||||
vo.setDataValue(entity.getDataValue());
|
||||
vo.setBrand(entity.getBrand());
|
||||
vo.setGroupId(entity.getGroupId());
|
||||
vo.setGroupName(groupName == null ? "" : groupName);
|
||||
vo.setRecordSource(isManualRecord(entity) ? RECORD_SOURCE_MANUAL : RECORD_SOURCE_AUTO);
|
||||
vo.setCreatedAt(entity.getCreatedAt());
|
||||
return vo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user