将学生和教师的管理分开
This commit is contained in:
parent
97998a2cca
commit
9d56a567a8
|
@ -45,6 +45,11 @@ public interface CacheNames {
|
|||
*/
|
||||
String SYS_DEPT = "sys_dept#30d";
|
||||
|
||||
/**
|
||||
* 部门
|
||||
*/
|
||||
String SYS_DEPT_NAME = "sys_dept_name#1d";
|
||||
|
||||
/**
|
||||
* OSS内容
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.apache.poi.ss.util.CellRangeAddressList;
|
|||
import org.apache.poi.ss.util.WorkbookUtil;
|
||||
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.service.DeptService;
|
||||
import org.dromara.common.core.service.DictService;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
|
@ -63,12 +64,15 @@ public class ExcelDownHandler implements SheetWriteHandler {
|
|||
*/
|
||||
private int currentLinkedOptionsSheetIndex;
|
||||
private final DictService dictService;
|
||||
private final DeptService deptService;
|
||||
|
||||
|
||||
public ExcelDownHandler(List<DropDownOptions> options) {
|
||||
this.dropDownOptions = options;
|
||||
this.currentOptionsColumnIndex = 0;
|
||||
this.currentLinkedOptionsSheetIndex = 0;
|
||||
this.dictService = SpringUtils.getBean(DictService.class);
|
||||
this.deptService = SpringUtils.getBean(DeptService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package org.dromara.scale.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
||||
import org.dromara.common.excel.convert.ExcelDictConvert;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
@ -18,7 +14,6 @@ import java.util.List;
|
|||
* @date 2024-03-29
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class SysScaleVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
|
@ -27,7 +22,6 @@ public class SysScaleVo implements Serializable {
|
|||
/**
|
||||
* 测评id
|
||||
*/
|
||||
@ExcelProperty(value = "测评id")
|
||||
private Long scaleId;
|
||||
|
||||
/**
|
||||
|
@ -43,7 +37,6 @@ public class SysScaleVo implements Serializable {
|
|||
/**
|
||||
* 测评标题
|
||||
*/
|
||||
@ExcelProperty(value = "测评标题")
|
||||
private String scaleTitle;
|
||||
|
||||
/**
|
||||
|
@ -54,14 +47,11 @@ public class SysScaleVo implements Serializable {
|
|||
/**
|
||||
* 测评详情
|
||||
*/
|
||||
@ExcelProperty(value = "测评详情")
|
||||
private String scaleDetails;
|
||||
|
||||
/**
|
||||
* 状态(0停用 1正常)
|
||||
*/
|
||||
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "0=停用,1=正常")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
|
@ -97,7 +87,6 @@ public class SysScaleVo implements Serializable {
|
|||
/**
|
||||
* 量表类型:对应字典项scale_type
|
||||
*/
|
||||
@ExcelProperty(value = "类型")
|
||||
private List<String> scaleType;
|
||||
|
||||
/**
|
||||
|
@ -123,10 +112,8 @@ public class SysScaleVo implements Serializable {
|
|||
/**
|
||||
* 测评时间
|
||||
*/
|
||||
@ExcelProperty(value = "测评时间")
|
||||
private String scaleTime;
|
||||
|
||||
|
||||
private boolean used;
|
||||
|
||||
private Long recordId;
|
||||
|
|
|
@ -83,7 +83,7 @@ public class SysScaleServiceImpl implements ISysScaleService {
|
|||
if(CollUtil.isNotEmpty(bo.getScaleType())){
|
||||
lqw.like(CollUtil.isNotEmpty(bo.getScaleType()), SysScale::getScaleType, bo.getScaleType().get(0));
|
||||
}
|
||||
lqw.orderByDesc(SysScale::getCreateTime);
|
||||
lqw.orderByDesc(SysScale::getUpdateTime);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
ir.annex
|
||||
from sys_intervene_record ir
|
||||
left join sys_user u on u.user_id = ir.counselor_id
|
||||
|
||||
where ir.user_id = #{userId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.dromara.system.controller.system;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.dev33.satoken.secure.BCrypt;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
@ -28,7 +29,8 @@ import org.dromara.system.domain.bo.SysPostBo;
|
|||
import org.dromara.system.domain.bo.SysRoleBo;
|
||||
import org.dromara.system.domain.bo.SysUserBo;
|
||||
import org.dromara.system.domain.vo.*;
|
||||
import org.dromara.system.listener.SysUserImportListener;
|
||||
import org.dromara.system.listener.SysStudentImportListener;
|
||||
import org.dromara.system.listener.SysTeacherImportListener;
|
||||
import org.dromara.system.service.ISysDeptService;
|
||||
import org.dromara.system.service.ISysPostService;
|
||||
import org.dromara.system.service.ISysRoleService;
|
||||
|
@ -61,7 +63,10 @@ public class SysUserController extends BaseController {
|
|||
/**
|
||||
* 获取用户列表
|
||||
*/
|
||||
@SaCheckPermission("system:user:list")
|
||||
@SaCheckPermission(value = {
|
||||
"system:teacher:list",
|
||||
"system:student:list"},
|
||||
mode = SaMode.OR)
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<SysUserVo> list(SysUserBo user, PageQuery pageQuery) {
|
||||
return userService.selectPageUserList(user, pageQuery);
|
||||
|
@ -82,23 +87,43 @@ public class SysUserController extends BaseController {
|
|||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @param file 导入文件
|
||||
* @param updateSupport 是否更新已存在数据
|
||||
* @param file 导入文件
|
||||
*/
|
||||
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
||||
@SaCheckPermission("system:user:import")
|
||||
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception {
|
||||
ExcelResult<SysUserImportVo> result = ExcelUtil.importExcel(file.getInputStream(), SysUserImportVo.class, new SysUserImportListener(updateSupport));
|
||||
@SaCheckPermission("system:teacher:import")
|
||||
@PostMapping(value = "/teacher/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R<Void> importTeacherData(@RequestPart("file") MultipartFile file) throws Exception {
|
||||
ExcelResult<SysTeacherImportVo> result = ExcelUtil.importExcel(file.getInputStream(), SysTeacherImportVo.class, new SysTeacherImportListener());
|
||||
return R.ok(result.getAnalysis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导入模板
|
||||
*/
|
||||
@PostMapping("/importTemplate")
|
||||
public void importTemplate(HttpServletResponse response) {
|
||||
ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response);
|
||||
@PostMapping("/teacher/importTemplate")
|
||||
public void importTeacherTemplate(HttpServletResponse response) {
|
||||
ExcelUtil.exportExcel(new ArrayList<>(), "教师数据", SysTeacherImportVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @param file 导入文件
|
||||
*/
|
||||
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
||||
@SaCheckPermission("system:student:import")
|
||||
@PostMapping(value = "/student/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R<Void> importStudentData(@RequestPart("file") MultipartFile file) throws Exception {
|
||||
ExcelResult<SysStudentImportVo> result = ExcelUtil.importExcel(file.getInputStream(), SysStudentImportVo.class, new SysStudentImportListener());
|
||||
return R.ok(result.getAnalysis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导入模板
|
||||
*/
|
||||
@PostMapping("/student/importTemplate")
|
||||
public void importStudentTemplate(HttpServletResponse response) {
|
||||
ExcelUtil.exportExcel(new ArrayList<>(), "学生数据", SysStudentImportVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,7 +150,10 @@ public class SysUserController extends BaseController {
|
|||
*
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
@SaCheckPermission("system:user:query")
|
||||
@SaCheckPermission(value = {
|
||||
"system:teacher:query",
|
||||
"system:student:query"},
|
||||
mode = SaMode.OR)
|
||||
@GetMapping(value = {"/", "/{userId}"})
|
||||
public R<SysUserInfoVo> getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
||||
userService.checkUserDataScope(userId);
|
||||
|
@ -149,7 +177,11 @@ public class SysUserController extends BaseController {
|
|||
/**
|
||||
* 新增用户
|
||||
*/
|
||||
@SaCheckPermission("system:user:add")
|
||||
|
||||
@SaCheckPermission(value = {
|
||||
"system:teacher:add",
|
||||
"system:student:add"},
|
||||
mode = SaMode.OR)
|
||||
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public R<Void> add(@Validated @RequestBody SysUserBo user) {
|
||||
|
@ -168,7 +200,10 @@ public class SysUserController extends BaseController {
|
|||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
@SaCheckPermission("system:user:edit")
|
||||
@SaCheckPermission(value = {
|
||||
"system:teacher:edit",
|
||||
"system:student:edit"},
|
||||
mode = SaMode.OR)
|
||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public R<Void> edit(@Validated @RequestBody SysUserBo user) {
|
||||
|
@ -190,7 +225,10 @@ public class SysUserController extends BaseController {
|
|||
*
|
||||
* @param userIds 角色ID串
|
||||
*/
|
||||
@SaCheckPermission("system:user:remove")
|
||||
@SaCheckPermission(value = {
|
||||
"system:teacher:remove",
|
||||
"system:student:remove"},
|
||||
mode = SaMode.OR)
|
||||
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{userIds}")
|
||||
public R<Void> remove(@PathVariable Long[] userIds) {
|
||||
|
@ -204,7 +242,10 @@ public class SysUserController extends BaseController {
|
|||
* 重置密码
|
||||
*/
|
||||
@ApiEncrypt
|
||||
@SaCheckPermission("system:user:resetPwd")
|
||||
@SaCheckPermission(value = {
|
||||
"system:teacher:resetPwd",
|
||||
"system:student:resetPwd"},
|
||||
mode = SaMode.OR)
|
||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/resetPwd")
|
||||
public R<Void> resetPwd(@RequestBody SysUserBo user) {
|
||||
|
@ -217,7 +258,10 @@ public class SysUserController extends BaseController {
|
|||
/**
|
||||
* 状态修改
|
||||
*/
|
||||
@SaCheckPermission("system:user:edit")
|
||||
@SaCheckPermission(value = {
|
||||
"system:teacher:edit",
|
||||
"system:student:edit"},
|
||||
mode = SaMode.OR)
|
||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeStatus")
|
||||
public R<Void> changeStatus(@RequestBody SysUserBo user) {
|
||||
|
@ -231,7 +275,10 @@ public class SysUserController extends BaseController {
|
|||
*
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
@SaCheckPermission("system:user:query")
|
||||
@SaCheckPermission(value = {
|
||||
"system:teacher:query",
|
||||
"system:student:query"},
|
||||
mode = SaMode.OR)
|
||||
@GetMapping("/authRole/{userId}")
|
||||
public R<SysUserInfoVo> authRole(@PathVariable Long userId) {
|
||||
SysUserVo user = userService.selectUserById(userId);
|
||||
|
@ -248,7 +295,11 @@ public class SysUserController extends BaseController {
|
|||
* @param userId 用户Id
|
||||
* @param roleIds 角色ID串
|
||||
*/
|
||||
@SaCheckPermission("system:user:edit")
|
||||
|
||||
@SaCheckPermission(value = {
|
||||
"system:teacher:edit",
|
||||
"system:student:edit"},
|
||||
mode = SaMode.OR)
|
||||
@Log(title = "用户管理", businessType = BusinessType.GRANT)
|
||||
@PutMapping("/authRole")
|
||||
public R<Void> insertAuthRole(Long userId, Long[] roleIds) {
|
||||
|
@ -280,7 +331,7 @@ public class SysUserController extends BaseController {
|
|||
* 导出用户列表
|
||||
*/
|
||||
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
||||
@SaCheckPermission("system:user:export")
|
||||
@SaCheckPermission("system:student:export")
|
||||
@PostMapping("/export/password")
|
||||
public void exportPassword(@NotNull Long deptId, HttpServletResponse response) {
|
||||
List<SysUserPassWordExportVo> listVo = userService.selectUserpassWordListByDept(deptId);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package org.dromara.system.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
||||
import org.dromara.common.excel.convert.ExcelDictConvert;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
||||
import org.dromara.common.excel.convert.ExcelDictConvert;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
@ -18,7 +18,7 @@ import java.io.Serializable;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
// @Accessors(chain = true) // 导入不允许使用 会找不到set方法
|
||||
public class SysUserImportVo implements Serializable {
|
||||
public class SysStudentImportVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -60,11 +60,5 @@ public class SysUserImportVo implements Serializable {
|
|||
@ExcelDictFormat(dictType = "sys_user_sex")
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
@ExcelProperty(value = "用户类型", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "sys_user_type")
|
||||
private String userType;
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package org.dromara.system.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
||||
import org.dromara.common.excel.convert.ExcelDictConvert;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户对象导入VO
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
// @Accessors(chain = true) // 导入不允许使用 会找不到set方法
|
||||
public class SysTeacherImportVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
@ExcelProperty(value = "登录名称")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@ExcelProperty(value = "用户名称")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
@ExcelProperty(value = "用户邮箱")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@ExcelProperty(value = "手机号码")
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 用户性别
|
||||
*/
|
||||
@ExcelProperty(value = "用户性别", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "sys_user_sex")
|
||||
private String sex;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package org.dromara.system.listener;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.ValidatorUtils;
|
||||
import org.dromara.common.excel.core.ExcelListener;
|
||||
import org.dromara.common.excel.core.ExcelResult;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.system.domain.bo.SysUserBo;
|
||||
import org.dromara.system.domain.vo.SysStudentImportVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.service.ISysConfigService;
|
||||
import org.dromara.system.service.ISysDeptService;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户自定义导入
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
public class SysStudentImportListener extends AnalysisEventListener<SysStudentImportVo> implements ExcelListener<SysStudentImportVo> {
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
private final ISysDeptService deptService;
|
||||
|
||||
private final String password;
|
||||
|
||||
private final Long operUserId;
|
||||
|
||||
private int successNum = 0;
|
||||
private int failureNum = 0;
|
||||
private final StringBuilder successMsg = new StringBuilder();
|
||||
private final StringBuilder failureMsg = new StringBuilder();
|
||||
|
||||
public SysStudentImportListener() {
|
||||
String initPassword = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.user.initPassword");
|
||||
this.userService = SpringUtils.getBean(ISysUserService.class);
|
||||
this.deptService = SpringUtils.getBean(ISysDeptService.class);
|
||||
this.password = BCrypt.hashpw(initPassword);
|
||||
this.operUserId = LoginHelper.getUserId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(SysStudentImportVo userVo, AnalysisContext context) {
|
||||
SysUserVo sysUser = this.userService.selectUserByUserName(userVo.getUserName());
|
||||
try {
|
||||
Long deptId = this.deptService.selectIdByName(userVo.getDeptName());
|
||||
if (ObjectUtil.isNotNull(deptId)) {
|
||||
// 验证是否存在这个用户
|
||||
if (ObjectUtil.isNull(sysUser)) {
|
||||
SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
|
||||
ValidatorUtils.validate(user);
|
||||
user.setPassword(password);
|
||||
user.setDeptId(deptId);
|
||||
user.setCreateBy(operUserId);
|
||||
userService.insertUser(user);
|
||||
successNum++;
|
||||
successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
|
||||
} else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(sysUser.getUserName()).append(" 已存在");
|
||||
}
|
||||
} else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(sysUser.getUserName()).append(" 查询不到部门");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、账号 " + userVo.getUserName() + " 导入失败:";
|
||||
failureMsg.append(msg).append(e.getMessage());
|
||||
log.error(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExcelResult<SysStudentImportVo> getExcelResult() {
|
||||
return new ExcelResult<>() {
|
||||
@Override
|
||||
public String getAnalysis() {
|
||||
if (failureNum > 0) {
|
||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||
throw new ServiceException(failureMsg.toString());
|
||||
} else {
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
@Override
|
||||
public List<SysStudentImportVo> getList() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<String> getErrorList() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -13,10 +13,9 @@ import org.dromara.common.excel.core.ExcelListener;
|
|||
import org.dromara.common.excel.core.ExcelResult;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.system.domain.bo.SysUserBo;
|
||||
import org.dromara.system.domain.vo.SysUserImportVo;
|
||||
import org.dromara.system.domain.vo.SysTeacherImportVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.service.ISysConfigService;
|
||||
import org.dromara.system.service.ISysDeptService;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -27,16 +26,12 @@ import java.util.List;
|
|||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
public class SysUserImportListener extends AnalysisEventListener<SysUserImportVo> implements ExcelListener<SysUserImportVo> {
|
||||
public class SysTeacherImportListener extends AnalysisEventListener<SysTeacherImportVo> implements ExcelListener<SysTeacherImportVo> {
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
private final ISysDeptService deptService;
|
||||
|
||||
private final String password;
|
||||
|
||||
private final Boolean isUpdateSupport;
|
||||
|
||||
private final Long operUserId;
|
||||
|
||||
private int successNum = 0;
|
||||
|
@ -44,47 +39,33 @@ public class SysUserImportListener extends AnalysisEventListener<SysUserImportVo
|
|||
private final StringBuilder successMsg = new StringBuilder();
|
||||
private final StringBuilder failureMsg = new StringBuilder();
|
||||
|
||||
public SysUserImportListener(Boolean isUpdateSupport) {
|
||||
public SysTeacherImportListener() {
|
||||
String initPassword = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.user.initPassword");
|
||||
this.userService = SpringUtils.getBean(ISysUserService.class);
|
||||
this.deptService = SpringUtils.getBean(ISysDeptService.class);
|
||||
this.password = BCrypt.hashpw(initPassword);
|
||||
this.isUpdateSupport = isUpdateSupport;
|
||||
this.operUserId = LoginHelper.getUserId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(SysUserImportVo userVo, AnalysisContext context) {
|
||||
public void invoke(SysTeacherImportVo userVo, AnalysisContext context) {
|
||||
SysUserVo sysUser = this.userService.selectUserByUserName(userVo.getUserName());
|
||||
try {
|
||||
// 验证是否存在这个用户
|
||||
if (ObjectUtil.isNull(sysUser)) {
|
||||
Long deptId = this.deptService.selectIdBuName(userVo.getDeptName());
|
||||
SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
|
||||
ValidatorUtils.validate(user);
|
||||
user.setPassword(password);
|
||||
user.setDeptId(deptId);
|
||||
//user.setDeptId(deptId);
|
||||
user.setCreateBy(operUserId);
|
||||
user.setUserType("teacher");
|
||||
userService.insertUser(user);
|
||||
successNum++;
|
||||
successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
|
||||
} else {
|
||||
//todo 是否需要更新,暂不知需求
|
||||
// } else if (isUpdateSupport) {
|
||||
// Long userId = sysUser.getUserId();
|
||||
// SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
|
||||
// user.setUserId(userId);
|
||||
// ValidatorUtils.validate(user);
|
||||
// userService.checkUserAllowed(user.getUserId());
|
||||
// userService.checkUserDataScope(user.getUserId());
|
||||
// user.setUpdateBy(operUserId);
|
||||
// userService.updateUser(user);
|
||||
// successNum++;
|
||||
// successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 更新成功");
|
||||
// } else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(sysUser.getUserName()).append(" 已存在");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、账号 " + userVo.getUserName() + " 导入失败:";
|
||||
|
@ -99,9 +80,8 @@ public class SysUserImportListener extends AnalysisEventListener<SysUserImportVo
|
|||
}
|
||||
|
||||
@Override
|
||||
public ExcelResult<SysUserImportVo> getExcelResult() {
|
||||
public ExcelResult<SysTeacherImportVo> getExcelResult() {
|
||||
return new ExcelResult<>() {
|
||||
|
||||
@Override
|
||||
public String getAnalysis() {
|
||||
if (failureNum > 0) {
|
||||
|
@ -114,7 +94,7 @@ public class SysUserImportListener extends AnalysisEventListener<SysUserImportVo
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserImportVo> getList() {
|
||||
public List<SysTeacherImportVo> getList() {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -115,6 +115,6 @@ public interface ISysDeptService {
|
|||
*/
|
||||
int deleteDeptById(Long deptId);
|
||||
|
||||
Long selectIdBuName(String deptName);
|
||||
Long selectIdByName(String deptName);
|
||||
|
||||
}
|
||||
|
|
|
@ -156,6 +156,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||
return String.join(StringUtils.SEPARATOR, list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据ID查询所有子部门数(正常状态)
|
||||
*
|
||||
|
@ -325,8 +326,9 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||
return baseMapper.deleteById(deptId);
|
||||
}
|
||||
|
||||
@Cacheable(cacheNames = CacheNames.SYS_DEPT_NAME, key = "#deptName")
|
||||
@Override
|
||||
public Long selectIdBuName(String deptName) {
|
||||
public Long selectIdByName(String deptName) {
|
||||
SysDept sysDept = baseMapper.selectOne(new LambdaQueryWrapper<SysDept>().select(SysDept::getDeptId).eq(SysDept::getDeptName, deptName));
|
||||
return sysDept.getDeptId();
|
||||
}
|
||||
|
|
|
@ -62,7 +62,6 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|||
|
||||
@Override
|
||||
public TableDataInfo<SysUserVo> selectPageUserList(SysUserBo user, PageQuery pageQuery) {
|
||||
//user.setUserType(UserType.STUDENT.getUserType());
|
||||
Page<SysUserVo> page = baseMapper.selectPageUserList(pageQuery.build(), this.buildQueryWrapper(user));
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue