批量导入功能

宜通世纪科技股份有限公司
Chengliang 4 weeks ago
parent 688fd36c5a
commit 477a02b2ef

@ -148,6 +148,8 @@ public interface JobMapper {
int selectByConditions(@Param("resourcePO") ResourcePO resourcePO);
int selectByE9(@Param("jobTitleName") String jobTitleName,@Param("jobactivitymark") String jobactivitymark,@Param("jobgroupremark") String jobgroupremark);
List<String> listUsedId();
List<String> isAllowDelete(@Param("jobId") Long jobId);

@ -482,6 +482,16 @@
and delete_type = 0
</select>
<select id="selectByE9" resultType="java.lang.Integer">
select h.id from hrmjobtitles h
left join hrmjobactivities j on h.jobactivityid = j.id
left join hrmjobgroups f on j.jobgroupid = f.id
where j.jobactivitymark = #{jobactivitymark}
and f.jobgroupremark = #{jobgroupremark}
and h.JOBTITLENAME = #{jobTitleName}
</select>
<select id="getIdByNameAndPid" resultMap="BaseResultMap">
select
<include refid="baseColumns"/>

@ -4,6 +4,7 @@ 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.hrmresource.po.ResourcePO;
import com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO;
import com.engine.organization.entity.job.po.JobPO;
import com.engine.organization.entity.staff.bo.StaffBO;
@ -25,15 +26,15 @@ 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.TimeUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.systeminfo.SystemEnv;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @author:dxfeng
@ -45,18 +46,17 @@ public class JobInfoImportUtil {
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());
importFieldsMap.put("岗位名称", ExtendInfoPO.builder().tableName("jcl_org_job").fieldName("ec_jobTitle").fieldNameDesc("岗位名称").isrequired(1).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("所属分部", ExtendInfoPO.builder().tableName("jcl_org_job").fieldName("ec_company").fieldNameDesc("所属分部").isrequired(1).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("所属部门", ExtendInfoPO.builder().tableName("jcl_org_job").fieldName("ec_department").fieldNameDesc("所属部门").isrequired(1).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("职务类别", ExtendInfoPO.builder().tableName("hrmjobgroups").fieldName("jobgroupname").fieldNameDesc("职务类别").isrequired(1).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("所属职务", ExtendInfoPO.builder().tableName("hrmjobactivities").fieldName("jobactivityname").fieldNameDesc("所属职务").isrequired(1).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
importFieldsMap.put("是否关键岗", ExtendInfoPO.builder().tableName("jcl_org_job").fieldName("is_key").fieldNameDesc("是否关键岗").isrequired(1).controlType(1).browserType("1").customValue("[\"input\",\"text\",\"100\"]").build());
}
public static Long saveImport(String operateType, String excelFile, User user) {
Long importHistoryId = OrgImportUtil.saveImportLog("staff_info", operateType, user);
Long importHistoryId = OrgImportUtil.saveImportLog("job_info", operateType, user);
JclImportHistoryDetailPO historyDetailPO;
ImageFileManager manager = new ImageFileManager();
@ -73,6 +73,7 @@ public class JobInfoImportUtil {
OrganizationAssert.isTrue(lastRow > 0, "导入数据为空");
short lastCellNum = sheetAt.getRow(0).getLastCellNum();
List<ExtendInfoPO> extendInfoPOS = new ArrayList<>();
JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
// 遍历每一行数据
nextRow:
for (int i = 0; i <= lastRow; i++) {
@ -83,11 +84,11 @@ public class JobInfoImportUtil {
continue;
}
// 组装待处理数据
Map<String, Object> map = new HashMap<>();
Integer parentCompanyId = null;
Integer parentDepartmentId = null;
Long parentJobId = null;
StaffPlanPO staffPlanPO = null;
Integer subCompanyId = null;
Integer departmentId = null;
Integer jobTitleId = null;
Integer isKey = null;
String jobactivitymark = "";
String jobgroupremark = "";
@ -126,26 +127,10 @@ public class JobInfoImportUtil {
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())) {
if ("ec_company".equals(infoPO.getFieldName())) {
String[] split = cellValue.split(">");
if (split.length > 0 && StringUtils.isNotBlank(cellValue)) {
if (split.length > 8) {
@ -155,8 +140,8 @@ public class JobInfoImportUtil {
continue nextRow;
}
for (String s : split) {
parentCompanyId = MapperProxyFactory.getProxy(CompMapper.class).getIdByNameAndPid(s, parentCompanyId == null ? 0 : parentCompanyId);
if (null == parentCompanyId) {
subCompanyId = MapperProxyFactory.getProxy(CompMapper.class).getIdByNameAndPid(s, subCompanyId == null ? 0 : subCompanyId);
if (null == subCompanyId) {
historyDetailPO.setOperateDetail(cellValue + "分部未找到对应数据");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
@ -164,11 +149,9 @@ public class JobInfoImportUtil {
}
}
}
map.put("comp_id", parentCompanyId);
map.put("ec_company", parentCompanyId);
}
// 部门
if ("dept_id".equals(infoPO.getFieldName())) {
if ("ec_department".equals(infoPO.getFieldName())) {
String[] split = cellValue.split(">");
if (split.length > 0 && StringUtils.isNotBlank(cellValue)) {
if (split.length > 8) {
@ -178,8 +161,8 @@ public class JobInfoImportUtil {
continue nextRow;
}
for (String s : split) {
parentDepartmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByNameAndPid(s, parentCompanyId, parentDepartmentId == null ? 0 : parentDepartmentId);
if (null == parentDepartmentId) {
departmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByNameAndPid(s, departmentId, departmentId == null ? 0 : departmentId);
if (null == departmentId) {
historyDetailPO.setOperateDetail(cellValue + "部门未找到对应数据");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
@ -188,67 +171,45 @@ public class JobInfoImportUtil {
}
}
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 ("is_key".equals(infoPO.getFieldName()) && StringUtils.isNotBlank(cellValue)) {
isKey = Integer.parseInt(cellValue);
}
// 岗位
if ("job_id".equals(infoPO.getFieldName()) && StringUtils.isNotBlank(cellValue)) {
if (null == parentCompanyId) {
historyDetailPO.setOperateDetail(cellValue + "所属分部未找到");
if ("ec_jobTitle".equals(infoPO.getFieldName()) && StringUtils.isNotBlank(cellValue)) {
String jobTitleName = cellValue;
//1.岗位在所属职务下是否存在
jobTitleId = MapperProxyFactory.getProxy(JobMapper.class).selectByE9(jobTitleName, jobactivitymark, jobgroupremark);
if (null == jobTitleId) {
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();
}
//2.岗位数据在聚才林岗位管理中是否重复
ResourcePO build = ResourcePO.builder().subcompanyid1(subCompanyId).departmentid(departmentId).jobtitle(jobTitleId).build();
int count = MapperProxyFactory.getProxy(JobMapper.class).selectByConditions(build);
if (count > 0) {
historyDetailPO.setOperateDetail(cellValue + "在聚才林岗位管理中已存在,请勿重复导入");
historyDetailPO.setStatus("0");
OrgImportUtil.saveImportDetailLog(historyDetailPO);
continue nextRow;
}
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;
}
}
}
// 校验、数据交互
@ -256,76 +217,18 @@ public class JobInfoImportUtil {
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;
}
String jobNo = jobTitlesComInfo.getJobTitlescode(String.valueOf(jobTitleId)) + "-" +departmentId;
JobPO jobPO = JobPO.builder()
.jobNo(jobNo)
.isKey(isKey)
.deleteType(0)
.createTime(new Date())
.ecCompany(subCompanyId)
.ecDepartment(departmentId)
.ecJobTitle(jobTitleId)
.build();
MapperProxyFactory.getProxy(JobMapper.class).insertIgnoreNull(jobPO);
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");

Loading…
Cancel
Save