feat(dify): 新增应用列表接口并优化角色和菜单相关逻辑
- 在 PPTController、Spider2Controller 和 WordController 中添加了获取应用列表的接口 -优化了 RoleServiceImpl 中的角色菜单更新逻辑 - 新增 RoleMenuRepository 中的按角色 ID 删除菜单关联的方法 - 优化了 UserServiceImpl 中的用户角色更新逻辑 - 调整了 SpringSecurityConfig 中的最大会话数限制
This commit is contained in:
parent
087591fc20
commit
f0066d4c64
@ -18,6 +18,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
|
||||
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
|
||||
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
|
||||
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
|
||||
import org.springframework.security.web.session.HttpSessionEventPublisher;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@ -141,10 +142,9 @@ public class SpringSecurityConfig {
|
||||
.tokenRepository(persistentTokenRepository()))
|
||||
.csrf(csrf -> csrf.ignoringRequestMatchers("v1/**","/api/internal/**", "/api/rest/user/logout","/api/rest/user/register"))
|
||||
.sessionManagement(session -> session
|
||||
.maximumSessions(3)
|
||||
.maximumSessions(1)
|
||||
.sessionRegistry(sessionRegistry)
|
||||
.expiredSessionStrategy(customSessionInformationExpiredStrategy))
|
||||
.build();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
package com.zsc.edu.dify.modules.dify.controller;
|
||||
|
||||
import com.zsc.edu.dify.exception.ExceptionUtil;
|
||||
import com.zsc.edu.dify.framework.mybatisplus.DataPermission;
|
||||
import com.zsc.edu.dify.framework.security.SecurityUtil;
|
||||
import com.zsc.edu.dify.modules.dify.entity.AppEntity;
|
||||
import com.zsc.edu.dify.modules.dify.service.AppEntityService;
|
||||
import com.zsc.edu.dify.modules.dify.service.DifyWorkflowService;
|
||||
import com.zsc.edu.dify.modules.operationLog.entity.OperationLogAnnotation;
|
||||
import io.github.guoshiqiufeng.dify.workflow.dto.request.WorkflowRunRequest;
|
||||
@ -10,6 +13,8 @@ import jakarta.annotation.Resource;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/ppt")
|
||||
public class PPTController {
|
||||
@ -17,6 +22,9 @@ public class PPTController {
|
||||
@Resource
|
||||
private DifyWorkflowService difyWorkflowService;
|
||||
|
||||
@Resource
|
||||
private AppEntityService appEntityService;
|
||||
|
||||
/**
|
||||
* 运行从可研申报书生成科技项目PPT_工作流
|
||||
*
|
||||
@ -29,4 +37,15 @@ public class PPTController {
|
||||
request.setUserId(SecurityUtil.getUserInfo().id.toString());
|
||||
return ExceptionUtil.difyException(() -> difyWorkflowService.run(request, "ee3889b6-50fa-463e-b956-3b93447727fc"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据appType获取应用列表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/apps")
|
||||
@DataPermission
|
||||
public List<AppEntity> getAppsByAppType(){
|
||||
return appEntityService.selectByAppType(AppEntity.AppType.PPT.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
package com.zsc.edu.dify.modules.dify.controller;
|
||||
|
||||
import com.zsc.edu.dify.exception.ExceptionUtil;
|
||||
import com.zsc.edu.dify.framework.mybatisplus.DataPermission;
|
||||
import com.zsc.edu.dify.framework.security.SecurityUtil;
|
||||
import com.zsc.edu.dify.modules.dify.entity.AppEntity;
|
||||
import com.zsc.edu.dify.modules.dify.service.AppEntityService;
|
||||
import com.zsc.edu.dify.modules.dify.service.DifyWorkflowService;
|
||||
import com.zsc.edu.dify.modules.operationLog.entity.OperationLogAnnotation;
|
||||
import io.github.guoshiqiufeng.dify.workflow.dto.request.WorkflowRunRequest;
|
||||
import io.github.guoshiqiufeng.dify.workflow.dto.response.WorkflowRunResponse;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/spider2")
|
||||
@ -19,6 +21,9 @@ public class Spider2Controller {
|
||||
@Resource
|
||||
private DifyWorkflowService difyWorkflowService;
|
||||
|
||||
@Resource
|
||||
private AppEntityService appEntityService;
|
||||
|
||||
/**
|
||||
* 运行广州公共资源交易中心 招标小助手
|
||||
*
|
||||
@ -31,4 +36,14 @@ public class Spider2Controller {
|
||||
request.setUserId(SecurityUtil.getUserInfo().id.toString());
|
||||
return ExceptionUtil.difyException(() -> difyWorkflowService.run(request, "c736edd0-925d-4877-9223-56aab7342311"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据appType获取应用列表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/apps")
|
||||
@DataPermission
|
||||
public List<AppEntity> getAppsByAppType(){
|
||||
return appEntityService.selectByAppType(AppEntity.AppType.SCRAPER.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.zsc.edu.dify.modules.dify.controller;
|
||||
|
||||
import com.zsc.edu.dify.exception.ExceptionUtil;
|
||||
import com.zsc.edu.dify.framework.mybatisplus.DataPermission;
|
||||
import com.zsc.edu.dify.framework.security.SecurityUtil;
|
||||
import com.zsc.edu.dify.modules.dify.entity.AppEntity;
|
||||
import com.zsc.edu.dify.modules.dify.service.AppEntityService;
|
||||
import com.zsc.edu.dify.modules.operationLog.entity.OperationLogAnnotation;
|
||||
import io.github.guoshiqiufeng.dify.chat.DifyChat;
|
||||
@ -11,6 +13,8 @@ import jakarta.annotation.Resource;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/word")
|
||||
public class WordController {
|
||||
@ -34,4 +38,14 @@ public class WordController {
|
||||
sendRequest.setUserId(SecurityUtil.getUserInfo().id.toString());
|
||||
return ExceptionUtil.difyException(()->difyChat.send(sendRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据appType获取应用列表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/apps")
|
||||
@DataPermission
|
||||
public List<AppEntity> getAppsByAppType(){
|
||||
return appEntityService.selectByAppType(AppEntity.AppType.WORD.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -103,3 +103,11 @@ public class AppEntityServiceImpl extends ServiceImpl<AppEntityRepository, AppEn
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class UserController {
|
||||
* @param dto 表单数据
|
||||
* @return 更新后的用户信息
|
||||
*/
|
||||
@OperationLogAnnotation(content = "信息", operationType = "更新")
|
||||
@OperationLogAnnotation(content = "'信息'", operationType = "更新")
|
||||
@PatchMapping("self")
|
||||
public Boolean selfUpdate(
|
||||
@AuthenticationPrincipal UserDetailsImpl userDetails,
|
||||
|
@ -11,6 +11,7 @@ import java.io.Serializable;
|
||||
*/
|
||||
@Data
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_users_roles")
|
||||
public class UserRole implements Serializable {
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package com.zsc.edu.dify.modules.system.repo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zsc.edu.dify.modules.system.entity.RoleMenu;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@ -14,4 +15,7 @@ public interface RoleMenuRepository extends BaseMapper<RoleMenu> {
|
||||
|
||||
@Select("select * from sys_role_menu where role_id = #{id}")
|
||||
List<RoleMenu> findByRoleId(@Param("id") Long id);
|
||||
|
||||
@Delete("delete from sys_role_menu where role_id = #{id}")
|
||||
int deleteByRoleId(@Param("id") Long id);
|
||||
}
|
||||
|
@ -92,21 +92,14 @@ public class RoleServiceImpl extends ServiceImpl<RoleRepository, Role> implement
|
||||
selectyRole.setRemark(dto.getRemark());
|
||||
updateById(selectyRole);
|
||||
if (dto.getMenuIds() != null && !dto.getMenuIds().isEmpty()) {
|
||||
// 查询当前角色已有的菜单权限
|
||||
List<RoleMenu> existingRoleMenus = roleMenuRepository.findByRoleId(id);
|
||||
Set<Long> existingMenuIds = existingRoleMenus.stream()
|
||||
.map(RoleMenu::getMenuId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 筛选出不存在的菜单ID组合进行插入
|
||||
// 删除已有的菜单
|
||||
roleMenuRepository.deleteByRoleId(id);
|
||||
List<RoleMenu> roleMenusToInsert = dto.getMenuIds().stream()
|
||||
.filter(menuId -> !existingMenuIds.contains(menuId))
|
||||
.map(menuId -> new RoleMenu(id, menuId))
|
||||
.collect(Collectors.toList());
|
||||
// 插入新的关联菜单
|
||||
roleMenuRepository.insert(roleMenusToInsert);
|
||||
|
||||
if (!roleMenusToInsert.isEmpty()) {
|
||||
roleMenuRepository.insert(roleMenusToInsert);
|
||||
}
|
||||
}
|
||||
return selectyRole;
|
||||
}
|
||||
|
@ -148,7 +148,8 @@ public class UserServiceImpl extends ServiceImpl<UserRepository, User> implement
|
||||
throw new ConstraintException("角色不存在");
|
||||
}
|
||||
UserDetailsImpl userDetails = SecurityUtil.getUserInfo();
|
||||
boolean updated = lambdaUpdate().eq(User::getId, userDetails.getId())
|
||||
boolean updated = lambdaUpdate()
|
||||
.eq(User::getId, userDetails.getId())
|
||||
.set(User::getRoleId, roleId)
|
||||
.update();
|
||||
userDetails.setRole(role);
|
||||
@ -164,12 +165,7 @@ public class UserServiceImpl extends ServiceImpl<UserRepository, User> implement
|
||||
|
||||
public Boolean addUserRole(List<Long> roleIds, Long userId) {
|
||||
List<UserRole> userRoles = roleIds.stream()
|
||||
.map(roleId -> {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setUserId(userId);
|
||||
userRole.setRoleId(roleId);
|
||||
return userRole;
|
||||
})
|
||||
.map(roleId -> new UserRole(userId, roleId))
|
||||
.collect(Collectors.toList());
|
||||
userRolesRepository.insert(userRoles);
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user