guoshilong
2023-12-04 a8385a2b16593c8c6db45c2f45f88f04b099fddd
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package cn.gistack.sm.sjztmd.word.service.impl;
 
import cn.gistack.common.utils.SpringContextUtil;
import cn.gistack.sm.sjztmd.entity.*;
import cn.gistack.sm.sjztmd.mapper.SjztMdMapper;
import cn.gistack.sm.sjztmd.service.*;
import cn.gistack.sm.sjztmd.word.service.ISjztmdService;
import cn.gistack.sm.sjztmd.word.vo.*;
import cn.gistack.sm.sjztods.constant.ZtApiUrlConstant;
import cn.gistack.sm.sjztods.constant.ZtConfigConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
@AllArgsConstructor
@DS("zt")
public class SjztmdServiceImpl implements ISjztmdService {
 
    //总计
    private final String RIBAO_SHEET1_TOTAL_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao_sheet1/api?small_start_stag=0&small_end_stag=2&mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2";
    //中大型水库
    private final String RIBAO_SHEET2_ZDX_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao/sheet2_zdx/api?mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2";
    //超汛明细
    private final String RIBAO_SHEET3_OVER_STAG_LIST_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao/sheet3_over_stag_list/api?small_start_stag=0&small_end_stag=2&mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2";
    //省直管
    private final String SZ_INFO = "/services/1234567890ABCDEFGHIJKLMN/ribao/shengzh_new_rz/api";
 
    @Autowired
    private RestTemplate restTemplate;
    private final SjztMdMapper mapper;
 
    private final ITbAttResBaseService attResBaseService;
    private final ITbAttResStagCharService attResStagCharService;
    private final ITbAttResWaterDeliveryService attResWaterDeliveryService;
    private final ITbAttResEngBeneService attResEngBeneService;
    private final ITbAttResSafetyMonitorService attResSafetyMonitorService;
    private final ITbAttResMgrSysBService attResMgrSysBService;
    private final IAttResManagePersonService attResManagePersonService;
    private final ITbAttResWaterBlockService attResWaterBlockService;
    private final ITbAttResRsbNorspiService attResRsbNorspiService;
    private final ITbAttResPowerStationService attResPowerStationService;
 
    @Override
    public TbWordVO getTbWordVO(String resCd) {
 
 
        TbAttResBase tbAttResBase = attResBaseService.getDetailByGuid(resCd);
        TbAttResStagChar tbAttResStagChar = attResStagCharService.getDetailByGuid(resCd);
        List<TbAttResWaterDelivery> tbAttResWaterDeliveryList = attResWaterDeliveryService.getDetailByGuid(resCd);
        //挡水建筑物
        List<TbAttResWaterBlock> tbAttResWaterBlockList  = attResWaterBlockService.getDetailByGuid(resCd);
 
        //正常溢洪道、泄洪洞、非常溢洪道
        Map<String, Object> resRsbNorsipiVerspiMionitorDetailByGuid  = attResRsbNorspiService.getResRsbNorsipiVerspiMionitorDetailByGuid(resCd);
 
        //电站
        List<TbAttResPowerStation> tbAttResPowerStationList = attResPowerStationService.getDetailByGuid(resCd);
 
        TbAttResEngBene tbAttResEngBene = attResEngBeneService.getDetailByGuid(resCd);
        TbAttResSafetyMonitor tbAttResSafetyMonitor = attResSafetyMonitorService.getDetailByGuid(resCd);
        TbAttResMgrSysB tbAttResMgrSysB = attResMgrSysBService.getDetailByGuid(resCd);
        List<AttResManagePerson> attResManagePeople = attResManagePersonService.getPersonList(resCd);
 
        String depart = attResManagePersonService.getCompetentDepart(resCd);
 
        TbWordVO tbWordVO = new TbWordVO(tbAttResBase, tbAttResStagChar, tbAttResWaterBlockList,resRsbNorsipiVerspiMionitorDetailByGuid,tbAttResPowerStationList,
            tbAttResWaterDeliveryList, tbAttResEngBene,tbAttResSafetyMonitor,tbAttResMgrSysB,attResManagePeople);
        tbWordVO.setCUnitName(depart);
 
        return tbWordVO;
    }
 
 
 
 
 
    @Override
    public  List<TotalInfo> getTotalInfo(){
        JSONObject ztData = this.getZtData(null, RIBAO_SHEET1_TOTAL_URL);
        JSONArray data = ztData.getJSONArray("data");
        List<TotalInfo> list = data.toJavaList(TotalInfo.class);
        return list;
    }
 
    @Override
    public List<DzkInfo> getDzkInfo() {
        JSONObject ztData = this.getZtData(null, RIBAO_SHEET2_ZDX_URL);
        JSONArray data = ztData.getJSONArray("data");
        List<DzkInfo> list = data.toJavaList(DzkInfo.class);
        return list;
    }
 
    @Override
    public List<OverDetail> getOverDetailInfo() {
        JSONObject ztData = this.getZtData(null, RIBAO_SHEET3_OVER_STAG_LIST_URL);
        JSONArray data = ztData.getJSONArray("data");
        List<OverDetail> list = data.toJavaList(OverDetail.class);
        return list;
    }
 
    @Override
    public List<SzInfo> getSzInfo() {
        JSONObject ztData = this.getZtData(null, SZ_INFO);
        JSONArray data = ztData.getJSONArray("data");
        List<SzInfo> list = data.toJavaList(SzInfo.class);
        return list;
    }
 
    /**
     * 调用接口获取中台数据
     */
    public JSONObject getZtData(String params, String url){
        // 获取环境
        String activeProfile = SpringContextUtil.getActiveProfile();
        if (activeProfile.equals("dev")){
            url = ZtApiUrlConstant.url_prefix_dev + url;
        }
        if (activeProfile.equals("prod")){
            url = ZtApiUrlConstant.url_prefix_prod + url;
        }
        if (activeProfile.equals("test")){
            url = ZtApiUrlConstant.url_prefix_test + url;
        }
        //设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.add(ZtConfigConstant.header_key, ZtConfigConstant.header_value);
        //封装请求头
        HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
        try {
            //有请求头,有参数请求
            ResponseEntity<String> responseEntity =
                restTemplate.exchange(url,
                    HttpMethod.GET,
                    formEntity,
                    String.class);
            // Feature.IgnoreNotMatch 保留null值的属性
            JSONObject jsonObject = JSON.parseObject(responseEntity.getBody(), Feature.IgnoreNotMatch);
            // 返回
            return jsonObject;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
 
}