using APT.BaseData.Domain.ApiModel;
using APT.BaseData.Domain.Entities;
using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.Enums;
using APT.BaseData.Domain.Enums.PF;
using APT.BaseData.Domain.IServices;
using APT.BaseData.Domain.IServices.FM;
using APT.BaseData.Services.DomainServices;
using APT.BaseData.Services.Services.FM;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.BI;
using APT.MS.Domain.Entities.BS;
using APT.MS.Domain.Entities.FO;
using APT.MS.Domain.Entities.HM;

using APT.MS.Domain.Entities.OG;
using APT.MS.Domain.Entities.PF;
using APT.MS.Domain.Entities.SC;
using APT.MS.Domain.Entities.SC.BI;
using APT.MS.Domain.Entities.SC.PT;
using APT.MS.Domain.Entities.SC.SC;
using APT.MS.Domain.Entities.SE;
using APT.MS.Domain.Enums;
using APT.Utility;
using Castle.Core.Internal;
using ICSharpCode.SharpZipLib.Core;
using InfluxData.Net.InfluxDb.Models.Responses;
using InfluxData.Net.Kapacitor.Models;
using log4net.Filter;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using MySqlX.XDevAPI.Common;
using NPOI.SS.Formula.Functions;
using Renci.SshNet.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace APT.SC.WebApi.Controllers.Api.BIController
{
    public class GroupbyMouldName
    {
        public string mouldName { get; set; }
        public int totalCount { get; set; }
        public int doneCount { get; set; }
        public int timeOverCount { get; set; }
    }
    public class GroupbyDepartmentId
    {
        public Guid? departmentId { get; set; }
        public string departmentName { get; set; }
        public string formCode { get; set; }
        public string formName { get; set; }
        public int TotalCount { get; set; }
        public int doneCount { get; set; }
        public int timeOverCount { get; set; }
    }
    public class DepartmentInfos
    {
        public string NAME { get; set; }
        public string USER_NAME { get; set; }

        public string CHARGE_NAME { get; set; }
        public int DEPARTMENT_TYPE { get; set; }
    }
    public class ApproveUserInfos
    {
        public int DEPARTMENT_TYPE { get; set; }
        public string DEPARTMENT_NAME { get; set; }
        public string APPROVE_ROLE_NAME { get; set; }
        public string USER_INFO { get; set; }
    }
    public class ParentDepartmentInfo
    {
        public Guid parent_departmentId { get; set; }
        public Guid departmentId { get; set; }

        public string parent_departmentName { get; set; }
        public string departmentName { get; set; }
    }
    public class UnFinishInfo
    {
        public string NAME { get; set; }
        public string CREATE_NAME { get; set; }

        public string DEPARTMENT_NAME { get; set; }
        public DateTime? CREATE_TIME { get; set; }
        public string STATUS_NAME { get; set; }
    }
    public class GroupbyDepartmentCompletion
    {
        public Guid? shopId { get; set; }
        public string shopName { get; set; }
        public int shopTotalCount { get; set; }
        public int shopDoneCount { get; set; }
        public int shopOntimeCount { get; set; }
        public double shopDoneRate { get; set; }
        public double shopOverDoneRate { get; set; }
        public Guid? teamId { get; set; }
        public string teamName { get; set; }
        public int teamTotalCount { get; set; }
        public int teamDoneCount { get; set; }
        public int teamOntimeCount { get; set; }
        public int teamUndoneCount { get; set; }
        public double teamDoneRate { get; set; }
        public double teamOverDoneRate { get; set; }
        public string month { get; set; }
        public string name { get; set; }
    }
    public class LoginInfo
    {
        public string NAME { get; set; }
        public DateTime? CREATE_TIME { get; set; }
        public string FROM { get; set; }
        public string VERSION { get; set; }
        public int QTY { get; set; }
    }
    public class DepartmentInfo
    {
        public Guid? parent_departmentId { get; set; }
        public Guid departmentId { get; set; }

        public int departmentType { get; set; }
        public string departmentName { get; set; }
        public int num { get; set; }
        public List<DepartmentInfo> deptInfos { get; set; }
    }
    /// <summary>
    ///  
    /// </summary>
    [Route("api/BI/BIStatiscialAnalysisController")]
    public class BIStatiscialAnalysisController : AuthorizeApiController<T_FM_NOTIFICATION_TASK>
    {
        IPFApproveCallBackService ApproveCallBackService { get; set; }
        public BIStatiscialAnalysisController(IPFApproveCallBackService approveCallBackService)
        {
            ApproveCallBackService = approveCallBackService;
        }
        #region 安全事务执行情况汇总
        /// <summary>
        /// 待办汇总查询
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetAllTask")]
        public JsonActionResult<dynamic> GetAllTask([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<dynamic>(() =>
            {
                //首页待办增加数量统计字段
                dynamic ret = new System.Dynamic.ExpandoObject();
                //var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (string.IsNullOrEmpty(pageFilter.Parameter1) || string.IsNullOrEmpty(pageFilter.Parameter2))
                {
                    throw new Exception("请先选择时间段");
                }
                var newFilter = new BaseFilter(pageFilter.OrgId);
                newFilter.SelectField = new List<string> { "CODE", "NAME" };
                var formInfo = this.GetEntities<T_PF_FORM>(t => true, newFilter);
                DateTime startTime = Convert.ToDateTime(pageFilter.Parameter1 + " 00:00:00");
                DateTime endTime = Convert.ToDateTime(pageFilter.Parameter2 + " 23:59:59");
                TimeSpan span = endTime.Subtract(startTime);
                int dayDidd = span.Days + 1;
                if (dayDidd >= 180)
                    throw new Exception("查询时间不能超过6个月!");
                var result = GetOrderPageEntities<T_BI_NOTIFICATION_TASK_NEW>(s => !s.IS_DELETED && s.CREATE_DATE >= startTime && s.CREATE_DATE <= endTime, pageFilter);
                //pageFilter.Sort = "CREATE_TIME";
                //pageFilter.Order = DbOrder.DESC;
                if (result.Data.Any())
                {
                    var newData = result.Data.ToList();
                    var userIds = newData.Select(t => t.USER_ID).Distinct().ToList();
                    newFilter.SelectField = new List<string> { "ID", "DEPARTMENT_ID", "Nav_Department" };
                    var userInfos = this.GetEntities<T_FM_USER>(t => userIds.Contains(t.ID) && t.ENABLE_STATUS == 0, newFilter);
                    newData.ForEach(t =>
                    {
                        var user = userInfos.FirstOrDefault(m => m.ID == t.USER_ID);
                        var department = GetDepartmentId(user.DEPARTMENT_ID.Value);
                        t.DEPARTMENT_ID = department == null ? null : department.ID;
                        t.DEPARTMENT_NAME = department == null ? "" : department.NAME;
                    });
                    //if (!string.IsNullOrEmpty(pageFilter.Keyword))
                    //{
                    //    newData = newData.Where(t => t.DEPARTMENT_ID == Guid.Parse(pageFilter.Keyword)).ToList();
                    //}
                    ret.newData = newData;
                    ret.TotalCount = newData.Count();
                    ret.doneCount = newData.Where(t => t.NOTICE_STATUS == 1).Count();
                    ret.timeOverCount = newData.Where(t => t.NOTICE_STATUS == 2).Count();
                    //if (!string.IsNullOrEmpty(pageFilter.Keyword))
                    //{
                    //    var formCodes = newData.Select(t => t.SOURCE_FORMCODE).Distinct().ToList();
                    //    var forms = this.GetEntities<T_PF_FORM>(t => formCodes.Contains(t.CODE), new BaseFilter(pageFilter.OrgId));
                    //    ret.groupData = newData.GroupBy(t => t.SOURCE_FORMCODE).Select(m => new GroupbyDepartmentId
                    //    {
                    //        formCode = m.Key,
                    //        formName = forms.FirstOrDefault(p => p.CODE == m.Key)?.NAME,
                    //        TotalCount = m.Count(),
                    //        doneCount = m.Where(p => p.NOTICE_STATUS == 1).Count(),
                    //        timeOverCount = m.Where(p => p.NOTICE_STATUS == 2).Count(),
                    //    }).ToList();
                    //}
                    //else 
                    var groupDataTemp = newData.GroupBy(t => new { t.DEPARTMENT_ID, t.DEPARTMENT_NAME, t.SOURCE_FORMCODE }).Select(m => new GroupbyDepartmentId
                    {
                        departmentId = m.Key.DEPARTMENT_ID,
                        departmentName = m.Key.DEPARTMENT_NAME,
                        formCode = m.Key.SOURCE_FORMCODE,
                        formName = formInfo.FirstOrDefault(p => p.CODE == m.Key.SOURCE_FORMCODE)?.NAME,
                        TotalCount = m.Count(p => p.DEPARTMENT_ID == m.Key.DEPARTMENT_ID && p.SOURCE_FORMCODE == m.Key.SOURCE_FORMCODE),
                        doneCount = m.Count(p => p.DEPARTMENT_ID == m.Key.DEPARTMENT_ID && p.NOTICE_STATUS == 1 && p.SOURCE_FORMCODE == m.Key.SOURCE_FORMCODE),
                        timeOverCount = m.Count(p => p.DEPARTMENT_ID == m.Key.DEPARTMENT_ID && p.NOTICE_STATUS == 2 && p.SOURCE_FORMCODE == m.Key.SOURCE_FORMCODE),
                    }).ToList();
                    ret.groupData = groupDataTemp;
                }
                return ret;
            });
        }
        /// <summary>
        /// 获取部门级ID
        /// </summary>
        /// <returns></returns>
        public 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.公司)
            {
                return null;
            }
            else if (department.DEPARTMENT_TYPE == (int)FMDepartmentType.部门)
            {
                return department;
            }
            else
            {
                department = GetDepartmentId(department.PARENT_ID.Value);
            }
            return department;
        }

        /// <summary>
        /// 获取组织ID的部门级组织
        /// </summary>
        /// <param name="DepartmentID"></param>
        /// <returns></returns>
        public T_FM_DEPARTMENT GetDEPARTMENTLevel(List<T_FM_DEPARTMENT> departList, Guid DepartmentID)
        {
            var department = GetEntity<T_FM_DEPARTMENT>(t => t.ID == DepartmentID);
            if (department.DEPARTMENT_TYPE == (int)FMDepartmentType.公司)
            {
                return null;
            }
            else if (department.DEPARTMENT_TYPE == (int)FMDepartmentType.部门)
            {
                return department;
            }
            else
            {
                department = GetDEPARTMENTLevel(departList, department.PARENT_ID.Value);
            }
            return department;
        }
        /// <summary>
        /// 获取组织ID的车间级组织
        /// </summary>
        /// <param name="DepartmentID"></param>
        /// <returns></returns>
        public T_FM_DEPARTMENT GetDEPARTMENTShop(List<T_FM_DEPARTMENT> departList,Guid DepartmentID)
        {
            var department = GetEntity<T_FM_DEPARTMENT>(t => t.ID == DepartmentID);
            if (department.DEPARTMENT_TYPE == (int)FMDepartmentType.部门 || department.DEPARTMENT_TYPE == (int)FMDepartmentType.公司)
            { 
                return null;
            }
            else if (department.DEPARTMENT_TYPE == (int)FMDepartmentType.车间)
            {
                return department;
            }
            else
            {
                department = GetDEPARTMENTShop(departList,department.PARENT_ID.Value);
            }
            return department;
        }
        /// <summary>
        /// 获取组织ID的班组级组织
        /// </summary>
        /// <param name="DepartmentID"></param>
        /// <returns></returns>
        public T_FM_DEPARTMENT GetDEPARTMENTClass(List<T_FM_DEPARTMENT> departList, Guid DepartmentID)
        {
            var department = GetEntity<T_FM_DEPARTMENT>(t => t.ID == DepartmentID);
            if (department.DEPARTMENT_TYPE == (int)FMDepartmentType.车间 || department.DEPARTMENT_TYPE == (int)FMDepartmentType.部门 || department.DEPARTMENT_TYPE == (int)FMDepartmentType.公司)
            {
                return null;
            }
            else if (department.DEPARTMENT_TYPE == (int)FMDepartmentType.班组)
            {
                return department;
            }
            else
            {
                department = GetDEPARTMENTClass(departList,department.PARENT_ID.Value);
            }
            return department;
        }
        #endregion
        /// <summary>
        /// 返回所有下级部门节点
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="listDepIDInt"></param>
        /// <param name="departmentIdPs"></param>
        public void GetDepartmentIds(Guid orgId, List<Guid> listDepIDInt, ref List<Guid> departmentIdPs)
        {
            var listDep = GetEntities<T_FM_DEPARTMENT>(e => !e.IS_DELETED && e.PARENT_ID.HasValue && listDepIDInt.Contains(e.PARENT_ID.Value),new BaseFilter(orgId));

            if (listDep != null && listDep.Any())
            {
                listDepIDInt = listDep.Select(e => e.ID).ToList();
                departmentIdPs.AddRange(listDepIDInt);
                GetDepartmentIds(orgId, listDepIDInt, ref departmentIdPs);
            }
        }
        [HttpPost, Route("GetFormRun")]
        public JsonActionResult<List<T_BI_FORM_RUN_ANALYSIS>> GetFormRun([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_BI_FORM_RUN_ANALYSIS>>(() =>
            {
                //首页待办增加数量统计字段
                //var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (string.IsNullOrEmpty(filter.Parameter1))
                {
                    throw new Exception("请先选择开始时间");
                }
                if (string.IsNullOrEmpty(filter.Parameter2))
                {
                    throw new Exception("请先选择结束时间");
                }
                List<Guid> outPartmentIds = new List<Guid>();
                if (!string.IsNullOrEmpty(filter.Keyword))
                {
                    List<Guid> inputIds = new List<Guid>() { Guid.Parse(filter.Keyword) };
                    GetDepartmentIds(APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value, inputIds, ref outPartmentIds);
                    outPartmentIds.Add(Guid.Parse(filter.Keyword));
                }
                
                List<T_BI_FORM_RUN_ANALYSIS> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS>();
                List<ParentDepartmentInfo> parentDepartments = new List<ParentDepartmentInfo>();
                DateTime startTime = Convert.ToDateTime(filter.Parameter1);
                DateTime endTime = Convert.ToDateTime(filter.Parameter2);
                TimeSpan span = endTime.Subtract(startTime);
                int dayDidd = span.Days + 1;
                if (dayDidd >= 180)
                    throw new Exception("查询时间不能超过6个月!");
                //var sourceIds = new List<Guid>();
                var departmentIds = new List<Guid?>();
                var newFilter = new BaseFilter(filter.OrgId);
                newFilter.IgnoreDataRule = true;
                if (string.IsNullOrEmpty(filter.Parameter3))
                {
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "INITIATING_DEPARTMENT" };
                    //风险评价计划审核表
                    var evalPlan = this.GetEntities<T_HM_EVALUATION_PLAN>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //风险评价计划发布
                    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.CREATE_TIME <= endTime && t.RELEAS_DEPARTMENT_ID != null, newFilter).ToList();
                    //危险源/风险辨识任务
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "INITIATING_DEPARTMENT" };
                    var riskTask = this.GetEntities<T_HM_RISK_TASK>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //危险源/风险辨识记录表
                    var riskRecord = this.GetEntities<T_HM_RISK_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //职业危害辨识任务
                    var hazardTask = this.GetEntities<T_HM_HAZARD_TASK>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //职业危害辨识记录表
                    var hazardRecord = this.GetEntities<T_HM_HAZARD_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //评价结果表
                    var evalResult = this.GetEntities<T_HM_EVALUATE_RESULT>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //作业任务识别
                    newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH", "DEPARTMENT_ID" };
                    var taskIdentify = this.GetEntities<T_HM_JOBTASK_IDENTIFY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //作业任务识别分析
                    var taskAnalysis = this.GetEntities<T_HM_OPERATION_TASK_DISTINGUISH_ANALYZE>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //一般任务分析
                    var taskOrdinary = this.GetEntities<T_HM_ORDINARY_TASK_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //关键任务分析
                    var taskCrucial = this.GetEntities<T_HM_CRUCIAL_TASK_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //许可任务分析
                    var taskLicense = this.GetEntities<T_HM_LICENSE_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //作业任务分析文件发布
                    var filePublish = this.GetEntities<T_HM_FILE_PUBLISH>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    newFilter.SelectField = new List<string> { "ID", "STATUSPLAN", "STATUCHECK", "DEPARTMENTID" };
                    //检查任务制定
                    var checkTask = this.GetEntities<T_BS_SAFE_CHECK>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENTID != null, newFilter).ToList();
                    //检查记录
                    var checkRecord = checkTask.Where(t => t.STATUSPLAN == (int)HMAuditStatusEnmu.归档).ToList();
                    ////隐患上报
                    //newFilter.SelectField = new List<string> { "ID", "SUBMIT_STATUS", "DEPARTMENT_ID" };
                    //var riskSubmit = this.GetEntities<T_BS_RISK_SUBMIT>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //隐患整改记录
                    newFilter.SelectField = new List<string> { "ID", "DEALSITUATION", "Nav_UserDeal" };
                    var riskDeal = this.GetEntities<T_BS_RISK_SUBMIT_CONTENT_DEAL>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_UserDeal != null && t.Nav_UserDeal.DEPARTMENT_ID != null, newFilter).ToList();
                    //延期整改申请
                    newFilter.SelectField = new List<string> { "ID", "APPLY_DEPARTMENT_ID" };
                    var delayApply = this.GetEntities<T_BS_RISK_SUBMIT_DELAY_APPLY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.APPLY_DEPARTMENT_ID != null, newFilter).ToList();
                    newFilter.SelectField = new List<string> { "ID", "SHIFT_STATUS", "OVERTIME", "DEPARTMENT_ID", "Nav_Team" };
                    //岗位当班工作记录
                    var classRecord = this.GetEntities<T_FO_CURRENT_CLASS_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //岗位交接班记录
                    var shiftRecord = this.GetEntities<T_FO_CHANGE_SHIFT_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //班组安全活动
                    newFilter.SelectField = new List<string> { "ID", "TA_STATUS", "OVERTIME", "Nav_User" };
                    var teamActive = this.GetEntities<T_FO_TEAM_ACTIVITY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null, newFilter).ToList();
                    //班前会议记录
                    newFilter.SelectField = new List<string> { "ID", "PRE_MEETING_STATUS", "OVERTIME", "DEPARTMENT_ID", "Nav_Team" };
                    var shiftMeeting = this.GetEntities<T_FO_PRE_SHIFT_MEETING_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //作业活动记录（一般作业）
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS", "Nav_CreateUser" };
                    var eventRecord = this.GetEntities<T_FO_JOB_EVENT_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_CreateUser != null && t.Nav_CreateUser.DEPARTMENT_ID != null, newFilter).ToList();
                    //作业方案讨论记录
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS", "DEPARTMENT_ID" };
                    var operSch = this.GetEntities<T_FO_PRE_OPER_SCH>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //关键作业/许可作业工作票
                    newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH", "Nav_ApplyUser" };
                    var licenseJob = this.GetEntities<T_FO_CRUCIAL_LICENSE_JOB>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_ApplyUser != null && t.Nav_ApplyUser.DEPARTMENT_ID != null, newFilter).ToList();
                    //技术交底表
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS", "Nav_DisclosurePerson" };
                    var techForm = this.GetEntities<T_FO_TECH_DISCLOSURE_FROM>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_DisclosurePerson != null && t.Nav_DisclosurePerson.DEPARTMENT_ID != null, newFilter).ToList();
                    //作业活动记录（关键和许可作业）
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS", "Nav_CreateUser" };
                    var activeRecord = this.GetEntities<T_FO_JOB_ACTIVITY_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_CreateUser != null && t.Nav_CreateUser.DEPARTMENT_ID != null, newFilter).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 && t.CREATE_TIME <= endTime, newFilter).ToList();
                    //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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            evalPlan = evalPlan.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            noticeRelease = noticeRelease.Where(t => outPartmentIds.Contains((Guid)t.RELEAS_DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            riskTask = riskTask.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            riskRecord = riskRecord.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            hazardTask = hazardTask.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            hazardRecord = hazardRecord.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            evalResult = evalResult.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskIdentify = taskIdentify.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskAnalysis = taskAnalysis.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskOrdinary = taskOrdinary.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskCrucial = taskCrucial.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskLicense = taskLicense.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            filePublish = filePublish.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        var count = filePublish.Count();
                        var finish = filePublish.Count(t => t.IS_OVERTIME == 0 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = filePublish.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 检查任务制定
                    if (checkTask.Any())
                    {
                        foreach (var item in checkTask)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            checkTask = checkTask.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENTID)).ToList();
                        }
                        var count = checkTask.Count();
                        var finish = checkTask.Count(t => t.IS_OVERTIME == 0 && t.STATUSPLAN == (int)HMAuditStatusEnmu.归档);
                        var overfinish = checkTask.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 检查记录
                    if (checkRecord.Any())
                    {
                        foreach (var item in checkRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            checkRecord = checkRecord.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENTID)).ToList();
                        }
                        var count = checkRecord.Count();
                        var finish = checkRecord.Count(t => t.IS_OVERTIME == 0 && t.STATUCHECK == (int)HMAuditStatusEnmu.归档);
                        var overfinish = checkRecord.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 隐患上报
                    //if (riskSubmit.Any())
                    //{
                    //    foreach (var item in riskSubmit)
                    //    {
                    //        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                    //        if (task == null)
                    //            item.IS_OVERTIME = 0;
                    //        else
                    //            item.IS_OVERTIME = 1;
                    //    }
                    //    if (!string.IsNullOrEmpty(filter.Keyword))
                    //    {
                    //        riskSubmit = riskSubmit.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    //    }
                    //    var count = riskSubmit.Count();
                    //    var finish = riskSubmit.Count(t => t.IS_OVERTIME == 0 && t.SUBMIT_STATUS == (int)BSSubmitStatusEnum.Start);
                    //    var overfinish = riskSubmit.Count(t => t.IS_OVERTIME == 1 && t.SUBMIT_STATUS == (int)BSSubmitStatusEnum.Start);
                    //    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") + "%";
                    //    T_BI_FORM_RUN_ANALYSIS 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);
                    //}
                    #endregion

                    #region 隐患整改记录
                    if (riskDeal.Any())
                    {
                        foreach (var item in riskDeal)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            riskDeal = riskDeal.Where(t => outPartmentIds.Contains((Guid)t.Nav_UserDeal.DEPARTMENT_ID)).ToList();
                        }
                        var count = riskDeal.Count();
                        var finish = riskDeal.Count(t => t.IS_OVERTIME == 0 && t.DEALSITUATION == (int)DealSituation.End);
                        var overfinish = riskDeal.Count(t => t.IS_OVERTIME == 1 && t.DEALSITUATION == (int)DealSituation.End);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 延期整改申请
                    if (delayApply.Any())
                    {
                        foreach (var item in delayApply)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            delayApply = delayApply.Where(t => outPartmentIds.Contains((Guid)t.APPLY_DEPARTMENT_ID)).ToList();
                        }
                        var count = delayApply.Count();
                        var finish = delayApply.Count(t => t.IS_OVERTIME == 0);
                        var overfinish = delayApply.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 岗位当班工作记录
                    if (classRecord.Any())
                    {
                        //var taskIds = tasks.Select(t => t.ID).ToList();
                        foreach (var item in classRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            classRecord = classRecord.Where(t => outPartmentIds.Contains((Guid)t.Nav_Team?.DEPARTMENT_ID)).ToList();
                            if (!classRecord.Any())
                            {
                                classRecord = classRecord.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                            }
                            //var recordIds = classRecord.Where(t => t.IS_OVERTIME == 1 && t.SHIFT_STATUS == (int)FOShiftStatusEnum.归档).Select(t => t.ID).ToList();
                        }
                        var count = classRecord.Count();
                        var finish = classRecord.Count(t => t.IS_OVERTIME == 0 && t.SHIFT_STATUS == (int)FOShiftStatusEnum.归档);
                        var overfinish = classRecord.Count(t => t.IS_OVERTIME == 1 && 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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 岗位交接班记录
                    if (shiftRecord.Any())
                    {
                        foreach (var item in shiftRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            shiftRecord = shiftRecord.Where(t => outPartmentIds.Contains((Guid)t.Nav_Team?.DEPARTMENT_ID)).ToList();
                            if (!shiftRecord.Any())
                            {
                                shiftRecord = shiftRecord.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                            }
                        }
                        var count = shiftRecord.Count();
                        var finish = shiftRecord.Count(t => t.IS_OVERTIME == 0 && t.SHIFT_STATUS == (int)FOChangeShiftStatusEnum.归档);
                        var overfinish = shiftRecord.Count(t => t.IS_OVERTIME == 1 && 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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 班组安全活动
                    if (teamActive.Any())
                    {
                        foreach (var item in teamActive)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            teamActive = teamActive.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                        }
                        var count = teamActive.Count();
                        var finish = teamActive.Count(t => t.IS_OVERTIME == 0 && t.TA_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = teamActive.Count(t => t.IS_OVERTIME == 1 && 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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 班前会议记录
                    if (shiftMeeting.Any())
                    {
                        foreach (var item in shiftMeeting)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            shiftMeeting = shiftMeeting.Where(t => outPartmentIds.Contains((Guid)t.Nav_Team?.DEPARTMENT_ID)).ToList();
                            if (!shiftMeeting.Any())
                            {
                                shiftMeeting = shiftMeeting.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                            }
                        }
                        var count = shiftMeeting.Count();
                        var finish = shiftMeeting.Count(t => t.IS_OVERTIME == 0 && t.PRE_MEETING_STATUS == FOPreMeetingStatusEnum.归档);
                        var overfinish = shiftMeeting.Count(t => t.IS_OVERTIME == 1 && 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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 作业活动记录（一般作业）
                    if (eventRecord.Any())
                    {
                        foreach (var item in eventRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            eventRecord = eventRecord.Where(t => outPartmentIds.Contains((Guid)t.Nav_CreateUser.DEPARTMENT_ID)).ToList();
                        }
                        var count = eventRecord.Count();
                        var finish = eventRecord.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = eventRecord.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 作业方案讨论记录
                    if (operSch.Any())
                    {
                        foreach (var item in operSch)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            operSch = operSch.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        var count = operSch.Count();
                        var finish = operSch.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = operSch.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 关键作业/许可作业工作票
                    if (licenseJob.Any())
                    {
                        foreach (var item in licenseJob)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            licenseJob = licenseJob.Where(t => outPartmentIds.Contains((Guid)t.Nav_ApplyUser.DEPARTMENT_ID)).ToList();
                        }
                        var count = licenseJob.Count();
                        var finish = licenseJob.Count(t => t.IS_OVERTIME == 0 && t.IS_PUBLISH == (int)FOPreMeetingStatusEnum.归档);
                        var overfinish = licenseJob.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 技术交底表
                    if (techForm.Any())
                    {
                        foreach (var item in techForm)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            techForm = techForm.Where(t => outPartmentIds.Contains((Guid)t.Nav_DisclosurePerson.DEPARTMENT_ID)).ToList();
                        }
                        var count = techForm.Count();
                        var finish = techForm.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = techForm.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 作业活动记录（关键和许可作业）
                    if (activeRecord.Any())
                    {
                        foreach (var item in activeRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            activeRecord = activeRecord.Where(t => outPartmentIds.Contains((Guid)t.Nav_CreateUser.DEPARTMENT_ID)).ToList();
                        }
                        var count = activeRecord.Count();
                        var finish = activeRecord.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = activeRecord.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && filter.Parameter3 == "风险管理")
                {
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "INITIATING_DEPARTMENT" };
                    //风险评价计划审核表
                    var evalPlan = this.GetEntities<T_HM_EVALUATION_PLAN>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //风险评价计划发布
                    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.CREATE_TIME <= endTime && t.RELEAS_DEPARTMENT_ID != null, newFilter).ToList();
                    //危险源/风险辨识任务
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "INITIATING_DEPARTMENT" };
                    var riskTask = this.GetEntities<T_HM_RISK_TASK>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //危险源/风险辨识记录表
                    var riskRecord = this.GetEntities<T_HM_RISK_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //职业危害辨识任务
                    var hazardTask = this.GetEntities<T_HM_HAZARD_TASK>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //职业危害辨识记录表
                    var hazardRecord = this.GetEntities<T_HM_HAZARD_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //评价结果表
                    var evalResult = this.GetEntities<T_HM_EVALUATE_RESULT>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null, newFilter).ToList();
                    //作业任务识别
                    newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH", "DEPARTMENT_ID" };
                    var taskIdentify = this.GetEntities<T_HM_JOBTASK_IDENTIFY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //作业任务识别分析
                    var taskAnalysis = this.GetEntities<T_HM_OPERATION_TASK_DISTINGUISH_ANALYZE>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //一般任务分析
                    var taskOrdinary = this.GetEntities<T_HM_ORDINARY_TASK_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //关键任务分析
                    var taskCrucial = this.GetEntities<T_HM_CRUCIAL_TASK_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //许可任务分析
                    var taskLicense = this.GetEntities<T_HM_LICENSE_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //作业任务分析文件发布
                    var filePublish = this.GetEntities<T_HM_FILE_PUBLISH>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).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 && t.CREATE_TIME <= endTime, newFilter).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 department = parentDepartments.FirstOrDefault(t=>t.departmentId == item.INITIATING_DEPARTMENT);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            evalPlan = evalPlan.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.RELEAS_DEPARTMENT_ID.Value);
                            //item.RELEAS_DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.RELEAS_DEPARTMENT_ID);
                            //item.RELEAS_DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            noticeRelease = noticeRelease.Where(t => outPartmentIds.Contains((Guid)t.RELEAS_DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.INITIATING_DEPARTMENT);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            riskTask = riskTask.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.INITIATING_DEPARTMENT);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            riskRecord = riskRecord.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.INITIATING_DEPARTMENT);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            hazardTask = hazardTask.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.INITIATING_DEPARTMENT);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            hazardRecord = hazardRecord.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.INITIATING_DEPARTMENT.Value);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.INITIATING_DEPARTMENT);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            evalResult = evalResult.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskIdentify = taskIdentify.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskAnalysis = taskAnalysis.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskOrdinary = taskOrdinary.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskCrucial = taskCrucial.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskLicense = taskLicense.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #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 department = GetDepartmentId(item.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            filePublish = filePublish.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        var count = filePublish.Count();
                        var finish = filePublish.Count(t => t.IS_OVERTIME == 0 && t.IS_PUBLISH == MS.Domain.Enums.FOPreMeetingStatusEnum.归档);
                        var overfinish = filePublish.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && filter.Parameter3 == "安全检查")
                {
                    newFilter.SelectField = new List<string> { "ID", "STATUSPLAN", "STATUCHECK", "DEPARTMENTID" };
                    //检查任务制定
                    var checkTask = this.GetEntities<T_BS_SAFE_CHECK>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENTID != null, newFilter).ToList();
                    //检查记录
                    var checkRecord = checkTask.Where(t => t.STATUSPLAN == (int)HMAuditStatusEnmu.归档).ToList();
                    //隐患上报
                    //newFilter.SelectField = new List<string> { "ID", "SUBMIT_STATUS", "DEPARTMENT_ID" };
                    //var riskSubmit = this.GetEntities<T_BS_RISK_SUBMIT>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //隐患整改记录
                    newFilter.SelectField = new List<string> { "ID", "DEALSITUATION", "Nav_UserDeal" };
                    var riskDeal = this.GetEntities<T_BS_RISK_SUBMIT_CONTENT_DEAL>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_UserDeal != null && t.Nav_UserDeal.DEPARTMENT_ID != null, newFilter).ToList();
                    //延期整改申请
                    newFilter.SelectField = new List<string> { "ID", "APPLY_DEPARTMENT_ID" };
                    var delayApply = this.GetEntities<T_BS_RISK_SUBMIT_DELAY_APPLY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.APPLY_DEPARTMENT_ID != null, newFilter).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 && t.CREATE_TIME <= endTime, newFilter).ToList();
                    #region 检查任务制定
                    if (checkTask.Any())
                    {
                        foreach (var item in checkTask)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.DEPARTMENTID.Value);
                            //item.DEPARTMENTID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.DEPARTMENTID);
                            //item.DEPARTMENTID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            checkTask = checkTask.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENTID)).ToList();
                        }
                        var count = checkTask.Count();
                        var finish = checkTask.Count(t => t.IS_OVERTIME == 0 && t.STATUSPLAN == (int)HMAuditStatusEnmu.归档);
                        var overfinish = checkTask.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 检查记录
                    if (checkRecord.Any())
                    {
                        foreach (var item in checkRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.DEPARTMENTID.Value);
                            //item.DEPARTMENTID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.DEPARTMENTID);
                            //item.DEPARTMENTID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            checkRecord = checkRecord.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENTID)).ToList();
                        }
                        var count = checkRecord.Count();
                        var finish = checkRecord.Count(t => t.IS_OVERTIME == 0 && t.STATUCHECK == (int)HMAuditStatusEnmu.归档);
                        var overfinish = checkRecord.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 隐患上报
                    //if (riskSubmit.Any())
                    //{
                    //    foreach (var item in riskSubmit)
                    //    {
                    //        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                    //        if (task == null)
                    //            item.IS_OVERTIME = 0;
                    //        else
                    //            item.IS_OVERTIME = 1;
                    //        //var department = GetDepartmentId(item.DEPARTMENT_ID.Value);
                    //        //item.DEPARTMENT_ID = department == null ? null : department.ID;
                    //        //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.DEPARTMENT_ID);
                    //        //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                    //    }
                    //    if (!string.IsNullOrEmpty(filter.Keyword))
                    //    {
                    //        riskSubmit = riskSubmit.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    //    }
                    //    var count = riskSubmit.Count();
                    //    var finish = riskSubmit.Count(t => t.IS_OVERTIME == 0 && t.SUBMIT_STATUS == (int)BSSubmitStatusEnum.Start);
                    //    var overfinish = riskSubmit.Count(t => t.IS_OVERTIME == 1 && t.SUBMIT_STATUS == (int)BSSubmitStatusEnum.Start);
                    //    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") + "%";
                    //    T_BI_FORM_RUN_ANALYSIS 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);
                    //}
                    #endregion

                    #region 隐患整改记录
                    if (riskDeal.Any())
                    {
                        foreach (var item in riskDeal)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.Nav_UserDeal.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_UserDeal.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            riskDeal = riskDeal.Where(t => outPartmentIds.Contains((Guid)t.Nav_UserDeal.DEPARTMENT_ID)).ToList();
                        }
                        var count = riskDeal.Count();
                        var finish = riskDeal.Count(t => t.IS_OVERTIME == 0 && t.DEALSITUATION == (int)DealSituation.End);
                        var overfinish = riskDeal.Count(t => t.IS_OVERTIME == 1 && t.DEALSITUATION == (int)DealSituation.End);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 延期整改申请
                    if (delayApply.Any())
                    {
                        foreach (var item in delayApply)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.APPLY_DEPARTMENT_ID);
                            //item.APPLY_DEPARTMENT_ID = department == null ? item.APPLY_DEPARTMENT_ID : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.APPLY_DEPARTMENT_ID);
                            //item.APPLY_DEPARTMENT_ID = department == null ? item.APPLY_DEPARTMENT_ID : (Guid)department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            delayApply = delayApply.Where(t => outPartmentIds.Contains((Guid)t.APPLY_DEPARTMENT_ID)).ToList();
                        }
                        var count = delayApply.Count();
                        var finish = delayApply.Count(t => t.IS_OVERTIME == 0);
                        var overfinish = delayApply.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && filter.Parameter3 == "作业现场管理")
                {
                    newFilter.SelectField = new List<string> { "ID", "SHIFT_STATUS", "OVERTIME", "DEPARTMENT_ID", "Nav_Team" };
                    //岗位当班工作记录
                    var classRecord = this.GetEntities<T_FO_CURRENT_CLASS_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //岗位交接班记录
                    var shiftRecord = this.GetEntities<T_FO_CHANGE_SHIFT_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //班组安全活动
                    newFilter.SelectField = new List<string> { "ID", "TA_STATUS", "OVERTIME", "Nav_User" };
                    var teamActive = this.GetEntities<T_FO_TEAM_ACTIVITY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null, newFilter).ToList();
                    //班前会议记录
                    newFilter.SelectField = new List<string> { "ID", "PRE_MEETING_STATUS", "OVERTIME", "DEPARTMENT_ID", "Nav_Team" };
                    var shiftMeeting = this.GetEntities<T_FO_PRE_SHIFT_MEETING_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //作业活动记录（一般作业）
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS", "Nav_CreateUser" };
                    var eventRecord = this.GetEntities<T_FO_JOB_EVENT_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_CreateUser != null && t.Nav_CreateUser.DEPARTMENT_ID != null, newFilter).ToList();
                    //作业方案讨论记录
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS", "DEPARTMENT_ID" };
                    var operSch = this.GetEntities<T_FO_PRE_OPER_SCH>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null, newFilter).ToList();
                    //关键作业/许可作业工作票
                    newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH", "Nav_ApplyUser" };
                    var licenseJob = this.GetEntities<T_FO_CRUCIAL_LICENSE_JOB>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_ApplyUser != null && t.Nav_ApplyUser.DEPARTMENT_ID != null, newFilter).ToList();
                    //技术交底表
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS", "Nav_DisclosurePerson" };
                    var techForm = this.GetEntities<T_FO_TECH_DISCLOSURE_FROM>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_DisclosurePerson != null && t.Nav_DisclosurePerson.DEPARTMENT_ID != null, newFilter).ToList();
                    //作业活动记录（关键和许可作业）
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS", "Nav_CreateUser" };
                    var activeRecord = this.GetEntities<T_FO_JOB_ACTIVITY_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_CreateUser != null && t.Nav_CreateUser.DEPARTMENT_ID != null, newFilter).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 && t.CREATE_TIME <= endTime, newFilter).ToList();
                    #region 岗位当班工作记录
                    if (classRecord.Any())
                    {
                        foreach (var item in classRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.Nav_CreateUser.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_CreateUser.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            classRecord = classRecord.Where(t => outPartmentIds.Contains((Guid)t.Nav_Team?.DEPARTMENT_ID)).ToList();
                            if (!classRecord.Any())
                            {
                                classRecord = classRecord.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                            }
                        }
                        var count = classRecord.Count();
                        var finish = classRecord.Count(t => t.IS_OVERTIME == 0 && t.SHIFT_STATUS == (int)FOShiftStatusEnum.归档);
                        var overfinish = classRecord.Count(t => t.IS_OVERTIME == 1 && 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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 岗位交接班记录
                    if (shiftRecord.Any())
                    {
                        foreach (var item in shiftRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.Nav_CreateUser.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_CreateUser.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            shiftRecord = shiftRecord.Where(t => outPartmentIds.Contains((Guid)t.Nav_Team?.DEPARTMENT_ID)).ToList();
                            if (!shiftRecord.Any())
                            {
                                shiftRecord = shiftRecord.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                            }
                        }
                        var count = shiftRecord.Count();
                        var finish = shiftRecord.Count(t => t.IS_OVERTIME == 0 && t.SHIFT_STATUS == (int)FOChangeShiftStatusEnum.归档);
                        var overfinish = shiftRecord.Count(t => t.IS_OVERTIME == 1 && 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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 班组安全活动
                    if (teamActive.Any())
                    {
                        foreach (var item in teamActive)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.Nav_CreateUser.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_CreateUser.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            teamActive = teamActive.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                        }
                        var count = teamActive.Count();
                        var finish = teamActive.Count(t => t.IS_OVERTIME == 0 && t.TA_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = teamActive.Count(t => t.IS_OVERTIME == 1 && 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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 班前会议记录
                    if (shiftMeeting.Any())
                    {
                        foreach (var item in shiftMeeting)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.Nav_CreateUser.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_CreateUser.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            shiftMeeting = shiftMeeting.Where(t => outPartmentIds.Contains((Guid)t.Nav_Team?.DEPARTMENT_ID)).ToList();
                            if (!shiftMeeting.Any())
                            {
                                shiftMeeting = shiftMeeting.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                            }
                        }
                        var count = shiftMeeting.Count();
                        var finish = shiftMeeting.Count(t => t.IS_OVERTIME == 0 && t.PRE_MEETING_STATUS == FOPreMeetingStatusEnum.归档);
                        var overfinish = shiftMeeting.Count(t => t.IS_OVERTIME == 1 && 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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 作业活动记录（一般作业）
                    if (eventRecord.Any())
                    {
                        foreach (var item in eventRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.Nav_CreateUser.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_CreateUser.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            eventRecord = eventRecord.Where(t => outPartmentIds.Contains((Guid)t.Nav_CreateUser.DEPARTMENT_ID)).ToList();
                        }
                        var count = eventRecord.Count();
                        var finish = eventRecord.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = eventRecord.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 作业方案讨论记录
                    if (operSch.Any())
                    {
                        foreach (var item in operSch)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            operSch = operSch.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        var count = operSch.Count();
                        var finish = operSch.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = operSch.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 关键作业/许可作业工作票
                    if (licenseJob.Any())
                    {
                        foreach (var item in licenseJob)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.Nav_ApplyUser.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_ApplyUser.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            licenseJob = licenseJob.Where(t => outPartmentIds.Contains((Guid)t.Nav_ApplyUser.DEPARTMENT_ID)).ToList();
                        }
                        var count = licenseJob.Count();
                        var finish = licenseJob.Count(t => t.IS_OVERTIME == 0 && t.IS_PUBLISH == (int)FOPreMeetingStatusEnum.归档);
                        var overfinish = licenseJob.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 技术交底表
                    if (techForm.Any())
                    {
                        foreach (var item in techForm)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.Nav_DisclosurePerson.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_DisclosurePerson.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            techForm = techForm.Where(t => outPartmentIds.Contains((Guid)t.Nav_DisclosurePerson.DEPARTMENT_ID)).ToList();
                        }
                        var count = techForm.Count();
                        var finish = techForm.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = techForm.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 作业活动记录（关键和许可作业）
                    if (activeRecord.Any())
                    {
                        foreach (var item in activeRecord)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = GetDepartmentId(item.Nav_CreateUser.DEPARTMENT_ID.Value);
                            //item.DEPARTMENT_ID = department == null ? null : department.ID;
                            //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_CreateUser.DEPARTMENT_ID);
                            //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            activeRecord = activeRecord.Where(t => outPartmentIds.Contains((Guid)t.Nav_CreateUser.DEPARTMENT_ID)).ToList();
                        }
                        var count = activeRecord.Count();
                        var finish = activeRecord.Count(t => t.IS_OVERTIME == 0 && t.FORM_STATUS == (int)FOTeamActivityState.已归档);
                        var overfinish = activeRecord.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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && filter.Parameter3 == "会议管理")
                {
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "DEPARTMENT_ID" , "MEETINGTYPE" };
                    //会议管理
                    var meetingManage = this.GetEntities<T_SC_MT_MEETING>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime, newFilter).ToList();
                    //普通会议通知
                    var orderMeeting = meetingManage.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.Ordinary).ToList();
                    //安委会通知
                    var safeMeeting = meetingManage.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.SafetyBoard || t.MEETINGTYPE == SCMEETINGTYPE.BasicSecurity).ToList();
                    //会议纪要
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_Meeting", "MEETINGTYPE" };
                    var meetingMinutes = this.GetEntities<T_SC_MT_MEETING_MINUTES>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_Meeting != null, newFilter).ToList();
                    //普通会议纪要
                    var orderMinute = meetingMinutes.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.Ordinary).ToList();
                    //安委会纪要
                    var safeMinute = meetingMinutes.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.SafetyBoard || t.MEETINGTYPE == SCMEETINGTYPE.BasicSecurity).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 && t.CREATE_TIME <= endTime, newFilter).ToList();
                    #region 普通会议通知
                    if (orderMeeting.Any())
                    {
                        foreach (var item in orderMeeting)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            orderMeeting = orderMeeting.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        var count = orderMeeting.Count();
                        var finish = orderMeeting.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                        var overfinish = orderMeeting.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 安委会通知
                    if (safeMeeting.Any())
                    {
                        foreach (var item in safeMeeting)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            safeMeeting = safeMeeting.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                        }
                        var count = safeMeeting.Count();
                        var finish = safeMeeting.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                        var overfinish = safeMeeting.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 普通会议纪要
                    if (orderMinute.Any())
                    {
                        foreach (var item in orderMinute)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            orderMinute = orderMinute.Where(t => outPartmentIds.Contains((Guid)t.Nav_Meeting.DEPARTMENT_ID)).ToList();
                        }
                        var count = orderMinute.Count();
                        var finish = orderMinute.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                        var overfinish = orderMinute.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 安委会纪要
                    if (safeMinute.Any())
                    {
                        foreach (var item in safeMinute)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            safeMinute = safeMinute.Where(t => outPartmentIds.Contains((Guid)t.Nav_Meeting.DEPARTMENT_ID)).ToList();
                        }
                        var count = safeMinute.Count();
                        var finish = safeMinute.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                        var overfinish = safeMinute.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && filter.Parameter3 == "安全教育培训")
                {
                    //安全教育培训
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "LAUNCH_DEPARTMENT_ID" };
                    //安全意识调查
                    var taskIdentify = this.GetEntities<T_SE_SAFE_SURVEY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                    //培训需求调查
                    var taskAnalysis = this.GetEntities<T_SE_TRAIN_SURVEY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                    //部门培训计划
                    var taskOrdinary = this.GetEntities<T_SE_DEP_TRAIN_PLAN>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime, newFilter).ToList();
                    //年度培训计划
                    var taskCrucial = this.GetEntities<T_SE_YEAR_TRAIN_PLAN>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                    //培训通知
                    var taskLicense = this.GetEntities<T_SE_TRAIN_NOTIFY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                    //三级安全教育卡
                    var checkTask = this.GetEntities<T_SE_THREE_LEVEL_SAFE_EDU_CARD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                    //培训记录
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_Notify" };
                    var filePublish = this.GetEntities<T_SE_TRAIN_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_Notify != null && t.Nav_Notify.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                    //培训效果评估表
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_User" };
                    var riskDeal = this.GetEntities<T_SE_TRAINING_EFFECT_EVALUATION_SURVEY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null, newFilter).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 && t.CREATE_TIME <= endTime, newFilter).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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskIdentify = taskIdentify.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                        }
                        var count = taskIdentify.Count();
                        var finish = taskIdentify.Count(t => t.IS_OVERTIME == 0 && t.STATUS == SESafeSurveyStatus.完成);
                        var overfinish = taskIdentify.Count(t => t.IS_OVERTIME == 1 && t.STATUS == SESafeSurveyStatus.完成);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                        analysis.MOUDLE_NAME = "安全教育培训";
                        analysis.FORM_NAME = "安全意识调查";
                        analysis.NUM = 14;
                        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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskAnalysis = taskAnalysis.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                        }
                        var count = taskAnalysis.Count();
                        var finish = taskAnalysis.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.SETrainSurveyStatus.完成);
                        var overfinish = taskAnalysis.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.SETrainSurveyStatus.完成);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                        analysis.MOUDLE_NAME = "安全教育培训";
                        analysis.FORM_NAME = "培训需求调查";
                        analysis.NUM = 15;
                        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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskOrdinary = taskOrdinary.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                        }
                        var count = taskOrdinary.Count();
                        var finish = taskOrdinary.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                        var overfinish = taskOrdinary.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                        analysis.MOUDLE_NAME = "安全教育培训";
                        analysis.FORM_NAME = "部门培训计划";
                        analysis.NUM = 16;
                        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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskCrucial = taskCrucial.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                        }
                        var count = taskCrucial.Count();
                        var finish = taskCrucial.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                        var overfinish = taskCrucial.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                        analysis.MOUDLE_NAME = "安全教育培训";
                        analysis.FORM_NAME = "年度培训计划";
                        analysis.NUM = 17;
                        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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            taskLicense = taskLicense.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                        }
                        var count = taskLicense.Count();
                        var finish = taskLicense.Count(t => t.IS_OVERTIME == 0 && t.STATUS == SETrainNotifyStatus.归档);
                        var overfinish = taskLicense.Count(t => t.IS_OVERTIME == 1 && t.STATUS == SETrainNotifyStatus.归档);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                        analysis.MOUDLE_NAME = "安全教育培训";
                        analysis.FORM_NAME = "培训通知";
                        analysis.NUM = 18;
                        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);
                    }
                    #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;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            filePublish = filePublish.Where(t => outPartmentIds.Contains((Guid)t.Nav_Notify.LAUNCH_DEPARTMENT_ID)).ToList();
                        }
                        var count = filePublish.Count();
                        var finish = filePublish.Count(t => t.IS_OVERTIME == 0 && t.STATUS == SETrainRecordStatus.归档);
                        var overfinish = filePublish.Count(t => t.IS_OVERTIME == 1 && t.STATUS == SETrainRecordStatus.归档);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                        analysis.MOUDLE_NAME = "安全教育培训";
                        analysis.FORM_NAME = "培训记录";
                        analysis.NUM = 19;
                        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);
                    }
                    #endregion

                    #region 三级安全教育卡
                    if (checkTask.Any())
                    {
                        foreach (var item in checkTask)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            checkTask = checkTask.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                        }
                        var count = checkTask.Count();
                        var finish = checkTask.Count(t => t.IS_OVERTIME == 0 && t.STATUS == SEThreeLevelSafeTrainStatus.归档);
                        var overfinish = checkTask.Count(t => t.IS_OVERTIME == 1 && t.STATUS == SEThreeLevelSafeTrainStatus.归档);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 培训效果评估表
                    if (riskDeal.Any())
                    {
                        foreach (var item in riskDeal)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            riskDeal = riskDeal.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                        }
                        var count = riskDeal.Count();
                        var finish = riskDeal.Count(t => t.IS_OVERTIME == 0 && t.STATUS == SETrainningEffectSurveyStatus.归档);
                        var overfinish = riskDeal.Count(t => t.IS_OVERTIME == 1 && t.STATUS == SETrainningEffectSurveyStatus.归档);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && filter.Parameter3 == "标准化创建")
                {
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_User" };
                    //标准化创建
                    var standardCreate = this.GetEntities<T_SC_STANDARD_CREATE>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null, newFilter).ToList();
                    //制度
                    var standardSystem = standardCreate.Where(t => t.TYPE == SCType.制度).ToList();
                    //责任制
                    var standardRespon = standardCreate.Where(t => t.TYPE == SCType.安全生产责任制).ToList();
                    //岗位安全操作规程和指导书
                    var standardPost = standardCreate.Where(t => t.TYPE == SCType.岗位安全操作规程和指导书).ToList();
                    //应急预案修订记录
                    var standardPlan = standardCreate.Where(t => t.TYPE == SCType.应急预案).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 && t.CREATE_TIME <= endTime, newFilter).ToList();
                    #region 标准化制度创建
                    if (standardSystem.Any())
                    {
                        foreach (var item in standardSystem)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = parentDepartments.FirstOrDefault(t=>t.departmentId == item.INITIATING_DEPARTMENT);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            standardSystem = standardSystem.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                        }
                        var count = standardSystem.Count();
                        var finish = standardSystem.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                        var overfinish = standardSystem.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 标准化责任制创建
                    if (standardRespon.Any())
                    {
                        foreach (var item in standardRespon)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = parentDepartments.FirstOrDefault(t=>t.departmentId == item.INITIATING_DEPARTMENT);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            standardRespon = standardRespon.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                        }
                        var count = standardRespon.Count();
                        var finish = standardRespon.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                        var overfinish = standardRespon.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 岗位安全操作规程和指导书
                    if (standardPost.Any())
                    {
                        foreach (var item in standardPost)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = parentDepartments.FirstOrDefault(t=>t.departmentId == item.INITIATING_DEPARTMENT);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            standardPost = standardPost.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                        }
                        var count = standardPost.Count();
                        var finish = standardPost.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                        var overfinish = standardPost.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion

                    #region 应急预案修订记录
                    if (standardPlan.Any())
                    {
                        foreach (var item in standardPlan)
                        {
                            var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                            if (task == null)
                                item.IS_OVERTIME = 0;
                            else
                                item.IS_OVERTIME = 1;
                            //var department = parentDepartments.FirstOrDefault(t=>t.departmentId == item.INITIATING_DEPARTMENT);
                            //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                        }
                        if (!string.IsNullOrEmpty(filter.Keyword))
                        {
                            standardPlan = standardPlan.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                        }
                        var count = standardPlan.Count();
                        var finish = standardPlan.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                        var overfinish = standardPlan.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                        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") + "%";
                        T_BI_FORM_RUN_ANALYSIS 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);
                    }
                    #endregion
                }
                return formAnalysis;
            });
        }

        [HttpPost, Route("GetFormRunSix")]
        public JsonActionResult<List<T_BI_FORM_RUN_ANALYSIS>> GetFormRunSix([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_BI_FORM_RUN_ANALYSIS>>(() =>
            {
                //首页待办增加数量统计字段
                //var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (string.IsNullOrEmpty(filter.Parameter1))
                {
                    throw new Exception("请先选择开始时间");
                }
                if (string.IsNullOrEmpty(filter.Parameter2))
                {
                    throw new Exception("请先选择结束时间");
                }
                List<Guid> outPartmentIds = new List<Guid>();
                if (!string.IsNullOrEmpty(filter.Keyword))
                {
                    List<Guid> inputIds = new List<Guid>() { Guid.Parse(filter.Keyword) };
                    GetDepartmentIds(APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value, inputIds, ref outPartmentIds);
                    outPartmentIds.Add(Guid.Parse(filter.Keyword));
                }

                List<T_BI_FORM_RUN_ANALYSIS> formAnalysis = new List<T_BI_FORM_RUN_ANALYSIS>();
                List<ParentDepartmentInfo> parentDepartments = new List<ParentDepartmentInfo>();
                DateTime startTime = Convert.ToDateTime(filter.Parameter1);
                DateTime endTime = Convert.ToDateTime(filter.Parameter2);
                TimeSpan span = endTime.Subtract(startTime);
                int dayDidd = span.Days + 1;
                if (dayDidd >= 180)
                    throw new Exception("查询时间不能超过6个月!");
                //var sourceIds = new List<Guid>();
                var departmentIds = new List<Guid?>();
                var newFilter = new BaseFilter(filter.OrgId);
                newFilter.IgnoreDataRule = true;
                newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_User" };
                //标准化创建
                var standardCreate = this.GetEntities<T_SC_STANDARD_CREATE>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null, newFilter).ToList();
                //制度
                var standardSystem = standardCreate.Where(t => t.TYPE == SCType.制度).ToList();
                //责任制
                var standardRespon = standardCreate.Where(t => t.TYPE == SCType.安全生产责任制).ToList();
                //岗位安全操作规程和指导书
                var standardPost = standardCreate.Where(t => t.TYPE == SCType.岗位安全操作规程和指导书).ToList();
                //应急预案修订记录
                var standardPlan = standardCreate.Where(t => t.TYPE == SCType.应急预案).ToList();
                //会议管理
                newFilter.SelectField = new List<string> { "ID", "STATUS", "DEPARTMENT_ID" };
                var meetingManage = this.GetEntities<T_SC_MT_MEETING>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime, newFilter).ToList();
                //普通会议通知
                var orderMeeting = meetingManage.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.Ordinary).ToList();
                //安委会通知
                var safeMeeting = meetingManage.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.SafetyBoard).ToList();
                //会议纪要
                newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_Meeting" };
                var meetingMinutes = this.GetEntities<T_SC_MT_MEETING_MINUTES>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_Meeting != null, newFilter).ToList();
                //普通会议纪要
                var orderMinute = meetingMinutes.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.Ordinary).ToList();
                //安委会纪要
                var safeMinute = meetingMinutes.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.SafetyBoard).ToList();
                //安全教育培训
                newFilter.SelectField = new List<string> { "ID", "STATUS", "LAUNCH_DEPARTMENT_ID" };
                //安全意识调查
                var taskIdentify = this.GetEntities<T_SE_SAFE_SURVEY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                //培训需求调查
                var taskAnalysis = this.GetEntities<T_SE_TRAIN_SURVEY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                //部门培训计划
                var taskOrdinary = this.GetEntities<T_SE_DEP_TRAIN_PLAN>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime, newFilter).ToList();
                //年度培训计划
                var taskCrucial = this.GetEntities<T_SE_YEAR_TRAIN_PLAN>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                //培训通知
                var taskLicense = this.GetEntities<T_SE_TRAIN_NOTIFY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                //三级安全教育卡
                var checkTask = this.GetEntities<T_SE_THREE_LEVEL_SAFE_EDU_CARD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                //培训记录
                newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_Notify" };
                var filePublish = this.GetEntities<T_SE_TRAIN_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_Notify != null && t.Nav_Notify.LAUNCH_DEPARTMENT_ID != null, newFilter).ToList();
                //培训效果评估表
                newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_User" };
                var riskDeal = this.GetEntities<T_SE_TRAINING_EFFECT_EVALUATION_SURVEY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null, newFilter).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 && t.CREATE_TIME <= endTime, newFilter).ToList();
                #region 标准化制度创建
                if (standardSystem.Any())
                {
                    foreach (var item in standardSystem)
                    {
                        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        if (task == null)
                            item.IS_OVERTIME = 0;
                        else
                            item.IS_OVERTIME = 1;
                        //var department = parentDepartments.FirstOrDefault(t=>t.departmentId == item.INITIATING_DEPARTMENT);
                        //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        standardSystem = standardSystem.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    var count = standardSystem.Count();
                    var finish = standardSystem.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                    var overfinish = standardSystem.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS 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);
                }
                #endregion

                #region 标准化责任制创建
                if (standardRespon.Any())
                {
                    foreach (var item in standardRespon)
                    {
                        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        if (task == null)
                            item.IS_OVERTIME = 0;
                        else
                            item.IS_OVERTIME = 1;
                        //var department = parentDepartments.FirstOrDefault(t=>t.departmentId == item.INITIATING_DEPARTMENT);
                        //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        standardRespon = standardRespon.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    var count = standardRespon.Count();
                    var finish = standardRespon.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                    var overfinish = standardRespon.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS 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);
                }
                #endregion

                #region 岗位安全操作规程和指导书
                if (standardPost.Any())
                {
                    foreach (var item in standardPost)
                    {
                        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        if (task == null)
                            item.IS_OVERTIME = 0;
                        else
                            item.IS_OVERTIME = 1;
                        //var department = parentDepartments.FirstOrDefault(t=>t.departmentId == item.INITIATING_DEPARTMENT);
                        //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        standardPost = standardPost.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    var count = standardPost.Count();
                    var finish = standardPost.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                    var overfinish = standardPost.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS 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);
                }
                #endregion

                #region 应急预案修订记录
                if (standardPlan.Any())
                {
                    foreach (var item in standardPlan)
                    {
                        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        if (task == null)
                            item.IS_OVERTIME = 0;
                        else
                            item.IS_OVERTIME = 1;
                        //var department = parentDepartments.FirstOrDefault(t=>t.departmentId == item.INITIATING_DEPARTMENT);
                        //item.INITIATING_DEPARTMENT = department == null ? null : department.parent_departmentId;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        standardPlan = standardPlan.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    var count = standardPlan.Count();
                    var finish = standardPlan.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                    var overfinish = standardPlan.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.SCSystemEditStatus.已归档);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS 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);
                }
                #endregion

                #region 普通会议通知
                if (orderMeeting.Any())
                {
                    foreach (var item in orderMeeting)
                    {
                        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        if (task == null)
                            item.IS_OVERTIME = 0;
                        else
                            item.IS_OVERTIME = 1;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        orderMeeting = orderMeeting.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                    var count = orderMeeting.Count();
                    var finish = orderMeeting.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                    var overfinish = orderMeeting.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS 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);
                }
                #endregion

                #region 安委会通知
                if (safeMeeting.Any())
                {
                    foreach (var item in safeMeeting)
                    {
                        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        if (task == null)
                            item.IS_OVERTIME = 0;
                        else
                            item.IS_OVERTIME = 1;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        safeMeeting = safeMeeting.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                    var count = safeMeeting.Count();
                    var finish = safeMeeting.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                    var overfinish = safeMeeting.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS 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);
                }
                #endregion

                #region 普通会议纪要
                if (orderMinute.Any())
                {
                    foreach (var item in orderMinute)
                    {
                        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        if (task == null)
                            item.IS_OVERTIME = 0;
                        else
                            item.IS_OVERTIME = 1;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        orderMinute = orderMinute.Where(t => outPartmentIds.Contains((Guid)t.Nav_Meeting.DEPARTMENT_ID)).ToList();
                    }
                    var count = orderMinute.Count();
                    var finish = orderMinute.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                    var overfinish = orderMinute.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS 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);
                }
                #endregion

                #region 安委会纪要
                if (safeMinute.Any())
                {
                    foreach (var item in safeMinute)
                    {
                        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        if (task == null)
                            item.IS_OVERTIME = 0;
                        else
                            item.IS_OVERTIME = 1;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        safeMinute = safeMinute.Where(t => outPartmentIds.Contains((Guid)t.Nav_Meeting.DEPARTMENT_ID)).ToList();
                    }
                    var count = safeMinute.Count();
                    var finish = safeMinute.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                    var overfinish = safeMinute.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS 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);
                }
                #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;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskIdentify = taskIdentify.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    var count = taskIdentify.Count();
                    var finish = taskIdentify.Count(t => t.IS_OVERTIME == 0 && t.STATUS == SESafeSurveyStatus.完成);
                    var overfinish = taskIdentify.Count(t => t.IS_OVERTIME == 1 && t.STATUS == SESafeSurveyStatus.完成);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                    analysis.MOUDLE_NAME = "安全教育培训";
                    analysis.FORM_NAME = "安全意识调查";
                    analysis.NUM = 14;
                    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);
                }
                #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;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskAnalysis = taskAnalysis.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    var count = taskAnalysis.Count();
                    var finish = taskAnalysis.Count(t => t.IS_OVERTIME == 0 && t.STATUS == MS.Domain.Enums.SETrainSurveyStatus.完成);
                    var overfinish = taskAnalysis.Count(t => t.IS_OVERTIME == 1 && t.STATUS == MS.Domain.Enums.SETrainSurveyStatus.完成);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                    analysis.MOUDLE_NAME = "安全教育培训";
                    analysis.FORM_NAME = "培训需求调查";
                    analysis.NUM = 15;
                    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);
                }
                #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;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskOrdinary = taskOrdinary.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    var count = taskOrdinary.Count();
                    var finish = taskOrdinary.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                    var overfinish = taskOrdinary.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                    analysis.MOUDLE_NAME = "安全教育培训";
                    analysis.FORM_NAME = "部门培训计划";
                    analysis.NUM = 16;
                    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);
                }
                #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;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskCrucial = taskCrucial.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    var count = taskCrucial.Count();
                    var finish = taskCrucial.Count(t => t.IS_OVERTIME == 0 && t.STATUS == PFStandardStatus.Archived);
                    var overfinish = taskCrucial.Count(t => t.IS_OVERTIME == 1 && t.STATUS == PFStandardStatus.Archived);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                    analysis.MOUDLE_NAME = "安全教育培训";
                    analysis.FORM_NAME = "年度培训计划";
                    analysis.NUM = 17;
                    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);
                }
                #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;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskLicense = taskLicense.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    var count = taskLicense.Count();
                    var finish = taskLicense.Count(t => t.IS_OVERTIME == 0 && t.STATUS == SETrainNotifyStatus.归档);
                    var overfinish = taskLicense.Count(t => t.IS_OVERTIME == 1 && t.STATUS == SETrainNotifyStatus.归档);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                    analysis.MOUDLE_NAME = "安全教育培训";
                    analysis.FORM_NAME = "培训通知";
                    analysis.NUM = 18;
                    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);
                }
                #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;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        filePublish = filePublish.Where(t => outPartmentIds.Contains((Guid)t.Nav_Notify.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    var count = filePublish.Count();
                    var finish = filePublish.Count(t => t.IS_OVERTIME == 0 && t.STATUS == SETrainRecordStatus.归档);
                    var overfinish = filePublish.Count(t => t.IS_OVERTIME == 1 && t.STATUS == SETrainRecordStatus.归档);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS analysis = new T_BI_FORM_RUN_ANALYSIS();
                    analysis.MOUDLE_NAME = "安全教育培训";
                    analysis.FORM_NAME = "培训记录";
                    analysis.NUM = 19;
                    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);
                }
                #endregion

                #region 三级安全教育卡
                if (checkTask.Any())
                {
                    foreach (var item in checkTask)
                    {
                        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        if (task == null)
                            item.IS_OVERTIME = 0;
                        else
                            item.IS_OVERTIME = 1;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        checkTask = checkTask.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    var count = checkTask.Count();
                    var finish = checkTask.Count(t => t.IS_OVERTIME == 0 && t.STATUS == SEThreeLevelSafeTrainStatus.归档);
                    var overfinish = checkTask.Count(t => t.IS_OVERTIME == 1 && t.STATUS == SEThreeLevelSafeTrainStatus.归档);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS 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);
                }
                #endregion

                #region 培训效果评估表
                if (riskDeal.Any())
                {
                    foreach (var item in riskDeal)
                    {
                        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                        if (task == null)
                            item.IS_OVERTIME = 0;
                        else
                            item.IS_OVERTIME = 1;
                    }
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        riskDeal = riskDeal.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    var count = riskDeal.Count();
                    var finish = riskDeal.Count(t => t.IS_OVERTIME == 0 && t.STATUS == SETrainningEffectSurveyStatus.归档);
                    var overfinish = riskDeal.Count(t => t.IS_OVERTIME == 1 && t.STATUS == SETrainningEffectSurveyStatus.归档);
                    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") + "%";
                    T_BI_FORM_RUN_ANALYSIS 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);
                }
                #endregion

                //#region 班组安全活动
                //if (teamActive.Any())
                //{
                //    foreach (var item in teamActive)
                //    {
                //        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                //        if (task == null)
                //            item.IS_OVERTIME = 0;
                //        else
                //            item.IS_OVERTIME = 1;
                //        //var department = GetDepartmentId(item.Nav_CreateUser.DEPARTMENT_ID.Value);
                //        //item.DEPARTMENT_ID = department == null ? null : department.ID;
                //        //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_CreateUser.DEPARTMENT_ID);
                //        //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                //    }
                //    if (!string.IsNullOrEmpty(filter.Keyword))
                //    {
                //        teamActive = teamActive.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                //    }
                //    var count = teamActive.Count();
                //    var finish = teamActive.Count(t => t.IS_OVERTIME == 0 && t.TA_STATUS == (int)FOTeamActivityState.已归档);
                //    var overfinish = teamActive.Count(t => t.IS_OVERTIME == 1 && 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") + "%";
                //    T_BI_FORM_RUN_ANALYSIS 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);
                //}
                //#endregion

                //#region 班前会议记录
                //if (shiftMeeting.Any())
                //{
                //    foreach (var item in shiftMeeting)
                //    {
                //        var task = tasks.FirstOrDefault(t => t.SOURCE_DATA_ID == item.ID);
                //        if (task == null)
                //            item.IS_OVERTIME = 0;
                //        else
                //            item.IS_OVERTIME = 1;
                //        //var department = GetDepartmentId(item.Nav_CreateUser.DEPARTMENT_ID.Value);
                //        //item.DEPARTMENT_ID = department == null ? null : department.ID;
                //        //var department = parentDepartments.FirstOrDefault(t => t.departmentId == item.Nav_CreateUser.DEPARTMENT_ID);
                //        //item.DEPARTMENT_ID = department == null ? null : department.parent_departmentId;
                //    }
                //    if (!string.IsNullOrEmpty(filter.Keyword))
                //    {
                //        shiftMeeting = shiftMeeting.Where(t => outPartmentIds.Contains((Guid)t.Nav_Team?.DEPARTMENT_ID)).ToList();
                //        if (!shiftMeeting.Any())
                //        {
                //            shiftMeeting = shiftMeeting.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                //        }
                //    }
                //    var count = shiftMeeting.Count();
                //    var finish = shiftMeeting.Count(t => t.IS_OVERTIME == 0 && t.PRE_MEETING_STATUS == FOPreMeetingStatusEnum.归档);
                //    var overfinish = shiftMeeting.Count(t => t.IS_OVERTIME == 1 && 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") + "%";
                //    T_BI_FORM_RUN_ANALYSIS 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);
                //}
                //#endregion
                return formAnalysis;
            });
        }

        /// <summary>
        /// 待办汇总查询
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetFormTask")]
        public JsonActionResult<dynamic> GetFormTask([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<dynamic>(() =>
            {
                //首页待办增加数量统计字段
                dynamic ret = new System.Dynamic.ExpandoObject();
                //var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (string.IsNullOrEmpty(pageFilter.Parameter1) || string.IsNullOrEmpty(pageFilter.Parameter2))
                {
                    throw new Exception("请先选择时间段");
                }
                if (string.IsNullOrEmpty(pageFilter.Keyword))
                {
                    throw new Exception("请先选择部门");
                }
                var newFilter = new BaseFilter(pageFilter.OrgId);
                newFilter.SelectField = new List<string> { "ID","CODE", "NAME" };
                var formInfo = this.GetEntities<T_PF_FORM>(t => t.ENABLE_STATUS == 0, newFilter);
                DateTime startTime = Convert.ToDateTime(pageFilter.Parameter1 + " 00:00:00");
                DateTime endTime = Convert.ToDateTime(pageFilter.Parameter2 + " 23:59:59");
                TimeSpan span = endTime.Subtract(startTime);
                int dayDidd = span.Days + 1;
                if (dayDidd >= 180)
                    throw new Exception("查询时间不能超过6个月!");
                var result = GetEntities<T_BI_NOTIFICATION_TASK_NEW>(s => !s.IS_DELETED && s.CREATE_DATE >= startTime && s.CREATE_DATE <= endTime && s.DEPT_DEPARTMENT_ID == Guid.Parse(pageFilter.Keyword), pageFilter);
                var userIds = result.Select(t => t.USER_ID).Distinct().ToList();
                var userInfos= GetEntities<T_FM_USER>(s => userIds.Contains(s.ID) && s.ENABLE_STATUS == 0, newFilter);
                //pageFilter.Sort = "CREATE_TIME";
                //pageFilter.Order = DbOrder.DESC;
                if (result.Any())
                {
                    var newData = result.ToList();
                    ret.formData = formInfo.ToList();
                    ret.userData = userInfos.ToList();
                    ret.newData = newData;
                    ret.TotalCount = newData.Count();
                    ret.doneCount = newData.Where(t => t.NOTICE_STATUS == 1).Count();
                    ret.timeOverCount = newData.Where(t => t.NOTICE_STATUS == 2).Count();
                    var groupDataTemp = newData.GroupBy(t => t.MOUDLE_NAME).Select(m => new GroupbyMouldName
                    {
                        mouldName = m.Key,
                        totalCount = m.Count(p => p.MOUDLE_NAME == m.Key),
                        doneCount = m.Count(p => p.MOUDLE_NAME == m.Key && p.NOTICE_STATUS == 1),
                        timeOverCount = m.Count(p => p.MOUDLE_NAME == m.Key && p.NOTICE_STATUS == 2),
                    }).ToList();
                    ret.groupData = groupDataTemp;
                }
                else
                {
                    ret.formData = formInfo.ToList();
                    ret.userData = userInfos.ToList();
                    ret.newData = new List<T_BI_NOTIFICATION_TASK_NEW>();
                    ret.TotalCount = 0;
                    ret.doneCount = 0;
                    ret.timeOverCount = 0;
                    ret.groupData = new List<GroupbyMouldName>();
                }
                return ret;
            });
        }
      
        /// <summary>
        /// 回调失败log执行
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("ExecuteLog")]
        public JsonActionResult<bool> ExecuteLog([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<bool>(() =>
            {
                var logs = this.GetEntities<T_PF_SYS_LOG>(t => t.LOG_TYPE == 80, new BaseFilter(pageFilter.OrgId));
                if (logs.Any())
                {
                    foreach (var item in logs)
                    {
                        var temp = item.LOG_DATA.Split("：");
                        if (temp.Length > 1)
                        {
                            var apiTemp = temp[1];
                            var api = apiTemp.Split("DATA_ID");
                            if (api.Length > 1)
                            {
                                var idTemp = api[1];
                                int arr = idTemp.IndexOf(")") - 1 - idTemp.IndexOf("(");
                                var id = idTemp.Substring(idTemp.IndexOf("(") + 1, arr);
                                var backApi = api[0].Substring(0, api[0].IndexOf("ID"));
                                var result = ApproveCallBackService.CallBack(backApi, id);
                                if (result)
                                {
                                    item.LOG_TYPE = (int)PFSysLogTypeEnum.FaildApproveCallBackOK;
                                    item.LOG_DATA = item.LOG_DATA.Replace("未执行回调", "已执行回调");
                                    UpdateEntity(item);
                                }
                                else
                                {
                                    item.LOG_TYPE = (int)PFSysLogTypeEnum.FaildApproveCallBackNG;
                                    item.LOG_DATA = item.LOG_DATA.Replace("未执行回调", "未执行回调且跑批失败");
                                    UpdateEntity(item);
                                }
                            }
                        }
                    }
                }
                return true;
            });
        }

        [HttpPost, Route("GetFormRunAnalyze")]
        public JsonActionResult<List<UnFinishInfo>> GetFormRunAnalyze([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<UnFinishInfo>>(() =>
            {
                //首页待办增加数量统计字段
                //var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (string.IsNullOrEmpty(filter.Parameter1))
                {
                    throw new Exception("请先选择开始时间");
                }
                if (string.IsNullOrEmpty(filter.Parameter2))
                {
                    throw new Exception("请先选择结束时间");
                }
                List<Guid> outPartmentIds = new List<Guid>();
                if (!string.IsNullOrEmpty(filter.Keyword))
                {
                    List<Guid> inputIds = new List<Guid>() { Guid.Parse(filter.Keyword) };
                    GetDepartmentIds(APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value, inputIds, ref outPartmentIds);
                    outPartmentIds.Add(Guid.Parse(filter.Keyword));
                }
                List<UnFinishInfo> formAnalysis = new List<UnFinishInfo>();
                List<ParentDepartmentInfo> parentDepartments = new List<ParentDepartmentInfo>();
                DateTime startTime = Convert.ToDateTime(filter.Parameter1);
                DateTime endTime = Convert.ToDateTime(filter.Parameter2);
                TimeSpan span = endTime.Subtract(startTime);
                int dayDidd = span.Days + 1;
                if (dayDidd >= 180)
                    throw new Exception("查询时间不能超过6个月!");
                //var sourceIds = new List<Guid>();
                var departmentIds = new List<Guid?>();
                var newFilter = new BaseFilter(filter.OrgId);
                newFilter.IgnoreDataRule = true;
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "风险评价计划审核表")
                {
                    newFilter.SelectField = new List<string> { "ID", "DOCUMENT_NAME", "STATUS", "INITIATING_DEPARTMENT", "CREATER_ID", "CREATE_TIME" };
                    //风险评价计划审核表
                    var evalPlan = this.GetEntities<T_HM_EVALUATION_PLAN>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null
                     && t.STATUS != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                   if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        evalPlan = evalPlan.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                    }
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 风险评价计划审核表
                    if (evalPlan.Any())
                    {
                        evalPlan.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.DOCUMENT_NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "风险评价计划发布")
                {
                    //风险评价计划发布
                    newFilter.SelectField = new List<string> { "ID", "NOTICE_NAME", "RELEASE_STATUS", "RELEAS_DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    var noticeRelease = this.GetEntities<T_HM_NOTICE_RELEASE>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.RELEAS_DEPARTMENT_ID != null
                     && t.RELEASE_STATUS != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                   if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        noticeRelease = noticeRelease.Where(t => outPartmentIds.Contains((Guid)t.RELEAS_DEPARTMENT_ID)).ToList();
                    }
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 风险评价计划发布
                    if (noticeRelease.Any())
                    {
                        noticeRelease.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NOTICE_NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.RELEASE_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "危险源/风险辨识任务")
                {
                    //危险源/风险辨识任务
                    newFilter.SelectField = new List<string> { "ID", "CODE", "STATUS", "INITIATING_DEPARTMENT", "CREATER_ID", "CREATE_TIME" };
                    var riskTask = this.GetEntities<T_HM_RISK_TASK>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null
                    && t.STATUS != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        riskTask = riskTask.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                    }
                    
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 危险源/风险辨识任务
                    if (riskTask.Any())
                    {
                        riskTask.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "危险源/风险辨识记录表")
                {
                    newFilter.SelectField = new List<string> { "ID", "CODE", "STATUS", "INITIATING_DEPARTMENT", "CREATER_ID", "CREATE_TIME" };
                    //危险源/风险辨识记录表
                    var riskRecord = this.GetEntities<T_HM_RISK_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null
                    && t.STATUS != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        riskRecord = riskRecord.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                    }
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 危险源/风险辨识记录表
                    if (riskRecord.Any())
                    {
                        riskRecord.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "职业危害辨识任务")
                {
                    newFilter.SelectField = new List<string> { "ID", "CODE", "STATUS", "INITIATING_DEPARTMENT", "CREATER_ID", "CREATE_TIME" };
                    //职业危害辨识任务
                    var hazardTask = this.GetEntities<T_HM_HAZARD_TASK>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null
                    && t.STATUS != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                   if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        hazardTask = hazardTask.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                    }
                   
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 职业危害辨识任务
                    if (hazardTask.Any())
                    {
                        hazardTask.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "职业危害辨识记录表")
                {
                    newFilter.SelectField = new List<string> { "ID", "CODE", "STATUS", "INITIATING_DEPARTMENT", "CREATER_ID", "CREATE_TIME" };
                    //职业危害辨识记录表
                    var hazardRecord = this.GetEntities<T_HM_HAZARD_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null
                    && t.STATUS != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        hazardRecord = hazardRecord.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                    }
                  
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 职业危害辨识记录表
                    if (hazardRecord.Any())
                    {
                        hazardRecord.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "评价结果表")
                {
                    newFilter.SelectField = new List<string> { "ID", "CODE", "STATUS", "INITIATING_DEPARTMENT", "CREATER_ID", "CREATE_TIME" };
                    //评价结果表
                    var evalResult = this.GetEntities<T_HM_EVALUATE_RESULT>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.INITIATING_DEPARTMENT != null
                    && t.STATUS != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                   if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        evalResult = evalResult.Where(t => outPartmentIds.Contains((Guid)t.INITIATING_DEPARTMENT)).ToList();
                    }
                    
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 评价结果表
                    if (evalResult.Any())
                    {
                        evalResult.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "作业任务识别")
                {
                    //作业任务识别
                    newFilter.SelectField = new List<string> { "ID", "CODE", "IS_PUBLISH", "DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    var taskIdentify = this.GetEntities<T_HM_JOBTASK_IDENTIFY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                     && t.IS_PUBLISH != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                   if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskIdentify = taskIdentify.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                   
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 作业任务识别
                    if (taskIdentify.Any())
                    {
                        taskIdentify.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.IS_PUBLISH);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "作业任务识别分析")
                {
                    newFilter.SelectField = new List<string> { "ID", "CODE", "IS_PUBLISH", "DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //作业任务识别分析
                    var taskAnalysis = this.GetEntities<T_HM_OPERATION_TASK_DISTINGUISH_ANALYZE>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                     && t.IS_PUBLISH != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskAnalysis = taskAnalysis.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 作业任务识别分析
                    if (taskAnalysis.Any())
                    {
                        taskAnalysis.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.IS_PUBLISH);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "一般任务分析")
                {
                    newFilter.SelectField = new List<string> { "ID", "CODE", "IS_PUBLISH", "DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //一般任务分析
                    var taskOrdinary = this.GetEntities<T_HM_ORDINARY_TASK_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                     && t.IS_PUBLISH != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskOrdinary = taskOrdinary.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                 
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 一般任务分析
                    if (taskOrdinary.Any())
                    {
                        taskOrdinary.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.IS_PUBLISH);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "关键任务分析")
                {
                    newFilter.SelectField = new List<string> { "ID", "CODE", "IS_PUBLISH", "DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //关键任务分析
                    var taskCrucial = this.GetEntities<T_HM_CRUCIAL_TASK_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                     && t.IS_PUBLISH != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskCrucial = taskCrucial.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                   
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 关键任务分析
                    if (taskCrucial.Any())
                    {
                        taskCrucial.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.IS_PUBLISH);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "许可任务分析")
                {
                    newFilter.SelectField = new List<string> { "ID", "CODE", "IS_PUBLISH", "DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //许可任务分析
                    var taskLicense = this.GetEntities<T_HM_LICENSE_ANALYSIS>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                     && t.IS_PUBLISH != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskLicense = taskLicense.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                   
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 许可任务分析
                    if (taskLicense.Any())
                    {
                        taskLicense.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.IS_PUBLISH);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "风险管理" && filter.Parameter4 == "作业任务分析文件发布")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "IS_PUBLISH", "DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //作业任务分析文件发布
                    var filePublish = this.GetEntities<T_HM_FILE_PUBLISH>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                     && t.IS_PUBLISH != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        filePublish = filePublish.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                   
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 作业任务分析文件发布
                    if (filePublish.Any())
                    {
                        filePublish.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.IS_PUBLISH);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
               && filter.Parameter3 == "作业现场管理" && filter.Parameter4 == "岗位当班工作记录")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "SHIFT_STATUS", "OVERTIME", "DEPARTMENT_ID", "Nav_Team", "CREATER_ID", "CREATE_TIME" };
                    //岗位当班工作记录
                    var classRecord = this.GetEntities<T_FO_CURRENT_CLASS_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                    && t.SHIFT_STATUS != (int)FOShiftStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        classRecord = classRecord.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 岗位当班工作记录
                    if (classRecord.Any())
                    {
                        classRecord.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOShiftStatusEnum), t.SHIFT_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
               && filter.Parameter3 == "作业现场管理" && filter.Parameter4 == "岗位交接班记录")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "SHIFT_STATUS", "OVERTIME", "DEPARTMENT_ID", "Nav_Team", "CREATER_ID", "CREATE_TIME" };
                    //岗位交接班记录
                    var shiftRecord = this.GetEntities<T_FO_CHANGE_SHIFT_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                     && t.SHIFT_STATUS != (int)FOChangeShiftStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        shiftRecord = shiftRecord.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 岗位交接班记录
                    if (shiftRecord.Any())
                    {
                        shiftRecord.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOChangeShiftStatusEnum), t.SHIFT_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
               && filter.Parameter3 == "作业现场管理" && filter.Parameter4 == "班组安全活动")
                {
                    //班组安全活动
                    newFilter.SelectField = new List<string> { "ID", "TITLE", "TA_STATUS", "OVERTIME", "Nav_User", "CREATER_ID", "CREATE_TIME" };
                    var teamActive = this.GetEntities<T_FO_TEAM_ACTIVITY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null
                    && t.TA_STATUS != (int)FOTeamActivityState.已归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        teamActive = teamActive.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 班组安全活动
                    if (teamActive.Any())
                    {
                        teamActive.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.TITLE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.Nav_User.ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.Nav_User.ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOTeamActivityState), t.TA_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
               && filter.Parameter3 == "作业现场管理" && filter.Parameter4 == "班前会议记录")
                {
                    //班前会议记录
                    newFilter.SelectField = new List<string> { "ID", "NAME", "PRE_MEETING_STATUS", "OVERTIME", "DEPARTMENT_ID", "Nav_Team", "CREATER_ID", "CREATE_TIME" };
                    var shiftMeeting = this.GetEntities<T_FO_PRE_SHIFT_MEETING_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                    &&t.PRE_MEETING_STATUS != FOPreMeetingStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        shiftMeeting = shiftMeeting.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 班前会议记录
                    if (shiftMeeting.Any())
                    {
                        shiftMeeting.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.PRE_MEETING_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
               && filter.Parameter3 == "作业现场管理" && filter.Parameter4 == "作业活动记录（一般作业）")
                {
                    //作业活动记录（一般作业）
                    newFilter.SelectField = new List<string> { "ID", "Nav_OperationStep", "FORM_STATUS", "Nav_CreateUser", "CREATER_ID", "CREATE_TIME" };
                    var eventRecord = this.GetEntities<T_FO_JOB_EVENT_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_CreateUser != null && t.Nav_CreateUser.DEPARTMENT_ID != null
                    && t.FORM_STATUS != (int)FOTeamActivityState.已归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        eventRecord = eventRecord.Where(t => outPartmentIds.Contains((Guid)t.Nav_CreateUser.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 作业活动记录（一般作业）
                    if (eventRecord.Any())
                    {
                        eventRecord.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.Nav_OperationStep?.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOTeamActivityState), t.FORM_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "作业现场管理" && filter.Parameter4 == "作业方案讨论记录")
                {
                    //作业方案讨论记录
                    newFilter.SelectField = new List<string> { "ID", "FILE_NAME", "FORM_STATUS", "DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    var operSch = this.GetEntities<T_FO_PRE_OPER_SCH>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                    && t.FORM_STATUS != (int)FOTeamActivityState.已归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        operSch = operSch.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 作业方案讨论记录
                    if (operSch.Any())
                    {
                        operSch.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.FILE_NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOTeamActivityState), t.FORM_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "作业现场管理" && filter.Parameter4 == "关键作业/许可作业工作票")
                {
                    //关键作业/许可作业工作票
                    newFilter.SelectField = new List<string> { "ID", "Nav_OperationStep", "IS_PUBLISH", "Nav_ApplyUser", "CREATER_ID", "CREATE_TIME" };
                    var licenseJob = this.GetEntities<T_FO_CRUCIAL_LICENSE_JOB>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_ApplyUser != null && t.Nav_ApplyUser.DEPARTMENT_ID != null
                    && t.IS_PUBLISH != (int)FOPreMeetingStatusEnum.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        licenseJob = licenseJob.Where(t => outPartmentIds.Contains((Guid)t.Nav_ApplyUser.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 关键作业/许可作业工作票
                    if (licenseJob.Any())
                    {
                        licenseJob.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.Nav_OperationStep?.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOPreMeetingStatusEnum), t.IS_PUBLISH);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "作业现场管理" && filter.Parameter4 == "技术交底表")
                {
                    //技术交底表
                    newFilter.SelectField = new List<string> { "ID", "Nav_OperationStep", "FORM_STATUS", "Nav_DisclosurePerson", "CREATER_ID", "CREATE_TIME" };
                    var techForm = this.GetEntities<T_FO_TECH_DISCLOSURE_FROM>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_DisclosurePerson != null && t.Nav_DisclosurePerson.DEPARTMENT_ID != null
                    && t.FORM_STATUS != (int)FOTeamActivityState.已归档, newFilter).ToList();
                    //作业活动记录（关键和许可作业）
                    newFilter.SelectField = new List<string> { "ID", "FORM_STATUS", "Nav_CreateUser" };
                    var activeRecord = this.GetEntities<T_FO_JOB_ACTIVITY_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_CreateUser != null && t.Nav_CreateUser.DEPARTMENT_ID != null, newFilter).ToList();
                    newFilter.SelectField = new List<string> { "ID", "IS_PUBLISH", "DEPARTMENT_ID" };
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        techForm = techForm.Where(t => outPartmentIds.Contains((Guid)t.Nav_DisclosurePerson.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 技术交底表
                    if (techForm.Any())
                    {
                        techForm.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.Nav_OperationStep?.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOTeamActivityState), t.FORM_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "作业现场管理" && filter.Parameter4 == "作业活动记录（关键和许可作业）")
                {
                    //作业活动记录（关键和许可作业）
                    newFilter.SelectField = new List<string> { "ID", "Nav_OperationStep", "FORM_STATUS", "Nav_CreateUser", "CREATER_ID", "CREATE_TIME" };
                    var activeRecord = this.GetEntities<T_FO_JOB_ACTIVITY_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_CreateUser != null && t.Nav_CreateUser.DEPARTMENT_ID != null
                    && t.FORM_STATUS != (int)FOTeamActivityState.已归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        activeRecord = activeRecord.Where(t => outPartmentIds.Contains((Guid)t.Nav_CreateUser.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 作业活动记录（关键和许可作业）
                    if (activeRecord.Any())
                    {
                        activeRecord.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.Nav_OperationStep?.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(FOTeamActivityState), t.FORM_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
               && filter.Parameter3 == "安全检查" && filter.Parameter4 == "检查任务制定")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUSPLAN", "STATUCHECK", "DEPARTMENTID","CREATER_ID", "CREATE_TIME" };
                    //检查任务制定
                    var checkTask = this.GetEntities<T_BS_SAFE_CHECK>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENTID != null
                    && t.STATUSPLAN != (int)HMAuditStatusEnmu.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        checkTask = checkTask.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENTID)).ToList();
                    }
                    //var ids = checkTask.Select(t => t.ID);
                    //var approveIds = this.GetEntities<T_PF_APPROVE>(t => ids.Contains(t.DATA_ID), new BaseFilter(filter.OrgId)).Select(t => t.ID).ToList();
                    //var allIds = new List<Guid>();
                    //allIds.AddRange(ids);
                    //allIds.AddRange(approveIds);
                    ////只取未完成的
                    //newFilter.SelectField = new List<string> { "NOTICE_TITLE", "USER_ID", "USER_NAME", "SOURCE_DATA_ID", "CREATE_TIME" };
                    //var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 0 && allIds.Contains((Guid)t.SOURCE_DATA_ID), newFilter).ToList();
                    ////人员
                    //var userIds = tasks.Select(t => t.USER_ID).Distinct().ToList();
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 检查任务制定
                    //if (tasks.Any())
                    //{
                    //    tasks.ForEach(t =>
                    //    {
                    //        UnFinishInfo analysis = new UnFinishInfo();
                    //        analysis.NAME = t.NOTICE_TITLE;
                    //        analysis.CREATE_NAME = t.USER_NAME;
                    //        analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.USER_ID)?.Nav_Department?.NAME;
                    //        analysis.CREATE_TIME = t.CREATE_TIME;
                    //        formAnalysis.Add(analysis);
                    //    });
                    //}
                    if (checkTask.Any())
                    {
                        checkTask.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(HMAuditStatusEnmu), t.STATUSPLAN);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
              && filter.Parameter3 == "安全检查" && filter.Parameter4 == "检查记录")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUSPLAN", "STATUCHECK", "DEPARTMENTID", "CREATER_ID","CREATE_TIME" };
                    //检查记录
                    var checkRecord = this.GetEntities<T_BS_SAFE_CHECK>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENTID != null
                    && t.STATUSPLAN == (int)HMAuditStatusEnmu.归档 && t.STATUCHECK!= (int)HMAuditStatusEnmu.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        checkRecord = checkRecord.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENTID)).ToList();
                    }
                    //var ids = checkRecord.Select(t => t.ID);
                    //var approveIds = this.GetEntities<T_PF_APPROVE>(t => ids.Contains(t.DATA_ID), new BaseFilter(filter.OrgId)).Select(t => t.ID).ToList();
                    //var allIds = new List<Guid>();
                    //allIds.AddRange(ids);
                    //allIds.AddRange(approveIds);
                    //allIds = allIds.Distinct().ToList();
                    ////只取未完成的
                    //newFilter.SelectField = new List<string> { "NOTICE_TITLE", "USER_ID", "USER_NAME", "SOURCE_DATA_ID", "CREATE_TIME" };
                    //var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => t.NOTICE_STATUS == 0 && allIds.Contains((Guid)t.SOURCE_DATA_ID), newFilter).ToList();
                    ////人员
                    //var userIds = tasks.Select(t => t.USER_ID).Distinct().ToList();
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t =>t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 检查记录
                    //if (tasks.Any())
                    //{
                    //    tasks.ForEach(t =>
                    //    {
                    //        UnFinishInfo analysis = new UnFinishInfo();
                    //        analysis.NAME = t.NOTICE_TITLE;
                    //        analysis.CREATE_NAME = t.USER_NAME;
                    //        analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.USER_ID)?.Nav_Department?.NAME;
                    //        analysis.CREATE_TIME = t.CREATE_TIME;
                    //        formAnalysis.Add(analysis);
                    //    });
                    //}
                    if (checkRecord.Any())
                    {
                        checkRecord.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(HMAuditStatusEnmu), t.STATUCHECK);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
             && filter.Parameter3 == "安全检查" && filter.Parameter4 == "隐患上报")
                {
                    //隐患上报
                    newFilter.SelectField = new List<string> { "ID", "NAME", "SUBMIT_STATUS", "DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    var riskSubmit = this.GetEntities<T_BS_RISK_SUBMIT>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.DEPARTMENT_ID != null
                    && t.SUBMIT_STATUS != (int)BSSubmitStatusEnum.Start, newFilter).ToList();
                   if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        riskSubmit = riskSubmit.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 隐患上报
                    if (riskSubmit.Any())
                    {
                        riskSubmit.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(BSSubmitStatusEnum), t.SUBMIT_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
             && filter.Parameter3 == "安全检查" && filter.Parameter4 == "隐患整改记录")
                {
                    //隐患整改记录
                    newFilter.SelectField = new List<string> { "ID", "NAME", "DEALSITUATION", "Nav_UserDeal", "CREATER_ID", "CREATE_TIME" };
                    var riskDeal = this.GetEntities<T_BS_RISK_SUBMIT_CONTENT_DEAL>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_UserDeal != null && t.Nav_UserDeal.DEPARTMENT_ID != null
                    && t.DEALSITUATION != (int)DealSituation.End, newFilter).ToList();
                   if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        riskDeal = riskDeal.Where(t => outPartmentIds.Contains((Guid)t.Nav_UserDeal.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 隐患整改记录
                    if (riskDeal.Any())
                    {
                        riskDeal.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(DealSituation), t.DEALSITUATION);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
             && filter.Parameter3 == "安全检查" && filter.Parameter4 == "延期整改申请")
                {
                    //延期整改申请
                    newFilter.SelectField = new List<string> { "ID", "NAME", "Nav_Submit", "APPLY_DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    var delayApply = this.GetEntities<T_BS_RISK_SUBMIT_DELAY_APPLY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.APPLY_DEPARTMENT_ID != null && t.Nav_Submit!=null, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        delayApply = delayApply.Where(t => outPartmentIds.Contains((Guid)t.APPLY_DEPARTMENT_ID)).ToList();
                    }
                    var ids = delayApply.Select(t => t.ID).ToList();
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    //只取待办超期的
                    newFilter.SelectField = new List<string> { "SOURCE_DATA_ID" };
                    var tasks = this.GetEntities<T_FM_NOTIFICATION_TASK>(t => (t.NOTICE_STATUS == 1|| t.NOTICE_STATUS == 2) && ids.Contains((Guid)t.SOURCE_DATA_ID) && t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime, newFilter).ToList();
                    var sourceIds = tasks.Select(t => t.SOURCE_DATA_ID).Distinct().ToList();
                    delayApply = delayApply.Where(t => !sourceIds.Contains(t.ID)).ToList();
                    #region 延期整改申请
                    if (delayApply.Any())
                    {
                        delayApply.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(BSSubmitStatusEnum), t.Nav_Submit.SUBMIT_STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "标准化创建" && filter.Parameter4 == "制度创建")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUS", "Nav_User", "CREATER_ID", "CREATE_TIME" };
                    //标准化创建
                    var standardCreate = this.GetEntities<T_SC_STANDARD_CREATE>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null
                    && t.STATUS != MS.Domain.Enums.SCSystemEditStatus.已归档, newFilter).ToList();
                    //制度
                    var standardSystem = standardCreate.Where(t => t.TYPE == SCType.制度).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        standardSystem = standardSystem.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 标准化制度创建
                    if (standardSystem.Any())
                    {
                        standardSystem.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(SCSystemEditStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "标准化创建" && filter.Parameter4 == "责任制创建")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUS", "Nav_User", "CREATER_ID", "CREATE_TIME" };
                    //标准化创建
                    var standardCreate = this.GetEntities<T_SC_STANDARD_CREATE>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null 
                    && t.STATUS != MS.Domain.Enums.SCSystemEditStatus.已归档, newFilter).ToList();
                    //责任制
                    var standardRespon = standardCreate.Where(t => t.TYPE == SCType.安全生产责任制).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        standardRespon = standardRespon.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 标准化责任制创建
                    if (standardRespon.Any())
                    {
                        standardRespon.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(SCSystemEditStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                 && filter.Parameter3 == "标准化创建" && filter.Parameter4 == "岗位安全操作规程和指导书")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUS", "Nav_User", "CREATER_ID", "CREATE_TIME" };
                    //标准化创建
                    var standardCreate = this.GetEntities<T_SC_STANDARD_CREATE>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null 
                    && t.Nav_User.DEPARTMENT_ID != null && t.STATUS != MS.Domain.Enums.SCSystemEditStatus.已归档, newFilter).ToList();
                    //岗位安全操作规程和指导书
                    var standardPost = standardCreate.Where(t => t.TYPE == SCType.岗位安全操作规程和指导书).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        standardPost = standardPost.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 岗位安全操作规程和指导书
                    if (standardPost.Any())
                    {
                        standardPost.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(SCSystemEditStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                 && filter.Parameter3 == "标准化创建" && filter.Parameter4 == "应急预案修订记录")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUS", "Nav_User", "CREATER_ID", "CREATE_TIME" };
                    //标准化创建
                    var standardCreate = this.GetEntities<T_SC_STANDARD_CREATE>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null 
                    && t.STATUS != MS.Domain.Enums.SCSystemEditStatus.已归档, newFilter).ToList();
                    //应急预案修订记录
                    var standardPlan = standardCreate.Where(t => t.TYPE == SCType.应急预案).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        standardPlan = standardPlan.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 应急预案修订记录
                    if (standardPlan.Any())
                    {
                        standardPlan.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(SCSystemEditStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                 && filter.Parameter3 == "会议管理" && filter.Parameter4 == "普通会议通知")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUS", "DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //会议管理
                    var meetingManage = this.GetEntities<T_SC_MT_MEETING>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime
                    && t.STATUS != PFStandardStatus.Archived, newFilter).ToList();
                    //普通会议通知
                    var orderMeeting = meetingManage.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.Ordinary).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        orderMeeting = orderMeeting.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 普通会议通知
                    if (orderMeeting.Any())
                    {
                        orderMeeting.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(PFStandardStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                  && filter.Parameter3 == "会议管理" && filter.Parameter4 == "安委会通知")
                {
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUS", "DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //会议管理
                    var meetingManage = this.GetEntities<T_SC_MT_MEETING>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime
                    && t.STATUS != PFStandardStatus.Archived, newFilter).ToList();
                    //安委会通知
                    var safeMeeting = meetingManage.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.SafetyBoard).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        safeMeeting = safeMeeting.Where(t => outPartmentIds.Contains((Guid)t.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 安委会通知
                    if (safeMeeting.Any())
                    {
                        safeMeeting.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(PFStandardStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                 && filter.Parameter3 == "会议管理" && filter.Parameter4 == "普通会议纪要")
                {
                    //会议纪要
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_Meeting" ,"CREATER_ID", "CREATE_TIME" };
                    var meetingMinutes = this.GetEntities<T_SC_MT_MEETING_MINUTES>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_Meeting != null
                    && t.STATUS != PFStandardStatus.Archived, newFilter).ToList();
                    //普通会议纪要
                    var orderMinute = meetingMinutes.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.Ordinary).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        orderMinute = orderMinute.Where(t => outPartmentIds.Contains((Guid)t.Nav_Meeting.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 普通会议纪要
                    if (orderMinute.Any())
                    {
                        orderMinute.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.Nav_Meeting?.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(PFStandardStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                 && filter.Parameter3 == "会议管理" && filter.Parameter4 == "安委会纪要")
                {
                    //会议纪要
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_Meeting", "CREATER_ID", "CREATE_TIME" };
                    var meetingMinutes = this.GetEntities<T_SC_MT_MEETING_MINUTES>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_Meeting != null
                    && t.STATUS != PFStandardStatus.Archived, newFilter).ToList();
                    //安委会纪要
                    var safeMinute = meetingMinutes.Where(t => t.MEETINGTYPE == SCMEETINGTYPE.SafetyBoard).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        safeMinute = safeMinute.Where(t => outPartmentIds.Contains((Guid)t.Nav_Meeting.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 安委会纪要
                    if (safeMinute.Any())
                    {
                        safeMinute.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.Nav_Meeting?.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(PFStandardStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "安全教育培训" && filter.Parameter4 == "安全意识调查")
                {
                    //安全教育培训
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUS", "LAUNCH_DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //安全意识调查
                    var taskIdentify = this.GetEntities<T_SE_SAFE_SURVEY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null
                    && t.STATUS != SESafeSurveyStatus.完成, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskIdentify = taskIdentify.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 安全意识调查
                    if (taskIdentify.Any())
                    {
                        taskIdentify.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(SESafeSurveyStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "安全教育培训" && filter.Parameter4 == "培训需求调查")
                {
                    //安全教育培训
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUS", "LAUNCH_DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //培训需求调查
                    var taskAnalysis = this.GetEntities<T_SE_TRAIN_SURVEY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null
                    && t.STATUS != MS.Domain.Enums.SETrainSurveyStatus.完成, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskAnalysis = taskAnalysis.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 培训需求调查
                    if (taskAnalysis.Any())
                    {
                        taskAnalysis.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(SETrainSurveyStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "安全教育培训" && filter.Parameter4 == "部门培训计划")
                {
                    //安全教育培训
                    newFilter.SelectField = new List<string> { "ID", "PLAN_YEAR", "STATUS", "LAUNCH_DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //部门培训计划
                    var taskOrdinary = this.GetEntities<T_SE_DEP_TRAIN_PLAN>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime 
                    && t.STATUS != PFStandardStatus.Archived, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskOrdinary = taskOrdinary.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 部门培训计划
                    if (taskOrdinary.Any())
                    {
                        taskOrdinary.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.PLAN_YEAR.ToString();
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(PFStandardStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "安全教育培训" && filter.Parameter4 == "年度培训计划")
                {
                    //安全教育培训
                    newFilter.SelectField = new List<string> { "ID", "PLAN_NAME", "STATUS", "LAUNCH_DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //年度培训计划
                    var taskCrucial = this.GetEntities<T_SE_YEAR_TRAIN_PLAN>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null
                    && t.STATUS != PFStandardStatus.Archived, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskCrucial = taskCrucial.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 年度培训计划
                    if (taskCrucial.Any())
                    {
                        taskCrucial.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.PLAN_NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(PFStandardStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "安全教育培训" && filter.Parameter4 == "培训通知")
                {
                    //安全教育培训
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUS", "LAUNCH_DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //培训通知
                    var taskLicense = this.GetEntities<T_SE_TRAIN_NOTIFY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null
                    && t.STATUS != SETrainNotifyStatus.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        taskLicense = taskLicense.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 培训通知
                    if (taskLicense.Any())
                    {
                        taskLicense.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(SETrainNotifyStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "安全教育培训" && filter.Parameter4 == "三级安全教育卡")
                {
                    //安全教育培训
                    newFilter.SelectField = new List<string> { "ID", "CODE", "STATUS", "LAUNCH_DEPARTMENT_ID", "CREATER_ID", "CREATE_TIME" };
                    //三级安全教育卡
                    var checkTask = this.GetEntities<T_SE_THREE_LEVEL_SAFE_EDU_CARD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.LAUNCH_DEPARTMENT_ID != null
                     && t.STATUS != SEThreeLevelSafeTrainStatus.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        checkTask = checkTask.Where(t => outPartmentIds.Contains((Guid)t.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 三级安全教育卡
                    if (checkTask.Any())
                    {
                        checkTask.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.CODE;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(SEThreeLevelSafeTrainStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                && filter.Parameter3 == "安全教育培训" && filter.Parameter4 == "培训记录")
                {
                    //安全教育培训
                    //培训记录
                    newFilter.SelectField = new List<string> { "ID", "STATUS", "Nav_Notify", "CREATER_ID", "CREATE_TIME" };
                    var filePublish = this.GetEntities<T_SE_TRAIN_RECORD>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_Notify != null && t.Nav_Notify.LAUNCH_DEPARTMENT_ID != null
                     && t.STATUS != SETrainRecordStatus.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        filePublish = filePublish.Where(t => outPartmentIds.Contains((Guid)t.Nav_Notify.LAUNCH_DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 培训记录
                    if (filePublish.Any())
                    {
                        filePublish.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.Nav_Notify.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(SETrainRecordStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(filter.Parameter3) && !string.IsNullOrEmpty(filter.Parameter4)
                 && filter.Parameter3 == "安全教育培训" && filter.Parameter4 == "培训效果评估表")
                {
                    //安全教育培训
                    //培训效果评估表
                    newFilter.SelectField = new List<string> { "ID", "NAME", "STATUS", "Nav_User", "CREATER_ID", "CREATE_TIME" };
                    var riskDeal = this.GetEntities<T_SE_TRAINING_EFFECT_EVALUATION_SURVEY>(t => t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.Nav_User != null && t.Nav_User.DEPARTMENT_ID != null
                     && t.STATUS !=  SETrainningEffectSurveyStatus.归档, newFilter).ToList();
                    if (!string.IsNullOrEmpty(filter.Keyword))
                    {
                        riskDeal = riskDeal.Where(t => outPartmentIds.Contains((Guid)t.Nav_User.DEPARTMENT_ID)).ToList();
                    }
                    //人员
                    newFilter.SelectField = new List<string> { "NAME", "Nav_Department" };
                    var userInfo = this.GetEntities<T_FM_USER>(t => t.ENABLE_STATUS == 0, newFilter).ToList();
                    #region 培训效果评估表
                    if (riskDeal.Any())
                    {
                        riskDeal.ForEach(t =>
                        {
                            UnFinishInfo analysis = new UnFinishInfo();
                            analysis.NAME = t.NAME;
                            analysis.CREATE_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.NAME;
                            analysis.DEPARTMENT_NAME = userInfo.FirstOrDefault(m => m.ID == t.CREATER_ID)?.Nav_Department?.NAME;
                            analysis.CREATE_TIME = t.CREATE_TIME;
                            analysis.STATUS_NAME = Enum.GetName(typeof(SETrainningEffectSurveyStatus), t.STATUS);
                            formAnalysis.Add(analysis);
                        });
                    }
                    #endregion
                }
                return formAnalysis;
            });
        }

        [HttpPost, Route("GetTotalCount")]
        public JsonActionResult<dynamic> GetTotalCount([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<dynamic>(() =>
            {
                pageFilter.IgnoreDataRule = true;
                //首页待办增加数量统计字段
                dynamic ret = new System.Dynamic.ExpandoObject();
                var ordinaryCount = GetCount<T_FO_JOB_EVENT_RECORD>(s => !s.IS_DELETED, pageFilter);
                var crucialCount = GetCount<T_FO_CRUCIAL_LICENSE_JOB>(s => !s.IS_DELETED, pageFilter);
                var activityCount = GetCount<T_FO_TEAM_ACTIVITY>(s => !s.IS_DELETED, pageFilter);
                var postCount = GetCount<T_FO_CURRENT_CLASS_RECORD>(s => !s.IS_DELETED, pageFilter);
                var postChangeCount = GetCount<T_FO_CHANGE_SHIFT_RECORD>(s => !s.IS_DELETED, pageFilter);
                var taskCount = GetCount<T_HM_OPERATION_LINK>(s => !s.IS_DELETED, pageFilter);
                var shiftMeetingCount = GetCount<T_FO_PRE_SHIFT_MEETING_RECORD>(s => !s.IS_DELETED, pageFilter);
                var shiftMeetingFinishCount = GetCount<T_FO_PRE_SHIFT_MEETING_RECORD>(s => !s.IS_DELETED && s.PRE_MEETING_STATUS == FOPreMeetingStatusEnum.归档, pageFilter);
                var postChangeFinishCount = GetCount<T_FO_CHANGE_SHIFT_RECORD>(s => !s.IS_DELETED && s.SHIFT_STATUS == (int)FOChangeShiftStatusEnum.归档, pageFilter);
                var postFinishCount = GetCount<T_FO_CURRENT_CLASS_RECORD>(s => !s.IS_DELETED && s.SHIFT_STATUS == (int)FOShiftStatusEnum.归档, pageFilter);
                ret.ordinaryCount = ordinaryCount;
                ret.crucialCount = crucialCount;
                ret.activityCount = activityCount;
                ret.postCount = postCount;
                ret.postChangeCount = postChangeCount;
                ret.taskCount = taskCount;
                ret.shiftMeetingFinishRate = shiftMeetingCount == 0 ? "0" : ((double)shiftMeetingFinishCount / shiftMeetingCount * 100).ToString("0");
                ret.postFinishRate = postCount == 0 ? "0" : ((double)postFinishCount / postCount * 100).ToString("0");
                ret.postChangeFinishRate = postChangeCount == 0 ? "0" : ((double)postChangeFinishCount / postChangeCount * 100).ToString("0");
                return ret;
            });
        }

        [HttpPost, Route("GetDepartmentSort")]
        public JsonActionResult<List<T_FM_DEPARTMENT_COMPLETION_SORT>> GetDepartmentSort([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_FM_DEPARTMENT_COMPLETION_SORT>>(() =>
            {
                List<T_FM_DEPARTMENT_COMPLETION_SORT> completionSorts = new List<T_FM_DEPARTMENT_COMPLETION_SORT>();
                var completions = GetEntities<T_FM_DEPARTMENT_COMPLETION>(null, new BaseFilter(filter.OrgId));
                if (!string.IsNullOrEmpty(filter.Keyword))
                {
                    completions = completions.Where(t => t.DEPARTMENT_NAME == filter.Keyword).ToList();
                }
                var preshift = completions.Where(t => t.FORM_NAME == "班前会议");
                foreach (var item in preshift)
                {
                    T_FM_DEPARTMENT_COMPLETION_SORT completionSort = new T_FM_DEPARTMENT_COMPLETION_SORT();
                    completionSort.DEPARTMENT_ID = item.DEPARTMENT_ID;
                    completionSort.DEPARTMENT_NAME = item.DEPARTMENT_NAME;
                    completionSort.TEAM_ID = item.TEAM_ID;
                    completionSort.TEAM_NAME = item.TEAM_NAME;
                    completionSort.TEAM_TOTAL_COUNT = item.TOTAL_COUNT;
                    completionSort.TEAM_FINISH_COUNT = item.FINISH_COUNT;
                    completionSort.TEAM_ONTIME_FINISH_COUNT = item.ONTIME_COUNT;
                    completionSort.ORG_ID = filter.GetOrgId();
                    var current = completions.Where(t => t.TEAM_ID == item.TEAM_ID && t.FORM_NAME == "岗位当班");
                    if (current.Any())
                    {
                        completionSort.POST_TOTAL_COUNT = current.FirstOrDefault().TOTAL_COUNT;
                        completionSort.POST_FINISH_COUNT = current.FirstOrDefault().FINISH_COUNT;
                        completionSort.POST_ONTIME_FINISH_COUNT = current.FirstOrDefault().ONTIME_COUNT;
                    }
                    else
                    {
                        completionSort.POST_TOTAL_COUNT = 0;
                        completionSort.POST_FINISH_COUNT = 0;
                        completionSort.POST_ONTIME_FINISH_COUNT = 0;
                    }
                    var change = completions.Where(t => t.TEAM_ID == item.TEAM_ID && t.FORM_NAME == "岗位交接班");
                    if (change.Any())
                    {
                        completionSort.HANDOVER_TOTAL_COUNT = change.FirstOrDefault().TOTAL_COUNT;
                        completionSort.HANDOVER_FINISH_COUNT = change.FirstOrDefault().FINISH_COUNT;
                        completionSort.HANDOVER_ONTIME_FINISH_COUNT = change.FirstOrDefault().ONTIME_COUNT;
                    }
                    else
                    {
                        completionSort.HANDOVER_TOTAL_COUNT = 0;
                        completionSort.HANDOVER_FINISH_COUNT = 0;
                        completionSort.HANDOVER_ONTIME_FINISH_COUNT = 0;
                    }
                    completionSorts.Add(completionSort);
                }
                foreach (var item in completionSorts)
                {
                    var temp1 = (item.TEAM_ONTIME_FINISH_COUNT + item.POST_ONTIME_FINISH_COUNT + item.HANDOVER_ONTIME_FINISH_COUNT);//(item.TEAM_FINISH_COUNT + item.POST_FINISH_COUNT + item.HANDOVER_FINISH_COUNT);
                    var temp2 = (item.TEAM_TOTAL_COUNT + item.POST_TOTAL_COUNT + item.HANDOVER_TOTAL_COUNT);
                    var tempCalc = (double)temp1 / (double)temp2;
                    item.CALC = tempCalc;
                }
                List<T_FM_DEPARTMENT_COMPLETION_SORT> completionSorts1 = completionSorts.OrderByDescending(t => t.CALC).Take(8).ToList();
                int i = 1;
                foreach (var item in completionSorts1)
                {
                    item.NUM = i;
                    i++;
                }
                return completionSorts1;
            });
        }

        [HttpPost, Route("GetLicenseJob")]
        public JsonActionResult<List<T_FM_RISK_LEVEL_PROPORTION>> GetLicenseJob([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_FM_RISK_LEVEL_PROPORTION>>(() =>
            {
                List<T_FM_RISK_LEVEL_PROPORTION> completionSorts = new List<T_FM_RISK_LEVEL_PROPORTION>();
                filter.IgnoreDataRule = true;
                var completions = GetEntities<T_FO_CRUCIAL_LICENSE_JOB>(t=>!t.IS_DELETED, filter);
                var count1 = completions.Where(t => t.AUDIT_LEVEL == (int)HMOperationTaskAuditEnum.一级审批).Count();
                T_FM_RISK_LEVEL_PROPORTION level1 = new T_FM_RISK_LEVEL_PROPORTION();
                level1.RISK_LEVEL = "一级审批";
                level1.COUNT = count1;
                completionSorts.Add(level1);
                var count2 = completions.Where(t => t.AUDIT_LEVEL == (int)HMOperationTaskAuditEnum.二级审批).Count();
                T_FM_RISK_LEVEL_PROPORTION level2 = new T_FM_RISK_LEVEL_PROPORTION();
                level2.RISK_LEVEL = "二级审批";
                level2.COUNT = count2;
                completionSorts.Add(level2);
                var count3 = completions.Where(t => t.AUDIT_LEVEL == (int)HMOperationTaskAuditEnum.三级审批).Count();
                T_FM_RISK_LEVEL_PROPORTION level3 = new T_FM_RISK_LEVEL_PROPORTION();
                level3.RISK_LEVEL = "三级审批";
                level3.COUNT = count3;
                completionSorts.Add(level3);
                var count4 = completions.Where(t => t.AUDIT_LEVEL == (int)HMOperationTaskAuditEnum.四级审批).Count();
                T_FM_RISK_LEVEL_PROPORTION level4 = new T_FM_RISK_LEVEL_PROPORTION();
                level4.RISK_LEVEL = "四级审批";
                level4.COUNT = count4;
                completionSorts.Add(level4);
                var count5 = completions.Where(t => t.AUDIT_LEVEL == (int)HMOperationTaskAuditEnum.无审批层级).Count();
                T_FM_RISK_LEVEL_PROPORTION level5 = new T_FM_RISK_LEVEL_PROPORTION();
                level5.RISK_LEVEL = "无审批层级";
                level5.COUNT = count5;
                completionSorts.Add(level5);
                return completionSorts;
            });
        }

        /// <summary>
        /// 待办汇总查询
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetPersonAnalyze")]
        public JsonActionResult<dynamic> GetPersonAnalyze([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<dynamic>(() =>
            {
                //首页待办增加数量统计字段
                dynamic ret = new System.Dynamic.ExpandoObject();
                //var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (string.IsNullOrEmpty(pageFilter.Parameter1) || string.IsNullOrEmpty(pageFilter.Parameter2))
                {
                    throw new Exception("请先选择时间段");
                }
                if (string.IsNullOrEmpty(pageFilter.Keyword))
                {
                    throw new Exception("请先输入人员或工号");
                }
                var newFilter = new BaseFilter(pageFilter.OrgId);
                newFilter.SelectField = new List<string> { "ID" };
                var user = GetEntity<T_FM_USER>(t => (t.NAME == pageFilter.Keyword.Trim()||t.CODE == pageFilter.Keyword.Trim()) && t.ENABLE_STATUS == 0, newFilter);
                if(user==null)
                    throw new Exception("该人员或工号不存在或已被禁用，请核对");
                newFilter.SelectField = new List<string> { "CREATE_TIME", "TASK_STARTDT", "NOTICE_STATUS", "TASK_ENDDT" };
                DateTime startTime = Convert.ToDateTime(pageFilter.Parameter1 + " 00:00:00");
                DateTime endTime = Convert.ToDateTime(pageFilter.Parameter2 + " 23:59:59");
                //TimeSpan span = endTime.Subtract(startTime);
                //int dayDidd = span.Days + 1;
                //if (dayDidd >= 180)
                //    throw new Exception("查询时间不能超过6个月!");
                List<T_BI_DEPARTMENT_MONTH_RUN> monthRuns = new List<T_BI_DEPARTMENT_MONTH_RUN>();
                var result = GetEntities<T_FM_NOTIFICATION_TASK>(s => s.TASK_STARTDT >= startTime && s.TASK_STARTDT <= endTime && s.USER_ID == user.ID && !s.IS_DELETED && s.NOTICE_TYPE != 2 && s.NOTICE_TYPE != 7, newFilter);
                if (result.Any())
                {
                    var newData = result.ToList();
                    ret.newData = newData;
                    ret.unfinishCount = newData.Where(s => s.NOTICE_STATUS == 0 ).Count();
                    ret.doneCount = newData.Where(s => s.NOTICE_STATUS == 1 || s.NOTICE_STATUS ==4).Count();
                    ret.timeOverCount = newData.Where(s =>  s.NOTICE_STATUS == 2).Count();
                    ret.timeOverWaitCount = newData.Where(s=>s.NOTICE_STATUS == 0 && s.TASK_ENDDT < DateTime.Now).Count();
                    ret.TotalCount = ret.doneCount + ret.unfinishCount+ ret.timeOverCount;
                    var currentMonth = startTime.Month;
                    var currentDay = startTime.Day;
                    for (DateTime i = startTime; i <= endTime; i=i.AddMonths(i.Month - i.Month+1).AddDays(1 - i.Day))
                    {
                        var monthEnd = Convert.ToDateTime(i.AddMonths(i.Month - i.Month + 1).AddDays(1 - i.Day - 1).ToString().Replace("0:00:00", "23:59:59"));
                        var ksJantask = result.Where(t => t.TASK_STARTDT >= i && t.TASK_STARTDT <= monthEnd).ToList();
                        if (ksJantask.Any())
                        {
                            T_BI_DEPARTMENT_MONTH_RUN run = new T_BI_DEPARTMENT_MONTH_RUN();
                            run.ORG_ID = pageFilter.OrgId;
                            run.MONTH = i;
                            run.MONTHStr = i.Year + "年" + i.Month + "月";
                            var total = ksJantask.Count();
                            var finish = ksJantask.Where(s => s.NOTICE_STATUS == 1).Count();
                            var overFinish = ksJantask.Where(s => s.NOTICE_STATUS == 2).Count();
                            var temp = total == 0 ? 0 : (double)(finish + overFinish) / total * 100;
                            run.FINISH_RATE = temp.ToString("0.0");
                            var temp2 = total == 0 ? 0 : (double)finish / total * 100;
                            run.NORMAL_FINISH_RATE = temp2.ToString("0.0");
                            run.TOTAL_QTY = total;
                            monthRuns.Add(run);
                        }
                        else
                        {
                            T_BI_DEPARTMENT_MONTH_RUN run = new T_BI_DEPARTMENT_MONTH_RUN();
                            run.ORG_ID = pageFilter.OrgId;
                            run.MONTH = i;
                            run.MONTHStr = i.Year + "年" + i.Month + "月";
                            var total = 0;
                            var finish = 0;
                            var overFinish = 0;
                            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");
                            run.TOTAL_QTY = total;
                            monthRuns.Add(run);
                        }
                    }
                    ret.groupData = monthRuns.OrderByDescending(t=>t.MONTH).ToList();
                    ret.groupDataLine = monthRuns.ToList();
                }
                return ret;
            });
        }

        /// <summary>
        /// 导出所有人
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetAllPersonAnalyze")]
        public JsonActionResult<dynamic> GetAllPersonAnalyze([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<dynamic>(() =>
            {
                //首页待办增加数量统计字段
                dynamic ret = new System.Dynamic.ExpandoObject();
                //var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (string.IsNullOrEmpty(pageFilter.Parameter1) || string.IsNullOrEmpty(pageFilter.Parameter2))
                {
                    throw new Exception("请先选择时间段");
                }
                var newFilter = new BaseFilter(pageFilter.OrgId);
                newFilter.SelectField = new List<string> { "ID","NAME" };
                var users = GetEntities<T_FM_USER>(t =>!t.IS_DELETED && t.ENABLE_STATUS ==0 && t.CODE!="admin", newFilter);
                var userIds = users.Select(t => t.ID).ToList();
                newFilter.SelectField = new List<string> { "CREATE_TIME", "TASK_STARTDT", "NOTICE_STATUS", "TASK_ENDDT" };
                DateTime startTime = Convert.ToDateTime(pageFilter.Parameter1 + " 00:00:00");
                DateTime endTime = Convert.ToDateTime(pageFilter.Parameter2 + " 23:59:59");
                TimeSpan span = endTime.Subtract(startTime);
                int dayDidd = span.Days + 1;
                if (dayDidd >= 180)
                    throw new Exception("查询时间不能超过6个月!");
                List<T_BI_DEPARTMENT_MONTH_RUN> monthRuns = new List<T_BI_DEPARTMENT_MONTH_RUN>();
                var resultTemp = GetEntities<T_FM_NOTIFICATION_TASK>(s => s.TASK_STARTDT >= startTime && s.TASK_STARTDT <= endTime && userIds.Contains(s.USER_ID) && !s.IS_DELETED && s.NOTICE_TYPE != 2 && s.NOTICE_TYPE != 7, newFilter);
                if (resultTemp.Any())
                {
                    foreach (var item in users)
                    {
                        var result = resultTemp.Where(t => t.USER_ID == item.ID).ToList();
                        //var newData = result.ToList();
                        //ret.newData = newData;
                        //ret.unfinishCount = newData.Where(s => s.NOTICE_STATUS == 0).Count();
                        //ret.doneCount = newData.Where(s => s.NOTICE_STATUS == 1 || s.NOTICE_STATUS == 4).Count();
                        //ret.timeOverCount = newData.Where(s => s.NOTICE_STATUS == 2).Count();
                        //ret.timeOverWaitCount = newData.Where(s => s.NOTICE_STATUS == 0 && s.TASK_ENDDT < DateTime.Now).Count();
                        //ret.TotalCount = ret.doneCount + ret.unfinishCount + ret.timeOverCount;
                        var currentMonth = startTime.Month;
                        var currentDay = startTime.Day;
                        for (DateTime i = startTime; i <= endTime; i = i.AddMonths(i.Month - i.Month + 1).AddDays(1 - i.Day))
                        {
                            var monthEnd = Convert.ToDateTime(i.AddMonths(i.Month - i.Month + 1).AddDays(1 - i.Day - 1).ToString().Replace("0:00:00", "23:59:59"));
                            var ksJantask = result.Where(t => t.TASK_STARTDT >= i && t.TASK_STARTDT <= monthEnd).ToList();
                            if (ksJantask.Any())
                            {
                                T_BI_DEPARTMENT_MONTH_RUN run = new T_BI_DEPARTMENT_MONTH_RUN();
                                run.ORG_ID = pageFilter.OrgId;
                                run.MONTH = i;
                                run.MONTHStr = i.Year + "年" + i.Month + "月";
                                var total = ksJantask.Count();
                                var finish = ksJantask.Where(s => s.NOTICE_STATUS == 1).Count();
                                var overFinish = ksJantask.Where(s => s.NOTICE_STATUS == 2).Count();
                                var temp = total == 0 ? 0 : (double)(finish + overFinish) / total * 100;
                                run.FINISH_RATE = temp.ToString("0.0");
                                var temp2 = total == 0 ? 0 : (double)finish / total * 100;
                                run.NORMAL_FINISH_RATE = temp2.ToString("0.0");
                                run.TOTAL_QTY = total;
                                run.DEPARTMENT_NAME = item.NAME;
                                monthRuns.Add(run);
                            }
                            else
                            {
                                T_BI_DEPARTMENT_MONTH_RUN run = new T_BI_DEPARTMENT_MONTH_RUN();
                                run.ORG_ID = pageFilter.OrgId;
                                run.MONTH = i;
                                run.MONTHStr = i.Year + "年" + i.Month + "月";
                                var total = 0;
                                var finish = 0;
                                var overFinish = 0;
                                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");
                                run.TOTAL_QTY = total;
                                run.DEPARTMENT_NAME = item.NAME;
                                monthRuns.Add(run);
                            }
                        }
                    }
                    ret.groupData = monthRuns.OrderByDescending(t => t.MONTH).ToList();
                }
                return ret;
            });
        }

        #region 获取选矿部、矿山部统计情况
        /// <summary>
        /// 获取选矿部、矿山部统计情况
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDepartmentAnalyze")]
        public JsonActionResult<List<T_BI_SYSTEM_RUN_SUMMARY>> GetDepartmentAnalyze([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<List<T_BI_SYSTEM_RUN_SUMMARY>>(() =>
            {
                var dt = DateTime.Now;
                if (string.IsNullOrEmpty(pageFilter.Parameter1) || string.IsNullOrEmpty(pageFilter.Parameter2))
                {
                    throw new Exception("请先选择时间开始时间和结束时间");
                }
                if (string.IsNullOrEmpty(pageFilter.Keyword))
                {
                    throw new Exception("部门未传入，请联系管理员");
                }
                var newFilter = new BaseFilter(pageFilter.OrgId);
                DateTime year = DateTime.Parse(pageFilter.Parameter1);
                DateTime yearEnd = DateTime.Parse(pageFilter.Parameter2);
                TimeSpan span = yearEnd.Subtract(year);
                int dayDidd = span.Days + 1;
                if (dayDidd >= 180)
                    throw new Exception("查询时间不能超过6个月!");
                var departmentId = Guid.Parse(pageFilter.Keyword);
                List<T_BI_SYSTEM_RUN_SUMMARY> departSummary = new List<T_BI_SYSTEM_RUN_SUMMARY>();
                var taskYear = this.GetEntities<T_BI_NOTIFICATION_TASK>(t => t.CREATE_DATE >= year && t.CREATE_DATE<= yearEnd && t.DEPT_DEPARTMENT_ID == departmentId, 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 shopGroupYear = taskYear.Where(t => t.SHOP_DEPARTMENT_ID != null && t.MOUDLE_NAME != null).ToList();
                //班组级
                var classGroupYear = taskYear.Where(t => t.CLASS_DEPARTMENT_ID != null).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);
                    });
                }
                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);
                    });
                }
                return departSummary;
            });
        }
        #endregion

        #region 获取选矿部、矿山部统计情况
        /// <summary>
        /// 获取选矿部、矿山部统计情况
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDepartmentAnalyzeNew")]
        public JsonActionResult<List<T_BI_SYSTEM_RUN_SUMMARY>> GetDepartmentAnalyzeNew([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeExecute<List<T_BI_SYSTEM_RUN_SUMMARY>>(() =>
            {
                var dt = DateTime.Now;
                if (string.IsNullOrEmpty(pageFilter.Parameter1) || string.IsNullOrEmpty(pageFilter.Parameter2))
                {
                    throw new Exception("请先选择时间开始时间和结束时间");
                }
                if (string.IsNullOrEmpty(pageFilter.Keyword))
                {
                    throw new Exception("部门未传入，请联系管理员");
                }
                var newFilter = new BaseFilter(pageFilter.OrgId);
                DateTime year = DateTime.Parse(pageFilter.Parameter1);
                DateTime yearEnd = DateTime.Parse(pageFilter.Parameter2);
                TimeSpan span = yearEnd.Subtract(year);
                if(year < DateTime.Now.AddMonths(-6))
                    throw new Exception("查询时间不能小于"+ DateTime.Now.AddMonths(-6));
                int dayDidd = span.Days + 1;
                if (dayDidd >= 180)
                    throw new Exception("查询时间不能超过6个月!");
                var departmentId = Guid.Parse(pageFilter.Keyword);
                List<T_BI_SYSTEM_RUN_SUMMARY> departSummary = new List<T_BI_SYSTEM_RUN_SUMMARY>();
                var taskYear = this.GetEntities<T_BI_NOTIFICATION_TASK_NEW>(t =>!t.IS_DELETED && t.CREATE_DATE >= year && t.CREATE_DATE <= yearEnd, 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();
                //newFilter.SelectField = new List<string> { "ID", "DEPARTMENT_ID", "NAME" };
                //var userInfos = this.GetEntities<T_FM_USER>(t => !t.IS_DELETED, newFilter).ToList();
                //部门级
                var departGroupYear = taskYear.Where(t => t.DEPT_DEPARTMENT_ID != null && t.DEPT_DEPARTMENT_ID == departmentId).ToList();
                //车间级
                var shopGroupYear = taskYear.Where(t => t.SHOP_DEPARTMENT_ID != null && t.DEPT_DEPARTMENT_ID == departmentId).ToList();
                //班组级
                var classGroupYear = taskYear.Where(t => t.CLASS_DEPARTMENT_ID != null && t.DEPT_DEPARTMENT_ID == departmentId).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 = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 0).Count();
                        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 (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 = t.Where(m => m.SHOP_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 0).Count();
                        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 = t.Where(m => m.CLASS_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 0).Count();
                        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);
                    });
                }
                return departSummary;
            });
        }
        #endregion

        /// <summary>
        /// 作业活动完成率前八（除班组级）
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDepartmentCompletionSortOld")]
        public JsonActionResult<List<T_FM_DEPARTMENT_COMPLETION_SORT>> GetDepartmentCompletionSortOld([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_FM_DEPARTMENT_COMPLETION_SORT>>(() =>
            {
                var departmentType = 3;
                List<GroupbyDepartmentId> completionLists = new List<GroupbyDepartmentId>();
                List<T_FM_DEPARTMENT_COMPLETION_SORT> completionSorts = new List<T_FM_DEPARTMENT_COMPLETION_SORT>();
                if (string.IsNullOrEmpty(filter.Keyword))
                   return completionSorts;
                var departmentInfo = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == Guid.Parse(filter.Keyword.ToString()));
                if (departmentInfo == null)
                    return completionSorts;
                else
                    departmentType = departmentInfo.DEPARTMENT_TYPE;
                //BaseFilter baseFilter = new BaseFilter(filter.GetOrgId());
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var completions = GetEntities<T_FM_DEPARTMENT_COMPLETION>(t=>!t.IS_DELETED, new BaseFilter(orgId)).ToList();
                if(departmentType == 3)
                {
                    completionLists = completions.Where(m => m.SHOP_DEPARTMENT_ID != null).GroupBy(t => new { t.SHOP_DEPARTMENT_ID, t.SHOP_DEPARTMENT_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.SHOP_DEPARTMENT_ID,
                        departmentName = group.Key.SHOP_DEPARTMENT_NAME,
                        doneCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m=>m.FINISH_COUNT),
                        TotalCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                    
                }
                if (departmentType == 0)
                {
                    completionLists = completions.Where(m => m.SHOP_DEPARTMENT_ID != null && m.DEPARTMENT_ID == Guid.Parse(filter.Keyword.ToString())).GroupBy(t => new { t.SHOP_DEPARTMENT_ID, t.SHOP_DEPARTMENT_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.SHOP_DEPARTMENT_ID,
                        departmentName = group.Key.SHOP_DEPARTMENT_NAME,
                        doneCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.FINISH_COUNT),
                        TotalCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (departmentType == 1)
                {
                    completionLists = completions.Where(m => m.TEAM_ID != null && m.SHOP_DEPARTMENT_ID == Guid.Parse(filter.Keyword.ToString())).GroupBy(t => new { t.TEAM_ID, t.TEAM_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.TEAM_ID,
                        departmentName = group.Key.TEAM_NAME,
                        doneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.FINISH_COUNT),
                        TotalCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (departmentType == 2)
                {
                    completionLists = completions.Where(m => m.TEAM_ID != null && m.SHOP_DEPARTMENT_ID == departmentInfo.PARENT_ID).GroupBy(t => new { t.TEAM_ID, t.TEAM_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.TEAM_ID,
                        departmentName = group.Key.TEAM_NAME,
                        doneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.FINISH_COUNT),
                        TotalCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (completionLists != null && completionLists.Any())
                {
                    foreach (var item in completionLists)
                    {
                        T_FM_DEPARTMENT_COMPLETION_SORT completionSort = new T_FM_DEPARTMENT_COMPLETION_SORT();
                        completionSort.TEAM_ID = item.departmentId;
                        completionSort.TEAM_NAME = item.departmentName;
                        completionSort.TEAM_FINISH_COUNT = item.doneCount;
                        completionSort.TEAM_TOTAL_COUNT = item.TotalCount;
                        completionSort.POST_FINISH_COUNT = 0;
                        completionSort.POST_TOTAL_COUNT = 0;
                        completionSort.HANDOVER_FINISH_COUNT = 0;
                        completionSort.HANDOVER_TOTAL_COUNT = 0;
                        completionSorts.Add(completionSort);
                    }
                }
                foreach (var item in completionSorts)
                {
                    if (item.TEAM_TOTAL_COUNT == 0)
                    {
                        item.CALC = 0;
                    }
                    else
                    {
                        var tempCalc = (double)item.TEAM_FINISH_COUNT / (double)item.TEAM_TOTAL_COUNT;
                        item.CALC = tempCalc;
                    }
                }
                List<T_FM_DEPARTMENT_COMPLETION_SORT> completionSorts1 = completionSorts.OrderByDescending(t => t.CALC).Take(8).ToList();
                int i = 1;
                foreach (var item in completionSorts1)
                {
                    item.NUM = i;
                    i++;
                }
                return completionSorts1;
            });
        }

        /// <summary>
        /// 作业活动完成率前八
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDepartmentCompletionSort")]
        public JsonActionResult<List<T_FM_DEPARTMENT_COMPLETION_SORT>> GetDepartmentCompletionSort([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_FM_DEPARTMENT_COMPLETION_SORT>>(() =>
            {
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var mineType = 30;
                var departmentIds = new List<Guid>();
                List<GroupbyDepartmentId> completionLists = new List<GroupbyDepartmentId>();
                List<T_FM_DEPARTMENT_COMPLETION_SORT> completionSorts = new List<T_FM_DEPARTMENT_COMPLETION_SORT>();
                if (string.IsNullOrEmpty(filter.Keyword))
                    return completionSorts;
                var departmentInfo = this.GetEntities<T_FM_DEPARTMENT>(t => t.MineType == int.Parse(filter.Keyword.ToString()), new BaseFilter(orgId));
                if (departmentInfo == null || !departmentInfo.Any())
                    return completionSorts;
                else
                    departmentIds = departmentInfo.Select(t => t.ID).ToList();
                BaseFilter baseFilter = new BaseFilter(orgId);
                baseFilter.SelectField = new string[] { "ID", "DEPARTMENT_ID" };
                var teams = GetEntities<T_FM_TEAM>(t => !t.IS_DELETED && departmentIds.Contains(t.DEPARTMENT_ID.Value), baseFilter);
                var teamIds = teams.Select(t => t.ID);
                var completions = GetEntities<T_FM_DEPARTMENT_COMPLETION>(t => !t.IS_DELETED, new BaseFilter(orgId)).ToList();
                if (teamIds != null && teamIds.Any())
                {
                    completionLists = completions.Where(m => m.TEAM_ID != null && teamIds.Contains(m.TEAM_ID.Value)).GroupBy(t => new { t.TEAM_ID, t.TEAM_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.TEAM_ID,
                        departmentName = group.Key.TEAM_NAME,
                        doneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.FINISH_COUNT),
                        TotalCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (completionLists != null && completionLists.Any())
                {
                    foreach (var item in completionLists)
                    {
                        T_FM_DEPARTMENT_COMPLETION_SORT completionSort = new T_FM_DEPARTMENT_COMPLETION_SORT();
                        completionSort.TEAM_ID = item.departmentId;
                        completionSort.TEAM_NAME = item.departmentName;
                        completionSort.TEAM_FINISH_COUNT = item.doneCount;
                        completionSort.TEAM_TOTAL_COUNT = item.TotalCount;
                        completionSort.POST_FINISH_COUNT = 0;
                        completionSort.POST_TOTAL_COUNT = 0;
                        completionSort.HANDOVER_FINISH_COUNT = 0;
                        completionSort.HANDOVER_TOTAL_COUNT = 0;
                        completionSorts.Add(completionSort);
                    }
                }
                foreach (var item in completionSorts)
                {
                    if (item.TEAM_TOTAL_COUNT == 0)
                    {
                        item.CALC = 0;
                    }
                    else
                    {
                        var tempCalc = (double)item.TEAM_FINISH_COUNT / (double)item.TEAM_TOTAL_COUNT;
                        item.CALC = tempCalc;
                    }
                }
                List<T_FM_DEPARTMENT_COMPLETION_SORT> completionSorts1 = completionSorts.OrderByDescending(t => t.CALC).Take(8).ToList();
                if (!string.IsNullOrEmpty(filter.Parameter1))
                {
                    var param = int.Parse(filter.Parameter1.ToString());
                    completionSorts1 = completionSorts.OrderByDescending(t => t.CALC).Take(param).ToList();
                }
                int i = 1;
                foreach (var item in completionSorts1)
                {
                    item.NUM = i;
                    i++;
                }
                return completionSorts1;
            });
        }
        /// <summary>
        /// 作业活动完成率前八（详情页）
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetClassCompletionSort")]
        public JsonActionResult<dynamic> GetClassCompletionSort([FromBody] KeywordFilter filter)
        {
            return SafeExecute<dynamic>(() =>
            {
                dynamic ret = new System.Dynamic.ExpandoObject();
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                //var mineType = 30;
                var departmentIds = new List<Guid>();
                List<GroupbyDepartmentCompletion> completionLists = new List<GroupbyDepartmentCompletion>();
                List<T_FM_DEPARTMENT_COMPLETION> completionSorts = new List<T_FM_DEPARTMENT_COMPLETION>();
                if (string.IsNullOrEmpty(filter.Keyword))
                    return ret;
                var departmentInfo = this.GetEntities<T_FM_DEPARTMENT>(t => !t.IS_DELETED && t.ENABLE_STATUS == 0, new BaseFilter(orgId));//t.MineType == int.Parse(filter.Keyword.ToString())
                if (departmentInfo == null || !departmentInfo.Any())
                    return ret;
                else
                    departmentIds = departmentInfo.Select(t => t.ID).ToList();
                BaseFilter baseFilter = new BaseFilter(orgId);
                baseFilter.SelectField = new string[] { "ID", "DEPARTMENT_ID" };
                var teams = GetEntities<T_FM_TEAM>(t => !t.IS_DELETED && departmentIds.Contains(t.DEPARTMENT_ID.Value), baseFilter);
                var teamIds = teams.Select(t => t.ID);
                var completions = GetEntities<T_FM_DEPARTMENT_COMPLETION>(t => !t.IS_DELETED && t.TEAM_ID != null && teamIds.Contains(t.TEAM_ID.Value), new BaseFilter(orgId)).ToList();
                if (completions != null && completions.Any())
                {
                    completionSorts = completions.GroupBy(t => new { t.MONTH,t.MONTHStr }).Select(group => new T_FM_DEPARTMENT_COMPLETION
                    {
                        MONTH = group.Key.MONTH,
                        MONTHStr = group.Key.MONTH.Year + "-" + group.Key.MONTH.Month,
                        FINISH_COUNT = group.Where(i => i.MONTH == group.Key.MONTH).Sum(m => m.FINISH_COUNT),
                        ONTIME_COUNT = group.Where(i => i.MONTH == group.Key.MONTH).Sum(m => m.ONTIME_COUNT),
                        TOTAL_COUNT = group.Where(i => i.MONTH == group.Key.MONTH).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                    completionLists = completions.GroupBy(t => new { t.TEAM_ID, t.TEAM_NAME,t.SHOP_DEPARTMENT_ID,t.SHOP_DEPARTMENT_NAME }).Select(group => new GroupbyDepartmentCompletion
                    {
                        shopId = group.Key.SHOP_DEPARTMENT_ID,
                        shopName = group.Key.SHOP_DEPARTMENT_NAME,
                        teamId = group.Key.TEAM_ID,
                        teamName = group.Key.TEAM_NAME,
                        teamDoneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.FINISH_COUNT),
                        teamOntimeCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.ONTIME_COUNT),
                        teamUndoneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.WAITTING_COUNT),
                        teamTotalCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (completionSorts != null && completionSorts.Any())
                {
                    foreach (var item in completionSorts)
                    {
                        if (item.TOTAL_COUNT == 0)
                        {
                            item.FINISH_RATE = 0;
                            item.NORMAL_FINISH_RATE = 0;
                        }
                        else
                        {
                            item.FINISH_RATE = Math.Round((double)item.FINISH_COUNT / (double)item.TOTAL_COUNT * 100, 2);
                            item.NORMAL_FINISH_RATE = Math.Round((double)item.ONTIME_COUNT / (double)item.TOTAL_COUNT * 100, 2);
                        }
                    }
                    ret.rateData = completionSorts.OrderBy(t=>t.MONTH).ToList();
                }
                if (completionLists != null && completionLists.Any())
                {
                    foreach (var item in completionLists)
                    {
                        item.shopDoneCount = completionLists.Where(i => i.shopId == item.shopId).Sum(m => m.teamDoneCount);
                        item.shopOntimeCount = completionLists.Where(i => i.shopId == item.shopId).Sum(m => m.teamOntimeCount);
                        item.shopTotalCount = completionLists.Where(i => i.shopId == item.shopId).Sum(m => m.teamTotalCount);
                        if (item.shopTotalCount == 0)
                        {
                            item.shopDoneRate = 0;
                            item.shopOverDoneRate = 0;
                        }
                        else
                        {
                            item.shopDoneRate = Math.Round((double)item.shopDoneCount / (double)item.shopTotalCount * 100, 2);
                            item.shopOverDoneRate = Math.Round((double)item.shopOntimeCount / (double)item.shopTotalCount * 100, 2);
                        }
                        if (item.teamTotalCount == 0)
                        {
                            item.teamDoneRate = 0;
                            item.teamOverDoneRate = 0;
                        }
                        else
                        {
                            item.teamDoneRate = Math.Round((double)item.teamDoneCount / (double)item.teamTotalCount * 100, 2);
                            item.teamOverDoneRate = Math.Round((double)item.teamOntimeCount / (double)item.teamTotalCount * 100, 2);
                        }
                    }
                    ret.retData = completionLists.OrderBy(t=>t.shopName).ThenByDescending(m=>m.teamOverDoneRate).ToList();
                }
                return ret;
            });
        }

        /// <summary>
        /// 首页工作票完成数前八
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetJobCompletionSortOld")]
        public JsonActionResult<List<T_FM_WORK_TICKET_COMPLETION>> GetJobCompletionSortOld([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_FM_WORK_TICKET_COMPLETION>>(() =>
            {
                var departmentType = 3;
                List<GroupbyDepartmentId> completionLists = new List<GroupbyDepartmentId>();
                List<T_FM_WORK_TICKET_COMPLETION> completionSorts = new List<T_FM_WORK_TICKET_COMPLETION>();
                if (string.IsNullOrEmpty(filter.Keyword))
                    return completionSorts;
                var departmentInfo = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == Guid.Parse(filter.Keyword.ToString()));
                if (departmentInfo == null)
                    return completionSorts;
                else
                    departmentType = departmentInfo.DEPARTMENT_TYPE;
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var completions = GetEntities<T_FM_WORK_TICKET_COMPLETION>(t => !t.IS_DELETED, new BaseFilter(orgId)).ToList();
                if (departmentType == 3)
                {
                    completionLists = completions.Where(m=>m.SHOP_DEPARTMENT_ID !=null).GroupBy(t => new { t.SHOP_DEPARTMENT_ID, t.SHOP_DEPARTMENT_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.SHOP_DEPARTMENT_ID,
                        departmentName = group.Key.SHOP_DEPARTMENT_NAME,
                        doneCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.ONTIME_COUNT),
                        timeOverCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.OVER_FINISH_COUNT),
                        TotalCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();

                }
                if (departmentType == 0)
                {
                    completionLists = completions.Where(m => m.SHOP_DEPARTMENT_ID != null && m.DEPARTMENT_ID == Guid.Parse(filter.Keyword.ToString())).GroupBy(t => new { t.SHOP_DEPARTMENT_ID, t.SHOP_DEPARTMENT_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.SHOP_DEPARTMENT_ID,
                        departmentName = group.Key.SHOP_DEPARTMENT_NAME,
                        doneCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.ONTIME_COUNT),
                        timeOverCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.OVER_FINISH_COUNT),
                        TotalCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (departmentType == 1)
                {
                    completionLists = completions.Where(m => m.TEAM_ID != null && m.SHOP_DEPARTMENT_ID == Guid.Parse(filter.Keyword.ToString())).GroupBy(t => new { t.TEAM_ID, t.TEAM_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.TEAM_ID,
                        departmentName = group.Key.TEAM_NAME,
                        doneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.ONTIME_COUNT),
                        timeOverCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.OVER_FINISH_COUNT),
                        TotalCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (departmentType == 2)
                {
                    completionLists = completions.Where(m=> m.TEAM_ID != null && m.SHOP_DEPARTMENT_ID == departmentInfo.PARENT_ID).GroupBy(t => new { t.TEAM_ID, t.TEAM_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.TEAM_ID,
                        departmentName = group.Key.TEAM_NAME,
                        doneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.ONTIME_COUNT),
                        timeOverCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.OVER_FINISH_COUNT),
                        TotalCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (completionLists != null && completionLists.Any())
                {
                    foreach (var item in completionLists)
                    {
                        T_FM_WORK_TICKET_COMPLETION completionSort = new T_FM_WORK_TICKET_COMPLETION();
                        completionSort.TEAM_ID = item.departmentId;
                        completionSort.TEAM_NAME = item.departmentName;
                        completionSort.FINISH_COUNT = item.doneCount;
                        completionSort.OVER_FINISH_COUNT = item.timeOverCount;
                        completionSort.TOTAL_COUNT = item.TotalCount;
                        completionSort.WAITTING_COUNT = item.TotalCount - item.doneCount - item.timeOverCount;
                        completionSorts.Add(completionSort);
                    }
                }
                foreach (var item in completionSorts)
                {
                    if (item.TOTAL_COUNT == 0)
                    {
                        item.CALC = 0;
                    }
                    else
                    {
                        var tempCalc = ((double)item.FINISH_COUNT + (double)item.OVER_FINISH_COUNT) / (double)item.TOTAL_COUNT;
                        item.CALC = tempCalc;
                    }
                }
                List<T_FM_WORK_TICKET_COMPLETION> completionSorts1 = completionSorts.OrderByDescending(t => t.CALC).Take(8).ToList();
                int i = 1;
                foreach (var item in completionSorts1)
                {
                    item.NUM = i;
                    i++;
                }
                return completionSorts1;
            });
        }

        /// <summary>
        /// 首页工作票完成数前八(班组级)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetJobCompletionSort")]
        public JsonActionResult<List<T_FM_WORK_TICKET_COMPLETION>> GetJobCompletionSort([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_FM_WORK_TICKET_COMPLETION>>(() =>
            {
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var MineType = 30;
                var departmentIds = new List<Guid>();
                List<GroupbyDepartmentId> completionLists = new List<GroupbyDepartmentId>();
                List<T_FM_WORK_TICKET_COMPLETION> completionSorts = new List<T_FM_WORK_TICKET_COMPLETION>();
                if (string.IsNullOrEmpty(filter.Keyword))
                    return completionSorts;
                var departmentInfo = this.GetEntities<T_FM_DEPARTMENT>(t => t.MineType == int.Parse(filter.Keyword.ToString()), new BaseFilter(orgId));
                if (departmentInfo == null || !departmentInfo.Any())
                    return completionSorts;
                else
                    departmentIds = departmentInfo.Select(t => t.ID).ToList();
                var completions = GetEntities<T_FM_WORK_TICKET_COMPLETION>(t => !t.IS_DELETED, new BaseFilter(orgId)).ToList();
                if (departmentIds !=null && departmentIds.Any())
                {
                    completionLists = completions.Where(m => m.TEAM_ID != null && departmentIds.Contains(m.TEAM_ID.Value)).GroupBy(t => new { t.TEAM_ID, t.TEAM_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.TEAM_ID,
                        departmentName = group.Key.TEAM_NAME,
                        doneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.ONTIME_COUNT),
                        timeOverCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.OVER_FINISH_COUNT),
                        TotalCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (completionLists != null && completionLists.Any())
                {
                    foreach (var item in completionLists)
                    {
                        T_FM_WORK_TICKET_COMPLETION completionSort = new T_FM_WORK_TICKET_COMPLETION();
                        completionSort.TEAM_ID = item.departmentId;
                        completionSort.TEAM_NAME = item.departmentName;
                        completionSort.FINISH_COUNT = item.doneCount;
                        completionSort.OVER_FINISH_COUNT = item.timeOverCount;
                        completionSort.TOTAL_COUNT = item.TotalCount;
                        completionSort.WAITTING_COUNT = item.TotalCount - item.doneCount - item.timeOverCount;
                        completionSorts.Add(completionSort);
                    }
                }
                foreach (var item in completionSorts)
                {
                    if (item.TOTAL_COUNT == 0)
                    {
                        item.CALC = 0;
                    }
                    else
                    {
                        var tempCalc = ((double)item.FINISH_COUNT + (double)item.OVER_FINISH_COUNT) / (double)item.TOTAL_COUNT;
                        item.CALC = tempCalc;
                    }
                }
                List<T_FM_WORK_TICKET_COMPLETION> completionSorts1 = completionSorts.OrderByDescending(t => t.CALC).Take(8).ToList();
                int i = 1;
                foreach (var item in completionSorts1)
                {
                    item.NUM = i;
                    i++;
                }
                return completionSorts1;
            });
        }

        /// <summary>
        /// 首页工作票完成数前八(车间级)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetJobShopCompletionSort")]
        public JsonActionResult<List<T_FM_WORK_TICKET_COMPLETION>> GetJobShopCompletionSort([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_FM_WORK_TICKET_COMPLETION>>(() =>
            {
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var MineType = 30;
                var departmentIds = new List<Guid>();
                List<GroupbyDepartmentId> completionLists = new List<GroupbyDepartmentId>();
                List<T_FM_WORK_TICKET_COMPLETION> completionSorts = new List<T_FM_WORK_TICKET_COMPLETION>();
                if (string.IsNullOrEmpty(filter.Keyword))
                    return completionSorts;
                var departmentInfo = this.GetEntities<T_FM_DEPARTMENT>(t => t.MineType == int.Parse(filter.Keyword.ToString()), new BaseFilter(orgId));
                if (departmentInfo == null || !departmentInfo.Any())
                    return completionSorts;
                else
                    departmentIds = departmentInfo.Select(t => t.ID).ToList();
                var completions = GetEntities<T_FM_WORK_TICKET_COMPLETION>(t => !t.IS_DELETED, new BaseFilter(orgId)).ToList();
                if (departmentIds != null && departmentIds.Any())
                {
                    completionLists = completions.Where(m => m.SHOP_DEPARTMENT_ID != null && departmentIds.Contains(m.SHOP_DEPARTMENT_ID.Value)).GroupBy(t => new { t.SHOP_DEPARTMENT_ID, t.SHOP_DEPARTMENT_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        departmentId = group.Key.SHOP_DEPARTMENT_ID,
                        departmentName = group.Key.SHOP_DEPARTMENT_NAME,
                        doneCount = group.Where(i => i.TEAM_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.ONTIME_COUNT),
                        timeOverCount = group.Where(i => i.TEAM_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.OVER_FINISH_COUNT),
                        TotalCount = group.Where(i => i.TEAM_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (completionLists != null && completionLists.Any())
                {
                    foreach (var item in completionLists)
                    {
                        T_FM_WORK_TICKET_COMPLETION completionSort = new T_FM_WORK_TICKET_COMPLETION();
                        completionSort.TEAM_ID = item.departmentId;
                        completionSort.TEAM_NAME = item.departmentName;
                        completionSort.FINISH_COUNT = item.doneCount;
                        completionSort.OVER_FINISH_COUNT = item.timeOverCount;
                        completionSort.TOTAL_COUNT = item.TotalCount;
                        completionSort.WAITTING_COUNT = item.TotalCount - item.doneCount - item.timeOverCount;
                        completionSorts.Add(completionSort);
                    }
                }
                foreach (var item in completionSorts)
                {
                    if (item.TOTAL_COUNT == 0)
                    {
                        item.CALC = 0;
                    }
                    else
                    {
                        var tempCalc = ((double)item.FINISH_COUNT + (double)item.OVER_FINISH_COUNT) / (double)item.TOTAL_COUNT;
                        item.CALC = tempCalc;
                    }
                }
                List<T_FM_WORK_TICKET_COMPLETION> completionSorts1 = completionSorts.OrderByDescending(t => t.CALC).Take(8).ToList();
                int i = 1;
                foreach (var item in completionSorts1)
                {
                    item.NUM = i;
                    i++;
                }
                return completionSorts1;
            });
        }
        /// <summary>
        /// 首页工作票完成数前八（详情页）
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetJobCompletionDetail")]
        public JsonActionResult<dynamic> GetJobCompletionDetail([FromBody] KeywordFilter filter)
        {
            return SafeExecute<dynamic>(() =>
            {
                dynamic ret = new System.Dynamic.ExpandoObject();
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var mineType = 30;
                var departmentIds = new List<Guid>();
                List<GroupbyDepartmentCompletion> completionLists = new List<GroupbyDepartmentCompletion>();
                List<T_FM_WORK_TICKET_COMPLETION> completionSorts = new List<T_FM_WORK_TICKET_COMPLETION>();
                if (string.IsNullOrEmpty(filter.Keyword))
                    return ret;
                var departmentInfo = this.GetEntities<T_FM_DEPARTMENT>(t => t.MineType == int.Parse(filter.Keyword.ToString()), new BaseFilter(orgId));
                if (departmentInfo == null || !departmentInfo.Any())
                    return ret;
                else
                    departmentIds = departmentInfo.Select(t => t.ID).ToList();
                var completions = GetEntities<T_FM_WORK_TICKET_COMPLETION>(t => !t.IS_DELETED && t.TEAM_ID != null && departmentIds.Contains(t.TEAM_ID.Value), new BaseFilter(orgId)).ToList();
                if (completions != null && completions.Any())
                {
                    completionSorts = completions.GroupBy(t => new { t.MONTH, t.MONTHStr }).Select(group => new T_FM_WORK_TICKET_COMPLETION
                    {
                        MONTH = group.Key.MONTH,
                        MONTHStr = group.Key.MONTH.Year +"-"+ group.Key.MONTH.Month,
                        FINISH_COUNT = group.Where(i => i.MONTH == group.Key.MONTH).Sum(m => m.FINISH_COUNT),
                        ONTIME_COUNT = group.Where(i => i.MONTH == group.Key.MONTH).Sum(m => m.ONTIME_COUNT),
                        TOTAL_COUNT = group.Where(i => i.MONTH == group.Key.MONTH).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                    completionLists = completions.GroupBy(t => new { t.TEAM_ID, t.TEAM_NAME, t.SHOP_DEPARTMENT_ID, t.SHOP_DEPARTMENT_NAME }).Select(group => new GroupbyDepartmentCompletion
                    {
                        shopId = group.Key.SHOP_DEPARTMENT_ID,
                        shopName = group.Key.SHOP_DEPARTMENT_NAME,
                        teamId = group.Key.TEAM_ID,
                        teamName = group.Key.TEAM_NAME,
                        teamDoneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.FINISH_COUNT),
                        teamOntimeCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.ONTIME_COUNT),
                        teamUndoneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.WAITTING_COUNT),
                        teamTotalCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (completionSorts != null && completionSorts.Any())
                {
                    foreach (var item in completionSorts)
                    {
                        if (item.TOTAL_COUNT == 0)
                        {
                            item.FINISH_RATE = 0;
                            item.NORMAL_FINISH_RATE = 0;
                        }
                        else
                        {
                            item.FINISH_RATE = Math.Round((double)item.FINISH_COUNT / (double)item.TOTAL_COUNT * 100, 2);
                            item.NORMAL_FINISH_RATE = Math.Round((double)item.ONTIME_COUNT / (double)item.TOTAL_COUNT * 100, 2);
                        }
                    }
                    ret.rateData = completionSorts.OrderBy(t => t.MONTH).ToList();
                }
                if (completionLists != null && completionLists.Any())
                {
                    foreach (var item in completionLists)
                    {
                        item.shopDoneCount = completionLists.Where(i => i.shopId == item.shopId).Sum(m => m.teamDoneCount);
                        item.shopOntimeCount = completionLists.Where(i => i.shopId == item.shopId).Sum(m => m.teamOntimeCount);
                        item.shopTotalCount = completionLists.Where(i => i.shopId == item.shopId).Sum(m => m.teamTotalCount);
                        if (item.shopTotalCount == 0)
                        {
                            item.shopDoneRate = 0;
                            item.shopOverDoneRate = 0;
                        }
                        else
                        {
                            item.shopDoneRate = Math.Round((double)item.shopDoneCount / (double)item.shopTotalCount * 100, 2);
                            item.shopOverDoneRate = Math.Round((double)item.shopOntimeCount / (double)item.shopTotalCount * 100, 2);
                        }
                        if (item.teamTotalCount == 0)
                        {
                            item.teamDoneRate = 0;
                            item.teamOverDoneRate = 0;
                        }
                        else
                        {
                            item.teamDoneRate = Math.Round((double)item.teamDoneCount / (double)item.teamTotalCount * 100, 2);
                            item.teamOverDoneRate = Math.Round((double)item.teamOntimeCount / (double)item.teamTotalCount * 100, 2);
                        }
                    }
                    ret.retData = completionLists.OrderBy(t => t.shopName).ThenByDescending(m => m.teamOverDoneRate).ToList();
                }
                return ret;
            });
        }
        /// <summary>
        /// 作业完成率前八（除班组级）
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetJobDepartmentCompletionSort")]
        public JsonActionResult<List<T_FM_DEPARTMENT_COMPLETION_SORT>> GetJobDepartmentCompletionSort([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_FM_DEPARTMENT_COMPLETION_SORT>>(() =>
            {
                var departmentType = 3;
                List<GroupbyDepartmentId> completionLists = new List<GroupbyDepartmentId>();
                List<T_FM_DEPARTMENT_COMPLETION_SORT> completionSorts = new List<T_FM_DEPARTMENT_COMPLETION_SORT>();
                if (string.IsNullOrEmpty(filter.Keyword))
                    return completionSorts;
                var departmentInfo = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == Guid.Parse(filter.Keyword.ToString()));
                if (departmentInfo == null)
                    return completionSorts;
                else
                    departmentType = departmentInfo.DEPARTMENT_TYPE;
                //BaseFilter baseFilter = new BaseFilter(filter.GetOrgId());
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var completions = GetEntities<T_FM_JOB_ACTIVITY_COMPLETION>(t => !t.IS_DELETED, new BaseFilter(orgId)).ToList();
                if (departmentType == 3)
                {
                    completionLists = completions.Where(m => m.SHOP_DEPARTMENT_ID != null).GroupBy(t => new { t.SHOP_DEPARTMENT_ID, t.SHOP_DEPARTMENT_NAME, t.FORM_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        formName = group.Key.FORM_NAME,
                        departmentId = group.Key.SHOP_DEPARTMENT_ID,
                        departmentName = group.Key.SHOP_DEPARTMENT_NAME,
                        doneCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID && i.FORM_NAME == group.Key.FORM_NAME).Sum(m => m.FINISH_COUNT),
                        TotalCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID && i.FORM_NAME == group.Key.FORM_NAME).Sum(m => m.TOTAL_COUNT),
                    }).ToList();

                }
                if (departmentType == 0)
                {
                    completionLists = completions.Where(m => m.SHOP_DEPARTMENT_ID != null && m.DEPARTMENT_ID == Guid.Parse(filter.Keyword.ToString())).GroupBy(t => new { t.SHOP_DEPARTMENT_ID, t.SHOP_DEPARTMENT_NAME, t.FORM_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        formName = group.Key.FORM_NAME,
                        departmentId = group.Key.SHOP_DEPARTMENT_ID,
                        departmentName = group.Key.SHOP_DEPARTMENT_NAME,
                        doneCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID && i.FORM_NAME == group.Key.FORM_NAME).Sum(m => m.FINISH_COUNT),
                        TotalCount = group.Where(i => i.SHOP_DEPARTMENT_ID == group.Key.SHOP_DEPARTMENT_ID && i.FORM_NAME == group.Key.FORM_NAME).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (departmentType == 1)
                {
                    completionLists = completions.Where(m => m.TEAM_ID != null && m.SHOP_DEPARTMENT_ID == Guid.Parse(filter.Keyword.ToString())).GroupBy(t => new { t.TEAM_ID, t.TEAM_NAME, t.FORM_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        formName = group.Key.FORM_NAME,
                        departmentId = group.Key.TEAM_ID,
                        departmentName = group.Key.TEAM_NAME,
                        doneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.FORM_NAME == group.Key.FORM_NAME).Sum(m => m.FINISH_COUNT),
                        TotalCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.FORM_NAME == group.Key.FORM_NAME).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (departmentType == 2)
                {
                    completionLists = completions.Where(m => m.TEAM_ID != null && m.SHOP_DEPARTMENT_ID == departmentInfo.PARENT_ID).GroupBy(t => new { t.TEAM_ID, t.TEAM_NAME, t.FORM_NAME }).Select(group => new GroupbyDepartmentId
                    {
                        formName = group.Key.FORM_NAME,
                        departmentId = group.Key.TEAM_ID,
                        departmentName = group.Key.TEAM_NAME,
                        doneCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.FORM_NAME == group.Key.FORM_NAME).Sum(m => m.FINISH_COUNT),
                        TotalCount = group.Where(i => i.TEAM_ID == group.Key.TEAM_ID && i.FORM_NAME == group.Key.FORM_NAME).Sum(m => m.TOTAL_COUNT),
                    }).ToList();
                }
                if (completionLists != null && completionLists.Any())
                {
                    var groupCompletion = completionLists.GroupBy(t => new { t.departmentId, t.departmentName }).Select(group => new T_FM_DEPARTMENT_COMPLETION_SORT
                    {
                        TEAM_ID = group.Key.departmentId,
                        TEAM_NAME = group.Key.departmentName,
                        TEAM_FINISH_COUNT = group.Where(i => i.departmentId == group.Key.departmentId && i.formName == "一般作业活动记录").Sum(m => m.doneCount),
                        TEAM_TOTAL_COUNT = group.Where(i => i.departmentId == group.Key.departmentId && i.formName == "一般作业活动记录").Sum(m => m.TotalCount),
                        POST_FINISH_COUNT = group.Where(i => i.departmentId == group.Key.departmentId && i.formName == "关键/许可作业活动记录").Sum(m => m.doneCount),
                        POST_TOTAL_COUNT = group.Where(i => i.departmentId == group.Key.departmentId && i.formName == "关键/许可作业活动记录").Sum(m => m.TotalCount),
                    }).ToList();
                    foreach (var item in groupCompletion)
                    {
                        T_FM_DEPARTMENT_COMPLETION_SORT completionSort = new T_FM_DEPARTMENT_COMPLETION_SORT();
                        completionSort.TEAM_ID = item.TEAM_ID;
                        completionSort.TEAM_NAME = item.TEAM_NAME;
                        completionSort.TEAM_FINISH_COUNT = item.TEAM_FINISH_COUNT;
                        completionSort.TEAM_TOTAL_COUNT = item.TEAM_TOTAL_COUNT;
                        completionSort.POST_FINISH_COUNT = item.POST_FINISH_COUNT;
                        completionSort.POST_TOTAL_COUNT = item.POST_TOTAL_COUNT;
                        completionSort.HANDOVER_FINISH_COUNT = 0;
                        completionSort.HANDOVER_TOTAL_COUNT = 0;
                        if (item.TEAM_TOTAL_COUNT == 0)
                        {
                            completionSort.CALC = 0;
                        }
                        else
                        {
                            var tempCalc = (double)item.TEAM_FINISH_COUNT / (double)item.TEAM_TOTAL_COUNT;
                            completionSort.CALC = tempCalc;
                        }
                        if (item.POST_TOTAL_COUNT == 0)
                        {
                            completionSort.CALC_LICENSE = 0;
                        }
                        else
                        {
                            var tempCalc = (double)item.POST_FINISH_COUNT / (double)item.POST_TOTAL_COUNT;
                            completionSort.CALC_LICENSE = tempCalc;
                        }
                        completionSorts.Add(completionSort);
                    }
                }
                List<T_FM_DEPARTMENT_COMPLETION_SORT> completionSorts1 = completionSorts.OrderByDescending(t => (t.CALC+ t.CALC_LICENSE)/2).Take(8).ToList();
                int i = 1;
                foreach (var item in completionSorts1)
                {
                    item.NUM = i;
                    i++;
                }
                return completionSorts1;
            });
        }

        /// <summary>
        /// 作业完成率前八（班组级别）
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetJobClassCompletionSort")]
        public JsonActionResult<List<T_FM_DEPARTMENT_COMPLETION_SORT>> GetJobClassCompletionSort([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_FM_DEPARTMENT_COMPLETION_SORT>>(() =>
            {
                List<GroupbyDepartmentId> completionLists = new List<GroupbyDepartmentId>();
                List<T_FM_DEPARTMENT_COMPLETION_SORT> completionSorts = new List<T_FM_DEPARTMENT_COMPLETION_SORT>();
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var completions = GetEntities<T_FM_JOB_ACTIVITY_COMPLETION>(t => !t.IS_DELETED && t.TEAM_NAME == filter.Keyword.ToString(), new BaseFilter(orgId)).ToList();
                completionLists = completions.GroupBy(t => t.FORM_NAME).Select(group => new GroupbyDepartmentId
                {
                    formName = group.Key,
                    departmentName = filter.Keyword.ToString(),
                    doneCount = group.Where(i => i.FORM_NAME == group.Key).Sum(m => m.FINISH_COUNT),
                    TotalCount = group.Where(i => i.FORM_NAME == group.Key).Sum(m => m.TOTAL_COUNT),
                }).ToList();
                if (completionLists != null && completionLists.Any())
                {
                    var groupCompletion = completionLists.GroupBy(t => t.departmentName ).Select(group => new T_FM_DEPARTMENT_COMPLETION_SORT
                    {
                        TEAM_NAME = group.Key,
                        TEAM_FINISH_COUNT = group.Where(i => i.departmentName == group.Key && i.formName == "一般作业活动记录").Sum(m => m.doneCount),
                        TEAM_TOTAL_COUNT = group.Where(i => i.departmentName == group.Key && i.formName == "一般作业活动记录").Sum(m => m.TotalCount),
                        POST_FINISH_COUNT = group.Where(i => i.departmentName == group.Key && i.formName == "关键/许可作业活动记录").Sum(m => m.doneCount),
                        POST_TOTAL_COUNT = group.Where(i => i.departmentName == group.Key && i.formName == "关键/许可作业活动记录").Sum(m => m.TotalCount),
                    }).ToList();
                    foreach (var item in groupCompletion)
                    {
                        T_FM_DEPARTMENT_COMPLETION_SORT completionSort = new T_FM_DEPARTMENT_COMPLETION_SORT();
                        completionSort.TEAM_NAME = item.TEAM_NAME;
                        completionSort.TEAM_FINISH_COUNT = item.TEAM_FINISH_COUNT;
                        completionSort.TEAM_TOTAL_COUNT = item.TEAM_TOTAL_COUNT;
                        completionSort.POST_FINISH_COUNT = item.POST_FINISH_COUNT;
                        completionSort.POST_TOTAL_COUNT = item.POST_TOTAL_COUNT;
                        completionSort.HANDOVER_FINISH_COUNT = 0;
                        completionSort.HANDOVER_TOTAL_COUNT = 0;
                        if (item.TEAM_TOTAL_COUNT == 0)
                        {
                            completionSort.CALC = 0;
                        }
                        else
                        {
                            var tempCalc = (double)item.TEAM_FINISH_COUNT / (double)item.TEAM_TOTAL_COUNT;
                            completionSort.CALC = tempCalc;
                        }
                        if (item.POST_TOTAL_COUNT == 0)
                        {
                            completionSort.CALC_LICENSE = 0;
                        }
                        else
                        {
                            var tempCalc = (double)item.POST_FINISH_COUNT / (double)item.POST_TOTAL_COUNT;
                            completionSort.CALC_LICENSE = tempCalc;
                        }
                        completionSorts.Add(completionSort);
                    }
                }
                return completionSorts;
            });
        }

        /// <summary>
        /// 各部门车间班组负责人、分管领导详情
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDepartmentInfos")]
        public JsonActionResult<dynamic> GetDepartmentInfos([FromBody] KeywordFilter filter)
        {
            return SafeExecute<dynamic>(() =>
            {
                List<DepartmentInfos> completionSorts = new List<DepartmentInfos>();
                dynamic ret = new System.Dynamic.ExpandoObject();
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var filter = new BaseFilter(orgId);
                filter.SelectField = new List<string> { "ID","NAME", "DEPARTMENT_TYPE", "Nav_User.NAME","Nav_ChargeUser.NAME"};
                var departs = this.GetEntities<T_FM_DEPARTMENT>(t => !t.IS_DELETED, filter);
                if (departs != null && departs.Any())
                {
                    foreach (var depart in departs)
                    {
                        DepartmentInfos info = new DepartmentInfos();
                        info.NAME = depart.NAME;
                        info.USER_NAME = depart.Nav_User?.NAME;
                        info.CHARGE_NAME = depart.Nav_ChargeUser?.NAME;
                        info.DEPARTMENT_TYPE = depart.DEPARTMENT_TYPE;
                        completionSorts.Add(info);
                    }
                }
                List<DepartmentInfos> completionSorts1 = completionSorts.Where(t => t.DEPARTMENT_TYPE == 3).ToList();
                var temps = completionSorts.Where(t => t.DEPARTMENT_TYPE != 3).OrderBy(m => m.DEPARTMENT_TYPE).ToList();
                completionSorts1.AddRange(temps);
                ret.retData = completionSorts1;
                List<ApproveUserInfos> approveUsers = new List<ApproveUserInfos>();
                filter.SelectField = new List<string> { "NAME", "DEPARTMENT_TYPE" };
                var approveRoles = this.GetEntities<T_PF_APPROVAL_ROLE>(t => !t.IS_DELETED, filter);
                var roleIds = approveRoles.Select(t => t.ID).ToList();
                filter.SelectField = new List<string> { "NAME", "DEPARTMENT_ID", "Nav_Department.NAME", "Nav_ApproveRole.NAME" };
                var userInfos = this.GetEntities<T_FM_USER>(t => !t.IS_DELETED && roleIds.Contains((Guid)t.APPROVE_ROLE_ID), filter);
                var departIds = departs.Select(t=>t.ID).ToList();
                if (approveRoles != null && approveRoles.Any())
                {
                    foreach (var role in approveRoles)
                    {
                        ApproveUserInfos info = new ApproveUserInfos();
                        info.APPROVE_ROLE_NAME = role.NAME;
                        info.DEPARTMENT_TYPE = role.DEPARTMENT_TYPE;
                        info.DEPARTMENT_NAME = Enum.GetName(typeof(FMDepartmentType), role.DEPARTMENT_TYPE);
                        var users = userInfos.Where(t => t.APPROVE_ROLE_ID == role.ID).ToList();
                        if (users != null && users.Any())
                        {
                            var userDepartIds = users.Select(t => t.DEPARTMENT_ID).ToList();
                            foreach (var user in users)
                            {
                                info.USER_INFO = user.Nav_Department?.NAME + "：" + user.NAME + "<br/>" + info.USER_INFO;
                            }
                            var departAnother = departs.Where(t => t.DEPARTMENT_TYPE == role.DEPARTMENT_TYPE && !userDepartIds.Contains(t.ID)).ToList();
                            if (departAnother != null && departAnother.Any())
                            {
                                foreach (var other in departAnother)
                                {
                                    info.USER_INFO = other.NAME + "：未设置当前角色" + "<br/>" + info.USER_INFO;
                                }
                            }
                        }
                        else
                        {
                            var departAnother = departs.Where(t => t.DEPARTMENT_TYPE == role.DEPARTMENT_TYPE).ToList();
                            if (departAnother != null && departAnother.Any())
                            {
                                foreach (var other in departAnother)
                                {
                                    info.USER_INFO = other.NAME + "：未设置当前角色" + "<br/>" + info.USER_INFO;
                                }
                            }
                        }
                        approveUsers.Add(info);
                    }
                }
                List<ApproveUserInfos> approveUsers1 = approveUsers.Where(t => t.DEPARTMENT_TYPE == 3).ToList();
                var tempApproves = approveUsers.Where(t => t.DEPARTMENT_TYPE != 3).OrderBy(m => m.DEPARTMENT_TYPE).ToList();
                approveUsers1.AddRange(tempApproves);
                ret.retDataApprove = approveUsers1;
                return ret;
            });
        }

        /// <summary>
        /// 排序查询所有数据
        /// </summary>
        /// <param name="filter">过滤实体</param>
        /// <returns></returns>

        [HttpPost, Route("GetEntities")]
        public JsonActionResult<List<T_BI_DEPARTMENT_MONTH_RUN>> GetEntities([FromBody] KeywordFilter filter)
        {
            return SafeExecute<List<T_BI_DEPARTMENT_MONTH_RUN>>(() =>
            {
                if (string.IsNullOrEmpty(filter.Parameter1) || string.IsNullOrEmpty(filter.Parameter2))
                {
                    throw new Exception("请先选择时间段");
                }
                if (string.IsNullOrEmpty(filter.Keyword))
                {
                    throw new Exception("请先选择部门");
                }
                DateTime startTime = Convert.ToDateTime(filter.Parameter1);
                DateTime endTime = Convert.ToDateTime(filter.Parameter2);
                var diffTime = startTime.AddMonths(12).Date;
                if (diffTime < endTime.Date)
                {
                    throw new Exception("查询时间不能超过12个月!");
                }
                //int type = 1;
                //if (dayDidd <= 31)
                //{
                //    type = 5;//最近一周(显示最近一月的，最小单位为月)
                //}
                //if (dayDidd > 31 && dayDidd<=90)
                //{
                //    type = 10;//最近三月
                //}
                //if (dayDidd > 90 && dayDidd <= 180)
                //{
                //    type = 15;//最近半年
                //}
                //if (dayDidd > 180)
                //{
                //    type = 20;//最近一年
                //}
                List<T_BI_DEPARTMENT_MONTH_RUN> completionLists = new List<T_BI_DEPARTMENT_MONTH_RUN>();
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var completions = GetEntities<T_BI_DEPARTMENT_MONTH_RUN>(t => !t.IS_DELETED && t.DEPARTMENT_NAME == filter.Keyword && t.MONTH >= startTime && t.MONTH < endTime, new BaseFilter(filter.OrgId)).OrderBy(m => m.MONTH).ToList();
                if (completions != null && completions.Any())
                {
                    foreach (var item in completions)
                    {
                        var temp = completions.Where(t => t.MONTH > item.MONTH).Sum(m => decimal.Parse(m.FINISH_RATE));
                        if (temp == 0)
                        {
                            completions.Where(t => t.MONTH > item.MONTH).ForEach(m => m.FINISH_RATE = item.FINISH_RATE);
                        }
                        var temp2 = completions.Where(t => t.MONTH > item.MONTH).Sum(m => decimal.Parse(m.NORMAL_FINISH_RATE));
                        if (temp2 == 0)
                        {
                            completions.Where(t => t.MONTH > item.MONTH).ForEach(m => m.NORMAL_FINISH_RATE = item.NORMAL_FINISH_RATE);
                        }
                    }
                }
                return completions;
            });
        }

        /// <summary>
        /// 部门完成情况、模块完成情况统计
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDepartMouldInfos")]
        public JsonActionResult<dynamic> GetDepartMouldInfos([FromBody] KeywordFilter filter)
        {
            return SafeExecute<dynamic>(() =>
            {
                //首页待办增加数量统计字段
                dynamic ret = new System.Dynamic.ExpandoObject();
                if (string.IsNullOrEmpty(filter.Parameter1) || string.IsNullOrEmpty(filter.Parameter2))
                {
                    throw new Exception("请先选择时间段");
                }
                var newFilter = new BaseFilter(filter.OrgId);
                newFilter.SelectField = new List<string> { "ID", "CODE", "NAME" };
                var formInfo = this.GetEntities<T_PF_FORM>(t => t.ENABLE_STATUS == 0, newFilter);
                DateTime startTime = Convert.ToDateTime(filter.Parameter1);
                DateTime endTime = Convert.ToDateTime(filter.Parameter2);
                var diffTime = startTime.AddMonths(11).Date;
                if (diffTime < endTime.Date)
                {
                    throw new Exception("查询时间不能超过12个月!");
                }
                var result = GetEntities<T_BI_NOTIFICATION_TASK_NEW>(s => !s.IS_DELETED && s.CREATE_DATE >= startTime && s.CREATE_DATE <= endTime, new BaseFilter(filter.OrgId)).ToList();
                var userIds = result.Select(t => t.USER_ID).Distinct().ToList();
                var userInfos = GetEntities<T_FM_USER>(s => userIds.Contains(s.ID) && s.ENABLE_STATUS == 0, newFilter);
                if (result.Any())
                {
                    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>();
                    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 companyIds = departmentInfos.Where(t => t.DEPARTMENT_TYPE == 3).Select(m => m.ID).ToList();
                    //按部门
                    var departGroupYear = result.Where(t => t.DEPT_DEPARTMENT_ID != null && !companyIds.Contains((Guid)t.DEPT_DEPARTMENT_ID)).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 = filter.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 = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 0).Count();
                            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);
                        });
                        ret.departData = departSummary;
                    }
                    //按模块
                    var mouldGroupYear = departGroupYear.Where(t => t.MOUDLE_NAME != null).ToList();
                    if (mouldGroupYear.Any())
                    {
                        //分组
                        var groupYearMould = mouldGroupYear.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 = filter.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);
                        });
                        ret.mouldData = mouldSummary;
                    }
                }
                return ret;
            });
        }
        /// <summary>
        /// 个人登录情况统计
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetLoginInfos")]
        public JsonActionResult<dynamic> GetLoginInfos([FromBody] KeywordFilter filter)
        {
            return SafeExecute<dynamic>(() =>
            {
                //表格
                List<LoginInfo> completionSorts = new List<LoginInfo>();
                dynamic ret = new System.Dynamic.ExpandoObject();
                var dt = DateTime.Now.AddMonths(-1);
                var startTime = DateTime.Parse(dt.Year.ToString() + "-" + dt.Month + "-" + dt.Day + " 00:00:00");
                var endTime = DateTime.Parse(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " 23:59:59");
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var userID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
                var newfilter = new BaseFilter(orgId);
                newfilter.SelectField = new List<string> { "ID", "USER_ID", "DEPARTMENT_ID", "FROM", "VERSION", "CREATE_TIME" };
                if (!string.IsNullOrEmpty(filter.Keyword))
                {
                    userID = this.GetEntity<T_FM_USER>(t => !t.IS_DELETED && t.ENABLE_STATUS == 0 && t.NAME == filter.Keyword).ID;
                }
                var loginInfos = this.GetEntities<T_BI_LOGIN_RECORD>(t => !t.IS_DELETED && t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.USER_ID == userID, newfilter);
                //表格
                var loginInfoTable = loginInfos.OrderByDescending(m => m.CREATE_TIME).Take(30);
                if (loginInfoTable != null && loginInfoTable.Any())
                {
                    foreach (var depart in loginInfoTable)
                    {
                        LoginInfo info = new LoginInfo();
                        info.CREATE_TIME = depart?.CREATE_TIME;
                        info.FROM = depart.FROM;
                        info.VERSION = depart.VERSION;
                        completionSorts.Add(info);
                    }
                }
                ret.retDetailData = completionSorts;
                //走势图(近一个月)
                List<LoginInfo> completionSorts1 = new List<LoginInfo>();
                for (DateTime date = startTime; date <= DateTime.Now; date = date.AddDays(1))
                {
                    var dayEnd = DateTime.Parse(date.Year.ToString() + "-" + date.Month + "-" + date.Day + " 23:59:59");
                    var ksJantask = loginInfos.Where(t => t.CREATE_TIME >= date && t.CREATE_TIME <= dayEnd).ToList();
                    if (ksJantask.Any())
                    {
                        LoginInfo run = new LoginInfo();
                        run.CREATE_TIME = date;
                        run.QTY = ksJantask.Count();
                        completionSorts1.Add(run);
                    }
                    else
                    {
                        LoginInfo run = new LoginInfo();
                        run.CREATE_TIME = date;
                        run.QTY = 0;
                        completionSorts1.Add(run);
                    }
                }
                ret.retChartData = completionSorts1;
                //饼图(近一个月)
                ret.groupData = loginInfos.GroupBy(t => t.FROM).Select(m => new LoginInfo
                {
                    FROM = m.Key,
                    QTY = m.Where(p => p.FROM == m.Key).Count(),
                }).ToList();
                return ret;
            });
        }

        /// <summary>
        /// 组织完成情况统计
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDepartmentAnalysis")]
        public JsonActionResult<dynamic> GetDepartmentAnalysis([FromBody] KeywordFilter filter)
        {
            return SafeExecute<dynamic>(() =>
            {
                //表格
                dynamic ret = new System.Dynamic.ExpandoObject();
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                T_FM_DEPARTMENT departInfo = null;
                Expression<Func<T_BI_NOTIFICATION_TASK_NEW, bool>> express = t => !t.IS_DELETED && (t.NOTICE_STATUS == 0 || t.NOTICE_STATUS == 1 || t.NOTICE_STATUS == 2);
                if (string.IsNullOrEmpty(filter.Keyword))
                {
                    //未选中组织，默认全公司
                }
                else
                {
                    departInfo = this.GetEntity<T_FM_DEPARTMENT>(filter.Keyword);
                    if (departInfo != null && departInfo.IS_DELETED == false)
                    {
                        //部门
                        if (departInfo.DEPARTMENT_TYPE == 0)
                        {
                            express = express.And(t => t.DEPT_DEPARTMENT_ID == departInfo.ID);
                        }
                        else if (departInfo.DEPARTMENT_TYPE == 1)
                        {
                            express = express.And(t => t.SHOP_DEPARTMENT_ID == departInfo.ID);
                        }
                        else if (departInfo.DEPARTMENT_TYPE == 2)
                        {
                            express = express.And(t => t.CLASS_DEPARTMENT_ID == departInfo.ID);
                        }
                    }
                }
                var dt = DateTime.Parse(DateTime.Now.Year + "-01-01 00:00:00");
                if (string.IsNullOrEmpty(filter.Parameter1))
                {
                    //未选择年份，默认当前年度
                }
                else
                {
                    dt = DateTime.Parse(filter.Parameter1 + "-01-01 00:00:00");
                }
                express = express.And(t => t.CREATE_DATE.Value.Year == dt.Year);
                var result = this.GetEntities<T_BI_NOTIFICATION_TASK_NEW>(express, filter);
                if (result != null && result.Any())
                {
                    //总数
                    ret.TotalCount = result.Count();
                    //未完成数
                    var UnfinishCount = result.Count(t => t.NOTICE_STATUS == 0);
                    ret.UnfinishCount = UnfinishCount;
                    //超时完成数
                    var OverfinishCount = result.Count(t => t.NOTICE_STATUS == 2);
                    //及时完成数
                    var FinishCount = result.Count(t => t.NOTICE_STATUS == 1);
                    //总完成数
                    ret.finishCount = FinishCount + OverfinishCount;
                    //完成率
                    ret.FinishRate = ret.TotalCount == 0 ? 0 : (double)ret.finishCount / ret.TotalCount * 100;
                    //及时完成率
                    ret.NormalFinishRate = ret.TotalCount == 0 ? 0 : (double)FinishCount / ret.TotalCount * 100;
                    //未完成弹窗
                    ret.UnfinishData = result.Where(t => t.NOTICE_STATUS == 0).ToList();
                    //走势图(近一个月)
                    List<GroupbyDepartmentCompletion> completionSorts = new List<GroupbyDepartmentCompletion>();
                    var dtEnd = dt.AddYears(1);
                    for (DateTime date = dt; date < dtEnd; date = date.AddMonths(1))
                    {
                        var dayEnd = date.AddMonths(1);
                        var taskTotal = result.Where(t => t.CREATE_DATE >= date && t.CREATE_DATE < dayEnd).ToList();
                        var taskFinish = taskTotal.Count(t => t.NOTICE_STATUS == 1 || t.NOTICE_STATUS == 2);
                        var normalFinish = taskTotal.Count(t => t.NOTICE_STATUS == 1);
                        if (taskTotal.Any())
                        {
                            GroupbyDepartmentCompletion run = new GroupbyDepartmentCompletion();
                            run.month = date.Year.ToString() + "-" + date.Month.ToString();
                            run.teamDoneRate = taskTotal.Count() == 0 ? 0 : (double)taskFinish / taskTotal.Count() * 100;
                            run.teamOverDoneRate = taskTotal.Count() == 0 ? 0 : (double)normalFinish / taskTotal.Count() * 100;
                            completionSorts.Add(run);
                        }
                        else
                        {
                            GroupbyDepartmentCompletion run = new GroupbyDepartmentCompletion();
                            run.month = date.Year.ToString() + "-" + date.Month.ToString();
                            run.teamDoneRate = 0;
                            run.teamOverDoneRate = 0;
                            completionSorts.Add(run);
                        }
                    }
                    ret.LineChart = completionSorts;
                    //按人分组
                    var groupTask = result.GroupBy(t => t.USER_NAME).Select(m => new GroupbyDepartmentCompletion
                    {
                        name = m.Key,
                        teamDoneRate = m.Count(p => p.USER_NAME == m.Key) == 0 ? 0 : m.Count(p => p.USER_NAME == m.Key && (p.NOTICE_STATUS == 1 || p.NOTICE_STATUS == 2)) / m.Count(p => p.USER_NAME == m.Key) * 100,
                        teamOverDoneRate = m.Count(p => p.USER_NAME == m.Key) == 0 ? 0 : m.Count(p => p.USER_NAME == m.Key && (p.NOTICE_STATUS == 1)) / m.Count(p => p.USER_NAME == m.Key) * 100
                    }).ToList();
                    if (groupTask.Count > 20)
                    {
                        //柱状图(前八)
                        ret.BarAsc = groupTask.OrderByDescending(t => t.teamOverDoneRate).Take(8).ToList();
                        //柱状图(后八)
                        ret.BarDesc = groupTask.OrderBy(t => t.teamOverDoneRate).Take(8).ToList();
                    }
                    else
                    {
                        ret.BarAsc = groupTask.OrderByDescending(t => t.teamOverDoneRate).ToList();
                    }
                    ret.UserCount = groupTask.Count;
                }
                else
                {
                    ret.TotalCount = 0;
                    ret.UnfinishCount = 0;
                    ret.FinishRate = 0;
                    ret.NormalFinishRate = 0;
                    ret.LineChart = new List<GroupbyDepartmentCompletion>();
                    ret.BarAsc = new List<GroupbyDepartmentCompletion>();
                    ret.BarDesc = new List<GroupbyDepartmentCompletion>();
                    ret.UserCount = 0;
                }
                return ret;
            });
        }

        /// <summary>
        /// 组织部门树
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDepartmentEntities")]
        public JsonActionResult<DepartmentInfo> GetDepartmentEntities([FromBody] KeywordFilter filter)
        {
            return SafeExecute<DepartmentInfo>(() =>
            {
                //表格
                DepartmentInfo ret = new DepartmentInfo();
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value;
                var departInfos = this.GetEntities<T_FM_DEPARTMENT>(t => !t.IS_DELETED, new BaseFilter(orgId));
                var company = departInfos.FirstOrDefault(t => t.DEPARTMENT_TYPE == 3);
                if (company != null)
                {
                    //公司
                    ret.departmentId = company.ID;
                    ret.departmentName = company.NAME;
                    ret.parent_departmentId = null;
                    ret.departmentType = company.DEPARTMENT_TYPE;
                    ret.num = company.NUM;
                    //部门
                    var deptInfos = departInfos.Where(t => t.PARENT_ID == company.ID).OrderBy(m => m.NUM).ToList();
                    if (deptInfos != null && deptInfos.Any())
                    {
                        List<DepartmentInfo> deptLists = new List<DepartmentInfo>();
                        foreach (var dept in deptInfos)
                        {
                            DepartmentInfo deptList = new DepartmentInfo();
                            deptList.departmentId = dept.ID;
                            deptList.departmentName = dept.NAME;
                            deptList.parent_departmentId = company.ID;
                            deptList.departmentType = dept.DEPARTMENT_TYPE;
                            deptList.num = dept.NUM;
                            //车间
                            var shopInfos = departInfos.Where(t => t.PARENT_ID == dept.ID).OrderBy(m => m.NUM).ToList();
                            if (shopInfos != null && shopInfos.Any())
                            {
                                List<DepartmentInfo> shopLists = new List<DepartmentInfo>();
                                foreach (var shop in shopInfos)
                                {
                                    DepartmentInfo shopList = new DepartmentInfo();
                                    shopList.departmentId = shop.ID;
                                    shopList.departmentName = shop.NAME;
                                    shopList.parent_departmentId = dept.ID;
                                    shopList.departmentType = shop.DEPARTMENT_TYPE;
                                    shopList.num = shop.NUM;
                                    //班组
                                    var classInfos = departInfos.Where(t => t.PARENT_ID == shop.ID).OrderBy(m => m.NUM).ToList();
                                    if (classInfos != null && classInfos.Any())
                                    {
                                        List<DepartmentInfo> classLists = new List<DepartmentInfo>();
                                        foreach (var item in classInfos)
                                        {
                                            DepartmentInfo classList = new DepartmentInfo();
                                            classList.departmentId = item.ID;
                                            classList.departmentName = item.NAME;
                                            classList.parent_departmentId = shop.ID;
                                            classList.departmentType = item.DEPARTMENT_TYPE;
                                            classList.num = item.NUM;
                                            classLists.Add(classList);
                                        }
                                        shopList.deptInfos = classLists;
                                    }
                                    shopLists.Add(shopList);
                                }
                                deptList.deptInfos = shopLists;
                            }
                            deptLists.Add(deptList);
                        }
                        ret.deptInfos = deptLists;
                    }
                }
                return ret;
            });
        }
    }
}
