diff --git a/src/com/engine/organization/entity/hrmresource/param/HrmResourceImportParam.java b/src/com/engine/organization/entity/hrmresource/param/HrmResourceImportParam.java index ea110eaf..9beb4967 100644 --- a/src/com/engine/organization/entity/hrmresource/param/HrmResourceImportParam.java +++ b/src/com/engine/organization/entity/hrmresource/param/HrmResourceImportParam.java @@ -327,9 +327,9 @@ public class HrmResourceImportParam { */ private String company_work_year; - private String baseFieldsValue=""; + private String baseFieldsValue; - private String baseFields=""; + private String baseFields; private Long creator; private int deleteType; diff --git a/src/com/engine/organization/entity/hrmresource/po/HrmResourcePO.java b/src/com/engine/organization/entity/hrmresource/po/HrmResourcePO.java index 3245bc2c..f67244fe 100644 --- a/src/com/engine/organization/entity/hrmresource/po/HrmResourcePO.java +++ b/src/com/engine/organization/entity/hrmresource/po/HrmResourcePO.java @@ -328,8 +328,8 @@ public class HrmResourcePO { private String companyWorkYear; - private String baseFieldsValue=""; + private String baseFieldsValue; - private String baseFields=""; + private String baseFields; } diff --git a/src/com/engine/organization/entity/jclimport/po/CusFormFieldPO.java b/src/com/engine/organization/entity/jclimport/po/CusFormFieldPO.java new file mode 100644 index 00000000..691c02d0 --- /dev/null +++ b/src/com/engine/organization/entity/jclimport/po/CusFormFieldPO.java @@ -0,0 +1,35 @@ +package com.engine.organization.entity.jclimport.po; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2022/07/28 + * @version: 1.0 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CusFormFieldPO { + private String fieldLabel; + private Long fieldId; + private String fieldName; + private String required; + /** + * 控件类型 + */ + private Integer fieldHtmlType; + /** + * 控件详细标识 + */ + private String type; + /** + * 自定义标识 + */ + private String dmlUrl; + private String tableName; +} diff --git a/src/com/engine/organization/entity/jclimport/po/JclSelectItem.java b/src/com/engine/organization/entity/jclimport/po/JclSelectItem.java new file mode 100644 index 00000000..0f26d013 --- /dev/null +++ b/src/com/engine/organization/entity/jclimport/po/JclSelectItem.java @@ -0,0 +1,21 @@ +package com.engine.organization.entity.jclimport.po; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2022/07/28 + * @version: 1.0 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class JclSelectItem { + private Long fieldId; + private String selectValue; + private String selectName; +} diff --git a/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.java b/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.java index 6e6e0e54..4db1254e 100644 --- a/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.java +++ b/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.java @@ -2,6 +2,8 @@ package com.engine.organization.mapper.hrmresource; import com.alibaba.fastjson.JSONObject; +import com.engine.organization.entity.jclimport.po.CusFormFieldPO; +import com.engine.organization.entity.jclimport.po.JclSelectItem; import org.apache.ibatis.annotations.Param; import java.util.Collection; @@ -49,4 +51,18 @@ public interface SystemDataMapper { */ int updateResourceJobTitleByIds(@Param("jobTitle") String jobTitle, @Param("ids") Collection ids); + /** + * 人员,hrmResource表字段 + * + * @return + */ + List getHrmFieldBeanList(); + + List getHrmFieldBeanListByFields(@Param("fields") Collection fields); + + List getHrmCustomFieldList(); + + List getSelectItems(@Param("tableName") String tableName, @Param("fieldId") Long fieldId); + + } diff --git a/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.xml b/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.xml index 4af54879..232388a8 100644 --- a/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.xml +++ b/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.xml @@ -1,6 +1,24 @@ + + + + + + + + + + + + + + + + + + update hrmresource set JOBTITLE = #{jobTitle} where id in @@ -75,6 +93,54 @@ where departmentid = #{departmentId} And jobTitle = #{jobTitle} + + + + \ No newline at end of file diff --git a/src/com/engine/organization/mapper/jclimport/JclImportHistoryMapper.java b/src/com/engine/organization/mapper/jclimport/JclImportHistoryMapper.java index b408d291..12ccab56 100644 --- a/src/com/engine/organization/mapper/jclimport/JclImportHistoryMapper.java +++ b/src/com/engine/organization/mapper/jclimport/JclImportHistoryMapper.java @@ -1,6 +1,7 @@ package com.engine.organization.mapper.jclimport; import com.engine.organization.entity.jclimport.po.JclImportHistoryPO; +import org.apache.ibatis.annotations.Param; /** * @author:dxfeng @@ -10,4 +11,8 @@ import com.engine.organization.entity.jclimport.po.JclImportHistoryPO; public interface JclImportHistoryMapper { int insertHistory(JclImportHistoryPO historyPO); + + int updateHistoryStatus(@Param("pId") Long pId, @Param("status") String status); + + } diff --git a/src/com/engine/organization/mapper/jclimport/JclImportHistoryMapper.xml b/src/com/engine/organization/mapper/jclimport/JclImportHistoryMapper.xml index 81092634..05e88c63 100644 --- a/src/com/engine/organization/mapper/jclimport/JclImportHistoryMapper.xml +++ b/src/com/engine/organization/mapper/jclimport/JclImportHistoryMapper.xml @@ -14,7 +14,9 @@ - t.id + t + . + id , t.operator , t.operate_time , t.client_address @@ -23,7 +25,8 @@ , t.operate_type , t.status - INSERT INTO jcl_import_history @@ -74,4 +77,9 @@ + + update jcl_import_history + set status = #{status} + where id = #{pId} + \ No newline at end of file diff --git a/src/com/engine/organization/service/ImportCommonService.java b/src/com/engine/organization/service/ImportCommonService.java index 7fe7680e..5845a34f 100644 --- a/src/com/engine/organization/service/ImportCommonService.java +++ b/src/com/engine/organization/service/ImportCommonService.java @@ -53,7 +53,7 @@ public interface ImportCommonService { * @param params * @return */ - Map saveImport(Map params); + Map saveImport(Map params,HttpServletRequest request); /** * 导入日志详情列表 diff --git a/src/com/engine/organization/service/impl/ImportCommonServiceImpl.java b/src/com/engine/organization/service/impl/ImportCommonServiceImpl.java index e7b6c226..c2f8f660 100644 --- a/src/com/engine/organization/service/impl/ImportCommonServiceImpl.java +++ b/src/com/engine/organization/service/impl/ImportCommonServiceImpl.java @@ -15,6 +15,7 @@ import com.engine.organization.entity.extend.param.ExtendInfoParams; import com.engine.organization.entity.extend.po.ExtendInfoPO; import com.engine.organization.entity.fieldset.param.FieldTypeTreeParam; import com.engine.organization.entity.hrmresource.param.HrmResourceImportParam; +import com.engine.organization.entity.jclimport.po.CusFormFieldPO; import com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO; import com.engine.organization.entity.jclimport.po.JclImportHistoryPO; import com.engine.organization.entity.jclimport.vo.JclImportHistoryDetailVO; @@ -24,6 +25,7 @@ import com.engine.organization.mapper.comp.CompMapper; import com.engine.organization.mapper.department.DepartmentMapper; import com.engine.organization.mapper.extend.ExtMapper; import com.engine.organization.mapper.extend.ExtendInfoMapper; +import com.engine.organization.mapper.hrmresource.SystemDataMapper; import com.engine.organization.mapper.jclimport.JclImportHistoryDetailMapper; import com.engine.organization.mapper.jclimport.JclImportHistoryMapper; import com.engine.organization.mapper.job.JobMapper; @@ -36,6 +38,8 @@ import com.engine.organization.util.relation.EcHrmRelationUtil; import com.engine.organization.util.saveimport.HrmResourceImportAdaptUtil; import com.engine.organization.util.saveimport.HrmResourceImportProcessUtil; import com.engine.organization.util.saveimport.SaveImportProcessUtil; +import com.engine.organization.util.saveimport.hrmimport.HrmImportAdaptExcelE9; +import com.engine.organization.util.saveimport.hrmimport.HrmImportProcessE9; import org.apache.commons.lang3.StringUtils; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.xssf.usermodel.XSSFCell; @@ -50,6 +54,7 @@ import weaver.general.GCONST; import weaver.general.Util; import weaver.hrm.User; import weaver.hrm.definedfield.HrmFieldManager; +import weaver.join.hrm.in.HrmResourceVo; import weaver.systeminfo.SystemEnv; import javax.servlet.http.HttpServletRequest; @@ -66,12 +71,22 @@ import java.util.stream.Collectors; * @version: 1.0 */ public class ImportCommonServiceImpl extends Service implements ImportCommonService { + /** + * extend_group + */ + private static final Long COMPANY_TYPE = 1L; + private static final Long DEPARTMENT_TYPE = 1L; + private static final Long JOB_TYPE = 1L; private ExtendInfoMapper getExtendInfoMapper() { return MapperProxyFactory.getProxy(ExtendInfoMapper.class); } + private SystemDataMapper getSystemDataMapper() { + return MapperProxyFactory.getProxy(SystemDataMapper.class); + } + @Override public Map saveImportResource(Map params, HttpServletRequest request) { @@ -156,26 +171,28 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ String extendType = ""; String tableName = ""; String errorMsg = ""; - List exculdeFields = new ArrayList<>(); + List excludeFields = new ArrayList<>(); + Map returnMaps = new HashMap<>(); if (StringUtils.isNotBlank(importType)) { switch (importType) { case "company": extendType = "1"; tableName = "JCL_ORG_COMP"; - exculdeFields.add("parent_company"); + excludeFields.add("parent_company"); break; case "department": extendType = "2"; - exculdeFields.add("parent_dept"); tableName = "JCL_ORG_DEPT"; + excludeFields.add("parent_dept"); break; case "jobtitle": extendType = "3"; - exculdeFields.add("parent_job"); tableName = "JCL_ORG_JOB"; + excludeFields.add("parent_job"); break; case "resource": - // TODO + extendType = "4"; + tableName = "hrmResource"; break; default: errorMsg = "未找到对应的导入类型,请确认"; @@ -185,16 +202,45 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ errorMsg = "请选择导入类型"; } OrganizationAssert.isBlank(errorMsg, errorMsg); - Map returnMaps = new HashMap<>(); if (StringUtils.isAnyEmpty(extendType, tableName)) { return returnMaps; } - List infoPOList = getExtendInfoMapper().listFields(extendType, "", tableName, "", "1"); - List filterList = infoPOList.stream().filter(item -> !exculdeFields.contains(item.getFieldName()) && 6 != item.getControlType()).collect(Collectors.toList()); - List fieldDatas = filterList.stream().map(item -> FieldTypeTreeParam.builder().id(item.getId()).name(item.getFieldNameDesc()).build()).collect(Collectors.toList()); - List selectedKeys = filterList.stream().filter(item -> (0 == item.getIsSystemDefault()) && 1 == item.getIsrequired()).map(ExtendInfoPO::getId).collect(Collectors.toList()); - returnMaps.put("data", fieldDatas); - returnMaps.put("selectedKeys", selectedKeys); + if ("4".equals(extendType)) { + String voField = "subcompanyid1,departmentid," + + "workcode,lastname,loginid,password,seclevel,sex," + + "jobtitle,jobactivity,jobgroupid,jobcall,joblevel," + + "jobactivitydesc,managerid,assistantid,status," + + "workroom,locationid,telephone,mobile,mobilecall," + + "fax,email,systemlanguage,birthday,folk," + + "nativeplace,regresidentplace,certificatenum," + + "maritalstatus,policy,bememberdate,bepartydate," + + "islabouunion,educationlevel,degree,healthinfo,height," + + "weight,usekind,startdate,enddate,probationenddate," + + "residentplace,homeaddress,tempresidentnumber," + + "companystartdate,workstartdate," + + "accumfundaccount,accounttype,belongto,height,weight,accountname,bankid1,accountid1," + + "telephone,dsporder,classification"; + Collection hrmFields = Arrays.asList(voField.split(",")); + // 获取人员表单字段 + List hrmFieldBeanList = getSystemDataMapper().getHrmFieldBeanListByFields(hrmFields); + List customFieldList = getSystemDataMapper().getHrmCustomFieldList(); + List mergeList = new ArrayList<>(); + mergeList.addAll(hrmFieldBeanList); + mergeList.addAll(customFieldList); + + List fieldDatas = mergeList.stream().map(item -> FieldTypeTreeParam.builder().id(item.getFieldId()).name(item.getFieldLabel()).build()).collect(Collectors.toList()); + List selectedKeys = mergeList.stream().filter(item -> ("1".equals(item.getRequired()) || "hrmresource".equals(item.getTableName()))).map(CusFormFieldPO::getFieldId).collect(Collectors.toList()); + + returnMaps.put("data", fieldDatas); + returnMaps.put("selectedKeys", selectedKeys); + } else { + List infoPOList = getExtendInfoMapper().listFields(extendType, "", tableName, "", "1"); + List filterList = infoPOList.stream().filter(item -> !excludeFields.contains(item.getFieldName()) && 6 != item.getControlType()).collect(Collectors.toList()); + List fieldDatas = filterList.stream().map(item -> FieldTypeTreeParam.builder().id(item.getId()).name(item.getFieldNameDesc()).build()).collect(Collectors.toList()); + List selectedKeys = filterList.stream().filter(item -> (0 == item.getIsSystemDefault()) && 1 == item.getIsrequired()).map(ExtendInfoPO::getId).collect(Collectors.toList()); + returnMaps.put("data", fieldDatas); + returnMaps.put("selectedKeys", selectedKeys); + } return returnMaps; } @@ -216,6 +262,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ break; case "resource": // TODO + returnMap.put("condition", getResourceImportForm(templatePath)); break; default: returnMap.put("status", "-1"); @@ -233,7 +280,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ } @Override - public Map saveImport(Map params) { + public Map saveImport(Map params, HttpServletRequest request) { String importType = (String) params.get("importType"); String operateType = (String) params.get("operateType"); String excelFile = (String) params.get("excelfile"); @@ -241,16 +288,41 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ if (StringUtils.isNotBlank(importType)) { switch (importType) { case "company": - returnMap.put("pId", companyImport(operateType, excelFile, 1L)); + returnMap.put("pId", companyImport(operateType, excelFile)); break; case "department": - returnMap.put("pId", departmentImport(operateType, excelFile, 2L)); + returnMap.put("pId", departmentImport(operateType, excelFile)); break; case "jobtitle": - returnMap.put("pId", jobImport(operateType, excelFile, 3L)); + returnMap.put("pId", jobImport(operateType, excelFile)); break; case "resource": // TODO + List lsErrorInfo = new ArrayList<>(); + HrmImportAdaptExcelE9 importAdapt = new HrmImportAdaptExcelE9(); + FileUploadToPath fu = new FileUploadToPath(request); + + List errorInfo = importAdapt.creatImportMap(fu); + + //如果读取数据和验证模板没有发生错误 + if (errorInfo.isEmpty()) { + Map hrMap = importAdapt.getHrmImportMap(); + + HrmImportProcessE9 importProcess = new HrmImportProcessE9(); + // TODO 日志记录 + Map map = importProcess.init(request); + int pId = Util.getIntValue(Util.null2String(map.get("pId"))); + returnMap.put("pId", pId); + + importProcess.processMap(hrMap); + } else { + Map error; + for (int i = 0; i < errorInfo.size(); i++) { + error = new HashMap<>(); + error.put("message", Util.null2String(errorInfo.get(i))); + lsErrorInfo.add(error); + } + } break; default: break; @@ -458,11 +530,88 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ return lsGroup; } + private List getResourceImportForm(String templatePath) throws IOException { + + // 返回导入数据 + List lsGroup = new ArrayList<>(); + Map groupItem = new HashMap<>(); + List itemList = new ArrayList<>(); + + groupItem.put("title", SystemEnv.getHtmlLabelName(1361, user.getLanguage())); + groupItem.put("defaultshow", true); + + SearchConditionItem searchConditionItem; + ConditionFactory conditionFactory = new ConditionFactory(user); + + //重复验证字段 + List statusOptions = new ArrayList(); + statusOptions.add(new SearchConditionOption("workcode", SystemEnv.getHtmlLabelName(714, user.getLanguage()), true)); + statusOptions.add(new SearchConditionOption("loginid", SystemEnv.getHtmlLabelName(412, user.getLanguage()))); + statusOptions.add(new SearchConditionOption("lastname", SystemEnv.getHtmlLabelName(413, user.getLanguage()))); + searchConditionItem = conditionFactory.createCondition(ConditionType.SELECT, 24638, "keyField", statusOptions); + searchConditionItem.setValue("workcode"); + itemList.add(searchConditionItem); + + //导入类型 + List statusOptions1 = new ArrayList(); + statusOptions1.add(new SearchConditionOption("add", SystemEnv.getHtmlLabelName(611, user.getLanguage()), true)); + statusOptions1.add(new SearchConditionOption("update", SystemEnv.getHtmlLabelName(17744, user.getLanguage()))); + searchConditionItem = conditionFactory.createCondition(ConditionType.SELECT, 24863, "importType", statusOptions1); + 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 lsPromptLabel = new ArrayList<>(); //提示信息 + lsPromptLabel.add(128520); + lsPromptLabel.add(125868); + lsPromptLabel.add(128365); + lsPromptLabel.add(81697); + lsPromptLabel.add(81698); + lsPromptLabel.add(81699); + lsPromptLabel.add(516263); + lsPromptLabel.add(81701); + lsPromptLabel.add(388880); + lsPromptLabel.add(81702); + lsPromptLabel.add(81703); + lsPromptLabel.add(125869); + + for (int i = 0; i < lsPromptLabel.size(); i++) { + Map 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 Long companyImport(String operateType, String excelFile, Long extendType) { + private Long companyImport(String operateType, String excelFile) { Long importHistoryId = saveImportLog("company", operateType); JclImportHistoryDetailPO historyDetailPO; @@ -501,7 +650,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ String cellValue = getCellValue(cell).trim(); if (i == 0) { // 首行 初始化字段信息 - ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByExtendAndLabelName(extendType, cellValue); + ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByExtendAndLabelName(COMPANY_TYPE, cellValue); extendInfoPOS.add(extendInfoPO); } else { ExtendInfoPO infoPO = extendInfoPOS.get(cellIndex); @@ -593,7 +742,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ historyDetailPO.setStatus("0"); saveImportDetailLog(historyDetailPO); } - if (checkRepeatNo(compNo, extendType, companyId)) { + if (checkRepeatNo(compNo, COMPANY_TYPE, companyId)) { map.put("update_time", new Date()); MapperProxyFactory.getProxy(ExtMapper.class).updateExt(ExtendInfoParams.builder().id(companyId).tableName("JCL_ORG_COMP").params(map).build()); map.put("id", companyId); @@ -618,13 +767,8 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ /** * 导入部门 - * - * @param operateType - * @param excelFile - * @param extendType - * @return */ - private Long departmentImport(String operateType, String excelFile, Long extendType) { + private Long departmentImport(String operateType, String excelFile) { Long importHistoryId = saveImportLog("department", operateType); JclImportHistoryDetailPO historyDetailPO; @@ -664,7 +808,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ String cellValue = getCellValue(cell).trim(); if (i == 0) { // 首行 初始化字段信息 - ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByExtendAndLabelName(extendType, cellValue); + ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByExtendAndLabelName(DEPARTMENT_TYPE, cellValue); extendInfoPOS.add(extendInfoPO); } else { ExtendInfoPO infoPO = extendInfoPOS.get(cellIndex); @@ -785,7 +929,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ historyDetailPO.setStatus("0"); saveImportDetailLog(historyDetailPO); } - if (checkRepeatNo(deptNo, extendType, departmentId)) { + if (checkRepeatNo(deptNo, DEPARTMENT_TYPE, departmentId)) { map.put("update_time", new Date()); MapperProxyFactory.getProxy(ExtMapper.class).updateExt(ExtendInfoParams.builder().id(departmentId).tableName("JCL_ORG_DEPT").params(map).build()); map.put("id", departmentId); @@ -810,13 +954,8 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ /** * 岗位导入 - * - * @param operateType - * @param excelFile - * @param extendType - * @return */ - private Long jobImport(String operateType, String excelFile, Long extendType) { + private Long jobImport(String operateType, String excelFile) { Long importHistoryId = saveImportLog("jobtitle", operateType); JclImportHistoryDetailPO historyDetailPO; @@ -857,7 +996,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ String cellValue = getCellValue(cell).trim(); if (i == 0) { // 首行 初始化字段信息 - ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByExtendAndLabelName(extendType, cellValue); + ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByExtendAndLabelName(JOB_TYPE, cellValue); extendInfoPOS.add(extendInfoPO); } else { ExtendInfoPO infoPO = extendInfoPOS.get(cellIndex); @@ -955,8 +1094,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ } } } - - // TODO map.put("parent_comp", parentCompanyId); map.put("parent_dept", parentDepartmentId); map.put("ec_company", EcHrmRelationUtil.getEcCompanyId(parentCompanyId + "")); @@ -1009,7 +1146,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ historyDetailPO.setStatus("0"); saveImportDetailLog(historyDetailPO); } - if (checkRepeatNo(jobNo, extendType, jobId)) { + if (checkRepeatNo(jobNo, JOB_TYPE, jobId)) { map.put("update_time", new Date()); MapperProxyFactory.getProxy(ExtMapper.class).updateExt(ExtendInfoParams.builder().id(jobId).tableName("JCL_ORG_JOB").params(map).build()); map.put("jobactivityid", JobServiceImpl.JOB_ACTIVITY_ID); @@ -1034,11 +1171,10 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ } + + /** * 读取表格文本内容 - * - * @param cell - * @return */ private String getCellValue(XSSFCell cell) { String cellValue = ""; @@ -1071,11 +1207,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ /** * 转换存入数据库的值 - * - * @param extendInfo - * @param cellValue - * @return - * @throws Exception */ private Object getReallyValue(ExtendInfoPO extendInfo, String cellValue) throws Exception { if (StringUtils.isBlank(cellValue)) { @@ -1132,11 +1263,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ /** * 校验重复编号 - * - * @param no - * @param extendType - * @param id - * @return */ private boolean checkRepeatNo(String no, Long extendType, Long id) { if (StringUtils.isBlank(no)) { @@ -1159,8 +1285,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ /** * 生成记录日志 - * - * @return */ private Long saveImportLog(String importType, String operateType) { JclImportHistoryPO historyPO = JclImportHistoryPO.builder().operator((long) user.getUID()).operateTime(DateUtil.getFullDate()).clientAddress(user.getLoginip()).importType(importType).sourceFrom("excel").operateType(operateType).status("importing").build(); @@ -1170,8 +1294,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ /** * 日志导入详细信息日志 - * - * @param historyDetailPO */ private void saveImportDetailLog(JclImportHistoryDetailPO historyDetailPO) { String detailMsg = "导入第" + historyDetailPO.getRowNums() + "行数据,[" + historyDetailPO.getRelatedName() + "]" + historyDetailPO.getOperateDetail(); @@ -1181,16 +1303,39 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ /** * 生成导入模板文件 - * - * @param importType - * @param columns - * @return - * @throws IOException */ private String getTemplatePath(String importType, String columns) throws IOException { // 根据选择字段、生成对应的导入模板 String[] split = columns.split(","); - List columnList = Arrays.asList(split); + List columnList = new ArrayList<>(Arrays.asList(split)); + Object companyColumn = ""; + Object departmentColumn = ""; + // 排序 + /* + 第一列:所属分部 + 第二列:所属部门\上级部门\部门 + */ + Iterator iterator = columnList.iterator(); + while (iterator.hasNext()) { + Object column = iterator.next(); + if ("所属分部".equals(column.toString())) { + companyColumn = column; + iterator.remove(); + } + + if ("所属部门".equals(column) || "上级部门".equals(column) || "部门".equals(column)) { + departmentColumn = column; + iterator.remove(); + } + } + if (StringUtils.isNotBlank(departmentColumn.toString())) { + columnList.add(0, departmentColumn); + } + + if (StringUtils.isNotBlank(companyColumn.toString())) { + columnList.add(0, companyColumn); + } + List> excelSheetData = new ArrayList<>(); excelSheetData.add(columnList); String outPutPath = GCONST.getRootPath() + "hrm" + File.separator + "import" + File.separator + "template" + File.separator + user.getUID(); diff --git a/src/com/engine/organization/util/saveimport/hrmimport/HrmImportAdaptExcelE9.java b/src/com/engine/organization/util/saveimport/hrmimport/HrmImportAdaptExcelE9.java new file mode 100644 index 00000000..bb4d36a9 --- /dev/null +++ b/src/com/engine/organization/util/saveimport/hrmimport/HrmImportAdaptExcelE9.java @@ -0,0 +1,1288 @@ +/** + * Title: Excel人员导入适配器a + * Company: 泛微软件 + * + * @author: 冯拥兵 + * @version: 1.0 + * create date : 2010-6-2 + * modify log: + *

+ * Description: 对Excel人员导入模板进行验证和数据解析,形成人员数据Map集合 + * Excel读取方案,通过初始化字段,形成标准的导入字段列名数组与数据库字段数组,然后通过从Excel读取的模板字段名数组 + * 的名称,建立Excel字段列号与数据库导入字段的Map映射关系,通过列号就可以找到对应的导入字段,就可以实现模板列的动态 + * 调整,同时可以通过反正找到对应的属性字段 + */ +package com.engine.organization.util.saveimport.hrmimport; + +import com.engine.hrm.util.HrmWeakPasswordUtil; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.ss.usermodel.*; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.file.FileUploadToPath; +import weaver.file.ImageFileManager; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.settings.ChgPasswdReminder; +import weaver.hrm.settings.RemindSettings; +import weaver.join.hrm.in.HrmResourceVo; +import weaver.join.hrm.in.IHrmImportAdapt; +import weaver.systeminfo.SystemEnv; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.regex.Pattern; + +public class HrmImportAdaptExcelE9 extends BaseBean implements IHrmImportAdapt { + + private String fileName; + + private String importType; + + private Sheet sheet; + + private int sheetCount = 0; + + private final List errorInfo = new ArrayList<>(); + + private String[] temFields; + + // TODO + //标准模板字段 + private String tempField = "所属分部,部门," + + "编号,姓名,登录名,密码,安全级别,性别," + + "岗位,职务,职务类别,职称,职级," + + "职责描述,直接上级,助理,状态," + + "办公室,办公地点,办公电话,移动电话,其他电话," + + "传真,电子邮件,系统语言,出生日期,民族," + + "籍贯,户口,身份证号码," + + "婚姻状况,政治面貌,入团日期,入党日期," + + "工会会员,学历,学位,健康状况,身高," + + "体重,用工性质,合同开始日期,合同结束日期,试用期结束日期,现居住地,家庭联系方式,暂住证号码," + + "入职日期,参加工作日期," + + "公积金帐户,账号类型,主账号,身高(cm),体重(kg),工资账号户名,工资银行,工资账号," + + "办公室电话,显示顺序,人员密级"; + + //存放必填列下标数组,包含自定义字段中的必填列 + private String[] requiredFields; + + //必填列标准模板或字段下标 + // 所属分部,部门,姓名,岗位,职务,职务类别,办公地点 + // private String requiredField = "0,1,3,8,9,10,18"; + private final StringBuilder requiredField = new StringBuilder(); + + //标准导入字段数组 + private String[] voFields; + + //标准导入字段 + private String voField = "subcompanyid1,departmentid," + + "workcode,lastname,loginid,password,seclevel,sex," + + "jobtitle,jobactivityid,jobgroupid,jobcall,joblevel," + + "jobactivitydesc,managerid,assistantid,status," + + "workroom,locationid,telephone,mobile,mobilecall," + + "fax,email,systemlanguage,birthday,folk," + + "nativeplace,regresidentplace,certificatenum," + + "maritalstatus,policy,bememberdate,bepartydate," + + "islabouunion,educationlevel,degree,healthinfo,height," + + "weight,usekind,startdate,enddate,probationenddate," + + "residentplace,homeaddress,tempresidentnumber," + + "companystartdate,workstartdate," + + "accumfundaccount,accounttype,belongto,height,weight,accountname,bankid1,accountid1," + + "telephone,dsporder,classification"; + + //基本信息字段数组最后下标 + private int baseFieldsLastIndex = 0; + + //基础自定义信息字段数组最后下标 + private int baseFieldsLastIndex1 = 0; + + //个人自定义信息数组最后下标 + private int personFieldsLastIndex = 0; + + //工作自定义信息数组最后下标 + private int workFieldLastIndex = 0; + + // 重复性验证标准数据库字段下标 例如 + private int keyFieldIndex = 2; + + // 重复性验证excel字段下标 + private int keyColumn = -1; + + // 用于做重复性验证,重复性与行键值对,<编号,4>,<编号,5> + private final Map repeatKeyMap = new HashMap<>(); + + private int certificateNumIndex = 29; + private int certificateNumColumn = -1; + private final Map certificateNums = new HashMap<>(); + + Map> checkInfos = new HashMap<>(); + + private final String[] checkKeys = new String[]{"loginid", "workcode"}; + + private int accounttypeIndex = 50; + private int accounttypeColumn = -1; + + // 用于存贮HrmResource所有方法参数内容格式为,通过fieldsMaping中的对应关系可以找到方法和参数 + private final Map parameterTypes = new HashMap<>(); + + // HrmResourceVo povo对象属性类型,用于反射赋值 + private final Map fieldTypes = new HashMap<>(); + + //excel字段数组下标与标准字段数组下标对应关系 + private final Map fieldsMap = new HashMap<>(); + + //人员map集合 + private final LinkedHashMap hrmResourceMap = new LinkedHashMap<>(); + + Map cusFieldValMap = new HashMap<>(); //个人信心自定义字段与工作信息自定字段数据验证条件 + + private int userlanguage = 7; //登录语言 + + //弱密码禁止保存:false-允许保存弱密码、true-不允许保存弱密码 + private boolean weakPasswordDisable = false; + //判断弱密码 + private HrmWeakPasswordUtil hrmWeakPasswordUtil; + + /** + * map集合创建类 + * + * @param fu 上传参数 + * @return List + */ + public List creatImportMap(FileUploadToPath fu) { + try { + // 初始化数据 + initDataSource(fu); + + if (!errorInfo.isEmpty()) { + deleteFile(); + return errorInfo; + } + //初始化模板字段 + initTempFields(); + + // 模板验证 + valExcelTemp(); + + if (!errorInfo.isEmpty()) { + deleteFile(); + return errorInfo; + } + + // 读取数据并验证 + readExcel(); + + deleteFile(); + return errorInfo; + } catch (NegativeArraySizeException e) { + errorInfo.add(SystemEnv.getHtmlLabelName(83615, userlanguage));//目前尚不清楚,这种异常的产生原因 + writeLog(e); + return errorInfo; + } catch (Exception e) { + errorInfo.add(SystemEnv.getHtmlLabelName(83617, userlanguage));//Excel导入错误,请阅读注意事项并检查模板文件 + writeLog(e); + return errorInfo; + } + + } + + private void deleteFile() { + new Thread(() -> { + try { + Thread.sleep(30 * 1000); + ImageFileManager.deletePdfImageFile(Util.getIntValue(fileName)); + } catch (InterruptedException e) { + writeLog(e); + } + }).start(); + } + + /** + * 获取人员map + */ + public Map getHrmImportMap() { + return hrmResourceMap; + } + + /** + * 获取上传文件,初始化参数 + * + * @param fu + */ + public void initDataSource(FileUploadToPath fu) { + this.importType = fu.getParameter("importType"); + + // 重复性验证字段 + String keyField = fu.getParameter("keyField"); + + voFields = voField.split(","); + + for (int i = 0; i < voFields.length; i++) { + if (keyField.equals(voFields[i])) { + keyFieldIndex = i; + } + if ("certificatenum".equalsIgnoreCase(voFields[i])) { + certificateNumIndex = i; + } + if ("accounttype".equalsIgnoreCase(voFields[i])) { + accounttypeIndex = i; + } + if (keyFieldIndex != 2 && certificateNumIndex != 29) break; + } + try { + Workbook workbook; + this.fileName = fu.getParameter("excelfile"); + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(Util.getIntValue(this.fileName)); + workbook = WorkbookFactory.create(manager.getInputStream()); + this.sheetCount = workbook.getNumberOfSheets(); + this.sheet = workbook.getSheetAt(this.sheetCount > 1 ? 1 : 0); + } catch (FileNotFoundException ignored) { + } catch (IOException e) { + errorInfo.add(SystemEnv.getHtmlLabelName(83618, userlanguage)); //上传文件不是excel文件 + writeLog(e); + } catch (IndexOutOfBoundsException e) { + errorInfo.add(SystemEnv.getHtmlLabelName(83619, userlanguage)); + writeLog(e); + } + + ChgPasswdReminder reminder = new ChgPasswdReminder(); + RemindSettings settings = reminder.getRemindSettings(); + //判断是否启用【弱密码禁止保存】 + this.weakPasswordDisable = Util.null2String(settings.getWeakPasswordDisable()).equals("1"); + try { + //判断是否为弱密码 + hrmWeakPasswordUtil = new HrmWeakPasswordUtil(); + } catch (Exception e) { + errorInfo.add("加载弱密码集合出错"); + writeLog(e); + } + } + + /** + * 验证模板格式 + */ + public void valExcelTemp() { + int rowIndex = (this.sheetCount > 1 ? 1 : 0); + Row row; + Cell cell; + String cellValue; + List fieldList = new ArrayList<>(); + try { + row = sheet.getRow(rowIndex); + for (int i = 0; i < row.getLastCellNum(); i++) { + boolean flag = false; + cell = row.getCell((short) i); + if (cell != null) { + cellValue = getCellValue(cell).trim(); + for (int k = 0; k < temFields.length; k++) { + if (cellValue.equals(temFields[k])) { + // 初始化必填字段下标 + String requiredFields = "所属分部,部门,姓名,岗位,职务,职务类别,办公地点"; + List requiredFieldList = Arrays.asList(requiredFields.split(",")); + + // TODO + if (requiredFieldList.contains(cellValue)) { + requiredField.append(",").append(i); + } + fieldsMap.put(i, k); + fieldList.add(cellValue); + if (keyFieldIndex == k) //如果重复性验证标准数据库字段下标与标准excel模板下标相等,则找到对应的excel验证列 + keyColumn = i; + if (certificateNumIndex == k) { + certificateNumColumn = i; + } + if (accounttypeIndex == k) { + accounttypeColumn = i; + } + flag = true; + break; + } + } + if (!flag) + errorInfo.add(getCellPosition(i, (rowIndex + 1)) + "[" + cellValue + "]" + " 不是模板中字段,请检查是否有误"); //不是模板中字段,请检查是否有误 + if (importType.equals("add")) { //如果是插入操作才验证固定列 + if (i == 0 && !cellValue.equals(temFields[0])) + errorInfo.add("分所属分部部必须在第" + (rowIndex + 1) + "行第1列"); //【所属分部】固定列 + if (i == 1 && !cellValue.equals(temFields[1])) + errorInfo.add("部门必须在第" + (rowIndex + 1) + "行第2列"); // 【部门】固定列 + } else { + //如果是更新,并且存在分部部门列,就规定分部、部门在第1、2列 + if (cellValue.equals(temFields[0]) && !temFields[1].equals(getCellValue(rowIndex, 1).trim())) + errorInfo.add("更新时有分所属分部部则后一列必须为部门,且第" + (rowIndex + 1) + "行第1列为分所属分部部,第2列为部门"); //【分部】固定列 + else if (cellValue.equals(temFields[0]) && i != 0) + errorInfo.add("所属分部必须在第" + (rowIndex + 1) + "行第1列"); //【分部】固定列 + + + if (cellValue.equals(temFields[1]) && !temFields[0].equals(getCellValue(rowIndex, 0).trim())) + errorInfo.add("更新时有部门则前一列必须为所属分部,且第" + (rowIndex + 1) + "行第1列为所属分部,第2列为部门"); //【分部】固定列 + else if (cellValue.equals(temFields[1]) && i != 1) + errorInfo.add("部门必须在第" + (rowIndex + 1) + "行第2列"); //【部门】固定列 + + } + } + } + if (keyColumn == -1) + errorInfo.add("[" + temFields[keyFieldIndex] + "]" + " 您所选的重复性验证字段不在模板中"); //您所选的重复性验证字段不在模板中 + + if (importType.equals("add")) { //如果是插入操作才验证必填列 + for (String field : requiredFields) { + boolean flag = false; + for (String s : fieldList) { + if (temFields[Integer.parseInt(field)].equals(s)) { + flag = true; + break; + } + } + if (!flag) + errorInfo.add("[" + temFields[Integer.parseInt(field)] + "]" + " 为必填字段"); //必填字段 + } + } + } catch (IllegalArgumentException e) { + errorInfo.add(SystemEnv.getHtmlLabelName(83617, userlanguage)); // excel模板有误时 + writeLog(e); + } + requiredFields = requiredField.toString().split(","); + } + + /** + * 初始化反射所需要的方法和字段Map,parameterTypes,fieldTypes + */ + public void initReflectParam() { + Class hrmResourceClass = HrmResourceVo.class; + Method[] hrmResourceMethods = hrmResourceClass.getDeclaredMethods(); + + for (Method hrmResourceMethod : hrmResourceMethods) { + parameterTypes.put(hrmResourceMethod.getName(), + hrmResourceMethod); + } + + Field[] hrmResourceFields = hrmResourceClass.getDeclaredFields(); + + for (Field hrmResourceField : hrmResourceFields) { + Class fieldTypeClass = hrmResourceField.getType(); + fieldTypes.put(hrmResourceField.getName(), fieldTypeClass + .getName()); + } + } + + /** + * 读取excel数据 + */ + public void readExcel() { + + initReflectParam(); // 初始化反射参数 + + boolean flag; // 标记验证是否通过 + Row row; + Cell cell; + int rowNum; // 行号 + int cellNum; // 列号 + int firstRow = (this.sheetCount > 1 ? 2 : 1); + String keyValue = ""; + int lastRow = sheet.getLastRowNum(); + String subCompany = ""; + String department = ""; + String cellValue; + int fieldIndex; + HrmResourceVo hrmResourceVo; + + for (int i = firstRow; i <= lastRow; i++) { + flag = true; + row = sheet.getRow(i); + if (row == null) { + errorInfo.add(SystemEnv.getHtmlLabelName(15323, userlanguage) + " " + (i + 1) + " " + SystemEnv.getHtmlLabelName(83622, userlanguage)); + continue; + } + rowNum = row.getRowNum(); + StringBuilder baseFieldsValue = new StringBuilder(); + StringBuilder baseFields = new StringBuilder(); + StringBuilder personFieldsValue = new StringBuilder(); + StringBuilder workFieldsValue = new StringBuilder(); + StringBuilder personFields = new StringBuilder(); + StringBuilder workFields = new StringBuilder(); + if (repeatValidate(row, rowNum)) { // 重复性验证 + continue; + } + + hrmResourceVo = new HrmResourceVo(); + + for (int cellIndex = 0; cellIndex < fieldsMap.size(); cellIndex++) { + + cell = row.getCell((short) cellIndex); + + cellNum = cellIndex; + + + fieldIndex = fieldsMap.get(cellNum); +// if (cell == null && !(Util.null2String(voFields[fieldIndex]).trim()).startsWith("field")) { +// +// continue; +// } + + cellValue = getCellValue(cell).trim(); + + if (valExcelDataFormate(rowNum, cellNum, cellValue)) { + if (fieldIndex == keyFieldIndex) { // 验证通过,如果当前单元格为重复性验证单元格,则把值赋给keyValue + keyValue = cellValue; + } + } else { + flag = false; + } + + if (flag) { // 为true则,设置值,否则不需要 + + if (fieldIndex == 0 && getCellValue(1, cellNum).equals("所属分部")) { // 对于excel分部为空则取上面分部读取的值 + if (cellValue.equals("")) + cellValue = subCompany; + else + subCompany = cellValue; + } + + if (fieldIndex == 1 && getCellValue(1, cellNum).equals("部门")) { // 对于excel部门为空则取上面部门读取的值 + if (cellValue.equals("")) + cellValue = department; + else + department = cellValue; + } + + if (fieldIndex <= baseFieldsLastIndex) { + setHrmResourceValue(fieldIndex, cellValue, hrmResourceVo, null); + } + + if (fieldIndex > baseFieldsLastIndex && fieldIndex <= baseFieldsLastIndex1) { + baseFields.append(",").append(voFields[fieldIndex]); + if (cellValue.equals("")) + cellValue = "?"; + baseFieldsValue.append(";").append(cellValue); + setHrmResourceValue(0, baseFields.substring(1), hrmResourceVo, "baseFields"); + setHrmResourceValue(0, baseFieldsValue.substring(1), hrmResourceVo, "baseFieldsValue"); + } + + if (fieldIndex > baseFieldsLastIndex1 && fieldIndex <= personFieldsLastIndex) { + personFields.append(",").append(voFields[fieldIndex]); + if (cellValue.equals("")) + cellValue = "?"; + personFieldsValue.append(";").append(cellValue); + setHrmResourceValue(0, personFields.substring(1), hrmResourceVo, "personFields"); + setHrmResourceValue(0, personFieldsValue.substring(1), hrmResourceVo, "personFieldsValue"); + } + + if (fieldIndex > personFieldsLastIndex && fieldIndex <= workFieldLastIndex) { + workFields.append(",").append(voFields[fieldIndex]); + if (cellValue.equals("")) + cellValue = "?"; + workFieldsValue.append(";").append(cellValue); + setHrmResourceValue(0, workFields.substring(1), hrmResourceVo, "workFields"); + setHrmResourceValue(0, workFieldsValue.substring(1), hrmResourceVo, "workFieldsValue"); + } + + } + } + //设置status 默认值0 试用 + //if(Util.null2String(hrmResourceVo.getStatus()).length()==0){ + //hrmResourceVo.setStatus("0");hrmResourceVo + //} + String currentDate = DateUtil.getCurrentDate(); + if (Util.null2String(hrmResourceVo.getWorkstartdate()).length() > 0 && Util.null2String(hrmResourceVo.getWorkyear()).length() == 0) {//计算工龄 + int day = DateUtil.dayDiff(hrmResourceVo.getWorkstartdate(), currentDate); + DecimalFormat df = new DecimalFormat("0.0"); + hrmResourceVo.setWorkyear(df.format(day / 365.0)); + } + + if (Util.null2String(hrmResourceVo.getCompanystartdate()).length() > 0 && Util.null2String(hrmResourceVo.getCompanyworkyear()).length() == 0) {//计算司令 + int day = DateUtil.dayDiff(hrmResourceVo.getCompanystartdate(), currentDate); + DecimalFormat df = new DecimalFormat("0.0"); + hrmResourceVo.setCompanyworkyear(df.format(day / 365.0)); + } + + repeatKeyMap.put(keyValue, "" + (i + 1)); // 用于重复性验证 + if (hrmResourceVo.getAccounttype() != null && !"".equals(hrmResourceVo.getAccounttype())) { + if ("主账号".equals(hrmResourceVo.getAccounttype())) { + certificateNums.put(hrmResourceVo.getCertificatenum(), String.valueOf(i + 1)); + } + } else { + certificateNums.put(hrmResourceVo.getCertificatenum(), String.valueOf(i + 1)); + } + + if (checkInfo(hrmResourceVo, rowNum)) { // 重复性验证 + continue; + } + + //新增账号、工号唯一性校验 + for (String key : checkKeys) { + Map checkInfo = checkInfos.get(key); + if (checkInfo == null) { + checkInfo = new HashMap<>(); + checkInfos.put(key, checkInfo); + } else { + checkInfo = checkInfos.get(key); + } + String val = ""; + switch (key) { + case "loginid": + val = hrmResourceVo.getLoginid(); + break; + case "workcode": + val = hrmResourceVo.getWorkcode(); + break; + case "certificatenum": + val = hrmResourceVo.getCertificatenum(); + break; + } + checkInfo.put(val, String.valueOf(i + 1)); + checkInfos.put(key, checkInfo); + } + + if (flag) { + hrmResourceMap.put(keyValue, hrmResourceVo); + } + } + } + + /** + * 重复性验证,读取唯一性cell值,然后从HrmResourceMap中查找是否存在 + * + * @param row 行 + * @param rowNum 行下标 + * @return + */ + public boolean repeatValidate(Row row, int rowNum) { + if (certificateNumColumn == -1) + return false; + String certificateNum = getCellValue(row.getCell((short) certificateNumColumn)).trim(); + String accounttype = getCellValue(row.getCell((short) accounttypeColumn)).trim(); + String key = getCellValue(row.getCell((short) keyColumn)).trim(); + if (voFields[fieldsMap.get(keyColumn)].equals("")) + key = getCellValue(row.getCell((short) 0)).trim() + ">" + getCellValue(row.getCell((short) 1)).trim() + "_" + key; + String repeatRow = repeatKeyMap.get(key); + String cnRow = certificateNums.get(certificateNum); + if (repeatRow != null) { + errorInfo.add((rowNum + 1) + "," + repeatRow + " 行重复"); //重复 num_5,6 行重复 + return true; + } else if (cnRow != null && certificateNum.length() > 0) { + if ("次账号".equalsIgnoreCase(accounttype)) { + return false; + } else { + errorInfo.add((rowNum + 1) + "," + cnRow + " " + SystemEnv.getHtmlLabelName(83623, userlanguage)); + return true; + } + } else { + return false; + } + } + + private boolean checkInfo(HrmResourceVo hrmResourceVo, int rowNum) { + //新增账号、工号唯一性校验 + for (String key : checkKeys) { + Map checkInfo = checkInfos.get(key); + if (checkInfo != null && !checkInfo.isEmpty()) { + String val = ""; + String errorMsg = ""; + switch (key) { + case "loginid": + val = Util.null2String(hrmResourceVo.getLoginid()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(520127, userlanguage); + break; + case "workcode": + val = Util.null2String(hrmResourceVo.getWorkcode()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(520128, userlanguage); + break; + case "certificatenum": + val = Util.null2String(hrmResourceVo.getCertificatenum()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(83623, userlanguage); + break; + } + String cnRow = Util.null2String(checkInfo.get(val)); + if (cnRow.length() > 0 && val.length() > 0) { + errorInfo.add((rowNum + 1) + "," + cnRow + errorMsg); + return true; + } + } + } + return false; + } + + /** + * 验证数据格式,必填列是否为空 + * + * @param rowNum 行号 + * @param cellNum 列号 + * @param cellValue 单元格值 + * @return + */ + public boolean valExcelDataFormate(int rowNum, int cellNum, String cellValue) { + + boolean flag = true; + String msg; + int fieldIndex = fieldsMap.get(cellNum); + String fieldName = voFields[fieldIndex]; + + // 人员信息第1行(模板第2行)的分部和部门为必填 + if ((rowNum == 1 || rowNum == 2) && fieldName.equals("subcompanyid1") && getCellValue(1, cellNum).equals("所属分部") && cellValue.equals("")) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【分部】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return flag; + } + + if ((rowNum == 1 || rowNum == 2) && fieldName.equals("departmentid") && getCellValue(1, cellNum).equals("部门") && cellValue.equals("")) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【部门】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return flag; + + } + //【分部】不为空则【部门】为必填 + if (fieldName.equals("departmentid") && cellValue.equals("")) { + if (!getCellValue(rowNum, cellNum - 1).equals("")) { //分部不为空 + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return flag; + } + } + + // 姓名 + if (fieldName.equals("lastname") && cellValue.equals("")) { + + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【姓名】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return flag; + } + + // 岗位 + if (fieldName.equals("jobtitle") && cellValue.equals("")) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【岗位】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return flag; + } + + if (fieldName.equals("jobactivityid") && cellValue.equals("")) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【职务】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return flag; + } + + + if (fieldName.equals("jobgroupid") && cellValue.equals("")) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【职务类别】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return flag; + } + + + // 办公地点 + if (fieldName.equals("locationid") && cellValue.equals("")) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【办公地点】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return flag; + } + + //自定义字段为必填设置时 + if (fieldIndex > baseFieldsLastIndex && requiredField.toString().contains(String.valueOf(fieldIndex))) { + if (cellValue.equals("")) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return flag; + } + } + + //基本信息、个人信息、工作信息自定义验证 + if (fieldIndex > baseFieldsLastIndex && !cellValue.equals("")) { + //自定义信息字段不能包含‘?’问号 + if (cellValue.contains("?") && getStrLength(cellValue) == 1) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83627, userlanguage)); + return flag; + } + String valType = cusFieldValMap.get(fieldIndex); + if (valType != null) + if (valType.equals("isInt")) { + if (!isInteger(cellValue)) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83628, userlanguage)); + return flag; + } + if (getStrLength(cellValue) > 18 && (Integer.MAX_VALUE < Double.parseDouble(cellValue) || Double.parseDouble(cellValue) < Integer.MIN_VALUE)) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83629, userlanguage) + Integer.MAX_VALUE + SystemEnv.getHtmlLabelName(15508, userlanguage) + Integer.MIN_VALUE); + return flag; + } + + } else if (valType.equals("isDouble")) { + if (isDecimal(cellValue)) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83637, userlanguage)); + return flag; + } + if (getStrLength(cellValue) > 18) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83639, userlanguage)); + } + } else if (valType.equals("isDate")) { + if (getStrLength(cellValue) != 10) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83640, userlanguage)); + } + + } else if (isInteger(valType) && getStrLength(cellValue) > Integer.parseInt(valType)) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83641, userlanguage) + valType + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return flag; + } else if (valType.equals("isCheck") && !cellValue.equals("0") && !cellValue.equals("1")) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83644, userlanguage)); + return flag; + } + } + + //安全级别、职级整数格式验证、大于0验证 + if ((fieldName.equals("seclevel") || fieldName.equals("joblevel")) && !cellValue.equals("")) { + if (fieldName.equals("seclevel")) { + //安全级别不能大于999 + if (Util.getIntValue(cellValue) > 999) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(515522, userlanguage)); + return flag; + } + //安全级别不能小于-999 + if (Util.getIntValue(cellValue) < -999) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(515523, userlanguage)); + return flag; + } + } else { + if (!isInteger(cellValue)) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83645, userlanguage)); + return flag; + } + if (Integer.parseInt(cellValue) < 0 || Integer.parseInt(cellValue) > 1000) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83648, userlanguage)); + return flag; + } + } + } + //身高、体重数据格式验证、大于0验证 + if ((fieldName.equals("height") || fieldName.equals("weight")) && !cellValue.equals("")) { + if (isDecimal(cellValue)) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83650, userlanguage)); + return flag; + } + if (Double.parseDouble(cellValue) < 0 || Double.parseDouble(cellValue) > 1000) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83648, userlanguage)); + return flag; + } + } + + //日期自定义日期字段长度 + if (fieldName.startsWith("datefield") && getStrLength(cellValue) > 10) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83658, userlanguage) + "10" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return flag; + } + //文本自定义文本字段长度 + if (fieldName.startsWith("textfield") && getStrLength(cellValue) > 100) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83702, userlanguage) + "100" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return flag; + } + //数字自定义数字字段是否为数字格式判断 + if (fieldName.startsWith("numberfield") && !cellValue.equals("") && isDecimal(cellValue)) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83662, userlanguage)); + return flag; + } + + //判断自定义字段值必须为0或1 + if (fieldName.startsWith("tinyintfield") && !cellValue.equals("") && !cellValue.equals("0") && !cellValue.equals("1")) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83664, userlanguage)); + return flag; + } + + + //长度为200个字符的标准字段 + if ((fieldName.equals("jobtitle") || fieldName.equals("jobactivityid") || fieldName.equals("jobgroupid") || + fieldName.equals("locationid") || fieldName.equals("jobactivitydesc") || fieldName.equals("regresidentplace")) && !cellValue.equals("") && getStrLength(cellValue) > 200) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83666, userlanguage) + "200" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return flag; + } + + //长度为100的标准字段 + if ((fieldName.equals("loginid") || fieldName.equals("password") || fieldName.equals("homeaddress") || fieldName.equals("nativeplace")) && !cellValue.equals("") && getStrLength(cellValue) > 100) { + + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //自定义日期字段长度验证 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83666, userlanguage) + "100" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return flag; + + } + //长度为60的标准字段 + + if ((fieldName.equals("lastname") || fieldName.equals("password") || fieldName.equals("telephone") || fieldName.equals("mobile") || fieldName.equals("mobilecall") + || fieldName.equals("email") || fieldName.equals("workroom") || fieldName.equals("workcode") || fieldName.equals("fax") + || fieldName.equals("certificatenum") || fieldName.equals("jobcall") || fieldName.equals("tempresidentnumber")) + && !cellValue.equals("") && getStrLength(cellValue) > 60) { + + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83666, userlanguage) + "60" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return flag; + + } + + //长度为30个字符的标准字段 + if ((fieldName.equals("degree") || fieldName.equals("policy")) && !cellValue.equals("") && getStrLength(cellValue) > 30) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83666, userlanguage) + "30" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return flag; + } + + //长度为10个字符的标准字段 + if ((fieldName.equals("birthday") || fieldName.equals("bememberdate") || fieldName.equals("bepartydate") || + fieldName.equals("startdate") || fieldName.equals("enddate") || fieldName.equals("probationenddate")) && !cellValue.equals("") && getStrLength(cellValue) > 10) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83666, userlanguage) + "10" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return flag; + } + + //分部各级长度验证 + if (fieldName.equals("subcompanyid1") && !cellValue.equals("")) { + String[] subcompanyname = cellValue.split(">"); + for (String s : subcompanyname) { + if (getStrLength(s) > 200) + flag = false; + } + if (!flag) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83667, userlanguage)); + return flag; + } + } + + //部门各级长度验证 + if (fieldName.equals("departmentid") && !cellValue.equals("")) { + String[] departmentname = cellValue.split(">"); + for (String s : departmentname) { + if (getStrLength(s) > 200) + flag = false; + } + if (!flag) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83668, userlanguage)); + return flag; + } + } + + //当启用【弱密码禁止保存】时,弱密码导入失败,失败信息为“密码安全性过弱” + if ("password".equalsIgnoreCase(fieldName)) { + if (weakPasswordDisable && hrmWeakPasswordUtil.isWeakPsd(cellValue)) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(515436, userlanguage)); + return flag; + } + } + + if (fieldIndex == keyFieldIndex && cellValue.equals("")) { + flag = false; + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; // 重复性验证字段不在模板中 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return flag; + } + + return flag; + } + + /** + * 通过反射为对象赋值 + * + * @param cellNum 列号 + * @param cellValue 单元格值 + * @param hrmResource 需要赋值的HrmResource + */ + public void setHrmResourceValue(int cellNum, String cellValue, + HrmResourceVo hrmResource, String field) { + if (field == null) { + String excelField = voFields[cellNum]; + String methodName = "set" + excelField.substring(0, 1).toUpperCase() + + excelField.substring(1); + Method method = parameterTypes.get(methodName); + try { + String fieldType = fieldTypes.get(excelField); + if (fieldType.equals("java.lang.String")) + method.invoke(hrmResource, cellValue); + else if (fieldType.equals("java.lang.Integer")) { + if (!cellValue.equals("")) + method.invoke(hrmResource, Integer.parseInt(cellValue)); + else + method.invoke(hrmResource, 0x7fffffff); + } else if (fieldType.equals("java.lang.Float") && !cellValue.equals("")) + method.invoke(hrmResource, Float.parseFloat(cellValue)); + else if (fieldType.equals("java.lang.Short") && !cellValue.equals("")) { + method.invoke(hrmResource, Short.parseShort(cellValue)); + } + } catch (Exception e) { + writeLog(e); + } + } else { + String methodName = "set" + field.substring(0, 1).toUpperCase() + + field.substring(1); + Method method = parameterTypes.get(methodName); + try { + method.invoke(hrmResource, cellValue); + } catch (Exception e) { + writeLog(e); + } + } + } + + /** + * excel单元格位置转换 + * + * @param cellIndex 列号 + * @param rowNum 行号 + * @return + */ + public String getCellPosition(int cellIndex, int rowNum) { + + int count = cellIndex / 26; + String cellChar = String.valueOf((char) (cellIndex % 26 + 65)); + String cellPosition; + + if (count != 0) + cellPosition = (char) ((count - 1) + 65) + cellChar; + else + cellPosition = cellChar; + cellPosition += rowNum; + return cellPosition; + } + + /** + * 初始化模板字段 + */ + public void initTempFields() { + RecordSet recordSet = new RecordSet(); + + temFields = tempField.split(","); + + baseFieldsLastIndex = temFields.length - 1; + + int requiredFieldIndex = baseFieldsLastIndex; + + /* end base fields*/ + + /*基本信息信息字段*/ + + String baseSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=-1 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(baseSql); + StringBuilder baseField = new StringBuilder(); + StringBuilder baseFieldLabel = new StringBuilder(); + String fieldhtmltype; + while (recordSet.next()) { + fieldhtmltype = recordSet.getString("fieldhtmltype"); + if (fieldhtmltype.equals("1") || fieldhtmltype.equals("2") || fieldhtmltype.equals("3") + || fieldhtmltype.equals("4") || fieldhtmltype.equals("5")) { + baseField.append(",field").append(recordSet.getInt("fieldid")); + baseFieldLabel.append(",").append(recordSet.getString("hrm_fieldlable")); + requiredFieldIndex++; + //验证条件 + //1为html文本类型 + switch (fieldhtmltype) { + case "1": + if (recordSet.getString("type").equals("1")) { //1为文本数据类型 + String fielddbtype = recordSet.getString("fielddbtype"); + fielddbtype = fielddbtype.substring(fielddbtype.indexOf("(") + 1, fielddbtype.lastIndexOf(")")); //截取字符设置的长度 + cusFieldValMap.put(requiredFieldIndex, fielddbtype); + } else if (recordSet.getString("type").equals("2")) { // 2为整数数据类型 + cusFieldValMap.put(requiredFieldIndex, "isInt"); + } else if (recordSet.getString("type").equals("3")) { // 3为浮点数数据类型 + cusFieldValMap.put(requiredFieldIndex, "isDouble"); + } else + cusFieldValMap.put(requiredFieldIndex, ""); + break; + case "4": //4 为check框 + cusFieldValMap.put(requiredFieldIndex, "isCheck"); + break; + case "3": + if (recordSet.getString("type").equals("2")) { + cusFieldValMap.put(requiredFieldIndex, "isDate"); + } else if (recordSet.getString("type").equals("19")) { + cusFieldValMap.put(requiredFieldIndex, "isTime"); + } else { + cusFieldValMap.put(requiredFieldIndex, "isBrowser"); + } + break; + case "5": + cusFieldValMap.put(requiredFieldIndex, "isSelect"); + break; + } + } + } + voField = voField + baseField; + tempField = tempField + baseFieldLabel; + temFields = tempField.split(","); + baseFieldsLastIndex1 = temFields.length - 1; + + + /*个人信息字段*/ + String personSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=1 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(personSql); + StringBuilder personField = new StringBuilder(); + StringBuilder personalFieldLabel = new StringBuilder(); + while (recordSet.next()) { + fieldhtmltype = recordSet.getString("fieldhtmltype"); + if (fieldhtmltype.equals("1") || fieldhtmltype.equals("2") || fieldhtmltype.equals("3") + || fieldhtmltype.equals("4") || fieldhtmltype.equals("5")) { + personField.append(",field").append(recordSet.getInt("fieldid")); + personalFieldLabel.append(",").append(recordSet.getString("hrm_fieldlable")); + requiredFieldIndex++; + //验证条件 + //1为html文本类型 + switch (fieldhtmltype) { + case "1": + if (recordSet.getString("type").equals("1")) { //1为文本数据类型 + String fielddbtype = recordSet.getString("fielddbtype"); + fielddbtype = fielddbtype.substring(fielddbtype.indexOf("(") + 1, fielddbtype.lastIndexOf(")")); //截取字符设置的长度 + cusFieldValMap.put(requiredFieldIndex, fielddbtype); + } else if (recordSet.getString("type").equals("2")) { // 2为整数数据类型 + cusFieldValMap.put(requiredFieldIndex, "isInt"); + } else if (recordSet.getString("type").equals("3")) { // 3为浮点数数据类型 + cusFieldValMap.put(requiredFieldIndex, "isDouble"); + } else { + cusFieldValMap.put(requiredFieldIndex, ""); + } + break; + case "4": //4 为check框 + cusFieldValMap.put(requiredFieldIndex, "isCheck"); + break; + case "3": + if (recordSet.getString("type").equals("2")) { + cusFieldValMap.put(requiredFieldIndex, "isDate"); + } else if (recordSet.getString("type").equals("19")) { + cusFieldValMap.put(requiredFieldIndex, "isTime"); + } else { + cusFieldValMap.put(requiredFieldIndex, "isBrowser"); + } + break; + case "5": + cusFieldValMap.put(requiredFieldIndex, "isSelect"); + break; + } + } + } + voField = voField + personField; + tempField = tempField + personalFieldLabel; + temFields = tempField.split(","); + personFieldsLastIndex = temFields.length - 1; + + /*个人信息字段*/ + /*工作信息字段*/ + String workSql = "select t1.fieldid,t1.hrm_fieldlable,t2.fielddbtype,t2.fieldhtmltype,t2.type from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=3 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(workSql); + StringBuilder workField = new StringBuilder(); + StringBuilder workFieldLabel = new StringBuilder(); + while (recordSet.next()) { + fieldhtmltype = recordSet.getString("fieldhtmltype"); + if (fieldhtmltype.equals("1") || fieldhtmltype.equals("2") || fieldhtmltype.equals("3") + || fieldhtmltype.equals("4") || fieldhtmltype.equals("5")) { + workField.append(",field").append(recordSet.getInt("fieldid")); + workFieldLabel.append(",").append(recordSet.getString("hrm_fieldlable")); + requiredFieldIndex++; + //验证条件 + //1为html文本类型 + switch (fieldhtmltype) { + case "1": + if (recordSet.getString("type").equals("1")) { //1为文本数据类型 + String fielddbtype = recordSet.getString("fielddbtype"); + fielddbtype = fielddbtype.substring(fielddbtype.indexOf("(") + 1, fielddbtype.lastIndexOf(")")); //截取字符设置的长度 + cusFieldValMap.put(requiredFieldIndex, fielddbtype); + } else if (recordSet.getString("type").equals("2")) { // 2为整数数据类型 + cusFieldValMap.put(requiredFieldIndex, "isInt"); + } else if (recordSet.getString("type").equals("3")) { // 3为浮点数数据类型 + cusFieldValMap.put(requiredFieldIndex, "isDouble"); + } else { + cusFieldValMap.put(requiredFieldIndex, ""); + } + break; + case "4": //4 为check框 + cusFieldValMap.put(requiredFieldIndex, "isCheck"); + break; + case "3": + if (recordSet.getString("type").equals("2")) { + cusFieldValMap.put(requiredFieldIndex, "isDate"); + } else if (recordSet.getString("type").equals("19")) { + cusFieldValMap.put(requiredFieldIndex, "isTime"); + } else { + cusFieldValMap.put(requiredFieldIndex, "isBrowser"); + } + break; + case "5": + cusFieldValMap.put(requiredFieldIndex, "isSelect"); + break; + } + } + } + voField = voField + workField; + tempField = tempField + workFieldLabel; + voFields = voField.split(","); + temFields = tempField.split(","); + //requiredFields = requiredField.split(","); + workFieldLastIndex = temFields.length - 1; + /*工作信息字段*/ + } + + /** + * 获取excel单元格值 + * + * @param cell 要读取的单元格对象 + * @return + */ + public String getCellValue(Cell 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 = 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(); + if (cellValue == null) + cellValue = ""; + Date d = validDate(cellValue); + if (d != null) + cellValue = new SimpleDateFormat("yyyy-MM-dd").format(d); + break; + } + cellValue = Util.toHtmlForHrm(cellValue); + return cellValue; + } + + private Date validDate(String str) { + Date d = null; + SimpleDateFormat fmt1 = new SimpleDateFormat("yyyy-MM-dd"); + fmt1.setLenient(false); + SimpleDateFormat fmt2 = new SimpleDateFormat("yyyy/MM/dd"); + fmt2.setLenient(false); + try { + d = fmt1.parse(str); + } catch (Exception ignored) { + } + try { + d = fmt2.parse(str); + } catch (Exception ignored) { + + } + return d; + } + + /** + * 获取指定行、列的单元格值 + * + * @param rowNum + * @param cellNum + * @return + */ + public String getCellValue(int rowNum, int cellNum) { + Row row = sheet.getRow(rowNum); + Cell cell = row.getCell((short) cellNum); + String cellValue = getCellValue(cell); + cellValue = Util.toHtmlForHrm(cellValue); + return cellValue; + } + + //浮点数判断 + public boolean isDecimal(String str) { + if (str == null || "".equals(str)) + return true; + Pattern pattern = Pattern.compile("[0-9]*(\\.?)[0-9]*"); + return !pattern.matcher(str).matches(); + } + + //整数判断 + public boolean isInteger(String str) { + if (str == null) + return false; + Pattern pattern = Pattern.compile("[0-9]+"); + return pattern.matcher(str).matches(); + } + + /** + * 获取字符串字节长度 由于java中中英字符都按1个字符,而数据库中汉字按两个字符计算 + * + * @param str + * @return + */ + public int getStrLength(String str) { + try { + if (str == null) + return 0; + else + return new String(str.getBytes("gb2312"), StandardCharsets.ISO_8859_1).length(); + } catch (Exception e) { + writeLog(e); + return 0; + } + } + + public int getUserlanguage() { + return userlanguage; + } + + + public void setUserlanguage(int userlanguage) { + this.userlanguage = userlanguage; + } +} diff --git a/src/com/engine/organization/util/saveimport/hrmimport/HrmImportProcessE9.java b/src/com/engine/organization/util/saveimport/hrmimport/HrmImportProcessE9.java new file mode 100644 index 00000000..8e533bd3 --- /dev/null +++ b/src/com/engine/organization/util/saveimport/hrmimport/HrmImportProcessE9.java @@ -0,0 +1,2637 @@ +package com.engine.organization.util.saveimport.hrmimport; + +import com.engine.common.entity.EncryptFieldEntity; +import com.engine.common.service.impl.HrmCommonServiceImpl; +import com.engine.common.util.ParamUtil; +import com.engine.encrypt.biz.EncryptFieldConfigComInfo; +import com.engine.hrm.entity.RuleCodeType; +import com.engine.hrm.util.CodeRuleManager; +import com.engine.hrm.util.HrmWeakPasswordUtil; +import com.engine.hrm.util.face.HrmFaceCheckManager; +import com.engine.hrm.util.face.ValidateFieldManager; +import com.engine.hrm.util.face.bean.CheckItemBean; +import com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO; +import com.engine.organization.entity.jclimport.po.JclImportHistoryPO; +import com.engine.organization.mapper.jclimport.JclImportHistoryDetailMapper; +import com.engine.organization.mapper.jclimport.JclImportHistoryMapper; +import com.engine.organization.util.db.MapperProxyFactory; +import com.weaver.integration.ldap.sync.oa.OaSync; +import com.weaver.integration.ldap.util.AuthenticUtil; +import ln.LN; +import org.apache.commons.lang3.StringUtils; +import org.json.JSONObject; +import weaver.common.DateUtil; +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.conn.RecordSetTrans; +import weaver.encrypt.EncryptUtil; +import weaver.general.BaseBean; +import weaver.general.PasswordUtil; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.common.DbFunctionUtil; +import weaver.hrm.common.database.dialect.DbDialectFactory; +import weaver.hrm.common.database.dialect.DialectUtil; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.definedfield.HrmFieldManager; +import weaver.hrm.job.JobActivitiesComInfo; +import weaver.hrm.job.JobGroupsComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import weaver.hrm.job.UseKindComInfo; +import weaver.hrm.location.LocationComInfo; +import weaver.hrm.passwordprotection.manager.HrmResourceManager; +import weaver.hrm.resource.ResourceComInfo; +import weaver.hrm.settings.ChgPasswdReminder; +import weaver.hrm.settings.RemindSettings; +import weaver.hrm.tools.HrmDateCheck; +import weaver.interfaces.hrm.HrmServiceManager; +import weaver.join.hrm.in.HrmResource; +import weaver.join.hrm.in.HrmResourceVo; +import weaver.join.hrm.in.ImportLog; +import weaver.join.hrm.in.processImpl.HrmTlevelManager; +import weaver.rtx.OrganisationCom; +import weaver.systeminfo.SystemEnv; + +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Field; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class HrmImportProcessE9 extends BaseBean { + + + private final Map keyMap = new HashMap<>(); //看数据库是否有重复,将数据库现有的数据查出 + + private final Map isADAccountMap = new HashMap<>(); + + private final Map certificateNums = new HashMap<>();//已存在的身份证 + + Map> checkInfos = new HashMap<>(); + + private final String[] checkKeys = new String[]{"loginid", "workcode"}; + + private Map baseTypeMap; //基础信息自定义字段数据库类型与字段名称映射 + + private Map personTypeMap; //个人信息自定义字段数据库类型与字段名称映射 + + private Map workTypeMap; //工作信息自定义字段数据库类型与字段名称映射 + + private final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + + private OrganisationCom rtxService = null; //添加到rtx + + private int userlanguage = 7; //登录语言 + + char separator = Util.getSeparator(); + + LN license = new LN(); //license + + String keyField = ""; + String operateType = ""; + + private HrmResourceVo vo = null; + + private String multilanguage; + + private Map sysLanguage = null; + + private Map jobcallMap = null; + private Map locationMap = null; + private Map usekindMap = null; + private Map educationlevelMap = null; + + private int cnLanguageId = 7; + + private User user; + private int pId = 0; + private int rowNum = 0; + + //判断弱密码 + private HrmWeakPasswordUtil hrmWeakPasswordUtil; + + public void setUser(User user) { + this.user = user; + } + + public Map init(HttpServletRequest request) { + Map retmap = new HashMap<>(); + try { + this.user = (User) request.getSession(true).getAttribute("weaver_user@bean"); + this.keyField = Util.null2String(request.getParameter("keyField")); + this.operateType = Util.null2String(request.getParameter("operateType")); + + Map params = ParamUtil.request2Map(request); + params.put("operateType", this.operateType); + JclImportHistoryPO historyPO = JclImportHistoryPO.builder().operator((long) user.getUID()).operateTime(DateUtil.getFullDate()).clientAddress(user.getLoginip()).importType("resource").sourceFrom("excel").operateType(operateType).status("importing").build(); + MapperProxyFactory.getProxy(JclImportHistoryMapper.class).insertHistory(historyPO); + retmap.put("pId", historyPO.getId()); + this.pId = Util.getIntValue(Util.null2String(retmap.get("pId"))); + + + LN license = new LN(); + license.InLicense(); + RecordSet recordSet = new RecordSet(); + + + String sql = "select multilanguage,(select id from syslanguage where language='简体中文' or language='中文') as cnLanguageId from license "; + recordSet.execute(sql); + recordSet.next(); + multilanguage = recordSet.getString("multilanguage"); + cnLanguageId = recordSet.getInt(2); + + sysLanguage = new HashMap<>(); + recordSet.execute("select id,language from syslanguage where activable=1"); + while (recordSet.next()) { + sysLanguage.put(recordSet.getString(2), recordSet.getInt(1)); + } + + educationlevelMap = new HashMap<>(); + + String educationName = "convToMultiLang(name,7)"; + if ("sqlserver".equalsIgnoreCase(recordSet.getDBType())) { + educationName = "dbo.convToMultiLang(name,7)"; + } + + + recordSet.execute(String.format("select id,%s from HrmEducationLevel", educationName)); + + while (recordSet.next()) { + educationlevelMap.put(recordSet.getString(2), recordSet.getInt(1)); + } + + + jobcallMap = new HashMap<>(); + if ("sqlserver".equalsIgnoreCase(recordSet.getDBType())) { + recordSet.execute("select id,dbo.convToMultiLang(name,7) from HrmJobCall"); + } else { + recordSet.execute("select id,convToMultiLang(name,7) from HrmJobCall"); + } + while (recordSet.next()) { + jobcallMap.put(recordSet.getString(2), recordSet.getInt(1)); + } + + locationMap = new HashMap<>(); + if ("sqlserver".equalsIgnoreCase(recordSet.getDBType())) { + recordSet.execute("select id,dbo.convToMultiLang(locationname,7) from HrmLocations where countryid=1"); + } else { + recordSet.execute("select id,convToMultiLang(locationname,7) from HrmLocations where countryid=1"); + } + while (recordSet.next()) { + locationMap.put(recordSet.getString(2), recordSet.getInt(1)); + } + + usekindMap = new HashMap<>(); + if ("sqlserver".equalsIgnoreCase(recordSet.getDBType())) { + recordSet.execute("select id,dbo.convToMultiLang(name,7) from HrmUseKind"); + } else { + recordSet.execute("select id,convToMultiLang(name,7) from HrmUseKind"); + } + while (recordSet.next()) { + usekindMap.put(recordSet.getString(2), recordSet.getInt(1)); + } + + } catch (Exception e) { + writeLog(e); + } + return retmap; + } + + /** + * 对人员数据进行解析,并添加到数据库 + * + * @param hrMap 人员数据Map集合 + * @return List + */ + public void processMap(Map hrMap) {//增加同步锁,防止同时多次调用 + List resultList = new ArrayList<>(); //导入结果 + RecordSet recordSet = new RecordSet(); + try { + String subCompanyName = ""; //分部名称 + String departmentName = ""; //部门名称 + int subcompanyid1 = 0; // 分部Id + int departmentid = 0; // 部门id + String key; // workcode_lastname 组合 + getKeyMap(keyField); //获取重复性验证字段Map + int id; + rtxService = new OrganisationCom(); + + final ResourceComInfo resourcecominfo = new ResourceComInfo(); + DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + JobActivitiesComInfo jobActivitiesComInfo = new JobActivitiesComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + JobGroupsComInfo jobGroupsComInfo = new JobGroupsComInfo(); + LocationComInfo locationComInfo = new LocationComInfo(); + UseKindComInfo useKindComInfo = new UseKindComInfo(); + + Set keySet = hrMap.keySet(); + Object[] keyArray = keySet.toArray(); + + Class hrmClass = HrmResource.class; + Class voClass = HrmResourceVo.class; + + String field = "id,subcompanyid1,departmentid,workcode,lastname," + + "loginid,password,seclevel,sex,jobtitle,jobcall,joblevel," + + "jobactivitydesc,managerid,assistantid,status,locationid,workroom," + + "telephone,mobile,mobilecall,fax,email," + + "systemlanguage,birthday,folk,nativeplace,regresidentplace," + + "certificatenum,maritalstatus,policy,bememberdate,bepartydate," + + "islabouunion,educationlevel,degree,healthinfo,height,weight," + + "usekind,startdate,enddate,probationenddate,"//add by lvyi + + "residentplace,homeaddress,tempresidentnumber," + + "datefield1,datefield2,datefield3,datefield4,datefield5," + + "textfield1,textfield2,textfield3,textfield4,textfield5," + + "numberfield1,numberfield2,numberfield3,numberfield4,numberfield5," + + "tinyintfield1,tinyintfield2,tinyintfield3,tinyintfield4,tinyintfield5," + + "companystartdate,workstartdate," + + "accumfundaccount,accounttype,belongto,accountname,bankid1,accountid1,dsporder,classification"; + + String[] fields = field.split(","); + + int createrid = 1; // 创建者id + int lastmodid = 1; // 最后修改者id + if (user != null) { + createrid = user.getUID(); + lastmodid = user.getUID(); + } + + String lastmoddate = date; // 最后修改时间 + + ChgPasswdReminder reminder = new ChgPasswdReminder(); + RemindSettings settings = reminder.getRemindSettings(); + //判断是否启用【启用初始密码】 + //是否启用初始密码:false-不启用初始密码、true-启用初始密码 + boolean defaultPasswordEnable = Util.null2String(settings.getDefaultPasswordEnable()).equals("1"); + //初始密码 + //初始密码 + String defaultPassword = Util.null2String(settings.getDefaultPassword()); + //判断是否启用【弱密码禁止保存】 + //弱密码禁止保存:false-允许保存弱密码、true-不允许保存弱密码 + boolean weakPasswordDisable = Util.null2String(settings.getWeakPasswordDisable()).equals("1"); + try { + //判断是否为弱密码 + hrmWeakPasswordUtil = new HrmWeakPasswordUtil(); + } catch (Exception e) { + writeLog(e); + } + + Object obj; + HrmResource hrm; + for (Object o : keyArray) { + obj = o; + vo = hrMap.get((String) obj); + key = (String) obj; + hrm = new HrmResource(); + this.rowNum++; + //TimeUnit.SECONDS.sleep(1); + try { // 异常处理 + + if (operateType.equals("add")) { + + if (keyMap.get(key) != null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83520, userlanguage))); + continue; + } + + if (this.checkInfo(vo, resultList)) { + continue; + } + if (vo.getAccounttype() == null || "".equalsIgnoreCase(Util.null2String(vo.getAccounttype()))) { + if (StringUtil.isNotNull(vo.getCertificatenum()) && certificateNums.get(StringUtil.vString(vo.getCertificatenum())) != null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } else { + if (vo.getAccounttype() != null && !"".equals(vo.getAccounttype())) { + if ("主账号".equals(vo.getAccounttype())) { + if (StringUtil.isNotNull(vo.getCertificatenum()) && certificateNums.get(StringUtil.vString(vo.getCertificatenum())) != null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } + } + } + + //添加人员信息 license 人员上限判断 + + if (keyMap.get(key) == null && StringUtils.isNotBlank(vo.getLoginid()) + && ("主账号".equals(vo.getAccounttype()) || StringUtils.isBlank(vo.getAccounttype())) + && "正式,试用,临时,试用延期".contains(Util.null2String(vo.getStatus()))) { + license.reloadLicenseInfo(); + if (license.CkHrmnum() >= 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83522, userlanguage))); + continue; + } + } + // 分部Id + String subCompanyNames = vo.getSubcompanyid1(); + String tempSubCompanyName = ""; + if (subCompanyNames != null) { + if (!subCompanyNames.equals(subCompanyName)) { + tempSubCompanyName = subCompanyName; + subCompanyName = subCompanyNames; + subcompanyid1 = getSubCompanyId(subCompanyName); + } + if (subcompanyid1 == 0) { + resultList.add(createLog(vo, "创建", "失败", "分部未找到")); + continue; + } + + if (subcompanyid1 == -9) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); + continue; + } + if (subcompanyid1 == -2) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + continue; + } + if (subcompanyid1 == -1) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83524, userlanguage))); + continue; + } + if (StringUtil.parseToInt(license.getConcurrentFlag(), 0) != 1) { + if (new HrmResourceManager().noMore(String.valueOf(subcompanyid1))) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83525, userlanguage))); + continue; + } + } + hrm.setSubcompanyid1(subcompanyid1); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83526, userlanguage))); + continue; + } + + // 部门id + String departmentNames = vo.getDepartmentid(); + if (departmentNames != null) { + if (!subCompanyNames.equals(tempSubCompanyName) || !departmentNames.equals(departmentName)) { + departmentName = departmentNames; + departmentid = getDeptId(departmentName, subcompanyid1); + } + if (departmentid == 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83537, userlanguage))); + continue; + } + + if (departmentid == -2) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + hrm.setDepartmentid(departmentid); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83527, userlanguage))); + continue; + } + + if (vo.getLastname() == null) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83529, userlanguage))); + continue; + } + + //主账号id-sunjsh + if (vo.getAccounttype() != null && !"".equals(vo.getAccounttype())) { + if ("主账号".equals(vo.getAccounttype())) { + hrm.setBelongto(-1); + hrm.setAccounttype(0); + } else if ("次账号".equals(vo.getAccounttype())) { + if (vo.getBelongto() != null && !"".equals(vo.getBelongto().trim())) { + int belongto = getBelongId(vo.getBelongto(), keyField); + hrm.setBelongto(belongto); + if (!vo.getBelongto().equals("") && belongto == 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(1); + } + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } + } else { + hrm.setBelongto(-1); + hrm.setAccounttype(0); + } + } else if (vo.getBelongto() != null && !"".equals(vo.getBelongto().trim())) { + int belongto = getBelongId(vo.getBelongto(), keyField); + hrm.setBelongto(belongto); + if (!vo.getBelongto().equals("") && belongto == 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(1); + } + } else { + hrm.setBelongto(-1); + hrm.setAccounttype(0); + } + + // 岗位id + if (vo.getJobtitle() != null && vo.getJobactivityid() != null && vo.getJobgroupid() != null) { + // TODO 岗位校验 + int jobtitle = getJobTitles(vo.getJobtitle(), vo + .getJobactivityid(), vo.getJobgroupid()); + /// -1:职务类别不存在,-2:职务不存在,-3:职务类别不存在 + if (jobtitle == -1) { + resultList.add(createLog(vo, "创建", "失败", "职务类别不存在")); + continue; + } else if (jobtitle == -2) { + resultList.add(createLog(vo, "创建", "失败", "职务不存在")); + continue; + } else if (jobtitle == -3) { + resultList.add(createLog(vo, "创建", "失败", "岗位名称不存在")); + continue; + } + hrm.setJobtitle(jobtitle); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83531, userlanguage))); + continue; + } + + //上级id + if (vo.getManagerid() != null) { + int managerid = 0; // 上级Id + String managerstr = ""; //所有上级 + Map managerInfo = getManagerIdAndStr("", vo.getManagerid(), keyField); + if (managerInfo != null) { + managerid = managerInfo.get("managerid") != null ? (Integer) managerInfo.get("managerid") : 0; + managerstr = (String) (managerInfo.get("managerstr") != null ? managerInfo.get("managerstr") : ""); + } + hrm.setManagerid(managerid); + hrm.setManagerstr(managerstr); + + //如果vo.getManagerid()有值,但manageid未找到,说明填写有误 + if (!vo.getManagerid().equals("") && managerid == 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83532, userlanguage))); + continue; + } + } else { + + hrm.setManagerid(0); + hrm.setManagerstr(""); + } + + // 助理id + if (vo.getAssistantid() != null) { + int assistantid; + assistantid = getAssistantid(vo.getAssistantid(), keyField); + hrm.setAssistantid(assistantid); + if (!vo.getAssistantid().equals("") && assistantid == 0) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(24678, userlanguage))); + continue; + } + } + + // 办公地点 + if (vo.getLocationid() != null) { + int locationid = getLocationid(vo.getLocationid()); + hrm.setLocationid(locationid); + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(83533, userlanguage))); + continue; + } + + //邮箱-sunjsh + if (vo.getEmail() != null) { + if (!"".equals(vo.getEmail().trim()) && vo.getEmail().contains("*")) { + vo.setEmail(null); + } else if ("".equals(vo.getEmail().trim())) { + hrm.setEmail(""); + } else { + Pattern pattern = Pattern.compile("^([a-zA-Z0-9_\\-]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(?)$"); + Matcher matcher = pattern.matcher(vo.getEmail()); + if (!matcher.matches()) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(24570, userlanguage))); + continue; + } else { + hrm.setEmail(vo.getEmail()); + } + } + } + + //mobile-sunjsh + if (vo.getMobile() != null) { + if ("".equals(vo.getMobile().trim()) || (!"".equals(vo.getMobile().trim()) && vo.getMobile().contains("*"))) + vo.setMobile(null); + } else + hrm.setMobile(""); + + //工资银行-sunjsh + if (vo.getBankid1() != null && !"".equals(vo.getBankid1())) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", 0); + jsonObject.put("fieldhtmltype", 3); + jsonObject.put("type", 284); + jsonObject.put("dmlurl", ""); + jsonObject.put("fieldvalue", vo.getBankid1()); + + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + if (!"".equals(fieldvalue)) { + hrm.setBankid1(new Integer(fieldvalue)); + } else { +// vo.setBankid1(null); + hrm.setBankid1(this.getBankId(vo.getBankid1())); + } + } + + //sunjsh-入职日期 + if (vo.getCompanystartdate() != null && !"".equals(vo.getCompanystartdate())) { + hrm.setCompanystartdate(vo.getCompanystartdate()); +// hrm.setCompanyworkyear(this.calculateDate(vo.getCompanystartdate())); + } + + //sunjsh-参加工作日期 + if (vo.getWorkstartdate() != null && !"".equals(vo.getWorkstartdate())) { + hrm.setWorkstartdate(vo.getWorkstartdate()); +// hrm.setWorkyear(this.calculateDate(vo.getWorkstartdate())); + } + // 性别,为空或其他情况统一为0(男) + String sex = "女".equals(vo.getSex()) ? "1" : "0"; + hrm.setSex(sex); + + // 职称 + if (vo.getJobcall() != null) { + int jobcall = getJobcall(vo.getJobcall()); + hrm.setJobcall(jobcall); + } + // 系统语言,默认简体中文 + if (vo.getSystemlanguage() != null) { + int systemlanguage = getSystemlanguage(vo.getSystemlanguage()); + + if (systemlanguage == -1) { //只能选择简体中文|Englisth|繁体中文 + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(518929, userlanguage))); + continue; + } + if (systemlanguage == 0) { //系统不支持多语言 + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(84810, userlanguage))); + continue; + } + hrm.setSystemlanguage(systemlanguage); + } else { + hrm.setSystemlanguage(7); + } + + // 婚姻状况,如果不是以下选项,则默认为未婚 + String maritalstatus = "已婚".equals(vo.getMaritalstatus()) ? "1" + : "离异".equals(vo.getMaritalstatus()) ? "2" : "0"; + hrm.setMaritalstatus(maritalstatus); + + // 员工状态 + if (!"".equals(Util.null2String(vo.getStatus()))) { + int status = getStatus(vo.getStatus()); + hrm.setStatus(status); + } else { + hrm.setStatus(1); + } + + // 人员密级 + if (!"".equals(Util.null2String(vo.getClassification()))) { + int classification = getClassification(vo.getClassification()); + hrm.setClassification(classification); + } + // 学历 + if (vo.getEducationlevel() != null) { + int educationlevel = getEducationlevel(vo + .getEducationlevel()); + hrm.setEducationlevel(educationlevel); + } + + // 工会会员,默认为是 + String islabouunion = "是".equals(vo.getIslabouunion()) ? "1" : "0"; + hrm.setIslabouunion(islabouunion); + + // 健康状况 + if (vo.getHealthinfo() != null) { + String healthinfo = getHealthinfo(vo.getHealthinfo()); + hrm.setHealthinfo(healthinfo); + } else { + hrm.setHealthinfo("0"); + } + + //安全级别不能大于999 + if (Util.getIntValue(vo.getSeclevel(), 0) > 999) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(515522, userlanguage))); + continue; + } + //安全级别不能小于-999 + if (Util.getIntValue(vo.getSeclevel(), 0) < -999) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(515523, userlanguage))); + continue; + } + //安全级别必须是数字 + if (!Util.null2String(vo.getSeclevel()).equals("")) { + if (Util.getIntValue(vo.getSeclevel(), -1000) == -1000) { + resultList.add(createLog(vo, "创建", "失败", "安全级别必须是数字")); + continue; + } else { + hrm.setSeclevel((short) Util.getIntValue(vo.getSeclevel())); + } + } else { + //安全级别为空时取缓存类中的安全级别 + hrm.setSeclevel((short) (0)); + } + + //职级 + if (isInteger(vo.getJoblevel())) { + int joblevel = vo.getJoblevel().equals("") ? 0 : Integer.parseInt(vo.getJoblevel()); + hrm.setJoblevel((short) joblevel); + } else { + hrm.setJoblevel((short) 0); + } + //用工性质 + if (vo.getUsekind() != null) { + int usekind = getUseKind(vo.getUsekind()); + hrm.setUsekind(usekind); + } else { + hrm.setUsekind(0); + } + //如果新增导入的时候,登陆名不为空,需要校验一下当前的license + + + // 手机 办公电话 + CheckItemBean mobileBean = new CheckItemBean("mobile", vo.getMobile()); + ValidateFieldManager.validate(mobileBean); + if (!mobileBean.isPass()) { + resultList.add(createLog(vo, "创建", "失败", mobileBean.getCheckMsg())); + continue; + } + CheckItemBean telephoneBean = new CheckItemBean("telephone", vo.getTelephone()); + ValidateFieldManager.validate(telephoneBean); + if (!telephoneBean.isPass()) { + resultList.add(createLog(vo, "创建", "失败", telephoneBean.getCheckMsg())); + continue; + } + + + //id,非自动增长 + recordSet.executeProc("HrmResourceMaxId_Get", ""); + recordSet.next(); + id = recordSet.getInt(1); + hrm.setId(id); + + + //密码 加密 + String password_tmp = Util.null2String(vo.getPassword()).trim(); + if ("".equals(password_tmp)) { + password_tmp = "1"; + //人员导入文件中,将密码这一列删除或者密码这一列存在,但是不填写都默认为初始密码 + if (defaultPasswordEnable) { + if (!defaultPassword.equals("")) { + if (weakPasswordDisable && this.hrmWeakPasswordUtil.isWeakPsd(defaultPassword)) { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(515436, userlanguage))); + continue; + } else { + password_tmp = defaultPassword; + } + } else { + resultList.add(createLog(vo, "创建", "失败", SystemEnv.getHtmlLabelName(516347, userlanguage))); + continue; + } + } + } + + String[] encrypts = PasswordUtil.encrypt(password_tmp); + HrmFaceCheckManager.setUserPassowrd(id + "", password_tmp); + + String password = encrypts[0]; + String salt = encrypts[1]; + hrm.setPassword(password); + + boolean flag = true; + + /*添加人员信息*/ + String insertStr = "insert into hrmResource("; + StringBuilder insertFields = new StringBuilder(); + StringBuilder insertValues = new StringBuilder(); + + String workcode = vo.getWorkcode(); + workcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.USER, String.valueOf(hrm.getSubcompanyid1()), String.valueOf(hrm.getDepartmentid()), String.valueOf(hrm.getJobtitle()), workcode); + vo.setWorkcode(workcode); + + for (String s : fields) { + Field hrmField = hrmClass.getDeclaredField(s); + Field voField = voClass.getDeclaredField(s); + + String hrmFieldType = hrmField.getType().getName(); + String voFieldType = voField.getType().getName(); + + hrmField.setAccessible(true); + voField.setAccessible(true); + + //首先取hrm对象中的数据,没有去vo中的 + if (hrmField.get(hrm) != null) { + if (hrmFieldType.endsWith("String")) { + insertFields.append(s).append(","); + insertValues.append("'").append(hrmField.get(hrm)).append("',"); + } else if (hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float")) { + insertFields.append(s).append(","); + String insertValueStr = Util.null2String(hrmField.get(hrm)); + if ("".equals(insertValueStr) && recordSet.getDBType().equalsIgnoreCase("postgresql")) { + insertValues.append("null,"); + } else { + insertValues.append(hrmField.get(hrm)).append(","); + } + } + } else if (voField.get(vo) != null) { + if (voFieldType.endsWith("String")) { + if (recordSet.getDBType().equalsIgnoreCase("mysql") || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + if (Util.null2String(voField.get(vo)).equals("")) { + insertFields.append(s).append(","); + insertValues.append("null,"); + } else { + insertFields.append(s).append(","); + insertValues.append("'").append(voField.get(vo)).append("',"); + } + } else { + insertFields.append(s).append(","); + insertValues.append("'").append(voField.get(vo)).append("',"); + } + } else if (hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float")) { + insertFields.append(s).append(","); + String insertValueStr = Util.null2String(voField.get(vo)); + if ("".equals(insertValueStr) && recordSet.getDBType().equalsIgnoreCase("postgresql")) { + insertValues.append("null,"); + } else { + insertValues.append(voField.get(vo)).append(","); + } + + } + } + } + ChgPasswdReminder cpr = new ChgPasswdReminder(); + RemindSettings hrmsettings = cpr.getRemindSettings(); + insertStr = insertStr + insertFields + "createrid,createdate,lastmodid,lastmoddate,lastlogindate,managerstr,mobileshowtype ," + DbFunctionUtil.getInsertColumnSql() + ") values(" + + insertValues + createrid + ",'" + date + "'," + lastmodid + ",'" + lastmoddate + "','" + date + "','" + hrm.getManagerstr() + "'," + Util.getIntValue(hrmsettings.getMobileShowTypeDefault(), 0) + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), lastmodid) + ")"; + + + boolean resourceInsertFlag = true; + if (!execSql(insertStr)) {//添加人员信息 + flag = false; + resourceInsertFlag = false; + } + if (resourceInsertFlag) {// 仅当人员插入成功后才进行自定义字段操作 + PasswordUtil.updateResourceSalt(id + "", salt); + + if (updateBaseData(vo.getBaseFields(), vo.getBaseFieldsValue(), id)) //添加基础字段信息 + flag = false; + if (updatePersonData(vo.getPersonFields(), vo.getPersonFieldsValue(), id)) //添加个人字段信息 + flag = false; + if (updateWorkData(vo.getWorkFields(), vo.getWorkFieldsValue(), id)) //添加工作字段信息 + flag = false; + } + + /*添加人员缓存,人员默认按id显示顺序,HrmResource_Trigger_Insert 人员共享 入职维护项目状态*/ + if (flag) { + + //HrmUserSettingManager.checkUserSettingInit(id) ; + + //人员显示顺序 + if (vo.getDsporder() == null) { + String taxissql = ("update HrmResource set dsporder = " + id + " where id = " + id); + recordSet.executeSql(taxissql); + } + //构建pinyin快速搜索 + if (vo.getLastname() != null) { + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(vo.getLastname()); + String sqlStr = "update HrmResource set pinyinlastname = ?, ecology_pinyin_search = ? where id = ?"; + recordSet.executeUpdate(sqlStr, quickSearchStr, quickSearchStr, id); + } + + //触发器 + String para = "" + id + separator + hrm.getManagerid() + separator + hrm.getDepartmentid() + separator + hrm.getSubcompanyid1() + separator + hrm.getSeclevel() + separator + hrm.getManagerstr(); + recordSet.executeProc("HrmResource_Trigger_Insert", para); + + //共享信息 + /*String p_para = "" + id + separator + hrm.getDepartmentid() + separator + hrm.getSubcompanyid1() + separator + hrm.getManagerid() + separator + hrm.getSeclevel() + separator + hrm.getManagerstr() + separator + "0" + separator + "0" + separator + "0" + separator + "0" + separator + "0" + separator + "0"; + recordSet.executeProc("HrmResourceShare", p_para);*/ + + //入职维护状态 + String sql_1 = ("insert into HrmInfoStatus (itemid,hrmid,status) values(1," + id + ",1)"); + recordSet.executeSql(sql_1); + String sql_2 = ("insert into HrmInfoStatus (itemid,hrmid) values(2," + id + ")"); + recordSet.executeSql(sql_2); + String sql_3 = ("insert into HrmInfoStatus (itemid,hrmid) values(3," + id + ")"); + recordSet.executeSql(sql_3); + + String sql_10 = ("insert into HrmInfoStatus (itemid,hrmid) values(10," + id + ")"); + recordSet.executeSql(sql_10); + + HrmFaceCheckManager.sync(id + "", HrmFaceCheckManager.getOptInsert(), "hrm_e9_import_resource", HrmFaceCheckManager.getOaResource()); + + new HrmDateCheck().calWorkInfo("" + id); + + } + + /*写日志*/ + if (flag) { + resultList.add(createLog(vo, "创建", "成功", "")); + if (!"".equals(vo.getLoginid())) { + rtxService.addUser(id);//添加到rtx + } + } else { + resultList.add(createLog(vo, "创建", "失败", "系统错误,请联系管理员")); + } + + } else { //更新人员 + if (keyMap.get(key) == null) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83535, userlanguage))); + continue; + } + + vo.setId(Util.getIntValue(keyMap.get(key)));//设置id + if (this.checkInfo(vo, resultList)) { + continue; + } + + if (vo.getAccounttype() == null || "".equalsIgnoreCase(Util.null2String(vo.getAccounttype()))) { + if (StringUtil.isNotNull(vo.getCertificatenum()) && certificateNums.get(StringUtil.vString(vo.getCertificatenum())) != null) { + if (StringUtil.parseToInt(String.valueOf(keyMap.get(key))) != StringUtil.parseToInt(String.valueOf(certificateNums.get(StringUtil.vString(vo.getCertificatenum()))))) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } + } else { + if (vo.getAccounttype() != null && !"".equals(vo.getAccounttype())) { + if ("主账号".equals(vo.getAccounttype())) { + if (StringUtil.isNotNull(vo.getCertificatenum()) && certificateNums.get(StringUtil.vString(vo.getCertificatenum())) != null) { + if (StringUtil.parseToInt(String.valueOf(keyMap.get(key))) != StringUtil.parseToInt(String.valueOf(certificateNums.get(StringUtil.vString(vo.getCertificatenum()))))) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } + } + } + } + + final String hrmId = String.valueOf(keyMap.get(key)); + + //分部id + String subCompanyNames = vo.getSubcompanyid1(); + boolean issameSub = true; + if (!"".equals(Util.null2String(subCompanyNames))) { + if (!subCompanyNames.equals(subCompanyName)) { + subCompanyName = subCompanyNames; + subcompanyid1 = getSubCompanyId(subCompanyName); + issameSub = false; + + } + if (subcompanyid1 == -9) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); + continue; + } + if (subcompanyid1 == -2) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + continue; + } + if (subcompanyid1 == 0 || subcompanyid1 == -1) { + resultList.add(createLog(vo, "更新", "失败", subcompanyid1 == 0 ? SystemEnv.getHtmlLabelName(83536, userlanguage) : SystemEnv.getHtmlLabelName(83524, userlanguage))); + continue; + } + + //qc139575 在验证并发非并发之前需要先CkHrmnum + license.CkHrmnum(); + if (StringUtil.parseToInt(license.getConcurrentFlag(), 0) != 1) { + if (!issameSub && new HrmResourceManager().noMore(String.valueOf(subcompanyid1))) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83525, userlanguage))); + continue; + } + } + hrm.setSubcompanyid1(subcompanyid1); + } + + // 部门id + String departmentNames = vo.getDepartmentid(); + if (!"".equals(Util.null2String(departmentNames))) { //部门存在时 + if (!issameSub || !departmentNames.equals(departmentName)) { + departmentName = departmentNames; + departmentid = getDeptId(departmentName, subcompanyid1); + + if (departmentid == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83537, userlanguage))); + continue; + } + if (departmentid == -2) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + } else { //add sjh 50102需要考虑不同公司名称相同部门架构情况 此时部门ID是不同的 + departmentid = getDeptId(departmentName, subcompanyid1); + if (departmentid == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83537, userlanguage))); + continue; + } + if (departmentid == -2) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + } + hrm.setDepartmentid(departmentid); + } + + //主账号id-sunjsh + if (vo.getAccounttype() != null && !"".equals(vo.getAccounttype())) { + if ("主账号".equals(vo.getAccounttype())) { + hrm.setBelongto(-1); + hrm.setAccounttype(0); + } else if ("次账号".equals(vo.getAccounttype())) { + if (vo.getBelongto() != null && !"".equals(vo.getBelongto().trim())) { + int belongto = getBelongId(vo.getBelongto(), keyField); + hrm.setBelongto(belongto); + if (!vo.getBelongto().equals("") && belongto == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(1); + } + } else { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } + } else { + hrm.setBelongto(-1); + hrm.setAccounttype(0); + } + } else if (vo.getBelongto() != null && !"".equals(vo.getBelongto().trim())) { + int belongto = getBelongId(vo.getBelongto(), keyField); + hrm.setBelongto(belongto); + if (!vo.getBelongto().equals("") && belongto == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(1); + } + } + + // 岗位id + if ("".equals(Util.null2String(vo.getJobtitle())) && (!"".equals(Util.null2String(vo.getJobactivityid())) || !"".equals(Util.null2String(vo.getJobgroupid())))) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83544, userlanguage))); + continue; + } + if (!"".equals(Util.null2String(vo.getJobtitle()))) { + String jobtitle; + String jobactivityid; + String jobactivityname; + String jobgroupid; + String jobgroupname; + if (vo.getJobactivityid() == null) { + jobtitle = resourcecominfo.getJobTitle(hrmId); + jobactivityid = jobTitlesComInfo.getJobactivityid(jobtitle); + jobactivityname = jobActivitiesComInfo.getJobActivitiesname(jobactivityid); + } else + jobactivityname = vo.getJobactivityid(); + if (vo.getJobgroupid() == null) { + jobtitle = resourcecominfo.getJobTitle(hrmId); + jobactivityid = jobTitlesComInfo.getJobactivityid(jobtitle); + jobgroupid = jobActivitiesComInfo.getJobgroupid(jobactivityid); + jobgroupname = jobGroupsComInfo.getJobGroupsname(jobgroupid); + } else { + jobgroupname = vo.getJobgroupid(); + } + int jobtitleid = getJobTitles(vo.getJobtitle(), jobactivityname, jobgroupname); + if (jobtitleid == -1) { + resultList.add(createLog(vo, "创建", "失败", "职务类别不存在")); + continue; + } else if (jobtitleid == -2) { + resultList.add(createLog(vo, "创建", "失败", "职务不存在")); + continue; + } else if (jobtitleid == -3) { + resultList.add(createLog(vo, "创建", "失败", "岗位名称不存在")); + continue; + } + hrm.setJobtitle(jobtitleid); + } + + if (Util.getIntValue(hrmId) < 0) continue; + + //上级id + String managerstr = ""; //所有上级 + String oldmanagerstr = resourcecominfo.getManagersIDs(hrmId);//原来的所有上sex + // 级序列 + if (!"".equals(Util.null2String(vo.getManagerid()))) { + int managerid = 0; // 上级Id + + Map managerInfo = getManagerIdAndStr(hrmId, vo.getManagerid(), keyField); + if (managerInfo != null) { + managerid = managerInfo.get("managerid") != null ? (Integer) managerInfo.get("managerid") : 0; + managerstr = (String) (managerInfo.get("managerstr") != null ? managerInfo.get("managerstr") : ""); + } + + //如果vo.getManagerid()有值,但manageid未找到,说明填写有误 + if (vo.getManagerid() != null && !vo.getManagerid().equals("") && managerid == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83532, userlanguage))); + continue; + } + hrm.setManagerid(managerid); + hrm.setManagerstr(managerstr); + } else { + if (vo.getManagerid() == null) { + hrm.setManagerid(StringUtil.parseToInt(resourcecominfo.getManagerID(hrmId), 0)); + hrm.setManagerstr(resourcecominfo.getManagersIDs(hrmId)); + managerstr = resourcecominfo.getManagersIDs(hrmId); + vo.setManagerid(resourcecominfo.getManagerID(hrmId)); + } else { + hrm.setManagerid(0); + hrm.setManagerstr(""); + } + } + // 助理id + if (!"".equals(Util.null2String(vo.getAssistantid()))) { + int assistantid; + assistantid = getAssistantid(vo.getAssistantid(), keyField); + if (vo.getAssistantid() != null && !vo.getAssistantid().equals("") && assistantid == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(24678, userlanguage))); + continue; + } + hrm.setAssistantid(assistantid); + } + // 办公地点 + if (!"".equals(Util.null2String(vo.getLocationid()))) { + int locationid = getLocationid(vo.getLocationid()); + hrm.setLocationid(locationid); + } + + //邮箱-sunjsh + if (vo.getEmail() != null) { + if (!"".equals(vo.getEmail().trim()) && vo.getEmail().contains("*")) { + vo.setEmail(null); + } else if ("".equals(vo.getEmail().trim())) { + hrm.setEmail(""); + } else { + Pattern pattern = Pattern.compile("^([a-zA-Z0-9_\\-]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(?)$"); + Matcher matcher = pattern.matcher(vo.getEmail()); + if (!matcher.matches()) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(24570, userlanguage))); + continue; + } else { + hrm.setEmail(vo.getEmail()); + } + } + } + + //mobile-sunjsh + if (vo.getMobile() != null) { + if ("".equals(vo.getMobile().trim())) + hrm.setMobile(""); + else if (!"".equals(vo.getMobile().trim()) && vo.getMobile().contains("*")) + vo.setMobile(null); + } + + //工资银行-sunjsh + if (vo.getBankid1() != null && !"".equals(vo.getBankid1())) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", 0); + jsonObject.put("fieldhtmltype", 3); + jsonObject.put("type", 284); + jsonObject.put("dmlurl", ""); + jsonObject.put("fieldvalue", vo.getBankid1()); + + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + if (!"".equals(fieldvalue)) { + hrm.setBankid1(new Integer(fieldvalue)); + } else { +// vo.setBankid1(null); + hrm.setBankid1(this.getBankId(vo.getBankid1())); + } + } + + //sunjsh-入职日期 + if (vo.getCompanystartdate() != null && !"".equals(vo.getCompanystartdate())) { + hrm.setCompanystartdate(vo.getCompanystartdate()); +// hrm.setCompanyworkyear(this.calculateDate(vo.getCompanystartdate())); + } else { + vo.setCompanystartdate(null); + } + + //sunjsh-参加工作日期 + if (vo.getWorkstartdate() != null && !"".equals(vo.getWorkstartdate())) { + hrm.setWorkstartdate(vo.getWorkstartdate()); +// hrm.setWorkyear(this.calculateDate(vo.getWorkstartdate())); + } else { + vo.setWorkstartdate(null); + } + // 职称 + if (!"".equals(Util.null2String(vo.getJobcall()))) { + int jobcall = getJobcall(vo.getJobcall()); + hrm.setJobcall(jobcall); + } + // 系统语言,默认简体中文 + if (!"".equals(Util.null2String(vo.getSystemlanguage()))) { + int systemlanguage = getSystemlanguage(vo.getSystemlanguage()); + + if (systemlanguage == -1) { //只能选择简体中文|Englisth|繁体中文 + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(518929, userlanguage))); + continue; + } + //系统不支持多语言 + if (systemlanguage == 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(84810, userlanguage))); + continue; + } + hrm.setSystemlanguage(systemlanguage); + } + + // 性别,为空或其他情况统一为0(男) + if (!"".equals(Util.null2String(vo.getSex()))) { + String sex = vo.getSex().equals("女") ? "1" : "0"; + hrm.setSex(sex); + } + + // 婚姻状况,如果不是以下选项,则默认为未婚 + if (!"".equals(Util.null2String(vo.getMaritalstatus()))) { + String maritalstatus = vo.getMaritalstatus().equals("已婚") ? "1" + : vo.getMaritalstatus().equals("离异") ? "2" : "0"; + hrm.setMaritalstatus(maritalstatus); + } + + // 员工状态 + if (!"".equals(Util.null2String(vo.getStatus()))) { + int status = getStatus(vo.getStatus()); + hrm.setStatus(status); + } + + // 人员密级 + if (!"".equals(Util.null2String(vo.getClassification()))) { + int classification = getClassification(vo.getClassification()); + hrm.setClassification(classification); + } + + // 学历 + if (!"".equals(Util.null2String(vo.getEducationlevel()))) { + int educationlevel = getEducationlevel(vo + .getEducationlevel()); + hrm.setEducationlevel(educationlevel); + } + + // 工会会员,默认为是 + if (!"".equals(Util.null2String(vo.getIslabouunion()))) { + String islabouunion = vo.getIslabouunion().equals("是") ? "1" + : "0"; + hrm.setIslabouunion(islabouunion); + } + + // 健康状况 + if (!"".equals(Util.null2String(vo.getHealthinfo()))) { + String healthinfo = getHealthinfo(vo.getHealthinfo()); + hrm.setHealthinfo(healthinfo); + } + + //安全级别不能大于999 + if (Util.getIntValue(vo.getSeclevel(), 0) > 999) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(515522, userlanguage))); + continue; + } + //安全级别不能小于-999 + if (Util.getIntValue(vo.getSeclevel(), 0) < -999) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(515523, userlanguage))); + continue; + } + //安全级别必须是数字 + if (!Util.null2String(vo.getSeclevel()).equals("")) { + if (Util.getIntValue(vo.getSeclevel(), -1000) == -1000) { + resultList.add(createLog(vo, "更新", "失败", "安全级别必须是数字")); + continue; + } else { + hrm.setSeclevel((short) Util.getIntValue(vo.getSeclevel())); + } + } else { + //安全级别为空时取缓存类中的安全级别 + hrm.setSeclevel(Short.parseShort(resourcecominfo.getSeclevel(hrmId))); + } + + //职级 + if (isInteger(vo.getJoblevel())) { + int joblevel = vo.getJoblevel().equals("") ? 0 : Integer.parseInt(vo.getJoblevel()); + hrm.setJoblevel((short) joblevel); + } + + //用工性质 + if (vo.getUsekind() != null) { + int usekind = getUseKind(vo.getUsekind()); + hrm.setUsekind(usekind); + } + + + //更新导入的时候,如果登录名不为空,需要校验一下当前的license + if (needCheckLicenseForUpdate(resourcecominfo, hrmId, vo)) { + license.reloadLicenseInfo(); + if (license.CkHrmnum() >= 0) { + resultList.add(createLog(vo, "更新", "失败", SystemEnv.getHtmlLabelName(83522, userlanguage))); + continue; + } + } + + // 手机 办公电话 + CheckItemBean mobileBean = new CheckItemBean("mobile", vo.getMobile()); + ValidateFieldManager.validate(mobileBean); + if (!mobileBean.isPass()) { + resultList.add(createLog(vo, "更新", "失败", mobileBean.getCheckMsg())); + continue; + } + CheckItemBean telephoneBean = new CheckItemBean("telephone", vo.getTelephone()); + ValidateFieldManager.validate(telephoneBean); + if (!telephoneBean.isPass()) { + resultList.add(createLog(vo, "更新", "失败", telephoneBean.getCheckMsg())); + continue; + } + + + //密码 加密 + if (!"".equals(Util.null2String(vo.getPassword()))) { + + String orgPwd = "1"; + if (!"".equals(vo.getPassword())) orgPwd = vo.getPassword(); + String[] pwdArr = PasswordUtil.encrypt(orgPwd); + String salt = pwdArr[1]; + hrm.setPassword(pwdArr[0]); + + PasswordUtil.updateResourceSalt(keyMap.get(key) + "", salt); + HrmFaceCheckManager.setUserPassowrd(keyMap.get(key) + "", orgPwd); + + } + boolean flag = true; + + StringBuilder updateStr = new StringBuilder("update hrmresource set "); + + String tmpstatus = ""; + //k从1开始,id不是update字段 +// String workcode = vo.getWorkcode(); +// workcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.USER, String.valueOf(hrm.getSubcompanyid1()), String.valueOf(hrm.getDepartmentid()), String.valueOf(hrm.getJobtitle()), workcode); +// vo.setWorkcode(workcode); + for (int k = 1; k < fields.length; k++) { + Field hrmField = hrmClass.getDeclaredField(fields[k]); + Field voField = voClass.getDeclaredField(fields[k]); + + String hrmFieldType = hrmField.getType().getName(); + String voFieldType = voField.getType().getName(); + + hrmField.setAccessible(true); + voField.setAccessible(true); + + if (Util.null2String(hrmField.get(hrm)).trim().length() > 0) { + if (hrmFieldType.endsWith("String")) + updateStr.append(fields[k]).append("='").append(hrmField.get(hrm)).append("',"); + else if (hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float")) { + updateStr.append(fields[k]).append("=").append(hrmField.get(hrm)).append(","); + } + + if (fields[k].equals("status")) { + tmpstatus = Util.null2String(hrmField.get(hrm)); + } + } else if (Util.null2String(voField.get(vo)).trim().length() > 0) { + if (voFieldType.endsWith("String")) { + if (recordSet.getDBType().equalsIgnoreCase("mysql") || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + if (Util.null2String(voField.get(vo)).equals("")) { + updateStr.append(fields[k]).append("=null,"); + } else { + updateStr.append(fields[k]).append("='").append(voField.get(vo)).append("',"); + } + } else { + updateStr.append(fields[k]).append("='").append(voField.get(vo)).append("',"); + } + } else if (voFieldType.endsWith("Integer") || voFieldType.endsWith("Short") || voFieldType.endsWith("Float")) { + if (voFieldType.endsWith("Integer") && (voField.get(vo).equals(0x7fffffff))) { + updateStr.append(fields[k]).append("=null,"); + } else { + updateStr.append(fields[k]).append("=").append(voField.get(vo)).append(","); + } + } + if (fields[k].equals("status")) tmpstatus = Util.null2String(voField.get(vo)); + } + } + + updateStr.append(" lastmodid=").append(lastmodid).append(",lastmoddate='").append(lastmoddate).append("',managerstr='").append(hrm.getManagerstr()).append("',").append(DbFunctionUtil.getUpdateSetSql(new RecordSet().getDBType(), lastmodid)).append(" where id=").append(keyMap.get(key)); + + if (!execSql(updateStr.toString())) + flag = false; + + //同步密码到AD + if (flag && !"".equals(Util.null2String(vo.getPassword()))) { + String userid = Util.null2String(keyMap.get(key)); + String loginid = Util.null2String(resourcecominfo.getLoginID(userid)); + String isADAccount = Util.null2String(isADAccountMap.get(userid)); + if ("1".equals(isADAccount) && !"1".equals(userid) && new AuthenticUtil().checkType(loginid)) { + Map map = new HashMap<>(); + map.put("userid", userid);//OA人员id + map.put("loginid", loginid);//人员帐号 + map.put("password", Util.null2String(vo.getPassword()));//新密码 + map.put("issysadmin", "true");//是否需要检验旧密码。0,是检验。1,不需要检验。 + String optype = "4"; //1,强制修改密码操作。2,首次登录密码操作,3,忘记密码找回。其它,系统修改ad操作。 + map.put("optype", optype); + Map retInfo = new OaSync("", "").modifyADPWDNew(map); + if (Util.null2String(retInfo.get("code")).equals("0")) { + //更新修改密码时间 + String passwdchgdate = Util.null2String(TimeUtil.getCurrentDateString()); + flag = recordSet.executeUpdate("update hrmresource set passwdchgdate=?, haschangepwd='y' where id = ?", passwdchgdate, userid); + } else { + flag = false; + writeLog("人员导入,更新人员密码,同步至AD失败___retInfo___" + com.alibaba.fastjson.JSONObject.toJSONString(retInfo)); + } + } + } + + //如果更新为解聘、离职、退休,处理相关数据 + if (("4".equals(tmpstatus) || "5".equals(tmpstatus) || "6".equals(tmpstatus)) && !tmpstatus.equals(resourcecominfo.getStatus("" + keyMap.get(key)))) { + OrganisationCom orgCom = new OrganisationCom(); + HrmServiceManager hrmaction = new HrmServiceManager(); + String tmpid; + String type = "5"; + String procType = "HrmResource_Dismiss"; + String statusType = "5"; + if ("4".equals(tmpstatus)) { + type = "1"; + procType = "HrmResource_Fire"; + statusType = "4"; + } else if ("6".equals(tmpstatus)) { + type = "6"; + procType = "HrmResource_Retire"; + statusType = "6"; + } + int resourceid = keyMap.get(key); + String changedate = TimeUtil.getCurrentDateString(); + String changereason = SystemEnv.getHtmlLabelName(17887, userlanguage); + String changecontractid = ""; + String infoman = ""; + String oldjobtitleid = resourcecominfo.getJobTitle("" + resourceid); + String para = "" + resourceid + separator + changedate + separator + changereason + separator + changecontractid + separator + infoman + separator + oldjobtitleid + separator + type + separator + "1"; + recordSet.executeProc(procType, para); + recordSet.executeSql("select max(id) from HrmStatusHistory"); + recordSet.next(); + tmpid = recordSet.getString(1); + + //删除角色成员 + recordSet.executeSql("delete from hrmrolemembers where resourcetype =1 and resourceid=" + resourceid); + //删除手机版中设置的登录人员 + recordSet.executeSql("delete from PluginLicenseUser where plugintype='mobile' and sharetype='0' and sharevalue='" + resourceid + "'"); + //更新人员未离职,清空账号 + recordSet.executeSql("update HrmResource set status = " + statusType + " ,loginid='',password='',account='', email='', tokenkey='', lastmoddate='" + changedate + "' where id = " + resourceid); + //删除自定义组成员 + recordSet.executeSql("delete hrmgroupmembers where userid=" + resourceid); + //更新变更记录状态为已处理 + recordSet.executeSql("update HrmStatusHistory set isdispose = 1 where id=" + tmpid); + boolean exist = orgCom.checkUser(resourceid); + if (exist) { + orgCom.deleteUser2(resourceid); + } + //OA与第三方接口单条数据同步方法开始 + hrmaction.SynInstantHrmResource("" + resourceid, "3"); + //OA与第三方接口单条数据同步方法结束 + } + + if (updateBaseData(vo.getBaseFields(), vo.getBaseFieldsValue().trim(), keyMap.get(key))) + flag = false; + + if (updatePersonData(vo.getPersonFields(), vo.getPersonFieldsValue().trim(), keyMap.get(key))) + flag = false; + + if (updateWorkData(vo.getWorkFields().trim(), vo.getWorkFieldsValue(), keyMap.get(key))) + flag = false; + + /*update HrmResource_Trigger */ + if (flag) { + recordSet.executeSql("select id from HrmResource_Trigger where id=" + hrmId); + if (recordSet.next()) { + recordSet.executeSql("update HrmResource_Trigger set managerid=" + hrm.getManagerid() + ",departmentid=" + hrm.getDepartmentid() + ",subcompanyid1=" + hrm.getSubcompanyid1() + ",seclevel=" + hrm.getSeclevel() + ",managerstr='" + hrm.getManagerstr() + "' where id=" + hrmId); + } else { + String para = "" + hrmId + separator + hrm.getManagerid() + separator + hrm.getDepartmentid() + separator + hrm.getSubcompanyid1() + separator + hrm.getSeclevel() + separator + hrm.getManagerstr(); + recordSet.executeProc("HrmResource_Trigger_Insert", para); + } + + //构建pinyin快速搜索 + if (vo.getLastname() != null) { + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(vo.getLastname()); + String sqlStr = "update HrmResource set pinyinlastname = ?, ecology_pinyin_search = ? where id = ?"; + recordSet.executeUpdate(sqlStr, quickSearchStr, quickSearchStr, hrmId); + } + } + + //更新下级managerstr + if (flag && !"".equals(Util.null2String(vo.getManagerid()))) { + String temOldmanagerstr = "," + hrmId + oldmanagerstr; + temOldmanagerstr = temOldmanagerstr.endsWith(",") ? temOldmanagerstr : (temOldmanagerstr + ","); + String sql = "select id,departmentid,subcompanyid1,managerid,seclevel,managerstr from HrmResource where managerstr like '%" + temOldmanagerstr + "'"; + recordSet.executeSql(sql); + while (recordSet.next()) { + String nowmanagerstr = Util.null2String(recordSet.getString("managerstr")); + String resourceid = recordSet.getString("id"); + //指定上级为自身的情况,不更新自身上级 + if (hrmId.equals(resourceid)) + continue; + String nowmanagerstr2 = ""; + int index = nowmanagerstr.lastIndexOf(oldmanagerstr); + if (index != -1) { + if (!"".equals(managerstr)) { + nowmanagerstr2 = nowmanagerstr.substring(0, index) + ("".equals(oldmanagerstr) ? managerstr.substring(1) : managerstr); + } else { + nowmanagerstr2 = nowmanagerstr.substring(0, index) + ("".equals(oldmanagerstr) ? "" : ","); + } + + } + RecordSetTrans rst = new RecordSetTrans(); + rst.setAutoCommit(false); + try { + String para = resourceid + separator + nowmanagerstr2; + rst.executeProc("HrmResource_UpdateManagerStr", para); + rst.commit(); + } catch (Exception e) { + rst.rollback(); + writeLog(e); + } + + } + } + if (flag) { + + HrmFaceCheckManager.sync(keyMap.get(key) + "", HrmFaceCheckManager.getOptUpdate(), "hrm_e9_import_resource", HrmFaceCheckManager.getOaResource()); + new HrmDateCheck().calWorkInfo(hrmId); + resultList.add(createLog(vo, "更新", "成功", "")); + //qc313055 [80][90][缺陷]IM集成-解决人员导入更新人员信息时,无账号列时,IM同步会进行删除操作的问题 ---start + RecordSet rst = new RecordSet(); + if (vo.getLoginid() != null) { + + //此时resourcecominfo对象还没有更新,可以直接取 + if (!"".equals(vo.getLoginid())) { + if (!rtxService.checkUser(Integer.parseInt(hrmId))) { + rtxService.addUser(Integer.parseInt(hrmId));//更新人员rtx + } + } else { + rst.executeSql("select * from hrmresource where id='" + hrmId + "'"); + String loginid = ""; + if (rst.next()) { + loginid = rst.getString("loginid"); + } + if (loginid != null && !loginid.equals("")) { + if (!rtxService.checkUser(Integer.parseInt(hrmId))) { + rtxService.addUser(Integer.parseInt(hrmId));//更新人员rtx + } + } else { + rtxService.deleteUser2(Integer.parseInt(hrmId)); + } + + } + } else { + rst.executeSql("select * from hrmresource where id='" + hrmId + "'"); + String loginid = ""; + if (rst.next()) { + loginid = rst.getString("loginid"); + } + if (loginid != null && !loginid.equals("")) { + if (!rtxService.checkUser(Integer.parseInt(hrmId))) { + rtxService.addUser(Integer.parseInt(hrmId));//更新人员rtx + } + } else { + rtxService.deleteUser2(Integer.parseInt(hrmId)); + } + //qc313055 [80][90][缺陷]IM集成-解决人员导入更新人员信息时,无账号列时,IM同步会进行删除操作的问题 ---end + } + } else { + resultList.add(createLog(vo, "更新", "失败", "系统错误,请联系管理员")); + } + } + } catch (Exception e) { + //数据异常 + writeLog(e); + } + } + try { + HrmTlevelManager.setUpdate(); + } catch (Exception e) { + writeLog(e); + } + + //更新人员、分部、部门、职位、岗位、职位类型缓存 + + resourcecominfo.removeResourceCache(); + departmentComInfo.removeCompanyCache(); + subCompanyComInfo.removeCompanyCache(); + jobActivitiesComInfo.removeJobActivitiesCache(); + jobTitlesComInfo.removeJobTitlesCache(); + jobGroupsComInfo.removeCompanyCache(); + locationComInfo.removeLocationCache(); + useKindComInfo.removeUseKindCache(); + //初始化应用分权 + new weaver.hrm.appdetach.AppDetachComInfo().initSubDepAppData(); + + MapperProxyFactory.getProxy(JclImportHistoryMapper.class).updateHistoryStatus((long) this.pId, "over"); + } catch (Exception e) { + writeLog(e); + MapperProxyFactory.getProxy(JclImportHistoryMapper.class).updateHistoryStatus((long) this.pId, "error"); + } + } + + /** + * 插入基础自定义字段信息 + * + * @param baseFild 存储人员自定义数据的字段 + * @param baseValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean addBaseData(String baseFild, String baseValue, int id) { + if (baseFild == null || baseFild.equals("")) return true; + String[] baseValues = baseValue.split(";"); + String[] baseFields = baseFild.split(","); + String fielddbType; + String sql = ""; + String scopeId = "-1"; + EncryptUtil encryptUtil = new EncryptUtil(); + RecordSet recordSet = new RecordSet(); + try { + if (baseTypeMap == null) { + baseTypeMap = new HashMap<>(); + String baseSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=-1 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(baseSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + baseTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + + sql = "insert into cus_fielddata "; + StringBuilder valueStr = new StringBuilder(); + for (int i = 0; i < baseFields.length; i++) { + String fieldname = baseFields[i]; + JSONObject jsonObject = baseTypeMap.get(baseFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", baseValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId); + if (encryptFieldEntity != null && encryptFieldEntity.getIsEncrypt().equals("1")) { + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId, fieldvalue, fieldvalue)); + } + + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + valueStr.append(",").append("'").append(!fieldvalue.equals("") ? fieldvalue : "").append("'"); + else + valueStr.append(",").append(!fieldvalue.equals("") ? fieldvalue : "NULL"); + } + valueStr = new StringBuilder(valueStr.substring(1)); + sql += "(scope,scopeid,id," + baseFild + ") values('HrmCustomFieldByInfoType'," + -1 + "," + id + "," + valueStr + ")"; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return recordSet.execute(sql); + } + + + /** + * 更新基础自定义字段 + * + * @param baseFild 存储人员自定义数据的字段 + * @param baseValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean updateBaseData(String baseFild, String baseValue, int id) { + if (baseFild == null || baseFild.equals("")) return false; + + //检查cus_fielddata表中是否存在,对应id人员的基础自定义信息,如果不存在则向数据库添加 + RecordSet recordSet = new RecordSet(); + String checkbaseInfo = "select id from cus_fielddata where scope='HrmCustomFieldByInfoType' and scopeid=-1 and id=" + id; + recordSet.execute(checkbaseInfo); + if (!recordSet.next()) { + return !addBaseData(baseFild, baseValue, id); + } + + String[] baseValues = baseValue.split(";"); + String[] baseFields = baseFild.split(","); + String fielddbType; + String sql = ""; + String scopeId = "-1"; + EncryptUtil encryptUtil = new EncryptUtil(); + boolean flag = false; + try { + if (baseTypeMap == null) { + baseTypeMap = new HashMap<>(); + String personSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=-1 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(personSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + baseTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + + sql = "update cus_fielddata set "; + StringBuilder setStr = new StringBuilder(); + for (int i = 0; i < baseFields.length; i++) { + String fieldname = baseFields[i]; + JSONObject jsonObject = baseTypeMap.get(baseFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", baseValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId); + if (encryptFieldEntity != null && encryptFieldEntity.getIsEncrypt().equals("1")) { + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId, fieldvalue, fieldvalue)); + } + if (fieldvalue.startsWith(",")) fieldvalue = fieldvalue.substring(1); + if (fieldvalue.endsWith(",")) fieldvalue = fieldvalue.substring(0, fieldvalue.length() - 1); + if (!fieldvalue.equals("")) { + flag = true; + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + setStr.append(",").append(baseFields[i]).append("='").append(fieldvalue).append("'"); + else + setStr.append(",").append(baseFields[i]).append("=").append(fieldvalue); + } + } + sql += setStr.substring(1) + " where scope='HrmCustomFieldByInfoType' and scopeid=-1 and id=" + id; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return (flag && !recordSet.execute(sql)); + } + + + /** + * 插入个人自定义字段信息 + * + * @param personFild 存储人员自定义数据的字段 + * @param personValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean addPersonData(String personFild, String personValue, int id) { + if (personFild == null || personFild.equals("")) return true; + String[] personValues = personValue.split(";"); + String[] personFields = personFild.split(","); + String fielddbType; + String sql = ""; + String scopeId = "1"; + EncryptUtil encryptUtil = new EncryptUtil(); + RecordSet recordSet = new RecordSet(); + try { + if (personTypeMap == null) { + personTypeMap = new HashMap<>(); + String personSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=1 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(personSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + personTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + + sql = "insert into cus_fielddata "; + StringBuilder valueStr = new StringBuilder(); + for (int i = 0; i < personFields.length; i++) { + String fieldname = personFields[i]; + JSONObject jsonObject = personTypeMap.get(personFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", personValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId); + if (encryptFieldEntity != null && encryptFieldEntity.getIsEncrypt().equals("1")) { + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId, fieldvalue, fieldvalue)); + } + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + valueStr.append(",").append("'").append(!fieldvalue.equals("") ? fieldvalue : "").append("'"); + else + valueStr.append(",").append(!fieldvalue.equals("") ? fieldvalue : "NULL"); + } + valueStr = new StringBuilder(valueStr.substring(1)); + sql += "(scope,scopeid,id," + personFild + ") values('HrmCustomFieldByInfoType'," + 1 + "," + id + "," + valueStr + ")"; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return recordSet.execute(sql); + } + + + /** + * 更新个人自定义字段 + * + * @param personFild 存储人员自定义数据的字段 + * @param personValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean updatePersonData(String personFild, String personValue, int id) { + if (personFild == null || personFild.equals("")) return false; + //检查cus_fielddata表中是否存在,对应id人员的个人自定义信息,如果不存在则向数据库添加 + String checkWorkInfo = "select id from cus_fielddata where scope='HrmCustomFieldByInfoType' and scopeid=1 and id=" + id; + RecordSet recordSet = new RecordSet(); + recordSet.execute(checkWorkInfo); + if (!recordSet.next()) { + return !addPersonData(personFild, personValue, id); + } + + String[] personValues = personValue.split(";"); + String[] personFields = personFild.split(","); + String fielddbType; + String sql = ""; + String scopeId = "1"; + EncryptUtil encryptUtil = new EncryptUtil(); + boolean flag = false; + try { + if (personTypeMap == null) { + personTypeMap = new HashMap<>(); + String personSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=1 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(personSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + personTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + + sql = "update cus_fielddata set "; + StringBuilder setStr = new StringBuilder(); + for (int i = 0; i < personFields.length; i++) { + String fieldname = personFields[i]; + JSONObject jsonObject = personTypeMap.get(personFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", personValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId); + if (encryptFieldEntity != null && encryptFieldEntity.getIsEncrypt().equals("1")) { + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId, fieldvalue, fieldvalue)); + } + if (fieldvalue.startsWith(",")) fieldvalue = fieldvalue.substring(1); + if (fieldvalue.endsWith(",")) fieldvalue = fieldvalue.substring(0, fieldvalue.length() - 1); + if (!fieldvalue.equals("")) { + flag = true; + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + setStr.append(",").append(personFields[i]).append("='").append(fieldvalue).append("'"); + else + setStr.append(",").append(personFields[i]).append("=").append(fieldvalue); + } + } + sql += setStr.substring(1) + " where scope='HrmCustomFieldByInfoType' and scopeid=1 and id=" + id; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return (flag && !recordSet.execute(sql)); + } + + + /** + * 插入工作自定义字段 + * + * @param workField 存储工作信息自定义数据的字段 + * @param workValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean addWorkData(String workField, String workValue, int id) { + if (workField == null || workField.equals("")) { + return true; + } + String[] workValues = workValue.split(";"); + String[] workFields = workField.split(","); + String fielddbType; + String sql = ""; + String scopeId = "3"; + EncryptUtil encryptUtil = new EncryptUtil(); + RecordSet recordSet = new RecordSet(); + try { + if (workTypeMap == null) { + workTypeMap = new HashMap<>(); + String workSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=3 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(workSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + workTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + sql = "insert into cus_fielddata "; + StringBuilder valueStr = new StringBuilder(); + for (int i = 0; i < workFields.length; i++) { + String fieldname = workFields[i]; + JSONObject jsonObject = workTypeMap.get(workFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", workValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId); + if (encryptFieldEntity != null && encryptFieldEntity.getIsEncrypt().equals("1")) { + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId, fieldvalue, fieldvalue)); + } + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + valueStr.append(",").append("'").append(!fieldvalue.equals("") ? fieldvalue : "").append("'"); + else + valueStr.append(",").append(!fieldvalue.equals("") ? fieldvalue : "NULL"); + } + valueStr = new StringBuilder(valueStr.substring(1)); + sql += "(scope,scopeid,id," + workField + ") values('HrmCustomFieldByInfoType'," + 3 + "," + id + "," + valueStr + ")"; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return recordSet.execute(sql); + } + + + /** + * 更新工作自定义字段 + * + * @param workField 存储工作信息自定义数据的字段 + * @param workValue 自定义数据值 + * @param id 需要添加自定义信息的人员id + * @return + */ + public boolean updateWorkData(String workField, String workValue, int id) { + if (workField == null || workField.equals("")) return false; + + //检查cus_fielddata表中是否存在,对应id人员的工作自定义信息,如果不存在则向数据库添加 + String checkWorkInfo = "select id from cus_fielddata where scope='HrmCustomFieldByInfoType' and scopeid=3 and id=" + id; + RecordSet recordSet = new RecordSet(); + recordSet.execute(checkWorkInfo); + if (!recordSet.next()) { + return !addWorkData(workField, workValue, id); + } + + String[] workValues = workValue.split(";"); + String[] workFields = workField.split(","); + String fielddbType; + String sql = ""; + String scopeId = "3"; + EncryptUtil encryptUtil = new EncryptUtil(); + boolean flag = false; + try { + if (workTypeMap == null) { + workTypeMap = new HashMap<>(); + String workSql = "select t1.fieldid,t1.hrm_fieldlable,t1.ismand,t2.fielddbtype,t2.fieldhtmltype,t2.type,t1.dmlurl from cus_formfield t1, cus_formdict t2 where t1.scope='HrmCustomFieldByInfoType' and t1.scopeid=3 and t1.fieldid=t2.id order by t1.fieldorder"; + recordSet.execute(workSql); + while (recordSet.next()) { + String fieldid = Util.null2String(recordSet.getString("fieldid")); + String fielddbtype = Util.null2String(recordSet.getString("fielddbtype")); + String fieldhtmltype = Util.null2String(recordSet.getString("fieldhtmltype")); + String type = Util.null2String(recordSet.getString("type")); + String dmlurl = Util.null2String(recordSet.getString("dmlurl")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", fieldid); + jsonObject.put("fielddbtype", fielddbtype); + jsonObject.put("fieldhtmltype", fieldhtmltype); + jsonObject.put("type", type); + jsonObject.put("dmlurl", dmlurl); + workTypeMap.put("field" + recordSet.getInt("fieldid"), jsonObject); + } + } + + sql = "update cus_fielddata set "; + StringBuilder setStr = new StringBuilder(); + for (int i = 0; i < workFields.length; i++) { + String fieldname = workFields[i]; + JSONObject jsonObject = workTypeMap.get(workFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", workValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + EncryptFieldEntity encryptFieldEntity = new EncryptFieldConfigComInfo().getFieldEncryptConfig("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId); + if (encryptFieldEntity != null && encryptFieldEntity.getIsEncrypt().equals("1")) { + //是否需要加密 + fieldvalue = Util.null2String(encryptUtil.encryt("cus_fielddata", fieldname, "HrmCustomFieldByInfoType", scopeId, fieldvalue, fieldvalue)); + } + if (fieldvalue.startsWith(",")) fieldvalue = fieldvalue.substring(1); + if (fieldvalue.endsWith(",")) fieldvalue = fieldvalue.substring(0, fieldvalue.length() - 1); + if (!fieldvalue.equals("")) { + flag = true; + if (fielddbType.toLowerCase().startsWith("char") || fielddbType.toLowerCase().startsWith("varchar") || fielddbType.toLowerCase().startsWith("text")) + setStr.append(",").append(workFields[i]).append("='").append(fieldvalue).append("'"); + else + setStr.append(",").append(workFields[i]).append("=").append(fieldvalue); + } + } + + sql += setStr.substring(1) + " where scope='HrmCustomFieldByInfoType' and scopeid=3 and id=" + id; + } catch (Exception e) { + writeLog(e); + } + recordSet.setNoAutoEncrypt(true); + return (flag && !recordSet.execute(sql)); + } + + /** + * 根据分部名称获取分部Id + * + * @param subCompanyName 分部名称 eg:泛微广东>泛微深圳 + * @return + */ + public int getSubCompanyId(String subCompanyName) { + + String[] subCompanyNames = subCompanyName.split(">"); + if (subCompanyNames.length >= 10) { + return -9; + } + int currentId = 0; + int parentId = 0; + int iscanceled; + + String currentidsql; + String canceledsql; + String sql; + RecordSet recordSet = new RecordSet(); + + String supsubcomidConditon = DbDialectFactory.get(recordSet.getDBType()).isNull("supsubcomid", 0); + + for (String companyName : subCompanyNames) { + if (StringUtil.isNull(companyName)) continue; + + sql = "select id from HrmSubCompany where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(subcompanyname))," + userlanguage + ")))='" + + companyName.trim() + "' and " + supsubcomidConditon + "=" + parentId; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + sql = "select id from HrmSubCompany where ltrim(rtrim(convToMultiLang(ltrim(rtrim(subcompanyname))," + userlanguage + ")))='" + + companyName.trim() + "' and " + supsubcomidConditon + "=" + parentId; + } + currentidsql = sql + " and (canceled is null or canceled != 1)"; + currentId = getResultSetId(currentidsql); + + //added by wcd 2015-02-06 [限制分部数] + if (currentId == 0) { + canceledsql = sql + " and canceled='1' "; + iscanceled = getResultSetId(canceledsql); + if (iscanceled != 0) { + currentId = -2; + } + break; + } + parentId = currentId; + if (currentId != -1) + rtxService.addSubCompany(parentId); //同步RTX + } + return currentId; + } + + /** + * 获取部门id + * + * @param deptNames 部门名称 + * @param subCompanyId 所属分部id + * @return + */ + public int getDeptId(String deptNames, int subCompanyId) { + + String[] deptName = deptNames.split(">"); + int currentId = 0; + int parentId = 0; + int iscanceled; + + String currentidsql; + String canceledsql; + String sql; + + RecordSet recordSet = new RecordSet(); + + String supdepidConditon = DbDialectFactory.get(recordSet.getDBType()).isNull("supdepid", 0); + + for (String s : deptName) { + if (s == null || s.equals("")) { + continue; + } + + sql = "select id from HrmDepartment where subcompanyid1=" + subCompanyId + " and ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(departmentname))," + userlanguage + ")))='" + + s.trim() + "' and " + supdepidConditon + "=" + parentId; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + sql = "select id from HrmDepartment where subcompanyid1=" + subCompanyId + " and ltrim(rtrim(convToMultiLang(ltrim(rtrim(departmentname))," + userlanguage + ")))='" + + s.trim() + "' and " + supdepidConditon + "=" + parentId; + } + currentidsql = sql + " and (canceled !=1 or canceled is null)"; + currentId = getResultSetId(currentidsql); + + if (currentId == 0) { + canceledsql = sql + " and canceled='1' "; + iscanceled = getResultSetId(canceledsql); + if (iscanceled != 0) { + currentId = -2; + } + break; + } + parentId = currentId; + } + return currentId; + } + + /** + * 获取岗位id + * + * @param jobtitlename 岗位名称 + * @param jobactivityname 职务 + * @param jobgroupname 职务类别 + * @return -1:职务类别不存在,-2:职务不存在,-3:岗位名称不存在 + */ + public int getJobTitles(String jobtitlename, String jobactivityname, + String jobgroupname) { + RecordSet rs = new RecordSet(); + RecordSet recordSet = new RecordSet(); + String sqlInsert; + + jobgroupname = Util.convertInput2DB4(jobgroupname); + jobactivityname = Util.convertInput2DB4(jobactivityname); + + /* 获取jobgroupid 职务类别 */ + String selSql = "select id from HrmJobGroups where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(jobgroupname))," + userlanguage + ")))='" + jobgroupname + "'"; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id from HrmJobGroups where ltrim(rtrim(convToMultiLang(ltrim(rtrim(jobgroupname))," + userlanguage + ")))='" + jobgroupname + "'"; + } + + int jobgroupid = getResultSetId(selSql); + + if (jobgroupid == 0) { + return -1; + } + + /* 获取jobactivityid 职务 */ + selSql = "select id from HrmJobActivities where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(jobactivityname))," + userlanguage + ")))='" + jobactivityname + "' and jobgroupid=" + jobgroupid; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id from HrmJobActivities where ltrim(rtrim(convToMultiLang(ltrim(rtrim(jobactivityname))," + userlanguage + ")))='" + jobactivityname + "' and jobgroupid=" + jobgroupid; + } + + int jobactivityid = getResultSetId(selSql); + + if (jobactivityid == 0) { + return -2; + } + + /*获取岗位id*/ + selSql = "select id from HrmJobTitles where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(jobtitlemark))," + userlanguage + ")))='" + jobtitlename + "' and jobactivityid=" + jobactivityid; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id from HrmJobTitles where ltrim(rtrim(convToMultiLang(ltrim(rtrim(jobtitlemark))," + userlanguage + ")))='" + jobtitlename + "' and jobactivityid=" + jobactivityid; + } + + int jobtitle = getResultSetId(selSql); + + if (jobtitle == 0) { + return -3; + + } else { + selSql = "select * from HrmJobTitles where id = '" + jobtitle + "' and jobactivityid = '" + jobactivityid + "' "; + recordSet.executeSql(selSql); + if (!recordSet.next()) {//查询这个名称已存在的岗位,对应的职务是否存在。如果对应职务的岗位不存在,则说明岗位对应的职务和职务类别有更新 + sqlInsert = "update HrmJobTitles set jobactivityid = '" + jobactivityid + "'," + DbFunctionUtil.getUpdateSetSql(rs.getDBType(), 1) + " where id = '" + jobtitle + "' "; + rs.executeSql(sqlInsert); + } + } + return jobtitle; + } + + + public static boolean needCheckLicenseForUpdate(ResourceComInfo resourceComInfo, String hrmId, HrmResourceVo vo) { + String statusOfHrmId = resourceComInfo.getStatus(hrmId); + String loginidOfHrmId = resourceComInfo.getLoginID(hrmId); + String accouttypeOfHrmId = resourceComInfo.getAccountType(hrmId); + + String statusOfExcel = vo.getStatus(); + String loginidOfExcel = vo.getLoginid(); + String accouttypeOfExcel = vo.getAccounttype(); + + // 1. 历史状态算license 不检查 + if ("0,1,2,3".contains(statusOfHrmId) && StringUtils.isNotBlank(loginidOfHrmId) && !"1".equals(accouttypeOfHrmId)) { + return false; + } + boolean isStatus; + if (StringUtils.isBlank(statusOfExcel)) { + isStatus = "0,1,2,3".contains(statusOfHrmId); + } else { + isStatus = "正式,试用,临时,试用延期".contains(statusOfExcel); + } + boolean isLoginid; + if (StringUtils.isBlank(loginidOfExcel)) { + isLoginid = StringUtils.isNotBlank(loginidOfHrmId); + } else { + isLoginid = StringUtils.isNotBlank(loginidOfExcel); + } + boolean isAccouttype; + if (StringUtils.isBlank(accouttypeOfExcel)) { + isAccouttype = !"1".equals(accouttypeOfHrmId); + } else { + isAccouttype = "主账号".equals(accouttypeOfExcel); + } + + return isStatus && isLoginid && isAccouttype; + + } + + /** + * 获取直接上级Id和所有上级 + * + * @param keyFieldValue 上级标记值,eg:编号 + * @param keyField 关键字段 + * @return + */ + public Map getManagerIdAndStr(String hrmid, String keyFieldValue, String keyField) { + + int managerId; + String managerstr; + RecordSet recordSet = new RecordSet(); + Map managerInfo = new HashMap<>(); + if (!keyFieldValue.equals("")) { +// String selSql = "select id,managerstr from hrmResource where " + keyField + "='" + keyFieldValue + "'"; + String selSql = "select id,managerstr from hrmResource where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id,managerstr from hrmResource where ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + } + recordSet.execute(selSql); + while (recordSet.next()) { + managerId = recordSet.getInt("id"); + managerstr = recordSet.getString("managerstr"); + if (!hrmid.equals("" + managerId)) { //设置上级为自身的情况 + managerstr = "," + managerId + managerstr; + } else { + managerstr = "," + managerId + ","; + } + + managerstr = managerstr.endsWith(",") ? managerstr : (managerstr + ","); + managerInfo.put("managerid", managerId); + managerInfo.put("managerstr", managerstr); + } + } + return managerInfo; + } + + /** + * 获取助理id + * + * @param keyFieldValue 助理标记 + * @param keyField 关键字段 + * @return + */ + public int getAssistantid(String keyFieldValue, String keyField) { + + int getAssistantid = 0; + RecordSet recordSet = new RecordSet(); + if (!keyFieldValue.equals("")) { +// String selSql = "select id from hrmResource where " + keyField + "='" + keyFieldValue + "'"; + String selSql = "select id from hrmResource where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id from hrmResource where ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + } + getAssistantid = getResultSetId(selSql); + } + return getAssistantid; + } + + /** + * 获取主账号id + * + * @param keyFieldValue 主账号标记 + * @param keyField 关键字段 + * @return + */ + public int getBelongId(String keyFieldValue, String keyField) { + int getAssistantid = -1; + RecordSet recordSet = new RecordSet(); + if (!keyFieldValue.equals("")) { +// String selSql = "select id from hrmResource where " + keyField + "='" + keyFieldValue + "'"; + String selSql = "select id from hrmResource where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + selSql = "select id from hrmResource where ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + } + getAssistantid = getResultSetId(selSql); + } + return getAssistantid; + } + + /** + * 办公地点id + * + * @param locationname 办公地点名称 + * @return + */ + public int getLocationid(String locationname) { + int locationid = 0; + if (!locationname.equals("")) { + locationid = locationMap.getOrDefault(locationname, 0); + if (locationid == 0) { + String insertSql = "insert into HrmLocations(locationname,locationdesc,countryid) values('" + locationname + "','" + locationname + "',1)"; + execSql(insertSql); + String selSql = "select id from HrmLocations where countryid=1 and locationname='" + locationname + "'"; + locationid = getResultSetId(selSql); + locationMap.put(locationname, locationid); + } + } + return locationid; + } + + /** + * 用工性质id + * + * @param usekindname 用工性质名称 + * @return + */ + public int getUseKind(String usekindname) { + int usekindid = 0; + if (!usekindname.equals("")) { + usekindid = usekindMap.getOrDefault(usekindname, 0); + if (usekindid == 0) { + String insertSql = "insert into HrmUseKind(name,description) values('" + usekindname + "','" + usekindname + "')"; + execSql(insertSql); + String selSql = "select id from HrmUseKind where name='" + usekindname + "'"; + usekindid = getResultSetId(selSql); + usekindMap.put(usekindname, usekindid); + } + } + return usekindid; + } + + /** + * 职称 + * + * @param jobcall 职称名称 + * @return + */ + public int getJobcall(String jobcall) { + + int jobcalld = 0; + if (!jobcall.equals("")) { + jobcalld = jobcallMap.getOrDefault(jobcall, 0); + if (jobcalld == 0) { + String insertSql = "insert into HrmJobCall(name) values('" + jobcall + "')"; + execSql(insertSql); + String selSql = "select id from HrmJobCall where name='" + jobcall + "'"; + jobcalld = getResultSetId(selSql); + jobcallMap.put(jobcall, jobcalld); + } + } + return jobcalld; + } + + /** + * 系统语言 + * + * @param language 语言 eg:简体中文,English,繁體中文 + * @return + */ + public int getSystemlanguage(String language) { + int systemlanguageid = 7; //系统语言默认为中文 + + //系统只支持三种语言,如果是其他语言,提示输入有误 + //if (!(language.equals("English") || language.equals("繁體中文") || language.equals("简体中文")) && language != "") + //return -1; + + //如果系统不支持多语言,则返回0 + if ((language.equals("English") || language.equals("繁體中文")) && !multilanguage.equalsIgnoreCase("y")) + return 0; + + if (!language.equals("")) { + if (language.equals("简体中文")) + systemlanguageid = cnLanguageId; + else { + systemlanguageid = sysLanguage.getOrDefault(language, -1); + } + } + return systemlanguageid; + } + + /** + * 工资银行id + * + * @param bank1 办公地点名称 + * @return + */ + public int getBankId(String bank1) { + int id = 0; + if (!bank1.equals("")) { + String insertSql = "insert into hrmbank(bankname,bankdesc) values('" + bank1 + "','" + bank1 + "')"; + execSql(insertSql); + String selSql = "select id from hrmbank where bankname='" + bank1 + "'"; + id = getResultSetId(selSql); + } + return id; + } + + /** + * 获取员工状态 + * + * @param status 员工状态值 + * @return + */ + public int getStatus(String status) { + + int statusid; + switch (status) { + case "试用": + statusid = 0; + break; + case "正式": + statusid = 1; + break; + case "临时": + statusid = 2; + break; + case "试用延期": + statusid = 3; + break; + case "解聘": + statusid = 4; + break; + case "离职": + statusid = 5; + break; + case "退休": + statusid = 6; + break; + case "无效": + statusid = 7; + break; + default: + statusid = 1; + break; + } + return statusid; + } + + + public int getClassification(String classification) { + + int classificationid; + switch (classification) { + case "核心": + classificationid = 0; + break; + case "重要": + classificationid = 1; + break; + case "一般": + classificationid = 2; + break; + default: + classificationid = 3; + break; + } + return classificationid; + } + + /** + * 获取学历Id + * + * @param educationlevel 学历值 + * @return + */ + public int getEducationlevel(String educationlevel) { + int educationlevelid = 0; + if (!educationlevel.equals("")) { + educationlevelid = educationlevelMap.getOrDefault(educationlevel, 0); + if (educationlevelid == 0) { + String insertSql = "insert into HrmEducationLevel(name,description) values('" + educationlevel + "','" + educationlevel + "')"; + execSql(insertSql); + String selSql = "select id from HrmEducationLevel where name='" + educationlevel + "'"; + educationlevelid = getResultSetId(selSql); + educationlevelMap.put(educationlevel, educationlevelid); + } + } + return educationlevelid; + } + + /** + * 获取身体状况 + * + * @param healthinfo + * @return + */ + public String getHealthinfo(String healthinfo) { + + String healthinfoid; + + switch (healthinfo) { + case "良好": + healthinfoid = "1"; + break; + case "一般": + healthinfoid = "2"; + break; + case "较差": + healthinfoid = "3"; + break; + default: + healthinfoid = "0"; + break; + } + + return healthinfoid; + } + + /** + * 获取id与workcode_lastname 键值对,用于对导入数据重复性判断 + * + * @param keyField key值,重复性验证字段 + */ + public void getKeyMap(String keyField) { + RecordSet recordSet = new RecordSet(); + String sql; + sql = "select id, accounttype,isADAccount,certificatenum,loginid,workcode, ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + "))) as " + keyField + " from hrmResource"; + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sql = "select id, accounttype,isADAccount,certificatenum,loginid,workcode, ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + "))) as " + keyField + " from hrmResource"; + } + recordSet.execute(sql); + String cerNum; + while (recordSet.next()) { + for (String key : checkKeys) { + Map checkInfo = checkInfos.get(key); + if (checkInfo == null) { + checkInfo = new HashMap<>(); + checkInfos.put(key, checkInfo); + } else { + checkInfo = checkInfos.get(key); + } + String val = Util.null2String(recordSet.getString(key)); + checkInfo.put(val, recordSet.getString("id")); + checkInfos.put(key, checkInfo); + } + + cerNum = recordSet.getString("certificatenum"); + keyMap.put(recordSet.getString(keyField), recordSet.getInt("id")); + isADAccountMap.put(Util.null2String(recordSet.getString("id")), Util.null2String(recordSet.getString("isADAccount"))); + String accounttype = recordSet.getString("accounttype"); + if (!"1".equalsIgnoreCase(accounttype)) { + if (StringUtil.isNotNull(cerNum)) { + certificateNums.put(StringUtil.vString(cerNum), recordSet.getInt("id")); + } + } + } + + } + + + /** + * 执行插入操作 + * + * @param sql + * @return + */ + + public boolean execSql(String sql) { + RecordSet recordSet = new RecordSet(); + return recordSet.execute(sql); + } + + /** + * 获得查询结果Id + * + * @param sql 查询语句 + * @return + */ + public int getResultSetId(String sql) { + int currentId = 0; + RecordSet recordSet = new RecordSet(); + recordSet.execute(sql); + try { + while (recordSet.next()) { + currentId = recordSet.getInt("id"); + } + } catch (Exception e) { + e.printStackTrace(); + } + return currentId; + } + + /** + * 创建日志对象 + * + * @param vo HrmResourceVo 人员信息对象 + * @param operation 操作类型 验证|创建|更新 + * @param status 状态 成功|失败 + * @param reason 失败原因 + * @return ImportLog对象 + */ + public ImportLog createLog(HrmResourceVo vo, String operation, String status, String reason) { + ImportLog log = new ImportLog(); + + log.setWorkCode(vo.getWorkcode()); //编号 + log.setLastname(vo.getLastname()); //用户名 + log.setLoginid(vo.getLoginid()); //登录名 + log.setOperation(operation); //操作类型 + if (vo.getSubcompanyid1() != null && vo.getDepartmentid() != null) + log.setDepartment(vo.getSubcompanyid1() + ">" + vo.getDepartmentid()); //分部部门 + else + log.setDepartment(""); + log.setStatus(status); //状态,成功、失败 + log.setReason(reason); //原因 + + try { + String relatedName = ""; + switch (this.keyField) { + case "workcode": + relatedName = log.getWorkCode(); + break; + case "loginid": + relatedName = log.getLoginid(); + break; + case "lastname": + relatedName = log.getLastname(); + break; + } + MapperProxyFactory.getProxy(JclImportHistoryDetailMapper.class).insertHistoryDetail(JclImportHistoryDetailPO.builder().pid((long) this.pId).rowNums(this.rowNum + 1 + "").relatedName(relatedName).operateDetail(log.getStatus().equals("成功") ? relatedName + "导入成功!" : log.getReason()).status(log.getStatus().equals("成功") ? "1" : "0").build()); + } catch (Exception e) { + writeLog(e); + } + return log; + } + + //整数判断 + public static boolean isInteger(String str) { + if (str == null) + return false; + Pattern pattern = Pattern.compile("[0-9]+"); + return pattern.matcher(str).matches(); + } + + + private boolean checkInfo(HrmResourceVo hrmResourceVo, List resultList) { + //新增账号、工号唯一性校验 + for (String key : checkKeys) { + Map checkInfo = checkInfos.get(key); + if (checkInfo != null && !checkInfo.isEmpty()) { + String val = ""; + String errorMsg = ""; + switch (key) { + case "loginid": + val = Util.null2String(hrmResourceVo.getLoginid()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(522076, userlanguage); + break; + case "workcode": + val = Util.null2String(hrmResourceVo.getWorkcode()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(520197, userlanguage); + break; + case "certificatenum": + val = Util.null2String(hrmResourceVo.getCertificatenum()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(83521, userlanguage); + break; + } + int reosurceid = Util.getIntValue(checkInfo.get(val)); + if (hrmResourceVo.getId() != null && hrmResourceVo.getId() == reosurceid) { + //如果是当前记录,不需要校验 + continue; + } + + if (reosurceid > 0 && val.length() > 0) { + resultList.add(createLog(vo, this.operateType.equals("add") ? "创建" : "更新", "失败", errorMsg)); + return true; + } + } + } + return false; + } + + + public int getUserlanguage() { + return userlanguage; + } + + + public void setUserlanguage(int userlanguage) { + this.userlanguage = userlanguage; + } +} diff --git a/src/com/engine/organization/web/ImportCommonController.java b/src/com/engine/organization/web/ImportCommonController.java index 0c8c3b75..cea8e702 100644 --- a/src/com/engine/organization/web/ImportCommonController.java +++ b/src/com/engine/organization/web/ImportCommonController.java @@ -79,7 +79,7 @@ public class ImportCommonController { try { User user = HrmUserVarify.getUser(request, response); Map map = ParamUtil.request2Map(request); - return ReturnResult.successed(getImportCommonWrapper(user).saveImport(map)); + return ReturnResult.successed(getImportCommonWrapper(user).saveImport(map,request)); } catch (Exception e) { return ReturnResult.exceptionHandle(e); } diff --git a/src/com/engine/organization/wrapper/ImportCommonWrapper.java b/src/com/engine/organization/wrapper/ImportCommonWrapper.java index d2238c09..a42e234f 100644 --- a/src/com/engine/organization/wrapper/ImportCommonWrapper.java +++ b/src/com/engine/organization/wrapper/ImportCommonWrapper.java @@ -49,10 +49,11 @@ public class ImportCommonWrapper extends Service { * 导入数据 * * @param params + * @param request * @return */ - public Map saveImport(Map params) { - return getImportCommonService(user).saveImport(params); + public Map saveImport(Map params, HttpServletRequest request) { + return getImportCommonService(user).saveImport(params,request); } /**