知识库代码框架
This commit is contained in:
@@ -195,6 +195,8 @@ public class PasswordUtil {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -179,6 +179,8 @@ public class ServiceManager {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -131,7 +131,8 @@ public class CustomerManagementController {
|
||||
@Parameter(description = "每页大小", example = "10")
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@Parameter(description = "客户姓名(模糊查询)")@RequestParam(required = false) String customerName,
|
||||
@Parameter(description = "所属人(模糊查询)")@RequestParam(required = false) String salesName,
|
||||
@Parameter(description = "所属人姓名(模糊查询)")@RequestParam(required = false) String salesName,
|
||||
@Parameter(description = "所属人电话")@RequestParam(required = false) String salesPhone,
|
||||
@Parameter(description = "联系方式(模糊查询)")
|
||||
@RequestParam(required = false) String contact,
|
||||
@Parameter(description = "所属门店ID")
|
||||
@@ -153,8 +154,8 @@ public class CustomerManagementController {
|
||||
if (customerName != null && !customerName.trim().isEmpty()) {
|
||||
queryWrapper.like(CustomerManagement::getCustomerName, customerName);
|
||||
}
|
||||
if (salesName != null && !salesName.trim().isEmpty()) {
|
||||
queryWrapper.like(CustomerManagement::getSalesName, salesName);
|
||||
if (salesPhone != null && !salesPhone.trim().isEmpty()) {
|
||||
queryWrapper.like(CustomerManagement::getSalesPhone, salesPhone);
|
||||
}
|
||||
if (contact != null && !contact.trim().isEmpty()) {
|
||||
queryWrapper.like(CustomerManagement::getContact, contact);
|
||||
|
||||
203
src/main/java/com/rj/controller/KnowledgeBaseController.java
Normal file
203
src/main/java/com/rj/controller/KnowledgeBaseController.java
Normal file
@@ -0,0 +1,203 @@
|
||||
package com.rj.controller;
|
||||
|
||||
import com.rj.entity.KnowledgeBase;
|
||||
import com.rj.service.IKnowledgeBaseService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 知识库管理表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 李中华 ,spllzh
|
||||
* @since 2025-01-27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/knowledgeBase")
|
||||
@Tag(name = "知识库管理", description = "知识库管理相关接口")
|
||||
public class KnowledgeBaseController {
|
||||
|
||||
@Autowired
|
||||
private IKnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
/**
|
||||
* 新增知识
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增知识", description = "添加新的知识信息")
|
||||
public ResponseEntity<Map<String, Object>> addKnowledge(
|
||||
@Parameter(description = "知识信息", required = true)
|
||||
@RequestBody KnowledgeBase knowledgeBase) {
|
||||
Map<String, Object> result = knowledgeBaseService.addKnowledge(knowledgeBase);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询知识
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
@Operation(summary = "根据ID查询知识", description = "根据知识ID获取知识详细信息")
|
||||
public ResponseEntity<Map<String, Object>> getKnowledgeById(
|
||||
@Parameter(description = "知识ID", required = true)
|
||||
@PathVariable String id) {
|
||||
Map<String, Object> result = knowledgeBaseService.getKnowledgeById(id);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询知识列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "分页查询知识列表", description = "分页查询知识信息列表")
|
||||
public ResponseEntity<Map<String, Object>> getKnowledgeList(
|
||||
@Parameter(description = "页码", example = "1")
|
||||
@RequestParam(defaultValue = "1") Integer current,
|
||||
@Parameter(description = "每页大小", example = "10")
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@Parameter(description = "知识标题(模糊查询)")
|
||||
@RequestParam(required = false) String title,
|
||||
@Parameter(description = "知识分类")
|
||||
@RequestParam(required = false) String category,
|
||||
@Parameter(description = "应用行业")
|
||||
@RequestParam(required = false) String industry,
|
||||
@Parameter(description = "创建人")
|
||||
@RequestParam(required = false) String creator,
|
||||
@Parameter(description = "状态")
|
||||
@RequestParam(required = false) String status) {
|
||||
Map<String, Object> result = knowledgeBaseService.getKnowledgeList(current, size, title, category, industry, creator, status);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新知识信息
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新知识信息", description = "更新知识详细信息")
|
||||
public ResponseEntity<Map<String, Object>> updateKnowledge(
|
||||
@Parameter(description = "知识信息", required = true)
|
||||
@RequestBody KnowledgeBase knowledgeBase) {
|
||||
Map<String, Object> result = knowledgeBaseService.updateKnowledge(knowledgeBase);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除知识
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@Operation(summary = "删除知识", description = "根据知识ID删除知识信息")
|
||||
public ResponseEntity<Map<String, Object>> deleteKnowledge(
|
||||
@Parameter(description = "知识ID", required = true)
|
||||
@PathVariable String id) {
|
||||
Map<String, Object> result = knowledgeBaseService.deleteKnowledge(id);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除知识
|
||||
*/
|
||||
@DeleteMapping("/batchDelete")
|
||||
@Operation(summary = "批量删除知识", description = "根据知识ID列表批量删除知识信息")
|
||||
public ResponseEntity<Map<String, Object>> batchDeleteKnowledge(
|
||||
@Parameter(description = "知识ID列表", required = true)
|
||||
@RequestBody List<String> ids) {
|
||||
Map<String, Object> result = knowledgeBaseService.batchDeleteKnowledge(ids);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 点赞知识
|
||||
*/
|
||||
@PostMapping("/like/{id}")
|
||||
@Operation(summary = "点赞知识", description = "为指定知识点赞")
|
||||
public ResponseEntity<Map<String, Object>> likeKnowledge(
|
||||
@Parameter(description = "知识ID", required = true)
|
||||
@PathVariable String id) {
|
||||
Map<String, Object> result = knowledgeBaseService.likeKnowledge(id);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 置顶/取消置顶知识
|
||||
*/
|
||||
@PostMapping("/toggleTop/{id}")
|
||||
@Operation(summary = "置顶/取消置顶知识", description = "切换知识的置顶状态")
|
||||
public ResponseEntity<Map<String, Object>> toggleTopKnowledge(
|
||||
@Parameter(description = "知识ID", required = true)
|
||||
@PathVariable String id) {
|
||||
Map<String, Object> result = knowledgeBaseService.toggleTopKnowledge(id);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识统计信息
|
||||
*/
|
||||
@GetMapping("/statistics")
|
||||
@Operation(summary = "获取知识统计信息", description = "获取知识总数等统计信息")
|
||||
public ResponseEntity<Map<String, Object>> getKnowledgeStatistics() {
|
||||
Map<String, Object> result = knowledgeBaseService.getKnowledgeStatistics();
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类列表
|
||||
*/
|
||||
@GetMapping("/categories")
|
||||
@Operation(summary = "获取分类列表", description = "获取所有知识分类")
|
||||
public ResponseEntity<Map<String, Object>> getCategories() {
|
||||
Map<String, Object> result = knowledgeBaseService.getCategories();
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取行业列表
|
||||
*/
|
||||
@GetMapping("/industries")
|
||||
@Operation(summary = "获取行业列表", description = "获取所有应用行业")
|
||||
public ResponseEntity<Map<String, Object>> getIndustries() {
|
||||
Map<String, Object> result = knowledgeBaseService.getIndustries();
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
}
|
||||
@@ -417,6 +417,8 @@ public class MenuController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -387,6 +387,8 @@ public class RoleController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -393,6 +393,8 @@ public class UserRoleController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -159,6 +159,8 @@ public class DifyWorkflowResponseDto {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
92
src/main/java/com/rj/entity/KnowledgeBase.java
Normal file
92
src/main/java/com/rj/entity/KnowledgeBase.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package com.rj.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 知识库管理表
|
||||
* </p>
|
||||
*
|
||||
* @author 李中华 ,spllzh
|
||||
* @since 2025-01-27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("knowledge_base")
|
||||
@Schema(description="知识库管理表")
|
||||
public class KnowledgeBase implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "主键ID,UUID")
|
||||
@TableId("id")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "知识标题")
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "知识分类")
|
||||
@TableField("category")
|
||||
private String category;
|
||||
|
||||
@Schema(description = "应用行业")
|
||||
@TableField("industry")
|
||||
private String industry;
|
||||
|
||||
@Schema(description = "知识内容")
|
||||
@TableField("content")
|
||||
private String content;
|
||||
|
||||
@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;
|
||||
}
|
||||
@@ -102,6 +102,8 @@ public interface CustomerProfileAnalysisMapper extends BaseMapper<CustomerProfil
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
16
src/main/java/com/rj/mapper/KnowledgeBaseMapper.java
Normal file
16
src/main/java/com/rj/mapper/KnowledgeBaseMapper.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.rj.mapper;
|
||||
|
||||
import com.rj.entity.KnowledgeBase;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 知识库管理表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 李中华 ,spllzh
|
||||
* @since 2025-01-27
|
||||
*/
|
||||
public interface KnowledgeBaseMapper extends BaseMapper<KnowledgeBase> {
|
||||
|
||||
}
|
||||
99
src/main/java/com/rj/service/IKnowledgeBaseService.java
Normal file
99
src/main/java/com/rj/service/IKnowledgeBaseService.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package com.rj.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.rj.entity.KnowledgeBase;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 知识库管理表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 李中华 ,spllzh
|
||||
* @since 2025-01-27
|
||||
*/
|
||||
public interface IKnowledgeBaseService extends IService<KnowledgeBase> {
|
||||
|
||||
/**
|
||||
* 新增知识
|
||||
* @param knowledgeBase 知识信息
|
||||
* @return 操作结果
|
||||
*/
|
||||
Map<String, Object> addKnowledge(KnowledgeBase knowledgeBase);
|
||||
|
||||
/**
|
||||
* 根据ID查询知识(增加浏览次数)
|
||||
* @param id 知识ID
|
||||
* @return 知识信息
|
||||
*/
|
||||
Map<String, Object> getKnowledgeById(String id);
|
||||
|
||||
/**
|
||||
* 分页查询知识列表
|
||||
* @param current 页码
|
||||
* @param size 每页大小
|
||||
* @param title 知识标题
|
||||
* @param category 知识分类
|
||||
* @param industry 应用行业
|
||||
* @param creator 创建人
|
||||
* @param status 状态
|
||||
* @return 分页结果
|
||||
*/
|
||||
Map<String, Object> getKnowledgeList(Integer current, Integer size, String title,
|
||||
String category, String industry, String creator, String status);
|
||||
|
||||
/**
|
||||
* 更新知识信息
|
||||
* @param knowledgeBase 知识信息
|
||||
* @return 操作结果
|
||||
*/
|
||||
Map<String, Object> updateKnowledge(KnowledgeBase knowledgeBase);
|
||||
|
||||
/**
|
||||
* 根据ID删除知识
|
||||
* @param id 知识ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
Map<String, Object> deleteKnowledge(String id);
|
||||
|
||||
/**
|
||||
* 批量删除知识
|
||||
* @param ids 知识ID列表
|
||||
* @return 操作结果
|
||||
*/
|
||||
Map<String, Object> batchDeleteKnowledge(List<String> ids);
|
||||
|
||||
/**
|
||||
* 点赞知识
|
||||
* @param id 知识ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
Map<String, Object> likeKnowledge(String id);
|
||||
|
||||
/**
|
||||
* 置顶/取消置顶知识
|
||||
* @param id 知识ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
Map<String, Object> toggleTopKnowledge(String id);
|
||||
|
||||
/**
|
||||
* 获取知识统计信息
|
||||
* @return 统计信息
|
||||
*/
|
||||
Map<String, Object> getKnowledgeStatistics();
|
||||
|
||||
/**
|
||||
* 获取分类列表
|
||||
* @return 分类列表
|
||||
*/
|
||||
Map<String, Object> getCategories();
|
||||
|
||||
/**
|
||||
* 获取行业列表
|
||||
* @return 行业列表
|
||||
*/
|
||||
Map<String, Object> getIndustries();
|
||||
}
|
||||
@@ -123,6 +123,8 @@ public interface ICustomerProfileAnalysisService extends IService<CustomerProfil
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -158,6 +158,8 @@ public class CustomerProfileAnalysisServiceImpl extends ServiceImpl<CustomerProf
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
350
src/main/java/com/rj/service/impl/KnowledgeBaseServiceImpl.java
Normal file
350
src/main/java/com/rj/service/impl/KnowledgeBaseServiceImpl.java
Normal file
@@ -0,0 +1,350 @@
|
||||
package com.rj.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.rj.entity.KnowledgeBase;
|
||||
import com.rj.mapper.KnowledgeBaseMapper;
|
||||
import com.rj.service.IKnowledgeBaseService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 知识库管理表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 李中华 ,spllzh
|
||||
* @since 2025-01-27
|
||||
*/
|
||||
@Service
|
||||
public class KnowledgeBaseServiceImpl extends ServiceImpl<KnowledgeBaseMapper, KnowledgeBase> implements IKnowledgeBaseService {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> addKnowledge(KnowledgeBase knowledgeBase) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
// 生成UUID作为主键
|
||||
knowledgeBase.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||
knowledgeBase.setCreateTime(LocalDateTime.now());
|
||||
knowledgeBase.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
// 设置默认值
|
||||
if (knowledgeBase.getViewCount() == null) {
|
||||
knowledgeBase.setViewCount(0);
|
||||
}
|
||||
if (knowledgeBase.getLikeCount() == null) {
|
||||
knowledgeBase.setLikeCount(0);
|
||||
}
|
||||
if (knowledgeBase.getSortOrder() == null) {
|
||||
knowledgeBase.setSortOrder(0);
|
||||
}
|
||||
if (knowledgeBase.getIsTop() == null) {
|
||||
knowledgeBase.setIsTop(false);
|
||||
}
|
||||
if (knowledgeBase.getStatus() == null || knowledgeBase.getStatus().trim().isEmpty()) {
|
||||
knowledgeBase.setStatus("已发布");
|
||||
}
|
||||
|
||||
boolean success = this.save(knowledgeBase);
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "知识添加成功");
|
||||
result.put("data", knowledgeBase);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "知识添加失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "知识添加异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getKnowledgeById(String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
KnowledgeBase knowledge = this.getById(id);
|
||||
if (knowledge != null) {
|
||||
// 增加浏览次数
|
||||
knowledge.setViewCount(knowledge.getViewCount() + 1);
|
||||
this.updateById(knowledge);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", knowledge);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "知识不存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getKnowledgeList(Integer current, Integer size, String title,
|
||||
String category, String industry, String creator, String status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
Page<KnowledgeBase> page = new Page<>(current, size);
|
||||
LambdaQueryWrapper<KnowledgeBase> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 添加查询条件
|
||||
if (title != null && !title.trim().isEmpty()) {
|
||||
queryWrapper.like(KnowledgeBase::getTitle, title);
|
||||
}
|
||||
if (category != null && !category.trim().isEmpty()) {
|
||||
queryWrapper.eq(KnowledgeBase::getCategory, category);
|
||||
}
|
||||
if (industry != null && !industry.trim().isEmpty()) {
|
||||
queryWrapper.eq(KnowledgeBase::getIndustry, industry);
|
||||
}
|
||||
if (creator != null && !creator.trim().isEmpty()) {
|
||||
queryWrapper.like(KnowledgeBase::getCreator, creator);
|
||||
}
|
||||
if (status != null && !status.trim().isEmpty()) {
|
||||
queryWrapper.eq(KnowledgeBase::getStatus, status);
|
||||
}
|
||||
|
||||
// 排序:置顶优先,然后按排序权重,最后按创建时间倒序
|
||||
queryWrapper.orderByDesc(KnowledgeBase::getUpdateTime);
|
||||
|
||||
Page<KnowledgeBase> knowledgePage = this.page(page, queryWrapper);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", knowledgePage.getRecords());
|
||||
result.put("total", knowledgePage.getTotal());
|
||||
result.put("current", knowledgePage.getCurrent());
|
||||
result.put("size", knowledgePage.getSize());
|
||||
result.put("pages", knowledgePage.getPages());
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> updateKnowledge(KnowledgeBase knowledgeBase) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (knowledgeBase.getId() == null || knowledgeBase.getId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "知识ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
knowledgeBase.setUpdateTime(LocalDateTime.now());
|
||||
boolean success = this.updateById(knowledgeBase);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "知识信息更新成功");
|
||||
result.put("data", knowledgeBase);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "知识信息更新失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "更新异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> deleteKnowledge(String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
boolean success = this.removeById(id);
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "知识删除成功");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "知识删除失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "删除异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> batchDeleteKnowledge(List<String> ids) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "知识ID列表不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean success = this.removeByIds(ids);
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "批量删除成功,共删除 " + ids.size() + " 条记录");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "批量删除失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "批量删除异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> likeKnowledge(String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
KnowledgeBase knowledge = this.getById(id);
|
||||
if (knowledge != null) {
|
||||
knowledge.setLikeCount(knowledge.getLikeCount() + 1);
|
||||
knowledge.setUpdateTime(LocalDateTime.now());
|
||||
boolean success = this.updateById(knowledge);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "点赞成功");
|
||||
result.put("data", knowledge);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "点赞失败");
|
||||
}
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "知识不存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "点赞异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toggleTopKnowledge(String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
KnowledgeBase knowledge = this.getById(id);
|
||||
if (knowledge != null) {
|
||||
knowledge.setIsTop(!knowledge.getIsTop());
|
||||
knowledge.setUpdateTime(LocalDateTime.now());
|
||||
boolean success = this.updateById(knowledge);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", knowledge.getIsTop() ? "置顶成功" : "取消置顶成功");
|
||||
result.put("data", knowledge);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "操作失败");
|
||||
}
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "知识不存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "操作异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getKnowledgeStatistics() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
long totalCount = this.count();
|
||||
|
||||
// 按状态统计
|
||||
LambdaQueryWrapper<KnowledgeBase> publishedWrapper = new LambdaQueryWrapper<>();
|
||||
publishedWrapper.eq(KnowledgeBase::getStatus, "已发布");
|
||||
long publishedCount = this.count(publishedWrapper);
|
||||
|
||||
LambdaQueryWrapper<KnowledgeBase> draftWrapper = new LambdaQueryWrapper<>();
|
||||
draftWrapper.eq(KnowledgeBase::getStatus, "草稿");
|
||||
long draftCount = this.count(draftWrapper);
|
||||
|
||||
LambdaQueryWrapper<KnowledgeBase> topWrapper = new LambdaQueryWrapper<>();
|
||||
topWrapper.eq(KnowledgeBase::getIsTop, true);
|
||||
long topCount = this.count(topWrapper);
|
||||
|
||||
Map<String, Object> statistics = new HashMap<>();
|
||||
statistics.put("totalKnowledge", totalCount);
|
||||
statistics.put("publishedCount", publishedCount);
|
||||
statistics.put("draftCount", draftCount);
|
||||
statistics.put("topCount", topCount);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "统计信息获取成功");
|
||||
result.put("data", statistics);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "统计信息获取异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getCategories() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
LambdaQueryWrapper<KnowledgeBase> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(KnowledgeBase::getCategory)
|
||||
.groupBy(KnowledgeBase::getCategory);
|
||||
List<KnowledgeBase> categories = this.list(queryWrapper);
|
||||
|
||||
List<String> categoryList = categories.stream()
|
||||
.map(KnowledgeBase::getCategory)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "分类列表获取成功");
|
||||
result.put("data", categoryList);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "分类列表获取异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getIndustries() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
LambdaQueryWrapper<KnowledgeBase> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(KnowledgeBase::getIndustry)
|
||||
.groupBy(KnowledgeBase::getIndustry);
|
||||
List<KnowledgeBase> industries = this.list(queryWrapper);
|
||||
|
||||
List<String> industryList = industries.stream()
|
||||
.map(KnowledgeBase::getIndustry)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "行业列表获取成功");
|
||||
result.put("data", industryList);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "行业列表获取异常:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -130,6 +130,8 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -130,6 +130,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -130,6 +130,8 @@ public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> i
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -139,6 +139,8 @@ spring:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -116,6 +116,8 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
30
src/main/resources/mapper/KnowledgeBaseMapper.xml
Normal file
30
src/main/resources/mapper/KnowledgeBaseMapper.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.rj.mapper.KnowledgeBaseMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.rj.entity.KnowledgeBase">
|
||||
<id column="id" property="id" />
|
||||
<result column="title" property="title" />
|
||||
<result column="category" property="category" />
|
||||
<result column="industry" property="industry" />
|
||||
<result column="content" property="content" />
|
||||
<result column="creator" property="creator" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="status" property="status" />
|
||||
<result column="view_count" property="viewCount" />
|
||||
<result column="like_count" property="likeCount" />
|
||||
<result column="tags" property="tags" />
|
||||
<result column="attachment_url" property="attachmentUrl" />
|
||||
<result column="sort_order" property="sortOrder" />
|
||||
<result column="is_top" property="isTop" />
|
||||
<result column="remark" property="remark" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, title, category, industry, content, creator, create_time, update_time, status, view_count, like_count, tags, attachment_url, sort_order, is_top, remark
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
@@ -315,6 +315,8 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -253,6 +253,8 @@ public class FaceDetectImageCountTest {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -194,6 +194,8 @@ public class TtsRequestLogShortUrlTest {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -172,6 +172,8 @@ public class VideoSynthesisTempUrlTest {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -147,6 +147,8 @@ public class VideoSynthesisVideoNameTest {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user