优化模板存放位置;学生导入bug优化

This commit is contained in:
cjw 2024-06-07 17:15:32 +08:00
parent 7ed87f3b9f
commit bdc87a6880
7 changed files with 37 additions and 20 deletions

View File

@ -31,7 +31,6 @@ import org.dromara.scale.service.ISysEvaluationRecordService;
import org.dromara.system.domain.vo.SysUserVo; import org.dromara.system.domain.vo.SysUserVo;
import org.dromara.system.mapper.SysUserMapper; import org.dromara.system.mapper.SysUserMapper;
import org.dromara.system.service.ISysConfigService; import org.dromara.system.service.ISysConfigService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.File; import java.io.File;
@ -216,10 +215,10 @@ public class SysEvaluationRecordServiceImpl implements ISysEvaluationRecordServi
wordData.setRadar(radar); wordData.setRadar(radar);
} }
wordData.setPropose(stringBuilder.toString()); wordData.setPropose(stringBuilder.toString());
ClassPathResource classPathResource = new ClassPathResource("word/personalTemplate.docx"); File path = new File("/usr/local/mental/word/personalTemplate.docx");
Configure config = Configure.builder() Configure config = Configure.builder()
.bind("factors", new LoopRowTableRenderPolicy()).useSpringEL().build(); .bind("factors", new LoopRowTableRenderPolicy()).useSpringEL().build();
XWPFTemplate template = XWPFTemplate.compile(classPathResource.getInputStream(), config).render(wordData); XWPFTemplate template = XWPFTemplate.compile(path, config).render(wordData);
File docx = FileUtil.createTempFile(".docx", true); File docx = FileUtil.createTempFile(".docx", true);
String wordPath = docx.getPath(); String wordPath = docx.getPath();

View File

@ -39,7 +39,6 @@ import org.dromara.system.domain.vo.SysDeptVo;
import org.dromara.system.mapper.SysDeptMapper; import org.dromara.system.mapper.SysDeptMapper;
import org.dromara.system.mapper.SysUserMapper; import org.dromara.system.mapper.SysUserMapper;
import org.dromara.system.service.ISysConfigService; import org.dromara.system.service.ISysConfigService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.File; import java.io.File;
@ -450,10 +449,10 @@ public class SysScalePublishServiceImpl implements ISysScalePublishService {
wordWarnList.add(wordWarn); wordWarnList.add(wordWarn);
} }
wordData.setWarnCharts(wordWarnList); wordData.setWarnCharts(wordWarnList);
ClassPathResource classPathResource = new ClassPathResource("word/groupTemplate.docx"); File path = new File("/usr/local/mental/word/groupTemplate.docx");
Configure config = Configure.builder() Configure config = Configure.builder()
.bind("warnCharts", new LoopRowTableRenderPolicy()).useSpringEL().build(); .bind("warnCharts", new LoopRowTableRenderPolicy()).useSpringEL().build();
XWPFTemplate template = XWPFTemplate.compile(classPathResource.getInputStream(), config).render(wordData); XWPFTemplate template = XWPFTemplate.compile(path, config).render(wordData);
File docx = FileUtil.createTempFile(".docx", true); File docx = FileUtil.createTempFile(".docx", true);
String wordPath = docx.getPath(); String wordPath = docx.getPath();

View File

@ -8,7 +8,6 @@ import com.alibaba.excel.event.AnalysisEventListener;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.core.utils.ValidatorUtils; import org.dromara.common.core.utils.ValidatorUtils;
import org.dromara.common.excel.core.ExcelListener; import org.dromara.common.excel.core.ExcelListener;
import org.dromara.common.excel.core.ExcelResult; import org.dromara.common.excel.core.ExcelResult;
@ -17,6 +16,7 @@ import org.dromara.system.domain.bo.SysUserBo;
import org.dromara.system.domain.vo.SysStudentImportVo; import org.dromara.system.domain.vo.SysStudentImportVo;
import org.dromara.system.domain.vo.SysUserVo; import org.dromara.system.domain.vo.SysUserVo;
import org.dromara.system.service.ISysConfigService; import org.dromara.system.service.ISysConfigService;
import org.dromara.system.service.ISysDeptService;
import org.dromara.system.service.ISysUserService; import org.dromara.system.service.ISysUserService;
import java.util.List; import java.util.List;
@ -30,11 +30,11 @@ import java.util.List;
public class SysStudentImportListener extends AnalysisEventListener<SysStudentImportVo> implements ExcelListener<SysStudentImportVo> { public class SysStudentImportListener extends AnalysisEventListener<SysStudentImportVo> implements ExcelListener<SysStudentImportVo> {
private final ISysUserService userService; private final ISysUserService userService;
private final ISysDeptService deptService;
private final String password; private final String password;
private final Long operUserId; private final Long operUserId;
private int successNum = 0; private int successNum = 0;
private int failureNum = 0; private int failureNum = 0;
private final StringBuilder successMsg = new StringBuilder(); private final StringBuilder successMsg = new StringBuilder();
@ -43,6 +43,7 @@ public class SysStudentImportListener extends AnalysisEventListener<SysStudentIm
public SysStudentImportListener() { public SysStudentImportListener() {
String initPassword = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.user.initPassword"); String initPassword = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.user.initPassword");
this.userService = SpringUtils.getBean(ISysUserService.class); this.userService = SpringUtils.getBean(ISysUserService.class);
this.deptService = SpringUtils.getBean(ISysDeptService.class);
this.password = BCrypt.hashpw(initPassword); this.password = BCrypt.hashpw(initPassword);
this.operUserId = LoginHelper.getUserId(); this.operUserId = LoginHelper.getUserId();
} }
@ -50,16 +51,18 @@ public class SysStudentImportListener extends AnalysisEventListener<SysStudentIm
@Override @Override
public void invoke(SysStudentImportVo userVo, AnalysisContext context) { public void invoke(SysStudentImportVo userVo, AnalysisContext context) {
SysUserVo sysUser = this.userService.selectUserByUserName(userVo.getUserName()); SysUserVo sysUser = this.userService.selectUserByUserName(userVo.getUserName());
Long deptId = deptService.selectIdByName(userVo.getDeptName());
try { try {
if (deptId != null) {
// 验证是否存在这个用户 // 验证是否存在这个用户
if (ObjectUtil.isNull(sysUser)) { if (ObjectUtil.isNull(sysUser)) {
SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class); SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
ValidatorUtils.validate(user); ValidatorUtils.validate(user);
user.setPassword(password); user.setPassword(password);
if (StringUtils.isNotEmpty(userVo.getDeptName())) { user.setDeptId(deptId);
user.setDeptId(Long.parseLong(userVo.getDeptName()));
}
user.setCreateBy(operUserId); user.setCreateBy(operUserId);
user.setUserType("student");
userService.insertUser(user); userService.insertUser(user);
successNum++; successNum++;
successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功"); successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
@ -67,6 +70,10 @@ public class SysStudentImportListener extends AnalysisEventListener<SysStudentIm
failureNum++; failureNum++;
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(userVo.getUserName()).append(" 已存在"); failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(userVo.getUserName()).append(" 已存在");
} }
} else {
failureNum++;
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(userVo.getUserName()).append(" 的部门不存在");
}
} catch (Exception e) { } catch (Exception e) {
failureNum++; failureNum++;
String msg = "<br/>" + failureNum + "、账号 " + userVo.getUserName() + " 导入失败:"; String msg = "<br/>" + failureNum + "、账号 " + userVo.getUserName() + " 导入失败:";

View File

@ -124,4 +124,6 @@ public interface ISysDeptService {
*/ */
List<SysDept> selectChildDeptListByParentId(Long parentId); List<SysDept> selectChildDeptListByParentId(Long parentId);
Long selectIdByName(String deptName);
} }

View File

@ -354,4 +354,14 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
.orderByAsc(SysDept::getOrderNum) .orderByAsc(SysDept::getOrderNum)
.orderByAsc(SysDept::getDeptId)); .orderByAsc(SysDept::getDeptId));
} }
@Override
public Long selectIdByName(String deptName) {
SysDept sysDept = baseMapper.selectOne(new LambdaQueryWrapper<SysDept>().select(SysDept::getDeptId).eq(SysDept::getDeptName, deptName));
if (ObjectUtil.isNotEmpty(sysDept)) {
return sysDept.getDeptId();
} else {
return null;
}
}
} }