feat(phase-3): 后管无侵权只读页——私有鉴权闸+readCompanyIdOrOwn 公司隔离+分页钳制;前端自绘表格页与路由/操作提示/五护栏同轮记账

后端:AdminAppearancePatentCleanItemsController(GET /api/admin/appearance-patent-clean-items,requireCleanItemsAccess 照去重页形状)+ AppearancePatentCleanItemQueryService(page≤10000/size≤100 钳制防 (page-1)*page_size 溢出)+两 VO;PageDefaults 第五种 page_size=10 显式登记。前端:AppearancePatentCleanItemsPage(自绘 table+OldPagination,companyScoped)+api/filter/model 拆件;routes/company-scope/operation-guides 收口。护栏:company-tab-wiring 24 处发送口、date-range-order 分母 21 实例/9 对、date-guard EXEMPT、ChunkRow 无侵权白名单四件(LlmClient 仍是唯一结论值来源)、SourceScan 52 支、G2 WIRED_PAGE_KEYS 第七支。判据修正:columnKey→getColumnKey 对齐代码库命名。
This commit is contained in:
2026-11-10 02:27:50 +08:00
parent 0512359b21
commit 83f1ecf952
22 changed files with 1375 additions and 76 deletions
@@ -40,6 +40,16 @@ public final class PageDefaults {
/** {@link #USER_LIST_PAGE_SIZE} 的数字镜像。 */
public static final int USER_LIST_PAGE_SIZE_INT = 15;
/**
* 外观专利无侵权数据后管只读页默认容量 = 10(v1.3,蓝图 §3.2「page_size 默认 10、上限 100」;
* 上限钳制在 {@code AppearancePatentCleanItemQueryService},不在注解上)。前端 OldPagination
* 首屏同为 10 条/页,两侧对齐。
*/
public static final String CLEAN_ITEMS_PAGE_SIZE = "10";
/** {@link #CLEAN_ITEMS_PAGE_SIZE} 的数字镜像。 */
public static final int CLEAN_ITEMS_PAGE_SIZE_INT = 10;
/** 超管台列表默认容量 = 20。现存 6 处(设备日志、图视任务、通知×2、商品分类×2)。 */
public static final String ADMIN_LIST_PAGE_SIZE = "20";
@@ -0,0 +1,136 @@
package com.nanri.aiimage.modules.appearancepatent.controller;
import com.nanri.aiimage.common.api.ApiResponse;
import com.nanri.aiimage.common.api.PageDefaults;
import com.nanri.aiimage.common.exception.BusinessException;
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
import com.nanri.aiimage.common.security.AdminAuthSupport;
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
import com.nanri.aiimage.common.service.DataReadScope;
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemPageVo;
import com.nanri.aiimage.modules.appearancepatent.service.AppearancePatentCleanItemQueryService;
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 lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
/**
* 后管「外观专利无侵权数据」只读页(v1.3 R2/R3)。数据由出表成功点自动同步落表
* ({@code AppearancePatentCleanSyncService}),本页只读——无写/删/导出接口,
* 下载走既有结果直链/任务中心。
*
* <p>鉴权照去重页私有 {@code requireXxxAccess} 形状:JWT → 内部令牌回退 → 超管放行 →
* 非超管菜单权限(column_key/route_path 双匹配)。菜单行由 V190 只插 columns 不预授权
* ⇒ 默认仅 super_admin 可见可访问,其余角色由超管在权限页手工勾授后才放行。</p>
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/admin/appearance-patent-clean-items")
@Tag(name = "外观专利无侵权数据", description = "后管只读页:出表成功自动同步的「结论=无侵权」明细,按分公司隔离分页查询。")
public class AdminAppearancePatentCleanItemsController {
private static final String CLEAN_ITEMS_COLUMN_KEY = "admin_appearance_patent_clean_items";
private static final String CLEAN_ITEMS_ROUTE_PATH = "patent-center/clean-items";
private final AppearancePatentCleanItemQueryService cleanItemQueryService;
private final AdminAuthSupport adminAuthSupport;
private final PermissionMenuService permissionMenuService;
private final DataReadScope dataReadScope;
@GetMapping
@Operation(summary = "分页查询外观专利无侵权数据", description = "按分公司隔离分页查询同步落表的无侵权明细;"
+ "company_id 只对站点超管生效(显式传才收窄,不传全量),非超管强制本公司。")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", content = @Content(schema = @Schema(implementation = AppearancePatentCleanItemPageVo.class)))
})
public ApiResponse<AppearancePatentCleanItemPageVo> page(
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = PageDefaults.FIRST_PAGE) Long page,
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = PageDefaults.CLEAN_ITEMS_PAGE_SIZE) Long pageSize,
@Parameter(description = "任务号") @RequestParam(name = "task_id", required = false) Long taskId,
@Parameter(description = "ASIN 前缀") @RequestParam(name = "asin", required = false) String asin,
@Parameter(description = "国家代码(如 DE、UK)") @RequestParam(name = "country", required = false) String country,
@Parameter(description = "同步开始日期(包含)")
@RequestParam(name = "start_date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
@Parameter(description = "同步结束日期(包含)")
@RequestParam(name = "end_date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
HttpServletRequest request) {
RequestOperator operator = requireCleanItemsAccess(request);
AdminUserEntity user = operator.user();
// 公司隔离正门是 readCompanyIdOrOwn(同店铺密钥 biz_shop_key 的表形状:归属物化在行
// company_id 列、可见集不靠账号/分组)——超管显式传才收窄、不传全量;非超管强制本公司
// (忽略请求传参)。superAdminScopedCompanyId 对非超管返回 null=按行 company_id 列查询时
// 等于把整张表交给每一家(该方法 javadoc 点名的越权形状),不是本表该走的门。
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
return ApiResponse.success(cleanItemQueryService.page(page, pageSize, taskId, asin, country,
startDate, endDate, scopedCompanyId));
}
private RequestOperator requireCleanItemsAccess(HttpServletRequest request) {
AdminUserEntity operator = resolveOperator(request);
if (operator == null || operator.getId() == null || operator.getId() <= 0) {
throw new BusinessException(403, "无权访问外观专利无侵权数据");
}
boolean superAdmin = DeviceSessionPolicy.isSuper(adminAuthSupport.currentRole(operator));
if (!superAdmin && !hasCleanItemsPermission(operator)) {
throw new BusinessException(403, "无权访问外观专利无侵权数据");
}
return new RequestOperator(operator.getId(), superAdmin, operator);
}
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 hasCleanItemsPermission(AdminUserEntity operator) {
return permissionMenuService.getUserColumnPermissions(operator.getId(), "admin")
.stream()
.anyMatch(item -> CLEAN_ITEMS_COLUMN_KEY.equals(item.getColumnKey())
|| CLEAN_ITEMS_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 record RequestOperator(Long id, boolean superAdmin, AdminUserEntity user) {
}
private boolean isTrustedInternalRequest(String suppliedToken) {
return adminAuthSupport.isTrustedSuppliedToken(suppliedToken);
}
}
@@ -0,0 +1,27 @@
package com.nanri.aiimage.modules.appearancepatent.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/**
* 外观专利无侵权数据分页结果(后管只读页,v1.3 R3;照 {@code DedupeTotalDataPageVo} 形状,
* 但<b>不做</b> keyset {@code nextLastId} 游标——蓝图 Out of Scope 明确本表量级先走 OFFSET 分页)。
*/
@Data
@Schema(description = "外观专利无侵权数据分页结果")
public class AppearancePatentCleanItemPageVo {
@Schema(description = "列表")
private List<AppearancePatentCleanItemVo> items;
@Schema(description = "总数")
private Long total;
@Schema(description = "页码")
private Long page;
@Schema(description = "每页数量")
private Long pageSize;
}
@@ -0,0 +1,76 @@
package com.nanri.aiimage.modules.appearancepatent.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 外观专利无侵权数据明细行(后管只读页,v1.3 R3)。字段与 {@code biz_appearance_patent_clean_item}
* 表列(V189)一一对应——行值是同步服务从 chunk payload 原样落的(不 trim、不转写,AC-1
* 「与 payload 一致」),读侧只做搬运不做二次加工。
*/
@Data
@Schema(description = "外观专利无侵权数据明细行")
public class AppearancePatentCleanItemVo {
@Schema(description = "行 id")
private Long id;
@Schema(description = "来源结果文件行 id(biz_file_result.id)")
private Long resultId;
@Schema(description = "来源任务 id")
private Long taskId;
@Schema(description = "任务 owner 用户 id")
private Long userId;
@Schema(description = "物化归属分公司 id")
private Long companyId;
@Schema(description = "结果内行号")
private Integer rowNo;
@Schema(description = "ASIN")
private String asin;
@Schema(description = "国家代码(如 DE、UK)")
private String country;
@Schema(description = "SKU")
private String sku;
@Schema(description = "品牌")
private String brand;
@Schema(description = "价格")
private String price;
@Schema(description = "商品标题")
private String title;
@Schema(description = "商品主图/检测图 URL")
private String imageUrl;
@Schema(description = "商品详情页 URL(payload 暂无该键,恒为空)")
private String itemUrl;
@Schema(description = "检测结论原值(严格口径下全为无侵权)")
private String conclusion;
@Schema(description = "标题检测原因")
private String titleReason;
@Schema(description = "外观检测原因")
private String appearanceReason;
@Schema(description = "专利检测原因")
private String patentReason;
@Schema(description = "来源文件名")
private String sourceFilename;
@Schema(description = "同步落库时刻")
private LocalDateTime syncedAt;
}
@@ -0,0 +1,101 @@
package com.nanri.aiimage.modules.appearancepatent.service;
import com.nanri.aiimage.common.api.PageDefaults;
import com.nanri.aiimage.common.exception.BusinessException;
import com.nanri.aiimage.modules.appearancepatent.mapper.AppearancePatentCleanItemMapper;
import com.nanri.aiimage.modules.appearancepatent.model.entity.CleanItemEntity;
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemPageVo;
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
/**
* 后管「外观专利无侵权数据」只读查询(v1.3 R2)。
*
* <p>分页钳制是本服务的职责(铁律 15):mapper 的 {@code offset}/{@code limit} 只收钳制后的值
* (Phase 1 定下的单一出口,mapper 不做第二次换算)。钳制形状照关键词服务 CR-18 先例:
* {@code page} 上限 {@link #MAX_PAGE}、{@code page_size} 上限 {@link #MAX_PAGE_SIZE},
* {@code (page-1)*page_size} 最大 999_900,{@code page=Long.MAX_VALUE} 不会把乘积顶成负数
* 生成 {@code LIMIT -N} 的 500 错。</p>
*
* <p>{@code scopedCompanyId} 由控制器经 {@code DataReadScope#readCompanyIdOrOwn} 算好传入
* (本表与店铺密钥同形状:归属物化在行 {@code company_id} 列、可见集不靠账号/分组):
* {@code null} = 超管没选公司、查全量;正数 = 只查该公司(非超管恒为自己的公司)。</p>
*/
@Service
@RequiredArgsConstructor
public class AppearancePatentCleanItemQueryService {
/** 页码上限(CR-18 关键词分页同值):10000 页 x 100 条 = 100 万行封顶,乘积不溢出。 */
private static final long MAX_PAGE = 10_000;
/** 每页条数上限(蓝图 §3.2)。 */
private static final long MAX_PAGE_SIZE = 100;
private final AppearancePatentCleanItemMapper cleanItemMapper;
/**
* 分页查询只读明细({@code synced_at} 倒序)。
*
* <p>过滤面:公司(物化列 eq)、任务号、ASIN 前缀(保 {@code idx_asin} 可用,同去重页口径)、
* 国家、同步起止日期(闭区间,含 end 当天)。</p>
*/
public AppearancePatentCleanItemPageVo page(Long page, Long pageSize, Long taskId, String asin,
String country, LocalDate startDate, LocalDate endDate, Long scopedCompanyId) {
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
throw new BusinessException("开始日期不能晚于结束日期");
}
long safePage = page == null || page < 1 ? 1 : Math.min(page, MAX_PAGE);
long safeSize = pageSize == null ? PageDefaults.CLEAN_ITEMS_PAGE_SIZE_INT
: Math.min(Math.max(pageSize, 1), MAX_PAGE_SIZE);
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
String safeAsin = trimToNull(asin);
String safeCountry = trimToNull(country);
long total = cleanItemMapper.countCleanItems(companyId, taskId, safeAsin, safeCountry, startDate, endDate);
List<CleanItemEntity> rows = total <= 0 ? List.of()
: cleanItemMapper.selectCleanItemPage(companyId, taskId, safeAsin, safeCountry, startDate, endDate,
(safePage - 1) * safeSize, (int) safeSize);
AppearancePatentCleanItemPageVo vo = new AppearancePatentCleanItemPageVo();
vo.setItems(rows.stream().map(AppearancePatentCleanItemQueryService::toVo).toList());
vo.setTotal(total);
vo.setPage(safePage);
vo.setPageSize(safeSize);
return vo;
}
private static String trimToNull(String value) {
if (value == null) {
return null;
}
String trimmed = value.trim();
return trimmed.isEmpty() ? null : trimmed;
}
/** 行值原样搬运(AC-1:与 payload 一致;读侧不加工)。 */
private static AppearancePatentCleanItemVo toVo(CleanItemEntity row) {
AppearancePatentCleanItemVo vo = new AppearancePatentCleanItemVo();
vo.setId(row.getId());
vo.setResultId(row.getResultId());
vo.setTaskId(row.getTaskId());
vo.setUserId(row.getUserId());
vo.setCompanyId(row.getCompanyId());
vo.setRowNo(row.getRowNo());
vo.setAsin(row.getAsin());
vo.setCountry(row.getCountry());
vo.setSku(row.getSku());
vo.setBrand(row.getBrand());
vo.setPrice(row.getPrice());
vo.setTitle(row.getTitle());
vo.setImageUrl(row.getImageUrl());
vo.setItemUrl(row.getItemUrl());
vo.setConclusion(row.getConclusion());
vo.setTitleReason(row.getTitleReason());
vo.setAppearanceReason(row.getAppearanceReason());
vo.setPatentReason(row.getPatentReason());
vo.setSourceFilename(row.getSourceFilename());
vo.setSyncedAt(row.getSyncedAt());
return vo;
}
}