Commit bb12b72a by 宋祥

1.德诚

parent 283c28b5
...@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/tcp") @RequestMapping("/tcp")
public class TCPController extends WebDispatchController { public class TCPController extends WebDispatchController {
private final static Logger logger = LoggerFactory.getLogger(DocController.class); private final static Logger logger = LoggerFactory.getLogger(TCPController.class);
@RequestMapping(value = "/receive/api", method = RequestMethod.POST) @RequestMapping(value = "/receive/api", method = RequestMethod.POST)
......
package com.baosight.hggp.core.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baosight.hggp.core.constant.ZhiBangConst;
import com.baosight.hggp.core.model.zhiBang.Chance;
import com.baosight.hggp.util.HttpUtils;
import com.baosight.hggp.util.StringUtils;
import com.baosight.iplat4j.core.exception.PlatException;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
/**
* 智邦开放平台
*
* @author:songx
* @date:2024/1/29,9:16
*/
@Slf4j
public class ZhiBangApi {
/**
* 获取TOKEN
*
* @return
*/
public static String getToken() {
String token = SingletonHolder.TOKEN;
if (StringUtils.isBlank(token)) {
throw new PlatException("zhi bang token is null!");
}
return token;
}
/**
* 刷新TOKEN
*
* @return
*/
public static void refreshToken() {
SingletonHolder.refresh();
}
/**
* 项目管理-列表
*
* @param startTime 开始日期
* @param endTime 结束日期
* @param pageIndex 当前页
*/
public static List<Chance> chanceList(String startTime, String endTime, int pageIndex) throws IOException {
JSONArray dataJsons = new JSONArray();
dataJsons.add(buildValueJson("a_date_0", startTime));
dataJsons.add(buildValueJson("a_date_1", endTime));
dataJsons.add(buildValueJson("pageindex", pageIndex));
dataJsons.add(buildValueJson("pagesize", 100));
String param = JSON.toJSONString(buildParamJson(dataJsons));
String result = HttpUtils.post(ZhiBangConst.CHANCE_LIST, param, HttpUtils.FORM_MEDIA_TYPE);
if (StringUtils.isBlank(result)) {
throw new PlatException("【智邦】获取项目管理列表失败");
}
return handleResult(result, Chance.class);
}
/**
* 组装数据
*
* @return
*/
private static JSONObject buildParamJson(JSONArray dataJsons) {
JSONObject paramJson = new JSONObject();
paramJson.put("session", getToken());
paramJson.put("cmdkey", "refresh");
paramJson.put("datas", dataJsons);
return paramJson;
}
/**
* 组装值的json
*
* @param id
* @param val
* @return
*/
private static JSONObject buildValueJson(String id, Object val) {
JSONObject valueJson = new JSONObject();
valueJson.put("id", id);
valueJson.put("val", val);
return valueJson;
}
/**
* 构建返回结果对象
*
* @param result
* @return
*/
private static <T> List<T> handleResult(String result, Class<T> clazz) {
JSONObject resultJson = JSONObject.parseObject(result);
// 异常处理
handleMessage(resultJson);
// 构建结果数据集
return buildTableData(resultJson, clazz);
}
/**
* 处理返回消息
*
* @param resultJson
*/
private static void handleMessage(JSONObject resultJson) {
JSONObject headerJson = resultJson.getJSONObject("header");
String message = headerJson.getString("message");
String status = headerJson.getString("status");
// 会话非法
if (ZhiBangConst.ApiStatus.S_2.equals(status)) {
refreshToken();
throw new PlatException("【智邦】" + message);
}
}
/**
* 构建数据集
*
* @param resultJson
* @param clazz
* @param <T>
* @return
*/
private static <T> List<T> buildTableData(JSONObject resultJson, Class<T> clazz) {
JSONObject bodyJson = resultJson.getJSONObject("body");
JSONObject sourceJson = bodyJson.getJSONObject("source");
JSONObject tableJson = sourceJson.getJSONObject("table");
JSONArray colJsons = tableJson.getJSONArray("cols");
JSONArray rowJsons = tableJson.getJSONArray("rows");
return rowJsons.stream().map(item -> {
JSONArray singleRowJsons = (JSONArray) item;
// rowJsons存储的是行数据的为二维数组,长度与colJson相同
JSONObject rowValueJson = new JSONObject();
for (int j = 0; j < colJsons.size(); j++) {
rowValueJson.put(colJsons.getJSONObject(j).getString("id"), singleRowJsons.get(j));
}
return rowValueJson.toJavaObject(clazz);
}).collect(Collectors.toList());
}
/**
* 静态内部类用于初始化
*
* @author:songx
* @date:2022/5/9,15:48
*/
private static class SingletonHolder {
/**
* TOKEN
*/
private static String TOKEN = getToken();
/**
* 刷新TOKEN
*
* @return
*/
public static void refresh() {
TOKEN = getToken();
}
/**
* 获取TOKEN
*
* @return
*/
private static String getToken() {
try {
String param = JSON.toJSONString(buildParamJson());
String result = HttpUtils.post(ZhiBangConst.TOKEN_URL, param, HttpUtils.JSON_MEDIA_TYPE);
if (StringUtils.isBlank(result)) {
log.error("获取智邦API的TOKEN失败,接口返回null");
return null;
}
JSONObject headerJson = JSONObject.parseObject(result).getJSONObject("header");
Integer status = headerJson.getInteger("status");
if (status == null || status != 0) {
log.error("获取智邦API的TOKEN失败,api message:{}", headerJson.getInteger("message"));
return null;
}
return headerJson.getString("session");
} catch (Exception e) {
log.error("获取智邦API的TOKEN失败:{}", e.getMessage(), e);
}
return null;
}
/**
* 组装数据
*
* @return
*/
private static JSONObject buildParamJson() {
JSONObject paramJson = new JSONObject();
paramJson.put("datas", buildDataJson());
return paramJson;
}
/**
* 组装数据
*
* @return
*/
private static JSONArray buildDataJson() {
JSONArray dataJsons = new JSONArray();
dataJsons.add(buildValueJson("user", "txt:" + ZhiBangConst.API_KEY));
dataJsons.add(buildValueJson("password", "txt:" + ZhiBangConst.SECRET_KEY));
dataJsons.add(buildValueJson("serialnum", "txt:qwert12345"));
return dataJsons;
}
}
}
package com.baosight.hggp.core.constant; package com.baosight.hggp.core.constant;
import com.baosight.iplat4j.core.security.user.User;
/** /**
* @author:songx * @author:songx
* @date:2022/11/1,17:08 * @date:2022/11/1,17:08
...@@ -60,13 +58,14 @@ public class CommonConstant { ...@@ -60,13 +58,14 @@ public class CommonConstant {
* @author:songx * @author:songx
* @date:2024/1/20,15:04 * @date:2024/1/20,15:04
*/ */
public static class PlanStatus{ public static class PlanStatus {
// 审核通过 // 审核通过
public static final Integer UN_PLAN = 1; public static final Integer UN_PLAN = 1;
// 待审核 // 待审核
public static final Integer ON_PLAN = 0; public static final Integer ON_PLAN = 0;
} }
/** /**
* 常用字段常量 * 常用字段常量
* *
......
package com.baosight.hggp.core.constant;
/**
* @author:songx
* @date:2024/8/9,15:46
*/
public class ZhiBangConst {
/**
* Api Key
*/
public static final String API_KEY = "田民";
/**
* Secret Key
*/
public static final String SECRET_KEY = "123456";
/**
* 鉴权接口
*/
public static final String TOKEN_URL = "http://1.202.243.190:32131/webapi/v3/ov1/login";
/**
* 项目管理-列表
*/
public static final String CHANCE_LIST = "http://1.202.243.190:32131/sysa/mobilephone/salesmanage/chance/list.asp";
/**
* API状态码
*
* @author:songx
* @date:2024/8/9,17:10
*/
public static class ApiStatus {
/**
* 会话非法
*/
public static final String S_2 = "2";
}
}
package com.baosight.hggp.core.model.zhiBang;
import lombok.Data;
/**
* @author:songx
* @date:2024/8/9,16:41
*/
@Data
public class Chance {
/**
* 项目编号
*/
private String xmid;
/**
* 项目主题
*/
private String title;
}
package com.baosight.hggp.util; package com.baosight.hggp.util;
import org.springframework.web.bind.annotation.RequestMethod;
import java.io.IOException;
import java.util.Map;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
//import okhttp3.Headers; import okhttp3.Headers;
//import okhttp3.MediaType; import okhttp3.MediaType;
//import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
//import okhttp3.Request; import okhttp3.Request;
//import okhttp3.RequestBody; import okhttp3.RequestBody;
/** /**
* httpclient * httpclient
...@@ -15,94 +20,94 @@ import lombok.extern.slf4j.Slf4j; ...@@ -15,94 +20,94 @@ import lombok.extern.slf4j.Slf4j;
*/ */
@Slf4j @Slf4j
public class HttpUtils { public class HttpUtils {
//
// public static final MediaType JSON_MEDIA_TYPE = MediaType.get("application/json; charset=utf-8"); public static final MediaType JSON_MEDIA_TYPE = MediaType.get("application/json; charset=utf-8");
// public static final MediaType FORM_MEDIA_TYPE = MediaType.get("application/x-www-form-urlencoded"); public static final MediaType FORM_MEDIA_TYPE = MediaType.get("application/x-www-form-urlencoded");
//
// /** /**
// * GET请求 * GET请求
// * *
// * @param url * @param url
// * @return * @return
// * @throws IOException * @throws IOException
// */ */
// public static String get(String url) throws IOException { public static String get(String url) throws IOException {
// return get(url, null); return get(url, null);
// } }
//
// /** /**
// * GET请求 * GET请求
// * *
// * @param url * @param url
// * @param header * @param header
// * @return * @return
// * @throws IOException * @throws IOException
// */ */
// public static String get(String url, Map<String, String> header) throws IOException { public static String get(String url, Map<String, String> header) throws IOException {
// return request(RequestMethod.GET, url, header, null, JSON_MEDIA_TYPE); return request(RequestMethod.GET, url, header, null, JSON_MEDIA_TYPE);
// } }
//
// /** /**
// * POST请求 * POST请求
// * *
// * @param url * @param url
// * @return * @return
// * @throws IOException * @throws IOException
// */ */
// public static String post(String url) throws IOException { public static String post(String url) throws IOException {
// return post(url, null, JSON_MEDIA_TYPE); return post(url, null, JSON_MEDIA_TYPE);
// } }
//
// /** /**
// * POST请求 * POST请求
// * *
// * @param url * @param url
// * @param param * @param param
// * @return * @return
// * @throws IOException * @throws IOException
// */ */
// public static String post(String url, String param, MediaType mediaType) throws IOException { public static String post(String url, String param, MediaType mediaType) throws IOException {
// return post(url, null, param, mediaType); return post(url, null, param, mediaType);
// } }
//
// /** /**
// * http请求(post) * http请求(post)
// * *
// * @param url * @param url
// * @param header * @param header
// * @param param * @param param
// * @return * @return
// */ */
// public static String post(String url, Map<String, String> header, String param, MediaType mediaType) public static String post(String url, Map<String, String> header, String param, MediaType mediaType)
// throws IOException { throws IOException {
// return request(RequestMethod.POST, url, header, param, mediaType); return request(RequestMethod.POST, url, header, param, mediaType);
// } }
//
// /** /**
// * 发送请求 * 发送请求
// * *
// * @param requestMethod 请求类型POST OR GET * @param requestMethod 请求类型POST OR GET
// * @param url * @param url
// * @param header * @param header
// * @param param * @param param
// * @return * @return
// */ */
// private static String request(RequestMethod requestMethod, String url, Map<String, String> header, String param, private static String request(RequestMethod requestMethod, String url, Map<String, String> header, String param,
// MediaType mediaType) throws IOException { MediaType mediaType) throws IOException {
// log.info("请求开始:{},{},{}", url, header, StringUtils.subStr(param, 500)); log.info("请求开始:{},{},{}", url, header, StringUtils.subStr(param, 500));
// OkHttpClient okHttpClient = new OkHttpClient(); OkHttpClient okHttpClient = new OkHttpClient();
// Request.Builder builder = new Request.Builder().url(url); Request.Builder builder = new Request.Builder().url(url);
// if (RequestMethod.POST.equals(requestMethod)) { if (RequestMethod.POST.equals(requestMethod)) {
// builder = builder.post(RequestBody.create(StringUtils.isBlank(param) ? "" : param, mediaType)); builder = builder.post(RequestBody.create(StringUtils.isBlank(param) ? "" : param, mediaType));
// } else { } else {
// builder = builder.get(); builder = builder.get();
// } }
// if (MapUtils.isNotEmpty(header)) { if (MapUtils.isNotEmpty(header)) {
// builder = builder.headers(Headers.of(header)); builder = builder.headers(Headers.of(header));
// } }
// String result = okHttpClient.newCall(builder.build()).execute().body().string(); String result = okHttpClient.newCall(builder.build()).execute().body().string();
// log.info("请求结束:{}", StringUtils.subStr(result, 500)); log.info("请求结束:{}", StringUtils.subStr(result, 500));
// return result; return result;
// } }
//
} }
...@@ -33,13 +33,13 @@ hggpSchema=hggp ...@@ -33,13 +33,13 @@ hggpSchema=hggp
customerName=\u6B66\u6C49\u5B9D\u4FE1\u5927\u6570\u636E\u4E8B\u4E1A\u90E8 customerName=\u6B66\u6C49\u5B9D\u4FE1\u5927\u6570\u636E\u4E8B\u4E1A\u90E8
enterpriseName=\u6B66\u6C49\u5B9D\u4FE1\u5927\u6570\u636E\u4E8B\u4E1A\u90E8 enterpriseName=\u6B66\u6C49\u5B9D\u4FE1\u5927\u6570\u636E\u4E8B\u4E1A\u90E8
datasource.type=dbcp datasource.type=dbcp
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.driverClassName=com.mysql.cj.jdbc.Driver
#jdbc.url=jdbc:mysql://127.0.0.1:3306/iplat?useSSL=false&useUnicode=true&characterEncoding=utf-8 #jdbc.url=jdbc:mysql://127.0.0.1:3306/iplat?useSSL=false&useUnicode=true&characterEncoding=utf-8
jdbc.url=jdbc:mysql://129.211.46.84:3306/iplat_hggp?useSSL=false&useUnicode=true&characterEncoding=utf-8 jdbc.url=jdbc:mysql://129.211.46.84:3306/iplat_hggp?useSSL=false&useUnicode=true&characterEncoding=utf-8
jdbc.username=hggp #jdbc.username=hggp
#jdbc.username=root jdbc.username=root
jdbc.password=hggp123!@# #jdbc.password=hggp123!@#
#jdbc.password=123456 jdbc.password=Whxz@2019
jdbc.maxActive=20 jdbc.maxActive=20
jdbc.validationQuery=SELECT 1 FROM ${platSchema}.TEDFA00 jdbc.validationQuery=SELECT 1 FROM ${platSchema}.TEDFA00
......
...@@ -25,7 +25,7 @@ org.quartz.jobStore.isClustered = true ...@@ -25,7 +25,7 @@ org.quartz.jobStore.isClustered = true
#\uFFFD\u02F4\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u077F\uFFFD\u05BE\u00FB\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u077F\uFFFD\uFFFD\uFFFD\u0635\uFFFD\uFFFD\uFFFD\u03E2 #\uFFFD\u02F4\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u077F\uFFFD\u05BE\u00FB\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u077F\uFFFD\uFFFD\uFFFD\u0635\uFFFD\uFFFD\uFFFD\u03E2
org.quartz.jobStore.clusterCheckinInterval = 20000 org.quartz.jobStore.clusterCheckinInterval = 20000
org.quartz.dataSource.appDS.driver = com.mysql.jdbc.Driver org.quartz.dataSource.appDS.driver = com.mysql.cj.jdbc.Driver
org.quartz.dataSource.appDS.URL = jdbc:mysql://129.211.46.84:3306/iplat_hggp?useSSL=false&useUnicode=true&characterEncoding=utf-8 org.quartz.dataSource.appDS.URL = jdbc:mysql://129.211.46.84:3306/iplat_hggp?useSSL=false&useUnicode=true&characterEncoding=utf-8
#org.quartz.dataSource.appDS.URL = jdbc:mysql://127.0.0.1:3306/iplat?useSSL=false&useUnicode=true&characterEncoding=utf-8 #org.quartz.dataSource.appDS.URL = jdbc:mysql://127.0.0.1:3306/iplat?useSSL=false&useUnicode=true&characterEncoding=utf-8
org.quartz.dataSource.appDS.user =root org.quartz.dataSource.appDS.user =root
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment