|
@@ -0,0 +1,89 @@
|
|
|
+package com.ruoyi.common.utils.http;
|
|
|
+
|
|
|
+import com.ruoyi.common.config.bpm.BpmProperties;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+@Component
|
|
|
+public class Sending<T> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BpmProperties bpmProperties;
|
|
|
+
|
|
|
+ // 创建RestTemplate实例
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * get请求拼接参数使用
|
|
|
+ *
|
|
|
+ * @param url
|
|
|
+ * @param params
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String appendParamsToUrl(String url, Map<String, Object> params) {
|
|
|
+ if (params != null && !params.isEmpty()) {
|
|
|
+ StringBuilder urlBuilder = new StringBuilder(url);
|
|
|
+ urlBuilder.append("?");
|
|
|
+ for (Map.Entry<String, Object> entry : params.entrySet()) {
|
|
|
+ urlBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
|
|
+ }
|
|
|
+ url = urlBuilder.toString();
|
|
|
+ }
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public ResponseEntity<String> sendCommon(String url, String httpMethod, T param) {
|
|
|
+ // 得到当前用户的token 下发流程请求需要携带
|
|
|
+ String token = SecurityUtils.getLoginUser().getToken();
|
|
|
+ // 设置请求头
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.set("Authorization", "XIAFA" + token);
|
|
|
+ // 判断请求类型
|
|
|
+ if (HttpMethod.GET.name().equalsIgnoreCase(httpMethod)) {
|
|
|
+ // 如果是 GET 请求,将参数拼接到 URL 上
|
|
|
+ url = appendParamsToUrl(url, (Map<String, Object>) param);
|
|
|
+ }
|
|
|
+ // 将请求体和请求头添加到 HttpEntity
|
|
|
+ HttpEntity<Object> requestEntity = new HttpEntity<>(param, headers);
|
|
|
+ // 发送请求
|
|
|
+ ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.resolve(httpMethod), requestEntity, String.class);
|
|
|
+ // 返回响应
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行流程排产
|
|
|
+ */
|
|
|
+ public ResponseEntity sendCommonUpdate(T param) {
|
|
|
+ return this.sendCommon(bpmProperties.formCommonUpdateIp, "PUT", param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据脚本key得到所有异常脚本信息
|
|
|
+ */
|
|
|
+ public ResponseEntity sendGetScriptInfo(T param) {
|
|
|
+ return this.sendCommon(bpmProperties.getNodeScriptsIp, "POST", param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 共通获取详情接口
|
|
|
+ */
|
|
|
+ public ResponseEntity sendCommonGetInfo(T param) {
|
|
|
+ return this.sendCommon(bpmProperties.formCommonGetInfoIp, "GET", param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过字段类型得到当前租户字典的所有值
|
|
|
+ */
|
|
|
+ public ResponseEntity sendGetTenantDict(T param) {
|
|
|
+ return this.sendCommon(bpmProperties.getTenantDictValIp, "GET", param);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|