代码之家  ›  专栏  ›  技术社区  ›  Dolphin

在java中使用调度任务时,为什么计算结果会返回意外数据

  •  0
  • Dolphin  · 技术社区  · 4 年前

    public <E> void calcSingle(T appListRecord, Class<T> type, E mapper) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
        Long tenantId = Long.valueOf(ReflectorUtil.getFieldValue(appListRecord, "tenantId").toString());
        Long roundId = Long.valueOf(ReflectorUtil.getFieldValue(appListRecord, "roundId").toString());
        Long appId = Long.valueOf(ReflectorUtil.getFieldValue(appListRecord, "appId").toString());
        Long id = Long.valueOf(ReflectorUtil.getFieldValue(appListRecord, "id").toString());
        MyContext.setTenant(tenantId);
        WalletConsumeRequest sourceDatarequest = new WalletConsumeRequest();
        sourceDatarequest.setBizId(roundId);
        sourceDatarequest.setAppId(appId);
        Integer sourceRecordcount = consumeRecordController.getRecordCount(sourceDatarequest);
        ReportWalletConsumeRequest syncedDataRequestReport = new ReportWalletConsumeRequest();
        syncedDataRequestReport.setBizId(roundId);
        syncedDataRequestReport.setAppId(appId);
        Response<Integer> response = reportWalletController.getUserConsumeCount(syncedDataRequestReport);
        if (response == null || response.getResult() == null) {
            return;
        }
        if (sourceRecordcount.intValue() == response.getResult().intValue()) {
            ReportWalletConsumeRequest consumeRequest = new ReportWalletConsumeRequest();
            consumeRequest.setAppId(Long.valueOf(appId));
            consumeRequest.setBizId(roundId);
            Response<Map<String, Object>> robotProfit = reportWalletController.getUserConsume(consumeRequest);
            if (robotProfit != null && MapUtils.isNotEmpty(robotProfit.getResult())) {
                T envelopeAppList = type.newInstance();
                ReflectorUtil.setFieldValue(envelopeAppList, "id", id);
                ReflectorUtil.setFieldValue(envelopeAppList, "isCalcPlayerProfit", 1);
                Long robotProfitValue = MapUtils.getLongValue(robotProfit.getResult(), "robotProfit");
                ReflectorUtil.setFieldValue(envelopeAppList, "robotProfit", robotProfitValue);
                Long realPeopleProfitValue = MapUtils.getLongValue(robotProfit.getResult(), "realPeopleProfit");
                ReflectorUtil.setFieldValue(envelopeAppList, "realPeopleProfit", realPeopleProfitValue);
                Method method = mapper.getClass().getMethod("updateByPrimaryKeySelective", envelopeAppList.getClass());
                method.invoke(mapper, envelopeAppList);
            }
        }
    }
    

    当前一些结果数据似乎不正确;变量A似乎复制到变量B。我的代码哪里出了问题?我检查了一遍又一遍,弄不清哪里出了问题。所有变量都在函数中创建。我应该怎么做来修正变量错误?这是任务条目之一:

    @Scheduled(cron = "0/10 * * * * ?")
    @NoTenant
    private void calcCardProfit() {}
    
    0 回复  |  直到 4 年前