2021-04-20 机构授权
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package com.hcframe.user.module.auth.controller;
|
||||
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.user.module.auth.service.RoleDeptService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Li Xinlei
|
||||
* @version 1.0
|
||||
* @className RoleDeptController
|
||||
* @date 2021-4-20 17:15:09
|
||||
* @description 描述
|
||||
*/
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/roleDept")
|
||||
@Api(tags="机构授权")
|
||||
public class RoleDeptController {
|
||||
|
||||
final RoleDeptService roleDeptService;
|
||||
|
||||
public RoleDeptController(RoleDeptService roleDeptService) {
|
||||
this.roleDeptService = roleDeptService;
|
||||
}
|
||||
|
||||
@PostMapping("role")
|
||||
public ResultVO<Object> roleDeptBind(String deptId, String roleIds) {
|
||||
return roleDeptService.roleDeptBind(deptId,roleIds);
|
||||
}
|
||||
|
||||
@GetMapping("role")
|
||||
public ResultVO<Object> getDeptRole(String deptId) {
|
||||
return roleDeptService.getDeptRole(deptId);
|
||||
}
|
||||
|
||||
@PostMapping("roleGroup")
|
||||
public ResultVO<Object> roleGroupBind(String deptId, String groupIds) {
|
||||
return roleDeptService.roleGroupBind(deptId,groupIds);
|
||||
}
|
||||
|
||||
@GetMapping("roleGroup")
|
||||
public ResultVO<Object> getDeptGroup(String deptId) {
|
||||
return roleDeptService.getDeptGroup(deptId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.hcframe.user.module.auth.service;
|
||||
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Li Xinlei
|
||||
* @version 1.0
|
||||
* @className RoleDeptService
|
||||
* @date 2021-4-20 17:16:50
|
||||
* @description 描述
|
||||
*/
|
||||
|
||||
public interface RoleDeptService {
|
||||
ResultVO<Object> roleDeptBind(String deptId, String roleIds);
|
||||
|
||||
ResultVO<Object> roleGroupBind(String deptId, String groupIds);
|
||||
|
||||
ResultVO<Object> getDeptRole(String deptId);
|
||||
|
||||
ResultVO<Object> getDeptGroup(String deptId);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.hcframe.user.module.auth.service.impl;
|
||||
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.common.utils.JudgeException;
|
||||
import com.hcframe.base.module.data.module.BaseMapper;
|
||||
import com.hcframe.base.module.data.module.BaseMapperImpl;
|
||||
import com.hcframe.base.module.data.module.Condition;
|
||||
import com.hcframe.base.module.data.service.TableService;
|
||||
import com.hcframe.base.module.tableconfig.entity.OsSysTable;
|
||||
import com.hcframe.user.module.auth.service.RoleDeptService;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Li Xinlei
|
||||
* @version 1.0
|
||||
* @className RoleDeptServiceImpl
|
||||
* @date 2021-4-20 17:24:17
|
||||
* @description 描述
|
||||
*/
|
||||
@Service
|
||||
public class RoleDeptServiceImpl implements RoleDeptService {
|
||||
|
||||
private static final String OS_REL_DEPT_ROLE = "OS_REL_DEPT_ROLE";
|
||||
private static final String DEPT_GROUP_ID = "DEPT_GROUP_ID";
|
||||
private static final String DEPT_ROLE_ID = "DEPT_ROLE_ID";
|
||||
private static final String OS_REL_DEPT_GROUP = "OS_REL_DEPT_GROUP";
|
||||
private static final String COMMA = ",";
|
||||
|
||||
final BaseMapper baseMapper;
|
||||
|
||||
final TableService tableService;
|
||||
|
||||
public RoleDeptServiceImpl(@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper,
|
||||
TableService tableService) {
|
||||
this.baseMapper = baseMapper;
|
||||
this.tableService = tableService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultVO<Object> roleDeptBind(String deptId, String roleIds) {
|
||||
JudgeException.isNull(deptId,"deptId 不能为空");
|
||||
OsSysTable osSysTable = OsSysTable.builder().tableName(OS_REL_DEPT_ROLE).tablePk(DEPT_ROLE_ID).build();
|
||||
Condition condition = Condition.creatCriteria().andEqual("DEPT_ID",deptId).build();
|
||||
baseMapper.deleteByCondition(OS_REL_DEPT_ROLE, condition);
|
||||
if (!StringUtils.isEmpty(roleIds)) {
|
||||
for (String roleId : roleIds.split(COMMA)) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("DEPT_ID", deptId.replaceAll("\"",""));
|
||||
map.put("ROLE_ID", Integer.parseInt(roleId));
|
||||
tableService.save(osSysTable, map);
|
||||
}
|
||||
}
|
||||
return ResultVO.getSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultVO<Object> roleGroupBind(String deptId, String groupIds) {
|
||||
JudgeException.isNull(deptId,"deptId 不能为空");
|
||||
Condition condition = Condition.creatCriteria().andEqual("DEPT_ID",deptId).build();
|
||||
baseMapper.deleteByCondition(OS_REL_DEPT_GROUP, condition);
|
||||
OsSysTable osSysTable = OsSysTable.builder().tableName(OS_REL_DEPT_GROUP).tablePk(DEPT_GROUP_ID).build();
|
||||
if (!StringUtils.isEmpty(groupIds)) {
|
||||
for (String groupId : groupIds.split(COMMA)) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("DEPT_ID", deptId.replaceAll("\"",""));
|
||||
map.put("GROUP_ID", groupId);
|
||||
tableService.save(osSysTable, map);
|
||||
}
|
||||
}
|
||||
return ResultVO.getSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<Object> getDeptRole(String deptId) {
|
||||
Condition condition = Condition.creatCriteria().andEqual("DEPT_ID",deptId).build();
|
||||
List<Map<String,Object>> list = baseMapper.selectByCondition(OS_REL_DEPT_ROLE, condition);
|
||||
return ResultVO.getSuccess(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<Object> getDeptGroup(String deptId) {
|
||||
Condition condition = Condition.creatCriteria().andEqual("DEPT_ID",deptId).build();
|
||||
List<Map<String,Object>> list = baseMapper.selectByCondition(OS_REL_DEPT_GROUP, condition);
|
||||
return ResultVO.getSuccess(list);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user