czt
2025-06-11 283da741b2429cf5a53786e5ee1b5528b757fdf6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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 "魔墙数据接口服务异常!";
        }
    }
}