diff --git a/src/com/api/organization/web/ImportCommonController.java b/src/com/api/organization/web/ImportCommonController.java new file mode 100644 index 00000000..141fe6d3 --- /dev/null +++ b/src/com/api/organization/web/ImportCommonController.java @@ -0,0 +1,12 @@ +package com.api.organization.web; + +import javax.ws.rs.Path; + +/** + * @author:dxfeng + * @createTime: 2022/06/29 + * @version: 1.0 + */ +@Path("/bs/hrmorganization/commonimport") +public class ImportCommonController extends com.engine.organization.web.ImportCommonController { +} 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/entity/hrmresource/po/HrmResourcePO.java b/src/com/engine/organization/entity/hrmresource/po/HrmResourcePO.java index 678f639a..3245bc2c 100644 --- a/src/com/engine/organization/entity/hrmresource/po/HrmResourcePO.java +++ b/src/com/engine/organization/entity/hrmresource/po/HrmResourcePO.java @@ -40,7 +40,7 @@ public class HrmResourcePO { /** * 性别 */ - private Integer sex; + private String sex; /** * 账号类型 @@ -75,7 +75,7 @@ public class HrmResourcePO { /** * 职称 */ - private Long jobCall; + private Integer jobCall; /** * 职级 @@ -120,12 +120,12 @@ public class HrmResourcePO { /** * 直接上级 */ - private Long managerId; + private Integer managerId; /** * 助理 */ - private Long assistantId; + private Integer assistantId; /** * 移动电话 @@ -161,4 +161,175 @@ public class HrmResourcePO { private int deleteType; private Date createTime; private Date updateTime; + + /** + * 密码 + */ + private String passWord; + + /** + * 安全级别 + */ + private Integer secLevel; + + /** + * 出生日期 + */ + private String birthday; + + /** + * 民族 + */ + private String folk; + + /** + * 籍贯 + */ + private String nativePlace; + + /** + * 户口 + */ + private String regResidentPlace; + + /** + * 身份证号码 + */ + private String certificateNum; + + /** + * 婚姻状况 + */ + private String maritalStatus; + + /** + * 政治面貌 + */ + private String policy; + + /** + * 入团日期 + */ + private String beMemberDate; + + /** + * 入党日期 + */ + private String bePartyDate; + + /** + * 工会会员 + */ + private String islabouunion; + + /** + * 学位 + */ + private String degree; + + /** + * 健康状况 + */ + private String healthInfo; + + /** + * 学历 + */ + private Integer educationLevel; + + /** + * 身高 + */ + private String height; + + /** + * 体重 + */ + private Integer weight; + + /** + * 用工性质 + */ + private Integer useKind; + + /** + * 合同开始日期 + */ + private String startDate; + + /** + * 合同结束日期 + */ + private String endDate; + + /** + * 试用期结束日期 + */ + private String probationEndDate; + + /** + * 现居住地 + */ + private String residentPlace; + + /** + * 家庭联系方式 + */ + private String homeAddress; + + /** + * 暂住证号码 + */ + private String tempResidentNumber; + + /** + * 入职日期 + */ + private String companyStartDate; + + /** + * 参加工作日期 + */ + private String workStartDate; + + /** + * 公积金帐户 + */ + private String accumFundAccount; + + /** + * 工资账号户名 + */ + private String accountName; + + /** + * 工资银行 + */ + private Integer bankId; + + /** + * 工资账号 + */ + private String accountId; + + /** + * 显示顺序 + */ + private Integer showOrder; + + /** + * 人员密级 + */ + private Integer classification; + + + private String workYear; + + + private String companyWorkYear; + + private String baseFieldsValue=""; + + private String baseFields=""; + } diff --git a/src/com/engine/organization/entity/postion/param/PostInfoSearchParam.java b/src/com/engine/organization/entity/postion/param/PostInfoSearchParam.java index 93de6af8..be9ffe5c 100644 --- a/src/com/engine/organization/entity/postion/param/PostInfoSearchParam.java +++ b/src/com/engine/organization/entity/postion/param/PostInfoSearchParam.java @@ -43,7 +43,7 @@ public class PostInfoSearchParam { /** * 职务分类 */ - private Integer postId; + private Long postId; /** * 说明 */ diff --git a/src/com/engine/organization/entity/postion/po/PostInfoPO.java b/src/com/engine/organization/entity/postion/po/PostInfoPO.java index 6fdcf20e..ee1290c0 100644 --- a/src/com/engine/organization/entity/postion/po/PostInfoPO.java +++ b/src/com/engine/organization/entity/postion/po/PostInfoPO.java @@ -45,7 +45,7 @@ public class PostInfoPO { /** * 职务分类 */ - private Integer postId; + private Long postId; /** * 说明 */ diff --git a/src/com/engine/organization/mapper/comp/CompMapper.xml b/src/com/engine/organization/mapper/comp/CompMapper.xml index d22ac668..ad99cb0a 100644 --- a/src/com/engine/organization/mapper/comp/CompMapper.xml +++ b/src/com/engine/organization/mapper/comp/CompMapper.xml @@ -135,7 +135,9 @@ #{description}, 0, - #{showOrder}, + + #{showOrder}, + diff --git a/src/com/engine/organization/mapper/hrmresource/HrmResourceMapper.java b/src/com/engine/organization/mapper/hrmresource/HrmResourceMapper.java new file mode 100644 index 00000000..97f2b629 --- /dev/null +++ b/src/com/engine/organization/mapper/hrmresource/HrmResourceMapper.java @@ -0,0 +1,12 @@ +package com.engine.organization.mapper.hrmresource; + +/** + * @description: + * @author:dxfeng + * @createTime: 2022/05/20 + * @version: 1.0 + */ +public interface HrmResourceMapper { + + Long getMaxId(); +} diff --git a/src/com/engine/organization/mapper/hrmresource/HrmResourceMapper.xml b/src/com/engine/organization/mapper/hrmresource/HrmResourceMapper.xml new file mode 100644 index 00000000..623d442e --- /dev/null +++ b/src/com/engine/organization/mapper/hrmresource/HrmResourceMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + t.id + , t.creator + , t.delete_type + , t.create_time + , t.update_time + + + + \ No newline at end of file diff --git a/src/com/engine/organization/mapper/post/PostInfoMapper.java b/src/com/engine/organization/mapper/post/PostInfoMapper.java index 9beeb3f8..8bb8b1d4 100644 --- a/src/com/engine/organization/mapper/post/PostInfoMapper.java +++ b/src/com/engine/organization/mapper/post/PostInfoMapper.java @@ -25,8 +25,11 @@ public interface PostInfoMapper { */ List listByNo(@Param("postInfoNo") String postInfoNo); + PostInfoPO getPostInfoByNameAndPostId(@Param("postInfoName") String postInfoName, @Param("postId") Long postId); + /** * 获取职务信息根据ID + * * @param id * @return */ @@ -39,10 +42,11 @@ public interface PostInfoMapper { * @return */ @MapKey("id") - List> listPostInfosByIds(@Param("ids") Collection ids); + List> listPostInfosByIds(@Param("ids") Collection ids); /** * 插入职务信息 + * * @param postInfoPO * @return */ @@ -63,6 +67,7 @@ public interface PostInfoMapper { * @return */ int updateForbiddenTagById(PostInfoPO postInfoPO); + /** * 批量删除职务信息方案 * diff --git a/src/com/engine/organization/mapper/post/PostInfoMapper.xml b/src/com/engine/organization/mapper/post/PostInfoMapper.xml index 10d12bf9..72c8d90b 100644 --- a/src/com/engine/organization/mapper/post/PostInfoMapper.xml +++ b/src/com/engine/organization/mapper/post/PostInfoMapper.xml @@ -60,6 +60,11 @@ #{id} + update jcl_org_post_info diff --git a/src/com/engine/organization/mapper/post/PostMapper.java b/src/com/engine/organization/mapper/post/PostMapper.java index db7ab1a0..22e104d1 100644 --- a/src/com/engine/organization/mapper/post/PostMapper.java +++ b/src/com/engine/organization/mapper/post/PostMapper.java @@ -26,6 +26,8 @@ public interface PostMapper { */ PostPO getPostByID(@Param("id") long id); + List listByName(@Param("postName") String postName); + /** * 根据ID查询职务分类列表 * 浏览按钮赋值、展示用 diff --git a/src/com/engine/organization/mapper/post/PostMapper.xml b/src/com/engine/organization/mapper/post/PostMapper.xml index df766b4b..0b5aa607 100644 --- a/src/com/engine/organization/mapper/post/PostMapper.xml +++ b/src/com/engine/organization/mapper/post/PostMapper.xml @@ -51,6 +51,11 @@ + update jcl_org_post 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/ImportCommonService.java b/src/com/engine/organization/service/ImportCommonService.java new file mode 100644 index 00000000..7925b451 --- /dev/null +++ b/src/com/engine/organization/service/ImportCommonService.java @@ -0,0 +1,20 @@ +package com.engine.organization.service; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2022/06/29 + * @version: 1.0 + */ +public interface ImportCommonService { + /** + * 人员导入 + * + * @param params + * @param request + * @return + */ + 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..8e81c05d --- /dev/null +++ b/src/com/engine/organization/service/impl/HrmResourceImportAdaptServiceImpl.java @@ -0,0 +1,1072 @@ +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.nio.charset.StandardCharsets; +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) { + //Excel导入错误,请阅读注意事项并检查模板文件 + errorInfo.add(SystemEnv.getHtmlLabelName(83617, userlanguage)); + 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 "login_id": + val = importParam.getLogin_id(); + break; + case "work_code": + val = importParam.getWork_code(); + break; + case "certificate_num": + 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 "login_id": + val = Util.null2String(importParam.getLogin_id()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(520127, userlanguage); + break; + case "work_code": + val = Util.null2String(importParam.getWork_code()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(520128, userlanguage); + break; + case "certificate_num": + 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 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 true; + Pattern pattern = Pattern.compile("\\d*(\\.?)\\d*"); + return !pattern.matcher(str).matches(); + } + + //整数判断 + public boolean isInteger(String str) { + if (str == null) + return false; + Pattern pattern = Pattern.compile("\\d+"); + return pattern.matcher(str).matches(); + } + + /** + * 获取字符串字节长度 由于java中中英字符都按1个字符,而数据库中汉字按两个字符计算 + * + * @param str + * @return + */ + public int getStrLength(String str) { + try { + if (str == null) + return 0; + else + return new String(str.getBytes("gb2312"), StandardCharsets.ISO_8859_1).length(); + } catch (Exception e) { + 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..e3654fdb --- /dev/null +++ b/src/com/engine/organization/service/impl/HrmResourceImportProcessServiceImpl.java @@ -0,0 +1,2044 @@ +package com.engine.organization.service.impl; + +import com.engine.common.entity.EncryptFieldEntity; +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.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.company.po.CompPO; +import com.engine.organization.entity.department.po.DepartmentPO; +import com.engine.organization.entity.hrmresource.param.HrmResourceImportParam; +import com.engine.organization.entity.hrmresource.po.HrmResourcePO; +import com.engine.organization.entity.job.po.JobPO; +import com.engine.organization.entity.postion.po.PostInfoPO; +import com.engine.organization.entity.postion.po.PostPO; +import com.engine.organization.mapper.comp.CompMapper; +import com.engine.organization.mapper.department.DepartmentMapper; +import com.engine.organization.mapper.hrmresource.HrmResourceMapper; +import com.engine.organization.mapper.job.JobMapper; +import com.engine.organization.mapper.post.PostInfoMapper; +import com.engine.organization.mapper.post.PostMapper; +import com.engine.organization.service.HrmResourceImportProcessService; +import com.engine.organization.util.PageInfoSortUtil; +import com.engine.organization.util.db.MapperProxyFactory; +import ln.LN; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.json.JSONObject; +import weaver.common.DateUtil; +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.encrypt.EncryptUtil; +import weaver.general.BaseBean; +import weaver.general.PasswordUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.common.database.dialect.DbDialectFactory; +import weaver.hrm.common.database.dialect.DialectUtil; +import weaver.hrm.definedfield.HrmFieldManager; +import weaver.hrm.passwordprotection.manager.HrmResourceManager; +import weaver.hrm.resource.ResourceComInfo; +import weaver.hrm.settings.ChgPasswdReminder; +import weaver.hrm.settings.RemindSettings; +import weaver.join.hrm.in.ImportLog; +import weaver.join.hrm.in.processImpl.HrmTlevelManager; +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 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; //登录语言 + + 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; + + + private HrmResourceMapper getResourceMapper() { + return MapperProxyFactory.getProxy(HrmResourceMapper.class); + } + + private CompMapper getCompMapper() { + return MapperProxyFactory.getProxy(CompMapper.class); + } + + private DepartmentMapper getDepartmentMapper() { + return MapperProxyFactory.getProxy(DepartmentMapper.class); + } + + private JobMapper getJobMapper() { + return MapperProxyFactory.getProxy(JobMapper.class); + } + + private PostInfoMapper getPostInfoMapper() { + return MapperProxyFactory.getProxy(PostInfoMapper.class); + } + + private PostMapper getPostMapper() { + return MapperProxyFactory.getProxy(PostMapper.class); + } + + @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 = ""; //部门名称 + long companyId = 0L; // 分部Id + long departmentId = 0L; // 部门id + String key; // workcode_lastname 组合 + getKeyMap(keyField); //获取重复性验证字段Map + Long id; + + Set keySet = hrMap.keySet(); + Object[] keyArray = keySet.toArray(); + + Class resourcePOClass = HrmResourcePO.class; + Class importParamClass = HrmResourceImportParam.class; + + String field = "id,work_code,login_id,last_name,sex,account_type,belong_to,company_id,department_id,job_activity,job_title,job_call,job_level,job_group_id,job_activity_desc,status,system_language,resource_image_id,messager_url,location_id,manager_id,assistant_id,mobile,telephone,mobile_call,fax,email,workroom,pass_word,sec_level,birthday,folk,native_place,reg_resident_place,certificate_num,marital_status,policy,be_member_date,be_party_date,islabouunion,degree,health_info,education_level,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_name,bank_id,account_id,show_order,classification,company_work_year,work_year"; + + String[] fields = field.split(","); + + int createrid = 1; // 创建者id + // 最后修改者id + if (user != null) { + createrid = user.getUID(); + } + + 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); + } + + String obj; + HrmResourcePO hrmResourcePO; + for (Object o : keyArray) { + obj = o.toString(); + hrmResourceImportParam = hrMap.get(obj); + key = obj; + hrmResourcePO = new HrmResourcePO(); + this.rowNum++; + 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; + companyId = getSubCompanyId(subCompanyName); + } + if (companyId == -9) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); + continue; + } + if (companyId == -2) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + continue; + } + if (companyId == -1) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83524, userlanguage))); + continue; + } + if (StringUtil.parseToInt(license.getConcurrentFlag(), 0) != 1) { + if (new HrmResourceManager().noMore(String.valueOf(companyId))) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83525, userlanguage))); + continue; + } + } + companyId = 0 == companyId ? null : companyId; + hrmResourcePO.setCompanyId(companyId); + } 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, companyId); + } + if (departmentId == -2) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + hrmResourcePO.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())) { + hrmResourcePO.setBelongTo(-1L); + hrmResourcePO.setAccountType(0); + } else if ("次账号".equals(hrmResourceImportParam.getAccount_type())) { + if (hrmResourceImportParam.getBelong_to() != null && !"".equals(hrmResourceImportParam.getBelong_to().trim())) { + long belongTo = getBelongId(hrmResourceImportParam.getBelong_to(), keyField); + hrmResourcePO.setBelongTo(belongTo); + if (!hrmResourceImportParam.getBelong_to().equals("") && belongTo == 0) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrmResourcePO.setAccountType(1); + } + } else { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } + } else { + hrmResourcePO.setBelongTo(-1L); + hrmResourcePO.setAccountType(0); + } + } else if (hrmResourceImportParam.getBelong_to() != null && !"".equals(hrmResourceImportParam.getBelong_to().trim())) { + long belongTo = getBelongId(hrmResourceImportParam.getBelong_to(), keyField); + hrmResourcePO.setBelongTo(belongTo); + if (!hrmResourceImportParam.getBelong_to().equals("") && belongTo == 0) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrmResourcePO.setAccountType(1); + } + } else { + hrmResourcePO.setBelongTo(-1L); + hrmResourcePO.setAccountType(0); + } + + // 岗位id + if (hrmResourceImportParam.getJob_title() != null && hrmResourceImportParam.getJob_activity() != null && hrmResourceImportParam.getJob_group_id() != null) { + String jobNames = hrmResourceImportParam.getJob_title(); + hrmResourcePO.setJobTitle(getJobTitles(companyId, departmentId, jobNames)); + } else { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83531, userlanguage))); + continue; + } + + //上级id + if (hrmResourceImportParam.getManager_id() != null) { + int managerid = getManagerId(hrmResourceImportParam.getManager_id(), keyField); + hrmResourcePO.setManagerId(0 == managerid ? null : managerid); + //如果vo.getManagerid()有值,但manageid未找到,说明填写有误 + if (!hrmResourceImportParam.getManager_id().equals("") && managerid == 0) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(83532, userlanguage))); + continue; + } + } else { + hrmResourcePO.setManagerId(null); + } + + // 助理id + if (hrmResourceImportParam.getAssistant_id() != null) { + int assistantId = getAssistantid(hrmResourceImportParam.getAssistant_id(), keyField); + hrmResourcePO.setAssistantId(assistantId); + if (!hrmResourceImportParam.getAssistant_id().equals("") && assistantId == 0) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", SystemEnv.getHtmlLabelName(24678, userlanguage))); + continue; + } + } + + // 办公地点 + if (hrmResourceImportParam.getLocation_id() != null) { + hrmResourcePO.setLocationId(getLocationid(hrmResourceImportParam.getLocation_id())); + } 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())) { + hrmResourcePO.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 { + hrmResourcePO.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 hrmResourcePO.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)) { + hrmResourcePO.setBankId(new Integer(fieldvalue)); + } else { + hrmResourcePO.setBankId(this.getBankId(hrmResourceImportParam.getBank_id())); + } + } + + //sunjsh-入职日期 + if (hrmResourceImportParam.getCompany_start_date() != null && !"".equals(hrmResourceImportParam.getCompany_start_date())) { + hrmResourcePO.setCompanyStartDate(hrmResourceImportParam.getCompany_start_date()); + } + + //sunjsh-参加工作日期 + if (hrmResourceImportParam.getWork_start_date() != null && !"".equals(hrmResourceImportParam.getWork_start_date())) { + hrmResourcePO.setWorkStartDate(hrmResourceImportParam.getWork_start_date()); + } + // 性别,为空或其他情况统一为0(男) + String sex = "女".equals(hrmResourceImportParam.getSex()) ? "1" : "0"; + hrmResourcePO.setSex(sex); + + // 职称 + if (hrmResourceImportParam.getJob_call() != null) { + int jobcall = getJobcall(hrmResourceImportParam.getJob_call()); + hrmResourcePO.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; + } + hrmResourcePO.setSystemLanguage(systemlanguage); + } else { + hrmResourcePO.setSystemLanguage(7); + } + + // 婚姻状况,如果不是以下选项,则默认为未婚 + String maritalStatus = "已婚".equals(hrmResourceImportParam.getMarital_status()) ? "1" : "离异".equals(hrmResourceImportParam.getMarital_status()) ? "2" : "0"; + hrmResourcePO.setMaritalStatus(maritalStatus); + + // 员工状态 + if (!"".equals(Util.null2String(hrmResourceImportParam.getStatus()))) { + int status = getStatus(hrmResourceImportParam.getStatus()); + hrmResourcePO.setStatus(status); + } else { + hrmResourcePO.setStatus(1); + } + + // 人员密级 + if (!"".equals(Util.null2String(hrmResourceImportParam.getClassification()))) { + int classification = getClassification(hrmResourceImportParam.getClassification()); + hrmResourcePO.setClassification(classification); + } + // 学历 + if (hrmResourceImportParam.getEducation_level() != null) { + int educationLevel = getEducationlevel(hrmResourceImportParam.getEducation_level()); + hrmResourcePO.setEducationLevel(educationLevel); + } + + // 工会会员,默认为是 + String islabouunion = "是".equals(hrmResourceImportParam.getIslabouunion()) ? "1" : "0"; + hrmResourcePO.setIslabouunion(islabouunion); + + // 健康状况 + if (hrmResourceImportParam.getHealth_info() != null) { + String healthinfo = getHealthinfo(hrmResourceImportParam.getHealth_info()); + hrmResourcePO.setHealthInfo(healthinfo); + } else { + hrmResourcePO.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 { + hrmResourcePO.setSecLevel(Util.getIntValue(hrmResourceImportParam.getSec_level())); + } + } else { + //安全级别为空时取缓存类中的安全级别 + hrmResourcePO.setSecLevel(0); + } + + //职级 + if (isInteger(hrmResourceImportParam.getJob_level())) { + // TODO 职级 + Long jobLevel = hrmResourceImportParam.getJob_level().equals("") ? 0 : Long.parseLong(hrmResourceImportParam.getJob_level()); + hrmResourcePO.setJobLevel(jobLevel); + } else { + hrmResourcePO.setJobLevel(0L); + } + Long jobGroupId = null; + if (hrmResourceImportParam.getJob_group_id() != null) { + List postPOS = getPostMapper().listByName(hrmResourceImportParam.getJob_group_id()); + if (CollectionUtils.isNotEmpty(postPOS)) { + jobGroupId = postPOS.get(0).getId(); + } else { + PostPO postPO = PostPO.builder() + .postName(hrmResourceImportParam.getJob_group_id()) + .creator((long) user.getUID()) + .deleteType(0) + .createTime(new Date()) + .build(); + getPostMapper().insertIgnoreNull(postPO); + jobGroupId = postPO.getId(); + } + hrmResourcePO.setJobGroupId(jobGroupId); + } + + // 职务 + if (hrmResourceImportParam.getJob_activity() != null) { + if (null == jobGroupId) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", "职务导入错误,未找到对应职务类别")); + continue; + } + PostInfoPO postInfoPO = getPostInfoMapper().getPostInfoByNameAndPostId(hrmResourceImportParam.getJob_activity(), jobGroupId); + if (null == postInfoPO) { + postInfoPO = PostInfoPO.builder() + .postInfoNo(hrmResourceImportParam.getJob_activity()) + .postInfoName(hrmResourceImportParam.getJob_activity()) + .postId(jobGroupId) + .creator((long) user.getUID()) + .deleteType(0) + .createTime(new Date()) + .build(); + getPostInfoMapper().insertIgnoreNull(postInfoPO); + } + hrmResourcePO.setJobActivity(postInfoPO.getId()); + } + + //用工性质 + if (hrmResourceImportParam.getUse_kind() != null) { + int useKind = getUseKind(hrmResourceImportParam.getUse_kind()); + hrmResourcePO.setUseKind(useKind); + } else { + hrmResourcePO.setUseKind(0); + } + + + // 手机 办公电话 + 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,非自动增长 + id = getResourceMapper().getMaxId() + 1; + hrmResourcePO.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; + } + } + } + // 显示顺序 + if (null != hrmResourceImportParam.getShow_order()) { + hrmResourcePO.setShowOrder(hrmResourceImportParam.getShow_order()); + } else { + hrmResourcePO.setShowOrder(id.intValue()); + } + + String[] encrypts = PasswordUtil.encrypt(password_tmp); + HrmFaceCheckManager.setUserPassowrd(id + "", password_tmp); + + String password = encrypts[0]; + String salt = encrypts[1]; + hrmResourcePO.setPassWord(password); + + boolean flag = true; + + /*添加人员信息*/ + String insertStr = "insert into jcl_org_hrmresource("; + StringBuilder insertFields = new StringBuilder(); + StringBuilder insertValues = new StringBuilder(); + + String workCode = hrmResourceImportParam.getWork_code(); + workCode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.USER, workCode); + hrmResourceImportParam.setWork_code(workCode); + + for (String s : fields) { + Field resourcePOClassField = resourcePOClass.getDeclaredField(PageInfoSortUtil.underlineToHump(s)); + Field paramClassDeclaredField = importParamClass.getDeclaredField(s); + + String hrmFieldType = resourcePOClassField.getType().getName(); + String voFieldType = paramClassDeclaredField.getType().getName(); + + resourcePOClassField.setAccessible(true); + paramClassDeclaredField.setAccessible(true); + + //首先取hrm对象中的数据,没有去vo中的 + boolean isNumber = hrmFieldType.endsWith("Long") || hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float"); + if (resourcePOClassField.get(hrmResourcePO) != null) { + if (hrmFieldType.endsWith("String")) { + insertFields.append(s).append(","); + insertValues.append("'").append(resourcePOClassField.get(hrmResourcePO)).append("',"); + } else if (isNumber) { + insertFields.append(s).append(","); + String insertValueStr = Util.null2String(resourcePOClassField.get(hrmResourcePO)); + if ("".equals(insertValueStr) && recordSet.getDBType().equalsIgnoreCase("postgresql")) { + insertValues.append("null,"); + } else { + insertValues.append(resourcePOClassField.get(hrmResourcePO)).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 (isNumber) { + 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(","); + } + + } + } + } + insertStr = insertStr + insertFields + "creator,delete_type,create_time,update_time) values(" + insertValues + createrid + ",'" + 0 + "','" + date + "','" + date + "')"; + boolean resourceInsertFlag = true; + if (!execSql(insertStr)) {//添加人员信息 + flag = false; + resourceInsertFlag = false; + } + if (resourceInsertFlag) {// 仅当人员插入成功后才进行自定义字段操作 + PasswordUtil.updateResourceSalt(id + "", salt); + // TODO 更新自定义字段 + //if (!updateBaseData(hrmResourceImportParam.getBaseFields(), hrmResourceImportParam.getBaseFieldsValue(), id.intValue())) { + // flag = false; + //} + } + + /*写日志*/ + 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; + } + } + } + } + } + + 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; + companyId = getSubCompanyId(subCompanyName); + issameSub = false; + } + if (companyId == -9) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getErrorMsgName(56, userlanguage))); + continue; + } + if (companyId == -2) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(126274, userlanguage))); + continue; + } + if (companyId == 0 || companyId == -1) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", companyId == 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(companyId))) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83525, userlanguage))); + continue; + } + } + companyId = 0 == companyId ? null : companyId; + hrmResourcePO.setCompanyId(companyId); + } + + // 部门id + String departmentNames = hrmResourceImportParam.getDepartment_id(); + if (!"".equals(Util.null2String(departmentNames))) { //部门存在时 + if (!issameSub || !departmentNames.equals(departmentName)) { + departmentName = departmentNames; + } + departmentId = getDeptId(departmentName, companyId); + if (departmentId == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83537, userlanguage))); + continue; + } + if (departmentId == -2) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(126275, userlanguage))); + continue; + } + hrmResourcePO.setDepartmentId(departmentId); + } + + //主账号id-sunjsh + if (hrmResourceImportParam.getAccount_type() != null && !"".equals(hrmResourceImportParam.getAccount_type())) { + if ("主账号".equals(hrmResourceImportParam.getAccount_type())) { + hrmResourcePO.setBelongTo(-1L); + hrmResourcePO.setAccountType(0); + } else if ("次账号".equals(hrmResourceImportParam.getAccount_type())) { + if (hrmResourceImportParam.getBelong_to() != null && !"".equals(hrmResourceImportParam.getBelong_to().trim())) { + long belongto = getBelongId(hrmResourceImportParam.getBelong_to(), keyField); + hrmResourcePO.setBelongTo(belongto); + if (!hrmResourceImportParam.getBelong_to().equals("") && belongto == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrmResourcePO.setAccountType(1); + } + } else { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } + } else { + hrmResourcePO.setBelongTo(-1L); + hrmResourcePO.setAccountType(0); + } + } else if (hrmResourceImportParam.getBelong_to() != null && !"".equals(hrmResourceImportParam.getBelong_to().trim())) { + long belongto = getBelongId(hrmResourceImportParam.getBelong_to(), keyField); + hrmResourcePO.setBelongTo(belongto); + if (!hrmResourceImportParam.getBelong_to().equals("") && belongto == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(131279, userlanguage))); + continue; + } else { + hrmResourcePO.setAccountType(1); + } + } + + // TODO 岗位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 jobNames = hrmResourceImportParam.getJob_title(); + hrmResourcePO.setJobTitle(getJobTitles(companyId, departmentId, jobNames)); + } + if (Util.getIntValue(hrmId) < 0) continue; + + + // 级序列 + if (!"".equals(Util.null2String(hrmResourceImportParam.getManager_id()))) { + int managerid = getManagerId(hrmResourceImportParam.getManager_id(), keyField); + //如果vo.getManagerid()有值,但manageid未找到,说明填写有误 + if (hrmResourceImportParam.getManager_id() != null && !hrmResourceImportParam.getManager_id().equals("") && managerid == 0) { + resultList.add(createLog(hrmResourceImportParam, "更新", "失败", SystemEnv.getHtmlLabelName(83532, userlanguage))); + continue; + } + hrmResourcePO.setManagerId(0 == managerid ? null : managerid); + } else { + hrmResourcePO.setManagerId(null); + } + // 助理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; + } + hrmResourcePO.setAssistantId(assistantId); + } + // 办公地点 + if (!"".equals(Util.null2String(hrmResourceImportParam.getLocation_id()))) { + int locationid = getLocationid(hrmResourceImportParam.getLocation_id()); + hrmResourcePO.setLocationId(locationid); + } + + //邮箱-sunjsh + if (hrmResourceImportParam.getEmail() != null) { + if (!"".equals(hrmResourceImportParam.getEmail().trim()) && hrmResourceImportParam.getEmail().contains("*")) { + hrmResourceImportParam.setEmail(null); + } else if ("".equals(hrmResourceImportParam.getEmail().trim())) { + hrmResourcePO.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 { + hrmResourcePO.setEmail(hrmResourceImportParam.getEmail()); + } + } + } + + //mobile-sunjsh + if (hrmResourceImportParam.getMobile() != null) { + if ("".equals(hrmResourceImportParam.getMobile().trim())) hrmResourcePO.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)) { + hrmResourcePO.setBankId(new Integer(fieldvalue)); + } else { + hrmResourcePO.setBankId(this.getBankId(hrmResourceImportParam.getBank_id())); + } + } + + //sunjsh-入职日期 + if (hrmResourceImportParam.getCompany_start_date() != null && !"".equals(hrmResourceImportParam.getCompany_start_date())) { + hrmResourcePO.setCompanyStartDate(hrmResourceImportParam.getCompany_start_date()); + } else { + hrmResourceImportParam.setCompany_start_date(null); + } + + //sunjsh-参加工作日期 + if (hrmResourceImportParam.getWork_start_date() != null && !"".equals(hrmResourceImportParam.getWork_start_date())) { + hrmResourcePO.setWorkStartDate(hrmResourceImportParam.getWork_start_date()); + } else { + hrmResourceImportParam.setWork_start_date(null); + } + // 职称 + if (!"".equals(Util.null2String(hrmResourceImportParam.getJob_call()))) { + hrmResourcePO.setJobCall(getJobcall(hrmResourceImportParam.getJob_call())); + } + // 系统语言,默认简体中文 + 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; + } + hrmResourcePO.setSystemLanguage(systemlanguage); + } + + // 性别,为空或其他情况统一为0(男) + if (hrmResourceImportParam.getSex() == null) { + hrmResourcePO.setSex("0"); + } else if (!"".equals(Util.null2String(hrmResourceImportParam.getSex()))) { + String sex = hrmResourceImportParam.getSex().equals("女") ? "1" : "0"; + hrmResourcePO.setSex(sex); + } + + // 婚姻状况,如果不是以下选项,则默认为未婚 + if (!"".equals(Util.null2String(hrmResourceImportParam.getMarital_status()))) { + String maritalstatus = hrmResourceImportParam.getMarital_status().equals("已婚") ? "1" : hrmResourceImportParam.getMarital_status().equals("离异") ? "2" : "0"; + hrmResourcePO.setMaritalStatus(maritalstatus); + } + + // 员工状态 + if (!"".equals(Util.null2String(hrmResourceImportParam.getStatus()))) { + int status = getStatus(hrmResourceImportParam.getStatus()); + hrmResourcePO.setStatus(status); + } else { + hrmResourcePO.setStatus(0); + } + + // 人员密级 + if (!"".equals(Util.null2String(hrmResourceImportParam.getClassification()))) { + int classification = getClassification(hrmResourceImportParam.getClassification()); + hrmResourcePO.setClassification(classification); + } + + // 学历 + if (!"".equals(Util.null2String(hrmResourceImportParam.getEducation_level()))) { + int educationlevel = getEducationlevel(hrmResourceImportParam.getEducation_level()); + hrmResourcePO.setEducationLevel(educationlevel); + } + + // 工会会员,默认为是 + if (!"".equals(Util.null2String(hrmResourceImportParam.getIslabouunion()))) { + String islabouunion = hrmResourceImportParam.getIslabouunion().equals("是") ? "1" : "0"; + hrmResourcePO.setIslabouunion(islabouunion); + } + + // 健康状况 + if (!"".equals(Util.null2String(hrmResourceImportParam.getHealth_info()))) { + String healthinfo = getHealthinfo(hrmResourceImportParam.getHealth_info()); + hrmResourcePO.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 { + hrmResourcePO.setSecLevel(Util.getIntValue(hrmResourceImportParam.getSec_level())); + } + } else { + // TODO + //安全级别为空时取缓存类中的安全级别 + // hrmResourcePO.setSecLevel(Integer.parseInt(resourcecominfo.getSeclevel(hrmId))); + } + + //职级 + if (isInteger(hrmResourceImportParam.getJob_level())) { + int joblevel = hrmResourceImportParam.getJob_level().equals("") ? 0 : Integer.parseInt(hrmResourceImportParam.getJob_level()); + hrmResourcePO.setJobLevel((long) joblevel); + } + + // 职务分类 + Long jobGroupId = null; + if (hrmResourceImportParam.getJob_group_id() != null) { + List postPOS = getPostMapper().listByName(hrmResourceImportParam.getJob_group_id()); + if (CollectionUtils.isNotEmpty(postPOS)) { + jobGroupId = postPOS.get(0).getId(); + } else { + PostPO postPO = PostPO.builder() + .postName(hrmResourceImportParam.getJob_group_id()) + .creator((long) user.getUID()) + .deleteType(0) + .createTime(new Date()) + .build(); + getPostMapper().insertIgnoreNull(postPO); + jobGroupId = postPO.getId(); + } + hrmResourcePO.setJobGroupId(jobGroupId); + } + + // 职务 + if (hrmResourceImportParam.getJob_activity() != null) { + if (null == jobGroupId) { + resultList.add(createLog(hrmResourceImportParam, "创建", "失败", "职务导入错误,未找到对应职务类别")); + continue; + } + PostInfoPO postInfoPO = getPostInfoMapper().getPostInfoByNameAndPostId(hrmResourceImportParam.getJob_activity(), jobGroupId); + if (null == postInfoPO) { + postInfoPO = PostInfoPO.builder() + .postInfoNo(hrmResourceImportParam.getJob_activity()) + .postInfoName(hrmResourceImportParam.getJob_activity()) + .postId(jobGroupId) + .creator((long) user.getUID()) + .deleteType(0) + .createTime(new Date()) + .build(); + getPostInfoMapper().insertIgnoreNull(postInfoPO); + } + hrmResourcePO.setJobActivity(postInfoPO.getId()); + } + + //用工性质 + if (hrmResourceImportParam.getUse_kind() != null) { + int usekind = getUseKind(hrmResourceImportParam.getUse_kind()); + hrmResourcePO.setUseKind(usekind); + } + + // 手机 办公电话 + 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]; + hrmResourcePO.setPassWord(pwdArr[0]); + + PasswordUtil.updateResourceSalt(keyMap.get(key) + "", salt); + HrmFaceCheckManager.setUserPassowrd(keyMap.get(key) + "", orgPwd); + + } + StringBuilder updateStr = new StringBuilder("update jcl_org_hrmresource set "); + + for (int k = 1; k < fields.length; k++) { + Field hrmField = resourcePOClass.getDeclaredField(PageInfoSortUtil.underlineToHump(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(hrmResourcePO)).trim().length() > 0) { + if (hrmFieldType.endsWith("String")) { + updateStr.append(fields[k]).append("='").append(hrmField.get(hrmResourcePO)).append("',"); + } else if (hrmFieldType.endsWith("Long") || hrmFieldType.endsWith("Integer") || hrmFieldType.endsWith("Short") || hrmFieldType.endsWith("Float")) { + updateStr.append(fields[k]).append("=").append(hrmField.get(hrmResourcePO)).append(","); + } + } 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("Long") || voFieldType.endsWith("Integer") || voFieldType.endsWith("Short") || voFieldType.endsWith("Float")) { + 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(","); + } + } + } + } + + // TODO + updateStr.append(" update_time ='").append(DateUtil.getCurrentDate()).append("' where id=").append(keyMap.get(key)); + + execSql(updateStr.toString()); + // TODO 更新自定义字段 + // updateBaseData(hrmResourceImportParam.getBaseFields(), hrmResourceImportParam.getBaseFieldsValue().trim(), keyMap.get(key)); + } + } catch (Exception e) { + //数据异常 + new BaseBean().writeLog(e); + } + } + try { + HrmTlevelManager.setUpdate(); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + + 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 = ""; + 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++) { + JSONObject jsonObject = baseTypeMap.get(baseFields[i]); + fielddbType = jsonObject.getString("fielddbtype"); + jsonObject.put("fieldvalue", baseValues[i]); + String fieldvalue = HrmFieldManager.getReallyFieldvalue(jsonObject); + + 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 Long getSubCompanyId(String subCompanyName) { + + String[] subCompanyNames = subCompanyName.split(">"); + if (subCompanyNames.length >= 10) { + return -9L; + } + long currentId = 0L; + long parentId = 0L; + int curCount = 0; + + String currentidsql; + String sql; + RecordSet recordSet = new RecordSet(); + + String supsubcomidConditon = DbDialectFactory.get(recordSet.getDBType()).isNull("parent_company", 0); + + for (String companyName : subCompanyNames) { + if (StringUtil.isNull(companyName)) continue; + + sql = "select id from jcl_org_comp where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(comp_name))," + userlanguage + ")))='" + companyName.trim() + "' and " + supsubcomidConditon + "=" + parentId; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + sql = "select id from jcl_org_comp where ltrim(rtrim(convToMultiLang(ltrim(rtrim(comp_name))," + userlanguage + ")))='" + companyName.trim() + "' and " + supsubcomidConditon + "=" + parentId; + } + currentidsql = sql + " and (delete_type = 0)"; + currentId = getResultSetId(currentidsql); + + if (parentId == 0 && currentId == 0) { + recordSet.execute("select COUNT(id) from jcl_org_comp where " + supsubcomidConditon + " = 0 "); + if (recordSet.next()) { + curCount = recordSet.getInt(1); + } + } + + //added by wcd 2015-02-06 [限制分部数] + if (currentId == 0) { + if (scCount == 0 || curCount < scCount) { + // 如果编码为空 自动生成编码 + String compNo = ""; + try { + compNo = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.SUBCOMPANY, compNo); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + CompPO compPO = CompPO.builder() + .compNo(compNo) + .compName(companyName.trim()) + .compNameShort(companyName.trim()) + .parentCompany(0 == parentId ? null : parentId) + .creator((long) user.getUID()) + .deleteType(0) + .createTime(new Date()) + .build(); + getCompMapper().insertIgnoreNull(compPO); + currentId = compPO.getId().intValue(); + + } else { + currentId = -1; + } + } + parentId = currentId; + } + return currentId; + } + + /** + * 获取部门id,不存在就创建 + * + * @param deptNames 部门名称 + * @param companyId 所属分部id + * @return + */ + public Long getDeptId(String deptNames, long companyId) { + + String[] deptNameArray = deptNames.split(">"); + long currentId = 0L; + long parentId = 0L; + + String currentIdSql; + String sql; + + RecordSet recordSet = new RecordSet(); + + String supdepidConditon = DbDialectFactory.get(recordSet.getDBType()).isNull("parent_dept", 0); + + for (String deptName : deptNameArray) { + if (deptName == null || deptName.equals("")) { + continue; + } + + sql = "select id from jcl_org_dept where parent_comp=" + companyId + " and ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(dept_name))," + userlanguage + ")))='" + deptName.trim() + "' and " + supdepidConditon + "=" + parentId; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + sql = "select id from jcl_org_dept where parent_comp=" + companyId + " and ltrim(rtrim(convToMultiLang(ltrim(rtrim(dept_name))," + userlanguage + ")))='" + deptName.trim() + "' and " + supdepidConditon + "=" + parentId; + } + currentIdSql = sql + " and delete_type = 0"; + currentId = getResultSetId(currentIdSql); + + if (currentId == 0) { + // 如果编码为空 自动生成编码 + String deptNo = ""; + try { + deptNo = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.DEPARTMENT, deptNo); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + DepartmentPO departmentPO = DepartmentPO.builder() + .deptNo(deptNo) + .deptName(deptName.trim()) + .deptNameShort(deptName.trim()) + .parentComp(0 == companyId ? null : companyId) + .parentDept(0 == parentId ? null : parentId) + .forbiddenTag(0) + .creator((long) user.getUID()) + .deleteType(0) + .createTime(new Date()) + .build(); + getDepartmentMapper().insertIgnoreNull(departmentPO); + currentId = departmentPO.getId().intValue(); + } + parentId = currentId; + } + return currentId; + } + + public Long getJobTitles(Long companyId, Long departmentId, String jobNames) { + + + String[] jobNameArray = jobNames.split(">"); + long currentId = 0L; + long parentId = 0L; + String currentIdSql; + String sql; + RecordSet recordSet = new RecordSet(); + String parentJobConditon = DbDialectFactory.get(recordSet.getDBType()).isNull("parent_job", 0); + + for (String jobName : jobNameArray) { + if (jobName == null || jobName.equals("")) { + continue; + } + sql = "select id from jcl_org_job where parent_comp=" + companyId + " and parent_dept = " + departmentId + " and ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(job_name))," + userlanguage + ")))='" + jobName.trim() + "' and " + parentJobConditon + "=" + parentId; + if (recordSet.getDBType().equalsIgnoreCase("oracle") || DialectUtil.isMySql(recordSet.getDBType()) || recordSet.getDBType().equalsIgnoreCase("postgresql")) { + sql = "select id from jcl_org_job where parent_comp=" + companyId + " and parent_dept = " + departmentId + " and ltrim(rtrim(convToMultiLang(ltrim(rtrim(job_name))," + userlanguage + ")))='" + jobName.trim() + "' and " + parentJobConditon + "=" + parentId; + } + currentIdSql = sql + " and delete_type = 0"; + currentId = getResultSetId(currentIdSql); + + if (currentId == 0) { + // 如果编码为空 自动生成编码 + String jobNo = ""; + try { + jobNo = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.JOBTITLES, jobNo); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + JobPO jobPO = JobPO.builder() + .jobNo(jobNo) + .jobName(jobName) + .parentComp(0 == companyId ? null : companyId) + .parentDept(0 == departmentId ? null : departmentId) + .parentJob(0 == parentId ? null : parentId) + .forbiddenTag(0) + .creator((long) user.getUID()) + .deleteType(0) + .createTime(new Date()) + .build(); + getJobMapper().insertIgnoreNull(jobPO); + currentId = jobPO.getId(); + } + parentId = currentId; + } + return currentId; + } + + + 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 int getManagerId(String keyFieldValue, String keyField) { + + int managerId = 0; + RecordSet recordSet = new RecordSet(); + if (!keyFieldValue.equals("")) { + String selSql = "select id from jcl_org_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 jcl_org_hrmresource where ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + } + recordSet.execute(selSql); + while (recordSet.next()) { + managerId = recordSet.getInt("id"); + } + } + return managerId; + } + + /** + * 获取助理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 jcl_org_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 jcl_org_hrmresource where ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + } + getAssistantid = getResultSetId(selSql); + } + return getAssistantid; + } + + /** + * 获取主账号id + * + * @param keyFieldValue 主账号标记 + * @param keyField 关键字段 + * @return + */ + public Long getBelongId(String keyFieldValue, String keyField) { + int getAssistantid = -1; + RecordSet recordSet = new RecordSet(); + if (!keyFieldValue.equals("")) { + String selSql = "select id from jcl_org_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 jcl_org_hrmresource where ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + ")))= '" + keyFieldValue + "'"; + } + getAssistantid = getResultSetId(selSql); + } + return (long) 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 = 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) { + // TODO + RecordSet recordSet = new RecordSet(); + String sql = "select id, account_type, certificate_num, login_id, work_code, ltrim(rtrim(convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + "))) as " + keyField + " from jcl_org_hrmresource"; + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sql = "select id, account_type, certificate_num, login_id, work_code, ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(" + keyField + "))," + userlanguage + "))) as " + keyField + " from jcl_org_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("certificate_num"); + keyMap.put(recordSet.getString(keyField), recordSet.getInt("id")); + // TODO + String accounttype = recordSet.getString("account_type"); + 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 "work_code": + relatedName = log.getWorkCode(); + break; + case "login_id": + relatedName = log.getLoginid(); + break; + case "last_name": + 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 "login_id": + val = Util.null2String(importParam.getLogin_id()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(522076, userlanguage); + break; + case "work_code": + val = Util.null2String(importParam.getWork_code()).trim(); + errorMsg = SystemEnv.getHtmlLabelName(520197, userlanguage); + break; + case "certificate_num": + 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/ImportCommonServiceImpl.java b/src/com/engine/organization/service/impl/ImportCommonServiceImpl.java new file mode 100644 index 00000000..45767118 --- /dev/null +++ b/src/com/engine/organization/service/impl/ImportCommonServiceImpl.java @@ -0,0 +1,64 @@ +package com.engine.organization.service.impl; + +import com.engine.core.impl.Service; +import com.engine.organization.entity.hrmresource.param.HrmResourceImportParam; +import com.engine.organization.service.HrmResourceImportAdaptService; +import com.engine.organization.service.HrmResourceImportProcessService; +import com.engine.organization.service.ImportCommonService; +import weaver.file.FileUploadToPath; +import weaver.general.Util; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2022/06/29 + * @version: 1.0 + */ +public class ImportCommonServiceImpl extends Service implements ImportCommonService { + + @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(); + 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/util/PageInfoSortUtil.java b/src/com/engine/organization/util/PageInfoSortUtil.java index 9146a6b8..79d267e0 100644 --- a/src/com/engine/organization/util/PageInfoSortUtil.java +++ b/src/com/engine/organization/util/PageInfoSortUtil.java @@ -21,7 +21,7 @@ public class PageInfoSortUtil { * @return */ public static String getSortSql(String sortParams) { - JSONArray jsonArray = JSONObject.parseArray(sortParams); + JSONArray jsonArray = JSONObject.parseArray(sortParams); if (CollectionUtils.isNotEmpty(jsonArray)) { JSONObject jsonObject = (JSONObject) jsonArray.get(0); String orderKey = upperCharToUnderLine(jsonObject.getString("orderkey")); @@ -54,4 +54,28 @@ public class PageInfoSortUtil { } return builder.toString(); } + + /** + * 下划线转驼峰 + * + * @param str + * @return + */ + public static String underlineToHump(String str) { + //正则匹配下划线及后一个字符,删除下划线并将匹配的字符转成大写 + Matcher matcher = Pattern.compile("_([a-z])").matcher(str); + StringBuffer sb = new StringBuffer(str); + if (matcher.find()) { + sb = new StringBuffer(); + //将当前匹配的子串替换成指定字符串,并且将替换后的子串及之前到上次匹配的子串之后的字符串添加到StringBuffer对象中 + //正则之前的字符和被替换的字符 + matcher.appendReplacement(sb, matcher.group(1).toUpperCase()); + //把之后的字符串也添加到StringBuffer对象中 + matcher.appendTail(sb); + } else { + //去除除字母之外的前面带的下划线 + return sb.toString().replaceAll("_", ""); + } + return underlineToHump(sb.toString()); + } } diff --git a/src/com/engine/organization/util/excel/ExcelParseHelper.java b/src/com/engine/organization/util/excel/ExcelParseHelper.java index 9c7f2d57..6a4bd001 100644 --- a/src/com/engine/organization/util/excel/ExcelParseHelper.java +++ b/src/com/engine/organization/util/excel/ExcelParseHelper.java @@ -1,8 +1,5 @@ package com.engine.organization.util.excel; -import com.engine.salary.util.excel.ExcelParseException; -import com.engine.salary.util.excel.ExcelProperty; -import com.engine.salary.util.excel.ExcelSupport; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.exception.ContextedRuntimeException; @@ -14,7 +11,7 @@ import java.lang.reflect.Field; import java.math.BigDecimal; import java.util.*; -import static com.engine.salary.util.excel.ExcelSupport.EXCEL_TYPE_XLSX; +import static com.engine.organization.util.excel.ExcelSupport.EXCEL_TYPE_XLSX; /** * Excel 解析工具类 diff --git a/src/com/engine/organization/web/ImportCommonController.java b/src/com/engine/organization/web/ImportCommonController.java new file mode 100644 index 00000000..1780e17b --- /dev/null +++ b/src/com/engine/organization/web/ImportCommonController.java @@ -0,0 +1,42 @@ +package com.engine.organization.web; + +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import com.engine.organization.util.response.ReturnResult; +import com.engine.organization.wrapper.ImportCommonWrapper; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2022/06/29 + * @version: 1.0 + */ +public class ImportCommonController { + + private ImportCommonWrapper getImportCommonWrapper(User user) { + return ServiceUtil.getService(ImportCommonWrapper.class, user); + } + + @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(getImportCommonWrapper(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..ea57986b 100644 --- a/src/com/engine/organization/wrapper/HrmResourceWrapper.java +++ b/src/com/engine/organization/wrapper/HrmResourceWrapper.java @@ -52,4 +52,6 @@ public class HrmResourceWrapper extends Service { public Map getHasRight() { return getHrmResourceService(user).getHasRight(); } + + } diff --git a/src/com/engine/organization/wrapper/ImportCommonWrapper.java b/src/com/engine/organization/wrapper/ImportCommonWrapper.java new file mode 100644 index 00000000..2a5d99c5 --- /dev/null +++ b/src/com/engine/organization/wrapper/ImportCommonWrapper.java @@ -0,0 +1,26 @@ +package com.engine.organization.wrapper; + +import com.engine.common.util.ServiceUtil; +import com.engine.core.impl.Service; +import com.engine.organization.service.ImportCommonService; +import com.engine.organization.service.impl.ImportCommonServiceImpl; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2022/06/29 + * @version: 1.0 + */ +public class ImportCommonWrapper extends Service { + + private ImportCommonService getImportCommonService(User user) { + return ServiceUtil.getService(ImportCommonServiceImpl.class, user); + } + + public Map saveImportResource(Map params, HttpServletRequest request) { + return getImportCommonService(user).saveImportResource(params, request); + } +}