Ver código fonte

知识库代码提交

jingyuanchao 2 anos atrás
pai
commit
1ab6df3e50

+ 96 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysKnowledgeController.java

@@ -0,0 +1,96 @@
+package com.xunmei.system.controller;
+
+import java.util.List;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.xunmei.common.log.annotation.Log;
+import com.xunmei.common.log.enums.BusinessType;
+import com.xunmei.common.security.annotation.RequiresPermissions;
+import com.xunmei.system.domain.SysKnowledge;
+import com.xunmei.system.service.ISysKnowledgeService;
+import com.xunmei.common.core.web.controller.BaseController;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.web.page.TableDataInfo;
+
+/**
+ * 知识库标签Controller
+ *
+ * @author xunmei
+ * @date 2023-08-21
+ */
+@Api(tags = {"SysKnowledge" })
+@RestController
+@RequestMapping("/knowledge")
+public class SysKnowledgeController extends BaseController {
+    @Autowired
+    private ISysKnowledgeService sysKnowledgeService;
+
+/**
+ * 查询知识库标签列表
+ */
+@ApiOperation(value = "查询SysKnowledge列表")
+@RequiresPermissions("system:knowledge:list")
+@GetMapping("/list")
+    public TableDataInfo list(SysKnowledge sysKnowledge) {
+
+        return sysKnowledgeService.selectPage( sysKnowledge);
+    }
+
+
+
+    /**
+     * 获取知识库标签详细信息
+     */
+    @ApiOperation(value = "获取SysKnowledge详细信息")
+    @RequiresPermissions("system:knowledge:query")
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable("id") Long id) {
+        return success(sysKnowledgeService.selectSysKnowledgeById(id));
+    }
+
+    /**
+     * 新增知识库标签
+     */
+    @ApiOperation(value = "新增SysKnowledge")
+    @RequiresPermissions("system:knowledge:add")
+    @Log(title = "知识库标签" , businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody SysKnowledge sysKnowledge) {
+        return toAjax(sysKnowledgeService.insertSysKnowledge(sysKnowledge));
+    }
+
+    /**
+     * 修改知识库标签
+     */
+    @ApiOperation(value = "修改SysKnowledge")
+    @RequiresPermissions("system:knowledge:edit")
+    @Log(title = "知识库标签" , businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody SysKnowledge sysKnowledge) {
+        return toAjax(sysKnowledgeService.updateSysKnowledge(sysKnowledge));
+    }
+
+    /**
+     * 删除知识库标签
+     */
+    @ApiOperation(value = "删除SysKnowledge")
+    @RequiresPermissions("system:knowledge:remove")
+    @Log(title = "知识库标签" , businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids) {
+        return toAjax(sysKnowledgeService.deleteSysKnowledgeByIds(ids));
+    }
+}

+ 55 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/domain/SysKnowledge.java

@@ -0,0 +1,55 @@
+package com.xunmei.system.domain;
+
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import com.xunmei.common.core.web.domain.BaseEntity;
+
+/**
+ * 知识库标签对象 sys_knowledge
+ *
+ * @author xunmei
+ * @date 2023-08-21
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("sys_knowledge")
+@ApiModel(value = "SysKnowledge对象", description = "知识库标签")
+public class SysKnowledge extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    @JsonSerialize(using = com.fasterxml.jackson.databind.ser.std.ToStringSerializer.class)
+    private Long id;
+
+    @ApiModelProperty(value = "标签名称")
+    private String name;
+
+    @TableLogic(value = "0", delval = "1")
+    @ApiModelProperty(value = "是否删除,0:未删除,1:已删除")
+    private Long deleted;
+
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+                .append("id", getId())
+                .append("name", getName())
+                .append("createBy", getCreateBy())
+                .append("createTime", getCreateTime())
+                .append("updateBy", getUpdateBy())
+                .append("updateTime", getUpdateTime())
+                .append("deleted", getDeleted())
+                .toString();
+    }
+}

+ 62 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/mapper/SysKnowledgeMapper.java

@@ -0,0 +1,62 @@
+package com.xunmei.system.mapper;
+
+import java.util.List;
+
+import com.xunmei.system.domain.SysKnowledge;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 知识库标签Mapper接口
+ *
+ * @author xunmei
+ * @date 2023-08-21
+ */
+public interface SysKnowledgeMapper extends BaseMapper<SysKnowledge> {
+    /**
+     * 查询知识库标签
+     *
+     * @param id 知识库标签主键
+     * @return 知识库标签
+     */
+    public SysKnowledge selectSysKnowledgeById(Long id);
+
+    /**
+     * 查询知识库标签列表
+     *
+     * @param sysKnowledge 知识库标签
+     * @return 知识库标签集合
+     */
+    public List<SysKnowledge> selectSysKnowledgeList(SysKnowledge sysKnowledge);
+
+    /**
+     * 新增知识库标签
+     *
+     * @param sysKnowledge 知识库标签
+     * @return 结果
+     */
+    public int insertSysKnowledge(SysKnowledge sysKnowledge);
+
+    /**
+     * 修改知识库标签
+     *
+     * @param sysKnowledge 知识库标签
+     * @return 结果
+     */
+    public int updateSysKnowledge(SysKnowledge sysKnowledge);
+
+    /**
+     * 删除知识库标签
+     *
+     * @param id 知识库标签主键
+     * @return 结果
+     */
+    public int deleteSysKnowledgeById(Long id);
+
+    /**
+     * 批量删除知识库标签
+     *
+     * @param ids 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteSysKnowledgeByIds(Long[] ids);
+}

+ 72 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysKnowledgeService.java

@@ -0,0 +1,72 @@
+package com.xunmei.system.service;
+
+import java.util.List;
+
+import com.xunmei.system.domain.SysKnowledge;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.web.page.TableDataInfo;
+
+/**
+ * 知识库标签Service接口
+ *
+ * @author xunmei
+ * @date 2023-08-21
+ */
+public interface ISysKnowledgeService extends IService<SysKnowledge> {
+    /**
+     * 查询知识库标签
+     *
+     * @param id 知识库标签主键
+     * @return 知识库标签
+     */
+    public SysKnowledge selectSysKnowledgeById(Long id);
+
+    /**
+     * 查询知识库标签列表
+     *
+     * @param sysKnowledge 知识库标签
+     * @return 知识库标签集合
+     */
+    public List<SysKnowledge> selectSysKnowledgeList(SysKnowledge sysKnowledge);
+
+    /**
+     * 新增知识库标签
+     *
+     * @param sysKnowledge 知识库标签
+     * @return 结果
+     */
+    public int insertSysKnowledge(SysKnowledge sysKnowledge);
+
+    /**
+     * 修改知识库标签
+     *
+     * @param sysKnowledge 知识库标签
+     * @return 结果
+     */
+    public int updateSysKnowledge(SysKnowledge sysKnowledge);
+
+    /**
+     * 批量删除知识库标签
+     *
+     * @param ids 需要删除的知识库标签主键集合
+     * @return 结果
+     */
+    public int deleteSysKnowledgeByIds(Long[] ids);
+
+    /**
+     * 删除知识库标签信息
+     *
+     * @param id 知识库标签主键
+     * @return 结果
+     */
+    public int deleteSysKnowledgeById(Long id);
+
+    /**
+     * 查询知识库标签分页数据
+     *
+     * @param sysKnowledge 查询条件对象
+     * @return Page
+     */
+    public TableDataInfo selectPage(SysKnowledge sysKnowledge);
+}

+ 136 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysKnowledgeServiceImpl.java

@@ -0,0 +1,136 @@
+package com.xunmei.system.service.impl;
+
+import java.util.List;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.xunmei.common.core.utils.DateUtils;
+import com.xunmei.common.core.utils.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.xunmei.system.service.ISysOrgService;
+
+import java.util.Arrays;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.system.mapper.SysKnowledgeMapper;
+import com.xunmei.system.domain.SysKnowledge;
+import com.xunmei.system.service.ISysKnowledgeService;
+
+/**
+ * 知识库标签Service业务层处理
+ *
+ * @author xunmei
+ * @date 2023-08-21
+ */
+@Service
+public class SysKnowledgeServiceImpl extends ServiceImpl<SysKnowledgeMapper, SysKnowledge> implements ISysKnowledgeService {
+    @Autowired
+    private SysKnowledgeMapper sysKnowledgeMapper;
+    @Autowired
+    private ISysOrgService orgService;
+
+    @Override
+    public TableDataInfo selectPage(SysKnowledge sysKnowledge) {
+
+        //未删除
+        sysKnowledge.setDeleted(0L);
+        Page<SysKnowledge> page;
+        //分页
+        if (sysKnowledge.getPageNum() != null && sysKnowledge.getPageSize() != null) {
+            page = new Page<>(sysKnowledge.getPageNum(), sysKnowledge.getPageSize());
+        } else {
+            page = new Page<>();
+        }
+        //查询条件
+        LambdaQueryWrapper<SysKnowledge> wrapper = new LambdaQueryWrapper<>(sysKnowledge);
+        //模糊查询
+        if (StringUtils.isNotNull(sysKnowledge.getName())) {
+            wrapper.like(SysKnowledge::getName, sysKnowledge.getName());
+            sysKnowledge.setName(null);
+        }
+        //获取数据
+        page = sysKnowledgeMapper.selectPage(page, wrapper);
+        //抓换为TableDataInfo适配前端
+        TableDataInfo tableDataInfo = new TableDataInfo();
+        tableDataInfo.setMsg("操作成功");
+        tableDataInfo.setCode(200);
+        tableDataInfo.setTotal(page.getTotal());
+        tableDataInfo.setRows(page.getRecords());
+        return tableDataInfo;
+
+
+    }
+
+
+    /**
+     * 查询知识库标签
+     *
+     * @param id 知识库标签主键
+     * @return 知识库标签
+     */
+    @Override
+    public SysKnowledge selectSysKnowledgeById(Long id) {
+        return sysKnowledgeMapper.selectById(id);
+    }
+
+    /**
+     * 查询知识库标签列表
+     *
+     * @param sysKnowledge 知识库标签
+     * @return 知识库标签
+     */
+    @Override
+    public List<SysKnowledge> selectSysKnowledgeList(SysKnowledge sysKnowledge) {
+        return sysKnowledgeMapper.selectList(new QueryWrapper<>(sysKnowledge));
+    }
+
+    /**
+     * 新增知识库标签
+     *
+     * @param sysKnowledge 知识库标签
+     * @return 结果
+     */
+    @Override
+    public int insertSysKnowledge(SysKnowledge sysKnowledge) {
+        sysKnowledge.setCreateTime(DateUtils.getNowDate());
+        return sysKnowledgeMapper.insert(sysKnowledge);
+    }
+
+    /**
+     * 修改知识库标签
+     *
+     * @param sysKnowledge 知识库标签
+     * @return 结果
+     */
+    @Override
+    public int updateSysKnowledge(SysKnowledge sysKnowledge) {
+        sysKnowledge.setUpdateTime(DateUtils.getNowDate());
+        return sysKnowledgeMapper.updateById(sysKnowledge);
+    }
+
+    /**
+     * 批量删除知识库标签
+     *
+     * @param ids 需要删除的知识库标签主键
+     * @return 结果
+     */
+    @Override
+    public int deleteSysKnowledgeByIds(Long[] ids) {
+        return sysKnowledgeMapper.deleteBatchIds(Arrays.asList((ids)));
+    }
+
+    /**
+     * 删除知识库标签信息
+     *
+     * @param id 知识库标签主键
+     * @return 结果
+     */
+    @Override
+    public int deleteSysKnowledgeById(Long id) {
+        return sysKnowledgeMapper.deleteById(id);
+    }
+}

+ 109 - 0
soc-modules/soc-modules-system/src/main/resources/mapper/system/SysKnowledgeMapper.xml

@@ -0,0 +1,109 @@
+<?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.xunmei.system.mapper.SysKnowledgeMapper">
+
+    <resultMap type="com.xunmei.system.domain.SysKnowledge" id="SysKnowledgeResult">
+                <result property="id" column="id"/>
+                <result property="name" column="name"/>
+                <result property="createBy" column="create_by"/>
+                <result property="createTime" column="create_time"/>
+                <result property="updateBy" column="update_by"/>
+                <result property="updateTime" column="update_time"/>
+                <result property="deleted" column="deleted"/>
+    </resultMap>
+
+    <sql id="selectSysKnowledgeVo">
+        select id, name, create_by, create_time, update_by, update_time, deleted
+        from sys_knowledge
+    </sql>
+
+    <select id="selectSysKnowledgeList" parameterType="com.xunmei.system.domain.SysKnowledge"
+            resultMap="SysKnowledgeResult">
+        <include refid="selectSysKnowledgeVo"/>
+        <where>
+                        <if test="name != null  and name != ''">
+                            and name like concat('%', #{name}, '%')
+                        </if>
+                        <if test="deleted != null ">
+                            and deleted = #{deleted}
+                        </if>
+        </where>
+    </select>
+
+    <select id="selectSysKnowledgeById" parameterType="Long"
+            resultMap="SysKnowledgeResult">
+            <include refid="selectSysKnowledgeVo"/>
+            where id = #{id}
+    </select>
+
+    <insert id="insertSysKnowledge" parameterType="com.xunmei.system.domain.SysKnowledge"            useGeneratedKeys="true" keyProperty="id">
+        insert into sys_knowledge
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+                    <if test="name != null and name != ''">name,
+                    </if>
+                    <if test="createBy != null">create_by,
+                    </if>
+                    <if test="createTime != null">create_time,
+                    </if>
+                    <if test="updateBy != null">update_by,
+                    </if>
+                    <if test="updateTime != null">update_time,
+                    </if>
+                    <if test="deleted != null">deleted,
+                    </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+                    <if test="name != null and name != ''">#{name},
+                    </if>
+                    <if test="createBy != null">#{createBy},
+                    </if>
+                    <if test="createTime != null">#{createTime},
+                    </if>
+                    <if test="updateBy != null">#{updateBy},
+                    </if>
+                    <if test="updateTime != null">#{updateTime},
+                    </if>
+                    <if test="deleted != null">#{deleted},
+                    </if>
+        </trim>
+    </insert>
+
+    <update id="updateSysKnowledge" parameterType="com.xunmei.system.domain.SysKnowledge">
+        update sys_knowledge
+        <trim prefix="SET" suffixOverrides=",">
+                    <if test="name != null and name != ''">name =
+                        #{name},
+                    </if>
+                    <if test="createBy != null">create_by =
+                        #{createBy},
+                    </if>
+                    <if test="createTime != null">create_time =
+                        #{createTime},
+                    </if>
+                    <if test="updateBy != null">update_by =
+                        #{updateBy},
+                    </if>
+                    <if test="updateTime != null">update_time =
+                        #{updateTime},
+                    </if>
+                    <if test="deleted != null">deleted =
+                        #{deleted},
+                    </if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteSysKnowledgeById" parameterType="Long">
+        delete
+        from sys_knowledge where id = #{id}
+    </delete>
+
+    <delete id="deleteSysKnowledgeByIds" parameterType="String">
+        delete from sys_knowledge where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+</mapper>