Commit f7e4f655 authored by tianbo's avatar tianbo

refactor(amos-boot): 优化视频服务和组织代码更新逻辑- 在 BaseEnterpriseVideoServiceImpl 中添加…

refactor(amos-boot): 优化视频服务和组织代码更新逻辑- 在 BaseEnterpriseVideoServiceImpl 中添加 getAllRegionInfo 方法,用于获取区域详细信息 - 修改 HistoryDataDealServiceImpl 中的 orgCode 更新逻辑,使用新方法查询监管单位信息- 更新 TzBaseEnterpriseInfoMapper 接口,增加 companyLevel 参数 - 修改 TzBaseEnterpriseInfoMapper.xml,根据 companyLevel 决定是否更新 org_code
parent b75fd821
......@@ -5,8 +5,10 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.yeejoin.amos.boot.biz.common.dto.CommonRegionDto;
import com.yeejoin.amos.boot.biz.common.dto.CommonVideoDto;
import com.yeejoin.amos.boot.biz.common.enums.CommonVideoEnum;
import com.yeejoin.amos.boot.module.common.api.dto.BaseEnterpriseVideoDto;
......@@ -19,15 +21,13 @@ 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.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import static com.yeejoin.amos.boot.biz.common.constants.VideoConstant.CODE_200;
......@@ -45,6 +45,8 @@ public class BaseEnterpriseVideoServiceImpl extends BaseService<BaseEnterpriseVi
@Value("${cylinder.video.default.image.url:/upload/tzs/cylinder/no-connect.png}")
private String defaultVideoUrl;
private String rootIndexCode = "root00000000";
public List<CommonVideoDto> getUnitVideoUrl(String useUnitCode, String regionCode) {
List<CommonVideoDto> result = new ArrayList<>();
LambdaQueryWrapper<BaseEnterpriseVideo> wrapper = new LambdaQueryWrapper<>();
......@@ -316,4 +318,77 @@ public class BaseEnterpriseVideoServiceImpl extends BaseService<BaseEnterpriseVi
}
return commonVideoDtos;
}
/**
* 根据编号获取区域详细信息
*/
@Transactional(rollbackFor = Exception.class)
public List<CommonRegionDto> getAllRegionInfo(String regionCode) {
List<BaseEnterpriseVideo> allRegionList = Lists.newArrayList();
BaseEnterpriseVideo baseEnterpriseVideo = new BaseEnterpriseVideo();
baseEnterpriseVideo.setAppKey("26245828");
baseEnterpriseVideo.setAppSecret("zzZ3KPeIRFU8PZkHSwVp");
baseEnterpriseVideo.setTokenUrl("https://113.140.67.204:55443/artemis/api/resource/v1/regions/subRegions");
final List<CommonRegionDto> commonRegionList = getCommonRegionList(baseEnterpriseVideo, rootIndexCode);
if (!ValidationUtil.isEmpty(commonRegionList)) {
commonRegionList.forEach(region -> {
BaseEnterpriseVideo enterpriseVideo = new BaseEnterpriseVideo();
enterpriseVideo.setAppKey(baseEnterpriseVideo.getAppKey());
enterpriseVideo.setAppSecret(baseEnterpriseVideo.getAppSecret());
enterpriseVideo.setTokenUrl("https://113.140.67.204:55443/artemis/api/resource/v1/regions/regionIndexCode/cameras?pageNo=1&pageSize=20");
enterpriseVideo.setUrl("https://113.140.67.204:55443/artemis/api/video/v2/cameras/previewURLs");
enterpriseVideo.setDeviceSerial(region.getIndexCode());
enterpriseVideo.setProtocol("2");
enterpriseVideo.setChannelNo("{\"streamType\":0,\"protocol\":\"hls\",\"transmode\":\"1\",\"viewProtocol\":\"hlsHk\"}");
enterpriseVideo.setExpireTime(60480000L);
enterpriseVideo.setUseUnitCode(region.getUseUnitCode());
enterpriseVideo.setIsEnabled(true);
enterpriseVideo.setPlatform("iSecureCenter");
enterpriseVideo.setRecDate(new Date());
allRegionList.add(enterpriseVideo);
});
}
this.saveOrUpdateBatch(allRegionList);
return commonRegionList;
}
private List<CommonRegionDto> getCommonRegionList(BaseEnterpriseVideo baseEnterpriseVideo, String regionCode) {
Map<String, Object> artemisInfo;
List<CommonRegionDto> commonRegionList = new ArrayList<>();
try {
artemisInfo = initArtemisConfigAndPath(baseEnterpriseVideo, baseEnterpriseVideo.getTokenUrl());
ArtemisConfig config = (ArtemisConfig) artemisInfo.get("config");
Map<String, String> path = (Map<String, String>) artemisInfo.get("path");
Map<String, String> paramMap = new HashMap<>();// post请求Form表单参数
paramMap.put("parentIndexCode", "cac9325d1ac74415b064a621595f6e09");
String body = JSON.toJSON(paramMap).toString();
String resultStr = ArtemisHttpUtil.doPostStringArtemis(config, path, body, null, null, "application/json", null);
if (ValidationUtil.isEmpty(resultStr)) {
return null;
}
JSONObject result = JSONObject.parseObject(resultStr);
if (!result.get("code").equals("0")) {
log.error("getRegionInfo列表失败,code:{}", result.get("code"));
}
if (result.get("data") instanceof JSONArray) {
JSONArray dataObj = (JSONArray) result.get("data");
if (!ValidationUtil.isEmpty(dataObj)) {
dataObj.forEach(data -> {
CommonRegionDto commonRegionDto = new CommonRegionDto();
JSONObject dataJson = (JSONObject) data;
commonRegionDto.setIndexCode(dataJson.getString("indexCode"));
commonRegionDto.setParentIndexCode(dataJson.getString("parentIndexCode"));
commonRegionDto.setUseUnitCode(dataJson.getString("name"));
commonRegionList.add(commonRegionDto);
});
}
}
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (Exception e) {
log.error("获取iSecureCenter视频对接平台区域列表失败,未知错误!", e);
throw new RuntimeException(e);
}
return commonRegionList;
}
}
\ No newline at end of file
......@@ -97,7 +97,7 @@ public interface TzBaseEnterpriseInfoMapper extends BaseMapper<TzBaseEnterpriseI
List<String> selectCompanyBySupervisionOrgCode(String oldOrgCode);
void updateRedundantSupervisionOrgCodeUnit(String newOrgName, String newOrgCode, String oldOrgCode);
void updateRedundantSupervisionOrgCodeUnit(String companyLevel, String newOrgName, String newOrgCode, String oldOrgCode);
void updateRedundantSupervisionOrgCodeStatistics(String newOrgCode, String oldOrgCode);
......
......@@ -293,9 +293,11 @@
update tz_base_enterprise_info
set supervise_org_code = replace(supervise_org_code, #{oldOrgCode}, #{newOrgCode})
where supervise_org_code like concat(#{oldOrgCode}, '%');
update tz_base_enterprise_info
set org_code = replace(org_code, #{oldOrgCode}, #{newOrgCode})
where org_code like concat(#{oldOrgCode}, '%');
<if test="companyLevel != null and companyLevel != 'company'">
update tz_base_enterprise_info
set org_code = replace(org_code, #{oldOrgCode}, #{newOrgCode})
where org_code like concat(#{oldOrgCode}, '%');
</if>
update tzs_jg_vehicle_information
set org_branch_code = replace(org_branch_code, #{oldOrgCode}, #{newOrgCode})
......
......@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.tcm.biz.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
......@@ -150,14 +151,14 @@ public class HistoryDataDealServiceImpl {
orgCodeMap.forEach(map -> {
String newOrgCode = map.get("newOrgCode").toString();
String oldOrgCode = map.get("oldOrgCode").toString();
//1. 处理平台旧orgCode本身错误数据
//1. 查询新orgCode对应的监管单位信息
@SuppressWarnings("unchecked")
HashMap<String, Object> platformCompanyInfo = (HashMap<String, Object>) Privilege.companyClient.queryByOrgcode(oldOrgCode).getResult();
HashMap<String, Object> platformCompanyInfo = (HashMap<String, Object>) Privilege.companyClient.queryByOrgcode(newOrgCode).getResult();
CompanyModel parentModel = JSON.parseObject(JSON.toJSONString(platformCompanyInfo.get(TZSCommonConstant.PLATFORM_FEIGN_RESULT_KEY_COMPANY)), CompanyModel.class);
parentModel.setOrgCode(newOrgCode);
Privilege.companyClient.update(parentModel, parentModel.getSequenceNbr());
JSONObject modelMap = new JSONObject();
modelMap.put("newModel", JSON.toJSON(parentModel));
//2. 处理业务表旧orgCode错误数据
baseEnterpriseInfoService.refreshCompanyOrgCode(null, newOrgCode, oldOrgCode);
baseEnterpriseInfoService.refreshCompanyOrgCode(modelMap, newOrgCode, oldOrgCode);
});
return "success";
}
......
......@@ -1471,13 +1471,14 @@ public class TzBaseEnterpriseInfoServiceImpl
try {
if (!ValidationUtil.isEmpty(newOrgCode) && !ValidationUtil.isEmpty(oldOrgCode) && !newOrgCode.equals(oldOrgCode)) {
JSONObject newModel = (JSONObject) dataResult.get("newModel");
String companyLevel = newModel.getString("level");
// 1. 查询旧属地监管部门orgCode对应所有的公司
List<String> companySeqList = tzBaseEnterpriseInfoMapper.selectCompanyBySupervisionOrgCode(oldOrgCode);
// 2. 查询旧属地监管部门orgCode对应的所有设备
List<String> equipmentRecordList = tzBaseEnterpriseInfoMapper.selectEquipmentBySupervisionOrgCode(oldOrgCode);
log.info("start-查询旧属地监管部门orgCode对应的所有设备equipmentRecordList:{},companySeqList:{}", equipmentRecordList.size(), companySeqList.size());
// 3. 3.1 更新单位及业务表的监管单位orgCode
tzBaseEnterpriseInfoMapper.updateRedundantSupervisionOrgCodeUnit(newModel.getString("companyName"), newOrgCode, oldOrgCode);
tzBaseEnterpriseInfoMapper.updateRedundantSupervisionOrgCodeUnit(companyLevel, newModel.getString("companyName"), newOrgCode, oldOrgCode);
// 3.2 更新业务表统计表冗余的监管单位orgCode
tzBaseEnterpriseInfoMapper.updateRedundantSupervisionOrgCodeStatistics(newOrgCode, oldOrgCode);
log.info("end-查询旧属地监管部门orgCode对应的所有设备equipmentRecordList:{},companySeqList:{}", equipmentRecordList.size(), companySeqList.size());
......@@ -1487,11 +1488,6 @@ public class TzBaseEnterpriseInfoServiceImpl
updateEnterpriseInfoEs(newOrgCode, oldOrgCode, companySeqList);
// 6. 更新idx_biz_equipment_info es设备信息
updateEquipmentInfoEs(newOrgCode, oldOrgCode, equipmentRecordList);
// // 5. 发送数据刷新事件 - 内存分页处理
// // 处理企业数据
// publishDataRefreshEvents(companySeqList, DataRefreshEvent.DataType.enterprise, 1000);
// // 处理设备数据
// publishDataRefreshEvents(equipmentRecordList, DataRefreshEvent.DataType.equipment, 1000);
}
} catch (Exception e) {
willInfo("refreshCompanyOrgCode", dataResult, "orgCodeUpdate", e);
......
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