|
|
|
@ -162,6 +162,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|
|
|
|
break;
|
|
|
|
|
case "department":
|
|
|
|
|
extendType = "2";
|
|
|
|
|
exculdeFields.add("parent_dept");
|
|
|
|
|
tableName = "JCL_ORG_DEPT";
|
|
|
|
|
break;
|
|
|
|
|
case "jobtitle":
|
|
|
|
@ -238,6 +239,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|
|
|
|
returnMap.put("pId", companyImport(operateType, excelFile, 1L));
|
|
|
|
|
break;
|
|
|
|
|
case "department":
|
|
|
|
|
returnMap.put("pId", departmentImport(operateType, excelFile, 2L));
|
|
|
|
|
break;
|
|
|
|
|
case "jobtitle":
|
|
|
|
|
break;
|
|
|
|
@ -255,17 +257,20 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> getImportProcessLog(Map<String, Object> params) {
|
|
|
|
|
public Map<String, Object> getImportResult(Map<String, Object> params) {
|
|
|
|
|
String pId = (String) params.get("pId");
|
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
// 刷新引用状态
|
|
|
|
|
OrganizationWeaTable<JclImportHistoryDetailVO> table = new OrganizationWeaTable<>(user, JclImportHistoryDetailVO.class);
|
|
|
|
|
String sqlWhere = " where pId = '" + pId + "'";
|
|
|
|
|
String sqlWhere = " where status = '0' and pId = '" + pId + "'";
|
|
|
|
|
table.setSqlwhere(sqlWhere);
|
|
|
|
|
WeaResultMsg result = new WeaResultMsg(false);
|
|
|
|
|
result.putAll(table.makeDataResult());
|
|
|
|
|
result.success();
|
|
|
|
|
resultMap.putAll(result.getResultMap());
|
|
|
|
|
resultMap.put("importStatus", "over");
|
|
|
|
|
resultMap.put("succnum", MapperProxyFactory.getProxy(JclImportHistoryDetailMapper.class).countRows("1", pId));
|
|
|
|
|
resultMap.put("failnum", MapperProxyFactory.getProxy(JclImportHistoryDetailMapper.class).countRows("0", pId));
|
|
|
|
|
return resultMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -498,13 +503,12 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|
|
|
|
String cellValue = getCellValue(cell).trim();
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
// 首行 初始化字段信息
|
|
|
|
|
ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByGroupAndLabelName(extendType, cellValue);
|
|
|
|
|
ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByExtendAndLabelName(extendType, cellValue);
|
|
|
|
|
extendInfoPOS.add(extendInfoPO);
|
|
|
|
|
} else {
|
|
|
|
|
ExtendInfoPO infoPO = extendInfoPOS.get(cellIndex);
|
|
|
|
|
// 数据校验
|
|
|
|
|
if (infoPO.getIsrequired() == 1 && StringUtils.isBlank(cellValue)) {
|
|
|
|
|
// TODO 记录日志
|
|
|
|
|
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "为必填项");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
@ -521,7 +525,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|
|
|
|
continue nextRow;
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(cellValue) && StringUtils.isBlank(Util.null2String(reallyValue))) {
|
|
|
|
|
// TODO 记录日志
|
|
|
|
|
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "数据转换失败,未找到对应数据");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
@ -533,7 +536,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|
|
|
|
String[] split = cellValue.split(">");
|
|
|
|
|
if (split.length > 1) {
|
|
|
|
|
if (split.length > 8) {
|
|
|
|
|
// TODO 记录日志
|
|
|
|
|
historyDetailPO.setOperateDetail("分部层级不能大于10");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
@ -542,7 +544,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|
|
|
|
for (int index = split.length - 2; index >= 0; index--) {
|
|
|
|
|
parentCompanyId = MapperProxyFactory.getProxy(CompMapper.class).getIdByNameAndPid(split[index], parentCompanyId == null ? 0 : parentCompanyId);
|
|
|
|
|
if (null == parentCompanyId) {
|
|
|
|
|
// TODO 记录日志
|
|
|
|
|
historyDetailPO.setOperateDetail(split[index] + "分部未找到对应数据");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
@ -583,7 +584,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|
|
|
|
// 查询对应ID
|
|
|
|
|
if (StringUtils.isNotBlank(compNo)) {
|
|
|
|
|
if (companyId == null) {
|
|
|
|
|
historyDetailPO.setOperateDetail(companyName + ":未找到对应数据");
|
|
|
|
|
historyDetailPO.setOperateDetail("未找到对应数据");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
}
|
|
|
|
@ -608,6 +609,194 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|
|
|
|
return importHistoryId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导入部门
|
|
|
|
|
*
|
|
|
|
|
* @param operateType
|
|
|
|
|
* @param excelFile
|
|
|
|
|
* @param extendType
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Long departmentImport(String operateType, String excelFile, Long extendType) {
|
|
|
|
|
Long importHistoryId = saveImportLog("department", operateType);
|
|
|
|
|
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 > 1, "导入数据为空");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历每一行数据
|
|
|
|
|
nextRow:
|
|
|
|
|
for (int i = 0; i <= lastRow; i++) {
|
|
|
|
|
historyDetailPO = new JclImportHistoryDetailPO();
|
|
|
|
|
historyDetailPO.setPid(importHistoryId);
|
|
|
|
|
XSSFRow row = sheetAt.getRow(i);
|
|
|
|
|
// 组装待处理数据
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
Long parentCompanyId = null;
|
|
|
|
|
Long parentDepartmentId = null;
|
|
|
|
|
String departmentName = "";
|
|
|
|
|
|
|
|
|
|
historyDetailPO.setRowNums(String.valueOf(i + 1));
|
|
|
|
|
for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) {
|
|
|
|
|
XSSFCell cell = row.getCell((short) cellIndex);
|
|
|
|
|
if (cell == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String cellValue = getCellValue(cell).trim();
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
// 首行 初始化字段信息
|
|
|
|
|
ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByExtendAndLabelName(extendType, cellValue);
|
|
|
|
|
extendInfoPOS.add(extendInfoPO);
|
|
|
|
|
} else {
|
|
|
|
|
ExtendInfoPO infoPO = extendInfoPOS.get(cellIndex);
|
|
|
|
|
// 数据校验
|
|
|
|
|
if (infoPO.getIsrequired() == 1 && StringUtils.isBlank(cellValue)) {
|
|
|
|
|
// TODO 记录日志
|
|
|
|
|
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "为必填项");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
continue nextRow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object reallyValue;
|
|
|
|
|
try {
|
|
|
|
|
reallyValue = getReallyValue(infoPO, cellValue);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
historyDetailPO.setOperateDetail(cellValue + "转换失败");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
continue nextRow;
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(cellValue) && StringUtils.isBlank(Util.null2String(reallyValue))) {
|
|
|
|
|
// TODO 记录日志
|
|
|
|
|
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "数据转换失败,未找到对应数据");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
continue nextRow;
|
|
|
|
|
}
|
|
|
|
|
map.put(infoPO.getFieldName(), reallyValue);
|
|
|
|
|
// 上级分部
|
|
|
|
|
if ("parent_comp".equals(infoPO.getFieldName())) {
|
|
|
|
|
String[] split = cellValue.split(">");
|
|
|
|
|
if (split.length > 1) {
|
|
|
|
|
if (split.length > 8) {
|
|
|
|
|
historyDetailPO.setOperateDetail("分部层级不能大于10");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
continue nextRow;
|
|
|
|
|
}
|
|
|
|
|
for (int index = split.length - 1; index >= 0; index--) {
|
|
|
|
|
parentCompanyId = MapperProxyFactory.getProxy(CompMapper.class).getIdByNameAndPid(split[index], parentDepartmentId == null ? 0 : parentDepartmentId);
|
|
|
|
|
if (null == parentDepartmentId) {
|
|
|
|
|
historyDetailPO.setOperateDetail(cellValue + "分部未找到对应数据");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
continue nextRow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 部门名称、上级部门
|
|
|
|
|
if ("dept_name".equals(infoPO.getFieldName())) {
|
|
|
|
|
if (null == parentCompanyId) {
|
|
|
|
|
historyDetailPO.setOperateDetail(cellValue + "所属分部未找到");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
continue nextRow;
|
|
|
|
|
}
|
|
|
|
|
historyDetailPO.setRelatedName(cellValue);
|
|
|
|
|
String[] split = cellValue.split(">");
|
|
|
|
|
if (split.length > 1) {
|
|
|
|
|
if (split.length > 8) {
|
|
|
|
|
historyDetailPO.setOperateDetail("部门层级不能大于10");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
continue nextRow;
|
|
|
|
|
}
|
|
|
|
|
for (int index = split.length - 2; index >= 0; index--) {
|
|
|
|
|
parentDepartmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByNameAndPid(split[index], parentCompanyId, parentDepartmentId == null ? 0 : parentDepartmentId);
|
|
|
|
|
if (null == parentDepartmentId) {
|
|
|
|
|
historyDetailPO.setOperateDetail(split[index] + "部门未找到对应数据");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
continue nextRow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
map.put("parent_comp", parentCompanyId);
|
|
|
|
|
map.put("parent_dept", parentDepartmentId);
|
|
|
|
|
departmentName = split[split.length - 1];
|
|
|
|
|
map.put("dept_name", departmentName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 校验、数据交互
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// TODO
|
|
|
|
|
String deptNo = (String) map.get("dept_no");
|
|
|
|
|
Long departmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByNameAndPid(departmentName, parentCompanyId, parentDepartmentId == null ? 0 : parentDepartmentId);
|
|
|
|
|
if ("add".equals(operateType)) {
|
|
|
|
|
if (departmentId != null) {
|
|
|
|
|
historyDetailPO.setOperateDetail("数据已存在");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
continue nextRow;
|
|
|
|
|
}
|
|
|
|
|
// 自动编号
|
|
|
|
|
deptNo = DepartmentServiceImpl.repeatDetermine(deptNo);
|
|
|
|
|
map.put("dept_no", deptNo);
|
|
|
|
|
map.put("creator", user.getUID());
|
|
|
|
|
map.put("delete_type", 0);
|
|
|
|
|
map.put("create_time", new Date());
|
|
|
|
|
MapperProxyFactory.getProxy(ExtMapper.class).insertExt(ExtendInfoParams.builder().tableName("JCL_ORG_DEPT").params(map).build());
|
|
|
|
|
historyDetailPO.setOperateDetail("添加成功");
|
|
|
|
|
historyDetailPO.setStatus("1");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
} else if ("update".equals(operateType)) {
|
|
|
|
|
// 查询对应ID
|
|
|
|
|
if (StringUtils.isNotBlank(deptNo)) {
|
|
|
|
|
if (departmentId == null) {
|
|
|
|
|
historyDetailPO.setOperateDetail("未找到对应数据");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
}
|
|
|
|
|
if (checkRepeatNo(deptNo, extendType, departmentId)) {
|
|
|
|
|
map.put("update_time", new Date());
|
|
|
|
|
MapperProxyFactory.getProxy(ExtMapper.class).updateExt(ExtendInfoParams.builder().id(departmentId).tableName("JCL_ORG_DEPT").params(map).build());
|
|
|
|
|
historyDetailPO.setOperateDetail("更新成功");
|
|
|
|
|
historyDetailPO.setStatus("1");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
} else {
|
|
|
|
|
historyDetailPO.setOperateDetail(deptNo + "编号已存在");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
historyDetailPO.setOperateDetail("编号为空,更新失败");
|
|
|
|
|
historyDetailPO.setStatus("0");
|
|
|
|
|
saveImportDetailLog(historyDetailPO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return importHistoryId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取表格文本内容
|
|
|
|
|
*
|
|
|
|
|