Commit fea857733e27db326236342737088fe04fa82c04

Authored by Liu Haoyu
1 parent ace728ed

可视化功能完善;

Linux服务器监听运维功能.md
... ... @@ -310,6 +310,92 @@
310 310 }
311 311 ```
312 312  
  313 +### 1.5.5 获取配置服务支持的所有接口信息
  314 +
  315 +| 调用方式 | 接口地址 |
  316 +| ------------ | :-------------------------------------------------- |
  317 +| POST | http://ip:port/background/findAllAvailableInterface |
  318 +| Content-Type | application/json;charset=UTF-8 |
  319 +
  320 +| 请求参数 | | | | |
  321 +| -------- | -------- | ------- | ---- | ------------------ |
  322 +| 参数项 | 名称 | 类型 | 必选 | 描述 |
  323 +| configId | 服务主键 | Integer | 是 | 主键(formdata形式) |
  324 +```
  325 +请求示例
  326 +"configId": 1
  327 +```
  328 +
  329 +| 返回结果 | | | |
  330 +| ------------ | -------------------- | ------ | --------------------------------- |
  331 +| 参数项 | 名称 | 类型 | 描述 |
  332 +| code | 响应码 | int | 200为操作成功,其他code表示失败 |
  333 +| message | 提示信息 | string | 200为操作成功, 其他为对应错误信息 |
  334 +| data | 返回信息 | | |
  335 +| +id | 主键 | int | 主键 |
  336 +| +mouldId | 模板id | int | 模板id |
  337 +| +methodType | 请求方式类型 | string | 请求方式类型 |
  338 +| +contentType | 请求头参数类型 | string | 请求头参数类型 |
  339 +| +uri | 请求地址 | string | 请求地址 |
  340 +| +defaultJson | 默认请求参数(json串) | string | 默认请求参数(json串) |
  341 +| +sort | 排序 | int | 排序 |
  342 +
  343 +```
  344 +响应示例
  345 +{
  346 + "code": 200,
  347 + "message": "操作成功",
  348 + "data": [
  349 + {
  350 + "id": 1,
  351 + "mouldId": 1,
  352 + "methodType": "post",
  353 + "contentType": "application/json;charset=UTF-8",
  354 + "uri": "/vehicle/base64",
  355 + "defaultJson": "{"TPXX":"#base64#"}",
  356 + "sort": 1
  357 + }
  358 + ]
  359 +}
  360 +```
  361 +### 1.5.6 根据配置明细项id获取请求http的返回值信息
  362 +
  363 +| 调用方式 | 接口地址 |
  364 +| ------------ | :----------------------------------------------- |
  365 +| POST | http://ip:port/background/getServiceHttpResponse |
  366 +| Content-Type | application/json;charset=UTF-8 |
  367 +
  368 +| 请求参数 | | | | |
  369 +| ---------------- | ------------ | ------- | ---- | ------------------------------------------ |
  370 +| 参数项 | 名称 | 类型 | 必选 | 描述 |
  371 +| configId | 配置服务id | Integer | 是 | 配置服务id (param格式) |
  372 +| interfaceMouldId | 接口id | Integer | 是 | 接口id (param格式) |
  373 +| params | 请求参数信息 | string | 否 | 如果是需要文件传入对应参数部分写入"#file#" |
  374 +| multipartFile | 文件信息 | string | 否 | 文件信息 (param格式) |
  375 +```
  376 +请求示例
  377 +"configId": 1
  378 +"interfaceMouldId": "start",
  379 +"params": "{"TPXX":"#file#"}",
  380 +"multipartFile": xxx
  381 +```
  382 +
  383 +| 返回结果 | | | |
  384 +| -------- | -------- | ------ | --------------------------------- |
  385 +| 参数项 | 名称 | 类型 | 描述 |
  386 +| code | 响应码 | int | 200为操作成功,其他code表示失败 |
  387 +| message | 提示信息 | string | 200为操作成功, 其他为对应错误信息 |
  388 +| data | 返回信息 | | |
  389 +| result | 操作结果 | string | 操作成功信息或者失败原因 |
  390 +
  391 +```
  392 +响应示例
  393 +{
  394 + "code": 200,
  395 + "message": "操作成功",
  396 + "data": {}
  397 +}
  398 +```
313 399  
314 400 ## 1.6 查询配置好的服务运行情况
315 401  
... ...
src/main/java/com/objecteye/controller/BackGroundController.java
... ... @@ -89,7 +89,8 @@ public class BackGroundController extends BasicController {
89 89 @ApiOperation("根据配置明细项id获取请求http的返回值信息")
90 90 @RequestMapping(value = "getServiceHttpResponse", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
91 91 public CommonResult<String> getServiceHttpResponse(@RequestParam Integer configId, @RequestParam Integer interfaceMouldId,
92   - @RequestParam String params, @RequestParam(required = false) MultipartFile multipartFile) {
  92 + @RequestParam(required = false) String params,
  93 + @RequestParam(required = false) MultipartFile multipartFile) {
93 94 return CommonResult.success(iBackGroundService.getServiceHttpResponse(configId, interfaceMouldId, params, multipartFile));
94 95 }
95 96  
... ...
src/main/java/com/objecteye/service/impl/BackGroundServiceImpl.java
... ... @@ -18,19 +18,23 @@ import com.objecteye.utils.LinuxUtils;
18 18 import com.objecteye.vo.VSyServiceMainTable;
19 19 import lombok.extern.slf4j.Slf4j;
20 20 import org.apache.commons.io.FileUtils;
  21 +import org.apache.http.Consts;
  22 +import org.apache.http.client.methods.CloseableHttpResponse;
  23 +import org.apache.http.client.methods.HttpPost;
  24 +import org.apache.http.entity.StringEntity;
  25 +import org.apache.http.entity.mime.MultipartEntityBuilder;
  26 +import org.apache.http.entity.mime.content.FileBody;
  27 +import org.apache.http.entity.mime.content.StringBody;
  28 +import org.apache.http.impl.client.CloseableHttpClient;
  29 +import org.apache.http.impl.client.HttpClients;
  30 +import org.apache.http.util.EntityUtils;
21 31 import org.springframework.beans.factory.annotation.Autowired;
22   -import org.springframework.core.io.FileSystemResource;
23 32 import org.springframework.data.redis.core.RedisTemplate;
24   -import org.springframework.http.HttpEntity;
25   -import org.springframework.http.HttpHeaders;
26   -import org.springframework.http.MediaType;
27 33 import org.springframework.http.ResponseEntity;
28 34 import org.springframework.scheduling.annotation.Async;
29 35 import org.springframework.scheduling.annotation.Scheduled;
30 36 import org.springframework.stereotype.Component;
31 37 import org.springframework.transaction.annotation.Transactional;
32   -import org.springframework.util.LinkedMultiValueMap;
33   -import org.springframework.util.MultiValueMap;
34 38 import org.springframework.web.client.RestTemplate;
35 39 import org.springframework.web.multipart.MultipartFile;
36 40  
... ... @@ -593,32 +597,49 @@ public class BackGroundServiceImpl implements IBackGroundService {
593 597 throw new CustomXException("201", "请求路径信息异常");
594 598 }
595 599 JSONObject paramJson = JSON.parseObject(paramsStr);
596   - MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
597   - for (String key : paramJson.keySet()) {
598   - String value = paramJson.getString(key);
599   - if ("#file#".equals(value)) {
600   - if (multipartFile != null && multipartFile.getOriginalFilename() != null) {
601   - try {
602   - FileUtils.writeByteArrayToFile(new File(multipartFile.getOriginalFilename()), multipartFile.getBytes());
603   - } catch (IOException e) {
604   - e.printStackTrace();
  600 + CloseableHttpResponse response = null;
  601 + String resultString = "";
  602 + CloseableHttpClient httpClient = HttpClients.createDefault();
  603 + HttpPost httpPost = new HttpPost("http://" + ip + ":" + port + uri);
  604 + MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
  605 + try {
  606 + if (paramsStr != null && paramsStr.contains("#file#")) {
  607 + for (String key : paramJson.keySet()) {
  608 + String value = paramJson.getString(key);
  609 + if ("#file#".equals(value)) {
  610 + if (multipartFile != null && multipartFile.getOriginalFilename() != null) {
  611 + FileUtils.writeByteArrayToFile(new File(multipartFile.getOriginalFilename()), multipartFile.getBytes());
  612 + FileBody fileBody = new FileBody(new File(multipartFile.getOriginalFilename()), org.apache.http.entity.ContentType.create("image/png", Consts.UTF_8));
  613 + multipartEntityBuilder.addPart(key, fileBody);
  614 + } else {
  615 + throw new CustomXException("201", "参数为空");
  616 + }
  617 + } else {
  618 + multipartEntityBuilder.addPart(key, new StringBody(value));
605 619 }
606   - FileSystemResource fileSystemResource = new FileSystemResource(new File(multipartFile.getOriginalFilename()));
607   - multiValueMap.add(key, fileSystemResource);
608   - } else {
609   - throw new CustomXException("201", "参数为空");
610 620 }
611   - } else {
612   - multiValueMap.add(key, value);
  621 + httpPost.setEntity(multipartEntityBuilder.build());
  622 + } else if (paramsStr != null) {
  623 + StringEntity stringEntity = new StringEntity(paramsStr, "utf-8");
  624 + httpPost.addHeader("Content-Type", syServiceInterfaceMould.getContentType());
  625 + httpPost.setEntity(stringEntity);
  626 + }
  627 + response = httpClient.execute(httpPost);
  628 + resultString = EntityUtils.toString(response.getEntity(), "utf-8");
  629 + } catch (IOException e) {
  630 + e.printStackTrace();
  631 + } finally {
  632 + if (response != null) {
  633 + try {
  634 + response.close();
  635 + } catch (IOException e) {
  636 + e.printStackTrace();
  637 + }
613 638 }
614 639 }
615 640  
616   - HttpHeaders httpHeaders = new HttpHeaders();
617   - httpHeaders.setContentType(MediaType.parseMediaType(syServiceInterfaceMould.getContentType()));
618   - HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(multiValueMap, httpHeaders);
619 641 if ("post".equals(syServiceInterfaceMould.getMethodType().toLowerCase())) {
620   - ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://" + ip + ":" + port + uri, httpEntity, String.class);
621   - return responseEntity.getBody();
  642 + return resultString;
622 643 } else {
623 644 return "其他请求方式暂不支持";
624 645 }
... ... @@ -639,7 +660,7 @@ public class BackGroundServiceImpl implements IBackGroundService {
639 660 .andItemNameIn(Arrays.asList("serviceInterface", "interfaceMould")).example());
640 661  
641 662 List<Integer> interfaceMouldIdList = new ArrayList<>();
642   - Integer mouldId = null;
  663 + List<Integer> mouldIdList = new ArrayList<>();
643 664 for (SyServiceConfigItem syServiceConfigItem : syServiceConfigItems) {
644 665 if (syServiceConfigItem == null) {
645 666 continue;
... ... @@ -647,16 +668,19 @@ public class BackGroundServiceImpl implements IBackGroundService {
647 668 if ("serviceInterface".equals(syServiceConfigItem.getItemName())) {
648 669 interfaceMouldIdList.add(Integer.valueOf(syServiceConfigItem.getItemValue()));
649 670 } else if ("interfaceMould".equals(syServiceConfigItem.getItemName())) {
650   - mouldId = Integer.valueOf(syServiceConfigItem.getItemValue());
  671 + mouldIdList.add(Integer.valueOf(syServiceConfigItem.getItemValue()));
651 672 }
652 673 }
653 674 SyServiceInterfaceMouldExample syServiceInterfaceMouldExample = new SyServiceInterfaceMouldExample();
  675 + boolean hasCondition = false;
654 676 if (interfaceMouldIdList.size() > 0) {
  677 + hasCondition = true;
655 678 syServiceInterfaceMouldExample.or(SyServiceInterfaceMouldExample.newAndCreateCriteria().andIdIn(interfaceMouldIdList));
656 679 }
657   - if (mouldId != null) {
658   - syServiceInterfaceMouldExample.or(SyServiceInterfaceMouldExample.newAndCreateCriteria().andMouldIdEqualTo(mouldId));
  680 + if (mouldIdList.size() > 0) {
  681 + hasCondition = true;
  682 + syServiceInterfaceMouldExample.or(SyServiceInterfaceMouldExample.newAndCreateCriteria().andMouldIdIn(mouldIdList));
659 683 }
660   - return syServiceInterfaceMouldMapper.selectByExample(syServiceInterfaceMouldExample);
  684 + return hasCondition ? syServiceInterfaceMouldMapper.selectByExample(syServiceInterfaceMouldExample) : new ArrayList<>();
661 685 }
662 686 }
... ...