新增算法布点相关逻辑
This commit is contained in:
parent
fff3a6744a
commit
1a110afcf8
@ -114,6 +114,8 @@ public class HttpServerConfig {
|
||||
@Value("${httpserver.patrolserver.maindevicefilepath}")
|
||||
private String mainDeviceFilepath;
|
||||
|
||||
@Value("${httpserver.patrolserver.planfilepath}")
|
||||
private String planFilePath;
|
||||
|
||||
@Value("${httpserver.patrolserver.tempfilepath}")
|
||||
private String tempFilePath;
|
||||
@ -263,6 +265,10 @@ public class HttpServerConfig {
|
||||
return mainDeviceFilepath;
|
||||
}
|
||||
|
||||
public String getPlanFilePath() {
|
||||
return planFilePath;
|
||||
}
|
||||
|
||||
public String getTempFilePath() {
|
||||
return tempFilePath;
|
||||
}
|
||||
|
@ -1,15 +1,21 @@
|
||||
package com.yfd.platform.config;
|
||||
|
||||
import io.swagger.models.auth.In;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.builders.RequestParameterBuilder;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.service.RequestParameter;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* swagger配置
|
||||
*/
|
||||
@ -159,4 +165,17 @@ public class SwaggerConfig {
|
||||
.version("3.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通用的全局参数
|
||||
*
|
||||
* @return 全局参数列表
|
||||
*/
|
||||
private List<RequestParameter> generateRequestParameters(){
|
||||
RequestParameterBuilder token = new RequestParameterBuilder();
|
||||
List<RequestParameter> parameters = new ArrayList<>();
|
||||
token.name("token").description("token").in(In.HEADER.toValue()).required(true).build();
|
||||
parameters.add(token.build());
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,9 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
@Value("${httpserver.patrolserver.maindevicefilepath}")
|
||||
private String mainDeviceFilepath;
|
||||
|
||||
@Value("${httpserver.patrolserver.planfilepath}")
|
||||
private String planFilePath;
|
||||
|
||||
|
||||
@Resource
|
||||
private ISubstationDeviceService substationDeviceService;
|
||||
@ -99,9 +102,13 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
String alarmUrl = "file:" + alarmFilePath;
|
||||
registry.addResourceHandler("/alarm/**").addResourceLocations(alarmUrl).setCachePeriod(0);
|
||||
|
||||
// 告警图片
|
||||
// 主设备图片
|
||||
String mainDeviceUrl = "file:" + mainDeviceFilepath;
|
||||
registry.addResourceHandler("/mainDevice/**").addResourceLocations(mainDeviceUrl).setCachePeriod(0);
|
||||
|
||||
// 变电站平面图地址
|
||||
String planUrl = "file:" + planFilePath;
|
||||
registry.addResourceHandler("/plan/**").addResourceLocations(planUrl).setCachePeriod(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,11 @@ import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeService;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
@ -45,15 +49,32 @@ public class AlgorithmArrangeController {
|
||||
Page<AlgorithmArrange> arrangePage = algorithmArrangeService.page(page, queryWrapper);
|
||||
return ResponseResult.successData(arrangePage);
|
||||
}
|
||||
@GetMapping("/getAlgorithmArrangeById")
|
||||
@ApiOperation("根据Id查询算法布点")
|
||||
public ResponseResult getAlgorithmArrangeById (String id){
|
||||
AlgorithmArrange algorithmArrange = algorithmArrangeService.getById(id);
|
||||
return ResponseResult.successData(algorithmArrange);
|
||||
}
|
||||
|
||||
@PostMapping("/saveAlgorithmArrange")
|
||||
@ApiOperation("新增算法布点")
|
||||
public ResponseResult saveAlgorithmArrange(@RequestBody AlgorithmArrange algorithmArrange) {
|
||||
algorithmArrange.setLastmodifier(SecurityUtils.getCurrentUsername());
|
||||
public ResponseResult saveAlgorithmArrange(AlgorithmArrange algorithmArrange, MultipartFile file) {
|
||||
algorithmArrange.setLastmodifier("admin");
|
||||
algorithmArrange.setLastmodifydate(LocalDateTime.now());
|
||||
algorithmArrange.setDatastatus("1");
|
||||
String id = IdUtil.fastSimpleUUID();
|
||||
algorithmArrange.setId(id);
|
||||
// 文件上传逻辑
|
||||
if (file != null && !file.isEmpty()) {
|
||||
try {
|
||||
// 上传文件
|
||||
String fileUrl = algorithmArrangeService.uploadImage(file);
|
||||
algorithmArrange.setImageUrl(fileUrl);
|
||||
algorithmArrange.setIsImageFlag("1");
|
||||
} catch (Exception e) {
|
||||
return ResponseResult.error("文件上传失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
boolean save = algorithmArrangeService.save(algorithmArrange);
|
||||
if (!save) {
|
||||
return ResponseResult.error();
|
||||
@ -63,13 +84,33 @@ public class AlgorithmArrangeController {
|
||||
|
||||
@PostMapping("/updateAlgorithmArrange")
|
||||
@ApiOperation("修改算法布点")
|
||||
public ResponseResult updateAlgorithmArrange(@RequestBody AlgorithmArrange algorithmArrange) {
|
||||
public ResponseResult updateAlgorithmArrange(AlgorithmArrange algorithmArrange, MultipartFile file) {
|
||||
algorithmArrange.setLastmodifier(SecurityUtils.getCurrentUsername());
|
||||
algorithmArrange.setLastmodifydate(LocalDateTime.now());
|
||||
// 文件上传逻辑
|
||||
if (file != null && !file.isEmpty()) {
|
||||
try {
|
||||
// 调用服务层方法
|
||||
String fileUrl = algorithmArrangeService.uploadImage(file);
|
||||
algorithmArrange.setImageUrl(fileUrl);
|
||||
algorithmArrange.setIsImageFlag("1");
|
||||
} catch (Exception e) {
|
||||
return ResponseResult.error("文件上传失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
boolean save = algorithmArrangeService.updateById(algorithmArrange);
|
||||
if (!save) {
|
||||
return ResponseResult.error();
|
||||
}
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/callAlgorithmArrange")
|
||||
@ApiOperation("调用算法布点API")
|
||||
public ResponseResult callAlgorithmArrange(String id) {
|
||||
AlgorithmArrange algorithmArrange=algorithmArrangeService.callAlgorithmArrange(id);
|
||||
return ResponseResult.successData(algorithmArrange);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
package com.yfd.platform.modules.algorithm.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author zhengsl
|
||||
@ -31,19 +33,14 @@ public class AlgorithmArrangeDevice implements Serializable {
|
||||
private String arrangeId;
|
||||
|
||||
/**
|
||||
* 主设备id
|
||||
* 区域id
|
||||
*/
|
||||
private String mainDeviceId;
|
||||
private String areaId;
|
||||
|
||||
/**
|
||||
* 主设备类型
|
||||
* 区域名称
|
||||
*/
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 主设备名称
|
||||
*/
|
||||
private String mainDeviceName;
|
||||
private String areaName;
|
||||
|
||||
/**
|
||||
* 设备类型;1:摄像机;2:声纹传感器;3:局放传感器;4:温湿度传感器
|
||||
@ -60,5 +57,4 @@ public class AlgorithmArrangeDevice implements Serializable {
|
||||
*/
|
||||
private String patroldeviceDes;
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,5 +16,10 @@ import java.util.Map;
|
||||
*/
|
||||
public interface AlgorithmArrangeDeviceMapper extends BaseMapper<AlgorithmArrangeDevice> {
|
||||
|
||||
/***********************************
|
||||
* 用途说明: 查询当前布点的主设备数量
|
||||
* 参数说明 arrangeId 算法布点ID
|
||||
* 返回值说明: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
|
||||
***********************************/
|
||||
List<Map<String, Object>> getArrangeDeviceInfo(String arrangeId);
|
||||
}
|
||||
|
@ -16,5 +16,10 @@ import java.util.Map;
|
||||
*/
|
||||
public interface IAlgorithmArrangeDeviceService extends IService<AlgorithmArrangeDevice> {
|
||||
|
||||
/***********************************
|
||||
* 用途说明: 查询当前布点的主设备数量
|
||||
* 参数说明 arrangeId 算法布点ID
|
||||
* 返回值说明: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
|
||||
***********************************/
|
||||
List<Map<String, Object>> getArrangeDeviceInfo(String arrangeId);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.yfd.platform.modules.algorithm.service;
|
||||
|
||||
import com.yfd.platform.modules.algorithm.domain.AlgorithmArrange;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -13,4 +14,17 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface IAlgorithmArrangeService extends IService<AlgorithmArrange> {
|
||||
|
||||
/***********************************
|
||||
* 用途说明: 调用算法布点API
|
||||
* 参数说明 id : 算法布点ID
|
||||
* 返回值说明: com.yfd.platform.modules.algorithm.domain.AlgorithmArrange
|
||||
***********************************/
|
||||
AlgorithmArrange callAlgorithmArrange(String id);
|
||||
|
||||
/***********************************
|
||||
* 用途说明: 上传文件
|
||||
* 参数说明 file 文件域
|
||||
* 返回值说明: java.lang.String
|
||||
***********************************/
|
||||
String uploadImage(MultipartFile file);
|
||||
}
|
||||
|
@ -24,6 +24,11 @@ public class AlgorithmArrangeDeviceServiceImpl extends ServiceImpl<AlgorithmArra
|
||||
@Resource
|
||||
private AlgorithmArrangeDeviceMapper algorithmArrangeDeviceMapper;
|
||||
|
||||
/***********************************
|
||||
* 用途说明: 查询当前布点的主设备数量
|
||||
* 参数说明 arrangeId 算法布点ID
|
||||
* 返回值说明: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
|
||||
***********************************/
|
||||
@Override
|
||||
public List<Map<String, Object>> getArrangeDeviceInfo(String arrangeId) {
|
||||
List<Map<String, Object>> rawData = algorithmArrangeDeviceMapper.getArrangeDeviceInfo(arrangeId);
|
||||
@ -32,19 +37,19 @@ public class AlgorithmArrangeDeviceServiceImpl extends ServiceImpl<AlgorithmArra
|
||||
Map<String, Map<String, Object>> groupedData = new HashMap<>();
|
||||
|
||||
for (Map<String, Object> row : rawData) {
|
||||
String mainDeviceId = (String) row.get("mainDeviceId");
|
||||
String mainDeviceName = (String) row.get("mainDeviceName");
|
||||
String areaId = (String) row.get("areaId");
|
||||
String areaName = (String) row.get("areaName");
|
||||
String deviceTypeCode = (String) row.get("deviceTypeCode");
|
||||
Long count = (Long) row.get("deviceTypeCount");
|
||||
|
||||
groupedData.computeIfAbsent(mainDeviceId, k -> {
|
||||
groupedData.computeIfAbsent(areaId, k -> {
|
||||
Map<String, Object> newRow = new HashMap<>();
|
||||
newRow.put("mainDeviceId", mainDeviceId);
|
||||
newRow.put("mainDeviceName", mainDeviceName);
|
||||
newRow.put("areaId", areaId);
|
||||
newRow.put("areaName", areaName);
|
||||
return newRow;
|
||||
});
|
||||
// 设置具体类型的数量
|
||||
groupedData.get(mainDeviceId).put(deviceTypeCode, count);
|
||||
groupedData.get(areaId).put(deviceTypeCode, count);
|
||||
}
|
||||
|
||||
return new ArrayList<>(groupedData.values());
|
||||
|
@ -1,20 +1,149 @@
|
||||
package com.yfd.platform.modules.algorithm.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.yfd.platform.config.HttpServerConfig;
|
||||
import com.yfd.platform.modules.algorithm.domain.AlgorithmArrange;
|
||||
import com.yfd.platform.modules.algorithm.domain.AlgorithmArrangeDevice;
|
||||
import com.yfd.platform.modules.algorithm.mapper.AlgorithmArrangeMapper;
|
||||
import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeDeviceService;
|
||||
import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yfd.platform.modules.basedata.domain.SubstationMaindevice;
|
||||
import com.yfd.platform.modules.basedata.service.ISubstationMaindeviceService;
|
||||
import com.yfd.platform.utils.FileUtil;
|
||||
import com.yfd.platform.utils.HttpRESTfulUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author zhengsl
|
||||
* @since 2025-06-06
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AlgorithmArrangeServiceImpl extends ServiceImpl<AlgorithmArrangeMapper, AlgorithmArrange> implements IAlgorithmArrangeService {
|
||||
|
||||
@Resource
|
||||
private HttpRESTfulUtils httpRESTfulUtils;
|
||||
|
||||
@Resource
|
||||
private ISubstationMaindeviceService substationMaindeviceService;
|
||||
@Resource
|
||||
private IAlgorithmArrangeDeviceService algorithmArrangeDeviceService;
|
||||
@Resource
|
||||
private HttpServerConfig httpServerConfig;
|
||||
|
||||
/***********************************
|
||||
* 用途说明: 调用算法布点API
|
||||
* 参数说明 id : 算法布点ID
|
||||
* 返回值说明: com.yfd.platform.modules.algorithm.domain.AlgorithmArrange
|
||||
***********************************/
|
||||
@Override
|
||||
public AlgorithmArrange callAlgorithmArrange(String id) {
|
||||
// 查询算法布点信息
|
||||
AlgorithmArrange algorithmArrange = this.getById(id);
|
||||
if (algorithmArrange == null) {
|
||||
return null;
|
||||
}
|
||||
if ("0".equals(algorithmArrange.getIsImageFlag())) {
|
||||
return algorithmArrange;
|
||||
}
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("arrange_id", algorithmArrange.getId());
|
||||
param.put("station_name", algorithmArrange.getStationName());
|
||||
param.put("station_type", algorithmArrange.getStationType());
|
||||
param.put("volt_level", algorithmArrange.getVoltLevel());
|
||||
param.put("business_type", algorithmArrange.getBusinessType());
|
||||
String deviceTypeList = algorithmArrange.getDeviceTypeList();
|
||||
List<String> typeList = StrUtil.split(deviceTypeList, ",");
|
||||
LambdaQueryWrapper<SubstationMaindevice> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SubstationMaindevice::getDeviceType, typeList).select(SubstationMaindevice::getMainDeviceId,
|
||||
SubstationMaindevice::getMainDeviceName, SubstationMaindevice::getDeviceType,
|
||||
SubstationMaindevice::getAreaId, SubstationMaindevice::getAreaName);
|
||||
List<Map<String, Object>> maps = substationMaindeviceService.listMaps(queryWrapper);
|
||||
List<Map<String, Object>> mainDeviceList = renameKeysWithStream(maps);
|
||||
param.put("main_device_list", mainDeviceList);
|
||||
File file = new File("D:\\riis\\video\\test0.jpg");
|
||||
JSONObject arrange = httpRESTfulUtils.uploadJsonWithImageFileWithDataWrapper("192.168.1.173", "20014",
|
||||
"arrange", param, file
|
||||
, null);
|
||||
if (!"200".equals(arrange.getString("code"))) {
|
||||
throw new RuntimeException("调用失败!");
|
||||
}
|
||||
String arrangeId = arrange.getString("arrange_id");
|
||||
JSONArray resultsList = arrange.getJSONArray("results_list");
|
||||
List<AlgorithmArrangeDevice> algorithmArrangeDeviceList = new java.util.ArrayList<>();
|
||||
for (int i = 0; i < resultsList.size(); i++) {
|
||||
JSONObject result = resultsList.getJSONObject(i);
|
||||
String areaId = result.getString("area_id");
|
||||
String areaName = result.getString("area_name");
|
||||
JSONArray patroldeviceList = result.getJSONArray("patroldevice_list");
|
||||
for (int j = 0; j < patroldeviceList.size(); j++) {
|
||||
AlgorithmArrangeDevice algorithmArrangeDevice = new AlgorithmArrangeDevice();
|
||||
JSONObject patroldevice = patroldeviceList.getJSONObject(j);
|
||||
String patroldeviceType = patroldevice.getString("patroldevice_type");
|
||||
String patroldevicePos = patroldevice.getString("patroldevice_pos");
|
||||
algorithmArrangeDevice.setArrangeId(arrangeId);
|
||||
algorithmArrangeDevice.setAreaId(areaId);
|
||||
algorithmArrangeDevice.setAreaName(areaName);
|
||||
algorithmArrangeDevice.setPatroldeviceType(patroldeviceType);
|
||||
algorithmArrangeDevice.setPatroldevicePos(patroldevicePos);
|
||||
algorithmArrangeDeviceList.add(algorithmArrangeDevice);
|
||||
}
|
||||
}
|
||||
algorithmArrangeDeviceService.saveBatch(algorithmArrangeDeviceList);
|
||||
return algorithmArrange;
|
||||
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* 用途说明: 上传文件
|
||||
* 参数说明 file 文件域
|
||||
* 返回值说明: java.lang.String
|
||||
***********************************/
|
||||
@Override
|
||||
public String uploadImage(MultipartFile file) {
|
||||
|
||||
// 文件存储地址
|
||||
String fileName =
|
||||
IdUtil.fastSimpleUUID() + "." + FileUtil.getExtensionName(file.getOriginalFilename());
|
||||
// 上传文件
|
||||
String name =
|
||||
Objects.requireNonNull(FileUtil.upload(file, httpServerConfig.getPlanFilePath(), fileName)).getName();
|
||||
return name;
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* 用途说明: 转换方法
|
||||
* 参数说明 originalList 原始列表
|
||||
* 返回值说明: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
|
||||
***********************************/
|
||||
private List<Map<String, Object>> renameKeysWithStream(List<Map<String, Object>> originalList) {
|
||||
return originalList.stream().map(originalMap -> {
|
||||
Map<String, Object> newMap = new HashMap<>();
|
||||
newMap.put("main_device_id", originalMap.get("mainDeviceId"));
|
||||
newMap.put("main_device_name", originalMap.get("mainDeviceName"));
|
||||
newMap.put("device_type", originalMap.get("deviceType"));
|
||||
newMap.put("area_id", originalMap.get("areaId"));
|
||||
newMap.put("area_name", originalMap.get("areaName"));
|
||||
return newMap;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +169,99 @@ public class HttpRESTfulUtils {
|
||||
return responseJSON;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 multipart/form-data 请求,其中 JSON 数据包装在 { "data": ... } 中,并附带一张图片
|
||||
*
|
||||
* @param ip 目标服务器 IP 地址
|
||||
* @param port 目标服务器端口
|
||||
* @param api 接口路径(如 /api/callAlgorithmArrange)
|
||||
* @param jsonData JSON 数据内容(即 data 字段的值)
|
||||
* @param imageFile 要上传的图片文件
|
||||
* @param callback 回调函数(null 表示同步)
|
||||
* @return 响应结果
|
||||
*/
|
||||
public JSONObject uploadJsonWithImageFileWithDataWrapper(String ip, String port, String api,
|
||||
JSONObject jsonData,
|
||||
File imageFile,
|
||||
RequestCallback callback) {
|
||||
OkHttpClient client = getClient();
|
||||
String url = String.format("http://%s:%s/%s", ip, port, api);
|
||||
JSONObject responseJSON = new JSONObject();
|
||||
responseJSON.put("code", -2);
|
||||
responseJSON.put("msg", "http请求调用失败!");
|
||||
|
||||
MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
|
||||
|
||||
// 添加 JSON 数据(包装为 { "data": ... } 格式)
|
||||
if (jsonData != null && !jsonData.isEmpty()) {
|
||||
builder.addFormDataPart("data", jsonData.toJSONString());
|
||||
}
|
||||
|
||||
// 添加图片文件
|
||||
if (imageFile != null && imageFile.exists()) {
|
||||
RequestBody fileBody = RequestBody.create(MediaType.parse("image/*"), imageFile);
|
||||
builder.addFormDataPart("image_file", imageFile.getName(), fileBody);
|
||||
}
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(builder.build())
|
||||
.build();
|
||||
|
||||
if (callback == null) {
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (response.isSuccessful()) {
|
||||
ResponseBody responseBody = response.body();
|
||||
if (responseBody != null) {
|
||||
String responseStr = responseBody.string();
|
||||
responseJSON = JSON.parseObject(responseStr);
|
||||
}
|
||||
} else {
|
||||
if (response.body() != null) {
|
||||
response.body().close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
if (e instanceof SocketTimeoutException) {
|
||||
throw new RuntimeException(String.format("读取Http服务器数据失败: %s, %s", url, e.getMessage()));
|
||||
}
|
||||
if (e instanceof ConnectException) {
|
||||
throw new RuntimeException(String.format("连接Http服务器失败: %s, %s", url, e.getMessage()));
|
||||
}
|
||||
throw new RuntimeException(String.format("访问Http服务器失败: %s, %s", url, e.getMessage()));
|
||||
}
|
||||
} else {
|
||||
client.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
|
||||
if (response.isSuccessful()) {
|
||||
String responseStr = Objects.requireNonNull(response.body()).string();
|
||||
callback.run(JSON.parseObject(responseStr));
|
||||
} else {
|
||||
response.close();
|
||||
Objects.requireNonNull(response.body()).close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
logger.error(String.format("连接Http服务器失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
if (e instanceof SocketTimeoutException) {
|
||||
logger.error(String.format("读取Http服务器数据失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
}
|
||||
if (e instanceof ConnectException) {
|
||||
logger.error(String.format("连接Http服务器失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return responseJSON;
|
||||
}
|
||||
|
||||
|
||||
public JSONObject sendHttpPost(String posttype, String ip, String port, String secret, String api, Map<String,
|
||||
Object> param, RequestCallback callback) {
|
||||
OkHttpClient client = getClient();
|
||||
@ -266,8 +359,8 @@ public class HttpRESTfulUtils {
|
||||
return responseJSON;
|
||||
}
|
||||
|
||||
|
||||
public JSONObject sendHttpUrlPost(String posttype,String url, String secret, Map<String, Object> param, RequestCallback callback) {
|
||||
public JSONObject sendHttpUrlPost(String posttype, String url, String secret, Map<String, Object> param,
|
||||
RequestCallback callback) {
|
||||
OkHttpClient client = getClient();
|
||||
JSONObject responseJSON = new JSONObject();
|
||||
//-2自定义流媒体 调用错误码
|
||||
@ -362,7 +455,8 @@ public class HttpRESTfulUtils {
|
||||
return responseJSON;
|
||||
}
|
||||
|
||||
public JSONObject sendHttpPostStr(String ip, String port, String api, Map<String, Object> param, RequestCallback callback) {
|
||||
public JSONObject sendHttpPostStr(String ip, String port, String api, Map<String, Object> param,
|
||||
RequestCallback callback) {
|
||||
OkHttpClient client = getClient();
|
||||
String url = String.format("http://%s:%s/%s", ip, port, api);
|
||||
JSONObject responseJSON = new JSONObject();
|
||||
@ -597,7 +691,8 @@ public class HttpRESTfulUtils {
|
||||
public JSONObject callDevicePos(String devicecode, String channelcode, String poscode, RequestCallback callback) {
|
||||
String api = String.format("api/ptz/front_end_command/%s/%s", devicecode, channelcode);
|
||||
if (StrUtil.isNotEmpty(Config.getMonitorAppname())) {
|
||||
api = String.format("%s/api/ptz/front_end_command/%s/%s", Config.getMonitorAppname(), devicecode, channelcode);
|
||||
api = String.format("%s/api/ptz/front_end_command/%s/%s", Config.getMonitorAppname(), devicecode,
|
||||
channelcode);
|
||||
}
|
||||
logger.info(api);
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
@ -649,7 +744,8 @@ public class HttpRESTfulUtils {
|
||||
}
|
||||
|
||||
//调用智能分析主机图像算法识别
|
||||
public JSONObject callPicAnalyse(String requestId, String objectId, String typeList, String customParams, String filename) throws Exception {
|
||||
public JSONObject callPicAnalyse(String requestId, String objectId, String typeList, String customParams,
|
||||
String filename) throws Exception {
|
||||
String api = "picAnalyse";
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("requestHostIp", Config.getPatrolIp()); //巡视主机IP
|
||||
@ -673,15 +769,15 @@ public class HttpRESTfulUtils {
|
||||
methodname = "playAudioFile";
|
||||
}
|
||||
// if ("3".equals(Config.getFilefromtype())) {
|
||||
// imageurl = filename;
|
||||
// } else {
|
||||
// imageurl = String.format("http://%s:%s/%s?filename=%s", Config.getPatrolIp(),
|
||||
// Config.getPatrolPort(), methodname, filename);
|
||||
// if (StrUtil.isNotEmpty(Config.getPatrolAppname())) {
|
||||
// imageurl = String.format("http://%s:%s/%s/%s?filename=%s", Config.getPatrolIp(),
|
||||
// Config.getPatrolPort(), Config.getPatrolAppname(), methodname, filename);
|
||||
// }
|
||||
// }
|
||||
// imageurl = filename;
|
||||
// } else {
|
||||
// imageurl = String.format("http://%s:%s/%s?filename=%s", Config.getPatrolIp(),
|
||||
// Config.getPatrolPort(), methodname, filename);
|
||||
// if (StrUtil.isNotEmpty(Config.getPatrolAppname())) {
|
||||
// imageurl = String.format("http://%s:%s/%s/%s?filename=%s", Config.getPatrolIp(),
|
||||
// Config.getPatrolPort(), Config.getPatrolAppname(), methodname, filename);
|
||||
// }
|
||||
// }
|
||||
|
||||
imageUrlArray.add(filename);
|
||||
jsonObject.put("imagePathList", imageUrlArray);
|
||||
@ -710,7 +806,8 @@ public class HttpRESTfulUtils {
|
||||
logger.info("===================调用分析===============" + jsonObject1.toString());
|
||||
return sendHttpPost("json", analyseIp, analysePort, "", api, param, null);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());;
|
||||
logger.error(e.getMessage());
|
||||
;
|
||||
logger.error("===================调用分析出错===============");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("code", "-2");
|
||||
@ -719,7 +816,8 @@ public class HttpRESTfulUtils {
|
||||
}
|
||||
|
||||
//调用智能分析主机图像算法识别
|
||||
public JSONObject callPicAnalyse(String requestId,String objectId,String typeList,String customParams,String filename,String manId) throws Exception {
|
||||
public JSONObject callPicAnalyse(String requestId, String objectId, String typeList, String customParams,
|
||||
String filename, String manId) throws Exception {
|
||||
String api = "picAnalyse";
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("requestHostIp", Config.getPatrolIp()); //巡视主机IP
|
||||
@ -779,7 +877,8 @@ public class HttpRESTfulUtils {
|
||||
logger.info("===================调用分析===============" + jsonObject1.toString());
|
||||
return sendHttpPost("json", analyseIp, analysePort, "", api, param, null);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());;
|
||||
logger.error(e.getMessage());
|
||||
;
|
||||
logger.error("===================调用分析出错===============");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("code", "-2");
|
||||
|
@ -149,6 +149,7 @@ httpserver: #配置http请求访问的地址
|
||||
snapfilepath: d:\riis\video\ #视频截图文件路径
|
||||
alarmfilepath: d:\riis\alarm\ #报警图片存储路径
|
||||
maindevicefilepath: d:\riis\maindevice\ #主设备文件存储地址
|
||||
planfilepath: d:\riis\plan\ #变电站平面原图地址
|
||||
tempfilepath: d:\riis\temp\ #模板图片路径
|
||||
ffmpegpath: E:\ffmpeg\bin\ #ffmpeg截图命名路径
|
||||
modelpath: d:\riis\model\
|
||||
|
@ -149,6 +149,7 @@ httpserver: #配置http请求访问的地址
|
||||
snapfilepath: d:\riis\video\ #视频截图文件路径
|
||||
alarmfilepath: d:\riis\alarm\ #报警图片存储路径
|
||||
maindevicefilepath: d:\riis\maindevice\ #主设备文件存储地址
|
||||
planfilepath: d:\riis\plan\ #变电站平面原图地址
|
||||
tempfilepath: d:\riis\temp\ #模板图片路径
|
||||
ffmpegpath: E:\ffmpeg\bin\ #ffmpeg截图命名路径
|
||||
modelpath: d:\riis\model\
|
||||
|
@ -4,13 +4,13 @@
|
||||
|
||||
<select id="getArrangeDeviceInfo" resultType="java.util.Map">
|
||||
SELECT
|
||||
d.main_device_id,
|
||||
d.main_device_name,
|
||||
d.area_id,
|
||||
d.area_name,
|
||||
t.device_type_code,
|
||||
t.device_type_name,
|
||||
COUNT(iis.id) AS device_type_count
|
||||
FROM
|
||||
(SELECT DISTINCT main_device_id, main_device_name FROM iis_algorithm_arrange_device) d
|
||||
(SELECT DISTINCT area_id, area_name FROM iis_algorithm_arrange_device) d
|
||||
CROSS JOIN
|
||||
(SELECT itemcode AS device_type_code, dictname AS device_type_name
|
||||
FROM sys_dictionary_items
|
||||
@ -18,18 +18,18 @@
|
||||
) t
|
||||
LEFT JOIN
|
||||
iis_algorithm_arrange_device iis
|
||||
ON iis.main_device_id = d.main_device_id
|
||||
ON iis.area_id = d.area_id
|
||||
AND iis.patroldevice_type = t.device_type_code
|
||||
<if test="arrangeId != null and arrangeId != ''">
|
||||
AND arrange_id = #{arrangeId}
|
||||
</if>
|
||||
GROUP BY
|
||||
d.main_device_id,
|
||||
d.main_device_name,
|
||||
d.area_id,
|
||||
d.area_name,
|
||||
t.device_type_code,
|
||||
t.device_type_name
|
||||
ORDER BY
|
||||
d.main_device_id,
|
||||
d.area_id,
|
||||
t.device_type_code;
|
||||
|
||||
</select>
|
||||
|
Loading…
Reference in New Issue
Block a user