using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Services.Services.BS;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.BI;
using APT.MS.Domain.Entities.SC.BI;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System;
using APT.MS.Domain.Entities.HM;
using APT.BaseData.Domain.Entities;
using System.Threading.Tasks;
using APT.MS.Domain.Entities.BS;
using APT.MS.Domain.Enums;
using APT.MS.Domain.Entities.FO;
using NPOI.SS.Formula.Functions;
using static NPOI.HSSF.Util.HSSFColor;
using APT.BaseData.Domain.Enums;
using APT.BaseData.Domain.IServices;
using NPOI.Util;
using APT.WebApi.Models;

namespace APT.PP.WebApi.Controllers.Api.PP
{
    [Route("api/PP/BIAnalysis")]
    [TypeFilter(typeof(CustomActionFilterAttribute))]
    public class BIAnalysisController : AuthorizeApiController<T_BI_FORM_RUN_ANALYSIS>
    {
        [HttpPost, Route("AddRiskMoudleInfo")]
        public JsonActionResult<bool> AddRiskMoudleInfo([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                try
                {
                    var sourceIds = new List<Guid>();
                    List<T_BI_FORM_RUN_ANALYSIS> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS>();
                    var newFilter = new BaseFilter(filter.OrgId);
                    newFilter.SelectField = new List<string> { "ID", "STATUS" };
                    //风险评价计划审核表
                    var evalPlan = this.GetEntities<T_HM_EVALUATION_PLAN>(t => true, newFilter);
                    var evalPlanIds = evalPlan.Select(t => t.ID).ToList();
                    sourceIds.AddRange(evalPlanIds);
                    //风险评价计划发布
                    newFilter.SelectField = new List<string> { "ID", "RELEASE_STATUS" };
                    var noticeRelease = this.GetEntities<T_HM_NOTICE_RELEASE>(t => true, newFilter);
                    var noticeReleaseIds = noticeRelease.Select(t => t.ID).ToList();
                    sourceIds.AddRange(noticeReleaseIds);
                    //危险源/风险辨识任务
                    newFilter.SelectField = new List<string> { "ID", "STATUS" };
                    var riskTask = this.GetEntities<T_HM_RISK_TASK>(t => true, newFilter);
                    var riskTaskIds = riskTask.Select(t => t.ID).ToList();
                    sourceIds.AddRange(riskTaskIds);
                    //危险源/风险辨识记录表
                    var riskRecord = this.GetEntities<T_HM_RISK_RECORD>(t => true, newFilter);
                    var riskRecordIds = riskRecord.Select(t => t.ID).ToList();
                    sourceIds.AddRange(riskRecordIds);
                    //职业危害辨识任务
                    var hazardTask = this.GetEntities<T_HM_HAZARD_TASK>(t => true, newFilter);
                    var hazardTaskIds = hazardTask.Select(t => t.ID).ToList();
                    sourceIds.AddRange(hazardTaskIds);
                    //职业危害辨识记录表
                    var hazardRecord = this.GetEntities<T_HM_HAZARD_RECORD>(t => true, newFilter);
                    var hazardRecordIds = hazardRecord.Select(t => t.ID).ToList();
                    sourceIds.AddRange(hazardRecordIds);
                    //评价结果表
                    var evalResult = this.GetEntities<T_HM_EVALUATE_RESULT>(t => true, newFilter);
                    var evalResultIds = evalResult.Select(t => t.ID).ToList();
                    sourceIds.AddRange(evalResultIds);
                    //作业任务识别
                    newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH" };
                    var taskIdentify = this.GetEntities<T_HM_JOBTASK_IDENTIFY>(t => true, newFilter);
                    var taskIdentifyIds = taskIdentify.Select(t => t.ID).ToList();
                    sourceIds.AddRange(taskIdentifyIds);
                    //作业任务识别分析
                    var taskAnalysis = this.GetEntities<T_HM_OPERATION_TASK_DISTINGUISH_ANALYZE>(t => true, newFilter);
                    var taskAnalysisIds = taskAnalysis.Select(t => t.ID).ToList();
                    sourceIds.AddRange(taskAnalysisIds);
                    //一般任务分析
                    var taskOrdinary = this.GetEntities<T_HM_ORDINARY_TASK_ANALYSIS>(t => true, newFilter);
                    var taskOrdinaryIds = taskOrdinary.Select(t => t.ID).ToList();
                    sourceIds.AddRange(taskOrdinaryIds);
                    //关键任务分析
                    var taskCrucial = this.GetEntities<T_HM_CRUCIAL_TASK_ANALYSIS>(t => true, newFilter);
                    var taskCrucialIds = taskCrucial.Select(t => t.ID).ToList();
                    sourceIds.AddRange(taskCrucialIds);
                    //许可任务分析
                    var taskLicense = this.GetEntities<T_HM_LICENSE_ANALYSIS>(t => true, newFilter);
                    var taskLicenseIds = taskLicense.Select(t => t.ID).ToList();
                    sourceIds.AddRange(taskLicenseIds);
                    //作业任务分析文件发布
                    newFilter.SelectField = new List<string> { "ID" };
                    var filePublish = this.GetEntities<T_HM_FILE_PUBLISH>(t => true, newFilter);
                    var filePublishIds = filePublish.Select(t => t.ID).ToList();
                    sourceIds.AddRange(filePublishIds);
                    //只取待办超期的
                    newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
                    var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2, newFilter);
                    tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
                    //表单运行情况分析表
                    var allAnalysis = this.GetEntities<T_BI_FORM_RUN_ANALYSIS>(t => true, new BaseFilter(filter.OrgId));
                    #region 风险评价计划审核表
                    if (evalPlan.Any())
                    {
                        foreach (var item in evalPlan)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = evalPlan.Count();
                        var finish = evalPlan.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = evalPlan.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "年度风险评价计划审核表");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "年度风险评价计划审核表";
                            analysis.NUM = 1;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "年度风险评价计划审核表");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "年度风险评价计划审核表";
                            analysis.NUM = 1;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 风险评价计划发布
                    if (noticeRelease.Any())
                    {
                        foreach (var item in noticeRelease)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = noticeRelease.Count();
                        var finish = noticeRelease.Count(t => t.IS_OVERTIME == 0 && t.RELEASE_STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = noticeRelease.Count(t => t.IS_OVERTIME == 1 && t.RELEASE_STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "风险评价计划发布");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "风险评价计划发布";
                            analysis.NUM = 2;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "风险评价计划发布");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "风险评价计划发布";
                            analysis.NUM = 2;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 危险源/风险辨识任务
                    if (riskTask.Any())
                    {
                        foreach (var item in riskTask)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = riskTask.Count();
                        var finish = riskTask.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = riskTask.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "危险源/风险辨识任务");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "危险源/风险辨识任务";
                            analysis.NUM = 3;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "危险源/风险辨识任务");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "危险源/风险辨识任务";
                            analysis.NUM = 3;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 危险源/风险辨识记录表
                    if (riskRecord.Any())
                    {
                        foreach (var item in riskRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = riskRecord.Count();
                        var finish = riskRecord.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = riskRecord.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "危险源/风险辨识记录表");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "危险源/风险辨识记录表";
                            analysis.NUM = 4;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "危险源/风险辨识记录表");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "危险源/风险辨识记录表";
                            analysis.NUM = 4;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 职业危害辨识任务
                    if (hazardTask.Any())
                    {
                        foreach (var item in hazardTask)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = hazardTask.Count();
                        var finish = hazardTask.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = hazardTask.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "职业危害辨识任务");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "职业危害辨识任务";
                            analysis.NUM = 5;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "职业危害辨识任务");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "职业危害辨识任务";
                            analysis.NUM = 5;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 职业危害辨识记录表
                    if (hazardRecord.Any())
                    {
                        foreach (var item in hazardRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = hazardRecord.Count();
                        var finish = hazardRecord.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = hazardRecord.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "职业危害辨识记录表");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "职业危害辨识记录表";
                            analysis.NUM = 6;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "职业危害辨识记录表");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "职业危害辨识记录表";
                            analysis.NUM = 6;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 评价结果表
                    if (evalResult.Any())
                    {
                        foreach (var item in evalResult)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = evalResult.Count();
                        var finish = evalResult.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = evalResult.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "评价结果表");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "评价结果表";
                            analysis.NUM = 7;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "评价结果表");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "评价结果表";
                            analysis.NUM = 7;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 作业任务识别
                    if (taskIdentify.Any())
                    {
                        foreach (var item in taskIdentify)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = taskIdentify.Count();
                        var finish = taskIdentify.Count(t => t.IS_OVERTIME == 0 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = taskIdentify.Count(t => t.IS_OVERTIME == 1 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "作业任务识别");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "作业任务识别";
                            analysis.NUM = 8;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "作业任务识别");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "作业任务识别";
                            analysis.NUM = 8;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 作业任务识别分析
                    if (taskAnalysis.Any())
                    {
                        foreach (var item in taskAnalysis)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = taskAnalysis.Count();
                        var finish = taskAnalysis.Count(t => t.IS_OVERTIME == 0 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = taskAnalysis.Count(t => t.IS_OVERTIME == 1 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "作业任务识别分析");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "作业任务识别分析";
                            analysis.NUM = 9;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "作业任务识别分析");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "作业任务识别分析";
                            analysis.NUM = 9;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 一般任务分析
                    if (taskOrdinary.Any())
                    {
                        foreach (var item in taskOrdinary)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = taskOrdinary.Count();
                        var finish = taskOrdinary.Count(t => t.IS_OVERTIME == 0 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = taskOrdinary.Count(t => t.IS_OVERTIME == 1 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "一般任务分析");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "一般任务分析";
                            analysis.NUM = 10;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "一般任务分析");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "一般任务分析";
                            analysis.NUM = 10;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 关键任务分析
                    if (taskCrucial.Any())
                    {
                        foreach (var item in taskCrucial)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = taskCrucial.Count();
                        var finish = taskCrucial.Count(t => t.IS_OVERTIME == 0 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = taskCrucial.Count(t => t.IS_OVERTIME == 1 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "关键任务分析");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "关键任务分析";
                            analysis.NUM = 11;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "关键任务分析");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "关键任务分析";
                            analysis.NUM = 11;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 许可任务分析
                    if (taskLicense.Any())
                    {
                        foreach (var item in taskLicense)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = taskLicense.Count();
                        var finish = taskLicense.Count(t => t.IS_OVERTIME == 0 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = taskLicense.Count(t => t.IS_OVERTIME == 1 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "许可任务分析");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "许可任务分析";
                            analysis.NUM = 12;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "许可任务分析");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "许可任务分析";
                            analysis.NUM = 12;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 作业任务分析文件发布
                    if (filePublish.Any())
                    {
                        foreach (var item in filePublish)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = filePublish.Count();
                        var finish = filePublish.Count(t => t.IS_OVERTIME == 0);
                        var overfinish = filePublish.Count(t => t.IS_OVERTIME == 1);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "作业任务分析文件发布");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "作业任务分析文件发布";
                            analysis.NUM = 13;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "风险管理" && t.FORM_NAME == "作业任务分析文件发布");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "风险管理";
                            analysis.FORM_NAME = "作业任务分析文件发布";
                            analysis.NUM = 13;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    this.UnifiedCommit(() =>
                    {
                        if (formAnalysis != null && formAnalysis.Any())
                            BantchSaveEntityNoCommit(formAnalysis);
                    });
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.StackTrace))
                        throw new Exception("错误日志：[StackTrace]" + ex.StackTrace);
                    else
                        throw new Exception("【" + HttpContext.Request.Path + "】错误日志：[Message]" + ex.Message);
                }
                return true;
            });
        }

        [HttpPost, Route("AddSafeCheckMoudleInfo")]
        public JsonActionResult<bool> AddSafeCheckMoudleInfo([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                try
                {
                    var sourceIds = new List<Guid>();
                    List<T_BI_FORM_RUN_ANALYSIS> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS>();
                    var newFilter = new BaseFilter(filter.OrgId);
                    newFilter.SelectField = new List<string> { "ID", "STATUSPLAN", "STATUCHECK" };
                    //检查任务制定
                    var evalPlan = this.GetEntities<T_BS_SAFE_CHECK>(t => true, newFilter);
                    var evalPlanIds = evalPlan.Select(t => t.ID).ToList();
                    sourceIds.AddRange(evalPlanIds);
                    //检查记录
                    var noticeRelease = evalPlan.Where(t => t.STATUSPLAN == (int)HMAuditStatusEnmu.归档).ToList();
                    var noticeReleaseIds = noticeRelease.Select(t => t.ID).ToList();
                    sourceIds.AddRange(noticeReleaseIds);
                    //隐患上报
                    newFilter.SelectField = new List<string> { "ID", "SUBMIT_STATUS" };
                    var riskTask = this.GetEntities<T_BS_RISK_SUBMIT>(t => true, newFilter);
                    var riskTaskIds = riskTask.Select(t => t.ID).ToList();
                    sourceIds.AddRange(riskTaskIds);
                    //隐患整改记录
                    newFilter.SelectField = new List<string> { "ID", "DEALSITUATION" };
                    var riskRecord = this.GetEntities<T_BS_RISK_SUBMIT_CONTENT_DEAL>(t => true, newFilter);
                    var riskRecordIds = riskRecord.Select(t => t.ID).ToList();
                    sourceIds.AddRange(riskRecordIds);
                    //延期整改申请
                    newFilter.SelectField = new List<string> { "ID" };
                    var hazardTask = this.GetEntities<T_BS_RISK_SUBMIT_DELAY_APPLY>(t => true, newFilter);
                    var hazardTaskIds = hazardTask.Select(t => t.ID).ToList();
                    sourceIds.AddRange(hazardTaskIds);
                    //只取待办超期的
                    newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
                    var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2, newFilter);
                    tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
                    //表单运行情况分析表
                    var allAnalysis = this.GetEntities<T_BI_FORM_RUN_ANALYSIS>(t => true, new BaseFilter(filter.OrgId));
                    #region 检查任务制定
                    if (evalPlan.Any())
                    {
                        foreach (var item in evalPlan)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = evalPlan.Count();
                        var finish = evalPlan.Count(t => t.IS_OVERTIME == 0 && t.STATUSPLAN == (int)HMAuditStatusEnmu.归档);
                        var overfinish = evalPlan.Count(t => t.IS_OVERTIME == 1 && t.STATUSPLAN == (int)HMAuditStatusEnmu.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "安全检查" && t.FORM_NAME == "检查任务制定");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "安全检查";
                            analysis.FORM_NAME = "检查任务制定";
                            analysis.NUM = 20;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "安全检查" && t.FORM_NAME == "检查任务制定");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "安全检查";
                            analysis.FORM_NAME = "检查任务制定";
                            analysis.NUM = 20;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 检查记录
                    if (noticeRelease.Any())
                    {
                        foreach (var item in noticeRelease)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = noticeRelease.Count();
                        var finish = noticeRelease.Count(t => t.IS_OVERTIME == 0 && t.STATUCHECK == (int)HMAuditStatusEnmu.归档);
                        var overfinish = noticeRelease.Count(t => t.IS_OVERTIME == 1 && t.STATUCHECK == (int)HMAuditStatusEnmu.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "安全检查" && t.FORM_NAME == "检查记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "安全检查";
                            analysis.FORM_NAME = "检查记录";
                            analysis.NUM = 21;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "安全检查" && t.FORM_NAME == "检查记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "安全检查";
                            analysis.FORM_NAME = "检查记录";
                            analysis.NUM = 21;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 隐患上报
                    if (riskTask.Any())
                    {
                        foreach (var item in riskTask)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = riskTask.Count();
                        var finish = riskTask.Count(t => t.IS_OVERTIME == 0 && t.SUBMIT_STATUS == (int)BSSubmitStatusEnum.AuditOK);
                        var overfinish = riskTask.Count(t => t.IS_OVERTIME == 1 && t.SUBMIT_STATUS == (int)BSSubmitStatusEnum.AuditOK);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "安全检查" && t.FORM_NAME == "隐患上报");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "安全检查";
                            analysis.FORM_NAME = "隐患上报";
                            analysis.NUM = 22;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "安全检查" && t.FORM_NAME == "隐患上报");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "安全检查";
                            analysis.FORM_NAME = "隐患上报";
                            analysis.NUM = 22;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 隐患整改记录
                    if (riskRecord.Any())
                    {
                        foreach (var item in riskRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = riskRecord.Count();
                        var finish = riskRecord.Count(t => t.IS_OVERTIME == 0 && t.DEALSITUATION == (int)DealSituation.OK);
                        var overfinish = riskRecord.Count(t => t.IS_OVERTIME == 1 && t.DEALSITUATION == (int)DealSituation.OK);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "安全检查" && t.FORM_NAME == "隐患整改记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "安全检查";
                            analysis.FORM_NAME = "隐患整改记录";
                            analysis.NUM = 23;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "安全检查" && t.FORM_NAME == "隐患整改记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "安全检查";
                            analysis.FORM_NAME = "隐患整改记录";
                            analysis.NUM = 23;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 延期整改申请
                    if (hazardTask.Any())
                    {
                        foreach (var item in hazardTask)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = hazardTask.Count();
                        var finish = hazardTask.Count(t => t.IS_OVERTIME == 0);
                        var overfinish = hazardTask.Count(t => t.IS_OVERTIME == 1);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "安全检查" && t.FORM_NAME == "延期整改申请");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "安全检查";
                            analysis.FORM_NAME = "延期整改申请";
                            analysis.NUM = 24;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "安全检查" && t.FORM_NAME == "延期整改申请");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "安全检查";
                            analysis.FORM_NAME = "延期整改申请";
                            analysis.NUM = 24;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    this.UnifiedCommit(() =>
                    {
                        if (formAnalysis != null && formAnalysis.Any())
                            BantchSaveEntityNoCommit(formAnalysis);
                    });
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.StackTrace))
                        throw new Exception("错误日志：[StackTrace]" + ex.StackTrace);
                    else
                        throw new Exception("【" + HttpContext.Request.Path + "】错误日志：[Message]" + ex.Message);
                }
                return true;
            });
        }
        [HttpPost, Route("AddOperationMoudleInfo")]
        public JsonActionResult<bool> AddOperationMoudleInfo([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                try
                {
                    var sourceIds = new List<Guid>();
                    List<T_BI_FORM_RUN_ANALYSIS> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS>();
                    var newFilter = new BaseFilter(filter.OrgId);
                    newFilter.SelectField = new List<string> { "ID", "SHIFT_STATUS", "OVERTIME" };
                    //岗位当班工作记录
                    var evalPlan = this.GetEntities<T_FO_CURRENT_CLASS_RECORD>(t => true, newFilter);
                    //var evalPlanIds = evalPlan.Select(t => t.ID).ToList();
                    //sourceIds.AddRange(evalPlanIds);
                    //岗位交接班记录
                    var noticeRelease = this.GetEntities<T_FO_CHANGE_SHIFT_RECORD>(t => true, newFilter);
                    //var noticeReleaseIds = noticeRelease.Select(t => t.ID).ToList();
                    //sourceIds.AddRange(noticeReleaseIds);
                    //班组安全活动
                    newFilter.SelectField = new List<string> { "ID", "TA_STATUS", "OVERTIME" };
                    var riskTask = this.GetEntities<T_FO_TEAM_ACTIVITY>(t => true, newFilter);
                    //var riskTaskIds = riskTask.Select(t => t.ID).ToList();
                    //sourceIds.AddRange(riskTaskIds);
                    //班前会议记录
                    newFilter.SelectField = new List<string> { "ID", "PRE_MEETING_STATUS", "OVERTIME" };
                    var riskRecord = this.GetEntities<T_FO_PRE_SHIFT_MEETING_RECORD>(t => true, newFilter);
                    //var riskRecordIds = riskRecord.Select(t => t.ID).ToList();
                    //sourceIds.AddRange(riskRecordIds);
                    //作业活动记录（一般作业）
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS" };
                    var hazardTask = this.GetEntities<T_FO_JOB_EVENT_RECORD>(t => true, newFilter);
                    var hazardTaskIds = hazardTask.Select(t => t.ID).ToList();
                    sourceIds.AddRange(hazardTaskIds);
                    //作业方案讨论记录
                    var hazardRecord = this.GetEntities<T_FO_PRE_OPER_SCH>(t => true, newFilter);
                    var hazardRecordIds = hazardRecord.Select(t => t.ID).ToList();
                    sourceIds.AddRange(hazardRecordIds);
                    //关键作业/许可作业工作票
                    newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH" };
                    var evalResult = this.GetEntities<T_FO_CRUCIAL_LICENSE_JOB>(t => true, newFilter);
                    var evalResultIds = evalResult.Select(t => t.ID).ToList();
                    sourceIds.AddRange(evalResultIds);
                    //技术交底表
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS" };
                    var taskIdentify = this.GetEntities<T_FO_TECH_DISCLOSURE_FROM>(t => true, newFilter);
                    var taskIdentifyIds = taskIdentify.Select(t => t.ID).ToList();
                    sourceIds.AddRange(taskIdentifyIds);
                    //作业活动记录（关键和许可作业）
                    var taskAnalysis = this.GetEntities<T_FO_JOB_ACTIVITY_RECORD>(t => true, newFilter);
                    var taskAnalysisIds = taskAnalysis.Select(t => t.ID).ToList();
                    sourceIds.AddRange(taskAnalysisIds);
                    //只取待办超期的
                    newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
                    var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2, newFilter);
                    tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
                    //表单运行情况分析表
                    var allAnalysis = this.GetEntities<T_BI_FORM_RUN_ANALYSIS>(t => true, new BaseFilter(filter.OrgId));
                    #region 岗位当班工作记录
                    if (evalPlan.Any())
                    {
                        //foreach (var item in evalPlan)
                        //{
                        //    var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        //    if (task == null)
                        //        item.IS_OVERTIME = 0;//不存在为正常已办
                        //    else
                        //        item.IS_OVERTIME = 1;//只要存在就超期
                        //}
                        var count = evalPlan.Count();
                        var finish = evalPlan.Count(t => t.OVERTIME == FOISOVERTIME.未超时 && t.SHIFT_STATUS == (int)FOShiftStatusEnum.归档);
                        var overfinish = evalPlan.Count(t => t.OVERTIME == FOISOVERTIME.超时 && t.SHIFT_STATUS == (int)FOShiftStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "岗位当班工作记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "岗位当班工作记录";
                            analysis.NUM = 30;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "岗位当班工作记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "岗位当班工作记录";
                            analysis.NUM = 30;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 岗位交接班记录
                    if (noticeRelease.Any())
                    {
                        //foreach (var item in noticeRelease)
                        //{
                        //    var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID && t.NOTICE_STATUS == 2);
                        //    if (task == null)
                        //        item.IS_OVERTIME = 0;
                        //    else
                        //        item.IS_OVERTIME = 1;
                        //}
                        var count = noticeRelease.Count();
                        var finish = evalPlan.Count(t => t.OVERTIME == FOISOVERTIME.未超时 && t.SHIFT_STATUS == (int)FOChangeShiftStatusEnum.归档);
                        var overfinish = evalPlan.Count(t => t.OVERTIME == FOISOVERTIME.超时 && t.SHIFT_STATUS == (int)FOChangeShiftStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "岗位交接班记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "岗位交接班记录";
                            analysis.NUM = 31;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "岗位交接班记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "岗位交接班记录";
                            analysis.NUM = 31;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 班组安全活动
                    if (riskTask.Any())
                    {
                        //foreach (var item in riskTask)
                        //{
                        //    var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID && t.NOTICE_STATUS == 2);
                        //    if (task == null)
                        //        item.IS_OVERTIME = 0;
                        //    else
                        //        item.IS_OVERTIME = 1;
                        //}
                        var count = riskTask.Count();
                        var finish = riskTask.Count(t => t.OVERTIME == FOISOVERTIME.未超时 && t.TA_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = riskTask.Count(t => t.OVERTIME == FOISOVERTIME.超时 && t.TA_STATUS == (int)FOTeamActivityState.已归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "班组安全活动");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "班组安全活动";
                            analysis.NUM = 32;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "班组安全活动");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "班组安全活动";
                            analysis.NUM = 32;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 班前会议记录
                    if (riskRecord.Any())
                    {
                        //foreach (var item in riskRecord)
                        //{
                        //    var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID && t.NOTICE_STATUS == 2);
                        //    if (task == null)
                        //        item.IS_OVERTIME = 0;
                        //    else
                        //        item.IS_OVERTIME = 1;
                        //}
                        var count = riskRecord.Count();
                        var finish = riskRecord.Count(t => t.OVERTIME == FOISOVERTIME.未超时 && t.PRE_MEETING_STATUS == FOPreMeetingStatusEnum.归档);
                        var overfinish = riskRecord.Count(t => t.OVERTIME == FOISOVERTIME.超时 && t.PRE_MEETING_STATUS == FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "班前会议记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "班前会议记录";
                            analysis.NUM = 33;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "班前会议记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "班前会议记录";
                            analysis.NUM = 33;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 作业活动记录（一般作业）
                    if (hazardTask.Any())
                    {
                        foreach (var item in hazardTask)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = hazardTask.Count();
                        var finish = hazardTask.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = hazardTask.Count(t => t.IS_OVERTIME == 1 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "作业活动记录（一般作业）");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "作业活动记录（一般作业）";
                            analysis.NUM = 34;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "作业活动记录（一般作业）");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "作业活动记录（一般作业）";
                            analysis.NUM = 34;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 作业方案讨论记录
                    if (hazardRecord.Any())
                    {
                        foreach (var item in hazardRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = hazardRecord.Count();
                        var finish = hazardRecord.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = hazardRecord.Count(t => t.IS_OVERTIME == 1 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "作业方案讨论记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "作业方案讨论记录";
                            analysis.NUM = 35;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "作业方案讨论记录");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "作业方案讨论记录";
                            analysis.NUM = 35;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 关键作业/许可作业工作票
                    if (evalResult.Any())
                    {
                        foreach (var item in evalResult)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = evalResult.Count();
                        var finish = evalResult.Count(t => t.IS_OVERTIME == 0 && t.IS_PUBLISH == (int)FOPreMeetingStatusEnum.归档);
                        var overfinish = evalResult.Count(t => t.IS_OVERTIME == 1 && t.IS_PUBLISH == (int)FOPreMeetingStatusEnum.归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "关键作业/许可作业工作票");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "关键作业/许可作业工作票";
                            analysis.NUM = 36;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "关键作业/许可作业工作票");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "关键作业/许可作业工作票";
                            analysis.NUM = 36;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 技术交底表
                    if (taskIdentify.Any())
                    {
                        foreach (var item in taskIdentify)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = taskIdentify.Count();
                        var finish = taskIdentify.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = taskIdentify.Count(t => t.IS_OVERTIME == 1 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "技术交底表");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "技术交底表";
                            analysis.NUM = 37;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "技术交底表");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "技术交底表";
                            analysis.NUM = 37;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    #region 作业活动记录（关键和许可作业）
                    if (taskAnalysis.Any())
                    {
                        foreach (var item in taskAnalysis)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        var count = taskAnalysis.Count();
                        var finish = taskAnalysis.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = taskAnalysis.Count(t => t.IS_OVERTIME == 1 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var unfinish = count - finish - overfinish;
                        var temp = count == 0 ? 0 : (double)(finish + overfinish) / count * 100;
                        var finishRate = temp.ToString("0") + "%";
                        var temp2 = count == 0 ? 0 : (double)finish / count * 100;
                        var normalFinishRate = temp2.ToString("0") + "%";
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "作业活动记录（关键和许可作业）");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "作业活动记录（关键和许可作业）";
                            analysis.NUM = 38;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = count;
                        analysis.FINISH_QTY = finish;
                        analysis.OVER_FINISH_QTY = overfinish;
                        analysis.UNFINISH_QTY = unfinish;
                        analysis.FINISH_RATE = finishRate;
                        analysis.NORMAL_FINISH_RATE = normalFinishRate;
                        formAnalysis.Add(analysis);
                    }
                    else
                    {
                        var analysis = allAnalysis.FirstOrDefault(t => t.MOUDLE_NAME == "作业现场管理" && t.FORM_NAME == "作业活动记录（关键和许可作业）");
                        if (analysis == null)
                        {
                            analysis = new T_BI_FORM_RUN_ANALYSIS();
                            analysis.MOUDLE_NAME = "作业现场管理";
                            analysis.FORM_NAME = "作业活动记录（关键和许可作业）";
                            analysis.NUM = 38;
                            analysis.ORG_ID = filter.OrgId;
                        }
                        analysis.TOTAL_QTY = 0;
                        analysis.FINISH_QTY = 0;
                        analysis.OVER_FINISH_QTY = 0;
                        analysis.UNFINISH_QTY = 0;
                        analysis.FINISH_RATE = "0%";
                        analysis.NORMAL_FINISH_RATE = "0%";
                        formAnalysis.Add(analysis);
                    }
                    #endregion

                    this.UnifiedCommit(() =>
                    {
                        if (formAnalysis != null && formAnalysis.Any())
                            BantchSaveEntityNoCommit(formAnalysis);
                    });
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.StackTrace))
                        throw new Exception("错误日志：[StackTrace]" + ex.StackTrace);
                    else
                        throw new Exception("【" + HttpContext.Request.Path + "】错误日志：[Message]" + ex.Message);
                }
                return true;
            });
        }

        //#region 年度风险评价计划审核表
        //[HttpPost, Route("AddEvalPlanInfo")]
        //public JsonActionResult<bool> AddEvalPlanInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime=Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        newFilter.SelectField = new List<string> { "ID", "STATUS", "INITIATING_DEPARTMENT" };
        //        //风险评价计划审核表
        //        var evalPlan = this.GetEntities<T_HM_EVALUATION_PLAN>(t => t.CREATE_TIME>= startTime && t.INITIATING_DEPARTMENT != null, newFilter);
        //        var sourceIds = evalPlan.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 风险评价计划审核表
        //        if (evalPlan.Any())
        //        {
        //            foreach (var item in evalPlan)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if(item.STATUS == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if(item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID= filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "年度风险评价计划审核表";
        //                analysis.NUM = 1;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 风险评价计划发布
        //[HttpPost, Route("AddNoticeReleaseInfo")]
        //public JsonActionResult<bool> AddNoticeReleaseInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        newFilter.SelectField = new List<string> { "ID", "RELEASE_STATUS", "RELEAS_DEPARTMENT_ID" };
        //        var noticeRelease = this.GetEntities<T_HM_NOTICE_RELEASE>(t => t.CREATE_TIME >= startTime && t.RELEAS_DEPARTMENT_ID != null, newFilter).ToList();
        //        var sourceIds = noticeRelease.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 风险评价计划发布
        //        if (noticeRelease.Any())
        //        {
        //            foreach (var item in noticeRelease)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.RELEASE_STATUS == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.RELEAS_DEPARTMENT_ID.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "风险评价计划发布";
        //                analysis.NUM = 2;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 危险源/风险辨识任务
        //[HttpPost, Route("AddRiskTaskInfo")]
        //public JsonActionResult<bool> AddRiskTaskInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        //危险源/风险辨识任务
        //        newFilter.SelectField = new List<string> { "ID", "STATUS", "INITIATING_DEPARTMENT" };
        //        var riskTask = this.GetEntities<T_HM_RISK_TASK>(t => t.CREATE_TIME >= startTime && t.INITIATING_DEPARTMENT!=null, newFilter).ToList();
        //        var sourceIds = riskTask.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 危险源/风险辨识任务
        //        if (riskTask.Any())
        //        {
        //            foreach (var item in riskTask)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.STATUS == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "危险源/风险辨识任务";
        //                analysis.NUM = 3;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 危险源/风险辨识记录表
        //[HttpPost, Route("AddRiskRecordInfo")]
        //public JsonActionResult<bool> AddRiskRecordInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        newFilter.SelectField = new List<string> { "ID", "STATUS", "INITIATING_DEPARTMENT" };
        //        //危险源/风险辨识记录表
        //        var riskRecord = this.GetEntities<T_HM_RISK_RECORD>(t => t.CREATE_TIME >= startTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
        //        var sourceIds = riskRecord.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 危险源/风险辨识记录表
        //        if (riskRecord.Any())
        //        {
        //            foreach (var item in riskRecord)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.STATUS == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "危险源/风险辨识记录表";
        //                analysis.NUM = 4;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 职业危害辨识任务
        //[HttpPost, Route("AddHazardTaskInfo")]
        //public JsonActionResult<bool> AddHazardTaskInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        newFilter.SelectField = new List<string> { "ID", "STATUS", "INITIATING_DEPARTMENT" };
        //        //职业危害辨识任务
        //        var hazardTask = this.GetEntities<T_HM_HAZARD_TASK>(t => t.CREATE_TIME >= startTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
        //        var sourceIds = hazardTask.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 职业危害辨识任务
        //        if (hazardTask.Any())
        //        {
        //            foreach (var item in hazardTask)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.STATUS == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "职业危害辨识任务";
        //                analysis.NUM = 5;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 职业危害辨识记录表
        //[HttpPost, Route("AddHazardRecordInfo")]
        //public JsonActionResult<bool> AddHazardRecordInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        newFilter.SelectField = new List<string> { "ID", "STATUS", "INITIATING_DEPARTMENT" };
        //        //职业危害辨识记录表
        //        var hazardRecord = this.GetEntities<T_HM_HAZARD_RECORD>(t => t.CREATE_TIME >= startTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
        //        var sourceIds = hazardRecord.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 职业危害辨识记录表
        //        if (hazardRecord.Any())
        //        {
        //            foreach (var item in hazardRecord)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.STATUS == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "职业危害辨识记录表";
        //                analysis.NUM = 6;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 评价结果表
        //[HttpPost, Route("AddEvalResultInfo")]
        //public JsonActionResult<bool> AddEvalResultInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        newFilter.SelectField = new List<string> { "ID", "STATUS", "INITIATING_DEPARTMENT" };
        //        //评价结果表
        //        var evalResult = this.GetEntities<T_HM_EVALUATE_RESULT>(t => t.CREATE_TIME >= startTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
        //        var sourceIds = evalResult.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 评价结果表
        //        if (evalResult.Any())
        //        {
        //            foreach (var item in evalResult)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.STATUS == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "评价结果表";
        //                analysis.NUM = 7;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 作业任务识别
        //[HttpPost, Route("AddTaskIdentifyInfo")]
        //public JsonActionResult<bool> AddTaskIdentifyInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        //作业任务识别
        //        newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH", "DEPARTMENT_ID" };
        //        var taskIdentify = this.GetEntities<T_HM_JOBTASK_IDENTIFY>(t => t.CREATE_TIME >= startTime && t.DEPARTMENT_ID != null, newFilter).ToList();
        //        var sourceIds = taskIdentify.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 作业任务识别
        //        if (taskIdentify.Any())
        //        {
        //            foreach (var item in taskIdentify)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.IS_PUBLISH == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.DEPARTMENT_ID.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "作业任务识别";
        //                analysis.NUM = 8;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 作业任务识别分析
        //[HttpPost, Route("AddTaskAnalysisInfo")]
        //public JsonActionResult<bool> AddTaskAnalysisInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH", "DEPARTMENT_ID" };
        //        //作业任务识别分析
        //        var taskAnalysis = this.GetEntities<T_HM_OPERATION_TASK_DISTINGUISH_ANALYZE>(t => t.CREATE_TIME >= startTime && t.DEPARTMENT_ID != null, newFilter).ToList();
        //        var sourceIds = taskAnalysis.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 作业任务识别分析
        //        if (taskAnalysis.Any())
        //        {
        //            foreach (var item in taskAnalysis)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.IS_PUBLISH == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.DEPARTMENT_ID.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "作业任务识别分析";
        //                analysis.NUM = 9;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 一般任务分析
        //[HttpPost, Route("AddTaskOrdinaryInfo")]
        //public JsonActionResult<bool> AddTaskOrdinaryInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH", "DEPARTMENT_ID" };
        //        //一般任务分析
        //        var taskOrdinary = this.GetEntities<T_HM_ORDINARY_TASK_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.DEPARTMENT_ID != null, newFilter).ToList();
        //        var sourceIds = taskOrdinary.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 一般任务分析
        //        if (taskOrdinary.Any())
        //        {
        //            foreach (var item in taskOrdinary)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.IS_PUBLISH == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.DEPARTMENT_ID.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "一般任务分析";
        //                analysis.NUM = 10;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 关键任务分析
        //[HttpPost, Route("AddTaskCrucialInfo")]
        //public JsonActionResult<bool> AddTaskCrucialInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH", "DEPARTMENT_ID" };
        //        //关键任务分析
        //        var taskCrucial = this.GetEntities<T_HM_CRUCIAL_TASK_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.DEPARTMENT_ID != null, newFilter).ToList();
        //        var sourceIds = taskCrucial.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 关键任务分析
        //        if (taskCrucial.Any())
        //        {
        //            foreach (var item in taskCrucial)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.IS_PUBLISH == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.DEPARTMENT_ID.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "关键任务分析";
        //                analysis.NUM = 11;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 许可任务分析
        //[HttpPost, Route("AddTaskLicenseInfo")]
        //public JsonActionResult<bool> AddTaskLicenseInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH", "DEPARTMENT_ID" };
        //        //许可任务分析
        //        var taskLicense = this.GetEntities<T_HM_LICENSE_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.DEPARTMENT_ID != null, newFilter).ToList();
        //        var sourceIds = taskLicense.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 许可任务分析
        //        if (taskLicense.Any())
        //        {
        //            foreach (var item in taskLicense)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.IS_PUBLISH == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.DEPARTMENT_ID.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "许可任务分析";
        //                analysis.NUM = 12;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        //#region 作业任务分析文件发布
        //[HttpPost, Route("AddFilePublishInfo")]
        //public JsonActionResult<bool> AddFilePublishInfo([FromBody] KeywordFilter filter)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var startTime = DateTime.Now.AddMonths(-1);
        //        if (string.IsNullOrEmpty(filter.Parameter1))
        //        {
        //            startTime = Convert.ToDateTime(filter.Parameter1);
        //        }
        //        List<T_BI_FORM_RUN_ANALYSIS_DETAIL> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS_DETAIL>();
        //        var newFilter = new BaseFilter(filter.OrgId);
        //        //作业任务分析文件发布
        //        newFilter.SelectField = new List<string> { "ID", "DEPARTMENT_ID" };
        //        var filePublish = this.GetEntities<T_HM_FILE_PUBLISH>(t => t.CREATE_TIME >= startTime && t.DEPARTMENT_ID != null, newFilter).ToList();
        //        var sourceIds = filePublish.Select(t => t.ID).ToList();
        //        //只取待办超期的
        //        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
        //        var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 2 && t.CREATE_TIME >= startTime, newFilter);
        //        tasks = tasks.Where(t => sourceIds.Contains(t.SOURCE_DATA_ID.Value)).ToList();
        //        #region 作业任务分析文件发布
        //        if (filePublish.Any())
        //        {
        //            foreach (var item in filePublish)
        //            {
        //                var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
        //                if (task == null)
        //                    item.IS_OVERTIME = 0;
        //                else
        //                    item.IS_OVERTIME = 1;
        //                var status = 0;
        //                if (item.IS_PUBLISH == FOPreMeetingStatusEnum.归档)
        //                {
        //                    if (item.IS_OVERTIME == 0)
        //                        status = 1;
        //                    else
        //                        status = 2;
        //                }
        //                var department = GetDepartmentId(item.DEPARTMENT_ID.Value);
        //                T_BI_FORM_RUN_ANALYSIS_DETAIL analysis = new T_BI_FORM_RUN_ANALYSIS_DETAIL();
        //                analysis.ID = item.ID;
        //                analysis.ORG_ID = filter.OrgId;
        //                analysis.MOUDLE_NAME = "风险管理";
        //                analysis.FORM_NAME = "作业任务分析文件发布";
        //                analysis.NUM = 13;
        //                analysis.FORM_CREATE_TIME = item.CREATE_TIME;
        //                analysis.DEPARTMENT_ID = department == null ? null : department.ID;
        //                analysis.DEPARTMENT_NAME = department == null ? null : department.NAME;
        //                analysis.STATUS = status;
        //                formAnalysis.Add(analysis);
        //            }
        //        }
        //        #endregion

        //        this.UnifiedCommit(() =>
        //        {
        //            if (formAnalysis != null && formAnalysis.Any())
        //                BantchSaveEntityNoCommit(formAnalysis);
        //        });
        //        return true;
        //    });
        //}
        //#endregion

        /// <summary>
        /// 获取部门级ID
        /// </summary>
        /// <returns></returns>
        //private T_FM_DEPARTMENT GetDepartmentId(Guid id)
        //{
        //    //var loginUserId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
        //    var department = GetEntity<T_FM_DEPARTMENT>(t => t.ID == id);
        //    if (department.DEPARTMENT_TYPE == (int)FMDepartmentType.部门 || department.DEPARTMENT_TYPE == (int)FMDepartmentType.公司)
        //    {
        //        return department;
        //    }
        //    else
        //    {
        //        department = GetDepartmentId(department.PARENT_ID.Value);
        //    }
        //    return department;
        //}

        #region 跑批-安全事务执行情况汇总
        /// <summary>
        /// 待办汇总跑批(安全事务执行情况汇总)
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("AddTaskInfo")]
        public JsonActionResult<bool> AddTaskInfo([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<bool>(() =>
            {
                try
                {
                    List<T_BI_SYSTEM_RUN_SUMMARY> departSummary = new List<T_BI_SYSTEM_RUN_SUMMARY>();
                    List<T_BI_MOULD_RUN_SUMMARY> mouldSummary = new List<T_BI_MOULD_RUN_SUMMARY>();
                    var dt = DateTime.Now.Date;
                    //最近一周
                    DateTime week = dt.AddDays(-7).Date;
                    //最近一月
                    DateTime month = dt.AddMonths(-1).Date;
                    //最近三月
                    DateTime threeMonth = dt.AddMonths(-3).Date;
                    //最近半年
                    DateTime sixMonth = dt.AddMonths(-6).Date;
                    //最近一年
                    DateTime year = dt.AddYears(-1).Date;
                    dt = Convert.ToDateTime(dt.ToString().Replace("0:00:00", "23:59:59"));
                    var newFilter = new BaseFilter(pageFilter.OrgId);
                    var taskYear = this.GetEntities<T_BI_NOTIFICATION_TASK_NEW>(t => t.CREATE_DATE >= year && t.CREATE_DATE <= dt, new BaseFilter(pageFilter.OrgId)).ToList();
                    newFilter.SelectField = new List<string> { "ID", "PARENT_ID", "NAME", "Nav_Parent", "DEPARTMENT_TYPE" };
                    var departmentInfos = this.GetEntities<T_FM_DEPARTMENT>(t => !t.IS_DELETED && t.ENABLE_STATUS == 0, newFilter).ToList();
                    //部门级
                    var departGroupYear = taskYear.Where(t => t.DEPT_DEPARTMENT_ID != null && t.MOUDLE_NAME != null).ToList();
                    var taskSixMonth = departGroupYear.Where(t => t.CREATE_DATE >= sixMonth).ToList();
                    var taskThreeMonth = departGroupYear.Where(t => t.CREATE_DATE >= threeMonth).ToList();
                    var taskMonth = departGroupYear.Where(t => t.CREATE_DATE >= month).ToList();
                    var taskWeek = departGroupYear.Where(t => t.CREATE_DATE >= week).ToList();
                    //车间级
                    var shopGroupYear = taskYear.Where(t => t.SHOP_DEPARTMENT_ID != null && t.MOUDLE_NAME != null).ToList();
                    var taskSixMonthShop = shopGroupYear.Where(t => t.CREATE_DATE >= sixMonth).ToList();
                    var taskThreeMonthShop = shopGroupYear.Where(t => t.CREATE_DATE >= threeMonth).ToList();
                    var taskMonthShop = shopGroupYear.Where(t => t.CREATE_DATE >= month).ToList();
                    var taskWeekShop = shopGroupYear.Where(t => t.CREATE_DATE >= week).ToList();
                    //班组级
                    var classGroupYear = taskYear.Where(t => t.CLASS_DEPARTMENT_ID != null).ToList();
                    var taskSixMonthClass = classGroupYear.Where(t => t.CREATE_DATE >= sixMonth).ToList();
                    var taskThreeMonthClass = classGroupYear.Where(t => t.CREATE_DATE >= threeMonth).ToList();
                    var taskMonthClass = classGroupYear.Where(t => t.CREATE_DATE >= month).ToList();
                    var taskWeekClass = classGroupYear.Where(t => t.CREATE_DATE >= week).ToList();
                    //年度
                    if (departGroupYear.Any())
                    {
                        var groupYearDepart = departGroupYear.GroupBy(t => t.DEPT_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastYear;
                            sum.TOTAL_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.部门;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                        var groupYearMould = departGroupYear.GroupBy(t => t.MOUDLE_NAME).ToList();
                        groupYearMould.ForEach(t =>
                        {
                            T_BI_MOULD_RUN_SUMMARY sum = new T_BI_MOULD_RUN_SUMMARY();
                            sum.MOUDLE_NAME = t.Key;
                            sum.ORG_ID = pageFilter.OrgId;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastYear;
                            sum.TOTAL_QTY = t.Where(m => m.MOUDLE_NAME == t.Key).Count();
                            sum.FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            mouldSummary.Add(sum);
                        });
                    }
                    if (shopGroupYear.Any())
                    {
                        var groupYearDepart = shopGroupYear.GroupBy(t => t.SHOP_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.PARENT_DEPARTMENT_ID = depart?.PARENT_ID;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastYear;
                            sum.TOTAL_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.车间;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                    }
                    if (classGroupYear.Any())
                    {
                        var groupYearDepart = classGroupYear.GroupBy(t => t.CLASS_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.PARENT_DEPARTMENT_ID = depart?.PARENT_ID;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastYear;
                            sum.TOTAL_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.班组;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                    }
                    //半年度
                    if (taskSixMonth.Any())
                    {
                        var groupYearDepart = taskSixMonth.GroupBy(t => t.DEPT_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastHalfYear;
                            sum.TOTAL_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.部门;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                        var groupYearMould = taskSixMonth.GroupBy(t => t.MOUDLE_NAME).ToList();
                        groupYearMould.ForEach(t =>
                        {
                            T_BI_MOULD_RUN_SUMMARY sum = new T_BI_MOULD_RUN_SUMMARY();
                            sum.MOUDLE_NAME = t.Key;
                            sum.ORG_ID = pageFilter.OrgId;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastHalfYear;
                            sum.TOTAL_QTY = t.Where(m => m.MOUDLE_NAME == t.Key).Count();
                            sum.FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            mouldSummary.Add(sum);
                        });
                    }
                    if (taskSixMonthShop.Any())
                    {
                        var groupYearDepart = taskSixMonthShop.GroupBy(t => t.SHOP_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.PARENT_DEPARTMENT_ID = depart?.PARENT_ID;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastHalfYear;
                            sum.TOTAL_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.车间;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                    }
                    if (taskSixMonthClass.Any())
                    {
                        var groupYearDepart = taskSixMonthClass.GroupBy(t => t.CLASS_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.PARENT_DEPARTMENT_ID = depart?.PARENT_ID;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastHalfYear;
                            sum.TOTAL_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.班组;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                    }
                    //三个月
                    if (taskThreeMonth.Any())
                    {
                        var groupYearDepart = taskThreeMonth.GroupBy(t => t.DEPT_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastThreeMonth;
                            sum.TOTAL_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.部门;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                        var groupYearMould = taskThreeMonth.GroupBy(t => t.MOUDLE_NAME).ToList();
                        groupYearMould.ForEach(t =>
                        {
                            T_BI_MOULD_RUN_SUMMARY sum = new T_BI_MOULD_RUN_SUMMARY();
                            sum.MOUDLE_NAME = t.Key;
                            sum.ORG_ID = pageFilter.OrgId;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastThreeMonth;
                            sum.TOTAL_QTY = t.Where(m => m.MOUDLE_NAME == t.Key).Count();
                            sum.FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            mouldSummary.Add(sum);
                        });
                    }
                    if (taskThreeMonthShop.Any())
                    {
                        var groupYearDepart = taskThreeMonthShop.GroupBy(t => t.SHOP_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.PARENT_DEPARTMENT_ID = depart?.PARENT_ID;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastThreeMonth;
                            sum.TOTAL_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.车间;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                    }
                    if (taskThreeMonthClass.Any())
                    {
                        var groupYearDepart = taskThreeMonthClass.GroupBy(t => t.CLASS_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.PARENT_DEPARTMENT_ID = depart?.PARENT_ID;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastThreeMonth;
                            sum.TOTAL_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.班组;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                    }
                    //一个月
                    if (taskMonth.Any())
                    {
                        var groupYearDepart = taskMonth.GroupBy(t => t.DEPT_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastMonth;
                            sum.TOTAL_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.部门;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                        var groupYearMould = taskMonth.GroupBy(t => t.MOUDLE_NAME).ToList();
                        groupYearMould.ForEach(t =>
                        {
                            T_BI_MOULD_RUN_SUMMARY sum = new T_BI_MOULD_RUN_SUMMARY();
                            sum.MOUDLE_NAME = t.Key;
                            sum.ORG_ID = pageFilter.OrgId;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastMonth;
                            sum.TOTAL_QTY = t.Where(m => m.MOUDLE_NAME == t.Key).Count();
                            sum.FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            mouldSummary.Add(sum);
                        });
                    }
                    if (taskMonthShop.Any())
                    {
                        var groupYearDepart = taskMonthShop.GroupBy(t => t.SHOP_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.PARENT_DEPARTMENT_ID = depart?.PARENT_ID;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastMonth;
                            sum.TOTAL_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.车间;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                    }
                    if (taskMonthClass.Any())
                    {
                        var groupYearDepart = taskMonthClass.GroupBy(t => t.CLASS_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.PARENT_DEPARTMENT_ID = depart?.PARENT_ID;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastMonth;
                            sum.TOTAL_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.班组;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                    }
                    //一周
                    if (taskWeek.Any())
                    {
                        var groupYearDepart = taskWeek.GroupBy(t => t.DEPT_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastWeek;
                            sum.TOTAL_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.部门;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                        var groupYearMould = taskWeek.GroupBy(t => t.MOUDLE_NAME).ToList();
                        groupYearMould.ForEach(t =>
                        {
                            T_BI_MOULD_RUN_SUMMARY sum = new T_BI_MOULD_RUN_SUMMARY();
                            sum.MOUDLE_NAME = t.Key;
                            sum.ORG_ID = pageFilter.OrgId;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastWeek;
                            sum.TOTAL_QTY = t.Where(m => m.MOUDLE_NAME == t.Key).Count();
                            sum.FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            mouldSummary.Add(sum);
                        });
                    }
                    if (taskWeekShop.Any())
                    {
                        var groupYearDepart = taskWeekShop.GroupBy(t => t.SHOP_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.PARENT_DEPARTMENT_ID = depart?.PARENT_ID;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastWeek;
                            sum.TOTAL_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.车间;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                    }
                    if (taskWeekClass.Any())
                    {
                        var groupYearDepart = taskWeekClass.GroupBy(t => t.CLASS_DEPARTMENT_ID).ToList();
                        groupYearDepart.ForEach(t =>
                        {
                            T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY();
                            sum.DEPARTMENT_ID = t.Key.Value;
                            sum.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value);
                            sum.DEPARTMENT_NAME = depart?.NAME;
                            sum.PARENT_DEPARTMENT_ID = depart?.PARENT_ID;
                            sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastWeek;
                            sum.TOTAL_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value).Count();
                            sum.FINISH_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count();
                            sum.OVER_FINISH_QTY = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count();
                            sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY;
                            sum.DEPARTMENT_TYPE = FMDepartmentType.班组;
                            var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100;
                            sum.FINISH_RATE = temp.ToString("0");
                            var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100;
                            sum.NORMAL_FINISH_RATE = temp2.ToString("0");
                            departSummary.Add(sum);
                        });
                    }
                    //折线图
                    List<T_BI_DEPARTMENT_MONTH_RUN> monthRuns = new List<T_BI_DEPARTMENT_MONTH_RUN>();
                    var ksDepartId = departmentInfos.FirstOrDefault(t => t.NAME == "矿山部")?.ID;
                    var xkDepartId = departmentInfos.FirstOrDefault(t => t.NAME == "选矿部")?.ID;
                    var currentMonth = DateTime.Now.Month;                       //获取当月
                    var currentDay = DateTime.Now.Day;                              //...........天

                    for (int i = 1; i <= 12; i++)
                    {
                        var monthStart = DateTime.Now.AddMonths(i - currentMonth).AddDays(1 - currentDay);
                        var monthEnd = DateTime.Now.AddMonths(i - currentMonth + 1).AddDays(1 - currentDay - 1);
                        var ksJantask = taskYear.Where(t => t.CREATE_DATE >= monthStart && t.CREATE_DATE <= monthEnd && t.DEPT_DEPARTMENT_ID == ksDepartId).ToList();
                        if (ksJantask.Any())
                        {
                            T_BI_DEPARTMENT_MONTH_RUN run = new T_BI_DEPARTMENT_MONTH_RUN();
                            run.DEPARTMENT_ID = ksDepartId.Value;
                            run.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == ksDepartId.Value);
                            run.DEPARTMENT_NAME = depart?.NAME;
                            run.MONTH = monthStart;
                            run.MONTHStr = monthStart.Year + "年" + monthStart.Month + "月";
                            var total = ksJantask.Count();
                            var finish = ksJantask.Where(t => t.NOTICE_STATUS == 1).Count();
                            var overFinish = ksJantask.Where(t => t.NOTICE_STATUS == 2).Count();
                            var temp = total == 0 ? 0 : (double)(finish + overFinish) / total * 100;
                            run.FINISH_RATE = temp.ToString("0");
                            var temp2 = total == 0 ? 0 : (double)finish / total * 100;
                            run.NORMAL_FINISH_RATE = temp2.ToString("0");
                            monthRuns.Add(run);
                        }
                        else
                        {
                            T_BI_DEPARTMENT_MONTH_RUN run = new T_BI_DEPARTMENT_MONTH_RUN();
                            run.DEPARTMENT_ID = ksDepartId.Value;
                            run.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == ksDepartId.Value);
                            run.DEPARTMENT_NAME = depart?.NAME;
                            run.MONTH = monthStart;
                            run.MONTHStr = monthStart.Year + "年" + monthStart.Month + "月";
                            run.FINISH_RATE = "0";
                            run.NORMAL_FINISH_RATE = "0";
                            if (i == 12)
                            {
                                var lastInfo = monthRuns.FirstOrDefault(t => t.DEPARTMENT_ID == ksDepartId.Value && t.MONTHStr == monthStart.Year + "年" + monthStart.AddMonths(-1).Month + "月");
                                if (lastInfo != null)
                                {
                                    run.FINISH_RATE = lastInfo.FINISH_RATE;
                                    run.NORMAL_FINISH_RATE = lastInfo.NORMAL_FINISH_RATE;
                                }
                            }
                            monthRuns.Add(run);
                        }
                        var xkJantask = taskYear.Where(t => t.CREATE_DATE >= monthStart && t.CREATE_DATE <= monthEnd && t.DEPT_DEPARTMENT_ID == xkDepartId).ToList();
                        if (xkJantask.Any())
                        {
                            T_BI_DEPARTMENT_MONTH_RUN run = new T_BI_DEPARTMENT_MONTH_RUN();
                            run.DEPARTMENT_ID = xkDepartId.Value;
                            run.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == xkDepartId.Value);
                            run.DEPARTMENT_NAME = depart?.NAME;
                            run.MONTH = monthStart;
                            run.MONTHStr = monthStart.Year + "年" + monthStart.Month + "月";
                            var total = xkJantask.Count();
                            var finish = xkJantask.Where(t => t.NOTICE_STATUS == 1).Count();
                            var overFinish = xkJantask.Where(t => t.NOTICE_STATUS == 2).Count();
                            var temp = total == 0 ? 0 : (double)(finish + overFinish) / total * 100;
                            run.FINISH_RATE = temp.ToString("0");
                            var temp2 = total == 0 ? 0 : (double)finish / total * 100;
                            run.NORMAL_FINISH_RATE = temp2.ToString("0");
                            monthRuns.Add(run);
                        }
                        else
                        {
                            T_BI_DEPARTMENT_MONTH_RUN run = new T_BI_DEPARTMENT_MONTH_RUN();
                            run.DEPARTMENT_ID = xkDepartId.Value;
                            run.ORG_ID = pageFilter.OrgId;
                            var depart = departmentInfos.FirstOrDefault(m => m.ID == xkDepartId.Value);
                            run.DEPARTMENT_NAME = depart?.NAME;
                            run.MONTH = monthStart;
                            run.MONTHStr = monthStart.Year + "年" + monthStart.Month + "月";
                            run.FINISH_RATE = "0";
                            run.NORMAL_FINISH_RATE = "0";
                            if (i == 12)
                            {
                                var lastInfo = monthRuns.FirstOrDefault(t => t.DEPARTMENT_ID == xkDepartId.Value && t.MONTHStr == monthStart.Year + "年" + monthStart.AddMonths(-1).Month + "月");
                                if (lastInfo != null)
                                {
                                    run.FINISH_RATE = lastInfo.FINISH_RATE;
                                    run.NORMAL_FINISH_RATE = lastInfo.NORMAL_FINISH_RATE;
                                }
                            }
                            monthRuns.Add(run);
                        }
                    }
                    var deleteIds = this.GetEntities<T_BI_SYSTEM_RUN_SUMMARY>(t => true, new BaseFilter(pageFilter.OrgId)).Select(m => m.ID).ToList();
                    var deletemouIds = this.GetEntities<T_BI_MOULD_RUN_SUMMARY>(t => true, new BaseFilter(pageFilter.OrgId)).Select(m => m.ID).ToList();
                    var deletemonthIds = this.GetEntities<T_BI_DEPARTMENT_MONTH_RUN>(t => true, new BaseFilter(pageFilter.OrgId)).Select(m => m.ID).ToList();
                    this.UnifiedCommit(() =>
                    {
                        if (deleteIds != null && deleteIds.Any())
                            BantchDeleteEntityNoCommit<T_BI_SYSTEM_RUN_SUMMARY>(deleteIds);
                        if (deleteIds != null && deleteIds.Any())
                            BantchDeleteEntityNoCommit<T_BI_MOULD_RUN_SUMMARY>(deletemouIds);
                        if (deleteIds != null && deleteIds.Any())
                            BantchDeleteEntityNoCommit<T_BI_DEPARTMENT_MONTH_RUN>(deletemonthIds);
                        if (departSummary != null && departSummary.Any())
                            BantchSaveEntityNoCommit(departSummary);
                        if (mouldSummary != null && mouldSummary.Any())
                            BantchSaveEntityNoCommit(mouldSummary);
                        if (monthRuns != null && monthRuns.Any())
                            BantchSaveEntityNoCommit(monthRuns);
                    });
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.StackTrace))
                        throw new Exception("错误日志：[StackTrace]" + ex.StackTrace);
                    else
                        throw new Exception("【" + HttpContext.Request.Path + "】错误日志：[Message]" + ex.Message);
                }
                return true;
            });
        }
        #endregion

        #region 跑批-更新所有待办的表名
        /// <summary>
        /// 更新7天所有待办的表名
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("UpdateTaskTable")]
        public JsonActionResult<bool> UpdateTaskTable([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<bool>(() =>
            {
                try
                {
                    var dt = DateTime.Now;
                    //最近一天
                    DateTime week = dt.AddDays(-1).Date;
                    if (!string.IsNullOrEmpty(pageFilter.Parameter1))
                    {
                        if (!pageFilter.Parameter1.Contains("|"))
                            throw new Exception("必须传入开始日期和结束日期，以|符号分隔");
                        var temp = pageFilter.Parameter1.Split("|");
                        if (temp[1].Length == 0)
                            throw new Exception("必须传入开始日期和结束日期，以|符号分隔");
                        week = DateTime.Parse(temp[0]);
                        dt = DateTime.Parse(temp[1]);
                    }
                    var formInfos = this.GetEntities<T_PF_FORM>(t => t.TABLE_NAME != null, new BaseFilter(pageFilter.OrgId)).ToList();
                    var formCodes = formInfos.Select(t => t.CODE).Distinct().ToList();
                    var taskInfos = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.CREATE_TIME >= week && t.CREATE_TIME <= dt && t.SOURCE_FORMCODE != "PF135" && t.SOURCE_FORMCODE != "PF119" && t.NOTICE_TYPE != 7 && t.NOTICE_TYPE != 8 && t.NOTICE_TYPE != 2 && t.SOURCE_FORMCODE != null && t.TABLE_NAME == null, new BaseFilter(pageFilter.OrgId)).ToList();
                    taskInfos.ForEach(t =>
                    {
                        if (t.SOURCE_FORMCODE.Contains("_SHOWPRINT"))
                        {
                            var table = formInfos.FirstOrDefault(m => m.CODE == t.SOURCE_FORMCODE.Split('_')[0]);
                            if (table != null)
                                t.TABLE_NAME = table.TABLE_NAME;
                        }
                        else
                        {
                            var table = formInfos.FirstOrDefault(m => m.CODE == t.SOURCE_FORMCODE);
                            if (table != null)
                                t.TABLE_NAME = table.TABLE_NAME;
                        }
                    });
                    this.UnifiedCommit(() =>
                    {
                        if (taskInfos != null && taskInfos.Any())
                            BantchSaveEntityNoCommit(taskInfos);
                    });
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.StackTrace))
                        throw new Exception("错误日志：[StackTrace]" + ex.StackTrace);
                    else
                        throw new Exception("【" + HttpContext.Request.Path + "】错误日志：[Message]" + ex.Message);
                }
                return true;
            });
        }
        #endregion

        #region 跑批-更新7天内今日提醒和审批的类型
        /// <summary>
        /// 更新7天内今日提醒和审批的类型
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("UpdateNoticeType")]
        public JsonActionResult<bool> UpdateNoticeType([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<bool>(() =>
            {
                try
                {
                    var dt = DateTime.Now;
                    //最近一周
                    DateTime week = dt.AddDays(-7).Date;
                    var taskInfos = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.CREATE_TIME >= week && (t.SOURCE_FORMCODE == "PF135" || t.SOURCE_FORMCODE == "PF119" || t.NOTICE_TITLE.Contains("审核")), new BaseFilter(pageFilter.OrgId)).ToList();
                    if (taskInfos.Any())
                    {
                        taskInfos.ForEach(t =>
                        {
                            if (t.SOURCE_FORMCODE == "PF135")
                                t.NOTICE_TYPE = 7;
                            if (t.SOURCE_FORMCODE == "PF119")
                                t.NOTICE_TYPE = 8;
                            if (t.SOURCE_FORMCODE != "PF119" && t.NOTICE_TITLE.Contains("审核"))
                                t.NOTICE_TYPE = 8;
                        });
                    }
                    this.UnifiedCommit(() =>
                    {
                        if (taskInfos != null && taskInfos.Any())
                            BantchSaveEntityNoCommit(taskInfos);
                    });

                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.StackTrace))
                        throw new Exception("错误日志：[StackTrace]" + ex.StackTrace);
                    else
                        throw new Exception("【" + HttpContext.Request.Path + "】错误日志：[Message]" + ex.Message);
                }
                return true;
            });
        }
        #endregion

        #region 跑批-待办中间表
        /// <summary>
        /// 更新7天内待办中间表
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("AddNoticeTask")]
        public JsonActionResult<bool> AddNoticeTask([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<bool>(() =>
            {
                try
                {
                    var dt = DateTime.Now;
                    //最近一周
                    DateTime week = dt.AddDays(-7).Date;
                    //最近一年
                    var taskInfos = new List<T_FM_NOTIFICATION_TASK>();
                    var biTaskInfos = new List<T_BI_NOTIFICATION_TASK>();
                    var addTaskInfos = new List<T_BI_NOTIFICATION_TASK>();
                    var newFilter = new BaseFilter(pageFilter.OrgId);
                    if (!string.IsNullOrEmpty(pageFilter.Parameter1))
                    {
                        if (!pageFilter.Parameter1.Contains("|"))
                            throw new Exception("必须传入开始日期和结束日期，以|符号分隔");
                        var temp = pageFilter.Parameter1.Split("|");
                        if (temp[1].Length == 0)
                            throw new Exception("必须传入开始日期和结束日期，以|符号分隔");
                        DateTime year = DateTime.Parse(temp[0]);
                        DateTime yearEnd = DateTime.Parse(temp[1]);
                        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
                        biTaskInfos = this.GetEntities<T_BI_NOTIFICATION_TASK>(t => t.CREATE_DATE >= year && t.CREATE_DATE < yearEnd, newFilter).ToList();
                        var dataIds = biTaskInfos.Select(t => t.SOURCE_DATA_ID).Distinct().ToList();
                        newFilter.SelectField = new List<string> { "NOTICE_TITLE", "NOTICE_STATUS", "USER_ID", "SOURCE_FORMCODE", "SOURCE_DATA_ID", "CREATE_TIME", "CREATER_ID" };
                        taskInfos = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.CREATE_TIME >= year && t.CREATE_TIME < yearEnd && t.NOTICE_TYPE != 7 && t.NOTICE_TYPE != 8 && t.USER_ID != null, newFilter).ToList();
                        taskInfos = taskInfos.Where(t => !dataIds.Contains(t.SOURCE_DATA_ID) && !t.NOTICE_TITLE.Contains("审核") && t.SOURCE_FORMCODE != "PF135" && t.SOURCE_FORMCODE != "PF119").ToList();
                    }
                    else
                    {
                        newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
                        biTaskInfos = this.GetEntities<T_BI_NOTIFICATION_TASK>(t => t.CREATE_DATE >= week, newFilter).ToList();
                        var dataIds = biTaskInfos.Select(t => t.SOURCE_DATA_ID).Distinct().ToList();
                        newFilter.SelectField = new List<string> { "NOTICE_TITLE", "NOTICE_STATUS", "USER_ID", "SOURCE_FORMCODE", "SOURCE_DATA_ID", "CREATE_TIME", "CREATER_ID" };
                        taskInfos = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.CREATE_TIME >= week && t.NOTICE_TYPE != 7 && t.NOTICE_TYPE != 8 && t.USER_ID != null, newFilter).ToList();
                        taskInfos = taskInfos.Where(t => !dataIds.Contains(t.SOURCE_DATA_ID) && !t.NOTICE_TITLE.Contains("审核") && t.SOURCE_FORMCODE != "PF135" && t.SOURCE_FORMCODE != "PF119").ToList();
                    }
                    //按sourcedataid分类
                    var groupTasks = taskInfos.GroupBy(t => t.SOURCE_DATA_ID).Select(p => new T_FM_NOTIFICATION_TASK
                    {
                        SOURCE_DATA_ID = p.Key,
                        NOTICE_TITLE = p.Where(q => q.SOURCE_DATA_ID == p.Key).OrderBy(g => g.CREATE_TIME).FirstOrDefault().NOTICE_TITLE,
                        USER_ID = p.Where(q => q.SOURCE_DATA_ID == p.Key).OrderBy(g => g.CREATE_TIME).FirstOrDefault().USER_ID,
                        CREATER_ID = p.Where(q => q.SOURCE_DATA_ID == p.Key).OrderBy(g => g.CREATE_TIME).FirstOrDefault().CREATER_ID,
                        CREATE_TIME = p.Where(q => q.SOURCE_DATA_ID == p.Key).OrderBy(g => g.CREATE_TIME).FirstOrDefault().CREATE_TIME,
                        SOURCE_FORMCODE = p.Where(q => q.SOURCE_DATA_ID == p.Key).OrderBy(g => g.CREATE_TIME).FirstOrDefault().SOURCE_FORMCODE,
                        NOTICE_STATUS = p.Where(q => q.SOURCE_DATA_ID == p.Key && q.NOTICE_STATUS == 0).FirstOrDefault() != null ? 0 : (p.Where(q => q.SOURCE_DATA_ID == p.Key && q.NOTICE_STATUS == 2).FirstOrDefault() != null ? 2 : 1),
                    }).ToList();
                    //人员表
                    newFilter.SelectField = new List<string> { "ID", "DEPARTMENT_ID" };
                    var userIds = groupTasks.Select(t => t.USER_ID).Distinct().ToList();
                    var userInfos = this.GetEntities<T_FM_USER>(t => userIds.Contains(t.ID) && t.ENABLE_STATUS == 0, newFilter).ToList();
                    //部门表
                    newFilter.SelectField = new List<string> { "ID", "PARENT_ID", "DEPARTMENT_TYPE", "Nav_Parent" };
                    var departmentInfos = this.GetEntities<T_FM_DEPARTMENT>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    if (groupTasks.Any())
                    {
                        groupTasks.ForEach(t =>
                        {
                            T_BI_NOTIFICATION_TASK task = new T_BI_NOTIFICATION_TASK();
                            task.ORG_ID = pageFilter.OrgId;
                            task.SOURCE_DATA_ID = t.SOURCE_DATA_ID;
                            task.CREATE_USER_ID = t.CREATER_ID;
                            task.NOTICE_STATUS = t.NOTICE_STATUS;
                            task.NOTICE_TITLE = t.NOTICE_TITLE;
                            task.SOURCE_FORMCODE = t.SOURCE_FORMCODE;
                            task.CREATE_DATE = t.CREATE_TIME;
                            var user = userInfos.FirstOrDefault(m => m.ID == t.USER_ID);
                            if (user != null)
                            {
                                var depart = departmentInfos.FirstOrDefault(m => m.ID == user.DEPARTMENT_ID);
                                if (depart != null)
                                {
                                    task.DEPARTMENT_ID = depart.ID;
                                    if (depart.DEPARTMENT_TYPE == 2)
                                    {
                                        task.CLASS_DEPARTMENT_ID = depart.ID;
                                        task.SHOP_DEPARTMENT_ID = depart.PARENT_ID;
                                        task.DEPT_DEPARTMENT_ID = depart.Nav_Parent?.PARENT_ID;
                                    }
                                    else if (depart.DEPARTMENT_TYPE == 1)
                                    {
                                        task.SHOP_DEPARTMENT_ID = depart.ID;
                                        task.DEPT_DEPARTMENT_ID = depart.PARENT_ID;
                                    }
                                    else if (depart.DEPARTMENT_TYPE == 0)
                                    {
                                        task.DEPT_DEPARTMENT_ID = depart.ID;
                                    }
                                }
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("HM") || t.SOURCE_FORMCODE.StartsWith("hm"))
                            {
                                task.MOUDLE_NAME = "风险管理";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("FO") || t.SOURCE_FORMCODE.StartsWith("fo"))
                            {
                                task.MOUDLE_NAME = "作业现场管理";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("BS") || t.SOURCE_FORMCODE.StartsWith("bs"))
                            {
                                task.MOUDLE_NAME = "安全检查";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("LR") || t.SOURCE_FORMCODE.StartsWith("lr"))
                            {
                                task.MOUDLE_NAME = "法律法规与其他要求";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("SE") || t.SOURCE_FORMCODE.StartsWith("se"))
                            {
                                task.MOUDLE_NAME = "安全教育培训";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("PT") || t.SOURCE_FORMCODE.StartsWith("pt"))
                            {
                                task.MOUDLE_NAME = "方针与目标管理";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("PE") || t.SOURCE_FORMCODE.StartsWith("pe"))
                            {
                                task.MOUDLE_NAME = "绩效测量与评价";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("PR") || t.SOURCE_FORMCODE.StartsWith("pr"))
                            {
                                task.MOUDLE_NAME = "生产工艺管理";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("AE") || t.SOURCE_FORMCODE.StartsWith("ae"))
                            {
                                task.MOUDLE_NAME = "事故事件";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("OG") || t.SOURCE_FORMCODE.StartsWith("og"))
                            {
                                task.MOUDLE_NAME = "安全生产组织保障";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("TI") || t.SOURCE_FORMCODE.StartsWith("ti"))
                            {
                                task.MOUDLE_NAME = "安全投入、科技与工伤";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("OH") || t.SOURCE_FORMCODE.StartsWith("oh"))
                            {
                                task.MOUDLE_NAME = "职业卫生";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("CM") || t.SOURCE_FORMCODE.StartsWith("cm"))
                            {
                                task.MOUDLE_NAME = "应急管理";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("DM") || t.SOURCE_FORMCODE.StartsWith("dm"))
                            {
                                task.MOUDLE_NAME = "机电安全管理";
                            }
                            if (t.SOURCE_FORMCODE.StartsWith("SC") || t.SOURCE_FORMCODE.StartsWith("sc"))
                            {
                                if (t.TABLE_NAME != null && t.TABLE_NAME.StartsWith("T_SC_MT"))
                                    task.MOUDLE_NAME = "会议管理";
                                else
                                    task.MOUDLE_NAME = "标准化创建";
                            }
                            addTaskInfos.Add(task);
                        });
                    }
                    this.UnifiedCommit(() =>
                    {
                        if (addTaskInfos != null && addTaskInfos.Any())
                            BantchAddEntityNoCommit(addTaskInfos);
                    });
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.StackTrace))
                        throw new Exception("错误日志：[StackTrace]" + ex.StackTrace);
                    else
                        throw new Exception("【" + HttpContext.Request.Path + "】错误日志：[Message]" + ex.Message);
                }
                return true;
            });
        }
        #endregion

        #region 跑批-删除一般作业user_id为null的数据
        /// <summary>
        /// 回调失败log执行
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("DeleteJobEventPerson")]
        public JsonActionResult<bool> DeleteJobEventPerson([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<bool>(() =>
            {
                var personIds = this.GetEntities<T_FO_JOB_EVENT_PERSON>(t => t.USER_ID == null, new BaseFilter(pageFilter.OrgId)).Select(m => m.ID).ToList();
                var tpersonIds = this.GetEntities<T_FO_TECH_DISCLOSURE_PERSON>(t => t.USER_ID == null, new BaseFilter(pageFilter.OrgId)).Select(m => m.ID).ToList();
                this.UnifiedCommit(() =>
                {
                    if (personIds != null && personIds.Any())
                    {
                        this.BantchDeleteEntityNoCommit<T_FO_JOB_EVENT_PERSON>(personIds);
                    }
                    if (tpersonIds != null && tpersonIds.Any())
                    {
                        this.BantchDeleteEntityNoCommit<T_FO_TECH_DISCLOSURE_PERSON>(tpersonIds);
                    }
                });
                return true;
            });
        }
        #endregion

        /// <summary>
        /// 删除一般作业重复的数据(仅限豫鹭)
        /// </summary>
        [HttpPost, Route("DeleteJobevent")]
        public JsonActionResult<bool> DeleteJobevent([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                var time = DateTime.Parse("2022-12-01 08:46:10.0000000");
                var stepIds = this.GetEntities<T_HM_OPERATION_STEP>(t => t.NAME.Contains("食堂") && t.ID != Guid.Parse("5E7C0BC3-F7DB-4452-BB13-BD4D4BB0900A") && t.ID != Guid.Parse("AC2BAD62-77C5-4366-B2DB-0B2633979978"), new BaseFilter(filter.OrgId)).Select(m => m.ID).ToList();
                var jobEventRecord = this.GetEntities<T_FO_JOB_EVENT_RECORD>(t => t.CREATE_TIME >= time && t.OPERATION_STEP_ID != null && stepIds.Contains((Guid)t.OPERATION_STEP_ID), new BaseFilter(filter.OrgId)).ToList();
                var groupRecord = jobEventRecord.GroupBy(t => new { t.OPERATION_STEP_ID, t.CREATE_TIME }).Select(m => m.OrderBy(m => m.MODIFY_TIME).FirstOrDefault()).ToList();
                var ids = groupRecord.Select(t => t.ID).ToList();
                var deleteIds = jobEventRecord.Where(m => !ids.Contains(m.ID)).Select(t => t.ID).ToList();
                var detailIds = this.GetEntities<T_FO_JOB_EVENT_DETAIL>(t => deleteIds.Contains(t.JOB_EVENT_RECORD_ID), new BaseFilter(filter.OrgId)).Select(m => m.ID).ToList();
                var personIds = this.GetEntities<T_FO_JOB_EVENT_PERSON>(t => deleteIds.Contains(t.JOB_EVENT_RECORD_ID), new BaseFilter(filter.OrgId)).Select(m => m.ID).ToList();
                var flowIds = this.GetEntities<T_FO_JOB_EVENT_FLOW>(t => deleteIds.Contains(t.JOB_EVENT_RECORD_ID), new BaseFilter(filter.OrgId)).Select(m => m.ID).ToList();
                var meaIds = this.GetEntities<T_FO_JOB_EVENT_MEASURE>(t => deleteIds.Contains(t.JOB_EVENT_RECORD_ID), new BaseFilter(filter.OrgId)).Select(m => m.ID).ToList();
                var taskIds = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => deleteIds.Contains((Guid)t.SOURCE_DATA_ID), new BaseFilter(filter.OrgId)).Select(m => m.ID).ToList();
                UnifiedCommit(() =>
                 {
                     if (deleteIds != null && deleteIds.Any())
                         this.BantchDeleteEntityNoCommit<T_FO_JOB_EVENT_RECORD>(deleteIds);
                     if (detailIds != null && detailIds.Any())
                         this.BantchDeleteEntityNoCommit<T_FO_JOB_EVENT_DETAIL>(detailIds);
                     if (personIds != null && personIds.Any())
                         this.BantchDeleteEntityNoCommit<T_FO_JOB_EVENT_PERSON>(personIds);
                     if (flowIds != null && flowIds.Any())
                         this.BantchDeleteEntityNoCommit<T_FO_JOB_EVENT_FLOW>(flowIds);
                     if (meaIds != null && meaIds.Any())
                         this.BantchDeleteEntityNoCommit<T_FO_JOB_EVENT_MEASURE>(meaIds);
                     if (taskIds != null && taskIds.Any())
                         this.BantchDeleteEntityNoCommit<T_FM_NOTIFICATION_TASK>(taskIds);
                 });
                return true;
            });
        }

        #region 跑批-7大作业分布情况
        /// <summary>
        /// 更新7天内待办中间表
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("JobProfile")]
        public JsonActionResult<bool> JobProfile([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<bool>(() =>
            {
                try
                {
                    //八大作业
                    var jobProfiles = new List<T_BI_JOB_PROFILE>();
                    var enumList = Enum.GetValues(typeof(StepTypeEnum));
                    var unitList = Enum.GetValues(typeof(FMProductionUnit));
                    var stepList = this.GetEntities<T_HM_OPERATION_STEP>(t => t.IS_SPECIAL == true, new BaseFilter(pageFilter.OrgId));
                    var stepIds = stepList.Select(t => t.ID).ToList();
                    var linkList = this.GetEntities<T_HM_OPERATION_LINK>(t => stepIds.Contains(t.OPERATION_STEP_ID.Value), new BaseFilter(pageFilter.OrgId));
                    var jobList = this.GetEntities<T_FO_CRUCIAL_LICENSE_JOB>(t => stepIds.Contains(t.OPERATION_STEP_ID.Value), new BaseFilter(pageFilter.OrgId)).Select(m => new { m.ID, m.OPERATION_STEP_ID }).ToList();
                    var stepTyes = stepList.Select(t => t.STEP_TYPE).Distinct().ToList();
                    foreach (FMProductionUnit unit in unitList)
                    {
                        foreach (StepTypeEnum level in enumList)
                        {
                            var fitstStep = stepList.Where(m => m.STEP_TYPE == level);
                            var stepItems = fitstStep.Select(m => m.ID).ToList();
                            var firstLink = linkList.FirstOrDefault(m => stepItems.Contains(m.OPERATION_STEP_ID.Value) && m.MineType.Value == unit.GetInt());
                            var jobCount = jobList.Where(m => stepItems.Contains(m.OPERATION_STEP_ID.Value)).Count();
                            T_BI_JOB_PROFILE job = new T_BI_JOB_PROFILE();
                            job.ORG_ID = pageFilter.OrgId;
                            job.MineType = unit;
                            job.JobName = level.GetDescription();
                            job.RiskCount = jobCount;
                            jobProfiles.Add(job);
                        };
                    }
                    var profilesIds = this.GetEntities<T_BI_JOB_PROFILE>(t => true, new BaseFilter(pageFilter.OrgId)).Select(m => m.ID).ToList();
                    this.UnifiedCommit(() =>
                    {
                        if (profilesIds != null && profilesIds.Any())
                            this.BantchDeleteEntityNoCommit<T_BI_JOB_PROFILE>(profilesIds);
                        if (jobProfiles != null && jobProfiles.Any())
                            BantchSaveEntityNoCommit(jobProfiles);
                    });
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.StackTrace))
                        throw new Exception("错误日志：[StackTrace]" + ex.StackTrace);
                    else
                        throw new Exception("【" + HttpContext.Request.Path + "】错误日志：[Message]" + ex.Message);
                }
                return true;
            });
        }
        #endregion

        #region 跑批-待办中间表
        /// <summary>
        /// 更新7天内待办中间表
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("AddNoticeTaskNew")]
        public JsonActionResult<bool> AddNoticeTaskNew([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<bool>(() =>
            {
                try
                {
                    var dt = DateTime.Now;
                    //最近一天
                    DateTime week = dt.AddDays(-1).Date;
                    var taskInfos = new List<T_FM_NOTIFICATION_TASK>();
                    var biTaskInfos = new List<T_BI_NOTIFICATION_TASK_NEW>();
                    var addTaskInfos = new List<T_BI_NOTIFICATION_TASK_NEW>();
                    var updateTaskInfos = new List<T_BI_NOTIFICATION_TASK_NEW>();
                    var deleteIds = new List<Guid>();
                    var newFilter = new BaseFilter(pageFilter.OrgId);
                    if (!string.IsNullOrEmpty(pageFilter.Parameter1))
                    {
                        if (!pageFilter.Parameter1.Contains("|"))
                            throw new Exception("必须传入开始日期和结束日期，以|符号分隔");
                        var temp = pageFilter.Parameter1.Split("|");
                        if (temp[1].Length == 0)
                            throw new Exception("必须传入开始日期和结束日期，以|符号分隔");
                        DateTime year = DateTime.Parse(temp[0] + " 00:00:00");
                        DateTime yearEnd = DateTime.Parse(temp[1] + " 23:59:59");
                        newFilter.SelectField = new List<string> {"ID", "NOTICE_TITLE", "NOTICE_STATUS", "USER_ID", "SOURCE_FORMCODE", "SOURCE_DATA_ID", "CREATE_TIME",
                        "CREATER_ID", "CODE","NOTICE_TYPE","TASK_DT","USER_NAME","TASK_STARTDT","TASK_ENDDT","FORM_TYPE","TABLE_NAME","IS_DELETED","ISCANCEL","SENDTIME" };
                        var taskInfoTemps = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => !t.IS_DELETED && t.MODIFY_TIME >= year && t.MODIFY_TIME < yearEnd && t.USER_ID != null && t.SOURCE_FORMCODE != null, newFilter).ToList();
                        //&& t.SOURCE_FORMCODE != "PF119" && t.SOURCE_FORMCODE != "PF135"&& t.NOTICE_TYPE != 7 && t.NOTICE_TYPE != 8 && t.NOTICE_TYPE != 2
                        var taskInfoIds = taskInfoTemps.Select(t => t.ID).ToList();
                        biTaskInfos = this.GetEntities<T_BI_NOTIFICATION_TASK_NEW>(t => taskInfoIds.Contains((Guid)t.TASK_ID), new BaseFilter(pageFilter.OrgId)).ToList();
                        var dataIds = biTaskInfos.Select(t => t.TASK_ID).Distinct();
                        taskInfos = taskInfoTemps.Where(t => !dataIds.Contains(t.ID)).ToList();//&& !t.NOTICE_TITLE.Contains("审核")
                        updateTaskInfos = biTaskInfos.Where(t => t.NOTICE_STATUS == 0).ToList();
                        updateTaskInfos.ForEach(t =>
                            {
                                var item = taskInfoTemps.FirstOrDefault(m => m.ID == t.TASK_ID);
                                if (item != null)
                                {
                                    t.NOTICE_STATUS = item.NOTICE_STATUS;
                                    t.TABLE_NAME = item.TABLE_NAME;
                                    t.IS_DELETED = item.IS_DELETED;
                                    t.ISCANCEL = item.ISCANCEL;
                                    t.SENDTIME = item.SENDTIME;
                                }
                            });
                    }
                    else
                    {
                        newFilter.SelectField = new List<string> {"ID", "NOTICE_TITLE", "NOTICE_STATUS", "USER_ID", "SOURCE_FORMCODE", "SOURCE_DATA_ID", "CREATE_TIME",
                        "CREATER_ID", "CODE","NOTICE_TYPE","TASK_DT","USER_NAME","TASK_STARTDT","TASK_ENDDT","FORM_TYPE","TABLE_NAME","IS_DELETED","ISCANCEL","SENDTIME" };
                        var taskInfoTemps = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => !t.IS_DELETED && t.MODIFY_TIME >= week && t.USER_ID != null && t.SOURCE_FORMCODE != null, newFilter).ToList();
                        //&& t.NOTICE_TYPE != 7 && t.NOTICE_TYPE != 8 && t.NOTICE_TYPE != 2 && t.SOURCE_FORMCODE != "PF135" && t.SOURCE_FORMCODE != "PF119"
                        var taskInfoIds = taskInfoTemps.Select(t => t.ID).ToList();
                        biTaskInfos = this.GetEntities<T_BI_NOTIFICATION_TASK_NEW>(t => taskInfoIds.Contains((Guid)t.TASK_ID), new BaseFilter(pageFilter.OrgId)).ToList();
                        var dataIds = biTaskInfos.Select(t => t.TASK_ID).Distinct().ToList();
                        taskInfos = taskInfoTemps.Where(t => !dataIds.Contains(t.ID)).ToList();//&& !t.NOTICE_TITLE.Contains("审核")
                        updateTaskInfos = biTaskInfos.Where(t => t.NOTICE_STATUS == 0).ToList();
                        updateTaskInfos.ForEach(t =>
                            {
                                var item = taskInfoTemps.FirstOrDefault(m => m.ID == t.TASK_ID);
                                if (item != null)
                                {
                                    t.NOTICE_STATUS = item.NOTICE_STATUS;
                                    t.TABLE_NAME = item.TABLE_NAME;
                                    t.IS_DELETED = item.IS_DELETED;
                                    t.ISCANCEL = item.ISCANCEL;
                                    t.SENDTIME = item.SENDTIME;
                                }
                            });
                    }
                    //人员表
                    newFilter.SelectField = new List<string> { "ID", "DEPARTMENT_ID" };
                    var userIds = taskInfos.Select(t => t.USER_ID).Distinct().ToList();
                    var userInfos = this.GetEntities<T_FM_USER>(t => userIds.Contains(t.ID), newFilter).ToList();
                    //部门表
                    newFilter.SelectField = new List<string> { "ID", "PARENT_ID", "DEPARTMENT_TYPE", "Nav_Parent" };
                    var departmentInfos = this.GetEntities<T_FM_DEPARTMENT>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    if (taskInfos.Any())
                    {
                        taskInfos.ForEach(t =>
                            {
                                T_BI_NOTIFICATION_TASK_NEW task = new T_BI_NOTIFICATION_TASK_NEW();
                                task.ORG_ID = pageFilter.OrgId;
                                task.TASK_ID = t.ID;
                                task.SOURCE_DATA_ID = t.SOURCE_DATA_ID;
                                task.CREATER_ID = t.CREATER_ID;
                                task.NOTICE_STATUS = t.NOTICE_STATUS;
                                task.NOTICE_TITLE = t.NOTICE_TITLE;
                                task.SOURCE_FORMCODE = t.SOURCE_FORMCODE;
                                task.CREATE_DATE = t.CREATE_TIME;
                                task.USER_ID = t.USER_ID;
                                task.CODE = t.CODE;
                                task.NOTICE_TYPE = t.NOTICE_TYPE;
                                task.TASK_DT = t.TASK_DT;
                                task.USER_NAME = t.USER_NAME;
                                task.TASK_STARTDT = t.TASK_STARTDT;
                                task.TASK_ENDDT = t.TASK_ENDDT;
                                task.FORM_TYPE = t.FORM_TYPE;
                                task.TABLE_NAME = t.TABLE_NAME;
                                task.IS_DELETED = t.IS_DELETED;
                                task.ISCANCEL = t.ISCANCEL;
                                task.SENDTIME = t.SENDTIME;
                                var user = userInfos.FirstOrDefault(m => m.ID == t.USER_ID);
                                if (user != null)
                                {
                                    var depart = departmentInfos.FirstOrDefault(m => m.ID == user.DEPARTMENT_ID);
                                    if (depart != null)
                                    {
                                        if (depart.DEPARTMENT_TYPE == 2)
                                        {
                                            task.CLASS_DEPARTMENT_ID = depart.ID;
                                            task.SHOP_DEPARTMENT_ID = depart.PARENT_ID;
                                            task.DEPT_DEPARTMENT_ID = depart.Nav_Parent?.PARENT_ID;
                                        }
                                        else if (depart.DEPARTMENT_TYPE == 1)
                                        {
                                            task.CLASS_DEPARTMENT_ID = null;
                                            task.SHOP_DEPARTMENT_ID = depart.ID;
                                            task.DEPT_DEPARTMENT_ID = depart.PARENT_ID;
                                        }
                                        else if (depart.DEPARTMENT_TYPE == 0)
                                        {
                                            task.CLASS_DEPARTMENT_ID = null;
                                            task.SHOP_DEPARTMENT_ID = null;
                                            task.DEPT_DEPARTMENT_ID = depart.ID;
                                        }
                                    }
                                }
                                if (t.SOURCE_FORMCODE == "PF119")
                                {
                                    task.MOUDLE_NAME = "审批管理";
                                }
                                if (t.SOURCE_FORMCODE == "PF135")
                                {
                                    task.MOUDLE_NAME = "今日提醒";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("HM") || t.SOURCE_FORMCODE.StartsWith("hm"))
                                {
                                    task.MOUDLE_NAME = "风险管理";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("FO") || t.SOURCE_FORMCODE.StartsWith("fo"))
                                {
                                    task.MOUDLE_NAME = "作业现场管理";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("BS") || t.SOURCE_FORMCODE.StartsWith("bs"))
                                {
                                    task.MOUDLE_NAME = "安全检查";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("LR") || t.SOURCE_FORMCODE.StartsWith("lr"))
                                {
                                    task.MOUDLE_NAME = "法律法规与其他要求";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("SE") || t.SOURCE_FORMCODE.StartsWith("se"))
                                {
                                    task.MOUDLE_NAME = "安全教育培训";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("PT") || t.SOURCE_FORMCODE.StartsWith("pt"))
                                {
                                    task.MOUDLE_NAME = "方针与目标管理";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("PE") || t.SOURCE_FORMCODE.StartsWith("pe"))
                                {
                                    task.MOUDLE_NAME = "绩效测量与评价";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("PR") || t.SOURCE_FORMCODE.StartsWith("pr"))
                                {
                                    task.MOUDLE_NAME = "生产工艺管理";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("AE") || t.SOURCE_FORMCODE.StartsWith("ae"))
                                {
                                    task.MOUDLE_NAME = "事故事件";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("OG") || t.SOURCE_FORMCODE.StartsWith("og"))
                                {
                                    task.MOUDLE_NAME = "安全生产组织保障";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("TI") || t.SOURCE_FORMCODE.StartsWith("ti"))
                                {
                                    task.MOUDLE_NAME = "安全投入、科技与工伤";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("OH") || t.SOURCE_FORMCODE.StartsWith("oh"))
                                {
                                    task.MOUDLE_NAME = "职业卫生";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("CM") || t.SOURCE_FORMCODE.StartsWith("cm"))
                                {
                                    task.MOUDLE_NAME = "应急管理";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("DM") || t.SOURCE_FORMCODE.StartsWith("dm"))
                                {
                                    task.MOUDLE_NAME = "机电安全管理";
                                }
                                if (t.SOURCE_FORMCODE.StartsWith("SC") || t.SOURCE_FORMCODE.StartsWith("sc"))
                                {
                                    if (t.TABLE_NAME != null && t.TABLE_NAME.StartsWith("T_SC_MT"))
                                        task.MOUDLE_NAME = "会议管理";
                                    else
                                        task.MOUDLE_NAME = "标准化创建";
                                }
                                addTaskInfos.Add(task);
                            });
                    }
                    this.UnifiedCommit(() =>
                        {
                            if (addTaskInfos != null && addTaskInfos.Any())
                                BantchAddEntityNoCommit(addTaskInfos);
                            if (updateTaskInfos != null && updateTaskInfos.Any())
                                BantchUpdateEntityNoCommit(updateTaskInfos);
                            //if (deleteIds != null && deleteIds.Any())
                            //    BantchDeleteEntityNoCommit<T_BI_NOTIFICATION_TASK_NEW>(deleteIds);
                        });
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.StackTrace))
                        throw new Exception("错误日志：[StackTrace]" + ex.StackTrace);
                    else
                        throw new Exception("【" + HttpContext.Request.Path + "】错误日志：[Message]" + ex.Message);
                }
                return true;
            });
        }
        #endregion

        #region 跑批-更新跑批中间表的表名
        /// <summary>
        /// 更新7天所有待办的表名
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("UpdateTaskTableNew")]
        public JsonActionResult<bool> UpdateTaskTableNew([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<bool>(() =>
            {
                try
                {
                    var dt = DateTime.Now;
                    //最近一周
                    DateTime week = dt.AddDays(-1).Date;
                    if (!string.IsNullOrEmpty(pageFilter.Parameter1))
                    {
                        if (!pageFilter.Parameter1.Contains("|"))
                            throw new Exception("必须传入开始日期和结束日期，以|符号分隔");
                        var temp = pageFilter.Parameter1.Split("|");
                        if (temp[1].Length == 0)
                            throw new Exception("必须传入开始日期和结束日期，以|符号分隔");
                        week = DateTime.Parse(temp[0]);
                        dt = DateTime.Parse(temp[1]);
                    }
                    var formInfos = this.GetEntities<T_PF_FORM>(t => t.TABLE_NAME != null, new BaseFilter(pageFilter.OrgId)).ToList();
                    var formCodes = formInfos.Select(t => t.CODE).Distinct().ToList();
                    var taskInfos = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.CREATE_TIME >= week && t.CREATE_TIME <= dt && t.SOURCE_FORMCODE != "PF135" && t.SOURCE_FORMCODE != "PF119" && t.NOTICE_TYPE != 7 && t.NOTICE_TYPE != 8 && t.NOTICE_TYPE != 2 && t.SOURCE_FORMCODE != null && t.TABLE_NAME != null, new BaseFilter(pageFilter.OrgId)).ToList();
                    var taskIds = taskInfos.Select(t => t.ID).ToList();
                    var biTaskInfos = this.GetEntities<T_BI_NOTIFICATION_TASK_NEW>(t => t.CREATE_DATE >= week && t.CREATE_DATE <= dt, new BaseFilter(pageFilter.OrgId)).ToList();
                    biTaskInfos = biTaskInfos.Where(t => t.TASK_ID != null && taskIds.Contains((Guid)t.TASK_ID)).ToList();
                    if (biTaskInfos != null && biTaskInfos.Any())
                    {
                        foreach (var item in biTaskInfos)
                        {
                            var taskFirst = taskInfos.FirstOrDefault(t => t.ID == item.TASK_ID);
                            if (taskFirst != null)
                            {
                                item.TABLE_NAME = taskFirst.TABLE_NAME;
                                item.SOURCE_FORMCODE = taskFirst.SOURCE_FORMCODE;
                                if (item.SOURCE_FORMCODE.StartsWith("HM") || item.SOURCE_FORMCODE.StartsWith("hm"))
                                {
                                    item.MOUDLE_NAME = "风险管理";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("FO") || item.SOURCE_FORMCODE.StartsWith("fo"))
                                {
                                    item.MOUDLE_NAME = "作业现场管理";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("BS") || item.SOURCE_FORMCODE.StartsWith("bs"))
                                {
                                    item.MOUDLE_NAME = "安全检查";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("LR") || item.SOURCE_FORMCODE.StartsWith("lr"))
                                {
                                    item.MOUDLE_NAME = "法律法规与其他要求";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("SE") || item.SOURCE_FORMCODE.StartsWith("se"))
                                {
                                    item.MOUDLE_NAME = "安全教育培训";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("PT") || item.SOURCE_FORMCODE.StartsWith("pt"))
                                {
                                    item.MOUDLE_NAME = "方针与目标管理";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("PE") || item.SOURCE_FORMCODE.StartsWith("pe"))
                                {
                                    item.MOUDLE_NAME = "绩效测量与评价";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("PR") || item.SOURCE_FORMCODE.StartsWith("pr"))
                                {
                                    item.MOUDLE_NAME = "生产工艺管理";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("AE") || item.SOURCE_FORMCODE.StartsWith("ae"))
                                {
                                    item.MOUDLE_NAME = "事故事件";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("OG") || item.SOURCE_FORMCODE.StartsWith("og"))
                                {
                                    item.MOUDLE_NAME = "安全生产组织保障";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("TI") || item.SOURCE_FORMCODE.StartsWith("ti"))
                                {
                                    item.MOUDLE_NAME = "安全投入、科技与工伤";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("OH") || item.SOURCE_FORMCODE.StartsWith("oh"))
                                {
                                    item.MOUDLE_NAME = "职业卫生";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("CM") || item.SOURCE_FORMCODE.StartsWith("cm"))
                                {
                                    item.MOUDLE_NAME = "应急管理";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("DM") || item.SOURCE_FORMCODE.StartsWith("dm"))
                                {
                                    item.MOUDLE_NAME = "机电安全管理";
                                }
                                if (item.SOURCE_FORMCODE.StartsWith("SC") || item.SOURCE_FORMCODE.StartsWith("sc"))
                                {
                                    if (item.TABLE_NAME != null && item.TABLE_NAME.StartsWith("T_SC_MT"))
                                        item.MOUDLE_NAME = "会议管理";
                                    else
                                        item.MOUDLE_NAME = "标准化创建";
                                }
                            }
                        }
                    }
                    this.UnifiedCommit(() =>
                        {
                            if (biTaskInfos != null && biTaskInfos.Any())
                                BantchSaveEntityNoCommit(biTaskInfos);
                        });
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.StackTrace))
                        throw new Exception("错误日志：[StackTrace]" + ex.StackTrace);
                    else
                        throw new Exception("【" + HttpContext.Request.Path + "】错误日志：[Message]" + ex.Message);
                }
                return true;
            });
        }
        #endregion

    }
}
