| | |
| | | import org.springframework.security.crypto.password.PasswordEncoder; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | @PostMapping |
| | | @PreAuthorize("hasAuthority('user:add')") |
| | | @ControllerEndpoint(operation = "新增用户", exceptionMessage = "新增用户失败") |
| | | public void addUser(@Valid SystemUser user) { |
| | | public void addUser(@Valid SystemUser user) throws FebsException { |
| | | this.userService.createUser(user); |
| | | } |
| | | |
| | | @PutMapping |
| | | @PreAuthorize("hasAuthority('user:update')") |
| | | @ControllerEndpoint(operation = "修改用户", exceptionMessage = "修改用户失败") |
| | | public void updateUser(@Valid SystemUser user) { |
| | | public void updateUser(@Valid SystemUser user) throws FebsException { |
| | | this.userService.updateUser(user); |
| | | } |
| | | |
| | |
| | | List<SystemUser> users = this.userService.findUserDetailList(user, queryRequest).getRecords(); |
| | | ExcelKit.$Export(SystemUser.class, response).downXlsx(users, false); |
| | | } |
| | | private static final String XLSX = ".xlsx"; |
| | | @PostMapping("import") |
| | | public FebsResponse importExcels(MultipartFile file) throws IOException, FebsException { |
| | | if (file.isEmpty()) { |
| | | throw new FebsException("导入数据为空"); |
| | | } |
| | | String filename = file.getOriginalFilename(); |
| | | if (!StringUtils.endsWith(filename, XLSX)) { |
| | | throw new FebsException("只支持.xlsx类型文件导入"); |
| | | } |
| | | Stopwatch stopwatch = Stopwatch.createStarted(); |
| | | final List<SystemUser> data = Lists.newArrayList(); |
| | | final List<Map<String, Object>> error = Lists.newArrayList(); |
| | | ExcelKit.$Import(SystemUser.class).readXlsx(file.getInputStream(), new ExcelReadHandler<SystemUser>() { |
| | | @Override |
| | | public void onSuccess(int sheet, int row, SystemUser eximport) { |
| | | data.add(eximport); |
| | | } |
| | | @Override |
| | | public void onError(int sheet, int row, List<ExcelErrorField> errorFields) { |
| | | error.add(ImmutableMap.of("row", row, "errorFields", errorFields)); |
| | | } |
| | | }); |
| | | if (CollectionUtils.isNotEmpty(data)) { |
| | | for (SystemUser systemUser:data){ |
| | | Dept one = deptService.getOne(new QueryWrapper<Dept>().eq("DEPT_NAME", systemUser.getDeptName())); |
| | | if(one!=null){ |
| | | systemUser.setDeptId(one.getDeptId()); |
| | | } |
| | | this.userService.createUser(systemUser); |
| | | } |
| | | } |
| | | ImmutableMap<String, Object> result = ImmutableMap.of( |
| | | "time", stopwatch.stop().toString(), |
| | | "data", data, |
| | | "error", error |
| | | ); |
| | | return new FebsResponse().data(result); |
| | | } |
| | | @PostMapping("template") |
| | | public void generateImportTemplate(HttpServletResponse response) { |
| | | List<SystemUser> list = new ArrayList<>(); |
| | | ExcelKit.$Export(SystemUser.class, response).downXlsx(list, true); |
| | | |
| | | @PostMapping("updateStatus") |
| | | public void updateStatus(@NotBlank(message = "{required}") String certificateNumb) { |
| | | this.userService.updateUserByCertificateNumb(certificateNumb); |
| | | } |
| | | } |