From 4eef6f62def6bafb62a4f54cde509a155cb13c13 Mon Sep 17 00:00:00 2001 From: dxfeng Date: Tue, 28 Jun 2022 10:47:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=91=98=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../param/HrmResourceImportParam.java | 338 +++ .../HrmResourceImportAdaptService.java | 33 + .../HrmResourceImportProcessService.java | 28 + .../service/HrmResourceService.java | 3 + .../HrmResourceImportAdaptServiceImpl.java | 1070 ++++++++ .../HrmResourceImportProcessServiceImpl.java | 2337 +++++++++++++++++ .../service/impl/HrmResourceServiceImpl.java | 48 + .../web/HrmResourceController.java | 14 + .../wrapper/HrmResourceWrapper.java | 5 + 9 files changed, 3876 insertions(+) create mode 100644 src/com/engine/organization/entity/hrmresource/param/HrmResourceImportParam.java create mode 100644 src/com/engine/organization/service/HrmResourceImportAdaptService.java create mode 100644 src/com/engine/organization/service/HrmResourceImportProcessService.java create mode 100644 src/com/engine/organization/service/impl/HrmResourceImportAdaptServiceImpl.java create mode 100644 src/com/engine/organization/service/impl/HrmResourceImportProcessServiceImpl.java diff --git a/src/com/engine/organization/entity/hrmresource/param/HrmResourceImportParam.java b/src/com/engine/organization/entity/hrmresource/param/HrmResourceImportParam.java new file mode 100644 index 00000000..ea110eaf --- /dev/null +++ b/src/com/engine/organization/entity/hrmresource/param/HrmResourceImportParam.java @@ -0,0 +1,338 @@ +package com.engine.organization.entity.hrmresource.param; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * @author:dxfeng + * @createTime: 2022/06/27 + * @version: 1.0 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class HrmResourceImportParam { + /** + * id + */ + private Long id; + + /** + * work_code + */ + private String work_code; + + /** + * login_id + */ + private String login_id; + + /** + * last_name + */ + private String last_name; + + /** + * sex + */ + private String sex; + + /** + * account_type + */ + private String account_type; + + /** + * belong_to + */ + private String belong_to; + + /** + * company_id + */ + private String company_id; + + /** + * department_id + */ + private String department_id; + + /** + * job_activity + */ + private String job_activity; + + /** + * job_title + */ + private String job_title; + + /** + * job_call + */ + private String job_call; + + /** + * job_level + */ + private String job_level; + + /** + * job_group_id + */ + private String job_group_id; + + /** + * job_activity_desc + */ + private String job_activity_desc; + + /** + * status + */ + private String status; + + /** + * system_language + */ + private String system_language; + + /** + * resource_image_id + */ + private String resource_image_id; + + /** + * messager_url + */ + private String messager_url; + + /** + * location_id + */ + private String location_id; + + /** + * manager_id + */ + private String manager_id; + + /** + * assistant_id + */ + private String assistant_id; + + /** + * mobile + */ + private String mobile; + + /** + * telephone + */ + private String telephone; + + /** + * mobile_call + */ + private String mobile_call; + + /** + * fax + */ + private String fax; + + /** + * email + */ + private String email; + + /** + * workroom + */ + private String workroom; + + /** + * pass_word + */ + private String pass_word; + + /** + * sec_level + */ + private String sec_level; + + /** + * birthday + */ + private String birthday; + + /** + * folk + */ + private String folk; + + /** + * native_place + */ + private String native_place; + + /** + * reg_resident_place + */ + private String reg_resident_place; + + /** + * certificate_num + */ + private String certificate_num; + + /** + * marital_status + */ + private String marital_status; + + /** + * policy + */ + private String policy; + + /** + * be_member_date + */ + private String be_member_date; + + /** + * be_party_date + */ + private String be_party_date; + + /** + * islabouunion + */ + private String islabouunion; + + /** + * degree + */ + private String degree; + + /** + * health_info + */ + private String health_info; + + /** + * education_level + */ + private String education_level; + + /** + * height + */ + private String height; + + /** + * weight + */ + private Integer weight; + + /** + * use_kind + */ + private String use_kind; + + /** + * start_date + */ + private String start_date; + + /** + * end_date + */ + private String end_date; + + /** + * probation_end_date + */ + private String probation_end_date; + + /** + * resident_place + */ + private String resident_place; + + /** + * home_address + */ + private String home_address; + + /** + * temp_resident_number + */ + private String temp_resident_number; + + /** + * company_start_date + */ + private String company_start_date; + + /** + * work_start_date + */ + private String work_start_date; + + /** + * accum_fund_account + */ + private String accum_fund_account; + + /** + * account_name + */ + private String account_name; + + /** + * bank_id + */ + private String bank_id; + + /** + * account_id + */ + private String account_id; + + /** + * show_order + */ + private Integer show_order; + + /** + * classification + */ + private String classification; + + /** + * woprk_year + */ + private String work_year; + + /** + * company_work_year + */ + private String company_work_year; + + private String baseFieldsValue=""; + + private String baseFields=""; + + private Long creator; + private int deleteType; + private Date createTime; + private Date updateTime; +} diff --git a/src/com/engine/organization/service/HrmResourceImportAdaptService.java b/src/com/engine/organization/service/HrmResourceImportAdaptService.java new file mode 100644 index 00000000..eec22608 --- /dev/null +++ b/src/com/engine/organization/service/HrmResourceImportAdaptService.java @@ -0,0 +1,33 @@ +package com.engine.organization.service; + +import weaver.file.FileUploadToPath; + +import java.util.List; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2022/06/27 + * @version: 1.0 + */ +public interface HrmResourceImportAdaptService { + /** + * 用于生成需要导入系统的人员与组织架构数据并放入Map中,同时包含参数和数据有效性验证 + * 其格式是: + * + * @return 返回错误提示 + */ + List creatImportMap(FileUploadToPath fu); + + /** + * 获得HrmImportMap + * + * @return + */ + Map getHrmImportMap(); + + /** + * 传递同步的人员语言id + */ + void setUserlanguage(int userlanguage); +} diff --git a/src/com/engine/organization/service/HrmResourceImportProcessService.java b/src/com/engine/organization/service/HrmResourceImportProcessService.java new file mode 100644 index 00000000..b91db640 --- /dev/null +++ b/src/com/engine/organization/service/HrmResourceImportProcessService.java @@ -0,0 +1,28 @@ +package com.engine.organization.service; + +import com.engine.organization.entity.hrmresource.param.HrmResourceImportParam; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2022/06/27 + * @version: 1.0 + */ +public interface HrmResourceImportProcessService { + /** + * 初始化数据 + * + * @param request + */ + Map init(HttpServletRequest request); + + /** + * 用于处理把所得到的组织和人员结构信息放入系统 + * + * @param map + * @return + */ + void processMap(Map map); +} diff --git a/src/com/engine/organization/service/HrmResourceService.java b/src/com/engine/organization/service/HrmResourceService.java index 5c0193b3..5fd0df7e 100644 --- a/src/com/engine/organization/service/HrmResourceService.java +++ b/src/com/engine/organization/service/HrmResourceService.java @@ -3,6 +3,7 @@ package com.engine.organization.service; import com.engine.organization.entity.hrmresource.param.HrmResourceSearchParam; import com.engine.organization.entity.searchtree.SearchTreeParams; +import javax.servlet.http.HttpServletRequest; import java.util.Map; /** @@ -73,4 +74,6 @@ public interface HrmResourceService { * @return */ Map getHasRight(); + + Map saveImportResource(Map params, HttpServletRequest request); } diff --git a/src/com/engine/organization/service/impl/HrmResourceImportAdaptServiceImpl.java b/src/com/engine/organization/service/impl/HrmResourceImportAdaptServiceImpl.java new file mode 100644 index 00000000..f6623595 --- /dev/null +++ b/src/com/engine/organization/service/impl/HrmResourceImportAdaptServiceImpl.java @@ -0,0 +1,1070 @@ +package com.engine.organization.service.impl; + +import com.engine.core.impl.Service; +import com.engine.hrm.util.HrmWeakPasswordUtil; +import com.engine.organization.entity.extend.po.ExtendInfoPO; +import com.engine.organization.entity.hrmresource.param.HrmResourceImportParam; +import com.engine.organization.mapper.extend.ExtendInfoMapper; +import com.engine.organization.service.HrmResourceImportAdaptService; +import com.engine.organization.util.db.MapperProxyFactory; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.ss.usermodel.*; +import weaver.common.DateUtil; +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.systeminfo.SystemEnv; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.regex.Pattern; + +/** + * @author:dxfeng + * @createTime: 2022/06/27 + * @version: 1.0 + */ +public class HrmResourceImportAdaptServiceImpl extends Service implements HrmResourceImportAdaptService { + + private String fileName; + + private String importType; + + private Sheet sheet; + + private int sheetCount = 0; + + private final List errorInfo = new ArrayList<>(); + + private String[] temFields; + + //标准模板字段 + private String tempField = "分部,部门," + + "编号,姓名,登录名,密码,安全级别,性别," + + "岗位,职务,职务类型,职称,职级," + + "职责描述,直接上级,助理,状态," + + "办公室,办公地点,办公电话,移动电话,其他电话," + + "传真,电子邮件,系统语言,出生日期,民族," + + "籍贯,户口,身份证号码," + + "婚姻状况,政治面貌,入团日期,入党日期," + + "工会会员,学历,学位,健康状况,身高," + + "体重,用工性质,合同开始日期,合同结束日期,试用期结束日期,现居住地,家庭联系方式,暂住证号码," + + "入职日期,参加工作日期," + + "公积金帐户,账号类型,主账号,身高(cm),体重(kg),工资账号户名,工资银行,工资账号," + + "办公室电话,显示顺序,人员密级"; + + //存放必填列下标数组,包含自定义字段中的必填列 + private String[] requiredFields; + + //必填列标准模板或字段下标 + private final String requiredField = "0,1,3,8,9,10,18"; + + //标准导入字段数组 + private String[] voFields; + + //标准导入字段 + private String voField = "company_id,department_id," + + "work_code,last_name,login_id,pass_word,sec_level,sex," + + "job_title,job_activity,job_group_id,job_call,job_level," + + "job_activity_desc,manager_id,assistant_id,status," + + "workroom,location_id,telephone,mobile,mobile_call," + + "fax,email,system_language,birthday,folk," + + "native_place,reg_resident_place,certificate_num," + + "marital_status,policy,be_member_date,be_party_date," + + "islabouunion,education_level,degree,health_info,height," + + "weight,use_kind,start_date,end_date,probation_end_date," + + "resident_place,home_address,temp_resident_number," + + "company_start_date,work_start_date," + + "accum_fund_account,account_type,belong_to,height,weight,account_name,bank_id,account_id," + + "telephone,show_order,classification"; + + //基本信息字段数组最后下标 + private int baseFieldsLastIndex = 0; + + //基础自定义信息字段数组最后下标 + private int baseFieldsLastIndex1 = 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[]{"login_id", "work_code"}; + + 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 + */ + @Override + public List creatImportMap(FileUploadToPath fu) { + try { + new BaseBean().writeLog("lxr2018>>>language2=" + userlanguage); + // 初始化数据 + 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));//目前尚不清楚,这种异常的产生原因 + new BaseBean().writeLog(e); + return errorInfo; + } catch (Exception e) { + errorInfo.add(SystemEnv.getHtmlLabelName(83617, userlanguage));//Excel导入错误,请阅读注意事项并检查模板文件 + new BaseBean().writeLog(e); + return errorInfo; + } + + } + + private void deleteFile() { + new Thread(() -> { + try { + Thread.sleep(30 * 1000); + ImageFileManager.deletePdfImageFile(Util.getIntValue(fileName)); + } catch (InterruptedException e) { + new BaseBean().writeLog(e); + } + }).start(); + } + + /** + * 获取人员map + */ + @Override + 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 ("certificate_num".equalsIgnoreCase(voFields[i])) { + certificateNumIndex = i; + } + // 账号类型 + if ("account_type".equalsIgnoreCase(voFields[i])) { + accountTypeIndex = i; + } + if (keyFieldIndex != 2 && certificateNumIndex != 29) break; + } + try { + this.fileName = fu.getParameter("excelfile"); + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(Util.getIntValue(this.fileName)); + Workbook 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文件 + new BaseBean().writeLog(e); + } catch (IndexOutOfBoundsException e) { + errorInfo.add(SystemEnv.getHtmlLabelName(83619, userlanguage)); + new BaseBean().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("加载弱密码集合出错"); + new BaseBean().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])) { + 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模板有误时 + new BaseBean().writeLog(e); + } + } + + /** + * 初始化反射所需要的方法和字段Map,parameterTypes,fieldTypes + */ + public void initReflectParam() { + Class hrmResourceImportParamClass = HrmResourceImportParam.class; + Method[] hrmResourceMethods = hrmResourceImportParamClass.getDeclaredMethods(); + + for (Method hrmResourceMethod : hrmResourceMethods) { + parameterTypes.put(hrmResourceMethod.getName(), + hrmResourceMethod); + } + + Field[] hrmResourceFields = hrmResourceImportParamClass.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; + HrmResourceImportParam importParam; + + 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(); + if (repeatValidate(row, rowNum)) { // 重复性验证 + continue; + } + + importParam = new HrmResourceImportParam(); + + for (int cellIndex = 0; cellIndex < fieldsMap.size(); cellIndex++) { + + cell = row.getCell((short) cellIndex); + + cellNum = cellIndex; + + + fieldIndex = fieldsMap.get(cellNum); + + 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, importParam, null); + } + + if (fieldIndex > baseFieldsLastIndex && fieldIndex <= baseFieldsLastIndex1) { + baseFields.append(",").append(voFields[fieldIndex]); + if (cellValue.equals("")) + cellValue = "?"; + baseFieldsValue.append(";").append(cellValue); + setHrmResourceValue(0, baseFields.substring(1), importParam, "baseFields"); + setHrmResourceValue(0, baseFieldsValue.substring(1), importParam, "baseFieldsValue"); + } + + } + } + String currentDate = weaver.common.DateUtil.getCurrentDate(); + if (Util.null2String(importParam.getWork_start_date()).length() > 0 && Util.null2String(importParam.getWork_year()).length() == 0) {//计算工龄 + int day = weaver.common.DateUtil.dayDiff(importParam.getWork_start_date(), currentDate); + DecimalFormat df = new DecimalFormat("0.0"); + importParam.setWork_year(df.format(day / 365.0)); + } + + if (Util.null2String(importParam.getCompany_start_date()).length() > 0 && Util.null2String(importParam.getCompany_work_year()).length() == 0) {//计算司令 + int day = DateUtil.dayDiff(importParam.getWork_start_date(), currentDate); + DecimalFormat df = new DecimalFormat("0.0"); + importParam.setCompany_work_year(df.format(day / 365.0)); + } + + repeatKeyMap.put(keyValue, "" + (i + 1)); // 用于重复性验证 + if (importParam.getAccount_type() != null && !"".equals(importParam.getAccount_type())) { + if ("主账号".equals(importParam.getAccount_type())) { + certificateNums.put(importParam.getCertificate_num(), String.valueOf(i + 1)); + } + } else { + certificateNums.put(importParam.getCertificate_num(), String.valueOf(i + 1)); + } + + if (checkInfo(importParam, 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 = importParam.getLogin_id(); + break; + case "workcode": + val = importParam.getWork_code(); + break; + case "certificatenum": + val = importParam.getCertificate_num(); + break; + } + checkInfo.put(val, String.valueOf(i + 1)); + checkInfos.put(key, checkInfo); + } + + if (flag) { + hrmResourceMap.put(keyValue, importParam); + } + } + } + + /** + * 重复性验证,读取唯一性cell值,然后从HrmResourceMap中查找是否存在 + * + * @param row 行 + * @param rowNum 行下标 + */ + 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(HrmResourceImportParam importParam, 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(importParam.getLogin_id()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(520127, userlanguage); + break; + case "workcode": + val = Util.null2String(importParam.getWork_code()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(520128, userlanguage); + break; + case "certificatenum": + val = Util.null2String(importParam.getCertificate_num()).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("company_id") && getCellValue(1, cellNum).equals("分部") && cellValue.equals("")) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【分部】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return false; + } + + if ((rowNum == 1 || rowNum == 2) && fieldName.equals("department_id") && getCellValue(1, cellNum).equals("部门") && cellValue.equals("")) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【部门】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return false; + + } + //【分部】不为空则【部门】为必填 + if (fieldName.equals("department_id") && cellValue.equals("")) { + if (!getCellValue(rowNum, cellNum - 1).equals("")) { //分部不为空 + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return false; + } + } + + // 姓名 + if (fieldName.equals("last_name") && cellValue.equals("")) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【姓名】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return false; + } + + // 岗位 + if (fieldName.equals("job_title") && cellValue.equals("")) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【岗位】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return false; + } + + if (fieldName.equals("job_activity") && cellValue.equals("")) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【职务】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return false; + } + + if (fieldName.equals("job_group_id") && cellValue.equals("")) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【职务类型】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return false; + } + + // 办公地点 + if (fieldName.equals("location_id") && cellValue.equals("")) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //【办公地点】为必填 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return false; + } + + //自定义字段为必填设置时 + if (fieldIndex > baseFieldsLastIndex && requiredField.contains(String.valueOf(fieldIndex))) { + if (cellValue.equals("")) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return false; + } + } + + //基本信息、个人信息、工作信息自定义验证 + if (fieldIndex > baseFieldsLastIndex && !cellValue.equals("")) { + //自定义信息字段不能包含‘?’问号 + if (cellValue.contains("?") && getStrLength(cellValue) == 1) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83627, userlanguage)); + return false; + } + String valType = cusFieldValMap.get(fieldIndex); + if (valType != null) + if (valType.equals("isInt")) { + if (!isInteger(cellValue)) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83628, userlanguage)); + return false; + } + if (getStrLength(cellValue) > 18 && (Integer.MAX_VALUE < Double.parseDouble(cellValue) || Double.parseDouble(cellValue) < Integer.MIN_VALUE)) { + 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 false; + } + + } else if (valType.equals("isDouble")) { + if (!isDecimal(cellValue)) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83637, userlanguage)); + return false; + } + 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)) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83641, userlanguage) + valType + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return false; + } else if (valType.equals("isCheck") && !cellValue.equals("0") && !cellValue.equals("1")) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83644, userlanguage)); + return false; + } + } + + //安全级别、职级整数格式验证、大于0验证 + if ((fieldName.equals("sec_level") || fieldName.equals("job_level")) && !cellValue.equals("")) { + if (fieldName.equals("sec_level")) { + //安全级别不能大于999 + if (Util.getIntValue(cellValue) > 999) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(515522, userlanguage)); + return false; + } + //安全级别不能小于-999 + if (Util.getIntValue(cellValue) < -999) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(515523, userlanguage)); + return false; + } + } else { + if (!isInteger(cellValue)) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83645, userlanguage)); + return false; + } + if (Integer.parseInt(cellValue) < 0 || Integer.parseInt(cellValue) > 1000) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83648, userlanguage)); + return false; + } + } + } + //身高、体重数据格式验证、大于0验证 + if ((fieldName.equals("height") || fieldName.equals("weight")) && !cellValue.equals("")) { + if (!isDecimal(cellValue)) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83650, userlanguage)); + return false; + } + if (Double.parseDouble(cellValue) < 0 || Double.parseDouble(cellValue) > 1000) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83648, userlanguage)); + return false; + } + } + + + //长度为200个字符的标准字段 + if ((fieldName.equals("job_title") || fieldName.equals("job_activity") || fieldName.equals("job_group_id") || + fieldName.equals("location_id") || fieldName.equals("job_activity_desc") || fieldName.equals("reg_resident_place")) && !cellValue.equals("") && getStrLength(cellValue) > 200) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83666, userlanguage) + "200" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return false; + } + + //长度为100的标准字段 + if ((fieldName.equals("login_id") || fieldName.equals("pass_word") || fieldName.equals("home_address") || fieldName.equals("native_place")) && !cellValue.equals("") && getStrLength(cellValue) > 100) { + + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; //自定义日期字段长度验证 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83666, userlanguage) + "100" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return false; + + } + //长度为60的标准字段 + if ((fieldName.equals("last_name") || fieldName.equals("pass_word") || fieldName.equals("telephone") || fieldName.equals("mobile") || fieldName.equals("mobile_call") + || fieldName.equals("email") || fieldName.equals("workroom") || fieldName.equals("work_code") || fieldName.equals("fax") + || fieldName.equals("certificate_num") || fieldName.equals("job_call") || fieldName.equals("temp_resident_number")) + && !cellValue.equals("") && getStrLength(cellValue) > 60) { + + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83666, userlanguage) + "60" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return false; + + } + + //长度为30个字符的标准字段 + if ((fieldName.equals("degree") || fieldName.equals("policy")) && !cellValue.equals("") && getStrLength(cellValue) > 30) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83666, userlanguage) + "30" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return false; + } + + //长度为10个字符的标准字段 + if ((fieldName.equals("birthday") || fieldName.equals("be_member_date") || fieldName.equals("be_party_date") || + fieldName.equals("start_date") || fieldName.equals("end_date") || fieldName.equals("probation_end_date")) && !cellValue.equals("") && getStrLength(cellValue) > 10) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83666, userlanguage) + "10" + SystemEnv.getHtmlLabelName(20075, userlanguage)); + return false; + } + + //分部各级长度验证 + if (fieldName.equals("company_id") && !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 false; + } + } + + //部门各级长度验证 + if (fieldName.equals("department_id") && !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 false; + } + } + + //当启用【弱密码禁止保存】时,弱密码导入失败,失败信息为“密码安全性过弱” + if ("pass_word".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("")) { + msg = getCellPosition(cellNum, rowNum + 1) + "[" + temFields[fieldIndex] + "]"; // 重复性验证字段不在模板中 + errorInfo.add(msg + " " + SystemEnv.getHtmlLabelName(83626, userlanguage)); + return false; + } + + return flag; + } + + /** + * 通过反射为对象赋值 + * + * @param cellNum 列号 + * @param cellValue 单元格值 + * @param importParam 需要赋值的HrmResource + */ + public void setHrmResourceValue(int cellNum, String cellValue, + HrmResourceImportParam importParam, 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(importParam, cellValue); + else if (fieldType.equals("java.lang.Integer")) { + if (!cellValue.equals("")) + method.invoke(importParam, Integer.parseInt(cellValue)); + else + method.invoke(importParam, 0x7fffffff); + } else if (fieldType.equals("java.lang.Float") && !cellValue.equals("")) + method.invoke(importParam, Float.parseFloat(cellValue)); + else if (fieldType.equals("java.lang.Short") && !cellValue.equals("")) { + method.invoke(importParam, Short.parseShort(cellValue)); + } + } catch (Exception e) { + new BaseBean().writeLog(e); + } + } else { + String methodName = "set" + field.substring(0, 1).toUpperCase() + + field.substring(1); + Method method = parameterTypes.get(methodName); + try { + method.invoke(importParam, cellValue); + } catch (Exception e) { + new BaseBean().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() { + new BaseBean().writeLog("initTempFields"); + + temFields = tempField.split(","); + + baseFieldsLastIndex = temFields.length - 1; + + int requiredFieldIndex = baseFieldsLastIndex; + + /*基本信息信息字段*/ + StringBuilder baseField = new StringBuilder(); + StringBuilder baseFieldLabel = new StringBuilder(); + String fieldHtmlType; + List infoPOList = MapperProxyFactory.getProxy(ExtendInfoMapper.class).listFields("4", "", "JCL_ORG_HRMRESOURCE", ""); + for (ExtendInfoPO extendInfoPO : infoPOList) { + fieldHtmlType = extendInfoPO.getControlType().toString(); + if (fieldHtmlType.equals("1") || fieldHtmlType.equals("2") || fieldHtmlType.equals("3") + || fieldHtmlType.equals("4") || fieldHtmlType.equals("5")) { + baseField.append(",field").append(extendInfoPO.getId()); + baseFieldLabel.append(",").append(extendInfoPO.getFieldNameDesc()); + requiredFieldIndex++; + //验证条件 + //1为html文本类型 + switch (fieldHtmlType) { + case "1": + switch (extendInfoPO.getBrowserType()) { + case "1"://1为文本数据类型 + String fielddbtype = extendInfoPO.getFieldType(); + fielddbtype = fielddbtype.substring(fielddbtype.indexOf("(") + 1, fielddbtype.lastIndexOf(")")); //截取字符设置的长度 + cusFieldValMap.put(requiredFieldIndex, fielddbtype); + break; + case "2":// 2为整数数据类型 + cusFieldValMap.put(requiredFieldIndex, "isInt"); + break; + case "3":// 3为浮点数数据类型 + cusFieldValMap.put(requiredFieldIndex, "isDouble"); + break; + default: + cusFieldValMap.put(requiredFieldIndex, ""); + break; + } + break; + case "4"://4 为check框 + cusFieldValMap.put(requiredFieldIndex, "isCheck"); + break; + case "3": + if (extendInfoPO.getBrowserType().equals("2")) { + cusFieldValMap.put(requiredFieldIndex, "isDate"); + } else if (extendInfoPO.getBrowserType().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; + requiredFields = requiredField.split(","); + } + + /** + * 获取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 false; + 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"), "iso-8859-1").length(); + } catch (Exception e) { + new BaseBean().writeLog(e); + return 0; + } + } + + @Override + public void setUserlanguage(int userlanguage) { + this.userlanguage = userlanguage; + } +} diff --git a/src/com/engine/organization/service/impl/HrmResourceImportProcessServiceImpl.java b/src/com/engine/organization/service/impl/HrmResourceImportProcessServiceImpl.java new file mode 100644 index 00000000..ca016ad6 --- /dev/null +++ b/src/com/engine/organization/service/impl/HrmResourceImportProcessServiceImpl.java @@ -0,0 +1,2337 @@ +package com.engine.organization.service.impl; + +import com.engine.common.entity.EncryptFieldEntity; +import com.engine.common.service.ThemeService; +import com.engine.common.service.impl.HrmCommonServiceImpl; +import com.engine.common.service.impl.ThemeServiceImpl; +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import com.engine.core.impl.Service; +import com.engine.encrypt.biz.EncryptFieldConfigComInfo; +import com.engine.hrm.entity.RuleCodeType; +import com.engine.hrm.service.ImportLogService; +import com.engine.hrm.service.impl.ImportLogServiceImpl; +import com.engine.hrm.util.CodeRuleManager; +import com.engine.hrm.util.HrmTriggerUtil; +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.hrmresource.param.HrmResourceImportParam; +import com.engine.organization.service.HrmResourceImportProcessService; +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.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.ImportLog; +import weaver.join.hrm.in.processImpl.HrmTlevelManager; +import weaver.matrix.MatrixUtil; +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; + +/** + * @author:dxfeng + * @createTime: 2022/06/27 + * @version: 1.0 + */ +public class HrmResourceImportProcessServiceImpl extends Service implements HrmResourceImportProcessService { + + + 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[]{"login_id", "work_code"}; + + private Map baseTypeMap; //基础信息自定义字段数据库类型与字段名称映射 + + private final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + + private final int userlanguage = 7; //登录语言 + + char separator = Util.getSeparator(); + + LN license = new LN(); //license + + String keyField = ""; + String operateType = ""; + + private int scCount = 0; + + private HrmResourceImportParam hrmResourceImportParam = 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; + + @Override + public void setUser(User user) { + this.user = user; + } + + @Override + 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")); + + ImportLogService importLogService = ServiceUtil.getService(ImportLogServiceImpl.class, user); + Map params = ParamUtil.request2Map(request); + params.put("operateType", this.operateType); + retmap = importLogService.saveImportLog(params, request, user); + if (Util.null2String(retmap.get("status")).equals("1")) { + this.pId = Util.getIntValue(Util.null2String(retmap.get("pId"))); + request.getSession(true).setAttribute("hrmresourcePId", this.pId); + } + + final int F_Y = 0; + final int F_N = 1; + LN license = new LN(); + license.InLicense(); + int type = StringUtil.parseToInt(license.getScType(), F_N); + scCount = StringUtil.parseToInt(license.getScCount(), 0); + scCount = type == F_Y ? (Math.max(scCount, 0)) : 0; + 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) { + new BaseBean().writeLog(e); + } + return retmap; + } + + /** + * 对人员数据进行解析,并添加到数据库 + * + * @param hrMap 人员数据Map集合 + */ + @Override + public void processMap(Map hrMap) {//增加同步锁,防止同时多次调用 + List resultList = new ArrayList<>(); //导入结果 + RecordSet recordSet = new RecordSet(); + ImportLogService importLogService = ServiceUtil.getService(ImportLogServiceImpl.class, user); + try { + String subCompanyName = ""; //分部名称 + String departmentName = ""; //部门名称 + int subcompanyid1 = 0; // 分部Id + int departmentid = 0; // 部门id + String key; // workcode_lastname 组合 + getKeyMap(keyField); //获取重复性验证字段Map + int id; + + 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 importParamClass = HrmResourceImportParam.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) { + new BaseBean().writeLog(e); + } + + Object obj; + HrmResource hrm; + for (Object o : keyArray) { + obj = o; + hrmResourceImportParam = hrMap.get(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(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83520, userlanguage))); + continue; + } + + if (this.checkInfo(hrmResourceImportParam, resultList)) { + continue; + } + if (hrmResourceImportParam.getAccount_type() == null || "".equalsIgnoreCase(Util.null2String(hrmResourceImportParam.getAccount_type()))) { + if (StringUtil.isNotNull(hrmResourceImportParam.getCertificate_num()) && certificateNums.get(StringUtil.vString(hrmResourceImportParam.getCertificate_num())) != null) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } else { + if (hrmResourceImportParam.getAccount_type() != null && !"".equals(hrmResourceImportParam.getAccount_type())) { + if ("主账号".equals(hrmResourceImportParam.getAccount_type())) { + if (StringUtil.isNotNull(hrmResourceImportParam.getCertificate_num()) && certificateNums.get(StringUtil.vString(hrmResourceImportParam.getCertificate_num())) != null) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } + } + } + + //添加人员信息 license 人员上限判断 + + if (keyMap.get(key) == null && StringUtils.isNotBlank(hrmResourceImportParam.getLogin_id()) && ("主账号".equals(hrmResourceImportParam.getAccount_type()) || StringUtils.isBlank(hrmResourceImportParam.getAccount_type())) && "正式,试用,临时,试用延期".contains(Util.null2String(hrmResourceImportParam.getStatus()))) { + license.reloadLicenseInfo(); + if (license.CkHrmnum() >= 0) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83522, userlanguage))); + continue; + } + } + // 分部Id + String subCompanyNames = hrmResourceImportParam.getCompany_id() + ""; + String tempSubCompanyName = ""; + if (subCompanyNames != null) { + if (!subCompanyNames.equals(subCompanyName)) { + tempSubCompanyName = subCompanyName; + subCompanyName = subCompanyNames; + subcompanyid1 = getSubCompanyId(subCompanyName); + } + if (subcompanyid1 == -9) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); + continue; + } + if (subcompanyid1 == -2) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + continue; + } + if (subcompanyid1 == -1) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83524, userlanguage))); + continue; + } + if (StringUtil.parseToInt(license.getConcurrentFlag(), 0) != 1) { + if (new HrmResourceManager().noMore(String.valueOf(subcompanyid1))) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83525, userlanguage))); + continue; + } + } + hrm.setSubcompanyid1(subcompanyid1); + } else { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83526, userlanguage))); + continue; + } + + // 部门id + String departmentNames = hrmResourceImportParam.getDepartment_id(); + if (departmentNames != null) { + if (!subCompanyNames.equals(tempSubCompanyName) || !departmentNames.equals(departmentName)) { + departmentName = departmentNames; + departmentid = getDeptId(departmentName, subcompanyid1); + } + if (departmentid == -2) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + hrm.setDepartmentid(departmentid); + } else { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83527, userlanguage))); + continue; + } + + if (hrmResourceImportParam.getLast_name() == null) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83529, userlanguage))); + continue; + } + + //主账号id-sunjsh + if (hrmResourceImportParam.getAccount_type() != null && !"".equals(hrmResourceImportParam.getAccount_type())) { + if ("主账号".equals(hrmResourceImportParam.getAccount_type())) { + hrm.setBelongto(-1); + hrm.setAccounttype(0); + } else if ("次账号".equals(hrmResourceImportParam.getAccount_type())) { + if (hrmResourceImportParam.getBelong_to() != null && !"".equals(hrmResourceImportParam.getBelong_to().trim())) { + int belongTo = getBelongId(hrmResourceImportParam.getBelong_to(), keyField); + hrm.setBelongto(belongTo); + if (!hrmResourceImportParam.getBelong_to().equals("") && belongTo == 0) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(1); + } + } else { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } + } else { + hrm.setBelongto(-1); + hrm.setAccounttype(0); + } + } else if (hrmResourceImportParam.getBelong_to() != null && !"".equals(hrmResourceImportParam.getBelong_to().trim())) { + int belongto = getBelongId(hrmResourceImportParam.getBelong_to(), keyField); + hrm.setBelongto(belongto); + if (!hrmResourceImportParam.getBelong_to().equals("") && belongto == 0) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(1); + } + } else { + hrm.setBelongto(-1); + hrm.setAccounttype(0); + } + + // 岗位id + if (hrmResourceImportParam.getJob_title() != null && hrmResourceImportParam.getJob_activity() != null && hrmResourceImportParam.getJob_group_id() != null) { + int jobtitle = getJobTitles(hrmResourceImportParam.getJob_title(), hrmResourceImportParam.getJob_activity(), hrmResourceImportParam.getJob_group_id()); + hrm.setJobtitle(jobtitle); + } else { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83531, userlanguage))); + continue; + } + + //上级id + if (hrmResourceImportParam.getManager_id() != null) { + int managerid = 0; // 上级Id + String managerstr = ""; //所有上级 + Map managerInfo = getManagerIdAndStr("", hrmResourceImportParam.getManager_id(), 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 (!hrmResourceImportParam.getManager_id().equals("") && managerid == 0) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83532, userlanguage))); + continue; + } + } else { + + hrm.setManagerid(0); + hrm.setManagerstr(""); + } + + // 助理id + if (hrmResourceImportParam.getAssistant_id() != null) { + int assistantid = getAssistantid(hrmResourceImportParam.getAssistant_id(), keyField); + hrm.setAssistantid(assistantid); + if (!hrmResourceImportParam.getAssistant_id().equals("") && assistantid == 0) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(24678, userlanguage))); + continue; + } + } + + // 办公地点 + if (hrmResourceImportParam.getLocation_id() != null) { + int locationid = getLocationid(hrmResourceImportParam.getLocation_id()); + hrm.setLocationid(locationid); + } else { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83533, userlanguage))); + continue; + } + + //邮箱-sunjsh + if (hrmResourceImportParam.getEmail() != null) { + if (!"".equals(hrmResourceImportParam.getEmail().trim()) && hrmResourceImportParam.getEmail().contains("*")) { + hrmResourceImportParam.setEmail(null); + } else if ("".equals(hrmResourceImportParam.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(hrmResourceImportParam.getEmail()); + if (!matcher.matches()) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(24570, userlanguage))); + continue; + } else { + hrm.setEmail(hrmResourceImportParam.getEmail()); + } + } + } + + //mobile-sunjsh + if (hrmResourceImportParam.getMobile() != null) { + if ("".equals(hrmResourceImportParam.getMobile().trim()) || (!"".equals(hrmResourceImportParam.getMobile().trim()) && hrmResourceImportParam.getMobile().contains("*"))) + hrmResourceImportParam.setMobile(null); + } else hrm.setMobile(""); + + //工资银行-sunjsh + if (hrmResourceImportParam.getBank_id() != null && !"".equals(hrmResourceImportParam.getBank_id())) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", 0); + jsonObject.put("fieldhtmltype", 3); + jsonObject.put("type", 284); + jsonObject.put("dmlurl", ""); + jsonObject.put("fieldvalue", hrmResourceImportParam.getBank_id()); + + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + if (!"".equals(fieldvalue)) { + hrm.setBankid1(new Integer(fieldvalue)); + } else { + hrm.setBankid1(this.getBankId(hrmResourceImportParam.getBank_id())); + } + } + + //sunjsh-入职日期 + if (hrmResourceImportParam.getCompany_start_date() != null && !"".equals(hrmResourceImportParam.getCompany_start_date())) { + hrm.setCompanystartdate(hrmResourceImportParam.getCompany_start_date()); + } + + //sunjsh-参加工作日期 + if (hrmResourceImportParam.getWork_start_date() != null && !"".equals(hrmResourceImportParam.getWork_start_date())) { + hrm.setWorkstartdate(hrmResourceImportParam.getWork_start_date()); + } + // 性别,为空或其他情况统一为0(男) + String sex = "女".equals(hrmResourceImportParam.getSex()) ? "1" : "0"; + hrm.setSex(sex); + + // 职称 + if (hrmResourceImportParam.getJob_call() != null) { + int jobcall = getJobcall(hrmResourceImportParam.getJob_call()); + hrm.setJobcall(jobcall); + } + // 系统语言,默认简体中文 + if (hrmResourceImportParam.getSystem_language() != null) { + int systemlanguage = getSystemlanguage(hrmResourceImportParam.getSystem_language()); + + if (systemlanguage == -1) { //只能选择简体中文|Englisth|繁体中文 + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(518929, userlanguage))); + continue; + } + if (systemlanguage == 0) { //系统不支持多语言 + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(84810, userlanguage))); + continue; + } + hrm.setSystemlanguage(systemlanguage); + } else { + hrm.setSystemlanguage(7); + } + + // 婚姻状况,如果不是以下选项,则默认为未婚 + String maritalStatus = "已婚".equals(hrmResourceImportParam.getMarital_status()) ? "1" : "离异".equals(hrmResourceImportParam.getMarital_status()) ? "2" : "0"; + hrm.setMaritalstatus(maritalStatus); + + // 员工状态 + if (!"".equals(Util.null2String(hrmResourceImportParam.getStatus()))) { + int status = getStatus(hrmResourceImportParam.getStatus()); + hrm.setStatus(status); + } else { + hrm.setStatus(1); + } + + // 人员密级 + if (!"".equals(Util.null2String(hrmResourceImportParam.getClassification()))) { + int classification = getClassification(hrmResourceImportParam.getClassification()); + hrm.setClassification(classification); + } + // 学历 + if (hrmResourceImportParam.getEducation_level() != null) { + int educationLevel = getEducationlevel(hrmResourceImportParam.getEducation_level()); + hrm.setEducationlevel(educationLevel); + } + + // 工会会员,默认为是 + String islabouunion = "是".equals(hrmResourceImportParam.getIslabouunion()) ? "1" : "0"; + hrm.setIslabouunion(islabouunion); + + // 健康状况 + if (hrmResourceImportParam.getHealth_info() != null) { + String healthinfo = getHealthinfo(hrmResourceImportParam.getHealth_info()); + hrm.setHealthinfo(healthinfo); + } else { + hrm.setHealthinfo("0"); + } + + //安全级别不能大于999 + if (Util.getIntValue(hrmResourceImportParam.getSec_level(), 0) > 999) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(515522, userlanguage))); + continue; + } + //安全级别不能小于-999 + if (Util.getIntValue(hrmResourceImportParam.getSec_level(), 0) < -999) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(515523, userlanguage))); + continue; + } + //安全级别必须是数字 + if (!Util.null2String(hrmResourceImportParam.getSec_level()).equals("")) { + if (Util.getIntValue(hrmResourceImportParam.getSec_level(), -1000) == -1000) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", "安全级别必须是数字")); + continue; + } else { + hrm.setSeclevel((short) Util.getIntValue(hrmResourceImportParam.getSec_level())); + } + } else { + //安全级别为空时取缓存类中的安全级别 + hrm.setSeclevel((short) (0)); + } + + //职级 + if (isInteger(hrmResourceImportParam.getJob_level())) { + int joblevel = hrmResourceImportParam.getJob_level().equals("") ? 0 : Integer.parseInt(hrmResourceImportParam.getJob_level()); + hrm.setJoblevel((short) joblevel); + } else { + hrm.setJoblevel((short) 0); + } + //用工性质 + if (hrmResourceImportParam.getUse_kind() != null) { + int useKind = getUseKind(hrmResourceImportParam.getUse_kind()); + hrm.setUsekind(useKind); + } else { + hrm.setUsekind(0); + } + //如果新增导入的时候,登陆名不为空,需要校验一下当前的license + + + // 手机 办公电话 + CheckItemBean mobileBean = new CheckItemBean("mobile", hrmResourceImportParam.getMobile()); + ValidateFieldManager.validate(mobileBean); + if (!mobileBean.isPass()) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", mobileBean.getCheckMsg())); + continue; + } + CheckItemBean telephoneBean = new CheckItemBean("telephone", hrmResourceImportParam.getTelephone()); + ValidateFieldManager.validate(telephoneBean); + if (!telephoneBean.isPass()) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", telephoneBean.getCheckMsg())); + continue; + } + + + //id,非自动增长 + recordSet.executeProc("HrmResourceMaxId_Get", ""); + recordSet.next(); + id = recordSet.getInt(1); + hrm.setId(id); + + + //密码 加密 + String password_tmp = Util.null2String(hrmResourceImportParam.getPass_word()).trim(); + if ("".equals(password_tmp)) { + password_tmp = "1"; + //人员导入文件中,将密码这一列删除或者密码这一列存在,但是不填写都默认为初始密码 + if (defaultPasswordEnable) { + if (!defaultPassword.equals("")) { + if (weakPasswordDisable && this.hrmWeakPasswordUtil.isWeakPsd(defaultPassword)) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(515436, userlanguage))); + continue; + } else { + password_tmp = defaultPassword; + } + } else { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", 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 = hrmResourceImportParam.getWork_code(); + workcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.USER, String.valueOf(hrm.getSubcompanyid1()), String.valueOf(hrm.getDepartmentid()), String.valueOf(hrm.getJobtitle()), workcode); + hrmResourceImportParam.setWork_code(workcode); + + for (String s : fields) { + Field hrmField = hrmClass.getDeclaredField(s); + Field paramClassDeclaredField = importParamClass.getDeclaredField(s); + + String hrmFieldType = hrmField.getType().getName(); + String voFieldType = paramClassDeclaredField.getType().getName(); + + hrmField.setAccessible(true); + paramClassDeclaredField.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 (paramClassDeclaredField.get(hrmResourceImportParam) != null) { + if (voFieldType.endsWith("String")) { + if (recordSet.getDBType().equalsIgnoreCase("mysql") || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + if (Util.null2String(paramClassDeclaredField.get(hrmResourceImportParam)).equals("")) { + insertFields.append(s).append(","); + insertValues.append("null,"); + } else { + insertFields.append(s).append(","); + insertValues.append("'").append(paramClassDeclaredField.get(hrmResourceImportParam)).append("',"); + } + } else { + insertFields.append(s).append(","); + insertValues.append("'").append(paramClassDeclaredField.get(hrmResourceImportParam)).append("',"); + } + } else if (hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float")) { + insertFields.append(s).append(","); + String insertValueStr = Util.null2String(paramClassDeclaredField.get(hrmResourceImportParam)); + if ("".equals(insertValueStr) && recordSet.getDBType().equalsIgnoreCase("postgresql")) { + insertValues.append("null,"); + } else { + insertValues.append(paramClassDeclaredField.get(hrmResourceImportParam)).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(hrmResourceImportParam.getBaseFields(), hrmResourceImportParam.getBaseFieldsValue(), id)) //添加基础字段信息 + flag = false; + } + + /*添加人员缓存,人员默认按id显示顺序,HrmResource_Trigger_Insert 人员共享 入职维护项目状态*/ + if (flag) { + + //HrmUserSettingManager.checkUserSettingInit(id) ; + + //人员显示顺序 + if (hrmResourceImportParam.getShow_order() == null) { + String taxissql = ("update HrmResource set dsporder = " + id + " where id = " + id); + recordSet.executeSql(taxissql); + } + //构建pinyin快速搜索 + if (hrmResourceImportParam.getLast_name() != null) { + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(hrmResourceImportParam.getLast_name()); + 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(hrmResourceImportParam, "创建", "成功", "")); + } else { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", "系统错误,请联系管理员")); + } + + } else { //更新人员 + if (keyMap.get(key) == null) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83535, userlanguage))); + continue; + } + + hrmResourceImportParam.setId(Long.parseLong(keyMap.get(key).toString()));//设置id + if (this.checkInfo(hrmResourceImportParam, resultList)) { + continue; + } + + if (hrmResourceImportParam.getAccount_type() == null || "".equalsIgnoreCase(Util.null2String(hrmResourceImportParam.getAccount_type()))) { + if (StringUtil.isNotNull(hrmResourceImportParam.getCertificate_num()) && certificateNums.get(StringUtil.vString(hrmResourceImportParam.getCertificate_num())) != null) { + if (StringUtil.parseToInt(String.valueOf(keyMap.get(key))) != StringUtil.parseToInt(String.valueOf(certificateNums.get(StringUtil.vString(hrmResourceImportParam.getCertificate_num()))))) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } + } else { + if (hrmResourceImportParam.getAccount_type() != null && !"".equals(hrmResourceImportParam.getAccount_type())) { + if ("主账号".equals(hrmResourceImportParam.getAccount_type())) { + if (StringUtil.isNotNull(hrmResourceImportParam.getCertificate_num()) && certificateNums.get(StringUtil.vString(hrmResourceImportParam.getCertificate_num())) != null) { + if (StringUtil.parseToInt(String.valueOf(keyMap.get(key))) != StringUtil.parseToInt(String.valueOf(certificateNums.get(StringUtil.vString(hrmResourceImportParam.getCertificate_num()))))) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83521, userlanguage))); + continue; + } + } + } + } + } + + final String hrmId = String.valueOf(keyMap.get(key)); + + //分部id + String subCompanyNames = hrmResourceImportParam.getCompany_id(); + 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(hrmResourceImportParam, "更新", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); + continue; + } + if (subcompanyid1 == -2) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + continue; + } + if (subcompanyid1 == 0 || subcompanyid1 == -1) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", 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(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83525, userlanguage))); + continue; + } + } + hrm.setSubcompanyid1(subcompanyid1); + } + + // 部门id + String departmentNames = hrmResourceImportParam.getDepartment_id(); + if (!"".equals(Util.null2String(departmentNames))) { //部门存在时 + if (!issameSub || !departmentNames.equals(departmentName)) { + departmentName = departmentNames; + departmentid = getDeptId(departmentName, subcompanyid1); + + if (departmentid == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83537, userlanguage))); + continue; + } + if (departmentid == -2) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + } else { //add sjh 50102需要考虑不同公司名称相同部门架构情况 此时部门ID是不同的 + departmentid = getDeptId(departmentName, subcompanyid1); + if (departmentid == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83537, userlanguage))); + continue; + } + if (departmentid == -2) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + } + hrm.setDepartmentid(departmentid); + } + + //主账号id-sunjsh + if (hrmResourceImportParam.getAccount_type() != null && !"".equals(hrmResourceImportParam.getAccount_type())) { + if ("主账号".equals(hrmResourceImportParam.getAccount_type())) { + hrm.setBelongto(-1); + hrm.setAccounttype(0); + } else if ("次账号".equals(hrmResourceImportParam.getAccount_type())) { + if (hrmResourceImportParam.getBelong_to() != null && !"".equals(hrmResourceImportParam.getBelong_to().trim())) { + int belongto = getBelongId(hrmResourceImportParam.getBelong_to(), keyField); + hrm.setBelongto(belongto); + if (!hrmResourceImportParam.getBelong_to().equals("") && belongto == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(1); + } + } else { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } + } else { + hrm.setBelongto(-1); + hrm.setAccounttype(0); + } + } else if (hrmResourceImportParam.getBelong_to() != null && !"".equals(hrmResourceImportParam.getBelong_to().trim())) { + int belongto = getBelongId(hrmResourceImportParam.getBelong_to(), keyField); + hrm.setBelongto(belongto); + if (!hrmResourceImportParam.getBelong_to().equals("") && belongto == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrm.setAccounttype(1); + } + } + + // 岗位id + if ("".equals(Util.null2String(hrmResourceImportParam.getJob_title())) && (!"".equals(Util.null2String(hrmResourceImportParam.getJob_activity())) || !"".equals(Util.null2String(hrmResourceImportParam.getJob_group_id())))) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83544, userlanguage))); + continue; + } + if (!"".equals(Util.null2String(hrmResourceImportParam.getJob_title()))) { + String jobtitle; + String jobactivityid; + String jobactivityname; + String jobgroupid; + String jobgroupname; + if (hrmResourceImportParam.getJob_activity() == null) { + jobtitle = resourcecominfo.getJobTitle(hrmId); + jobactivityid = jobTitlesComInfo.getJobactivityid(jobtitle); + jobactivityname = jobActivitiesComInfo.getJobActivitiesname(jobactivityid); + } else jobactivityname = hrmResourceImportParam.getJob_activity(); + if (hrmResourceImportParam.getJob_group_id() == null) { + jobtitle = resourcecominfo.getJobTitle(hrmId); + jobactivityid = jobTitlesComInfo.getJobactivityid(jobtitle); + jobgroupid = jobActivitiesComInfo.getJobgroupid(jobactivityid); + jobgroupname = jobGroupsComInfo.getJobGroupsname(jobgroupid); + } else { + jobgroupname = hrmResourceImportParam.getJob_group_id(); + } + int jobtitleid = getJobTitles(hrmResourceImportParam.getJob_title(), jobactivityname, jobgroupname); + hrm.setJobtitle(jobtitleid); + } + + if (Util.getIntValue(hrmId) < 0) continue; + + //上级id + String managerstr = ""; //所有上级 + String oldmanagerstr = resourcecominfo.getManagersIDs(hrmId);//原来的所有上sex + // 级序列 + if (!"".equals(Util.null2String(hrmResourceImportParam.getManager_id()))) { + int managerid = 0; // 上级Id + + Map managerInfo = getManagerIdAndStr(hrmId, hrmResourceImportParam.getManager_id(), 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 (hrmResourceImportParam.getManager_id() != null && !hrmResourceImportParam.getManager_id().equals("") && managerid == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83532, userlanguage))); + continue; + } + hrm.setManagerid(managerid); + hrm.setManagerstr(managerstr); + } else { + if (hrmResourceImportParam.getManager_id() == null) { + hrm.setManagerid(StringUtil.parseToInt(resourcecominfo.getManagerID(hrmId), 0)); + hrm.setManagerstr(resourcecominfo.getManagersIDs(hrmId)); + managerstr = resourcecominfo.getManagersIDs(hrmId); + hrmResourceImportParam.setManager_id(resourcecominfo.getManagerID(hrmId)); + } else { + hrm.setManagerid(0); + hrm.setManagerstr(""); + } + } + // 助理id + if (!"".equals(Util.null2String(hrmResourceImportParam.getAssistant_id()))) { + int assistantid; + assistantid = getAssistantid(hrmResourceImportParam.getAssistant_id(), keyField); + if (hrmResourceImportParam.getAssistant_id() != null && !hrmResourceImportParam.getAssistant_id().equals("") && assistantid == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(24678, userlanguage))); + continue; + } + hrm.setAssistantid(assistantid); + } + // 办公地点 + if (!"".equals(Util.null2String(hrmResourceImportParam.getLocation_id()))) { + int locationid = getLocationid(hrmResourceImportParam.getLocation_id()); + hrm.setLocationid(locationid); + } + + //邮箱-sunjsh + if (hrmResourceImportParam.getEmail() != null) { + if (!"".equals(hrmResourceImportParam.getEmail().trim()) && hrmResourceImportParam.getEmail().contains("*")) { + hrmResourceImportParam.setEmail(null); + } else if ("".equals(hrmResourceImportParam.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(hrmResourceImportParam.getEmail()); + if (!matcher.matches()) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(24570, userlanguage))); + continue; + } else { + hrm.setEmail(hrmResourceImportParam.getEmail()); + } + } + } + + //mobile-sunjsh + if (hrmResourceImportParam.getMobile() != null) { + if ("".equals(hrmResourceImportParam.getMobile().trim())) hrm.setMobile(""); + else if (!"".equals(hrmResourceImportParam.getMobile().trim()) && hrmResourceImportParam.getMobile().contains("*")) + hrmResourceImportParam.setMobile(null); + } + + //工资银行-sunjsh + if (hrmResourceImportParam.getBank_id() != null && !"".equals(hrmResourceImportParam.getBank_id())) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fieldid", 0); + jsonObject.put("fieldhtmltype", 3); + jsonObject.put("type", 284); + jsonObject.put("dmlurl", ""); + jsonObject.put("fieldvalue", hrmResourceImportParam.getBank_id()); + + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + if (!"".equals(fieldvalue)) { + hrm.setBankid1(new Integer(fieldvalue)); + } else { +// vo.setBankid1(null); + hrm.setBankid1(this.getBankId(hrmResourceImportParam.getBank_id())); + } + } + + //sunjsh-入职日期 + if (hrmResourceImportParam.getCompany_start_date() != null && !"".equals(hrmResourceImportParam.getCompany_start_date())) { + hrm.setCompanystartdate(hrmResourceImportParam.getCompany_start_date()); +// hrm.setCompanyworkyear(this.calculateDate(vo.getCompanystartdate())); + } else { + hrmResourceImportParam.setCompany_start_date(null); + } + + //sunjsh-参加工作日期 + if (hrmResourceImportParam.getWork_start_date() != null && !"".equals(hrmResourceImportParam.getWork_start_date())) { + hrm.setWorkstartdate(hrmResourceImportParam.getWork_start_date()); + } else { + hrmResourceImportParam.setWork_start_date(null); + } + // 职称 + if (!"".equals(Util.null2String(hrmResourceImportParam.getJob_call()))) { + int jobcall = getJobcall(hrmResourceImportParam.getJob_call()); + hrm.setJobcall(jobcall); + } + // 系统语言,默认简体中文 + if (!"".equals(Util.null2String(hrmResourceImportParam.getSystem_language()))) { + int systemlanguage = getSystemlanguage(hrmResourceImportParam.getSystem_language()); + + if (systemlanguage == -1) { //只能选择简体中文|Englisth|繁体中文 + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(518929, userlanguage))); + continue; + } + //系统不支持多语言 + if (systemlanguage == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(84810, userlanguage))); + continue; + } + hrm.setSystemlanguage(systemlanguage); + } + + // 性别,为空或其他情况统一为0(男) + if (hrmResourceImportParam.getSex() == null) { + hrm.setSex("0"); + } else if (!"".equals(Util.null2String(hrmResourceImportParam.getSex()))) { + String sex = hrmResourceImportParam.getSex().equals("女") ? "1" : "0"; + hrm.setSex(sex); + } + + // 婚姻状况,如果不是以下选项,则默认为未婚 + if (!"".equals(Util.null2String(hrmResourceImportParam.getMarital_status()))) { + String maritalstatus = hrmResourceImportParam.getMarital_status().equals("已婚") ? "1" : hrmResourceImportParam.getMarital_status().equals("离异") ? "2" : "0"; + hrm.setMaritalstatus(maritalstatus); + } + + // 员工状态 + if (!"".equals(Util.null2String(hrmResourceImportParam.getStatus()))) { + int status = getStatus(hrmResourceImportParam.getStatus()); + hrm.setStatus(status); + } else { + // TODO 待验证 + hrm.setStatus(0); + } + + // 人员密级 + if (!"".equals(Util.null2String(hrmResourceImportParam.getClassification()))) { + int classification = getClassification(hrmResourceImportParam.getClassification()); + hrm.setClassification(classification); + } + + // 学历 + if (!"".equals(Util.null2String(hrmResourceImportParam.getEducation_level()))) { + int educationlevel = getEducationlevel(hrmResourceImportParam.getEducation_level()); + hrm.setEducationlevel(educationlevel); + } + + // 工会会员,默认为是 + if (!"".equals(Util.null2String(hrmResourceImportParam.getIslabouunion()))) { + String islabouunion = hrmResourceImportParam.getIslabouunion().equals("是") ? "1" : "0"; + hrm.setIslabouunion(islabouunion); + } + + // 健康状况 + if (!"".equals(Util.null2String(hrmResourceImportParam.getHealth_info()))) { + String healthinfo = getHealthinfo(hrmResourceImportParam.getHealth_info()); + hrm.setHealthinfo(healthinfo); + } + + //安全级别不能大于999 + if (Util.getIntValue(hrmResourceImportParam.getSec_level(), 0) > 999) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(515522, userlanguage))); + continue; + } + //安全级别不能小于-999 + if (Util.getIntValue(hrmResourceImportParam.getSec_level(), 0) < -999) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(515523, userlanguage))); + continue; + } + //安全级别必须是数字 + if (!Util.null2String(hrmResourceImportParam.getSec_level()).equals("")) { + if (Util.getIntValue(hrmResourceImportParam.getSec_level(), -1000) == -1000) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", "安全级别必须是数字")); + continue; + } else { + hrm.setSeclevel((short) Util.getIntValue(hrmResourceImportParam.getSec_level())); + } + } else { + //安全级别为空时取缓存类中的安全级别 + hrm.setSeclevel(Short.parseShort(resourcecominfo.getSeclevel(hrmId))); + } + + //职级 + if (isInteger(hrmResourceImportParam.getJob_level())) { + int joblevel = hrmResourceImportParam.getJob_level().equals("") ? 0 : Integer.parseInt(hrmResourceImportParam.getJob_level()); + hrm.setJoblevel((short) joblevel); + } + + //用工性质 + if (hrmResourceImportParam.getUse_kind() != null) { + int usekind = getUseKind(hrmResourceImportParam.getUse_kind()); + hrm.setUsekind(usekind); + } + + + //更新导入的时候,如果登录名不为空,需要校验一下当前的license + if (needCheckLicenseForUpdate(resourcecominfo, hrmId, hrmResourceImportParam)) { + license.reloadLicenseInfo(); + if (license.CkHrmnum() >= 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83522, userlanguage))); + continue; + } + } + + // 手机 办公电话 + CheckItemBean mobileBean = new CheckItemBean("mobile", hrmResourceImportParam.getMobile()); + ValidateFieldManager.validate(mobileBean); + if (!mobileBean.isPass()) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", mobileBean.getCheckMsg())); + continue; + } + CheckItemBean telephoneBean = new CheckItemBean("telephone", hrmResourceImportParam.getTelephone()); + ValidateFieldManager.validate(telephoneBean); + if (!telephoneBean.isPass()) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", telephoneBean.getCheckMsg())); + continue; + } + + + //密码 加密 + if (!"".equals(Util.null2String(hrmResourceImportParam.getPass_word()))) { + + String orgPwd = "1"; + if (!"".equals(hrmResourceImportParam.getPass_word())) + orgPwd = hrmResourceImportParam.getPass_word(); + 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 = ""; + for (int k = 1; k < fields.length; k++) { + Field hrmField = hrmClass.getDeclaredField(fields[k]); + Field paramClassDeclaredField = importParamClass.getDeclaredField(fields[k]); + + String hrmFieldType = hrmField.getType().getName(); + String voFieldType = paramClassDeclaredField.getType().getName(); + + hrmField.setAccessible(true); + paramClassDeclaredField.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")) + if (false) { + //0数据的这个临时改回去 + + } else { + 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(paramClassDeclaredField.get(hrmResourceImportParam)).trim().length() > 0) { + if (voFieldType.endsWith("String")) { + if (recordSet.getDBType().equalsIgnoreCase("mysql") || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + if (Util.null2String(paramClassDeclaredField.get(hrmResourceImportParam)).equals("")) { + updateStr.append(fields[k]).append("=null,"); + } else { + updateStr.append(fields[k]).append("='").append(paramClassDeclaredField.get(hrmResourceImportParam)).append("',"); + } + } else { + updateStr.append(fields[k]).append("='").append(paramClassDeclaredField.get(hrmResourceImportParam)).append("',"); + } + } else if (voFieldType.endsWith("Integer") || voFieldType.endsWith("Short") || voFieldType.endsWith("Float")) { + if (paramClassDeclaredField.get(hrmResourceImportParam).equals(0) && false) { + + } else { + if (voFieldType.endsWith("Integer") && (paramClassDeclaredField.get(hrmResourceImportParam).equals(0x7fffffff))) { + updateStr.append(fields[k]).append("=null,"); + } else { + updateStr.append(fields[k]).append("=").append(paramClassDeclaredField.get(hrmResourceImportParam)).append(","); + } + } + } + if (fields[k].equals("status")) + tmpstatus = Util.null2String(paramClassDeclaredField.get(hrmResourceImportParam)); + } + } + + 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(hrmResourceImportParam.getPass_word()))) { + 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(hrmResourceImportParam.getPass_word()));//新密码 + 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; + new BaseBean().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(hrmResourceImportParam.getBaseFields(), hrmResourceImportParam.getBaseFieldsValue().trim(), 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 (hrmResourceImportParam.getLast_name() != null) { + String quickSearchStr = new HrmCommonServiceImpl().generateQuickSearchStr(hrmResourceImportParam.getLast_name()); + String sqlStr = "update HrmResource set pinyinlastname = ?, ecology_pinyin_search = ? where id = ?"; + recordSet.executeUpdate(sqlStr, quickSearchStr, quickSearchStr, hrmId); + } + } + + //更新下级managerstr + if (flag && !"".equals(Util.null2String(hrmResourceImportParam.getManager_id()))) { + 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(); + new BaseBean().writeLog(e); + } + + } + } + if (flag) { + + HrmFaceCheckManager.sync(keyMap.get(key) + "", HrmFaceCheckManager.getOptUpdate(), "hrm_e9_import_resource", HrmFaceCheckManager.getOaResource()); + new HrmDateCheck().calWorkInfo(hrmId); + resultList.add(createLog(hrmResourceImportParam, "更新", "成功", "")); + //qc313055 [80][90][缺陷]IM集成-解决人员导入更新人员信息时,无账号列时,IM同步会进行删除操作的问题 ---start + RecordSet rst = new RecordSet(); + if (hrmResourceImportParam.getLogin_id() != null) { + + //此时resourcecominfo对象还没有更新,可以直接取 + if (!"".equals(hrmResourceImportParam.getLogin_id())) { + + } else { + rst.executeSql("select * from hrmresource where id='" + hrmId + "'"); + String loginid = ""; + if (rst.next()) { + loginid = rst.getString("loginid"); + } + } + } else { + rst.executeSql("select * from hrmresource where id='" + hrmId + "'"); + String loginid = ""; + if (rst.next()) { + loginid = rst.getString("loginid"); + } + } + } else { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", "系统错误,请联系管理员")); + } + } + } catch (Exception e) { + //数据异常 + new BaseBean().writeLog(e); + } + } + try { + HrmTlevelManager.setUpdate(); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + + +// endTime = System.currentTimeMillis(); +// System.out.println("---分部、部门层级更新结束,用时:"+(endTime - startTime)); +// startTime = endTime; + //更新人员、分部、部门、职位、岗位、职位类型缓存 + + resourcecominfo.removeResourceCache(); + departmentComInfo.removeCompanyCache(); + subCompanyComInfo.removeCompanyCache(); + jobActivitiesComInfo.removeJobActivitiesCache(); + jobTitlesComInfo.removeJobTitlesCache(); + jobGroupsComInfo.removeCompanyCache(); + locationComInfo.removeLocationCache(); + useKindComInfo.removeUseKindCache(); + //初始化应用分权 + new weaver.hrm.appdetach.AppDetachComInfo().initSubDepAppData(); + + Map params = new HashMap<>(); + params.put("pId", this.pId); + params.put("status", "over"); + importLogService.saveImportLogStatus(params, user); + + } catch (Exception e) { + new BaseBean().writeLog(e); + Map params = new HashMap<>(); + params.put("pId", this.pId); + params.put("status", "error"); + importLogService.saveImportLogStatus(params, user); + } + } + + /** + * 插入基础自定义字段信息 + * + * @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) { + new BaseBean().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 true; + + //检查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) { + new BaseBean().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 curCount = 0; + int iscanceled; + + String currentidsql; + String canceledsql; + String sql; + String sqlInsert; + 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); + + if (parentId == 0 && currentId == 0) { + recordSet.executeSql("select COUNT(id) from HrmSubCompany where supsubcomid = 0 and (canceled is null or canceled != '1')"); + if (recordSet.next()) { + curCount = recordSet.getInt(1); + } + } + + //added by wcd 2015-02-06 [限制分部数] + if (currentId == 0) { + canceledsql = sql + " and canceled='1' "; + iscanceled = getResultSetId(canceledsql); + if (iscanceled == 0) { + } else { + currentId = -2; + break; + } + if (scCount == 0 || curCount < scCount) { + // 如果编码为空 自动生成编码 + String subcompanycode = ""; + try { + subcompanycode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.SUBCOMPANY, subcompanycode); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + sqlInsert = "insert into HrmSubCompany(subcompanyname,subcompanydesc,companyid,supsubcomid ," + DbFunctionUtil.getInsertColumnSql() + " , subcompanycode) values('" + companyName.trim() + "','" + companyName.trim() + "',1" + "," + parentId + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ",'" + subcompanycode + "')"; // 创建 + execSql(sqlInsert); + HrmTriggerUtil.generateSubcompanyPinyin(companyName.trim(), null); + currentId = getResultSetId(sql); + HrmTriggerUtil.Tri_I_SubComKPICheckFlow(String.valueOf(currentId)); + MatrixUtil.updateSubcompayData(currentId + ""); + //新增分部,統一调用门户接口创建门户菜单 + ThemeService themService = new ThemeServiceImpl(); + themService.createSubCompanyMenu(currentId, parentId); +// sql = "insert into leftmenuconfig (userid,infoid,visible,viewindex,resourceid,resourcetype,locked,lockedbyid,usecustomname,customname,customname_e) select distinct userid,infoid,visible,viewindex," + currentId + ",2,locked,lockedbyid,usecustomname,customname,customname_e from leftmenuconfig where resourcetype=1 and resourceid=1"; +// execSql(sql); +// sql = "insert into mainmenuconfig (userid,infoid,visible,viewindex,resourceid,resourcetype,locked,lockedbyid,usecustomname,customname,customname_e) select distinct userid,infoid,visible,viewindex," + currentId + ",2,locked,lockedbyid,usecustomname,customname,customname_e from mainmenuconfig where resourcetype=1 and resourceid=1"; +// execSql(sql); + + HrmFaceCheckManager.sync(currentId + "", HrmFaceCheckManager.getOptInsert(), "HRM_E9_IMPORT", HrmFaceCheckManager.getOaSubcompany()); + } else { + currentId = -1; + } + } + parentId = currentId; + } + 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; + String sqlInsert; + + 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) { + } else { + currentId = -2; + break; + } + // 如果编码为空 自动生成编码 + String departmentcode = ""; + try { + departmentcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.DEPARTMENT, String.valueOf(subCompanyId), departmentcode); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + sqlInsert = "insert into HrmDepartment (departmentname,Departmentmark,subcompanyid1,supdepid ," + DbFunctionUtil.getInsertColumnSql() + ", departmentcode) values('" + s.trim() + "','" + s.trim() + "'," + subCompanyId + "," + parentId + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ", '" + departmentcode + "')"; // 创建 + execSql(sqlInsert); + HrmTriggerUtil.generateDepartmentPinyin(s.trim(), null); + currentId = getResultSetId(sql); + HrmTriggerUtil.Tri_I_DeptKPICheckFlow(String.valueOf(currentId)); + MatrixUtil.updateDepartmentData(currentId + ""); + HrmFaceCheckManager.sync(currentId + "", HrmFaceCheckManager.getOptInsert(), "HRM_E9_IMPORT_getDeptId", HrmFaceCheckManager.getOaDepartment()); + } + parentId = currentId; + } + return currentId; + } + + /** + * 获取岗位id + * + * @param jobtitlename 岗位名称 + * @param jobactivityname 职务 + * @param jobgroupname 职务类型 + * @return + */ + 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) { + if (jobgroupname.length() == 0) { + selSql = "select max(id) as id from HrmJobGroups"; + jobgroupid = getResultSetId(selSql); + } else { + sqlInsert = "insert into HrmJobGroups (jobgroupname,jobgroupremark ," + DbFunctionUtil.getInsertColumnSql() + ") values('" + jobgroupname + "','" + jobgroupname + "'," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ")"; // 创建 + execSql(sqlInsert); + jobgroupid = getResultSetId(selSql); + } + } + + /* 获取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) { + sqlInsert = "insert into HrmJobActivities (jobactivityname,Jobactivitymark,jobgroupid ," + DbFunctionUtil.getInsertColumnSql() + ") values('" + jobactivityname + "','" + jobactivityname + "'," + jobgroupid + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ")"; // 创建 + execSql(sqlInsert); + jobactivityid = getResultSetId(selSql); + } + + /*获取岗位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) { + String jobtitlecode = ""; + try { + jobtitlecode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.JOBTITLES, jobtitlecode); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + sqlInsert = "insert into HrmJobTitles (jobtitlename,Jobtitlemark,jobactivityid ," + DbFunctionUtil.getInsertColumnSql() + ", jobtitlecode) values('" + jobtitlename + "','" + jobtitlename + "'," + jobactivityid + " ," + DbFunctionUtil.getInsertColumnValueSql(recordSet.getDBType(), 1) + ", '" + jobtitlecode + "')"; // 创建 + execSql(sqlInsert); + HrmTriggerUtil.generateJobtitlesPinyin(jobtitlename, null); + jobtitle = getResultSetId(selSql); + + HrmFaceCheckManager.sync(jobtitle + "", HrmFaceCheckManager.getOptInsert(), "hrm_e9_import_getJobtitles", HrmFaceCheckManager.getOaJobtitle()); + + } 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, + HrmResourceImportParam importParam) { + String statusOfHrmId = resourceComInfo.getStatus(hrmId); + String loginidOfHrmId = resourceComInfo.getLoginID(hrmId); + String accouttypeOfHrmId = resourceComInfo.getAccountType(hrmId); + + String statusOfExcel = importParam.getStatus(); + String loginidOfExcel = importParam.getLogin_id(); + String accouttypeOfExcel = importParam.getAccount_type(); + + // 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; //系统语言默认为中文 + + + //如果系统不支持多语言,则返回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; + } + + /** + * 获取人员密级 + * + * @return + */ + 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 = "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 importParam HrmResourceVo 人员信息对象 + * @param operation 操作类型 验证|创建|更新 + * @param status 状态 成功|失败 + * @param reason 失败原因 + * @return ImportLog对象 + */ + public ImportLog createLog(HrmResourceImportParam importParam, String operation, String status, String reason) { + ImportLog log = new ImportLog(); + + log.setWorkCode(importParam.getWork_code()); //编号 + log.setLastname(importParam.getLast_name()); //用户名 + log.setLoginid(importParam.getLogin_id()); //登录名 + log.setOperation(operation); //操作类型 + if (importParam.getCompany_id() != null && importParam.getDepartment_id() != null) + log.setDepartment(importParam.getCompany_id() + ">" + importParam.getDepartment_id()); //分部部门 + else log.setDepartment(""); + log.setStatus(status); //状态,成功、失败 + log.setReason(reason); //原因 + + try { + ImportLogService importLogService = ServiceUtil.getService(ImportLogServiceImpl.class, user); + String relatedName = ""; + switch (this.keyField) { + case "workcode": + relatedName = log.getWorkCode(); + break; + case "loginid": + relatedName = log.getLoginid(); + break; + case "lastname": + relatedName = log.getLastname(); + break; + } + + Map params = new HashMap<>(); + params.put("pId", this.pId); + params.put("lineNum", this.rowNum + 2);//修正偏移量错误 + params.put("relatedName", relatedName); + params.put("msg", log.getStatus().equals("成功") ? relatedName + "导入成功!" : log.getReason()); + params.put("status", log.getStatus().equals("成功") ? "1" : "0"); + importLogService.saveImportDeitalLog(params, user); + } catch (Exception e) { + new BaseBean().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(HrmResourceImportParam importParam, 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(importParam.getLogin_id()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(522076, userlanguage); + break; + case "workcode": + val = Util.null2String(importParam.getWork_code()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(520197, userlanguage); + break; + case "certificatenum": + val = Util.null2String(importParam.getCertificate_num()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(83521, userlanguage); + break; + } + int reosurceid = Util.getIntValue(checkInfo.get(val)); + if (importParam.getId() != null && importParam.getId() == reosurceid) { + //如果是当前记录,不需要校验 + continue; + } + + if (reosurceid > 0 && val.length() > 0) { + resultList.add(createLog(hrmResourceImportParam, this.operateType.equals("add") ? "创建" : "更新", "失败", errorMsg)); + return true; + } + } + } + return false; + } + +} diff --git a/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java b/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java index 37474de5..07684783 100644 --- a/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java +++ b/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java @@ -1,5 +1,6 @@ package com.engine.organization.service.impl; +import com.alibaba.fastjson.JSON; import com.api.browser.bean.SearchConditionGroup; import com.api.browser.bean.SearchConditionItem; import com.cloudstore.eccom.result.WeaResultMsg; @@ -12,6 +13,7 @@ import com.engine.organization.entity.company.po.CompPO; import com.engine.organization.entity.department.bo.DepartmentBO; import com.engine.organization.entity.department.po.DepartmentPO; import com.engine.organization.entity.extend.po.ExtendTitlePO; +import com.engine.organization.entity.hrmresource.param.HrmResourceImportParam; import com.engine.organization.entity.hrmresource.param.HrmResourceSearchParam; import com.engine.organization.entity.hrmresource.vo.HrmResourceVO; import com.engine.organization.entity.job.bo.JobBO; @@ -23,6 +25,8 @@ import com.engine.organization.mapper.department.DepartmentMapper; import com.engine.organization.mapper.extend.ExtendTitleMapper; import com.engine.organization.mapper.job.JobMapper; import com.engine.organization.service.ExtService; +import com.engine.organization.service.HrmResourceImportAdaptService; +import com.engine.organization.service.HrmResourceImportProcessService; import com.engine.organization.service.HrmResourceService; import com.engine.organization.util.MenuBtn; import com.engine.organization.util.OrganizationAssert; @@ -33,10 +37,12 @@ import com.engine.organization.util.tree.SearchTreeUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import weaver.conn.RecordSet; +import weaver.file.FileUploadToPath; import weaver.general.StringUtil; import weaver.general.Util; import weaver.hrm.User; +import javax.servlet.http.HttpServletRequest; import java.util.*; import java.util.stream.Collectors; @@ -242,6 +248,48 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic return btnDatas; } + @Override + public Map saveImportResource(Map params, HttpServletRequest request) { + + Map retmap = new HashMap(); + try { + /*综合考虑多数据源后,实现通过配置文件配置适配器和解析类*/ + List lsErrorInfo = new ArrayList(); + + HrmResourceImportAdaptService importAdapt = (HrmResourceImportAdaptService) Class.forName("com.engine.organization.service.impl.HrmResourceImportAdaptServiceImpl").newInstance(); + + FileUploadToPath fu = new FileUploadToPath(request); + + int language = this.user.getLanguage(); + importAdapt.setUserlanguage(language); + List errorInfo = importAdapt.creatImportMap(fu); + + //如果读取数据和验证模板没有发生错误 + if (errorInfo.isEmpty()) { + Map hrMap = importAdapt.getHrmImportMap(); + System.out.println(JSON.toJSON(hrMap)); + HrmResourceImportProcessService importProcess = (HrmResourceImportProcessService) Class.forName("com.engine.organization.service.impl.HrmResourceImportProcessServiceImpl").newInstance(); + importProcess.init(request); + importProcess.processMap(hrMap); + } else { + if (errorInfo != null && !errorInfo.isEmpty()) { + Map error; + for (int i = 0; i < errorInfo.size(); i++) { + error = new HashMap<>(); + error.put("message", Util.null2String(errorInfo.get(i))); + lsErrorInfo.add(error); + } + } + } + retmap.put("errorInfo", lsErrorInfo); + retmap.put("status", "1"); + } catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", e.getMessage()); + } + return retmap; + } + /** * 查询条件 * diff --git a/src/com/engine/organization/web/HrmResourceController.java b/src/com/engine/organization/web/HrmResourceController.java index b3c5e9ac..db1f325e 100644 --- a/src/com/engine/organization/web/HrmResourceController.java +++ b/src/com/engine/organization/web/HrmResourceController.java @@ -187,4 +187,18 @@ public class HrmResourceController { return ReturnResult.exceptionHandle(e.getMessage()); } } + + + @POST + @Path("/saveImportResource") + @Produces(MediaType.APPLICATION_JSON) + public ReturnResult saveImportResource(@Context HttpServletRequest request, @Context HttpServletResponse response) { + try { + User user = HrmUserVarify.getUser(request, response); + Map map = ParamUtil.request2Map(request); + return ReturnResult.successed(getHrmResourceWrapper(user).saveImportResource(map, request)); + } catch (Exception e) { + return ReturnResult.exceptionHandle(e.getMessage()); + } + } } diff --git a/src/com/engine/organization/wrapper/HrmResourceWrapper.java b/src/com/engine/organization/wrapper/HrmResourceWrapper.java index fa3dace7..26f38310 100644 --- a/src/com/engine/organization/wrapper/HrmResourceWrapper.java +++ b/src/com/engine/organization/wrapper/HrmResourceWrapper.java @@ -8,6 +8,7 @@ import com.engine.organization.service.HrmResourceService; import com.engine.organization.service.impl.HrmResourceServiceImpl; import weaver.hrm.User; +import javax.servlet.http.HttpServletRequest; import java.util.Map; /** @@ -52,4 +53,8 @@ public class HrmResourceWrapper extends Service { public Map getHasRight() { return getHrmResourceService(user).getHasRight(); } + + public Map saveImportResource(Map params, HttpServletRequest request) { + return getHrmResourceService(user).saveImportResource(params, request); + } }