本文共 3865 字,大约阅读时间需要 12 分钟。
package com.learn.system.controller;import com.learn.common.controller.BaseController;import com.learn.common.entity.PageResult;import com.learn.common.entity.Result;import com.learn.common.entity.ResultCode;import com.learn.common.exception.CommonException;import com.learn.common.utils.JwtUtils;import com.learn.common.utils.PermissionConstants;import com.learn.domain.system.Permission;import com.learn.domain.system.Role;import com.learn.domain.system.response.ProfileResult;import com.learn.domain.system.User;import com.learn.domain.system.response.UserResult;import com.learn.system.client.DepartmentFeignClient;import com.learn.system.service.PermissionService;import com.learn.system.service.RoleService;import com.learn.system.service.UserService;import io.jsonwebtoken.Claims;import org.apache.poi.ss.usermodel.*;import org.apache.poi.xssf.usermodel.XSSFWorkbook;import org.apache.shiro.SecurityUtils;import org.apache.shiro.authc.UsernamePasswordToken;import org.apache.shiro.authz.annotation.RequiresPermissions;import org.apache.shiro.crypto.hash.Md5Hash;import org.apache.shiro.subject.PrincipalCollection;import org.apache.shiro.subject.Subject;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.domain.Page;import org.springframework.util.StringUtils;import org.springframework.web.bind.annotation.*;import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletRequest;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;//1.解决跨域@CrossOrigin//2.声明restContoller@RestController//3.设置父路径@RequestMapping(value="/sys")public class UserController extends BaseController { @Autowired private UserService userService; @Autowired private PermissionService permissionService; @Autowired private JwtUtils jwtUtils; @Autowired private DepartmentFeignClient departmentFeignClient; /** * 根据ID查询user */ @RequestMapping(value = "/user/{id}", method = RequestMethod.GET) public Result findById(@PathVariable(value = "id") String id) { // 添加 roleIds (用户已经具有的角色id数组) User user = userService.findById(id); UserResult userResult = new UserResult(user); return new Result(ResultCode.SUCCESS, userResult); }}
package com.ihrm.domain.system.response;import com.ihrm.domain.system.Role;import com.ihrm.domain.system.User;import lombok.Getter;import lombok.Setter;import org.springframework.beans.BeanUtils;import javax.persistence.Id;import java.io.Serializable;import java.util.ArrayList;import java.util.Date;import java.util.List;@Getter@Setterpublic class UserResult implements Serializable { /** * ID */ @Id private String id; /** * 手机号码 */ private String mobile; /** * 用户名称 */ private String username; /** * 密码 */ private String password; /** * 启用状态 0为禁用 1为启用 */ private Integer enableState; /** * 创建时间 */ private Date createTime; private String companyId; private String companyName; /** * 部门ID */ private String departmentId; /** * 入职时间 */ private Date timeOfEntry; /** * 聘用形式 */ private Integer formOfEmployment; /** * 工号 */ private String workNumber; /** * 管理形式 */ private String formOfManagement; /** * 工作城市 */ private String workingCity; /** * 转正时间 */ private Date correctionTime; /** * 在职状态 1.在职 2.离职 */ private Integer inServiceStatus; private String departmentName; private ListroleIds = new ArrayList<>(); private String staffPhoto;//用户头像 public UserResult(User user) { BeanUtils.copyProperties(user,this); for (Role role : user.getRoles()) { this.roleIds.add(role.getId()); } }}
转载地址:http://yqkzb.baihongyu.com/