修正了错误。
This commit is contained in:
parent
cd544d64c8
commit
f80156459b
@ -2,6 +2,7 @@ package com.stdproject.controller;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.stdproject.common.OperationLog;
|
import com.stdproject.common.OperationLog;
|
||||||
|
import com.stdproject.config.ResponseResult;
|
||||||
import com.stdproject.service.IDynamicDataService;
|
import com.stdproject.service.IDynamicDataService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@ -32,53 +33,62 @@ public class DynamicDataController {
|
|||||||
@Operation(summary = "向指定数据源的表中添加数据")
|
@Operation(summary = "向指定数据源的表中添加数据")
|
||||||
@OperationLog(type = "01", module = "动态数据管理", description = "添加表数据")
|
@OperationLog(type = "01", module = "动态数据管理", description = "添加表数据")
|
||||||
@PostMapping("addTableData")
|
@PostMapping("addTableData")
|
||||||
public boolean addTableData(Long datasourceId, @RequestParam("tableData") String tableData) throws Exception {
|
public ResponseResult addTableData(Long datasourceId, @RequestParam("tableData") String tableData) throws Exception {
|
||||||
boolean result = dynamicDataService.addTableData(
|
boolean result = dynamicDataService.addTableData(
|
||||||
datasourceId,
|
datasourceId,
|
||||||
tableData
|
tableData
|
||||||
);
|
);
|
||||||
return result;
|
if (!result) {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
return ResponseResult.success();
|
||||||
}
|
}
|
||||||
@Operation(summary = "根据主键查询表数据")
|
@Operation(summary = "根据主键查询表数据")
|
||||||
@PostMapping("getTableDataByPk")
|
@PostMapping("getTableDataByPk")
|
||||||
public Map<String, Object> getTableDataByPk(Long datasourceId,@RequestParam("whereJson") String whereJson) throws Exception {
|
public ResponseResult getTableDataByPk(Long datasourceId,@RequestParam("whereJson") String whereJson) throws Exception {
|
||||||
Map<String, Object> result=dynamicDataService.getTableDataByPk(
|
Map<String, Object> result=dynamicDataService.getTableDataByPk(
|
||||||
datasourceId,
|
datasourceId,
|
||||||
whereJson
|
whereJson
|
||||||
);
|
);
|
||||||
return result;
|
return ResponseResult.successData( result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "更新表数据")
|
@Operation(summary = "更新表数据")
|
||||||
@OperationLog(type = "02", module = "动态数据管理", description = "更新表数据")
|
@OperationLog(type = "02", module = "动态数据管理", description = "更新表数据")
|
||||||
@PostMapping("updateTableData")
|
@PostMapping("updateTableData")
|
||||||
public boolean updateTableData(Long datasourceId, @RequestParam("tableData") String tableData) throws Exception {
|
public ResponseResult updateTableData(Long datasourceId, @RequestParam("tableData") String tableData) throws Exception {
|
||||||
boolean result = dynamicDataService.updateTableData(
|
boolean result = dynamicDataService.updateTableData(
|
||||||
datasourceId,
|
datasourceId,
|
||||||
tableData
|
tableData
|
||||||
);
|
);
|
||||||
return result;
|
if (!result) {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
return ResponseResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "删除表数据")
|
@Operation(summary = "删除表数据")
|
||||||
@OperationLog(type = "03", module = "动态数据管理", description = "删除表数据")
|
@OperationLog(type = "03", module = "动态数据管理", description = "删除表数据")
|
||||||
@PostMapping("deleteTableData")
|
@PostMapping("deleteTableData")
|
||||||
public boolean deleteTableData(Long datasourceId, @RequestParam("whereJson") String whereJson) throws Exception {
|
public ResponseResult deleteTableData(Long datasourceId, @RequestParam("whereJson") String whereJson) throws Exception {
|
||||||
boolean result = dynamicDataService.deleteTableData(
|
boolean result = dynamicDataService.deleteTableData(
|
||||||
datasourceId,
|
datasourceId,
|
||||||
whereJson
|
whereJson
|
||||||
);
|
);
|
||||||
return result;
|
if (!result) {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
return ResponseResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "分页查询表数据")
|
@Operation(summary = "分页查询表数据")
|
||||||
@PostMapping("queryTableDataPaged")
|
@PostMapping("queryTableDataPaged")
|
||||||
public Page<Map<String, Object>> queryTableDataPaged(Long datasourceId, @RequestParam("queryJson") String queryJson) throws Exception {
|
public ResponseResult queryTableDataPaged(Long datasourceId, @RequestParam("queryJson") String queryJson) throws Exception {
|
||||||
Page<Map<String, Object>> result = dynamicDataService.queryTableDataPaged(
|
Page<Map<String, Object>> result = dynamicDataService.queryTableDataPaged(
|
||||||
datasourceId,
|
datasourceId,
|
||||||
queryJson
|
queryJson
|
||||||
);
|
);
|
||||||
return result;
|
return ResponseResult.successData( result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -10,6 +10,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@ -18,9 +19,9 @@ public class LoginUser implements UserDetails {
|
|||||||
|
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
private List<Menu> permissions;
|
private List<Map> permissions;
|
||||||
|
|
||||||
public LoginUser(User user, List<Menu> permissions) {
|
public LoginUser(User user, List<Map> permissions) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.permissions = permissions;
|
this.permissions = permissions;
|
||||||
}
|
}
|
||||||
@ -28,7 +29,7 @@ public class LoginUser implements UserDetails {
|
|||||||
@JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
private List<SimpleGrantedAuthority> authorities;
|
private List<SimpleGrantedAuthority> authorities;
|
||||||
|
|
||||||
public List<Menu> getPermissions() {
|
public List<Map> getPermissions() {
|
||||||
return permissions;
|
return permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface MenuMapper extends BaseMapper<Menu> {
|
public interface MenuMapper extends BaseMapper<Menu> {
|
||||||
@ -15,4 +16,7 @@ public interface MenuMapper extends BaseMapper<Menu> {
|
|||||||
|
|
||||||
@Select("select m.id FROM app_role_menu rm INNER JOIN app_menu m on rm.menuid = m.id where m.isdisplay = 1 AND rm.app_id = #{appid} AND rm.roleid = #{roleid} ORDER BY m.orderno ASC")
|
@Select("select m.id FROM app_role_menu rm INNER JOIN app_menu m on rm.menuid = m.id where m.isdisplay = 1 AND rm.app_id = #{appid} AND rm.roleid = #{roleid} ORDER BY m.orderno ASC")
|
||||||
List<String> selectMenuByRoleId( @Param("appid")String appId, @Param("roleid") String roleId);
|
List<String> selectMenuByRoleId( @Param("appid")String appId, @Param("roleid") String roleId);
|
||||||
|
|
||||||
|
@Select("<script>select me.id,me.type,me.code,me.name,me.parentid,me.module_id,mo.type module_type FROM app_menu me LEFT JOIN app_module mo on me.module_id = mo.id where me.id in <foreach collection='menuIds' item='id' open='(' separator=',' close=')'>#{id}</foreach> and me.isdisplay='1' order by me.code</script>")
|
||||||
|
List<Map> listMenuByIds(@Param("menuIds") List<String> menuIds);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class CustomUserDetailsService implements UserDetailsService {
|
|||||||
if (appUser == null) {
|
if (appUser == null) {
|
||||||
throw new UsernameNotFoundException("用户不存在: " + username);
|
throw new UsernameNotFoundException("用户不存在: " + username);
|
||||||
}
|
}
|
||||||
List<Menu> permissions = buildUserAuthorities(appUser);
|
List<Map> permissions = buildUserAuthorities(appUser);
|
||||||
LoginUser loginUser = new LoginUser(appUser,permissions);
|
LoginUser loginUser = new LoginUser(appUser,permissions);
|
||||||
return loginUser;
|
return loginUser;
|
||||||
|
|
||||||
@ -60,8 +60,8 @@ public class CustomUserDetailsService implements UserDetailsService {
|
|||||||
* @param appUser 用户信息
|
* @param appUser 用户信息
|
||||||
* @return 权限集合
|
* @return 权限集合
|
||||||
*/
|
*/
|
||||||
private List<Menu> buildUserAuthorities(User appUser) {
|
private List<Map> buildUserAuthorities(User appUser) {
|
||||||
List<Menu> permissions = new ArrayList<>();
|
List<Map> permissions = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 使用RoleMapper直接查询用户的角色信息
|
// 使用RoleMapper直接查询用户的角色信息
|
||||||
@ -80,13 +80,8 @@ public class CustomUserDetailsService implements UserDetailsService {
|
|||||||
|
|
||||||
if (!menuIds.isEmpty()) {
|
if (!menuIds.isEmpty()) {
|
||||||
// 查询菜单信息并添加菜单权限
|
// 查询菜单信息并添加菜单权限
|
||||||
List<Menu> menus = appMenuService.listByIds(menuIds);
|
List<Map> menus = menuMapper.listMenuByIds(menuIds);
|
||||||
for (Menu menu : menus) {
|
permissions.addAll(menus);
|
||||||
if ("1".equals(menu.getIsdisplay()) && StringUtils.hasText(menu.getCode())) {
|
|
||||||
// 添加菜单权限,格式:菜单编码
|
|
||||||
permissions.add(menu);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user