初始代码
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yunzhupaas-permission</artifactId>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yunzhupaas-permission-controller</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-permission-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-system-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-exception</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,269 @@
|
||||
package com.yunzhupaas.permission.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.service.DictionaryTypeService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.constant.PermissionConst;
|
||||
import com.yunzhupaas.permission.entity.GroupEntity;
|
||||
import com.yunzhupaas.permission.entity.UserRelationEntity;
|
||||
import com.yunzhupaas.permission.model.user.mod.UserIdModel;
|
||||
import com.yunzhupaas.permission.model.usergroup.*;
|
||||
import com.yunzhupaas.permission.service.GroupService;
|
||||
import com.yunzhupaas.permission.service.UserRelationService;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.enums.DictionaryDataEnum;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.treeutil.newtreeutil.TreeDotUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分组管理控制器
|
||||
*
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2022/3/10 17:57
|
||||
*/
|
||||
@RestController
|
||||
@Tag(name = "分组管理", description = "UserGroupController")
|
||||
@RequestMapping("/api/permission/Group")
|
||||
public class GroupController extends SuperController<GroupService, GroupEntity> {
|
||||
|
||||
@Autowired
|
||||
private GroupService userGroupService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataApi;
|
||||
@Autowired
|
||||
private DictionaryTypeService dictionaryTypeApi;
|
||||
@Autowired
|
||||
private UserRelationService userRelationService;
|
||||
|
||||
/**
|
||||
* 获取分组管理列表
|
||||
*
|
||||
* @param pagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取分组管理列表")
|
||||
@SaCheckPermission(value = {"permission.group"})
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<GroupPaginationVO>> list(PaginationGroup pagination) {
|
||||
List<GroupEntity> list = userGroupService.getList(pagination);
|
||||
List<GroupPaginationVO> jsonToList = JsonUtil.getJsonToList(list, GroupPaginationVO.class);
|
||||
// 通过数据字典获取类型
|
||||
List<DictionaryDataEntity> dictionaryDataEntities = dictionaryDataApi.getList(dictionaryTypeApi.getInfoByEnCode(DictionaryDataEnum.PERMISSION_GROUP.getDictionaryTypeId()).getId());
|
||||
for (GroupPaginationVO userGroupPaginationVO : jsonToList) {
|
||||
DictionaryDataEntity dictionaryDataEntity = dictionaryDataEntities.stream().filter(t -> t.getId().equals(userGroupPaginationVO.getType())).findFirst().orElse(null);
|
||||
userGroupPaginationVO.setType(dictionaryDataEntity != null ? dictionaryDataEntity.getFullName() : userGroupPaginationVO.getId());
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(jsonToList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分组管理下拉框
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取分组管理下拉框")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<List<GroupSelectorVO>> selector() {
|
||||
List<GroupTreeModel> tree = new ArrayList<>();
|
||||
List<GroupEntity> data = userGroupService.list();
|
||||
List<DictionaryDataEntity> dataEntityList = dictionaryDataApi.getList(dictionaryTypeApi.getInfoByEnCode(DictionaryDataEnum.PERMISSION_GROUP.getDictionaryTypeId()).getId());
|
||||
// 获取分组管理外层菜单
|
||||
for (DictionaryDataEntity dictionaryDataEntity : dataEntityList) {
|
||||
GroupTreeModel firstModel = JsonUtil.getJsonToBean(dictionaryDataEntity, GroupTreeModel.class);
|
||||
firstModel.setId(dictionaryDataEntity.getId());
|
||||
firstModel.setType("0");
|
||||
long num = data.stream().filter(t -> t.getType().equals(dictionaryDataEntity.getId())).count();
|
||||
firstModel.setNum(num);
|
||||
if (num > 0) {
|
||||
tree.add(firstModel);
|
||||
}
|
||||
}
|
||||
for (GroupEntity entity : data) {
|
||||
GroupTreeModel treeModel = JsonUtil.getJsonToBean(entity, GroupTreeModel.class);
|
||||
treeModel.setType("group");
|
||||
treeModel.setParentId(entity.getType());
|
||||
treeModel.setIcon("icon-ym icon-ym-generator-group1");
|
||||
treeModel.setId(entity.getId());
|
||||
DictionaryDataEntity dataEntity = dictionaryDataApi.getInfo(entity.getType());
|
||||
if (dataEntity != null) {
|
||||
tree.add(treeModel);
|
||||
}
|
||||
}
|
||||
List<SumTree<GroupTreeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(tree);
|
||||
List<GroupSelectorVO> list = JsonUtil.getJsonToList(sumTrees, GroupSelectorVO.class);
|
||||
ListVO<GroupSelectorVO> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义范围获取分组下拉框
|
||||
*
|
||||
* @param idModel 岗位选择模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "自定义范围获取分组下拉框")
|
||||
@Parameters({
|
||||
@Parameter(name = "positionConditionModel", description = "岗位选择模型", required = true)
|
||||
})
|
||||
@PostMapping("/GroupCondition")
|
||||
public ActionResult<ListVO<GroupSelectorVO>> positionCondition(@RequestBody UserIdModel idModel) {
|
||||
List<GroupEntity> data = userGroupService.getListByIds(idModel.getIds(), true);
|
||||
List<GroupTreeModel> tree = new ArrayList<>();
|
||||
List<DictionaryDataEntity> dataEntityList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.PERMISSION_GROUP.getDictionaryTypeId());
|
||||
// 获取分组管理外层菜单
|
||||
for (DictionaryDataEntity dictionaryDataEntity : dataEntityList) {
|
||||
GroupTreeModel firstModel = JsonUtil.getJsonToBean(dictionaryDataEntity, GroupTreeModel.class);
|
||||
firstModel.setId(dictionaryDataEntity.getId());
|
||||
firstModel.setType("0");
|
||||
long num = data.stream().filter(t -> t.getType().equals(dictionaryDataEntity.getId())).count();
|
||||
firstModel.setNum(num);
|
||||
if (num > 0) {
|
||||
tree.add(firstModel);
|
||||
}
|
||||
}
|
||||
for (GroupEntity entity : data) {
|
||||
GroupTreeModel treeModel = JsonUtil.getJsonToBean(entity, GroupTreeModel.class);
|
||||
treeModel.setType("group");
|
||||
treeModel.setParentId(entity.getType());
|
||||
treeModel.setIcon("icon-ym icon-ym-generator-group1");
|
||||
treeModel.setId(entity.getId());
|
||||
DictionaryDataEntity dataEntity = dictionaryDataApi.getInfo(entity.getType());
|
||||
if (dataEntity != null) {
|
||||
tree.add(treeModel);
|
||||
}
|
||||
}
|
||||
List<SumTree<GroupTreeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(tree);
|
||||
List<GroupSelectorVO> list = JsonUtil.getJsonToList(sumTrees, GroupSelectorVO.class);
|
||||
ListVO<GroupSelectorVO> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission(value = {"permission.group"})
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<GroupInfoVO> info(@PathVariable("id") String id) {
|
||||
GroupEntity entity = userGroupService.getInfo(id);
|
||||
GroupInfoVO vo = JsonUtil.getJsonToBean(entity, GroupInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param userGroupCrForm 新建模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "创建")
|
||||
@Parameters({
|
||||
@Parameter(name = "userGroupCrForm", description = "新建模型", required = true)
|
||||
})
|
||||
@SaCheckPermission(value = {"permission.group"})
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid GroupCrForm userGroupCrForm) {
|
||||
GroupEntity entity = JsonUtil.getJsonToBean(userGroupCrForm, GroupEntity.class);
|
||||
// 判断名称是否重复
|
||||
if (userGroupService.isExistByFullName(entity.getFullName(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
// 判断编码是否重复
|
||||
if (userGroupService.isExistByEnCode(entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
userGroupService.crete(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param id 主键
|
||||
* @param userGroupUpForm 修改模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "userGroupUpForm", description = "修改模型", required = true)
|
||||
})
|
||||
@SaCheckPermission(value = {"permission.group"})
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid GroupUpForm userGroupUpForm) {
|
||||
GroupEntity groupEntity = userGroupService.getInfo(id);
|
||||
if (groupEntity == null) {
|
||||
return ActionResult.fail(MsgCode.FA013.get());
|
||||
}
|
||||
if ((groupEntity.getEnabledMark() == 1 && userGroupUpForm.getEnabledMark() == 0)
|
||||
&& userRelationService.getListByObjectId(id, PermissionConst.GROUP).size() > 0) {
|
||||
return ActionResult.fail(MsgCode.FA030.get());
|
||||
}
|
||||
GroupEntity entity = JsonUtil.getJsonToBean(userGroupUpForm, GroupEntity.class);
|
||||
// 判断名称是否重复
|
||||
if (userGroupService.isExistByFullName(entity.getFullName(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
// 判断编码是否重复
|
||||
if (userGroupService.isExistByEnCode(entity.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
userGroupService.update(id, entity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission(value = {"permission.group"})
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
GroupEntity entity = userGroupService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
List<UserRelationEntity> bingUserByRoleList = userRelationService.getListByObjectId(id, PermissionConst.GROUP);
|
||||
if (bingUserByRoleList.size() > 0) {
|
||||
return ActionResult.fail(MsgCode.FA024.get());
|
||||
}
|
||||
userGroupService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,719 @@
|
||||
package com.yunzhupaas.permission.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.yunzhupaas.base.entity.*;
|
||||
import com.yunzhupaas.base.model.portalManage.PortalModel;
|
||||
import com.yunzhupaas.base.model.print.PaginationPrint;
|
||||
import com.yunzhupaas.base.model.print.PrintDevTreeModel;
|
||||
import com.yunzhupaas.base.model.vo.PrintDevVO;
|
||||
import com.yunzhupaas.base.service.*;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.constant.PermissionConst;
|
||||
import com.yunzhupaas.flowable.entity.TemplateEntity;
|
||||
import com.yunzhupaas.flowable.model.template.TemplateTreeListVo;
|
||||
import com.yunzhupaas.model.FlowWorkModel;
|
||||
import com.yunzhupaas.permission.constant.AuthorizeConst;
|
||||
import com.yunzhupaas.permission.entity.*;
|
||||
import com.yunzhupaas.permission.model.permissiongroup.*;
|
||||
import com.yunzhupaas.permission.model.user.UserIdListVo;
|
||||
import com.yunzhupaas.permission.model.user.mod.UserIdModel;
|
||||
import com.yunzhupaas.permission.service.*;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.treeutil.newtreeutil.TreeDotUtils;
|
||||
import com.yunzhupaas.workflow.service.TemplateApi;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@Tag(name = "权限组控制器", description = "PermissionGroup")
|
||||
@RequestMapping("/api/permission/PermissionGroup")
|
||||
public class PermissionGroupController extends SuperController<PermissionGroupService, PermissionGroupEntity> {
|
||||
|
||||
@Autowired
|
||||
private PermissionGroupService permissionGroupService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private AuthorizeService authorizeService;
|
||||
@Autowired
|
||||
private ModuleButtonService buttonApi;
|
||||
@Autowired
|
||||
private ModuleColumnService columnApi;
|
||||
@Autowired
|
||||
private ModuleFormService formApi;
|
||||
@Autowired
|
||||
private ModuleDataAuthorizeSchemeService schemeApi;
|
||||
@Autowired
|
||||
private SystemService systemApi;
|
||||
@Autowired
|
||||
private ModuleService moduleApi;
|
||||
@Autowired
|
||||
private OrganizeService organizeService;
|
||||
@Autowired
|
||||
private PositionService positionService;
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
@Autowired
|
||||
private TemplateApi templateApi;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataApi;
|
||||
@Autowired
|
||||
private PrintDevService printDevApi;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param pagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "列表")
|
||||
@SaCheckPermission("permission.authorize")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<PermissionGroupListVO>> list(PaginationPermissionGroup pagination) {
|
||||
List<PermissionGroupEntity> data = permissionGroupService.list(pagination);
|
||||
List<PermissionGroupListVO> list = JsonUtil.getJsonToList(data, PermissionGroupListVO.class);
|
||||
list.forEach(t -> {
|
||||
String permissionMember = t.getPermissionMember();
|
||||
if (StringUtil.isEmpty(permissionMember)) {
|
||||
t.setPermissionMember("");
|
||||
return;
|
||||
}
|
||||
List<String> fullNameByIds = userService.getFullNameByIds(Arrays.asList(permissionMember.split(",")));
|
||||
StringJoiner stringJoiner = new StringJoiner(",");
|
||||
fullNameByIds.forEach(stringJoiner::add);
|
||||
t.setPermissionMember(stringJoiner.toString());
|
||||
});
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(list, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下拉选择
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "下拉框")
|
||||
@SaCheckPermission("permission.authorize")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<ListVO<FlowWorkModel>> list() {
|
||||
List<PermissionGroupEntity> data = permissionGroupService.list(true, null);
|
||||
List<FlowWorkModel> list = JsonUtil.getJsonToList(data, FlowWorkModel.class);
|
||||
list.forEach(t -> t.setIcon("icon-ym icon-ym-authGroup"));
|
||||
ListVO<FlowWorkModel> listVO = new ListVO<>();
|
||||
listVO.setList(list);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看权限成员
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "权限成员")
|
||||
@SaCheckPermission("permission.authorize")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@GetMapping("/PermissionMember/{id}")
|
||||
public ActionResult<ListVO<UserIdListVo>> permissionMember(@PathVariable("id") String id) {
|
||||
PermissionGroupEntity entity = permissionGroupService.permissionMember(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
ListVO<UserIdListVo> listVO = new ListVO<>();
|
||||
List<UserIdListVo> list = new ArrayList<>();
|
||||
if (StringUtil.isEmpty(entity.getPermissionMember())) {
|
||||
listVO.setList(list);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
List<String> ids = Arrays.asList(entity.getPermissionMember().split(",")).stream().distinct().collect(Collectors.toList());
|
||||
list = userService.selectedByIds(ids);
|
||||
listVO.setList(list);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存权限成员
|
||||
*
|
||||
* @param id 主键
|
||||
* @param userIdModel 用户id模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "保存权限成员")
|
||||
@SaCheckPermission("permission.authorize")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "userIdModel", description = "用户id模型", required = true)
|
||||
})
|
||||
@PostMapping("/PermissionMember/{id}")
|
||||
public ActionResult<ListVO<UserIdListVo>> savePermissionMember(@PathVariable("id") String id, @RequestBody UserIdModel userIdModel) {
|
||||
PermissionGroupEntity entity = permissionGroupService.info(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
//删除退出的用户
|
||||
List<String> oldPermission = StringUtil.isNotEmpty(entity.getPermissionMember()) ? Arrays.asList(entity.getPermissionMember().split(",")) : new ArrayList<>();
|
||||
// List<String> permission = userIdModel.getIds();
|
||||
// List<String> allUpdateIds = oldPermission.stream().filter(t->!permission.contains(t)).collect(Collectors.toList());
|
||||
List<String> deleteUser = userService.getUserIdList(oldPermission, null);
|
||||
//保存新的用户
|
||||
StringJoiner stringJoiner = new StringJoiner(",");
|
||||
List<String> userId = userIdModel.getIds();
|
||||
userId.forEach(t -> {
|
||||
stringJoiner.add(t);
|
||||
});
|
||||
entity.setPermissionMember(stringJoiner.toString());
|
||||
// 修改前的用户
|
||||
List<String> member = permissionGroupService.list(Collections.singletonList(id))
|
||||
.stream().filter(t -> StringUtil.isNotEmpty(t.getPermissionMember())).map(PermissionGroupEntity::getPermissionMember).collect(Collectors.toList());
|
||||
// 新的用户
|
||||
member.addAll(userId);
|
||||
member = member.stream().distinct().collect(Collectors.toList());
|
||||
List<String> userIdList = userService.getUserIdList(member, null);
|
||||
permissionGroupService.update(id, entity);
|
||||
userService.delCurRoleUser(MsgCode.PS010.get(), Collections.singletonList(id));
|
||||
//移除权限缓存
|
||||
authorizeService.removeAuthByUserOrMenu(deleteUser, null);
|
||||
return ActionResult.success(MsgCode.SU002.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "详情")
|
||||
@SaCheckPermission("permission.authorize")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<PermissionGroupModel> info(@PathVariable("id") String id) {
|
||||
PermissionGroupEntity entity = permissionGroupService.info(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
PermissionGroupModel model = JsonUtil.getJsonToBean(entity, PermissionGroupModel.class);
|
||||
return ActionResult.success(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @param model 模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新建")
|
||||
@SaCheckPermission("permission.authorize")
|
||||
@Parameter(name = "id", description = "模型", required = true)
|
||||
@PostMapping
|
||||
public ActionResult<String> crete(@RequestBody PermissionGroupModel model) {
|
||||
PermissionGroupEntity entity = JsonUtil.getJsonToBean(model, PermissionGroupEntity.class);
|
||||
if (permissionGroupService.isExistByFullName(entity.getId(), entity)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (permissionGroupService.isExistByEnCode(entity.getId(), entity)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
permissionGroupService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param id 主键
|
||||
* @param model 模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改")
|
||||
@SaCheckPermission("permission.authorize")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "model", description = "模型", required = true)
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult<String> update(@PathVariable("id") String id, @RequestBody PermissionGroupModel model) {
|
||||
PermissionGroupEntity entity = JsonUtil.getJsonToBean(model, PermissionGroupEntity.class);
|
||||
if (permissionGroupService.isExistByFullName(id, entity)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (permissionGroupService.isExistByEnCode(id, entity)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
userService.delCurRoleUser(MsgCode.PS010.get(), Collections.singletonList(id));
|
||||
permissionGroupService.update(id, entity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@SaCheckPermission("permission.authorize")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult<String> delete(@PathVariable("id") String id) {
|
||||
PermissionGroupEntity entity = permissionGroupService.info(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
userService.delCurRoleUser(MsgCode.PS010.get(), ImmutableList.of(id));
|
||||
permissionGroupService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "复制")
|
||||
@SaCheckPermission("permission.authorize")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@PostMapping("/{id}/Actions/Copy")
|
||||
@Transactional
|
||||
public ActionResult<String> copy(@PathVariable("id") String id) {
|
||||
PermissionGroupEntity entity = permissionGroupService.info(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA004.get());
|
||||
}
|
||||
String copyNum = UUID.randomUUID().toString().substring(0, 5);
|
||||
entity.setFullName(entity.getFullName() + ".副本" + copyNum);
|
||||
if (entity.getFullName().length() > 50) return ActionResult.fail(MsgCode.COPY001.get());
|
||||
entity.setEnCode(entity.getEnCode() + copyNum);
|
||||
entity.setId(RandomUtil.uuId());
|
||||
entity.setEnabledMark(0);
|
||||
entity.setCreatorTime(new Date());
|
||||
entity.setCreatorUserId(UserProvider.getLoginUserId());
|
||||
entity.setLastModifyTime(null);
|
||||
entity.setLastModifyUserId(null);
|
||||
permissionGroupService.save(entity);
|
||||
// 赋值权限表
|
||||
List<AuthorizeEntity> listByObjectId = authorizeService.getListByObjectId(Collections.singletonList(id));
|
||||
listByObjectId.forEach(t -> {
|
||||
t.setId(RandomUtil.uuId());
|
||||
t.setObjectId(entity.getId());
|
||||
});
|
||||
authorizeService.saveBatch(listByObjectId);
|
||||
return ActionResult.success(MsgCode.SU007.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取菜单权限返回权限组
|
||||
*
|
||||
* @param model 模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取菜单权限返回权限组")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@GetMapping("/getPermissionGroup")
|
||||
public ActionResult<Map<String, Object>> getPermissionGroup(ViewPermissionsModel model) {
|
||||
String objectType = model.getObjectType();
|
||||
String id = model.getId();
|
||||
if (checkDataById(id, objectType)) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
int type = 0; // 0未开启权限,1有
|
||||
List<FlowWorkModel> list = new ArrayList<>();
|
||||
List<PermissionGroupEntity> permissionGroupByUserId = permissionGroupService.getPermissionGroupByObjectId(id, objectType);
|
||||
// List<String> roleId = permissionGroupByUserId.stream().map(PermissionGroupEntity::getId).collect(Collectors.toList());
|
||||
// List<AuthorizeEntity> authorizeByItem = authorizeService.getListByObjectId(roleId);
|
||||
list = JsonUtil.getJsonToList(permissionGroupByUserId, FlowWorkModel.class);
|
||||
list.forEach(t -> t.setIcon("icon-ym icon-ym-authGroup"));
|
||||
if (list.size() > 0) {
|
||||
type = 1;
|
||||
} else {
|
||||
type = 2;
|
||||
}
|
||||
map.put("list", list);
|
||||
map.put("type", type);
|
||||
return ActionResult.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限组id获取相关权限
|
||||
*
|
||||
* @param model 模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "通过权限组id获取相关权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "权限组id", required = true)
|
||||
})
|
||||
@GetMapping("/getPermission")
|
||||
public ActionResult<List<ViewPermissionsVO>> getPermission(ViewPermissionsModel model) {
|
||||
String objectType = model.getObjectType();
|
||||
String id = model.getId();
|
||||
String permissionId = model.getPermissionId();
|
||||
if (StringUtil.isEmpty(permissionId)) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
// 获取当前菜单开启了哪些权限
|
||||
if (checkDataById(id, objectType)) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
PermissionGroupEntity permissionGroupEntity = permissionGroupService.info(permissionId);
|
||||
if (permissionGroupEntity == null) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
String itemType = model.getItemType();
|
||||
// 权限组的权限
|
||||
List<AuthorizeEntity> authList = authorizeService.getListByObjectId(Collections.singletonList(permissionId));
|
||||
List<ViewPermissionsTreeModel> list = new ArrayList<>();
|
||||
if (AuthorizeConst.SYSTEM.equals(itemType)) {
|
||||
list = this.system(authList, itemType);
|
||||
} else if (AuthorizeConst.MODULE.equals(itemType)) {
|
||||
list = this.module(authList, itemType);
|
||||
} else if (AuthorizeConst.BUTTON.equals(itemType)) {
|
||||
list = this.button(authList, itemType);
|
||||
} else if (AuthorizeConst.COLUMN.equals(itemType)) {
|
||||
list = this.column(authList, itemType);
|
||||
} else if (AuthorizeConst.FROM.equals(itemType)) {
|
||||
list = this.form(authList, itemType);
|
||||
} else if (AuthorizeConst.RESOURCE.equals(itemType)) {
|
||||
list = this.resources(authList, itemType);
|
||||
} else if (AuthorizeConst.AUTHORIZE_PORTAL_MANAGE.equals(itemType)) {
|
||||
list = this.portal(authList, itemType);
|
||||
} else if (AuthorizeConst.FLOW.equals(itemType)) {
|
||||
list = this.flow(authList, itemType);
|
||||
} else if (AuthorizeConst.PRINT.equals(itemType)) {
|
||||
list = this.print(authList, itemType);
|
||||
}
|
||||
list = list.stream().sorted(Comparator.comparing(ViewPermissionsTreeModel::getSortCode, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(ViewPermissionsTreeModel::getCreatorTime, Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList());
|
||||
List<SumTree<ViewPermissionsTreeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(list);
|
||||
List<ViewPermissionsVO> jsonToList = JsonUtil.getJsonToList(sumTrees, ViewPermissionsVO.class);
|
||||
return ActionResult.success(jsonToList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有系统信息
|
||||
*
|
||||
* @param authList
|
||||
* @param itemType
|
||||
* @return
|
||||
*/
|
||||
private List<ViewPermissionsTreeModel> system(List<AuthorizeEntity> authList, String itemType) {
|
||||
List<String> ids = authList.stream().filter(t -> itemType.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList());
|
||||
return JsonUtil.getJsonToList(systemApi.getListByIds(ids, null), ViewPermissionsTreeModel.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有菜单信息
|
||||
*
|
||||
* @param authList
|
||||
* @param itemType
|
||||
* @return
|
||||
*/
|
||||
private List<ViewPermissionsTreeModel> module(List<AuthorizeEntity> authList, String itemType) {
|
||||
List<ViewPermissionsTreeModel> systemList = this.system(authList, AuthorizeConst.SYSTEM);
|
||||
systemList.forEach(systemEntity -> systemEntity.setParentId("-1"));
|
||||
List<String> ids = authList.stream().filter(t -> itemType.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList());
|
||||
List<ModuleEntity> moduleByIds = moduleApi.getModuleByIds(ids, null, null, false);
|
||||
Map<String, List<ModuleEntity>> systemGroupMap = moduleByIds.stream().collect(Collectors.groupingBy(ModuleEntity::getSystemId));
|
||||
List<ModuleEntity> categoryList = new ArrayList<>();
|
||||
Date datetime = new Date();
|
||||
if (systemGroupMap != null) {
|
||||
ids.forEach(systemId -> {
|
||||
List<ModuleEntity> moduleEntities = systemGroupMap.get(systemId);
|
||||
if (moduleEntities != null && moduleEntities.size() > 0) {
|
||||
Map<String, List<ModuleEntity>> categoryMap = moduleEntities.stream().collect(Collectors.groupingBy(ModuleEntity::getCategory));
|
||||
if (categoryMap != null) {
|
||||
List<ModuleEntity> webModuleList = categoryMap.get("Web");
|
||||
if (webModuleList != null && webModuleList.size() > 0) {
|
||||
ModuleEntity entity = new ModuleEntity();
|
||||
entity.setParentId(webModuleList.get(0).getSystemId());
|
||||
entity.setId(webModuleList.get(0).getSystemId() + "1");
|
||||
entity.setFullName("WEB菜单");
|
||||
entity.setIcon("icon-ym icon-ym-pc");
|
||||
entity.setSortCode(-1L);
|
||||
entity.setCreatorTime(datetime);
|
||||
categoryList.add(entity);
|
||||
}
|
||||
List<ModuleEntity> appModuleList = categoryMap.get("App");
|
||||
if (appModuleList != null && appModuleList.size() > 0) {
|
||||
ModuleEntity entity = new ModuleEntity();
|
||||
entity.setParentId(appModuleList.get(0).getSystemId());
|
||||
entity.setId(appModuleList.get(0).getSystemId() + "2");
|
||||
entity.setFullName("APP菜单");
|
||||
entity.setIcon("icon-ym icon-ym-mobile");
|
||||
entity.setSortCode(0L);
|
||||
entity.setCreatorTime(datetime);
|
||||
categoryList.add(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
moduleByIds.addAll(categoryList);
|
||||
moduleByIds.forEach(t -> {
|
||||
if ("-1".equals(t.getParentId())) {
|
||||
if ("Web".equals(t.getCategory())) {
|
||||
t.setParentId(t.getSystemId() + "1");
|
||||
} else {
|
||||
t.setParentId(t.getSystemId() + "2");
|
||||
}
|
||||
}
|
||||
});
|
||||
List<ViewPermissionsTreeModel> moduleList = JsonUtil.getJsonToList(moduleByIds, ViewPermissionsTreeModel.class);
|
||||
List<String> systemId = moduleByIds.stream().map(ModuleEntity::getSystemId).distinct().collect(Collectors.toList());
|
||||
List<ViewPermissionsTreeModel> collect = systemList.stream().filter(t -> systemId.contains(t.getId())).collect(Collectors.toList());
|
||||
moduleList.addAll(collect);
|
||||
return moduleList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有按钮权限信息
|
||||
*
|
||||
* @param authList
|
||||
* @param itemType
|
||||
* @return
|
||||
*/
|
||||
private List<ViewPermissionsTreeModel> button(List<AuthorizeEntity> authList, String itemType) {
|
||||
List<ViewPermissionsTreeModel> module = this.module(authList, AuthorizeConst.MODULE);
|
||||
List<String> ids = authList.stream().filter(t -> itemType.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList());
|
||||
List<ModuleButtonEntity> listByIds = buttonApi.getListByIds(ids);
|
||||
listByIds.forEach(t -> t.setParentId(t.getModuleId()));
|
||||
List<ViewPermissionsTreeModel> moduleList = JsonUtil.getJsonToList(listByIds, ViewPermissionsTreeModel.class);
|
||||
Map<String, ViewPermissionsTreeModel> moduleModel = module.stream().collect(Collectors.toMap(ViewPermissionsTreeModel::getId, Function.identity()));
|
||||
// 上级菜单id
|
||||
List<String> moduleIds = listByIds.stream().map(ModuleButtonEntity::getModuleId).distinct().collect(Collectors.toList());
|
||||
moduleIds.forEach(t -> {
|
||||
ViewPermissionsTreeModel viewPermissionsTreeModel = moduleModel.get(t);
|
||||
moduleList.add(viewPermissionsTreeModel);
|
||||
getParentModule(moduleModel, viewPermissionsTreeModel.getParentId(), moduleList);
|
||||
});
|
||||
return moduleList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有列表权限信息
|
||||
*
|
||||
* @param authList
|
||||
* @param itemType
|
||||
* @return
|
||||
*/
|
||||
private List<ViewPermissionsTreeModel> column(List<AuthorizeEntity> authList, String itemType) {
|
||||
List<ViewPermissionsTreeModel> module = this.module(authList, AuthorizeConst.MODULE);
|
||||
List<String> ids = authList.stream().filter(t -> itemType.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList());
|
||||
List<ModuleColumnEntity> listByIds = columnApi.getListByIds(ids);
|
||||
listByIds.forEach(t -> t.setParentId(t.getModuleId()));
|
||||
List<ViewPermissionsTreeModel> moduleList = JsonUtil.getJsonToList(listByIds, ViewPermissionsTreeModel.class);
|
||||
Map<String, ViewPermissionsTreeModel> moduleModel = module.stream().collect(Collectors.toMap(ViewPermissionsTreeModel::getId, Function.identity()));
|
||||
// 上级菜单id
|
||||
List<String> moduleIds = listByIds.stream().map(ModuleColumnEntity::getModuleId).distinct().collect(Collectors.toList());
|
||||
moduleIds.forEach(t -> {
|
||||
ViewPermissionsTreeModel viewPermissionsTreeModel = moduleModel.get(t);
|
||||
moduleList.add(viewPermissionsTreeModel);
|
||||
getParentModule(moduleModel, viewPermissionsTreeModel.getParentId(), moduleList);
|
||||
});
|
||||
return moduleList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有表单权限信息
|
||||
*
|
||||
* @param authList
|
||||
* @param itemType
|
||||
* @return
|
||||
*/
|
||||
private List<ViewPermissionsTreeModel> form(List<AuthorizeEntity> authList, String itemType) {
|
||||
List<ViewPermissionsTreeModel> module = this.module(authList, AuthorizeConst.MODULE);
|
||||
List<String> ids = authList.stream().filter(t -> itemType.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList());
|
||||
List<ModuleFormEntity> listByIds = formApi.getListByIds(ids);
|
||||
listByIds.forEach(t -> t.setParentId(t.getModuleId()));
|
||||
List<ViewPermissionsTreeModel> moduleList = JsonUtil.getJsonToList(listByIds, ViewPermissionsTreeModel.class);
|
||||
Map<String, ViewPermissionsTreeModel> moduleModel = module.stream().collect(Collectors.toMap(ViewPermissionsTreeModel::getId, Function.identity()));
|
||||
// 上级菜单id
|
||||
List<String> moduleIds = listByIds.stream().map(ModuleFormEntity::getModuleId).distinct().collect(Collectors.toList());
|
||||
moduleIds.forEach(t -> {
|
||||
ViewPermissionsTreeModel viewPermissionsTreeModel = moduleModel.get(t);
|
||||
moduleList.add(viewPermissionsTreeModel);
|
||||
getParentModule(moduleModel, viewPermissionsTreeModel.getParentId(), moduleList);
|
||||
});
|
||||
return moduleList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有数据权限信息
|
||||
*
|
||||
* @param authList
|
||||
* @param itemType
|
||||
* @return
|
||||
*/
|
||||
private List<ViewPermissionsTreeModel> resources(List<AuthorizeEntity> authList, String itemType) {
|
||||
List<ViewPermissionsTreeModel> module = this.module(authList, AuthorizeConst.MODULE);
|
||||
List<String> ids = authList.stream().filter(t -> itemType.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList());
|
||||
List<ModuleDataAuthorizeSchemeEntity> listByIds = schemeApi.getListByIds(ids);
|
||||
List<ViewPermissionsTreeModel> moduleList = JsonUtil.getJsonToList(listByIds, ViewPermissionsTreeModel.class);
|
||||
moduleList.forEach(t -> t.setParentId(t.getModuleId()));
|
||||
Map<String, ViewPermissionsTreeModel> moduleModel = module.stream().collect(Collectors.toMap(ViewPermissionsTreeModel::getId, Function.identity()));
|
||||
// 上级菜单id
|
||||
List<String> moduleIds = listByIds.stream().map(ModuleDataAuthorizeSchemeEntity::getModuleId).distinct().collect(Collectors.toList());
|
||||
moduleIds.forEach(t -> {
|
||||
ViewPermissionsTreeModel viewPermissionsTreeModel = moduleModel.get(t);
|
||||
moduleList.add(viewPermissionsTreeModel);
|
||||
getParentModule(moduleModel, viewPermissionsTreeModel.getParentId(), moduleList);
|
||||
});
|
||||
return moduleList;
|
||||
}
|
||||
|
||||
private List<ViewPermissionsTreeModel> portal(List<AuthorizeEntity> authList, String itemType) {
|
||||
List<String> ids = authList.stream().filter(t -> AuthorizeConst.SYSTEM.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList());
|
||||
List<PortalModel> myPortalList = new ArrayList<>();
|
||||
List<SystemEntity> mySystemList = systemApi.getListByIds(ids, null);
|
||||
List<String> collect = authList.stream().filter(t -> itemType.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList());
|
||||
if (ObjectUtil.isEmpty(collect)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
authorizeService.getPortal(mySystemList, myPortalList, System.currentTimeMillis(), collect);
|
||||
return JsonUtil.getJsonToList(myPortalList.stream().sorted(Comparator.comparing(PortalModel::getSortCode).thenComparing(PortalModel::getCreatorTime).reversed()).collect(Collectors.toList()), ViewPermissionsTreeModel.class);
|
||||
}
|
||||
|
||||
private List<ViewPermissionsTreeModel> flow(List<AuthorizeEntity> authList, String itemType) {
|
||||
List<ViewPermissionsTreeModel> listVO = new ArrayList<>();
|
||||
List<AuthorizeEntity> authorizeList = authList.stream().filter(t -> itemType.equals(t.getItemType())).collect(Collectors.toList());
|
||||
List<String> itemId = authorizeList.stream().map(AuthorizeEntity::getItemId).distinct().collect(Collectors.toList());
|
||||
if (itemId.isEmpty()) {
|
||||
return listVO;
|
||||
}
|
||||
List<TemplateEntity> list = templateApi.getListByFlowIds(itemId);
|
||||
List<String> category = list.stream().map(TemplateEntity::getCategory).collect(Collectors.toList());
|
||||
List<DictionaryDataEntity> dictionName = dictionaryDataApi.getDictionName(category);
|
||||
List<ViewPermissionsTreeModel> childListAll = new ArrayList<>();
|
||||
Long date = System.currentTimeMillis();
|
||||
for (DictionaryDataEntity dict : dictionName) {
|
||||
ViewPermissionsTreeModel vo = JsonUtil.getJsonToBean(dict, ViewPermissionsTreeModel.class);
|
||||
vo.setSortCode(0L);
|
||||
vo.setCreatorTime(date);
|
||||
List<TemplateEntity> childList = list.stream()
|
||||
.filter(e -> dict.getId().equals(e.getCategory()))
|
||||
.sorted(Comparator.comparing(TemplateEntity::getSortCode).thenComparing(TemplateEntity::getCreatorTime, Comparator.reverseOrder())).collect(Collectors.toList());
|
||||
if (childList.size() > 0) {
|
||||
listVO.add(vo);
|
||||
for (TemplateEntity entity : childList) {
|
||||
ViewPermissionsTreeModel user = JsonUtil.getJsonToBean(entity, ViewPermissionsTreeModel.class);
|
||||
user.setParentId(dict.getId());
|
||||
childListAll.add(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
listVO.addAll(childListAll);
|
||||
return listVO;
|
||||
}
|
||||
|
||||
private List<ViewPermissionsTreeModel> print(List<AuthorizeEntity> authList, String itemType) {
|
||||
List<ViewPermissionsTreeModel> listVO = new ArrayList<>();
|
||||
List<AuthorizeEntity> authorizeList = authList.stream().filter(t -> itemType.equals(t.getItemType())).collect(Collectors.toList());
|
||||
List<String> itemId = authorizeList.stream().map(AuthorizeEntity::getItemId).distinct().collect(Collectors.toList());
|
||||
if (itemId.isEmpty()) {
|
||||
return listVO;
|
||||
}
|
||||
List<PrintDevEntity> list = printDevApi.getWorkSelector(itemId);
|
||||
List<String> category = list.stream().map(PrintDevEntity::getCategory).collect(Collectors.toList());
|
||||
List<DictionaryDataEntity> dictionName = dictionaryDataApi.getDictionName(category);
|
||||
List<ViewPermissionsTreeModel> childListAll = new ArrayList<>();
|
||||
Long date = System.currentTimeMillis();
|
||||
for (DictionaryDataEntity dict : dictionName) {
|
||||
ViewPermissionsTreeModel vo = JsonUtil.getJsonToBean(dict, ViewPermissionsTreeModel.class);
|
||||
vo.setSortCode(0L);
|
||||
vo.setCreatorTime(date);
|
||||
List<PrintDevEntity> childList = list.stream()
|
||||
.filter(e -> dict.getId().equals(e.getCategory()))
|
||||
.sorted(Comparator.comparing(PrintDevEntity::getSortCode).thenComparing(PrintDevEntity::getCreatorTime, Comparator.reverseOrder())).collect(Collectors.toList());
|
||||
if (childList.size() > 0) {
|
||||
listVO.add(vo);
|
||||
for (PrintDevEntity entity : childList) {
|
||||
ViewPermissionsTreeModel user = JsonUtil.getJsonToBean(entity, ViewPermissionsTreeModel.class);
|
||||
user.setParentId(dict.getId());
|
||||
childListAll.add(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
listVO.addAll(childListAll);
|
||||
return listVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上级菜单
|
||||
*
|
||||
* @param moduleModel
|
||||
* @param parentId
|
||||
* @param moduleList
|
||||
*/
|
||||
private void getParentModule(Map<String, ViewPermissionsTreeModel> moduleModel, String parentId, List<ViewPermissionsTreeModel> moduleList) {
|
||||
if (!"-1".equals(parentId)) {
|
||||
if (moduleModel.get(parentId) != null) {
|
||||
moduleList.add(moduleModel.get(parentId));
|
||||
this.getParentModule(moduleModel, moduleModel.get(parentId).getParentId(), moduleList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证对象数据是否存在
|
||||
*
|
||||
* @param id
|
||||
* @param objectType
|
||||
* @return
|
||||
*/
|
||||
private boolean checkDataById(String id, String objectType) {
|
||||
if (PermissionConst.COMPANY.equals(objectType) || PermissionConst.DEPARTMENT.equals(objectType)) {
|
||||
// 获取当前菜单开启了哪些权限
|
||||
OrganizeEntity entity = organizeService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return true;
|
||||
}
|
||||
} else if ("position".equals(objectType)) {
|
||||
PositionEntity entity = positionService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return true;
|
||||
}
|
||||
} else if ("user".equals(objectType)) {
|
||||
UserEntity entity = userService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return true;
|
||||
}
|
||||
} else if ("role".equals(objectType)) {
|
||||
RoleEntity entity = roleService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return true;
|
||||
}
|
||||
} else if ("group".equals(objectType)) {
|
||||
GroupEntity entity = groupService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,976 @@
|
||||
package com.yunzhupaas.permission.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.annotation.PositionPermission;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.constant.PermissionConst;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.model.ExcelColumnAttr;
|
||||
import com.yunzhupaas.model.ExcelImportForm;
|
||||
import com.yunzhupaas.model.ExcelImportVO;
|
||||
import com.yunzhupaas.model.ExcelModel;
|
||||
import com.yunzhupaas.permission.constant.PosColumnMap;
|
||||
import com.yunzhupaas.permission.entity.*;
|
||||
import com.yunzhupaas.permission.model.check.CheckResult;
|
||||
import com.yunzhupaas.permission.model.permission.PermissionModel;
|
||||
import com.yunzhupaas.permission.model.position.*;
|
||||
import com.yunzhupaas.permission.model.user.UserIdListVo;
|
||||
import com.yunzhupaas.permission.model.user.mod.UserIdModel;
|
||||
import com.yunzhupaas.permission.service.*;
|
||||
import com.yunzhupaas.base.util.ExcelTool;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.enums.DictionaryDataEnum;
|
||||
import com.yunzhupaas.util.treeutil.ListToTreeUtil;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.treeutil.newtreeutil.TreeDotUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 岗位信息
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024-09-26 上午9:18
|
||||
*/
|
||||
@Tag(name = "岗位管理", description = "Position")
|
||||
@RestController
|
||||
@RequestMapping("/api/permission/Position")
|
||||
public class PositionController extends SuperController<PositionService, PositionEntity> {
|
||||
@Autowired
|
||||
private UserRelationService userRelationService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private PositionService positionService;
|
||||
@Autowired
|
||||
private OrganizeService organizeService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataApi;
|
||||
@Autowired
|
||||
private OrganizeRelationService organizeRelationService;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
|
||||
/**
|
||||
* 获取岗位管理信息列表
|
||||
*
|
||||
* @param paginationPosition 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取岗位列表(分页)")
|
||||
@SaCheckPermission("permission.position")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<PositionListVO>> list(PaginationPosition paginationPosition) {
|
||||
List<DictionaryDataEntity> dictionaryDataEntities = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.POSITION_TYPE.getDictionaryTypeId());
|
||||
if (StringUtil.isNotEmpty(paginationPosition.getType())) {
|
||||
DictionaryDataEntity dictionaryDataEntity = dictionaryDataEntities.stream().filter(t -> paginationPosition.getType().equals(t.getId())).findFirst().orElse(null);
|
||||
if (dictionaryDataEntity != null) {
|
||||
paginationPosition.setEnCode(dictionaryDataEntity.getEnCode());
|
||||
}
|
||||
}
|
||||
List<PositionEntity> data = positionService.getList(paginationPosition);
|
||||
//添加部门信息,部门映射到organizeId
|
||||
List<PositionListVO> voList = JsonUtil.getJsonToList(data, PositionListVO.class);
|
||||
List<String> collect = data.stream().map(PositionEntity::getOrganizeId).collect(Collectors.toList());
|
||||
List<OrganizeEntity> list = organizeService.getOrgEntityList(collect, true);
|
||||
//添加部门信息
|
||||
Map<String, String> orgIdNameMaps = organizeService.getInfoList();
|
||||
for (PositionListVO entity1 : voList) {
|
||||
OrganizeEntity entity = list.stream().filter(t -> t.getId().equals(entity1.getOrganizeId())).findFirst().orElse(new OrganizeEntity());
|
||||
if (entity1.getOrganizeId().equals(entity.getId())) {
|
||||
entity1.setDepartment(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, entity.getOrganizeIdTree(), "/"));
|
||||
}
|
||||
}
|
||||
//将type成中文名
|
||||
for (PositionListVO entity1 : voList) {
|
||||
dictionaryDataEntities.stream().filter(t -> t.getEnCode().equals(entity1.getType())).findFirst().ifPresent(entity -> entity1.setType(entity.getFullName()));
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(paginationPosition, PaginationVO.class);
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "列表")
|
||||
@GetMapping("/All")
|
||||
public ActionResult<ListVO<PositionListAllVO>> listAll() {
|
||||
List<PositionEntity> list = positionService.getList(true);
|
||||
List<PositionListAllVO> vos = JsonUtil.getJsonToList(list, PositionListAllVO.class);
|
||||
ListVO<PositionListAllVO> vo = new ListVO<>();
|
||||
vo.setList(vos);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 树形(机构+岗位)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取岗位下拉列表(公司+部门+岗位)")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<ListVO<PositionSelectorVO>> selector() {
|
||||
List<PositionEntity> list1 = positionService.getList(true);
|
||||
Map<String, OrganizeEntity> orgMaps = organizeService.getOrgMaps(null, false, null);
|
||||
Map<String, String> orgIdNameMaps = organizeService.getInfoList();
|
||||
List<OrganizeEntity> list2 = new ArrayList<>(orgMaps.values());
|
||||
;
|
||||
List<PosOrgModel> posList = new ArrayList<>();
|
||||
for (PositionEntity entity : list1) {
|
||||
PosOrgModel posOrgModel = JsonUtil.getJsonToBean(entity, PosOrgModel.class);
|
||||
String organizeId = entity.getOrganizeId();
|
||||
posOrgModel.setParentId(organizeId);
|
||||
posOrgModel.setType("position");
|
||||
posOrgModel.setIcon("icon-ym icon-ym-tree-position1");
|
||||
OrganizeEntity organizeEntity = orgMaps.get(organizeId);
|
||||
if (organizeEntity != null) {
|
||||
posOrgModel.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/"));
|
||||
posOrgModel.setOrganizeIds(organizeService.getOrgIdTree(organizeEntity));
|
||||
} else {
|
||||
posOrgModel.setOrganizeIds(new ArrayList<>());
|
||||
}
|
||||
posList.add(posOrgModel);
|
||||
}
|
||||
List<PosOrgModel> orgList = JsonUtil.getJsonToList(list2, PosOrgModel.class);
|
||||
for (PosOrgModel entity1 : orgList) {
|
||||
if ("department".equals(entity1.getType())) {
|
||||
entity1.setIcon("icon-ym icon-ym-tree-department1");
|
||||
} else if ("company".equals(entity1.getType())) {
|
||||
entity1.setIcon("icon-ym icon-ym-tree-organization3");
|
||||
}
|
||||
OrganizeEntity organizeEntity = orgMaps.get(entity1.getId());
|
||||
if (organizeEntity != null) {
|
||||
entity1.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/"));
|
||||
entity1.setOrganizeIds(organizeService.getOrgIdTree(organizeEntity));
|
||||
} else {
|
||||
entity1.setOrganizeIds(new ArrayList<>());
|
||||
}
|
||||
entity1.setOrganizeIds(new ArrayList<>());
|
||||
}
|
||||
JSONArray objects = ListToTreeUtil.treeWhere(posList, orgList);
|
||||
List<PosOrgModel> jsonToList = JsonUtil.getJsonToList(objects, PosOrgModel.class);
|
||||
|
||||
List<PosOrgModel> list = new ArrayList<>(16);
|
||||
// 得到角色的值
|
||||
List<PosOrgModel> collect = jsonToList.stream().filter(t -> "position".equals(t.getType())).sorted(Comparator.comparing(PosOrgModel::getSortCode)).collect(Collectors.toList());
|
||||
list.addAll(collect);
|
||||
jsonToList.removeAll(collect);
|
||||
List<PosOrgModel> collect1 = jsonToList.stream().sorted(Comparator.comparing(PosOrgModel::getSortCode).thenComparing(PosOrgModel::getCreatorTime, Comparator.reverseOrder())).collect(Collectors.toList());
|
||||
list.addAll(collect1);
|
||||
|
||||
List<SumTree<PosOrgModel>> trees = TreeDotUtils.convertListToTreeDot(list);
|
||||
List<PositionSelectorVO> jsonToList1 = JsonUtil.getJsonToList(trees, PositionSelectorVO.class);
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(jsonToList1);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过部门、岗位获取岗位下拉框
|
||||
*
|
||||
* @param idModel 岗位选择模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "通过部门、岗位获取岗位下拉框")
|
||||
@Parameters({
|
||||
@Parameter(name = "positionConditionModel", description = "岗位选择模型", required = true)
|
||||
})
|
||||
@PostMapping("/PositionCondition")
|
||||
public ActionResult<ListVO<PositionSelectorVO>> positionCondition(@RequestBody UserIdModel idModel) {
|
||||
// 定义返回对象
|
||||
List<PositionSelectorVO> modelList = new ArrayList<>();
|
||||
|
||||
List<String> list = organizeRelationService.getOrgIds(idModel.getIds(), null);
|
||||
List<String> lists = new ArrayList<>();
|
||||
list.forEach(t -> lists.add(t.split("--")[0]));
|
||||
list = lists;
|
||||
List<String> collect = positionService.getListByOrganizeId(list, false).stream().map(PositionEntity::getId).collect(Collectors.toList());
|
||||
collect.addAll(list);
|
||||
List<PositionEntity> positionName = positionService.getPositionName(collect, null);
|
||||
positionName = positionName.stream().filter(t -> "1".equals(String.valueOf(t.getEnabledMark()))).collect(Collectors.toList());
|
||||
|
||||
Map<String, OrganizeEntity> orgMaps = organizeService.getOrganizeName(positionName.stream().map(PositionEntity::getOrganizeId).collect(Collectors.toList()), null, false, null);
|
||||
Map<String, String> orgIdNameMaps = organizeService.getInfoList();
|
||||
|
||||
List<PosOrgConditionModel> posOrgModels = new ArrayList<>(16);
|
||||
positionName.forEach(t -> {
|
||||
PosOrgConditionModel posOrgModel = JsonUtil.getJsonToBean(t, PosOrgConditionModel.class);
|
||||
OrganizeEntity entity = orgMaps.get(t.getOrganizeId());
|
||||
if (entity != null) {
|
||||
posOrgModel.setOrganizeId(entity.getId());
|
||||
posOrgModel.setParentId(entity.getId());
|
||||
if (StringUtil.isNotEmpty(entity.getOrganizeIdTree())) {
|
||||
posOrgModel.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, entity.getOrganizeIdTree(), "/"));
|
||||
}
|
||||
}
|
||||
posOrgModel.setType("position");
|
||||
posOrgModel.setIcon("icon-ym icon-ym-tree-position1");
|
||||
posOrgModels.add(posOrgModel);
|
||||
});
|
||||
|
||||
// 处理组织
|
||||
orgMaps.values().forEach(org -> {
|
||||
PosOrgConditionModel orgVo = JsonUtil.getJsonToBean(org, PosOrgConditionModel.class);
|
||||
if ("department".equals(orgVo.getType())) {
|
||||
orgVo.setIcon("icon-ym icon-ym-tree-department1");
|
||||
} else if ("company".equals(orgVo.getType())) {
|
||||
orgVo.setIcon("icon-ym icon-ym-tree-organization3");
|
||||
}
|
||||
// 处理断层
|
||||
if (StringUtil.isNotEmpty(org.getOrganizeIdTree())) {
|
||||
List<String> list1 = new ArrayList<>();
|
||||
String[] split = org.getOrganizeIdTree().split(",");
|
||||
list1 = Arrays.asList(split);
|
||||
Collections.reverse(list1);
|
||||
for (String orgId : list1) {
|
||||
OrganizeEntity organizeEntity1 = orgMaps.get(orgId);
|
||||
if (organizeEntity1 != null && !organizeEntity1.getId().equals(orgVo.getId())) {
|
||||
orgVo.setParentId(organizeEntity1.getId());
|
||||
String[] split1 = org.getOrganizeIdTree().split(organizeEntity1.getId());
|
||||
if (split1.length > 1) {
|
||||
orgVo.setFullName(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, split1[1], "/"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
posOrgModels.add(orgVo);
|
||||
});
|
||||
|
||||
List<SumTree<PosOrgConditionModel>> trees = TreeDotUtils.convertListToTreeDot(posOrgModels);
|
||||
List<PositionSelectorVO> positionSelectorVO = JsonUtil.getJsonToList(trees, PositionSelectorVO.class);
|
||||
// 处理数据
|
||||
positionSelectorVO.forEach(t -> {
|
||||
if (!"position".equals(t.getType())) {
|
||||
t.setFullName(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, t.getOrganizeIdTree(), "/"));
|
||||
}
|
||||
});
|
||||
modelList.addAll(positionSelectorVO);
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(modelList);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过组织id获取岗位列表
|
||||
*
|
||||
* @param organizeId 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "通过组织id获取岗位列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "organizeId", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("permission.position")
|
||||
@GetMapping("/getList/{organizeId}")
|
||||
public ActionResult<List<PositionVo>> getListByOrganizeId(@PathVariable("organizeId") String organizeId) {
|
||||
List<PositionEntity> list = positionService.getListByOrganizeId(Collections.singletonList(organizeId), false);
|
||||
List<PositionVo> jsonToList = JsonUtil.getJsonToList(list, PositionVo.class);
|
||||
return ActionResult.success(jsonToList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取岗位管理信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取岗位管理信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("permission.position")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<PositionInfoVO> getInfo(@PathVariable("id") String id) throws DataException {
|
||||
PositionEntity entity = positionService.getInfo(id);
|
||||
PositionInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, PositionInfoVO.class);
|
||||
String organizeId = entity.getOrganizeId();
|
||||
OrganizeEntity organizeEntity = organizeService.getInfo(organizeId);
|
||||
vo.setOrganizeIdTree(StringUtil.isNotEmpty(organizeEntity.getOrganizeIdTree()) ? Arrays.asList(organizeEntity.getOrganizeIdTree().split(",")) : new ArrayList<>());
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新建岗位管理
|
||||
*
|
||||
* @param positionCrForm 实体对象
|
||||
* @return
|
||||
*/
|
||||
@PositionPermission
|
||||
@Operation(summary = "新建岗位管理")
|
||||
@Parameters({
|
||||
@Parameter(name = "positionCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("permission.position")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid PositionCrForm positionCrForm) {
|
||||
PositionEntity entity = JsonUtil.getJsonToBean(positionCrForm, PositionEntity.class);
|
||||
if (positionService.isExistByFullName(entity, false)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (positionService.isExistByEnCode(entity, false)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
// 设置岗位id
|
||||
entity.setId(RandomUtil.uuId());
|
||||
// createOrganizeRoleRelation(entity.getOrganizeId(), entity.getId());
|
||||
positionService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新岗位管理
|
||||
*
|
||||
* @param id 主键值
|
||||
* @param positionUpForm 实体对象
|
||||
* @return
|
||||
*/
|
||||
@PositionPermission
|
||||
@Operation(summary = "更新岗位管理")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "positionUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("permission.position")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid PositionUpForm positionUpForm) {
|
||||
PositionEntity positionEntity = positionService.getInfo(id);
|
||||
if (positionEntity == null) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
// 当岗位绑定用户不让其更改
|
||||
if (userRelationService.existByObj(PermissionConst.POSITION, id)) {
|
||||
if (!positionService.getInfo(id).getOrganizeId().equals(positionUpForm.getOrganizeId())) {
|
||||
return ActionResult.fail(MsgCode.FA023.get());
|
||||
}
|
||||
if (positionUpForm.getEnabledMark() == 0 && positionEntity.getEnabledMark() == 1) {
|
||||
return ActionResult.fail(MsgCode.FA030.get());
|
||||
}
|
||||
}
|
||||
PositionEntity entity = JsonUtil.getJsonToBean(positionUpForm, PositionEntity.class);
|
||||
entity.setId(id);
|
||||
if (positionService.isExistByFullName(entity, true)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (positionService.isExistByEnCode(entity, true)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
// createOrganizeRoleRelation(entity.getOrganizeId(), id);
|
||||
boolean flag = positionService.update(id, entity);
|
||||
if (flag == false) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除岗位管理
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@PositionPermission
|
||||
@Operation(summary = "删除岗位管理")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("permission.position")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
// 当岗位绑定用户不让其更改
|
||||
if (userRelationService.existByObj(PermissionConst.POSITION, id)) {
|
||||
return ActionResult.fail(MsgCode.FA024.get());
|
||||
}
|
||||
PositionEntity entity = positionService.getInfo(id);
|
||||
if (entity != null) {
|
||||
List<UserRelationEntity> userRelList = userRelationService.getListByObjectId(id);
|
||||
if (userRelList.size() > 0) {
|
||||
return ActionResult.fail(MsgCode.FA024.get());
|
||||
}
|
||||
for (UserRelationEntity entity1 : userRelList) {
|
||||
UserEntity entity2 = userService.getById(entity1.getUserId());
|
||||
if (entity2 != null) {
|
||||
String newPositionId = entity2.getPositionId().replace(id, "");
|
||||
if (entity2.getPositionId().contains(id)) {
|
||||
if (newPositionId.length() != 0 && newPositionId.substring(0, 1).equals(",")) {
|
||||
entity2.setPositionId(newPositionId.substring(1));
|
||||
} else if (newPositionId.length() != 0) {
|
||||
entity2.setPositionId(newPositionId.replace(",,", ","));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
userRelationService.deleteAllByObjId(id);
|
||||
|
||||
// 删除岗位与组织之间的关联数据
|
||||
QueryWrapper<OrganizeRelationEntity> query = new QueryWrapper<>();
|
||||
query.lambda().eq(OrganizeRelationEntity::getObjectType, PermissionConst.POSITION);
|
||||
query.lambda().eq(OrganizeRelationEntity::getObjectId, id);
|
||||
organizeRelationService.remove(query);
|
||||
|
||||
positionService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单状态
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新菜单状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("permission.position")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult upState(@PathVariable("id") String id) {
|
||||
PositionEntity entity = positionService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) {
|
||||
entity.setEnabledMark(0);
|
||||
} else {
|
||||
entity.setEnabledMark(1);
|
||||
}
|
||||
positionService.update(id, entity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过组织id获取岗位列表
|
||||
*
|
||||
* @param organizeIds 组织id数组
|
||||
* @return 岗位列表
|
||||
*/
|
||||
@Operation(summary = "获取岗位列表通过组织id数组")
|
||||
@Parameters({
|
||||
@Parameter(name = "organizeIds", description = "组织id数组", required = true)
|
||||
})
|
||||
@SaCheckPermission("permission.position")
|
||||
@PostMapping("/getListByOrgIds")
|
||||
public ActionResult<ListVO<PermissionModel>> getListByOrganizeIds(@RequestBody @Valid Map<String, List<String>> organizeIds) {
|
||||
List<PermissionModel> PositionModelAll = new LinkedList<>();
|
||||
if (organizeIds.get("organizeIds") != null) {
|
||||
List<String> ids = organizeIds.get("organizeIds");
|
||||
PositionModelAll = positionService.getListByOrganizeIds(ids, false,true);
|
||||
}
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(PositionModelAll);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加组织角色关联关系
|
||||
*
|
||||
* @param organizeId 组织id
|
||||
* @param positionId 岗位id
|
||||
*/
|
||||
private void createOrganizeRoleRelation(String organizeId, String positionId) {
|
||||
// 清除之前的关联关系
|
||||
QueryWrapper<OrganizeRelationEntity> query = new QueryWrapper<>();
|
||||
query.lambda().eq(OrganizeRelationEntity::getObjectType, PermissionConst.POSITION);
|
||||
query.lambda().eq(OrganizeRelationEntity::getObjectId, positionId);
|
||||
organizeRelationService.remove(query);
|
||||
// 添加与组织的关联关系
|
||||
OrganizeRelationEntity organizeRelationEntity = new OrganizeRelationEntity();
|
||||
organizeRelationEntity.setId(RandomUtil.uuId());
|
||||
organizeRelationEntity.setOrganizeId(organizeId);
|
||||
organizeRelationEntity.setObjectType(PermissionConst.POSITION);
|
||||
organizeRelationEntity.setObjectId(positionId);
|
||||
organizeRelationService.save(organizeRelationEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@GetMapping("/SelectAsyncList/{id}")
|
||||
public ActionResult<?> selectAsyncList(@PathVariable("id") String id,PaginationPosition pagination) {
|
||||
List<PositionSelectorVO> listVO = new ArrayList<>();
|
||||
Map<String, String> orgIdNameMaps = organizeService.getInfoList();
|
||||
Map<String, OrganizeEntity> orgMaps = organizeService.getOrgMaps(null, true, null);
|
||||
List<OrganizeRelationEntity> organizeList = organizeRelationService.getRelationListByType(PermissionConst.POSITION);
|
||||
boolean isKeyWord = StringUtil.isNotEmpty(pagination.getKeyword());
|
||||
if(isKeyWord) {
|
||||
List<String> objectId = organizeList.stream().map(OrganizeRelationEntity::getObjectId).collect(Collectors.toList());
|
||||
List<PositionEntity> list = positionService.getList(objectId, pagination, true);
|
||||
for (PositionEntity entity : list) {
|
||||
PositionSelectorVO vo =new PositionSelectorVO();
|
||||
vo.setId(entity.getId());
|
||||
vo.setFullName(entity.getFullName());
|
||||
vo.setType("position");
|
||||
vo.setIcon("icon-ym icon-ym-tree-position1");
|
||||
vo.setHasChildren(false);
|
||||
vo.setOnlyId(UUID.randomUUID().toString());
|
||||
List<OrganizeRelationEntity> relationList = organizeList.stream().filter(t -> t.getObjectId().equals(entity.getId())).collect(Collectors.toList());
|
||||
StringJoiner orgName = new StringJoiner(",");
|
||||
List<String> organizeId = new ArrayList<>();
|
||||
relationList.forEach(organizeRelationEntity -> {
|
||||
OrganizeEntity organizeEntity = organizeService.getInfo(organizeRelationEntity.getOrganizeId());
|
||||
if (organizeEntity != null) {
|
||||
String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
|
||||
orgName.add(fullNameByOrgIdTree);
|
||||
organizeId.addAll(organizeService.getOrgIdTree(organizeEntity));
|
||||
}
|
||||
});
|
||||
vo.setOrganize(orgName.toString());
|
||||
vo.setOrganizeIds(organizeId);
|
||||
listVO.add(vo);
|
||||
}
|
||||
}else {
|
||||
if (!"0".equals(id)) {
|
||||
List<String> objectId = organizeList.stream().filter(t -> t.getOrganizeId().equals(id)).map(OrganizeRelationEntity::getObjectId).collect(Collectors.toList());
|
||||
List<PositionEntity> list = positionService.getList(objectId, pagination, false);
|
||||
for (PositionEntity entity : list) {
|
||||
PositionSelectorVO vo =JsonUtil.getJsonToBean(entity,PositionSelectorVO.class);
|
||||
vo.setType("position");
|
||||
vo.setIcon("icon-ym icon-ym-tree-position1");
|
||||
vo.setHasChildren(false);
|
||||
vo.setOnlyId(UUID.randomUUID().toString());
|
||||
OrganizeRelationEntity relationEntity = organizeList.stream().filter(t -> t.getOrganizeId().equals(id)).findFirst().orElse(null);
|
||||
List<String> organizeId = new ArrayList<>();
|
||||
if(relationEntity!=null){
|
||||
OrganizeEntity organizeEntity = orgMaps.get(relationEntity.getOrganizeId());
|
||||
if(organizeEntity!=null){
|
||||
vo.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/"));
|
||||
organizeId.addAll(organizeService.getOrgIdTree(organizeEntity));
|
||||
}
|
||||
}
|
||||
vo.setOrganizeIds(organizeId);
|
||||
listVO.add(vo);
|
||||
}
|
||||
//单个组织
|
||||
List<OrganizeEntity> collect = new ArrayList<>(orgMaps.values());
|
||||
OrganizeEntity organizeEntity = orgMaps.get(id);
|
||||
if(organizeEntity!=null){
|
||||
List<OrganizeEntity> collect1 = collect.stream().filter(t -> t.getParentId().equals(organizeEntity.getId())).collect(Collectors.toList());
|
||||
for (OrganizeEntity entity : collect1) {
|
||||
PositionSelectorVO vo = JsonUtil.getJsonToBean(entity, PositionSelectorVO.class);
|
||||
vo.setIcon("company".equals(entity.getCategory()) ? "icon-ym icon-ym-tree-organization3" : "icon-ym icon-ym-tree-department1");
|
||||
vo.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, entity.getOrganizeIdTree(), "/"));
|
||||
vo.setOrganizeIds(organizeService.getOrgIdTree(entity));
|
||||
vo.setHasChildren(true);
|
||||
listVO.add(vo);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<OrganizeEntity> list = new ArrayList<>(orgMaps.values()).stream().filter(t->"-1".equals(t.getParentId()) && Objects.equals(t.getEnabledMark(),1)).collect(Collectors.toList());
|
||||
for (OrganizeEntity entity : list) {
|
||||
PositionSelectorVO vo =JsonUtil.getJsonToBean(entity,PositionSelectorVO.class);
|
||||
vo.setType(entity.getCategory());
|
||||
vo.setIcon("company".equals(entity.getCategory()) ? "icon-ym icon-ym-tree-organization3" : "icon-ym icon-ym-tree-department1");
|
||||
vo.setOnlyId(UUID.randomUUID().toString());
|
||||
vo.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, entity.getOrganizeIdTree(), "/"));
|
||||
vo.setOrganizeIds(organizeService.getOrgIdTree(entity));
|
||||
vo.setHasChildren(true);
|
||||
listVO.add(vo);
|
||||
}
|
||||
}
|
||||
}
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(listVO);
|
||||
if(!isKeyWord){
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
PaginationVO jsonToBean = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(listVO, jsonToBean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取选中值
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取选中值")
|
||||
@Parameters({
|
||||
@Parameter(name = "userIdModel", description = "id", required = true)
|
||||
})
|
||||
@PostMapping("/SelectedList")
|
||||
public ActionResult<ListVO<UserIdListVo>> SelectedList(@RequestBody UserIdModel userIdModel) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
for(String id : userIdModel.getIds()){
|
||||
ids.add(id+"--"+PermissionConst.POSITION);
|
||||
}
|
||||
List<UserIdListVo> list = userService.selectedByIds(ids);
|
||||
ListVO<UserIdListVo> listVO = new ListVO<>();
|
||||
listVO.setList(list);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板下载
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "模板下载")
|
||||
@SaCheckPermission("permission.position")
|
||||
@GetMapping("/TemplateDownload")
|
||||
public ActionResult<DownloadVO> TemplateDownload() {
|
||||
PosColumnMap columnMap = new PosColumnMap();
|
||||
String excelName = columnMap.getExcelName();
|
||||
Map<String, String> keyMap = columnMap.getColumnByType(0);
|
||||
List<ExcelColumnAttr> models = columnMap.getFieldsModel(false);
|
||||
List<Map<String, Object>> list = columnMap.getDefaultList();
|
||||
Map<String, String[]> optionMap = getOptionMap();
|
||||
ExcelModel excelModel = ExcelModel.builder().models(models).selectKey(new ArrayList<>(keyMap.keySet())).optionMap(optionMap).build();
|
||||
DownloadVO vo = ExcelTool.getImportTemplate(configValueUtil.getTemporaryFilePath(), excelName, keyMap, list, excelModel);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传Excel
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "上传导入Excel")
|
||||
@SaCheckPermission("permission.position")
|
||||
@PostMapping("/Uploader")
|
||||
public ActionResult<Object> Uploader() {
|
||||
return ExcelTool.uploader();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入预览
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导入预览")
|
||||
@SaCheckPermission("permission.position")
|
||||
@GetMapping("/ImportPreview")
|
||||
public ActionResult<Map<String, Object>> ImportPreview(String fileName) throws Exception {
|
||||
// 导入字段
|
||||
PosColumnMap columnMap = new PosColumnMap();
|
||||
Map<String, String> keyMap = columnMap.getColumnByType(0);
|
||||
Map<String, Object> headAndDataMap = ExcelTool.importPreview(configValueUtil.getTemporaryFilePath(), fileName, keyMap);
|
||||
return ActionResult.success(headAndDataMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出异常报告
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导出异常报告")
|
||||
@SaCheckPermission("permission.position")
|
||||
@PostMapping("/ExportExceptionData")
|
||||
public ActionResult<DownloadVO> ExportExceptionData(@RequestBody ExcelImportForm visualImportModel) {
|
||||
String temporaryFilePath = configValueUtil.getTemporaryFilePath();
|
||||
List<Map<String, Object>> dataList = visualImportModel.getList();
|
||||
PosColumnMap columnMap = new PosColumnMap();
|
||||
String excelName = columnMap.getExcelName();
|
||||
Map<String, String> keyMap = columnMap.getColumnByType(0);
|
||||
List<ExcelColumnAttr> models = columnMap.getFieldsModel(true);
|
||||
ExcelModel excelModel = ExcelModel.builder().optionMap(getOptionMap()).models(models).build();
|
||||
DownloadVO vo = ExcelTool.exportExceptionReport(temporaryFilePath, excelName, keyMap, dataList, excelModel);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导入数据")
|
||||
@SaCheckPermission("permission.position")
|
||||
@PostMapping("/ImportData")
|
||||
public ActionResult<ExcelImportVO> ImportData(@RequestBody ExcelImportForm visualImportModel) throws Exception {
|
||||
List<Map<String, Object>> listData = new ArrayList<>();
|
||||
List<Map<String, Object>> headerRow = new ArrayList<>();
|
||||
if (visualImportModel.isType()){
|
||||
ActionResult result = ImportPreview(visualImportModel.getFileName());
|
||||
if (result == null){
|
||||
throw new Exception(MsgCode.FA018.get());
|
||||
}
|
||||
if (result.getCode() != 200){
|
||||
throw new Exception(result.getMsg());
|
||||
}
|
||||
if (result.getData() instanceof Map){
|
||||
Map<String,Object> data = (Map<String, Object>) result.getData();
|
||||
listData = (List<Map<String, Object>>) data.get("dataRow");
|
||||
headerRow = (List<Map<String, Object>>) data.get("headerRow");
|
||||
}
|
||||
}else {
|
||||
listData = visualImportModel.getList();
|
||||
}
|
||||
List<PositionEntity> addList = new ArrayList<PositionEntity>();
|
||||
List<Map<String, Object>> failList = new ArrayList<>();
|
||||
// 对数据做校验
|
||||
this.validateImportData(listData, addList, failList);
|
||||
|
||||
//正常数据插入
|
||||
for (PositionEntity each : addList) {
|
||||
positionService.create(each);
|
||||
}
|
||||
ExcelImportVO importModel = new ExcelImportVO();
|
||||
importModel.setSnum(addList.size());
|
||||
importModel.setFnum(failList.size());
|
||||
importModel.setResultType(failList.size() > 0 ? 1 : 0);
|
||||
importModel.setFailResult(failList);
|
||||
importModel.setHeaderRow(headerRow);
|
||||
return ActionResult.success(importModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出Excel
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导出Excel")
|
||||
@SaCheckPermission("permission.position")
|
||||
@GetMapping("/ExportData")
|
||||
public ActionResult ExportData(PaginationPosition paginationPosition) throws IOException {
|
||||
if (StringUtil.isEmpty(paginationPosition.getSelectKey())) {
|
||||
return ActionResult.fail(MsgCode.IMP011.get());
|
||||
}
|
||||
List<DictionaryDataEntity> dictionaryDataEntities = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.POSITION_TYPE.getDictionaryTypeId());
|
||||
if (StringUtil.isNotEmpty(paginationPosition.getType())) {
|
||||
DictionaryDataEntity dictionaryDataEntity = dictionaryDataEntities.stream().filter(t -> paginationPosition.getType().equals(t.getId())).findFirst().orElse(null);
|
||||
if (dictionaryDataEntity != null) {
|
||||
paginationPosition.setEnCode(dictionaryDataEntity.getEnCode());
|
||||
}
|
||||
}
|
||||
List<PositionEntity> dataList = positionService.getList(paginationPosition);
|
||||
//组织部门
|
||||
List<String> collect = dataList.stream().map(PositionEntity::getOrganizeId).collect(Collectors.toList());
|
||||
List<OrganizeEntity> list = organizeService.getOrgEntityList(collect, true);
|
||||
Map<String, String> orgIdNameMaps = organizeService.getInfoList();
|
||||
|
||||
List<Map<String, Object>> realList = new ArrayList<>();
|
||||
for (PositionEntity entity : dataList) {
|
||||
Map<String, Object> positionMap = JsonUtil.entityToMap(entity);
|
||||
//组织
|
||||
OrganizeEntity organizeEntity = list.stream().filter(t -> t.getId().equals(entity.getOrganizeId())).findFirst().orElse(new OrganizeEntity());
|
||||
if (entity.getOrganizeId().equals(organizeEntity.getId())) {
|
||||
positionMap.put("organizeId", organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/"));
|
||||
}
|
||||
//岗位类型
|
||||
DictionaryDataEntity dictionaryDataEntity = dictionaryDataEntities.stream().filter(t -> t.getEnCode().equals(entity.getType()) && "1".equals(String.valueOf(t.getEnabledMark())) && t.getDeleteMark() == null).findFirst().orElse(null);
|
||||
if (dictionaryDataEntity != null) {
|
||||
positionMap.put("type", dictionaryDataEntity.getFullName());
|
||||
} else {
|
||||
positionMap.put("type", "");
|
||||
}
|
||||
positionMap.put("enabledMark", "1".equals(String.valueOf(entity.getEnabledMark())) ? "启用" : "禁用");
|
||||
realList.add(positionMap);
|
||||
}
|
||||
String[] keys = !StringUtil.isEmpty(paginationPosition.getSelectKey()) ? paginationPosition.getSelectKey() : new String[0];
|
||||
PosColumnMap posColumnMap = new PosColumnMap();
|
||||
String excelName = posColumnMap.getExcelName();
|
||||
List<ExcelColumnAttr> models = posColumnMap.getFieldsModel(false);
|
||||
Map<String, String> keyMap = posColumnMap.getColumnByType(null);
|
||||
ExcelModel excelModel = ExcelModel.builder().selectKey(Arrays.asList(keys)).models(models).optionMap(null).build();
|
||||
DownloadVO vo = ExcelTool.creatModelExcel(configValueUtil.getTemporaryFilePath(), excelName, keyMap, realList, excelModel);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
private void validateImportData(List<Map<String, Object>> listData, List<PositionEntity> addList, List<Map<String, Object>> failList) {
|
||||
PosColumnMap columnMap = new PosColumnMap();
|
||||
Map<String, String> keyMap = columnMap.getColumnByType(0);
|
||||
QueryWrapper<PositionEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().isNull(PositionEntity::getDeleteMark);
|
||||
queryWrapper.lambda().orderByAsc(PositionEntity::getSortCode).orderByDesc(PositionEntity::getCreatorTime);
|
||||
List<PositionEntity> allPositionList = positionService.list(queryWrapper);
|
||||
List<DictionaryDataEntity> typeDictionaryList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.POSITION_TYPE.getDictionaryTypeId());
|
||||
Map<String, Object> allOrgsTreeName = organizeService.getAllOrgsTreeName();
|
||||
for (int i = 0, len = listData.size(); i < len; i++) {
|
||||
Map<String, Object> eachMap = listData.get(i);
|
||||
Map<String, Object> realMap = JsonUtil.getJsonToBean(eachMap, Map.class);
|
||||
StringJoiner errInfo = new StringJoiner(",");
|
||||
boolean checkOrganizeIdPass = false;
|
||||
for (String column : keyMap.keySet()) {
|
||||
Object valueObj = eachMap.get(column);
|
||||
String value = valueObj == null ? null : String.valueOf(valueObj);
|
||||
String columnName = keyMap.get(column);
|
||||
switch (column) {
|
||||
case "organizeId":
|
||||
if (StringUtil.isEmpty(value)) {
|
||||
errInfo.add(columnName + "不能为空");
|
||||
break;
|
||||
}
|
||||
CheckResult organizeIdCheckResult = checkOrganizeId(value, allOrgsTreeName);
|
||||
if (!organizeIdCheckResult.isPass()) {
|
||||
errInfo.add("找不到该所属组织");
|
||||
break;
|
||||
}
|
||||
realMap.put("organizeId", organizeIdCheckResult.getValue());
|
||||
checkOrganizeIdPass = true;
|
||||
break;
|
||||
case "fullName":
|
||||
if (StringUtil.isEmpty(value)) {
|
||||
errInfo.add(columnName + "不能为空");
|
||||
break;
|
||||
}
|
||||
if (value.length() > 50) {
|
||||
errInfo.add(columnName + "值超出最多输入字符限制");
|
||||
}
|
||||
//值不能含有特殊符号
|
||||
if (!RegexUtils.checkSpecoalSymbols(value)) {
|
||||
errInfo.add(columnName + "值不能含有特殊符号");
|
||||
}
|
||||
//组织不通过
|
||||
if (!checkOrganizeIdPass) {
|
||||
break;
|
||||
}
|
||||
String thisOrganizeId = (String) realMap.get("organizeId");
|
||||
//库里重复
|
||||
long fullNameCount = allPositionList.stream().filter(t -> t.getOrganizeId().equals(thisOrganizeId) && t.getFullName().equals(value)).count();
|
||||
if (fullNameCount > 0) {
|
||||
errInfo.add(columnName + "值已存在");
|
||||
break;
|
||||
}
|
||||
//表格内重复
|
||||
fullNameCount = addList.stream().filter(t -> t.getOrganizeId().equals(thisOrganizeId) && t.getFullName().equals(value)).count();
|
||||
if (fullNameCount > 0) {
|
||||
errInfo.add(columnName + "值已存在");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "enCode":
|
||||
if (StringUtil.isEmpty(value)) {
|
||||
errInfo.add(columnName + "不能为空");
|
||||
break;
|
||||
}
|
||||
if (value.length() > 50) {
|
||||
errInfo.add(columnName + "值超出最多输入字符限制");
|
||||
}
|
||||
if(!RegexUtils.checkEnCode(value)){
|
||||
errInfo.add(columnName + "只能输入英文、数字和小数点且小数点不能放在首尾");
|
||||
}
|
||||
//库里重复
|
||||
long enCodeCount = allPositionList.stream().filter(t -> t.getEnCode().equals(value)).count();
|
||||
if (enCodeCount > 0) {
|
||||
errInfo.add(columnName + "值已存在");
|
||||
break;
|
||||
}
|
||||
//表格内重复
|
||||
enCodeCount = addList.stream().filter(t -> t.getEnCode().equals(value)).count();
|
||||
if (enCodeCount > 0) {
|
||||
errInfo.add(columnName + "值已存在");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "type":
|
||||
if (StringUtil.isEmpty(value)) {
|
||||
errInfo.add(columnName + "不能为空");
|
||||
break;
|
||||
}
|
||||
DictionaryDataEntity typeDictionary = typeDictionaryList.stream().filter(t -> t.getFullName().equals(value)).findFirst().orElse(null);
|
||||
if (typeDictionary == null) {
|
||||
errInfo.add("找不到该" + columnName + "值");
|
||||
break;
|
||||
}
|
||||
realMap.put("type", typeDictionary.getEnCode());
|
||||
break;
|
||||
case "sortCode":
|
||||
if (StringUtil.isEmpty(value)) {
|
||||
realMap.put("sortCode", 0);
|
||||
break;
|
||||
}
|
||||
Long numValue = 0l;
|
||||
try {
|
||||
numValue = Long.parseLong(value);
|
||||
} catch (Exception e) {
|
||||
errInfo.add(columnName + "值不正确");
|
||||
break;
|
||||
}
|
||||
if (numValue < 0) {
|
||||
errInfo.add(columnName + "值不能小于0");
|
||||
break;
|
||||
}
|
||||
if (numValue > 1000000) {
|
||||
errInfo.add(columnName + "值不能大于999999");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "enabledMark":
|
||||
if (StringUtil.isEmpty(value)) {
|
||||
errInfo.add(columnName + "不能为空");
|
||||
break;
|
||||
}
|
||||
if ("启用".equals(value)) {
|
||||
realMap.put("enabledMark", 1);
|
||||
} else if ("禁用".equals(value)) {
|
||||
realMap.put("enabledMark", 0);
|
||||
} else {
|
||||
errInfo.add(columnName + "值不正确");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (errInfo.length() == 0) {
|
||||
PositionEntity positionEntity = JsonUtil.getJsonToBean(realMap, PositionEntity.class);
|
||||
positionEntity.setCreatorTime(new Date());
|
||||
addList.add(positionEntity);
|
||||
} else {
|
||||
eachMap.put("errorsInfo", errInfo.toString());
|
||||
failList.add(eachMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private CheckResult checkOrganizeId(String organizeName, Map<String, Object> allOrgsTreeName) {
|
||||
for (String key : allOrgsTreeName.keySet()) {
|
||||
Object o = allOrgsTreeName.get(key);
|
||||
if (organizeName.equals(o.toString())) {
|
||||
String[] split = key.split(",");
|
||||
return new CheckResult(true, null, split[split.length - 1]);
|
||||
}
|
||||
}
|
||||
return new CheckResult(false, "所属组织不正确", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下拉框
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Map<String, String[]> getOptionMap() {
|
||||
Map<String, String[]> optionMap = new HashMap<>();
|
||||
//岗位类型
|
||||
List<DictionaryDataEntity> typeList = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.POSITION_TYPE.getDictionaryTypeId());
|
||||
String[] type = typeList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
|
||||
optionMap.put("type", type);
|
||||
//状态
|
||||
optionMap.put("enabledMark", new String[]{"启用", "禁用"});
|
||||
return optionMap;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,434 @@
|
||||
package com.yunzhupaas.permission.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.annotation.UserPermission;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.util.NoDataSourceBind;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.database.util.TenantDataSourceUtil;
|
||||
import com.yunzhupaas.exception.LoginException;
|
||||
import com.yunzhupaas.permission.entity.SocialsUserEntity;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.model.socails.SocialsUserInfo;
|
||||
import com.yunzhupaas.permission.model.socails.SocialsUserModel;
|
||||
import com.yunzhupaas.permission.model.socails.SocialsUserVo;
|
||||
import com.yunzhupaas.permission.service.SocialsUserService;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.permission.util.socials.AuthCallbackNew;
|
||||
import com.yunzhupaas.permission.util.socials.AuthSocialsUtil;
|
||||
import com.yunzhupaas.permission.util.socials.SocialsAuthEnum;
|
||||
import com.yunzhupaas.permission.util.socials.SocialsConfig;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RedisUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import com.yunzhupaas.util.wxutil.HttpUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.enums.AuthResponseStatus;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import me.zhyd.oauth.utils.AuthStateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 单点登录
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/7/14 10:48:00
|
||||
*/
|
||||
@Tag(name = "第三方登录和绑定", description = "Socials")
|
||||
@RestController
|
||||
@RequestMapping("/api/permission/socials")
|
||||
@Slf4j
|
||||
public class SocialsUserController extends SuperController<SocialsUserService, SocialsUserEntity> {
|
||||
@Autowired
|
||||
private SocialsUserService socialsUserService;
|
||||
@Autowired
|
||||
private AuthSocialsUtil authSocialsUtil;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private SocialsConfig socialsConfig;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*
|
||||
* @param
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取用户授权列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户id")
|
||||
})
|
||||
@GetMapping
|
||||
public ActionResult<List<SocialsUserVo>> getList(@RequestParam(value = "userId", required = false) String userId) {
|
||||
if (StringUtil.isEmpty(userId)) {
|
||||
userId = UserProvider.getUser().getUserId();
|
||||
}
|
||||
List<Map<String, Object>> platformInfos = SocialsAuthEnum.getPlatformInfos();
|
||||
String s = JSONArray.toJSONString(platformInfos);
|
||||
List<SocialsUserVo> socialsUserVos = JsonUtil.getJsonToList(s, SocialsUserVo.class);
|
||||
List<SocialsConfig.Config> config = socialsConfig.getConfig();
|
||||
List<SocialsUserVo> res = new ArrayList<>();
|
||||
if (config == null) {
|
||||
return ActionResult.fail(MsgCode.PS019.get());
|
||||
}
|
||||
config.stream().forEach(item -> {
|
||||
socialsUserVos.stream().forEach(item2 -> {
|
||||
if (item2.getEnname().toLowerCase().equals(item.getProvider())) {
|
||||
res.add(item2);
|
||||
}
|
||||
});
|
||||
});
|
||||
//查询绑定信息
|
||||
List<SocialsUserEntity> listByUserId = socialsUserService.getListByUserId(userId);
|
||||
List<SocialsUserModel> listModel = JsonUtil.getJsonToList(listByUserId, SocialsUserModel.class);
|
||||
res.stream().forEach(item -> {
|
||||
listModel.stream().forEach(item2 -> {
|
||||
if (item.getEnname().equals(item2.getSocialType())) item.setEntity(item2);
|
||||
});
|
||||
});
|
||||
return ActionResult.success(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定:重定向第三方登录页面
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "重定向第三方登录页面")
|
||||
@Parameters({
|
||||
@Parameter(name = "source", description = "地址", required = true)
|
||||
})
|
||||
@GetMapping("/render/{source}")
|
||||
@ResponseBody
|
||||
public ActionResult render(@PathVariable String source) {
|
||||
AuthRequest authRequest = authSocialsUtil.getAuthRequest(source, UserProvider.getUser().getUserId(), false, null, UserProvider.getUser().getTenantId());
|
||||
String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
|
||||
return ActionResult.success(authorizeUrl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置租户库
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/9/8
|
||||
*/
|
||||
private boolean setTenantData(String tenantId, UserInfo userInfo) {
|
||||
try{
|
||||
TenantDataSourceUtil.switchTenant(tenantId);
|
||||
}catch (Exception e){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@UserPermission
|
||||
@Operation(summary = "解绑")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户id"),
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult deleteSocials(@RequestParam(value = "userId",required = false)String userId,@PathVariable("id") String id) {
|
||||
SocialsUserEntity byId = socialsUserService.getById(id);
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
boolean b = socialsUserService.removeById(id);
|
||||
if (b) {
|
||||
//多租户开启-解除绑定
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
String param = "?userId=" + byId.getUserId() + "&tenantId=" + userInfo.getTenantId() + "&socialsType=" + byId.getSocialType();
|
||||
JSONObject object = HttpUtil.httpRequest(configValueUtil.getMultiTenancyUrl() + "socials" + param, "DELETE", null);
|
||||
if (object == null || "500".equals(object.get("code").toString()) || "400".equals(object.getString("code"))) {
|
||||
return ActionResult.fail(MsgCode.PS018.get());
|
||||
}
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.PS018.get());
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/list")
|
||||
@NoDataSourceBind
|
||||
public List<SocialsUserVo> getLoginList(@RequestParam("ticket") String ticket) {
|
||||
if (!socialsConfig.isSocialsEnabled()) return null;
|
||||
List<Map<String, Object>> platformInfos = SocialsAuthEnum.getPlatformInfos();
|
||||
String s = JSONArray.toJSONString(platformInfos);
|
||||
List<SocialsUserVo> socialsUserVos = JsonUtil.getJsonToList(s, SocialsUserVo.class);
|
||||
List<SocialsConfig.Config> config = socialsConfig.getConfig();
|
||||
List<SocialsUserVo> res = new ArrayList<>();
|
||||
config.stream().forEach(item -> {
|
||||
socialsUserVos.stream().forEach(item2 -> {
|
||||
if (item2.getEnname().toLowerCase().equals(item.getProvider())) {
|
||||
AuthRequest authRequest = authSocialsUtil.getAuthRequest(item2.getEnname(), null, true, ticket, null);
|
||||
String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
|
||||
item2.setRenderUrl(authorizeUrl);
|
||||
res.add(item2);
|
||||
}
|
||||
});
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
@GetMapping("/getSocialsUserInfo")
|
||||
@NoDataSourceBind
|
||||
public SocialsUserInfo getSocialsUserInfo(@RequestParam("source") String source, @RequestParam("code") String code,
|
||||
@RequestParam(value = "state", required = false) String state) throws LoginException {
|
||||
//获取第三方请求
|
||||
AuthCallbackNew callback = setAuthCallback(code, state);
|
||||
AuthRequest authRequest = authSocialsUtil.getAuthRequest(source, null, false, null, null);
|
||||
AuthResponse<AuthUser> res = authRequest.login(callback);
|
||||
if(AuthResponseStatus.FAILURE.getCode()==res.getCode()){
|
||||
throw new LoginException("连接失败!");
|
||||
}else if(AuthResponseStatus.SUCCESS.getCode()!=res.getCode()){
|
||||
throw new LoginException("授权失败:"+res.getMsg());
|
||||
}
|
||||
//登录用户第三方id
|
||||
String uuid = getSocialUuid(res);
|
||||
String socialName=StringUtil.isNotEmpty(res.getData().getUsername())?res.getData().getUsername():res.getData().getNickname();
|
||||
SocialsUserInfo socialsUserInfo = getUserInfo(source, uuid, socialName);
|
||||
return socialsUserInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户绑定信息列表
|
||||
* @param
|
||||
* @return
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/9/20
|
||||
*/
|
||||
@NoDataSourceBind
|
||||
public SocialsUserInfo getUserInfo(String source, String uuid, String socialName) throws LoginException {
|
||||
SocialsUserInfo socialsUserInfo=new SocialsUserInfo();
|
||||
UserInfo userInfo=new UserInfo();
|
||||
//查询租户绑定
|
||||
if ("wechat_applets".equals(source)) {
|
||||
source = "wechat_open";
|
||||
}
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
JSONObject object = HttpUtil.httpRequest(configValueUtil.getMultiTenancyUrl() + "socials/list?socialsId=" + uuid, "GET", null);
|
||||
if (object == null || "500".equals(object.get("code").toString()) || "400".equals(object.getString("code"))) {
|
||||
throw new LoginException("租户绑定信息查询错误!");
|
||||
}
|
||||
if ("200".equals(object.get("code").toString())) {
|
||||
JSONArray data = JSONArray.parseArray(object.get("data").toString());
|
||||
int size = data.size();
|
||||
System.out.println(size);
|
||||
if (data == null || data.size() == 0) {
|
||||
socialsUserInfo.setSocialUnionid(uuid);
|
||||
socialsUserInfo.setSocialName(socialName);
|
||||
return socialsUserInfo;
|
||||
} else if (data.size() == 1) {
|
||||
//租户开启时-切换租户库
|
||||
JSONObject oneUser = (JSONObject) data.get(0);
|
||||
setTenantData(oneUser.get("tenantId").toString(), userInfo);
|
||||
List<SocialsUserEntity> list = socialsUserService.getUserIfnoBySocialIdAndType(uuid, source);
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
throw new LoginException("第三方未绑定账号!");
|
||||
}
|
||||
UserEntity infoById = userService.getInfo(list.get(0).getUserId());
|
||||
userInfo = JsonUtil.getJsonToBean(infoById, UserInfo.class);
|
||||
userInfo.setUserId(infoById.getId());
|
||||
userInfo.setUserAccount(oneUser.get("tenantId").toString() + "@" + infoById.getAccount());
|
||||
socialsUserInfo.setTenantUserInfo(data);
|
||||
socialsUserInfo.setUserInfo(userInfo);
|
||||
} else {
|
||||
socialsUserInfo.setTenantUserInfo(data);
|
||||
}
|
||||
}
|
||||
} else {//非多租户
|
||||
//查询绑定
|
||||
List<SocialsUserEntity> list = socialsUserService.getUserIfnoBySocialIdAndType(uuid, source);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
UserEntity infoById = userService.getInfo(list.get(0).getUserId());
|
||||
userInfo = JsonUtil.getJsonToBean(infoById, UserInfo.class);
|
||||
userInfo.setUserId(infoById.getId());
|
||||
userInfo.setUserAccount(infoById.getAccount());
|
||||
socialsUserInfo.setUserInfo(userInfo);
|
||||
} else {
|
||||
socialsUserInfo.setSocialUnionid(uuid);
|
||||
socialsUserInfo.setSocialName(socialName);
|
||||
}
|
||||
}
|
||||
return socialsUserInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@GetMapping("/callback")
|
||||
@ResponseBody
|
||||
@NoDataSourceBind
|
||||
public JSONObject binding(@RequestParam("source") String source,
|
||||
@RequestParam(value = "userId", required = false) String userId,
|
||||
@RequestParam(value = "tenantId", required = false) String tenantId,
|
||||
@RequestParam(value = "code", required = false) String code,
|
||||
@RequestParam(value = "state", required = false) String state) {
|
||||
log.info("进入callback:" + source + " callback params:");
|
||||
//获取第三方请求
|
||||
AuthCallbackNew callback = setAuthCallback(code, state);
|
||||
//租户开启时-切换租户库
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
boolean b = setTenantData(tenantId, new UserInfo());
|
||||
if (!b) {
|
||||
return resultJson(201, "查询租户信息错误!");
|
||||
}
|
||||
|
||||
}
|
||||
//获取第三方请求
|
||||
AuthRequest authRequest = authSocialsUtil.getAuthRequest(source, userId, false, null, null);
|
||||
AuthResponse<AuthUser> res = authRequest.login(callback);
|
||||
log.info(JSONObject.toJSONString(res));
|
||||
if (res.ok()) {
|
||||
String uuid = getSocialUuid(res);
|
||||
List<SocialsUserEntity> userIfnoBySocialIdAndType = socialsUserService.getUserIfnoBySocialIdAndType(uuid, source);
|
||||
if (CollectionUtil.isNotEmpty(userIfnoBySocialIdAndType)) {
|
||||
UserEntity info = userService.getInfo(userIfnoBySocialIdAndType.get(0).getUserId());
|
||||
return resultJson(201, "当前账户已被" + info.getRealName() + "/" + info.getAccount() + "绑定,不能重复绑定");
|
||||
}
|
||||
SocialsUserEntity socialsUserEntity = new SocialsUserEntity();
|
||||
socialsUserEntity.setUserId(userId);
|
||||
socialsUserEntity.setSocialType(source);
|
||||
socialsUserEntity.setSocialName(res.getData().getUsername());
|
||||
socialsUserEntity.setSocialId(uuid);
|
||||
socialsUserEntity.setCreatorTime(new Date());
|
||||
boolean save = socialsUserService.save(socialsUserEntity);
|
||||
|
||||
//租户开启时-添加租户库绑定数据
|
||||
if (configValueUtil.isMultiTenancy() && save) {
|
||||
JSONObject params = (JSONObject) JSONObject.toJSON(socialsUserEntity);
|
||||
UserEntity info = userService.getInfo(userId);
|
||||
params.put("tenantId", tenantId);
|
||||
params.put("account", info.getAccount());
|
||||
params.put("accountName", info.getRealName() + "/" + info.getAccount());
|
||||
JSONObject object = HttpUtil.httpRequest(configValueUtil.getMultiTenancyUrl() + "socials", "POST", params.toJSONString());
|
||||
if (object == null || "500".equals(object.get("code").toString()) || "400".equals(object.getString("code"))) {
|
||||
return resultJson(201, "用户租户绑定错误!");
|
||||
}
|
||||
}
|
||||
return resultJson(200, "绑定成功!");
|
||||
|
||||
}
|
||||
return resultJson(201, "第三方回调失败!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置第三方code state参数
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/9/8
|
||||
*/
|
||||
private AuthCallbackNew setAuthCallback(String code, String state) {
|
||||
AuthCallbackNew callback = new AuthCallbackNew();
|
||||
callback.setAuthCode(code);
|
||||
callback.setAuth_code(code);
|
||||
callback.setAuthorization_code(code);
|
||||
callback.setCode(code);
|
||||
callback.setState(state);
|
||||
return callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回json
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/9/8
|
||||
*/
|
||||
private JSONObject resultJson(int code, String message) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("code", code);
|
||||
jsonObject.put("message", message);
|
||||
return jsonObject;
|
||||
}
|
||||
private String getSocialUuid(AuthResponse<AuthUser> res) {
|
||||
String uuid = res.getData().getUuid();
|
||||
if (res.getData().getToken() != null && StringUtil.isNotEmpty(res.getData().getToken().getUnionId())) {
|
||||
uuid = res.getData().getToken().getUnionId();
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@GetMapping("/loginbind")
|
||||
@ResponseBody
|
||||
@NoDataSourceBind
|
||||
public void loginAutoBinding(@RequestParam("socialType") String socialType,
|
||||
@RequestParam("socialUnionid") String socialUnionid,
|
||||
@RequestParam("socialName") String socialName,
|
||||
@RequestParam("userId") String userId,
|
||||
@RequestParam(value = "tenantId", required = false) String tenantId) {
|
||||
//查询租户绑定
|
||||
if ("wechat_applets".equals(socialType)) {
|
||||
socialType = "wechat_open";
|
||||
}
|
||||
//租户开启时-切换租户库
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
setTenantData(tenantId, new UserInfo());
|
||||
}
|
||||
List<SocialsUserEntity> list = socialsUserService.getListByUserIdAndSource(userId, socialType);
|
||||
if(CollectionUtil.isNotEmpty(list)){//账号已绑定该第三方其他账号,则不绑定
|
||||
return;
|
||||
}
|
||||
SocialsUserEntity socialsUserEntity = new SocialsUserEntity();
|
||||
socialsUserEntity.setUserId(userId);
|
||||
socialsUserEntity.setSocialType(socialType);
|
||||
socialsUserEntity.setSocialName(socialName);
|
||||
socialsUserEntity.setSocialId(socialUnionid);
|
||||
socialsUserEntity.setCreatorTime(new Date());
|
||||
boolean save = socialsUserService.save(socialsUserEntity);
|
||||
//租户开启时-添加租户库绑定数据
|
||||
if (configValueUtil.isMultiTenancy() && save) {
|
||||
JSONObject params = (JSONObject) JSONObject.toJSON(socialsUserEntity);
|
||||
UserEntity info = userService.getInfo(userId);
|
||||
params.put("tenantId", tenantId);
|
||||
params.put("account", info.getAccount());
|
||||
params.put("accountName", info.getRealName() + "/" + info.getAccount());
|
||||
JSONObject object = HttpUtil.httpRequest(configValueUtil.getMultiTenancyUrl() + "socials", "POST", params.toJSONString());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,104 @@
|
||||
package com.yunzhupaas.permission.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.annotation.UserPermission;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.constant.PermissionConst;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.entity.UserRelationEntity;
|
||||
import com.yunzhupaas.permission.model.userrelation.UserRelationForm;
|
||||
import com.yunzhupaas.permission.model.userrelation.UserRelationIdsVO;
|
||||
import com.yunzhupaas.permission.service.UserRelationService;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户关系
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024-09-26 上午9:18
|
||||
*/
|
||||
@Tag(name = "用户关系", description = "UserRelation")
|
||||
@RestController
|
||||
@RequestMapping("/api/permission/UserRelation")
|
||||
public class UserRelationController extends SuperController<UserRelationService, UserRelationEntity> {
|
||||
|
||||
@Autowired
|
||||
private UserRelationService userRelationService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param objectId 对象主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取岗位/角色/门户成员列表ids")
|
||||
@Parameters({
|
||||
@Parameter(name = "objectId", description = "对象主键", required = true)
|
||||
})
|
||||
@SaCheckPermission(value = {"permission.authorize", "permission.position", "permission.role"}, mode = SaMode.OR)
|
||||
@GetMapping("/{objectId}")
|
||||
public ActionResult<UserRelationIdsVO> listTree(@PathVariable("objectId") String objectId) {
|
||||
List<UserRelationEntity> data = userRelationService.getListByObjectId(objectId);
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (UserRelationEntity entity : data) {
|
||||
ids.add(entity.getUserId());
|
||||
}
|
||||
UserRelationIdsVO vo = new UserRelationIdsVO();
|
||||
vo.setIds(ids);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @param objectId 对象主键
|
||||
* @param userRelationForm 页面数据
|
||||
* @return
|
||||
*/
|
||||
@UserPermission
|
||||
@Operation(summary = "添加岗位或角色成员")
|
||||
@Parameters({
|
||||
@Parameter(name = "objectId", description = "对象主键", required = true),
|
||||
@Parameter(name = "userRelationForm", description = "页面数据", required = true)
|
||||
})
|
||||
@SaCheckPermission(value = {"permission.authorize", "permission.position", "permission.role"}, mode = SaMode.OR)
|
||||
@PostMapping("/{objectId}")
|
||||
public ActionResult save(@PathVariable("objectId") String objectId, @RequestBody UserRelationForm userRelationForm) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
// 得到禁用的id
|
||||
List<UserRelationEntity> listByObjectId = userRelationService.getListByObjectId(objectId, userRelationForm.getObjectType());
|
||||
List<String> collect = listByObjectId.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
|
||||
//删除的用户
|
||||
List<String> collect1 = collect.stream().filter(t -> !userRelationForm.getUserIds().contains(t)).collect(Collectors.toList());
|
||||
//添加的用户
|
||||
List<String> collect2 = userRelationForm.getUserIds().stream().filter(t -> !collect.contains(t)).collect(Collectors.toList());
|
||||
userIds.addAll(collect1);
|
||||
userIds.addAll(collect2);
|
||||
Set<String> set = new HashSet<>(userRelationForm.getUserIds());
|
||||
set.addAll(userService.getUserList(collect).stream().map(UserEntity::getId).collect(Collectors.toList()));
|
||||
List<String> list = new ArrayList<>(set);
|
||||
userRelationForm.setUserIds(list);
|
||||
userRelationService.saveObjectId(objectId,userRelationForm);
|
||||
return ActionResult.success(MsgCode.SU002.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user