Procházet zdrojové kódy

添加块 功能提交

cxd před 8 měsíci
rodič
revize
df6bde55ec

+ 44 - 1
gqy-admin/src/main/java/com/gqy/web/controller/document/DcTemplateController.java

@@ -24,6 +24,49 @@ public class DcTemplateController extends BaseController {
     @Autowired
     private IDcTemplateService templateService;
 
+
+    /**
+     * 分页查询模板列表
+     */
+    @PostMapping("/pageTemplate")
+    @ResponseBody
+    public AjaxResultCQY pageTemplate(@RequestBody  Map request){
+        // 获取表单参数
+        String page = request.get("page").toString();
+//        String category_id = request.get("category_id").toString();
+        String pageSizeStr = request.get("pageSize").toString();
+        String name = request.get("name").toString();
+        //String parent_id = request.get("parent_id").toString();
+        String status = request.get("status").toString();
+
+        //查询对象
+        DcTemplate dcTemplateQuery = new DcTemplate();
+//        dcTemplateQuery.setCategory_id(Integer.valueOf(category_id));
+        dcTemplateQuery.setName(name);
+        if(StringUtils.isNotEmpty(status))
+        dcTemplateQuery.setStatus(Integer.valueOf(status));
+
+        // 分页查询
+        Integer pageNum = StringUtils.isNotEmpty(page) ? Integer.valueOf(page) : 1;
+        Integer pageSize = StringUtils.isNotEmpty(pageSizeStr) ? Integer.valueOf(pageSizeStr) : 10;
+        PageHelper.startPage(pageNum, pageSize);
+        List<DcTemplate> list = templateService.pageTemplate(dcTemplateQuery);
+        // 3. 获取分页信息
+        PageInfo<DcTemplate> pageInfo = new PageInfo<>(list);
+
+        // 4. 封装并返回结果
+        PageResult PageResult=  new PageResult(
+                pageInfo.getPageNum(),
+                pageInfo.getPageSize(),
+                pageInfo.getPages(),
+                pageInfo.getTotal(),
+                pageInfo.getList());
+
+        return AjaxResultCQY.success("查询成功", PageResult);
+    }
+
+
+
     /**
      * 搜索模板列表
      * 对应Python的@require_http_methods(['POST'])
@@ -66,7 +109,7 @@ public class DcTemplateController extends BaseController {
     /**
      * 获取模板详细信息
      *
-     * @param id 模板ID
+     *
      * @return 模板详细信息,包括基本信息和分类信息
      */
     @PostMapping("/info")

+ 2 - 1
gqy-admin/src/main/java/com/gqy/web/controller/document/TemplateCategoryController.java

@@ -31,7 +31,8 @@ public class TemplateCategoryController {
      */
     @PostMapping("/treeCategory")
     public AjaxResultCQY treeCategory(){
-        return AjaxResultCQY.success("查询成功", new PageResult());
+
+        return templateCategoryService.treeCategory();
     }
 
 

+ 54 - 2
gqy-system/src/main/java/com/gqy/document/domain/DcTemplate.java

@@ -6,23 +6,74 @@ import java.util.Date;
 
 public class DcTemplate {
 
+
+    /** 主键ID */
     private Integer id;
+
+    /** 模板编码 */
     private String code;
+
+    /** 模板名称 */
     private String name;
-    private Integer category_id;
+
+    /** 模板介绍 */
+    private String intro;
+
+    /** 图层ID */
     private String lay_id;
+
+    /** 类型 */
     private String type;
+
+    /** 模板内容 */
     private String content;
+
+    /** 属性 */
     private String attrs;
-    private String intro;
+
+    /** 分类ID */
+    private Integer category_id;
+
+    /** 管理员ID */
     private Integer admin_id;
 
+    /** 用户id */
+    private Integer user_id;
+
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date create_time;
+    /** 状态 */
     private Integer status;
 
+    /** 查询关联模板分类 */
     private TemplateCategory category;
 
+    /** 分类名称(非数据库字段) */
+    private String type_name;
+
+    public Integer getUser_id() {
+        return user_id;
+    }
+
+    public void setUser_id(Integer user_id) {
+        this.user_id = user_id;
+    }
+
+    public TemplateCategory getCategory() {
+        return category;
+    }
+
+    public void setCategory(TemplateCategory category) {
+        this.category = category;
+    }
+
+    public String getType_name() {
+        return type_name;
+    }
+
+    public void setType_name(String type_name) {
+        this.type_name = type_name;
+    }
 
     public Integer getId() {
         return id;
@@ -121,4 +172,5 @@ public class DcTemplate {
     }
 
 
+
 }

+ 2 - 1
gqy-system/src/main/java/com/gqy/document/domain/TemplateCategory.java

@@ -1,13 +1,14 @@
 package com.gqy.document.domain;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.gqy.common.core.domain.TreeEntity;
 
 import java.util.Date;
 
 /**
  * 模板分类对象
  */
-public class TemplateCategory {
+public class TemplateCategory extends TreeEntity {
     private Integer id;
     private String name;
     private String intro;

+ 32 - 0
gqy-system/src/main/java/com/gqy/document/mapper/DcTemplateMapper.java

@@ -1,5 +1,6 @@
 package com.gqy.document.mapper;
 
+import com.gqy.common.core.domain.AjaxResult;
 import com.gqy.document.domain.DcTemplate;
 import com.gqy.document.domain.TemplateCategory;
 import org.apache.ibatis.annotations.Param;
@@ -35,4 +36,35 @@ public interface DcTemplateMapper {
      */
     TemplateCategory selectTemplateCategoryById(Long categoryId);
 
+
+    /**
+     * 分页查询模板列表
+     * @param dcTemplate
+     * @return
+     */
+    public List<DcTemplate> pageTemplate(DcTemplate dcTemplate);
+
+
+    /**
+     * 检查模板名称是否唯一
+     * @param template 模板信息
+     * @return 结果
+     */
+    public DcTemplate checkNameUnique(DcTemplate template);
+
+    /**
+     * 新增模板
+     * @param template 模板信息
+     * @return 结果
+     */
+    public int insertTemplate(DcTemplate template);
+
+    /**
+     * 更新模板编码
+     * @param template 模板信息
+     * @return 结果
+     */
+    public int updateTemplateCode(DcTemplate template);
+
+
 }

+ 9 - 0
gqy-system/src/main/java/com/gqy/document/mapper/TemplateCategoryMapper.java

@@ -23,4 +23,13 @@ public interface TemplateCategoryMapper {
      */
     public int selectChildCount(@Param("category_id") Integer categoryId);
 
+    /**
+     * 查询所有有效的分类列表
+     * 排除已删除(status=4)的记录
+     *
+     * @return 分类列表
+     */
+    public List<TemplateCategory> selectTemplateCategoryList();
+
+
 }

+ 9 - 0
gqy-system/src/main/java/com/gqy/document/service/IDcTemplateService.java

@@ -20,4 +20,13 @@ public interface IDcTemplateService {
      */
     AjaxResultCQY getInfo(Long id);
 
+
+    /**
+     * 分页查询模板列表
+     * @param dcTemplate
+     * @return
+     */
+    public List<DcTemplate> pageTemplate(DcTemplate dcTemplate);
+
+
 }

+ 9 - 0
gqy-system/src/main/java/com/gqy/document/service/ITemplateCategoryService.java

@@ -1,6 +1,8 @@
 package com.gqy.document.service;
 
 
+import com.gqy.common.core.domain.AjaxResult;
+import com.gqy.common.core.domain.AjaxResultCQY;
 import com.gqy.document.domain.TemplateCategory;
 
 import java.util.List;
@@ -25,4 +27,11 @@ public interface ITemplateCategoryService {
      */
     public int selectChildCount(Integer categoryId);
 
+    /**
+     * 获取分类树结构
+     *
+     * @return 树结构数据
+     */
+    public AjaxResultCQY treeCategory();
+
 }

+ 13 - 0
gqy-system/src/main/java/com/gqy/document/service/impl/DcTemplateServiceImpl.java

@@ -22,6 +22,9 @@ public class DcTemplateServiceImpl implements IDcTemplateService {
     @Autowired
     private DcTemplateMapper dcTemplateMapper;
 
+    /**
+     * 分页查询模板列表
+     */
     @Override
     public List<DcTemplate> selectTemplateList(String name, Integer category_id, Integer status) {
         return dcTemplateMapper.selectTemplateList(name, category_id, status);
@@ -77,4 +80,14 @@ public class DcTemplateServiceImpl implements IDcTemplateService {
         // 4. 返回成功结果
         return AjaxResultCQY.success(result);
     }
+
+
+    /**
+     * 分页查询模板列表
+     * @param dcTemplate
+     * @return
+     */
+   public List<DcTemplate> pageTemplate(DcTemplate dcTemplate){
+        return  dcTemplateMapper.pageTemplate(dcTemplate);
+    }
 }

+ 43 - 0
gqy-system/src/main/java/com/gqy/document/service/impl/TemplateCategoryServiceImpl.java

@@ -1,12 +1,17 @@
 package com.gqy.document.service.impl;
 
+import com.gqy.common.core.domain.AjaxResult;
+import com.gqy.common.core.domain.AjaxResultCQY;
 import com.gqy.document.domain.TemplateCategory;
 import com.gqy.document.mapper.TemplateCategoryMapper;
 import com.gqy.document.service.ITemplateCategoryService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class TemplateCategoryServiceImpl  implements ITemplateCategoryService {
@@ -34,4 +39,42 @@ public class TemplateCategoryServiceImpl  implements ITemplateCategoryService {
     public int selectChildCount(Integer categoryId) {
         return templateCategoryMapper.selectChildCount(categoryId);
     }
+
+    /**
+     * 获取分类树结构
+     */
+    public AjaxResultCQY treeCategory() {
+        List<TemplateCategory> allCategories = templateCategoryMapper.selectTemplateCategoryList();
+        // 2. 构建树形结构,从顶级分类(parent_id=0)开始
+        List<Map<String, Object>> treeData = buildTree(allCategories, "0");
+        // 3. 返回成功结果
+        return AjaxResultCQY.success(treeData);
+    }
+
+
+    /**
+     * 递归构建树形结构
+     *
+     * @param categories 所有分类列表
+     * @param parentId 父级ID
+     * @return 树形结构数据
+     */
+    private List<Map<String, Object>> buildTree(List<TemplateCategory> categories, String parentId) {
+        return categories.stream()
+                .filter(category -> category.getParent_id().equals(parentId))
+                .map(category -> {
+                    // 构建当前节点
+                    Map<String, Object> node = new HashMap<>();
+                    node.put("id", category.getId());
+                    node.put("name", category.getName());
+
+                    // 递归构建子节点
+                    List<Map<String, Object>> children = buildTree(categories, String.valueOf(category.getId()));
+                    node.put("children", children);
+
+                    return node;
+                })
+                .collect(Collectors.toList());
+    }
+
 }

+ 1 - 1
gqy-system/src/main/resources/mapper/document/DcDocumentMapper.xml

@@ -181,7 +181,7 @@
         where doc_id = #{documentId}
           and status != 4
     </select>
-
+    <!-- 获取文档关联的项目ID列表 -->
 
 
 </mapper>

+ 84 - 0
gqy-system/src/main/resources/mapper/document/DcTemplateMapper.xml

@@ -19,6 +19,8 @@
         <result property="admin_id"    column="admin_id"    />
         <result property="create_time" column="create_time" />
         <result property="status"      column="status"      />
+        <result property="type_name"   column="type_name"   />
+        <result property="user_id"   column="user_id"   />
 
         <!-- 分类关联映射 -->
         <association property="category" javaType="TemplateCategory">
@@ -93,4 +95,86 @@
 
 
 
+    <!-- 分页查询模板列表   pageTemplate -->
+    <select id="pageTemplate" parameterType="DcTemplate" resultMap="TemplateResult">
+        SELECT
+        t.id,
+        t.code,
+        t.name,
+        t.category_id,
+        t.create_time,
+        t.status,
+        c.name as type_name
+        FROM dc_template t
+        LEFT JOIN dc_template_category c ON t.category_id = c.id
+        <where>
+            t.status != 4
+            <if test="name != null and name != ''">
+                AND t.name like concat('%', #{name}, '%')
+            </if>
+            <if test="category_id != null">
+                AND t.category_id = #{category_id}
+            </if>
+            <if test="status != null">
+                AND t.status = #{status}
+            </if>
+        </where>
+        ORDER BY t.id DESC
+    </select>
+
+    <!-- 分页查询模板列表   pageTemplate -->
+
+    <!-- 检查模板名称是否存在 -->
+    <select id="checkNameUnique" parameterType="DcTemplate" resultMap="TemplateResult">
+        SELECT id, name FROM dc_template
+        WHERE name = #{name} AND status != 4
+        LIMIT 1
+    </select>
+    <!-- 检查模板名称是否存在 -->
+
+
+    <!-- 创建模板 -->
+    <insert id="insertTemplate" parameterType="DcTemplate" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO dc_template (
+        <if test="code != null">code,</if>
+        <if test="name != null">name,</if>
+        <if test="intro != null">intro,</if>
+        <if test="lay_id != null">lay_id,</if>
+        <if test="type != null">type,</if>
+        <if test="content != null">content,</if>
+        <if test="attrs != null">attrs,</if>
+        <if test="category_id != null">category_id,</if>
+        <if test="admin_id != null">admin_id,</if>
+        <if test="status != null">status,</if>
+        <if test="user_id != null">status,</if>
+
+        create_time
+        ) VALUES (
+        <if test="code != null">#{code},</if>
+        <if test="name != null">#{name},</if>
+        <if test="intro != null">#{intro},</if>
+        <if test="lay_id != null">#{lay_id},</if>
+        <if test="type != null">#{type},</if>
+        <if test="content != null">#{content},</if>
+        <if test="attrs != null">#{attrs},</if>
+        <if test="category_id != null">#{category_id},</if>
+        <if test="admin_id != null">#{admin_id},</if>
+        <if test="status != null">#{status},</if>
+        <if test="user_id != null">#{user_id},</if>
+        sysdate()
+        )
+    </insert>
+    <!-- 创建模板 -->
+
+    <!-- 更新模板编码 -->
+    <update id="updateTemplateCode" parameterType="DcTemplate">
+        UPDATE dc_template
+        SET code = #{code}
+        WHERE id = #{id}
+        <!-- 数据权限控制 -->
+        AND (admin_id = #{params.userId} OR 1 = 0)
+    </update>
+
+
+
 </mapper>

+ 5 - 1
gqy-system/src/main/resources/mapper/document/DocumentCategoryMapper.xml

@@ -4,6 +4,10 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.gqy.document.mapper.DocumentCategoryMapper">
 
+
+
+
+
     <!-- 搜索文档分类列表 -->
     <select id="search" resultType="DocumentCategory">
         <!-- 查询字段 -->
@@ -12,7 +16,7 @@
         name,             <!-- 分类名称 -->
         intro,            <!-- 分类介绍 -->
         status,           <!-- 状态 -->
-        create_time as createTime  <!-- 创建时间 -->
+        create_time   <!-- 创建时间 -->
         FROM dc_document_category
         <where>
             <!-- 排除已删除数据 -->

+ 16 - 0
gqy-system/src/main/resources/mapper/document/TemplateCategoryMapper.xml

@@ -14,6 +14,22 @@
         <result property="status"      column="status"      />
     </resultMap>
 
+
+    <!-- 查询所有有效分类 -->
+    <select id="selectTemplateCategoryList" resultMap="TemplateCategoryResult">
+        select
+            id,
+            name,
+            intro,
+            parent_id,
+            status,
+            create_time
+        from dc_template_category
+        where status != 4
+        order by id desc
+    </select>
+
+
     <!-- 查询顶级分类列表 -->
     <select id="selectTopCategoryList" resultMap="TemplateCategoryResult">
         select * from dc_template_category