| | |
| | | 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; |
| | |
| | | @AllArgsConstructor |
| | | @DS("zt") |
| | | public class SjztmdServiceImpl implements ISjztmdService { |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | private final SjztMdMapper mapper; |
| | | |
| | | private final ITbAttResBaseService attResBaseService; |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |