|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|