|
|
@@ -10,21 +10,26 @@ import com.sckw.core.web.config.CustomConfig;
|
|
|
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.model.*;
|
|
|
+import com.sckw.system.model.pojo.FindMenuTreePojo;
|
|
|
import com.sckw.system.model.vo.req.AddRoleReqVo;
|
|
|
import com.sckw.system.model.vo.req.RoleBindMeunReqVo;
|
|
|
import com.sckw.system.model.vo.req.UserBindRoleReqVo;
|
|
|
import com.sckw.system.model.vo.res.IdResVo;
|
|
|
import com.sckw.system.model.vo.res.KwsDeptResVo;
|
|
|
+import com.sckw.system.model.vo.res.KwsMenuResVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 角色service接口
|
|
|
@@ -43,11 +48,14 @@ public class KwsRoleService {
|
|
|
@Autowired
|
|
|
KwsAuthorityDao kwsAuthorityDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ KwsUserDeptDao kwsUserDeptDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
KwsDeptService kwsDeptService;
|
|
|
|
|
|
@Autowired
|
|
|
- KwsMenuService kwsMenuServicel;
|
|
|
+ KwsMenuService kwsMenuService;
|
|
|
|
|
|
@Autowired
|
|
|
CustomConfig customConfig;
|
|
|
@@ -97,7 +105,7 @@ public class KwsRoleService {
|
|
|
roleBindMeunReqVo.setRoleId(roleId);
|
|
|
roleBindMeunReqVo.setEntId(list.get(0).getEntId());
|
|
|
roleBindMeunReqVo.setMenuIds(reqVo.getMenuIds());
|
|
|
- kwsMenuServicel.roleBindMeun(roleBindMeunReqVo);
|
|
|
+ kwsMenuService.roleBindMeun(roleBindMeunReqVo);
|
|
|
|
|
|
/*3、设置数据权限*/
|
|
|
if (reqVo.getVisiblePersonal()) {
|
|
|
@@ -133,22 +141,24 @@ public class KwsRoleService {
|
|
|
* @param ids 主键
|
|
|
* @return HttpResult
|
|
|
*/
|
|
|
- public HttpResult deleteByKey(String ids) throws Exception {
|
|
|
+ public void deleteByKey(String ids) throws Exception {
|
|
|
/*1.数据校验*/
|
|
|
- if (StringUtils.isBlank(ids)) {
|
|
|
- return HttpResult.error("请选择您要删除的角色信息!");
|
|
|
+ List<Long> idList = Arrays.asList(ids.split(",")).stream().map(Long::parseLong).toList();
|
|
|
+ List<KwsRole> kwsRoles = kwsRoleDao.selectBatchByKeys(idList);
|
|
|
+ if (CollectionUtils.isEmpty(kwsRoles)) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
|
|
|
}
|
|
|
|
|
|
- int resultCode = 0;
|
|
|
- String[] idArray = ids.split(",");
|
|
|
- for (String id : idArray) {
|
|
|
- KwsRole kwsRole = kwsRoleDao.selectByKey(Long.parseLong(id));
|
|
|
- if (null != kwsRole) {
|
|
|
- kwsRole.setDelFlag(Global.YES);
|
|
|
- resultCode = kwsRoleDao.update(kwsRole);
|
|
|
+ /*2、删角色*/
|
|
|
+ for (KwsRole kwsRole : kwsRoles) {
|
|
|
+ kwsRole.setDelFlag(Global.YES);
|
|
|
+ if (kwsRoleDao.update(kwsRole) <= 0) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.DELETE_FAIL);
|
|
|
}
|
|
|
}
|
|
|
- return resultCode > 0 ? HttpResult.ok("删除成功!") : HttpResult.error("删除失败!");
|
|
|
+
|
|
|
+ //todo
|
|
|
+ /*3、用户绑定关系怎么办?*/
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -198,26 +208,31 @@ public class KwsRoleService {
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void userBindRole(UserBindRoleReqVo reqVo) {
|
|
|
- /*1、存用户角色信息*/
|
|
|
+ //特殊校验,之前说用户和角色是一对多,后来产品改成一对一
|
|
|
String[] roleIdArr = reqVo.getRoleIds().split(",");
|
|
|
if (customConfig.getIsBindManyRole() == Global.NO && roleIdArr.length > 1) {
|
|
|
throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.MSG_006);
|
|
|
}
|
|
|
|
|
|
+ /*1、若有数据则先置为删除状态*/
|
|
|
+ extracted(reqVo);
|
|
|
+
|
|
|
+ /*2、存用户角色信息*/
|
|
|
List<KwsUserRole> kwsUserRolelist = new ArrayList<>();
|
|
|
Date date = new Date();
|
|
|
- Long userId = LoginUserHolder.getUserId();
|
|
|
+ Long currentUserId = LoginUserHolder.getUserId();
|
|
|
+ long userId = reqVo.getUserId();
|
|
|
List<Long> roleIdList = new ArrayList<>();
|
|
|
for (String roleId : roleIdArr) {
|
|
|
KwsUserRole kwsUserRole = new KwsUserRole();
|
|
|
- kwsUserRole.setUserId(reqVo.getUserId());
|
|
|
+ kwsUserRole.setUserId(userId);
|
|
|
kwsUserRole.setRoleId(Long.parseLong(roleId));
|
|
|
kwsUserRole.setRemark(reqVo.getRemark());
|
|
|
kwsUserRole.setId(new IdWorker(1).nextId());
|
|
|
kwsUserRole.setCreateTime(date);
|
|
|
- kwsUserRole.setCreateBy(userId);
|
|
|
+ kwsUserRole.setCreateBy(currentUserId);
|
|
|
kwsUserRole.setUpdateTime(date);
|
|
|
- kwsUserRole.setUpdateBy(userId);
|
|
|
+ kwsUserRole.setUpdateBy(currentUserId);
|
|
|
kwsUserRole.setStatus(Global.NO);
|
|
|
kwsUserRole.setDelFlag(Global.NO);
|
|
|
kwsUserRolelist.add(kwsUserRole);
|
|
|
@@ -227,24 +242,65 @@ public class KwsRoleService {
|
|
|
throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
|
|
|
}
|
|
|
|
|
|
- /*2、存用户机构信息*/
|
|
|
+ /*3、存用户机构信息*/
|
|
|
List<KwsRole> kwsRoles = kwsRoleDao.selectBatchByKeys(roleIdList);
|
|
|
List<KwsUserDept> kwsUserDeptList = new ArrayList<>();
|
|
|
kwsRoles.forEach(item -> {
|
|
|
KwsUserDept kwsUserDept = new KwsUserDept();
|
|
|
- kwsUserDept.setUserId(reqVo.getUserId());
|
|
|
+ kwsUserDept.setUserId(userId);
|
|
|
kwsUserDept.setDeptId(item.getDeptId());
|
|
|
kwsUserDept.setId(new IdWorker(1).nextId());
|
|
|
kwsUserDept.setRemark("");
|
|
|
kwsUserDept.setStatus(Global.NO);
|
|
|
- kwsUserDept.setCreateBy(userId);
|
|
|
+ kwsUserDept.setCreateBy(currentUserId);
|
|
|
kwsUserDept.setCreateTime(date);
|
|
|
- kwsUserDept.setUpdateBy(userId);
|
|
|
+ kwsUserDept.setUpdateBy(currentUserId);
|
|
|
kwsUserDept.setUpdateTime(date);
|
|
|
kwsUserDept.setDelFlag(Global.NO);
|
|
|
kwsUserDeptList.add(kwsUserDept);
|
|
|
});
|
|
|
kwsDeptService.addUserDept(kwsUserDeptList);
|
|
|
+
|
|
|
+ /*4、后置处理,修改redis中的信息*/
|
|
|
+ FindMenuTreePojo findMenuTreePojo = new FindMenuTreePojo();
|
|
|
+ findMenuTreePojo.setRoleIds(roleIdList);
|
|
|
+ List<KwsMenuResVo> kwsMenuResVos = kwsMenuService.findList(findMenuTreePojo);
|
|
|
+ if (CollectionUtils.isEmpty(kwsMenuResVos)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> menus = new ArrayList<>();
|
|
|
+ for (KwsMenuResVo kwsMenuResVo : kwsMenuResVos) {
|
|
|
+ String links = kwsMenuResVo.getLinks();
|
|
|
+ if (StringUtils.isNotBlank(links)) {
|
|
|
+ menus.addAll(Arrays.asList(kwsMenuResVo.getLinks().split(",")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RedissonUtils.putSet(Global.REDIS_SYS_MENU_PREFIX + userId, menus);
|
|
|
+ RedissonUtils.delete(Global.REDIS_USER_PREFIX + userId + "*");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void extracted(UserBindRoleReqVo reqVo) {
|
|
|
+ List<KwsUserRole> currentUserRoleList = kwsUserRoleDao.findAllByUserId(reqVo.getUserId());
|
|
|
+ if (!CollectionUtils.isEmpty(currentUserRoleList)) {
|
|
|
+ for (KwsUserRole kwsUserRole : currentUserRoleList) {
|
|
|
+ kwsUserRole.setDelFlag(Global.YES);
|
|
|
+ if(kwsUserRoleDao.update(kwsUserRole) <= 0){
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<KwsUserDept> currentUserDeptList = kwsUserDeptDao.findAllByUserId(reqVo.getUserId());
|
|
|
+ if (!CollectionUtils.isEmpty(currentUserDeptList)) {
|
|
|
+ for (KwsUserDept kwsUserDept : currentUserDeptList) {
|
|
|
+ kwsUserDept.setDelFlag(Global.YES);
|
|
|
+ if (kwsUserDeptDao.update(kwsUserDept) <= 0) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|