# JournalPostProcessor.java

    package cloud.wconnect.finance.businesstask.chargeback;

    import cloud.wconnect.commonlib.businesstask.postprocessor.IReportMissedPostProcessor;
    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.cons.ReportImportResultCons;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.pojo.dto.ReportMissedDTO;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.finance.cons.BusinessEnum;
    import cloud.wconnect.finance.cons.EventSubjectEnum;
    import cloud.wconnect.finance.entity.chargeback.CbJournalImportLog;
    import cloud.wconnect.finance.service.chargeback.ICbJournalImportLogService;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;

    import java.util.Objects;

    /**
     * journal 报告缺失后续逻辑处理
     *
     * @author yyt
     * 2023/9/8
     */
    @Component
    public class JournalPostProcessor implements IReportMissedPostProcessor {

        @Autowired
        private ICbJournalImportLogService cbJournalImportLogService;

        private static final String SUBJECT = EventSubjectEnum.JOURNAL_BY_CASHIER_AND_TRANSACTION_CODE_SERVICE.getSubject();

        private static final String BUSINESS = BusinessEnum.CHARGEBACK_JOURNAL.getBusiness();

        @Override
        public boolean supports(ReportMissedDTO reportMissedDTO) {
            return reportMissedDTO.getBusiness().equals(BUSINESS) && reportMissedDTO.getSubject().equals(SUBJECT);
        }

        @Override
        public void afterPostProcess(ReportMissedDTO reportMissedDTO) {
            PropertyDTO property = reportMissedDTO.getPropertyDTO();
            Integer propertyId = property.getId();
            long yesterday = DateTimeUtils.dateNow(property.getTimezone()).minusDays(1).toEpochSecond();
            // 没有报告缺失异常时，插入异常
            CbJournalImportLog exceptionImportLog = cbJournalImportLogService.getOne(new QueryWrapper<CbJournalImportLog>().lambda()
                    .eq(CbJournalImportLog::getPropertyId, propertyId)
                    .eq(CbJournalImportLog::getTheDate, yesterday)
                    .eq(CbJournalImportLog::getStatus, ReportImportResultCons.IMPORT_RESULT_MISSED)
                    .eq(CbJournalImportLog::getCreateBy, BaseConstant.ZERO)
                    .last("limit 1"));
            if (Objects.nonNull(exceptionImportLog)) {
                return;
            }
            cbJournalImportLogService.save(new CbJournalImportLog()
                    .setPropertyId(propertyId)
                    .setTheDate(yesterday)
                    .setStatus(ReportImportResultCons.IMPORT_RESULT_MISSED)
                    .setCreateBy(BaseConstant.ZERO)
                    .setCreatedTime(DateTimeUtils.nowTimestamp())
                    .setResolvedBy(BaseConstant.ZERO)
                    .setResolvedTime(BaseConstant.LONG_ZERO));
        }

    }