brook před 3 roky
rodič
revize
f68f25d92c

+ 1 - 0
backendApi/config/urlManagerRules.php

@@ -566,6 +566,7 @@ return [
             'GET pull-perf-period/<periodNum>' => 'pull-perf-period',
             'GET calc-bonus/<periodNum>' => 'calc-bonus',
             'GET pull-bonus/<periodNum>' => 'pull-bonus',
+            'GET sync-calc-record/<periodNum>' => 'sync-calc-record',
         ],
     ],
 ];

+ 16 - 0
backendApi/modules/v1/controllers/CalcController.php

@@ -281,5 +281,21 @@ class CalcController extends BaseController
         return static::notice($data);
     }
 
+    /**
+     * 更新奖金计算进度的日志
+     * @return mixed
+     * @throws \yii\web\HttpException
+     */
+    public function actionSyncCalcRecord()
+    {
+        $periodNum = \Yii::$app->request->get('periodNum');
+        if (!$periodNum) {
+            return static::notice('期数不存在', 400);
+        }
+        $businessPeriod = Period::find()->where(['PERIOD_NUM' => $periodNum])->asArray()->one();
+        CalcConsole::syncCalcRecord($periodNum, CalcConsole::CALC_DB_NAME, $businessPeriod['START_EXEC_TIME'] ?? 0);
+        return static::notice('已更新奖金计算的操作日志,请刷新');
+    }
+
 
 }

+ 38 - 2
common/helpers/bonus/Calc/CalcConsole.php

@@ -27,8 +27,9 @@ class CalcConsole extends BaseBusiness
         $businessPeriod = Period::find()->where(['PERIOD_NUM' => $period['PERIOD_NUM']])
             ->asArray()->one();
         //用户选择是否自动执行
-        $autoExec             = $businessPeriod['AUTO_EXEC'] > 0;
-        $businessIsCalculated = $businessPeriod['IS_CALCULATED'] == 1;
+        $autoExec             = $businessPeriod['AUTO_EXEC'] > Period::MANUAL_EXEC_CALC;
+        $businessIsCalculated = $businessPeriod['IS_CALCULATED'] == Period::CALCULATE_FINISH;
+        $startExecTime        = $businessPeriod['START_EXEC_TIME'] ?? 0;
 
         if (2 == $period['IS_PREPARE'] && 1 == $period['IS_PERFED'] && $autoExec) {
             //拉取期业绩
@@ -52,7 +53,11 @@ class CalcConsole extends BaseBusiness
             //同步周期表的值到业务系统
             self::pullPeriodForUpdate($period['PERIOD_NUM']);
             return \Yii::$app->$db->createCommand()->update('AR_PERIOD', ['IS_PREPARE' => 3], 'PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM' => $period['PERIOD_NUM']])->execute();
+        }
 
+        //同步计算进度日志到业务系统
+        if (4 == $period['IS_PREPARE'] && 0 == $period['IS_CALCULATED']) {
+            self::syncCalcRecord($period['PERIOD_NUM'], $db, $startExecTime);
         }
 
         if (4 == $period['IS_PREPARE'] && 1 == $period['IS_CALCULATED'] && $autoExec && !$businessIsCalculated) {
@@ -66,6 +71,8 @@ class CalcConsole extends BaseBusiness
                 CalcRecord::record($period['PERIOD_NUM'], '第' . $period['PERIOD_NUM'] . '期的奖金数据已全部拉取');
                 //待拉取完成后再将计算完成标识改为已完成
                 \Yii::$app->db->createCommand()->update('AR_PERIOD', ['IS_CALCULATED' => 1], 'PERIOD_NUM=' . $period['PERIOD_NUM'])->execute();
+                //拉取计算系统的进度日志
+                self::syncCalcRecord($period['PERIOD_NUM'], $db, $startExecTime);
                 //自动执行完成 更新对应字段
                 //计算结束
                 Period::updatePeriodIsProcessing($period['PERIOD_NUM'], Period::NOT_PROCESSING);
@@ -84,4 +91,33 @@ class CalcConsole extends BaseBusiness
         return true;
     }
 
+    /**
+     * 同步计算系统的计算进度日志到业务系统计算步骤表
+     * @param $periodNum
+     * @param $db
+     * @param $startTime
+     * @return bool|int
+     * @throws \yii\base\InvalidConfigException
+     * @throws \yii\db\Exception
+     */
+    public static function syncCalcRecord($periodNum, $db, $startTime = 0)
+    {
+        $type         = 'bonus';
+        $calcTaskDesc = \Yii::$app->$db->createCommand("SELECT
+        ID,PERIOD_NUM,TASK_DESCRIBE,START_AT FROM AR_SERVE_PROCESS 
+        where TASK_TYPE='$type' AND PERIOD_NUM=$periodNum  AND START_AT>=$startTime
+        order by START_AT desc")->queryAll();
+
+        $calcTaskDescKeys = array_column($calcTaskDesc, null, 'ID');
+
+        $currentRecordList    = CalcRecord::find()->where(['PERIOD_NUM' => $periodNum])->select('ID')->asArray()->column();
+        $currentRecordListKey = array_flip($currentRecordList);
+
+        $tableName = (new CalcRecord())->getTableSchema()->name;
+        $result    = array_diff_key($calcTaskDescKeys, $currentRecordListKey);
+        if (!empty($result)) {
+            return \Yii::$app->db->createCommand()->batchInsert($tableName, ['ID', 'PERIOD_NUM', 'TEXT', 'CREATED_AT'], $result)->execute();
+        }
+        return true;
+    }
 }

+ 1 - 1
common/models/Period.php

@@ -861,7 +861,7 @@ class Period extends \common\components\ActiveRecord
 
     public static function updatePeriodIsProcessing($periodNum, $isProcessing = 1): int
     {
-        return Period::updateAll(['IS_PROCESSING' => $isProcessing], ['PERIOD_NUM' => $periodNum]);
+        return Period::updateAll(['IS_PROCESSING' => $isProcessing, 'START_EXEC_TIME' => time()], ['PERIOD_NUM' => $periodNum]);
     }
 
     /**