ecology_maven/customization/test/NewTest.java

512 lines
18 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package customization.test;
import aiyh.utils.Util;
import aiyh.utils.entity.ApiConfigMainDTO;
import aiyh.utils.entity.FnainvoiceinterfaceDTO;
import aiyh.utils.httpUtil.HttpArgsType;
import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import aiyh.utils.mapUtil.UtilLinkedHashMap;
import aiyh.utils.sqlUtil.sqlResult.impl.BatchSqlResultImpl;
import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
import aiyh.utils.sqlUtil.whereUtil.Where;
import aiyh.utils.sqlUtil.whereUtil.impl.PrepWhereImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.api.aiyh_pcn.fadada.dao.FaDDServiceMapping;
import com.api.aiyh_pcn.fadada.service.impl.FaDDServiceImpl;
import com.api.aiyh_pcn.fadada.util.FaDDRequestUtils;
import com.weaver.general.TimeUtil;
import org.apache.axiom.util.base64.Base64Utils;
import org.apache.commons.codec.binary.Hex;
import org.apache.http.HttpEntity;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.junit.Test;
import weaver.conn.RecordSet;
import weaver.file.ImageFileManager;
import weaver.formmode.data.ModeDataIdUpdate;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.xcommon.IOUtils;
import weaver.hrm.User;
import weaver.soa.workflow.FileProcessor;
import weaver.workflow.workflow.WorkflowVersion;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* @author EBU7-dev1-ayh
* @create 2021/9/30 0030 12:50
* xinceshilei
*/
public class NewTest extends BaseTest {
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
// putIfAbsent添加不存在的键返回null如果为null表示不重复
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
public static String string2SHA256(String str) {
MessageDigest messageDigest;
String encdeStr = "";
try {
messageDigest = MessageDigest.getInstance("SHA-256");
byte[] hash = messageDigest.digest(str.getBytes(StandardCharsets.UTF_8));
encdeStr = Hex.encodeHexString(hash);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return encdeStr.toUpperCase();
}
@Test
public void testNewSQL() {
String sql = "select * from workflow_base";
RecordSet rs = new RecordSet();
rs.executeQuery(sql);
List<Map<String, Object>> maps = Util.recordSet2MapList(rs);
System.out.println(maps);
System.out.println("jiehus");
}
@Test
public void test() {
String versionStringByWfid = WorkflowVersion.getVersionStringByWfid("45");
System.out.println(versionStringByWfid);
}
@Test
public void createJavaFile() throws IOException {
String query = "";
/*query = "select main.id,main.workflow_type, wf.fieldname field_control, " +
"(select GROUP_CONCAT('',selectvalue,'') result from workflow_selectitem where FIND_IN_SET(id,main.check_personal)) check_personal, " +
"(select GROUP_CONCAT('',selectvalue,'') result from workflow_selectitem where FIND_IN_SET(id,main.check_enterprise)) check_enterprise, " +
"main.check_source_type,wdt.tablename check_source " +
"from uf_attestation_conf main " +
"left join workflow_field_table_view wf on wf.id = main.field_control " +
"left join workflow_detail_table_view wdt on wdt.id = main.check_source and wdt.workflow_id = main.workflow_type";
query = "select dt.id,dt.line_num,dt.param_name,dt.param_type,dt.object_child,dt.parent_line,dt.change_rule, " +
"dt.param_value,wf.fieldname workflow_field,wf.tablename tablename,dt.array_sql,dt.api_type " +
"from uf_attestation_conf_dt1 dt " +
"left join workflow_field_table_view wf on wf.id = dt.workflow_field ";
*/
/*query = "select dt.id,dt.line_num,dt.param_name,dt.param_type,dt.object_child,dt.parent_line,dt.change_rule, " +
"dt.param_value,wf.fieldname workflow_field,wf.tablename tablename,dt.array_sql " +
"from uf_api_param_config_dt1 dt " +
"left join workflow_field_table_view wf on wf.id = dt.workflow_field ";
Util.creatJavaFileBySql(query, "ApiConfigDetail", "aiyh.utils.entity");
query = "select id,workflow_type,api_url,api_name from uf_api_param_config ";
Util.creatJavaFileBySql(query, "ApiConfigMain", "aiyh.utils.entity");*/
/*query = "select main.id,main.workflow_type,main.api_type, main.params_config, " +
"wf.fieldname field_control, " +
"(select GROUP_CONCAT('',selectvalue,'') selectvalue from workflow_selectitem where FIND_IN_SET(id,main.check_personal)) check_personal, " +
"(select GROUP_CONCAT('',selectvalue,'') selectvalue from workflow_selectitem where FIND_IN_SET(id,main.check_enterprise)) check_enterprise, " +
"main.check_source_type,wdt.tablename check_source " +
"from uf_contract_config main " +
"left join workflow_field_table_view wf on wf.id = main.field_control " +
"left join workflow_detail_table_view wdt on wdt.id = main.check_source and wdt.workflow_id = main.workflow_type ";*/
query = "select * from uf_multi_language_dt1";
Util.creatJavaFileBySql(query, "MultiLanguage", "aiyh.utils.entity");
}
@Test
public void testQueryConf() {
FaDDServiceMapping faDDServiceMapping = new FaDDServiceMapping();
// FaDDConfigMainDTO configParam = faDDServiceMapping.getConfigParam("45");
// System.out.println(JSON.toJSONString(configParam));
}
@Test
public void testSubString() {
String str = "formtable_main_17_dt1";
System.out.println(str.substring(str.indexOf("_dt") + 3));
}
@Test
public void pattern() {
String str = "流程的requestid{{$requestId}}流程路径的{{$workflowid}}我不知道{{main.test}}对不对,{{detail.field}}";
String pattern = "\\{{2}(?<table>((?!\\$)\\S)+?)\\.(?<field>\\S+?)}{2}";
String pattern1 = "\\{{2}\\$(?<value>(\\S)+?)}{2}";
Pattern compile1 = Pattern.compile(pattern1);
Matcher matcher1 = compile1.matcher(str);
// while (matcher1.find()){
// str = str.replaceFirst(pattern1,matcher1.group("value"));
// System.out.println(str);
// System.out.println(matcher1.group("value"));
// }
Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(str);
while (matcher.find()) {
System.out.println(matcher.group("table"));
System.out.println(matcher.group("field"));
}
System.out.println(matcher);
}
@Test
public void testParsingSql() {
Map<String, Object> params = new HashMap<>();
params.put("requestId", "67544");
params.put("workflowId", "45");
params.put("main.field", null);
params.put("main.field1", "field1");
params.put("main.field2", "field2");
params.put("main.field3", "field3");
String map = Util.parsingSq("select * from maintable where " +
"test1 = {{main.field1}} and " +
"test2 = {{main.field2}} and " +
"test3 = {{main.field}} and " +
"test4 = {{main.field1}} and " +
"test5 = {{main.field3}}", params);
System.out.println(map);
}
@Test
public void testParsingSqlByWorkflowId() {
Map<String, Object> params = new HashMap<>();
params.put("requestId", "67544");
params.put("workflowId", "45");
params.put("main.field", "field");
params.put("main.field1", "field1");
params.put("main.field2", "field2");
params.put("main.field3", "field3");
params.put("main.indata", "1,2,3,4,5,6");
String result = "select * from maintable where " +
"test1 = {{main.field1}} and " +
"test2 = {{main.field2}} and " +
"test3 = {{main.field}} and " +
"test4 = {{main.field1}} and " +
"test5 = {{main.field3}} and " +
"id in (#{{main.indata}})";
String s = Util.parsingSq(result, params);
System.out.println(s);
}
@Test
public void testImp() {
FaDDServiceImpl faDDService = new FaDDServiceImpl();
// Map<String, Object> configParam1 = faDDService.getConfigParam1("45");
// System.out.println(JSON.toJSONString(configParam1));
// Map<String, Object> configParam = faDDService.getConfigParam("45");
// System.out.println(JSON.toJSONString(configParam));
// Map<String,Object> map = new HashMap<>();
// map.put("workflowId","45");
// map.put("dataArr",new ArrayList<TableFieldMappingVO>(){{
// TableFieldMappingVO tableFieldMappingVO = new TableFieldMappingVO();
// tableFieldMappingVO.setField("field");
// tableFieldMappingVO.setTableName("tableName");
// add(tableFieldMappingVO);
// TableFieldMappingVO tableFieldMappingVO1 = new TableFieldMappingVO();
// tableFieldMappingVO1.setField("field1");
// tableFieldMappingVO1.setTableName("tableName1");
// add(tableFieldMappingVO1);
// }});
// faDDService.checkCertification(map);
Map<String, Object> map = new HashMap<>();
List<Map<String, Object>> dataArr = new ArrayList<Map<String, Object>>() {{
Map<String, Object> map = new HashMap<>();
map.put("detail_1.gyshtfmczw", "gyshtfmczw-value-api");
map.put("detail_1.tyshxydm", "gyshtflb-value-api");
add(map);
Map<String, Object> map1 = new HashMap<>();
map1.put("detail_1.gyshtfmczw", "gyshtfmczw1-value-api");
map1.put("detail_1.tyshxydm", "gyshtflb1-value-api");
add(map1);
Map<String, Object> map2 = new HashMap<>();
map2.put("detail_1.gyshtfmczw", "gyshtfmczw2-value-api");
map2.put("detail_1.tyshxydm", "gyshtflb2-value-api");
add(map2);
Map<String, Object> map3 = new HashMap<>();
map3.put("detail_1.gyshtfmczw", "gyshtfmczw3-value-api");
map3.put("detail_1.tyshxydm", "gyshtflb3-value-api");
add(map3);
Map<String, Object> map4 = new HashMap<>();
map4.put("detail_1.gyshtfmczw", "gyshtfmczw4-value-api");
map4.put("detail_1.tyshxydm", "gyshtflb4-value-api");
add(map4);
}};
map.put("dataArr", dataArr);
map.put("workflowId", "45");
Map<String, Object> stringObjectMap = faDDService.checkCertification(map);
// faDDService.checkCertification1(map);
System.out.println(stringObjectMap);
}
@Test
public void testMap() {
List<String> list = new ArrayList<String>() {{
add("测试");
add("测试1");
add("测试2");
add("测试3");
add("测试4");
add("测试");
}};
List<String> collect = list.stream().map(item -> item + "[aaa]").collect(Collectors.toList());
System.out.println(collect);
System.out.println(list);
}
@Test
public void testHttp() throws UnsupportedEncodingException {
HttpUtils httpUtils = new HttpUtils();
Map<String, String> header = httpUtils.getGlobalCache().header;
header.put("appId", "100001");
header.put("signType", "SHA256");
header.put("timestamp", Util.getTime("yyyy-MM-dd HH:mm:ss"));
Map<String, Object> data = new HashMap<>();
data.put("companyName", "公司名称");
data.put("creditNo", "统一社会信用代码");
String jsonString = JSONObject.toJSONString(data);
String encode = URLEncoder.encode(jsonString, "UTF-8");
String bizContent = Base64.getEncoder().encodeToString(encode.getBytes(StandardCharsets.UTF_8));
header.put("bizContent", bizContent);
StringBuilder signBuilder = new StringBuilder();
String signStr = signBuilder.append("appId=").append(header.get("appId"))
.append("&bizContent=").append(header.get("bizContent"))
.append("&signType=").append(header.get("signType"))
.append("&timestamp=").append(header.get("timestamp")).toString();
System.out.println(signStr);
String appkey = "L7P59oqA2An0XgJ1LeMN0fRu1";
String sha256 = string2SHA256(signStr) + appkey;
String sign = Base64.getEncoder().encodeToString(string2SHA256(sha256).getBytes(StandardCharsets.UTF_8));
System.out.println(sign);
header.put("sign", sign);
header.put("apikey", "TulQxnZSRKeHoQfmeZzOUzGn6KpTDkDK");
header.put("Content-Type", HttpArgsType.APPLICATION_JSON);
try {
ResponeVo responeVo = httpUtils.apiPost("http://apigwaws-lite.porsche-cloudservice.com/env-101/econtract/econtract/contract/api/v1/account/company/info",
data, null);
System.out.println(responeVo.getEntityString());
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void testApi() {
ApiConfigMainDTO apiConfigMainDTO = Util.queryApiConfig("2");
}
@Test
public void getCode() {
Map<String, Object> map = new HashMap<>();
map.put("companyName", "陕西正天建设有限公司");
map.put("creditNo", "916100007273444965");
Map<String, Object> stringObjectMap = FaDDRequestUtils.checkCompanyInfo(map);
System.out.println(JSON.toJSONString(stringObjectMap));
}
@Test
public void testBatch() {
List<LinkedHashMap<String, Object>> list = new ArrayList<>();
List<Where> whereList = new ArrayList<>();
for (int i = 0; i < 50; i++) {
int finalI = i;
list.add(new UtilLinkedHashMap<String, Object>() {{
put("mobile", "1111111" + finalI);
}});
whereList.add(new PrepWhereImpl().whereAnd("id").whereEqual(22 + finalI));
}
BatchSqlResultImpl hrmresource = Util.createSqlBuilder().updateBatchSql("hrmresource", list, whereList);
RecordSet rs = new RecordSet();
long l = System.currentTimeMillis();
boolean b = rs.executeBatchSql(hrmresource.getSqlStr(), hrmresource.getBatchList());
long l1 = System.currentTimeMillis();
System.out.println(l1 - l);
System.out.println(b);
}
@Test
public void testUpdate() {
long constTime = 0L;
RecordSet rs = new RecordSet();
for (int i = 0; i < 50; i++) {
int finalI = i;
UtilLinkedHashMap<String, Object> mobile = new UtilLinkedHashMap<String, Object>() {{
put("mobile", "111111" + finalI);
}};
Where id = new PrepWhereImpl().whereAnd("id").whereEqual(22 + finalI);
PrepSqlResultImpl sqlResult = Util.createSqlBuilder().updateSql("hrmresource", mobile, id);
long l = System.currentTimeMillis();
boolean b = rs.executeUpdate(sqlResult.getSqlStr(), sqlResult.getArgs());
long l1 = System.currentTimeMillis();
constTime += (l1 - l);
System.out.println(b);
}
System.out.println(constTime);
}
@Test
public void testSuffix() {
String str = "【保时捷】合同管理需求文档-第一阶段流程V5.3.pdf";
String substring = str.substring(str.lastIndexOf("."));
System.out.println(substring);
}
@Test
public void testUpload() {
RecordSet rs = new RecordSet();
String query = "select * from formtable_main_17_dt1 where mainid = 5";
rs.executeQuery(query);
List<Map<String, Object>> maps = Util.recordSet2MapList(rs);
System.out.println(JSONObject.toJSONString(maps));
// Map<String, String> map = Util.queryLanguage(1, 8);
// System.out.println(map);
}
@Test
public void invoice() throws IOException {
String query = "select * from fnainvoiceinterface where interfaceType=2 and status=1 and subIdStatus=0";
RecordSet rs = new RecordSet();
rs.executeQuery(query);
FnainvoiceinterfaceDTO fnainvoiceinterfaceDTO = Util.recordeSet2Entity(rs, FnainvoiceinterfaceDTO.class);
System.out.println(fnainvoiceinterfaceDTO);
// Util.creatJavaFileByTable("fnainvoiceinterface","aiyh.utils.entity");
}
@Test
public void testLanguage() {
System.out.println(Util.getHtmlLabelName(1, 7, "不知道"));
}
@Test
public void createJava() throws IOException {
Util.creatJavaFileByTable("uf_invoice_config", "com.api.aiyh_kafang.entity");
}
@Test
public void testUtil() {
RecordSet rs = new RecordSet();
rs.executeQuery("select formid from workflow_base where id = 45");
String s = Util.recordeSet2Entity(rs, String.class);
System.out.println(s);
}
@Test
public void testMode() {
ModeDataIdUpdate mdu = ModeDataIdUpdate.getInstance();
String formModeId = "52";
int dataid = mdu.getModeDataNewId("uf_contract_config",
Util.getIntValue(formModeId, -1),
1, 0, TimeUtil.getCurrentDateString(),
TimeUtil.getOnlyCurrentTimeString());
//数据权限重构
ModeRightInfo mri = new ModeRightInfo();
mri.rebuildModeDataShareByEdit(1, Util.getIntValue(formModeId, -1), 1);
}
@Test
public void donwTest() throws IOException {
Map<String, Object> data = new HashMap<>();
data.put("contractNo", "bda970602f4a4e1dbe37ee9c43908cfc");
AtomicReference<InputStream> content = new AtomicReference<>();
FaDDRequestUtils.downContract(data, response -> {
HttpEntity entity = response.getEntity();
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("法大大请求接口错误!");
}
try {
content.set(entity.getContent());
} catch (IOException e) {
e.printStackTrace();
}
InputStream inputStream = content.get();
try {
byte[] bytes = IOUtils.toByteArray(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}, "https://apigwaws-lite.porsche-cloudservice.com/env-101/econtract/econtract/contract/api/v1/contract/download");
}
@Test
public void testBase642system() throws IOException {
String path = "C:\\Users\\77449\\Downloads\\154157.pdf";
InputStream is = new FileInputStream(path);
byte[] bytes = IOUtils.toByteArray(is);
String base64 = Base64Utils.encode(bytes);
FileProcessor fileProcessor = new FileProcessor();
User user = new User();
user.setUid(1);
user.setLogintype("1");
int process = fileProcessor.Process("base64:"+base64, ",,88", user, "测试合同下载保存.pdf");
System.out.println(process);
}
@Test
public void downPDF() throws IOException {
InputStream inputStreamById = ImageFileManager.getInputStreamById(3618);
OutputStream out = new FileOutputStream("C:\\Users\\77449\\Downloads\\154157合同测试.pdf");
int cache = 1024 * 10;
byte[] bytes = new byte[cache];
int len = 0;
while ((len = inputStreamById.read(bytes)) != -1){
out.write(bytes,0,len);
}
out.flush();
out.close();
}
@Test
public void testDocCategorys(){
String docCategorys = Util.getDocCategorys("47","khpj");
System.out.println(docCategorys);
}
@Test
public void testToint(){
List<Integer> docIds = new ArrayList<>();
docIds.add(1);
docIds.add(2);
docIds.add(3);
docIds.add(4);
Integer[] strings = docIds.toArray(new Integer[0]);
int[] ints = Arrays.stream(strings).mapToInt(Integer::valueOf).toArray();
System.out.println(Arrays.toString(ints));
}
@Test
public void tesetLong(){
// SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
// Sheet sheet = sxssfWorkbook.createSheet("人员信息");
// Row desc = sheet.createRow(0);
// desc.createCell(1).setCellValue(null);
// System.out.println(i);
}
}