|  |  |  | 
|---|
|  |  |  | import com.dy.common.multiDataSource.DataSourceContext; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.Command; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.CommandType; | 
|---|
|  |  |  | import com.dy.common.softUpgrade.state.UpgradeTaskVo; | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponse; | 
|---|
|  |  |  | import org.springframework.core.env.Environment; | 
|---|
|  |  |  | import org.springframework.http.HttpEntity; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private static final String pro_mw = "mw"; | 
|---|
|  |  |  | private static final String key_mw = "comSendUrl"; | 
|---|
|  |  |  | private static final String keyUg_mw = "ugTaskSendUrl"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | protected String getToMwUrl(Environment env) { | 
|---|
|  |  |  | return env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + key_mw); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到向通信中间件发送数据的URL | 
|---|
|  |  |  | * @param env | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | protected String getToMwUgUrl(Environment env) { | 
|---|
|  |  |  | return env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + keyUg_mw); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return response.getBody(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 向通信中间件发送rtu远程升级任务 | 
|---|
|  |  |  | * @param restTemplate | 
|---|
|  |  |  | * @param comSendUrl | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | protected BaseResponse sendUpgradeTask2Mw(RestTemplate restTemplate, String comSendUrl, UpgradeTaskVo vo) { | 
|---|
|  |  |  | String url = UriComponentsBuilder.fromUriString(comSendUrl) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .toUriString(); | 
|---|
|  |  |  | HttpHeaders headers = new HttpHeaders(); | 
|---|
|  |  |  | HttpEntity<UpgradeTaskVo> httpEntity = new HttpEntity<>(vo, headers); | 
|---|
|  |  |  | ResponseEntity<BaseResponse> response = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | // 通过Post方式调用接口 | 
|---|
|  |  |  | response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, BaseResponse.class); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return response.getBody(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|