package customization.test; import aiyh.utils.zwl.common.ToolUtil; import com.alibaba.fastjson.JSON; import com.api.aiyh_guijiu.service.WorkflowQueueService; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.ibm.icu.text.SimpleDateFormat; import com.interfaces.toolkit.SSOLoginUtil; import km.org.apache.poi.hssf.usermodel.HSSFCellStyle; import km.org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.h2.util.StringUtils; import org.junit.Test; import aiyh.utils.HotDeployToolUtil; import tebie.applib.api.M; import weaver.aiyh_pcn.async_organization.SyncOrganizationForOtherAPI; import weaver.aiyh_pcn.async_organization.model.Department; import weaver.aiyh_pcn.async_organization.model.Employee; import weaver.aiyh_pcn.async_organization.model.Position; import weaver.aiyh_pcn.async_organization.result.ApiAsyncConfigResult; import weaver.aiyh_pcn.async_organization.result.GetOrganizationResult; import weaver.aiyh_pcn.async_organization.util.GetModelValue; import weaver.aiyh_quanshi.QsAPI; import weaver.aiyh_quanshi.RequestApi; import weaver.aiyh_quanshi.entity.QsResponse; import weaver.conn.RecordSet; import java.io.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.util.*; /** * @author liutaihong * @version 1.0.0 * @ClassName TestAction.java * @Description TODO * @createTime 2020-05-15 10:55:00 */ public class TestAction extends BaseTest { @Test public void testHot() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, InterruptedException { int i = 0; while (true) { HotDeployToolUtil hotDeployToolUtil = new HotDeployToolUtil("d:\\WEAVER\\ecology\\classbean\\", ""); Class aClass = hotDeployToolUtil.loadClass("com.api.aiyhTools.TestHot"); Object o = aClass.newInstance(); Method test = o.getClass().getMethod("test"); Object invoke = test.invoke(o); Thread.sleep(1000); System.out.println(invoke); if (i > 100) { return; } i++; } } @Test public void testFile() throws ClassNotFoundException { HotDeployToolUtil hotDeployTool = new HotDeployToolUtil("d:\\WEAVER\\ecology\\classbean\\", ""); hotDeployTool.findClass("com\\api\\aiyhTools\\HotDeployTool.class"); } @Test public void testLog4j() { ToolUtil toolUtil = new ToolUtil(); toolUtil.writeDebuggerLog("TestAction", "i am is test log4j method, are you ok?"); } @Test public void getDate() { Date date = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); // return "?date=" + formatter.format(date); System.out.println("?date=" + formatter.format(date)); } @Test public void testAsync() { SyncOrganizationForOtherAPI syncOrganization = new SyncOrganizationForOtherAPI(); syncOrganization.SynTimingToOADepartment(); syncOrganization.SynTimingToOAJobtitle(); syncOrganization.SynTimingToOAHrmResource(); } @Test public void testString() { RecordSet rs = new RecordSet(); rs.executeProc("HrmResourceMaxId_Get", ""); rs.next(); int hrmid = rs.getInt(1); System.out.println(hrmid); StringBuilder sysSetSql = new StringBuilder(); System.out.println(StringUtils.isNullOrEmpty(null)); System.out.println(sysSetSql.lastIndexOf(",")); String str = "q=1,w=2,e=3,"; System.out.println(str.substring(0, str.lastIndexOf(","))); } @Test public void testCallMethod() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { ApiAsyncConfigResult asyncConfigResult = new ApiAsyncConfigResult(); asyncConfigResult.setId(1); asyncConfigResult.setAsyncType(0); asyncConfigResult.setApiField("apiField"); asyncConfigResult.setoAField("oAField"); asyncConfigResult.setFieldType(1); asyncConfigResult.setChangeRules(2); asyncConfigResult.setCustomRules("customRules"); String str = "Id"; GetModelValue apiAsyncConfigResultGetModelValue = new GetModelValue<>(); Object id = apiAsyncConfigResultGetModelValue.getValueForString(asyncConfigResult, "Id"); // Class clazz = asyncConfigResult.getClass(); // Method getId = clazz.getDeclaredMethod("get" + str); // Object invoke = getId.invoke(asyncConfigResult); System.out.println(id); } @Test public void testQueryConfigTableInfo() { GetModelValue getModelValue = new GetModelValue<>(); Position position = new Position(); position.setCompany_Code("public static void main test~"); this.builderSql("Company_Code", position, getModelValue); } public void builderSql(String filedName, Object obj, GetModelValue getModelValue) { // 拼接系统部门字段 try { String value = getModelValue.getValueForString(obj, filedName).toString(); System.out.println(value); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } } @Test public void testSyncOrganizationForOtherAPI() { new SyncOrganizationForOtherAPI().SynTimingToOADepartment(); } @Test public void testFormatSql() { Map map = new HashMap<>(); URL resource = Thread.currentThread().getContextClassLoader().getResource(""); String path = resource.getPath().replaceFirst("/", "").replace("/", "\\"); map.put("packageName", "com.api.aiyhTools"); map.put("filePath", path); map.put("path", path); map.put("classPath", path + "com.api.aiyhTools".replace(".", System.getProperties().getProperty("file.separator"))); System.out.println(map); File file = new File((String) map.get("classPath")); if (file.exists()) { System.out.println(map.get("classPath")); } } @Test public void testWritExcel() throws IOException { GetOrganizationResult getOrganizationResult = new GetOrganizationResult(); List employeeList = getOrganizationResult.getEmployeeList(); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(); CellStyle cellStyle = sxssfWorkbook.createCellStyle(); // 设置单元格居中对齐 cellStyle.setAlignment(HorizontalAlignment.forInt(HSSFCellStyle.ALIGN_CENTER)); Font font = sxssfWorkbook.createFont(); font.setColor(HSSFColor.RED.index); cellStyle.setFont(font); Sheet sheet = sxssfWorkbook.createSheet("人员信息"); Row desc = sheet.createRow(0); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 13)); Cell cell2 = desc.createCell(0); cell2.setCellValue("员工信息表,同步数据时,按照岗位id进行同步!"); cell2.setCellStyle(cellStyle); Row th = sheet.createRow(1); th.createCell(0).setCellValue("员工ID"); th.createCell(1).setCellValue("名(英文)"); th.createCell(2).setCellValue("姓(英文)"); th.createCell(3).setCellValue("中文姓名"); th.createCell(4).setCellValue("英文名"); th.createCell(5).setCellValue("员工编号"); th.createCell(6).setCellValue("岗位ID"); th.createCell(7).setCellValue("部门ID"); th.createCell(8).setCellValue("部门名称"); th.createCell(9).setCellValue("成本中心编码"); th.createCell(10).setCellValue("邮箱"); th.createCell(11).setCellValue("公司实体"); th.createCell(12).setCellValue("电话号"); th.createCell(13).setCellValue("座机号"); for (int i = 0; i < employeeList.size(); i++) { Employee e = employeeList.get(i); Row row = sheet.createRow(i + 2); row.createCell(0).setCellValue(e.getUserID()); row.createCell(1).setCellValue(e.getFIRSTNAMEEN()); row.createCell(2).setCellValue(e.getLASTNAMEEN()); row.createCell(3).setCellValue(e.getUSERNAMECN()); row.createCell(4).setCellValue(e.getPreferred_Name()); row.createCell(5).setCellValue(e.getUSERCODE()); row.createCell(6).setCellValue(e.getJOBCODEID()); row.createCell(7).setCellValue(e.getDEPARTMENTID()); row.createCell(8).setCellValue(e.getDEPARTMENTNAME()); row.createCell(9).setCellValue(e.getCOSTCENTERCODE()); row.createCell(10).setCellValue(e.getEMAIL()); row.createCell(11).setCellValue(e.getORGANIZATION()); row.createCell(12).setCellValue(e.getMOBILENO()); row.createCell(13).setCellValue(e.getTEL()); } List departmentList = getOrganizationResult.getDepartmentList(); Sheet depSheet = sxssfWorkbook.createSheet("部门信息"); Row depdesc = depSheet.createRow(0); depSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 2)); Cell cell1 = depdesc.createCell(0); cell1.setCellValue("部门信息表,同步数据时按照该上级部门id进行排序同步!红色字体为根部门!"); cell1.setCellStyle(cellStyle); Row depTh = depSheet.createRow(1); depTh.createCell(0).setCellValue("部门ID"); depTh.createCell(1).setCellValue("部门名称"); depTh.createCell(2).setCellValue("上级部门"); for (int i = 0; i < departmentList.size(); i++) { Row row = depSheet.createRow(i + 2); Department d = departmentList.get(i); row.createCell(0).setCellValue(d.getDEPARTMENTID()); row.createCell(1).setCellValue(d.getDEPARTMENTNAME()); Cell cell = row.createCell(2); cell.setCellValue(d.getPARENTDEPARTMENDID()); if (d.getPARENTDEPARTMENDID() == 0) { cell.setCellStyle(cellStyle); } } List positionList = getOrganizationResult.getPositionList(); Sheet posSheet = sxssfWorkbook.createSheet("职位信息"); Row posdesc = posSheet.createRow(0); posSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3)); Cell cell3 = posdesc.createCell(0); cell3.setCellValue("职位信息表,职位同步过程中以上级岗位id升序排序进行同步!"); cell3.setCellStyle(cellStyle); Row posTh = posSheet.createRow(1); posTh.createCell(0).setCellValue("岗位编号"); posTh.createCell(1).setCellValue("岗位编号"); posTh.createCell(2).setCellValue("岗位描述"); posTh.createCell(3).setCellValue("上级岗位ID"); for (int i = 0; i < positionList.size(); i++) { Row row = posSheet.createRow(i + 2); Position p = positionList.get(i); row.createCell(0).setCellValue(p.getJOBCODEID()); row.createCell(1).setCellValue(p.getJOBCODE()); row.createCell(2).setCellValue(p.getJOBFUNCTION()); row.createCell(3).setCellValue(p.getSUPERIORJOBCODEID()); } File file = new File("F:\\fanwei\\cms_async\\cms_data_proud.xlsx"); if (!file.exists()) { //先得到文件的上级目录,并创建上级目录,在创建文件 file.getParentFile().mkdir(); try { //创建文件 file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = new FileOutputStream(file); //写入文件 sxssfWorkbook.write(fileOutputStream); fileOutputStream.close(); } @Test public void testSyncOrganization() throws IOException { GetOrganizationResult getOrganizationResult = new GetOrganizationResult(); List employeeList = getOrganizationResult.getEmployeeList(); System.out.println(employeeList.size()); BufferedWriter employeeListOut = new BufferedWriter(new FileWriter("F:\\fanwei\\employee-list.json")); employeeListOut.write(JSON.toJSONString(employeeList)); employeeListOut.close(); List departmentList = getOrganizationResult.getDepartmentList(); BufferedWriter departmentListOut = new BufferedWriter(new FileWriter("F:\\fanwei\\department-list.json")); departmentListOut.write(JSON.toJSONString(departmentList)); departmentListOut.close(); System.out.println(departmentList.size()); List positionList = getOrganizationResult.getPositionList(); BufferedWriter positionListOut = new BufferedWriter(new FileWriter("F:\\fanwei\\position-list.json")); positionListOut.write(JSON.toJSONString(positionList)); positionListOut.close(); System.out.println(positionList.size()); } @Test public void testContains() { String str = "select d.id,m.api_field_type,d.api_field,d.change_rules,d.custom_rules_value,d.ao_field,oa_field_type from uf_cms_async as m inner join uf_cms_async_dt1 as d on d.mainid = m.id"; RecordSet rs = new RecordSet(); rs.executeQuery(str); rs.next(); System.out.println(rs.getString(0)); } @Test public void testSortEmployee() throws IOException { GetOrganizationResult getOrganizationResult = new GetOrganizationResult(); List employeeList = getOrganizationResult.getEmployeeList(); Collections.sort(employeeList); System.out.println(employeeList.size()); BufferedWriter employeeListOut = new BufferedWriter(new FileWriter("F:\\fanwei\\employee-list-sort.json")); employeeListOut.write(JSON.toJSONString(employeeList)); employeeListOut.close(); } @Test public void testCav(){ Map map = new HashMap<>(); map.put("contrast","[{\n" + "\t\"start\": \"fieldName\",\n" + "\t\"tableName\": \"databaseTableName\",\n" + "\t\"end\": \"endFieldName\",\n" + "\t\"workflowId\": 9,\n" + "\t\"user\": 10\n" + "}, {\n" + "\t\"start\": \"fieldName\",\n" + "\t\"tableName\": \"databaseTableName\",\n" + "\t\"end\": \"endFieldName\",\n" + "\t\"workflowId\": 9,\n" + "\t\"user\": 10\n" + "}, {\n" + "\t\"start\": \"fieldName\",\n" + "\t\"tableName\": \"databaseTableName\",\n" + "\t\"end\": \"endFieldName\",\n" + "\t\"workflowId\": 9,\n" + "\t\"user\": 10\n" + "}]"); WorkflowQueueService workflowQueueService = new WorkflowQueueService(); workflowQueueService.getWorkflowQueue(map); } @Test public void testEmailgetID(){ RequestApi requestApi = new RequestApi(); QsResponse userIdsByEmails = requestApi.getInfoByEmail( new ArrayList() {{ add("ZhangYun03@saicmotor.com"); }}); Map resultMap = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); try { resultMap = mapper.readValue(userIdsByEmails.getResult(), Map.class); } catch (JsonProcessingException e) { // toolUtil.writeErrorLog("请求结果转换失败,失败信息:" + e); } System.out.println(((Map) resultMap.get("ZhangYun03@saicmotor.com")).get("userId")); System.out.println(userIdsByEmails); } }