用户区分教师与学生,分别的导入与导出
This commit is contained in:
parent
c1c54b0504
commit
d03f5f5b3e
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
@ -27,6 +28,7 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -142,6 +144,58 @@ public class UserController {
|
||||
UserConvert.INSTANCE.convertList(list, deptMap));
|
||||
}
|
||||
|
||||
@GetMapping("/student/export")
|
||||
@Operation(summary = "导出用户")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exporStudent(@Validated UserPageReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<AdminUserDO> list = userService.getUserPage(exportReqVO).getList();
|
||||
|
||||
//将用户转换成学生的标头
|
||||
List<UserStudentExcelVO> studentUserList = new ArrayList<>();
|
||||
if (!list.isEmpty()) {
|
||||
list.stream().forEach(sysUser ->{
|
||||
UserStudentExcelVO student = new UserStudentExcelVO();
|
||||
BeanUtil.copyProperties(sysUser, student);
|
||||
studentUserList.add(student);
|
||||
});
|
||||
}
|
||||
|
||||
// 输出 Excel
|
||||
Map<Long, DeptDO> deptMap = deptService.getDeptMap(
|
||||
convertList(list, AdminUserDO::getDeptId));
|
||||
ExcelUtils.write(response, "学生数据.xls", "数据", UserRespVO.class,
|
||||
UserConvert.INSTANCE.convertList(list, deptMap));
|
||||
}
|
||||
|
||||
@GetMapping("/teacher/export")
|
||||
@Operation(summary = "导出用户")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exporTeacher(@Validated UserPageReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<AdminUserDO> list = userService.getUserPage(exportReqVO).getList();
|
||||
|
||||
//将用户转换成学生的标头
|
||||
List<UserTeacherExcelVO> studentUserList = new ArrayList<>();
|
||||
if (!list.isEmpty()) {
|
||||
list.stream().forEach(sysUser ->{
|
||||
UserTeacherExcelVO student = new UserTeacherExcelVO();
|
||||
BeanUtil.copyProperties(sysUser, student);
|
||||
studentUserList.add(student);
|
||||
});
|
||||
}
|
||||
|
||||
// 输出 Excel
|
||||
Map<Long, DeptDO> deptMap = deptService.getDeptMap(
|
||||
convertList(list, AdminUserDO::getDeptId));
|
||||
ExcelUtils.write(response, "教师数据.xls", "数据", UserRespVO.class,
|
||||
UserConvert.INSTANCE.convertList(list, deptMap));
|
||||
}
|
||||
|
||||
@GetMapping("/get-import-template")
|
||||
@Operation(summary = "获得导入用户模板")
|
||||
public void importTemplate(HttpServletResponse response) throws IOException {
|
||||
@ -169,4 +223,44 @@ public class UserController {
|
||||
return success(userService.importUserList(list, updateSupport));
|
||||
}
|
||||
|
||||
@PostMapping("/student/import")
|
||||
@Operation(summary = "导入学生")
|
||||
@Parameters({
|
||||
@Parameter(name = "file", description = "Excel 文件", required = true),
|
||||
})
|
||||
@PreAuthorize("@ss.hasPermission('system:user:import')")
|
||||
public CommonResult<String> importExcelStudent(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
List<UserStudentExcelVO> list = ExcelUtils.read(file, UserStudentExcelVO.class);
|
||||
List<AdminUserDO> userList = new ArrayList<>();
|
||||
if (!list.isEmpty()) {
|
||||
list.stream().forEach(sysStudentUser ->{
|
||||
AdminUserDO user = new AdminUserDO();
|
||||
BeanUtil.copyProperties(sysStudentUser, user);
|
||||
user.setUserType(2);
|
||||
userList.add(user);
|
||||
});
|
||||
}
|
||||
return success(userService.importUserStudentTeacher(userList));
|
||||
}
|
||||
|
||||
@PostMapping("/teacher/import")
|
||||
@Operation(summary = "导入教师")
|
||||
@Parameters({
|
||||
@Parameter(name = "file", description = "Excel 文件", required = true)
|
||||
})
|
||||
@PreAuthorize("@ss.hasPermission('system:user:import')")
|
||||
public CommonResult<String> importExcelTeacher(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
List<UserTeacherExcelVO> list = ExcelUtils.read(file, UserTeacherExcelVO.class);
|
||||
List<AdminUserDO> userList = new ArrayList<>();
|
||||
if (!list.isEmpty()) {
|
||||
list.stream().forEach(sysStudentUser ->{
|
||||
AdminUserDO user = new AdminUserDO();
|
||||
BeanUtil.copyProperties(sysStudentUser, user);
|
||||
user.setUserType(1);
|
||||
userList.add(user);
|
||||
});
|
||||
}
|
||||
return success(userService.importUserStudentTeacher(userList));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,4 +38,16 @@ public class UserPageReqVO extends PageParam {
|
||||
@Schema(description = "角色编号", example = "1024")
|
||||
private Long roleId;
|
||||
|
||||
@Schema(description = "用户类型", example = "0 管理员 1教师 2学生")
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "教职工号/学生编号", example = "1")
|
||||
private String userNo;
|
||||
|
||||
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
|
||||
private LocalDateTime birthDate;
|
||||
|
||||
@Schema(description = "当userType为学生时 0 学生 1学员,当userType为教师时 0 教师 1培训教师", example = "1")
|
||||
private Integer statusType;
|
||||
|
||||
}
|
||||
|
@ -72,4 +72,16 @@ public class UserRespVO{
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "用户类型", example = "0 管理员 1教师 2学生")
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "教职工号/学生编号", example = "1")
|
||||
private String userNo;
|
||||
|
||||
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
|
||||
private LocalDateTime birthDate;
|
||||
|
||||
@Schema(description = "当userType为学生时 0 学生 1学员,当userType为教师时 0 教师 1培训教师", example = "1")
|
||||
private Integer statusType;
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Set;
|
||||
|
||||
@Schema(description = "管理后台 - 用户创建/修改 Request VO")
|
||||
@ -77,4 +78,16 @@ public class UserSaveReqVO {
|
||||
|| (ObjectUtil.isAllNotEmpty(password)); // 新增时,必须都传递 password
|
||||
}
|
||||
|
||||
@Schema(description = "用户类型", example = "0 管理员 1教师 2学生")
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "教职工号/学生编号", example = "1")
|
||||
private String userNo;
|
||||
|
||||
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
|
||||
private LocalDateTime birthDate;
|
||||
|
||||
@Schema(description = "当userType为学生时 0 学生 1学员,当userType为教师时 0 教师 1培训教师", example = "1")
|
||||
private Integer statusType;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class UserStudentExcelVO {
|
||||
|
||||
@ExcelProperty("登录账号")
|
||||
private String userName;
|
||||
|
||||
@ExcelProperty("学生姓名")
|
||||
private String nickname;
|
||||
|
||||
@ExcelProperty("学生编号")
|
||||
private String userNo;
|
||||
|
||||
@ExcelProperty("学生类型")
|
||||
private String statusType;
|
||||
|
||||
@ExcelProperty("性别")
|
||||
private String sex;
|
||||
|
||||
@ExcelProperty("手机号码")
|
||||
private String mobile;
|
||||
|
||||
@ExcelProperty("状态")
|
||||
private String status;
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class UserTeacherExcelVO {
|
||||
|
||||
@ExcelProperty("登录账号")
|
||||
private String userName;
|
||||
|
||||
@ExcelProperty("教职工号")
|
||||
private String userNo;
|
||||
|
||||
@ExcelProperty("姓名")
|
||||
private String nickname;
|
||||
|
||||
@ExcelProperty("邮箱")
|
||||
private String email;
|
||||
|
||||
@ExcelProperty("手机号码")
|
||||
private String mobile;
|
||||
|
||||
@ExcelProperty("性别")
|
||||
private String sex;
|
||||
|
||||
@ExcelProperty("状态")
|
||||
private String status;
|
||||
|
||||
@ExcelProperty("出生日期")
|
||||
private String birthDate;
|
||||
|
||||
@ExcelProperty("教师类型类型")
|
||||
private String statusType;
|
||||
|
||||
|
||||
|
||||
}
|
@ -96,4 +96,20 @@ public class AdminUserDO extends TenantBaseDO {
|
||||
* 用户类型:0 - 管理员、1-老师、2-学生
|
||||
*/
|
||||
private Integer userType;
|
||||
|
||||
/**
|
||||
* 教职工号/学生编号
|
||||
*/
|
||||
private String userNo;
|
||||
|
||||
/**
|
||||
* 出生日期
|
||||
*/
|
||||
private LocalDateTime birthDate;
|
||||
|
||||
/**
|
||||
* 当userType为学生时 0 学生 1学员
|
||||
* 当userType为教师时 0 教师 1培训教师
|
||||
*/
|
||||
private Integer statusType;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
|
||||
.likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername())
|
||||
.likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile())
|
||||
.eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(AdminUserDO::getUserType, reqVO.getUserType())
|
||||
.betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime())
|
||||
.inIfPresent(AdminUserDO::getDeptId, deptIds)
|
||||
.inIfPresent(AdminUserDO::getId, userIds)
|
||||
|
@ -199,6 +199,8 @@ public interface AdminUserService {
|
||||
*/
|
||||
UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport);
|
||||
|
||||
String importUserStudentTeacher(List<AdminUserDO> importUsers);
|
||||
|
||||
/**
|
||||
* 获得指定状态的用户们
|
||||
*
|
||||
|
@ -33,8 +33,10 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import com.mzt.logapi.context.LogRecordContext;
|
||||
import com.mzt.logapi.service.impl.DiffParseFunction;
|
||||
import com.mzt.logapi.starter.annotation.LogRecord;
|
||||
import com.thoughtworks.xstream.core.SecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -508,6 +510,33 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
return respVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String importUserStudentTeacher(List<AdminUserDO> importUsers) {
|
||||
if (importUsers == null || importUsers.size() == 0) {
|
||||
throw new ServiceException(500,"导入用户数据不能为空!");
|
||||
}
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
for (AdminUserDO user : importUsers) {
|
||||
if(user.getUsername() == null || user.getUsername().equals("")){
|
||||
successMsg.append("用户名不能为空,导入失败/n" );
|
||||
continue;
|
||||
}
|
||||
AdminUserDO adminUserDO = userMapper.selectByUsername(user.getUsername());
|
||||
if(adminUserDO != null){
|
||||
successMsg.append("用户名:" + user.getUsername() + "已存在,导入失败/n" );
|
||||
continue;
|
||||
}
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
String password = passwordEncoder.encode("123456");
|
||||
user.setPassword(password);
|
||||
user.setStatus(0);
|
||||
userMapper.insert(user);
|
||||
successMsg.append("用户名:" + user.getUsername() + "已导入成功/n" );
|
||||
}
|
||||
successMsg.insert(0, "导入完成,数据如下:");
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUserListByStatus(Integer status) {
|
||||
return userMapper.selectListByStatus(status);
|
||||
|
Loading…
x
Reference in New Issue
Block a user