qirong
2023-07-05 21ff1b4f2ef67975eef303bff66ef60388243cf1
src/main/java/com/mindskip/xzs/controller/admin/UserController.java
@@ -6,10 +6,14 @@
import com.mindskip.xzs.domain.User;
import com.mindskip.xzs.domain.UserEventLog;
import com.mindskip.xzs.domain.enums.UserStatusEnum;
import com.mindskip.xzs.domain.vo.UserVO;
import com.mindskip.xzs.service.AuthenticationService;
import com.mindskip.xzs.service.DepartmentService;
import com.mindskip.xzs.service.UserEventLogService;
import com.mindskip.xzs.service.UserService;
import com.mindskip.xzs.utility.DateTimeUtil;
import com.mindskip.xzs.utility.convert.UserClassConvert;
import com.mindskip.xzs.utility.excel.ExcelUtils;
import com.mindskip.xzs.viewmodel.admin.user.*;
import com.mindskip.xzs.utility.PageInfoHelper;
import com.github.pagehelper.PageInfo;
@@ -17,11 +21,13 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@RestController("AdminUserController")
@@ -31,12 +37,14 @@
    private final UserService userService;
    private final UserEventLogService userEventLogService;
    private final AuthenticationService authenticationService;
    private final DepartmentService departmentService;
    @Autowired
    public UserController(UserService userService, UserEventLogService userEventLogService, AuthenticationService authenticationService) {
    public UserController(UserService userService, UserEventLogService userEventLogService, AuthenticationService authenticationService, DepartmentService departmentService) {
        this.userService = userService;
        this.userEventLogService = userEventLogService;
        this.authenticationService = authenticationService;
        this.departmentService = departmentService;
    }
@@ -148,4 +156,23 @@
        return RestResponse.ok(keyValues);
    }
    @PostMapping("/import")
    public RestResponse importUser(@RequestPart("file") MultipartFile file) throws Exception {
        List<UserVO> userVOS = ExcelUtils.readMultipartFile(file, UserVO.class)
                .stream().map(e -> {
                    e.setUserLevel(departmentService.getName(e.getDepartment()).getId());
                    String encodePwd = authenticationService.pwdEncode(e.getPassword());
                    e.setPassword(encodePwd);
                    e.setUserUuid(UUID.randomUUID().toString());
                    e.setCreateTime(new Date());
                    e.setLastActiveTime(new Date());
                    e.setDeleted(false);
                    e.setAge(null);
                    return e;
                }).collect(Collectors.toList());
        List<User> users = UserClassConvert.INSTANCE.UserVOListToUserList(userVOS);
        userService.insertUsers(users);
        return RestResponse.ok();
    }
}