From cbe05ba834b69e65f679be08d21eaf2cb1f7ee5d Mon Sep 17 00:00:00 2001
From: zhc077 <565291854>
Date: Wed, 12 Apr 2023 17:17:06 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E9=A1=B9=E7=9B=AE?=
=?UTF-8?q?=E7=AE=A1=E7=90=86=E7=B3=BB=E7=BB=9F=20=E7=94=A8=E6=88=B7?=
=?UTF-8?q?=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=20=E4=BF=AE=E6=94=B9=204.1?=
=?UTF-8?q?2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../system/controller/SysUserController.java | 1028 +++++++++--------
.../src/main/resources/application-dev.yml | 4 +-
.../src/main/resources/application-prod.yml | 2 +-
3 files changed, 527 insertions(+), 507 deletions(-)
diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysUserController.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysUserController.java
index 113a1e0..4aa638e 100644
--- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysUserController.java
+++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysUserController.java
@@ -63,23 +63,23 @@ import java.util.stream.Collectors;
@RestController
@RequestMapping("/sys/user")
public class SysUserController {
- @Autowired
- private ISysBaseAPI sysBaseAPI;
+ @Autowired
+ private ISysBaseAPI sysBaseAPI;
- @Autowired
- private ISysUserService sysUserService;
+ @Autowired
+ private ISysUserService sysUserService;
@Autowired
private ISysDepartService sysDepartService;
- @Autowired
- private ISysUserRoleService sysUserRoleService;
+ @Autowired
+ private ISysUserRoleService sysUserRoleService;
- @Autowired
- private ISysUserDepartService sysUserDepartService;
+ @Autowired
+ private ISysUserDepartService sysUserDepartService;
- @Autowired
- private ISysUserRoleService userRoleService;
+ @Autowired
+ private ISysUserRoleService userRoleService;
@Autowired
private ISysDepartRoleUserService departRoleUserService;
@@ -87,8 +87,8 @@ public class SysUserController {
@Autowired
private ISysDepartRoleService departRoleService;
- @Autowired
- private RedisUtil redisUtil;
+ @Autowired
+ private RedisUtil redisUtil;
@Value("${jeecg.path.upload}")
private String upLoadPath;
@@ -98,6 +98,7 @@ public class SysUserController {
/**
* 获取用户列表数据
+ *
* @param user
* @param pageNo
* @param pageSize
@@ -105,35 +106,35 @@ public class SysUserController {
* @return
*/
@PermissionData(pageComponent = "system/UserList")
- @RequestMapping(value = "/list", method = RequestMethod.GET)
- public Result> queryPageList(SysUser user,@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,HttpServletRequest req) {
- Result> result = new Result>();
- QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(user, req.getParameterMap());
- //TODO 外部模拟登陆临时账号,列表不显示
- queryWrapper.ne("username","_reserve_user_external");
- Page page = new Page(pageNo, pageSize);
- IPage pageList = sysUserService.page(page, queryWrapper);
-
- //批量查询用户的所属部门
+ @RequestMapping(value = "/list", method = RequestMethod.GET)
+ public Result> queryPageList(SysUser user, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
+ Result> result = new Result>();
+ QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(user, req.getParameterMap());
+ //TODO 外部模拟登陆临时账号,列表不显示
+ queryWrapper.ne("username", "_reserve_user_external");
+ Page page = new Page(pageNo, pageSize);
+ IPage pageList = sysUserService.page(page, queryWrapper);
+
+ //批量查询用户的所属部门
//step.1 先拿到全部的 useids
//step.2 通过 useids,一次性查询用户的所属部门名字
List userIds = pageList.getRecords().stream().map(SysUser::getId).collect(Collectors.toList());
- if(userIds!=null && userIds.size()>0){
- Map useDepNames = sysUserService.getDepNamesByUserIds(userIds);
- pageList.getRecords().forEach(item->{
+ if (userIds != null && userIds.size() > 0) {
+ Map useDepNames = sysUserService.getDepNamesByUserIds(userIds);
+ pageList.getRecords().forEach(item -> {
item.setOrgCodeTxt(useDepNames.get(item.getId()));
});
}
- result.setSuccess(true);
- result.setResult(pageList);
- log.info(pageList.toString());
- return result;
- }
-
- @RequestMapping(value = "/student",method = RequestMethod.GET)
- public Result> query(SysUser user,@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,HttpServletRequest req) {
+ result.setSuccess(true);
+ result.setResult(pageList);
+ log.info(pageList.toString());
+ return result;
+ }
+
+ @RequestMapping(value = "/student", method = RequestMethod.GET)
+ public Result> query(SysUser user, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
Result> result = new Result>();
//QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(user, req.getParameterMap());
//TODO 外部模拟登陆临时账号,列表不显示
@@ -141,9 +142,9 @@ public class SysUserController {
Page page = new Page(pageNo, pageSize);
IPage pageList = sysUserService.selectStudent(page, user);
List userIds = pageList.getRecords().stream().map(SysUser::getId).collect(Collectors.toList());
- if(userIds!=null && userIds.size()>0){
- Map useDepNames = sysUserService.getDepNamesByUserIds(userIds);
- pageList.getRecords().forEach(item->{
+ if (userIds != null && userIds.size() > 0) {
+ Map useDepNames = sysUserService.getDepNamesByUserIds(userIds);
+ pageList.getRecords().forEach(item -> {
item.setOrgCodeTxt(useDepNames.get(item.getId()));
});
}
@@ -155,6 +156,7 @@ public class SysUserController {
/**
* 获取员工列表数据
+ *
* @param user
* @param pageNo
* @param pageSize
@@ -163,13 +165,13 @@ public class SysUserController {
*/
@PermissionData(pageComponent = "system/StaffList")
@RequestMapping(value = "/slist", method = RequestMethod.GET)
- public Result> queryPageStaffList(SysUser user,@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,HttpServletRequest req) {
+ public Result> queryPageStaffList(SysUser user, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
Result> result = new Result>();
QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(user, req.getParameterMap());
//TODO 外部模拟登陆临时账号,列表不显示
- queryWrapper.ne("username","_reserve_user_external");
- queryWrapper.eq("user_identity",3);
+ queryWrapper.ne("username", "_reserve_user_external");
+ queryWrapper.eq("user_identity", 3);
Page page = new Page(pageNo, pageSize);
IPage pageList = sysUserService.page(page, queryWrapper);
@@ -177,9 +179,9 @@ public class SysUserController {
//step.1 先拿到全部的 useids
//step.2 通过 useids,一次性查询用户的所属部门名字
List userIds = pageList.getRecords().stream().map(SysUser::getId).collect(Collectors.toList());
- if(userIds!=null && userIds.size()>0){
- Map useDepNames = sysUserService.getDepNamesByUserIds(userIds);
- pageList.getRecords().forEach(item->{
+ if (userIds != null && userIds.size() > 0) {
+ Map useDepNames = sysUserService.getDepNamesByUserIds(userIds);
+ pageList.getRecords().forEach(item -> {
item.setOrgCodeTxt(useDepNames.get(item.getId()));
});
}
@@ -191,106 +193,110 @@ public class SysUserController {
//@RequiresRoles({"admin"})
//@RequiresPermissions("user:add")
- @RequestMapping(value = "/add", method = RequestMethod.POST)
- public Result add(@RequestBody JSONObject jsonObject) {
- Result result = new Result();
- String selectedRoles = jsonObject.getString("selectedroles");
- String selectedDeparts = jsonObject.getString("selecteddeparts");
- System.out.println("我的测试"+selectedRoles);
- try {
- SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
- user.setCreateTime(new Date());//设置创建时间
- String salt = oConvertUtils.randomGen(8);
- user.setSalt(salt);
- String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
- user.setPassword(passwordEncode);
- user.setStatus(1);
- user.setDelFlag(CommonConstant.DEL_FLAG_0);
- // 保存用户走一个service 保证事务
- sysUserService.saveUser(user, selectedRoles, selectedDeparts);
- result.success("添加成功!");
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- result.error500("操作失败");
- }
- return result;
- }
+ @RequestMapping(value = "/add", method = RequestMethod.POST)
+ public Result add(@RequestBody JSONObject jsonObject) {
+ Result result = new Result();
+ String selectedRoles = jsonObject.getString("selectedroles");
+ String selectedDeparts = jsonObject.getString("selecteddeparts");
+// System.out.println("我的测试" + selectedRoles);
+ try {
+ SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
+ user.setCreateTime(new Date());//设置创建时间
+ String salt = oConvertUtils.randomGen(8);
+ user.setSalt(salt);
+ String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
+ user.setPassword(passwordEncode);
+ user.setStatus(1);
+ user.setDelFlag(CommonConstant.DEL_FLAG_0);
+ // 保存用户走一个service 保证事务
+ this.sysUserService.save(user);
+// sysUserService.saveUser(user, selectedRoles, selectedDeparts);
+ result.success("添加成功!");
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ result.error500("操作失败");
+ }
+ return result;
+ }
//@RequiresRoles({"admin"})
//@RequiresPermissions("user:edit")
- @RequestMapping(value = "/edit", method = RequestMethod.PUT)
- public Result edit(@RequestBody JSONObject jsonObject) {
- Result result = new Result();
- try {
- SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
- baseCommonService.addLog("编辑用户,id: " +jsonObject.getString("id") ,CommonConstant.LOG_TYPE_2, 2);
- if(sysUser==null) {
- result.error500("未找到对应实体");
- }else {
- SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
- user.setUpdateTime(new Date());
- //String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
- user.setPassword(sysUser.getPassword());
- String roles = jsonObject.getString("selectedroles");
+ @RequestMapping(value = "/edit", method = RequestMethod.PUT)
+ public Result edit(@RequestBody JSONObject jsonObject) {
+ Result result = new Result();
+ try {
+ SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
+ baseCommonService.addLog("编辑用户,id: " + jsonObject.getString("id"), CommonConstant.LOG_TYPE_2, 2);
+ if (sysUser == null) {
+ result.error500("未找到对应实体");
+ } else {
+ SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
+ user.setUpdateTime(new Date());
+ //String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
+ user.setPassword(sysUser.getPassword());
+ String roles = jsonObject.getString("selectedroles");
String departs = jsonObject.getString("selecteddeparts");
// 修改用户走一个service 保证事务
- sysUserService.editUser(user, roles, departs);
- result.success("修改成功!");
- }
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- result.error500("操作失败");
- }
- return result;
- }
-
- /**
- * 删除用户
- */
- //@RequiresRoles({"admin"})
- @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
- public Result> delete(@RequestParam(name="id",required=true) String id) {
- baseCommonService.addLog("删除用户,id: " +id ,CommonConstant.LOG_TYPE_2, 3);
- this.sysUserService.deleteUser(id);
- return Result.ok("删除用户成功");
- }
-
- /**
- * 批量删除用户
- */
- //@RequiresRoles({"admin"})
- @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
- public Result> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
- baseCommonService.addLog("批量删除用户, ids: " +ids ,CommonConstant.LOG_TYPE_2, 3);
- this.sysUserService.deleteBatchUsers(ids);
- return Result.ok("批量删除用户成功");
- }
-
- /**
- * 冻结&解冻用户
- * @param jsonObject
- * @return
- */
- //@RequiresRoles({"admin"})
- @RequestMapping(value = "/frozenBatch", method = RequestMethod.PUT)
- public Result frozenBatch(@RequestBody JSONObject jsonObject) {
- Result result = new Result();
- try {
- String ids = jsonObject.getString("ids");
- String status = jsonObject.getString("status");
- String[] arr = ids.split(",");
- for (String id : arr) {
- if(oConvertUtils.isNotEmpty(id)) {
- this.sysUserService.update(new SysUser().setStatus(Integer.parseInt(status)),
- new UpdateWrapper().lambda().eq(SysUser::getId,id));
- }
- }
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- result.error500("操作失败"+e.getMessage());
- }
- result.success("操作成功!");
- return result;
+ sysUserService.updateById(user);
+// sysUserService.editUser(user, roles, departs);
+ result.success("修改成功!");
+ }
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ result.error500("操作失败");
+ }
+ return result;
+ }
+
+ /**
+ * 删除用户
+ */
+ //@RequiresRoles({"admin"})
+ @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
+ public Result> delete(@RequestParam(name = "id", required = true) String id) {
+ this.sysUserService.removeById(id);
+// baseCommonService.addLog("删除用户,id: " + id, CommonConstant.LOG_TYPE_2, 3);
+// this.sysUserService.deleteUser(id);
+ return Result.ok("删除用户成功");
+ }
+
+ /**
+ * 批量删除用户
+ */
+ //@RequiresRoles({"admin"})
+ @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
+ public Result> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+ baseCommonService.addLog("批量删除用户, ids: " + ids, CommonConstant.LOG_TYPE_2, 3);
+ this.sysUserService.deleteBatchUsers(ids);
+ return Result.ok("批量删除用户成功");
+ }
+
+ /**
+ * 冻结&解冻用户
+ *
+ * @param jsonObject
+ * @return
+ */
+ //@RequiresRoles({"admin"})
+ @RequestMapping(value = "/frozenBatch", method = RequestMethod.PUT)
+ public Result frozenBatch(@RequestBody JSONObject jsonObject) {
+ Result result = new Result();
+ try {
+ String ids = jsonObject.getString("ids");
+ String status = jsonObject.getString("status");
+ String[] arr = ids.split(",");
+ for (String id : arr) {
+ if (oConvertUtils.isNotEmpty(id)) {
+ this.sysUserService.update(new SysUser().setStatus(Integer.parseInt(status)),
+ new UpdateWrapper().lambda().eq(SysUser::getId, id));
+ }
+ }
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ result.error500("操作失败" + e.getMessage());
+ }
+ result.success("操作成功!");
+ return result;
}
@@ -315,11 +321,11 @@ public class SysUserController {
* @return
*/
@AutoLog(value = "用户信息-通过username查询")
- @ApiOperation(value="用户信息-通过username查询", notes="用户信息-通过username查询")
+ @ApiOperation(value = "用户信息-通过username查询", notes = "用户信息-通过username查询")
@GetMapping(value = "/queryByName")
public Result> queryByName(@RequestParam(name = "username", required = true) String username) {
SysUser sysUser = sysUserService.getUserByName(username);
- if(sysUser==null) {
+ if (sysUser == null) {
return Result.error("未找到对应数据");
}
return Result.OK(sysUser);
@@ -344,8 +350,8 @@ public class SysUserController {
/**
- * 校验用户账号是否唯一
- * 可以校验其他 需要检验什么就传什么。。。
+ * 校验用户账号是否唯一
+ * 可以校验其他 需要检验什么就传什么。。。
*
* @param sysUser
* @return
@@ -409,7 +415,7 @@ public class SysUserController {
}
return result;
} catch (Exception e) {
- log.error(e.getMessage(), e);
+ log.error(e.getMessage(), e);
result.setSuccess(false);
result.setMessage("查找过程中出现了异常: " + e.getMessage());
return result;
@@ -439,19 +445,19 @@ public class SysUserController {
* @return
*/
@RequestMapping(value = "/queryUserByDepId", method = RequestMethod.GET)
- public Result> queryUserByDepId(@RequestParam(name = "id", required = true) String id,@RequestParam(name="realname",required=false) String realname) {
+ public Result> queryUserByDepId(@RequestParam(name = "id", required = true) String id, @RequestParam(name = "realname", required = false) String realname) {
Result> result = new Result<>();
//List userList = sysUserDepartService.queryUserByDepId(id);
SysDepart sysDepart = sysDepartService.getById(id);
- List userList = sysUserDepartService.queryUserByDepCode(sysDepart.getOrgCode(),realname);
+ List userList = sysUserDepartService.queryUserByDepCode(sysDepart.getOrgCode(), realname);
//批量查询用户的所属部门
//step.1 先拿到全部的 useids
//step.2 通过 useids,一次性查询用户的所属部门名字
List userIds = userList.stream().map(SysUser::getId).collect(Collectors.toList());
- if(userIds!=null && userIds.size()>0){
- Map useDepNames = sysUserService.getDepNamesByUserIds(userIds);
- userList.forEach(item->{
+ if (userIds != null && userIds.size() > 0) {
+ Map useDepNames = sysUserService.getDepNamesByUserIds(userIds);
+ userList.forEach(item -> {
//TODO 临时借用这个字段用于页面展示
item.setOrgCodeTxt(useDepNames.get(item.getId()));
});
@@ -462,7 +468,7 @@ public class SysUserController {
result.setResult(userList);
return result;
} catch (Exception e) {
- log.error(e.getMessage(), e);
+ log.error(e.getMessage(), e);
result.setSuccess(false);
return result;
}
@@ -470,27 +476,29 @@ public class SysUserController {
/**
* 用户选择组件 专用 根据用户账号或部门分页查询
+ *
* @param departId
* @param username
* @return
*/
@RequestMapping(value = "/queryUserComponentData", method = RequestMethod.GET)
public Result> queryUserComponentData(
- @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "departId", required = false) String departId,
- @RequestParam(name="realname",required=false) String realname,
- @RequestParam(name="username",required=false) String username) {
+ @RequestParam(name = "realname", required = false) String realname,
+ @RequestParam(name = "username", required = false) String username) {
IPage pageList = sysUserDepartService.queryDepartUserPageList(departId, username, realname, pageSize, pageNo);
return Result.OK(pageList);
}
+
@RequestMapping(value = "/queryStudentComponentData", method = RequestMethod.GET)
public Result> queryStudentComponentData(
- @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "departId", required = false) String departId,
- @RequestParam(name="realname",required=false) String realname,
- @RequestParam(name="username",required=false) String username) {
+ @RequestParam(name = "realname", required = false) String realname,
+ @RequestParam(name = "username", required = false) String username) {
IPage pageList = sysUserDepartService.queryDepartStudentPageList(departId, username, realname, pageSize, pageNo);
return Result.OK(pageList);
}
@@ -502,24 +510,24 @@ public class SysUserController {
* @param sysUser
*/
@RequestMapping(value = "/exportXls")
- public ModelAndView exportXls(SysUser sysUser,HttpServletRequest request) {
+ public ModelAndView exportXls(SysUser sysUser, HttpServletRequest request) {
// Step.1 组装查询条件
QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(sysUser, request.getParameterMap());
//Step.2 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
//update-begin--Author:kangxiaolin Date:20180825 for:[03]用户导出,如果选择数据则只导出相关数据--------------------
String selections = request.getParameter("selections");
- if(!oConvertUtils.isEmpty(selections)){
- queryWrapper.in("id",selections.split(","));
- }
+ if (!oConvertUtils.isEmpty(selections)) {
+ queryWrapper.in("id", selections.split(","));
+ }
//update-end--Author:kangxiaolin Date:20180825 for:[03]用户导出,如果选择数据则只导出相关数据----------------------
List pageList = sysUserService.list(queryWrapper);
//导出文件名称
mv.addObject(NormalExcelConstants.FILE_NAME, "用户列表");
mv.addObject(NormalExcelConstants.CLASS, SysUser.class);
- LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
- ExportParams exportParams = new ExportParams("用户列表数据", "导出人:"+user.getRealname(), "导出信息");
+ LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+ ExportParams exportParams = new ExportParams("用户列表数据", "导出人:" + user.getRealname(), "导出信息");
exportParams.setImageBasePath(upLoadPath);
mv.addObject(NormalExcelConstants.PARAMS, exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
@@ -536,7 +544,7 @@ public class SysUserController {
//@RequiresRoles({"admin"})
//@RequiresPermissions("user:import")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
- public Result> importExcel(HttpServletRequest request, HttpServletResponse response)throws IOException {
+ public Result> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map fileMap = multipartRequest.getFileMap();
// 错误信息
@@ -602,58 +610,58 @@ public class SysUserController {
try {
file.getInputStream().close();
} catch (IOException e) {
- log.error(e.getMessage(), e);
+ log.error(e.getMessage(), e);
}
}
}
- return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
+ return ImportExcelUtil.imporReturnRes(errorLines, successLines, errorMessage);
}
/**
- * @功能:根据id 批量查询
- * @param userIds
- * @return
- */
- @RequestMapping(value = "/queryByIds", method = RequestMethod.GET)
- public Result> queryByIds(@RequestParam String userIds) {
- Result> result = new Result<>();
- String[] userId = userIds.split(",");
- Collection idList = Arrays.asList(userId);
- Collection userRole = sysUserService.listByIds(idList);
- result.setSuccess(true);
- result.setResult(userRole);
- return result;
- }
-
- /**
- * 首页用户重置密码
- */
+ * @param userIds
+ * @return
+ * @功能:根据id 批量查询
+ */
+ @RequestMapping(value = "/queryByIds", method = RequestMethod.GET)
+ public Result> queryByIds(@RequestParam String userIds) {
+ Result> result = new Result<>();
+ String[] userId = userIds.split(",");
+ Collection idList = Arrays.asList(userId);
+ Collection userRole = sysUserService.listByIds(idList);
+ result.setSuccess(true);
+ result.setResult(userRole);
+ return result;
+ }
+
+ /**
+ * 首页用户重置密码
+ */
//@RequiresRoles({"admin"})
@RequestMapping(value = "/updatePassword", method = RequestMethod.PUT)
- public Result> updatePassword(@RequestBody JSONObject json) {
- String username = json.getString("username");
- String oldpassword = json.getString("oldpassword");
- String password = json.getString("password");
- String confirmpassword = json.getString("confirmpassword");
- LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
- if(!sysUser.getUsername().equals(username)){
+ public Result> updatePassword(@RequestBody JSONObject json) {
+ String username = json.getString("username");
+ String oldpassword = json.getString("oldpassword");
+ String password = json.getString("password");
+ String confirmpassword = json.getString("confirmpassword");
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+ if (!sysUser.getUsername().equals(username)) {
return Result.error("只允许修改自己的密码!");
}
- SysUser user = this.sysUserService.getOne(new LambdaQueryWrapper().eq(SysUser::getUsername, username));
- if(user==null) {
- return Result.error("用户不存在!");
- }
- return sysUserService.resetPassword(username,oldpassword,password,confirmpassword);
- }
+ SysUser user = this.sysUserService.getOne(new LambdaQueryWrapper().eq(SysUser::getUsername, username));
+ if (user == null) {
+ return Result.error("用户不存在!");
+ }
+ return sysUserService.resetPassword(username, oldpassword, password, confirmpassword);
+ }
@RequestMapping(value = "/userRoleList", method = RequestMethod.GET)
- public Result> userRoleList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
+ public Result> userRoleList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
Result> result = new Result>();
Page page = new Page(pageNo, pageSize);
String roleId = req.getParameter("roleId");
String username = req.getParameter("username");
- IPage pageList = sysUserService.getUserByRoleId(page,roleId,username);
+ IPage pageList = sysUserService.getUserByRoleId(page, roleId, username);
result.setSuccess(true);
result.setResult(pageList);
return result;
@@ -671,12 +679,12 @@ public class SysUserController {
Result result = new Result();
try {
String sysRoleId = sysUserRoleVO.getRoleId();
- for(String sysUserId:sysUserRoleVO.getUserIdList()) {
- SysUserRole sysUserRole = new SysUserRole(sysUserId,sysRoleId);
+ for (String sysUserId : sysUserRoleVO.getUserIdList()) {
+ SysUserRole sysUserRole = new SysUserRole(sysUserId, sysRoleId);
QueryWrapper queryWrapper = new QueryWrapper();
- queryWrapper.eq("role_id", sysRoleId).eq("user_id",sysUserId);
+ queryWrapper.eq("role_id", sysRoleId).eq("user_id", sysUserId);
SysUserRole one = sysUserRoleService.getOne(queryWrapper);
- if(one==null){
+ if (one == null) {
sysUserRoleService.save(sysUserRole);
}
@@ -684,30 +692,32 @@ public class SysUserController {
result.setMessage("添加成功!");
result.setSuccess(true);
return result;
- }catch(Exception e) {
+ } catch (Exception e) {
log.error(e.getMessage(), e);
result.setSuccess(false);
result.setMessage("出错了: " + e.getMessage());
return result;
}
}
+
/**
- * 删除指定角色的用户关系
+ * 删除指定角色的用户关系
+ *
* @param
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteUserRole", method = RequestMethod.DELETE)
- public Result deleteUserRole(@RequestParam(name="roleId") String roleId,
- @RequestParam(name="userId",required=true) String userId
+ public Result deleteUserRole(@RequestParam(name = "roleId") String roleId,
+ @RequestParam(name = "userId", required = true) String userId
) {
Result result = new Result();
try {
QueryWrapper queryWrapper = new QueryWrapper();
- queryWrapper.eq("role_id", roleId).eq("user_id",userId);
+ queryWrapper.eq("role_id", roleId).eq("user_id", userId);
sysUserRoleService.remove(queryWrapper);
result.success("删除成功!");
- }catch(Exception e) {
+ } catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("删除失败!");
}
@@ -723,15 +733,15 @@ public class SysUserController {
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteUserRoleBatch", method = RequestMethod.DELETE)
public Result deleteUserRoleBatch(
- @RequestParam(name="roleId") String roleId,
- @RequestParam(name="userIds",required=true) String userIds) {
+ @RequestParam(name = "roleId") String roleId,
+ @RequestParam(name = "userIds", required = true) String userIds) {
Result result = new Result();
try {
QueryWrapper queryWrapper = new QueryWrapper();
- queryWrapper.eq("role_id", roleId).in("user_id",Arrays.asList(userIds.split(",")));
+ queryWrapper.eq("role_id", roleId).in("user_id", Arrays.asList(userIds.split(",")));
sysUserRoleService.remove(queryWrapper);
result.success("删除成功!");
- }catch(Exception e) {
+ } catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("删除失败!");
}
@@ -742,8 +752,8 @@ public class SysUserController {
* 部门用户列表
*/
@RequestMapping(value = "/departUserList", method = RequestMethod.GET)
- public Result> departUserList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
+ public Result> departUserList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
Result> result = new Result>();
Page page = new Page(pageNo, pageSize);
String depId = req.getParameter("depId");
@@ -751,22 +761,22 @@ public class SysUserController {
//根据部门ID查询,当前和下级所有的部门IDS
List subDepids = new ArrayList<>();
//部门id为空时,查询我的部门下所有用户
- if(oConvertUtils.isEmpty(depId)){
+ if (oConvertUtils.isEmpty(depId)) {
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
- int userIdentity = user.getUserIdentity() != null?user.getUserIdentity():CommonConstant.USER_IDENTITY_1;
- if(oConvertUtils.isNotEmpty(userIdentity) && userIdentity == CommonConstant.USER_IDENTITY_2 ){
+ int userIdentity = user.getUserIdentity() != null ? user.getUserIdentity() : CommonConstant.USER_IDENTITY_1;
+ if (oConvertUtils.isNotEmpty(userIdentity) && userIdentity == CommonConstant.USER_IDENTITY_2) {
subDepids = sysDepartService.getMySubDepIdsByDepId(user.getDepartIds());
}
- }else{
+ } else {
subDepids = sysDepartService.getSubDepIdsByDepId(depId);
}
- if(subDepids != null && subDepids.size()>0){
- IPage pageList = sysUserService.getUserByDepIds(page,subDepids,username);
+ if (subDepids != null && subDepids.size() > 0) {
+ IPage pageList = sysUserService.getUserByDepIds(page, subDepids, username);
//批量查询用户的所属部门
//step.1 先拿到全部的 useids
//step.2 通过 useids,一次性查询用户的所属部门名字
List userIds = pageList.getRecords().stream().map(SysUser::getId).collect(Collectors.toList());
- if(userIds!=null && userIds.size()>0){
+ if (userIds != null && userIds.size() > 0) {
Map useDepNames = sysUserService.getDepNamesByUserIds(userIds);
pageList.getRecords().forEach(item -> {
//批量查询用户的所属部门
@@ -775,7 +785,7 @@ public class SysUserController {
}
result.setSuccess(true);
result.setResult(pageList);
- }else{
+ } else {
result.setSuccess(true);
result.setResult(null);
}
@@ -806,7 +816,7 @@ public class SysUserController {
public Result> queryByOrgCodeForAddressList(
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
- @RequestParam(name = "orgCode",required = false) String orgCode,
+ @RequestParam(name = "orgCode", required = false) String orgCode,
SysUser userParams
) {
IPage page = new Page(pageNo, pageSize);
@@ -853,19 +863,19 @@ public class SysUserController {
Result result = new Result();
try {
String sysDepId = sysDepartUsersVO.getDepId();
- for(String sysUserId:sysDepartUsersVO.getUserIdList()) {
- SysUserDepart sysUserDepart = new SysUserDepart(null,sysUserId,sysDepId);
+ for (String sysUserId : sysDepartUsersVO.getUserIdList()) {
+ SysUserDepart sysUserDepart = new SysUserDepart(null, sysUserId, sysDepId);
QueryWrapper queryWrapper = new QueryWrapper();
- queryWrapper.eq("dep_id", sysDepId).eq("user_id",sysUserId);
+ queryWrapper.eq("dep_id", sysDepId).eq("user_id", sysUserId);
SysUserDepart one = sysUserDepartService.getOne(queryWrapper);
- if(one==null){
+ if (one == null) {
sysUserDepartService.save(sysUserDepart);
}
}
result.setMessage("添加成功!");
result.setSuccess(true);
return result;
- }catch(Exception e) {
+ } catch (Exception e) {
log.error(e.getMessage(), e);
result.setSuccess(false);
result.setMessage("出错了: " + e.getMessage());
@@ -874,31 +884,31 @@ public class SysUserController {
}
/**
- * 删除指定机构的用户关系
+ * 删除指定机构的用户关系
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteUserInDepart", method = RequestMethod.DELETE)
- public Result deleteUserInDepart(@RequestParam(name="depId") String depId,
- @RequestParam(name="userId",required=true) String userId
+ public Result deleteUserInDepart(@RequestParam(name = "depId") String depId,
+ @RequestParam(name = "userId", required = true) String userId
) {
Result result = new Result();
try {
QueryWrapper queryWrapper = new QueryWrapper();
- queryWrapper.eq("dep_id", depId).eq("user_id",userId);
+ queryWrapper.eq("dep_id", depId).eq("user_id", userId);
boolean b = sysUserDepartService.remove(queryWrapper);
- if(b){
- List sysDepartRoleList = departRoleService.list(new QueryWrapper().eq("depart_id",depId));
+ if (b) {
+ List sysDepartRoleList = departRoleService.list(new QueryWrapper().eq("depart_id", depId));
List roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
- if(roleIds != null && roleIds.size()>0){
+ if (roleIds != null && roleIds.size() > 0) {
QueryWrapper query = new QueryWrapper<>();
- query.eq("user_id",userId).in("drole_id",roleIds);
+ query.eq("user_id", userId).in("drole_id", roleIds);
departRoleUserService.remove(query);
}
result.success("删除成功!");
- }else{
+ } else {
result.error500("当前选中部门与用户无关联关系!");
}
- }catch(Exception e) {
+ } catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("删除失败!");
}
@@ -911,18 +921,18 @@ public class SysUserController {
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteUserInDepartBatch", method = RequestMethod.DELETE)
public Result deleteUserInDepartBatch(
- @RequestParam(name="depId") String depId,
- @RequestParam(name="userIds",required=true) String userIds) {
+ @RequestParam(name = "depId") String depId,
+ @RequestParam(name = "userIds", required = true) String userIds) {
Result result = new Result();
try {
QueryWrapper queryWrapper = new QueryWrapper();
- queryWrapper.eq("dep_id", depId).in("user_id",Arrays.asList(userIds.split(",")));
+ queryWrapper.eq("dep_id", depId).in("user_id", Arrays.asList(userIds.split(",")));
boolean b = sysUserDepartService.remove(queryWrapper);
- if(b){
- departRoleUserService.removeDeptRoleUser(Arrays.asList(userIds.split(",")),depId);
+ if (b) {
+ departRoleUserService.removeDeptRoleUser(Arrays.asList(userIds.split(",")), depId);
}
result.success("删除成功!");
- }catch(Exception e) {
+ } catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("删除失败!");
}
@@ -930,21 +940,22 @@ public class SysUserController {
}
/**
- * 查询当前用户的所有部门/当前部门编码
+ * 查询当前用户的所有部门/当前部门编码
+ *
* @return
*/
@RequestMapping(value = "/getCurrentUserDeparts", method = RequestMethod.GET)
- public Result
*
* @Author scott
- * @since 2018-12-20
+ * @since 2023-04-12
*/
@Slf4j
@RestController
@@ -193,12 +194,12 @@ public class SysUserController {
//@RequiresRoles({"admin"})
//@RequiresPermissions("user:add")
+ @AutoLog
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result add(@RequestBody JSONObject jsonObject) {
Result result = new Result();
String selectedRoles = jsonObject.getString("selectedroles");
String selectedDeparts = jsonObject.getString("selecteddeparts");
-// System.out.println("我的测试" + selectedRoles);
try {
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
user.setCreateTime(new Date());//设置创建时间
@@ -208,9 +209,11 @@ public class SysUserController {
user.setPassword(passwordEncode);
user.setStatus(1);
user.setDelFlag(CommonConstant.DEL_FLAG_0);
+ //用户表字段org_code不能在这里设置他的值
+ user.setOrgCode(null);
// 保存用户走一个service 保证事务
- this.sysUserService.save(user);
-// sysUserService.saveUser(user, selectedRoles, selectedDeparts);
+ sysUserService.saveUser(user, selectedRoles, selectedDeparts);
+// baseCommonService.addLog("添加用户,username: " + user.getUsername(), CommonConstant.LOG_TYPE_2, 2);
result.success("添加成功!");
} catch (Exception e) {
log.error(e.getMessage(), e);
@@ -221,6 +224,7 @@ public class SysUserController {
//@RequiresRoles({"admin"})
//@RequiresPermissions("user:edit")
+ @AutoLog
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
public Result edit(@RequestBody JSONObject jsonObject) {
Result result = new Result();
@@ -237,8 +241,8 @@ public class SysUserController {
String roles = jsonObject.getString("selectedroles");
String departs = jsonObject.getString("selecteddeparts");
// 修改用户走一个service 保证事务
- sysUserService.updateById(user);
-// sysUserService.editUser(user, roles, departs);
+// sysUserService.updateById(user);
+ sysUserService.editUser(user, roles, departs);
result.success("修改成功!");
}
} catch (Exception e) {
@@ -252,6 +256,7 @@ public class SysUserController {
* 删除用户
*/
//@RequiresRoles({"admin"})
+ @AutoLog
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
public Result> delete(@RequestParam(name = "id", required = true) String id) {
this.sysUserService.removeById(id);
@@ -266,8 +271,8 @@ public class SysUserController {
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
public Result> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
- baseCommonService.addLog("批量删除用户, ids: " + ids, CommonConstant.LOG_TYPE_2, 3);
- this.sysUserService.deleteBatchUsers(ids);
+// baseCommonService.addLog("批量删除用户, ids: " + ids, CommonConstant.LOG_TYPE_2, 3);
+ this.sysUserService.removeByIds(Arrays.asList(ids.split(",")));
return Result.ok("批量删除用户成功");
}
diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
index 90c9b1b..790af86 100644
--- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
+++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
@@ -44,34 +44,34 @@ import java.util.stream.Collectors;
@Slf4j
public class SysUserServiceImpl extends ServiceImpl implements ISysUserService {
- @Autowired
- private SysUserMapper userMapper;
- @Autowired
- private SysPermissionMapper sysPermissionMapper;
- @Autowired
- private SysUserRoleMapper sysUserRoleMapper;
- @Autowired
- private SysUserDepartMapper sysUserDepartMapper;
- @Autowired
- private ISysBaseAPI sysBaseAPI;
- @Autowired
- private SysDepartMapper sysDepartMapper;
- @Autowired
- private SysRoleMapper sysRoleMapper;
- @Autowired
- private SysDepartRoleUserMapper departRoleUserMapper;
- @Autowired
- private SysDepartRoleMapper sysDepartRoleMapper;
- @Resource
- private BaseCommonService baseCommonService;
- @Autowired
- private SysThirdAccountMapper sysThirdAccountMapper;
- @Autowired
- ThirdAppWechatEnterpriseServiceImpl wechatEnterpriseService;
- @Autowired
- ThirdAppDingtalkServiceImpl dingtalkService;
- @Autowired
- private IJxStudentService jxStudentService;
+ @Autowired
+ private SysUserMapper userMapper;
+ @Autowired
+ private SysPermissionMapper sysPermissionMapper;
+ @Autowired
+ private SysUserRoleMapper sysUserRoleMapper;
+ @Autowired
+ private SysUserDepartMapper sysUserDepartMapper;
+ @Autowired
+ private ISysBaseAPI sysBaseAPI;
+ @Autowired
+ private SysDepartMapper sysDepartMapper;
+ @Autowired
+ private SysRoleMapper sysRoleMapper;
+ @Autowired
+ private SysDepartRoleUserMapper departRoleUserMapper;
+ @Autowired
+ private SysDepartRoleMapper sysDepartRoleMapper;
+ @Resource
+ private BaseCommonService baseCommonService;
+ @Autowired
+ private SysThirdAccountMapper sysThirdAccountMapper;
+ @Autowired
+ ThirdAppWechatEnterpriseServiceImpl wechatEnterpriseService;
+ @Autowired
+ ThirdAppDingtalkServiceImpl dingtalkService;
+ @Autowired
+ private IJxStudentService jxStudentService;
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
@@ -105,338 +105,342 @@ public class SysUserServiceImpl extends ServiceImpl impl
}
@Override
- @CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true)
- @Transactional(rollbackFor = Exception.class)
- public boolean deleteUser(String userId) {
- //1.删除用户
- this.removeById(userId);
- //暂时是直接把学生信息给物理删除了,实际上可以使用逻辑删除,因为用户表的删除在当前就是逻辑删除,虽然有物理删除,但他们之前好像没写,如果需要后期我可以添加。
- jxStudentService.removeById(userId);
- return false;
- }
-
- @Override
- @CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true)
- @Transactional(rollbackFor = Exception.class)
- public boolean deleteBatchUsers(String userIds) {
- //1.删除用户
- this.removeByIds(Arrays.asList(userIds.split(",")));
- //同上单个删除。
- jxStudentService.removeByIds(Arrays.asList(userIds.split(",")));
- return false;
- }
-
- @Override
- public SysUser getUserByName(String username) {
- return userMapper.getUserByName(username);
- }
-
-
- @Override
- @Transactional
- public void addUserWithRole(SysUser user, String roles) {
- this.save(user);
- if(oConvertUtils.isNotEmpty(roles)) {
- String[] arr = roles.split(",");
- for (String roleId : arr) {
- SysUserRole userRole = new SysUserRole(user.getId(), roleId);
- sysUserRoleMapper.insert(userRole);
- }
- }
- }
-
- @Override
- @CacheEvict(value= {CacheConstant.SYS_USERS_CACHE}, allEntries=true)
- @Transactional
- public void editUserWithRole(SysUser user, String roles) {
- this.updateById(user);
- //先删后加
- sysUserRoleMapper.delete(new QueryWrapper().lambda().eq(SysUserRole::getUserId, user.getId()));
- if(oConvertUtils.isNotEmpty(roles)) {
- String[] arr = roles.split(",");
- for (String roleId : arr) {
- SysUserRole userRole = new SysUserRole(user.getId(), roleId);
- sysUserRoleMapper.insert(userRole);
- }
- }
- }
-
-
- @Override
- public List getRole(String username) {
- return sysUserRoleMapper.getRoleByUserName(username);
- }
-
- /**
- * 通过用户名获取用户角色集合
- * @param username 用户名
+ @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
+ @Transactional(rollbackFor = Exception.class)
+ public boolean deleteUser(String userId) {
+ //1.删除用户
+ this.removeById(userId);
+ //暂时是直接把学生信息给物理删除了,实际上可以使用逻辑删除,因为用户表的删除在当前就是逻辑删除,虽然有物理删除,但他们之前好像没写,如果需要后期我可以添加。
+ jxStudentService.removeById(userId);
+ return false;
+ }
+
+ @Override
+ @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
+ @Transactional(rollbackFor = Exception.class)
+ public boolean deleteBatchUsers(String userIds) {
+ //1.删除用户
+ this.removeByIds(Arrays.asList(userIds.split(",")));
+ //同上单个删除。
+ jxStudentService.removeByIds(Arrays.asList(userIds.split(",")));
+ return false;
+ }
+
+ @Override
+ public SysUser getUserByName(String username) {
+ return userMapper.getUserByName(username);
+ }
+
+
+ @Override
+ @Transactional
+ public void addUserWithRole(SysUser user, String roles) {
+ this.save(user);
+ if (oConvertUtils.isNotEmpty(roles)) {
+ String[] arr = roles.split(",");
+ for (String roleId : arr) {
+ SysUserRole userRole = new SysUserRole(user.getId(), roleId);
+ sysUserRoleMapper.insert(userRole);
+ }
+ }
+ }
+
+ @Override
+ @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
+ @Transactional
+ public void editUserWithRole(SysUser user, String roles) {
+ this.updateById(user);
+ //先删后加
+ sysUserRoleMapper.delete(new QueryWrapper().lambda().eq(SysUserRole::getUserId, user.getId()));
+ if (oConvertUtils.isNotEmpty(roles)) {
+ String[] arr = roles.split(",");
+ for (String roleId : arr) {
+ SysUserRole userRole = new SysUserRole(user.getId(), roleId);
+ sysUserRoleMapper.insert(userRole);
+ }
+ }
+ }
+
+
+ @Override
+ public List getRole(String username) {
+ return sysUserRoleMapper.getRoleByUserName(username);
+ }
+
+ /**
+ * 通过用户名获取用户角色集合
+ *
+ * @param username 用户名
* @return 角色集合
- */
- @Override
- public Set getUserRolesSet(String username) {
- // 查询用户拥有的角色集合
- List roles = sysUserRoleMapper.getRoleByUserName(username);
- log.info("-------通过数据库读取用户拥有的角色Rules------username: " + username + ",Roles size: " + (roles == null ? 0 : roles.size()));
- return new HashSet<>(roles);
- }
-
- /**
- * 通过用户名获取用户权限集合
- *
- * @param username 用户名
- * @return 权限集合
- */
- @Override
- public Set getUserPermissionsSet(String username) {
- Set permissionSet = new HashSet<>();
- List permissionList = sysPermissionMapper.queryByUser(username);
- for (SysPermission po : permissionList) {
+ */
+ @Override
+ public Set getUserRolesSet(String username) {
+ // 查询用户拥有的角色集合
+ List roles = sysUserRoleMapper.getRoleByUserName(username);
+ log.info("-------通过数据库读取用户拥有的角色Rules------username: " + username + ",Roles size: " + (roles == null ? 0 : roles.size()));
+ return new HashSet<>(roles);
+ }
+
+ /**
+ * 通过用户名获取用户权限集合
+ *
+ * @param username 用户名
+ * @return 权限集合
+ */
+ @Override
+ public Set getUserPermissionsSet(String username) {
+ Set permissionSet = new HashSet<>();
+ List permissionList = sysPermissionMapper.queryByUser(username);
+ for (SysPermission po : permissionList) {
// // TODO URL规则有问题?
// if (oConvertUtils.isNotEmpty(po.getUrl())) {
// permissionSet.add(po.getUrl());
// }
- if (oConvertUtils.isNotEmpty(po.getPerms())) {
- permissionSet.add(po.getPerms());
- }
- }
- log.info("-------通过数据库读取用户拥有的权限Perms------username: "+ username+",Perms size: "+ (permissionSet==null?0:permissionSet.size()) );
- return permissionSet;
- }
-
- @Override
- public SysUserCacheInfo getCacheUser(String username) {
- SysUserCacheInfo info = new SysUserCacheInfo();
- info.setOneDepart(true);
+ if (oConvertUtils.isNotEmpty(po.getPerms())) {
+ permissionSet.add(po.getPerms());
+ }
+ }
+ log.info("-------通过数据库读取用户拥有的权限Perms------username: " + username + ",Perms size: " + (permissionSet == null ? 0 : permissionSet.size()));
+ return permissionSet;
+ }
+
+ @Override
+ public SysUserCacheInfo getCacheUser(String username) {
+ SysUserCacheInfo info = new SysUserCacheInfo();
+ info.setOneDepart(true);
// SysUser user = userMapper.getUserByName(username);
// info.setSysUserCode(user.getUsername());
// info.setSysUserName(user.getRealname());
- LoginUser user = sysBaseAPI.getUserByName(username);
- if(user!=null) {
- info.setSysUserCode(user.getUsername());
- info.setSysUserName(user.getRealname());
- info.setSysOrgCode(user.getOrgCode());
- }
-
- //多部门支持in查询
- List list = sysDepartMapper.queryUserDeparts(user.getId());
- List sysMultiOrgCode = new ArrayList();
- if(list==null || list.size()==0) {
- //当前用户无部门
- //sysMultiOrgCode.add("0");
- }else if(list.size()==1) {
- sysMultiOrgCode.add(list.get(0).getOrgCode());
- }else {
- info.setOneDepart(false);
- for (SysDepart dpt : list) {
- sysMultiOrgCode.add(dpt.getOrgCode());
- }
- }
- info.setSysMultiOrgCode(sysMultiOrgCode);
-
- return info;
- }
-
- // 根据部门Id查询
- @Override
- public IPage getUserByDepId(Page page, String departId,String username) {
- return userMapper.getUserByDepId(page, departId,username);
- }
-
- @Override
- public IPage getUserByDepIds(Page page, List departIds, String username) {
- return userMapper.getUserByDepIds(page, departIds,username);
- }
- @Override
- public List getUserByDepIds(List departIds, String username) {
- return userMapper.getUserByDepIds(departIds,username);
- }
- @Override
- public Map getDepNamesByUserIds(List userIds) {
- List list = this.baseMapper.getDepNamesByUserIds(userIds);
-
- Map res = new HashMap();
- list.forEach(item -> {
- if (res.get(item.getUserId()) == null) {
- res.put(item.getUserId(), item.getDepartName());
- } else {
- res.put(item.getUserId(), res.get(item.getUserId()) + "," + item.getDepartName());
- }
- }
- );
- return res;
- }
-
- @Override
- public IPage getUserByDepartIdAndQueryWrapper(Page page, String departId, QueryWrapper queryWrapper) {
- LambdaQueryWrapper lambdaQueryWrapper = queryWrapper.lambda();
-
- lambdaQueryWrapper.eq(SysUser::getDelFlag, CommonConstant.DEL_FLAG_0);
+ LoginUser user = sysBaseAPI.getUserByName(username);
+ if (user != null) {
+ info.setSysUserCode(user.getUsername());
+ info.setSysUserName(user.getRealname());
+ info.setSysOrgCode(user.getOrgCode());
+ }
+
+ //多部门支持in查询
+ List list = sysDepartMapper.queryUserDeparts(user.getId());
+ List sysMultiOrgCode = new ArrayList();
+ if (list == null || list.size() == 0) {
+ //当前用户无部门
+ //sysMultiOrgCode.add("0");
+ } else if (list.size() == 1) {
+ sysMultiOrgCode.add(list.get(0).getOrgCode());
+ } else {
+ info.setOneDepart(false);
+ for (SysDepart dpt : list) {
+ sysMultiOrgCode.add(dpt.getOrgCode());
+ }
+ }
+ info.setSysMultiOrgCode(sysMultiOrgCode);
+
+ return info;
+ }
+
+ // 根据部门Id查询
+ @Override
+ public IPage getUserByDepId(Page page, String departId, String username) {
+ return userMapper.getUserByDepId(page, departId, username);
+ }
+
+ @Override
+ public IPage getUserByDepIds(Page page, List departIds, String username) {
+ return userMapper.getUserByDepIds(page, departIds, username);
+ }
+
+ @Override
+ public List getUserByDepIds(List departIds, String username) {
+ return userMapper.getUserByDepIds(departIds, username);
+ }
+
+ @Override
+ public Map getDepNamesByUserIds(List userIds) {
+ List list = this.baseMapper.getDepNamesByUserIds(userIds);
+
+ Map res = new HashMap();
+ list.forEach(item -> {
+ if (res.get(item.getUserId()) == null) {
+ res.put(item.getUserId(), item.getDepartName());
+ } else {
+ res.put(item.getUserId(), res.get(item.getUserId()) + "," + item.getDepartName());
+ }
+ }
+ );
+ return res;
+ }
+
+ @Override
+ public IPage getUserByDepartIdAndQueryWrapper(Page page, String departId, QueryWrapper queryWrapper) {
+ LambdaQueryWrapper lambdaQueryWrapper = queryWrapper.lambda();
+
+ lambdaQueryWrapper.eq(SysUser::getDelFlag, CommonConstant.DEL_FLAG_0);
lambdaQueryWrapper.inSql(SysUser::getId, "SELECT user_id FROM sys_user_depart WHERE dep_id = '" + departId + "'");
return userMapper.selectPage(page, lambdaQueryWrapper);
- }
+ }
- @Override
- public IPage queryUserByOrgCode(String orgCode, SysUser userParams, IPage page) {
- List list = baseMapper.getUserByOrgCode(page, orgCode, userParams);
- Integer total = baseMapper.getUserByOrgCodeTotal(orgCode, userParams);
+ @Override
+ public IPage queryUserByOrgCode(String orgCode, SysUser userParams, IPage page) {
+ List list = baseMapper.getUserByOrgCode(page, orgCode, userParams);
+ Integer total = baseMapper.getUserByOrgCodeTotal(orgCode, userParams);
- IPage result = new Page<>(page.getCurrent(), page.getSize(), total);
- result.setRecords(list);
+ IPage result = new Page<>(page.getCurrent(), page.getSize(), total);
+ result.setRecords(list);
- return result;
- }
+ return result;
+ }
- // 根据角色Id查询
- @Override
- public IPage getUserByRoleId(Page page, String roleId, String username) {
- return userMapper.getUserByRoleId(page,roleId,username);
- }
+ // 根据角色Id查询
+ @Override
+ public IPage getUserByRoleId(Page page, String roleId, String username) {
+ return userMapper.getUserByRoleId(page, roleId, username);
+ }
- @Override
- @CacheEvict(value= {CacheConstant.SYS_USERS_CACHE}, key="#username")
- public void updateUserDepart(String username,String orgCode) {
- baseMapper.updateUserDepart(username, orgCode);
- }
+ @Override
+ @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, key = "#username")
+ public void updateUserDepart(String username, String orgCode) {
+ baseMapper.updateUserDepart(username, orgCode);
+ }
- @Override
- public SysUser getUserByPhone(String phone) {
- return userMapper.getUserByPhone(phone);
- }
+ @Override
+ public SysUser getUserByPhone(String phone) {
+ return userMapper.getUserByPhone(phone);
+ }
- @Override
- public SysUser getUserByEmail(String email) {
- return userMapper.getUserByEmail(email);
- }
+ @Override
+ public SysUser getUserByEmail(String email) {
+ return userMapper.getUserByEmail(email);
+ }
- @Override
- @Transactional
- public void addUserWithDepart(SysUser user, String selectedParts) {
+ @Override
+ @Transactional
+ public void addUserWithDepart(SysUser user, String selectedParts) {
// this.save(user); //保存角色的时候已经添加过一次了
- if(oConvertUtils.isNotEmpty(selectedParts)) {
- String[] arr = selectedParts.split(",");
- for (String deaprtId : arr) {
- SysUserDepart userDeaprt = new SysUserDepart(user.getId(), deaprtId);
- sysUserDepartMapper.insert(userDeaprt);
- }
- }
- }
-
-
- @Override
- @Transactional(rollbackFor = Exception.class)
- @CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true)
- public void editUserWithDepart(SysUser user, String departs) {
- this.updateById(user); //更新角色的时候已经更新了一次了,可以再跟新一次
- String[] arr = {};
- if(oConvertUtils.isNotEmpty(departs)){
- arr = departs.split(",");
- }
- //查询已关联部门
- List userDepartList = sysUserDepartMapper.selectList(new QueryWrapper().lambda().eq(SysUserDepart::getUserId, user.getId()));
- if(userDepartList != null && userDepartList.size()>0){
- for(SysUserDepart depart : userDepartList ){
- //修改已关联部门删除部门用户角色关系
- if(!Arrays.asList(arr).contains(depart.getDepId())){
- List sysDepartRoleList = sysDepartRoleMapper.selectList(
- new QueryWrapper().lambda().eq(SysDepartRole::getDepartId,depart.getDepId()));
- List roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
- if(roleIds != null && roleIds.size()>0){
- departRoleUserMapper.delete(new QueryWrapper().lambda().eq(SysDepartRoleUser::getUserId, user.getId())
- .in(SysDepartRoleUser::getDroleId,roleIds));
- }
- }
- }
- }
- //先删后加
- sysUserDepartMapper.delete(new QueryWrapper().lambda().eq(SysUserDepart::getUserId, user.getId()));
- if(oConvertUtils.isNotEmpty(departs)) {
- for (String departId : arr) {
- SysUserDepart userDepart = new SysUserDepart(user.getId(), departId);
- sysUserDepartMapper.insert(userDepart);
- }
- }
- }
-
-
- /**
- * 校验用户是否有效
- * @param sysUser
- * @return
- */
- @Override
- public Result> checkUserIsEffective(SysUser sysUser) {
- Result> result = new Result