|
@@ -0,0 +1,160 @@
|
|
|
+package com.dragoninfo.dcuc.auth.audit.service.log;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.dragoninfo.dcuc.auth.audit.config.AuditConfig;
|
|
|
+import com.dragoninfo.dcuc.auth.audit.constance.AuditConstance;
|
|
|
+import com.dragoninfo.dcuc.auth.audit.dto.AuthorizeHandlerDto;
|
|
|
+import com.dragoninfo.dcuc.auth.audit.dto.AuthorizeLogDto;
|
|
|
+import com.dragoninfo.dcuc.auth.audit.dto.AuthorizeObjectDto;
|
|
|
+import com.dragoninfo.dcuc.auth.audit.dto.AuthorizeSubjectDto;
|
|
|
+import com.dragoninfo.dcuc.auth.audit.enums.AuthorizeTypeEnum;
|
|
|
+import com.dragonsoft.auditlog.collection.qmtj.LogSendComponent;
|
|
|
+import com.dragonsoft.auditlog.collection.qmtj.pojo.req.AuthBusLog;
|
|
|
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author mazq
|
|
|
+ * @date 2021/7/28
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class QmAuditPushService {
|
|
|
+
|
|
|
+ private static final String AUTH_TYPE_KEY = "AUTH_TYPE_KEY";
|
|
|
+
|
|
|
+ private static final String OPERATE_TYPE_KEY = "OPERATE_TYPE_KEY";
|
|
|
+
|
|
|
+ ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("qm-push-service-pool-").build();
|
|
|
+
|
|
|
+ ThreadPoolExecutor executor = new ThreadPoolExecutor(
|
|
|
+ 20,
|
|
|
+ 50,
|
|
|
+ 5*60,
|
|
|
+ TimeUnit.SECONDS,
|
|
|
+ new LinkedBlockingQueue<>(2000),
|
|
|
+ threadFactory);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LogSendComponent logSendComponent;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AuditConfig config;
|
|
|
+
|
|
|
+
|
|
|
+ public void pushAuthorizeLog(AuthorizeLogDto authorizeLogDto) {
|
|
|
+ Boolean qmEnabled = config.getQmEnabled();
|
|
|
+ if(null == qmEnabled || !qmEnabled) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ executor.submit(()-> pushLogMessage(authorizeLogDto));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void pushLogMessage(AuthorizeLogDto authorizeLogDto) {
|
|
|
+ String sysId = config.getSysId();
|
|
|
+ String logType = AuditConstance.AUDIT_LOG_TYPE_SQ;
|
|
|
+ List<AuthBusLog> busLogs = getAuthBusLog(authorizeLogDto);
|
|
|
+ if(CollectionUtils.isNotEmpty(busLogs)) {
|
|
|
+ logSendComponent.sendAuthBusLog(sysId, logType, busLogs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<AuthBusLog> getAuthBusLog(AuthorizeLogDto authorizeLogDto) {
|
|
|
+ String authorizeType = authorizeLogDto.getAuthorizeType();
|
|
|
+ AuthorizeTypeEnum typeEnum = AuthorizeTypeEnum.getByAuthorizeType(authorizeType);
|
|
|
+ if(null == typeEnum) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ Map<String, String> map = getOperateAndAuth(typeEnum);
|
|
|
+ String authType = map.get(AUTH_TYPE_KEY);
|
|
|
+ String operateType = map.get(OPERATE_TYPE_KEY);
|
|
|
+ return constructBusLogs(authorizeLogDto, authType ,operateType);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> getOperateAndAuth(AuthorizeTypeEnum typeEnum) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ switch (typeEnum) {
|
|
|
+ case GNSQ:
|
|
|
+ map.put(AUTH_TYPE_KEY, AuditConstance.AUDIT_AUTH_TYPE_GNSQ);
|
|
|
+ map.put(OPERATE_TYPE_KEY, AuditConstance.AUDIT_OPERATE_TYPE_SQ);
|
|
|
+ break;
|
|
|
+ case FWSQ:
|
|
|
+ map.put(AUTH_TYPE_KEY, AuditConstance.AUDIT_AUTH_TYPE_FWSQ);
|
|
|
+ map.put(OPERATE_TYPE_KEY, AuditConstance.AUDIT_OPERATE_TYPE_SQ);
|
|
|
+ break;
|
|
|
+ case SJSQ:
|
|
|
+ map.put(AUTH_TYPE_KEY, AuditConstance.AUDIT_AUTH_TYPE_SJSQ);
|
|
|
+ map.put(OPERATE_TYPE_KEY, AuditConstance.AUDIT_OPERATE_TYPE_SQ);
|
|
|
+ break;
|
|
|
+ case GNXQ:
|
|
|
+ map.put(AUTH_TYPE_KEY, AuditConstance.AUDIT_AUTH_TYPE_GNSQ);
|
|
|
+ map.put(OPERATE_TYPE_KEY, AuditConstance.AUDIT_OPERATE_TYPE_XQ);
|
|
|
+ break;
|
|
|
+ case FWXQ:
|
|
|
+ map.put(AUTH_TYPE_KEY, AuditConstance.AUDIT_AUTH_TYPE_FWSQ);
|
|
|
+ map.put(OPERATE_TYPE_KEY, AuditConstance.AUDIT_OPERATE_TYPE_XQ);
|
|
|
+ break;
|
|
|
+ case SJXQ:
|
|
|
+ map.put(AUTH_TYPE_KEY, AuditConstance.AUDIT_AUTH_TYPE_SJSQ);
|
|
|
+ map.put(OPERATE_TYPE_KEY, AuditConstance.AUDIT_OPERATE_TYPE_XQ);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<AuthBusLog> constructBusLogs(AuthorizeLogDto authorizeLogDto, String authType, String operateType) {
|
|
|
+ List<AuthBusLog> list = new ArrayList<>();
|
|
|
+ if(StringUtils.isAnyBlank(authType, operateType)) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ String timeStr = getTimeStr(authorizeLogDto);
|
|
|
+ AuthorizeHandlerDto handlerDto = authorizeLogDto.getAuthorizeHandlers().get(0);
|
|
|
+ List<AuthorizeSubjectDto> subjectDtos = authorizeLogDto.getAuthorizeSubjects();
|
|
|
+ List<AuthorizeObjectDto> objectDtos = authorizeLogDto.getAuthorizeObjects();
|
|
|
+ for (AuthorizeSubjectDto subjectDto : subjectDtos) {
|
|
|
+ AuthBusLog authBusLog = new AuthBusLog();
|
|
|
+ authBusLog.setAuthType(authType);
|
|
|
+ //设置操作者
|
|
|
+ authBusLog.setOperateType(operateType);
|
|
|
+ String operateUserId = handlerDto.getHandlerId();
|
|
|
+ authBusLog.setOperateUserId(operateUserId);
|
|
|
+ authBusLog.setOperateUserName(handlerDto.getHandlerName());
|
|
|
+ authBusLog.setOperateUserIdcard(handlerDto.getHandlerIdcard());
|
|
|
+ authBusLog.setOperateOrgCode(handlerDto.getHandlerOrgCode());
|
|
|
+ authBusLog.setOperateTime(timeStr);
|
|
|
+ //设置授权对象
|
|
|
+ authBusLog.setUserId(subjectDto.getSubjectId());
|
|
|
+ authBusLog.setUserName(subjectDto.getSubjectName());
|
|
|
+ String roleNames = objectDtos
|
|
|
+ .stream()
|
|
|
+ .map(AuthorizeObjectDto::getObjectName)
|
|
|
+ .collect(Collectors.joining(StrUtil.COMMA));
|
|
|
+ //设置角色名称
|
|
|
+ authBusLog.setRoleNames(roleNames);
|
|
|
+ authBusLog.setApproveResult(authorizeLogDto.getState());
|
|
|
+ list.add(authBusLog);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getTimeStr(AuthorizeLogDto authorizeLogDto) {
|
|
|
+ Date createTime = authorizeLogDto.getCreateTime();
|
|
|
+ String timeStr = "";
|
|
|
+ if(null != createTime) {
|
|
|
+ long time = createTime.getTime();
|
|
|
+ timeStr = String.valueOf(time);
|
|
|
+ }
|
|
|
+ return timeStr;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|