From 894e56b97456193859b691f41c6f52fcde1ef4f3 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Fri, 25 Nov 2022 16:47:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=E5=91=98=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E6=9E=B6=E6=9E=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/aiyh/utils/Util.java | 2 +- .../youhong/ai/csv/ReadCsvUtil.java | 5 + .../youhong/ai/sftp/SftpConnectUtil.java | 4 +- .../service/OrganizationAsyncService.java | 104 ++++++++++++++++-- .../wesmat/SyncOrganizationForOtherAPI.java | 2 +- .../wesmat/model/Department.java | 82 ++++++-------- .../hrorganization/wesmat/model/Employee.java | 46 ++++++++ .../hrorganization/wesmat/model/Position.java | 23 ++++ .../wesmat/result/GetOrganizationResult.java | 21 +--- .../java/youhong/ai/pcn/TestOrganization.java | 21 +++- 10 files changed, 230 insertions(+), 80 deletions(-) diff --git a/src/main/java/aiyh/utils/Util.java b/src/main/java/aiyh/utils/Util.java index 6b6df65..7e50011 100644 --- a/src/main/java/aiyh/utils/Util.java +++ b/src/main/java/aiyh/utils/Util.java @@ -113,7 +113,7 @@ public class Util extends weaver.general.Util { /** * 获取指定格式的当前时间 * - * @param format 格式化字符串 + * @param format 格式化字符串 yyyy-MM-dd * @return 指定格式日期的字符串 */ public static String getTime(String format) { diff --git a/src/main/java/ebu7common/youhong/ai/csv/ReadCsvUtil.java b/src/main/java/ebu7common/youhong/ai/csv/ReadCsvUtil.java index 5567d6f..a438fa9 100644 --- a/src/main/java/ebu7common/youhong/ai/csv/ReadCsvUtil.java +++ b/src/main/java/ebu7common/youhong/ai/csv/ReadCsvUtil.java @@ -64,6 +64,11 @@ public class ReadCsvUtil { } } catch (IOException e) { throw new CustomerException("无法读取文件数据!", e); + } finally { + try { + reader.close(); + } catch (IOException ignore) { + } } return tableInfo; } diff --git a/src/main/java/ebu7common/youhong/ai/sftp/SftpConnectUtil.java b/src/main/java/ebu7common/youhong/ai/sftp/SftpConnectUtil.java index 4422314..2fa1020 100644 --- a/src/main/java/ebu7common/youhong/ai/sftp/SftpConnectUtil.java +++ b/src/main/java/ebu7common/youhong/ai/sftp/SftpConnectUtil.java @@ -147,7 +147,7 @@ public class SftpConnectUtil extends ChannelSftp { File file = new File(localeFile); if (!file.exists()) { boolean mkdirs = file.getParentFile().mkdirs(); - if (!mkdirs) { + if (!mkdirs && !file.getParentFile().exists()) { throw new CustomerException("无法创建目录(can not create dirs):[" + localeFile + "]"); } } else { @@ -177,7 +177,7 @@ public class SftpConnectUtil extends ChannelSftp { * @throws IOException IO异常 */ public String downFileToSystemFilePath(String remoteFile, String localeFileName) throws IOException { - return this.downFile(remoteFile, GCONST.getSysFilePath() + localeFileName); + return this.downFile(remoteFile, GCONST.getSysFilePath() + "cus" + File.separatorChar + localeFileName); } diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/service/OrganizationAsyncService.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/service/OrganizationAsyncService.java index c727dcc..91f5500 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/service/OrganizationAsyncService.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/service/OrganizationAsyncService.java @@ -1,10 +1,19 @@ package weaver.youhong.ai.pcn.hrorganization.service; import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import ebu7common.youhong.ai.csv.ReadCsvUtil; import ebu7common.youhong.ai.sftp.SftpConnectUtil; import weaver.general.GCONST; +import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Department; +import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Employee; +import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Position; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; /** @@ -21,18 +30,97 @@ public class OrganizationAsyncService { /** * csv文件数据 */ - public List> getRemoteFileData(String fileName) { - String userName = Util.getCusConfigValue("sftpUserName"); - String ipAddress = Util.getCusConfigValue("sftpIp"); - String sftpPort = Util.getCusConfigValue("sftpPort"); + private List> getRemoteFileData(String fileName) { + //String userName = Util.getCusConfigValue("sftpUserName"); + //String ipAddress = Util.getCusConfigValue("sftpIp"); + //String sftpPort = Util.getCusConfigValue("sftpPort"); + String userName = "HR Digital_PROD"; + String ipAddress = "58.246.33.86"; + String sftpPort = null; SftpConnectUtil sftpConnectUtil = new SftpConnectUtil( userName, - GCONST.getRootPath() + "sftp" + File.separatorChar + "HR_Digital_PROD.pem", + GCONST.getRootPath() + "ssl" + File.separatorChar + "HR_Digital_PROD.pem", null, ipAddress, - Integer.parseInt(sftpPort), 1000 * 100); - sftpConnectUtil.close(); - return null; + Integer.parseInt(sftpPort == null || "".equals(sftpPort) ? "22" : sftpPort), 1000 * 100); + try { + String localeFilePath = sftpConnectUtil.downFileToSystemFilePath(fileName, fileName + ".csv"); + List> lists = ReadCsvUtil.readCsvFromPath(localeFilePath); + Files.delete(Paths.get(localeFilePath)); + return lists; + } catch (IOException e) { + throw new CustomerException(Util.logStr("sftp下载文件[{}]出错!", fileName), e); + } finally { + sftpConnectUtil.close(); + } } + /** + * 获取部门数据 + */ + public List getEmployeeList() { + List dataList = new ArrayList<>(); + List> employeeList = getRemoteFileData("HRIS_EmployeeExport" + "20221124"); + if (employeeList == null || employeeList.isEmpty()) { + throw new CustomerException("获取人员数据信息失败!"); + } + // 获取表头 + List heard = employeeList.get(0); + for (int i = 1; i < employeeList.size(); i++) { + List row = employeeList.get(i); + for (int j = 0; j < row.size(); j++) { + Employee employee = new Employee(); + employee.setValue(heard.get(j).replace(" ", "_").replace("-", "_"), row.get(j)); + dataList.add(employee); + } + } + return dataList; + } + + + /** + * 获取部门数据 + */ + public List getDepartmentList() { + List dataList = new ArrayList<>(); + List> departmentList = getRemoteFileData("HRIS_DepartmentExport" + "20221124"); + if (departmentList == null || departmentList.isEmpty()) { + throw new CustomerException("获取部门数据信息失败!"); + } + // 获取表头 + List heard = departmentList.get(0); + for (int i = 1; i < departmentList.size(); i++) { + List row = departmentList.get(i); + for (int j = 0; j < row.size(); j++) { + Department department = new Department(); + department.setValue(heard.get(j).replace(" ", "_").replace("-", "_"), row.get(j)); + dataList.add(department); + } + } + return dataList; + } + + /** + * 获取职位数据 + */ + public List getPositionList() { + List dataList = new ArrayList<>(); + List> positionList = getRemoteFileData("HRIS_PositionExport" + "20221124"); + if (positionList == null || positionList.isEmpty()) { + throw new CustomerException("获取职位数据信息失败!"); + } + // 获取表头 + List heard = positionList.get(0); + for (int i = 1; i < positionList.size(); i++) { + List row = positionList.get(i); + for (int j = 0; j < row.size(); j++) { + Position position = new Position(); + position.setValue(heard.get(j).replace(" ", "_").replace("-", "_"), row.get(j)); + dataList.add(position); + } + } + return dataList; + } + + } \ No newline at end of file diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/SyncOrganizationForOtherAPI.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/SyncOrganizationForOtherAPI.java index 99198e3..ac4264a 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/SyncOrganizationForOtherAPI.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/SyncOrganizationForOtherAPI.java @@ -72,7 +72,7 @@ public class SyncOrganizationForOtherAPI extends ToolUtil implements HrmSynServi getUnAsyncDepIdList(); try { List departmentList = getOrganizationResult.getDepartmentList(); - Collections.sort(departmentList); + //Collections.sort(departmentList); List> synResultlist = new ArrayList<>(); for (Department department : departmentList) { // 如果不启用就不执行 diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Department.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Department.java index a55e20b..250a709 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Department.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Department.java @@ -1,6 +1,9 @@ package weaver.youhong.ai.pcn.hrorganization.wesmat.model; -import org.jetbrains.annotations.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; /** * @author EBU7-dev1-ayh @@ -8,12 +11,15 @@ import org.jetbrains.annotations.NotNull; * 部门实体类 */ - -public class Department implements Comparable { +@Getter +@Setter +@ToString +@AllArgsConstructor +public class Department { /** * 部门ID */ - private Long DEPARTMENTID; + private String DEPARTMENTID; /** * 部门名称 */ @@ -23,10 +29,15 @@ public class Department implements Comparable { */ private Long PARENTDEPARTMENDID; + private String Company_Code_Company; + + public Department() { + } + public String getValue(String fieldName) { if ("DEPARTMENTID".equals(fieldName)) { - return String.valueOf(this.getDEPARTMENTID()); + return this.getDEPARTMENTID(); } if ("DEPARTMENTNAME".equals(fieldName)) { return this.getDEPARTMENTNAME(); @@ -34,54 +45,25 @@ public class Department implements Comparable { if ("PARENTDEPARTMENDID".equals(fieldName)) { return String.valueOf(this.getPARENTDEPARTMENDID()); } + if ("Company_Code_Company".equals(fieldName)) { + return getCompany_Code_Company(); + } return null; } - public Department() { + public void setValue(String fieldName, String value) { + if ("DEPARTMENTID".equals(fieldName)) { + setDEPARTMENTID(value); + } + if ("DEPARTMENTNAME".equals(fieldName)) { + setDEPARTMENTNAME(value); + } + if ("PARENTDEPARTMENDID".equals(fieldName)) { + setPARENTDEPARTMENDID(Long.valueOf(value)); + } + if ("Company_Code_Company".equals(fieldName)) { + setCompany_Code_Company(value); + } } - public Department(Long DEPARTMENTID, String DEPARTMENTNAME, Long PARENTDEPARTMENDID) { - this.DEPARTMENTID = DEPARTMENTID; - this.DEPARTMENTNAME = DEPARTMENTNAME; - this.PARENTDEPARTMENDID = PARENTDEPARTMENDID; - } - - public Long getDEPARTMENTID() { - return DEPARTMENTID; - } - - public void setDEPARTMENTID(Long DEPARTMENTID) { - this.DEPARTMENTID = DEPARTMENTID; - } - - public String getDEPARTMENTNAME() { - return DEPARTMENTNAME; - } - - public void setDEPARTMENTNAME(String DEPARTMENTNAME) { - this.DEPARTMENTNAME = DEPARTMENTNAME; - } - - public Long getPARENTDEPARTMENDID() { - return PARENTDEPARTMENDID; - } - - public void setPARENTDEPARTMENDID(Long PARENTDEPARTMENDID) { - this.PARENTDEPARTMENDID = PARENTDEPARTMENDID; - } - - - @Override - public String toString() { - return "Department{" + - "DEPARTMENTID='" + DEPARTMENTID + '\'' + - ", DEPARTMENTNAME='" + DEPARTMENTNAME + '\'' + - ", PARENTDEPARTMENDID='" + PARENTDEPARTMENDID + '\'' + - '}'; - } - - @Override - public int compareTo(@NotNull Department o) { - return new Long(this.PARENTDEPARTMENDID - o.getPARENTDEPARTMENDID()).intValue(); - } } diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Employee.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Employee.java index 13ced0d..0713316 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Employee.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Employee.java @@ -110,6 +110,52 @@ public class Employee implements Comparable { return null; } + public void setValue(String fieldName, String value) { + if ("UserID".equals(fieldName)) { + setUserID(Long.valueOf(null == value || "".equals(value) ? "-1" : value)); + } + if ("FIRSTNAMEEN".equals(fieldName)) { + setFIRSTNAMEEN(value); + } + if ("LASTNAMEEN".equals(fieldName)) { + setLASTNAMEEN(value); + } + if ("USERNAMECN".equals(fieldName)) { + setUSERNAMECN(value); + } + if ("USERCODE".equals(fieldName)) { + setUSERCODE(value); + } + if ("JOBCODEID".equals(fieldName)) { + setJOBCODEID(Long.valueOf(null == value || "".equals(value) ? "-1" : value)); + } + if ("DEPARTMENTID".equals(fieldName)) { + setDEPARTMENTID(Long.valueOf(null == value || "".equals(value) ? "-1" : value)); + } + if ("DEPARTMENTNAME".equals(fieldName)) { + setDEPARTMENTNAME(value); + } + if ("COSTCENTERCODE".equals(fieldName)) { + setCOSTCENTERCODE(value); + } + if ("EMAIL".equals(fieldName)) { + setEMAIL(value); + } + if ("ORGANIZATION".equals(fieldName)) { + setORGANIZATION(value); + } + if ("MOBILENO".equals(fieldName)) { + setMOBILENO(value); + } + if ("TEL".equals(fieldName)) { + setTEL(value); + } + if ("Preferred_Name".equals(fieldName)) { + setPreferred_Name(value); + } + } + + public Employee() { } diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Position.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Position.java index 690cd33..92b9019 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Position.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/model/Position.java @@ -52,6 +52,27 @@ public class Position implements Comparable { return null; } + public void setValue(String fieldName, String value) { + if ("JOBCODEID".equals(fieldName)) { + setJOBCODEID(Long.parseLong(null == value || "".equals(value) ? "-1" : value)); + } + if ("JOBCODE".equals(fieldName)) { + setJOBCODE(value); + } + if ("JOBFUNCTION".equals(fieldName)) { + setJOBFUNCTION(value); + } + if ("SUPERIORJOBCODEID".equals(fieldName)) { + setSUPERIORJOBCODEID(Long.parseLong(null == value || "".equals(value) ? "-1" : value)); + } + if ("POSITIONOCCUPIED".equals(fieldName)) { + setPOSITIONOCCUPIED(Long.parseLong(null == value || "".equals(value) ? "-1" : value)); + } + if ("Company_Code".equals(fieldName)) { + setCompany_Code(value); + } + } + public Position() { } @@ -129,4 +150,6 @@ public class Position implements Comparable { ", Company_Code='" + Company_Code + '\'' + '}'; } + + } diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/result/GetOrganizationResult.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/result/GetOrganizationResult.java index dd4d9da..c5e8b49 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/result/GetOrganizationResult.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/result/GetOrganizationResult.java @@ -1,8 +1,6 @@ package weaver.youhong.ai.pcn.hrorganization.wesmat.result; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import weaver.youhong.ai.pcn.hrorganization.wesmat.config.SyncOrganizationConfig; +import weaver.youhong.ai.pcn.hrorganization.service.OrganizationAsyncService; import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Department; import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Employee; import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Position; @@ -17,33 +15,26 @@ import java.util.List; public class GetOrganizationResult { + private final OrganizationAsyncService organizationAsyncService = new OrganizationAsyncService(); + /** * 获取员工数据 */ public List getEmployeeList() { - SyncOrganizationConfig employeeSyncOrganizationConfig = new SyncOrganizationConfig<>(); - List dataList = employeeSyncOrganizationConfig.getDataList(employeeSyncOrganizationConfig.getEMPLOYEE_API_RUL()); - String jsonString = JSON.toJSON(dataList).toString(); - return (List) JSONObject.parseArray(jsonString, Employee.class); + return organizationAsyncService.getEmployeeList(); } /** * 获取部门数据 */ public List getDepartmentList() { - SyncOrganizationConfig employeeSyncOrganizationConfig = new SyncOrganizationConfig<>(); - List dataList = employeeSyncOrganizationConfig.getDataList(employeeSyncOrganizationConfig.getDEPARTMENT_API_URL()); - String jsonString = JSON.toJSON(dataList).toString(); - return (List) JSONObject.parseArray(jsonString, Department.class); + return organizationAsyncService.getDepartmentList(); } /** * 获取职位数据 */ public List getPositionList() { - SyncOrganizationConfig employeeSyncOrganizationConfig = new SyncOrganizationConfig<>(); - List dataList = employeeSyncOrganizationConfig.getDataList(employeeSyncOrganizationConfig.getPOSITION_API_URL()); - String jsonString = JSON.toJSON(dataList).toString(); - return (List) JSONObject.parseArray(jsonString, Position.class); + return organizationAsyncService.getPositionList(); } } diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index e728413..d7c3729 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -1,9 +1,14 @@ package youhong.ai.pcn; import basetest.BaseTest; +import com.alibaba.fastjson.JSON; import ebu7common.youhong.ai.sftp.SftpConnectUtil; import org.junit.Test; import weaver.general.GCONST; +import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Department; +import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Employee; +import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Position; +import weaver.youhong.ai.pcn.hrorganization.wesmat.result.GetOrganizationResult; import java.io.BufferedReader; import java.io.FileNotFoundException; @@ -41,10 +46,22 @@ public class TestOrganization extends BaseTest { } + @Test + public void testGeOrganizationData() { + GetOrganizationResult getOrganizationResult = new GetOrganizationResult(); + List departmentList = getOrganizationResult.getDepartmentList(); + List employeeList = getOrganizationResult.getEmployeeList(); + List positionList = getOrganizationResult.getPositionList(); + log.info(departmentList.size() + "::" + employeeList.size() + "::" + positionList.size()); + log.info(JSON.toJSONString(departmentList)); + log.info(JSON.toJSONString(employeeList)); + log.info(JSON.toJSONString(positionList)); + } + + @Test public void testStaticLog() { log.info("哈哈哈好的方式"); - log.info(this.getClass().getResource("/")); } @@ -110,7 +127,5 @@ public class TestOrganization extends BaseTest { } catch (Exception e) { e.printStackTrace(); } - - } }