Browse Source

file-service模块优化

home 2 years ago
parent
commit
41889ac41d

+ 269 - 260
bladex/blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml

@@ -44,19 +44,19 @@
         <result column="key" property="key"/>
     </resultMap>
 
-    <select id="lazyList"  resultMap="menuVOResultMap">
+    <select id="lazyList" resultMap="menuVOResultMap">
         SELECT
-            menu.*,
-            (
-                SELECT
-                    CASE WHEN count( 1 ) > 0 THEN 1 ELSE 0 END
-            FROM
-                blade_menu
-            WHERE
-                parent_id = menu.id AND is_deleted = 0
+        menu.*,
+        (
+        SELECT
+        CASE WHEN count( 1 ) > 0 THEN 1 ELSE 0 END
+        FROM
+        blade_menu
+        WHERE
+        parent_id = menu.id AND is_deleted = 0
         ) AS "has_children"
         FROM
-            blade_menu menu
+        blade_menu menu
         WHERE menu.is_deleted = 0
         <if test="param1!=null">
             and menu.parent_id = #{param1}
@@ -75,17 +75,17 @@
 
     <select id="lazyMenuList" resultMap="menuVOResultMap">
         SELECT
-            menu.*,
-            (
-                SELECT
-                    CASE WHEN count( 1 ) > 0 THEN 1 ELSE 0 END
+        menu.*,
+        (
+        SELECT
+        CASE WHEN count( 1 ) > 0 THEN 1 ELSE 0 END
         FROM
-                blade_menu
+        blade_menu
         WHERE
-        parent_id = menu.id AND is_deleted = 0  AND category = 1
+        parent_id = menu.id AND is_deleted = 0 AND category = 1
         ) AS "has_children"
         FROM
-            blade_menu menu
+        blade_menu menu
         WHERE menu.is_deleted = 0 AND menu.category = 1
         <if test="param1!=null">
             and menu.parent_id = #{param1}
@@ -103,11 +103,17 @@
     </select>
 
     <select id="tree" resultMap="treeNodeResultMap">
-        select id, parent_id, name as title, id as "value", id as "key" from blade_menu where is_deleted = 0 and category = 1
+        select id, parent_id, name as title, id as "value", id as "key"
+        from blade_menu
+        where is_deleted = 0
+          and category = 1
     </select>
 
     <select id="allMenu" resultMap="menuResultMap">
-        select * from blade_menu where is_deleted = 0 and category = 1
+        select *
+        from blade_menu
+        where is_deleted = 0
+          and category = 1
     </select>
 
     <select id="roleMenu" resultMap="menuResultMap">
@@ -127,49 +133,52 @@
 
     <select id="roleMenuByRoleId" resultMap="menuResultMap">
         select * from blade_menu where is_deleted = 0 and id IN
-            ( SELECT menu_id FROM blade_role_menu WHERE role_id IN
-                <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            )
+        ( SELECT menu_id FROM blade_role_menu WHERE role_id IN
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
     </select>
 
     <select id="roleMenuByTopMenuId" resultMap="menuResultMap">
-        select * from blade_menu where is_deleted = 0 and id IN
+        select *
+        from blade_menu
+        where is_deleted = 0
+          and id IN
               (
-                  SELECT menu_id FROM blade_top_menu_setting WHERE top_menu_id = #{param1}
+                  SELECT menu_id
+                  FROM blade_top_menu_setting
+                  WHERE top_menu_id = #{param1}
               )
     </select>
 
     <select id="routes" resultMap="menuResultMap">
         SELECT
-            *
+        *
         FROM
-            blade_menu
+        blade_menu
         WHERE
-            is_deleted = 0 and category = 1
-            and id IN ( SELECT menu_id FROM blade_role_menu WHERE role_id IN
-                        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                            #{item}
-                        </foreach> )
+        is_deleted = 0 and category = 1
+        and id IN ( SELECT menu_id FROM blade_role_menu WHERE role_id IN
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
     </select>
 
     <select id="allButtons" resultMap="menuResultMap">
-        SELECT
-            id,
-            parent_id,
-            CODE,
-            NAME,
-            alias,
-            path,
-            source,
-            action,
-            sort
-        FROM
-            blade_menu
-        WHERE
-            (
-                category = 2 OR id IN ( SELECT parent_id FROM blade_menu WHERE is_deleted = 0 AND category = 2 )
+        SELECT id,
+               parent_id,
+               CODE,
+               NAME,
+               alias,
+               path,
+               source,
+               action,
+               sort
+        FROM blade_menu
+        WHERE (
+                    category = 2 OR id IN (SELECT parent_id FROM blade_menu WHERE is_deleted = 0 AND category = 2)
             )
           AND is_deleted = 0
         ORDER BY sort
@@ -177,51 +186,54 @@
 
     <select id="buttons" resultMap="menuResultMap">
         SELECT * FROM (
-            SELECT
-                id,
-                parent_id,
-                code,
-                name,
-                alias,
-                path,
-                source,
-                action,
-                sort
-            FROM
-                blade_menu
-            WHERE
-                is_deleted = 0 and id IN (
-                  SELECT parent_id FROM blade_menu
-                  WHERE ( category = 2 AND id IN ( SELECT menu_id FROM blade_role_menu WHERE role_id IN
-                    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                        #{item}
-                    </foreach>
-                  ) ) )
-
-            UNION ALL
-
-            SELECT
-                id,
-                parent_id,
-                code,
-                name,
-                alias,
-                path,
-                source,
-                action,
-                sort
-            FROM
-                blade_menu
-            WHERE
-                is_deleted = 0 and  category = 2 AND id IN ( SELECT menu_id FROM blade_role_menu WHERE role_id IN
-                <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>)
+        SELECT
+        id,
+        parent_id,
+        code,
+        name,
+        alias,
+        path,
+        source,
+        action,
+        sort
+        FROM
+        blade_menu
+        WHERE
+        is_deleted = 0 and id IN (
+        SELECT parent_id FROM blade_menu
+        WHERE ( category = 2 AND id IN ( SELECT menu_id FROM blade_role_menu WHERE role_id IN
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        ) ) )
+
+        UNION ALL
+
+        SELECT
+        id,
+        parent_id,
+        code,
+        name,
+        alias,
+        path,
+        source,
+        action,
+        sort
+        FROM
+        blade_menu
+        WHERE
+        is_deleted = 0 and category = 2 AND id IN ( SELECT menu_id FROM blade_role_menu WHERE role_id IN
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>)
         ) menu ORDER BY sort
     </select>
 
     <select id="grantTree" resultMap="treeNodeResultMap">
-        select id, parent_id, name as title, id as "value", id as "key" from blade_menu where is_deleted = 0 order by sort
+        select id, parent_id, name as title, id as "value", id as "key"
+        from blade_menu
+        where is_deleted = 0
+        order by sort
     </select>
 
     <select id="grantTreeByRole" resultMap="treeNodeResultMap">
@@ -229,102 +241,95 @@
         and id in ( select menu_id from blade_role_menu where role_id in
         <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
             #{item}
-        </foreach> )
+        </foreach>
+        )
         or id in (
-            select parent_id from blade_menu where is_deleted = 0
-            and id in ( select menu_id from blade_role_menu where role_id in
-            <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                #{item}
-            </foreach> )
-          )
+        select parent_id from blade_menu where is_deleted = 0
+        and id in ( select menu_id from blade_role_menu where role_id in
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
+        )
         order by sort
     </select>
 
     <select id="grantTopTree" resultMap="treeNodeResultMap">
-        select id, parent_id, name as title, id as "value", id as "key" from blade_menu where category = 1 and is_deleted = 0 order by sort
+        select id, parent_id, name as title, id as "value", id as "key"
+        from blade_menu
+        where category = 1
+          and is_deleted = 0
+        order by sort
     </select>
 
     <select id="grantTopTreeByRole" resultMap="treeNodeResultMap">
-        select id, parent_id, name as title, id as "value", id as "key" from blade_menu where category = 1 and is_deleted = 0
+        select id, parent_id, name as title, id as "value", id as "key" from blade_menu where category = 1 and
+        is_deleted = 0
         and id in ( select menu_id from blade_role_menu where role_id in
         <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
             #{item}
-        </foreach> )
+        </foreach>
+        )
         or id in (
         select parent_id from blade_menu where is_deleted = 0
         and id in ( select menu_id from blade_role_menu where role_id in
         <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
             #{item}
-        </foreach> )
+        </foreach>
+        )
         )
         order by sort
     </select>
 
     <select id="grantDataScopeTree" resultMap="treeNodeResultMap">
-        SELECT
-            *
-        FROM
-            (
-                SELECT
-                    id,
-                    parent_id,
-                    NAME AS title,
-                    id AS "value",
-                    id AS "key"
-                FROM
-                    blade_menu
-                WHERE
-                    category = 1
-                  AND is_deleted = 0
-                  AND id IN ( SELECT menu_id FROM blade_scope_data WHERE is_deleted = 0 AND menu_id IS NOT NULL )
-            ) menu
+        SELECT *
+        FROM (
+                 SELECT id,
+                        parent_id,
+                        NAME AS title,
+                        id   AS "value",
+                        id   AS "key"
+                 FROM blade_menu
+                 WHERE category = 1
+                   AND is_deleted = 0
+                   AND id IN (SELECT menu_id FROM blade_scope_data WHERE is_deleted = 0 AND menu_id IS NOT NULL)
+             ) menu
 
         UNION ALL
 
-        SELECT
-            id,
-            menu_id AS parent_id,
-            scope_name AS title,
-            id AS "value",
-            id AS "key"
-        FROM
-            blade_scope_data
-        WHERE
-            is_deleted = 0
+        SELECT id,
+               menu_id    AS parent_id,
+               scope_name AS title,
+               id         AS "value",
+               id         AS "key"
+        FROM blade_scope_data
+        WHERE is_deleted = 0
           AND menu_id IS NOT NULL
     </select>
 
     <select id="grantApiScopeTree" resultMap="treeNodeResultMap">
-        SELECT
-            *
-        FROM
-            (
-                SELECT
-                    id,
-                    parent_id,
-                    NAME AS title,
-                    id AS "value",
-                    id AS "key"
-                FROM
-                    blade_menu
-                WHERE
-                    category = 1
-                  AND is_deleted = 0
-                  AND id IN ( SELECT menu_id FROM blade_scope_api WHERE is_deleted = 0 AND menu_id IS NOT NULL )
-            ) menu
+        SELECT *
+        FROM (
+                 SELECT id,
+                        parent_id,
+                        NAME AS title,
+                        id   AS "value",
+                        id   AS "key"
+                 FROM blade_menu
+                 WHERE category = 1
+                   AND is_deleted = 0
+                   AND id IN (SELECT menu_id FROM blade_scope_api WHERE is_deleted = 0 AND menu_id IS NOT NULL)
+             ) menu
 
         UNION ALL
 
-        SELECT
-            id,
-            menu_id AS parent_id,
-            scope_name AS title,
-            id AS "value",
-            id AS "key"
-        FROM
-            blade_scope_api
-        WHERE
-            is_deleted = 0
+        SELECT id,
+               menu_id    AS parent_id,
+               scope_name AS title,
+               id         AS "value",
+               id         AS "key"
+        FROM blade_scope_api
+        WHERE is_deleted = 0
           AND menu_id IS NOT NULL
     </select>
 
@@ -333,61 +338,63 @@
         *
         FROM
         (
-            SELECT
-                id,
-                parent_id,
-                NAME AS title,
-                id AS "value",
-                id AS "key"
-            FROM
-                blade_menu
-            WHERE
-                category = 1
-            AND is_deleted = 0
-            AND id IN ( SELECT menu_id FROM blade_scope_data WHERE is_deleted = 0 AND menu_id IS NOT NULL )
-            AND (
-                id IN (
-                    select menu_id from blade_role_menu where role_id in
-                    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                        #{item}
-                    </foreach>
-                )
-                OR id IN (
-                    select parent_id from blade_menu where is_deleted = 0
-                    and id in ( select menu_id from blade_role_menu where role_id in
-                    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                        #{item}
-                    </foreach> )
-                )
-            )
+        SELECT
+        id,
+        parent_id,
+        NAME AS title,
+        id AS "value",
+        id AS "key"
+        FROM
+        blade_menu
+        WHERE
+        category = 1
+        AND is_deleted = 0
+        AND id IN ( SELECT menu_id FROM blade_scope_data WHERE is_deleted = 0 AND menu_id IS NOT NULL )
+        AND (
+        id IN (
+        select menu_id from blade_role_menu where role_id in
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
+        OR id IN (
+        select parent_id from blade_menu where is_deleted = 0
+        and id in ( select menu_id from blade_role_menu where role_id in
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
+        )
+        )
         ) menu
 
         UNION ALL
 
         SELECT
-            id,
-            menu_id AS parent_id,
-            scope_name AS title,
-            id AS "value",
-            id AS "key"
+        id,
+        menu_id AS parent_id,
+        scope_name AS title,
+        id AS "value",
+        id AS "key"
         FROM
-            blade_scope_data
+        blade_scope_data
         WHERE
-            is_deleted = 0
+        is_deleted = 0
         AND (
-            menu_id IN (
-                select menu_id from blade_role_menu where role_id in
-                <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            )
-            OR menu_id IN (
-                select parent_id from blade_menu where is_deleted = 0
-                and id in ( select menu_id from blade_role_menu where role_id in
-                <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach> )
-            )
+        menu_id IN (
+        select menu_id from blade_role_menu where role_id in
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
+        OR menu_id IN (
+        select parent_id from blade_menu where is_deleted = 0
+        and id in ( select menu_id from blade_role_menu where role_id in
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
+        )
         )
         AND menu_id IS NOT NULL
     </select>
@@ -397,81 +404,83 @@
         *
         FROM
         (
-            SELECT
-                id,
-                parent_id,
-                NAME AS title,
-                id AS "value",
-                id AS "key"
-            FROM
-                blade_menu
-            WHERE
-                category = 1
-            AND is_deleted = 0
-            AND id IN ( SELECT menu_id FROM blade_scope_api WHERE is_deleted = 0 AND menu_id IS NOT NULL )
-            AND (
-                id IN (
-                    select menu_id from blade_role_menu where role_id in
-                    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                        #{item}
-                    </foreach>
-                )
-                OR id IN (
-                    select parent_id from blade_menu where is_deleted = 0
-                    and id in (
-                        select menu_id from blade_role_menu where role_id in
-                    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                        #{item}
-                    </foreach> )
-                )
-            )
+        SELECT
+        id,
+        parent_id,
+        NAME AS title,
+        id AS "value",
+        id AS "key"
+        FROM
+        blade_menu
+        WHERE
+        category = 1
+        AND is_deleted = 0
+        AND id IN ( SELECT menu_id FROM blade_scope_api WHERE is_deleted = 0 AND menu_id IS NOT NULL )
+        AND (
+        id IN (
+        select menu_id from blade_role_menu where role_id in
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
+        OR id IN (
+        select parent_id from blade_menu where is_deleted = 0
+        and id in (
+        select menu_id from blade_role_menu where role_id in
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
+        )
+        )
         ) menu
 
         UNION ALL
 
         SELECT
-            id,
-            menu_id AS parent_id,
-            scope_name AS title,
-            id AS "value",
-            id AS "key"
+        id,
+        menu_id AS parent_id,
+        scope_name AS title,
+        id AS "value",
+        id AS "key"
         FROM
-            blade_scope_api
+        blade_scope_api
         WHERE
-            is_deleted = 0
+        is_deleted = 0
         AND
-            (
-                menu_id IN (
-                    select menu_id from blade_role_menu where role_id in
-                    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                        #{item}
-                    </foreach>
-                )
-            OR menu_id IN (
-                    select parent_id from blade_menu where is_deleted = 0
-                    and id in ( select menu_id from blade_role_menu where role_id in
-                    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                        #{item}
-                    </foreach> )
-                )
+        (
+        menu_id IN (
+        select menu_id from blade_role_menu where role_id in
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
+        OR menu_id IN (
+        select parent_id from blade_menu where is_deleted = 0
+        and id in ( select menu_id from blade_role_menu where role_id in
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
+        )
         )
         AND menu_id IS NOT NULL
     </select>
 
     <select id="authRoutes" resultType="org.springblade.system.dto.MenuDTO">
         SELECT
-            GROUP_CONCAT(r.role_alias) as alias,
-            m.path
+        GROUP_CONCAT(r.role_alias) as alias,
+        m.path
         FROM
-            blade_role_menu rm
-            LEFT JOIN blade_menu m ON rm.menu_id = m.id
-            LEFT JOIN blade_role r ON rm.role_id = r.id
+        blade_role_menu rm
+        LEFT JOIN blade_menu m ON rm.menu_id = m.id
+        LEFT JOIN blade_role r ON rm.role_id = r.id
         WHERE
-            rm.role_id IN
-            <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
-                #{item}
-            </foreach>
-            AND m.path IS NOT NULL and m.is_deleted = 0
+        rm.role_id IN
+        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        AND m.path IS NOT NULL and m.is_deleted = 0
         GROUP BY m.path
     </select>
 

+ 179 - 176
bladex/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java

@@ -59,181 +59,184 @@ import static org.springblade.core.cache.constant.CacheConstant.MENU_CACHE;
 @AllArgsConstructor
 public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {
 
-	private final IRoleMenuService roleMenuService;
-	private final IRoleScopeService roleScopeService;
-	private final ITopMenuSettingService topMenuSettingService;
-	private final static String PARENT_ID = "parentId";
-	private final static Integer MENU_CATEGORY = 1;
-
-	@Override
-	public List<MenuVO> lazyList(Long parentId, Map<String, Object> param) {
-		if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) {
-			parentId = null;
-		}
-		return baseMapper.lazyList(parentId, param);
-	}
-
-	@Override
-	public List<MenuVO> lazyMenuList(Long parentId, Map<String, Object> param) {
-		if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) {
-			parentId = null;
-		}
-		return baseMapper.lazyMenuList(parentId, param);
-	}
-
-
-	@Override
-	public List<MenuVO> routes(String roleId, Long topMenuId) {
-		if (StringUtil.isBlank(roleId)) {
-			return null;
-		}
-		List<Menu> allMenus = baseMapper.allMenu();
-		List<Menu> roleMenus;
-		// 超级管理员并且不是顶部菜单请求则返回全部菜单
-		if (AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
-			roleMenus = allMenus;
-		}
-		// 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单
-		else if (!AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
-			roleMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
-		}
-		// 顶部菜单请求返回对应角色权限菜单
-		else {
-			// 角色配置对应菜单
-			List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
-			// 反向递归角色菜单所有父级
-			List<Menu> routes = new LinkedList<>(roleIdMenus);
-			roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
-			// 顶部配置对应菜单
-			List<Menu> topIdMenus = baseMapper.roleMenuByTopMenuId(topMenuId);
-			// 筛选匹配角色对应的权限菜单
-			roleMenus = topIdMenus.stream().filter(x ->
-				routes.stream().anyMatch(route -> route.getId().longValue() == x.getId().longValue())
-			).collect(Collectors.toList());
-		}
-		return buildRoutes(allMenus, roleMenus);
-	}
-
-	private List<MenuVO> buildRoutes(List<Menu> allMenus, List<Menu> roleMenus) {
-		List<Menu> routes = new LinkedList<>(roleMenus);
-		roleMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
-		routes.sort(Comparator.comparing(Menu::getSort));
-		MenuWrapper menuWrapper = new MenuWrapper();
-		List<Menu> collect = routes.stream().filter(x -> Func.equals(x.getCategory(), 1)).collect(Collectors.toList());
-		return menuWrapper.listNodeVO(collect);
-	}
-
-	private void recursion(List<Menu> allMenus, List<Menu> routes, Menu roleMenu) {
-		Optional<Menu> menu = allMenus.stream().filter(x -> Func.equals(x.getId(), roleMenu.getParentId())).findFirst();
-		if (menu.isPresent() && !routes.contains(menu.get())) {
-			routes.add(menu.get());
-			recursion(allMenus, routes, menu.get());
-		}
-	}
-
-	@Override
-	public List<MenuVO> buttons(String roleId) {
-		List<Menu> buttons = (AuthUtil.isAdministrator()) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId));
-		MenuWrapper menuWrapper = new MenuWrapper();
-		return menuWrapper.listNodeVO(buttons);
-	}
-
-	@Override
-	public List<MenuVO> tree() {
-		return ForestNodeMerger.merge(baseMapper.tree());
-	}
-
-	@Override
-	public List<MenuVO> grantTree(BladeUser user) {
-		return ForestNodeMerger.merge(user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantTree() : baseMapper.grantTreeByRole(Func.toLongList(user.getRoleId())));
-	}
-
-	@Override
-	public List<MenuVO> grantTopTree(BladeUser user) {
-		return ForestNodeMerger.merge(user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantTopTree() : baseMapper.grantTopTreeByRole(Func.toLongList(user.getRoleId())));
-	}
-
-	@Override
-	public List<MenuVO> grantDataScopeTree(BladeUser user) {
-		return ForestNodeMerger.merge(user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantDataScopeTree() : baseMapper.grantDataScopeTreeByRole(Func.toLongList(user.getRoleId())));
-	}
-
-	@Override
-	public List<MenuVO> grantApiScopeTree(BladeUser user) {
-		return ForestNodeMerger.merge(user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantApiScopeTree() : baseMapper.grantApiScopeTreeByRole(Func.toLongList(user.getRoleId())));
-	}
-
-	@Override
-	public List<String> roleTreeKeys(String roleIds) {
-		List<RoleMenu> roleMenus = roleMenuService.list(Wrappers.<RoleMenu>query().lambda().in(RoleMenu::getRoleId, Func.toLongList(roleIds)));
-		return roleMenus.stream().map(roleMenu -> Func.toStr(roleMenu.getMenuId())).collect(Collectors.toList());
-	}
-
-	@Override
-	public List<String> topTreeKeys(String topMenuIds) {
-		List<TopMenuSetting> settings = topMenuSettingService.list(Wrappers.<TopMenuSetting>query().lambda().in(TopMenuSetting::getTopMenuId, Func.toLongList(topMenuIds)));
-		return settings.stream().map(setting -> Func.toStr(setting.getMenuId())).collect(Collectors.toList());
-	}
-
-	@Override
-	public List<String> dataScopeTreeKeys(String roleIds) {
-		List<RoleScope> roleScopes = roleScopeService.list(Wrappers.<RoleScope>query().lambda().eq(RoleScope::getScopeCategory, DATA_SCOPE_CATEGORY).in(RoleScope::getRoleId, Func.toLongList(roleIds)));
-		return roleScopes.stream().map(roleScope -> Func.toStr(roleScope.getScopeId())).collect(Collectors.toList());
-	}
-
-	@Override
-	public List<String> apiScopeTreeKeys(String roleIds) {
-		List<RoleScope> roleScopes = roleScopeService.list(Wrappers.<RoleScope>query().lambda().eq(RoleScope::getScopeCategory, API_SCOPE_CATEGORY).in(RoleScope::getRoleId, Func.toLongList(roleIds)));
-		return roleScopes.stream().map(roleScope -> Func.toStr(roleScope.getScopeId())).collect(Collectors.toList());
-	}
-
-	@Override
-	@Cacheable(cacheNames = MENU_CACHE, key = "'auth:routes:' + #user.roleId")
-	public List<Kv> authRoutes(BladeUser user) {
-		List<MenuDTO> routes = baseMapper.authRoutes(Func.toLongList(user.getRoleId()));
-		List<Kv> list = new ArrayList<>();
-		routes.forEach(route -> list.add(Kv.create().set(route.getPath(), Kv.create().set("authority", Func.toStrArray(route.getAlias())))));
-		return list;
-	}
-
-	@Override
-	public boolean removeMenu(String ids) {
-		Integer cnt = baseMapper.selectCount(Wrappers.<Menu>query().lambda().in(Menu::getParentId, Func.toLongList(ids)));
-		if (cnt > 0) {
-			throw new ServiceException("请先删除子节点!");
-		}
-		return removeByIds(Func.toLongList(ids));
-	}
-
-	@Override
-	public boolean submit(Menu menu) {
-		LambdaQueryWrapper<Menu> menuQueryWrapper = Wrappers.lambdaQuery();
-		if (menu.getId() == null) {
-			menuQueryWrapper.eq(Menu::getCode, menu.getCode()).or(
-				wrapper -> wrapper.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY)
-			);
-		} else {
-			menuQueryWrapper.ne(Menu::getId, menu.getId()).and(
-				wrapper -> wrapper.eq(Menu::getCode, menu.getCode()).or(
-					o -> o.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY)
-				)
-			);
-		}
-		Integer cnt = baseMapper.selectCount(menuQueryWrapper);
-		if (cnt > 0) {
-			throw new ServiceException("菜单名或编号已存在!");
-		}
-		if (menu.getParentId() == null && menu.getId() == null) {
-			menu.setParentId(BladeConstant.TOP_PARENT_ID);
-		}
-		if (menu.getParentId() != null && menu.getId() == null) {
-			Menu parentMenu = baseMapper.selectById(menu.getParentId());
-			if (parentMenu != null && parentMenu.getCategory() != 1) {
-				throw new ServiceException("父节点只可选择菜单类型!");
-			}
-		}
-		menu.setIsDeleted(BladeConstant.DB_NOT_DELETED);
-		return saveOrUpdate(menu);
-	}
+    private final IRoleMenuService roleMenuService;
+    private final IRoleScopeService roleScopeService;
+    private final ITopMenuSettingService topMenuSettingService;
+    private final static String PARENT_ID = "parentId";
+    private final static Integer MENU_CATEGORY = 1;
+
+    @Override
+    public List<MenuVO> lazyList(Long parentId, Map<String, Object> param) {
+        if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) {
+            parentId = null;
+        }
+        return baseMapper.lazyList(parentId, param);
+    }
+
+    @Override
+    public List<MenuVO> lazyMenuList(Long parentId, Map<String, Object> param) {
+        if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) {
+            parentId = null;
+        }
+        return baseMapper.lazyMenuList(parentId, param);
+    }
+
+
+    @Override
+    public List<MenuVO> routes(String roleId, Long topMenuId) {
+        if (StringUtil.isBlank(roleId)) {
+            return null;
+        }
+        List<Menu> allMenus = baseMapper.allMenu();
+        List<Menu> roleMenus;
+        // 超级管理员并且不是顶部菜单请求则返回全部菜单
+        if (AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
+            roleMenus = allMenus;
+        }
+        // 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单
+        else if (!AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
+            roleMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
+        }
+        // 顶部菜单请求返回对应角色权限菜单
+        else {
+            // 角色配置对应菜单
+            List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
+            // 反向递归角色菜单所有父级
+            List<Menu> routes = new LinkedList<>(roleIdMenus);
+            roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
+            // 顶部配置对应菜单
+            List<Menu> topIdMenus = baseMapper.roleMenuByTopMenuId(topMenuId);
+            // 筛选匹配角色对应的权限菜单
+            roleMenus = topIdMenus.stream().filter(x ->
+                    routes.stream().anyMatch(route -> route.getId().longValue() == x.getId().longValue())
+            ).collect(Collectors.toList());
+        }
+        return buildRoutes(allMenus, roleMenus);
+    }
+
+    private List<MenuVO> buildRoutes(List<Menu> allMenus, List<Menu> roleMenus) {
+        List<Menu> routes = new LinkedList<>(roleMenus);
+        roleMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
+        routes.sort(Comparator.comparing(Menu::getSort));
+        MenuWrapper menuWrapper = new MenuWrapper();
+        List<Menu> collect = routes.stream().filter(x -> Func.equals(x.getCategory(), 1)).collect(Collectors.toList());
+        return menuWrapper.listNodeVO(collect);
+    }
+
+    private void recursion(List<Menu> allMenus, List<Menu> routes, Menu roleMenu) {
+        Optional<Menu> menu = allMenus.stream().filter(x -> Func.equals(x.getId(), roleMenu.getParentId())).findFirst();
+        if (menu.isPresent() && !routes.contains(menu.get())) {
+            routes.add(menu.get());
+            recursion(allMenus, routes, menu.get());
+        }
+    }
+
+    @Override
+    public List<MenuVO> buttons(String roleId) {
+        List<Menu> buttons = (AuthUtil.isAdministrator()) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId));
+        MenuWrapper menuWrapper = new MenuWrapper();
+        return menuWrapper.listNodeVO(buttons);
+    }
+
+    @Override
+    public List<MenuVO> tree() {
+        return ForestNodeMerger.merge(baseMapper.tree());
+    }
+
+    @Override
+    public List<MenuVO> grantTree(BladeUser user) {
+        return ForestNodeMerger.merge(
+                user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID)
+                        ? baseMapper.grantTree()
+                        : baseMapper.grantTreeByRole(Func.toLongList(user.getRoleId())));
+    }
+
+    @Override
+    public List<MenuVO> grantTopTree(BladeUser user) {
+        return ForestNodeMerger.merge(user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantTopTree() : baseMapper.grantTopTreeByRole(Func.toLongList(user.getRoleId())));
+    }
+
+    @Override
+    public List<MenuVO> grantDataScopeTree(BladeUser user) {
+        return ForestNodeMerger.merge(user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantDataScopeTree() : baseMapper.grantDataScopeTreeByRole(Func.toLongList(user.getRoleId())));
+    }
+
+    @Override
+    public List<MenuVO> grantApiScopeTree(BladeUser user) {
+        return ForestNodeMerger.merge(user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantApiScopeTree() : baseMapper.grantApiScopeTreeByRole(Func.toLongList(user.getRoleId())));
+    }
+
+    @Override
+    public List<String> roleTreeKeys(String roleIds) {
+        List<RoleMenu> roleMenus = roleMenuService.list(Wrappers.<RoleMenu>query().lambda().in(RoleMenu::getRoleId, Func.toLongList(roleIds)));
+        return roleMenus.stream().map(roleMenu -> Func.toStr(roleMenu.getMenuId())).collect(Collectors.toList());
+    }
+
+    @Override
+    public List<String> topTreeKeys(String topMenuIds) {
+        List<TopMenuSetting> settings = topMenuSettingService.list(Wrappers.<TopMenuSetting>query().lambda().in(TopMenuSetting::getTopMenuId, Func.toLongList(topMenuIds)));
+        return settings.stream().map(setting -> Func.toStr(setting.getMenuId())).collect(Collectors.toList());
+    }
+
+    @Override
+    public List<String> dataScopeTreeKeys(String roleIds) {
+        List<RoleScope> roleScopes = roleScopeService.list(Wrappers.<RoleScope>query().lambda().eq(RoleScope::getScopeCategory, DATA_SCOPE_CATEGORY).in(RoleScope::getRoleId, Func.toLongList(roleIds)));
+        return roleScopes.stream().map(roleScope -> Func.toStr(roleScope.getScopeId())).collect(Collectors.toList());
+    }
+
+    @Override
+    public List<String> apiScopeTreeKeys(String roleIds) {
+        List<RoleScope> roleScopes = roleScopeService.list(Wrappers.<RoleScope>query().lambda().eq(RoleScope::getScopeCategory, API_SCOPE_CATEGORY).in(RoleScope::getRoleId, Func.toLongList(roleIds)));
+        return roleScopes.stream().map(roleScope -> Func.toStr(roleScope.getScopeId())).collect(Collectors.toList());
+    }
+
+    @Override
+    @Cacheable(cacheNames = MENU_CACHE, key = "'auth:routes:' + #user.roleId")
+    public List<Kv> authRoutes(BladeUser user) {
+        List<MenuDTO> routes = baseMapper.authRoutes(Func.toLongList(user.getRoleId()));
+        List<Kv> list = new ArrayList<>();
+        routes.forEach(route -> list.add(Kv.create().set(route.getPath(), Kv.create().set("authority", Func.toStrArray(route.getAlias())))));
+        return list;
+    }
+
+    @Override
+    public boolean removeMenu(String ids) {
+        Integer cnt = baseMapper.selectCount(Wrappers.<Menu>query().lambda().in(Menu::getParentId, Func.toLongList(ids)));
+        if (cnt > 0) {
+            throw new ServiceException("请先删除子节点!");
+        }
+        return removeByIds(Func.toLongList(ids));
+    }
+
+    @Override
+    public boolean submit(Menu menu) {
+        LambdaQueryWrapper<Menu> menuQueryWrapper = Wrappers.lambdaQuery();
+        if (menu.getId() == null) {
+            menuQueryWrapper.eq(Menu::getCode, menu.getCode()).or(
+                    wrapper -> wrapper.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY)
+            );
+        } else {
+            menuQueryWrapper.ne(Menu::getId, menu.getId()).and(
+                    wrapper -> wrapper.eq(Menu::getCode, menu.getCode()).or(
+                            o -> o.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY)
+                    )
+            );
+        }
+        Integer cnt = baseMapper.selectCount(menuQueryWrapper);
+        if (cnt > 0) {
+            throw new ServiceException("菜单名或编号已存在!");
+        }
+        if (menu.getParentId() == null && menu.getId() == null) {
+            menu.setParentId(BladeConstant.TOP_PARENT_ID);
+        }
+        if (menu.getParentId() != null && menu.getId() == null) {
+            Menu parentMenu = baseMapper.selectById(menu.getParentId());
+            if (parentMenu != null && parentMenu.getCategory() != 1) {
+                throw new ServiceException("父节点只可选择菜单类型!");
+            }
+        }
+        menu.setIsDeleted(BladeConstant.DB_NOT_DELETED);
+        return saveOrUpdate(menu);
+    }
 
 }

+ 29 - 16
hx-common/client-util/src/main/java/com/fjhx/utils/FileClientUtil.java

@@ -6,7 +6,10 @@ import com.fjhx.feign.IFileClient;
 import com.fjhx.params.FileInfoParam;
 import org.springblade.core.tool.api.R;
 
+import java.util.Collections;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 public class FileClientUtil {
 
@@ -24,7 +27,7 @@ public class FileClientUtil {
      */
     public static void bindingFile(Long businessId, Integer businessType, FileInfoParam param) {
         if (ObjectUtil.isEmpty(param)) return;
-        R result = fileClient.bindingFile(APPLICATION_NAME, businessId, businessType, param);
+        R result = fileClient.bindingFile(APPLICATION_NAME, businessId, businessType, Collections.singletonList(param));
         Assert.eqTrue(result.isSuccess(), "保存文件信息失败");
     }
 
@@ -37,7 +40,7 @@ public class FileClientUtil {
      */
     public static void bindingFile(Long businessId, Integer businessType, List<FileInfoParam> paramList) {
         if (ObjectUtil.isEmpty(paramList)) return;
-        R result = fileClient.bindingFileList(APPLICATION_NAME, businessId, businessType, paramList);
+        R result = fileClient.bindingFile(APPLICATION_NAME, businessId, businessType, paramList);
         Assert.eqTrue(result.isSuccess(), "保存文件信息失败");
     }
 
@@ -50,7 +53,7 @@ public class FileClientUtil {
      */
     public static void againBindingFile(Long businessId, Integer businessType, FileInfoParam param) {
         if (ObjectUtil.isEmpty(param)) return;
-        R result = fileClient.againBindingFile(APPLICATION_NAME, businessId, businessType, param);
+        R result = fileClient.againBindingFile(APPLICATION_NAME, businessId, businessType, Collections.singletonList(param));
         Assert.eqTrue(result.isSuccess(), "保存文件信息失败");
     }
 
@@ -63,7 +66,7 @@ public class FileClientUtil {
      */
     public static void againBindingFile(Long businessId, Integer businessType, List<FileInfoParam> paramList) {
         if (ObjectUtil.isEmpty(paramList)) return;
-        R result = fileClient.againBindingFileList(APPLICATION_NAME, businessId, businessType, paramList);
+        R result = fileClient.againBindingFile(APPLICATION_NAME, businessId, businessType, paramList);
         Assert.eqTrue(result.isSuccess(), "保存文件信息失败");
     }
 
@@ -80,33 +83,43 @@ public class FileClientUtil {
     /**
      * 获取文件信息
      */
-    public static void getFileInfo(Long businessId) {
-        R<FileInfoParam> result = fileClient.getFileInfo(businessId, null);
-        Assert.eqTrue(result.isSuccess(), "获取文件信息失败");
+    public static FileInfoParam getFileInfo(Long businessId) {
+        R<List<FileInfoParam>> result = fileClient.getFileInfo(Collections.singletonList(businessId));
+        List<FileInfoParam> data = result.getData();
+        return data.size() == 0 ? null : data.get(data.size() - 1);
     }
 
     /**
      * 获取文件信息
      */
-    public static void getFileInfo(Long businessId, Integer businessType) {
-        R<FileInfoParam> result = fileClient.getFileInfo(businessId, businessType);
-        Assert.eqTrue(result.isSuccess(), "获取文件信息失败");
+    public static List<FileInfoParam> getFileInfoList(Long businessId) {
+        R<List<FileInfoParam>> result = fileClient.getFileInfo(Collections.singletonList(businessId));
+        return result.getData();
     }
 
     /**
      * 获取文件信息
      */
-    public static void getFileInfoList(Long businessId) {
-        R<List<FileInfoParam>> result = fileClient.getFileInfoList(businessId, null);
-        Assert.eqTrue(result.isSuccess(), "获取文件信息失败");
+    public static Map<Long, FileInfoParam> getFileInfoMap(List<Long> businessId) {
+        R<List<FileInfoParam>> result = fileClient.getFileInfo(businessId);
+
+        return result.getData().stream().collect(Collectors.toMap(
+                FileInfoParam::getBusinessId,
+                item -> item,
+                (v1, v2) -> v2
+        ));
     }
 
     /**
      * 获取文件信息
      */
-    public static void getFileInfoList(Long businessId, Integer businessType) {
-        R<List<FileInfoParam>> result = fileClient.getFileInfoList(businessId, businessType);
-        Assert.eqTrue(result.isSuccess(), "获取文件信息失败");
+    public static Map<Long, List<FileInfoParam>> getFileInfoListMap(List<Long> businessId) {
+        R<List<FileInfoParam>> result = fileClient.getFileInfo(businessId);
+
+        return result.getData().stream().collect(Collectors.groupingBy(
+                FileInfoParam::getBusinessId
+        ));
     }
 
+
 }

+ 6 - 49
hx-service-api/file-service-api/src/main/java/com/fjhx/feign/IFileClient.java

@@ -18,70 +18,37 @@ public interface IFileClient {
 
     String BINDING_FILE = ClientConstant.API_PREFIX + "/bindingFile";
 
-    String BINDING_FILE_LIST = ClientConstant.API_PREFIX + "/bindingFileList";
-
     String AGAIN_BINDING_FILE = ClientConstant.API_PREFIX + "/againBindingFile";
 
-    String AGAIN_BINDING_FILE_List = ClientConstant.API_PREFIX + "/againBindingFileList";
-
     String RELIEVE_BINDING_FILE = ClientConstant.API_PREFIX + "/relieveBindingFile";
 
     String GET_FILE_INFO = ClientConstant.API_PREFIX + "/getFileInfo";
 
-    String GET_FILE_INFO_LIST = ClientConstant.API_PREFIX + "/getFileInfoList";
-
-
     /**
      * 文件绑定业务id
      *
      * @param businessId   业务id
      * @param businessType 业务类型
-     * @param param        文件信息
+     * @param paramList    文件信息
      */
     @PostMapping(BINDING_FILE)
     R bindingFile(@RequestParam("applicationName") String applicationName,
                   @RequestParam("businessId") Long businessId,
                   @RequestParam("businessType") Integer businessType,
-                  @RequestBody FileInfoParam param);
-
-    /**
-     * 文件绑定业务id
-     *
-     * @param businessId   业务id
-     * @param businessType 业务类型
-     * @param paramList    文件信息
-     */
-    @PostMapping(BINDING_FILE_LIST)
-    R bindingFileList(@RequestParam("applicationName") String applicationName,
-                      @RequestParam("businessId") Long businessId,
-                      @RequestParam("businessType") Integer businessType,
-                      @RequestBody List<FileInfoParam> paramList);
+                  @RequestBody List<FileInfoParam> paramList);
 
     /**
      * 修改文件绑定信息
      *
      * @param businessId   业务id
      * @param businessType 业务类型
-     * @param param        文件信息
+     * @param paramList    文件信息
      */
     @PostMapping(AGAIN_BINDING_FILE)
     R againBindingFile(@RequestParam("applicationName") String applicationName,
                        @RequestParam("businessId") Long businessId,
                        @RequestParam("businessType") Integer businessType,
-                       @RequestBody FileInfoParam param);
-
-    /**
-     * 修改文件绑定信息
-     *
-     * @param businessId   业务id
-     * @param businessType 业务类型
-     * @param paramList    文件信息
-     */
-    @PostMapping(AGAIN_BINDING_FILE_List)
-    R againBindingFileList(@RequestParam("applicationName") String applicationName,
-                           @RequestParam("businessId") Long businessId,
-                           @RequestParam("businessType") Integer businessType,
-                           @RequestBody List<FileInfoParam> paramList);
+                       @RequestBody List<FileInfoParam> paramList);
 
     /**
      * 删除文件绑定信息
@@ -94,19 +61,9 @@ public interface IFileClient {
     /**
      * 获取文件信息
      *
-     * @param businessId 业务id
+     * @param businessIdList 业务id集合
      */
     @PostMapping(GET_FILE_INFO)
-    R<FileInfoParam> getFileInfo(@RequestParam("businessId") Long businessId,
-                                 @RequestParam("businessType") Integer businessType);
-
-    /**
-     * 获取文件信息
-     *
-     * @param businessId 业务id
-     */
-    @PostMapping(GET_FILE_INFO_LIST)
-    R<List<FileInfoParam>> getFileInfoList(@RequestParam("businessId") Long businessId,
-                                           @RequestParam("businessType") Integer businessType);
+    R<List<FileInfoParam>> getFileInfo(@RequestBody List<Long> businessIdList);
 
 }

+ 5 - 26
hx-service/file-service/src/main/java/com/fjhx/feign/FileClient.java

@@ -17,28 +17,14 @@ public class FileClient implements IFileClient {
 
     @PostMapping(BINDING_FILE)
     @Override
-    public R bindingFile(String applicationName, Long businessId, Integer businessType, FileInfoParam param) {
-        fileInfoService.bindingFile(applicationName, businessId, businessType, param);
-        return R.success();
-    }
-
-    @PostMapping(BINDING_FILE_LIST)
-    @Override
-    public R bindingFileList(String applicationName, Long businessId, Integer businessType, List<FileInfoParam> paramList) {
+    public R bindingFile(String applicationName, Long businessId, Integer businessType, List<FileInfoParam> paramList) {
         fileInfoService.bindingFile(applicationName, businessId, businessType, paramList);
         return R.success();
     }
 
     @PostMapping(AGAIN_BINDING_FILE)
     @Override
-    public R againBindingFile(String applicationName, Long businessId, Integer businessType, FileInfoParam param) {
-        fileInfoService.againBindingFile(applicationName, businessId, businessType, param);
-        return R.success();
-    }
-
-    @PostMapping(AGAIN_BINDING_FILE_List)
-    @Override
-    public R againBindingFileList(String applicationName, Long businessId, Integer businessType, List<FileInfoParam> paramList) {
+    public R againBindingFile(String applicationName, Long businessId, Integer businessType, List<FileInfoParam> paramList) {
         fileInfoService.againBindingFile(applicationName, businessId, businessType, paramList);
         return R.success();
     }
@@ -52,16 +38,9 @@ public class FileClient implements IFileClient {
 
     @PostMapping(GET_FILE_INFO)
     @Override
-    public R<FileInfoParam> getFileInfo(Long businessId, Integer businessType) {
-        FileInfoParam fileInfoParam = fileInfoService.getFileInfo(businessId, businessType);
-        return R.success(fileInfoParam);
-    }
-
-    @PostMapping(GET_FILE_INFO_LIST)
-    @Override
-    public R<List<FileInfoParam>> getFileInfoList(Long businessId, Integer businessType) {
-        List<FileInfoParam> fileInfoParamList = fileInfoService.getFileInfoList(businessId, businessType);
-        return R.success(fileInfoParamList);
+    public R<List<FileInfoParam>> getFileInfo(List<Long> businessIdList) {
+        List<FileInfoParam> list = fileInfoService.getFileInfo(businessIdList);
+        return R.success(list);
     }
 
 }

+ 3 - 16
hx-service/file-service/src/main/java/com/fjhx/service/FileInfoService.java

@@ -26,21 +26,11 @@ public interface FileInfoService extends BaseService<FileInfo> {
     /**
      * 绑定文件
      */
-    void bindingFile(String applicationName, Long businessId, Integer businessType, FileInfoParam param);
-
-    /**
-     * 绑定文件
-     */
     void bindingFile(String applicationName, Long businessId, Integer businessType, List<FileInfoParam> paramList);
 
     /**
      * 重新绑定文件
      */
-    void againBindingFile(String applicationName, Long businessId, Integer businessType, FileInfoParam param);
-
-    /**
-     * 重新绑定文件
-     */
     void againBindingFile(String applicationName, Long businessId, Integer businessType, List<FileInfoParam> paramList);
 
     /**
@@ -50,12 +40,9 @@ public interface FileInfoService extends BaseService<FileInfo> {
 
     /**
      * 获取文件信息
+     *
+     * @param businessIdList 业务id list
      */
-    FileInfoParam getFileInfo(Long businessId, Integer businessType);
-
-    /**
-     * 获取文件信息
-     */
-    List<FileInfoParam> getFileInfoList(Long businessId, Integer businessType);
+    List<FileInfoParam> getFileInfo(List<Long> businessIdList);
 
 }

+ 19 - 54
hx-service/file-service/src/main/java/com/fjhx/service/impl/FileInfoServiceImpl.java

@@ -4,7 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.lang.UUID;
 import cn.hutool.core.util.ObjectUtil;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.base.BaseEntity;
@@ -16,6 +15,7 @@ import org.springblade.core.launch.BladeApplication;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.tool.utils.DateUtil;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.FileOutputStream;
@@ -91,24 +91,14 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
         return map;
     }
 
-    @Override
-    public void bindingFile(String applicationName, Long businessId, Integer businessType, FileInfoParam param) {
-
-        FileInfo fileInfo = BeanUtil.toBean(param, FileInfo.class);
-        fileInfo.setBusinessId(businessId);
-        fileInfo.setBusinessType(businessType);
-        fileInfo.setApplicationName(applicationName);
-
-        updateById(fileInfo);
-    }
-
     public void bindingFile(String applicationName, Long businessId, Integer businessType, List<FileInfoParam> paramList) {
         if (paramList.size() == 0) {
             return;
         }
 
         List<FileInfo> collect = paramList.stream().map(item -> {
-            FileInfo fileInfo = BeanUtil.toBean(item, FileInfo.class);
+            FileInfo fileInfo = new FileInfo();
+            fileInfo.setId(item.getId());
             fileInfo.setBusinessId(businessId);
             fileInfo.setBusinessType(businessType);
             fileInfo.setApplicationName(applicationName);
@@ -118,25 +108,14 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
         updateBatchById(collect);
     }
 
-    @Override
-    public void againBindingFile(String applicationName, Long businessId, Integer businessType, FileInfoParam param) {
-        if (ObjectUtil.isNotEmpty(param.getBusinessId())) {
-            return;
-        }
-        removeById(param.getId());
-
-        FileInfo fileInfo = BeanUtil.toBean(param, FileInfo.class);
-        fileInfo.setBusinessId(businessId);
-        fileInfo.setBusinessType(businessType);
-        fileInfo.setApplicationName(applicationName);
-        updateById(fileInfo);
-    }
-
+    @Transactional
     @Override
     public void againBindingFile(String applicationName, Long businessId, Integer businessType, List<FileInfoParam> paramList) {
 
+        // 记录排除编辑的文件id
         List<Long> excludeIdList = new ArrayList<>();
 
+        // 获取需要添加业务id的文件列表
         List<FileInfo> collect = paramList.stream().filter(fileInfo -> {
             if (ObjectUtil.isNotEmpty(fileInfo.getBusinessId())) {
                 excludeIdList.add(fileInfo.getId());
@@ -144,18 +123,24 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
             }
             return true;
         }).map(item -> {
-            FileInfo fileInfo = BeanUtil.toBean(item, FileInfo.class);
+            FileInfo fileInfo = new FileInfo();
+            fileInfo.setId(item.getId());
             fileInfo.setBusinessId(businessId);
             fileInfo.setBusinessType(businessType);
             fileInfo.setApplicationName(applicationName);
             return fileInfo;
         }).collect(Collectors.toList());
 
-        remove(Wrappers.<FileInfo>lambdaQuery()
-                .eq(FileInfo::getBusinessId, businessId)
-                .eq(FileInfo::getBusinessType, businessType)
-                .notIn(excludeIdList.size() > 0, BaseEntity::getId, collect));
+        // 如果排除的id数等于提交文件编辑数,则不执行删除逻辑
+        int excludeIdSize = excludeIdList.size();
+        if (paramList.size() != excludeIdSize) {
+            remove(Wrappers.<FileInfo>lambdaQuery()
+                    .eq(FileInfo::getBusinessId, businessId)
+                    .eq(FileInfo::getBusinessType, businessType)
+                    .notIn(excludeIdSize > 0, BaseEntity::getId, collect));
+        }
 
+        // 如果需要添加业务id的文件数为0,跳过提交
         if (collect.size() > 0) {
             updateBatchById(collect);
         }
@@ -168,28 +153,8 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
     }
 
     @Override
-    public FileInfoParam getFileInfo(Long businessId, Integer businessType) {
-
-        LambdaQueryWrapper<FileInfo> wrapper = Wrappers.<FileInfo>lambdaQuery()
-                .eq(FileInfo::getBusinessId, businessId)
-                .eq(ObjectUtil.isNotEmpty(businessType), FileInfo::getBusinessType, businessType)
-                .orderByDesc(BaseEntity::getId)
-                .last("limit 1");
-
-        FileInfo fileInfo = getOne(wrapper);
-
-        return BeanUtil.toBean(fileInfo, FileInfoParam.class);
-    }
-
-    @Override
-    public List<FileInfoParam> getFileInfoList(Long businessId, Integer businessType) {
-
-        LambdaQueryWrapper<FileInfo> wrapper = Wrappers.<FileInfo>lambdaQuery()
-                .eq(FileInfo::getBusinessId, businessId)
-                .eq(ObjectUtil.isNotEmpty(businessType), FileInfo::getBusinessType, businessType);
-
-        List<FileInfo> list = list(wrapper);
-
+    public List<FileInfoParam> getFileInfo(List<Long> businessIdList) {
+        List<FileInfo> list = lambdaQuery().in(FileInfo::getBusinessId, businessIdList).list();
         return list.stream().map(item -> BeanUtil.toBean(item, FileInfoParam.class)).collect(Collectors.toList());
     }
 

+ 1 - 1
hx-service/iot-management/src/main/java/com/fjhx/bom/controller/BomController.java

@@ -1,8 +1,8 @@
 package com.fjhx.bom.controller;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.fjhx.entity.bom.Bom;
 import com.fjhx.bom.service.BomService;
+import com.fjhx.entity.bom.Bom;
 import com.fjhx.params.bom.BomEx;
 import com.fjhx.params.bom.BomVo;
 import org.springblade.core.tool.api.R;

+ 1 - 3
hx-service/iot-management/src/main/java/com/fjhx/bom/service/impl/BomServiceImpl.java

@@ -9,7 +9,6 @@ import com.fjhx.constants.StatusConstant;
 import com.fjhx.entity.bom.Bom;
 import com.fjhx.enums.bom.BomTypeEnum;
 import com.fjhx.feign.IFileClient;
-import com.fjhx.params.FileInfoParam;
 import com.fjhx.params.bom.BomEx;
 import com.fjhx.params.bom.BomVo;
 import com.fjhx.utils.FileClientUtil;
@@ -66,8 +65,7 @@ public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomSe
         save(bomVo);
 
         // 绑定文件
-        FileInfoParam fileInfoParam = bomVo.getFileInfoParam();
-        FileClientUtil.bindingFile(bomVo.getId(), 1, fileInfoParam);
+        FileClientUtil.bindingFile(bomVo.getId(), 1, bomVo.getFileInfoParam());
 
     }