guoshilong
2023-11-29 1d46a2bc8a1b843eb2ee84e65fdc2f61651a18a3
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
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.TbWordVO;
import cn.gistack.sm.sjztods.constant.ZtApiUrlConstant;
import cn.gistack.sm.sjztods.constant.ZtConfigConstant;
import com.alibaba.fastjson.JSON;
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 {
    @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;
    }
 
    /**
     * 调用接口获取中台数据
     */
    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 + params,
                    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;
    }
 
 
}