diff --git a/src/main/java/com/rj/controller/ScriptManagementMyController.java b/src/main/java/com/rj/controller/ScriptManagementMyController.java new file mode 100644 index 0000000..80e0343 --- /dev/null +++ b/src/main/java/com/rj/controller/ScriptManagementMyController.java @@ -0,0 +1,107 @@ +package com.rj.controller; + +import com.rj.entity.ScriptManagementMy; +import com.rj.service.IScriptManagementMyService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.Map; + +/** + * 知识库管理前端控制器 + */ +@Slf4j +@RestController +@RequestMapping("/api/scriptManagementMy") +@Tag(name = "话术库管理(script_management_my)", description = "增删改查与分页") +public class ScriptManagementMyController { + + @Autowired + private IScriptManagementMyService scriptManagementMyService; + + @PostMapping("/add") + @Operation(summary = "新增") + public ResponseEntity> add( + @Parameter(description = "实体", required = true) @RequestBody ScriptManagementMy entity) { + Map result = scriptManagementMyService.add(entity); + Boolean success = (Boolean) result.get("success"); + if (success != null && success) { + return ResponseEntity.ok(result); + } + return ResponseEntity.badRequest().body(result); + } + + @PutMapping("/update") + @Operation(summary = "更新") + public ResponseEntity> update( + @Parameter(description = "实体", required = true) @RequestBody ScriptManagementMy entity) { + Map result = scriptManagementMyService.update(entity); + Boolean success = (Boolean) result.get("success"); + if (success != null && success) { + return ResponseEntity.ok(result); + } + return ResponseEntity.badRequest().body(result); + } + + @DeleteMapping("/delete/{id}") + @Operation(summary = "删除") + public ResponseEntity> delete( + @Parameter(description = "主键ID", required = true) @PathVariable String id) { + Map result = scriptManagementMyService.deleteById(id); + Boolean success = (Boolean) result.get("success"); + if (success != null && success) { + return ResponseEntity.ok(result); + } + return ResponseEntity.badRequest().body(result); + } + + @GetMapping("/list") + @Operation(summary = "分页查询") + public ResponseEntity> list( + @RequestParam(defaultValue = "1") Integer current, + @RequestParam(defaultValue = "10") Integer size, + @RequestParam(required = false) String title, + @RequestParam(required = false) String category, + @RequestParam(required = false) String industry, + @RequestParam(required = false) String creator, + @RequestParam(required = false) String status) { + Map result = scriptManagementMyService.pageQuery( + current, size, title, category, industry, creator, status + ); + Boolean success = (Boolean) result.get("success"); + if (success != null && success) { + return ResponseEntity.ok(result); + } + return ResponseEntity.internalServerError().body(result); + } + + @GetMapping("/get/{id}") + @Operation(summary = "按ID查询") + public ResponseEntity> getById( + @Parameter(description = "主键ID", required = true) @PathVariable String id) { + Map result = new HashMap<>(); + try { + ScriptManagementMy data = scriptManagementMyService.getById(id); + if (data == null) { + result.put("success", false); + result.put("message", "记录不存在"); + return ResponseEntity.notFound().build(); + } + result.put("success", true); + result.put("message", "查询成功"); + result.put("data", data); + return ResponseEntity.ok(result); + } catch (Exception e) { + log.error("script_management_my get by id error, id={}", id, e); + result.put("success", false); + result.put("message", "查询异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } +} diff --git a/src/main/java/com/rj/entity/ScriptManagementMy.java b/src/main/java/com/rj/entity/ScriptManagementMy.java new file mode 100644 index 0000000..4b053de --- /dev/null +++ b/src/main/java/com/rj/entity/ScriptManagementMy.java @@ -0,0 +1,103 @@ +package com.rj.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * 知识库管理(表 script_management_my) + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("script_management_my") +@Schema(description = "知识库管理(script_management_my)") +public class ScriptManagementMy implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "主键ID,UUID") + @TableId("id") + private String id; + + @Schema(description = "租户id") + @TableField("tenant_id") + private String tenantId; + + @Schema(description = "知识标题") + @TableField("title") + private String title; + + @Schema(description = "知识分类") + @TableField("category") + private String category; + + @Schema(description = "应用行业") + @TableField("industry") + private String industry; + + @Schema(description = "问题") + @TableField("question") + private String question; + + @Schema(description = "知识内容") + @TableField("answer_content") + private String answerContent; + + @Schema(description = "详细分解") + @TableField("detailed_breakdown") + private String detailedBreakdown; + + @Schema(description = "使用场景") + @TableField("usage_scenario") + private String usageScenario; + + @Schema(description = "创建人") + @TableField("creator") + private String creator; + + @Schema(description = "创建时间") + @TableField("create_time") + private LocalDateTime createTime; + + @Schema(description = "更新时间") + @TableField("update_time") + private LocalDateTime updateTime; + + @Schema(description = "状态:已发布、草稿、已下架") + @TableField("status") + private String status; + + @Schema(description = "浏览次数") + @TableField("view_count") + private Integer viewCount; + + @Schema(description = "点赞次数") + @TableField("like_count") + private Integer likeCount; + + @Schema(description = "标签,多个用逗号分隔") + @TableField("tags") + private String tags; + + @Schema(description = "附件URL") + @TableField("attachment_url") + private String attachmentUrl; + + @Schema(description = "排序权重") + @TableField("sort_order") + private Integer sortOrder; + + @Schema(description = "是否置顶:0否,1是") + @TableField("is_top") + private Boolean isTop; + + @Schema(description = "备注") + @TableField("remark") + private String remark; +} diff --git a/src/main/java/com/rj/mapper/ScriptManagementMyMapper.java b/src/main/java/com/rj/mapper/ScriptManagementMyMapper.java new file mode 100644 index 0000000..b8d66e9 --- /dev/null +++ b/src/main/java/com/rj/mapper/ScriptManagementMyMapper.java @@ -0,0 +1,12 @@ +package com.rj.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.rj.entity.ScriptManagementMy; +import org.apache.ibatis.annotations.Mapper; + +/** + * 知识库管理表 Mapper + */ +@Mapper +public interface ScriptManagementMyMapper extends BaseMapper { +} diff --git a/src/main/java/com/rj/service/IScriptManagementMyService.java b/src/main/java/com/rj/service/IScriptManagementMyService.java new file mode 100644 index 0000000..0d69901 --- /dev/null +++ b/src/main/java/com/rj/service/IScriptManagementMyService.java @@ -0,0 +1,21 @@ +package com.rj.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.rj.entity.ScriptManagementMy; + +import java.util.Map; + +/** + * 知识库管理服务 + */ +public interface IScriptManagementMyService extends IService { + + Map add(ScriptManagementMy entity); + + Map update(ScriptManagementMy entity); + + Map deleteById(String id); + + Map pageQuery(Integer current, Integer size, String title, String category, String industry, + String creator, String status); +} diff --git a/src/main/java/com/rj/service/impl/ScriptManagementMyServiceImpl.java b/src/main/java/com/rj/service/impl/ScriptManagementMyServiceImpl.java new file mode 100644 index 0000000..b98d07c --- /dev/null +++ b/src/main/java/com/rj/service/impl/ScriptManagementMyServiceImpl.java @@ -0,0 +1,148 @@ +package com.rj.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.rj.entity.ScriptManagementMy; +import com.rj.mapper.ScriptManagementMyMapper; +import com.rj.service.IScriptManagementMyService; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * 知识库管理服务实现 + */ +@Service +public class ScriptManagementMyServiceImpl extends ServiceImpl + implements IScriptManagementMyService { + + private static final String DEFAULT_STATUS = "已发布"; + + @Override + public Map add(ScriptManagementMy entity) { + Map result = new HashMap<>(); + try { + entity.setId(UUID.randomUUID().toString().replace("-", "")); + LocalDateTime now = LocalDateTime.now(); + entity.setCreateTime(now); + entity.setUpdateTime(now); + if (entity.getStatus() == null || entity.getStatus().trim().isEmpty()) { + entity.setStatus(DEFAULT_STATUS); + } + if (entity.getViewCount() == null) { + entity.setViewCount(0); + } + if (entity.getLikeCount() == null) { + entity.setLikeCount(0); + } + if (entity.getSortOrder() == null) { + entity.setSortOrder(0); + } + if (entity.getIsTop() == null) { + entity.setIsTop(false); + } + boolean ok = this.save(entity); + result.put("success", ok); + result.put("message", ok ? "添加成功" : "添加失败"); + if (ok) { + result.put("data", entity); + } + return result; + } catch (Exception e) { + result.put("success", false); + result.put("message", "添加异常:" + e.getMessage()); + return result; + } + } + + @Override + public Map update(ScriptManagementMy entity) { + Map result = new HashMap<>(); + try { + if (entity.getId() == null || entity.getId().trim().isEmpty()) { + result.put("success", false); + result.put("message", "ID不能为空"); + return result; + } + entity.setUpdateTime(LocalDateTime.now()); + boolean ok = this.updateById(entity); + result.put("success", ok); + result.put("message", ok ? "更新成功" : "更新失败"); + if (ok) { + result.put("data", this.getById(entity.getId())); + } + return result; + } catch (Exception e) { + result.put("success", false); + result.put("message", "更新异常:" + e.getMessage()); + return result; + } + } + + @Override + public Map deleteById(String id) { + Map result = new HashMap<>(); + try { + boolean ok = this.removeById(id); + result.put("success", ok); + result.put("message", ok ? "删除成功" : "删除失败"); + return result; + } catch (Exception e) { + result.put("success", false); + result.put("message", "删除异常:" + e.getMessage()); + return result; + } + } + + @Override + public Map pageQuery(Integer current, Integer size, String title, String category, String industry, + String creator, String status) { + Map result = new HashMap<>(); + try { + if (current == null || current < 1) { + current = 1; + } + if (size == null || size < 1) { + size = 10; + } + Page page = new Page<>(current, size); + LambdaQueryWrapper q = new LambdaQueryWrapper<>(); + if (title != null && !title.trim().isEmpty()) { + q.like(ScriptManagementMy::getTitle, title.trim()); + } + if (category != null && !category.trim().isEmpty()) { + q.eq(ScriptManagementMy::getCategory, category.trim()); + } + if (industry != null && !industry.trim().isEmpty()) { + q.eq(ScriptManagementMy::getIndustry, industry.trim()); + } + if (creator != null && !creator.trim().isEmpty()) { + q.like(ScriptManagementMy::getCreator, creator.trim()); + } + if (status != null && !status.trim().isEmpty()) { + q.eq(ScriptManagementMy::getStatus, status.trim()); + } + q.orderByDesc(ScriptManagementMy::getIsTop) + .orderByDesc(ScriptManagementMy::getSortOrder) + .orderByDesc(ScriptManagementMy::getUpdateTime); + + Page data = this.page(page, q); + result.put("success", true); + result.put("message", "查询成功"); + result.put("data", data.getRecords()); + result.put("total", data.getTotal()); + result.put("current", data.getCurrent()); + result.put("size", data.getSize()); + result.put("pages", data.getPages()); + return result; + } catch (Exception e) { + result.put("success", false); + result.put("message", "查询异常:" + e.getMessage()); + return result; + } + } +} diff --git a/src/main/sql/touch_red_line.sql b/src/main/sql/touch_red_line.sql index 26515f0..7e56a56 100644 --- a/src/main/sql/touch_red_line.sql +++ b/src/main/sql/touch_red_line.sql @@ -1,6 +1,9 @@ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; +-- 说明:本文件为「删表重建」全量脚本,仅适合空库/可丢数据环境。 +-- 若库中已有旧结构 red_line_record(缺 sales_id 等列),请执行: +-- touch_red_line_alter_add_sales_and_subtype.sql -- ---------------------------- -- Table structure for red_line_record -- 触及红线记录:关联录音主表与分段,记录类型、阈值与当时文本 diff --git a/src/main/sql/touch_red_line_alter_add_sales_and_subtype.sql b/src/main/sql/touch_red_line_alter_add_sales_and_subtype.sql new file mode 100644 index 0000000..b5a7739 --- /dev/null +++ b/src/main/sql/touch_red_line_alter_add_sales_and_subtype.sql @@ -0,0 +1,23 @@ +-- ============================================================================= +-- 升级脚本:为已存在的 red_line_record 表补齐与 Java 实体一致的列与索引。 +-- 报错 Unknown column 'sales_id' 时,在目标库执行本脚本一次即可。 +-- 新建库请直接使用 touch_red_line.sql 全量建表,无需执行本脚本。 +-- ============================================================================= + +SET NAMES utf8mb4; + +-- 列(若某列已存在会报错,可删掉对应 ADD 行后重试) +ALTER TABLE `red_line_record` + ADD COLUMN `sales_id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '销售人员的id' AFTER `tenant_id`, + ADD COLUMN `sales_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '销售人员的姓名' AFTER `sales_id`, + ADD COLUMN `sales_phone` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '销售人员的电话' AFTER `sales_name`, + ADD COLUMN `red_line_subtype` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '触及的红线的子类型' AFTER `red_line_type`; + +-- 索引(若索引已存在会报错,可忽略或先 DROP INDEX) +ALTER TABLE `red_line_record` + ADD KEY `idx_red_line_subtype` (`red_line_subtype`) USING BTREE, + ADD KEY `idx_sales_id` (`sales_id`) USING BTREE; + +-- 若业务要求 sales_id 非空:先 UPDATE 补全所有行的 sales_id,再执行: +-- ALTER TABLE `red_line_record` +-- MODIFY COLUMN `sales_id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '销售人员的id';