| | |
| | | package com.ycl.controller.user; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.read.listener.ReadListener; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ycl.annotation.LogSave; |
| | | import com.ycl.api.CommonResult; |
| | | import com.ycl.bo.AdminUserDetails; |
| | | import com.ycl.controller.BaseController; |
| | | import com.ycl.dto.UmsAdminLoginParam; |
| | | import com.ycl.dto.UmsAdminParam; |
| | | import com.ycl.dto.UpdateAdminPasswordParam; |
| | | import com.ycl.dto.*; |
| | | import com.ycl.dto.user.UmsAdminParamDto; |
| | | import com.ycl.dto.user.UmsUserDto1; |
| | | import com.ycl.entity.depart.UmsDepart; |
| | | import com.ycl.entity.dict.DataDictionary; |
| | | import com.ycl.entity.user.UmsAdmin; |
| | | import com.ycl.entity.user.UmsRole; |
| | | import com.ycl.mapper.depart.UmsDepartMapper; |
| | | import com.ycl.mapper.dict.DataDictionary2Mapper; |
| | | import com.ycl.mapper.user.UmsAdminMapper; |
| | | import com.ycl.mapper.user.UmsRoleMapper; |
| | | import com.ycl.service.redis.RedisService; |
| | | import com.ycl.service.user.UmsAdminService; |
| | | import com.ycl.service.user.UmsRoleService; |
| | | import com.ycl.service.user.UmsMenuService; |
| | | import com.ycl.utils.AesEncryptUtil; |
| | | import com.ycl.utils.EasyExcelUtils; |
| | | import com.ycl.utils.redis.RedisKey; |
| | | import com.ycl.vo.user.UserVO; |
| | | import io.swagger.annotations.Api; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.security.Principal; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | private UmsAdminService adminService; |
| | | @Autowired |
| | | private UmsRoleService roleService; |
| | | UmsMenuService umsMenuService; |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @ApiOperation(value = "用户注册") |
| | | @RequestMapping(value = "/register", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | @LogSave(operationType = "用户管理",contain = "添加用户") |
| | | @LogSave(operationType = "用户管理", contain = "添加用户") |
| | | public CommonResult<UmsAdmin> register(@Validated @RequestBody UmsAdminParam umsAdminParam) { |
| | | UmsAdmin umsAdmin = adminService.register(umsAdminParam); |
| | | if (umsAdmin == null) { |
| | |
| | | @ApiOperation(value = "登录以后返回token") |
| | | @RequestMapping(value = "/login", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | public CommonResult login(@Validated @RequestBody UmsAdminLoginParam umsAdminLoginParam) { |
| | | String token = adminService.login(umsAdminLoginParam.getUsername(), umsAdminLoginParam.getPassword()); |
| | | public CommonResult login(@Validated @RequestBody UmsAdminLoginParam umsAdminLoginParam) throws Exception { |
| | | String password = AesEncryptUtil.desEncrypt(umsAdminLoginParam.getPassword()); |
| | | // String password = umsAdminLoginParam.getPassword(); |
| | | String token = adminService.login(umsAdminLoginParam.getUsername(), password); |
| | | |
| | | if (token == null) { |
| | | return CommonResult.validateFailed("用户名或密码错误"); |
| | | } |
| | |
| | | } |
| | | String username = principal.getName(); |
| | | UmsAdmin umsAdmin = adminService.getAdminByUsername(username); |
| | | AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("userId", umsAdmin.getId()); |
| | | data.put("username", umsAdmin.getUsername()); |
| | | data.put("menus", roleService.getMenuList(umsAdmin.getId())); |
| | | data.put("icon", umsAdmin.getIcon()); |
| | | data.put("user", umsAdmin); |
| | | data.put("menus", umsMenuService.ListTreeMyself(user.getUserId())); |
| | | List<UmsRole> roleList = adminService.getRoleList(umsAdmin.getId()); |
| | | if (CollUtil.isNotEmpty(roleList)) { |
| | | List<String> roles = roleList.stream().map(UmsRole::getName).collect(Collectors.toList()); |
| | |
| | | return CommonResult.success(page); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("用户导出") |
| | | @PostMapping("/export") |
| | | public void exportUser(HttpServletResponse response) { |
| | | List<UmsUserDto1> umsUserDtos = adminService.userExp(); |
| | | String sheetName = "用户导出"; |
| | | EasyExcelUtils.export1(response, sheetName, UmsUserDto1.class, umsUserDtos, "用户导出"); |
| | | } |
| | | |
| | | @Resource |
| | | private UmsRoleMapper umsRoleMapper; |
| | | @Resource |
| | | private UmsAdminMapper umsAdminMapper; |
| | | @Resource |
| | | private DataDictionary2Mapper dataDictionary2Mapper; |
| | | @Resource |
| | | private UmsDepartMapper umsDepartMapper; |
| | | |
| | | @ApiOperation("用户导入") |
| | | @PostMapping("/import") |
| | | public CommonResult importUser(MultipartFile file) throws IOException { |
| | | EasyExcel.read(file.getInputStream()) |
| | | .head(UmsAdminParamDto.class) |
| | | .registerReadListener(new ReadListener<UmsAdminParamDto>() { |
| | | @Override |
| | | public void invoke(UmsAdminParamDto item, AnalysisContext analysisContext) { |
| | | UmsAdminParam param = new UmsAdminParam(); |
| | | param.setUsername(item.getUsername()); |
| | | param.setPassword(item.getPassword()); |
| | | param.setNickName(item.getNickName()); |
| | | |
| | | String sex = item.getSex(); |
| | | if (sex.equals("男")) { |
| | | param.setSex((byte) 1); |
| | | } else if (sex.equals("女")) { |
| | | param.setSex((byte) 0); |
| | | } else { |
| | | throw new RuntimeException("性别输入有误"); |
| | | } |
| | | |
| | | String isDy = item.getIsDy(); |
| | | if (isDy.equals("是")) { |
| | | param.setSex((byte) 1); |
| | | } else if (isDy.equals("否")) { |
| | | param.setSex((byte) 0); |
| | | } else { |
| | | throw new RuntimeException("党员输入有误"); |
| | | } |
| | | |
| | | param.setMobile(item.getMobile()); |
| | | param.setEmail(item.getEmail()); |
| | | |
| | | String role = item.getRole(); |
| | | UmsRole umsRole = umsRoleMapper.selectOne(new LambdaQueryWrapper<UmsRole>().eq(UmsRole::getName, role)); |
| | | if (Objects.isNull(umsRole)) { |
| | | param.setRoleIds(null); |
| | | } else { |
| | | List list = new ArrayList<>(); |
| | | list.add(umsRole.getId()); |
| | | param.setRoleIds(list); |
| | | } |
| | | |
| | | String userType = item.getUserType(); |
| | | DataDictionary dataDictionary = dataDictionary2Mapper.selectOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getName, userType)); |
| | | if (Objects.isNull(dataDictionary)) { |
| | | throw new RuntimeException("用户类型不存在"); |
| | | } else { |
| | | param.setUserType(dataDictionary.getId().intValue()); |
| | | } |
| | | |
| | | String department = item.getDepartment(); |
| | | UmsDepart umsDepart = umsDepartMapper.selectOne(new LambdaQueryWrapper<UmsDepart>().eq(UmsDepart::getDepartName, department)); |
| | | if (Objects.isNull(umsDepart)) { |
| | | throw new RuntimeException("部门不存在"); |
| | | } else { |
| | | param.setDepartmentId(umsDepart.getId()); |
| | | } |
| | | |
| | | param.setJobTitle(item.getJobTitle()); |
| | | |
| | | adminService.importExcl(param); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| | | |
| | | } |
| | | }).sheet().doRead(); |
| | | return CommonResult.success(true, "导入成功"); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("获取指定用户信息") |
| | | @RequestMapping(value = "/{id}", method = RequestMethod.GET) |
| | | @ResponseBody |
| | |
| | | @ApiOperation("修改指定用户信息") |
| | | @RequestMapping(value = "/update/{id}", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | @LogSave(operationType = "用户管理",contain = "修改用户") |
| | | @LogSave(operationType = "用户管理", contain = "修改用户") |
| | | public CommonResult update(@PathVariable Long id, @RequestBody UmsAdmin admin) { |
| | | boolean success = adminService.update(id, admin); |
| | | if (success) { |
| | |
| | | @ApiOperation("修改指定用户密码") |
| | | @RequestMapping(value = "/updatePassword", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | @LogSave(operationType = "用户管理",contain = "修改用户密码") |
| | | @LogSave(operationType = "用户管理", contain = "修改用户密码") |
| | | public CommonResult updatePassword(@Validated @RequestBody UpdateAdminPasswordParam updatePasswordParam) { |
| | | int status = adminService.updatePassword(updatePasswordParam); |
| | | if (status > 0) { |
| | | return CommonResult.success(status); |
| | | } else if (status == -1) { |
| | | return CommonResult.failed("提交参数不合法"); |
| | | return CommonResult.failed("密码长度8到16位且密码中的字符必须包含字母(大写或者小写)和必须包含数字,不能包含空格"); |
| | | } else if (status == -2) { |
| | | return CommonResult.failed("找不到该用户"); |
| | | } else if (status == -3) { |
| | | return CommonResult.failed("旧密码错误"); |
| | | } else if (status == -4) { |
| | | return CommonResult.failed("密码不能和登录名完全一致"); |
| | | } else { |
| | | return CommonResult.failed(); |
| | | } |
| | |
| | | @ApiOperation("删除指定用户信息") |
| | | @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | @LogSave(operationType = "用户管理",contain = "删除用户") |
| | | @LogSave(operationType = "用户管理", contain = "删除用户") |
| | | public CommonResult delete(@PathVariable Long id) { |
| | | boolean success = adminService.delete(id); |
| | | if (success) { |
| | |
| | | @ApiOperation("修改帐号状态") |
| | | @RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | @LogSave(operationType = "用户管理",contain = "用户账号启用/禁用") |
| | | @LogSave(operationType = "用户管理", contain = "用户账号启用/禁用") |
| | | public CommonResult updateStatus(@PathVariable Long id, @RequestParam(value = "status") Integer status) { |
| | | UmsAdmin umsAdmin = new UmsAdmin(); |
| | | umsAdmin.setStatus(status); |
| | |
| | | @ApiOperation("批量删除用户") |
| | | @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "ids", value = "用户Ids",required = true, dataType = "Array") |
| | | @ApiImplicitParam(name = "ids", value = "用户Ids", required = true, dataType = "Array") |
| | | }) |
| | | @ResponseBody |
| | | @LogSave(operationType = "用户管理",contain = "批量删除用户") |
| | | @LogSave(operationType = "用户管理", contain = "批量删除用户") |
| | | public CommonResult deleteBatch(@RequestParam("ids") List<Long> ids) { |
| | | boolean success = adminService.deleteBatch(ids); |
| | | if (success) { |
| | |
| | | @ApiOperation("批量修改用户状态") |
| | | @RequestMapping(value = "/updateStatusBatch", method = RequestMethod.POST) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "ids", value = "用户Ids",required = true, dataType = "Array"), |
| | | @ApiImplicitParam(name = "status", value = "状态0->禁用;1->启用",required = true, dataType = "Integer") |
| | | @ApiImplicitParam(name = "ids", value = "用户Ids", required = true, dataType = "Array"), |
| | | @ApiImplicitParam(name = "status", value = "状态0->禁用;1->启用", required = true, dataType = "Integer") |
| | | }) |
| | | @ResponseBody |
| | | @LogSave(operationType = "用户管理",contain = "用户账号批量启用/禁用") |
| | | @LogSave(operationType = "用户管理", contain = "用户账号批量启用/禁用") |
| | | public CommonResult updateStatusBatch(@RequestParam("ids") List<Long> ids, @RequestParam(value = "status") Integer status) { |
| | | boolean success = adminService.updateStatusBatch(ids, status); |
| | | if (success) { |
| | |
| | | return CommonResult.failed(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("获取部门人员") |
| | | @RequestMapping(value = "/getDepartUser/{departId}", method = RequestMethod.GET) |
| | | @ResponseBody |
| | | public CommonResult<List<UmsAdmin>> getDepartUser(@PathVariable Long departId) { |
| | | return CommonResult.success(adminService.getDepartUser(departId)); |
| | | } |
| | | |
| | | } |
| | | } |