提交 09dd9329 编写于 作者: Crimson's avatar Crimson

clear & usr代码添加回调rest信息

上级 75af4799
package com.ibiz.web.ht.service;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ibiz.web.ps.domain.PS;
import com.ibiz.web.ps.service.PSService;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Service;
import feign.Client;
......@@ -34,6 +45,9 @@ import com.ibiz.util.config.UniWFClientProperties;
import com.ibiz.util.feign.UniWFFeignClient;
import com.ibiz.util.config.SysInfoProperties;
import com.ibiz.util.domain.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
@Service
public class IMService {
......@@ -196,8 +210,7 @@ public class IMService {
}
PSDEWF psdewf = psdewfs.getContent().get(0);
// PS
PS ps = new PS();
// 业务状态
String status = null;
......@@ -223,16 +236,84 @@ public class IMService {
// 保存业务数据
this.update(im_id, im);
if ("finish".equals(type)) {
// FOR TEST ADD gotostep
if ("finish".equals(type) || "gotostep".equals(type)) {
// PS
PS ps = new PS();
ps.setPSId(im.getIMId());
ps = psService.get(ps.getPSId());
if (ps != null) {
ps.setImstate("30");
psService.update(ps.getPSId(), ps);
// psService.update(ps.getPSId(), ps);
}
if (data.getString("callbackdata") != null) {
JSONArray callbackdata = JSONObject.parseArray(data.getString("callbackdata"));
if (callbackdata.size() > 0) {
for (int i =0; i < callbackdata.size(); i++) {
JSONObject jo = callbackdata.getJSONObject(i);
HttpMethod httpMethod = HttpMethod.valueOf(jo.getString("method"));
String url = jo.getString("url");
JSONObject params = null;
if (jo.getBoolean("containspk")) {
String replaceStr = url.substring(url.indexOf("{"), url.indexOf("}") + 1);
replaceStr = "\\" + replaceStr;
replaceStr = replaceStr.substring(0, replaceStr.length() - 1) + "\\}";
url = url.replaceAll(replaceStr, im.getIMId());
}
if (jo.getBoolean("containset")) {
params = (JSONObject) JSONObject.toJSON(ps);
}
doRestRequest(url, httpMethod, getHeader(), params);
}
}
}
}
data.put("rst", "1");
return data;
}
public JSONObject getHeader(){
JSONObject header = new JSONObject();
header.put("Content-Type","application/json");
// String token= null;
// try {
// Base64 base64 = new Base64();
// token = base64.encodeToString((username+":"+password).getBytes("UTF-8"));
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// header.put("Authorization","Basic "+ token);
return header;
}
private String doRestRequest(String url, HttpMethod method, JSONObject headerMap, JSONObject paramMap){
RestTemplate restTemplate = getRestTemplate();
HttpHeaders headers = new HttpHeaders();
if(headerMap!=null){
for(String key : headerMap.keySet()){
headers.add(key,headerMap.getString(key));
}
}
MultiValueMap<String,String> params = new LinkedMultiValueMap<String,String>();
HttpEntity<String> entity;
if(paramMap!=null){
entity = new HttpEntity<>(paramMap.toString(), headers);
}else{
entity = new HttpEntity<>(null, headers);
}
ResponseEntity<String> responseEntity = restTemplate.exchange(url, method, entity, String.class);
return responseEntity.getBody();
}
private RestTemplate getRestTemplate(){
RestTemplate restTemplate = new RestTemplate();
for (HttpMessageConverter<?> httpMessageConverter : restTemplate.getMessageConverters()) {
if (httpMessageConverter instanceof StringHttpMessageConverter) {
((StringHttpMessageConverter) httpMessageConverter).setDefaultCharset(Charset.forName("UTF-8"));
break;
}
}
return restTemplate;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册