Commit 63381967 by liuyang

添加同步鸿鹏日志接口

parent c02459bb
package com.baosight.hggp.core.extapp.decheng.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baosight.hggp.util.HttpUtils;
import com.baosight.hggp.util.MapUtils;
import com.baosight.hggp.util.StringUtils;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author LiuYang
* @version 1.0 2024/11/3
* @description
*/
@Slf4j
public class SbOpenApi {
/**
* 部门管理-列表
*
* @param eiInfo 当前页
*/
public static JSONArray list(EiInfo eiInfo) throws IOException, InstantiationException,
IllegalAccessException {
Map headerMap = new HashMap();
headerMap.put("x-token", SbTokenApi.getToken());
String url = PlatApplicationContext.getProperty("hpjx.url");
String result = HttpUtils.post(url+"/S_HP_SB_01", headerMap, JSON.toJSONString(eiInfo),
HttpUtils.JSON_MEDIA_TYPE);
if (StringUtils.isBlank(result)) {
throw new PlatException("【鸿鹏】获取设备日志列表失败");
}
JSONObject resultJson = JSONObject.parseObject(result);
return resultJson.getJSONArray(EiConstant.resultBlock);
}
}
package com.baosight.hggp.core.extapp.decheng.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baosight.hggp.util.HttpUtils;
import com.baosight.hggp.util.StringUtils;
import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext;
import lombok.extern.slf4j.Slf4j;
/**
* @author LiuYang
* @version 1.0 2024/11/3
* @description
*/
@Slf4j
public class SbTokenApi {
/**
* 获取TOKEN
*
* @return
*/
public static String getToken() {
String token = SbTokenApi.SingletonHolder.getToken();
if (StringUtils.isBlank(token)) {
throw new PlatException("hong pong token is null!");
}
return token;
}
/**
* 获取TOKEN(缓存)
*
* @return
*/
public static String getTokenCache() {
String token = SbTokenApi.SingletonHolder.TOKEN;
if (StringUtils.isNotBlank(token)) {
return token;
}
if (refreshToken()) {
return SbTokenApi.SingletonHolder.TOKEN;
} else {
throw new PlatException("hong pong token is null!");
}
}
/**
* 刷新TOKEN
*
* @return
*/
public static boolean refreshToken() {
return SbTokenApi.SingletonHolder.refresh();
}
/**
* 静态内部类用于初始化
*
* @author:songx
* @date:2022/5/9,15:48
*/
private static class SingletonHolder {
/**
* TOKEN
*/
private static String TOKEN = getToken();
/**
* 刷新TOKEN
*
* @return
*/
public static boolean refresh() {
String token = getToken();
if (StringUtils.isBlank(token)) {
return false;
}
TOKEN = token;
return true;
}
/**
* 获取TOKEN
*
* @return
*/
public static String getToken() {
try {
String param = JSON.toJSONString(buildValueJson("Q24022802","a123456"));
String url = PlatApplicationContext.getProperty("hpjx.url");
String result = HttpUtils.post(url+"/S_XS_105", param, HttpUtils.JSON_MEDIA_TYPE);
if (StringUtils.isBlank(result)) {
log.error("获取鸿鹏API的TOKEN失败,接口返回null");
return null;
}
JSONObject headerJson = JSONObject.parseObject(result);
Integer status = headerJson.getJSONObject("__sys__").getInteger("status");
if (status == null || status < 0) {
log.error("获取鸿鹏API的TOKEN失败,api msg:{}", headerJson.getInteger("msg"));
return null;
}
return headerJson.getString("x-token");
} catch (Exception e) {
log.error("获取鸿鹏API的TOKEN失败:{}", e.getMessage(), e);
}
return null;
}
/**
* 组装值的json
*
* @param loginName 登录名
* @param password 密码
* @return
*/
private static JSONObject buildValueJson(String loginName, Object password) {
JSONObject valueJson = new JSONObject();
valueJson.put("loginName", loginName);
valueJson.put("password", password);
return valueJson;
}
}
}
......@@ -47,11 +47,11 @@ public class HGSB010 extends DaoEPBase {
public static final String COL_UPDATED_TIME = "UPDATED_TIME"; /* 更新时间*/
public static final String COL_DELETE_FLAG = "DELETE_FLAG"; /* 是否删除0.否1.是*/
public static final String QUERY = "HPSB002.query";
public static final String COUNT = "HPSB002.count";
public static final String INSERT = "HPSB002.insert";
public static final String UPDATE = "HPSB002.update";
public static final String DELETE = "HPSB002.delete";
public static final String QUERY = "HGSB010.query";
public static final String COUNT = "HGSB010.count";
public static final String INSERT = "HGSB010.insert";
public static final String UPDATE = "HGSB010.update";
public static final String DELETE = "HGSB010.delete";
private Long id = new Long(0); /* ID*/
private String companyCode = " ";
......
package com.baosight.hggp.hg.sb.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baosight.hggp.aspect.annotation.OperationLogAnnotation;
import com.baosight.hggp.core.dao.DaoBase;
import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.extapp.decheng.api.SbOpenApi;
import com.baosight.hggp.hg.sb.domain.HGSB010;
import com.baosight.hggp.hg.xs.domain.User;
import com.baosight.hggp.hg.xs.tools.HGXSTools;
import com.baosight.hggp.util.DateUtils;
import com.baosight.hggp.util.EiInfoUtils;
import com.baosight.hggp.util.LogUtils;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
......@@ -162,4 +171,28 @@ public class ServiceHGSB010 extends ServiceEPBase {
//inInfo.set("errerDate", listMap2);
//inInfo.set("errerTime", result);
}
public EiInfo add(EiInfo inInfo){
try {
JSONArray jsonArray = SbOpenApi.list(inInfo);
User user = HGXSTools.XsUser.getByLogin("HG0000");
List<Map> list = jsonArray.stream().map(o -> (Map) o).collect(Collectors.toList());
for (Map map:list) {
HGSB010 hgsb010 = new HGSB010();
hgsb010.fromMap(map);
if (user!=null){
hgsb010.setCompanyCode(user.getAccountCode());
}else {
hgsb010.setCompanyCode("Q24072514");
}
DaoUtils.insert(HGSB010.INSERT, hgsb010);
}
inInfo.setStatus(EiConstant.STATUS_DEFAULT);
inInfo.setMsg("操作成功!本次对[" + jsonArray.size() + "]条数据新增成功!");
} catch (Exception e) {
LogUtils.setDetailMsg(inInfo, e, "设备数据同步失败");
}
return inInfo;
}
}
......@@ -128,7 +128,7 @@
-->
<insert id="insert">
INSERT INTO ${hggpSchema}.HGSB010 (ID, <!-- ID -->
INSERT INTO ${hggpSchema}.HGSB010 (
ACCOUNT_CODE,
FILE_NAME, <!-- 文件名 -->
EQUIPMENT_TYPE, <!-- 设备状态 -->
......@@ -138,12 +138,9 @@
CREATED_BY, <!-- 创建人 -->
CREATED_NAME, <!-- 创建人名称 -->
CREATED_TIME, <!-- 创建时间 -->
UPDATED_BY, <!-- 更新人 -->
UPDATED_NAME, <!-- 更新人名称 -->
UPDATED_TIME, <!-- 更新时间 -->
DELETE_FLAG <!-- 是否删除0.否1.是 -->
)
VALUES (#id#, #accountCode#, #fileName#, #equipmentType#, #equipmentCode#, #logInivalue#, #logValue#, #createdBy#, #createdName#, #createdTime#, #updatedBy#, #updatedName#, #updatedTime#, #deleteFlag#)
VALUES (#companyCode#, #fileName#, #equipmentType#, #equipmentCode#, #logInivalue#, #logValue#, #createdBy#, #createdName#, #createdTime#, #deleteFlag#)
</insert>
<delete id="delete">
......
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