Commit 5ca6f1be authored by tianbo's avatar tianbo

refactor(amos-boot): 重构视频服务并优化数据校验逻辑

- 重构 BaseEnterpriseVideoServiceImpl 中的 URL 解析和 Artemis 配置初始化逻辑 -优化 DataDockServiceImpl 中的数据校验逻辑,增加对安装年月的校验 - 为 PipingExcelDto 添加安装年月字段- 重构 VideoServiceImpl 中的视频树构建逻辑,为不同视频平台提供扩展点
parent 3a449428
......@@ -90,7 +90,7 @@ public class MetaHandler implements MetaObjectHandler {
// if (isExistField("companyName", entity)) {
// this.setFieldValByName("companyName", reginParams.getCompany().getCompanyName(), metaObject);
// }
if (isExistField("orgCode", entity)) {
if (isExistField("orgCode", entity) && !isHasValue("orgCode", entity)) {
this.setFieldValByName("orgCode", reginParams.getCompany().getOrgCode(), metaObject);
}
if (isExistField("departmentName", entity)) {
......@@ -121,6 +121,18 @@ public class MetaHandler implements MetaObjectHandler {
return jsonObj.containsKey(field);
}
private Boolean isHasValue(String field, Object obj) {
if (obj == null || StringUtils.isEmpty(field)) {
return false;
}
Object o = JSONObject.toJSON(obj);
JSONObject jsonObj = new JSONObject();
if (o instanceof JSONObject) {
jsonObj = (JSONObject) o;
}
return StringUtils.isNotEmpty(jsonObj.getString(field));
}
private Boolean isStringField(MetaObject metaObject, String fieldName) {
Class clazz = metaObject.getOriginalObject().getClass();
Field[] fields = clazz.getDeclaredFields();
......
......@@ -16,6 +16,7 @@ import com.yeejoin.amos.boot.module.common.api.mapper.BaseEnterpriseVideoMapper;
import com.yeejoin.amos.boot.module.common.api.service.IBaseEnterpriseVideoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.conn.ConnectTimeoutException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
......@@ -77,25 +78,10 @@ public class BaseEnterpriseVideoServiceImpl extends BaseService<BaseEnterpriseVi
videoList.forEach(video -> {
List<CommonVideoDto> commonVideoDtos = new ArrayList<>();
try {
String getCamerasUrl = baseEnterpriseVideo.getUrl();
// 将getCamerasUrl解析为https://192.168.1.1:8080/api/v1?pageNo=1&pageSize=20这种方式
// 使用URI标准库解析URL结构
URI uri = new URI(getCamerasUrl);
String scheme = uri.getScheme(); // 获取协议部分(https)
String protocol = scheme + "://"; // "https://"
String hostPort = uri.getHost() + (uri.getPort() != -1 ? ":" + uri.getPort() : ""); // "ip:port"
String urlPath = uri.getPath();
Map<String, Object> artemisInfo = initArtemisConfigAndPath(baseEnterpriseVideo);
ArtemisConfig config = (ArtemisConfig) artemisInfo.get("config");
Map<String, String> path = (Map<String, String>) artemisInfo.get("path");
ArtemisConfig config = new ArtemisConfig();
config.setAppKey(baseEnterpriseVideo.getAppKey());
config.setAppSecret(baseEnterpriseVideo.getAppSecret());
config.setHost(hostPort);
Map<String, String> path = new HashMap<String, String>(2) {
{
put(protocol, urlPath);
}
};
JSONObject param = JSONObject.parseObject(baseEnterpriseVideo.getChannelNo());// post请求Form表单参数
param.put("cameraIndexCode", video.getKey());
String body = param.toJSONString();
......@@ -125,6 +111,54 @@ public class BaseEnterpriseVideoServiceImpl extends BaseService<BaseEnterpriseVi
videoUrlResult.addAll(videoList);
}
/**
* 解析URL字符串为协议、主机+端口和路径部分
*
* @param url 完整的URL字符串
* @return 包含 protocol, hostPort 和 urlPath 的Map
*/
private Map<String, String> parseUri(String url) throws URISyntaxException {
// 将url解析为https://192.168.1.1:8080/api/v1?pageNo=1&pageSize=20这种方式
URI uri = new URI(url);
String scheme = uri.getScheme();
String protocol = scheme != null ? scheme + "://" : "";
String hostPort = uri.getHost() + (uri.getPort() != -1 ? ":" + uri.getPort() : "");
String urlPath = uri.getPath();
Map<String, String> result = new HashMap<>();
result.put("protocol", protocol);
result.put("hostPort", hostPort);
result.put("urlPath", urlPath);
return result;
}
/**
* 初始化Artemis配置和路径信息
*
* @param baseEnterpriseVideo 视频设备信息
* @return 包含 ArtemisConfig、请求路径和协议的Map
*/
private Map<String, Object> initArtemisConfigAndPath(BaseEnterpriseVideo baseEnterpriseVideo) throws URISyntaxException {
String getCamerasUrl = baseEnterpriseVideo.getUrl(); // 或 getTokenUrl(),根据具体方法传入
Map<String, String> uriInfo = parseUri(getCamerasUrl);
String protocol = uriInfo.get("protocol");
String hostPort = uriInfo.get("hostPort");
String urlPath = uriInfo.get("urlPath");
ArtemisConfig config = new ArtemisConfig();
config.setAppKey(baseEnterpriseVideo.getAppKey());
config.setAppSecret(baseEnterpriseVideo.getAppSecret());
config.setHost(hostPort);
Map<String, String> path = new HashMap<>();
path.put(protocol, urlPath);
Map<String, Object> result = new HashMap<>();
result.put("config", config);
result.put("path", path);
return result;
}
private void getYsVideoUrl(List<BaseEnterpriseVideo> videos, List<CommonVideoDto> result) {
for (BaseEnterpriseVideo video : videos) {
Map<String, Object> requestInfo = new HashMap<>();
......@@ -235,25 +269,10 @@ public class BaseEnterpriseVideoServiceImpl extends BaseService<BaseEnterpriseVi
List<CommonVideoDto> commonVideoDtos = new ArrayList<>();
BaseEnterpriseVideo baseEnterpriseVideo = iSecureCenterVideoList.get(0);
try {
String getCamerasUrl = baseEnterpriseVideo.getTokenUrl();
// 将getCamerasUrl解析为https://192.168.1.1:8080/api/v1?pageNo=1&pageSize=20这种方式
// 使用URI标准库解析URL结构
URI uri = new URI(getCamerasUrl);
String scheme = uri.getScheme(); // 获取协议部分(https)
String protocol = scheme + "://"; // "https://"
String hostPort = uri.getHost() + (uri.getPort() != -1 ? ":" + uri.getPort() : ""); // "ip:port"
String urlPath = uri.getPath();
Map<String, Object> artemisInfo = initArtemisConfigAndPath(baseEnterpriseVideo);
ArtemisConfig config = (ArtemisConfig) artemisInfo.get("config");
Map<String, String> path = (Map<String, String>) artemisInfo.get("path");
ArtemisConfig config = new ArtemisConfig();
config.setAppKey(baseEnterpriseVideo.getAppKey());
config.setAppSecret(baseEnterpriseVideo.getAppSecret());
config.setHost(hostPort);
Map<String, String> path = new HashMap<String, String>(2) {
{
put(protocol, urlPath);
}
};
Map<String, String> paramMap = new HashMap<>();// post请求Form表单参数
paramMap.put("regionIndexCode", baseEnterpriseVideo.getDeviceSerial());
paramMap.put("pageNo", "1");
......@@ -290,8 +309,12 @@ public class BaseEnterpriseVideoServiceImpl extends BaseService<BaseEnterpriseVi
}
} catch (URISyntaxException e) {
throw new RuntimeException("URL格式解析异常", e);
} catch (ConnectTimeoutException e) {
log.error("获取iSecureCenter视频对接平台超时:{}", e.getLocalizedMessage(), e);
return commonVideoDtos;
} catch (Exception e) {
throw new RuntimeException(e);
log.error("获取iSecureCenter视频对接平台摄像头列表失败,未知错误!", e);
return commonVideoDtos;
}
return commonVideoDtos;
}
......
......@@ -94,6 +94,10 @@ public class PipingExcelDto extends BaseDto {
@ExcelProperty(value = "安装单位名称")
private String uscUnitName;
@ApiModelProperty(value = "安装年月")
@ExcelProperty(value = "安装年月")
private String uscDate;
//-----------------------------------------------------------------------检验检测信息
@ApiModelProperty(value = "检验检测机构统一社会信用代码")
......
......@@ -1499,6 +1499,7 @@ public class DataDockServiceImpl {
checkNotBlank(data.getInspectReportNo(), "检验报告编号不能为空;", rowError);
checkNotBlank(data.getUscUnitCreditCode(), "安装单位统一社会信用代码不能为空;", rowError);
checkNotBlank(data.getUscUnitName(), "安装单位名称不能为空;", rowError);
checkNotBlank(data.getUscDate(), "安装年月不能为空", rowError);
// 技术参数
checkNotBlank(data.getWallThickness(), "公称壁厚不能为空;", rowError);
Optional.ofNullable(data.getWallThickness()).ifPresent(item -> checkPipeSpecifications(item, "公称壁厚请输入数字或者/分割的范围,如2/6;", rowError));
......
......@@ -59,7 +59,7 @@ public class VideoServiceImpl {
*/
public List<TreeNodeVo> getVideoTree(DPFilterParamDto dpFilterParamDto) {
// 摄像头设备
List<BaseEnterpriseVideo> videoEquipList = getVideos(dpFilterParamDto);
List<BaseEnterpriseVideo> videoEquipList = getVideos(dpFilterParamDto.getCityCode());
// 摄像头对应的单位列表
List<TzBaseEnterpriseInfo> baseEnterpriseInfos = this.getUnitListForTree(videoEquipList.stream().map(BaseEnterpriseVideo::getUseUnitCode).collect(Collectors.toSet()));
// 摄像头对应的行政区域列表
......@@ -131,6 +131,7 @@ public class VideoServiceImpl {
}
private List<TreeNodeVo> buildVideoTypeNode(TreeNodeVo parentNode, List<CommonVideoDto> channelNoList) {
// TODO 需按索道设备分组,萤石云和海康平台分别处理
return channelNoList.stream().filter(v -> v.getParent().contains(parentNode.getCode())).map(u -> {
TreeNodeVo treeNodeVo = new TreeNodeVo();
treeNodeVo.setNodeType(NODE_TYPE_VIDEO);
......@@ -172,15 +173,6 @@ public class VideoServiceImpl {
return tzBaseEnterpriseInfoMapper.selectList(queryWrapper);
}
private List<BaseEnterpriseVideo> getVideos(DPFilterParamDto dpFilterParamDto) {
LambdaQueryWrapper<BaseEnterpriseVideo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BaseEnterpriseVideo::getEquListCode, EquipmentClassifityEnum.KYSD.getCode());
queryWrapper.like(BaseEnterpriseVideo::getRegionCode, dpFilterParamDto.getCityCode());
queryWrapper.eq(BaseEnterpriseVideo::getIsEnabled, true);
return enterpriseVideoService.list(queryWrapper);
}
private List<BaseEnterpriseVideo> getVideos(String regionCode) {
LambdaQueryWrapper<BaseEnterpriseVideo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BaseEnterpriseVideo::getEquListCode, EquipmentClassifityEnum.KYSD.getCode());
......
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