commit
e0e838d73b
|
|
@ -168,4 +168,6 @@ public interface CompMapper {
|
|||
*/
|
||||
Integer countTopCompany(@Param("parentCompany") Long parentCompany);
|
||||
|
||||
int checkRepeatNo(@Param("companyNo") String companyNo, @Param("id") Long id);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -300,6 +300,15 @@
|
|||
WHERE t.delete_type = 0
|
||||
and uuid = #{uuid}
|
||||
</select>
|
||||
<select id="checkRepeatNo" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from jcl_org_comp t
|
||||
where t.delete_type = 0
|
||||
AND comp_no = #{companyNo}
|
||||
<if test=" id != null ">
|
||||
and t.id != #{id}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<update id="updateForbiddenTagById" parameterType="com.engine.organization.entity.sequence.po.SequencePO">
|
||||
update jcl_org_comp
|
||||
|
|
|
|||
|
|
@ -132,4 +132,6 @@ public interface DepartmentMapper {
|
|||
* @return
|
||||
*/
|
||||
Long getIdByNameAndPid(@Param("departmentName") String departmentName, @Param("parentCompany") Long parentCompany, @Param("parentDepartment") Long parentDepartment);
|
||||
|
||||
int checkRepeatNo(@Param("departmentNo") String departmentNo, @Param("id") Long id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,6 +157,15 @@
|
|||
where delete_type = 0
|
||||
and uuid = #{uuid}
|
||||
</select>
|
||||
<select id="checkRepeatNo" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from jcl_org_dept t
|
||||
where t.delete_type = 0
|
||||
AND dept_no = #{departmentNo}
|
||||
<if test=" id != null ">
|
||||
and t.id != #{id}
|
||||
</if>
|
||||
</select>
|
||||
<sql id="nullParentDepartment">
|
||||
and ifnull(parent_dept,0) =
|
||||
#{parentDepartment}
|
||||
|
|
|
|||
|
|
@ -37,5 +37,7 @@ public interface ExtendInfoMapper {
|
|||
|
||||
int updateExtendGroupId(@Param("groupId") Long groupId, @Param("ids") Collection<Long> ids);
|
||||
|
||||
ExtendInfoPO getInfoByGroupAndLabelName(@Param("extendType") Long extendType, @Param("labelName") String labelName);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -284,6 +284,13 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getInfoByGroupAndLabelName" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="baseColumns"/>
|
||||
from jcl_field_extendinfo t
|
||||
where t.delete_type = 0 and t.extend_type = #{extendType}
|
||||
and t.field_name_desc = #{labelName}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
@ -153,4 +153,6 @@ public interface JobMapper {
|
|||
* @return
|
||||
*/
|
||||
Long getIdByNameAndPid(@Param("jobName") String jobName, @Param("parentCompany") Long parentCompany, @Param("parentDepartment") Long parentDepartment, @Param("parentJob") Long parentJob);
|
||||
|
||||
int checkRepeatNo(@Param("jobNo") String jobNo, @Param("id") Long id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -363,6 +363,15 @@
|
|||
AND job_name = #{jobName}
|
||||
AND id != #{id}
|
||||
</select>
|
||||
<select id="checkRepeatNo" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from jcl_org_job t
|
||||
where t.delete_type = 0
|
||||
AND job_no = #{jobNo}
|
||||
<if test=" id != null ">
|
||||
and t.id != #{id}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<sql id="nullparentJob">
|
||||
and ifnull(parent_job,0) =
|
||||
|
|
|
|||
|
|
@ -30,4 +30,29 @@ public interface ImportCommonService {
|
|||
* @return
|
||||
*/
|
||||
Map<String, Object> saveImport(Map<String, Object> params, HttpServletRequest request, User user);
|
||||
|
||||
|
||||
/**
|
||||
* 获取导入字段
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getImportFields(String importType);
|
||||
|
||||
/**
|
||||
* 获取导入表单
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getImportForm(String importType, String ids);
|
||||
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> saveImport(Map<String, Object> params);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import com.engine.organization.util.OrganizationAssert;
|
|||
import com.engine.organization.util.OrganizationFormItemUtil;
|
||||
import com.engine.organization.util.db.DBType;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import com.engine.organization.util.page.PageUtil;
|
||||
import com.engine.organization.util.tree.SearchTreeUtil;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -507,9 +508,22 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
|
|||
List<SearchTree> jobTrees = SearchTreeUtil.builderTreeMode(JobBO.buildSetToSearchTree(builderJobs));
|
||||
String parentDeptS = jobTrees.stream().map(SearchTree::getParentComp).collect(Collectors.joining(","));
|
||||
if (!StringUtil.isEmpty(parentDeptS)) {
|
||||
List<DepartmentPO> compsByIds = getDepartmentMapper().getDeptsByIds(DeleteParam.builder().ids(parentDeptS).build().getIds());
|
||||
if (CollectionUtils.isNotEmpty(compsByIds)) {
|
||||
filterDeparts.addAll(compsByIds);
|
||||
// 兼容SQLServer每次最多in,2100条数据
|
||||
List<Long> ids = (List<Long>) DeleteParam.builder().ids(parentDeptS).build().getIds();
|
||||
int ceilCount = (int) Math.ceil((double) ids.size() / 1000);
|
||||
List<DepartmentPO> departmentsByIds = new ArrayList<>();
|
||||
for (int i = 0; i < ceilCount - 1; i++) {
|
||||
List<Long> longs = PageUtil.subList(i, 1000, ids);
|
||||
System.out.println(longs.size());
|
||||
List<DepartmentPO> departmentsById = getDepartmentMapper().getDeptsByIds(longs);
|
||||
if (CollectionUtils.isNotEmpty(departmentsById)) {
|
||||
departmentsByIds.addAll(departmentsById);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (CollectionUtils.isNotEmpty(departmentsByIds)) {
|
||||
filterDeparts.addAll(departmentsByIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -548,9 +562,19 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
|
|||
List<SearchTree> jobTrees = SearchTreeUtil.builderTreeMode(JobBO.buildSetToSearchTree(builderJobs));
|
||||
String parentDeptS = jobTrees.stream().map(SearchTree::getParentComp).collect(Collectors.joining(","));
|
||||
if (!StringUtil.isEmpty(parentDeptS)) {
|
||||
List<DepartmentPO> compsByIds = getDepartmentMapper().getDeptsByIds(DeleteParam.builder().ids(parentDeptS).build().getIds());
|
||||
if (CollectionUtils.isNotEmpty(compsByIds)) {
|
||||
filterDeparts.addAll(compsByIds);
|
||||
// 兼容SQLServer每次最多in,2100条数据
|
||||
List<Long> ids = (List<Long>) DeleteParam.builder().ids(parentDeptS).build().getIds();
|
||||
int ceilCount = (int) Math.ceil((double) ids.size() / 1000);
|
||||
List<DepartmentPO> departmentsByIds = new ArrayList<>();
|
||||
for (int i = 0; i < ceilCount - 1; i++) {
|
||||
List<DepartmentPO> departmentsById = getDepartmentMapper().getDeptsByIds(PageUtil.subList(i, 1000, ids));
|
||||
if (CollectionUtils.isNotEmpty(departmentsById)) {
|
||||
departmentsByIds.addAll(departmentsById);
|
||||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(departmentsByIds)) {
|
||||
filterDeparts.addAll(departmentsByIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,52 @@
|
|||
package com.engine.organization.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.core.impl.Service;
|
||||
import com.engine.hrm.entity.FieldSelectOptionBean;
|
||||
import com.engine.organization.entity.DeleteParam;
|
||||
import com.engine.organization.entity.SelectOptionParam;
|
||||
import com.engine.organization.entity.company.po.CompPO;
|
||||
import com.engine.organization.entity.extend.param.ExtendInfoParams;
|
||||
import com.engine.organization.entity.extend.po.ExtendInfoPO;
|
||||
import com.engine.organization.entity.hrmresource.param.HrmResourceImportParam;
|
||||
import com.engine.organization.mapper.comp.CompMapper;
|
||||
import com.engine.organization.mapper.extend.ExtMapper;
|
||||
import com.engine.organization.mapper.extend.ExtendInfoMapper;
|
||||
import com.engine.organization.service.ImportCommonService;
|
||||
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.HrmResourceImportAdaptUtil;
|
||||
import com.engine.organization.util.saveimport.HrmResourceImportProcessUtil;
|
||||
import com.engine.organization.util.saveimport.SaveImportProcessUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.json.JSONException;
|
||||
import weaver.file.FileUploadToPath;
|
||||
import weaver.file.ImageFileManager;
|
||||
import weaver.general.BaseBean;
|
||||
import weaver.general.GCONST;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
import weaver.systeminfo.SystemEnv;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
|
|
@ -25,6 +55,11 @@ import java.util.Map;
|
|||
*/
|
||||
public class ImportCommonServiceImpl extends Service implements ImportCommonService {
|
||||
|
||||
|
||||
private ExtendInfoMapper getExtendInfoMapper() {
|
||||
return MapperProxyFactory.getProxy(ExtendInfoMapper.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> saveImportResource(Map<String, Object> params, HttpServletRequest request) {
|
||||
|
||||
|
|
@ -33,13 +68,13 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
String keyField = (String) params.get("keyField");
|
||||
switch (keyField) {
|
||||
case "workcode":
|
||||
params.put("keyField","work_code");
|
||||
params.put("keyField", "work_code");
|
||||
break;
|
||||
case "lastname":
|
||||
params.put("keyField","last_name");
|
||||
params.put("keyField", "last_name");
|
||||
break;
|
||||
case "loginid":
|
||||
params.put("keyField","login_id");
|
||||
params.put("keyField", "login_id");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -102,4 +137,395 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
returnMap.put("pid", request.getSession(true).getAttribute("importExcelPid"));
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getImportFields(String importType) {
|
||||
String extendType = "";
|
||||
String tableName = "";
|
||||
String errorMsg = "";
|
||||
List<String> exculdeFields = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(importType)) {
|
||||
switch (importType) {
|
||||
case "company":
|
||||
extendType = "1";
|
||||
tableName = "JCL_ORG_COMP";
|
||||
exculdeFields.add("parent_company");
|
||||
break;
|
||||
case "department":
|
||||
extendType = "2";
|
||||
tableName = "JCL_ORG_DEPT";
|
||||
break;
|
||||
case "jobtitles":
|
||||
extendType = "3";
|
||||
tableName = "JCL_ORG_JOB";
|
||||
break;
|
||||
case "resource":
|
||||
// TODO
|
||||
break;
|
||||
default:
|
||||
errorMsg = "未找到对应的导入类型,请确认";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
errorMsg = "请选择导入类型";
|
||||
}
|
||||
OrganizationAssert.isBlank(errorMsg, errorMsg);
|
||||
Map<String, Object> returnMaps = new HashMap<>();
|
||||
if (StringUtils.isAnyEmpty(extendType, tableName)) {
|
||||
return returnMaps;
|
||||
}
|
||||
List<ExtendInfoPO> infoPOList = getExtendInfoMapper().listFields(extendType, "", tableName, "");
|
||||
List<JSONObject> fieldDatas = infoPOList.stream().filter(item -> !exculdeFields.contains(item.getFieldName())).map(item -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", item.getId());
|
||||
jsonObject.put("name", item.getFieldNameDesc());
|
||||
return jsonObject;
|
||||
}).collect(Collectors.toList());
|
||||
List<Long> selectedKeys = infoPOList.stream().filter(item -> 0 == item.getIsSystemDefault()).map(ExtendInfoPO::getId).collect(Collectors.toList());
|
||||
returnMaps.put("data", fieldDatas);
|
||||
returnMaps.put("selectedKeys", selectedKeys);
|
||||
return returnMaps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getImportForm(String importType, String ids) {
|
||||
Map<String, Object> returnMap = new HashMap<>();
|
||||
try {
|
||||
if (StringUtils.isNotBlank(importType)) {
|
||||
switch (importType) {
|
||||
case "company":
|
||||
returnMap.put("condition", getCompanyImportForm(ids));
|
||||
break;
|
||||
case "department":
|
||||
break;
|
||||
case "jobtitles":
|
||||
break;
|
||||
case "resource":
|
||||
// TODO
|
||||
break;
|
||||
default:
|
||||
returnMap.put("status", "-1");
|
||||
returnMap.put("message", "请选择合适的导入类型");
|
||||
return returnMap;
|
||||
}
|
||||
}
|
||||
returnMap.put("status", "1");
|
||||
} catch (IOException e) {
|
||||
returnMap.put("status", "-1");
|
||||
returnMap.put("message", "导入模板生成异常");
|
||||
new BaseBean().writeLog(e);
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> saveImport(Map<String, Object> params) {
|
||||
String importType = (String) params.get("importType");
|
||||
String operateType = (String) params.get("operateType");
|
||||
String excelfile = (String) params.get("excelfile");
|
||||
if (StringUtils.isNotBlank(importType)) {
|
||||
switch (importType) {
|
||||
case "company":
|
||||
companyImport(operateType, excelfile, 1L);
|
||||
break;
|
||||
case "department":
|
||||
break;
|
||||
case "jobtitles":
|
||||
break;
|
||||
case "resource":
|
||||
// TODO
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分部导入表单
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private List<Object> getCompanyImportForm(String ids) throws IOException {
|
||||
// 根据选择字段、生成对应的导入模板
|
||||
List<ExtendInfoPO> extendInfosByIds = getExtendInfoMapper().getExtendInfosByIds(DeleteParam.builder().ids(ids).build().getIds());
|
||||
List<Object> fieldList = extendInfosByIds.stream().map(ExtendInfoPO::getFieldNameDesc).collect(Collectors.toList());
|
||||
List<List<Object>> excelSheetData = new ArrayList<>();
|
||||
excelSheetData.add(fieldList);
|
||||
String sheetName = "company";
|
||||
String outPutPath = GCONST.getRootPath() + "hrm" + File.separator + "import" + File.separator + "templet" + File.separator + user.getUID();
|
||||
XSSFWorkbook sheets = ExcelUtil.genWorkbookV2(excelSheetData, sheetName);
|
||||
String excelPath = outPutPath + File.separator + sheetName + ".xls";
|
||||
File excelPathFile = new File(excelPath);
|
||||
if (!excelPathFile.exists()) {
|
||||
String substring = excelPath.substring(0, excelPath.lastIndexOf(File.separator));
|
||||
File file = new File(substring);
|
||||
file.mkdirs();
|
||||
excelPathFile.createNewFile();
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream(excelPathFile);
|
||||
sheets.write(out);
|
||||
excelPath = "/hrm/import/templet/" + user.getUID() + "/company.xls";
|
||||
|
||||
// 返回导入数据
|
||||
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(excelPath);
|
||||
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, weaver.general.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", excelPath);
|
||||
}
|
||||
item.put("value", value);
|
||||
itemList.add(item);
|
||||
}
|
||||
groupItem.put("items", itemList);
|
||||
lsGroup.add(groupItem);
|
||||
return lsGroup;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导入分部
|
||||
*
|
||||
* @param operateType
|
||||
* @param excelFile
|
||||
*/
|
||||
private void companyImport(String operateType, String excelFile, Long extendType) {
|
||||
try {
|
||||
ImageFileManager manager = new ImageFileManager();
|
||||
manager.getImageFileInfoById(Util.getIntValue(excelFile));
|
||||
HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(manager.getInputStream()));
|
||||
// 当前sheet
|
||||
HSSFSheet sheetAt = workbook.getSheetAt(0);
|
||||
int lastRow = sheetAt.getLastRowNum();
|
||||
List<ExtendInfoPO> extendInfoPOS = new ArrayList<>();
|
||||
List<String> errMsg = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i <= lastRow; i++) {
|
||||
HSSFRow row = sheetAt.getRow(i);
|
||||
// 组装待处理数据
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
nextRow:
|
||||
for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) {
|
||||
HSSFCell cell = row.getCell((short) cellIndex);
|
||||
if (cell == null) {
|
||||
continue;
|
||||
}
|
||||
String cellValue = getCellValue(cell).trim();
|
||||
if (i == 0) {
|
||||
// 首行 初始化字段信息
|
||||
ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByGroupAndLabelName(extendType, cellValue);
|
||||
extendInfoPOS.add(extendInfoPO);
|
||||
} else {
|
||||
ExtendInfoPO infoPO = extendInfoPOS.get(cellIndex);
|
||||
if ("comp_name".equals(infoPO.getFieldName())) {
|
||||
String[] split = cellValue.split(">");
|
||||
Long parentCompanyId = null;
|
||||
if (split.length > 1) {
|
||||
if (split.length > 8) {
|
||||
// TODO 记录日志
|
||||
errMsg.add("分部层级不能大于10");
|
||||
break nextRow;
|
||||
}
|
||||
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 记录日志
|
||||
errMsg.add(split[index] + ":未找到对应数据");
|
||||
break nextRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put("parent_company", parentCompanyId);
|
||||
map.put("comp_name", split[split.length - 1]);
|
||||
}
|
||||
// 数据校验
|
||||
if (infoPO.getIsrequired() == 1 && StringUtils.isBlank(cellValue)) {
|
||||
// TODO 记录日志
|
||||
errMsg.add(infoPO.getFieldNameDesc() + "为必填项");
|
||||
break nextRow;
|
||||
}
|
||||
|
||||
Object reallyValue = getReallyValue(infoPO, cellValue);
|
||||
if (StringUtils.isNotBlank(cellValue) && StringUtils.isBlank((String) reallyValue)) {
|
||||
// TODO 记录日志
|
||||
errMsg.add(infoPO.getFieldNameDesc() + "数据转换失败,未找到对应数据");
|
||||
break nextRow;
|
||||
}
|
||||
map.put(infoPO.getFieldName(), reallyValue);
|
||||
// TODO 自动编号
|
||||
if ("add".equals(operateType)) {
|
||||
MapperProxyFactory.getProxy(ExtMapper.class).insertExt(ExtendInfoParams.builder().tableName("JCL_ORG_COMP").params(map).build());
|
||||
} else if ("update".equals(operateType)) {
|
||||
String compNo = (String) map.get("comp_no");
|
||||
// 查询对应ID
|
||||
if (StringUtils.isNotBlank(compNo)) {
|
||||
List<CompPO> compPOS = MapperProxyFactory.getProxy(CompMapper.class).listByNo(compNo);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 校验、数据交互
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getCellValue(HSSFCell cell) {
|
||||
String cellValue = "";
|
||||
if (cell == null)
|
||||
return "";
|
||||
switch (cell.getCellType()) {
|
||||
case BOOLEAN: // 得到Boolean对象的方法
|
||||
cellValue = String.valueOf(cell.getBooleanCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
if (HSSFDateUtil.isCellDateFormatted(cell)) {// 先看是否是日期格式
|
||||
SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd");
|
||||
cellValue = String.valueOf(sft.format(cell.getDateCellValue())); // 读取日期格式
|
||||
} else {
|
||||
cellValue = String.valueOf(new Double(cell.getNumericCellValue())); // 读取数字
|
||||
if (cellValue.endsWith(".0"))
|
||||
cellValue = cellValue.substring(0, cellValue.indexOf("."));
|
||||
}
|
||||
break;
|
||||
case FORMULA: // 读取公式
|
||||
cellValue = cell.getCellFormula();
|
||||
break;
|
||||
case STRING: // 读取String
|
||||
cellValue = cell.getStringCellValue();
|
||||
break;
|
||||
}
|
||||
cellValue = Util.toHtmlForHrm(cellValue);
|
||||
return cellValue;
|
||||
}
|
||||
|
||||
private Object getReallyValue(ExtendInfoPO extendInfo, String cellValue) throws JSONException {
|
||||
Object object = null;
|
||||
JSONArray jsonArray = JSONObject.parseArray(extendInfo.getCustomValue());
|
||||
switch (extendInfo.getControlType()) {
|
||||
case 1:
|
||||
String valueType = (String) jsonArray.get(1);
|
||||
// INPUT
|
||||
if ("int".equals(valueType)) {
|
||||
object = Integer.parseInt(cellValue);
|
||||
} else if ("float".equals(valueType)) {
|
||||
object = Float.parseFloat(cellValue);
|
||||
} else {
|
||||
object = cellValue;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// BROWSER
|
||||
org.json.JSONObject jsonObject = new org.json.JSONObject();
|
||||
jsonObject.put("fieldhtmltype", extendInfo.getControlType());
|
||||
jsonObject.put("type", extendInfo.getBrowserType());
|
||||
jsonObject.put("fieldvalue", cellValue);
|
||||
jsonObject.put("dmlurl", SelectOptionParam.getCustomBrowserId(extendInfo.getCustomValue()));
|
||||
|
||||
break;
|
||||
case 5:
|
||||
// SELECT
|
||||
JSONObject o = (JSONObject) jsonArray.get(2);
|
||||
JSONArray datas = o.getJSONArray("datas");
|
||||
List<FieldSelectOptionBean> options = datas.toJavaList(FieldSelectOptionBean.class);
|
||||
Map<String, String> optionMap = options.stream().collect(Collectors.toMap(FieldSelectOptionBean::getOption, FieldSelectOptionBean::getId, (k1, k2) -> k1));
|
||||
object = optionMap.get(cellValue);
|
||||
break;
|
||||
case 4:// CHECKBOX
|
||||
case 6:
|
||||
// FILEUPLOAD
|
||||
break;
|
||||
case 7:// TEXT
|
||||
case 2:// TEXTAREA
|
||||
default:
|
||||
object = cellValue;
|
||||
break;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验重复编号
|
||||
*
|
||||
* @param no
|
||||
* @param tableName
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
private boolean checkRepeatNo(String no, String tableName, Long id) {
|
||||
if (StringUtils.isBlank(no)) {
|
||||
return true;
|
||||
}
|
||||
if (StringUtils.isNotBlank(tableName)) {
|
||||
switch (tableName) {
|
||||
case "JCL_ORG_COMP":
|
||||
return 0 == MapperProxyFactory.getProxy(CompMapper.class).checkRepeatNo(no, id);
|
||||
case "JCL_ORG_DEPT":
|
||||
case "JCL_ORG_JOB":
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import weaver.hrm.User;
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
|
@ -36,7 +37,38 @@ public class ImportCommonController {
|
|||
Map<String, Object> map = ParamUtil.request2Map(request);
|
||||
return ReturnResult.successed(getImportCommonWrapper(user).saveImportResource(map, request));
|
||||
} catch (Exception e) {
|
||||
return ReturnResult.exceptionHandle(e);
|
||||
return ReturnResult.exceptionHandle(e);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/getImportFields")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ReturnResult getImportFields(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
try {
|
||||
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
Map<String, Object> map = ParamUtil.request2Map(request);
|
||||
String importType = (String) map.get("importType");
|
||||
return ReturnResult.successed(getImportCommonWrapper(user).getImportFields(importType));
|
||||
} catch (Exception e) {
|
||||
return ReturnResult.exceptionHandle(e);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/getImportForm")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ReturnResult getImportForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
try {
|
||||
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
Map<String, Object> map = ParamUtil.request2Map(request);
|
||||
String importType = (String) map.get("importType");
|
||||
String ids = (String) map.get("ids");
|
||||
return ReturnResult.successed(getImportCommonWrapper(user).getImportForm(importType, ids));
|
||||
} catch (Exception e) {
|
||||
return ReturnResult.exceptionHandle(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,4 +23,25 @@ public class ImportCommonWrapper extends Service {
|
|||
public Map<String, Object> saveImportResource(Map<String, Object> params, HttpServletRequest request) {
|
||||
return getImportCommonService(user).saveImportResource(params, request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 选择导入字段
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getImportFields(String importType) {
|
||||
return getImportCommonService(user).getImportFields(importType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导入表单
|
||||
*
|
||||
* @param importType
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getImportForm(String importType, String ids) {
|
||||
return getImportCommonService(user).getImportForm(importType, ids);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue