package com.fzzy.igds.dzhwk.v1;
|
|
import com.alibaba.fastjson.JSON;
|
import com.fzzy.igds.dzhwk.domain.DicSysConf;
|
import com.fzzy.igds.dzhwk.v1.dto.ApiV1ReqDto;
|
import com.fzzy.igds.dzhwk.v1.dto.ApiV1RespDto;
|
import com.fzzy.igds.dzhwk.v1.util.ApiV1Utils;
|
import com.fzzy.igds.sys.SysConfService;
|
import com.fzzy.igds.util.ContextUtil;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.http.HttpUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.springframework.stereotype.Component;
|
import javax.annotation.Resource;
|
import java.util.Date;
|
|
/**
|
* @Description 魔墙数据接口服务
|
* @Author CZT
|
* @Date 2025/6/04 16:10
|
*/
|
@Slf4j
|
@Component
|
public class ApiV1Server {
|
|
@Resource
|
private SysConfService confService;
|
@Resource
|
private ApiV1Manager apiManager;
|
|
/**
|
* 拉取数据
|
* @param interfaceId 接口编码
|
* @param startTime 起始时间
|
* @param endTime 截止时间
|
* @return
|
*/
|
public String pullData(String interfaceId, Date startTime, Date endTime) {
|
|
if (StringUtils.isEmpty(interfaceId)) {
|
log.error("接口编码为空,接口编码={}", interfaceId);
|
return "接口编码为空!";
|
}
|
if (null == startTime || null == endTime) {
|
log.error("请求时间段为空,startTime={}, endTime={}", startTime, endTime);
|
return "请求时间段为空!";
|
}
|
DicSysConf sysConf = confService.getCacheSysConf(ContextUtil.getDefaultCompanyId());
|
if (null == sysConf) {
|
log.error("未配置系统配置信息");
|
return "未配置系统配置信息!";
|
}
|
if (StringUtils.isEmpty(sysConf.getHwkApiPath())) {
|
log.error("未配置接口请求地址,请求地址={}", sysConf.getHwkApiPath());
|
return "未配置接口请求地址!";
|
}
|
|
//组装请求数据
|
ApiV1ReqDto reqDto = new ApiV1ReqDto();
|
reqDto.setInterfaceId(interfaceId);
|
reqDto.setDeptId("");
|
reqDto.setDeptId("");
|
reqDto.setReqDate(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
reqDto.setStartTime(DateFormatUtils.format(startTime, "yyyy-MM-dd HH:mm:ss"));
|
reqDto.setEndTime(DateFormatUtils.format(endTime, "yyyy-MM-dd HH:mm:ss"));
|
String jsonString = JSON.toJSONString(reqDto);
|
|
//POST请求获取数据
|
String result = HttpUtils.sendPost(sysConf.getHwkApiPath(), jsonString);
|
|
log.info("请求接口,返回数据={}", result);
|
if(StringUtils.isEmpty(result)){
|
log.error("请求接口失败,返回数据={}", result);
|
return "请求接口失败!";
|
}
|
//解析返回数据
|
ApiV1RespDto respDto = JSON.parseObject(result, ApiV1RespDto.class);
|
if (null == respDto) {
|
log.error("请求接口失败,返回数据={}", respDto);
|
return "请求接口失败!";
|
}
|
if(!"200".equals(respDto.getCode())){
|
log.error("请求接口失败,返回数据={}", respDto.getMsg());
|
return respDto.getMsg();
|
}
|
//解密报文
|
String dataStr = ApiV1Utils.decrypt(respDto.getData(), null);
|
log.info("请求接口,返回数据,解密后={}", dataStr);
|
if (dataStr == null) {
|
log.error("解密后数据为空,解密数据={}", dataStr);
|
return "解密后数据为空!";
|
}
|
try {
|
//异步解析数据
|
apiManager.analysis(interfaceId, dataStr, reqDto);
|
return null;
|
} catch (Exception e) {
|
log.error("魔墙数据接口服务异常", e);
|
return "魔墙数据接口服务异常!";
|
}
|
}
|
}
|