|
|
|
@@ -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 >= #{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) > 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>
|