|
@@ -1,36 +1,85 @@
|
|
|
import {PrjInfo} from "@core-models/PrjInfo";
|
|
|
-import {Op} from "sequelize";
|
|
|
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
|
|
|
+import {Op, QueryTypes} from "sequelize";
|
|
|
import dayjs from "dayjs";
|
|
|
-import {ReportPrjState} from "@core-models/ReportPrjState";
|
|
|
+import {ReportPrjStat} from "@core-models/ReportPrjStat";
|
|
|
+import {PrjPlanTask} from "@core-models/PrjPlanTask";
|
|
|
+import {Logger} from "@util/Logger";
|
|
|
+import {ReportTaskDelayRate} from "@core-models/ReportTaskDelayRate";
|
|
|
|
|
|
export function prj_stat_monthly(): Promise<void> {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
try {
|
|
|
- // 使用dayjs获取今天是否是月末这一天
|
|
|
- // let is_last_day = dayjs().isSame(dayjs().endOf('month'), 'day');
|
|
|
- //if (!is_last_day) return resolve();
|
|
|
let count = await PrjInfo.count({where: {phase_id: {[Op.ne]: 'deprecated'}}});
|
|
|
let undone = await PrjInfo.count({where: {phase_id: {[Op.ne]: 'done'}}});
|
|
|
let ts = dayjs().endOf("month").format('YYYY-MM-DD');
|
|
|
- // await PrjStatReport.findOrCreate({
|
|
|
- // where: {
|
|
|
- // ts: ts
|
|
|
- // },
|
|
|
- // defaults: {
|
|
|
- // ts: ts,
|
|
|
- // amount: count,
|
|
|
- // undone: undone
|
|
|
- // }
|
|
|
- // })
|
|
|
- await ReportPrjState.upsert({
|
|
|
+ await ReportPrjStat.upsert({
|
|
|
ts: ts,
|
|
|
amount: count,
|
|
|
undone: undone
|
|
|
}, {returning: false})
|
|
|
resolve();
|
|
|
} catch (error) {
|
|
|
- reject(error);
|
|
|
+ Logger.error(error);
|
|
|
+ resolve();
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function task_stat_daily(): Promise<void> {
|
|
|
+ return new Promise(async (resolve, reject) => {
|
|
|
+ try {
|
|
|
+ let sql = `
|
|
|
+ INSERT INTO tb_report_task_stat
|
|
|
+ (ts, total_count, incomplete_count, delayed_count, delay_rate)
|
|
|
+ SELECT
|
|
|
+ now() as ts,
|
|
|
+ COUNT(CASE WHEN status <> 90 THEN 1 ELSE 0 END) AS total_count,
|
|
|
+ SUM(CASE WHEN status NOT IN (100, 90, 80) THEN 1 ELSE 0 END) AS incomplete_count,
|
|
|
+ SUM(CASE WHEN status = 20 THEN 1 ELSE 0 END) AS delayed_count,
|
|
|
+ CASE
|
|
|
+ WHEN COUNT(CASE WHEN status <> 90 THEN 1 ELSE 0 END) = 0 THEN 0
|
|
|
+ ELSE (SUM(CASE WHEN status in (20, 80) THEN 1 ELSE 0 END) * 100.0 / COUNT(CASE WHEN status <> 90 THEN 1 ELSE 0 END))
|
|
|
+ END AS delay_rate
|
|
|
+ FROM
|
|
|
+ tb_prj_plan_task, tb_prj_info
|
|
|
+ WHERE tb_prj_plan_task.prj_id = tb_prj_info.id and
|
|
|
+ tb_prj_info.phase_id <> 'deprecated' and tb_prj_info.phase_id <> 'done' --去除已完成和取消的项目
|
|
|
+ ON CONFLICT DO NOTHING
|
|
|
+ `;
|
|
|
+ await PrjPlanTask.sequelize!.query(sql, {type: QueryTypes.UPDATE, raw: true});
|
|
|
+ resolve();
|
|
|
+ } catch (error) {
|
|
|
+ Logger.error(error);
|
|
|
+ resolve();
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function task_delay_rate_daily(): Promise<void> {
|
|
|
+ return new Promise(async (resolve, reject) => {
|
|
|
+ try {
|
|
|
+ let sql = `
|
|
|
+ INSERT INTO ${ReportTaskDelayRate.table_name}
|
|
|
+ (ts, total_count, delayed_count, delay_rate)
|
|
|
+ SELECT
|
|
|
+ now() as ts,
|
|
|
+ COUNT(CASE WHEN status <> 90 THEN 1 ELSE 0 END) AS total_count,
|
|
|
+ SUM(CASE WHEN status = 20 THEN 1 ELSE 0 END) AS delayed_count,
|
|
|
+ CASE
|
|
|
+ WHEN COUNT(CASE WHEN status <> 90 THEN 1 ELSE 0 END) = 0 THEN 0
|
|
|
+ ELSE (SUM(CASE WHEN status in (20, 80) THEN 1 ELSE 0 END) * 100.0 / COUNT(CASE WHEN status <> 90 THEN 1 ELSE 0 END))
|
|
|
+ END AS delay_rate
|
|
|
+ FROM
|
|
|
+ tb_prj_plan_task, tb_prj_info
|
|
|
+ WHERE tb_prj_plan_task.prj_id = tb_prj_info.id and
|
|
|
+ tb_prj_info.phase_id <> 'deprecated' --去除已取消的项目
|
|
|
+ ON CONFLICT DO NOTHING
|
|
|
+ `;
|
|
|
+ await PrjPlanTask.sequelize!.query(sql, {type: QueryTypes.UPDATE, raw: true});
|
|
|
+ resolve();
|
|
|
+ } catch (error) {
|
|
|
+ Logger.error(error);
|
|
|
+ resolve();
|
|
|
}
|
|
|
});
|
|
|
}
|