宅男在线永久免费观看网直播,亚洲欧洲日产国码无码久久99,野花社区在线观看视频,亚洲人交乣女bbw,一本一本久久a久久精品综合不卡

全部
常見(jiàn)問(wèn)題
產(chǎn)品動(dòng)態(tài)
精選推薦

多商戶—每月帳單定時(shí)任務(wù)優(yōu)化

管理 管理 編輯 刪除

近期,我發(fā)現(xiàn)測(cè)試環(huán)境的帳單數(shù)據(jù)有些異常,2月份之后的數(shù)據(jù)都沒(méi)有,在檢查演示環(huán)境后,發(fā)現(xiàn)演示環(huán)境正常。最后確定是測(cè)試環(huán)境在暴力測(cè)試或手動(dòng)改動(dòng)數(shù)據(jù)后,導(dǎo)致的問(wèn)題—數(shù)據(jù)庫(kù)沒(méi)有當(dāng)月平臺(tái)月帳單記錄,從而導(dǎo)致定時(shí)任務(wù)一直執(zhí)行不下去,月賬單記錄一直缺失。

優(yōu)化方案:

在每月1號(hào)凌晨2點(diǎn),因各種情況導(dǎo)致的平臺(tái)上月賬單記錄不存在的情況下,定時(shí)任務(wù)依舊能正常執(zhí)行,統(tǒng)計(jì)上個(gè)月的數(shù)據(jù),初始化當(dāng)月數(shù)據(jù)

(以后的版本sql中不會(huì)再有當(dāng)月月賬單記錄的插入)

優(yōu)化后的代碼:

改動(dòng)Java項(xiàng)目中StatisticsTaskServiceImpl類(lèi)下monthStatement()方法


/**
     * 每月帳單定時(shí)任務(wù)
     * 每月第一天2點(diǎn)執(zhí)行
     * 獲取上個(gè)月所有的帳單記錄,然后通過(guò)累加獲取月帳單記錄
     * 生成當(dāng)月帳單記錄,數(shù)值為0
     */
    @Override
    public void monthStatement() {
        String lastMonth = DateUtil.lastMonth().toString(DateConstants.DATE_FORMAT_MONTH);
        PlatformMonthStatement platformMonthStatement = platformMonthStatementService.getByMonth(lastMonth);
        List<MerchantMonthStatement> merchantMonthStatementList = CollUtil.newArrayList();
        List<Integer> merIdList = merchantService.getAllId();
        if (ObjectUtil.isNull(platformMonthStatement)) {
            LOGGER.error("每月帳單定時(shí)任務(wù),未查詢到上一個(gè)月的數(shù)據(jù),現(xiàn)在開(kāi)始初始化上個(gè)月數(shù)據(jù)");
            // 初始化上一個(gè)月的數(shù)據(jù),值為0
            platformMonthStatement = new PlatformMonthStatement();
            platformMonthStatement.setDataDate(lastMonth);
            // 初始化上一個(gè)月的商戶帳單數(shù)據(jù),值為0
            merchantMonthStatementList = merchantMonthStatementService.findByMonth(lastMonth);
            List<MerchantMonthStatement> tempMerchantMonthStatementList = CollUtil.newArrayList();
            if (CollUtil.isNotEmpty(merchantMonthStatementList)) {
                if (merIdList.size() != merchantMonthStatementList.size()) {
                    // 處理上個(gè)約沒(méi)有月賬單的商戶數(shù)據(jù)
                    List<Integer> staMerIdList = merchantMonthStatementList.stream().map(MerchantMonthStatement::getMerId).collect(Collectors.toList());
                    for (Integer merId : merIdList) {
                        if (!staMerIdList.contains(merId)) {
                            MerchantMonthStatement merchantMonthStatement = new MerchantMonthStatement();
                            merchantMonthStatement.setMerId(merId);
                            merchantMonthStatement.setDataDate(lastMonth);
                            tempMerchantMonthStatementList.add(merchantMonthStatement);
                        }
                    }
                }
            } else {
                merIdList.forEach(merId -> {
                    MerchantMonthStatement merchantMonthStatement = new MerchantMonthStatement();
                    merchantMonthStatement.setMerId(merId);
                    merchantMonthStatement.setDataDate(lastMonth);
                    tempMerchantMonthStatementList.add(merchantMonthStatement);
                });
            }

            PlatformMonthStatement finalPlatformMonthStatement = platformMonthStatement;
            Boolean execute = transactionTemplate.execute(e -> {
                boolean save = platformMonthStatementService.save(finalPlatformMonthStatement);
                if (!save) {
                    LOGGER.error("每月帳單定時(shí)任務(wù),初始化上個(gè)月平臺(tái)月帳單失敗,觸發(fā)回滾");
                    e.setRollbackOnly();
                    return Boolean.FALSE;
                }
                save = merchantMonthStatementService.saveBatch(tempMerchantMonthStatementList, 100);
                if (!save) {
                    LOGGER.error("每月帳單定時(shí)任務(wù),初始化上個(gè)月商戶月帳單失敗,觸發(fā)回滾");
                    e.setRollbackOnly();
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;
            });
            if (!execute) {
                LOGGER.error("每月帳單定時(shí)任務(wù),因沒(méi)有上個(gè)月數(shù)據(jù),初始化上個(gè)月數(shù)據(jù)時(shí)失敗");
                return;
            }
            platformMonthStatement.setId(finalPlatformMonthStatement.getId());
            if (CollUtil.isNotEmpty(tempMerchantMonthStatementList)) {
                merchantMonthStatementList.addAll(tempMerchantMonthStatementList);
            }
        }
        writePlatformMonthStatement(platformMonthStatement);
        writeMerchantMonthStatement(merchantMonthStatementList, lastMonth);
        PlatformMonthStatement finalTempPlatformMonthStatement = platformMonthStatement;
        List<MerchantMonthStatement> finalMerchantMonthStatementList = merchantMonthStatementList;
        transactionTemplate.execute(e -> {
            boolean save = platformMonthStatementService.updateById(finalTempPlatformMonthStatement);
            if (!save) {
                LOGGER.error("每月帳單定時(shí)任務(wù),更新平臺(tái)月帳單失敗,觸發(fā)回滾");
                e.setRollbackOnly();
                return Boolean.FALSE;
            }
            save = merchantMonthStatementService.updateBatchById(finalMerchantMonthStatementList, 100);
            if (!save) {
                LOGGER.error("每月帳單定時(shí)任務(wù),更新商戶月帳單失敗,觸發(fā)回滾");
                e.setRollbackOnly();
                return Boolean.FALSE;
            }
            save = initMonthStatement(merIdList);
            if (!save) {
                LOGGER.error("每月帳單定時(shí)任務(wù),初始化平臺(tái)當(dāng)月帳單失敗,觸發(fā)回滾");
                e.setRollbackOnly();
                return Boolean.FALSE;
            }
            return Boolean.TRUE;
        });
    }

最后

在代碼改動(dòng)發(fā)布后,如果你跟我一樣,當(dāng)前2023-05月,在數(shù)據(jù)庫(kù)沒(méi)有的記錄的情況下,想看到統(tǒng)計(jì)的2023-04月的統(tǒng)計(jì)數(shù)據(jù)

在平臺(tái)端的管理后臺(tái),維護(hù) → 定時(shí)任務(wù)管理 → 定時(shí)任務(wù),找到每月帳單定時(shí)任務(wù),點(diǎn)擊觸發(fā)即可

就可以在eb_platform_month_statement和eb_merchant_month_statement表中看到對(duì)應(yīng)數(shù)據(jù)

4c86a202305061505459499.png

請(qǐng)登錄后查看

?指縫de陽(yáng)光 最后編輯于2023-05-06 15:09:58

快捷回復(fù)
回復(fù)
回復(fù)
回復(fù)({{post_count}}) {{!is_user ? '我的回復(fù)' :'全部回復(fù)'}}
排序 默認(rèn)正序 回復(fù)倒序 點(diǎn)贊倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level }}

作者 管理員 企業(yè)

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
{{item.is_suggest == 1? '取消推薦': '推薦'}}
沙發(fā) 板凳 地板 {{item.floor}}#
{{item.user_info.title || '暫無(wú)簡(jiǎn)介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打賞
已打賞¥{{item.reward_price}}
{{item.like_count}}
{{item.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回復(fù) {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打賞
已打賞¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)
查看更多
打賞
已打賞¥{{reward_price}}
2819
{{like_count}}
{{collect_count}}
添加回復(fù) ({{post_count}})

相關(guān)推薦

快速安全登錄

使用微信掃碼登錄
{{item.label}} 加精
{{item.label}} {{item.label}} 板塊推薦 常見(jiàn)問(wèn)題 產(chǎn)品動(dòng)態(tài) 精選推薦 首頁(yè)頭條 首頁(yè)動(dòng)態(tài) 首頁(yè)推薦
取 消 確 定
回復(fù)
回復(fù)
問(wèn)題:
問(wèn)題自動(dòng)獲取的帖子內(nèi)容,不準(zhǔn)確時(shí)需要手動(dòng)修改. [獲取答案]
答案:
提交
bug 需求 取 消 確 定
打賞金額
當(dāng)前余額:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
請(qǐng)輸入 0.1-{{reward_max_price}} 范圍內(nèi)的數(shù)值
打賞成功
¥{{price}}
完成 確認(rèn)打賞

微信登錄/注冊(cè)

切換手機(jī)號(hào)登錄

{{ bind_phone ? '綁定手機(jī)' : '手機(jī)登錄'}}

{{codeText}}
切換微信登錄/注冊(cè)
暫不綁定
CRMEB客服

CRMEB咨詢熱線 咨詢熱線

400-8888-794

微信掃碼咨詢

CRMEB開(kāi)源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
返回頂部 返回頂部
CRMEB客服