批量导入功能

宜通世纪科技股份有限公司
Chengliang 1 month ago
parent b0db84f231
commit 688fd36c5a

@ -1,6 +1,7 @@
package com.engine.organization.enums;
import com.engine.organization.exception.OrganizationRunTimeException;
import com.engine.organization.util.saveimport.JobInfoImportUtil;
import com.engine.organization.util.saveimport.PostInfoImportUtil;
import com.engine.organization.util.saveimport.SequenceImportUtil;
import com.engine.organization.util.saveimport.StaffInfoImportUtil;
@ -30,6 +31,22 @@ public enum OrgImportEnum implements OrgImportAdapter {
return StaffInfoImportUtil.importForm(user);
}
},
JOB("job") {
@Override
public Map<String, Object> orgImport(Map<String, Object> params, User user) {
Map<String, Object> resultMap = new HashMap<>();
String excelFile = (String) params.get("excelfile");
resultMap.put("pId", JobInfoImportUtil.saveImport("add", excelFile, user));
return resultMap;
}
@Override
public List<Map<String, Object>> orgForm(User user) {
return JobInfoImportUtil.importForm(user);
}
},
SEQUENCE("sequence"){
@Override
public Map<String, Object> orgImport(Map<String, Object> params, User user) {

@ -207,6 +207,9 @@ public class JobServiceImpl extends Service implements JobService {
// 批量删除
topMenuList.add(MenuBtn.topMenu_batchDelete(userLanguage));
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("refresh").menuIcon("icon-coms-Refresh").menuName(SystemEnv.getHtmlLabelName(547432,userLanguage)).type("BTN_REFRESH").build());
// 批量导入
topMenuList.add(MenuBtn.builder().isBatch("1").isTop("1").menuFun("batchImport").menuIcon("icon-coms-leading-in").menuName(SystemEnv.getHtmlLabelName(547242,user.getLanguage())).type("BTN_BatchImport").build());
topMenuList.add(MenuBtn.topMenu_addNew(userLanguage));
btnDatas.put("topMenu", topMenuList);
// 日志

@ -0,0 +1,371 @@
package com.engine.organization.util.saveimport;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.organization.entity.department.po.DepartmentPO;
import com.engine.organization.entity.extend.po.ExtendInfoPO;
import com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO;
import com.engine.organization.entity.job.po.JobPO;
import com.engine.organization.entity.staff.bo.StaffBO;
import com.engine.organization.entity.staff.param.StaffParams;
import com.engine.organization.entity.staff.po.StaffPO;
import com.engine.organization.entity.staff.po.StaffPlanPO;
import com.engine.organization.mapper.comp.CompMapper;
import com.engine.organization.mapper.department.DepartmentMapper;
import com.engine.organization.mapper.job.JobMapper;
import com.engine.organization.mapper.staff.StaffMapper;
import com.engine.organization.mapper.staff.StaffPlanMapper;
import com.engine.organization.service.impl.StaffServiceImpl;
import com.engine.organization.util.OrganizationAssert;
import com.engine.organization.util.db.MapperProxyFactory;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import weaver.file.ImageFileManager;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2022/09/15
* @version: 1.0
*/
public class JobInfoImportUtil {
static Map<String, ExtendInfoPO> importFieldsMap;
static {
importFieldsMap = new HashMap<>();
importFieldsMap.put("岗位名称", ExtendInfoPO.builder().tableName("hrmjobtitles").fieldName("plan_name").fieldNameDesc("方案名称").isrequired(0).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("所属分部", ExtendInfoPO.builder().tableName("jcl_org_staff").fieldName("comp_id").fieldNameDesc("分部").isrequired(1).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("所属部门", ExtendInfoPO.builder().tableName("jcl_org_staff").fieldName("dept_id").fieldNameDesc("部门").isrequired(0).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("职务类别", ExtendInfoPO.builder().tableName("hrmjobgroups").fieldName("jobgroupname").fieldNameDesc("职务类型").isrequired(0).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("所属职务", ExtendInfoPO.builder().tableName("hrmjobactivities").fieldName("jobactivityname").fieldNameDesc("职务").isrequired(0).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("是否关键岗", ExtendInfoPO.builder().tableName("jcl_org_staff").fieldName("job_id").fieldNameDesc("岗位").isrequired(0).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("显示顺序", ExtendInfoPO.builder().tableName("jcl_org_staff").fieldName("staff_num").fieldNameDesc("编制数").isrequired(1).controlType(1).browserType("2").customValue("[\"input\",\"int\"]").build());
}
public static Long saveImport(String operateType, String excelFile, User user) {
Long importHistoryId = OrgImportUtil.saveImportLog("staff_info", operateType, user);
JclImportHistoryDetailPO historyDetailPO;
ImageFileManager manager = new ImageFileManager();
manager.getImageFileInfoById(Util.getIntValue(excelFile));
XSSFWorkbook workbook;
try {
workbook = new XSSFWorkbook(manager.getInputStream());
} catch (IOException e) {
throw new RuntimeException(e);
}
// 当前sheet
XSSFSheet sheetAt = workbook.getSheetAt(0);
int lastRow = sheetAt.getLastRowNum();
OrganizationAssert.isTrue(lastRow > 0, "导入数据为空");
short lastCellNum = sheetAt.getRow(0).getLastCellNum();
List<ExtendInfoPO> extendInfoPOS = new ArrayList<>();
// 遍历每一行数据
nextRow:
for (int i = 0; i <= lastRow; i++) {
historyDetailPO = new JclImportHistoryDetailPO();
historyDetailPO.setPid(importHistoryId);
XSSFRow row = sheetAt.getRow(i);
if (null == row) {
continue;
}
// 组装待处理数据
Map<String, Object> map = new HashMap<>();
Integer parentCompanyId = null;
Integer parentDepartmentId = null;
Long parentJobId = null;
StaffPlanPO staffPlanPO = null;
String jobactivitymark = "";
String jobgroupremark = "";
historyDetailPO.setRowNums(String.valueOf(i + 1));
for (int cellIndex = 0; cellIndex < lastCellNum; cellIndex++) {
XSSFCell cell = row.getCell((short) cellIndex);
String cellValue = OrgImportUtil.getCellValue(cell).trim();
if (i == 0) {
// 首行 初始化字段信息
ExtendInfoPO extendInfoPO = importFieldsMap.get(cellValue);
extendInfoPOS.add(extendInfoPO);
} else {
ExtendInfoPO infoPO = extendInfoPOS.get(cellIndex);
// 数据校验
if (infoPO.getIsrequired() == 1 && StringUtils.isBlank(cellValue)) {
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "为必填项");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
Object reallyValue;
try {
reallyValue = OrgImportUtil.getReallyValue(infoPO, cellValue);
} catch (Exception e) {
historyDetailPO.setOperateDetail(cellValue + "转换失败");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
if (StringUtils.isNotBlank(cellValue) && StringUtils.isBlank(Util.null2String(reallyValue))) {
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "数据转换失败,未找到对应数据");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
map.put(infoPO.getFieldName(), reallyValue);
// 编制方案
if ("plan_no".equals(infoPO.getFieldName())) {
// 根据编制方案判断控制维度,控制必填
List<StaffPlanPO> staffPlanPOS = MapperProxyFactory.getProxy(StaffPlanMapper.class).listByNo(Util.null2String(reallyValue));
if (CollectionUtils.isNotEmpty(staffPlanPOS)) {
staffPlanPO = staffPlanPOS.get(0);
map.put("plan_id", staffPlanPO.getId());
historyDetailPO.setRelatedName(staffPlanPO.getPlanNo());
} else {
historyDetailPO.setRelatedName("");
historyDetailPO.setOperateDetail("编号:" + reallyValue + ",未找到对应数据");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
}
// 分部
if ("comp_id".equals(infoPO.getFieldName())) {
String[] split = cellValue.split(">");
if (split.length > 0 && StringUtils.isNotBlank(cellValue)) {
if (split.length > 8) {
historyDetailPO.setOperateDetail("分部层级不能大于10");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
for (String s : split) {
parentCompanyId = MapperProxyFactory.getProxy(CompMapper.class).getIdByNameAndPid(s, parentCompanyId == null ? 0 : parentCompanyId);
if (null == parentCompanyId) {
historyDetailPO.setOperateDetail(cellValue + "分部未找到对应数据");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
}
}
map.put("comp_id", parentCompanyId);
map.put("ec_company", parentCompanyId);
}
// 部门
if ("dept_id".equals(infoPO.getFieldName())) {
String[] split = cellValue.split(">");
if (split.length > 0 && StringUtils.isNotBlank(cellValue)) {
if (split.length > 8) {
historyDetailPO.setOperateDetail("部门层级不能大于10");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
for (String s : split) {
parentDepartmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByNameAndPid(s, parentCompanyId, parentDepartmentId == null ? 0 : parentDepartmentId);
if (null == parentDepartmentId) {
historyDetailPO.setOperateDetail(cellValue + "部门未找到对应数据");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
}
}
map.put("dept_id", parentDepartmentId);
map.put("ec_department", parentDepartmentId);
}
//职务类型
if ("jobgroupname".equals(infoPO.getFieldName()) && StringUtils.isNotBlank(cellValue)) {
jobgroupremark = cellValue;
}
//职务
if ("jobactivityname".equals(infoPO.getFieldName()) && StringUtils.isNotBlank(cellValue)) {
jobactivitymark = cellValue;
}
// 岗位
if ("job_id".equals(infoPO.getFieldName()) && StringUtils.isNotBlank(cellValue)) {
if (null == parentCompanyId) {
historyDetailPO.setOperateDetail(cellValue + "所属分部未找到");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
String[] split = cellValue.split(">");
if (split.length > 0 && StringUtils.isNotBlank(cellValue)) {
if (split.length > 8) {
historyDetailPO.setOperateDetail("岗位层级不能大于10");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
for (String s : split) {
List<JobPO> jobPList = MapperProxyFactory.getProxy(JobMapper.class).getIdByNameAndPid(s, parentCompanyId, parentDepartmentId == null ? 0 : parentDepartmentId, parentJobId == null ? 0 : parentJobId
,jobactivitymark,jobgroupremark);
if (jobPList.size() > 1) {
historyDetailPO.setOperateDetail(s + "岗位在岗位管理中存在重复数据,请先处理");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
if (jobPList.size() == 0) {
historyDetailPO.setOperateDetail(s + "岗位未找到对应数据");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
parentJobId = jobPList.get(0).getId();
}
}
map.put("job_id", parentJobId);
}
// 编制数大于0
if ("staff_num".equals(infoPO.getFieldName()) && Integer.parseInt(Util.null2String(reallyValue)) < 0) {
historyDetailPO.setOperateDetail("编制数不可小于0");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
}
}
// 校验、数据交互
if (i == 0) {
continue;
}
if (null == staffPlanPO) {
historyDetailPO.setOperateDetail("未找到对应数据");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue;
}
StaffParams param = JSONObject.toJavaObject((JSON) JSONObject.toJSON(map), StaffParams.class);
String controlDimension = staffPlanPO.getControlDimension();
String checkMsg = "";
switch (controlDimension) {
case "1":// 分部
if (null == parentCompanyId) {
checkMsg = "编制维度选择分部时,分部必填!";
}
// 取消部门、岗位赋值
param.setDeptId(null);
param.setJobId(null);
break;
case "2":// 部门
if (null == parentDepartmentId) {
checkMsg = "编制维度选择部门时,部门必填!";
} else {
DepartmentPO deptById = MapperProxyFactory.getProxy(DepartmentMapper.class).getDeptById(parentDepartmentId);
if (null == deptById) {
checkMsg = "未找到对应部门!";
} else {
param.setCompId(deptById.getSubCompanyId1());
param.setEcCompany(deptById.getSubCompanyId1());
}
}
// 取消岗位赋值
param.setJobId(null);
break;
case "3": // 岗位
if (null == parentJobId) {
checkMsg = "编制维度选择岗位时,未找到对应岗位!";
} else {
JobPO jobPO = MapperProxyFactory.getProxy(JobMapper.class).getJobById(parentJobId);
if (null == jobPO) {
checkMsg = "未找到对应岗位!";
} else {
param.setCompId(jobPO.getEcCompany());
param.setEcCompany(jobPO.getEcCompany());
param.setDeptId(jobPO.getEcDepartment());
param.setEcDepartment(jobPO.getEcDepartment());
}
}
break;
default:
checkMsg = "编制方案数据有误,请确认";
break;
}
StaffPO staffPO = StaffBO.convertParamToPO(param, (long) user.getUID());
if (null == staffPO.getControlPolicy()) {
staffPO.setControlPolicy(1);
}
List<StaffPO> verify = MapperProxyFactory.getProxy(StaffMapper.class).customSelect(param.getPlanId(), param.getEcCompany(), param.getEcDepartment(), param.getJobId());
if (!verify.isEmpty()) {
checkMsg = "同一编制方案下,同一维度的编制信息不可重复创建!";
}
if (StringUtils.isNotBlank(checkMsg)) {
historyDetailPO.setOperateDetail(checkMsg);
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue;
}
MapperProxyFactory.getProxy(StaffMapper.class).insertIgnoreNull(staffPO);
// 初始化编制信息
StaffServiceImpl.initStaffInfo(staffPO);
historyDetailPO.setOperateDetail("添加成功");
historyDetailPO.setStatus("1");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
}
return importHistoryId;
}
public static List<Map<String, Object>> importForm(User user) {
// 返回导入数据
List<Map<String, Object>> lsGroup = new ArrayList<>();
Map<String, Object> groupItem = new HashMap<>(3);
List<Object> itemList = new ArrayList<>();
groupItem.put("title", SystemEnv.getHtmlLabelName(33803, Util.getIntValue(user.getLanguage())));
groupItem.put("defaultshow", true);
List<Integer> lsPromptLabel = new ArrayList<>();
lsPromptLabel.add(34275);
lsPromptLabel.add(125452);
for (int i = 0; i < lsPromptLabel.size(); i++) {
Map<String, Object> item = new HashMap<>();
item.put("index", (i + 1));
String value = Util.toScreen(SystemEnv.getHtmlLabelName(lsPromptLabel.get(i), user.getLanguage()), user.getLanguage());
if (i == 0) {
value += SystemEnv.getHtmlLabelName(28576, user.getLanguage());
item.put("link", "/hrm/import/template/job.xls");
}
item.put("value", value);
itemList.add(item);
}
Map<String, Object> other = new HashMap<>();
other.put("index", (lsPromptLabel.size() + 1));
other.put("value", "注意:分部和部门存在多层级时候用 > 分割");
itemList.add(other);
groupItem.put("items", itemList);
lsGroup.add(groupItem);
return lsGroup;
}
}
Loading…
Cancel
Save