feat(keywordshare): 五国关键词共享后端模块(桌面工具网页化)

词本体直接读写主库既有 keyword_share 表(已是全量词库),使用状态
keyword_usage,留痕 keyword_add_log/keyword_delete_log;不建新表、无 SQLite。
九个端点挂 /api/keyword-share,权限键 keyword-share,companyId 服务端取。
列表排序对齐桌面版:已使用在前、按 used_time 升序;添加查重跳过+留痕+
自动标记已使用;随机抽词从未使用池。
SQL 账本 99→115(16 条新写语句)、select 账本 67→78(11 条),逐条点入
NOT_MIGRATED;ApiGuardCoverageAuditor METHOD_GUARDED_PATHS 登记
/api/keyword-share(9 端点全部 handler 内 requireConsolePageAccess 把门)。
FILTER_* 命名避开任务状态词表棘轮。
This commit is contained in:
2026-10-23 21:54:52 +08:00
parent 6d9d4b98b2
commit 2d408199d6
38 changed files with 2077 additions and 4 deletions
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nanri.aiimage.modules.keywordshare.mapper.KeywordAddLogMapper">
<insert id="insertBatch">
INSERT INTO keyword_add_log (company_id, country, keyword, user_name, add_time)
VALUES
<foreach collection="rows" item="row" separator=",">
(#{row.companyId}, #{row.country}, #{row.keyword}, #{row.userName}, #{row.addTime})
</foreach>
</insert>
</mapper>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nanri.aiimage.modules.keywordshare.mapper.KeywordDeleteLogMapper">
<insert id="insertBatch">
INSERT INTO keyword_delete_log (company_id, country, keyword, user_name, delete_time)
VALUES
<foreach collection="rows" item="row" separator=",">
(#{row.companyId}, #{row.country}, #{row.keyword}, #{row.userName}, #{row.deleteTime})
</foreach>
</insert>
</mapper>
@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nanri.aiimage.modules.keywordshare.mapper.KeywordShareMapper">
<!-- 五国关键词共享(词本体 keyword_share)。动态筛选全部走 #{} 占位符,不做任何字符串拼接;
排序口径对齐桌面版 keyword_share_app.py _filtered_rows_conn(未使用在前、已使用按 used_time 升序)。 -->
<!-- 词表 × 使用状态:usage 行按 (company_id, country, keyword) 三键对上,与桌面版同一口径 -->
<sql id="usageJoin">
keyword_share k
LEFT JOIN keyword_usage u
ON u.company_id = k.company_id
AND u.country = k.country
AND u.keyword = k.keyword
</sql>
<sql id="filterConds">
k.company_id = #{f.companyId}
<if test="f.country != null and f.country != ''">AND k.country = #{f.country}</if>
<if test="f.category != null and f.category != ''">AND k.category = #{f.category}</if>
<if test="f.subCategory != null and f.subCategory != ''">AND k.sub_category = #{f.subCategory}</if>
<if test="f.categoryL3 != null and f.categoryL3 != ''">AND k.category_l3 = #{f.categoryL3}</if>
<if test="f.categoryL4 != null and f.categoryL4 != ''">AND k.category_l4 = #{f.categoryL4}</if>
<if test="f.search != null and f.search != ''">
AND (k.keyword LIKE CONCAT('%', #{f.search}, '%') OR k.chinese LIKE CONCAT('%', #{f.search}, '%'))
</if>
<if test="f.status == 'used'">AND u.country IS NOT NULL</if>
<if test="f.status == 'unused'">AND u.country IS NULL</if>
<if test="f.usedSince != null">AND u.country IS NOT NULL AND u.used_time &gt;= #{f.usedSince}</if>
<if test="f.onlyMine != null and f.onlyMine">AND u.user_name = #{f.userName}</if>
</sql>
<select id="countHit" resultType="long">
SELECT COUNT(*)
FROM <include refid="usageJoin"/>
WHERE <include refid="filterConds"/>
</select>
<select id="selectRows" resultType="com.nanri.aiimage.modules.keywordshare.model.vo.KeywordShareRowVo">
SELECT k.id, k.country, k.keyword, k.chinese, k.category, k.sub_category, k.category_l3, k.category_l4,
(u.country IS NOT NULL) AS used, u.used_time, u.user_name
FROM <include refid="usageJoin"/>
WHERE <include refid="filterConds"/>
ORDER BY (u.country IS NULL) ASC, u.used_time ASC
LIMIT #{f.offset}, #{f.limit}
</select>
<select id="selectRandomUnused" resultType="com.nanri.aiimage.modules.keywordshare.model.vo.KeywordShareRowVo">
SELECT k.id, k.country, k.keyword, k.chinese, k.category, k.sub_category, k.category_l3, k.category_l4,
(u.country IS NOT NULL) AS used, u.used_time, u.user_name
FROM <include refid="usageJoin"/>
WHERE <include refid="filterConds"/>
ORDER BY RAND()
LIMIT #{f.limit}
</select>
<select id="countDupKeywords" resultType="long">
SELECT COUNT(*)
FROM (
SELECT keyword FROM keyword_share
WHERE company_id = #{companyId}
GROUP BY keyword
HAVING COUNT(DISTINCT country) &gt; 1
) t
</select>
<select id="selectFilterCountries" resultType="string">
SELECT DISTINCT country
FROM keyword_share
WHERE company_id = #{companyId}
AND country IS NOT NULL AND country != ''
ORDER BY country
</select>
<select id="selectFilterTreeRows" resultType="com.nanri.aiimage.modules.keywordshare.model.dto.KeywordCategoryTreeRow">
SELECT DISTINCT category, sub_category, category_l3, category_l4
FROM keyword_share
WHERE company_id = #{companyId}
AND category IS NOT NULL AND category != ''
ORDER BY category, sub_category, category_l3, category_l4
</select>
<select id="selectCountryCounts" resultType="com.nanri.aiimage.modules.keywordshare.model.dto.KeywordNameCountRow">
SELECT country AS name, COUNT(*) AS count
FROM keyword_share
WHERE company_id = #{companyId}
AND country IS NOT NULL AND country != ''
GROUP BY country
ORDER BY count DESC
</select>
<select id="selectCategoryCounts" resultType="com.nanri.aiimage.modules.keywordshare.model.dto.KeywordNameCountRow">
SELECT category AS name, COUNT(*) AS count
FROM keyword_share
WHERE company_id = #{companyId}
AND category IS NOT NULL AND category != ''
GROUP BY category
ORDER BY count DESC
</select>
<select id="selectSubCategoryCounts" resultType="com.nanri.aiimage.modules.keywordshare.model.dto.KeywordCategoryCountRow">
SELECT category, sub_category AS name, COUNT(*) AS count
FROM keyword_share
WHERE company_id = #{companyId}
AND category IS NOT NULL AND category != ''
GROUP BY category, sub_category
ORDER BY category, count DESC
</select>
<select id="selectCategoryL3Counts" resultType="com.nanri.aiimage.modules.keywordshare.model.dto.KeywordCategoryL3CountRow">
SELECT category, sub_category, category_l3 AS name, COUNT(*) AS count
FROM keyword_share
WHERE company_id = #{companyId}
AND category IS NOT NULL AND category != ''
GROUP BY category, sub_category, category_l3
ORDER BY category, count DESC
</select>
<select id="selectExistingKeywords" resultType="com.nanri.aiimage.modules.keywordshare.model.dto.KeywordShareKey">
SELECT country, keyword
FROM keyword_share
WHERE company_id = #{companyId}
AND (country, keyword) IN
<foreach collection="keys" item="key" open="(" separator="," close=")">
(#{key.country}, #{key.keyword})
</foreach>
</select>
<insert id="insertBatchIgnore">
INSERT IGNORE INTO keyword_share
(country, keyword, chinese, ktype, source, category, sub_category, category_l3, category_l4,
user_name, add_time, company_id)
VALUES
<foreach collection="rows" item="row" separator=",">
(#{row.country}, #{row.keyword}, #{row.chinese}, #{row.ktype}, #{row.source}, #{row.category},
#{row.subCategory}, #{row.categoryL3}, #{row.categoryL4}, #{row.userName}, #{row.addTime}, #{row.companyId})
</foreach>
</insert>
</mapper>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nanri.aiimage.modules.keywordshare.mapper.KeywordUsageMapper">
<!-- 使用状态批量写:UPSERT 语义对齐桌面版 ShareSync.mark(ON DUPLICATE KEY UPDATE),
唯一键 uk_comp_cw(company_id, country, keyword) 冲突即刷新使用者与时间,天然幂等。 -->
<insert id="upsertBatch">
INSERT INTO keyword_usage (company_id, country, keyword, user_name, used_time)
VALUES
<foreach collection="rows" item="row" separator=",">
(#{row.companyId}, #{row.country}, #{row.keyword}, #{row.userName}, #{row.usedTime})
</foreach>
ON DUPLICATE KEY UPDATE user_name = VALUES(user_name), used_time = VALUES(used_time)
</insert>
<delete id="deleteBatch">
DELETE FROM keyword_usage
WHERE company_id = #{companyId}
AND (country, keyword) IN
<foreach collection="keys" item="key" open="(" separator="," close=")">
(#{key.country}, #{key.keyword})
</foreach>
</delete>
</mapper>