Parcourir la source

新增添加模块功能

cxd il y a 8 mois
Parent
commit
8c48f002d5

+ 18 - 0
gqy-admin/src/main/java/com/gqy/web/controller/document/DcTemplateController.java

@@ -10,6 +10,7 @@ import com.gqy.document.domain.DcTemplate;
 import com.gqy.document.domain.vo.PageResult;
 import com.gqy.document.service.IDcTemplateService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
@@ -119,5 +120,22 @@ public class DcTemplateController extends BaseController {
     }
 
 
+    /**
+     * 创建模板
+     */
+//    @PreAuthorize("@ss.hasPermi('system:template:add')")
+    @PostMapping("/create")
+    public @ResponseBody  AjaxResultCQY create(@RequestBody DcTemplate template) {
+        return templateService.create(template);
+    }
+
+    /**
+     * 更新模板
+     */
+//    @PreAuthorize("@ss.hasPermi('system:template:edit')")
+    @PostMapping("/update")
+    public @ResponseBody AjaxResultCQY update(@RequestBody DcTemplate template) {
+        return templateService.update(template);
+    }
 
 }

+ 1 - 1
gqy-common/src/main/java/com/gqy/common/core/domain/AjaxResultCQY.java

@@ -76,7 +76,7 @@ public class AjaxResultCQY extends HashMap<String, Object>
      */
     public static AjaxResultCQY success(Object data)
     {
-        return AjaxResultCQY.success("操作成功", data);
+        return AjaxResultCQY.success("success", data);
     }
 
     /**

+ 17 - 9
gqy-system/src/main/java/com/gqy/document/domain/DcTemplate.java

@@ -1,14 +1,17 @@
 package com.gqy.document.domain;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.gqy.common.core.domain.BaseEntity;
 
 import java.util.Date;
 
-public class DcTemplate {
-
+/**
+ * 模板对象 dc_template
+ */
+public class DcTemplate extends BaseEntity {
 
     /** 主键ID */
-    private Integer id;
+    private Long id;
 
     /** 模板编码 */
     private String code;
@@ -38,11 +41,16 @@ public class DcTemplate {
     private Integer admin_id;
 
     /** 用户id */
-    private Integer user_id;
+    private Long user_id;
 
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date create_time;
-    /** 状态 */
+    /**
+     *  状态
+     *      (5, "使用中"),
+     *     (6, "已停用"),
+     *     (4, "已删除"),
+     *  */
     private Integer status;
 
     /** 查询关联模板分类 */
@@ -51,11 +59,11 @@ public class DcTemplate {
     /** 分类名称(非数据库字段) */
     private String type_name;
 
-    public Integer getUser_id() {
+    public Long getUser_id() {
         return user_id;
     }
 
-    public void setUser_id(Integer user_id) {
+    public void setUser_id(Long user_id) {
         this.user_id = user_id;
     }
 
@@ -75,11 +83,11 @@ public class DcTemplate {
         this.type_name = type_name;
     }
 
-    public Integer getId() {
+    public Long getId() {
         return id;
     }
 
-    public void setId(Integer id) {
+    public void setId(Long id) {
         this.id = id;
     }
 

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

@@ -67,4 +67,6 @@ public interface DcTemplateMapper {
     public int updateTemplateCode(DcTemplate template);
 
 
+
+
 }

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

@@ -29,4 +29,17 @@ public interface IDcTemplateService {
     public List<DcTemplate> pageTemplate(DcTemplate dcTemplate);
 
 
+    /**
+     * 创建模板
+     * @param template 模板信息
+     * @return 结果
+     */
+    public AjaxResultCQY create(DcTemplate template);
+
+
+    /**
+     * 更新模板
+     */
+    public AjaxResultCQY update(DcTemplate template);
+
 }

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

@@ -2,12 +2,17 @@ package com.gqy.document.service.impl;
 
 import com.gqy.common.core.domain.AjaxResult;
 import com.gqy.common.core.domain.AjaxResultCQY;
+import com.gqy.common.utils.SecurityUtils;
+import com.gqy.common.utils.StringUtils;
 import com.gqy.document.domain.DcTemplate;
 import com.gqy.document.domain.TemplateCategory;
 import com.gqy.document.mapper.DcTemplateMapper;
 import com.gqy.document.service.IDcTemplateService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.HashMap;
 import java.util.List;
@@ -17,8 +22,11 @@ import java.util.Map;
  * 模板服务实现
  */
 @Service
+
 public class DcTemplateServiceImpl implements IDcTemplateService {
 
+    private static final Logger log = LoggerFactory.getLogger(DcTemplateServiceImpl.class);
+
     @Autowired
     private DcTemplateMapper dcTemplateMapper;
 
@@ -90,4 +98,86 @@ public class DcTemplateServiceImpl implements IDcTemplateService {
    public List<DcTemplate> pageTemplate(DcTemplate dcTemplate){
         return  dcTemplateMapper.pageTemplate(dcTemplate);
     }
+
+    /**
+     * 创建模板
+     */
+    @Transactional
+    public AjaxResultCQY create(DcTemplate template) {
+        try {
+            // 参数校验
+            if (StringUtils.isEmpty(template.getName())) {
+                return AjaxResultCQY.error("模板名称不能为空");
+            }
+            template.setUser_id(SecurityUtils.getUserId());
+
+            // 设置当前用户ID
+           // template.getParams().put("userId", SecurityUtils.getUserId());
+
+            // 检查名称是否已存在
+            if (dcTemplateMapper.checkNameUnique(template) != null) {
+                return AjaxResultCQY.error("已存在同名模板");
+            }
+
+            // 设置默认值
+            if (template.getAttrs() == null) {
+                template.setAttrs("[]");
+            }
+
+            // 插入记录
+            dcTemplateMapper.insertTemplate(template);
+
+            // 使用返回的ID更新code
+            template.setCode(String.valueOf(template.getId()));
+
+            // 更新编码为ID
+            dcTemplateMapper.updateTemplateCode(template);
+
+            return AjaxResultCQY.success("创建成功");
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return AjaxResultCQY.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 更新模板
+     */
+    @Transactional
+    public AjaxResultCQY update(DcTemplate template) {
+        try {
+            // 参数校验
+            if (template.getId() == null) {
+                return AjaxResultCQY.error("模板ID不能为空");
+            }
+
+            // 设置当前用户ID
+            template.getParams().put("userId", SecurityUtils.getUserId());
+
+            template.setUser_id(SecurityUtils.getUserId());
+
+            // 检查模板是否存在
+            DcTemplate existTemplate = dcTemplateMapper.selectTemplateById(template.getId());
+            if (existTemplate == null) {
+                return AjaxResultCQY.error("模板不存在");
+            }
+
+            // 检查是否有权限修改
+//            if (!existTemplate.getAdmin_id().equals(SecurityUtils.getUserId())) {
+//                return AjaxResult.error("无权修改此模板");
+//            }
+
+            // 更新模板
+            if (dcTemplateMapper.updateTemplateCode(template) > 0) {
+                return AjaxResultCQY.success("更新成功");
+            }
+            return AjaxResultCQY.error("更新失败");
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return AjaxResultCQY.error(e.getMessage());
+        }
+    }
+
 }

+ 0 - 91
gqy-system/src/main/resources/mapper/document/ SysFileMapper.xml

@@ -1,91 +0,0 @@
-<?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.gqy.system.mapper.SysFileMapper">
-
-    <resultMap type="SysFile" id="SysFileResult">
-        <id     property="file_id"        column="file_id"         />
-        <result property="file_name"      column="file_name"       />
-        <result property="original_name"  column="original_name"   />
-        <result property="file_path"      column="file_path"       />
-        <result property="url"            column="url"             />
-        <result property="file_type"      column="file_type"       />
-        <result property="file_size"      column="file_size"       />
-        <result property="storage_type"   column="storage_type"    />
-        <result property="status"         column="status"          />
-        <result property="createTime"    column="create_time"     />
-        <result property="createBy"      column="create_by"       />
-    </resultMap>
-
-    <insert id="insertSysFile" parameterType="SysFile" useGeneratedKeys="true" keyProperty="file_id">
-        insert into sys_file(
-            file_name,
-            original_name,
-            file_path,
-            url,
-            file_type,
-            file_size,
-            storage_type,
-            status,
-            create_by,
-            create_time
-        )values(
-                   #{file_name},
-                   #{original_name},
-                   #{file_path},
-                   #{url},
-                   #{file_type},
-                   #{file_size},
-                   #{storage_type},
-                   #{status},
-                   #{create_by},
-                   sysdate()
-               )
-    </insert>
-
-    <select id="selectSysFileByUrl" parameterType="String" resultMap="SysFileResult">
-        select file_id, file_name, original_name, file_path, url, file_type,
-               file_size, storage_type, status, create_time, create_by
-        from sys_file
-        where url = #{url}
-          and status = 5
-    </select>
-
-
-    <update id="updateSysFile" parameterType="SysFile">
-        update sys_file
-        <set>
-            <if test="file_name != null and file_name != ''">
-                file_name = #{file_name},
-            </if>
-            <if test="original_name != null and original_name != ''">
-                original_name = #{original_name},
-            </if>
-            <if test="file_path != null and file_path != ''">
-                file_path = #{file_path},
-            </if>
-            <if test="url != null and url != ''">
-                url = #{url},
-            </if>
-            <if test="file_type != null and file_type != ''">
-                file_type = #{file_type},
-            </if>
-            <if test="file_size != null">
-                file_size = #{file_size},
-            </if>
-            <if test="storage_type != null">
-                storage_type = #{storage_type},
-            </if>
-            <if test="status != null">
-                status = #{status},
-            </if>
-            <if test="update_by != null and update_by != ''">
-                update_by = #{update_by},
-            </if>
-            update_time = sysdate()
-        </set>
-        where file_id = #{file_id}
-    </update>
-
-</mapper>

+ 14 - 4
gqy-system/src/main/resources/mapper/document/DcTemplateMapper.xml

@@ -146,7 +146,7 @@
         <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>
+        <if test="user_id != null">user_id,</if>
 
         create_time
         ) VALUES (
@@ -169,10 +169,20 @@
     <!-- 更新模板编码 -->
     <update id="updateTemplateCode" parameterType="DcTemplate">
         UPDATE dc_template
-        SET code = #{code}
+        <set>
+            <if test="name != null">name = #{name},</if>
+            <if test="code != null">code = #{code},</if>
+            <if test="content != null">content = #{content},</if>
+            <if test="attrs != null">attrs = #{attrs},</if>
+            <if test="category_id != null">category_id = #{category_id},</if>
+            <if test="status != null">status = #{status},</if>
+            <if test="lay_id != null">lay_id = #{lay_id},</if>
+            <if test="intro != null">intro = #{intro},</if>
+            <if test="type != null">type = #{type},</if>
+        </set>
         WHERE id = #{id}
-        <!-- 数据权限控制 -->
-        AND (admin_id = #{params.userId} OR 1 = 0)
+<!--        &lt;!&ndash; 数据权限控制 &ndash;&gt;-->
+<!--        AND (admin_id = #{params.userId} OR 1 = 0)-->
     </update>