|
@@ -3,22 +3,20 @@ import java.util.Date;
|
|
|
|
|
|
|
|
import com.sckw.core.exception.SystemException;
|
|
import com.sckw.core.exception.SystemException;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
import com.sckw.core.model.constant.Global;
|
|
|
|
|
+import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
import com.sckw.core.utils.IdWorker;
|
|
|
import com.sckw.core.utils.StringUtils;
|
|
import com.sckw.core.utils.StringUtils;
|
|
|
import com.sckw.core.web.constant.HttpStatus;
|
|
import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
-import com.sckw.core.web.model.LoginUserInfo;
|
|
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
-import com.sckw.system.api.model.dto.res.KwsRoleResDto;
|
|
|
|
|
-import com.sckw.system.dao.KwsMenuRightsDao;
|
|
|
|
|
|
|
+import com.sckw.system.dao.KwsAuthorityDao;
|
|
|
import com.sckw.system.dao.KwsRoleDao;
|
|
import com.sckw.system.dao.KwsRoleDao;
|
|
|
import com.sckw.system.dao.KwsUserRoleDao;
|
|
import com.sckw.system.dao.KwsUserRoleDao;
|
|
|
-import com.sckw.system.model.KwsMenuRights;
|
|
|
|
|
-import com.sckw.system.model.KwsRole;
|
|
|
|
|
-import com.sckw.system.model.KwsUserDept;
|
|
|
|
|
-import com.sckw.system.model.KwsUserRole;
|
|
|
|
|
|
|
+import com.sckw.system.model.*;
|
|
|
|
|
+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.req.UserBindRoleReqVo;
|
|
|
-import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
+import com.sckw.system.model.vo.res.KwsDeptResVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -40,15 +38,19 @@ public class KwsRoleService {
|
|
|
KwsUserRoleDao kwsUserRoleDao;
|
|
KwsUserRoleDao kwsUserRoleDao;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- KwsMenuRightsDao kwsMenuRightsDao;
|
|
|
|
|
|
|
+ KwsAuthorityDao kwsAuthorityDao;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
KwsDeptService kwsDeptService;
|
|
KwsDeptService kwsDeptService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ KwsMenuService kwsMenuServicel;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 添加新纪录
|
|
|
|
|
- * @param params
|
|
|
|
|
- * @return
|
|
|
|
|
- * @throws Exception
|
|
|
|
|
|
|
+ * @param params KwsRole
|
|
|
|
|
+ * @desc: 单表插入
|
|
|
|
|
+ * @author: czh
|
|
|
|
|
+ * @date: 2023/6/15
|
|
|
*/
|
|
*/
|
|
|
public void add(KwsRole params) {
|
|
public void add(KwsRole params) {
|
|
|
if (kwsRoleDao.insert(params) <= 0) {
|
|
if (kwsRoleDao.insert(params) <= 0) {
|
|
@@ -56,22 +58,80 @@ public class KwsRoleService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param reqVo 新增角色
|
|
|
|
|
+ * @desc: 新增角色
|
|
|
|
|
+ * @author: czh
|
|
|
|
|
+ * @date: 2023/6/15
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void add(AddRoleReqVo reqVo) {
|
|
|
|
|
+ /*1、存角色信息*/
|
|
|
|
|
+ KwsRole kwsRole = new KwsRole();
|
|
|
|
|
+ long roleId = new IdWorker(1L).nextId();
|
|
|
|
|
+ kwsRole.setId(roleId);
|
|
|
|
|
+ kwsRole.setName(reqVo.getName());
|
|
|
|
|
+ kwsRole.setDeptId(reqVo.getCurrentDeptId());
|
|
|
|
|
+ kwsRole.setRemark(reqVo.getRemark());
|
|
|
|
|
+ if (kwsRoleDao.insert(kwsRole) <= 0) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /*2、绑定菜单功能*/
|
|
|
|
|
+ KwsDept kwsDept = new KwsDept();
|
|
|
|
|
+ kwsDept.setId(reqVo.getCurrentDeptId());
|
|
|
|
|
+ List<KwsDeptResVo> list = kwsDeptService.findList(kwsDept);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
|
|
|
|
|
+ }
|
|
|
|
|
+ RoleBindMeunReqVo roleBindMeunReqVo = new RoleBindMeunReqVo();
|
|
|
|
|
+ roleBindMeunReqVo.setRoleId(roleId);
|
|
|
|
|
+ roleBindMeunReqVo.setEntId(list.get(0).getEntId());
|
|
|
|
|
+ roleBindMeunReqVo.setMenuIds(reqVo.getMenuIds());
|
|
|
|
|
+ kwsMenuServicel.roleBindMeun(roleBindMeunReqVo);
|
|
|
|
|
+
|
|
|
|
|
+ /*3、设置数据权限*/
|
|
|
|
|
+ if (reqVo.getVisiblePersonal()) {
|
|
|
|
|
+ //只能看见自己的数据则不管
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] deptIds = reqVo.getDeptIds().split(",");
|
|
|
|
|
+ List<KwsAuthority> kwsAuthorities = new ArrayList<>();
|
|
|
|
|
+ Long userId = LoginUserHolder.getUserId();
|
|
|
|
|
+ Date date = new Date();
|
|
|
|
|
+ for (String deptId : deptIds) {
|
|
|
|
|
+ KwsAuthority kwsAuthority = new KwsAuthority();
|
|
|
|
|
+ kwsAuthority.setRoleId(roleId);
|
|
|
|
|
+ kwsAuthority.setDeptId(Long.parseLong(deptId));
|
|
|
|
|
+ kwsAuthority.setId(new IdWorker(1L).nextId());
|
|
|
|
|
+ kwsAuthority.setStatus(Global.NO);
|
|
|
|
|
+ kwsAuthority.setCreateBy(userId);
|
|
|
|
|
+ kwsAuthority.setCreateTime(date);
|
|
|
|
|
+ kwsAuthority.setUpdateBy(userId);
|
|
|
|
|
+ kwsAuthority.setUpdateTime(date);
|
|
|
|
|
+ kwsAuthority.setDelFlag(Global.NO);
|
|
|
|
|
+ kwsAuthorities.add(kwsAuthority);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(kwsAuthorityDao.saveBatch(kwsAuthorities) != kwsAuthorities.size() ) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 删除记录-根据主键
|
|
* 删除记录-根据主键
|
|
|
- * @param ids
|
|
|
|
|
- * @return
|
|
|
|
|
- * @throws Exception
|
|
|
|
|
|
|
+ * @param ids 主键
|
|
|
|
|
+ * @return HttpResult
|
|
|
*/
|
|
*/
|
|
|
public HttpResult deleteByKey(String ids) throws Exception {
|
|
public HttpResult deleteByKey(String ids) throws Exception {
|
|
|
- /**1.数据校验**/
|
|
|
|
|
|
|
+ /*1.数据校验*/
|
|
|
if (StringUtils.isBlank(ids)) {
|
|
if (StringUtils.isBlank(ids)) {
|
|
|
return HttpResult.error("请选择您要删除的角色信息!");
|
|
return HttpResult.error("请选择您要删除的角色信息!");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int resultCode = 0;
|
|
int resultCode = 0;
|
|
|
String[] idArray = ids.split(",");
|
|
String[] idArray = ids.split(",");
|
|
|
- for (int i = 0; i < idArray.length; i++) {
|
|
|
|
|
- String id = idArray[i];
|
|
|
|
|
|
|
+ for (String id : idArray) {
|
|
|
KwsRole kwsRole = kwsRoleDao.selectByKey(Long.parseLong(id));
|
|
KwsRole kwsRole = kwsRoleDao.selectByKey(Long.parseLong(id));
|
|
|
if (null != kwsRole) {
|
|
if (null != kwsRole) {
|
|
|
kwsRole.setDelFlag(Global.YES);
|
|
kwsRole.setDelFlag(Global.YES);
|
|
@@ -83,9 +143,8 @@ public class KwsRoleService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 更新记录
|
|
* 更新记录
|
|
|
- * @param params
|
|
|
|
|
- * @return
|
|
|
|
|
- * @throws Exception
|
|
|
|
|
|
|
+ * @param params KwsRole
|
|
|
|
|
+ * @return HttpResult
|
|
|
*/
|
|
*/
|
|
|
public HttpResult update(KwsRole params) throws Exception {
|
|
public HttpResult update(KwsRole params) throws Exception {
|
|
|
int count = kwsRoleDao.update(params);
|
|
int count = kwsRoleDao.update(params);
|
|
@@ -94,9 +153,8 @@ public class KwsRoleService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据主键查询
|
|
* 根据主键查询
|
|
|
- * @param key
|
|
|
|
|
- * @return
|
|
|
|
|
- * @throws Exception
|
|
|
|
|
|
|
+ * @param key 主键
|
|
|
|
|
+ * @return KwsRole
|
|
|
*/
|
|
*/
|
|
|
public KwsRole selectByKey(Long key) {
|
|
public KwsRole selectByKey(Long key) {
|
|
|
return kwsRoleDao.selectByKey(key);
|
|
return kwsRoleDao.selectByKey(key);
|
|
@@ -104,17 +162,16 @@ public class KwsRoleService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 分页查询
|
|
* 分页查询
|
|
|
- * @param params
|
|
|
|
|
- * @return
|
|
|
|
|
- * @throws Exception
|
|
|
|
|
|
|
+ * @param params 分页入参
|
|
|
|
|
+ * @return List
|
|
|
*/
|
|
*/
|
|
|
public List<KwsRole> findPage(Map<String, Object> params) throws Exception{
|
|
public List<KwsRole> findPage(Map<String, Object> params) throws Exception{
|
|
|
return kwsRoleDao.findPage(params);
|
|
return kwsRoleDao.findPage(params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @param * @param 用户id
|
|
|
|
|
- * @return
|
|
|
|
|
|
|
+ * @param userId 用户id
|
|
|
|
|
+ * @return List
|
|
|
* @desc: 根据用户id查角色
|
|
* @desc: 根据用户id查角色
|
|
|
* @author: czh
|
|
* @author: czh
|
|
|
* @date: 2023/6/12
|
|
* @date: 2023/6/12
|
|
@@ -129,7 +186,7 @@ public class KwsRoleService {
|
|
|
* @author: czh
|
|
* @author: czh
|
|
|
* @date: 2023/6/13
|
|
* @date: 2023/6/13
|
|
|
*/
|
|
*/
|
|
|
- @Transactional(rollbackFor = {})
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void userBindRole(UserBindRoleReqVo reqVo) {
|
|
public void userBindRole(UserBindRoleReqVo reqVo) {
|
|
|
/*1、存用户角色信息*/
|
|
/*1、存用户角色信息*/
|
|
|
String[] roleIdArr = reqVo.getRoleIds().split(",");
|
|
String[] roleIdArr = reqVo.getRoleIds().split(",");
|