| | |
| | | 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.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; |
| | |
| | | @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; |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @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; |
| | | } |
| | | |
| | | |
| | | } |