Prechádzať zdrojové kódy

feat(sop): 添加总后台模板权限控制和置顶功能

- 在QwSopTemp实体中新增templateType和isTop字段
- 实现总后台模板的权限校验,仅允许总后台管理员修改和删除- 子公司用户无法修改或删除总后台模板- 添加按置顶状态排序的功能
- 新增专门用于创建总后台模板的接口
- 复制总后台模板时自动转换为普通模板- 查询时支持展示总后台模板给所有公司
- 更新操作时保护总后台模板的核心属性不被篡改
xw 1 týždeň pred
rodič
commit
0ff4ae44ec

+ 57 - 0
fs-admin/src/main/java/com/fs/qw/controller/QwSopTempController.java

@@ -93,6 +93,15 @@ public class QwSopTempController extends BaseController
     @PutMapping
     public AjaxResult edit(@RequestBody QwSopTemp qwSopTemp)
     {
+        //检查是否为总后台模板,如果是则只允许总后台用户修改
+        QwSopTemp existingTemp = qwSopTempService.selectQwSopTempById(qwSopTemp.getId());
+        if(existingTemp!=null && existingTemp.getTemplateType() != null &&existingTemp.getTemplateType() ==1){
+            LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+            //只有总后台用户可以修改总后台模板
+            if (!loginUser.isAdmin()) {
+                return AjaxResult.error("只有总后台管理员才能修改总后台模板");
+            }
+        }
 
         SimpleDateFormat slf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
@@ -108,6 +117,17 @@ public class QwSopTempController extends BaseController
 	@DeleteMapping("/{ids}")
     public AjaxResult remove(@PathVariable String[] ids)
     {
+        // 检查是否包含总后台模板
+        for (String id : ids) {
+            QwSopTemp existingTemp = qwSopTempService.selectQwSopTempById(id);
+            if (existingTemp != null && existingTemp.getTemplateType() != null && existingTemp.getTemplateType() == 1) {
+                LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+                // 只有admin用户可以删除总后台模板
+                if (!loginUser.isAdmin()) {
+                    return AjaxResult.error("只有总后台管理员才能删除总后台模板");
+                }
+            }
+        }
         ;
 //        qwSopTempService.deleteQwSopTempByIds(ids);
         return toAjax(qwSopTempService.updateQwSopTempByIds(ids));
@@ -144,6 +164,15 @@ public class QwSopTempController extends BaseController
     @Log(title = "sop模板", businessType = BusinessType.UPDATE)
     @PostMapping("/update")
     public AjaxResult updateNew(@RequestBody QwSopTemp qwSopTemp){
+        // 检查是否为总后台模板,如果是则只允许总后台用户修改
+        QwSopTemp existingTemp = qwSopTempService.selectQwSopTempById(qwSopTemp.getId());
+        if (existingTemp != null && existingTemp.getTemplateType() != null && existingTemp.getTemplateType() == 1) {
+            LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+            // 只有admin用户可以修改总后台模板
+            if (!loginUser.isAdmin()) {
+                return AjaxResult.error("只有总后台管理员才能修改总后台模板");
+            }
+        }
         int update = qwSopTempService.update(qwSopTemp);
         return toAjax(update);
     }
@@ -199,4 +228,32 @@ public class QwSopTempController extends BaseController
     public R getSelectableRange(){
         return R.ok().put("data", qwSopTempService.getSelectableRange());
     }
+
+    /**
+     * 新增总后台模板
+     */
+    @PreAuthorize("@ss.hasPermi('qw:sopTemp:add')")
+    @Log(title = "新增总后台模板", businessType = BusinessType.INSERT)
+    @PostMapping("/addHeadquartersTemplate")
+    public AjaxResult addHeadquartersTemplate(@RequestBody QwSopTemp qwSopTemp) {
+        // 检查是否为总后台用户
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        if (!loginUser.isAdmin()) {
+            return AjaxResult.error("只有总后台管理员才能创建总后台模板");
+        }
+        
+        // 设置为总后台模板
+        qwSopTemp.setTemplateType(1);
+        qwSopTemp.setCreateBy(loginUser.getUser().getUserId().toString());
+        
+        int i = qwSopTempService.addNew(qwSopTemp);
+        if(qwSopTemp.getSendType() == 11){
+            //筛选选课程数据
+            if(ObjectUtils.isNotNull(qwSopTemp.getTimeList()) && !qwSopTemp.getTimeList().isEmpty()){
+                qwSopTemp.setTimeList(new ArrayList<>(qwSopTemp.getTimeList().stream().filter(t->ObjectUtils.isNotNull(t) && !t.isEmpty()).collect(Collectors.toList())));
+            }
+            new Thread(() -> qwSopTempService.createSopTempRules(qwSopTemp)).start();
+        }
+        return toAjax(i);
+    }
 }

+ 24 - 0
fs-company/src/main/java/com/fs/company/controller/qw/QwSopTempController.java

@@ -155,6 +155,11 @@ public class QwSopTempController extends BaseController
     @PutMapping
     public AjaxResult edit(@RequestBody QwSopTemp qwSopTemp)
     {
+        // 检查是否为总后台模板,子公司不能修改
+        QwSopTemp existingTemp = qwSopTempService.selectQwSopTempById(qwSopTemp.getId());
+        if (existingTemp != null && existingTemp.getTemplateType() != null && existingTemp.getTemplateType() == 1) {
+            return AjaxResult.error("子公司不能修改总后台模板");
+        }
 
         SimpleDateFormat slf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
@@ -170,6 +175,13 @@ public class QwSopTempController extends BaseController
 	@DeleteMapping("/{ids}")
     public AjaxResult remove(@PathVariable String[] ids)
     {
+        // 检查是否包含总后台模板,子公司不能删除
+        for (String id : ids) {
+            QwSopTemp existingTemp = qwSopTempService.selectQwSopTempById(id);
+            if (existingTemp != null && existingTemp.getTemplateType() != null && existingTemp.getTemplateType() == 1) {
+                return AjaxResult.error("子公司不能删除总后台模板");
+            }
+        }
         ;
 //        qwSopTempService.deleteQwSopTempByIds(ids);
         return toAjax(qwSopTempService.updateQwSopTempByIds(ids));
@@ -208,6 +220,11 @@ public class QwSopTempController extends BaseController
     @Log(title = "sop模板update", businessType = BusinessType.UPDATE)
     @PostMapping("/update")
     public AjaxResult updateNew(@RequestBody QwSopTemp qwSopTemp){
+        // 检查是否为总后台模板,子公司不能修改
+        QwSopTemp existingTemp = qwSopTempService.selectQwSopTempById(qwSopTemp.getId());
+        if (existingTemp != null && existingTemp.getTemplateType() != null && existingTemp.getTemplateType() == 1) {
+            return AjaxResult.error("子公司不能修改总后台模板");
+        }
         int update = qwSopTempService.update(qwSopTemp);
         return toAjax(update);
     }
@@ -236,6 +253,13 @@ public class QwSopTempController extends BaseController
     @PreAuthorize("@ss.hasPermi('qw:sopTemp:edit') or @ss.hasPermi('qw:sopTemp:myEdit') or @ss.hasPermi('qw:sopTemp:deptEdit')")
     @PostMapping("/copyTemplate")
     public AjaxResult copyTemplate(@RequestBody QwSopTemp qwSopTemp){
+        // 子公司可以复制总后台模板,但复制后的模板为普通模板
+        QwSopTemp sourceTemp = qwSopTempService.selectQwSopTempById(qwSopTemp.getId());
+        if (sourceTemp != null && sourceTemp.getTemplateType() != null && sourceTemp.getTemplateType() == 1) {
+            // 复制总后台模板时,新模板设置为普通模板
+            qwSopTemp.setTemplateType(0);
+            qwSopTemp.setIsTop(0);
+        }
         qwSopTempService.copyTemplate(qwSopTemp);
         return toAjax(1);
     }

+ 12 - 0
fs-service/src/main/java/com/fs/sop/domain/QwSopTemp.java

@@ -67,6 +67,18 @@ public class QwSopTemp implements Serializable
     @Excel(name = "模板类型")
     private Integer sendType;
 
+    /**
+     * 模板类型:0-普通模板,1-总后台模板
+     */
+    @Excel(name = "模板类型")
+    private Integer templateType;
+
+    /**
+     * 是否置顶:0-否,1-是
+     */
+    @Excel(name = "是否置顶")
+    private Integer isTop;
+
     @Excel(name = "创建时间")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private String createTime;

+ 17 - 0
fs-service/src/main/java/com/fs/sop/service/impl/QwSopTempServiceImpl.java

@@ -146,6 +146,15 @@ public class QwSopTempServiceImpl implements IQwSopTempService
      */
     @Override
     public int updateQwSopTemp(QwSopTemp qwSopTemp){
+        // 如果是总后台模板,不允许修改模板类型和置顶状态
+        QwSopTemp existingTemp = qwSopTempMapper.selectQwSopTempById(qwSopTemp.getId());
+        if (existingTemp != null && existingTemp.getTemplateType() != null && existingTemp.getTemplateType() == 1) {
+            // 总后台模板的基础属性不允许修改
+            qwSopTemp.setTemplateType(1);
+            if (existingTemp.getIsTop() != null) {
+                qwSopTemp.setIsTop(existingTemp.getIsTop());
+            }
+        }
         return qwSopTempMapper.updateQwSopTemp(qwSopTemp);
     }
 
@@ -337,7 +346,15 @@ public class QwSopTempServiceImpl implements IQwSopTempService
     public void copyTemplate(QwSopTemp qwSopTemp) {
         String oldId = qwSopTemp.getId();
         String newId = UUID.randomUUID().toString();
+        QwSopTemp sourceTemp = qwSopTempMapper.selectQwSopTempById(oldId);
+        
         qwSopTemp.setId(newId);
+        // 如果复制的是总后台模板,新模板设置为普通模板
+        if (sourceTemp != null && sourceTemp.getTemplateType() != null && sourceTemp.getTemplateType() == 1) {
+            qwSopTemp.setTemplateType(0);
+            qwSopTemp.setIsTop(0);
+        }
+        
         qwSopTempMapper.insertQwSopTemp(qwSopTemp);
         List<QwSopTempDay> dayList = qwSopTempRulesService.listByTempIdAll(oldId);
         if(dayList.isEmpty()) return;

+ 12 - 2
fs-service/src/main/resources/mapper/sop/QwSopTempMapper.xml

@@ -16,6 +16,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="gap"    column="gap"    />
         <result property="sendType"    column="send_type"    />
         <result property="updateTime"    column="update_time"    />
+        <result property="templateType"    column="template_type"    />
+        <result property="isTop"    column="is_top"    />
     </resultMap>
 
     <sql id="selectQwSopTempVo">
@@ -41,7 +43,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
             <if test="status != null  and status != ''"> and status = #{status}</if>
             <if test="sort != null "> and sort = #{sort}</if>
-            <if test="companyId != null "> and company_id = #{companyId}</if>
+            <if test="companyId != null ">
+                AND (company_id = #{companyId} OR template_type = 1)
+            </if>
             <if test="sendType != null "> and send_type = #{sendType}</if>
             <if test="createBy != null "> and create_by = #{createBy}</if>
             <if test="cuDeptIdList != null and !cuDeptIdList.isEmpty()">
@@ -51,7 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 </foreach>
             </if>
         </where>
-        order by sort,create_time desc
+        order by is_top desc, sort, create_time desc
     </select>
 
     <select id="selectQwSopTempById" parameterType="String" resultMap="QwSopTempResult">
@@ -82,6 +86,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="data.gap != null">gap,</if>
             <if test="data.sendType != null">send_type,</if>
             <if test="data.updateTime != null">update_time,</if>
+            <if test="data.templateType != null">template_type,</if>
+            <if test="data.isTop != null">is_top,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="data.id != null">#{data.id},</if>
@@ -95,6 +101,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="data.gap != null">#{data.gap},</if>
             <if test="data.sendType != null">#{data.sendType},</if>
             <if test="data.updateTime != null">#{data.updateTime},</if>
+            <if test="data.templateType != null">#{data.templateType},</if>
+            <if test="data.isTop != null">#{data.isTop},</if>
          </trim>
     </insert>
 
@@ -111,6 +119,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="data.gap != null">gap = #{data.gap},</if>
             <if test="data.sendType != null">send_type = #{data.sendType},</if>
             <if test="data.updateTime != null">update_time = #{data.updateTime},</if>
+            <if test="data.templateType != null">template_type = #{data.templateType},</if>
+            <if test="data.isTop != null">is_top = #{data.isTop},</if>
         </trim>
         where id = #{data.id}
     </update>