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.Infrastructure.Core;
using APT.MS.Domain.Entities.BS;
using APT.MS.Domain.Entities.CM;
using APT.MS.Domain.Entities.HM;
using APT.MS.Domain.Entities.PF;
using APT.MS.Domain.Entities.SC;
using APT.MS.Domain.Enums;
using APT.Utility;
using APT.WebApi.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;

namespace APT.PP.WebApi.Controllers.Api.PP
{
    [Route("api/PP/CM")]
    [TypeFilter(typeof(CustomActionFilterAttribute))]
    public partial class CMController : AuthorizeApiController<T_CM_DRILL_PLAN>
    {

        IFMNotificationTaskService NotificationTaskService { get; set; }
        IFMUserService UserService { get; set; }
        IFMSyncLogDetailService SyncLogDetailService { get; set; }
        //IBSSafeCheckService SafeCheckService { get; set; }, IBSSafeCheckService safeCheckService
        IPFSysLogService SysLogService { get; set; }
        public CMController(IFMNotificationTaskService notificationTaskService, IPFSysLogService sysLogService, IFMUserService userService, IFMSyncLogDetailService syncLogDetailService)
        {
            NotificationTaskService = notificationTaskService;
            SysLogService = sysLogService;
            UserService = userService;
            SyncLogDetailService = syncLogDetailService;
        }

        /// <summary>
        /// 应急管理 每天触发一次
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("DailyRun")]
        public JsonActionResult<bool> DailyRun([FromBody] KeywordFilter filter)
        {
            //自动触发日期配置 新增 接收部门 接收岗位(部门岗位搜索的任意一人)
            //                                       如果没有配置 取【安环部负责人】（即保留原来的做法）    
            return SafeExecute<bool>(() =>
            {
                DateTime dtNow = DateTime.Now;
                if (!string.IsNullOrEmpty(filter.Parameter1))
                {
                    try
                    {
                        dtNow = Convert.ToDateTime(filter.Parameter1);
                    }
                    catch
                    {
                        dtNow = DateTime.Now;
                    }
                }
                string Parameter1 = filter.Parameter1;
                var configDate = GetEntity<T_CM_CONFIG>(e => e.ORG_ID == filter.OrgId);
                if (configDate == null)
                {
                    configDate = new T_CM_CONFIG();
                    configDate.ID = Guid.NewGuid();
                    configDate.ORG_ID = filter.OrgId;
                }

                bool isUrgentEventTrigger = false;
                #region  潜在紧急事件清单   3月1日

                if (!configDate.URGENT_EVENT_TRIGGER_TIME.HasValue)
                    configDate.URGENT_EVENT_TRIGGER_TIME = Convert.ToDateTime(dtNow.Year + "-03-01");
                if (configDate.URGENT_EVENT_TRIGGER_TIME.Value.ToString("MM-dd") == dtNow.ToString("MM-dd"))
                    isUrgentEventTrigger = true;

                #endregion

                //是否触发 应急装备需求调查
                //1）频率为每年，每年3月1日定期触发待办事项给部门安全员，截止时间3月15日确定。开始时间和截止时间在系统设置中可配置
                bool isDemandSurvey = false;
                bool isDemandSurveyEnd = false;

                #region 是否触发 应急装备需求调查
                if (!configDate.DEMAND_SURVEY_START_TIME.HasValue)
                    configDate.DEMAND_SURVEY_START_TIME = Convert.ToDateTime(DateTime.Now.Year + "-03-01");
                if (!configDate.DEMAND_SURVEY_END_TIME.HasValue)
                    configDate.DEMAND_SURVEY_END_TIME = Convert.ToDateTime(DateTime.Now.Year + "-03-15");
                if (configDate.DEMAND_SURVEY_START_TIME.Value.ToString("MM-dd") == dtNow.ToString("MM-dd"))
                    isDemandSurvey = true;

                DateTime dtE = Convert.ToDateTime(dtNow.Year + "-" + configDate.DEMAND_SURVEY_END_TIME.Value.ToString("MM-dd HH:mm:ss"));
                if (dtE >= dtNow)
                    isDemandSurveyEnd = true;

                #endregion

                //DRILL_PLAN_TRIGGER_TIME 年度应急演练计划触发时间
                bool isDrillPlan = false;

                #region 年度应急演练计划触发时间

                if (!configDate.DRILL_PLAN_TRIGGER_TIME.HasValue)
                    configDate.DRILL_PLAN_TRIGGER_TIME = Convert.ToDateTime(DateTime.Now.Year + "-01-01");
                if (configDate.DRILL_PLAN_TRIGGER_TIME.Value.ToString("MM-dd") == dtNow.ToString("MM-dd"))
                    isDrillPlan = true;

                #endregion

                if ((!isUrgentEventTrigger && !isDrillPlan && !isDemandSurvey && !isDemandSurveyEnd)
                || configDate.LASTRUNDATE.Date == dtNow.Date)
                {
                    //当前日期未设置值 或者 与设置日期 不一致 或者 今天已经跑过
                    return true;
                }

                string Msg = string.Empty;
                T_FM_USER userSafeMaster = null;//安环部负责人

                //T_CM_URGENT_EVENT ModelEvent = null;//潜在紧急事件清单触发日期
                T_FM_NOTIFICATION_TASK TaskEvent = null;//潜在紧急事件清单触发日期

                #region 潜在紧急事件清单
                if (isUrgentEventTrigger)
                {
                    if (userSafeMaster == null)
                    {
                        if (configDate.DEPARTMENT_ID.HasValue && configDate.POST_ID.HasValue && configDate.DEPARTMENT_ID.Value != Guid.Empty && configDate.POST_ID.Value != Guid.Empty)
                        {
                            var listUser = UserService.GetDepPostUser(ref Msg, configDate.DEPARTMENT_ID.Value, configDate.POST_ID.Value, true);
                            if (listUser != null && listUser.Any())
                                userSafeMaster = listUser[0];
                        }
                        else
                            userSafeMaster = UserService.GetRoleUser(ref Msg, "安环部负责人", null, null);
                    }

                    if (userSafeMaster == null)
                    {
                        SysLogService.AddLog(filter.OrgId.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, "系统缺少【安环部负责人】", Msg + "  体检计划接口【PP/CM/DailyRun】");
                    }
                    else
                    {
                        //潜在紧急事件清单触发日期
                        //每年3月1日触发给安环部负责人 发送待办
                        // 暂不-- 今日提醒消息类型：召开会议，消息内容：请召开潜在紧急事件讨论会

                        TaskEvent = NotificationTaskService.InsertUserNoticeTaskModel("潜在紧急事件", Guid.Empty, filter.OrgId, userSafeMaster.ID, userSafeMaster.NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "CM018");
                    }
                }
                #endregion

                #region     应急装备需求调查 isDemandSurvey

                List<T_CM_EQUIPMENT_DEMAND_SURVEY> listDemandSurvey = null;
                List<T_FM_NOTIFICATION_TASK> listTaskDemandSurvey = null;
                if (isDemandSurvey)
                {
                    var listDemandSurveyCheck = GetEntities<T_CM_EQUIPMENT_DEMAND_SURVEY>(e => e.YEAR == dtNow.Year && !e.IS_DELETED, null, null);
                    //var listDemandSurveyCheck = GetEntities<T_CM_EQUIPMENT_DEMAND_SURVEY>(e => e.YEAR == dtNow.Year && e.CREATE_TIME.HasValue && e.CREATE_TIME.Value.Date == dtNow.Date && !e.IS_DELETED, null, null);//不按每年走（可能有问题）
                    if (listDemandSurveyCheck == null || !listDemandSurveyCheck.Any())
                    {
                        //给所有部门级 安全员 发送【应急装备需求调查】待办
                        var approveRole = GetEntity<T_PF_APPROVAL_ROLE>(e => e.NAME.Contains("部门安全员"));
                        if (approveRole != null)
                        {
                            List<T_FM_USER> listUserSafe = new List<T_FM_USER>();
                            List<Guid> listDepID = new List<Guid>();
                            var listDepSafe = GetEntities<T_FM_USER>(e => e.APPROVE_ROLE_ID.HasValue && e.APPROVE_ROLE_ID == approveRole.ID && !e.IS_DELETED, null, "Nav_Department");
                            if (listDepSafe != null && listDepSafe.Any())
                            {

                                foreach (var item in listDepSafe)
                                {
                                    //部门=0,  车间=1,   班组=2,  公司=3
                                    if (item.Nav_Department.DEPARTMENT_TYPE == 0)
                                    {
                                        if (item.DEPARTMENT_ID.HasValue && !listDepID.Contains(item.DEPARTMENT_ID.Value))
                                        {
                                            listDepID.Add(item.DEPARTMENT_ID.Value);
                                            listUserSafe.Add(item);
                                        }
                                    }
                                }

                                List<Guid> DataId = new List<Guid>();
                                List<Guid> UserId = new List<Guid>();
                                List<string> userName = new List<string>();
                                List<string> Title = new List<string>();
                                listDemandSurvey = new List<T_CM_EQUIPMENT_DEMAND_SURVEY>();
                                DateTime dtStart = Convert.ToDateTime(dtNow.Year + configDate.DEMAND_SURVEY_START_TIME.Value.ToString("-MM-dd 00:00:00"));
                                DateTime dtEnd = Convert.ToDateTime(dtNow.Year + configDate.DEMAND_SURVEY_END_TIME.Value.ToString("-MM-dd 23:59:59"));
                                T_CM_EQUIPMENT_DEMAND_SURVEY modelAdd = null;
                                foreach (var item in listUserSafe)
                                {
                                    modelAdd = new T_CM_EQUIPMENT_DEMAND_SURVEY()
                                    {
                                        ID = Guid.NewGuid(),
                                        START_TIME = dtStart,
                                        END_TIME = dtEnd,
                                        DEPARTMENT_ID = item.DEPARTMENT_ID,
                                        USER_ID = item.ID,
                                        YEAR = dtNow.Year,
                                        STATUS = PFStandardStatus.Draft,
                                        IS_DELETED = false,
                                        ORG_ID = item.ORG_ID,
                                        //ENTITY_ORG_TPYE = ,
                                        //FORM_ID = ,
                                        //FLOW_STATUS = ,
                                        //FLOW_SEND_STATUS = ,
                                        //FLOW_ID = ,
                                        CREATE_TIME = dtNow,
                                        MODIFY_TIME = dtNow,
                                        //CREATER_ID = ,
                                        //MODIFIER_ID = ,
                                    };
                                    listDemandSurvey.Add(modelAdd);
                                    DataId.Add(modelAdd.ID);
                                    UserId.Add(item.ID);
                                    userName.Add(item.NAME);
                                    Title.Add("应急装备需求调查");
                                }
                                listTaskDemandSurvey = NotificationTaskService.InsertUserNoticeTaskModels(Title, DataId, filter.OrgId.Value, UserId, userName, dtStart, dtEnd, 1, "CM030");
                            }
                        }
                    }
                }

                #endregion

                #region    截至时间 应急装备需求评估表到安环部负责人
                T_CM_EQUIPMENT_DEMAND_SURVEY_MASTER modelSurveyMaster = null;
                List<T_CM_EQUIPMENT_DEMAND_SURVEY_DETAIL> listSurveyDetail = null;
                T_FM_NOTIFICATION_TASK taskSurveyMaster = null;
                List<T_FM_NOTIFICATION_TASK> listTask = null;
                if (isDemandSurveyEnd)
                {
                    var SurveyMaster = GetEntity<T_CM_EQUIPMENT_DEMAND_SURVEY_MASTER>(e => e.YEAR == dtNow.Year && !e.IS_DELETED);
                    if (SurveyMaster == null)
                    {
                        //if (userSafeMaster == null)
                        //    userSafeMaster = UserService.GetRoleUser(ref Msg, "安环部负责人", null, null);
                        if (userSafeMaster == null)
                        {
                            if (configDate.DEPARTMENT_ID.HasValue && configDate.POST_ID.HasValue && configDate.DEPARTMENT_ID.Value != Guid.Empty && configDate.POST_ID.Value != Guid.Empty)
                            {
                                var listUser = UserService.GetDepPostUser(ref Msg, configDate.DEPARTMENT_ID.Value, configDate.POST_ID.Value, true);
                                if (listUser != null && listUser.Any())
                                    userSafeMaster = listUser[0];
                            }
                            else
                                userSafeMaster = UserService.GetRoleUser(ref Msg, "安环部负责人", null, null);
                        }

                        if (userSafeMaster != null)
                        {
                            modelSurveyMaster = new T_CM_EQUIPMENT_DEMAND_SURVEY_MASTER();
                            modelSurveyMaster.ID = Guid.NewGuid();
                            modelSurveyMaster.START_TIME = dtNow;
                            modelSurveyMaster.END_TIME = dtNow.AddDays(1);
                            modelSurveyMaster.USER_ID = userSafeMaster.ID;
                            modelSurveyMaster.YEAR = dtNow.Year;
                            modelSurveyMaster.STATUS = PFStandardStatus.Draft;
                            modelSurveyMaster.IS_DELETED = false;
                            modelSurveyMaster.ORG_ID = filter.OrgId;
                            //modelSurveyMaster.ENTITY_ORG_TPYE = ;
                            //modelSurveyMaster.FORM_ID = ;
                            //modelSurveyMaster.FLOW_STATUS = ;
                            //modelSurveyMaster.FLOW_SEND_STATUS = ;
                            //modelSurveyMaster.FLOW_ID = ;
                            modelSurveyMaster.CREATE_TIME = dtNow;
                            modelSurveyMaster.MODIFY_TIME = dtNow;
                            //modelSurveyMaster.CREATER_ID = ;
                            //modelSurveyMaster.MODIFIER_ID = ;

                            var listSurvey = GetEntities<T_CM_EQUIPMENT_DEMAND_SURVEY>(e => e.YEAR == dtNow.Year && e.STATUS == PFStandardStatus.Sign && !e.IS_DELETED, null, "Nav_ListDetail");
                            if (listSurvey != null && listSurvey.Any())
                            {
                                listSurveyDetail = new List<T_CM_EQUIPMENT_DEMAND_SURVEY_DETAIL>();
                                foreach (var item in listSurvey)
                                {
                                    listSurveyDetail.AddRange(item.Nav_ListDetail);
                                }
                                foreach (var item in listSurveyDetail)
                                {
                                    item.SURVEY_MASTER_ID = modelSurveyMaster.ID;
                                }
                            }

                            taskSurveyMaster = NotificationTaskService.InsertUserNoticeTaskModel("应急装备需求评估", modelSurveyMaster.ID, modelSurveyMaster.ORG_ID, modelSurveyMaster.USER_ID.Value, userSafeMaster.NAME, dtNow, dtNow.AddDays(1), 0, "CM032");


                            //应急装备需求调查表 没填的  未办 无需处理
                            var taskEnd = GetEntities<T_FM_NOTIFICATION_TASK>(e => e.NOTICE_STATUS == 0 && e.SOURCE_FORMCODE == "CM030", null, null);
                            if (taskEnd != null && taskEnd.Any())
                            {
                                listTask = new List<T_FM_NOTIFICATION_TASK>();
                                foreach (var item in taskEnd)
                                {
                                    item.NOTICE_STATUS = (int)FMNoticeStatusEnum.超时无需办理;
                                    listTask.Add(item);
                                }
                            }
                        }
                    }
                }

                #endregion

                #region     年度应急演练计划触发时间

                T_CM_DRILL_PLAN modelDrillPlan = null;
                T_FM_NOTIFICATION_TASK taskPlan = null;
                if (isDrillPlan)
                {
                    //if (userSafeMaster == null)
                    //    userSafeMaster = UserService.GetRoleUser(ref Msg, "安环部负责人", null, null);
                    if (userSafeMaster == null)
                    {
                        if (configDate.DEPARTMENT_ID.HasValue && configDate.POST_ID.HasValue && configDate.DEPARTMENT_ID.Value != Guid.Empty && configDate.POST_ID.Value != Guid.Empty)
                        {
                            var listUser = UserService.GetDepPostUser(ref Msg, configDate.DEPARTMENT_ID.Value, configDate.POST_ID.Value, true);
                            if (listUser != null && listUser.Any())
                                userSafeMaster = listUser[0];
                        }
                        else
                            userSafeMaster = UserService.GetRoleUser(ref Msg, "安环部负责人", null, null);
                    }
                    if (userSafeMaster != null)
                    {
                        var planCheck = GetEntity<T_CM_DRILL_PLAN>(e => e.YEAR == dtNow.Year && !e.IS_DELETED);
                        if (planCheck == null)
                        {
                            modelDrillPlan = new T_CM_DRILL_PLAN();
                            modelDrillPlan.ID = Guid.NewGuid();
                            modelDrillPlan.YEAR = dtNow.Year;
                            modelDrillPlan.DEPARTMENT_ID = userSafeMaster.DEPARTMENT_ID;
                            modelDrillPlan.STATUS = PFStandardStatus.Draft;
                            //modelDrillPlan.APPROVE_ID =;
                            modelDrillPlan.IS_DELETED = false;
                            modelDrillPlan.ORG_ID = userSafeMaster.ORG_ID;
                            //modelDrillPlan.ENTITY_ORG_TPYE =;
                            //modelDrillPlan.FORM_ID =;
                            //modelDrillPlan.FLOW_STATUS =;
                            //modelDrillPlan.FLOW_SEND_STATUS =;
                            //modelDrillPlan.FLOW_ID =;
                            modelDrillPlan.CREATE_TIME = dtNow;
                            modelDrillPlan.MODIFY_TIME = dtNow;
                            //modelDrillPlan.CREATER_ID =;
                            //modelDrillPlan.MODIFIER_ID =;

                            taskPlan = NotificationTaskService.InsertUserNoticeTaskModel("年度应急演练计划表", modelDrillPlan.ID, modelDrillPlan.ORG_ID, userSafeMaster.ID, userSafeMaster.NAME, dtNow, dtNow.AddDays(1), 1, "CM002");

                        }
                    }
                }
                #endregion

                #region      跑批信息修改

                T_FM_SYNC_TASK task = null;
                task = GetEntity<T_FM_SYNC_TASK>(filter.Keyword);
                if (task != null)
                {
                    task.UPDATE_SUCCES_TIME = DateTime.Now;//上次同步结束时间
                    task.SYNC_PARAM = "";//清空参数
                }

                #endregion

                //if (listSurveyDetail != null && listSurveyDetail.Any())
                //{
                //    foreach (var item in listSurveyDetail)
                //    {
                //        item.Nav_EQDSurvey = null;
                //    }
                //}
                configDate.LASTRUNDATE = DateTime.Now.Date;
                this.UnifiedCommit(() =>
                {
                    if (task != null)
                        UpdateEntityNoCommit(task);//跑批信息
                    if (configDate != null)
                        UpdateEntityNoCommit(configDate);//配置信息
                    //if (ModelEvent != null)
                    //    UpdateEntityNoCommit(ModelEvent);//潜在紧急事件清单
                    if (TaskEvent != null)
                        UpdateEntityNoCommit(TaskEvent);//潜在紧急事件清单  直接添加 表单


                    if (listDemandSurvey != null && listDemandSurvey.Any())
                        BantchAddEntityNoCommit(listDemandSurvey);//应急装备需求调查
                    if (listTaskDemandSurvey != null && listTaskDemandSurvey.Any())
                        BantchAddEntityNoCommit(listTaskDemandSurvey);//应急装备需求调查  待办

                    if (taskSurveyMaster != null)//应急装备需求评估表 待办
                        UpdateEntityNoCommit(taskSurveyMaster);
                    if (listTask != null && listTask.Any())
                        BantchSaveEntityNoCommit(listTask);//应急装备需求调查表 自动结束

                    if (modelSurveyMaster != null)//应急装备需求评估表
                        UpdateEntityNoCommit(modelSurveyMaster);
                    if (listSurveyDetail != null && listSurveyDetail.Any())
                        BantchSaveEntityNoCommit(listSurveyDetail);//应急装备需求评估表

                    if (taskPlan != null)//年度应急演练计划表
                        UpdateEntityNoCommit(taskPlan);
                    if (modelDrillPlan != null)//年度应急演练计划表
                        UpdateEntityNoCommit(modelDrillPlan);
                });
                int Count = ((listDemandSurvey != null && listDemandSurvey.Any()) ? listDemandSurvey.Count : 0) + ((listTaskDemandSurvey != null && listTaskDemandSurvey.Any()) ? listTaskDemandSurvey.Count : 0) + ((listTask != null && listTask.Any()) ? listTask.Count : 0) + ((listSurveyDetail != null && listSurveyDetail.Any()) ? listSurveyDetail.Count : 0);
                SyncLogDetailService.InsertSyncLogDetail(HttpContext.Items, HttpContext.TraceIdentifier, filter.OrgId, Count, Parameter1, SyncLogType.BSCreateCheckPlanSet);
                return true;
            });
        }


        /// <summary>
        /// 年度应急演练计划表  演练方案触发时间 触发
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("DrillPlanDetailWarm")]
        public JsonActionResult<bool> DrillPlanDetailWarm([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                DateTime dtNow = DateTime.Now;
                if (!string.IsNullOrEmpty(filter.Parameter1))
                {
                    try
                    {
                        dtNow = Convert.ToDateTime(filter.Parameter1);
                    }
                    catch
                    {
                        dtNow = DateTime.Now;
                    }
                }

                #region      跑批信息修改

                T_FM_SYNC_TASK task = null;
                task = GetEntity<T_FM_SYNC_TASK>(filter.Keyword);
                if (task != null)
                {
                    //if (task.UPDATE_SUCCES_TIME.HasValue && task.UPDATE_SUCCES_TIME.Value.Date == dtNow.Date)
                    //{
                    //    //今天执行过了
                    //    return true;
                    //}

                    task.UPDATE_SUCCES_TIME = dtNow;//上次同步结束时间
                    task.SYNC_PARAM = "";//清空参数
                }

                #endregion

                var listPlanDetailID = GetEntities<T_CM_DRILL_RECORD>(e => e.CREATE_TIME.Value.Day == dtNow.Day && e.CREACTTYPE == CREACTTYPEEnum.System, null, null).Select(e => e.PLAN_DETAIL_ID);
                Expression<Func<T_CM_DRILL_PLAN_DETAIL, bool>> expression = e => !e.IS_DELETED && e.TRIGGER_TIME.HasValue && e.TRIGGER_TIME.Value.Date == dtNow.Date;

                if (listPlanDetailID != null && listPlanDetailID.Any())
                {
                    expression = expression.And(e => !listPlanDetailID.Contains(e.ID));
                }
                var planDetail = GetEntities(expression, null, null);

                if (planDetail != null && planDetail.Any())
                {
                    string title = string.Empty;
                    List<Guid> listDetailID = planDetail.Select(e => e.ID).ToList();
                    var detail = GetEntities<T_CM_DRILL_PLAN_DETAIL>(e => listDetailID.Contains(e.ID) && !e.Nav_PLAN.IS_DELETED && e.Nav_PLAN.STATUS == PFStandardStatus.Archived && e.Nav_PLAN.YEAR == dtNow.Year, null, "Nav_PLAN", "Nav_User");
                    List<T_FM_NOTIFICATION_TASK> listTaskRead = null;
                    List<T_CM_DRILL_RECORD> listDrillRecord = null;
                    T_CM_DRILL_RECORD modelT = null;
                    if (detail != null && detail.Any())
                    {
                        listTaskRead = new List<T_FM_NOTIFICATION_TASK>();
                        listDrillRecord = new List<T_CM_DRILL_RECORD>();
                        int i = 0;
                        foreach (var item in detail)
                        {
                            listTaskRead.Add(NotificationTaskService.InsertUserNoticeTaskModel("请编制应急演练方案并召开应急演练方案讨论会", Guid.Empty, item.ORG_ID, item.USER_ID.Value, item.Nav_User.NAME, dtNow, dtNow.AddDays(1), 2, ""));
                            i++;
                            //应急演练活动记录表
                            modelT = new T_CM_DRILL_RECORD();
                            modelT.ID = Guid.NewGuid();
                            modelT.ORG_ID = item.ORG_ID;
                            modelT.CREATER_ID = item.USER_ID;
                            modelT.PLAN_DETAIL_ID = item.ID;
                            modelT.NAME_ID = item.NAME_ID;
                            modelT.CODE = "YJ" + dtNow.ToString("yyyyMMddHHmm") + i.ToString();
                            modelT.STATUS = PFStandardStatus.Draft;
                            modelT.CREACTTYPE = CREACTTYPEEnum.System;
                            listDrillRecord.Add(modelT);

                            title = item.DRLL_DATE.Value.ToString("yyyy-MM") + item.NAME + "-演练记录";
                            //年度应急演练计划触发应急演练活动   演练年月+演练名称-演练记录
                            listTaskRead.Add(NotificationTaskService.InsertUserNoticeTaskModel(title, modelT.ID, item.ORG_ID, item.USER_ID.Value, item.Nav_User.NAME, dtNow, 1, "CM034", FMTASKTYPE.Default, null, item.DRLL_DATE));
                        }
                    }

                    if (listTaskRead != null && listTaskRead.Any())
                    {
                        this.UnifiedCommit(() =>
                        {
                            if (task != null)
                                UpdateEntityNoCommit(task);//跑批信息
                            BantchAddEntityNoCommit(listTaskRead);//今日提醒给责任人

                            if (listDrillRecord != null && listDrillRecord.Any())//应急演练记录
                                BantchAddEntityNoCommit(listDrillRecord);
                        });
                        int Count = ((listTaskRead != null && listTaskRead.Any()) ? listTaskRead.Count : 0) + ((listDrillRecord != null && listDrillRecord.Any()) ? listDrillRecord.Count : 0);
                        SyncLogDetailService.InsertSyncLogDetail(HttpContext.Items, HttpContext.TraceIdentifier, filter.OrgId, Count, filter.Parameter1, SyncLogType.BSCreateCheckPlanSet);
                    }
                }
                return true;
            });
        }

        //      /// <summary>
        //      /// 体检结果录入表单
        //      /// </summary>
        //      /// <param name="filter"></param>
        //      /// <returns></returns>
        //      [HttpPost, Route("SendResultImport")]
        //      public JsonActionResult<bool> SendResultImport([FromBody] KeywordFilter filter)
        //      {
        //          return SafeExecute<bool>(() =>
        //          {
        //              DateTime dtNow = DateTime.Now;
        //              if (!string.IsNullOrEmpty(filter.Parameter1))
        //              {
        //                  try
        //                  {
        //                      DateTime deParm = Convert.ToDateTime(filter.Parameter1);
        //                      dtNow = deParm;
        //                  }
        //                  catch { }
        //              }

        //              var listNotice = GetEntities<T_OH_HEALTH_EXAM_NOTICE>(e => e.NOTICEIMPORTSTATE == NoticeImportState.Draft && e.END_TIME <= dtNow && !e.IS_DELETED, null, null);
        //              if (listNotice == null || !listNotice.Any())
        //              {
        //                  return true;
        //              }
        //              string Msg = string.Empty;
        //              T_FM_USER userRS = UserService.GetPostUser(ref Msg);
        //              if (userRS == null)
        //              {
        //                  if (string.IsNullOrEmpty(Msg))
        //                  {
        //                      SysLogService.AddLog(filter.OrgId.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, "系统缺少【人事专员】岗位人员", "体检计划接口【PP/OH/SendResultImport】");
        //                  }
        //                  else
        //                  {
        //                      SysLogService.AddLog(filter.OrgId.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, "系统缺少【人事专员】岗位人员", Msg + "  体检计划接口【PP/OH/SendResultImport】");
        //                  }
        //              }
        //              else
        //              {

        //                  T_FM_SYNC_TASK task = null;//跑批待办
        //                  List<T_FM_NOTIFICATION_TASK> listNoticeImport = new List<T_FM_NOTIFICATION_TASK>(); //体检导入通知
        //                  List<Guid> listPARENTID = new List<Guid>();
        //                  List<Guid> listDataID = new List<Guid>();
        //                  List<T_OH_HEALTH_EXAM_RESULT_IMPORT> listImportOrder = new List<T_OH_HEALTH_EXAM_RESULT_IMPORT>();

        //                  List<string> Name = new List<string>();
        //                  List<Guid> UserId = new List<Guid>();
        //                  List<string> userName = new List<string>();
        //                  //同一个 PARENTID 发送一个待办
        //                  foreach (var item in listNotice)
        //                  {
        //                      item.NOTICEIMPORTSTATE = NoticeImportState.NoticeImport;

        //                      if (item.PARENTID.HasValue && !listPARENTID.Contains(item.PARENTID.Value))
        //                      {
        //                          listPARENTID.Add(item.PARENTID.Value);

        //                          T_OH_HEALTH_EXAM_RESULT_IMPORT modelImport = new T_OH_HEALTH_EXAM_RESULT_IMPORT();
        //                          modelImport.ID = Guid.NewGuid();
        //                          modelImport.ORG_ID = item.ORG_ID.Value;
        //                          modelImport.NOTICE_ID = item.PARENTID.Value;
        //                          listDataID.Add(modelImport.ID);
        //                          listImportOrder.Add(modelImport);

        //                          Name.Add("体检通知结果导入");
        //                          UserId.Add(userRS.ID);
        //                          userName.Add(userRS.NAME);
        //                      }
        //                  }

        //                  List<T_FM_NOTIFICATION_TASK> listTaskImport = NotificationTaskService.InsertUserNoticeTaskModels(Name, listDataID, filter.OrgId, UserId, userName, DateTime.Now, DateTime.Now.AddDays(1), 1, "OH017_IMPORT");

        //                  task = GetEntity<T_FM_SYNC_TASK>(filter.Keyword);
        //                  if (task != null)
        //                  {
        //                      task.UPDATE_SUCCES_TIME = DateTime.Now;//上次同步结束时间
        //                      task.SYNC_PARAM = "";//清空参数
        //                  }
        //                  this.UnifiedCommit(() =>
        //                  {
        //                      if (task != null)
        //                          UpdateEntityNoCommit(task);//跑批信息
        //                      if (listNotice != null && listNotice.Any())//修改状态
        //                          BantchSaveEntityNoCommit(listNotice);
        //                      if (listImportOrder != null && listImportOrder.Any())//添加导入Model
        //                          BantchSaveEntityNoCommit(listImportOrder);
        //                      if (listTaskImport != null && listTaskImport.Any())//添加待办
        //                          BantchSaveEntityNoCommit(listTaskImport);
        //                  });
        //              }
        //              return true;
        //          });
        //      }


        //      /// <summary>
        //      /// 判断跑批时间是否符合
        //      /// </summary>
        //      /// <param name="RUNSETTIME"></param>
        //      /// <param name="dtNow"></param>
        //      /// <param name="minAdvance"></param>
        //      /// <param name="minLaster"></param>
        //      /// <returns></returns>
        //      private bool ISTimeOK(DateTime? RUNSETTIME, DateTime dtNow, int minAdvance, int minLaster)
        //      {
        //          if (RUNSETTIME == null)
        //          {
        //              return false;
        //          }

        //          if (RUNSETTIME != null)
        //          {
        //              if (minAdvance != 0 || minLaster != 0)
        //              {
        //                  //DateTime dtSetTime = Convert.ToDateTime(dtNow.ToString("yyyy") + RUNSETTIME.Value.ToString("-MM-dd HH:mm:ss"));
        //                  DateTime dtSetTime = Convert.ToDateTime(dtNow.ToString("yyyy-MM-dd") + RUNSETTIME.Value.ToString(" HH:mm:ss"));
        //                  if (minAdvance > 0 && minLaster > 0)
        //                  {
        //                      if (dtNow.AddMinutes(-1 * minAdvance) <= dtSetTime && dtSetTime <= dtNow.AddMinutes(minLaster))
        //                      {
        //                          return true;
        //                      }
        //                  }
        //                  else if (minAdvance > 0)
        //                  {
        //                      if (dtNow.AddMinutes(-1 * minAdvance) <= dtSetTime && dtSetTime <= dtNow)
        //                      {
        //                          //如果设置时间小于当前时间  并且 设置使劲按大于 当前时间大于当前时间往前偏移分钟数
        //                          return true;
        //                      }
        //                  }
        //                  else
        //                  {
        //                      if (dtNow <= dtSetTime && dtSetTime <= dtNow.AddMinutes(minLaster))
        //                      {
        //                          //如果 设置时间大于当前时间 并且设置时间小于当前时间往后偏移分钟数
        //                          return true;
        //                      }
        //                  }
        //              }
        //              else
        //              {
        //                  if (RUNSETTIME.Value.ToString("HH:mm") == dtNow.ToString("HH:mm"))
        //                  {
        //                      return true;
        //                  }
        //              }
        //          }
        //          return false;
        //      }

        //      /// <summary>
        //      /// 按体检通知明细 最后日期
        //      /// 给人事专员发送体检通知待办
        //      /// 每天一次即可
        //      /// </summary>
        //      /// <param name="filter"></param>
        //      /// <returns></returns>
        //      [HttpPost, Route("NoticeCycle")]
        //      public JsonActionResult<bool> NoticeCycle([FromBody] KeywordFilter filter)
        //      {
        //          return SafeExecute<bool>(() =>
        //          {
        //              DateTime dtNow = DateTime.Now;
        //              if (!string.IsNullOrEmpty(filter.Parameter1))
        //              {
        //                  try
        //                  {
        //                      //接收来自页面的参数
        //                      DateTime deParm = Convert.ToDateTime(filter.Parameter1);
        //                      dtNow = deParm;
        //                  }
        //                  catch { }
        //              }
        //              int WarmDay = 15;
        //              DateTime dtSearch = dtNow.AddDays(WarmDay);

        //              //体检周期都是几个月的
        //              //所以半个月内有人需要体检就发送待办

        //              //如果有最近的未完成的待办 直接做今日提醒
        //              var listNotice = GetEntities<T_OH_HEALTH_EXAM_NOTICE_REGISTER>(e => e.NEXTDATE.HasValue && e.NEXTDATE <= dtSearch, null, null);
        //              if (listNotice == null || !listNotice.Any())
        //              {
        //                  return true;
        //              }
        //              string Msg = string.Empty;
        //              T_FM_USER userRS = UserService.GetPostUser(ref Msg);

        //              if (userRS == null)
        //              {
        //                  SysLogService.AddLog(filter.OrgId.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, "系统缺少【人事专员】岗位人员", Msg + "  体检计划接口【PP/OH/ExamPlan】");
        //                  return true;
        //              }

        //              var taskNotice = GetEntity<T_FM_NOTIFICATION_TASK>(e => e.USER_ID == userRS.ID && e.SOURCE_FORMCODE == "OH026" && e.NOTICE_STATUS == 0);
        //              if (taskNotice != null)
        //              {
        //                  //有没处理的待办
        //                  //位置靠前
        //                  taskNotice.MODIFY_TIME = DateTime.Now;
        //                  this.UnifiedCommit(() =>
        //                  {
        //                      if (taskNotice != null)
        //                          UpdateEntityNoCommit(taskNotice);
        //                  });
        //              }
        //              else
        //              {
        //                  T_OH_HEALTH_EXAM_NOTICE modelWarm = new T_OH_HEALTH_EXAM_NOTICE();
        //                  modelWarm.ID = Guid.NewGuid();
        //                  modelWarm.CODE = "XTTJTZ" + dtNow.ToString("yyyyMMddHHmmss");
        //                  //modelWarm.NAME =;
        //                  //modelWarm.OTHER_STUFF =;
        //                  modelWarm.STATUS = PFStandardStatus.Draft;
        //                  //modelWarm.APPROVE_ID =;
        //                  modelWarm.IS_DELETED = false;
        //                  modelWarm.ORG_ID = filter.OrgId;
        //                  //modelWarm.ENTITY_ORG_TPYE =;
        //                  //modelWarm.FORM_ID =;
        //                  //modelWarm.FLOW_STATUS =;
        //                  //modelWarm.FLOW_SEND_STATUS =;
        //                  //modelWarm.FLOW_ID =;
        //                  //modelWarm.CREATE_TIME =;
        //                  //modelWarm.MODIFY_TIME =;
        //                  //modelWarm.CREATER_ID =;
        //                  //modelWarm.MODIFIER_ID =;
        //                  //modelWarm.PARENTID =;
        //                  modelWarm.ISSYSTEM = true;//根据这个值前端要自动加载有审批周期待体检的人

        //                  T_FM_NOTIFICATION_TASK taskNoticeRs = NotificationTaskService.InsertUserNoticeTaskModel("体检通知", modelWarm.ID, modelWarm.ORG_ID, userRS.ID, userRS.NAME,
        //DateTime.Now, DateTime.Now.AddDays(1), 0, "OH026");

        //                  T_FM_SYNC_TASK task = GetEntity<T_FM_SYNC_TASK>(filter.Keyword);
        //                  if (task != null)
        //                  {
        //                      task.UPDATE_SUCCES_TIME = DateTime.Now;//上次同步结束时间
        //                      task.SYNC_PARAM = "";//清空参数
        //                  }

        //                  this.UnifiedCommit(() =>
        //                  {
        //                      if (task != null)
        //                          UpdateEntityNoCommit(task);
        //                      if (taskNoticeRs != null)
        //                          UpdateEntityNoCommit(taskNoticeRs);
        //                      if (modelWarm != null)
        //                          UpdateEntityNoCommit(modelWarm);
        //                  });
        //              }

        //              return true;
        //          });
        //      }




        //      /// <summary>
        //      /// 发送检测记录
        //      /// </summary>
        //      /// <param name="filter"></param>
        //      /// <returns></returns>
        //      [HttpPost, Route("SendMonitor")]
        //      public JsonActionResult<bool> SendMonitor([FromBody] KeywordFilter filter)
        //      {
        //          return SafeExecute<bool>(() =>
        //          {
        //              //根据  职业危害因素监测规则 T_OH_HAZARD_MONITOR_RULE 
        //              // 给 责任部门对应记录人 发送检测记录表

        //              DateTime dtNow = DateTime.Now;
        //              if (!string.IsNullOrEmpty(filter.Parameter1))
        //              {
        //                  try
        //                  {
        //                      //接收来自页面的参数
        //                      DateTime deParm = Convert.ToDateTime(filter.Parameter1);
        //                      dtNow = deParm;
        //                  }
        //                  catch { }
        //              }
        //              int minLaster = 20;
        //              //30分钟
        //              DateTime dtEnd = dtNow.AddMinutes(minLaster);//

        //              var listRule = GetEntities<T_OH_HAZARD_MONITOR_RULE>(e => !e.IS_DELETED && e.MONITOR_INTERVAL != OHHazardMonitorIntervalEnum.None && e.TIME != DateTime.MinValue, null, new string[] { "Nav_RecordPost.Nav_Users.Nav_User", "Nav_Type" });
        //              //符合时间的 规则
        //              List<T_OH_HAZARD_MONITOR_RULE> listRun = new List<T_OH_HAZARD_MONITOR_RULE>();

        //              var listSendDetail = GetEntities<T_OH_HAZARD_MONITOR_JOB_DETAIL>(e => e.RULE_ID.HasValue && e.CREATE_TIME.HasValue && e.CREATE_TIME.Value.Date == dtNow.Date, null, null);

        //              if (listRule != null && listRule.Any())
        //              {
        //                  DateTime dtCombin = dtNow.Date;
        //                  foreach (var item in listRule)
        //                  {
        //                      if (!ISTimeOK(item.TIME, dtNow, 0, minLaster))
        //                      {
        //                          //设置时间往前后各偏移 20 分钟 判断跑批
        //                          continue;
        //                      }
        //                      switch (item.MONITOR_INTERVAL)
        //                      {
        //                          case OHHazardMonitorIntervalEnum.Date://每天
        //                              listRun.Add(item);
        //                              break;
        //                          case OHHazardMonitorIntervalEnum.Week://每周
        //                              if (item.WEEKDATA != null && (int)dtNow.DayOfWeek == (int)item.WEEKDATA.Value)
        //                                  //星期匹配   DateTime.Now.DayOfWeek Thursday    (int)DateTime.Now.DayOfWeek 4
        //                                  listRun.Add(item);
        //                              break;
        //                          case OHHazardMonitorIntervalEnum.Month://每月
        //                              if (item.DAY == dtNow.Day)
        //                                  listRun.Add(item);
        //                              break;
        //                          case OHHazardMonitorIntervalEnum.Quarter://每季度
        //                              if (item.DAY == dtNow.Day && (item.MONTH == dtNow.Month || item.MONTH == dtNow.Month - 3 || item.MONTH == dtNow.Month - 6 || item.MONTH == dtNow.Month - 9))//日相等 月相等 或者 月= 当前月-3n
        //                                  listRun.Add(item);
        //                              break;
        //                          case OHHazardMonitorIntervalEnum.HalfYear://每半年
        //                              if (item.DAY == dtNow.Day && (item.MONTH == dtNow.Month || item.MONTH == dtNow.Month - 6))//日相等 月相等 或者 月= 当前月-6
        //                                  listRun.Add(item);
        //                              break;
        //                          case OHHazardMonitorIntervalEnum.Year://每年
        //                              if (item.MONTH == dtNow.Month && item.DAY == dtNow.Day)
        //                                  listRun.Add(item);
        //                              break;
        //                          default:
        //                              break;
        //                      }
        //                  }
        //              }

        //              if (listRun.Count < 1)
        //              {
        //                  return true;
        //              }

        //              //OH024
        //              //监测记录
        //              List<T_OH_HAZARD_MONITOR_JOB> listMonitorJob = new List<T_OH_HAZARD_MONITOR_JOB>();
        //              List<T_OH_HAZARD_MONITOR_JOB_DETAIL> listMonitorJobDetail = new List<T_OH_HAZARD_MONITOR_JOB_DETAIL>();


        //              //责任部门 对应记录人 发送检测记录 单据
        //              List<T_FM_NOTIFICATION_TASK> listTask = new List<T_FM_NOTIFICATION_TASK>();
        //              T_OH_HAZARD_MONITOR_JOB_DETAIL modelCheckDetail = null;
        //              DateTime LAST_NOTIFY = DateTime.Now;
        //              List<T_OH_HAZARD_MONITOR_RULE> listRuleUpdate = new List<T_OH_HAZARD_MONITOR_RULE>();
        //              //责任部门 对应 记录人 
        //              foreach (var item in listRun)
        //              {
        //                  //判断今天有没有 添加  e.USER_ID_GET == itemPost.USER_ID &&
        //                  modelCheckDetail = listSendDetail.FirstOrDefault(e => e.RULE_ID == item.ID);
        //                  if (modelCheckDetail != null)
        //                  {
        //                      //今天有添加
        //                      continue;
        //                  }


        //                  foreach (var itemPost in item.Nav_RecordPost.Nav_Users)
        //                  {
        //                      if (item.DEPARTMENT_ID != itemPost.Nav_User.DEPARTMENT_ID)
        //                      {
        //                          continue;
        //                      }
        //                      modelCheckDetail = listMonitorJobDetail.FirstOrDefault(e => e.RULE_ID == item.ID);
        //                      if (modelCheckDetail != null)
        //                      {
        //                          //有加过(虽然人不一样)
        //                          continue;
        //                      }

        //                      #region      检测单

        //                      T_OH_HAZARD_MONITOR_JOB Job = listMonitorJob.FirstOrDefault(e => e.MONITOR_TYPE == item.Nav_Type.MONITOR_TYPE && e.USER_ID_GET == itemPost.USER_ID);
        //                      if (Job == null)
        //                      {
        //                          Job = new T_OH_HAZARD_MONITOR_JOB();
        //                          Job.ID = Guid.NewGuid();
        //                          //Job.RULE_ID = item.ID;
        //                          //Job.MONITOR_TIME =;
        //                          //Job.USER_ID = itemPost.USER_ID;
        //                          //Job.DEVICE_NAME =;
        //                          //Job.DEVICE_SPEC =;
        //                          //Job.MONITOR_METHOD =;
        //                          //Job.SAMPLE_PEOPLE =;
        //                          Job.STATUS = OHHazardMonitorJobStatusEnum.WaitSign;
        //                          Job.IS_DELETED = false;
        //                          Job.ORG_ID = item.ORG_ID;
        //                          //Job.ENTITY_ORG_TPYE =;
        //                          //Job.FORM_ID =;
        //                          //Job.FLOW_STATUS =;
        //                          //Job.FLOW_SEND_STATUS =;
        //                          //Job.FLOW_ID =;
        //                          //Job.CREATE_TIME = dtNow;
        //                          //Job.MODIFY_TIME = dtNow;
        //                          //Job.CREATER_ID = itemPost.USER_ID;
        //                          //Job.MODIFIER_ID = itemPost.USER_ID;
        //                          Job.USER_ID_GET = itemPost.USER_ID;
        //                          Job.TYPE_ID = item.TYPE_ID;
        //                          Job.MONITOR_TYPE = item.Nav_Type.MONITOR_TYPE;

        //                          //添加监测记录单
        //                          listMonitorJob.Add(Job);


        //                          //添加待办
        //                          T_FM_NOTIFICATION_TASK taskAdd = NotificationTaskService.InsertUserNoticeTaskModel(item.Nav_Type.MONITOR_TYPE.GetDescription(), Job.ID, Job.ORG_ID, itemPost.USER_ID, itemPost.Nav_User.NAME, dtNow, dtNow.AddDays(1), 0, "OH024");
        //                          listTask.Add(taskAdd);

        //                          //最后修改时间
        //                          item.LAST_NOTIFY = DateTime.Now;//最后推送日期
        //                          if (!listRuleUpdate.Contains(item))
        //                          {
        //                              listRuleUpdate.Add(item);
        //                          }

        //                      }

        //                      #region     监测明细

        //                      T_OH_HAZARD_MONITOR_JOB_DETAIL JobDetail = new T_OH_HAZARD_MONITOR_JOB_DETAIL();
        //                      JobDetail.ID = Guid.NewGuid();
        //                      JobDetail.JOB_ID = Job.ID;
        //                      JobDetail.RULE_ID = item.ID;
        //                      JobDetail.USER_ID_GET = itemPost.USER_ID;

        //                      //JobDetail.SAMPLE_SOURCE      =;
        //                      //JobDetail.JOB_STATUS         =;
        //                      //JobDetail.PROTECT_STATUS     =;
        //                      //JobDetail.MONITOR_RESULT_LOW =;
        //                      //JobDetail.MONITOR_RESULT_HIGH=;
        //                      //JobDetail.OVER_LIMIT         =;
        //                      //JobDetail.MONITOR_RESULT_05  =;
        //                      //JobDetail.MONITOR_RESULT_10  =;
        //                      //JobDetail.MONITOR_RESULT_AROUND=;
        //                      //JobDetail.SAMPLE_TIME    =;
        //                      //JobDetail.TEST_TIME      =;
        //                      //JobDetail.MONITOR_RESULT =;
        //                      //JobDetail.TEST_DEPARTMENT=;
        //                      //JobDetail.TESTER         =;
        //                      JobDetail.IS_DELETED = false;
        //                      JobDetail.ORG_ID = item.ORG_ID;
        //                      //JobDetail.ENTITY_ORG_TPYE =;
        //                      //JobDetail.FORM_ID         =;
        //                      //JobDetail.FLOW_STATUS     =;
        //                      //JobDetail.FLOW_SEND_STATUS=;
        //                      //JobDetail.FLOW_ID         =;
        //                      //JobDetail.CREATE_TIME     =;
        //                      //JobDetail.MODIFY_TIME     =;
        //                      //JobDetail.CREATER_ID      =;
        //                      //JobDetail.MODIFIER_ID     =;

        //                      listMonitorJobDetail.Add(JobDetail);

        //                      #endregion


        //                      #endregion

        //                  }
        //              }




        //              T_FM_SYNC_TASK task = GetEntity<T_FM_SYNC_TASK>(filter.Keyword);
        //              if (task != null)
        //              {
        //                  task.UPDATE_SUCCES_TIME = DateTime.Now;//上次同步结束时间
        //                  task.SYNC_PARAM = "";//清空参数
        //              }

        //              this.UnifiedCommit(() =>
        //              {
        //                  if (task != null)
        //                      UpdateEntityNoCommit(task);
        //                  if (listMonitorJob != null && listMonitorJob.Any())
        //                      BantchSaveEntityNoCommit(listMonitorJob);
        //                  if (listTask != null && listTask.Any())
        //                      BantchSaveEntityNoCommit(listTask);
        //                  if (listMonitorJobDetail != null && listMonitorJobDetail.Any())
        //                      BantchSaveEntityNoCommit(listMonitorJobDetail);
        //                  if (listRuleUpdate != null && listRuleUpdate.Any())
        //                      BantchSaveEntityNoCommit(listRuleUpdate);
        //              });
        //              return true;
        //          });
        //      }

    }
}
