优化模板存放位置;学生导入bug优化
This commit is contained in:
parent
7ed87f3b9f
commit
bdc87a6880
|
@ -31,7 +31,6 @@ import org.dromara.scale.service.ISysEvaluationRecordService;
|
|||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.system.service.ISysConfigService;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -216,10 +215,10 @@ public class SysEvaluationRecordServiceImpl implements ISysEvaluationRecordServi
|
|||
wordData.setRadar(radar);
|
||||
}
|
||||
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()
|
||||
.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);
|
||||
String wordPath = docx.getPath();
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.dromara.system.domain.vo.SysDeptVo;
|
|||
import org.dromara.system.mapper.SysDeptMapper;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.system.service.ISysConfigService;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -450,10 +449,10 @@ public class SysScalePublishServiceImpl implements ISysScalePublishService {
|
|||
wordWarnList.add(wordWarn);
|
||||
}
|
||||
wordData.setWarnCharts(wordWarnList);
|
||||
ClassPathResource classPathResource = new ClassPathResource("word/groupTemplate.docx");
|
||||
File path = new File("/usr/local/mental/word/groupTemplate.docx");
|
||||
Configure config = Configure.builder()
|
||||
.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);
|
||||
String wordPath = docx.getPath();
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -8,7 +8,6 @@ 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.StringUtils;
|
||||
import org.dromara.common.core.utils.ValidatorUtils;
|
||||
import org.dromara.common.excel.core.ExcelListener;
|
||||
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.SysUserVo;
|
||||
import org.dromara.system.service.ISysConfigService;
|
||||
import org.dromara.system.service.ISysDeptService;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -30,11 +30,11 @@ import java.util.List;
|
|||
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();
|
||||
|
@ -43,6 +43,7 @@ public class SysStudentImportListener extends AnalysisEventListener<SysStudentIm
|
|||
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();
|
||||
}
|
||||
|
@ -50,22 +51,28 @@ public class SysStudentImportListener extends AnalysisEventListener<SysStudentIm
|
|||
@Override
|
||||
public void invoke(SysStudentImportVo userVo, AnalysisContext context) {
|
||||
SysUserVo sysUser = this.userService.selectUserByUserName(userVo.getUserName());
|
||||
|
||||
Long deptId = deptService.selectIdByName(userVo.getDeptName());
|
||||
try {
|
||||
// 验证是否存在这个用户
|
||||
if (ObjectUtil.isNull(sysUser)) {
|
||||
SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
|
||||
ValidatorUtils.validate(user);
|
||||
user.setPassword(password);
|
||||
if (StringUtils.isNotEmpty(userVo.getDeptName())) {
|
||||
user.setDeptId(Long.parseLong(userVo.getDeptName()));
|
||||
if (deptId != null) {
|
||||
// 验证是否存在这个用户
|
||||
if (ObjectUtil.isNull(sysUser)) {
|
||||
SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
|
||||
ValidatorUtils.validate(user);
|
||||
user.setPassword(password);
|
||||
user.setDeptId(deptId);
|
||||
user.setCreateBy(operUserId);
|
||||
user.setUserType("student");
|
||||
userService.insertUser(user);
|
||||
successNum++;
|
||||
successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
|
||||
} else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(userVo.getUserName()).append(" 已存在");
|
||||
}
|
||||
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(userVo.getUserName()).append(" 已存在");
|
||||
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(userVo.getUserName()).append(" 的部门不存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
|
|
|
@ -124,4 +124,6 @@ public interface ISysDeptService {
|
|||
*/
|
||||
List<SysDept> selectChildDeptListByParentId(Long parentId);
|
||||
|
||||
Long selectIdByName(String deptName);
|
||||
|
||||
}
|
||||
|
|
|
@ -354,4 +354,14 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||
.orderByAsc(SysDept::getOrderNum)
|
||||
.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue