feat(appearance-patent): 外观专利数据库改为按主管划分的一主管一卡(2026-11-11 客户「应该是只显示一个卡片的才对」「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」)——后端新增 GET /supervisors 主管聚合(组键=与「所属主管」列同源的归属表达式:主管本人取自己、普通账户取创建人、读不到归同一 NULL 组;返回条数/任务数/最近任务号/最近同步/国家集,total 是主管数),卡片[下载]走 /export 新增 supervisor_user_id 按同一表达式收窄(不近似成 user_id OR created_by_id);共享 cleanItemConds 前移到 i. 前缀并复用(铁律 20 SQL 下推);后管页面由「每明细一卡」改为「一主管一卡」(卡头主管名/条数/任务/国家/最新 + 下载,对齐店铺数据记录一店一卡),明细分页卡片下架(3488 条铺成几千张卡是客户不要的形态),明细仍走 /export 表格看;护栏台账同轮更新(XML_SELECT_TOTAL 105→109、XML_STATEMENT_TOTAL 151→155、PageDefaults 56→58、SourceScan 52→55/vo 11→14、wiring 新增 /supervisors 发送口);后端 test-compile rc=0、controller 22 例绿+6 支护栏绿,前端 vue-tsc rc=0、mount 13/13、三支 node --test 21/21
This commit is contained in:
+34
-2
@@ -9,6 +9,7 @@ import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
import com.nanri.aiimage.common.support.DownloadHeaderUtil;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemPageVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorPageVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.AppearancePatentCleanItemQueryService;
|
||||
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -93,6 +94,31 @@ public class AdminAppearancePatentCleanItemsController {
|
||||
startDate, endDate, groupId, scopedCompanyId));
|
||||
}
|
||||
|
||||
@GetMapping("/supervisors")
|
||||
@Operation(summary = "按主管聚合查询(一主管一卡)", description = "后管「外观专利数据库」页的卡片面"
|
||||
+ "(2026-11-11 客户口径「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」):按主管"
|
||||
+ "归组返回条数/任务数/最近同步时间/国家集,total 是主管数;过滤面与明细分页同一段 SQL 谓词"
|
||||
+ "(公司/国家/同步起止/分组用户集),公司隔离走同一 readCompanyIdOrOwn 正门。")
|
||||
public ApiResponse<AppearancePatentSupervisorPageVo> supervisors(
|
||||
@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 = "国家代码(如 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 = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireCleanItemsAccess(request);
|
||||
AdminUserEntity user = operator.user();
|
||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
||||
return ApiResponse.success(cleanItemQueryService.supervisorPage(page, pageSize, country,
|
||||
startDate, endDate, groupId, scopedCompanyId));
|
||||
}
|
||||
|
||||
@GetMapping("/export")
|
||||
@Operation(summary = "导出外观专利数据库 Excel", description = "与分页查询同一过滤面(任务号/ASIN/国家/同步起止日期/分组),"
|
||||
+ "公司隔离走同一正门:company_id 只对站点超管生效(显式传才收窄,不传全量),非超管强制本公司。"
|
||||
@@ -108,6 +134,9 @@ public class AdminAppearancePatentCleanItemsController {
|
||||
@RequestParam(name = "end_date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
|
||||
@Parameter(description = "分组 id:按该分组「组长本人+名下子账户」的用户集过滤(主管=组长)")
|
||||
@RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "主管用户 id:只导出该主管名下明细(卡片上的「下载」,"
|
||||
+ "归属口径与主管聚合卡片同一表达式)")
|
||||
@RequestParam(name = "supervisor_user_id", required = false) Long supervisorUserId,
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireCleanItemsAccess(request);
|
||||
@@ -115,8 +144,11 @@ public class AdminAppearancePatentCleanItemsController {
|
||||
// 导出与分页共用 readCompanyIdOrOwn 正门(同 page 的口径注释):超管显式传才收窄、
|
||||
// 不传全量;非超管强制本公司(忽略请求传参),绝不让导出绕过页签的公司隔离。
|
||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
||||
byte[] bytes = cleanItemQueryService.export(taskId, asin, country, startDate, endDate, groupId,
|
||||
scopedCompanyId);
|
||||
byte[] bytes = supervisorUserId != null
|
||||
? cleanItemQueryService.exportBySupervisor(supervisorUserId, country, startDate, endDate, groupId,
|
||||
scopedCompanyId)
|
||||
: cleanItemQueryService.export(taskId, asin, country, startDate, endDate, groupId,
|
||||
scopedCompanyId);
|
||||
String filename = "外观专利数据库-" + LocalDateTime.now().format(EXPORT_FILENAME_FORMATTER) + ".xlsx";
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, DownloadHeaderUtil.contentDisposition(filename))
|
||||
|
||||
+52
@@ -2,6 +2,7 @@ package com.nanri.aiimage.modules.appearancepatent.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.entity.CleanItemEntity;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorSummaryVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -59,4 +60,55 @@ public interface AppearancePatentCleanItemMapper extends BaseMapper<CleanItemEnt
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("offset") long offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
/**
|
||||
* 主管聚合分组数(2026-11-11「按主管划分」):组键由 XML 的 {@code supervisorIdExpr} 现算,
|
||||
* 与读侧 {@code fillSupervisorNames} 同口径(主管本人取自己、普通账户取创建人、读不到归 NULL 组)。
|
||||
* 过滤面与 {@link #selectSupervisorSummaries} 完全同一段 {@code cleanItemConds}。
|
||||
*/
|
||||
long countSupervisors(@Param("companyId") Long companyId,
|
||||
@Param("taskId") Long taskId,
|
||||
@Param("asin") String asin,
|
||||
@Param("country") String country,
|
||||
@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("userIds") List<Long> userIds);
|
||||
|
||||
/**
|
||||
* 主管聚合分页(一主管一行:条数/任务数/最近任务号/最近同步时间/国家集)。
|
||||
*
|
||||
* <p>{@code offset}/{@code limit} 同样只收服务侧钳制后的值(铁律 15)。国家列是
|
||||
* GROUP_CONCAT 出来的 csv,服务侧拆列表(读侧不加工明细值,只在这个聚合面上做一次收集)。</p>
|
||||
*/
|
||||
List<AppearancePatentSupervisorSummaryVo> selectSupervisorSummaries(@Param("companyId") Long companyId,
|
||||
@Param("taskId") Long taskId,
|
||||
@Param("asin") String asin,
|
||||
@Param("country") String country,
|
||||
@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("offset") long offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
/** 单个主管名下的明细行数(卡片「下载」的导出口,先卡上限再取数)。 */
|
||||
long countSupervisorItems(@Param("companyId") Long companyId,
|
||||
@Param("taskId") Long taskId,
|
||||
@Param("asin") String asin,
|
||||
@Param("country") String country,
|
||||
@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("supervisorUserId") Long supervisorUserId);
|
||||
|
||||
/** 单个主管名下的明细页(导出全量用 offset=0、limit=上限;与明细分页同一过滤面)。 */
|
||||
List<CleanItemEntity> selectSupervisorItems(@Param("companyId") Long companyId,
|
||||
@Param("taskId") Long taskId,
|
||||
@Param("asin") String asin,
|
||||
@Param("country") String country,
|
||||
@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("supervisorUserId") Long supervisorUserId,
|
||||
@Param("offset") long offset,
|
||||
@Param("limit") int limit);
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主管卡片分页信封(2026-11-11「按主管划分」):形状与明细页一致(items/total/page/pageSize),
|
||||
* total 是<b>主管数</b>而不是明细条数——前端分页条按主管翻页。
|
||||
*/
|
||||
@Data
|
||||
public class AppearancePatentSupervisorPageVo {
|
||||
|
||||
private List<AppearancePatentSupervisorVo> items;
|
||||
|
||||
private Long total;
|
||||
|
||||
private Long page;
|
||||
|
||||
private Long pageSize;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 主管聚合的 mapper 行(2026-11-11「按主管划分」):SQL 侧 {@code GROUP BY supervisorIdExpr}
|
||||
* 的原始读数,只负责搬运,不在这一层加工国家 csv(拆列表在服务层,避免 mapper 里做字符串处理)。
|
||||
*/
|
||||
@Data
|
||||
public class AppearancePatentSupervisorSummaryVo {
|
||||
|
||||
/** 主管用户 id(读不到主管的行=null,聚合时归入同一个「未知主管」组)。 */
|
||||
private Long supervisorId;
|
||||
|
||||
/** 该主管名下「无侵权」明细条数。 */
|
||||
private Long itemCount;
|
||||
|
||||
/** 该主管名下涉及的任务数(COUNT(DISTINCT task_id))。 */
|
||||
private Long taskCount;
|
||||
|
||||
/** 该主管名下最近一次涉及的任务号(MAX(task_id),卡片的「任务」行用它)。 */
|
||||
private Long lastTaskId;
|
||||
|
||||
/** 该主管名下最近一次同步时间(MAX(synced_at),卡片的「最新」列与默认排序键)。 */
|
||||
private LocalDateTime lastSyncedAt;
|
||||
|
||||
/** 国家集 csv(GROUP_CONCAT,服务层拆成列表;原样搬运不做翻译)。 */
|
||||
private String countryCsv;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后管「外观专利数据库」页的一个主管卡片(2026-11-11 客户口径「获取店铺那边是按店铺做成卡片,
|
||||
* 我们这边就是按主管划分」):一主管一卡,卡内是该主管名下的汇总,不再铺明细。
|
||||
*
|
||||
* <p>{@code supervisorName} 是唯一的读侧加工列(同明细分页的「所属主管」口径:主管本人取自己、
|
||||
* 普通账户取创建人),读不到时为空、前端展示 -(铁律 30 不猜名)。</p>
|
||||
*/
|
||||
@Data
|
||||
public class AppearancePatentSupervisorVo {
|
||||
|
||||
/** 主管用户 id;null=读不到主管的那一组(该卡不提供按主管下载)。 */
|
||||
private Long supervisorId;
|
||||
|
||||
/** 主管名(读不到为空)。 */
|
||||
private String supervisorName;
|
||||
|
||||
/** 无侵权明细条数。 */
|
||||
private Long itemCount;
|
||||
|
||||
/** 涉及任务数。 */
|
||||
private Long taskCount;
|
||||
|
||||
/** 最近涉及的任务号。 */
|
||||
private Long lastTaskId;
|
||||
|
||||
/** 最近同步时间。 */
|
||||
private LocalDateTime lastSyncedAt;
|
||||
|
||||
/** 涉及国家码集(原样搬运,前端用自己的国家字典翻中文)。 */
|
||||
private List<String> countryCodes;
|
||||
}
|
||||
+130
@@ -10,6 +10,9 @@ import com.nanri.aiimage.modules.appearancepatent.mapper.AppearancePatentCleanIt
|
||||
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 com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorPageVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorSummaryVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
@@ -20,6 +23,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -136,6 +140,101 @@ public class AppearancePatentCleanItemQueryService {
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主管聚合分页(2026-11-11 客户「要按主管分组显示」「应该是只显示一个卡片的才对」「获取店铺
|
||||
* 那边是按店铺做成卡片 我们这边就是按主管划分」):一主管一卡,total 是<b>主管数</b>,
|
||||
* 不再按明细铺页(3488 条明细铺成卡片等于整页上千张卡)。
|
||||
*
|
||||
* <p>组键与「所属主管」列同源(XML {@code supervisorIdExpr} ↔ {@link #fillSupervisorNames}):
|
||||
* 主管本人跑的单归自己、普通账户归创建人、读不到归同一个 NULL 组(该组 supervisorId 为 null,
|
||||
* 前端展示 - 且不提供按主管下载)。过滤面复用共享 {@code cleanItemConds}(公司/国家/同步起止/
|
||||
* 分组用户集),SQL 侧下推,铁律 20。</p>
|
||||
*/
|
||||
public AppearancePatentSupervisorPageVo supervisorPage(Long page, Long pageSize, String country,
|
||||
LocalDate startDate, LocalDate endDate, Long groupId, 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 safeCountry = trimToNull(country);
|
||||
List<Long> groupUserIds = groupUserIds(groupId);
|
||||
AppearancePatentSupervisorPageVo vo = new AppearancePatentSupervisorPageVo();
|
||||
vo.setPage(safePage);
|
||||
vo.setPageSize(safeSize);
|
||||
if (groupUserIds != null && groupUserIds.isEmpty()) {
|
||||
vo.setItems(List.of());
|
||||
vo.setTotal(0L);
|
||||
return vo;
|
||||
}
|
||||
long total = cleanItemMapper.countSupervisors(companyId, null, null, safeCountry, startDate, endDate,
|
||||
groupUserIds);
|
||||
if (total <= 0) {
|
||||
vo.setItems(List.of());
|
||||
vo.setTotal(0L);
|
||||
return vo;
|
||||
}
|
||||
List<AppearancePatentSupervisorSummaryVo> summaries = cleanItemMapper.selectSupervisorSummaries(
|
||||
companyId, null, null, safeCountry, startDate, endDate, groupUserIds,
|
||||
(safePage - 1) * safeSize, (int) safeSize);
|
||||
vo.setItems(toSupervisorVos(summaries));
|
||||
vo.setTotal(total);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/** 聚合行 → 卡片:主管名批量富化(与明细同一 {@code fillSupervisorNames} 口径的两步批量查询),
|
||||
* 国家 csv 拆列表(空值不下发)。 */
|
||||
private List<AppearancePatentSupervisorVo> toSupervisorVos(List<AppearancePatentSupervisorSummaryVo> summaries) {
|
||||
List<AppearancePatentSupervisorVo> items = new ArrayList<>(summaries.size());
|
||||
for (AppearancePatentSupervisorSummaryVo summary : summaries) {
|
||||
AppearancePatentSupervisorVo vo = new AppearancePatentSupervisorVo();
|
||||
vo.setSupervisorId(summary.getSupervisorId());
|
||||
vo.setItemCount(summary.getItemCount());
|
||||
vo.setTaskCount(summary.getTaskCount());
|
||||
vo.setLastTaskId(summary.getLastTaskId());
|
||||
vo.setLastSyncedAt(summary.getLastSyncedAt());
|
||||
vo.setCountryCodes(splitCountryCsv(summary.getCountryCsv()));
|
||||
items.add(vo);
|
||||
}
|
||||
List<Long> supervisorIds = items.stream()
|
||||
.map(AppearancePatentSupervisorVo::getSupervisorId)
|
||||
.filter(id -> id != null)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (supervisorIds.isEmpty()) {
|
||||
return items;
|
||||
}
|
||||
Map<Long, String> namesById = new LinkedHashMap<>();
|
||||
for (AdminUserEntity user : adminUserMapper.selectBatchIds(supervisorIds)) {
|
||||
String username = trimmed(user.getUsername());
|
||||
if (user.getId() != null && !username.isEmpty()) {
|
||||
namesById.put(user.getId(), username);
|
||||
}
|
||||
}
|
||||
for (AppearancePatentSupervisorVo vo : items) {
|
||||
if (vo.getSupervisorId() != null) {
|
||||
vo.setSupervisorName(namesById.get(vo.getSupervisorId()));
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private static List<String> splitCountryCsv(String csv) {
|
||||
if (csv == null || csv.isBlank()) {
|
||||
return List.of();
|
||||
}
|
||||
List<String> codes = new ArrayList<>();
|
||||
for (String part : csv.split(",")) {
|
||||
String code = part.trim();
|
||||
if (!code.isEmpty()) {
|
||||
codes.add(code);
|
||||
}
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出当前过滤面全量明细为 xlsx 字节(控制器直接回 {@code ResponseEntity<byte[]>},
|
||||
* 口径同 {@code QueryAsinService.export})。
|
||||
@@ -171,6 +270,37 @@ public class AppearancePatentCleanItemQueryService {
|
||||
return writeExportWorkbook(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出<b>单个主管</b>名下明细为 xlsx 字节(2026-11-11 卡片上的「下载」):过滤面=当前页签
|
||||
* (公司/国家/同步起止/分组)+主管归属条件(与卡片分组同一表达式,不是 user_id OR created_by_id
|
||||
* 的近似写法)。上限与全量导出同一条 {@link #EXPORT_MAX_ROWS}。{@code supervisorUserId} 为空
|
||||
* 按「不按主管收窄」处理(控制器不会走到这里,纯防呆)。
|
||||
*/
|
||||
public byte[] exportBySupervisor(Long supervisorUserId, String country, LocalDate startDate,
|
||||
LocalDate endDate, Long groupId, Long scopedCompanyId) {
|
||||
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
|
||||
throw new BusinessException("开始日期不能晚于结束日期");
|
||||
}
|
||||
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
|
||||
String safeCountry = trimToNull(country);
|
||||
List<Long> groupUserIds = groupUserIds(groupId);
|
||||
if (groupUserIds != null && groupUserIds.isEmpty()) {
|
||||
return writeExportWorkbook(List.of());
|
||||
}
|
||||
long total = cleanItemMapper.countSupervisorItems(companyId, null, null, safeCountry, startDate, endDate,
|
||||
groupUserIds, supervisorUserId);
|
||||
if (total > EXPORT_MAX_ROWS) {
|
||||
throw new BusinessException("该主管的无侵权数据共 " + total + " 行,超过导出上限 " + EXPORT_MAX_ROWS
|
||||
+ " 行,请缩小筛选范围后重试");
|
||||
}
|
||||
List<CleanItemEntity> rows = total <= 0 ? List.of()
|
||||
: cleanItemMapper.selectSupervisorItems(companyId, null, null, safeCountry, startDate, endDate,
|
||||
groupUserIds, supervisorUserId, 0L, (int) EXPORT_MAX_ROWS);
|
||||
List<AppearancePatentCleanItemVo> items = rows.stream().map(AppearancePatentCleanItemQueryService::toVo).toList();
|
||||
fillSupervisorNames(items);
|
||||
return writeExportWorkbook(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组筛选 → 该分组「组长本人+名下子账户」的用户 id 集({@code null} = 没选分组、不过滤);
|
||||
* id 非法(≤0)按没选处理,不把它当全量之外的第三档。解析交给
|
||||
|
||||
+88
-13
@@ -9,18 +9,41 @@
|
||||
全部走 #{} 占位符。offset/limit 必须是服务侧钳制后的值(铁律 15)。 -->
|
||||
|
||||
<sql id="cleanItemConds">
|
||||
<if test="companyId != null">AND company_id = #{companyId}</if>
|
||||
<if test="taskId != null">AND task_id = #{taskId}</if>
|
||||
<if test="asin != null and asin != ''">AND asin LIKE CONCAT(#{asin}, '%')</if>
|
||||
<if test="country != null and country != ''">AND country = #{country}</if>
|
||||
<if test="startDate != null">AND synced_at >= #{startDate}</if>
|
||||
<if test="endDate != null">AND synced_at < DATE_ADD(#{endDate}, INTERVAL 1 DAY)</if>
|
||||
<if test="companyId != null">AND i.company_id = #{companyId}</if>
|
||||
<if test="taskId != null">AND i.task_id = #{taskId}</if>
|
||||
<if test="asin != null and asin != ''">AND i.asin LIKE CONCAT(#{asin}, '%')</if>
|
||||
<if test="country != null and country != ''">AND i.country = #{country}</if>
|
||||
<if test="startDate != null">AND i.synced_at >= #{startDate}</if>
|
||||
<if test="endDate != null">AND i.synced_at < DATE_ADD(#{endDate}, INTERVAL 1 DAY)</if>
|
||||
<if test="userIds != null and userIds.size() > 0">
|
||||
AND user_id IN
|
||||
AND i.user_id IN
|
||||
<foreach collection="userIds" item="uid" open="(" separator="," close=")">#{uid}</foreach>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<!-- 主管归属表达式(2026-11-11「按主管划分」):与读侧 fillSupervisorNames 同口径
|
||||
(DeviceSessionPolicy#resolveRole)——owner 是 super_admin/company_super_admin/admin
|
||||
或 (role 空 且 is_admin=1)=主管本人(取自己);普通账户=创建人 created_by_id;
|
||||
读不到创建人=NULL(聚合时归入同一个「未知主管」组,界面展示 -,铁律 30 不猜名)。
|
||||
只允许带 users 联表的语句引用(u = users 别名,i = 明细表别名)。 -->
|
||||
<sql id="supervisorIdExpr">
|
||||
CASE
|
||||
WHEN u.role IS NOT NULL AND LOWER(TRIM(u.role)) IN ('super_admin', 'company_super_admin', 'admin') THEN i.user_id
|
||||
WHEN (u.role IS NULL OR TRIM(u.role) = '') AND u.is_admin = 1 THEN i.user_id
|
||||
WHEN u.created_by_id IS NOT NULL AND u.created_by_id > 0 THEN u.created_by_id
|
||||
ELSE NULL
|
||||
END
|
||||
</sql>
|
||||
|
||||
<!-- 按主管过滤(卡片上的「下载」=导出该主管数据):判据就是上面那个表达式等于入参,
|
||||
不许改写成 user_id = S OR created_by_id = S——那会把「主管本人跑的单」误并进谁的子账户集。 -->
|
||||
<sql id="supervisorScopeConds">
|
||||
<if test="supervisorUserId != null">
|
||||
AND (<include refid="supervisorIdExpr"/>) = #{supervisorUserId}
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
|
||||
<delete id="deleteByResultId">
|
||||
DELETE FROM biz_appearance_patent_clean_item
|
||||
WHERE result_id = #{resultId}
|
||||
@@ -43,17 +66,69 @@
|
||||
|
||||
<select id="countCleanItems" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM biz_appearance_patent_clean_item
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
WHERE 1=1 <include refid="cleanItemConds"/>
|
||||
</select>
|
||||
|
||||
<select id="selectCleanItemPage" resultType="com.nanri.aiimage.modules.appearancepatent.model.entity.CleanItemEntity">
|
||||
SELECT id, result_id, task_id, user_id, company_id, row_no,
|
||||
asin, country, sku, brand, price, title, image_url, item_url, conclusion,
|
||||
title_reason, appearance_reason, patent_reason, source_filename, synced_at
|
||||
FROM biz_appearance_patent_clean_item
|
||||
SELECT i.id, i.result_id, i.task_id, i.user_id, i.company_id, i.row_no,
|
||||
i.asin, i.country, i.sku, i.brand, i.price, i.title, i.image_url, i.item_url, i.conclusion,
|
||||
i.title_reason, i.appearance_reason, i.patent_reason, i.source_filename, i.synced_at
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
WHERE 1=1 <include refid="cleanItemConds"/>
|
||||
ORDER BY synced_at DESC, id DESC
|
||||
ORDER BY i.synced_at DESC, i.id DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 主管聚合(2026-11-11 客户「要按主管分组显示」「应该是只显示一个卡片的才对」「获取店铺那边
|
||||
是按店铺做成卡片 我们这边就是按主管划分」):一主管一卡,不按明细分页。
|
||||
组键=supervisorIdExpr(与读侧 fillSupervisorNames 同口径);读不到主管的行归入同一个
|
||||
NULL 组(那一卡展示 -,铁律 30)。国家用 GROUP_CONCAT 收成 csv,服务侧拆成列表;
|
||||
排序按最近同步倒序(卡片的「最新」列),同刻按条数、主管 id 兜稳定序。
|
||||
company_id 等条件全部走共享 cleanItemConds(与明细分页/导出同一过滤面,铁律 20 下推)。 -->
|
||||
<select id="countSupervisors" resultType="long">
|
||||
SELECT COUNT(*) FROM (
|
||||
SELECT 1
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
LEFT JOIN users u ON u.id = i.user_id
|
||||
WHERE 1=1 <include refid="cleanItemConds"/>
|
||||
GROUP BY (<include refid="supervisorIdExpr"/>)
|
||||
) supervisor_groups
|
||||
</select>
|
||||
|
||||
<select id="selectSupervisorSummaries"
|
||||
resultType="com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorSummaryVo">
|
||||
SELECT (<include refid="supervisorIdExpr"/>) AS supervisor_id,
|
||||
COUNT(*) AS item_count,
|
||||
COUNT(DISTINCT i.task_id) AS task_count,
|
||||
MAX(i.task_id) AS last_task_id,
|
||||
MAX(i.synced_at) AS last_synced_at,
|
||||
GROUP_CONCAT(DISTINCT i.country ORDER BY i.country SEPARATOR ',') AS country_csv
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
LEFT JOIN users u ON u.id = i.user_id
|
||||
WHERE 1=1 <include refid="cleanItemConds"/>
|
||||
GROUP BY supervisor_id
|
||||
ORDER BY last_synced_at DESC, item_count DESC, supervisor_id DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 卡片「下载」=导出该主管名下全量明细(分页/导出同一过滤面 + 主管归属条件)。 -->
|
||||
<select id="countSupervisorItems" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
LEFT JOIN users u ON u.id = i.user_id
|
||||
WHERE 1=1 <include refid="cleanItemConds"/> <include refid="supervisorScopeConds"/>
|
||||
</select>
|
||||
|
||||
<select id="selectSupervisorItems"
|
||||
resultType="com.nanri.aiimage.modules.appearancepatent.model.entity.CleanItemEntity">
|
||||
SELECT i.id, i.result_id, i.task_id, i.user_id, i.company_id, i.row_no,
|
||||
i.asin, i.country, i.sku, i.brand, i.price, i.title, i.image_url, i.item_url, i.conclusion,
|
||||
i.title_reason, i.appearance_reason, i.patent_reason, i.source_filename, i.synced_at
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
LEFT JOIN users u ON u.id = i.user_id
|
||||
WHERE 1=1 <include refid="cleanItemConds"/> <include refid="supervisorScopeConds"/>
|
||||
ORDER BY i.synced_at DESC, i.id DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -82,7 +82,10 @@ class MigratedSqlEquivalenceTest {
|
||||
// 103 → 105:v1.3(外观专利无侵权数据同步后管)appearancepatent 模块首份 mapper 新写
|
||||
// 2 条只读 select(count/page),逐条点名进 NOT_MIGRATED
|
||||
// (SqlLayeringConventionTest.XML_STATEMENT_TOTAL 同轮 147 → 151)。
|
||||
private static final int XML_SELECT_TOTAL = 105;
|
||||
// 105 → 109:2026-11-11「按主管划分」同一 mapper 再落 4 条 select(主管聚合 count/page
|
||||
// +按主管导出 count/page),同样从来没有注解原文可对撞,逐条点名
|
||||
//(SqlLayeringConventionTest.XML_STATEMENT_TOTAL 同轮 151 → 155)。
|
||||
private static final int XML_SELECT_TOTAL = 109;
|
||||
|
||||
/**
|
||||
* 不是「从注解搬过来」的语句:注解时代没有原文可对撞,等价性这支只能跳过它们。
|
||||
@@ -164,7 +167,14 @@ class MigratedSqlEquivalenceTest {
|
||||
"AppearancePatentCleanItemMapper#deleteByResultId",
|
||||
"AppearancePatentCleanItemMapper#insertBatch",
|
||||
"AppearancePatentCleanItemMapper#countCleanItems",
|
||||
"AppearancePatentCleanItemMapper#selectCleanItemPage");
|
||||
"AppearancePatentCleanItemMapper#selectCleanItemPage",
|
||||
// 2026-11-11「按主管划分」(一主管一卡):4 条新写的 select——主管聚合
|
||||
// count/page 与按主管导出的 count/page(带 users 联表按归属表达式收窄),
|
||||
// 注解时代没有原文可对撞,逐条点名留痕(XML_SELECT_TOTAL 105 → 109)。
|
||||
"AppearancePatentCleanItemMapper#countSupervisors",
|
||||
"AppearancePatentCleanItemMapper#selectSupervisorSummaries",
|
||||
"AppearancePatentCleanItemMapper#countSupervisorItems",
|
||||
"AppearancePatentCleanItemMapper#selectSupervisorItems");
|
||||
|
||||
/** 账本 5 列:接口 / 方法 / @Select 种类 / 是否含常量插值 / 注解原文(Java 反转义后那条串)。 */
|
||||
private static final int LEDGER_COLUMNS = 5;
|
||||
|
||||
@@ -101,7 +101,10 @@ class SqlLayeringConventionTest {
|
||||
// 147 → 151:v1.3(外观专利无侵权数据同步后管)appearancepatent 模块首份 XML 4 条语句——
|
||||
// 覆盖式重写 delete/insert + 只读页 count/page select(V189 建表同窗),全部新写,
|
||||
// 同轮登记进 MigratedSqlEquivalenceTest.NOT_MIGRATED(该文件 XML_SELECT_TOTAL 同轮 103 → 105)。
|
||||
private static final int XML_STATEMENT_TOTAL = 151;
|
||||
// 151 → 155:2026-11-11「按主管划分」同一 mapper 再落 4 条 select——主管聚合 count/page
|
||||
// +按主管导出 count/page(users 联表按归属表达式收窄),同轮登记进 NOT_MIGRATED
|
||||
//(该文件 XML_SELECT_TOTAL 105 → 109)。
|
||||
private static final int XML_STATEMENT_TOTAL = 155;
|
||||
|
||||
/**
|
||||
* wrapper 里夹带函数级 SQL 的现状("这不是简单单表"的证据),文件名 → 条数:
|
||||
|
||||
+10
-5
@@ -61,6 +61,10 @@ class PageDefaultsLedgerTest {
|
||||
"AdminNotificationController.java#pageSize=ADMIN_LIST_PAGE_SIZE",
|
||||
"AdminAppearancePatentCleanItemsController.java#page=FIRST_PAGE",
|
||||
"AdminAppearancePatentCleanItemsController.java#page_size=CLEAN_ITEMS_PAGE_SIZE",
|
||||
// 2026-11-11「按主管划分」:同一控制器上的 /supervisors 主管聚合卡片页也分页(total 是主管数),
|
||||
// 与明细列表端点同参数名同默认值(按出站点计数、不去重)
|
||||
"AdminAppearancePatentCleanItemsController.java#page=FIRST_PAGE",
|
||||
"AdminAppearancePatentCleanItemsController.java#page_size=CLEAN_ITEMS_PAGE_SIZE",
|
||||
"AppearancePatentController.java#limit=DEFAULT_RESULT_LIMIT",
|
||||
"CollectDataController.java#page=FIRST_PAGE",
|
||||
"CollectDataController.java#page_size=TASK_LIST_PAGE_SIZE",
|
||||
@@ -111,10 +115,11 @@ class PageDefaultsLedgerTest {
|
||||
List<String> constants = actual.stream().filter(s -> !s.contains("LITERAL")).sorted().toList();
|
||||
|
||||
assertThat(constants)
|
||||
.as("56 处分页/条数出站点的具名默认值必须与台账一一对应")
|
||||
.as("58 处分页/条数出站点的具名默认值必须与台账一一对应"
|
||||
+ "(56→58:2026-11-11 /supervisors 主管聚合卡片页的 page/page_size 两处出站点)")
|
||||
.isEqualTo(LEDGER.stream().sorted().toList());
|
||||
// 同口径非零对照:台账不是空的,扫描器也确实数得出 56 处
|
||||
assertThat(constants).hasSize(56);
|
||||
// 同口径非零对照:台账不是空的,扫描器也确实数得出 58 处
|
||||
assertThat(constants).hasSize(58);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,8 +134,8 @@ class PageDefaultsLedgerTest {
|
||||
void oneSemanticCannotGrowASecondDefault() {
|
||||
List<String> actual = sites();
|
||||
assertThat(kindsUsing(actual, "page", "FIRST_PAGE"))
|
||||
.as("页码口径只有一套:全部从 1 起")
|
||||
.isEqualTo(25);
|
||||
.as("页码口径只有一套:全部从 1 起(25→26:2026-11-11 /supervisors 主管聚合卡片页也是分页出站点)")
|
||||
.isEqualTo(26);
|
||||
assertThat(distinctConstants(actual, "page_size"))
|
||||
.as("page_size 的默认容量集合:10/15/20/50/1000 五种各自登记,新来第六种要红"
|
||||
+ "(10 是 v1.3 无侵权只读页,蓝图 §3.2 拍板、与前端 OldPagination 首屏同值)")
|
||||
|
||||
+131
-7
@@ -12,6 +12,9 @@ import com.nanri.aiimage.modules.appearancepatent.mapper.AppearancePatentCleanIt
|
||||
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 com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorPageVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorSummaryVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.AppearancePatentCleanItemQueryService;
|
||||
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -378,15 +381,21 @@ class AdminAppearancePatentCleanItemsControllerTest {
|
||||
long scopeCalls = source.split("readCompanyIdOrOwn\\(", -1).length - 1;
|
||||
assertTrue(scopeCalls >= 2, "分页与导出两支 handler 都必须走 readCompanyIdOrOwn 公司隔离,实得 " + scopeCalls);
|
||||
// 导出是全量导出(服务侧另有 EXPORT_MAX_ROWS 上限),不收 page/page_size:
|
||||
// 全文件 page_size 只允许出现一次(分页 handler 的参数声明)。
|
||||
// 带分页参数的两个 handler 各声明一次 page_size(明细分页 + 2026-11-11 主管聚合卡片页,
|
||||
// total 是主管数);导出两支(全量/按主管)都不收分页参数,所以分母恒为 2。
|
||||
long pageSizeParams = source.split("page_size", -1).length - 1;
|
||||
assertEquals(1, pageSizeParams, "导出不收分页参数,page_size 只许出现在分页 handler 的参数声明里");
|
||||
assertEquals(2, pageSizeParams, "page_size 只许出现在两个分页 handler 的参数声明里(明细分页+主管卡片),"
|
||||
+ "导出不许收分页参数");
|
||||
// 分组(主管=组长)筛选:group_id 在分页与导出两支都要收;选项不下新端点(复用
|
||||
// 既有 GET /shop-manages/groups,与去重页/店铺管理同源)。
|
||||
long groupParams = source.split("group_id", -1).length - 1;
|
||||
assertTrue(groupParams >= 2, "分页与导出都必须收 group_id(主管=组长,就是分组,2026-11-11 客户口径)");
|
||||
assertFalse(source.contains("\"/supervisors\""),
|
||||
"选项复用既有分组端点,本控制器不得再挂 /supervisors 第二份选项源");
|
||||
// 2026-11-11 二次改版:/supervisors 是<b>主管聚合卡片</b>(一主管一卡),不是分组选项源;
|
||||
// 「选项不得另开端点」的判据改成看 /groups——本控制器不许自带一份分组选项。
|
||||
assertTrue(source.contains("\"/supervisors\""),
|
||||
"主管聚合卡片端点必须是 GET /supervisors(客户「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」)");
|
||||
assertFalse(source.contains("\"/groups\""),
|
||||
"分组选项复用既有 GET /shop-manages/groups,本控制器不得再挂分组选项端点");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -408,7 +417,7 @@ class AdminAppearancePatentCleanItemsControllerTest {
|
||||
byte[] payload = "xlsx-bytes".getBytes(StandardCharsets.UTF_8);
|
||||
when(queryService.export(null, null, null, null, null, null, 5L)).thenReturn(payload);
|
||||
|
||||
ResponseEntity<byte[]> response = controller.export(null, null, null, null, null, null, 5L, request);
|
||||
ResponseEntity<byte[]> response = controller.export(null, null, null, null, null, null, null, 5L, request);
|
||||
|
||||
verify(dataReadScope).readCompanyIdOrOwn(operator, 5L);
|
||||
verify(queryService).export(null, null, null, null, null, null, 5L);
|
||||
@@ -538,9 +547,124 @@ class AdminAppearancePatentCleanItemsControllerTest {
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== 2026-11-11 二次改版:按主管聚合(一主管一卡) =====================
|
||||
|
||||
@Test
|
||||
void 主管聚合一主管一卡_条数任务国家最新与主管名齐备() {
|
||||
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
|
||||
AdminUserMapper adminUserMapper = mock(AdminUserMapper.class);
|
||||
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
|
||||
mapper, adminUserMapper, mock(ShopManageGroupMapper.class));
|
||||
|
||||
when(mapper.countSupervisors(any(), any(), any(), any(), any(), any(), any())).thenReturn(2L);
|
||||
AppearancePatentSupervisorSummaryVo leaderCard = new AppearancePatentSupervisorSummaryVo();
|
||||
leaderCard.setSupervisorId(9L);
|
||||
leaderCard.setItemCount(120L);
|
||||
leaderCard.setTaskCount(3L);
|
||||
leaderCard.setLastTaskId(33874L);
|
||||
leaderCard.setLastSyncedAt(LocalDateTime.of(2026, 11, 11, 11, 34));
|
||||
leaderCard.setCountryCsv("DE,UK");
|
||||
AppearancePatentSupervisorSummaryVo unknownCard = new AppearancePatentSupervisorSummaryVo();
|
||||
unknownCard.setSupervisorId(null);
|
||||
unknownCard.setItemCount(5L);
|
||||
unknownCard.setTaskCount(1L);
|
||||
when(mapper.selectSupervisorSummaries(any(), any(), any(), any(), any(), any(), any(), eq(0L), anyInt()))
|
||||
.thenReturn(List.of(leaderCard, unknownCard));
|
||||
AdminUserEntity leader = new AdminUserEntity();
|
||||
leader.setId(9L);
|
||||
leader.setUsername(" 主管甲 ");
|
||||
when(adminUserMapper.selectBatchIds(anyCollection())).thenAnswer(invocation -> {
|
||||
Collection<?> ids = invocation.getArgument(0);
|
||||
List<AdminUserEntity> out = new ArrayList<>();
|
||||
if (ids.contains(9L)) out.add(leader);
|
||||
return out;
|
||||
});
|
||||
|
||||
AppearancePatentSupervisorPageVo vo = service.supervisorPage(1L, 10L, null, null, null, null, 5L);
|
||||
|
||||
assertEquals(2L, vo.getTotal(), "total 是主管数(不是明细条数——铺明细分页会把几千条画成几千张卡)");
|
||||
assertEquals(2, vo.getItems().size(), "一主管一卡");
|
||||
AppearancePatentSupervisorVo first = vo.getItems().get(0);
|
||||
assertEquals("主管甲", first.getSupervisorName(), "主管名批量富化,两侧空白剥掉");
|
||||
assertEquals(120L, first.getItemCount());
|
||||
assertEquals(3L, first.getTaskCount(), "任务数是 COUNT(DISTINCT task_id)");
|
||||
assertEquals(33874L, first.getLastTaskId(), "卡片「任务」行显示最近任务号");
|
||||
assertEquals(LocalDateTime.of(2026, 11, 11, 11, 34), first.getLastSyncedAt());
|
||||
assertEquals(List.of("DE", "UK"), first.getCountryCodes(), "国家 csv 拆成码集(前端用自己的字典翻中文)");
|
||||
AppearancePatentSupervisorVo second = vo.getItems().get(1);
|
||||
assertNull(second.getSupervisorName(), "读不到主管=不猜名字(铁律 30),前端展示 -");
|
||||
assertNull(second.getSupervisorId(), "未知主管组的 supervisorId 为 null(该卡不提供按主管下载)");
|
||||
assertEquals(List.of(), second.getCountryCodes(), "空国家 csv 拆成空列表,不下发 null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 主管聚合_分组读不出用户时短路不碰mapper() {
|
||||
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
|
||||
ShopManageGroupMapper groupMapper = mock(ShopManageGroupMapper.class);
|
||||
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
|
||||
mapper, mock(AdminUserMapper.class), groupMapper);
|
||||
|
||||
when(groupMapper.selectUserIdsByGroupId(9L)).thenReturn(List.of());
|
||||
|
||||
AppearancePatentSupervisorPageVo vo = service.supervisorPage(1L, 10L, null, null, null, 9L, 5L);
|
||||
|
||||
assertEquals(0L, vo.getTotal());
|
||||
assertTrue(vo.getItems().isEmpty());
|
||||
verify(mapper, never()).countSupervisors(any(), any(), any(), any(), any(), any(), any());
|
||||
verify(mapper, never()).selectSupervisorSummaries(any(), any(), any(), any(), any(), any(), any(),
|
||||
anyLong(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 按主管导出走主管专口并保留xlsx主管列() throws Exception {
|
||||
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
|
||||
AdminUserMapper adminUserMapper = mock(AdminUserMapper.class);
|
||||
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
|
||||
mapper, adminUserMapper, mock(ShopManageGroupMapper.class));
|
||||
|
||||
when(mapper.countSupervisorItems(any(), any(), any(), any(), any(), any(), any(), eq(9L))).thenReturn(1L);
|
||||
when(mapper.selectSupervisorItems(any(), any(), any(), any(), any(), any(), any(), eq(9L), eq(0L), anyInt()))
|
||||
.thenReturn(List.of(rowEntity(1L, 33L)));
|
||||
AdminUserEntity plainOwner = new AdminUserEntity();
|
||||
plainOwner.setId(33L);
|
||||
plainOwner.setUsername("sub-user-1");
|
||||
plainOwner.setCreatedById(9L);
|
||||
AdminUserEntity creator = new AdminUserEntity();
|
||||
creator.setId(9L);
|
||||
creator.setUsername("主管甲");
|
||||
when(adminUserMapper.selectBatchIds(anyCollection())).thenAnswer(invocation -> {
|
||||
Collection<?> ids = invocation.getArgument(0);
|
||||
List<AdminUserEntity> out = new ArrayList<>();
|
||||
if (ids.contains(33L)) out.add(plainOwner);
|
||||
if (ids.contains(9L)) out.add(creator);
|
||||
return out;
|
||||
});
|
||||
|
||||
byte[] bytes = service.exportBySupervisor(9L, null, null, null, null, 5L);
|
||||
|
||||
// 走的是主管专口:不能落到不按主管收窄的 countCleanItems/selectCleanItemPage 上
|
||||
verify(mapper, never()).countCleanItems(any(), any(), any(), any(), any(), any(), any());
|
||||
verify(mapper, never()).selectCleanItemPage(any(), any(), any(), any(), any(), any(), any(),
|
||||
anyLong(), anyInt());
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(bytes))) {
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
assertEquals(1, sheet.getLastRowNum(), "表头 + 1 行明细");
|
||||
assertEquals("主管甲", sheet.getRow(1).getCell(8).getStringCellValue(),
|
||||
"按主管导出同样带所属主管列(与全量导出同一表头)");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void 主管聚合端点与按主管导出参数就位() throws IOException {
|
||||
String source = stripComments(Files.readString(CONTROLLER));
|
||||
assertTrue(source.contains("supervisorPage("), "主管聚合必须落到服务的 supervisorPage");
|
||||
assertTrue(source.contains("supervisor_user_id"), "按主管导出参数名 supervisor_user_id(卡片「下载」)");
|
||||
assertTrue(source.contains("exportBySupervisor("), "按主管导出必须走主管专口(按归属表达式收窄,不近似成 user_id OR created_by_id)");
|
||||
assertTrue(source.contains("AppearancePatentSupervisorPageVo"), "主管卡片页信封类型必须点名");
|
||||
}
|
||||
|
||||
/** 导出/分页用例共用的明细行夹具:task 归 owner,值非空便于按列对撞。 */
|
||||
private static CleanItemEntity rowEntity(long id, long userId) {
|
||||
CleanItemEntity entity = new CleanItemEntity();
|
||||
private static CleanItemEntity rowEntity(long id, long userId) { CleanItemEntity entity = new CleanItemEntity();
|
||||
entity.setId(id);
|
||||
entity.setResultId(900 + id);
|
||||
entity.setTaskId(33179L);
|
||||
|
||||
@@ -318,17 +318,19 @@ class SourceScanTest {
|
||||
List<Path> files = SourceScan.moduleSources("modules/appearancepatent");
|
||||
|
||||
assertThat(files)
|
||||
.as("真实集成:对真仓目录求值。52 支=2 controller+1 client+8 service 根件"
|
||||
.as("真实集成:对真仓目录求值。55 支=2 controller+1 client+8 service 根件"
|
||||
+ "(主件/只读查询/同步/出表作业/缓存/心跳与拉取与重试 SPI)"
|
||||
+ "+21 service/support+19 model(dto7/entity1/vo11)+1 mapper,"
|
||||
+ "+21 service/support+22 model(dto7/entity1/vo14)+1 mapper,"
|
||||
+ "与 find 实测同号"
|
||||
+ "(3A 拆薄第十三笔再落 5 支;失败任务重试再落 1 支 RetrySpi;"
|
||||
+ "v1.3 Phase 1 无侵权同步底座再落 2 支:model/entity/CleanItemEntity+"
|
||||
+ "mapper/AppearancePatentCleanItemMapper;Phase 2 同步服务再落 1 支"
|
||||
+ " AppearancePatentCleanSyncService;Phase 3 只读页再落 4 支:"
|
||||
+ "controller/AdminAppearancePatentCleanItemsController+"
|
||||
+ "service/AppearancePatentCleanItemQueryService+model/vo 两件)")
|
||||
.hasSize(52);
|
||||
+ "service/AppearancePatentCleanItemQueryService+model/vo 两件;"
|
||||
+ "2026-11-11「按主管划分」再落 3 支 model/vo:"
|
||||
+ "SupervisorPageVo/SummaryVo/SupervisorVo)")
|
||||
.hasSize(55);
|
||||
assertThat(files.stream().map(p -> p.toString().replace('\\', '/')).toList())
|
||||
.as("support 目录里的既有件必须在面里——聚合入口存在的理由就是拆分后的新文件要自动被看到")
|
||||
.anyMatch(rel -> rel.endsWith("service/support/AppearancePatentRowNormalizer.java"));
|
||||
@@ -463,8 +465,8 @@ class SourceScanTest {
|
||||
.as("model/dto 一层嵌套")
|
||||
.isEqualTo(7);
|
||||
assertThat(rel.stream().filter(p -> p.contains("/model/vo/")).count())
|
||||
.as("model/vo 一层嵌套")
|
||||
.isEqualTo(11);
|
||||
.as("model/vo 一层嵌套(11→14:2026-11-11「按主管划分」三支 Supervisor 聚合 VO)")
|
||||
.isEqualTo(14);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user