Commit c8c1e108 authored by hezhuozhi's avatar hezhuozhi

所有厂商的所有接口采集数据新增采集原始数据日志表,以及时间

parent ed6e5d61
......@@ -3,14 +3,14 @@ package com.yeejoin.amos.api.householdapi.Utils;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.log.Log;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.api.householdapi.constant.GoLangConstant;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HousepvapiRecords;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HYGFThirdStationLog;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HousepvapiRecordsMapper;
import com.yeejoin.amos.api.householdapi.face.service.IHYGFThirdStationLogService;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
......@@ -26,7 +26,8 @@ public class GolangRequestUtil {
@Autowired
HousepvapiRecordsMapper housepvapiRecordsMapper;
@Autowired
IHYGFThirdStationLogService thirdStationLogService;
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer
......@@ -79,6 +80,15 @@ public class GolangRequestUtil {
if (!ObjectUtils.isEmpty(jsonArray)) {
result.addAll(JSONArray.parseArray(jsonArray.toJSONString(), tClass));
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.JLY.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
//处理其他页数的数据
JSONObject responeJSON = JSONObject.parseObject(respone);
JSONObject data = responeJSON.getJSONObject("data");
......@@ -130,6 +140,15 @@ public class GolangRequestUtil {
if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.JLY.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
} catch (Exception exception) {
return result;
}
......
......@@ -6,6 +6,9 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.api.householdapi.constant.GoodWeConstant;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HYGFThirdStationLog;
import com.yeejoin.amos.api.householdapi.face.service.IHYGFThirdStationLogService;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
......@@ -18,7 +21,8 @@ public class GoodWeRequestUtil {
@Autowired
private RedisUtils redisUtils;
@Autowired
IHYGFThirdStationLogService thirdStationLogService;
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer
......@@ -77,6 +81,15 @@ public class GoodWeRequestUtil {
if (!ObjectUtils.isEmpty(jsonArray)) {
result.addAll(JSONArray.parseArray(jsonArray.toJSONString(), tClass));
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.GDW.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
//处理其他页数的数据
JSONObject responeJSON = JSONObject.parseObject(respone);
JSONObject data = responeJSON.getJSONObject("data");
......@@ -124,6 +137,15 @@ public class GoodWeRequestUtil {
if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.GDW.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
} catch (Exception exception) {
return result;
}
......
......@@ -10,8 +10,9 @@ import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.api.householdapi.constant.ImasterConstant;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HousepvapiRecords;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HYGFThirdStationLog;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HousepvapiRecordsMapper;
import com.yeejoin.amos.api.householdapi.face.service.impl.GoodWeDataAcquisitionServiceImpl;
import com.yeejoin.amos.api.householdapi.face.service.IHYGFThirdStationLogService;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import lombok.extern.slf4j.Slf4j;
......@@ -33,6 +34,8 @@ public class ImasterUtils {
HousepvapiRecordsMapper housepvapiRecordsMapper;
@Autowired
RedisUtils redisUtils;
@Autowired
IHYGFThirdStationLogService thirdStationLogService;
final static Logger logger = LoggerFactory.getLogger(ImasterUtils.class);
......@@ -96,6 +99,15 @@ public class ImasterUtils {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
}
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
} else {
HashMap<String, String> headMap = getHeader();
String url = ImasterConstant.baseurl + apiurl;
......@@ -105,6 +117,15 @@ public class ImasterUtils {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
redisUtils.set(redisKey, headMap.get("XSRF-TOKEN"));
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
}
} catch (Exception exception) {
return result;
......@@ -155,6 +176,15 @@ public class ImasterUtils {
}
}
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
} else {
HashMap<String, String> headMap = getHeader();
String url = ImasterConstant.baseurl + apiurl;
......@@ -164,6 +194,15 @@ public class ImasterUtils {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
redisUtils.set(redisKey, headMap.get("XSRF-TOKEN"));
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
}
} catch (Exception exception) {
exception.printStackTrace();
......
......@@ -2,16 +2,15 @@ package com.yeejoin.amos.api.householdapi.Utils;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.api.householdapi.constant.GoLangConstant;
import com.yeejoin.amos.api.householdapi.constant.KSolarConstant;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HousepvapiRecords;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HYGFThirdStationLog;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HousepvapiRecordsMapper;
import com.yeejoin.amos.api.householdapi.face.service.IHYGFThirdStationLogService;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.jcajce.provider.symmetric.AES;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
......@@ -25,7 +24,8 @@ public class KsolarRequestUtil {
@Autowired
HousepvapiRecordsMapper housepvapiRecordsMapper;
@Autowired
IHYGFThirdStationLogService thirdStationLogService;
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer
......@@ -74,6 +74,15 @@ public class KsolarRequestUtil {
if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.KSOLAR.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
} catch (Exception exception) {
return result;
}
......
......@@ -6,6 +6,9 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.api.householdapi.constant.SoFarConstant;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HYGFThirdStationLog;
import com.yeejoin.amos.api.householdapi.face.service.IHYGFThirdStationLogService;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -55,6 +58,8 @@ public class SofarRequestUtil {
@Autowired
private RedisUtils redisUtils;
@Autowired
IHYGFThirdStationLogService thirdStationLogService;
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
......@@ -115,6 +120,15 @@ public class SofarRequestUtil {
result.addAll(JSONArray.parseArray(fastjson.JSON.toJSONString(jsonObject.get(ResultResolveRule)), tClass));
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.SH.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
//处理其他页数的数据
JSONObject responeJSON = JSONObject.parseObject(respone);
Integer total = responeJSON.getInteger("total");
......@@ -156,6 +170,15 @@ public class SofarRequestUtil {
result = JSONArray.parseArray(fastjson.JSON.toJSONString(jsonObject.get(ResultResolveRule)), tClass);
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.SH.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
} catch (Exception exception) {
exception.printStackTrace();
return result;
......@@ -176,6 +199,15 @@ public class SofarRequestUtil {
}else{
jsonObject = JSONObject.parseObject(respone);
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.SH.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
} catch (Exception exception) {
exception.printStackTrace();
}
......
......@@ -8,27 +8,15 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.google.gson.Gson;
import com.yeejoin.amos.api.householdapi.face.dto.SunlightDto;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.Sunlight;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HousepvapiRecordsMapper;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HYGFThirdStationLog;
import com.yeejoin.amos.api.householdapi.face.service.IHYGFThirdStationLogService;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.naming.Name;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
......@@ -158,6 +146,8 @@ public class SunlightUtil {
@Autowired
RedisUtils redisUtils;
@Autowired
IHYGFThirdStationLogService thirdStationLogService;
/*
*
......@@ -249,6 +239,15 @@ public class SunlightUtil {
pageList.addAll(JSONArray.parseArray(JSON.toJSONString(resultData.get("pageList"))));
resultData.putOpt("pageList",pageList);
}
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.YG.getCode());
hygfThirdStationLog.setReqMethod(request.getMethod().toString());
hygfThirdStationLog.setReqHeaders(request.headers().toString());
hygfThirdStationLog.setReqPath(dfurl+url);
hygfThirdStationLog.setReqBody(body);
hygfThirdStationLog.setResBody(res);
thirdStationLogService.saveLog(hygfThirdStationLog);
//处理其他页数的数据
Integer rowCount = resultData.getInt("rowCount");
Integer pageSize= bodyparam.get("size")==null || (Integer)bodyparam.get("size")==0? 1:(Integer)bodyparam.get("size");
......@@ -295,7 +294,15 @@ public class SunlightUtil {
JSONObject jsonObject = JSONUtil.parseObj(res, true);
JSONObject resultData = JSONUtil.parseObj(jsonObject.get("result_data"), true);
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.YG.getCode());
hygfThirdStationLog.setReqMethod(request.getMethod().toString());
hygfThirdStationLog.setReqHeaders(request.headers().toString());
hygfThirdStationLog.setReqPath(dfurl+url);
hygfThirdStationLog.setReqBody(body);
hygfThirdStationLog.setResBody(res);
thirdStationLogService.saveLog(hygfThirdStationLog);
return resultData;
} catch (Exception e) {
log.error("失败,msg["+e.getMessage()+"]", e);
......
......@@ -10,9 +10,14 @@ import com.yeejoin.amos.api.householdapi.exception.BusinessException;
import com.yeejoin.amos.api.householdapi.face.dto.TanYinAccessTokenDTO;
import com.yeejoin.amos.api.householdapi.face.dto.TanYinBaseResultDTO;
import com.yeejoin.amos.api.householdapi.face.dto.TanYinPageResultDTO;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HYGFThirdStationLog;
import com.yeejoin.amos.api.householdapi.face.service.IHYGFThirdStationLogService;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
......@@ -50,6 +55,9 @@ public class TanYinApiUtils {
@Resource (type = RedisUtils.class)
private RedisUtils redisUtils;
@Autowired
private IHYGFThirdStationLogService thirdStationLogService;
/**
* 获取 accessToken 接口
*
......@@ -118,6 +126,15 @@ public class TanYinApiUtils {
headers.put("Authorization", "Bearer " + getAccessToken(clientKey, clientSecret));
// 发送GET请求并获取响应。
response = HttpUtil.createGet(url).execute();
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.TANYIN.getCode());
hygfThirdStationLog.setReqMethod(HttpMethod.GET.name());
hygfThirdStationLog.setReqHeaders(headers.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(null);
hygfThirdStationLog.setResBody(response.toString());
thirdStationLogService.saveLog(hygfThirdStationLog);
// 解析响应并返回结果。
return parseResponse(desc, response, resultClass);
} catch (BusinessException businessException) {
......@@ -166,6 +183,15 @@ public class TanYinApiUtils {
try {
// 发送POST请求,带上参数和headers,并执行。
response = HttpUtil.createPost(url).body(paramsJsonStr, MediaType.APPLICATION_JSON_UTF8_VALUE).headerMap(headers, true).execute();
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.TANYIN.getCode());
hygfThirdStationLog.setReqMethod(HttpMethod.POST.name());
hygfThirdStationLog.setReqHeaders(headers.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(paramsJsonStr);
hygfThirdStationLog.setResBody(response.toString());
thirdStationLogService.saveLog(hygfThirdStationLog);
// 解析响应并返回。
return parseResponse(desc, response, resultClass);
} catch (BusinessException businessException) {
......@@ -218,6 +244,15 @@ public class TanYinApiUtils {
response = HttpUtil.createPost(url).body(paramsJsonStr, MediaType.APPLICATION_JSON_UTF8_VALUE).headerMap(headers, true).execute();
// 记录响应日志
log.info("响应 => 碳银{}接口,参数:{},httpCode:{}, response:{}", desc, paramsJsonStr, response.getStatus(), response.body());
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.TANYIN.getCode());
hygfThirdStationLog.setReqMethod(HttpMethod.POST.name());
hygfThirdStationLog.setReqHeaders(headers.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(paramsJsonStr);
hygfThirdStationLog.setResBody(response.toString());
thirdStationLogService.saveLog(hygfThirdStationLog);
// 解析响应,返回分页信息和请求结果
return parsePageResponse(desc, response, resultClass);
} catch (BusinessException businessException) {
......
package com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class HYGFThirdStationLog implements Serializable {
private String id;
private String thirdCode;
private Date reqTime;
private String reqMethod;
private String reqPath;
private String reqHeaders;
private String reqBody;
private String resBody;
}
package com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HYGFThirdStationLog;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
public interface HYGFThirdStationLogMapper extends BaseMapper<HYGFThirdStationLog> {
// 创建新的数据表
@Select("CREATE TABLE IF NOT EXISTS ${tableName} (\n" +
" `id` varchar(256) NOT NULL,\n" +
" `third_code` varchar(30),\n" +
" `req_time` datetime(0),\n" +
" `req_method` varchar(20),\n" +
" `req_path` varchar(1000),\n" +
" `req_headers` varchar(1000),\n" +
" `req_body` longtext,\n" +
" `res_body` longtext,\n" +
" PRIMARY KEY (`id`) USING BTREE\n" +
");")
void createTable(@Param("tableName")String tableName);
// 插入数据到指定表
@Insert("INSERT INTO ${tableName} (`id`,`third_code`,`req_time`,`req_method`,`req_path`,`req_headers`,`req_body`,`res_body`) VALUES (#{thirdStationLog.id},#{thirdStationLog.thirdCode},#{thirdStationLog.reqTime},#{thirdStationLog.reqMethod},#{thirdStationLog.reqPath},#{thirdStationLog.reqHeaders},#{thirdStationLog.reqBody},#{thirdStationLog.resBody})")
void insertData(@Param("tableName") String tableName, @Param("thirdStationLog")HYGFThirdStationLog thirdStationLog);
// 删除超过时间的表
@Select("DROP TABLE IF EXISTS ${tableName}")
void dropTable(@Param("tableName")String tableName);
//获取表数量
@Select("SELECT COUNT(1) FROM information_schema.tables WHERE table_name LIKE #{tableName}")
Integer countTable(@Param("tableName")String tableName);
//获取最老的表名称
@Select("SELECT table_name FROM information_schema.tables WHERE table_name LIKE #{tableName} ORDER BY table_name ASC LIMIT 1")
String getOldestTableName(@Param("tableName")String tableName);
}
package com.yeejoin.amos.api.householdapi.face.service;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HYGFThirdStationLog;
public interface IHYGFThirdStationLogService {
void saveLog(HYGFThirdStationLog hygfThirdStationLog);
}
package com.yeejoin.amos.api.householdapi.face.service.impl;
import cn.hutool.core.lang.UUID;
import com.baomidou.mybatisplus.core.toolkit.Sequence;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HYGFThirdStationLog;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HYGFThirdStationLogMapper;
import com.yeejoin.amos.api.householdapi.face.service.IHYGFThirdStationLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
@Service
@Slf4j
public class HYGFThirdStationLogServiceImpl implements IHYGFThirdStationLogService {
private final String TABLE_NAME = "hygf_third_station_log";
@Autowired
private HYGFThirdStationLogMapper hygfThirdStationLogMapper;
@Value("${hygf.third.station.log.reserve.day:7}")
private Integer reserveDay;
@Override
public void saveLog(HYGFThirdStationLog hygfThirdStationLog) {
try {
// 获取今天的表名
String tableName = TABLE_NAME + "_" + getCurrentDate();
// 校验并创建新表
checkAndCreateNewTable(tableName);
//插入数据
insertLogData(tableName,hygfThirdStationLog);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
private void insertLogData(String tableName,HYGFThirdStationLog hygfThirdStationLog) {
if (Objects.nonNull(hygfThirdStationLog)) {
hygfThirdStationLog.setId(UUID.randomUUID().toString());
hygfThirdStationLog.setReqTime(new Date());
hygfThirdStationLogMapper.insertData(tableName, hygfThirdStationLog);
}
}
private void checkAndCreateNewTable(String tableName) {
// 查询当前表的数量
Integer countTable = hygfThirdStationLogMapper.countTable(TABLE_NAME);
// 如果表超过7个,删除最旧的表
if (countTable >= reserveDay) {
String oldestTableName = hygfThirdStationLogMapper.getOldestTableName(TABLE_NAME);
hygfThirdStationLogMapper.dropTable(oldestTableName);
}
// 创建新表
hygfThirdStationLogMapper.createTable(tableName);
}
// 获取当前日期(格式为 yyyyMMdd)
private String getCurrentDate() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
return sdf.format(new Date());
}
}
......@@ -65,18 +65,19 @@ biz.lxyd.lift.url=http://39.106.181.149:8088/elevatorapi
# ??????????
dataRequstScheduled.jinlangyun=0 0/50 * * * *
dataRequstScheduled.huawei=0 0/50 * * * *
dataRequstScheduled.keshida=0 0/50 * * * *
dataRequstScheduled.jinlangyun=0 0/40 * * * *
dataRequstScheduled.huawei=0 0/40 * * * *
dataRequstScheduled.keshida=0 0/40 * * * *
dataRequstScheduled.Sunlight=0 0/50 * * * *
dataRequstScheduled.GoodWe=0 0/50 * * * *
dataRequstScheduled.Sunlight=0 0/40 * * * *
dataRequstScheduled.GoodWe=0 0/40 * * * *
dataRequstScheduled.Sofar=0 0/50 * * * *
dataRequstScheduled.Sofar=0 0/40 * * * *
# 碳银
tanYin.api.apiUrl=https://userauth.tanwin.cn
tanYin.api.clientSecret=rKrWVa2sXsSZeNAOW43v
tanYin.api.clientKey=yx10001
dataRequestScheduled.tanYin=0 0/50 * * * *
dataRequestScheduled.tanYin.warn=0 0/50 * * * *
\ No newline at end of file
dataRequestScheduled.tanYin=0 0/40 * * * *
dataRequestScheduled.tanYin.warn=0 0/40 * * * *
hygf.third.station.log.reserve.day=3
\ No newline at end of file
......@@ -499,7 +499,8 @@ public class WorkOrderServiceImpl extends BaseService<WorkOrderDto, WorkOrder, W
query.last("limit 1");
HygfWorkOrderStationAuditing hygfWorkOrderStationAuditing = hygfWorkOrderStationAuditingService.getBaseMapper().selectOne(query);
if (!taskKey.contains(hygfWorkOrderStationAuditing.getNextNodeKey())){
throw new BadRequest("无可执行任务");
// throw new BadRequest("无可执行任务");
return;
}
//组装信息
TaskResultDTO task = new TaskResultDTO();
......
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