|
|
@@ -0,0 +1,127 @@
|
|
|
+package org.dromara.main.listener;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.idev.excel.context.AnalysisContext;
|
|
|
+import cn.idev.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.excel.core.ExcelListener;
|
|
|
+import org.dromara.common.excel.core.ExcelResult;
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
+import org.dromara.main.domain.MainAudit;
|
|
|
+import org.dromara.main.domain.MainPostApply;
|
|
|
+import org.dromara.main.domain.bo.MainPostApplyBo;
|
|
|
+import org.dromara.main.domain.vo.MainPostApplyImportVo;
|
|
|
+import org.dromara.main.mapper.MainAuditMapper;
|
|
|
+import org.dromara.main.mapper.MainPostApplyMapper;
|
|
|
+import org.dromara.system.domain.vo.SysTenantVo;
|
|
|
+import org.dromara.system.service.ISysTenantService;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 岗位申请批量导入监听器
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class MainPostApplyImportListener extends AnalysisEventListener<MainPostApplyImportVo> implements ExcelListener<MainPostApplyImportVo> {
|
|
|
+
|
|
|
+ private final MainPostApplyMapper postApplyMapper;
|
|
|
+ private final MainAuditMapper auditMapper;
|
|
|
+ private final ISysTenantService tenantService;
|
|
|
+
|
|
|
+ private int successNum = 0;
|
|
|
+ private int failureNum = 0;
|
|
|
+ private final StringBuilder successMsg = new StringBuilder();
|
|
|
+ private final StringBuilder failureMsg = new StringBuilder();
|
|
|
+
|
|
|
+ public MainPostApplyImportListener() {
|
|
|
+ this.postApplyMapper = SpringUtils.getBean(MainPostApplyMapper.class);
|
|
|
+ this.auditMapper = SpringUtils.getBean(MainAuditMapper.class);
|
|
|
+ this.tenantService = SpringUtils.getBean(ISysTenantService.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void invoke(MainPostApplyImportVo importVo, AnalysisContext context) {
|
|
|
+ try {
|
|
|
+ if (StrUtil.isBlank(importVo.getPostName())) {
|
|
|
+ failureNum++;
|
|
|
+ failureMsg.append("<br/>").append(failureNum).append("、岗位名称不能为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String tenantId = LoginHelper.getTenantId();
|
|
|
+ MainPostApplyBo bo = BeanUtil.toBean(importVo, MainPostApplyBo.class);
|
|
|
+ bo.setTenantId(tenantId);
|
|
|
+
|
|
|
+ // 自动填充公司名称
|
|
|
+ if (StrUtil.isBlank(bo.getCompanyName()) && StrUtil.isNotBlank(tenantId)) {
|
|
|
+ SysTenantVo tenantVo = tenantService.queryByTenantId(tenantId);
|
|
|
+ if (tenantVo != null) {
|
|
|
+ bo.setCompanyName(tenantVo.getCompanyName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ MainPostApply entity = BeanUtil.toBean(bo, MainPostApply.class);
|
|
|
+
|
|
|
+ // 招聘人数校验
|
|
|
+ if (entity.getRecruitNum() != null && entity.getRecruitNum() <= 0) {
|
|
|
+ throw new ServiceException("招聘人数必须大于0");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean flag = postApplyMapper.insert(entity) > 0;
|
|
|
+ if (flag) {
|
|
|
+ // 创建待审核记录
|
|
|
+ MainAudit audit = new MainAudit();
|
|
|
+ audit.setAuditType(2);
|
|
|
+ audit.setTargetId(entity.getId());
|
|
|
+ audit.setAuditResult(0);
|
|
|
+ audit.setTenantId(tenantId);
|
|
|
+ auditMapper.insert(audit);
|
|
|
+
|
|
|
+ entity.setAuditId(audit.getId());
|
|
|
+ entity.setApplyStatus(0);
|
|
|
+ postApplyMapper.updateById(entity);
|
|
|
+
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>").append(successNum).append("、岗位 ").append(importVo.getPostName()).append(" 导入成功");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、岗位 " + (importVo.getPostName() == null ? "未知" : importVo.getPostName()) + " 导入失败:";
|
|
|
+ failureMsg.append(msg).append(e.getMessage());
|
|
|
+ log.error(msg, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ExcelResult<MainPostApplyImportVo> 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<MainPostApplyImportVo> getList() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> getErrorList() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+}
|