|
@@ -0,0 +1,197 @@
|
|
|
+package com.management.platform.util;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
+import com.fasterxml.jackson.databind.MapperFeature;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
|
+import com.management.platform.mapper.CompanyReportMapper;
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.message.BasicNameValuePair;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.security.Key;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+public class DockWithMLD {
|
|
|
+ static String port="10.1.10.41:20170";
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ DockWithMLD dockWithMLD=new DockWithMLD();
|
|
|
+ JSONObject jsonObject=new JSONObject();
|
|
|
+ LocalDateTime startDate=LocalDateTime.parse("2022-08-01 00:00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ LocalDateTime endDate=LocalDateTime.parse("2022-08-31 00:00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ jsonObject.put("startDate",startDate);
|
|
|
+ jsonObject.put("endDate",endDate);
|
|
|
+ String jsonString = jsonObject.toJSONString();
|
|
|
+ dockWithMLD.getResult("http://"+port+"/api/cube/restful/interface/getModeDataPageList/getTravelRecord",jsonString);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static HttpRespMsg getResult(String url,String screenString){
|
|
|
+ HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ objectMapper.configure(MapperFeature.AUTO_DETECT_CREATORS, true);
|
|
|
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
+ objectMapper.registerModule(new JavaTimeModule());
|
|
|
+ objectMapper.configure(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
|
|
+ Map<String,Object> map = null;
|
|
|
+ CloseableHttpResponse response;// 响应类
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ //restful 接口 url
|
|
|
+ HttpPost httpPost = new HttpPost(url);//ex:"http://ip:port/api/cube/restful/interface/getModeDataPageList/rpakeywordList"
|
|
|
+ //当前日期
|
|
|
+ String currentDate = getCurrentDate();
|
|
|
+ //当前时间
|
|
|
+ String currentTime = getCurrentTime();
|
|
|
+ //获取时间戳
|
|
|
+ String currentTimeTamp = getTimestamp();
|
|
|
+ Map params = new HashMap<>();
|
|
|
+ Map paramDatajson = new HashMap<>();
|
|
|
+ //header
|
|
|
+ Map header = new HashMap<>();
|
|
|
+ //系统标识
|
|
|
+ String systemid = "worktime";
|
|
|
+ //密码
|
|
|
+ String d_password = "BF4CDEF5ED4941CE93F19D234D366241";
|
|
|
+ //封装 header 里的参数
|
|
|
+ header.put("systemid",systemid);
|
|
|
+ header.put("currentDateTime",currentTimeTamp);
|
|
|
+ String md5Source = systemid+d_password+currentTimeTamp;
|
|
|
+ String md5OfStr = getMD5Str(md5Source).toLowerCase();
|
|
|
+ //Md5 是:系统标识+密码+时间戳 并且 md5 加密的结果
|
|
|
+ header.put("Md5",md5OfStr);
|
|
|
+ paramDatajson.put("header",header);
|
|
|
+ //分页参数 处理全部数据 不需要进行分页
|
|
|
+ /*JSONObject pageInfo = new JSONObject();
|
|
|
+ pageInfo.put("pageNo", -1);
|
|
|
+ pageInfo.put("pageSize", -1);
|
|
|
+ paramDatajson.put("pageInfo",pageInfo);*/
|
|
|
+ //封装 mainTable 参数
|
|
|
+ JSONObject mainTable = JSON.parseObject(screenString);
|
|
|
+ paramDatajson.put("mainTable",mainTable);
|
|
|
+ //封装 operationinfo 参数
|
|
|
+ JSONObject operationinfo = new JSONObject();
|
|
|
+ operationinfo.put("operator", "MD10520");
|
|
|
+ paramDatajson.put("operationinfo",operationinfo);
|
|
|
+ System.out.println("===请求参数 datajson==="+paramDatajson);
|
|
|
+ params.put("datajson",paramDatajson);
|
|
|
+ //装填参数
|
|
|
+ List nvps = new ArrayList();
|
|
|
+ if(params!=null){
|
|
|
+ params.forEach((key, value) -> nvps.add(new BasicNameValuePair((String) key, JSONObject.toJSONString(value))));
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ httpPost.addHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
|
|
|
+ httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
|
|
|
+ response = httpClient.execute(httpPost);
|
|
|
+ if (response != null && response.getEntity() != null) {
|
|
|
+ //返回信息
|
|
|
+ String resulString = EntityUtils.toString(response.getEntity(),"UTF-8");
|
|
|
+ //todo 反序列化 报文数值到Map
|
|
|
+ map= objectMapper.readValue(resulString,Map.class);
|
|
|
+ List<Map> list = JSON.parseArray(String.valueOf(map.get("result")), Map.class);
|
|
|
+ List<Map> resultList=new ArrayList<>();
|
|
|
+ for (Map item : list) {
|
|
|
+ Map resultMap = (Map) item.get("mainTable");
|
|
|
+ resultList.add(resultMap);
|
|
|
+ }
|
|
|
+ httpRespMsg.data=resultList;
|
|
|
+ //todo 这里处理返回信息
|
|
|
+ System.out.println("成功"+ resulString);
|
|
|
+ }else{
|
|
|
+ System.out.println("获取数据失败,请查看日志"+currentDate+" "+currentTime);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ System.out.println("请求失败"+currentDate+" "+currentTime+"====error msg:"+e.getMessage());
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getMD5Str(String plainText) {
|
|
|
+ //定义一个字节数组
|
|
|
+ byte[] secretBytes = null;
|
|
|
+ try {
|
|
|
+ // 生成一个 MD5 加密计算摘要
|
|
|
+ MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
+ //对字符串进行加密
|
|
|
+ md.update(plainText.getBytes());
|
|
|
+ //获得加密后的数据
|
|
|
+ secretBytes = md.digest();
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ throw new RuntimeException("没有 md5 这个算法!");
|
|
|
+ }
|
|
|
+ //将加密后的数据转换为 16 进制数字
|
|
|
+ String md5code = new BigInteger(1, secretBytes).toString(16);
|
|
|
+ // 如果生成数字未满 32 位,需要前面补 0
|
|
|
+ // 不能把变量放到循环条件,值改变之后会导致条件变化。如果生成 30 位 只能生成 31位 md5
|
|
|
+ int tempIndex = 32 - md5code.length();
|
|
|
+ for (int i = 0; i < tempIndex; i++) {
|
|
|
+ md5code = "0" + md5code;
|
|
|
+
|
|
|
+ }
|
|
|
+ return md5code;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getCurrentTime() {
|
|
|
+ Date newdate = new Date();
|
|
|
+ long datetime = newdate.getTime();
|
|
|
+ Timestamp timestamp = new Timestamp(datetime);
|
|
|
+ String currenttime = (timestamp.toString()).substring(11, 13) + ":" +
|
|
|
+ (timestamp.toString()).substring(14, 16) + ":"
|
|
|
+ + (timestamp.toString()).substring(17, 19);
|
|
|
+ return currenttime;
|
|
|
+ }
|
|
|
+ public static String getCurrentDate() {
|
|
|
+ Date newdate = new Date();
|
|
|
+ long datetime = newdate.getTime();
|
|
|
+ Timestamp timestamp = new Timestamp(datetime);
|
|
|
+ String currentdate = (timestamp.toString()).substring(0, 4) + "-" +
|
|
|
+ (timestamp.toString()).substring(5, 7) + "-"
|
|
|
+ + (timestamp.toString()).substring(8, 10);
|
|
|
+ return currentdate;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取当前日期时间。 YYYY-MM-DD HH:MM:SS
|
|
|
+ * @return 当前日期时间
|
|
|
+ */
|
|
|
+ public static String getCurDateTime() {
|
|
|
+ Date newdate = new Date();
|
|
|
+ long datetime = newdate.getTime();
|
|
|
+ Timestamp timestamp = new Timestamp(datetime);
|
|
|
+ return (timestamp.toString()).substring(0, 19);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取时间戳 格式如:1999010123595
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getTimestamp(){
|
|
|
+ return getCurDateTime().replace("-", "").replace(":", "").replace(" ",
|
|
|
+ "");
|
|
|
+ }
|
|
|
+ public static int getIntValue(String v, int def) {
|
|
|
+ try {
|
|
|
+ return Integer.parseInt(v);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return def;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public static String null2String(Object s) {
|
|
|
+ return s == null ? "" : s.toString();
|
|
|
+ }
|
|
|
+}
|