Merge pull request '分部、部门导入Excel批量新增、更新' (#82) from feature/dxf into develop
Reviewed-on: http://221.226.25.34:3000/liang.cheng/weaver-hrm-organization/pulls/82
This commit is contained in:
commit
f17e8ade50
|
|
@ -6,6 +6,7 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import weaver.general.Util;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
|
|
@ -29,10 +30,10 @@ public class HrmFormFieldPO {
|
|||
|
||||
public JSONObject getJsonObject(String fieldValue) throws JSONException {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("fieldid", this.fieldId);
|
||||
jsonObject.put("fieldhtmltype", this.fieldHtmlType);
|
||||
jsonObject.put("type", this.type);
|
||||
jsonObject.put("dmlurl", this.dmlUrl);
|
||||
jsonObject.put("fieldid", Util.null2String(this.fieldId));
|
||||
jsonObject.put("fieldhtmltype", Util.null2String(this.fieldHtmlType));
|
||||
jsonObject.put("type", Util.null2String(this.type));
|
||||
jsonObject.put("dmlurl", Util.null2String(this.dmlUrl));
|
||||
jsonObject.put("fieldvalue", fieldValue);
|
||||
return jsonObject;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,4 +94,6 @@ public interface DepartmentMapper {
|
|||
|
||||
int countUsedInJob(@Param("supDepId") Long supDepId);
|
||||
|
||||
String getIdByDepartmentCode(@Param("departmentCode") String departmentCode);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,6 +139,11 @@
|
|||
and delete_type = 0
|
||||
and parent_dept = = #{supDepId}
|
||||
</select>
|
||||
<select id="getIdByDepartmentCode" resultType="java.lang.String">
|
||||
select id
|
||||
from hrmdepartment
|
||||
where departmentcode = #{departmentCode}
|
||||
</select>
|
||||
|
||||
<sql id="likeSQL">
|
||||
<if test=" departmentPO.departmentCode != null and departmentPO.departmentCode != '' ">
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import com.engine.organization.util.OrganizationAssert;
|
|||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import com.engine.organization.util.excel.ExcelUtil;
|
||||
import com.engine.organization.util.saveimport.CompanyImport;
|
||||
import com.engine.organization.util.saveimport.DepartmentImport;
|
||||
import com.engine.organization.util.saveimport.OrgImportUtil;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -74,14 +75,10 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
/**
|
||||
* extend_group
|
||||
*/
|
||||
private static final Long COMPANY_TYPE = 1L;
|
||||
private static final Long DEPARTMENT_TYPE = 2L;
|
||||
private static final Long JOB_TYPE = 3L;
|
||||
private static final Long RESOURCE_TYPE = 4L;
|
||||
|
||||
private static final String RIGHT_NAME = "DataImport:All";
|
||||
private static final String HRM_COMPANY = "hrmsubcompany";
|
||||
private static final String HRM_DEPARTMENT = "hrmdepartment";
|
||||
private static final String HRM_RESOURCE = "hrmresource";
|
||||
|
||||
static Map<String, ExtendInfoPO> importFieldsMap;
|
||||
|
|
@ -126,11 +123,10 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
excludeFields.add("subshowid");
|
||||
return CompanyImport.getImportFields(user, excludeFields);
|
||||
case "department":
|
||||
extendType = "2";
|
||||
tableName = "JCL_ORG_DEPT";
|
||||
excludeFields.add("parent_dept");
|
||||
excludeFields.add("ec_department");
|
||||
break;
|
||||
excludeFields.add("departmentname");
|
||||
excludeFields.add("supdepid");
|
||||
excludeFields.add("showid");
|
||||
return DepartmentImport.getImportFields(user, excludeFields);
|
||||
case "jobtitle":
|
||||
extendType = "3";
|
||||
tableName = "JCL_ORG_JOB";
|
||||
|
|
@ -202,7 +198,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
returnMap.put("condition", CompanyImport.importForm(user, templatePath));
|
||||
break;
|
||||
case "department":
|
||||
returnMap.put("condition", getDepartmentImportForm(templatePath));
|
||||
returnMap.put("condition", DepartmentImport.importForm(user, templatePath));
|
||||
break;
|
||||
case "jobtitle":
|
||||
returnMap.put("condition", getJobTitleImportForm(templatePath));
|
||||
|
|
@ -238,11 +234,10 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
if (StringUtils.isNotBlank(importType)) {
|
||||
switch (importType) {
|
||||
case "company":
|
||||
// returnMap.put("pId", companyImport(operateType, excelFile));
|
||||
returnMap.put("pId", CompanyImport.saveImport(operateType, excelFile, user));
|
||||
break;
|
||||
case "department":
|
||||
returnMap.put("pId", departmentImport(operateType, excelFile));
|
||||
returnMap.put("pId", DepartmentImport.saveImport(operateType, excelFile, user));
|
||||
break;
|
||||
case "jobtitle":
|
||||
returnMap.put("pId", jobImport(operateType, excelFile));
|
||||
|
|
@ -305,69 +300,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
}
|
||||
|
||||
|
||||
|
||||
private List<Object> getDepartmentImportForm(String templatePath) throws IOException {
|
||||
|
||||
// 返回导入数据
|
||||
List<Object> lsGroup = new ArrayList<>();
|
||||
Map<String, Object> groupItem = new HashMap<>();
|
||||
List<Object> itemList = new ArrayList<>();
|
||||
|
||||
groupItem.put("title", SystemEnv.getHtmlLabelName(1361, user.getLanguage()));
|
||||
groupItem.put("defaultshow", true);
|
||||
|
||||
SearchConditionItem searchConditionItem;
|
||||
ConditionFactory conditionFactory = new ConditionFactory(user);
|
||||
//导入类型
|
||||
List<SearchConditionOption> statusOptions = new ArrayList<>();
|
||||
statusOptions.add(new SearchConditionOption("add", SystemEnv.getHtmlLabelName(611, user.getLanguage()), true));
|
||||
statusOptions.add(new SearchConditionOption("update", SystemEnv.getHtmlLabelName(17744, user.getLanguage())));
|
||||
searchConditionItem = conditionFactory.createCondition(ConditionType.SELECT, 24863, "importType", statusOptions);
|
||||
searchConditionItem.setValue("add");
|
||||
itemList.add(searchConditionItem);
|
||||
|
||||
//模板文件
|
||||
searchConditionItem = conditionFactory.createCondition(ConditionType.INPUT, 28576, "templet");
|
||||
searchConditionItem.setValue(templatePath);
|
||||
itemList.add(searchConditionItem);
|
||||
|
||||
//Excel文件
|
||||
searchConditionItem = conditionFactory.createCondition(ConditionType.RESOURCEIMG, 16630, "excelfile");
|
||||
itemList.add(searchConditionItem);
|
||||
|
||||
groupItem.put("items", itemList);
|
||||
lsGroup.add(groupItem);
|
||||
|
||||
|
||||
itemList = new ArrayList<>();
|
||||
groupItem = new HashMap<>();
|
||||
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);
|
||||
lsPromptLabel.add(125466);
|
||||
//lsPromptLabel.add(522355);
|
||||
//lsPromptLabel.add(522356);
|
||||
//lsPromptLabel.add(522357);
|
||||
//lsPromptLabel.add(530411);
|
||||
|
||||
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", templatePath);
|
||||
}
|
||||
item.put("value", value);
|
||||
itemList.add(item);
|
||||
}
|
||||
groupItem.put("items", itemList);
|
||||
lsGroup.add(groupItem);
|
||||
return lsGroup;
|
||||
}
|
||||
|
||||
private List<Object> getJobTitleImportForm(String templatePath) throws IOException {
|
||||
|
||||
// 返回导入数据
|
||||
|
|
@ -566,245 +498,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 导入部门
|
||||
*/
|
||||
private Long departmentImport(String operateType, String excelFile) {
|
||||
Long importHistoryId = OrgImportUtil.saveImportLog("department", 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();
|
||||
List<ExtendInfoPO> extendInfoPOS = new ArrayList<>();
|
||||
OrganizationAssert.isTrue(lastRow > 0, "导入数据为空");
|
||||
short lastCellNum = sheetAt.getRow(0).getLastCellNum();
|
||||
|
||||
|
||||
// 遍历每一行数据
|
||||
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;
|
||||
String departmentName = "";
|
||||
|
||||
historyDetailPO.setRowNums(String.valueOf(i + 1));
|
||||
for (int cellIndex = 0; cellIndex < lastCellNum; cellIndex++) {
|
||||
XSSFCell cell = row.getCell((short) cellIndex);
|
||||
String cellValue = getCellValue(cell).trim();
|
||||
if (i == 0) {
|
||||
// 首行 初始化字段信息
|
||||
List<ExtendInfoPO> infoPOList = getExtendInfoMapper().getInfoByExtendAndLabelName(DEPARTMENT_TYPE, cellValue);
|
||||
boolean isBreak = OrgImportUtil.isBreak(historyDetailPO, cellValue, infoPOList);
|
||||
if (isBreak) {
|
||||
break nextRow;
|
||||
}
|
||||
ExtendInfoPO extendInfoPO = infoPOList.get(0);
|
||||
extendInfoPOS.add(extendInfoPO);
|
||||
} else {
|
||||
ExtendInfoPO infoPO = extendInfoPOS.get(cellIndex);
|
||||
// 数据校验
|
||||
if (infoPO.getIsrequired() == 1 && StringUtils.isBlank(cellValue) && !"dept_no".equalsIgnoreCase(infoPO.getFieldName())) {
|
||||
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)) && !"ec_company".equals(infoPO.getFieldName())) {
|
||||
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "数据转换失败,未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
map.put(infoPO.getFieldName(), reallyValue);
|
||||
// 上级分部
|
||||
if ("ec_company".equals(infoPO.getFieldName())) {
|
||||
String[] split = cellValue.split(">");
|
||||
if (split.length > 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ("dept_name".equals(infoPO.getFieldName())) {
|
||||
if (null == parentCompanyId) {
|
||||
historyDetailPO.setOperateDetail(cellValue + "所属分部未找到");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
historyDetailPO.setRelatedName(cellValue);
|
||||
String[] split = cellValue.split(">");
|
||||
if (split.length > 0) {
|
||||
if (split.length > 8) {
|
||||
historyDetailPO.setOperateDetail("部门层级不能大于10");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
for (int index = 0; index < split.length - 1; index++) {
|
||||
parentDepartmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByNameAndPid(split[index], parentCompanyId, parentDepartmentId == null ? 0 : parentDepartmentId);
|
||||
if (null == parentDepartmentId) {
|
||||
historyDetailPO.setOperateDetail(split[index] + "部门未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put("parent_comp", parentCompanyId);
|
||||
map.put("ec_company", parentCompanyId);
|
||||
map.put("parent_dept", parentDepartmentId);
|
||||
map.put("ec_department", parentDepartmentId);
|
||||
|
||||
departmentName = split[split.length - 1];
|
||||
map.put("dept_name", departmentName);
|
||||
}
|
||||
if ("dept_principal".equals(infoPO.getFieldName())) {
|
||||
boolean hasSameName = hasSameName(historyDetailPO, cellValue);
|
||||
if (hasSameName) {
|
||||
continue nextRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 校验、数据交互
|
||||
if (i == 0) {
|
||||
continue;
|
||||
}
|
||||
String deptNo = (String) map.get("dept_no");
|
||||
Integer departmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByNameAndPid(departmentName, parentCompanyId, parentDepartmentId == null ? 0 : parentDepartmentId);
|
||||
if ("add".equals(operateType)) {
|
||||
if (departmentId != null) {
|
||||
historyDetailPO.setOperateDetail("数据已存在");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue;
|
||||
}
|
||||
// 自动编号
|
||||
try {
|
||||
deptNo = DepartmentServiceImpl.repeatDetermine(deptNo);
|
||||
} catch (OrganizationRunTimeException e) {
|
||||
historyDetailPO.setOperateDetail(e.getMessage());
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue;
|
||||
}
|
||||
map.put("dept_no", deptNo);
|
||||
map.put("creator", user.getUID());
|
||||
map.put("delete_type", 0);
|
||||
map.put("create_time", new Date());
|
||||
// 禁用表示为空,默认启用
|
||||
if (StringUtils.isBlank(Util.null2String(map.get("forbidden_tag")))) {
|
||||
map.put("forbidden_tag", 0);
|
||||
}
|
||||
String showOrder = Util.null2String(map.get("show_order"));
|
||||
if (StringUtils.isBlank(showOrder)) {
|
||||
Double maxShowOrder = MapperProxyFactory.getProxy(DepartmentMapper.class).getMaxShowOrder();
|
||||
if (null == maxShowOrder) {
|
||||
maxShowOrder = 0D;
|
||||
}
|
||||
map.put("show_order", maxShowOrder + 1);
|
||||
}
|
||||
Map<String, Object> syncMap = new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.ADD, map, false).sync();
|
||||
if (OrgImportUtil.isThrowError(syncMap)) {
|
||||
// 查询UUID
|
||||
String ecDepartmentID = Util.null2String(syncMap.get("id"));
|
||||
RecordInfo recordInfo = getSystemDataMapper().getHrmObjectByID(HRM_DEPARTMENT, ecDepartmentID);
|
||||
map.put("uuid", recordInfo.getUuid());
|
||||
ExtendInfoParams infoParams = ExtendInfoParams.builder().tableName("JCL_ORG_DEPT").params(map).build();
|
||||
MapperProxyFactory.getProxy(ExtMapper.class).insertTable(infoParams);
|
||||
// 刷新组织架构图
|
||||
//TODO new DepartmentTriggerRunnable(infoParams.getId()).run();
|
||||
map.put("id", infoParams.getId());
|
||||
historyDetailPO.setOperateDetail("添加成功");
|
||||
historyDetailPO.setStatus("1");
|
||||
} else {
|
||||
historyDetailPO.setOperateDetail(Util.null2String(syncMap.get("message")));
|
||||
historyDetailPO.setStatus("0");
|
||||
}
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
} else if ("update".equals(operateType)) {
|
||||
// 查询对应ID
|
||||
if (StringUtils.isNotBlank(deptNo)) {
|
||||
if (departmentId == null) {
|
||||
historyDetailPO.setOperateDetail("未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue;
|
||||
}
|
||||
if (checkRepeatNo(deptNo, DEPARTMENT_TYPE, Long.valueOf(departmentId))) {
|
||||
map.put("update_time", new Date());
|
||||
map.put("id", departmentId);
|
||||
Map<String, Object> syncMap = new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.UPDATE, map, false).sync();
|
||||
if (OrgImportUtil.isThrowError(syncMap)) {
|
||||
map.remove("id");
|
||||
MapperProxyFactory.getProxy(ExtMapper.class).updateTable(ExtendInfoParams.builder().id(Long.valueOf(departmentId)).tableName("JCL_ORG_DEPT").params(map).build());
|
||||
// 刷新组织架构图
|
||||
//TODO new DepartmentTriggerRunnable(departmentId).run();
|
||||
historyDetailPO.setOperateDetail("更新成功");
|
||||
historyDetailPO.setStatus("1");
|
||||
} else {
|
||||
historyDetailPO.setOperateDetail(Util.null2String(syncMap.get("message")));
|
||||
historyDetailPO.setStatus("0");
|
||||
}
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
} else {
|
||||
historyDetailPO.setOperateDetail(deptNo + "编号已存在");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
}
|
||||
} else {
|
||||
historyDetailPO.setOperateDetail("编号为空,更新失败");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
}
|
||||
}
|
||||
}
|
||||
return importHistoryId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 岗位导入
|
||||
*/
|
||||
|
|
@ -1872,7 +1565,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 判断表头是否正确
|
||||
*
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.api.browser.bean.SearchConditionItem;
|
|||
import com.api.browser.bean.SearchConditionOption;
|
||||
import com.api.browser.util.ConditionFactory;
|
||||
import com.api.browser.util.ConditionType;
|
||||
import com.engine.hrm.util.face.hrmrestful.service.HrmFieldManagerForService;
|
||||
import com.engine.organization.entity.fieldset.param.FieldTransferParam;
|
||||
import com.engine.organization.entity.jclimport.po.HrmFormFieldPO;
|
||||
import com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO;
|
||||
|
|
@ -23,7 +24,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|||
import weaver.file.ImageFileManager;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
import weaver.hrm.definedfield.HrmFieldManager;
|
||||
import weaver.systeminfo.SystemEnv;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -193,7 +193,7 @@ public class CompanyImport {
|
|||
if ("subcompanyname".equalsIgnoreCase(infoPO.getFieldName())) {
|
||||
reallyValue = cellValue;
|
||||
} else {
|
||||
reallyValue = HrmFieldManager.getReallyFieldvalue(infoPO.getJsonObject(cellValue));
|
||||
reallyValue = HrmFieldManagerForService.getReallyFieldvalue(infoPO.getJsonObject(cellValue), true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
historyDetailPO.setOperateDetail(cellValue + "转换失败");
|
||||
|
|
@ -228,7 +228,7 @@ public class CompanyImport {
|
|||
}
|
||||
}
|
||||
}
|
||||
map.put("supsubcomid", parentCompanyId);
|
||||
map.put("supsubcomid", Util.null2String(parentCompanyId));
|
||||
|
||||
companyName = split[split.length - 1];
|
||||
map.put("subcompanyname", companyName);
|
||||
|
|
@ -265,7 +265,7 @@ public class CompanyImport {
|
|||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue;
|
||||
}
|
||||
map.put("id", companyId);
|
||||
map.put("id", Util.null2String(companyId));
|
||||
Map<String, Object> syncMap = new OrganizationSyncEc(user, LogModuleNameEnum.COMPANY, OperateTypeEnum.UPDATE, map, false).sync();
|
||||
if (OrgImportUtil.isThrowError(syncMap)) {
|
||||
// 刷新组织架构图
|
||||
|
|
|
|||
|
|
@ -0,0 +1,321 @@
|
|||
package com.engine.organization.util.saveimport;
|
||||
|
||||
import com.api.browser.bean.SearchConditionItem;
|
||||
import com.api.browser.bean.SearchConditionOption;
|
||||
import com.api.browser.util.ConditionFactory;
|
||||
import com.api.browser.util.ConditionType;
|
||||
import com.engine.hrm.util.face.hrmrestful.service.HrmFieldManagerForService;
|
||||
import com.engine.organization.entity.fieldset.param.FieldTransferParam;
|
||||
import com.engine.organization.entity.jclimport.po.HrmFormFieldPO;
|
||||
import com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO;
|
||||
import com.engine.organization.enums.HrmGroupEnum;
|
||||
import com.engine.organization.enums.LogModuleNameEnum;
|
||||
import com.engine.organization.enums.OperateTypeEnum;
|
||||
import com.engine.organization.mapper.comp.CompMapper;
|
||||
import com.engine.organization.mapper.department.DepartmentMapper;
|
||||
import com.engine.organization.mapper.jclimport.ImportMapper;
|
||||
import com.engine.organization.thread.OrganizationSyncEc;
|
||||
import com.engine.organization.util.OrganizationAssert;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2022/12/06
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class DepartmentImport {
|
||||
|
||||
private static ImportMapper getImportMapper() {
|
||||
return MapperProxyFactory.getProxy(ImportMapper.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入模板可选择字段
|
||||
*
|
||||
* @param user 当前用户
|
||||
* @param excludedFields 排除的字段
|
||||
*/
|
||||
public static Map<String, Object> getImportFields(User user, List<String> excludedFields) {
|
||||
Map<String, Object> returnMaps = new HashMap<>();
|
||||
List<HrmFormFieldPO> importFields = getImportMapper().getImportFields(user.getLanguage(), HrmGroupEnum.DEPARTMENT.getGroupType());
|
||||
importFields.removeIf(item -> excludedFields.contains(item.getFieldName()));
|
||||
|
||||
// 查询所有可以勾选的字段
|
||||
List<FieldTransferParam> fieldDatas = importFields.stream().map(item -> FieldTransferParam.builder().id(item.getFieldId().toString()).name(item.getLabelName()).build()).collect(Collectors.toList());
|
||||
returnMaps.put("data", fieldDatas);
|
||||
// 设置必填字段
|
||||
List<String> selectedKeys = importFields.stream().filter(item -> null != item.getIsSystem() && 1 == item.getIsSystem() && 1 == item.getIsMand()).map(item -> item.getFieldId().toString()).collect(Collectors.toList());
|
||||
returnMaps.put("selectedKeys", selectedKeys);
|
||||
return returnMaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导入模板及导入提示信息
|
||||
*
|
||||
* @param user 当前用户
|
||||
* @param templatePath 导入模板路径
|
||||
*/
|
||||
public static List<Map<String, Object>> importForm(User user, String templatePath) {
|
||||
|
||||
// 返回导入数据
|
||||
List<Map<String, Object>> lsGroup = new ArrayList<>();
|
||||
Map<String, Object> groupItem = new HashMap<>();
|
||||
List<Object> itemList = new ArrayList<>();
|
||||
|
||||
groupItem.put("title", SystemEnv.getHtmlLabelName(1361, user.getLanguage()));
|
||||
groupItem.put("defaultshow", true);
|
||||
|
||||
SearchConditionItem searchConditionItem;
|
||||
ConditionFactory conditionFactory = new ConditionFactory(user);
|
||||
//导入类型
|
||||
List<SearchConditionOption> statusOptions = new ArrayList<>();
|
||||
statusOptions.add(new SearchConditionOption("add", SystemEnv.getHtmlLabelName(611, user.getLanguage()), true));
|
||||
statusOptions.add(new SearchConditionOption("update", SystemEnv.getHtmlLabelName(17744, user.getLanguage())));
|
||||
searchConditionItem = conditionFactory.createCondition(ConditionType.SELECT, 24863, "importType", statusOptions);
|
||||
searchConditionItem.setValue("add");
|
||||
itemList.add(searchConditionItem);
|
||||
|
||||
//模板文件
|
||||
searchConditionItem = conditionFactory.createCondition(ConditionType.INPUT, 28576, "templet");
|
||||
searchConditionItem.setValue(templatePath);
|
||||
itemList.add(searchConditionItem);
|
||||
|
||||
//Excel文件
|
||||
searchConditionItem = conditionFactory.createCondition(ConditionType.RESOURCEIMG, 16630, "excelfile");
|
||||
itemList.add(searchConditionItem);
|
||||
|
||||
groupItem.put("items", itemList);
|
||||
lsGroup.add(groupItem);
|
||||
|
||||
|
||||
itemList = new ArrayList<>();
|
||||
groupItem = new HashMap<>();
|
||||
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);
|
||||
lsPromptLabel.add(125466);
|
||||
|
||||
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", templatePath);
|
||||
}
|
||||
item.put("value", value);
|
||||
itemList.add(item);
|
||||
}
|
||||
groupItem.put("items", itemList);
|
||||
lsGroup.add(groupItem);
|
||||
return lsGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param operateType 导入类型
|
||||
* @param excelFile 上传的文件
|
||||
* @param user 当前用户
|
||||
*/
|
||||
public static Long saveImport(String operateType, String excelFile, User user) {
|
||||
Long importHistoryId = OrgImportUtil.saveImportLog("department", 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();
|
||||
List<HrmFormFieldPO> extendInfoPOS = new ArrayList<>();
|
||||
OrganizationAssert.isTrue(lastRow > 0, "导入数据为空");
|
||||
short lastCellNum = sheetAt.getRow(0).getLastCellNum();
|
||||
|
||||
|
||||
// 遍历每一行数据
|
||||
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;
|
||||
String departmentName = "";
|
||||
|
||||
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) {
|
||||
// 首行 初始化字段信息
|
||||
List<HrmFormFieldPO> infoPOList = getImportMapper().getImportFieldInfo(user.getLanguage(), HrmGroupEnum.DEPARTMENT.getGroupType(), cellValue);
|
||||
boolean isBreak = OrgImportUtil.isBreak(historyDetailPO, cellValue, infoPOList);
|
||||
if (isBreak) {
|
||||
break nextRow;
|
||||
}
|
||||
extendInfoPOS.add(infoPOList.get(0));
|
||||
} else {
|
||||
HrmFormFieldPO infoPO = extendInfoPOS.get(cellIndex);
|
||||
|
||||
// 数据校验
|
||||
if (infoPO.getIsMand() == 1 && StringUtils.isBlank(cellValue) && !"departmentcode".equalsIgnoreCase(infoPO.getFieldName())) {
|
||||
historyDetailPO.setOperateDetail(infoPO.getLabelName() + "为必填项");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
|
||||
Object reallyValue;
|
||||
try {
|
||||
if ("departmentmark".equalsIgnoreCase(infoPO.getFieldName()) || "subcompanyid1".equalsIgnoreCase(infoPO.getFieldName())) {
|
||||
reallyValue = cellValue;
|
||||
} else {
|
||||
reallyValue = HrmFieldManagerForService.getReallyFieldvalue(infoPO.getJsonObject(cellValue), true);
|
||||
}
|
||||
} 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.getLabelName() + "数据转换失败,未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
map.put(infoPO.getFieldName(), reallyValue);
|
||||
// 上级分部
|
||||
if ("subcompanyid1".equals(infoPO.getFieldName())) {
|
||||
String[] split = cellValue.split(">");
|
||||
if (split.length > 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ("departmentmark".equals(infoPO.getFieldName())) {
|
||||
if (null == parentCompanyId) {
|
||||
historyDetailPO.setOperateDetail(cellValue + "所属分部未找到");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
historyDetailPO.setRelatedName(cellValue);
|
||||
String[] split = cellValue.split(">");
|
||||
if (split.length > 0) {
|
||||
if (split.length > 8) {
|
||||
historyDetailPO.setOperateDetail("部门层级不能大于10");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
for (int index = 0; index < split.length - 1; index++) {
|
||||
parentDepartmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByNameAndPid(split[index], parentCompanyId, parentDepartmentId == null ? 0 : parentDepartmentId);
|
||||
if (null == parentDepartmentId) {
|
||||
historyDetailPO.setOperateDetail(split[index] + "部门未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put("subcompanyid1", Util.null2String(parentCompanyId));
|
||||
map.put("supdepid", Util.null2String(parentDepartmentId));
|
||||
|
||||
departmentName = split[split.length - 1];
|
||||
map.put("departmentmark", departmentName);
|
||||
map.put("departmentname", departmentName);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 校验、数据交互
|
||||
if (i == 0) {
|
||||
continue;
|
||||
}
|
||||
if ("add".equals(operateType)) {
|
||||
Map<String, Object> syncMap = new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.ADD, map, false).sync();
|
||||
if (OrgImportUtil.isThrowError(syncMap)) {
|
||||
// 查询UUID
|
||||
historyDetailPO.setOperateDetail("添加成功");
|
||||
historyDetailPO.setStatus("1");
|
||||
} else {
|
||||
historyDetailPO.setOperateDetail(Util.null2String(syncMap.get("message")));
|
||||
historyDetailPO.setStatus("0");
|
||||
}
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
} else if ("update".equals(operateType)) {
|
||||
String deptNo = (String) map.get("departmentcode");
|
||||
// 查询对应ID
|
||||
if (StringUtils.isNotBlank(deptNo)) {
|
||||
String departmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByDepartmentCode(deptNo);
|
||||
if (departmentId == null) {
|
||||
historyDetailPO.setOperateDetail("未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
continue;
|
||||
}
|
||||
map.put("id", departmentId);
|
||||
Map<String, Object> syncMap = new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.UPDATE, map, false).sync();
|
||||
if (OrgImportUtil.isThrowError(syncMap)) {
|
||||
// 刷新组织架构图
|
||||
//TODO new DepartmentTriggerRunnable(departmentId).run();
|
||||
historyDetailPO.setOperateDetail("更新成功");
|
||||
historyDetailPO.setStatus("1");
|
||||
} else {
|
||||
historyDetailPO.setOperateDetail(Util.null2String(syncMap.get("message")));
|
||||
historyDetailPO.setStatus("0");
|
||||
}
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
|
||||
} else {
|
||||
historyDetailPO.setOperateDetail("编号为空,更新失败");
|
||||
historyDetailPO.setStatus("0");
|
||||
OrgImportUtil.saveImportDetailLog(historyDetailPO);
|
||||
}
|
||||
}
|
||||
}
|
||||
return importHistoryId;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue