feat(keywordusage): 新增关键词使用记录并归位店铺管理菜单
V175 把品牌Gating库从数据管理组迁到店铺管理组(排序85),并在其后新增 关键词使用记录独立菜单(排序86)。后端新增只读查询模块,按公司范围读取 keyword_usage/keyword_add_log/keyword_delete_log,前端提供使用/删除记录、 统计卡与筛选。
This commit is contained in:
+93
@@ -0,0 +1,93 @@
|
||||
package com.nanri.aiimage.modules.keywordusage.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
import com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsageOverviewVo;
|
||||
import com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsagePageVo;
|
||||
import com.nanri.aiimage.modules.keywordusage.service.KeywordUsageAdminService;
|
||||
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 关键词使用记录(管理后台):只读展示 keyword_usage / keyword_add_log / keyword_delete_log。
|
||||
*
|
||||
* <p>独立菜单「关键词使用记录」{@code admin_keyword_usage}(V175),按公司 tab 取数:
|
||||
* 平台超管可收窄到请求里的 company_id,其余账号由 DataReadScope 强制本公司。
|
||||
* 留痕表由桌面端与 keywordshare 模块共用,本页不写、不删。</p>
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/admin/keyword-usage")
|
||||
@Tag(name = "关键词使用记录(后台)", description = "关键词复制/添加/删除留痕的只读分页与统计。")
|
||||
public class AdminKeywordUsageController {
|
||||
|
||||
private static final String PERMISSION_KEY = "admin_keyword_usage";
|
||||
private static final String DENIAL_MESSAGE = "无权访问关键词使用记录";
|
||||
|
||||
private final KeywordUsageAdminService keywordUsageAdminService;
|
||||
private final AdminAuthSupport adminAuthSupport;
|
||||
private final PermissionMenuService permissionMenuService;
|
||||
private final DataReadScope dataReadScope;
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "使用记录分页", description = "复制关键词 + 添加关键词合并按时间倒序;scene=已使用/添加关键词可只看一支。")
|
||||
public ApiResponse<KeywordUsagePageVo> usage(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||
@Parameter(description = "使用者") @RequestParam(name = "user", required = false) String user,
|
||||
@Parameter(description = "国家") @RequestParam(name = "country", required = false) String country,
|
||||
@Parameter(description = "关键词模糊搜索") @RequestParam(name = "keyword", required = false) String keyword,
|
||||
@Parameter(description = "场景:已使用 / 添加关键词") @RequestParam(name = "scene", required = false) String scene,
|
||||
@Parameter(description = "页码(1 起)") @RequestParam(name = "page", required = false) Long page,
|
||||
@Parameter(description = "每页数量(默认 15,上限 100)")
|
||||
@RequestParam(name = "page_size", required = false) Long pageSize) {
|
||||
AdminUserEntity operator = requireAccess(request);
|
||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(operator, companyId);
|
||||
return ApiResponse.success(
|
||||
keywordUsageAdminService.usage(scopedCompanyId, user, country, keyword, scene, page, pageSize));
|
||||
}
|
||||
|
||||
@GetMapping("/deletes")
|
||||
@Operation(summary = "删除记录分页", description = "keyword_delete_log 按删除时间倒序;只读、不可删。")
|
||||
public ApiResponse<KeywordUsagePageVo> deletes(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||
@Parameter(description = "删除者") @RequestParam(name = "user", required = false) String user,
|
||||
@Parameter(description = "国家") @RequestParam(name = "country", required = false) String country,
|
||||
@Parameter(description = "关键词模糊搜索") @RequestParam(name = "keyword", required = false) String keyword,
|
||||
@Parameter(description = "页码(1 起)") @RequestParam(name = "page", required = false) Long page,
|
||||
@Parameter(description = "每页数量(默认 15,上限 100)")
|
||||
@RequestParam(name = "page_size", required = false) Long pageSize) {
|
||||
AdminUserEntity operator = requireAccess(request);
|
||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(operator, companyId);
|
||||
return ApiResponse.success(
|
||||
keywordUsageAdminService.deletes(scopedCompanyId, user, country, keyword, page, pageSize));
|
||||
}
|
||||
|
||||
@GetMapping("/overview")
|
||||
@Operation(summary = "统计卡与筛选候选", description = "统计卡 + 有操作记录的使用者/国家(五国在首位)。")
|
||||
public ApiResponse<KeywordUsageOverviewVo> overview(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = requireAccess(request);
|
||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(operator, companyId);
|
||||
return ApiResponse.success(keywordUsageAdminService.overview(scopedCompanyId));
|
||||
}
|
||||
|
||||
/** 逐端点把门:登录态 + 「关键词使用记录」后台菜单权限(admin_keyword_usage)。 */
|
||||
private AdminUserEntity requireAccess(HttpServletRequest request) {
|
||||
AdminUserEntity operator = adminAuthSupport.requireUser(request);
|
||||
permissionMenuService.requireConsolePageAccess(operator, DENIAL_MESSAGE, PERMISSION_KEY);
|
||||
return operator;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.nanri.aiimage.modules.keywordusage.mapper;
|
||||
|
||||
import com.nanri.aiimage.modules.keywordusage.model.dto.KeywordUsageFilterQuery;
|
||||
import com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsageRowVo;
|
||||
import com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsageStatsVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 关键词使用记录(管理后台只读视图)数据访问。
|
||||
*
|
||||
* <p>表 {@code keyword_usage} / {@code keyword_add_log} / {@code keyword_delete_log} /
|
||||
* {@code keyword_share} 由桌面端与 keywordshare 模块共用,本 Mapper 只读不写;
|
||||
* SQL 全部收口在 {@code mapper/keywordusage/KeywordUsageAdminMapper.xml}。</p>
|
||||
*/
|
||||
@Mapper
|
||||
public interface KeywordUsageAdminMapper {
|
||||
|
||||
long countUsageRows(@Param("f") KeywordUsageFilterQuery filter);
|
||||
|
||||
List<KeywordUsageRowVo> selectUsageRows(@Param("f") KeywordUsageFilterQuery filter);
|
||||
|
||||
long countCopy(@Param("f") KeywordUsageFilterQuery filter);
|
||||
|
||||
long countCopyExisting(@Param("f") KeywordUsageFilterQuery filter);
|
||||
|
||||
long countAdd(@Param("f") KeywordUsageFilterQuery filter);
|
||||
|
||||
long countDeletes(@Param("f") KeywordUsageFilterQuery filter);
|
||||
|
||||
List<KeywordUsageRowVo> selectDeleteRows(@Param("f") KeywordUsageFilterQuery filter);
|
||||
|
||||
KeywordUsageStatsVo selectStats(@Param("companyId") Long companyId);
|
||||
|
||||
List<String> selectUsers(@Param("companyId") Long companyId);
|
||||
|
||||
List<String> selectCountries(@Param("companyId") Long companyId);
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.nanri.aiimage.modules.keywordusage.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 关键词留痕查询条件——Mapper XML 的唯一入参载体({@code @Param("f")})。
|
||||
* 筛选值一律走 {@code #{}} 占位符,不做字符串拼接。
|
||||
*/
|
||||
@Data
|
||||
public class KeywordUsageFilterQuery {
|
||||
|
||||
/** null = 平台超管未指定公司(跨公司全量);非 null = 收窄到该公司。 */
|
||||
private Long companyId;
|
||||
|
||||
private String user;
|
||||
private String country;
|
||||
private String keyword;
|
||||
|
||||
/** 使用记录合并视图:是否包含「复制关键词」/「添加关键词」两支。 */
|
||||
private boolean includeCopy;
|
||||
private boolean includeAdd;
|
||||
|
||||
private long offset;
|
||||
private long limit;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.nanri.aiimage.modules.keywordusage.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/** 使用记录口径计数:复制 = 现存词 + 已删除词留痕。 */
|
||||
@Data
|
||||
@Schema(description = "关键词使用记录计数")
|
||||
public class KeywordUsageCountsVo {
|
||||
|
||||
@Schema(description = "复制关键词(标记已使用)总数")
|
||||
private long copy;
|
||||
|
||||
@Schema(description = "复制关键词中仍存在于 keyword_share 的数量")
|
||||
private long copyExisting;
|
||||
|
||||
@Schema(description = "复制关键词中已从 keyword_share 删除的数量")
|
||||
private long copyDeleted;
|
||||
|
||||
@Schema(description = "添加关键词总数")
|
||||
private long add;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.nanri.aiimage.modules.keywordusage.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 关键词使用记录页首屏:统计卡 + 筛选下拉候选。 */
|
||||
@Data
|
||||
@Schema(description = "关键词使用记录概览")
|
||||
public class KeywordUsageOverviewVo {
|
||||
|
||||
@Schema(description = "统计卡")
|
||||
private KeywordUsageStatsVo stats = new KeywordUsageStatsVo();
|
||||
|
||||
@Schema(description = "有操作记录的使用者")
|
||||
private List<String> users = List.of();
|
||||
|
||||
@Schema(description = "有操作记录的国家(五国在首位)")
|
||||
private List<String> countries = List.of();
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.nanri.aiimage.modules.keywordusage.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 关键词留痕分页负载。 */
|
||||
@Data
|
||||
@Schema(description = "关键词使用/删除记录分页")
|
||||
public class KeywordUsagePageVo {
|
||||
|
||||
@Schema(description = "总条数")
|
||||
private long total;
|
||||
|
||||
@Schema(description = "当前页行")
|
||||
private List<KeywordUsageRowVo> rows = List.of();
|
||||
|
||||
@Schema(description = "使用记录口径计数(删除记录页为空对象)")
|
||||
private KeywordUsageCountsVo counts = new KeywordUsageCountsVo();
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.nanri.aiimage.modules.keywordusage.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 关键词使用/删除留痕单行。 */
|
||||
@Data
|
||||
@Schema(description = "关键词使用记录行")
|
||||
public class KeywordUsageRowVo {
|
||||
|
||||
@Schema(description = "操作人")
|
||||
private String userName;
|
||||
|
||||
@Schema(description = "国家")
|
||||
private String country;
|
||||
|
||||
@Schema(description = "关键词")
|
||||
private String keyword;
|
||||
|
||||
@Schema(description = "场景:复制关键词 / 添加关键词 / 删除关键词")
|
||||
private String scene;
|
||||
|
||||
@Schema(description = "操作时间")
|
||||
private LocalDateTime time;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.nanri.aiimage.modules.keywordusage.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/** 关键词使用记录统计卡。 */
|
||||
@Data
|
||||
@Schema(description = "关键词使用记录统计")
|
||||
public class KeywordUsageStatsVo {
|
||||
|
||||
@Schema(description = "复制关键词(标记已使用)总数")
|
||||
private long used;
|
||||
|
||||
@Schema(description = "复制关键词中仍存在于 keyword_share 的数量")
|
||||
private long exist;
|
||||
|
||||
@Schema(description = "已删除词留痕 = used - exist")
|
||||
private long deletedKw;
|
||||
|
||||
@Schema(description = "添加关键词总数")
|
||||
private long added;
|
||||
|
||||
@Schema(description = "使用记录合计 = used + added")
|
||||
private long totalUse;
|
||||
|
||||
@Schema(description = "删除关键词记录总数")
|
||||
private long deletes;
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
package com.nanri.aiimage.modules.keywordusage.service;
|
||||
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.keywordusage.mapper.KeywordUsageAdminMapper;
|
||||
import com.nanri.aiimage.modules.keywordusage.model.dto.KeywordUsageFilterQuery;
|
||||
import com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsageCountsVo;
|
||||
import com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsageOverviewVo;
|
||||
import com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsagePageVo;
|
||||
import com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsageRowVo;
|
||||
import com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsageStatsVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 关键词使用记录(管理后台只读视图)。
|
||||
*
|
||||
* <p>口径对齐独立小网页后台 v1.2.6g:使用记录 = 复制关键词(keyword_usage)+ 添加关键词
|
||||
* (keyword_add_log)合并按时间倒序;删除记录单独一页;统计卡里的「已删除词留痕」
|
||||
* = 复制总数 - 仍存在于 keyword_share 的数量。公司范围由 Controller 经 DataReadScope 解析后传入,
|
||||
* 本层不再自行从请求参数取公司。</p>
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class KeywordUsageAdminService {
|
||||
|
||||
private static final long DEFAULT_PAGE_SIZE = 15;
|
||||
private static final long MAX_PAGE_SIZE = 100;
|
||||
private static final List<String> BASE_COUNTRIES = List.of("英国", "德国", "法国", "西班牙", "意大利");
|
||||
|
||||
private final KeywordUsageAdminMapper keywordUsageAdminMapper;
|
||||
|
||||
public KeywordUsagePageVo usage(Long companyId, String user, String country, String keyword,
|
||||
String scene, Long page, Long pageSize) {
|
||||
KeywordUsageFilterQuery filter = buildFilter(companyId, user, country, keyword, page, pageSize);
|
||||
applyScene(filter, scene);
|
||||
|
||||
KeywordUsagePageVo vo = new KeywordUsagePageVo();
|
||||
if (!filter.isIncludeCopy() && !filter.isIncludeAdd()) {
|
||||
vo.setTotal(0);
|
||||
vo.setRows(List.of());
|
||||
vo.setCounts(new KeywordUsageCountsVo());
|
||||
return vo;
|
||||
}
|
||||
|
||||
long total = keywordUsageAdminMapper.countUsageRows(filter);
|
||||
long copy = filter.isIncludeCopy() ? keywordUsageAdminMapper.countCopy(filter) : 0;
|
||||
long copyExisting = filter.isIncludeCopy() ? keywordUsageAdminMapper.countCopyExisting(filter) : 0;
|
||||
long add = filter.isIncludeAdd() ? keywordUsageAdminMapper.countAdd(filter) : 0;
|
||||
KeywordUsageCountsVo counts = new KeywordUsageCountsVo();
|
||||
counts.setCopy(copy);
|
||||
counts.setCopyExisting(copyExisting);
|
||||
counts.setCopyDeleted(Math.max(0, copy - copyExisting));
|
||||
counts.setAdd(add);
|
||||
|
||||
vo.setTotal(total);
|
||||
vo.setRows(keywordUsageAdminMapper.selectUsageRows(filter));
|
||||
vo.setCounts(counts);
|
||||
return vo;
|
||||
}
|
||||
|
||||
public KeywordUsagePageVo deletes(Long companyId, String user, String country, String keyword,
|
||||
Long page, Long pageSize) {
|
||||
KeywordUsageFilterQuery filter = buildFilter(companyId, user, country, keyword, page, pageSize);
|
||||
KeywordUsagePageVo vo = new KeywordUsagePageVo();
|
||||
vo.setTotal(keywordUsageAdminMapper.countDeletes(filter));
|
||||
vo.setRows(keywordUsageAdminMapper.selectDeleteRows(filter));
|
||||
vo.setCounts(new KeywordUsageCountsVo());
|
||||
return vo;
|
||||
}
|
||||
|
||||
public KeywordUsageOverviewVo overview(Long companyId) {
|
||||
KeywordUsageStatsVo stats = keywordUsageAdminMapper.selectStats(companyId);
|
||||
if (stats == null) {
|
||||
stats = new KeywordUsageStatsVo();
|
||||
}
|
||||
stats.setDeletedKw(Math.max(0, stats.getUsed() - stats.getExist()));
|
||||
stats.setTotalUse(stats.getUsed() + stats.getAdded());
|
||||
|
||||
List<String> countries = new ArrayList<>(BASE_COUNTRIES);
|
||||
for (String country : safeList(keywordUsageAdminMapper.selectCountries(companyId))) {
|
||||
if (!countries.contains(country)) {
|
||||
countries.add(country);
|
||||
}
|
||||
}
|
||||
|
||||
KeywordUsageOverviewVo vo = new KeywordUsageOverviewVo();
|
||||
vo.setStats(stats);
|
||||
vo.setUsers(safeList(keywordUsageAdminMapper.selectUsers(companyId)));
|
||||
vo.setCountries(countries);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private KeywordUsageFilterQuery buildFilter(Long companyId, String user, String country, String keyword,
|
||||
Long page, Long pageSize) {
|
||||
KeywordUsageFilterQuery filter = new KeywordUsageFilterQuery();
|
||||
filter.setCompanyId(companyId);
|
||||
filter.setUser(trimToNull(user));
|
||||
filter.setCountry(normalizeCountry(country));
|
||||
filter.setKeyword(trimToNull(keyword));
|
||||
long safePage = page == null || page < 1 ? 1 : page;
|
||||
long safeSize = pageSize == null ? DEFAULT_PAGE_SIZE : Math.min(Math.max(pageSize, 1), MAX_PAGE_SIZE);
|
||||
filter.setOffset((safePage - 1) * safeSize);
|
||||
filter.setLimit(safeSize);
|
||||
return filter;
|
||||
}
|
||||
|
||||
private void applyScene(KeywordUsageFilterQuery filter, String scene) {
|
||||
String value = trimToNull(scene);
|
||||
boolean copy = value == null || "已使用".equals(value) || "复制关键词".equals(value);
|
||||
boolean add = value == null || "添加关键词".equals(value);
|
||||
if (!copy && !add) {
|
||||
throw new BusinessException("scene 只支持 已使用 / 添加关键词");
|
||||
}
|
||||
filter.setIncludeCopy(copy);
|
||||
filter.setIncludeAdd(add);
|
||||
}
|
||||
|
||||
private String normalizeCountry(String country) {
|
||||
String value = trimToNull(country);
|
||||
return value == null || "全部".equals(value) ? null : value;
|
||||
}
|
||||
|
||||
private String trimToNull(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String trimmed = value.trim();
|
||||
return trimmed.isEmpty() ? null : trimmed;
|
||||
}
|
||||
|
||||
private List<String> safeList(List<String> values) {
|
||||
return values == null ? List.of() : values;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -80,7 +80,6 @@ public class PermissionMenuSchemaInitializer {
|
||||
new DefaultAdminMenu("密钥用量统计", "admin_user_secret_usage", "account/user-secret-usage", 42, "admin_group_account"),
|
||||
new DefaultAdminMenu("去重数据汇总", "admin_dedupe_total_data", "dedupe-total-data", 30, "admin_group_data"),
|
||||
new DefaultAdminMenu("品牌数据库", "admin_invalid_asin_data", "invalid-asin-data", 35, "admin_group_data"),
|
||||
new DefaultAdminMenu("品牌Gating库", "admin_brand_gating", "brand-gating", 36, "admin_group_data"),
|
||||
new DefaultAdminMenu("查询ASIN", "admin_query_asin", "query-asin", 65, "admin_group_data"),
|
||||
new DefaultAdminMenu("商品类目", "admin_product_categories", "product-categories", 66, "admin_group_data"),
|
||||
new DefaultAdminMenu("店铺密钥管理", "admin_shop_keys", "shop-keys", 40, "admin_group_shop"),
|
||||
@@ -88,6 +87,8 @@ public class PermissionMenuSchemaInitializer {
|
||||
new DefaultAdminMenu("最低价ASIN设置", "admin_skip_price_asin", "skip-price-asin", 60, "admin_group_shop"),
|
||||
new DefaultAdminMenu("店铺数据记录", "admin_shop_data_crawl_tasks", "shop-data-crawl-tasks", 82, "admin_group_shop"),
|
||||
new DefaultAdminMenu("店铺数据重复检查", "admin_shop_data_duplicate_check", "shop-data-duplicate-check", 84, "admin_group_shop"),
|
||||
new DefaultAdminMenu("品牌Gating库", "admin_brand_gating", "brand-gating", 85, "admin_group_shop"),
|
||||
new DefaultAdminMenu("关键词使用记录", "admin_keyword_usage", "keyword-usage", 86, "admin_group_shop"),
|
||||
new DefaultAdminMenu("生成记录", "admin_history", "history", 70, "admin_group_record"),
|
||||
new DefaultAdminMenu("视频任务记录", "admin_image_video_tasks", "image-video-tasks", 75, "admin_group_record"),
|
||||
new DefaultAdminMenu("软件版本管理", "admin_version", "version", 80, "admin_group_record"),
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
-- =============================================================
|
||||
-- 迁移 V175__move_gating_and_add_keyword_usage_menu
|
||||
--
|
||||
-- 1. 变更目的(2026-10-25 控制方截图定案):
|
||||
-- a) 「品牌Gating库」从数据管理组迁到店铺管理组 admin_group_shop,排序 85,
|
||||
-- 紧跟「店铺数据重复检查」(84);
|
||||
-- b) 新增「关键词使用记录」独立菜单 admin_keyword_usage,挂在店铺管理组,排序 86。
|
||||
--
|
||||
-- 2. 口径:
|
||||
-- - 两行都按每家公司一套菜单树维护:company_id=1 为模板行,其余公司(含停用公司)
|
||||
-- 逐家复制;子行 parent_id 必须认本公司 admin_group_shop 组行,严禁跨公司认父。
|
||||
-- - 品牌Gating库行由 V174 恢复,V175 只改 parent_id/sort_order,不重建、不删授权。
|
||||
-- - 关键词使用记录只读页面,默认不预授 user_column_permission;管理员角色链可直进,
|
||||
-- 普通账号由管理员在「菜单权限配置」里按公司分配。
|
||||
-- - 幂等守卫按 (company_id, column_key) 判存,同时防 (menu_type, route_path) 唯一键
|
||||
-- uk_company_menu_type_route_path 撞行。
|
||||
--
|
||||
-- 3. 影响表与数据量:columns 更新 N 行 + 新增 N 行(N = 公司数),字典小表,毫秒级。
|
||||
--
|
||||
-- 4. 【可重跑性】UPDATE 重复执行结果一致;两段 INSERT 都带 NOT EXISTS 守卫,重跑逐条 no-op。
|
||||
-- =============================================================
|
||||
|
||||
-- ---------- 1. 品牌Gating库归位:店铺管理组、排序 85 ----------
|
||||
UPDATE `columns` col
|
||||
JOIN `columns` grp
|
||||
ON grp.`company_id` = col.`company_id`
|
||||
AND grp.`column_key` = 'admin_group_shop'
|
||||
SET col.`parent_id` = grp.`id`,
|
||||
col.`sort_order` = 85
|
||||
WHERE col.`column_key` = 'admin_brand_gating';
|
||||
|
||||
-- ---------- 2. 公司 1 模板行:关键词使用记录 ----------
|
||||
INSERT INTO `columns` (`name`, `column_key`, `menu_type`, `route_path`, `sort_order`, `parent_id`, `company_id`)
|
||||
SELECT '关键词使用记录', 'admin_keyword_usage', 'admin', 'keyword-usage', 86, grp.`id`, 1
|
||||
FROM `columns` grp
|
||||
WHERE grp.`company_id` = 1 AND grp.`column_key` = 'admin_group_shop'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM `columns`
|
||||
WHERE `company_id` = 1
|
||||
AND (`column_key` = 'admin_keyword_usage'
|
||||
OR (`menu_type` = 'admin' AND `route_path` = 'keyword-usage'))
|
||||
);
|
||||
|
||||
-- ---------- 3. 复制到其余公司(含停用公司),各自认本公司店铺管理组行 ----------
|
||||
INSERT INTO `columns` (`name`, `column_key`, `menu_type`, `route_path`, `sort_order`, `parent_id`, `company_id`)
|
||||
SELECT '关键词使用记录', 'admin_keyword_usage', 'admin', 'keyword-usage', 86, grp.`id`, c.`id`
|
||||
FROM `company` c
|
||||
JOIN `columns` grp ON grp.`company_id` = c.`id` AND grp.`column_key` = 'admin_group_shop'
|
||||
WHERE c.`id` <> 1
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM `columns` col
|
||||
WHERE col.`company_id` = c.`id`
|
||||
AND (col.`column_key` = 'admin_keyword_usage'
|
||||
OR (col.`menu_type` = 'admin' AND col.`route_path` = 'keyword-usage'))
|
||||
);
|
||||
|
||||
-- ---------- 4. 自检闸门:不为 0 就抛 1048(列 must_be_zero NOT NULL) ----------
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS `_v175_gate` (`must_be_zero` INT NOT NULL);
|
||||
|
||||
-- 闸门 1:每家公司恰好一行品牌Gating库,且父必须是本公司店铺管理组、排序 85
|
||||
INSERT INTO `_v175_gate`
|
||||
SELECT IF(COUNT(*) = 0, 0, NULL)
|
||||
FROM (
|
||||
SELECT c.`id`
|
||||
FROM `company` c
|
||||
LEFT JOIN `columns` col ON col.`company_id` = c.`id` AND col.`column_key` = 'admin_brand_gating'
|
||||
LEFT JOIN `columns` grp ON grp.`id` = col.`parent_id`
|
||||
AND grp.`company_id` = c.`id` AND grp.`column_key` = 'admin_group_shop'
|
||||
GROUP BY c.`id`
|
||||
HAVING COUNT(col.`id`) <> 1 OR COUNT(grp.`id`) <> 1 OR MAX(col.`sort_order`) <> 85
|
||||
) bad;
|
||||
|
||||
-- 闸门 2:每家公司恰好一行关键词使用记录,且父必须是本公司店铺管理组、排序 86
|
||||
INSERT INTO `_v175_gate`
|
||||
SELECT IF(COUNT(*) = 0, 0, NULL)
|
||||
FROM (
|
||||
SELECT c.`id`
|
||||
FROM `company` c
|
||||
LEFT JOIN `columns` col ON col.`company_id` = c.`id` AND col.`column_key` = 'admin_keyword_usage'
|
||||
LEFT JOIN `columns` grp ON grp.`id` = col.`parent_id`
|
||||
AND grp.`company_id` = c.`id` AND grp.`column_key` = 'admin_group_shop'
|
||||
GROUP BY c.`id`
|
||||
HAVING COUNT(col.`id`) <> 1 OR COUNT(grp.`id`) <> 1 OR MAX(col.`sort_order`) <> 86
|
||||
) bad;
|
||||
|
||||
-- 闸门 3:两条路由不允许被别的 column_key 占行
|
||||
INSERT INTO `_v175_gate`
|
||||
SELECT IF(COUNT(*) = 0, 0, NULL)
|
||||
FROM `columns` col
|
||||
WHERE col.`menu_type` = 'admin'
|
||||
AND col.`route_path` IN ('brand-gating', 'keyword-usage')
|
||||
AND col.`column_key` NOT IN ('admin_brand_gating', 'admin_keyword_usage');
|
||||
|
||||
-- 闸门 4:两个 key 的 route_path 必须各自保持原值(防止历史行被别的迁移改名)
|
||||
INSERT INTO `_v175_gate`
|
||||
SELECT IF(COUNT(*) = 0, 0, NULL)
|
||||
FROM `columns` col
|
||||
WHERE (col.`column_key` = 'admin_brand_gating' AND col.`route_path` <> 'brand-gating')
|
||||
OR (col.`column_key` = 'admin_keyword_usage' AND col.`route_path` <> 'keyword-usage');
|
||||
|
||||
DROP TEMPORARY TABLE `_v175_gate`;
|
||||
@@ -0,0 +1,158 @@
|
||||
<?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.keywordusage.mapper.KeywordUsageAdminMapper">
|
||||
<!-- 关键词使用记录(管理后台只读视图)。四张表由桌面端/keywordshare 模块维护,这里只查不写;
|
||||
筛选值一律 #{} 占位符,LIKE 由 CONCAT 拼通配符,不拼接用户输入。 -->
|
||||
|
||||
<sql id="usageConds">
|
||||
<if test="f.companyId != null">AND k.company_id = #{f.companyId}</if>
|
||||
<if test="f.user != null and f.user != ''">AND k.user_name = #{f.user}</if>
|
||||
<if test="f.country != null and f.country != ''">AND k.country = #{f.country}</if>
|
||||
<if test="f.keyword != null and f.keyword != ''">
|
||||
AND k.keyword LIKE CONCAT('%', #{f.keyword}, '%')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="addConds">
|
||||
<if test="f.companyId != null">AND a.company_id = #{f.companyId}</if>
|
||||
<if test="f.user != null and f.user != ''">AND a.user_name = #{f.user}</if>
|
||||
<if test="f.country != null and f.country != ''">AND a.country = #{f.country}</if>
|
||||
<if test="f.keyword != null and f.keyword != ''">
|
||||
AND a.keyword LIKE CONCAT('%', #{f.keyword}, '%')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="deleteConds">
|
||||
<if test="f.companyId != null">AND d.company_id = #{f.companyId}</if>
|
||||
<if test="f.user != null and f.user != ''">AND d.user_name = #{f.user}</if>
|
||||
<if test="f.country != null and f.country != ''">AND d.country = #{f.country}</if>
|
||||
<if test="f.keyword != null and f.keyword != ''">
|
||||
AND d.keyword LIKE CONCAT('%', #{f.keyword}, '%')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="countUsageRows" resultType="long">
|
||||
SELECT
|
||||
<choose>
|
||||
<when test="f.includeCopy and f.includeAdd">
|
||||
(SELECT COUNT(*) FROM keyword_usage k WHERE 1=1 <include refid="usageConds"/>)
|
||||
+ (SELECT COUNT(*) FROM keyword_add_log a WHERE 1=1 <include refid="addConds"/>)
|
||||
</when>
|
||||
<when test="f.includeCopy">
|
||||
(SELECT COUNT(*) FROM keyword_usage k WHERE 1=1 <include refid="usageConds"/>)
|
||||
</when>
|
||||
<when test="f.includeAdd">
|
||||
(SELECT COUNT(*) FROM keyword_add_log a WHERE 1=1 <include refid="addConds"/>)
|
||||
</when>
|
||||
<otherwise>0</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
|
||||
<select id="selectUsageRows" resultType="com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsageRowVo">
|
||||
SELECT x.user_name AS userName,
|
||||
x.country AS country,
|
||||
x.keyword AS keyword,
|
||||
x.scene AS scene,
|
||||
x.op_time AS `time`
|
||||
FROM (
|
||||
<if test="f.includeCopy">
|
||||
SELECT k.user_name, k.country, k.keyword, '复制关键词' AS scene,
|
||||
k.used_time AS op_time, k.id AS sid
|
||||
FROM keyword_usage k
|
||||
WHERE 1=1 <include refid="usageConds"/>
|
||||
</if>
|
||||
<if test="f.includeCopy and f.includeAdd">UNION ALL</if>
|
||||
<if test="f.includeAdd">
|
||||
SELECT a.user_name, a.country, a.keyword, '添加关键词' AS scene,
|
||||
a.add_time AS op_time, a.id AS sid
|
||||
FROM keyword_add_log a
|
||||
WHERE 1=1 <include refid="addConds"/>
|
||||
</if>
|
||||
) x
|
||||
ORDER BY x.op_time DESC, x.sid DESC
|
||||
LIMIT #{f.offset}, #{f.limit}
|
||||
</select>
|
||||
|
||||
<select id="countCopy" resultType="long">
|
||||
SELECT COUNT(*) FROM keyword_usage k WHERE 1=1 <include refid="usageConds"/>
|
||||
</select>
|
||||
|
||||
<select id="countCopyExisting" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM keyword_usage k
|
||||
INNER JOIN keyword_share s
|
||||
ON s.company_id = k.company_id
|
||||
AND s.country = k.country
|
||||
AND s.keyword = k.keyword
|
||||
WHERE 1=1 <include refid="usageConds"/>
|
||||
</select>
|
||||
|
||||
<select id="countAdd" resultType="long">
|
||||
SELECT COUNT(*) FROM keyword_add_log a WHERE 1=1 <include refid="addConds"/>
|
||||
</select>
|
||||
|
||||
<select id="countDeletes" resultType="long">
|
||||
SELECT COUNT(*) FROM keyword_delete_log d WHERE 1=1 <include refid="deleteConds"/>
|
||||
</select>
|
||||
|
||||
<select id="selectDeleteRows" resultType="com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsageRowVo">
|
||||
SELECT d.user_name AS userName,
|
||||
d.country AS country,
|
||||
d.keyword AS keyword,
|
||||
'删除关键词' AS scene,
|
||||
d.delete_time AS `time`
|
||||
FROM keyword_delete_log d
|
||||
WHERE 1=1 <include refid="deleteConds"/>
|
||||
ORDER BY d.delete_time DESC, d.id DESC
|
||||
LIMIT #{f.offset}, #{f.limit}
|
||||
</select>
|
||||
|
||||
<select id="selectStats" resultType="com.nanri.aiimage.modules.keywordusage.model.vo.KeywordUsageStatsVo">
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM keyword_usage k
|
||||
WHERE 1=1
|
||||
<if test="companyId != null">AND k.company_id = #{companyId}</if>) AS used,
|
||||
(SELECT COUNT(*)
|
||||
FROM keyword_usage k
|
||||
INNER JOIN keyword_share s
|
||||
ON s.company_id = k.company_id
|
||||
AND s.country = k.country
|
||||
AND s.keyword = k.keyword
|
||||
WHERE 1=1
|
||||
<if test="companyId != null">AND k.company_id = #{companyId}</if>) AS exist,
|
||||
(SELECT COUNT(*) FROM keyword_add_log a
|
||||
WHERE 1=1
|
||||
<if test="companyId != null">AND a.company_id = #{companyId}</if>) AS added,
|
||||
(SELECT COUNT(*) FROM keyword_delete_log d
|
||||
WHERE 1=1
|
||||
<if test="companyId != null">AND d.company_id = #{companyId}</if>) AS deletes
|
||||
</select>
|
||||
|
||||
<select id="selectUsers" resultType="string">
|
||||
SELECT DISTINCT user_name
|
||||
FROM (
|
||||
SELECT user_name, company_id FROM keyword_usage
|
||||
UNION
|
||||
SELECT user_name, company_id FROM keyword_add_log
|
||||
UNION
|
||||
SELECT user_name, company_id FROM keyword_delete_log
|
||||
) t
|
||||
WHERE user_name IS NOT NULL AND user_name != ''
|
||||
<if test="companyId != null">AND company_id = #{companyId}</if>
|
||||
ORDER BY user_name
|
||||
</select>
|
||||
|
||||
<select id="selectCountries" resultType="string">
|
||||
SELECT DISTINCT country
|
||||
FROM (
|
||||
SELECT country, company_id FROM keyword_usage
|
||||
UNION
|
||||
SELECT country, company_id FROM keyword_add_log
|
||||
UNION
|
||||
SELECT country, company_id FROM keyword_delete_log
|
||||
) t
|
||||
WHERE country IS NOT NULL AND country != ''
|
||||
<if test="companyId != null">AND company_id = #{companyId}</if>
|
||||
ORDER BY country
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user