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:
2026-11-11 12:31:28 +08:00
parent 2a2e276c32
commit e1767faff5
17 changed files with 903 additions and 298 deletions
@@ -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))
@@ -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);
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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)按没选处理,不把它当全量之外的第三档。解析交给
@@ -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 &gt;= #{startDate}</if>
<if test="endDate != null">AND synced_at &lt; 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 &gt;= #{startDate}</if>
<if test="endDate != null">AND i.synced_at &lt; 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 &gt; 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>