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..38c08b9 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
@@ -14,18 +14,19 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.apache.shiro.authz.annotation.RequiresRoles;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
-import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
-import org.jeecg.common.util.*;
+import org.jeecg.common.util.ImportExcelUtil;
+import org.jeecg.common.util.PasswordUtil;
+import org.jeecg.common.util.RedisUtil;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.model.DepartIdModel;
import org.jeecg.modules.system.model.SysUserSysDepartModel;
@@ -57,29 +58,29 @@ import java.util.stream.Collectors;
*
*
* @Author scott
- * @since 2018-12-20
+ * @since 2023-04-12
*/
@Slf4j
@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 +88,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 +99,7 @@ public class SysUserController {
/**
* 获取用户列表数据
+ *
* @param user
* @param pageNo
* @param pageSize
@@ -105,35 +107,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 +143,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 +157,7 @@ public class SysUserController {
/**
* 获取员工列表数据
+ *
* @param user
* @param pageNo
* @param pageSize
@@ -163,13 +166,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 +180,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 +194,114 @@ 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;
- }
+ @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");
+ 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);
+ //用户表字段org_code不能在这里设置他的值
+ user.setOrgCode(null);
+ // 保存用户走一个service 保证事务
+ 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);
+ 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");
+ @AutoLog
+ @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"})
+ @AutoLog
+ @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.removeByIds(Arrays.asList(ids.split(",")));
+ 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 +326,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 +355,8 @@ public class SysUserController {
/**
- * 校验用户账号是否唯一
- * 可以校验其他 需要检验什么就传什么。。。
+ * 校验用户账号是否唯一
+ * 可以校验其他 需要检验什么就传什么。。。
*
* @param sysUser
* @return
@@ -409,7 +420,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 +450,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 +473,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 +481,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 +515,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 +549,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 +615,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 +684,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 +697,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 +738,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 +757,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 +766,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 +790,7 @@ public class SysUserController {
}
result.setSuccess(true);
result.setResult(pageList);
- }else{
+ } else {
result.setSuccess(true);
result.setResult(null);
}
@@ -806,7 +821,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 +868,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 +889,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 +926,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 +945,22 @@ public class SysUserController {
}
/**
- * 查询当前用户的所有部门/当前部门编码
+ * 查询当前用户的所有部门/当前部门编码
+ *
* @return
*/
@RequestMapping(value = "/getCurrentUserDeparts", method = RequestMethod.GET)
- public Result