| | |
| | | import com.kidgrow.common.context.ClientContextHolder; |
| | | import com.kidgrow.common.model.*; |
| | | import com.kidgrow.common.utils.ExcelUtil; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.log.annotation.AuditLog; |
| | | import com.kidgrow.searchcenter.client.service.IQueryService; |
| | | import com.kidgrow.searchcenter.model.LogicDelDto; |
| | |
| | | import com.kidgrow.usercenter.model.SysUserExcel; |
| | | import com.kidgrow.usercenter.model.SysUserLogs; |
| | | import com.kidgrow.usercenter.service.ISysUserService; |
| | | import com.kidgrow.usercenter.vo.UserRegVo; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | public class SysUserController { |
| | | private static final String ADMIN_CHANGE_MSG = "超级管理员不给予修改"; |
| | | |
| | | |
| | | /** |
| | | * 全文搜索逻辑删除Dto |
| | | */ |
| | |
| | | */ |
| | | @ApiOperation(value = "根据access_token当前登录用户") |
| | | @GetMapping("/users/current") |
| | | public ResultBody<LoginAppUser> getLoginAppUser(@LoginUser(isFull = true) SysUser user) { |
| | | public ResultBody<LoginAppUser> getLoginAppUser(@LoginUser(isFull = true) SysUser user,HttpServletRequest request) { |
| | | if(user!=null){ |
| | | loginLogs(user, request); |
| | | } |
| | | return ResultBody.ok().data(appUserService.getLoginAppUser(user)); |
| | | } |
| | | |
| | |
| | | @ApiOperation(value = "根据用户名查询用户实体") |
| | | @Cacheable(value = "user", key = "#username") |
| | | public SysUser selectByUsername(@PathVariable String username) { |
| | | |
| | | return appUserService.selectByUsername(username); |
| | | } |
| | | |
| | |
| | | */ |
| | | @GetMapping(value = "/users-anon/login", params = "username") |
| | | @ApiOperation(value = "根据用户名查询用户") |
| | | public LoginAppUser findByUsername(String username,HttpServletRequest request) { |
| | | |
| | | LoginAppUser loginAppUser =appUserService.findByUsername(username); |
| | | if(loginAppUser!=null){ |
| | | loginLogs(loginAppUser,request); |
| | | } |
| | | public LoginAppUser findByUsername(String username) { |
| | | LoginAppUser loginAppUser = appUserService.findByUsername(username); |
| | | return loginAppUser; |
| | | } |
| | | |
| | | /** |
| | | * 用户登录日志 |
| | | * |
| | | * @param sysUser |
| | | * @return |
| | | */ |
| | | private int loginLogs(LoginAppUser sysUser,HttpServletRequest request){ |
| | | private int loginLogs(SysUser sysUser, HttpServletRequest request) { |
| | | SysUserLogs sysUserLogs = new SysUserLogs(); |
| | | sysUserLogs.setClientId(ClientContextHolder.getClient()); |
| | | sysUserLogs.setLoginAgentSystem(request.getHeader(CommonConstant.USER_AGENT_SYSTEM)); |
| | | sysUserLogs.setLoginAgentBrowser(request.getHeader(CommonConstant.USER_AGENT_BROWSER)); |
| | | sysUserLogs.setLoginIp(request.getHeader(CommonConstant.USER_AGENT_IP)); |
| | | sysUserLogs.setLoginSystemScreen(request.getHeader(CommonConstant.USER_AGENT_SYSTEM_SCREEN)); |
| | | sysUserLogs.setLoginTime(new Date()); |
| | | sysUserLogs.setUserid(sysUser.getId()); |
| | | sysUserLogs.setUsername(sysUser.getUsername()); |
| | |
| | | * @param sysUser |
| | | */ |
| | | @PutMapping("/users") |
| | | @CachePut(value = "user", key = "#sysUser.username", unless="#result == null") |
| | | @CachePut(value = "user", key = "#sysUser.username", unless = "#result == null") |
| | | @AuditLog(operation = "'更新用户:' + #sysUser") |
| | | public ResultBody updateSysUser(@RequestBody SysUser sysUser) { |
| | | appUserService.updateById(sysUser); |
| | |
| | | // log.info("IP:"+request.getHeader(CommonConstant.USER_AGENT_IP)); |
| | | return appUserService.findUsers(params); |
| | | } |
| | | /** |
| | | * 获取医院科室下的所有有效的医生 |
| | | * @param hospitalId |
| | | * @param departmentId |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "用户查询列表") |
| | | @GetMapping("/users/HDoctorusers") |
| | | public ResultBody hospitalDoctorList(@RequestParam Long hospitalId, Long departmentId,boolean isIncluddel) { |
| | | if (StringUtils.isNotBlank(hospitalId.toString()) && StringUtils.isNotBlank(departmentId.toString())) { |
| | | return appUserService.hospitalDoctorList(hospitalId, departmentId,isIncluddel); |
| | | } else { |
| | | return ResultBody.failed("查询参数有误"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改用户状态 |
| | |
| | | |
| | | /** |
| | | * 管理后台,给用户重置密码 |
| | | * 重置密码后,会将新密码返回到data字段。 |
| | | * |
| | | * @param id |
| | | */ |
| | | @PutMapping(value = "/users/{id}/password") |
| | | @AuditLog(operation = "'重置用户密码:' + #id") |
| | | public ResultBody resetPassword(@PathVariable Long id) { |
| | | public ResultBody resetPassword(@PathVariable Long id) throws Exception{ |
| | | if (checkAdmin(id)) { |
| | | return ResultBody.failed(ADMIN_CHANGE_MSG); |
| | | } |
| | | appUserService.updatePassword(id, null, null); |
| | | return ResultBody.ok().msg("重置成功"); |
| | | return appUserService.updatePassword(id, null, null, true); |
| | | } |
| | | |
| | | /** |
| | | * 返回给Python加密密码 |
| | | */ |
| | | @GetMapping(value = "/users/python") |
| | | public ResultBody jiaMipython(@RequestBody String password) { |
| | | if (password==null||"".equals(password)) { |
| | | return ResultBody.failed().msg("请输入密码"); |
| | | } |
| | | ResultBody resultBody = appUserService.jiaMipython(password); |
| | | return resultBody; |
| | | } |
| | | |
| | | /** |
| | | * 用户自己修改密码 |
| | | */ |
| | | @PutMapping(value = "/users/password") |
| | | public ResultBody resetPassword(@RequestBody SysUser sysUser) { |
| | | public ResultBody resetPassword(@RequestBody SysUser sysUser) throws Exception { |
| | | if (checkAdmin(sysUser.getId())) { |
| | | return ResultBody.failed().msg(ADMIN_CHANGE_MSG); |
| | | } |
| | | appUserService.updatePassword(sysUser.getId(), sysUser.getOldPassword(), sysUser.getNewPassword()); |
| | | return ResultBody.ok().msg("重置成功"); |
| | | ResultBody resultBody = appUserService.updatePassword(sysUser.getId(), sysUser.getOldPassword(), sysUser.getNewPassword(), false); |
| | | return resultBody; |
| | | } |
| | | |
| | | /** |
| | | * 用户自己修改密码-后端以外 |
| | | */ |
| | | @PutMapping(value = "/users/resetpassword") |
| | | public ResultBody resetClientPassword(@RequestParam Map<String, Object> params) throws Exception { |
| | | Long id = MapUtils.getLong(params, "id"); |
| | | String oldPassword = MapUtils.getString(params, "oldPassword"); |
| | | String newPassword = MapUtils.getString(params, "newPassword"); |
| | | String refPassword = MapUtils.getString(params, "refPassword"); |
| | | if (id > 0 && !oldPassword.isEmpty() && !newPassword.isEmpty() && !refPassword.isEmpty()) { |
| | | if (refPassword.equals(newPassword)) { |
| | | return appUserService.updatePassword(id, oldPassword, newPassword, false).data(true).msg("密码修改成功!"); |
| | | } else { |
| | | return ResultBody.failed("两次新密码输入不一致!").data(false); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("必须参数有误!").data(false); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 用户修改自己的手机号 |
| | | * |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @PutMapping(value = "/users/updateusertel") |
| | | public ResultBody updateUserTel(@RequestParam Map<String, Object> params,@LoginUser SysUser sysUser) throws Exception { |
| | | String oldTel = MapUtils.getString(params, "oldTel"); |
| | | if (oldTel==null){ |
| | | return ResultBody.failed("请输入原账号"); |
| | | } |
| | | if(!sysUser.getUsername().equals(oldTel)){ |
| | | return ResultBody.failed("请输入正确的原账号"); |
| | | } |
| | | return appUserService.updateUserTel(params); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (checkAdmin(id)) { |
| | | return ResultBody.failed(ADMIN_CHANGE_MSG); |
| | | } |
| | | appUserService.delUser(id); |
| | | return ResultBody.ok().msg("删除成功"); |
| | | boolean v = appUserService.delUser(id); |
| | | return ResultBody.ok().msg("删除成功").data(v); |
| | | } |
| | | |
| | | /** |
| | | * 删除用户 不删除关系表 ,role_user 表 和 用户组织 |
| | | * |
| | | * @param id |
| | | */ |
| | | @DeleteMapping(value = "/users/deleteNoContact/{id}") |
| | | //@AuditLog(operation = "'删除用户:' + #id") |
| | | public ResultBody deleteNoContact(@PathVariable Long id) { |
| | | if (checkAdmin(id)) { |
| | | return ResultBody.failed(ADMIN_CHANGE_MSG); |
| | | } |
| | | boolean v = appUserService.deleteNoContact(id); |
| | | return ResultBody.ok().msg("删除成功").data(v); |
| | | } |
| | | |
| | | /** |
| | | * 新增or更新 |
| | |
| | | @AuditLog(operation = "'新增或更新用户:' + #sysUser.username") |
| | | public ResultBody saveOrUpdate(@RequestBody SysUser sysUser) { |
| | | return appUserService.saveOrUpdateUser(sysUser); |
| | | } |
| | | |
| | | /** |
| | | * 用户注册,添加用户 |
| | | * @param userRegVo 注册信息 |
| | | * @param sysUser 当前登录用户 |
| | | * @return |
| | | */ |
| | | @PostMapping("/users/doctorUserReg") |
| | | @AuditLog(operation = "'注册/添加用户:' + #userRegVo.mobile") |
| | | public ResultBody doctorUserReg(@RequestBody UserRegVo userRegVo,SysUser sysUser) throws Exception { |
| | | return appUserService.doctorUserReg(userRegVo,sysUser); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PostMapping(value = "/users/import") |
| | | public ResultBody importExcl(@RequestParam("file") MultipartFile excl) throws Exception { |
| | | int rowNum = 0; |
| | | if(!excl.isEmpty()) { |
| | | if (!excl.isEmpty()) { |
| | | List<SysUserExcel> list = ExcelUtil.importExcel(excl, 0, 1, SysUserExcel.class); |
| | | rowNum = list.size(); |
| | | if (rowNum > 0) { |
| | |
| | | appUserService.saveBatch(users); |
| | | } |
| | | } |
| | | return ResultBody.ok().msg("导入数据成功,一共【"+rowNum+"】行"); |
| | | return ResultBody.ok().msg("导入数据成功,一共【" + rowNum + "】行"); |
| | | } |
| | | |
| | | @ApiOperation(value = "用户全文搜索列表") |
| | |
| | | } |
| | | |
| | | /** |
| | | * 是否超级管理员 |
| | | * 根据map查询 |
| | | */ |
| | | private boolean checkAdmin(long id) { |
| | | return id == 1L; |
| | | } |
| | | |
| | | @PostMapping("/users/findAll") |
| | | public ResultBody findAll(@RequestParam Map<String,Object> map) { |
| | | public ResultBody findAll(@RequestBody Map<String, Object> map) { |
| | | return appUserService.findAll(map); |
| | | } |
| | | |
| | | /** |
| | | * 根据map查询 总个数 |
| | | * |
| | | * @param map |
| | | * @return |
| | | */ |
| | | @PostMapping("/users/findCountByMap") |
| | | public ResultBody findCountByMap(@RequestBody Map<String, Object> map) { |
| | | return appUserService.findCountByMap(map); |
| | | } |
| | | |
| | | /** |
| | | * 获取当前用的 组织下的所有人员 |
| | | */ |
| | | @GetMapping("users/getThisUserOrganizationUser") |
| | | public ResultBody getThisUserOrganizationUser(HttpServletRequest request){ |
| | | public ResultBody getThisUserOrganizationUser(HttpServletRequest request) { |
| | | return appUserService.getThisUserOrganizationUser(request); |
| | | } |
| | | |
| | | /** |
| | | * 通过手机修改密码 |
| | | */ |
| | | @PutMapping(value = "/users/passwordByPhone") |
| | | public ResultBody passwordByPhone(@RequestBody Map<String, Object> map) throws Exception { |
| | | return appUserService.passwordByPhone(map); |
| | | } |
| | | |
| | | /** |
| | | * 通过手机号注册 新用户 |
| | | */ |
| | | @PutMapping(value = "/users/registerByPhone") |
| | | public ResultBody registerByPhone(@RequestBody Map<String, Object> map) { |
| | | return appUserService.registerByPhone(map); |
| | | } |
| | | |
| | | /** |
| | | * 更换手机号 |
| | | */ |
| | | @PutMapping(value = "/users/updatePhone") |
| | | public ResultBody updatePhone(@RequestBody Map<String, Object> map, @LoginUser SysUser sysUser) { |
| | | return appUserService.updatePhone(map, sysUser); |
| | | } |
| | | |
| | | /** |
| | | * 获取指定用户信息(销售人员和服务人员) |
| | | */ |
| | | @GetMapping("users/getAppointUser") |
| | | public ResultBody getAppointUser() { |
| | | String type = request.getParameter("type"); |
| | | |
| | | return appUserService.findAppointUsers(Integer.parseInt(type)); |
| | | } |
| | | /** |
| | | * 检查该手机号是否注册 false 未注册 true已经注册 |
| | | */ |
| | | @GetMapping("users/isRegUser") |
| | | public ResultBody isRegUser(String userTel) { |
| | | |
| | | if(appUserService.phoneIsUsed(userTel)) |
| | | { |
| | | return ResultBody.ok().data(true); |
| | | } |
| | | return ResultBody.failed().data(false); |
| | | } |
| | | } |