diff --git a/src/main/java/com/zhgd/xmgl/async/AsyncHikvision.java b/src/main/java/com/zhgd/xmgl/async/AsyncHikvision.java index 6c661767b..a68fce937 100644 --- a/src/main/java/com/zhgd/xmgl/async/AsyncHikvision.java +++ b/src/main/java/com/zhgd/xmgl/async/AsyncHikvision.java @@ -5,6 +5,7 @@ import com.zhgd.jeecg.common.execption.OpenPromptException; import com.zhgd.jeecg.common.util.SpringContextUtils; import com.zhgd.jeecg.common.util.pass.HttpUtils; import com.zhgd.xmgl.call.HikvisionCall; +import com.zhgd.xmgl.constant.Cts; import com.zhgd.xmgl.modules.basicdata.service.INoticeService; import com.zhgd.xmgl.modules.car.entity.CarInfo; import com.zhgd.xmgl.modules.project.entity.Project; @@ -17,11 +18,11 @@ 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.xz.mapper.XzHikvisionCompareDataMapper; -import com.zhgd.xmgl.modules.xz.service.impl.XzHikvisionCompareDataServiceImpl; import com.zhgd.xmgl.modules.xz.entity.XzHikvisionSync; +import com.zhgd.xmgl.modules.xz.mapper.XzHikvisionCompareDataMapper; import com.zhgd.xmgl.modules.xz.mapper.XzHikvisionSyncMapper; -import com.zhgd.xmgl.security.util.SecurityUtils; +import com.zhgd.xmgl.modules.xz.service.impl.XzHikvisionCompareDataServiceImpl; +import com.zhgd.xmgl.security.entity.UserInfo; import com.zhgd.xmgl.util.ThreadLocalUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; @@ -148,8 +149,8 @@ public class AsyncHikvision { } else { msg = "同步失败,人员名称:" + workerInfo.getWorkerName() + ",身份证号:" + workerInfo.getIdCard() + "。失败原因:下发异常"; } - if (SecurityUtils.getUser() != null && SecurityUtils.getUser().getUserId() != null) { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), msg, title, type); + if (ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class) != null) { + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), msg, title, type); } hikvisionCall.updateAllFailStatusIfNullByNow(workerInfo.getProjectSn(), workerInfo.getId(), 1, getSyncTimeWithInitIfAbsent(1, workerInfo.getId())); } @@ -215,8 +216,8 @@ public class AsyncHikvision { } else { msg = "同步失败,车牌号:" + carInfo.getCarNumber() + "。失败原因:下发异常"; } - if (SecurityUtils.getUser() != null && SecurityUtils.getUser().getUserId() != null) { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), msg, title, type); + if (ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class) != null) { + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), msg, title, type); } hikvisionCall.updateAllFailStatusIfNullByNow(carInfo.getProjectSn(), carInfo.getId(), 4, getSyncTimeWithInitIfAbsent(2, carInfo.getId())); } @@ -287,8 +288,8 @@ public class AsyncHikvision { } else { msg = "同步失败,组织名称:" + name + "。失败原因:下发异常"; } - if (SecurityUtils.getUser() != null && SecurityUtils.getUser().getUserId() != null) { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), msg, title, type); + if (ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class) != null) { + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), msg, title, type); } xzHikvisionCompareDataService.compareRetryFail(); } @@ -406,9 +407,9 @@ public class AsyncHikvision { } } catch (Exception e) { if (HttpUtils.isTimeOut(e)) { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), "失败原因:平台连接isc网络异常", "人员下发设备提醒", "1"); + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), "失败原因:平台连接isc网络异常", "人员下发设备提醒", "1"); } else { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), e.getMessage(), "人员下发设备提醒", "1"); + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), e.getMessage(), "人员下发设备提醒", "1"); } hikvisionCall.updateAllFailStatusIfNullByNowForAuth(workerInfo.getProjectSn(), workerInfo.getId(), 3, 1, getSyncTimeWithInitIfAbsent(1, workerInfo.getId())); return; @@ -427,8 +428,8 @@ public class AsyncHikvision { failSbStr = "下发权限失败:" + failSbStr; msg += failSbStr; } - if (SecurityUtils.getUser() != null && SecurityUtils.getUser().getUserId() != null) { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), StringUtils.substring(msg, 0, msg.length() - 1), title, type); + if (ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class) != null) { + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), StringUtils.substring(msg, 0, msg.length() - 1), title, type); } hikvisionCall.updateAllFailStatusIfNullByNowForAuth(workerInfo.getProjectSn(), workerInfo.getId(), 3, 1, getSyncTimeWithInitIfAbsent(1, workerInfo.getId())); } catch (Exception e) { @@ -469,9 +470,9 @@ public class AsyncHikvision { } } catch (Exception e) { if (HttpUtils.isTimeOut(e)) { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), "网络异常", "人员下发设备提醒", "1"); + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), "网络异常", "人员下发设备提醒", "1"); } else { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), e.getMessage(), "人员下发设备提醒", "1"); + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), e.getMessage(), "人员下发设备提醒", "1"); } hikvisionCall.updateAllFailStatusIfNullByNowForAuth(workerInfo.getProjectSn(), workerInfo.getId(), 3, 3, getSyncTimeWithInitIfAbsent(1, workerInfo.getId())); return; @@ -490,8 +491,8 @@ public class AsyncHikvision { failSbStr = "移除权限失败:" + failSbStr; msg += failSbStr; } - if (SecurityUtils.getUser() != null && SecurityUtils.getUser().getUserId() != null) { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), StringUtils.substring(msg, 0, msg.length() - 1), title, type); + if (ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class) != null) { + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), StringUtils.substring(msg, 0, msg.length() - 1), title, type); } hikvisionCall.updateAllFailStatusIfNullByNowForAuth(workerInfo.getProjectSn(), workerInfo.getId(), 3, 3, getSyncTimeWithInitIfAbsent(1, workerInfo.getId())); } catch (Exception e) { diff --git a/src/main/java/com/zhgd/xmgl/call/HikvisionCall.java b/src/main/java/com/zhgd/xmgl/call/HikvisionCall.java index cad69e0f7..f7235ecb7 100644 --- a/src/main/java/com/zhgd/xmgl/call/HikvisionCall.java +++ b/src/main/java/com/zhgd/xmgl/call/HikvisionCall.java @@ -61,7 +61,7 @@ import com.zhgd.xmgl.modules.xz.mapper.XzHikvisionCompareDataMapper; import com.zhgd.xmgl.modules.xz.mapper.XzHikvisionSyncMapper; import com.zhgd.xmgl.modules.xz.service.IXzHikvisionCompareDataService; import com.zhgd.xmgl.modules.xz.service.impl.XzHikvisionSyncServiceImpl; -import com.zhgd.xmgl.security.util.SecurityUtils; +import com.zhgd.xmgl.security.entity.UserInfo; import com.zhgd.xmgl.util.*; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -1078,8 +1078,8 @@ public class HikvisionCall { updateFailStatusByNow(carInfo.getProjectSn(), carInfo.getId(), type, operate, AsyncHikvision.getSyncTime(), null); } if (isNotice) { - if (SecurityUtils.getUser() != null && SecurityUtils.getUser().getUserId() != null) { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), msg, title, "24"); + if (ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class) != null) { + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), msg, title, "24"); } else if (carInfo.getUserIds() != null && carInfo.getUserIds().size() > 0) { for (String userId : carInfo.getUserIds()) { noticeService.addUserNotice(Long.valueOf(userId), msg, title, "24"); @@ -1125,8 +1125,8 @@ public class HikvisionCall { } else { xzHikvisionCompareDataService.compareRetryFail(); } - if (SecurityUtils.getUser() != null && SecurityUtils.getUser().getUserId() != null) { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), msg, title, type); + if (ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class) != null) { + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), msg, title, type); } } @@ -1192,8 +1192,8 @@ public class HikvisionCall { updateFailStatusByNow(workerInfo.getProjectSn(), workerInfo.getId(), type, operate, AsyncHikvision.getSyncTime(), null); xzHikvisionCompareDataService.compareRetryFail(); } - if (SecurityUtils.getUser() != null && SecurityUtils.getUser().getUserId() != null) { - noticeService.addUserNotice(SecurityUtils.getUser().getUserId(), msg, title, noticeType); + if (ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class) != null) { + noticeService.addUserNotice(ThreadLocalUtil.getByKey(Cts.TL_AUTH_USER, UserInfo.class).getUserId(), msg, title, noticeType); } } diff --git a/src/main/java/com/zhgd/xmgl/constant/Cts.java b/src/main/java/com/zhgd/xmgl/constant/Cts.java index e2e3a0082..527694ec5 100644 --- a/src/main/java/com/zhgd/xmgl/constant/Cts.java +++ b/src/main/java/com/zhgd/xmgl/constant/Cts.java @@ -44,4 +44,5 @@ public interface Cts { String RESERVATION_TYPE = "reservationType"; String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; String YYYY_MM_DD = "yyyy-MM-dd"; + String TL_AUTH_USER = "authUser"; } diff --git a/src/main/java/com/zhgd/xmgl/security/RequestIdFilter.java b/src/main/java/com/zhgd/xmgl/security/RequestIdFilter.java index 1b13038b4..4da2c0b60 100644 --- a/src/main/java/com/zhgd/xmgl/security/RequestIdFilter.java +++ b/src/main/java/com/zhgd/xmgl/security/RequestIdFilter.java @@ -1,6 +1,7 @@ package com.zhgd.xmgl.security; import com.zhgd.xmgl.constant.Cts; +import com.zhgd.xmgl.security.util.SecurityUtils; import com.zhgd.xmgl.util.RequestIdUtil; import com.zhgd.xmgl.util.ThreadLocalUtil; import lombok.extern.slf4j.Slf4j; @@ -17,6 +18,7 @@ public class RequestIdFilter implements Filter { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { RequestIdUtil.setRequestId("-i"); ThreadLocalUtil.addInKey(Cts.TL_IS_FROM_WEB, true); + ThreadLocalUtil.addInKey(Cts.TL_AUTH_USER, SecurityUtils.getUser()); log.info("接口开始..."); try { filterChain.doFilter(servletRequest, servletResponse);