| | |
| | | package com.project.admin.controller.system; |
| | | |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.project.common.annotation.Log; |
| | | import com.project.common.annotation.RepeatSubmit; |
| | | import com.project.common.constant.UserConstants; |
| | | import com.project.common.core.controller.BaseController; |
| | | import com.project.common.core.domain.AjaxResult; |
| | |
| | | import com.project.common.core.page.TableDataInfo; |
| | | import com.project.common.enums.BusinessType; |
| | | import com.project.common.utils.SecurityUtils; |
| | | import com.project.common.utils.SensitiveUtil; |
| | | import com.project.common.utils.StringUtils; |
| | | import com.project.common.utils.poi.ExcelUtil; |
| | | import com.project.system.service.ISysDeptService; |
| | | import com.project.system.service.ISysPostService; |
| | | import com.project.system.service.ISysRoleService; |
| | | import com.project.system.service.ISysUserService; |
| | | import com.project.system.domain.bo.editBo.UserDeptBo; |
| | | import com.project.system.domain.vo.SysUserResultVo; |
| | | import com.project.system.domain.vo.SysUserVo; |
| | | import com.project.system.service.*; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 用户信息 |
| | |
| | | private final ISysUserService userService; |
| | | private final ISysRoleService roleService; |
| | | private final ISysDeptService deptService; |
| | | private final ISysPostService postService; |
| | | private final ISysPostService postService; |
| | | private final ISysUserDeptService userDeptService; |
| | | |
| | | /** |
| | | * 获取用户列表 |
| | |
| | | public TableDataInfo list(SysUser user) |
| | | { |
| | | startPage(); |
| | | List<SysUser> list = userService.selectUserList(user); |
| | | List<SysUser> list = userService.selectUserListCommon(user); |
| | | list.forEach(SensitiveUtil::desensitize); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysUser user) |
| | | { |
| | | List<SysUser> list = userService.selectUserList(user); |
| | | List<SysUser> list = userService.selectUserListCommon(user); |
| | | ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class); |
| | | util.exportExcel(response, list, "用户数据"); |
| | | } |
| | | |
| | | |
| | | |
| | | @Log(title = "用户管理", businessType = BusinessType.IMPORT) |
| | | @PreAuthorize("@ss.hasPermi('system:user:import')") |
| | |
| | | return success(message); |
| | | } |
| | | |
| | | @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) |
| | | { |
| | | ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class); |
| | | util.importTemplateExcel(response, "用户数据"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据用户编号获取详细信息 |
| | |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysUser user) |
| | | { |
| | | user.setPassword(user.getPhonenumber()); |
| | | if (user.getDeptId()!=null){ |
| | | user.setUserType("01"); |
| | | SysDept sysDept = deptService.selectDeptById(user.getDeptId()); |
| | | if (sysDept.getAncestors().contains("101") || sysDept.getDeptId().equals(101L)){ |
| | | user.setUserType("00"); |
| | | user.setRecommendPhone(deptService.getCheckDeptIdByLoginDeptId(user.getDeptId()).toString()); |
| | | } else { |
| | | user.setUserType("01"); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | user.setCreateBy(getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | user.setRecommendUser(user.getPassword()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | return toAjax(userService.insertUser(user)); |
| | | } |
| | | |
| | |
| | | { |
| | | userService.checkUserAllowed(user); |
| | | userService.checkUserDataScope(user.getUserId()); |
| | | user.setPassword(user.getPhonenumber()); |
| | | if (user.getDeptId()!=null){ |
| | | SysDept sysDept = deptService.selectDeptById(user.getDeptId()); |
| | | if (sysDept.getAncestors().contains("101") || sysDept.getDeptId().equals(101L)){ |
| | | user.setUserType("00"); |
| | | } else { |
| | | user.setUserType("01"); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 重置密码 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") |
| | | // @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/resetPwd") |
| | | public AjaxResult resetPwd(@RequestBody SysUser user) |
| | |
| | | user.setUpdateBy(getUsername()); |
| | | |
| | | return toAjax(userService.resetPwd(user)); |
| | | } |
| | | |
| | | @ApiOperation("用户多机构——回显") |
| | | @GetMapping("/batchUserDeptView") |
| | | public AjaxResult batchUserDeptView(@RequestParam("userId") Long userId) |
| | | { |
| | | return AjaxResult.success(userDeptService.batchUserDeptView(userId)); |
| | | } |
| | | |
| | | @ApiOperation("用户多机构——保存") |
| | | @Log(title = "用户多机构保存", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/batchUserDeptSave") |
| | | public AjaxResult batchUserDeptSave(@RequestBody UserDeptBo bo) |
| | | { |
| | | return AjaxResult.success(userDeptService.batchUserDeptSave(bo)); |
| | | } |
| | | |
| | | @ApiOperation("用户多机构——机构树") |
| | | @GetMapping("/batchUserDeptTree") |
| | | public AjaxResult batchUserDeptTree(@RequestParam("deptId") Long deptId) |
| | | { |
| | | return AjaxResult.success(userDeptService.batchUserDeptTree(deptId)); |
| | | } |
| | | |
| | | @ApiOperation("企业用户重置密码") |
| | | @Log(title = "企业用户重置密码", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/resetCompanyUserPwd") |
| | | public AjaxResult resetCompanyUserPwd(@RequestParam("companyId") Long companyId,@RequestParam("newPassword") String newPassword) |
| | | { |
| | | SysUser user = userService.list(userService.lq().eq(SysUser::getDeptId, companyId)).get(0); |
| | | if (user==null) { |
| | | return AjaxResult.error("没有该企业对应账户"); |
| | | } |
| | | if (userService.resetUserPwd(user.getUserName(), SecurityUtils.encryptPassword(newPassword), newPassword) > 0) |
| | | { |
| | | return success(); |
| | | } |
| | | return error("修改密码异常,请联系管理员"); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | return success(deptService.selectDeptTreeList(dept)); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("用户模板下载") |
| | | @GetMapping("/exportTemplate") |
| | | public AjaxResult exportTemplate() |
| | | { |
| | | ExcelUtil<SysUserVo> util = new ExcelUtil<>(SysUserVo.class); |
| | | return util.exportExcel(null, "用户信息模板"); |
| | | } |
| | | |
| | | @ApiOperation(value = "处理导入信息") |
| | | @Log(title = "导入用户信息处理" , businessType = BusinessType.OTHER) |
| | | @ApiImplicitParam(value = "用户信息", name = "file", dataType = "file", dataTypeClass = MultipartFile.class) |
| | | @PostMapping("/doImport") |
| | | public AjaxResult doImport(@RequestPart(value = "file") MultipartFile file, @RequestParam("deptId") Long deptId) throws Exception |
| | | { |
| | | |
| | | ExcelUtil<SysUserVo> util = new ExcelUtil<>(SysUserVo.class); |
| | | List<SysUserVo> list = util.importExcel(file.getInputStream()); |
| | | return AjaxResult.success(userService.doImport(list, deptId)); |
| | | } |
| | | |
| | | @ApiOperation(value = "校验导入信息") |
| | | @Log(title = "导入用户信息校验" , businessType = BusinessType.OTHER) |
| | | @PostMapping("/checkImport") |
| | | public AjaxResult checkImport(@RequestBody SysUserResultVo resultVo) |
| | | { |
| | | return AjaxResult.success(userService.checkImport(resultVo)); |
| | | } |
| | | |
| | | @ApiOperation(value = "保存导入信息") |
| | | @Log(title = "导入用户信息保存" , businessType = BusinessType.IMPORT) |
| | | @PostMapping("/saveImport") |
| | | @RepeatSubmit |
| | | public AjaxResult saveImport(@RequestBody SysUserResultVo resultVo) |
| | | { |
| | | return toAjax(userService.saveImport(resultVo) ? 1 : 0); |
| | | } |
| | | |
| | | } |