Commit 1b8aff7e by yushien

《完善用户信息》完善用户登录这块1.1

parent f2b301b0
package com.ruoyi.web.controller.system; package com.ruoyi.web.controller.system;
import cn.dev33.satoken.annotation.SaIgnore; import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.collection.CollUtil;
import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysMenu; import com.ruoyi.common.core.domain.entity.SysMenu;
...@@ -22,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -22,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -134,6 +136,9 @@ public class SysLoginController { ...@@ -134,6 +136,9 @@ public class SysLoginController {
public R<Map<String, Object>> getInfo() { public R<Map<String, Object>> getInfo() {
LoginUser loginUser = LoginHelper.getLoginUser(); LoginUser loginUser = LoginHelper.getLoginUser();
SysUser user = userService.selectUserById(loginUser.getUserId()); SysUser user = userService.selectUserById(loginUser.getUserId());
if(StringUtils.isNotEmpty(user.getDeptList())){
user.setDeptListArray(CollUtil.newArrayList(user.getDeptList().split(",")));
}
Map<String, Object> ajax = new HashMap<>(); Map<String, Object> ajax = new HashMap<>();
ajax.put("user", user); ajax.put("user", user);
ajax.put("roles", loginUser.getRolePermission()); ajax.put("roles", loginUser.getRolePermission());
......
...@@ -133,6 +133,9 @@ public class SysUserController extends BaseController { ...@@ -133,6 +133,9 @@ public class SysUserController extends BaseController {
ajax.put("posts", postService.selectPostAll()); ajax.put("posts", postService.selectPostAll());
if (ObjectUtil.isNotNull(userId)) { if (ObjectUtil.isNotNull(userId)) {
SysUser sysUser = userService.selectUserById(userId); SysUser sysUser = userService.selectUserById(userId);
if(StringUtils.isNotEmpty(sysUser.getDeptList())){
sysUser.setDeptListArray(CollUtil.newArrayList(sysUser.getDeptList().split(",")));
}
ajax.put("user", sysUser); ajax.put("user", sysUser);
ajax.put("postIds", postService.selectPostListByUserId(userId)); ajax.put("postIds", postService.selectPostListByUserId(userId));
ajax.put("roleIds", StreamUtils.toList(sysUser.getRoles(), SysRole::getRoleId)); ajax.put("roleIds", StreamUtils.toList(sysUser.getRoles(), SysRole::getRoleId));
...@@ -147,6 +150,27 @@ public class SysUserController extends BaseController { ...@@ -147,6 +150,27 @@ public class SysUserController extends BaseController {
@Log(title = "用户管理", businessType = BusinessType.INSERT) @Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public R<Void> add(@Validated @RequestBody SysUser user) { public R<Void> add(@Validated @RequestBody SysUser user) {
//新增逻辑处理
if(StringUtils.isNotEmpty(user.getDeptList())){
//判断是否为父级
List<String> colList = CollUtil.newArrayList(user.getDeptList().split(","));
List<String> uio=new ArrayList<>();
colList.forEach(syu->{
List<SysDept> sysDep = deptService.selectDeptListByDeID(new Long(syu));
if(CollUtil.isNotEmpty(sysDep)){
sysDep.forEach(ss->{
uio.add(String.valueOf(ss.getDeptId()));
});
return;
}
uio.add(syu);
});
// 设置list
if(CollUtil.isNotEmpty(uio)){
user.setDeptList(CollUtil.join(uio, ","));
}
}
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) { if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) {
return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) } else if (StringUtils.isNotEmpty(user.getPhonenumber())
...@@ -167,6 +191,26 @@ public class SysUserController extends BaseController { ...@@ -167,6 +191,26 @@ public class SysUserController extends BaseController {
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public R<Void> edit(@Validated @RequestBody SysUser user) { public R<Void> edit(@Validated @RequestBody SysUser user) {
//修改用户逻辑
if(StringUtils.isNotEmpty(user.getDeptList())){
//判断是否为父级
List<String> colList = CollUtil.newArrayList(user.getDeptList().split(","));
List<String> uio=new ArrayList<>();
colList.forEach(syu->{
List<SysDept> sysDep = deptService.selectDeptListByDeID(new Long(syu));
if(CollUtil.isNotEmpty(sysDep)){
sysDep.forEach(ss->{
uio.add(String.valueOf(ss.getDeptId()));
});
return;
}
uio.add(syu);
});
// 设置list
if(CollUtil.isNotEmpty(uio)){
user.setDeptList(CollUtil.join(uio, ","));
}
}
userService.checkUserAllowed(user); userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId()); userService.checkUserDataScope(user.getUserId());
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) { if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) {
...@@ -178,6 +222,7 @@ public class SysUserController extends BaseController { ...@@ -178,6 +222,7 @@ public class SysUserController extends BaseController {
&& UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) { && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
return R.fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); return R.fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
} }
return toAjax(userService.updateUser(user)); return toAjax(userService.updateUser(user));
} }
......
...@@ -158,6 +158,11 @@ public class SysUser extends BaseEntity { ...@@ -158,6 +158,11 @@ public class SysUser extends BaseEntity {
*/ */
@TableField(exist = false) @TableField(exist = false)
private String deptListStr; private String deptListStr;
/**
* 班级数组
*/
@TableField(exist = false)
private List<String> deptListArray;
public SysUser(Long userId) { public SysUser(Long userId) {
this.userId = userId; this.userId = userId;
......
...@@ -36,6 +36,14 @@ public interface SysDeptMapper extends BaseMapperPlus<SysDeptMapper, SysDept, Sy ...@@ -36,6 +36,14 @@ public interface SysDeptMapper extends BaseMapperPlus<SysDeptMapper, SysDept, Sy
List<SysDept> selectDeptListNew(@Param("deptList") List<Long> deptList); List<SysDept> selectDeptListNew(@Param("deptList") List<Long> deptList);
/** /**
* 查询部门管理数据
*
* @param deptList 查询条件
* @return 部门信息集合
*/
List<SysDept> selectDeptListDeId(@Param("deptList") Long deptList);
/**
* 根据角色ID查询部门树信息 * 根据角色ID查询部门树信息
* *
* @param roleId 角色ID * @param roleId 角色ID
......
...@@ -28,6 +28,15 @@ public interface ISysDeptService { ...@@ -28,6 +28,15 @@ public interface ISysDeptService {
*/ */
List<SysDept> selectDeptListByList(List<Long> deptList); List<SysDept> selectDeptListByList(List<Long> deptList);
/**
* 根据父类id查询所有子类
*
* @param deptList 部门信息
* @return 部门信息集合
*/
List<SysDept> selectDeptListByDeID(Long deptList);
/** /**
* 查询部门树结构信息 * 查询部门树结构信息
* *
......
...@@ -63,6 +63,10 @@ public class SysDeptServiceImpl implements ISysDeptService { ...@@ -63,6 +63,10 @@ public class SysDeptServiceImpl implements ISysDeptService {
return baseMapper.selectDeptListNew(deptList); return baseMapper.selectDeptListNew(deptList);
} }
@Override
public List<SysDept> selectDeptListByDeID(Long deptList) {
return baseMapper.selectDeptListDeId(deptList);
}
/** /**
* 查询部门树结构信息 * 查询部门树结构信息
* *
......
...@@ -51,6 +51,15 @@ ...@@ -51,6 +51,15 @@
</foreach> </foreach>
</select> </select>
<select id="selectDeptListDeId" resultMap="SysDeptResult">
SELECT *
FROM
sys_dept
where st.del_flag='0'
AND st.parent_id =#{deptList}
</select>
<select id="selectDeptListByRoleId" resultType="Long"> <select id="selectDeptListByRoleId" resultType="Long">
select d.dept_id select d.dept_id
from sys_dept d from sys_dept d
......
...@@ -164,7 +164,7 @@ ...@@ -164,7 +164,7 @@
where u.del_flag = '0' and u.phonenumber = #{phonenumber} where u.del_flag = '0' and u.phonenumber = #{phonenumber}
</select> </select>
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult"> <select id="selectUserById" parameterType="Long" resultMap="SysUserResult12">
<include refid="selectUserVo"/> <include refid="selectUserVo"/>
where u.del_flag = '0' and u.user_id = #{userId} where u.del_flag = '0' and u.user_id = #{userId}
</select> </select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment