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,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>