|
|
|
@ -1,628 +0,0 @@
|
|
|
|
|
package com.engine.organization.util.saveimport;
|
|
|
|
|
|
|
|
|
|
import com.engine.common.util.ParamUtil;
|
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
import com.engine.hrm.service.ImportLogService;
|
|
|
|
|
import com.engine.hrm.service.impl.ImportLogServiceImpl;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
|
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import weaver.file.ImageFileManager;
|
|
|
|
|
import weaver.general.BaseBean;
|
|
|
|
|
import weaver.general.Util;
|
|
|
|
|
import weaver.hrm.User;
|
|
|
|
|
import weaver.hrm.excelimport.*;
|
|
|
|
|
import weaver.systeminfo.SystemEnv;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author:dxfeng
|
|
|
|
|
* @createTime: 2022/06/30
|
|
|
|
|
* @version: 1.0
|
|
|
|
|
*/
|
|
|
|
|
public class SaveImportProcessUtil {
|
|
|
|
|
/**
|
|
|
|
|
* 导入类型
|
|
|
|
|
*/
|
|
|
|
|
private String importType;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* excel页签
|
|
|
|
|
*/
|
|
|
|
|
private HSSFSheet sheet;
|
|
|
|
|
/**
|
|
|
|
|
* 存储报错信息位置
|
|
|
|
|
*/
|
|
|
|
|
private final List<Object> lsImportSourceMap = new ArrayList<>();
|
|
|
|
|
/**
|
|
|
|
|
* 存储报错信息
|
|
|
|
|
*/
|
|
|
|
|
private final List<String> errorInfo = new ArrayList<>();
|
|
|
|
|
/**
|
|
|
|
|
* 存储参数类型名称
|
|
|
|
|
*/
|
|
|
|
|
private final Map<String, Method> parameterTypes = new HashMap<>();
|
|
|
|
|
/**
|
|
|
|
|
* 字段类型
|
|
|
|
|
*/
|
|
|
|
|
private final Map<String, String> fieldTypes = new HashMap<>();
|
|
|
|
|
/**
|
|
|
|
|
* 类名
|
|
|
|
|
*/
|
|
|
|
|
private final Map<String, String[]> mapImportSource = new HashMap<>();
|
|
|
|
|
/**
|
|
|
|
|
* 导入类型名称
|
|
|
|
|
*/
|
|
|
|
|
private final Map<String, String> mapImportSourceName = new HashMap<>();
|
|
|
|
|
/**
|
|
|
|
|
* excel文件中对应的字段别名
|
|
|
|
|
*/
|
|
|
|
|
private final Map<String, String[]> mapImportSourceField = new HashMap<>();
|
|
|
|
|
/**
|
|
|
|
|
* excel文件中对应的字段名称
|
|
|
|
|
*/
|
|
|
|
|
private final Map<String, String[]> mapImportSourceFieldName = new HashMap<>();
|
|
|
|
|
/**
|
|
|
|
|
* 多语言--中文
|
|
|
|
|
*/
|
|
|
|
|
private int userLanguage = 7;
|
|
|
|
|
/**
|
|
|
|
|
* 字段名
|
|
|
|
|
*/
|
|
|
|
|
private String[] voFields;
|
|
|
|
|
/**
|
|
|
|
|
* 类
|
|
|
|
|
*/
|
|
|
|
|
private Class<?> importSourceClass;
|
|
|
|
|
/**
|
|
|
|
|
* 字段标识
|
|
|
|
|
*/
|
|
|
|
|
private String keyField = "";
|
|
|
|
|
/**
|
|
|
|
|
* 操作人
|
|
|
|
|
*/
|
|
|
|
|
private String creator = "";
|
|
|
|
|
/**
|
|
|
|
|
* 导入类型
|
|
|
|
|
*/
|
|
|
|
|
private String operateType = "";
|
|
|
|
|
/**
|
|
|
|
|
* 常用组成员导入为覆盖时,清除旧数据只需要执行一次。false--还未清除旧数据、true--旧数据已经清除
|
|
|
|
|
*/
|
|
|
|
|
private boolean isDeleted = false;
|
|
|
|
|
|
|
|
|
|
private User user;
|
|
|
|
|
private int pId = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 客户端操作IP
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public SaveImportProcessUtil() {
|
|
|
|
|
// TODO 组织导入类
|
|
|
|
|
mapImportSource.put("company", new String[]{CompanyImportUtil.class.getName()});
|
|
|
|
|
|
|
|
|
|
mapImportSource.put("jobtitle", new String[]{HrmJobTitle.class.getName()});
|
|
|
|
|
mapImportSource.put("group", new String[]{HrmGroup.class.getName()});
|
|
|
|
|
mapImportSource.put("groupMember", new String[]{HrmGroupMember.class.getName()});
|
|
|
|
|
mapImportSource.put("resourcedetial", new String[]{HrmFamilyInfo.class.getName(),
|
|
|
|
|
HrmLanguageAbility.class.getName(),
|
|
|
|
|
HrmEducationInfo.class.getName(),
|
|
|
|
|
HrmWorkResume.class.getName(),
|
|
|
|
|
HrmTrainBeforeWork.class.getName(),
|
|
|
|
|
HrmCertification.class.getName(),
|
|
|
|
|
HrmRewardBeforeWork.class.getName()});
|
|
|
|
|
mapImportSource.put("city", new String[]{HrmCity.class.getName()});
|
|
|
|
|
mapImportSource.put("location", new String[]{HrmLoaction.class.getName()});
|
|
|
|
|
mapImportSource.put("special", new String[]{HrmSpeciality.class.getName()});
|
|
|
|
|
mapImportSource.put("area", new String[]{HrmArea.class.getName()});
|
|
|
|
|
mapImportSource.put("sensitiveword", new String[]{SensitiveWord.class.getName()});
|
|
|
|
|
|
|
|
|
|
mapImportSourceName.put("company", "分部、部门导入");
|
|
|
|
|
mapImportSourceName.put("jobtitle", "岗位体系导入");
|
|
|
|
|
mapImportSourceName.put("group", "常用组信息导入");
|
|
|
|
|
mapImportSourceName.put("groupMember", "常用组成员导入");
|
|
|
|
|
mapImportSourceName.put("resourcedetial", "个人数据导入");
|
|
|
|
|
mapImportSourceName.put("city", "位置信息导入");
|
|
|
|
|
mapImportSourceName.put("location", "办公地点信息导入");
|
|
|
|
|
mapImportSourceName.put("special", "专业信息导入");
|
|
|
|
|
mapImportSourceName.put("area", "行政区域导入");
|
|
|
|
|
mapImportSourceName.put("sensitiveword", "敏感词");
|
|
|
|
|
|
|
|
|
|
mapImportSourceField.put("company", new String[]{"subcompanyname,departmentname,subcompanyshoworder,subcompanycode,departmentshoworder,departmentcode"});
|
|
|
|
|
mapImportSourceField.put("jobtitle", new String[]{"jobtitlemark,jobtitlename,jobtitlecode,jobactivityname,jobgroupname,jobresponsibility,jobcompetency,jobtitleremark"});
|
|
|
|
|
mapImportSourceField.put("group", new String[]{"typename,groupname,username,keycode"});
|
|
|
|
|
mapImportSourceField.put("groupMember", new String[]{"workCode,lastName,loginId"});
|
|
|
|
|
mapImportSourceField.put("resourcedetial", new String[]{"lastname,loginid,member,title,company,jobtitle,address",
|
|
|
|
|
"lastname,loginid,language,level_n,memo",
|
|
|
|
|
"lastname,loginid,school,speciality,startdate,enddate,educationlevel,studydesc",
|
|
|
|
|
"lastname,loginid,company,startdate,enddate,jobtitle,workdesc,leavereason",
|
|
|
|
|
"lastname,loginid,trainname,trainstartdate,trainenddate,trainresource,trainmemo",
|
|
|
|
|
"lastname,loginid,certname,datefrom,dateto,awardfrom",
|
|
|
|
|
"lastname,loginid,rewardname,rewarddate,rewardmemo"});
|
|
|
|
|
mapImportSourceField.put("city", new String[]{"位置信息导入"});
|
|
|
|
|
mapImportSourceField.put("location", new String[]{"locationname,locationdesc,locationcityname,countryname,showorder"});
|
|
|
|
|
mapImportSourceField.put("special", new String[]{"name,description"});
|
|
|
|
|
mapImportSourceField.put("area", new String[]{"countryname,provincename,cityname,citytwoname,longitude,latitude"});
|
|
|
|
|
mapImportSourceField.put("sensitiveword", new String[]{"word,description,wordtype,handleway"});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapImportSourceFieldName.put("company", new String[]{"分部[必填],部门,分部显示顺序,分部编号,部门显示顺序,部门编号"});
|
|
|
|
|
mapImportSourceFieldName.put("jobtitle", new String[]{"岗位简称[必填],岗位全称[必填],岗位编号,所属职务[必填],职务类别[必填],岗位职责,任职资格,备注"});
|
|
|
|
|
mapImportSourceFieldName.put("group", new String[]{"类型[必填],名称[必填],成员姓名[必填],成员登录名[必填]"});
|
|
|
|
|
mapImportSourceFieldName.put("groupMember", new String[]{"编号,姓名,登录名"});
|
|
|
|
|
mapImportSourceFieldName.put("resourcedetial", new String[]{"员工姓名[必填],员工登录名[必填],成员,称谓,工作单位,职务,地址",
|
|
|
|
|
"员工姓名[必填],员工登录名[必填],语言,水平,备注",
|
|
|
|
|
"员工姓名[必填],员工登录名[必填],学校名称,专业,开始日期,结束日期,学历,详细描述",
|
|
|
|
|
"员工姓名[必填],员工登录名[必填],公司名称,开始日期,结束日期,职务,工作描述,离开原因",
|
|
|
|
|
"员工姓名[必填],员工登录名[必填],培训名称,开始日期,结束日期,培训单位,备注",
|
|
|
|
|
"员工姓名[必填],员工登录名[必填],名称,开始日期,结束日期,颁发单位",
|
|
|
|
|
"员工姓名[必填],员工登录名[必填],奖惩名称,奖惩日期,备注"});
|
|
|
|
|
mapImportSourceFieldName.put("city", new String[]{"位置信息导入"});
|
|
|
|
|
mapImportSourceFieldName.put("location", new String[]{"办公地点简称[必填],办公地点全称[必填],城市[必填],国家,顺序"});
|
|
|
|
|
mapImportSourceFieldName.put("special", new String[]{"专业名称[必填],专业描述[必填]"});
|
|
|
|
|
mapImportSourceFieldName.put("area", new String[]{"国家[必填],省份,城市,区县,经度,纬度"});
|
|
|
|
|
mapImportSourceFieldName.put("sensitiveword", new String[]{"敏感词[必填],详细描述,所属分类[必填],处理方式[必填]"});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取数据
|
|
|
|
|
*
|
|
|
|
|
* @param request 请求
|
|
|
|
|
*/
|
|
|
|
|
public List<String> importXls(HttpServletRequest request) {
|
|
|
|
|
ImportLogService importLogService = ServiceUtil.getService(ImportLogServiceImpl.class, user);
|
|
|
|
|
Map<String, Object> params;
|
|
|
|
|
try {
|
|
|
|
|
this.user = (User) request.getSession(true).getAttribute("weaver_user@bean");
|
|
|
|
|
String filename = request.getParameter("excelfile");
|
|
|
|
|
this.importType = Util.null2String(request.getParameter("importType"));
|
|
|
|
|
this.keyField = Util.null2String(request.getParameter("keyField"));
|
|
|
|
|
this.creator = "" + user.getUID();
|
|
|
|
|
this.userLanguage = Util.getIntValue(request.getParameter("userlanguage"), 7);
|
|
|
|
|
this.operateType = Util.null2String(request.getParameter("operateType"));
|
|
|
|
|
// 常用组导入为覆盖时,已经清除掉旧数据的常用组ID集合(暂时只用于常用组的导入)
|
|
|
|
|
List<Integer> deletedGroupId = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
ImageFileManager manager = new ImageFileManager();
|
|
|
|
|
manager.getImageFileInfoById(Util.getIntValue(filename));
|
|
|
|
|
HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(manager.getInputStream()));
|
|
|
|
|
|
|
|
|
|
params = ParamUtil.request2Map(request);
|
|
|
|
|
Map<String, Object> retmap = importLogService.saveImportLog(params, request, user);
|
|
|
|
|
if (Util.null2String(retmap.get("status")).equals("1")) {
|
|
|
|
|
this.pId = Util.getIntValue(Util.null2String(retmap.get("pId")));
|
|
|
|
|
String pIdName = "hrm" + this.importType + "PId";
|
|
|
|
|
request.getSession(true).setAttribute(pIdName, this.pId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String[] tmpMapImportSource = mapImportSource.get(this.importType);
|
|
|
|
|
int idx = 0;
|
|
|
|
|
for (String tmpImportSource : tmpMapImportSource) {
|
|
|
|
|
idx++;
|
|
|
|
|
this.sheet = workbook.getSheetAt(idx);
|
|
|
|
|
importSourceClass = Class.forName(tmpImportSource);
|
|
|
|
|
voFields = mapImportSourceField.get(this.importType)[idx - 1].split(",");
|
|
|
|
|
initReflectParam();
|
|
|
|
|
/*校验模板有效性 */
|
|
|
|
|
if (idx == 1) {
|
|
|
|
|
String[] importSourceFieldName = mapImportSourceFieldName.get(this.importType);
|
|
|
|
|
String valExcelTempInfo = valExcelTemp(importSourceFieldName[idx - 1]);
|
|
|
|
|
if (valExcelTempInfo.length() > 0) {
|
|
|
|
|
this.errorInfo.add(valExcelTempInfo);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
readexcel();
|
|
|
|
|
String importSourceName;
|
|
|
|
|
if (tmpImportSource.equals(HrmFamilyInfo.class.getName())) {
|
|
|
|
|
importSourceName = SystemEnv.getHtmlLabelName(814, userLanguage);
|
|
|
|
|
} else if (tmpImportSource.equals(HrmLanguageAbility.class.getName())) {
|
|
|
|
|
importSourceName = SystemEnv.getHtmlLabelName(815, userLanguage);
|
|
|
|
|
} else if (tmpImportSource.equals(HrmEducationInfo.class.getName())) {
|
|
|
|
|
importSourceName = SystemEnv.getHtmlLabelName(813, userLanguage);
|
|
|
|
|
} else if (tmpImportSource.equals(HrmWorkResume.class.getName())) {
|
|
|
|
|
importSourceName = SystemEnv.getHtmlLabelName(15716, userLanguage);
|
|
|
|
|
} else if (tmpImportSource.equals(HrmTrainBeforeWork.class.getName())) {
|
|
|
|
|
importSourceName = SystemEnv.getHtmlLabelName(15717, userLanguage);
|
|
|
|
|
} else if (tmpImportSource.equals(HrmCertification.class.getName())) {
|
|
|
|
|
importSourceName = SystemEnv.getHtmlLabelName(1502, userLanguage);
|
|
|
|
|
} else if (tmpImportSource.equals(HrmRewardBeforeWork.class.getName())) {
|
|
|
|
|
importSourceName = SystemEnv.getHtmlLabelName(15718, userLanguage);
|
|
|
|
|
} else {
|
|
|
|
|
importSourceName = mapImportSourceName.get(this.importType);
|
|
|
|
|
}
|
|
|
|
|
Object obj = null;
|
|
|
|
|
Method method;
|
|
|
|
|
String flag;
|
|
|
|
|
String valErrorInfo;
|
|
|
|
|
if (lsImportSourceMap.size() == 0) {
|
|
|
|
|
this.errorInfo.add("【" + importSourceName + "】" + SystemEnv.getHtmlLabelName(34195, userLanguage) + "!");
|
|
|
|
|
}
|
|
|
|
|
if ("area".equals(importType)) {
|
|
|
|
|
//如果是行政区域导入,先删除脏数据
|
|
|
|
|
HrmArea.deleteDirtyData();
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < lsImportSourceMap.size(); i++) {
|
|
|
|
|
obj = lsImportSourceMap.get(i);
|
|
|
|
|
if (importType.equals("groupMember")) {
|
|
|
|
|
String groupId = Util.null2String(request.getParameter("groupid"));
|
|
|
|
|
|
|
|
|
|
method = importSourceClass.getMethod("setGroupid", String.class);
|
|
|
|
|
method.invoke(obj, groupId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
method = importSourceClass.getMethod("setUserLanguage", String.class);
|
|
|
|
|
method.invoke(obj, "" + userLanguage);
|
|
|
|
|
if (this.importType.equals("company")) {
|
|
|
|
|
method = importSourceClass.getMethod("setOperateType", String.class);
|
|
|
|
|
method.invoke(obj, this.operateType);
|
|
|
|
|
}
|
|
|
|
|
method = importSourceClass.getMethod("valExcelData");
|
|
|
|
|
try {
|
|
|
|
|
valErrorInfo = (String) method.invoke(obj);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
//验证出错返回错误信息
|
|
|
|
|
params = new HashMap<>();
|
|
|
|
|
params.put("pId", this.pId);
|
|
|
|
|
params.put("lineNum", (i + 2));
|
|
|
|
|
params.put("relatedName", this.getRelatedName(obj));
|
|
|
|
|
params.put("msg", importSourceName + "第" + (i + 2) + "行数据,验证失败!");
|
|
|
|
|
params.put("status", "0");
|
|
|
|
|
importLogService.saveImportDeitalLog(params, user);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (valErrorInfo.length() == 0) {
|
|
|
|
|
/*如果是常用组的导入,并且导入类型是覆盖,则需要先删除原有的数据*/
|
|
|
|
|
if (this.importType.equals("group") && this.operateType.equals("cover")) {
|
|
|
|
|
method = importSourceClass.getMethod("setOperateType", String.class);
|
|
|
|
|
method.invoke(obj, this.operateType);
|
|
|
|
|
method = importSourceClass.getMethod("getId");
|
|
|
|
|
int temp = (int) method.invoke(obj);
|
|
|
|
|
|
|
|
|
|
if (!deletedGroupId.contains(temp)) {
|
|
|
|
|
method = importSourceClass.getMethod("deleteOldData");
|
|
|
|
|
method.invoke(obj);
|
|
|
|
|
|
|
|
|
|
deletedGroupId.add(temp);
|
|
|
|
|
}
|
|
|
|
|
} else if (this.importType.equals("groupMember") && this.operateType.equals("cover")) {
|
|
|
|
|
/*如果是常用组成员的导入,并且导入类型是覆盖,则需要先删除原有的数据*/
|
|
|
|
|
method = importSourceClass.getMethod("setOperateType", String.class);
|
|
|
|
|
method.invoke(obj, this.operateType);
|
|
|
|
|
if (!this.isDeleted) {
|
|
|
|
|
method = importSourceClass.getMethod("deleteOldData");
|
|
|
|
|
method.invoke(obj);
|
|
|
|
|
this.isDeleted = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
method = importSourceClass.getMethod("save");
|
|
|
|
|
flag = (String) method.invoke(obj);
|
|
|
|
|
params = new HashMap<>();
|
|
|
|
|
params.put("pId", this.pId);
|
|
|
|
|
params.put("lineNum", (i + 2));
|
|
|
|
|
params.put("relatedName", this.getRelatedName(obj));
|
|
|
|
|
String msg = importSourceName + "第" + (i + 2) + "行数据," + this.getRelatedName(obj);
|
|
|
|
|
if (this.importType.equals("company")) {
|
|
|
|
|
method = importSourceClass.getMethod("getMessage");
|
|
|
|
|
msg += (String) method.invoke(obj);
|
|
|
|
|
}
|
|
|
|
|
params.put("msg", flag.equals("true") ? msg + "导入成功" : msg + "导入失败");
|
|
|
|
|
params.put("status", flag.equals("true") ? "1" : "0");
|
|
|
|
|
importLogService.saveImportDeitalLog(params, user);
|
|
|
|
|
} else {
|
|
|
|
|
//验证出错返回错误信息
|
|
|
|
|
params = new HashMap<>();
|
|
|
|
|
params.put("pId", this.pId);
|
|
|
|
|
params.put("lineNum", (i + 2));
|
|
|
|
|
params.put("relatedName", this.getRelatedName(obj));
|
|
|
|
|
params.put("msg", importSourceName + "第" + (i + 2) + "行数据," + valErrorInfo);
|
|
|
|
|
params.put("status", "0");
|
|
|
|
|
importLogService.saveImportDeitalLog(params, user);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//加载缓存
|
|
|
|
|
method = importSourceClass.getMethod("removeCache");
|
|
|
|
|
if (obj != null) method.invoke(obj);
|
|
|
|
|
|
|
|
|
|
if (!this.importType.equals("resourcedetial")) {
|
|
|
|
|
params = new HashMap<>();
|
|
|
|
|
params.put("pId", this.pId);
|
|
|
|
|
params.put("status", "over");
|
|
|
|
|
importLogService.saveImportLogStatus(params, user);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.importType.equals("resourcedetial")) {
|
|
|
|
|
//导入基本信息自定义明细字段
|
|
|
|
|
HrmResourceDefineDetialE9 HrmResourceDefineDetialE9 = new HrmResourceDefineDetialE9();
|
|
|
|
|
HrmResourceDefineDetialE9.importXls(workbook, this.pId, user);
|
|
|
|
|
params = new HashMap<>();
|
|
|
|
|
params.put("pId", this.pId);
|
|
|
|
|
params.put("status", "over");
|
|
|
|
|
importLogService.saveImportLogStatus(params, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
params = new HashMap<>();
|
|
|
|
|
params.put("pId", this.pId);
|
|
|
|
|
params.put("status", "error");
|
|
|
|
|
importLogService.saveImportLogStatus(params, user);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
this.errorInfo.add(SystemEnv.getHtmlLabelName(83618, userLanguage));
|
|
|
|
|
new BaseBean().writeLog(e);
|
|
|
|
|
params = new HashMap<>();
|
|
|
|
|
params.put("pId", this.pId);
|
|
|
|
|
params.put("status", "error");
|
|
|
|
|
importLogService.saveImportLogStatus(params, user);
|
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
|
new BaseBean().writeLog("岗位导入的报错1。。。。");
|
|
|
|
|
this.errorInfo.add(SystemEnv.getHtmlLabelName(125871, userLanguage));
|
|
|
|
|
new BaseBean().writeLog(e);
|
|
|
|
|
params = new HashMap<>();
|
|
|
|
|
params.put("pId", this.pId);
|
|
|
|
|
params.put("status", "error");
|
|
|
|
|
importLogService.saveImportLogStatus(params, user);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
new BaseBean().writeLog("岗位导入的报错2。。。。");
|
|
|
|
|
new BaseBean().writeLog(e);
|
|
|
|
|
this.errorInfo.add(SystemEnv.getHtmlLabelName(125871, userLanguage));
|
|
|
|
|
params = new HashMap<>();
|
|
|
|
|
params.put("pId", this.pId);
|
|
|
|
|
params.put("status", "error");
|
|
|
|
|
importLogService.saveImportLogStatus(params, user);
|
|
|
|
|
}
|
|
|
|
|
return this.errorInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验模板有效性
|
|
|
|
|
*
|
|
|
|
|
* @param importSourceFieldName 导入文件名称
|
|
|
|
|
*/
|
|
|
|
|
public String valExcelTemp(String importSourceFieldName) {
|
|
|
|
|
String valExcelTempInfo = "";
|
|
|
|
|
HSSFRow row;
|
|
|
|
|
HSSFCell cell;
|
|
|
|
|
String cellValue;
|
|
|
|
|
try {
|
|
|
|
|
String[] fieldname = importSourceFieldName.split(",");
|
|
|
|
|
if (this.importType.equals("group")) {
|
|
|
|
|
if (this.keyField.equals("workcode")) {
|
|
|
|
|
fieldname[3] = "成员编号[必填]";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
row = sheet.getRow(0);
|
|
|
|
|
for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) {
|
|
|
|
|
cell = row.getCell((short) cellIndex);
|
|
|
|
|
if (cell == null) continue;
|
|
|
|
|
cellValue = getCellValue(cell).trim();
|
|
|
|
|
if (!fieldname[cellIndex].equals(cellValue)) {
|
|
|
|
|
valExcelTempInfo = SystemEnv.getHtmlLabelName(387156, user.getLanguage());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
new BaseBean().writeLog(e);
|
|
|
|
|
valExcelTempInfo = SystemEnv.getHtmlLabelName(387156, user.getLanguage()) + "1";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return valExcelTempInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读excel文件内容
|
|
|
|
|
*/
|
|
|
|
|
public void readexcel() {
|
|
|
|
|
try {
|
|
|
|
|
HSSFRow row;
|
|
|
|
|
HSSFCell cell;
|
|
|
|
|
String cellValue;
|
|
|
|
|
// 行号
|
|
|
|
|
// 列号
|
|
|
|
|
int firstRow = 1;
|
|
|
|
|
lsImportSourceMap.clear();
|
|
|
|
|
int lastRow = sheet.getLastRowNum();
|
|
|
|
|
for (int i = firstRow; i <= lastRow; i++) {
|
|
|
|
|
row = sheet.getRow(i);
|
|
|
|
|
if (row == null) {
|
|
|
|
|
errorInfo.add(SystemEnv.getHtmlLabelName(15323, userLanguage) + " " + (i + 1) + " " + SystemEnv.getHtmlLabelName(83622, userLanguage));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object obj = importSourceClass.newInstance();
|
|
|
|
|
for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) {
|
|
|
|
|
cell = row.getCell((short) cellIndex);
|
|
|
|
|
if (cell == null) continue;
|
|
|
|
|
cellValue = getCellValue(cell).trim();
|
|
|
|
|
setImportSourceValue(cellIndex, cellValue, obj, null);
|
|
|
|
|
}
|
|
|
|
|
switch (this.importType) {
|
|
|
|
|
case "group":
|
|
|
|
|
((HrmGroup) obj).setKeyField(this.keyField);
|
|
|
|
|
((HrmGroup) obj).setOwner(this.creator);
|
|
|
|
|
((HrmGroup) obj).setOperateType(this.operateType);
|
|
|
|
|
break;
|
|
|
|
|
case "groupMember":
|
|
|
|
|
((HrmGroupMember) obj).setKeyField(this.keyField);
|
|
|
|
|
break;
|
|
|
|
|
case "sensitiveword":
|
|
|
|
|
((SensitiveWord) obj).setCreater(this.creator);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
lsImportSourceMap.add(obj);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
new BaseBean().writeLog(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取excel单元格值
|
|
|
|
|
*
|
|
|
|
|
* @param cell 要读取的单元格对象
|
|
|
|
|
*/
|
|
|
|
|
public String getCellValue(HSSFCell cell) {
|
|
|
|
|
String cellValue = "";
|
|
|
|
|
if (cell == null)
|
|
|
|
|
return "";
|
|
|
|
|
switch (cell.getCellType()) {
|
|
|
|
|
case BOOLEAN: // 得到Boolean对象的方法
|
|
|
|
|
cellValue = String.valueOf(cell.getBooleanCellValue());
|
|
|
|
|
break;
|
|
|
|
|
case NUMERIC:
|
|
|
|
|
cellValue = getString(HSSFDateUtil.isCellDateFormatted(cell), cell.getDateCellValue(), cell.getNumericCellValue());
|
|
|
|
|
break;
|
|
|
|
|
case FORMULA: // 读取公式
|
|
|
|
|
cellValue = cell.getCellFormula();
|
|
|
|
|
break;
|
|
|
|
|
case STRING: // 读取String
|
|
|
|
|
cellValue = cell.getStringCellValue();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
cellValue = Util.toHtmlForHrm(cellValue);
|
|
|
|
|
return cellValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
|
public static String getString(boolean cellDateFormatted, Date dateCellValue, double numericCellValue) {
|
|
|
|
|
String cellValue;
|
|
|
|
|
if (cellDateFormatted) {// 先看是否是日期格式
|
|
|
|
|
SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
cellValue = sft.format(dateCellValue); // 读取日期格式
|
|
|
|
|
} else {
|
|
|
|
|
cellValue = String.valueOf(new Double(numericCellValue)); // 读取数字
|
|
|
|
|
if (cellValue.endsWith(".0"))
|
|
|
|
|
cellValue = cellValue.substring(0, cellValue.indexOf("."));
|
|
|
|
|
}
|
|
|
|
|
return cellValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通过反射为对象赋值
|
|
|
|
|
*
|
|
|
|
|
* @param cellNum 列号
|
|
|
|
|
* @param cellValue 单元格值
|
|
|
|
|
* @param importSourceObj 需要赋值的
|
|
|
|
|
*/
|
|
|
|
|
public void setImportSourceValue(int cellNum, String cellValue, Object importSourceObj, 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(importSourceObj, cellValue);
|
|
|
|
|
else if (fieldType.equals("java.lang.Integer") && !cellValue.equals("")) {
|
|
|
|
|
method.invoke(importSourceObj, Integer.parseInt(cellValue));
|
|
|
|
|
} else if (fieldType.equals("java.lang.Float") && !cellValue.equals(""))
|
|
|
|
|
method.invoke(importSourceObj, Float.parseFloat(cellValue));
|
|
|
|
|
else if (fieldType.equals("java.lang.Short") && !cellValue.equals("")) {
|
|
|
|
|
method.invoke(importSourceObj, 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(importSourceObj, cellValue);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
new BaseBean().writeLog(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化反射所需要的方法和字段Map,parameterTypes,fieldTypes
|
|
|
|
|
*/
|
|
|
|
|
public void initReflectParam() {
|
|
|
|
|
try {
|
|
|
|
|
parameterTypes.clear();
|
|
|
|
|
fieldTypes.clear();
|
|
|
|
|
Method[] hrmResourceMethods = importSourceClass.getDeclaredMethods();
|
|
|
|
|
for (Method hrmResourceMethod : hrmResourceMethods) {
|
|
|
|
|
parameterTypes.put(hrmResourceMethod.getName(), hrmResourceMethod);
|
|
|
|
|
}
|
|
|
|
|
Field[] importSourceFields = importSourceClass.getDeclaredFields();
|
|
|
|
|
for (Field importSourceField : importSourceFields) {
|
|
|
|
|
Class<?> fieldTypeClass = importSourceField.getType();
|
|
|
|
|
if (fieldTypeClass == Integer.TYPE) {
|
|
|
|
|
fieldTypeClass = Integer.class;
|
|
|
|
|
}
|
|
|
|
|
fieldTypes.put(importSourceField.getName(), fieldTypeClass.getName());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
new BaseBean().writeLog(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getRelatedName(Object obj) {
|
|
|
|
|
String relatedName = "";
|
|
|
|
|
try {
|
|
|
|
|
switch (this.importType) {
|
|
|
|
|
case "company": {
|
|
|
|
|
Method method = importSourceClass.getMethod("getSubcompanyname");
|
|
|
|
|
relatedName = Util.null2String(method.invoke(obj));
|
|
|
|
|
method = importSourceClass.getMethod("getDepartmentname");
|
|
|
|
|
String departmentname = Util.null2String(method.invoke(obj));
|
|
|
|
|
if (departmentname.length() > 0) {
|
|
|
|
|
relatedName += ">";
|
|
|
|
|
}
|
|
|
|
|
relatedName += departmentname;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "loaction": {
|
|
|
|
|
Method method = importSourceClass.getMethod("getLocationname");
|
|
|
|
|
relatedName = Util.null2String(method.invoke(obj));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "jobtitle": {
|
|
|
|
|
Method method = importSourceClass.getMethod("setJobtitlemark");
|
|
|
|
|
relatedName = Util.null2String(method.invoke(obj));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "group": {
|
|
|
|
|
Method method = importSourceClass.getMethod("getGroupname");
|
|
|
|
|
relatedName = Util.null2String(method.invoke(obj));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "city":
|
|
|
|
|
case "special": {
|
|
|
|
|
Method method = importSourceClass.getMethod("getName");
|
|
|
|
|
relatedName = Util.null2String(method.invoke(obj));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "area": {
|
|
|
|
|
Method method = importSourceClass.getMethod("getCountryname");
|
|
|
|
|
relatedName = Util.null2String(method.invoke(obj));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "resourcedetial": {
|
|
|
|
|
Method method = importSourceClass.getMethod("getLastname");
|
|
|
|
|
relatedName = Util.null2String(method.invoke(obj));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "sensitiveword": {
|
|
|
|
|
Method method = importSourceClass.getMethod("getWord");
|
|
|
|
|
relatedName = Util.null2String(method.invoke(obj));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
new BaseBean().writeLog(e);
|
|
|
|
|
}
|
|
|
|
|
return relatedName;
|
|
|
|
|
}
|
|
|
|
|
}
|