| | |
| | | package com.project.admin.controller.system; |
| | | |
| | | import com.project.common.config.ProjectConfig; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | 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.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.project.common.annotation.Log; |
| | | import com.project.common.config.ProjectConfig; |
| | | 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.domain.entity.SysDept; |
| | | import com.project.common.core.domain.entity.SysUser; |
| | | import com.project.common.core.domain.model.LoginUser; |
| | | import com.project.common.enums.BusinessType; |
| | |
| | | import com.project.common.utils.StringUtils; |
| | | import com.project.common.utils.file.FileUploadUtils; |
| | | import com.project.common.utils.file.MimeTypeUtils; |
| | | import com.project.framework.web.service.SysPermissionService; |
| | | import com.project.framework.web.service.TokenService; |
| | | import com.project.system.domain.SysCompany; |
| | | import com.project.system.service.ISysCompanyService; |
| | | import com.project.system.service.ISysDeptService; |
| | | import com.project.system.service.ISysUserService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * 个人信息 业务处理 |
| | |
| | | public class SysProfileController extends BaseController |
| | | { |
| | | private final ISysUserService userService; |
| | | private final ISysDeptService deptService; |
| | | private final TokenService tokenService; |
| | | private final SysPermissionService permissionService; |
| | | private final ISysCompanyService companyService; |
| | | |
| | | |
| | | /** |
| | |
| | | @GetMapping |
| | | public AjaxResult profile() |
| | | { |
| | | SysUser user = userService.getById(getUserId()); |
| | | SysUser user = userService.selectUserById(SecurityUtils.getLoginUser().getUserId()); |
| | | if ("02".equals(user.getUserType())){ |
| | | SysCompany company = companyService.getById(userService.getById(user.getUserId()).getDeptId()); |
| | | SysDept sysDept = new SysDept(); |
| | | sysDept.setDeptName(company.getCompanyName()); |
| | | user.setDept(sysDept); |
| | | } else { |
| | | SysDept sysDept = deptService.selectDeptById(userService.getById(user.getUserId()).getDeptId()); |
| | | if (sysDept!=null){ |
| | | sysDept.setDeptName(deptService.getDeptAllName(sysDept.getDeptId())); |
| | | user.setDept(sysDept); |
| | | } |
| | | } |
| | | |
| | | // 角色集合 |
| | | Set<String> roles = permissionService.getRolePermission(user); |
| | | // 权限集合 |
| | | Set<String> permissions = permissionService.getMenuPermission(user); |
| | | AjaxResult ajax = AjaxResult.success(user); |
| | | ajax.put("roles", roles); |
| | | ajax.put("permissions", permissions); |
| | | ajax.put("roleGroup", userService.selectUserRoleGroup(user.getUserName())); |
| | | ajax.put("postGroup", userService.selectUserPostGroup(user.getUserName())); |
| | | return ajax; |
| | |
| | | public AjaxResult updateProfile(@RequestBody SysUser user) |
| | | { |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser sysUser = loginUser.getUser(); |
| | | user.setUserName(sysUser.getUserName()); |
| | | if (StringUtils.isNotEmpty(user.getPhonenumber()) |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) |
| | | { |
| | |
| | | { |
| | | return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); |
| | | } |
| | | user.setUserId(sysUser.getUserId()); |
| | | if (userService.updateUser(user) > 0) |
| | | int upd = userService.updateUser(user); |
| | | if (upd > 0) |
| | | { |
| | | // 更新缓存用户信息 |
| | | sysUser.setNickName(user.getNickName()); |
| | | sysUser.setPhonenumber(user.getPhonenumber()); |
| | | sysUser.setEmail(user.getEmail()); |
| | | sysUser.setSex(user.getSex()); |
| | | sysUser.setAvatar(user.getAvatar()); |
| | | loginUser.setUser(user); |
| | | tokenService.setLoginUser(loginUser); |
| | | return success(); |
| | | } |
| | | return error("修改个人信息异常,请联系管理员"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 重置密码 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 更换手机号 |
| | | */ |
| | | @Log(title = "更换手机号", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/updatePhone/{phone}") |
| | | public AjaxResult updatePhone(@PathVariable String phone) |
| | | { |
| | | if (StringUtils.isEmpty(phone)){ |
| | | return error("请填写手机号"); |
| | | } |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | SysUser user = userService.selectUserById(SecurityUtils.getUserId()); |
| | | user.setPhonenumber(phone); |
| | | if (StringUtils.isNotEmpty(user.getPhonenumber()) |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) |
| | | { |
| | | return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | if (userService.resetPhone(user.getUserId(), phone) > 0) |
| | | { |
| | | // 更新缓存 |
| | | loginUser.getUser().setUserName(phone); |
| | | loginUser.getUser().setPhonenumber(phone); |
| | | tokenService.setLoginUser(loginUser); |
| | | if ("02".equals(user.getUserType())){ |
| | | companyService.update(companyService.lu().set(SysCompany::getCompanyPhone, phone).eq(SysCompany::getCompanyId, user.getDeptId())); |
| | | } |
| | | return success(); |
| | | } |
| | | return error("修改密码异常,请联系管理员"); |
| | | } |
| | | |
| | | /** |
| | | * 头像上传 |
| | | */ |
| | | @Log(title = "用户头像", businessType = BusinessType.UPDATE) |