Sop管理
This commit is contained in:
@@ -14,7 +14,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 知识库管理前端控制器
|
||||
* 话术库管理前端控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
||||
107
src/main/java/com/rj/controller/SopManagementMyController.java
Normal file
107
src/main/java/com/rj/controller/SopManagementMyController.java
Normal file
@@ -0,0 +1,107 @@
|
||||
package com.rj.controller;
|
||||
|
||||
import com.rj.entity.SopManagementMy;
|
||||
import com.rj.service.ISopManagementMyService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* SOP知识库管理前端控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/sopManagementMy")
|
||||
@Tag(name = "SOP知识库管理(sop_management_my)", description = "增删改查与分页")
|
||||
public class SopManagementMyController {
|
||||
|
||||
@Autowired
|
||||
private ISopManagementMyService sopManagementMyService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增")
|
||||
public ResponseEntity<Map<String, Object>> add(
|
||||
@Parameter(description = "实体", required = true) @RequestBody SopManagementMy entity) {
|
||||
Map<String, Object> result = sopManagementMyService.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<Map<String, Object>> update(
|
||||
@Parameter(description = "实体", required = true) @RequestBody SopManagementMy entity) {
|
||||
Map<String, Object> result = sopManagementMyService.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<Map<String, Object>> delete(
|
||||
@Parameter(description = "主键ID", required = true) @PathVariable String id) {
|
||||
Map<String, Object> result = sopManagementMyService.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<Map<String, Object>> 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<String, Object> result = sopManagementMyService.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<Map<String, Object>> getById(
|
||||
@Parameter(description = "主键ID", required = true) @PathVariable String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
SopManagementMy data = sopManagementMyService.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("sop_management_my get by id error, id={}", id, e);
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
91
src/main/java/com/rj/entity/SopManagementMy.java
Normal file
91
src/main/java/com/rj/entity/SopManagementMy.java
Normal file
@@ -0,0 +1,91 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* SOP知识库管理(表 sop_management_my)
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sop_management_my")
|
||||
@Schema(description = "SOP知识库管理(sop_management_my)")
|
||||
public class SopManagementMy 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 = "SOP标题")
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "SOP分类")
|
||||
@TableField("category")
|
||||
private String category;
|
||||
|
||||
@Schema(description = "应用行业")
|
||||
@TableField("industry")
|
||||
private String industry;
|
||||
|
||||
@Schema(description = "SOP内容")
|
||||
@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;
|
||||
}
|
||||
12
src/main/java/com/rj/mapper/SopManagementMyMapper.java
Normal file
12
src/main/java/com/rj/mapper/SopManagementMyMapper.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.rj.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.rj.entity.SopManagementMy;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* SOP知识库管理表 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface SopManagementMyMapper extends BaseMapper<SopManagementMy> {
|
||||
}
|
||||
21
src/main/java/com/rj/service/ISopManagementMyService.java
Normal file
21
src/main/java/com/rj/service/ISopManagementMyService.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.rj.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.rj.entity.SopManagementMy;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* SOP知识库管理服务
|
||||
*/
|
||||
public interface ISopManagementMyService extends IService<SopManagementMy> {
|
||||
|
||||
Map<String, Object> add(SopManagementMy entity);
|
||||
|
||||
Map<String, Object> update(SopManagementMy entity);
|
||||
|
||||
Map<String, Object> deleteById(String id);
|
||||
|
||||
Map<String, Object> pageQuery(Integer current, Integer size, String title, String category, String industry,
|
||||
String creator, String status);
|
||||
}
|
||||
@@ -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.SopManagementMy;
|
||||
import com.rj.mapper.SopManagementMyMapper;
|
||||
import com.rj.service.ISopManagementMyService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* SOP知识库管理服务实现
|
||||
*/
|
||||
@Service
|
||||
public class SopManagementMyServiceImpl extends ServiceImpl<SopManagementMyMapper, SopManagementMy>
|
||||
implements ISopManagementMyService {
|
||||
|
||||
private static final String DEFAULT_STATUS = "已发布";
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(SopManagementMy entity) {
|
||||
Map<String, Object> 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<String, Object> update(SopManagementMy entity) {
|
||||
Map<String, Object> 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<String, Object> deleteById(String id) {
|
||||
Map<String, Object> 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<String, Object> pageQuery(Integer current, Integer size, String title, String category, String industry,
|
||||
String creator, String status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (current == null || current < 1) {
|
||||
current = 1;
|
||||
}
|
||||
if (size == null || size < 1) {
|
||||
size = 10;
|
||||
}
|
||||
Page<SopManagementMy> page = new Page<>(current, size);
|
||||
LambdaQueryWrapper<SopManagementMy> q = new LambdaQueryWrapper<>();
|
||||
if (title != null && !title.trim().isEmpty()) {
|
||||
q.like(SopManagementMy::getTitle, title.trim());
|
||||
}
|
||||
if (category != null && !category.trim().isEmpty()) {
|
||||
q.eq(SopManagementMy::getCategory, category.trim());
|
||||
}
|
||||
if (industry != null && !industry.trim().isEmpty()) {
|
||||
q.eq(SopManagementMy::getIndustry, industry.trim());
|
||||
}
|
||||
if (creator != null && !creator.trim().isEmpty()) {
|
||||
q.like(SopManagementMy::getCreator, creator.trim());
|
||||
}
|
||||
if (status != null && !status.trim().isEmpty()) {
|
||||
q.eq(SopManagementMy::getStatus, status.trim());
|
||||
}
|
||||
q.orderByDesc(SopManagementMy::getIsTop)
|
||||
.orderByDesc(SopManagementMy::getSortOrder)
|
||||
.orderByDesc(SopManagementMy::getUpdateTime);
|
||||
|
||||
Page<SopManagementMy> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user