|
|
@@ -11,11 +11,7 @@ import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
|
-import com.sckw.system.api.model.dto.res.UserAccessMenuInfoResDto;
|
|
|
-import com.sckw.system.dao.KwsAuthorityDao;
|
|
|
-import com.sckw.system.dao.KwsRoleDao;
|
|
|
-import com.sckw.system.dao.KwsUserDeptDao;
|
|
|
-import com.sckw.system.dao.KwsUserRoleDao;
|
|
|
+import com.sckw.system.dao.*;
|
|
|
import com.sckw.system.model.*;
|
|
|
import com.sckw.system.model.pojo.FindMenuTreePojo;
|
|
|
import com.sckw.system.model.vo.req.AddRoleReqVo;
|
|
|
@@ -29,7 +25,6 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 角色service接口
|
|
|
@@ -52,11 +47,14 @@ public class KwsRoleService {
|
|
|
KwsUserDeptDao kwsUserDeptDao;
|
|
|
|
|
|
@Autowired
|
|
|
- KwsDeptService kwsDeptService;
|
|
|
+ KwsDeptDao kwsDeptDao;
|
|
|
|
|
|
@Autowired
|
|
|
KwsMenuService kwsMenuService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ KwsMenuRightsDao kwsMenuRightsDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
CustomConfig customConfig;
|
|
|
|
|
|
@@ -97,7 +95,7 @@ public class KwsRoleService {
|
|
|
/*2、绑定菜单功能*/
|
|
|
KwsDept kwsDept = new KwsDept();
|
|
|
kwsDept.setId(reqVo.getCurrentDeptId());
|
|
|
- List<KwsDeptResVo> list = kwsDeptService.findList(kwsDept);
|
|
|
+ List<KwsDeptResVo> list = kwsDeptDao.findList(kwsDept);
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
|
|
|
}
|
|
|
@@ -112,11 +110,16 @@ public class KwsRoleService {
|
|
|
//只能看见自己的数据则不管
|
|
|
return idResVo;
|
|
|
}
|
|
|
- String[] deptIds = reqVo.getDeptIds().split(",");
|
|
|
+
|
|
|
+ String deptIds = reqVo.getDeptIds();
|
|
|
+ if (StringUtils.isBlank(deptIds)) {
|
|
|
+ return idResVo;
|
|
|
+ }
|
|
|
+ String[] deptIdArr = deptIds.split(",");
|
|
|
List<KwsAuthority> kwsAuthorities = new ArrayList<>();
|
|
|
Long userId = LoginUserHolder.getUserId();
|
|
|
Date date = new Date();
|
|
|
- for (String deptId : deptIds) {
|
|
|
+ for (String deptId : deptIdArr) {
|
|
|
KwsAuthority kwsAuthority = new KwsAuthority();
|
|
|
kwsAuthority.setRoleId(roleId);
|
|
|
kwsAuthority.setDeptId(Long.parseLong(deptId));
|
|
|
@@ -136,19 +139,36 @@ public class KwsRoleService {
|
|
|
return idResVo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param deptIdList 机构id集合
|
|
|
+ * @desc: 根据机构删除角色信息
|
|
|
+ * @author: czh
|
|
|
+ * @date: 2023/6/25
|
|
|
+ */
|
|
|
+ public void deleteByDeptIds(List<Long> deptIdList) throws Exception {
|
|
|
+ List<KwsRole> kwsRoles = kwsRoleDao.selectBatchByDeptIds(deptIdList);
|
|
|
+ if (CollectionUtils.isEmpty(kwsRoles)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ deleteRole(kwsRoles);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 删除记录-根据主键
|
|
|
* @param ids 主键
|
|
|
- * @return HttpResult
|
|
|
*/
|
|
|
public void deleteByKey(String ids) throws Exception {
|
|
|
- /*1.数据校验*/
|
|
|
- List<Long> idList = Arrays.asList(ids.split(",")).stream().map(Long::parseLong).toList();
|
|
|
+
|
|
|
+ List<Long> idList = Arrays.stream(ids.split(",")).map(Long::parseLong).toList();
|
|
|
List<KwsRole> kwsRoles = kwsRoleDao.selectBatchByKeys(idList);
|
|
|
if (CollectionUtils.isEmpty(kwsRoles)) {
|
|
|
throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
|
|
|
}
|
|
|
|
|
|
+ deleteRole(kwsRoles);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteRole(List<KwsRole> kwsRoles) throws Exception {
|
|
|
/*2、删角色*/
|
|
|
for (KwsRole kwsRole : kwsRoles) {
|
|
|
kwsRole.setDelFlag(Global.YES);
|
|
|
@@ -157,8 +177,22 @@ public class KwsRoleService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //todo
|
|
|
- /*3、用户绑定关系怎么办?*/
|
|
|
+ /*3、删用户角色关系*/
|
|
|
+ List<Long> idList = kwsRoles.stream().map(KwsRole::getId).toList();
|
|
|
+ List<KwsUserRole> kwsUserRoleList = kwsUserRoleDao.findAllByRoleIds(idList);
|
|
|
+ if (CollectionUtils.isEmpty(kwsUserRoleList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KwsUserRole kwsUserRole : kwsUserRoleList) {
|
|
|
+ kwsUserRole.setDelFlag(Global.YES);
|
|
|
+ if (kwsUserRoleDao.update(kwsUserRole) <= 0) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.DELETE_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*4、删除角色菜单关系*/
|
|
|
+ kwsMenuService.deleteMenuRightsByRoleIds(idList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -259,7 +293,9 @@ public class KwsRoleService {
|
|
|
kwsUserDept.setDelFlag(Global.NO);
|
|
|
kwsUserDeptList.add(kwsUserDept);
|
|
|
});
|
|
|
- kwsDeptService.addUserDept(kwsUserDeptList);
|
|
|
+ if (kwsUserDeptDao.saveBatch(kwsUserDeptList) < kwsUserDeptList.size()) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
|
|
|
+ }
|
|
|
|
|
|
/*4、后置处理,修改redis中的信息*/
|
|
|
FindMenuTreePojo findMenuTreePojo = new FindMenuTreePojo();
|