数据校验修改
This commit is contained in:
parent
1c509a9625
commit
f1e9ec8d78
@ -16,6 +16,7 @@ import com.zhgd.xmgl.modules.worker.entity.TeamInfo;
|
||||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||||
import com.zhgd.xmgl.modules.worker.mapper.EnterpriseInfoMapper;
|
||||
import com.zhgd.xmgl.modules.worker.service.impl.WorkerInfoServiceImpl;
|
||||
import com.zhgd.xmgl.modules.x.mapper.XzHikvisionCompareDataMapper;
|
||||
import com.zhgd.xmgl.modules.xz.entity.XzHikvisionSync;
|
||||
import com.zhgd.xmgl.modules.xz.mapper.XzHikvisionSyncMapper;
|
||||
import com.zhgd.xmgl.security.util.SecurityUtils;
|
||||
@ -63,6 +64,9 @@ public class AsyncHikvision {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private XzHikvisionSyncMapper xzHikvisionSyncMapper;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private XzHikvisionCompareDataMapper xzHikvisionCompareDataMapper;
|
||||
|
||||
public static Date getSyncLotNowOrSetIfNull() {
|
||||
Date now = ThreadLocalUtil.getNotNull().getDate("now");
|
||||
@ -281,6 +285,7 @@ public class AsyncHikvision {
|
||||
if (SecurityUtils.getUser() != null && SecurityUtils.getUser().getUserId() != null) {
|
||||
noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), msg, title, type);
|
||||
}
|
||||
hikvisionCall.compareRetryFail();
|
||||
}
|
||||
|
||||
@Async("carInfoExecutor")
|
||||
@ -294,15 +299,12 @@ public class AsyncHikvision {
|
||||
}
|
||||
|
||||
@Async("carInfoExecutor")
|
||||
public void deleteEnterpriseInfoForHikvision(String enterpriseId, String projectSn) {
|
||||
public void deleteEnterpriseInfoForHikvision(String enterpriseId, String projectSn, String enterpriseName) {
|
||||
try {
|
||||
hikvisionCall.deleteEnterpriseInfoForHikvision(enterpriseId, projectSn);
|
||||
hikvisionCall.deleteEnterpriseInfoForHikvision(enterpriseId, projectSn, enterpriseName);
|
||||
} catch (Exception e) {
|
||||
log.error("海康:", e);
|
||||
EnterpriseInfo enterpriseInfo = enterpriseInfoMapper.selectById(enterpriseId);
|
||||
if (enterpriseInfo != null) {
|
||||
sendNoticeForOrg(enterpriseInfo.getEnterpriseName(), e, "删除");
|
||||
}
|
||||
sendNoticeForOrg(enterpriseName, e, "删除");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -51,6 +51,8 @@ import com.zhgd.xmgl.modules.worker.mapper.WorkerInfoMapper;
|
||||
import com.zhgd.xmgl.modules.worker.service.IWorkerAttendancePresenceService;
|
||||
import com.zhgd.xmgl.modules.worker.service.IWorkerAttendanceService;
|
||||
import com.zhgd.xmgl.modules.worker.service.impl.WorkerAttendanceServiceImpl;
|
||||
import com.zhgd.xmgl.modules.x.entity.XzHikvisionCompareData;
|
||||
import com.zhgd.xmgl.modules.x.mapper.XzHikvisionCompareDataMapper;
|
||||
import com.zhgd.xmgl.modules.xz.entity.XzHikvisionSync;
|
||||
import com.zhgd.xmgl.modules.xz.mapper.XzHikvisionSyncMapper;
|
||||
import com.zhgd.xmgl.modules.xz.service.impl.XzHikvisionSyncServiceImpl;
|
||||
@ -97,6 +99,9 @@ public class HikvisionCall {
|
||||
CarInfoServiceImpl carInfoService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private XzHikvisionCompareDataMapper xzHikvisionCompareDataMapper;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private AiAnalyseHardWareAlarmRecordMapper aiAnalyseHardWareAlarmRecordMapper;
|
||||
@Lazy
|
||||
@Autowired
|
||||
@ -1077,6 +1082,11 @@ public class HikvisionCall {
|
||||
msg = "同步失败,组织名称:" + orgName + "。失败原因:" + rs;
|
||||
title += "失败";
|
||||
}
|
||||
if (success) {
|
||||
this.compareRetrySuc();
|
||||
} else {
|
||||
this.compareRetryFail();
|
||||
}
|
||||
if (SecurityUtils.getUser() != null && SecurityUtils.getUser().getUserId() != null) {
|
||||
noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), msg, title, type);
|
||||
}
|
||||
@ -1220,7 +1230,7 @@ public class HikvisionCall {
|
||||
Integer sendSuccessStatus = null;
|
||||
if (CollUtil.isEmpty(xzHikvisionSyncs)) {
|
||||
sendSuccessStatus = null;
|
||||
}else if (xzHikvisionSyncs.stream().allMatch(xzHikvisionSync1 -> Objects.equals(xzHikvisionSync1.getIsSuccess(), 1))) {
|
||||
} else if (xzHikvisionSyncs.stream().allMatch(xzHikvisionSync1 -> Objects.equals(xzHikvisionSync1.getIsSuccess(), 1))) {
|
||||
sendSuccessStatus = 1;
|
||||
} else if (xzHikvisionSyncs.stream().allMatch(xzHikvisionSync1 -> xzHikvisionSync1.getIsSuccess() == null)) {
|
||||
sendSuccessStatus = null;
|
||||
@ -1948,8 +1958,9 @@ public class HikvisionCall {
|
||||
*
|
||||
* @param enterpriseId
|
||||
* @param projectSn
|
||||
* @param enterpriseName
|
||||
*/
|
||||
public void deleteEnterpriseInfoForHikvision(String enterpriseId, String projectSn) throws Exception {
|
||||
public void deleteEnterpriseInfoForHikvision(String enterpriseId, String projectSn, String enterpriseName) throws Exception {
|
||||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, projectSn));
|
||||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||||
return;
|
||||
@ -1960,10 +1971,7 @@ public class HikvisionCall {
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("indexCodes", Arrays.asList(enterpriseId));
|
||||
String rs = HikvisionUtil.doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||||
EnterpriseInfo enterpriseInfo = enterpriseInfoMapper.selectById(enterpriseId);
|
||||
if (enterpriseInfo != null) {
|
||||
sendNoticeForOrg("删除组织到海康isc", rs, enterpriseInfo.getEnterpriseName());
|
||||
}
|
||||
sendNoticeForOrg("删除组织到海康isc", rs, enterpriseName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2157,11 +2165,7 @@ public class HikvisionCall {
|
||||
jo.put("pageSize", 100);
|
||||
jo.put("orgIndexCodes", orgIndex);
|
||||
String body = jo.toJSONString();
|
||||
String rs = HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||||
if (StringUtils.isBlank(rs)) {
|
||||
throw new OpenPromptException("海康网络异常");
|
||||
}
|
||||
return rs;
|
||||
return HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2585,5 +2589,26 @@ public class HikvisionCall {
|
||||
return JSON.parseObject(HikvisionUtil.doPost(host, path, JSON.toJSONString(param), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据校验重试失败
|
||||
*/
|
||||
public void compareRetryFail() {
|
||||
JSONObject tlJo = ThreadLocalUtil.getByKey(Cts.TL_XZ_HIKVISION_COMPARE_DATA_RETRY);
|
||||
if (tlJo != null) {
|
||||
XzHikvisionCompareData data = BeanUtil.toBean(tlJo, XzHikvisionCompareData.class);
|
||||
data.setSyncResult(2);
|
||||
xzHikvisionCompareDataMapper.updateById(data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据校验重试成功
|
||||
*/
|
||||
public void compareRetrySuc() {
|
||||
JSONObject tlJo = ThreadLocalUtil.getByKey(Cts.TL_XZ_HIKVISION_COMPARE_DATA_RETRY);
|
||||
if (tlJo != null) {
|
||||
XzHikvisionCompareData data = BeanUtil.toBean(tlJo, XzHikvisionCompareData.class);
|
||||
xzHikvisionCompareDataMapper.deleteById(data.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.zhgd.xmgl.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zhgd.xmgl.util.RequestIdUtil;
|
||||
import com.zhgd.xmgl.util.ThreadLocalUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
@ -18,6 +20,7 @@ public class MdcThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
|
||||
@Override
|
||||
public void execute(Runnable task) {
|
||||
Map<String, String> context = MDC.getCopyOfContextMap(); //复制主线程MDC
|
||||
JSONObject tlJo = ThreadLocalUtil.get();
|
||||
log.info("MDC异步多线程...");
|
||||
super.execute(() -> {
|
||||
if (null != context) {
|
||||
@ -25,11 +28,13 @@ public class MdcThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
|
||||
} else {
|
||||
RequestIdUtil.setRequestId(); //主线程没有MDC就自己生成一个
|
||||
}
|
||||
ThreadLocalUtil.set(tlJo);
|
||||
try {
|
||||
task.run();
|
||||
} finally {
|
||||
try {
|
||||
RequestIdUtil.clear();
|
||||
ThreadLocalUtil.remove();
|
||||
} catch (Exception e) {
|
||||
log.warn("MDC clear exception:{}", e.getMessage());
|
||||
}
|
||||
@ -43,6 +48,7 @@ public class MdcThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
|
||||
@Override
|
||||
public <T> Future<T> submit(Callable<T> task) {
|
||||
Map<String, String> context = MDC.getCopyOfContextMap(); //复制主线程MDC
|
||||
JSONObject tlJo = ThreadLocalUtil.get();
|
||||
log.info("MDC异步多线程...");
|
||||
return super.submit(() -> {
|
||||
if (null != context) {
|
||||
@ -50,11 +56,13 @@ public class MdcThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
|
||||
} else {
|
||||
RequestIdUtil.setRequestId(); //主线程没有MDC就自己生成一个
|
||||
}
|
||||
ThreadLocalUtil.set(tlJo);
|
||||
try {
|
||||
return task.call();
|
||||
} finally {
|
||||
try {
|
||||
RequestIdUtil.clear();
|
||||
ThreadLocalUtil.remove();
|
||||
} catch (Exception e) {
|
||||
log.warn("MDC clear exception:{}", e.getMessage());
|
||||
}
|
||||
|
||||
@ -18,4 +18,8 @@ public interface Cts {
|
||||
String SUCCESS = "success";
|
||||
String MSG = "msg";
|
||||
String ENTERPRISE_ID = "enterpriseId";
|
||||
/**
|
||||
* 数据校验重试是否成功
|
||||
*/
|
||||
String TL_XZ_HIKVISION_COMPARE_DATA_RETRY = "tl_xz_hikvision_compare_data";
|
||||
}
|
||||
|
||||
@ -252,9 +252,9 @@ public class EnterpriseInfoServiceImpl extends ServiceImpl<EnterpriseInfoMapper,
|
||||
for (XzUserToSupplier xzUserToSupplier : xzUserToSuppliers) {
|
||||
systemUserService.deleteTenantOrSupplier(String.valueOf(xzUserToSupplier.getUserId()), projectSn);
|
||||
}
|
||||
|
||||
EnterpriseInfo enterpriseInfo = baseMapper.selectById(enterpriseId);
|
||||
//同步海康
|
||||
asyncHikvision.deleteEnterpriseInfoForHikvision(enterpriseId, projectSn);
|
||||
asyncHikvision.deleteEnterpriseInfoForHikvision(enterpriseId, projectSn, enterpriseInfo.getEnterpriseName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -21,17 +21,13 @@ import com.zhgd.xmgl.modules.worker.service.impl.EnterpriseInfoServiceImpl;
|
||||
import com.zhgd.xmgl.modules.x.entity.XzHikvisionCompareData;
|
||||
import com.zhgd.xmgl.modules.x.mapper.XzHikvisionCompareDataMapper;
|
||||
import com.zhgd.xmgl.modules.x.service.IXzHikvisionCompareDataService;
|
||||
import com.zhgd.xmgl.util.HikvisionUtil;
|
||||
import com.zhgd.xmgl.util.MapBuilder;
|
||||
import com.zhgd.xmgl.util.PageUtil;
|
||||
import com.zhgd.xmgl.util.RefUtil;
|
||||
import com.zhgd.xmgl.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -124,6 +120,7 @@ public class XzHikvisionCompareDataServiceImpl extends ServiceImpl<XzHikvisionCo
|
||||
List<String> idList = StrUtil.split(ids, ",");
|
||||
for (String id : idList) {
|
||||
XzHikvisionCompareData data = baseMapper.selectById(id);
|
||||
ThreadLocalUtil.addInKeyIfNotExist(Cts.TL_XZ_HIKVISION_COMPARE_DATA_RETRY, data);
|
||||
ProjectInfoExtVo projectInfoBySn = projectService.getProjectInfoBySn(new MapBuilder<String, Object>().put(Cts.PROJECT_SN, data.getProjectSn()).build());
|
||||
EnterpriseInfo enterpriseInfo = BeanUtil.toBean(enterpriseInfoService.getEnterpriseInfoById(new MapBuilder<String, Object>()
|
||||
.put(Cts.PROJECT_SN, data.getProjectSn()).put(Cts.ENTERPRISE_ID, data.getUniqueId()).build()), EnterpriseInfo.class);
|
||||
@ -133,7 +130,7 @@ public class XzHikvisionCompareDataServiceImpl extends ServiceImpl<XzHikvisionCo
|
||||
//同步海康
|
||||
asyncHikvision.editEnterpriseInfoForHikvision(enterpriseInfo);
|
||||
} else {
|
||||
asyncHikvision.deleteEnterpriseInfoForHikvision(data.getUniqueId(), data.getProjectSn());
|
||||
asyncHikvision.deleteEnterpriseInfoForHikvision(data.getUniqueId(), data.getProjectSn(), enterpriseInfo.getEnterpriseName());
|
||||
}
|
||||
} else if (data.getExistIsc() == 0 && data.getExistMyPlatform() == 1) {
|
||||
//查询id是否存在isc,存在就更新,不存在就新增
|
||||
|
||||
@ -63,8 +63,8 @@ public class HikvisionUtil {
|
||||
if (Objects.equals(code, "0")) {
|
||||
return rsJo.getJSONObject("data");
|
||||
} else {
|
||||
log.error("海康解析结果失败:{}", rs);
|
||||
return null;
|
||||
log.error("海康返回错误码:{}", rs);
|
||||
throw new OpenAlertException("海康返回错误码");
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ public class HikvisionUtil {
|
||||
if (Objects.equals(code, "0")) {
|
||||
return rsJo.getJSONObject("data");
|
||||
} else {
|
||||
log.error("海康解析结果失败:{}", rsJo.toJSONString());
|
||||
log.error("海康返回错误码:{}", rsJo.toJSONString());
|
||||
throw new OpenAlertException("海康调用失败");
|
||||
}
|
||||
}
|
||||
@ -93,7 +93,7 @@ public class HikvisionUtil {
|
||||
if (Objects.equals(code, "0")) {
|
||||
return rsJo.getJSONArray("data");
|
||||
} else {
|
||||
log.error("海康解析结果失败:{}", rs);
|
||||
log.error("海康返回错误码:{}", rs);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,16 +4,34 @@ import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class ThreadLocalUtil {
|
||||
|
||||
private static final ThreadLocal<JSONObject> threadLocal = new ThreadLocal<>();
|
||||
|
||||
private ThreadLocalUtil() {
|
||||
|
||||
}
|
||||
|
||||
private static final ThreadLocal<JSONObject> threadLocal = new ThreadLocal<>();
|
||||
|
||||
public static void set(JSONObject str) {
|
||||
threadLocal.set(str);
|
||||
}
|
||||
|
||||
public static JSONObject get() {
|
||||
return threadLocal.get();
|
||||
}
|
||||
|
||||
public static JSONObject getNotNull() {
|
||||
if (get() == null) {
|
||||
threadLocal.set(new JSONObject());
|
||||
}
|
||||
return get();
|
||||
}
|
||||
|
||||
public static JSONObject getByKey(String key) {
|
||||
if (get() == null) {
|
||||
return null;
|
||||
}
|
||||
return get().getJSONObject(key);
|
||||
}
|
||||
|
||||
public static void add(JSONObject str) {
|
||||
if (get() == null) {
|
||||
threadLocal.set(str);
|
||||
@ -28,22 +46,19 @@ public class ThreadLocalUtil {
|
||||
add(jo);
|
||||
}
|
||||
|
||||
public static JSONObject get() {
|
||||
return threadLocal.get();
|
||||
public static void addInKeyIfNotExist(String key, Object val) {
|
||||
JSONObject jo = getNotNull();
|
||||
if (!jo.containsKey(key)) {
|
||||
jo = new JSONObject();
|
||||
jo.put(key, val);
|
||||
add(jo);
|
||||
}
|
||||
|
||||
public static JSONObject getNotNull() {
|
||||
if (get() == null) {
|
||||
threadLocal.set(new JSONObject());
|
||||
}
|
||||
return get();
|
||||
}
|
||||
|
||||
public static void remove() {
|
||||
threadLocal.remove();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("jo", "0");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user