Commit 69c70f23 authored by 刘凡's avatar 刘凡

*)新增二级详情接口

parent 40f305da
......@@ -34,6 +34,11 @@
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-redis-spring</artifactId>
</dependency>
<dependency>
<groupId>com.yeejoin</groupId>
<artifactId>visual-feign-morphic</artifactId>
<version>1.9.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
......
package com.yeejoin.amos.boot.module.jyjc.biz.config;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
/**
* @Author: xl
* @Description:
* @Date: 2022/9/21 18:04
*/
@Configuration
public class RestTemplateConfig {
@Bean
@LoadBalanced
public RestTemplate getRestTemplate() {
return new RestTemplate();
}
}
\ No newline at end of file
package com.yeejoin.amos.boot.module.jyjc.biz.controller;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.DPSubServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.Map;
/**
* 大屏统计controller
*
* @author Administrator
*/
@RestController
@RequestMapping("/dp/sub")
@Api(tags = "大屏二级弹窗")
public class DPSubController {
private DPSubServiceImpl subService;
public DPSubController(DPSubServiceImpl subService) {
this.subService = subService;
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "POST", value = "动态详情页", notes = "动态详情页")
@PostMapping(value = "/{template}")
public ResponseModel<JSONObject> commonQuery(@PathVariable String template, @RequestBody Map<String, Object> param) {
if (template.equals("company")){
Assert.notNull(param.get("useUnitCode"), "企业统一信用代码不能为空");
} else if (template.equals("equip")){
param.put("record", param.get("SEQUENCE_NBR"));
param.put("equList", param.get("EQU_LIST_CODE"));
Assert.notNull(param.get("record"), "设备ID不能为空");
Assert.notNull(param.get("equList"), "设备种类不能为空");
template = template + "_" + param.get("equList");
} else {
throw new RuntimeException("暂无模板");
}
return ResponseHelper.buildResponse(subService.commonQuery(template, param));
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jyjc.biz.util.DpSubUtils;
import com.yeejoin.amos.boot.module.jyjc.biz.util.JsonValueUtils;
import com.yeejoin.amos.boot.module.jyjc.biz.util.RestTemplateUtils;
import com.yeejoin.amos.boot.module.jyjc.biz.util.StringUtils;
import com.yeejoin.amos.feign.morphic.Morphic;
import com.yeejoin.amos.feign.morphic.model.FormSceneModel;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.client.RestTemplate;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.net.URI;
import java.util.*;
import java.util.stream.Collectors;
/**
* 大屏二级页面实现类
*
* @author Administrator
*/
@Slf4j
@Service
public class DPSubServiceImpl {
private static final String GATEWAY_SERVER_NAME = "AMOS-SERVER-GATEWAY";
@Autowired
@LoadBalanced
private RestTemplate restTemplate;
public JSONObject commonQuery(String template, @RequestBody Map<String, Object> param){
JSONObject result = new JSONObject();
String templateJson = DpSubUtils.getFileContent(template + ".json");
//1、替换json中所有的变量
if (!ValidationUtil.isEmpty(param)) {
for (Map.Entry item:param.entrySet()) {
templateJson = templateJson.replaceAll("\\{" + item.getKey() + "\\}", item.getValue().toString());
}
}
//2、解析结构
result = JSON.parseObject(templateJson);
JSONArray tabs = result.getJSONArray("tabs");
JSONObject content = result.getJSONObject("content");
tabs.stream().forEach(x -> {
this.buildContent(content, (JSONObject) x);
});
return result;
}
public void buildContent(JSONObject content, JSONObject tab){
Long formSeq = tab.getLong("formSeq");
Object resultConvert = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.resultConvert");
Object api = JsonValueUtils.getValueByKey(tab, "dataConfig", "dataConfig.api");
JSONObject map = content.getJSONObject(tab.getString("key"));
ResponseModel apiResult = null;
if (!ValidationUtil.isEmpty(api)){
apiResult = this.getApiResult((JSONObject) api, !ValidationUtil.isEmpty(resultConvert) ? resultConvert.toString() : null);
// log.info("查询结果:{}", apiResult);
}
if (!ValidationUtil.isEmpty(formSeq)){
FormSceneModel formPage = Morphic.formSceneClient.seleteOne(formSeq).getResult();
// 1、排除表单隐藏字段
JSONArray children = (JSONArray)JsonValueUtils.getValueByKey(JSONObject.parseObject(formPage.getContent()), "children", "children");
List<Object> noHiddenChildren = children.stream().filter(x -> !"hidden".equals(JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.behavior"))).collect(Collectors.toList());
ResponseModel finalApiResult = apiResult;
for (int i = 0; i < noHiddenChildren.size(); i++) {
JSONObject yObj = (JSONObject) noHiddenChildren.get(i);
if ("pageSection".equals(yObj.get("componentKey")) || "columnsLayout".equals(yObj.get("componentKey"))) { // 分组或者布局容器
List<Object> mergedArray = mergedList(yObj.getJSONArray("children"));
// 第一组去除标题
if (i == 0){
this.buildContentData(map, mergedArray, finalApiResult);
} else {
this.buildSubContentData(map, i, yObj, mergedArray, finalApiResult);
}
} else if("subForm".equals(yObj.get("componentKey"))) { // 子表单
} else if("formTable".equals(yObj.get("componentKey"))){
map = new JSONObject();
map.put("columns", JsonValueUtils.getValueByKey(yObj, "visualParams", "visualParams.modelTableColumns"));
map.put("dataList", apiResult.getResult());
content.put(tab.getString("key"), map);
}
}
} else {
if (ValidationUtil.isEmpty(map)){
content.put(tab.getString("key"), apiResult.getResult());
}
}
}
/**
* 合并分组组件下的所有组件
* @param children
* @return
*/
private List<Object> mergedList(JSONArray children){
JSONArray mergedArray = new JSONArray();
int maxSize = 0; // 初始化为JSONArray的长度
for (int i = 0; i < children.size(); i++) {
JSONArray cchildren = children.getJSONObject(i).getJSONArray("children");
if (!ValidationUtil.isEmpty(cchildren)){
maxSize = Math.max(maxSize, cchildren.size());
}
}
for (int i = 0; i < maxSize; i++) {
for (int j = 0; j < children.size(); j++) {
JSONArray cchildren = children.getJSONObject(j).getJSONArray("children");
if (!ValidationUtil.isEmpty(cchildren)){
List<Object> noHiddenMergedArray = cchildren.stream().filter(x -> {
JSONObject xObj = (JSONObject) x;
return !"hidden".equals(JsonValueUtils.getValueByKey(xObj, "visualParams", "visualParams.behavior"));
}).collect(Collectors.toList());
if (i < noHiddenMergedArray.size()) {
mergedArray.add(cchildren.get(i));
}
}
}
}
return mergedArray;
}
public JSONObject buildContentData(JSONObject map, List<Object> mergedArray, ResponseModel apiResult){
JSONObject result = new JSONObject();
if (!ValidationUtil.isEmpty(apiResult)){
result = JSONObject.parseObject(apiResult.getResult().toString());
}
JSONArray datas = new JSONArray();
JSONObject finalResult = result;
// 二维码
mergedArray.stream().filter(x -> "QRCode".equals(JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.componentKey"))).findFirst().ifPresent(x -> {
});
mergedArray = mergedArray.stream().filter(x -> !"QRCode".equals(JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.componentKey"))).collect(Collectors.toList());
mergedArray.stream().forEach(x -> {
JSONObject xObj = (JSONObject) x;
JSONObject visualParams = xObj.getJSONObject("visualParams");
String fieldKey = visualParams.getString("fieldKey");
if (!ValidationUtil.isEmpty(fieldKey)){
JSONObject jsonObject = new JSONObject();
jsonObject.put("label", visualParams.getString("label"));
Object value = finalResult.get(fieldKey);
if ("upload".equals(xObj.getString("componentKey"))){
jsonObject.put("type", "img");
if (!ValidationUtil.isEmpty(value)){
jsonObject.put("value", ((JSONArray)value).getJSONObject(0).getString("url"));
}
} else if("select".equals(xObj.getString("componentKey"))){
jsonObject.put("type", "text");
ResponseModel selectResult = this.getApiResult(visualParams.getJSONObject("api"), null);
if (!ValidationUtil.isEmpty(selectResult) && !ValidationUtil.isEmpty(value)){
((JSONArray)selectResult.getResult()).stream().filter(y -> value.equals(JsonValueUtils.getValueByKey(y, "valueKey", "valueKey"))).findFirst().ifPresent(z -> {
jsonObject.put("value", ((JSONObject)z).getString("nameKey"));
});
} else {
jsonObject.put("value", value);
}
} else {
jsonObject.put("type", "text");
jsonObject.put("value", value);
}
datas.add(jsonObject);
}
});
map.put("datas", datas);
return map;
}
public JSONObject buildSubContentData(JSONObject map, int i, JSONObject yObj, List<Object> mergedArray, ResponseModel apiResult){
JSONArray jsonArray = map.getJSONArray("subs");
JSONObject result = new JSONObject();
if (!ValidationUtil.isEmpty(apiResult)){
result = JSONObject.parseObject(apiResult.getResult().toString());
}
JSONArray children = yObj.getJSONArray("children");
List<Object> columnsArray = children.stream().filter(x -> {
JSONObject xObj = (JSONObject) x;
return !ValidationUtil.isEmpty(xObj.getJSONArray("children")) && xObj.getJSONArray("children").size() > 0;
}).collect(Collectors.toList());
JSONObject subObj = new JSONObject();
subObj.put("key", "key" + i);
subObj.put("displayName", JsonValueUtils.getValueByKey(yObj, "visualParams", "visualParams.title"));
subObj.put("renderType", "basic");
subObj.put("columns", columnsArray.size());
JSONArray datas = new JSONArray();
JSONObject finalResult = result;
mergedArray.stream().forEach(x -> {
JSONObject xObj = (JSONObject) x;
JSONObject visualParams = xObj.getJSONObject("visualParams");
String fieldKey = visualParams.getString("fieldKey");
if (!ValidationUtil.isEmpty(fieldKey)){
JSONObject jsonObject = new JSONObject();
jsonObject.put("label", visualParams.getString("label"));
Object value = finalResult.get(fieldKey);
if ("upload".equals(xObj.getString("componentKey"))){
jsonObject.put("type", "img");
if (!ValidationUtil.isEmpty(value)){
jsonObject.put("value", ((JSONArray)value).getJSONObject(0).getString("url"));
}
} else if("select".equals(xObj.getString("componentKey"))){
jsonObject.put("type", "text");
ResponseModel selectResult = this.getApiResult(visualParams.getJSONObject("api"), null);
if (!ValidationUtil.isEmpty(selectResult) && selectResult.getStatus() == 200 && !ValidationUtil.isEmpty(value)){
((JSONArray)selectResult.getResult()).stream().filter(y -> value.equals(JsonValueUtils.getValueByKey(y, "valueKey", "valueKey"))).findFirst().ifPresent(z -> {
jsonObject.put("value", ((JSONObject)z).getString("nameKey"));
});
} else {
jsonObject.put("value", value);
}
} else {
jsonObject.put("type", "text");
jsonObject.put("value", value);
}
datas.add(jsonObject);
subObj.put("datas", datas);
}
});
jsonArray.add(subObj);
return map;
}
public ResponseModel getApiResult(JSONObject apiObj, String resultConvert) {
String url = apiObj.getString("apiPath");
String reqType = !ValidationUtil.isEmpty(apiObj.getString("httpMethod")) ? apiObj.getString("httpMethod") : "GET";
Object params = apiObj.get("params");
Object body = apiObj.get("body");
ResponseEntity<String> responseEntity = null;
//如果url以/开头,则调用本服务内接口
if (url != null && url.trim().startsWith("/")) {
url = "http://" + GATEWAY_SERVER_NAME + url;
}
if (url != null && url.trim().startsWith("http")) {
String reqUrl = buildUrl(url, params);
HttpHeaders httpHeaders = this.builderHeaders();
log.info("调用第三方接口: {}, httpheaders: {}", reqUrl, httpHeaders);
try {
URI reqUri = new URI(reqUrl);
if (StringUtils.contrastLowerStr("GET", reqType)) {
responseEntity = reqUrl.contains(GATEWAY_SERVER_NAME)
? RestTemplateUtils.get(restTemplate, reqUri, httpHeaders, body, String.class, new HashMap<>())
: RestTemplateUtils.get(reqUri, httpHeaders, body, String.class, new HashMap<>());
} else if (StringUtils.contrastLowerStr("POST", reqType)) {
responseEntity = reqUrl.contains(GATEWAY_SERVER_NAME)
? RestTemplateUtils.post(restTemplate, reqUri, httpHeaders, body, String.class, new HashMap<>())
: RestTemplateUtils.post(reqUri, httpHeaders, body, String.class, new HashMap<>());
} else if (StringUtils.contrastLowerStr("PUT", reqType)) {
responseEntity = reqUrl.contains(GATEWAY_SERVER_NAME)
? RestTemplateUtils.put(restTemplate, reqUri, httpHeaders, body, String.class)
: RestTemplateUtils.put(reqUri, httpHeaders, body, String.class);
} else if (StringUtils.contrastLowerStr("DELETE", reqType)) {
responseEntity = reqUrl.contains(GATEWAY_SERVER_NAME)
? RestTemplateUtils.delete(restTemplate, reqUri, httpHeaders, body, String.class)
: RestTemplateUtils.delete(reqUri, httpHeaders, body, String.class);
}
} catch (Exception e) {
log.info("调用第三方接口失败, 请求头参数:{}", httpHeaders);
e.printStackTrace();
throw new RuntimeException(String.format("调用第三方接口失败, %s请求【%s】,失败原因:%s", reqType, reqUrl, e.getMessage()));
}
} else {
throw new IllegalArgumentException("仅支持以/或http开头的地址");
}
String response = responseEntity.getBody();
//结果转换(执行javaScript函数)
Object bizResult = convertResult(JSONObject.parseObject(response), resultConvert);
ResponseModel responseModel = JSONObject.parseObject(response, ResponseModel.class);
JSONObject ruleData = apiObj.getJSONObject("ruleData");
if (!ValidationUtil.isEmpty(ruleData)) {
String responseSuccess = ruleData.getString("responseSuccess").replace("data", "");
Object result = JsonValueUtils.getValueByKey(bizResult, "result", responseSuccess);
boolean isRefactor = false; // 是否需要重构返回字段
if (result instanceof JSONObject) {
Map<String, Object> resultMap = (Map) result;
for (String key : ruleData.keySet()) {
if (!(key.equals("responseExpression") || key.equals("responseSuccess") || key.equals("responseError"))) {
isRefactor = true;
resultMap.put(key, resultMap.get(ruleData.get(key)));
}
}
result = isRefactor ? resultMap : result;
} else if (result instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) result;
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
for (String key : ruleData.keySet()) {
if (!(key.equals("responseExpression") || key.equals("responseSuccess") || key.equals("responseError"))) {
isRefactor = true;
obj.put(key, obj.get(ruleData.get(key)));
}
}
}
result = isRefactor ? jsonArray : result;
}
responseModel.setResult(result);
}
return responseModel;
}
private String buildUrl(String url, Object params) {
if (!url.contains("?") && !ValidationUtil.isEmpty(params)) {
url += "?";
}
if (params instanceof Map) {
url = url + StringUtils.transMap2UrlParam((Map) params);
} else if (params instanceof List) {
url = url + StringUtils.transList2UrlParam((List) params);
}
return url.replace("?&", "?");
}
private HttpHeaders builderHeaders(){
HttpHeaders httpheaders = new HttpHeaders();
httpheaders.add("appKey", RequestContext.getAppKey());
httpheaders.add("product", RequestContext.getProduct());
httpheaders.add("token", RequestContext.getToken());
httpheaders.setContentType(MediaType.APPLICATION_JSON);
return httpheaders;
}
/**
* ScriptObjectMirror 转 JavaObject
*
* @param scriptObj
* @return
*/
private static Object convertIntoJavaObject(Object scriptObj) {
if (scriptObj instanceof ScriptObjectMirror) {
ScriptObjectMirror scriptObjectMirror = (ScriptObjectMirror) scriptObj;
if (scriptObjectMirror.isFunction()) {
return scriptObjectMirror.toString();
} else if (scriptObjectMirror.isArray()) {
return new JSONArray(scriptObjectMirror.values().stream().map(e -> convertIntoJavaObject(e)).collect(Collectors.toList()));
} else {
return new JSONObject(scriptObjectMirror.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> convertIntoJavaObject(e.getValue()))));
}
} else {
return scriptObj;
}
}
/**
* 结果转换(执行javaScript函数)
*
* @param bizResult 原始请求结果
* @param resultConvert js转换脚本
* @return 转换后的结果
*/
private Object convertResult(Object bizResult, String resultConvert) {
if (!ValidationUtil.isEmpty(resultConvert)) {
//获取javaScript执行引擎
ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
//获取js函数执行体并拼接函数名
String jsFun = "function resultConvert(data){" + resultConvert + "}";
//向js函数传入参数
engine.put("data", bizResult);
try {
engine.eval(jsFun);
if (engine instanceof Invocable) {
Invocable invoke = (Invocable) engine;
//执行js函数,获取返回值
bizResult = invoke.invokeFunction("resultConvert", bizResult);
}
} catch (Exception e) {
log.info("js表达式runtime错误:{}", e.getMessage());
throw new RuntimeException(String.format("结果转换错误【%s】", e.getMessage()));
}
//ScriptObjectMirror 转 JavaObject
bizResult = convertIntoJavaObject(bizResult);
}
return bizResult;
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.util;
import org.springframework.core.io.ClassPathResource;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class DpSubUtils {
public static String companyJson = null;
public static String textJson = null;
public static String imageJson = null;
public static String circleJson = null;
public static String rectJson = null;
static {
// companyJson = getFileContent("company.json");
// textJson = getFileContent("text.json");
// imageJson = getFileContent("image.json");
// circleJson = getFileContent("circle.json");
// rectJson = getFileContent("rect.json");
}
public static String getFileContent(String filename){
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new ClassPathResource("json/"+filename).getInputStream()));
StringBuffer sb = new StringBuffer();
String line = null;
while((line = br.readLine())!=null){
if(line.trim().length()>0)
sb.append(line);
}
br.close();
return sb.toString();
} catch (Exception e) {
throw new RuntimeException(e);
// return null;
}
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
/**
* @Author: xl
* @Description: json快速取值
* @Date: 2022/5/12 11:11
*/
public class JsonValueUtils {
public static Object getValueByKey(Object originObject, String startKey,
String targetKey) {
if (Strings.isNullOrEmpty(startKey)) {
return originObject;
}
if (originObject instanceof JSONObject) {
return getValueFromJSONObjectByKey((JSONObject) originObject, startKey,
targetKey);
}
if (originObject instanceof JSONArray) {
return getValueFromJSONArrayByKey((JSONArray) originObject, startKey,
targetKey);
}
return null;
}
private static String getNextKey(String startKey, String targetKey) {
if (Strings.isNullOrEmpty(targetKey)) {
return null;
}
String[] keys = targetKey.split("\\.");
for (int i = 0; i < keys.length; i++) {
if (keys[i].equals(startKey) && (i < keys.length - 1)) {
return keys[i + 1];
}
}
return null;
}
private static Object getValueFromJSONArrayByKey(JSONArray originObject,
String startKey,
String targetKey) {
try {
Integer integer = Integer.valueOf(startKey);
JSONObject jsonObject = originObject.getJSONObject(integer);
Object targetObject = getValueFromJSONObjectByKey(jsonObject, getNextKey(startKey, targetKey),
targetKey);
if (targetObject != null) {
return targetObject;
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
return null;
}
private static Object getValueFromJSONObjectByKey(JSONObject originObject,
String startKey,
String targetKey) {
Object object = originObject.get(startKey);
return object != null
? getValueByKey(object, getNextKey(startKey, targetKey),
targetKey)
: null;
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.util;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.net.URI;
import java.util.Map;
/**
* @Author: xl
* @Description: 远程调用工具类
* @Date: 2021/10/8 13:46
*/
public class RestTemplateUtils {
private static class SingletonRestTemplate {
static final RestTemplate INSTANCE = new RestTemplate();
}
private RestTemplateUtils() {
}
public static RestTemplate getInstance() {
return SingletonRestTemplate.INSTANCE;
}
/**
* 带请求头的GET请求调用方式
*
* @param uri 请求URL
* @param headers 请求头参数
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> get(URI uri, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
HttpEntity<?> requestEntity = new HttpEntity<>(headers);
return RestTemplateUtils.getInstance().exchange(uri, HttpMethod.GET, requestEntity, responseType);
}
/**
* @param restTemplate 可传入负载均衡的restTemplate
* @param uri
* @param headers
* @param responseType
* @param uriVariables
* @param <T>
* @return
*/
public static <T> ResponseEntity<T> get(RestTemplate restTemplate, URI uri, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
HttpEntity<?> requestEntity = new HttpEntity<>(headers);
return restTemplate.exchange(uri, HttpMethod.GET, requestEntity, responseType);
}
/**
* 带请求头的POST请求调用方式
*
* @param uri 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> post(URI uri, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return RestTemplateUtils.getInstance().postForEntity(uri, requestEntity, responseType);
}
/**
* @param restTemplate 可传入负载均衡的restTemplate
* @param uri
* @param headers
* @param requestBody
* @param responseType
* @param uriVariables
* @param <T>
* @return
*/
public static <T> ResponseEntity<T> post(RestTemplate restTemplate, URI uri, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return restTemplate.postForEntity(uri, requestEntity, responseType);
}
/**
* 带请求头的PUT请求调用方式
*
* @param uri 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> put(URI uri, HttpHeaders headers, Object requestBody, Class<T> responseType) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return RestTemplateUtils.getInstance().exchange(uri, HttpMethod.PUT, requestEntity, responseType);
}
/**
* @param restTemplate 可传入负载均衡的restTemplate
* @param uri
* @param headers
* @param requestBody
* @param responseType
* @param <T>
* @return
*/
public static <T> ResponseEntity<T> put(RestTemplate restTemplate, URI uri, HttpHeaders headers, Object requestBody, Class<T> responseType) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return restTemplate.exchange(uri, HttpMethod.PUT, requestEntity, responseType);
}
/**
* 带请求头的DELETE请求调用方式
*
* @param uri 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(URI uri, HttpHeaders headers, Object requestBody, Class<T> responseType) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return RestTemplateUtils.getInstance().exchange(uri, HttpMethod.DELETE, requestEntity, responseType);
}
/**
* @param restTemplate 可传入负载均衡的restTemplate
* @param uri
* @param headers
* @param requestBody
* @param responseType
* @param <T>
* @return
*/
public static <T> ResponseEntity<T> delete(RestTemplate restTemplate, URI uri, HttpHeaders headers, Object requestBody, Class<T> responseType) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return restTemplate.exchange(uri, HttpMethod.DELETE, requestEntity, responseType);
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
/**
* @Author: xinglei
* @Description:
* @Date: 2020/8/24 9:58
*/
public class StringUtils {
public static boolean contrastLowerStr(String str1, String str2) {
boolean flag = false;
if (str1.toLowerCase().equals(str2.toLowerCase())) {
flag = true;
}
return flag;
}
/**
* 将map转换成url
*
* @param map
* @return
*/
public static String transMap2UrlParam(Map<String, Object> map) {
StringBuilder stringBuilder = new StringBuilder();
for (Map.Entry entry : map.entrySet()) {
// 值为空或匹配total不拼接
if (ValidationUtil.isEmpty(entry.getValue()) || "total".equals(entry.getKey()))
continue;
try {
stringBuilder.append("&").append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue().toString(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return stringBuilder.toString();
}
/**
* 将list转换成url
*
* @param list
* @return
*/
public static String transList2UrlParam(List<Map<String, Object>> list) {
StringBuilder stringBuilder = new StringBuilder();
list.forEach(x -> {
Map<String, Object> map = JSONObject.parseObject(JSON.toJSONString(x));
try {
stringBuilder.append("&").append(map.get("key")).append("=").append(URLEncoder.encode(map.get("value").toString(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
});
return stringBuilder.toString();
}
}
{
"name": "检验检测机构模板",
"tabs": [
{
"key": "basic",
"displayName": "基本信息",
"renderType": "basic",
"formSeq": "1793454184889085953",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/tcm/baseEnterprise/getInfoByUseCode",
"params": {
"useCode": "{useUnitCode}"
}
},
"resultConvert": ""
}
},
{
"key": "devtable",
"displayName": "设备列表",
"renderType": "table",
"formSeq": "1792821076963651585",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/equipment-register/page",
"params": {
"number": 1,
"size": 10,
"USE_UNIT_CREDIT_CODE": "{useUnitCode}"
}
}
}
}
],
"content": {
"basic": {
"columns": 2,
"datas": [],
"qrcode": {},
"subs": []
}
}
}
\ No newline at end of file
{
"name": "设备-锅炉",
"tabs": [
{
"key": "basic",
"displayName": "设备信息",
"renderType": "basic",
"formSeq": "1793458381554479105",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/equipment-register/{record}",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
}
},
{
"key": "reghistory",
"displayName": "监管履历信息",
"renderType": "timeline",
"formSeq": "",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/common/equOnJgServiceOperationRecords",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result",
"operater": "content"
}
}
}
},
{
"key": "devtable",
"displayName": "问题列表",
"renderType": "table",
"formSeq": "1793458819301404673",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/safety-problem-tracing/equipId/page",
"params": {
"number": 1,
"size": 10,
"record": "{record}"
}
}
}
}
],
"content": {
"basic": {
"columns": 3,
"datas": [],
"qrcode": {},
"subs": []
},
"dianti": {
"columns": 3,
"datas": []
}
}
}
\ No newline at end of file
{
"name": "设备-压力容器",
"tabs": [
{
"key": "basic",
"displayName": "设备信息",
"renderType": "basic",
"formSeq": "1793458381554479105",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/equipment-register/{record}",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
}
},
{
"key": "reghistory",
"displayName": "监管履历信息",
"renderType": "timeline",
"formSeq": "",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/common/equOnJgServiceOperationRecords",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result",
"operater": "content"
}
}
}
},
{
"key": "devtable",
"displayName": "问题列表",
"renderType": "table",
"formSeq": "1793458819301404673",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/safety-problem-tracing/equipId/page",
"params": {
"number": 1,
"size": 10,
"record": "{record}"
}
}
}
}
],
"content": {
"basic": {
"columns": 3,
"datas": [],
"qrcode": {},
"subs": []
},
"dianti": {
"columns": 3,
"datas": []
}
}
}
\ No newline at end of file
{
"name": "设备-电梯",
"tabs": [
{
"key": "basic",
"displayName": "设备信息",
"renderType": "basic",
"formSeq": "1793458381554479105",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/equipment-register/{record}",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
}
},
{
"key": "reghistory",
"displayName": "监管履历信息",
"renderType": "timeline",
"formSeq": "",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/common/equOnJgServiceOperationRecords",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result",
"operater": "content"
}
}
}
},
{
"key": "devtable",
"displayName": "问题列表",
"renderType": "table",
"formSeq": "1793458819301404673",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/safety-problem-tracing/equipId/page",
"params": {
"number": 1,
"size": 10,
"record": "{record}"
}
}
}
}
],
"content": {
"basic": {
"columns": 3,
"datas": [],
"qrcode": {},
"subs": []
},
"dianti": {
"columns": 3,
"datas": []
}
}
}
\ No newline at end of file
{
"name": "设备-起重机械",
"tabs": [
{
"key": "basic",
"displayName": "设备信息",
"renderType": "basic",
"formSeq": "1793458381554479105",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/equipment-register/{record}",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
}
},
{
"key": "reghistory",
"displayName": "监管履历信息",
"renderType": "timeline",
"formSeq": "",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/common/equOnJgServiceOperationRecords",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result",
"operater": "content"
}
}
}
},
{
"key": "devtable",
"displayName": "问题列表",
"renderType": "table",
"formSeq": "1793458819301404673",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/safety-problem-tracing/equipId/page",
"params": {
"number": 1,
"size": 10,
"record": "{record}"
}
}
}
}
],
"content": {
"basic": {
"columns": 3,
"datas": [],
"qrcode": {},
"subs": []
},
"dianti": {
"columns": 3,
"datas": []
}
}
}
\ No newline at end of file
{
"name": "设备-场(厂)内机动车",
"tabs": [
{
"key": "basic",
"displayName": "设备信息",
"renderType": "basic",
"formSeq": "1793458381554479105",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/equipment-register/{record}",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
}
},
{
"key": "reghistory",
"displayName": "监管履历信息",
"renderType": "timeline",
"formSeq": "",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/common/equOnJgServiceOperationRecords",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result",
"operater": "content"
}
}
}
},
{
"key": "devtable",
"displayName": "问题列表",
"renderType": "table",
"formSeq": "1793458819301404673",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/safety-problem-tracing/equipId/page",
"params": {
"number": 1,
"size": 10,
"record": "{record}"
}
}
}
}
],
"content": {
"basic": {
"columns": 3,
"datas": [],
"qrcode": {},
"subs": []
},
"dianti": {
"columns": 3,
"datas": []
}
}
}
\ No newline at end of file
{
"name": "设备-大型游乐设施",
"tabs": [
{
"key": "basic",
"displayName": "设备信息",
"renderType": "basic",
"formSeq": "1793458381554479105",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/equipment-register/{record}",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
}
},
{
"key": "reghistory",
"displayName": "监管履历信息",
"renderType": "timeline",
"formSeq": "",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/common/equOnJgServiceOperationRecords",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result",
"operater": "content"
}
}
}
},
{
"key": "devtable",
"displayName": "问题列表",
"renderType": "table",
"formSeq": "1793458819301404673",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/safety-problem-tracing/equipId/page",
"params": {
"number": 1,
"size": 10,
"record": "{record}"
}
}
}
}
],
"content": {
"basic": {
"columns": 3,
"datas": [],
"qrcode": {},
"subs": []
},
"dianti": {
"columns": 3,
"datas": []
}
}
}
\ No newline at end of file
{
"name": "设备-压力管道",
"tabs": [
{
"key": "basic",
"displayName": "设备信息",
"renderType": "basic",
"formSeq": "1793458381554479105",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/equipment-register/{record}",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
}
},
{
"key": "reghistory",
"displayName": "监管履历信息",
"renderType": "timeline",
"formSeq": "",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/common/equOnJgServiceOperationRecords",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result",
"operater": "content"
}
}
}
},
{
"key": "devtable",
"displayName": "问题列表",
"renderType": "table",
"formSeq": "1793458819301404673",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/safety-problem-tracing/equipId/page",
"params": {
"number": 1,
"size": 10,
"record": "{record}"
}
}
}
}
],
"content": {
"basic": {
"columns": 3,
"datas": [],
"qrcode": {},
"subs": []
},
"dianti": {
"columns": 3,
"datas": []
}
}
}
\ No newline at end of file
{
"name": "设备-客运索道",
"tabs": [
{
"key": "basic",
"displayName": "设备信息",
"renderType": "basic",
"formSeq": "1793458381554479105",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/equipment-register/{record}",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result.equipInfo"
}
}
}
},
{
"key": "reghistory",
"displayName": "监管履历信息",
"renderType": "timeline",
"formSeq": "",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/common/equOnJgServiceOperationRecords",
"params": {
"record": "{record}"
},
"ruleData": {
"responseSuccess": "data.result",
"operater": "content"
}
}
}
},
{
"key": "devtable",
"displayName": "问题列表",
"renderType": "table",
"formSeq": "1793458819301404673",
"dataConfig": {
"api": {
"httpMethod":"GET",
"apiPath":"/jg/safety-problem-tracing/equipId/page",
"params": {
"number": 1,
"size": 10,
"record": "{record}"
}
}
}
}
],
"content": {
"basic": {
"columns": 3,
"datas": [],
"qrcode": {},
"subs": []
},
"dianti": {
"columns": 3,
"datas": []
}
}
}
\ No newline at end of file
{
"name": "非检验检测机构模板",
"tabs": [
{
"key": "basic",
"displayName": "基本信息",
"renderType": "basic",
"formSeq": "1793454184889085953",
"dataConfig": {
"api": {
"reqType":"GET",
"url":"/tcm/baseEnterprise/getInfoByUseCode",
"params": {
"useCode": "{useUnitCode}"
}
}
}
},
{
"key": "devtable",
"displayName": "设备列表",
"renderType": "table",
"formSeq": "1792821076963651585",
"dataConfig": {
"api": {
"reqType":"GET",
"url":"/jg/equipment-register/page",
"params": {
"number": 1,
"size": 10,
"USE_UNIT_CREDIT_CODE": "{useUnitCode}"
}
}
}
}
],
"content": {
"basic": {
"columns": 2,
"datas": [],
"qrcode": {
"src": "/public/ag/zongshu.png",
"text": "2023/12/26",
"subtext": "23:10:16"
},
"subs": []
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment