异常消息定时任务处理
This commit is contained in:
parent
b49b7d63c7
commit
8dd1bf5ed8
|
|
@ -65,4 +65,14 @@ public interface IMDErrorInfoMapper {
|
|||
* @date 2025/11/17 13:28
|
||||
*/
|
||||
List<String> getErrorInfoByTable(ErrorInfo errorQueryDto);
|
||||
|
||||
/**
|
||||
* 根据业务id和来源表查询已存在的异常消息
|
||||
* @param businessIds
|
||||
* @param tableName
|
||||
* @return List<ErrorInfo>
|
||||
* @author cwchen
|
||||
* @date 2025/11/17 14:29
|
||||
*/
|
||||
List<ErrorInfo> getErrorInfoByBusiness(@Param("list") List<Long> businessIds,@Param("tableName") String tableName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,4 +63,14 @@ public interface IMDErrorInfoService {
|
|||
* @date 2025/11/17 13:28
|
||||
*/
|
||||
List<String> getErrorInfoByTable(ErrorInfo errorQueryDto);
|
||||
|
||||
/**
|
||||
* 根据业务id和来源表查询已存在的异常消息
|
||||
* @param businessIds
|
||||
* @param tbEnterprise
|
||||
* @return List<ErrorInfo>
|
||||
* @author cwchen
|
||||
* @date 2025/11/17 14:28
|
||||
*/
|
||||
List<ErrorInfo> getErrorInfoByBusiness(List<Long> businessIds, String tbEnterprise);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,11 +84,18 @@ public class MDEnterpriseServiceImpl implements IMDEnterpriseService {
|
|||
List<EnterpriseVo.EnterpriseDetailVo> list = Optional.ofNullable(imdEnterpriseMapper.queryExpiredCertificate()).orElse(new ArrayList<>());
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
for (EnterpriseVo.EnterpriseDetailVo vo : list) {
|
||||
// 身份证
|
||||
ErrorInfo errorInfo = CertificateUtil.checkCertificateState(vo.getIdCardStartDate(), CertificateConstants.NATIONAL_EMBLEM_ID_CARD,
|
||||
vo.getEnterpriseId(), vo.getEnterpriseId(), TableConstants.TB_ENTERPRISE);
|
||||
// 营业执照
|
||||
ErrorInfo errorInfo2 = CertificateUtil.checkCertificateState(vo.getBusinessTerm(), CertificateConstants.BUSINESS_LICENSE,
|
||||
vo.getEnterpriseId(), vo.getEnterpriseId(), TableConstants.TB_ENTERPRISE);
|
||||
if(Objects.nonNull(errorInfo)){
|
||||
errorInfos.add(errorInfo);
|
||||
}
|
||||
if(Objects.nonNull(errorInfo2)){
|
||||
errorInfos.add(errorInfo2);
|
||||
}
|
||||
}
|
||||
}
|
||||
return errorInfos;
|
||||
|
|
|
|||
|
|
@ -49,4 +49,9 @@ public class MDErrorInfoServiceImpl implements IMDErrorInfoService {
|
|||
public List<String> getErrorInfoByTable(ErrorInfo errorQueryDto) {
|
||||
return imdErrorInfoMapper.getErrorInfoByTable(errorQueryDto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErrorInfo> getErrorInfoByBusiness(List<Long> businessIds, String tableName) {
|
||||
return imdErrorInfoMapper.getErrorInfoByBusiness(businessIds,tableName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,9 +146,10 @@
|
|||
|
||||
<!--查询主体库过期证件-->
|
||||
<select id="queryExpiredCertificate" resultType="com.bonus.common.domain.mainDatabase.vo.EnterpriseVo$EnterpriseDetailVo">
|
||||
SELECT enterprise_id AS enterpriseId,
|
||||
id_card_start_date AS idCardStartDate
|
||||
FROM tb_enterprise
|
||||
WHERE del_flag = '0'
|
||||
SELECT te.enterprise_id AS enterpriseId,
|
||||
te.id_card_start_date AS idCardStartDate,
|
||||
te.business_term AS businessTerm
|
||||
FROM tb_enterprise te
|
||||
WHERE te.del_flag = '0'
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -63,4 +63,15 @@
|
|||
<select id="getErrorInfoByTable" resultType="java.lang.String">
|
||||
SELECT error_content FROM tb_error_info WHERE source_table = #{sourceTable} AND business_id = #{businessId}
|
||||
</select>
|
||||
|
||||
<!--根据业务id和来源表查询已存在的异常消息-->
|
||||
<select id="getErrorInfoByBusiness" resultType="com.bonus.common.domain.mainDatabase.po.ErrorInfo">
|
||||
SELECT business_id AS businessId,
|
||||
business_type AS businessType,
|
||||
source_table AS sourceTable
|
||||
FROM tb_error_info WHERE source_table = #{tableName} AND business_id IN
|
||||
<foreach collection="list" open="(" close=")" item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.bonus.quartz.task;
|
||||
|
||||
import com.bonus.common.constant.TableConstants;
|
||||
import com.bonus.common.domain.mainDatabase.po.ErrorInfo;
|
||||
import com.bonus.mainDataBase.service.IMDEnterpriseService;
|
||||
import com.bonus.mainDataBase.service.IMDErrorInfoService;
|
||||
|
|
@ -9,8 +10,8 @@ import org.apache.commons.collections4.CollectionUtils;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @className:Scan
|
||||
|
|
@ -36,17 +37,131 @@ public class ScanCertificateTask {
|
|||
log.info("开始扫描证件是否过期");
|
||||
List<ErrorInfo> totalList = new ArrayList<>();
|
||||
// 主体库
|
||||
List<ErrorInfo> enterpriselist = imdEnterpriseService.queryExpiredCertificate();
|
||||
if(CollectionUtils.isNotEmpty(enterpriselist)) {
|
||||
totalList.addAll(enterpriselist);
|
||||
List<ErrorInfo> enterpriseErrorInfos = handleDataByType(TableConstants.TB_ENTERPRISE);
|
||||
if (CollectionUtils.isEmpty(enterpriseErrorInfos)) {
|
||||
totalList.addAll(enterpriseErrorInfos);
|
||||
}
|
||||
// 人员库
|
||||
List<ErrorInfo> personnellist = imdPersonnelService.queryExpiredCertificate();
|
||||
if(CollectionUtils.isNotEmpty(personnellist)) {
|
||||
totalList.addAll(personnellist);
|
||||
// 人员证件库
|
||||
List<ErrorInfo> personnelErrorInfos = handleDataByType(TableConstants.TB_PERSONNEL_CERTIFICATE);
|
||||
if (CollectionUtils.isEmpty(personnelErrorInfos)) {
|
||||
totalList.addAll(personnelErrorInfos);
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(totalList)) {
|
||||
if (CollectionUtils.isNotEmpty(totalList)) {
|
||||
imdErrorInfoService.addErrorInfo(totalList);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ErrorInfo> handleDataByType(String type) {
|
||||
List<ErrorInfo> errorInfos = new ArrayList<>();
|
||||
switch (type) {
|
||||
case TableConstants.TB_ENTERPRISE: // 主体库
|
||||
List<ErrorInfo> enterpriseList = handleEnterpriseErrorInfo();
|
||||
errorInfos.addAll(enterpriseList);
|
||||
break;
|
||||
case TableConstants.TB_PERSONNEL_CERTIFICATE: // 人员证件
|
||||
List<ErrorInfo> personnelCertificateList = handlePersonnelCertificateErrorInfo();
|
||||
errorInfos.addAll(personnelCertificateList);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return errorInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理主体库证件过期异常数据
|
||||
*
|
||||
* @return List<ErrorInfo>
|
||||
* @author cwchen
|
||||
* @date 2025/11/17 14:41
|
||||
*/
|
||||
public List<ErrorInfo> handleEnterpriseErrorInfo() {
|
||||
List<ErrorInfo> expiredList = imdEnterpriseService.queryExpiredCertificate();
|
||||
return filterNotExistErrorInfo(expiredList, TableConstants.TB_ENTERPRISE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理人员证件过期异常数据
|
||||
*
|
||||
* @return List<ErrorInfo>
|
||||
* @author cwchen
|
||||
* @date 2025/11/17 14:50
|
||||
*/
|
||||
private List<ErrorInfo> handlePersonnelCertificateErrorInfo() {
|
||||
List<ErrorInfo> expiredList = imdPersonnelService.queryExpiredCertificate();
|
||||
return filterNotExistErrorInfo(expiredList, TableConstants.TB_PERSONNEL_CERTIFICATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公共方法:过滤掉已存在的异常信息
|
||||
*
|
||||
* @param expiredList 过期证件列表
|
||||
* @param sourceTable 来源表
|
||||
* @return 不存在的异常信息列表
|
||||
*/
|
||||
private List<ErrorInfo> filterNotExistErrorInfo(List<ErrorInfo> expiredList, String sourceTable) {
|
||||
if (CollectionUtils.isEmpty(expiredList)) {
|
||||
return Collections.emptyList(); // 返回空集合而不是null,避免NPE
|
||||
}
|
||||
|
||||
// 提取业务ID并去重
|
||||
List<Long> businessIds = extractBusinessIds(expiredList);
|
||||
if (CollectionUtils.isEmpty(businessIds)) {
|
||||
return expiredList; // 如果没有有效的businessId,返回所有记录
|
||||
}
|
||||
|
||||
// 查询已存在的异常信息
|
||||
List<ErrorInfo> existErrorInfo = imdErrorInfoService.getErrorInfoByBusiness(businessIds, sourceTable);
|
||||
|
||||
// 筛选出不存在的记录
|
||||
return filterNotExistRecords(expiredList, existErrorInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从错误信息列表中提取业务ID并去重
|
||||
*/
|
||||
private List<Long> extractBusinessIds(List<ErrorInfo> errorInfoList) {
|
||||
return errorInfoList.stream()
|
||||
.map(ErrorInfo::getBusinessId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选出不存在的记录
|
||||
*/
|
||||
private List<ErrorInfo> filterNotExistRecords(List<ErrorInfo> sourceList, List<ErrorInfo> existList) {
|
||||
if (CollectionUtils.isEmpty(existList)) {
|
||||
return new ArrayList<>(sourceList); // 如果没有已存在的记录,返回所有源记录
|
||||
}
|
||||
|
||||
// 创建存在的记录的键值集合
|
||||
Set<String> existKeys = buildExistKeys(existList);
|
||||
|
||||
// 筛选出不存在的记录
|
||||
return sourceList.stream()
|
||||
.filter(item -> !existKeys.contains(buildKey(item)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建已存在记录的键集合
|
||||
*/
|
||||
private Set<String> buildExistKeys(List<ErrorInfo> existList) {
|
||||
return existList.stream()
|
||||
.map(this::buildKey)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建记录的唯一键
|
||||
*/
|
||||
private String buildKey(ErrorInfo errorInfo) {
|
||||
return String.join("|",
|
||||
String.valueOf(errorInfo.getBusinessId()),
|
||||
Objects.toString(errorInfo.getBusinessType(), ""),
|
||||
Objects.toString(errorInfo.getSourceTable(), "")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue