123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- package com.dragoninfo.dcuc.authweb.restcontroller.auth;
- import com.alibaba.fastjson.JSON;
- import com.dragoninfo.dcuc.auth.auth.entity.RoleInfo;
- import com.dragoninfo.dcuc.auth.auth.entity.StaffAssignAuthInfo;
- import com.dragoninfo.dcuc.auth.auth.facade.IRoleInfoFacade;
- import com.dragoninfo.dcuc.auth.auth.facade.IStaffAssignAuthInfoFacade;
- import com.dragoninfo.dcuc.auth.auth.vo.RoleInfoVO;
- import com.dragoninfo.dcuc.auth.auth.vo.RsGridCheckedVO;
- import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.rolemanage.RoleOperateApplyVo;
- import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.RoleFunRsRlVo;
- import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.RoleInfoVo;
- import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.RoleQuotaVo;
- import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.StaffAssignAuthInfoVo;
- import com.dragoninfo.dcuc.common.utils.ResponseUtil;
- import com.dragoninfo.duceap.core.response.Result;
- import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
- import com.dragonsoft.duceap.base.entity.search.SearchDTO;
- import com.dragonsoft.duceap.base.entity.security.SecurityUser;
- import com.dragonsoft.duceap.base.enums.BooleanEnum;
- import com.dragonsoft.duceap.base.utils.UserContextUtils;
- import com.dragonsoft.duceap.commons.util.string.StringUtils;
- import com.dragonsoft.duceap.core.context.ContextUtils;
- import com.dragonsoft.duceap.core.search.Searchable;
- import com.dragonsoft.duceap.core.search.enums.SearchOperator;
- import com.dragonsoft.duceap.core.search.filter.Condition;
- import com.dragonsoft.duceap.web.annotation.Permission;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.domain.Page;
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.*;
- import javax.validation.Valid;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- @Api(tags = {"授权模块-角色管理接口"})
- @RestController
- @RequestMapping(value = "authsvr/v2/roleinfo")
- public class RoleInfoController {
- private static Logger logger = LoggerFactory.getLogger(RoleInfoController.class);
- @Autowired
- private IRoleInfoFacade roleInfoFacade;
- @Autowired
- private IStaffAssignAuthInfoFacade iStaffAssignAuthInfoFacade;
- @ApiOperation(value = "角色新增、修改、删除操作申请")
- @PostMapping("role-operate-apply")
- public Result<Object> roleOperateApply(@Valid @RequestBody RoleOperateApplyVo roleOperateApplyVo) {
- ResponseDTO<Object> responseDTO = roleInfoFacade.roleOperateApply(roleOperateApplyVo);
- if (ResponseUtil.isSuccess(responseDTO)) {
- return Result.success();
- } else {
- return Result.failMessage(responseDTO.getMessage());
- }
- }
- /**
- * 角色列表
- *
- * @param searchDTO
- * @return
- */
- @ApiOperation(value = "角色列表")
- @ApiImplicitParam(name = "searchable", value = "查询条件,app_id_eq不能为空")
- @PostMapping(value = "roleList/_search")
- public Result<List<RoleInfoVO>> roleList(SearchDTO searchDTO) {
- Page<RoleInfoVO> roleInfoVOPage = roleInfoFacade.page(searchDTO);
- return Result.success(roleInfoVOPage.getTotalElements(), roleInfoVOPage.getContent());
- }
- /**
- * 保存菜单,功能
- *
- * @return
- */
- @ApiOperation(value = "保存菜单")
- @Permission(value = "power_config")
- @PostMapping(value = "/rsGrid", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Result saveRsGrid(@RequestBody RoleFunRsRlVo roleFunRsRlVo) {
- Result result;
- try {
- //TODO
- //DTO暂未设计,沿用原来的接口参数,后期修改
- String roleId = roleFunRsRlVo.getRoleId();
- String rsGridList = JSON.toJSONString(roleFunRsRlVo.getRsGridLists());
- roleInfoFacade.saveRsGrid(rsGridList, roleId);
- result = Result.success("保存成功");
- } catch (Exception e) {
- logger.error("saveRsGrid error:{}", e);
- result = Result.fail("保存异常");
- }
- return result;
- }
- /**
- * 查看角色信息
- *
- * @param id
- * @return
- */
- @ApiOperation(value = "查看角色信息")
- @ApiImplicitParams({@ApiImplicitParam(paramType = "path", name = "id", value = "角色ID", required = true
- , example = "40288a8b699fc2500169a33b20540000")})
- @GetMapping(value = "/role/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Result<RoleInfoVo> roleInfo(@PathVariable("id") String id) {
- RoleInfo roleInfo = roleInfoFacade.get(id);
- if (null == roleInfo) {
- return Result.failMessage("角色不存在");
- }
- RoleInfoVo vo = new RoleInfoVo();
- BeanUtils.copyProperties(roleInfo, vo);
- return Result.success(vo);
- }
- /**
- * 保存角色
- *
- * @param roleInfoVo
- * @return
- */
- @ApiOperation(value = "保存角色信息")
- @Permission(value = "power_config")
- @PostMapping(value = "/role", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Result saveRole(@RequestBody RoleInfoVo roleInfoVo) {
- Result result;
- try {
- if (!StringUtils.isEmpty(roleInfoVo.getDetail()) && (roleInfoVo.getDetail().trim().length() > 40 || roleInfoVo.getDetail().trim().getBytes().length > 120)) {
- result = Result.fail("角色描述不能超过40个字");
- return result;
- }
- Searchable searchable = Searchable.newSearchable();
- searchable.addSearchFilter("code", SearchOperator.eq, roleInfoVo.getCode());
- if (StringUtils.isNotEmpty(roleInfoVo.getId())) {
- searchable.addSearchFilter("id", SearchOperator.ne, roleInfoVo.getId());
- }
- List<RoleInfo> list = roleInfoFacade.roleList(searchable.toSearchDTO());
- if (list != null && list.size() > 0) {
- return Result.failMessage("角色代码已被使用");
- }
- SecurityUser user = UserContextUtils.getCurrentUser();
- roleInfoVo.setInitNumber(0);
- roleInfoVo.setCreator(user.getId());
- roleInfoVo.setIsActive(BooleanEnum.TRUE.getValue());
- roleInfoVo.setPoliceCategory(StringUtils.isEmpty(roleInfoVo.getPoliceCategory()) ? null : roleInfoVo.getPoliceCategory());
- roleInfoVo.setCreateTime(new Date());
- //TODO
- //DTO暂未设计,沿用原来的接口参数,后期修改
- RoleInfo roleInfo = new RoleInfo();
- BeanUtils.copyProperties(roleInfoVo, roleInfo);
- roleInfoFacade.save(roleInfo);
- result = Result.success("保存成功");
- } catch (Exception e) {
- logger.error("", e);
- result = Result.fail("保存失败");
- }
- return result;
- }
- /**
- * 修改角色
- *
- * @param roleInfoVo
- * @return
- */
- @ApiOperation(value = "修改角色信息")
- @Permission(value = "power_config")
- @PutMapping(value = "/role", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Result updateRole(@RequestBody RoleInfoVo roleInfoVo) {
- Result result;
- try {
- if (!StringUtils.isEmpty(roleInfoVo.getDetail()) && (roleInfoVo.getDetail().trim().length() > 40 || roleInfoVo.getDetail().trim().getBytes().length > 120)) {
- result = Result.fail("角色描述不能超过40个字");
- return result;
- }
- Searchable searchable = Searchable.newSearchable();
- searchable.addSearchFilter("code", SearchOperator.eq, roleInfoVo.getCode());
- if (StringUtils.isNotEmpty(roleInfoVo.getId())) {
- searchable.addSearchFilter("id", SearchOperator.ne, roleInfoVo.getId());
- }
- List<RoleInfo> list = roleInfoFacade.roleList(searchable.toSearchDTO());
- if (list != null && list.size() > 0) {
- return Result.fail("角色代码已被使用");
- }
- RoleInfo role_info = roleInfoFacade.get(roleInfoVo.getId());
- role_info.setCode(roleInfoVo.getCode());
- role_info.setName(roleInfoVo.getName());
- role_info.setRoleLevel(roleInfoVo.getRoleLevel());
- role_info.setDetail(roleInfoVo.getDetail());
- role_info.setModifier(ContextUtils.getUserInfo().getName());
- role_info.setModifiedTime(new Date());
- role_info.setPoliceCategory(StringUtils.isEmpty(roleInfoVo.getPoliceCategory()) ? null : roleInfoVo.getPoliceCategory());
- role_info.setRoleBusiness(roleInfoVo.getRoleBusiness());
- role_info.setIsNotLimitCount(roleInfoVo.getIsNotLimitCount());
- role_info.setRoleCategory(roleInfoVo.getRoleCategory());
- roleInfoFacade.update(role_info);
- result = Result.success("保存成功");
- } catch (Exception e) {
- logger.error("", e);
- result = Result.fail("保存失败");
- }
- return result;
- }
- /**
- * 删除角色
- *
- * @param id 角色id
- * @return
- */
- @ApiOperation(value = "删除角色信息")
- @ApiImplicitParams({@ApiImplicitParam(paramType = "path", name = "id", value = "角色ID", required = true
- , example = "40288a8b699fc2500169a33b20540000")})
- @Permission(value = "power_config")
- @DeleteMapping(value = "/role/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Result deleteRole(@PathVariable("id") String id) {
- Result result;
- try {
- //删除角色信息
- roleInfoFacade.delete(id);
- //删除角色相关表的信息
- roleInfoFacade.delAllRolesInfo(id);
- result = Result.success("删除成功");
- } catch (Exception e) {
- logger.error("delete role error:{}", e);
- result = Result.fail("删除异常");
- }
- return result;
- }
- /**
- * 根据角色获取选中菜单、功能
- *
- * @param roleId 角色id
- * @return
- */
- @ApiOperation(value = "根据角色获取选中菜单、功能")
- @ApiImplicitParam(name = "roleId", value = "角色id", required = true)
- @GetMapping(value = "/checked/{roleId}")
- public Result<List<RsGridCheckedVO>> checked(@PathVariable("roleId") String roleId) {
- List<RsGridCheckedVO> rsGridCheckedVOList = roleInfoFacade.getRsGridChecked(roleId);
- return Result.success(rsGridCheckedVOList);
- }
- /**
- * 获取角色配额授权情况列表
- *
- * @param searchDTO
- * @return
- */
- @ApiOperation(value = "获取角色配额授权情况列表")
- @ApiImplicitParam(name = "searchDTO", value = "查询条件,applicationId不能为空", required = true)
- @PostMapping(value = "/roleQuotaList/_search")
- public Result<List<RoleInfoVO>> getRoleQuotaList(SearchDTO searchDTO) {
- Searchable searchable = Searchable.toSearchable(searchDTO);
- Condition condition = searchable.getSearchFilterByKey("applicationId_eq");
- if (null == condition) return Result.fail("400", "applicationId 不能为空");
- String applicationId = (String) condition.getValue();
- if (StringUtils.isBlank(applicationId)){
- return Result.fail("400", "applicationId 不能为空");
- }
- Page<RoleInfoVO> page = roleInfoFacade.getRoleQuotaList(searchDTO);
- return Result.success(page.getTotalElements(), page.getContent());
- }
- /**
- * 获取应用有限配额的角色列表
- *
- * @param searchDTO
- * @return
- */
- @ApiOperation(value = "获取应用有限配额的角色列表")
- @ApiImplicitParam(name = "searchDTO", value = "查询条件,applicationId不能为空", required = true)
- @PostMapping(value = "/orgQuotoAuthInfo/_search")
- public Result<List<RoleInfoVO>> getOrgQuotoAuthInfo(SearchDTO searchDTO) {
- Searchable searchable = Searchable.toSearchable(searchDTO);
- Condition condition = searchable.getSearchFilterByKey("applicationId_eq");
- if (null == condition) {
- return Result.fail("400", "applicationId 不能为空");
- }
- String applicationId = (String) condition.getValue();
- if (StringUtils.isBlank(applicationId)) {
- return Result.fail("400", "applicationId 不能为空");
- }
- Condition roleLevel_eq = searchable.getSearchFilterByKey("roleLevel_eq");
- if (roleLevel_eq != null) {
- searchable.removeSearchFilter("roleLevel_eq");
- searchable.addSearchFilter("role_level", SearchOperator.eq, roleLevel_eq.getValue());
- }
- searchable.addSearchFilter("is_not_limit_count", SearchOperator.eq, BooleanEnum.TRUE.value);
- Page<RoleInfoVO> page = roleInfoFacade.getQuotoRoles(searchable.toSearchDTO());
- return Result.success(page.getTotalElements(), page.getContent());
- }
- /**
- * 角色初始配额信息保存
- *
- * @return
- */
- @ApiOperation(value = "角色初始配额信息保存")
- @Permission(value = "quota_init")
- @PostMapping(value = "/roleQuota", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Result roleQuotaSave(@RequestBody List<RoleQuotaVo> roleQuotaList) {
- Result result;
- try {
- String listStr = JSON.toJSONString(roleQuotaList);
- roleInfoFacade.roleQuotaSave(listStr);
- result = Result.success("保存成功");
- } catch (Exception e) {
- logger.error("role quota save error:{}", e);
- result = Result.fail(e.getMessage());
- }
- return result;
- }
- /**
- * 用户角色列表
- *
- * @param searchDTO
- * @return
- */
- @ApiOperation(value = "用户角色列表")
- @ApiImplicitParam(name = "searchDTO", value = "查询条件,staffId不能为空 ", required = true)
- @PostMapping(value = "/userRole/_search")
- public Result<List<StaffAssignAuthInfoVo>> userRole(SearchDTO searchDTO) {
- Searchable searchable = Searchable.toSearchable(searchDTO);
- String staffId = (String) searchable.getSearchFilterByKey("staffId_eq").getValue();
- if (StringUtils.isBlank(staffId)) {
- return Result.fail("300", "staffId 不能为空");
- }
- Page<StaffAssignAuthInfo> page = iStaffAssignAuthInfoFacade.findForPage(searchable.toSearchDTO());
- List<StaffAssignAuthInfoVo> vos = new ArrayList<>();
- for (StaffAssignAuthInfo source : page.getContent()) {
- StaffAssignAuthInfoVo vo = new StaffAssignAuthInfoVo();
- BeanUtils.copyProperties(source, vo);
- }
- return Result.success(page.getTotalElements(), vos);
- }
- }
|