소스 검색

完成素材库权限配置(sys_role)

tsurumure 1 개월 전
부모
커밋
5f7d99e631

+ 3 - 2
db/sys_user_role.sql

@@ -14,7 +14,6 @@ CREATE TABLE `sys_user_role` (
     `status` TINYINT(1) DEFAULT '1' COMMENT '角色状态(1正常 2停用)',
     UNIQUE KEY (`role_name`),
     INDEX `idx_nickname` (`role_name`)
-#     FOREIGN KEY (`id`) REFERENCES `sys_user_role_module_relation`(`role_id`) ON DELETE CASCADE
 ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='系统用户角色表';
 
 # ALTER TABLE sys_user_role_module_relation DROP FOREIGN KEY sys_user_role_module_relation_ibfk_1;
@@ -22,5 +21,7 @@ CREATE TABLE `sys_user_role` (
 INSERT INTO sys_user_role(role_name, role_description, sort) VALUES
     ('开发者', '全部权限', 1),
     ('管理员', '全部功能权限', 2),
-    ('普通用户', '基础权限', 3)
+    ('普通用户', '基础权限', 3),
+    ('运营-素材-管理员', '素材管理', 4),
+    ('运营-素材-普通用户', '素材管理', 5)
 ;

+ 2 - 4
db/sys_user_role_menu.sql

@@ -43,10 +43,8 @@ INSERT INTO sys_user_role_menu(id, parent_id, menu_name, menu_name_en, type, pat
     (11, -1, 'AI成片', 'AI Video', 1, '/ai/generate/video/broadcast/my/broadcast', '', '{}', 'VideoCamera', '34', 909),
 
 
-#     (-1, '素材管理', 'MaterialService', 1, '/material', '', '{}', 'MessageBox', '20', 10),
-#     (4, '素材中心', 'MaterialService', 1, '/material/center', '/src/views/material/materialCenter.vue', '{}', null, '20.3', 10),
-#     (4, '素材列表', 'MaterialService List', 1, '/material/list', '/src/views/material/materialList.vue', '{}', null, '20.1', 10),
-#     (4, '素材分类', 'MaterialService Category', 1, '/material/category', '/src/views/material/materialCategory.vue', '{}', null, '20.2', 10),
+    (20, -1, '素材管理', 'Material', 1, '/material', '', '{}', 'MessageBox', '20', 10),
+    (21, 20, '素材列表', 'Material List', 1, '/material/list', '/src/views/material/materialList.vue', '{}', null, '20.1', 10),
 #
 #     (-1, '我的', 'Account', 1, '/account', '', '{}', 'User', '21', 11),
 #     (8, '我的素材', 'My MaterialService', 1, '/account/myMaterial', '', '{}', null, '21.1', 11),

+ 14 - 17
db/sys_user_role_permission.sql

@@ -176,23 +176,20 @@ INSERT INTO sys_user_role_permission(id, parent_id, permission_name, sort) VALUE
             ('11.6.1', '11.6', '商品规格SKU详情', null),
             ('11.6.2', '11.6', '创建商品规格SKU', null),
             ('11.6.3', '11.6', '编辑商品规格SKU', null),
-            ('11.6.4', '11.6', '删除商品规格SKU', null)
-
-
-
-#     ('20', -1, '素材管理', null),
-#         ('20.1', '20', '素材列表', null),
-#             ('20.1.1', '20.1', '素材中心', null),
-#             ('20.1.2', '20.1', '素材列表详情', null),
-#             ('20.1.3', '20.1', '创建素材', null),
-#             ('20.1.4', '20.1', '编辑素材', null),
-#             ('20.1.5', '20.1', '审核素材', null),
-#             ('20.1.6', '20.1', '删除素材', null),
-#         ('20.2', '20', '素材分类列表', null),
-#             ('20.2.1', '20.2', '素材分类详情', null),
-#             ('20.2.2', '20.2', '创建素材分类', null),
-#             ('20.2.3', '20.2', '编辑素材分类', null),
-#             ('20.2.4', '20.2', '删除素材分类', null),
+            ('11.6.4', '11.6', '删除商品规格SKU', null),
+
+
+    ('20', -1, '素材管理', null),
+        ('20.1', '20', '素材列表', null),
+            ('20.1.1', '20.1', '素材详情', null),
+            ('20.1.2', '20.1', '创建素材', null),
+            ('20.1.3', '20.1', '编辑素材', null),
+            ('20.1.4', '20.1', '删除素材', null),
+        ('20.2', '20', '素材分类列表', null),
+        ('20.3', '20', '素材标签列表', null)
+
+
+
 #
 #     ('21', -1, '个人中心', null),
 #         ('21.1', '21', '我的素材', null),

+ 18 - 3
db/sys_user_role_permission_relation.sql

@@ -165,9 +165,24 @@ INSERT INTO sys_user_role_permission_relation(role_id, permission_id) VALUES
 
     (3, '1'),
         (3, '1.1'),
-            (2, '1.1.2'), (3, '1.1.3'), (3, '1.1.4'), (3, '1.1.6'),
+            (3, '1.1.2'), (3, '1.1.3'), (3, '1.1.4'), (3, '1.1.6'),
 
     (3, '2'),
-    (3, '31')
-
+    (3, '31'),
+
+    # 运营-素材管理者
+    (4, '1.1.2'), (4, '1.1.3'), (4, '1.1.6'),
+    (4, '20'),
+        (4, '20.1'),
+            (4, '20.1.1'), (4, '20.1.2'), (4, '20.1.3'), (4, '20.1.4'),
+        (4, '20.2'),
+        (4, '20.3'),
+
+    # 运营-素材使用者
+    (5, '1.1.2'), (5, '1.1.3'), (5, '1.1.6'),
+    (5, '20.1'),
+        (5, '20.1'),
+            (5, '20.1.1'),
+        (5, '20.2'),
+        (5, '20.3')
 ;

+ 1 - 1
db/sys_user_role_relation.sql

@@ -15,7 +15,7 @@ CREATE TABLE `sys_user_role_relation` (
 ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='系统用户角色关系表';
 
 INSERT INTO sys_user_role_relation(user_id, role_id) VALUES
-    (1, 1), (2, 1), (3, 3), (4, 2), (5, 2), (6, 2),
+    (1, 4), (2, 1), (3, 3), (4, 2), (5, 2), (6, 2),
     (7, 2), (8, 2), (9, 2), (10, 2), (11, 2), (12, 2),
     (13, 1), (14, 1), (15, 1), (16, 1)
 ;

+ 2 - 2
src/main/java/com/backendsys/modules/ai/material/controller/MaterialCategoryController.java

@@ -20,14 +20,14 @@ public class MaterialCategoryController {
     private MaterialCategoryService materialCategoryService;
 
     @Operation(summary = "获取素材分类列表")
-//    @PreAuthorize("@sr.hasPermission('31')")
+//    @PreAuthorize("@sr.hasPermission('20.2')")
     @GetMapping("/api/ai/material/getMaterialCategoryList")
     public Result getMaterialCategoryList(MaterialCategory materialCategory) {
         return Result.success().put("data", materialCategoryService.selectMaterialCategoryList(materialCategory));
     }
 
     @Operation(summary = "获取素材分类列表(下拉)")
-//    @PreAuthorize("@sr.hasPermission('31')")
+//    @PreAuthorize("@sr.hasPermission('20.2')")
     @GetMapping("/api/ai/material/getMaterialCategoryPopover")
     public Result getMaterialCategoryPopover() {
         return Result.success().put("data", materialCategoryService.selectMaterialCategoryPopover());

+ 13 - 5
src/main/java/com/backendsys/modules/ai/material/controller/MaterialController.java

@@ -9,6 +9,7 @@ import com.backendsys.modules.common.utils.Result;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -21,14 +22,21 @@ public class MaterialController {
     private MaterialService materialService;
 
     @Operation(summary = "获取素材列表")
-//    @PreAuthorize("@sr.hasPermission('31')")
+    @PreAuthorize("@sr.hasPermission('20.1')")
     @GetMapping("/api/ai/material/getMaterialList")
-    public Result getMaterialTagList(Material material) {
+    public Result getMaterialList(Material material) {
         return Result.success().put("data", materialService.selectMaterialList(material));
     }
 
+    @Operation(summary = "获取素材列表")
+//    @PreAuthorize("@sr.hasPermission('20.1.1')")
+    @GetMapping("/api/ai/material/getMaterialDetail")
+    public Result getMaterialDetail(@Validated(Material.Detail.class) Material material) {
+        return Result.success().put("data", materialService.selectMaterialDetail(material));
+    }
+
     @Operation(summary = "创建素材")
-//    @PreAuthorize("@sr.hasPermission('31')")
+    @PreAuthorize("@sr.hasPermission('20.1.2')")
     @PostMapping("/api/ai/material/createMaterial")
     public Result createMaterial(@Validated(Material.Create.class) @RequestBody Material material) {
         material.setUser_id(SecurityUtil.getUserId());
@@ -37,7 +45,7 @@ public class MaterialController {
 
     @SysLog("编辑素材")
     @Operation(summary = "编辑素材")
-//    @PreAuthorize("@sr.hasPermission('31')")
+    @PreAuthorize("@sr.hasPermission('20.1.3')")
     @PutMapping("/api/ai/material/updateMaterial")
     public Result updateMaterial(@Validated(Material.Update.class) @RequestBody Material material) {
         material.setUser_id(SecurityUtil.getUserId());
@@ -46,7 +54,7 @@ public class MaterialController {
 
     @SysLog("删除素材")
     @Operation(summary = "删除素材")
-//    @PreAuthorize("@sr.hasPermission('31')")
+    @PreAuthorize("@sr.hasPermission('20.1.4')")
     @DeleteMapping("/api/ai/material/deleteMaterial")
     public Result deleteMaterial(@Validated(Material.Delete.class) @RequestBody Material material) {
         return Result.success().put("data", materialService.deleteMaterial(material));

+ 5 - 4
src/main/java/com/backendsys/modules/ai/material/controller/MaterialTagController.java

@@ -6,6 +6,7 @@ import com.backendsys.modules.common.utils.Result;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -18,15 +19,15 @@ public class MaterialTagController {
     @Autowired
     private MaterialTagService materialTagService;
 
-    @Operation(summary = "获取素材分类列表")
-//    @PreAuthorize("@sr.hasPermission('31')")
+    @Operation(summary = "获取素材标签列表")
+    @PreAuthorize("@sr.hasPermission('20.3')")
     @GetMapping("/api/ai/material/getMaterialTagList")
     public Result getMaterialTagList(@Validated(MaterialTag.TagList.class) MaterialTag materialTag) {
         return Result.success().put("data", materialTagService.selectMaterialTagList(materialTag));
     }
 
-    @Operation(summary = "获取素材分类列表(下拉)")
-//    @PreAuthorize("@sr.hasPermission('31')")
+    @Operation(summary = "获取素材标签列表(下拉)")
+    @PreAuthorize("@sr.hasPermission('20.3')")
     @GetMapping("/api/ai/material/getMaterialTagPopover")
     public Result getMaterialTagPopover(@Validated(MaterialTag.TagList.class) MaterialTag materialTag) {
         return Result.success().put("data", materialTagService.selectMaterialTagPopover(materialTag));

+ 3 - 1
src/main/java/com/backendsys/modules/ai/material/dao/MaterialDao.java

@@ -11,7 +11,9 @@ import java.util.Map;
 public interface MaterialDao extends BaseMapper<Material> {
 
     // 获取素材列表
-    List<Material> selectMaterialList(Material material);
+    List<Map<String, Object>> selectMaterialList(Material material);
+    // 获取素材详情
+    Material selectMaterialDetail(Material material);
     // 创建素材
     int insertMaterial(Material material);
     // 编辑素材

+ 2 - 0
src/main/java/com/backendsys/modules/ai/material/entity/Material.java

@@ -34,6 +34,8 @@ public class Material {
     private Long material_id;
 
     private Long user_id;
+    @TableField(exist = false)
+    private String user_nickname;
 
     @NotNull(message="素材分类ID不能为空", groups = { Create.class, Update.class })
     private Long category_id;

+ 3 - 0
src/main/java/com/backendsys/modules/ai/material/service/MaterialService.java

@@ -10,6 +10,9 @@ public interface MaterialService {
     // 获取素材列表
     PageEntity selectMaterialList(Material material);
 
+    // 获取素材详情
+    Material selectMaterialDetail(Material material);
+
     // 创建素材
     Map<String, Object> insertMaterial(Material material);
 

+ 30 - 9
src/main/java/com/backendsys/modules/ai/material/service/impl/MaterialServiceImpl.java

@@ -1,5 +1,6 @@
 package com.backendsys.modules.ai.material.service.impl;
 
+import cn.hutool.core.convert.Convert;
 import cn.hutool.core.util.StrUtil;
 import com.backendsys.exception.CustException;
 import com.backendsys.modules.ai.material.dao.MaterialCategoryDao;
@@ -40,6 +41,14 @@ public class MaterialServiceImpl implements MaterialService {
     @Autowired
     private ObjectKeyUtil objectKeyUtil;
 
+    private List<MaterialTag> getMaterialTagByIds(String tag_ids) {
+        if (StrUtil.isEmpty(tag_ids)) return null;
+        LambdaQueryWrapper<MaterialTag> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(MaterialTag::getId, tag_ids.split(","));
+        wrapper.orderByDesc(MaterialTag::getSort);
+        return materialTagDao.selectList(wrapper);
+    }
+
     /**
      * 获取素材列表
      */
@@ -47,7 +56,7 @@ public class MaterialServiceImpl implements MaterialService {
     public PageEntity selectMaterialList(Material material) {
         PageUtils.startPage();  // 分页
 
-        List<Material> list = materialDao.selectMaterialList(material);
+        List<Map<String, Object>> list = materialDao.selectMaterialList(material);
 
         // 1) 完成分页实体渲染
         PageEntity pageEntity = new PageInfoResult(list).toEntity();
@@ -55,14 +64,10 @@ public class MaterialServiceImpl implements MaterialService {
         if (!list.isEmpty()) {
             // 2) 分页列表格式化
             list = list.stream().map(item -> {
-                String tag_ids = item.getTag_ids();
-                if (StrUtil.isNotEmpty(tag_ids)) {
-                    LambdaQueryWrapper<MaterialTag> wrapper = new LambdaQueryWrapper<>();
-                    wrapper.in(MaterialTag::getId, tag_ids.split(","));
-                    wrapper.orderByDesc(MaterialTag::getSort);
-                    List<MaterialTag> materialTagList = materialTagDao.selectList(wrapper);
-                    item.setTag_list(materialTagList);
-                }
+                // 新增字段:标签列表
+                String tag_ids = Convert.toStr(item.get("tag_ids"));
+                List<MaterialTag> materialTagList = getMaterialTagByIds(tag_ids);
+                item.put("tag_list", materialTagList);
                 return item;
             }).collect(Collectors.toList());
 
@@ -74,6 +79,22 @@ public class MaterialServiceImpl implements MaterialService {
         return pageEntity;
     }
 
+    /**
+     * 获取素材详情
+     */
+    @Override
+    public Material selectMaterialDetail(Material material) {
+
+        Material detail = materialDao.selectMaterialDetail(material);
+        if (detail == null) throw new CustException("素材不存在");
+
+        // 新增字段:标签列表
+        List<MaterialTag> materialTagList = getMaterialTagByIds(detail.getTag_ids());
+        detail.setTag_list(materialTagList);
+
+        return detail;
+    }
+
     /**
      * 创建素材
      */

+ 43 - 1
src/main/resources/mapper/ai/material/MaterialDao.xml

@@ -3,6 +3,20 @@
 <mapper namespace="com.backendsys.modules.ai.material.dao.MaterialDao">
 
     <sql id="includeMaterial">
+        m.id,
+        m.id material_id,
+        m.user_id,
+        m.category_id,
+        COALESCE(mc.category_name, '') category_name,
+        COALESCE(m.tag_ids, '') tag_ids,
+        m.material_name,
+        COALESCE(m.image_thumb_url, '') image_thumb_url,
+        m.is_copyright,
+        m.create_time,
+        m.update_time
+    </sql>
+
+    <sql id="includeMaterialDetail">
         m.id,
         m.id material_id,
         m.user_id,
@@ -19,9 +33,28 @@
         m.update_time
     </sql>
 
-    <resultMap id="resultMapMaterial" type="com.backendsys.modules.ai.material.entity.Material">
+    <resultMap id="resultMapMaterial" type="java.util.LinkedHashMap">
+        <id property="id" column="id" jdbcType="BIGINT" />
+        <result property="material_id" column="id" javaType="java.lang.Long" />
+        <result property="user_id" column="user_id" javaType="java.lang.Long" />
+        <result property="user_nickname" column="user_nickname" />
+        <result property="category_id" column="category_id" javaType="java.lang.Long" />
+        <result property="category_name" column="category_name" />
+        <result property="tag_ids" column="tag_ids" />
+        <result property="material_name" column="material_name" />
+        <result property="image_thumb_url" column="image_thumb_url" />
+        <result property="is_copyright" column="is_copyright" javaType="java.lang.Integer" />
+        <result property="create_time" column="create_time"
+                typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
+        <result property="update_time" column="update_time"
+                typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
+    </resultMap>
+
+    <resultMap id="resultMapMaterialDetail" type="com.backendsys.modules.ai.material.entity.Material">
         <id property="id" column="id" jdbcType="BIGINT" />
         <result property="material_id" column="id" javaType="java.lang.Long" />
+        <result property="user_id" column="user_id" javaType="java.lang.Long" />
+        <result property="user_nickname" column="user_nickname" />
         <result property="category_id" column="category_id" javaType="java.lang.Long" />
         <result property="category_name" column="category_name" />
         <result property="tag_ids" column="tag_ids" />
@@ -60,6 +93,15 @@
         ORDER BY m.create_time DESC
     </select>
 
+    <select id="selectMaterialDetail" resultMap="resultMapMaterialDetail">
+        SELECT
+            <include refid="includeMaterialDetail" />, uf.nickname AS user_nickname
+        FROM ai_material m
+        LEFT JOIN ai_material_category mc ON m.category_id = mc.id
+        LEFT JOIN sys_user_info uf ON m.user_id = uf.user_id
+        WHERE m.id = #{material_id}
+    </select>
+
     <!-- 增 -->
     <insert id="insertMaterial" parameterType="com.backendsys.modules.ai.material.entity.Material"
         useGeneratedKeys="true" keyProperty="material_id">