修改人员组织架构代码

main
youHong.ai 2022-11-25 16:47:48 +08:00
parent 062b998ce5
commit 894e56b974
10 changed files with 230 additions and 80 deletions

View File

@ -113,7 +113,7 @@ public class Util extends weaver.general.Util {
/** /**
* *
* *
* @param format * @param format yyyy-MM-dd
* @return * @return
*/ */
public static String getTime(String format) { public static String getTime(String format) {

View File

@ -64,6 +64,11 @@ public class ReadCsvUtil {
} }
} catch (IOException e) { } catch (IOException e) {
throw new CustomerException("无法读取文件数据!", e); throw new CustomerException("无法读取文件数据!", e);
} finally {
try {
reader.close();
} catch (IOException ignore) {
}
} }
return tableInfo; return tableInfo;
} }

View File

@ -147,7 +147,7 @@ public class SftpConnectUtil extends ChannelSftp {
File file = new File(localeFile); File file = new File(localeFile);
if (!file.exists()) { if (!file.exists()) {
boolean mkdirs = file.getParentFile().mkdirs(); boolean mkdirs = file.getParentFile().mkdirs();
if (!mkdirs) { if (!mkdirs && !file.getParentFile().exists()) {
throw new CustomerException("无法创建目录(can not create dirs)[" + localeFile + "]"); throw new CustomerException("无法创建目录(can not create dirs)[" + localeFile + "]");
} }
} else { } else {
@ -177,7 +177,7 @@ public class SftpConnectUtil extends ChannelSftp {
* @throws IOException IO * @throws IOException IO
*/ */
public String downFileToSystemFilePath(String remoteFile, String localeFileName) throws IOException { 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);
} }

View File

@ -1,10 +1,19 @@
package weaver.youhong.ai.pcn.hrorganization.service; package weaver.youhong.ai.pcn.hrorganization.service;
import aiyh.utils.Util; import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import ebu7common.youhong.ai.csv.ReadCsvUtil;
import ebu7common.youhong.ai.sftp.SftpConnectUtil; import ebu7common.youhong.ai.sftp.SftpConnectUtil;
import weaver.general.GCONST; 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.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -21,18 +30,97 @@ public class OrganizationAsyncService {
/** /**
* csv * csv
*/ */
public List<List<String>> getRemoteFileData(String fileName) { private List<List<String>> getRemoteFileData(String fileName) {
String userName = Util.getCusConfigValue("sftpUserName"); //String userName = Util.getCusConfigValue("sftpUserName");
String ipAddress = Util.getCusConfigValue("sftpIp"); //String ipAddress = Util.getCusConfigValue("sftpIp");
String sftpPort = Util.getCusConfigValue("sftpPort"); //String sftpPort = Util.getCusConfigValue("sftpPort");
String userName = "HR Digital_PROD";
String ipAddress = "58.246.33.86";
String sftpPort = null;
SftpConnectUtil sftpConnectUtil = new SftpConnectUtil( SftpConnectUtil sftpConnectUtil = new SftpConnectUtil(
userName, userName,
GCONST.getRootPath() + "sftp" + File.separatorChar + "HR_Digital_PROD.pem", GCONST.getRootPath() + "ssl" + File.separatorChar + "HR_Digital_PROD.pem",
null, null,
ipAddress, ipAddress,
Integer.parseInt(sftpPort), 1000 * 100); Integer.parseInt(sftpPort == null || "".equals(sftpPort) ? "22" : sftpPort), 1000 * 100);
sftpConnectUtil.close(); try {
return null; String localeFilePath = sftpConnectUtil.downFileToSystemFilePath(fileName, fileName + ".csv");
List<List<String>> 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<Employee> getEmployeeList() {
List<Employee> dataList = new ArrayList<>();
List<List<String>> employeeList = getRemoteFileData("HRIS_EmployeeExport" + "20221124");
if (employeeList == null || employeeList.isEmpty()) {
throw new CustomerException("获取人员数据信息失败!");
}
// 获取表头
List<String> heard = employeeList.get(0);
for (int i = 1; i < employeeList.size(); i++) {
List<String> 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<Department> getDepartmentList() {
List<Department> dataList = new ArrayList<>();
List<List<String>> departmentList = getRemoteFileData("HRIS_DepartmentExport" + "20221124");
if (departmentList == null || departmentList.isEmpty()) {
throw new CustomerException("获取部门数据信息失败!");
}
// 获取表头
List<String> heard = departmentList.get(0);
for (int i = 1; i < departmentList.size(); i++) {
List<String> 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<Position> getPositionList() {
List<Position> dataList = new ArrayList<>();
List<List<String>> positionList = getRemoteFileData("HRIS_PositionExport" + "20221124");
if (positionList == null || positionList.isEmpty()) {
throw new CustomerException("获取职位数据信息失败!");
}
// 获取表头
List<String> heard = positionList.get(0);
for (int i = 1; i < positionList.size(); i++) {
List<String> 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;
}
} }

View File

@ -72,7 +72,7 @@ public class SyncOrganizationForOtherAPI extends ToolUtil implements HrmSynServi
getUnAsyncDepIdList(); getUnAsyncDepIdList();
try { try {
List<Department> departmentList = getOrganizationResult.getDepartmentList(); List<Department> departmentList = getOrganizationResult.getDepartmentList();
Collections.sort(departmentList); //Collections.sort(departmentList);
List<Map<String, Object>> synResultlist = new ArrayList<>(); List<Map<String, Object>> synResultlist = new ArrayList<>();
for (Department department : departmentList) { for (Department department : departmentList) {
// 如果不启用就不执行 // 如果不启用就不执行

View File

@ -1,6 +1,9 @@
package weaver.youhong.ai.pcn.hrorganization.wesmat.model; 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 * @author EBU7-dev1-ayh
@ -8,12 +11,15 @@ import org.jetbrains.annotations.NotNull;
* *
*/ */
@Getter
public class Department implements Comparable<Department> { @Setter
@ToString
@AllArgsConstructor
public class Department {
/** /**
* ID * ID
*/ */
private Long DEPARTMENTID; private String DEPARTMENTID;
/** /**
* *
*/ */
@ -23,10 +29,15 @@ public class Department implements Comparable<Department> {
*/ */
private Long PARENTDEPARTMENDID; private Long PARENTDEPARTMENDID;
private String Company_Code_Company;
public Department() {
}
public String getValue(String fieldName) { public String getValue(String fieldName) {
if ("DEPARTMENTID".equals(fieldName)) { if ("DEPARTMENTID".equals(fieldName)) {
return String.valueOf(this.getDEPARTMENTID()); return this.getDEPARTMENTID();
} }
if ("DEPARTMENTNAME".equals(fieldName)) { if ("DEPARTMENTNAME".equals(fieldName)) {
return this.getDEPARTMENTNAME(); return this.getDEPARTMENTNAME();
@ -34,54 +45,25 @@ public class Department implements Comparable<Department> {
if ("PARENTDEPARTMENDID".equals(fieldName)) { if ("PARENTDEPARTMENDID".equals(fieldName)) {
return String.valueOf(this.getPARENTDEPARTMENDID()); return String.valueOf(this.getPARENTDEPARTMENDID());
} }
if ("Company_Code_Company".equals(fieldName)) {
return getCompany_Code_Company();
}
return null; 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();
}
} }

View File

@ -110,6 +110,52 @@ public class Employee implements Comparable<Employee> {
return null; 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() { public Employee() {
} }

View File

@ -52,6 +52,27 @@ public class Position implements Comparable<Position> {
return null; 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() { public Position() {
} }
@ -129,4 +150,6 @@ public class Position implements Comparable<Position> {
", Company_Code='" + Company_Code + '\'' + ", Company_Code='" + Company_Code + '\'' +
'}'; '}';
} }
} }

View File

@ -1,8 +1,6 @@
package weaver.youhong.ai.pcn.hrorganization.wesmat.result; package weaver.youhong.ai.pcn.hrorganization.wesmat.result;
import com.alibaba.fastjson.JSON; import weaver.youhong.ai.pcn.hrorganization.service.OrganizationAsyncService;
import com.alibaba.fastjson.JSONObject;
import weaver.youhong.ai.pcn.hrorganization.wesmat.config.SyncOrganizationConfig;
import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Department; 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.Employee;
import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Position; import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Position;
@ -17,33 +15,26 @@ import java.util.List;
public class GetOrganizationResult { public class GetOrganizationResult {
private final OrganizationAsyncService organizationAsyncService = new OrganizationAsyncService();
/** /**
* *
*/ */
public List<Employee> getEmployeeList() { public List<Employee> getEmployeeList() {
SyncOrganizationConfig<Employee> employeeSyncOrganizationConfig = new SyncOrganizationConfig<>(); return organizationAsyncService.getEmployeeList();
List<Employee> dataList = employeeSyncOrganizationConfig.getDataList(employeeSyncOrganizationConfig.getEMPLOYEE_API_RUL());
String jsonString = JSON.toJSON(dataList).toString();
return (List<Employee>) JSONObject.parseArray(jsonString, Employee.class);
} }
/** /**
* *
*/ */
public List<Department> getDepartmentList() { public List<Department> getDepartmentList() {
SyncOrganizationConfig<Department> employeeSyncOrganizationConfig = new SyncOrganizationConfig<>(); return organizationAsyncService.getDepartmentList();
List<Department> dataList = employeeSyncOrganizationConfig.getDataList(employeeSyncOrganizationConfig.getDEPARTMENT_API_URL());
String jsonString = JSON.toJSON(dataList).toString();
return (List<Department>) JSONObject.parseArray(jsonString, Department.class);
} }
/** /**
* *
*/ */
public List<Position> getPositionList() { public List<Position> getPositionList() {
SyncOrganizationConfig<Position> employeeSyncOrganizationConfig = new SyncOrganizationConfig<>(); return organizationAsyncService.getPositionList();
List<Position> dataList = employeeSyncOrganizationConfig.getDataList(employeeSyncOrganizationConfig.getPOSITION_API_URL());
String jsonString = JSON.toJSON(dataList).toString();
return (List<Position>) JSONObject.parseArray(jsonString, Position.class);
} }
} }

View File

@ -1,9 +1,14 @@
package youhong.ai.pcn; package youhong.ai.pcn;
import basetest.BaseTest; import basetest.BaseTest;
import com.alibaba.fastjson.JSON;
import ebu7common.youhong.ai.sftp.SftpConnectUtil; import ebu7common.youhong.ai.sftp.SftpConnectUtil;
import org.junit.Test; import org.junit.Test;
import weaver.general.GCONST; 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.BufferedReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -41,10 +46,22 @@ public class TestOrganization extends BaseTest {
} }
@Test
public void testGeOrganizationData() {
GetOrganizationResult getOrganizationResult = new GetOrganizationResult();
List<Department> departmentList = getOrganizationResult.getDepartmentList();
List<Employee> employeeList = getOrganizationResult.getEmployeeList();
List<Position> 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 @Test
public void testStaticLog() { public void testStaticLog() {
log.info("哈哈哈好的方式"); log.info("哈哈哈好的方式");
log.info(this.getClass().getResource("/"));
} }
@ -110,7 +127,5 @@ public class TestOrganization extends BaseTest {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }