using APT.BaseData.Domain.Entities;
using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.Enums;
using APT.BaseData.Domain.IServices;
using APT.BaseData.Domain.IServices.FM;
using APT.Infrastructure.Core;
using APT.MS.Domain.ApiModel.BS;
using APT.MS.Domain.Entities.BS;
using APT.MS.Domain.Entities.HM;
using APT.MS.Domain.Entities.PF;
using APT.MS.Domain.Enums;
using APT.Utility;
using APT.WebApi.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;

namespace APT.BS.WebApi.Controllers.Api
{
    [Route("api/BS/BSRiskSubmit")]
    public partial class BSRiskSubmitController : AuthorizeApiController<T_BS_RISK_SUBMIT>
    {
        IFMFlowPermitService MFlowPermitService { get; set; }
        IPFApproveCallBackService ApproveCallBackService { get; set; }
        IFMNotificationTaskService NotificationTaskService { get; set; }
        IPFCodeRuleService CodeRuleService { get; set; }
        IPFSysLogService SysLogService { get; set; }
        IFMDepartmentService DepartmentService { get; set; }
        IBSOperateLogService OperateLogService { get; set; }

        ///// <summary>
        ///// 回调
        ///// </summary>
        ///// <param name="CALLBACK_INTERFACE"></param>
        ///// <param name="DATA_ID"></param>
        //public delegate void DelegateCallBack(string CALLBACK_INTERFACE, string DATA_ID);

        public BSRiskSubmitController(IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFCodeRuleService codeRuleService, IPFSysLogService sysLogService, IPFApproveCallBackService approveCallBackService, IFMDepartmentService departmentService, IBSOperateLogService operateLogService)
        {
            NotificationTaskService = notificationTaskService;
            MFlowPermitService = mFlowPermitService;
            CodeRuleService = codeRuleService;
            SysLogService = sysLogService;
            ApproveCallBackService = approveCallBackService;
            DepartmentService = departmentService;
            OperateLogService = operateLogService;
            //DelegateCallBack callBack = new DelegateCallBack(CallBACK);
            //callBack += CallBACK;
        }


        //public static void CallBACK(string CALLBACK_INTERFACE, string DATA_ID)
        //{
        //    switch (CALLBACK_INTERFACE)
        //    {
        //        case "":
        //            break;
        //        default:
        //            break;
        //    }
        //}



        #region 隐患上报


        /// <summary>
        /// 获得单条实体数据
        /// </summary>
        /// <param name="filter">过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("Get")]
        public JsonActionResult<T_BS_RISK_SUBMIT> Get([FromBody] KeywordFilter filter)
        {
            return SafeExecute<T_BS_RISK_SUBMIT>(() =>
            {
                List<FilterRule> filterRules = filter.FilterGroup.Rules.ToList();
                var guid = new Guid(filterRules[0].Value.ToString());

            //var modelSub = GetEntity<T_BS_RISK_SUBMIT>(e => e.ID == guid, new string[] { "Nav_CheckType", "Nav_CheckTypeLevel.Nav_Enums", "Nav_ListRiskSubmitContent.Nav_SafeCheckDetail", "Nav_ListRiskSubmitContent.Nav_CheckMain", "Nav_ListRiskSubmitContent.Nav_CheckMain.Nav_CheckProject", "Nav_ListRiskSubmitContent.Nav_Question", "Nav_ListRiskSubmitContent.Nav_User", "Nav_ListRiskSubmitContent.Nav_Department", "Nav_Files.Nav_ImgFile.Nav_File" });
            again:

                var modelSub = GetEntity<T_BS_RISK_SUBMIT>(e => e.ID == guid, new string[] { "Nav_CheckType", "Nav_CheckTypeLevel.Nav_Enums", "Nav_Files.Nav_ImgFile.Nav_File", "Nav_User" });

                if (modelSub == null)
                {
                    //modelSub = GetEntity<T_BS_RISK_SUBMIT>(e => e.CHECK_ID == guid, new string[] { "Nav_Check", "Nav_CheckType", "Nav_CheckTypeLevel.Nav_Enums", "Nav_Files.Nav_ImgFile.Nav_File", "Nav_ListRiskSubmitContent.Nav_Question", "Nav_ListRiskSubmitContent.Nav_ListRiskQuestionReason.Nav_RiskReason", "Nav_ListRiskSubmitContent.Nav_User", "Nav_ListRiskSubmitContent.Nav_Department",
                    //    "Nav_Department", "Nav_User" });

                    modelSub = GetEntity<T_BS_RISK_SUBMIT>(e => e.CHECK_ID == guid, new string[] { "Nav_Check", "Nav_CheckType", "Nav_CheckTypeLevel.Nav_Enums", "Nav_Files.Nav_ImgFile.Nav_File",
                        "Nav_Department", "Nav_User" });
                    if (modelSub == null)
                    {
                        var notice = GetEntity<T_BS_RISK_SUBMIT_NOTICE>(guid);
                        if (notice != null && notice.RISK_SUBMIT_ID.HasValue)
                        {
                            guid = notice.RISK_SUBMIT_ID.Value;
                            goto again;
                        }
                        else
                        {
                            var entity = GetEntity<T_BS_SAFE_CHECK>(guid, new string[] { "Nav_User", "Nav_CheckType", "Nav_CheckTypeLevel.Nav_Enums", "Nav_ListSafeCheckDetail" });
                            modelSub = new T_BS_RISK_SUBMIT();
                            modelSub.ID = Guid.NewGuid();
                            modelSub.CODE = entity.CODE;//替换成同一个
                            if (entity.CHECKOBJECT.HasValue)
                            {
                                try
                                {
                                    modelSub.CHECKOBJECT = (BSMineTypeEnum)entity.CHECKOBJECT;
                                }
                                catch { }
                            }
                            modelSub.NAME = entity.Nav_CheckTypeLevel.Nav_Enums.NAME + entity.Nav_CheckType.NAME;
                            modelSub.Nav_Check = entity;
                            modelSub.Nav_CheckType = entity.Nav_CheckType;
                            modelSub.Nav_CheckTypeLevel = entity.Nav_CheckTypeLevel;
                            modelSub.CREATER_ID = entity.USERID_DOPLAN.Value;
                            modelSub.CHECK_ID = entity.ID;
                            modelSub.CHECKTIME = entity.CHECKTIME;
                            modelSub.SUBMIT_STATUS = (int)BSSubmitStatusEnum.WaiteStart;
                            modelSub.USER_ID = modelSub.CREATER_ID;
                            modelSub.DEPARTMENT_ID = entity.Nav_User.DEPARTMENT_ID;

                            modelSub.SUBMIT_TYPE = (int)SUBMIT_TYPE.Check;
                            modelSub.ISORDEREND = false;

                            modelSub.CHECK_TYPE_ID = entity.CHECK_TYPE_ID;
                            modelSub.CHECK_TYPE_LEVEL_ID = entity.CHECK_TYPE_LEVEL_ID;
                            modelSub.ORG_ID = entity.ORG_ID;


                            var files = GetEntities<T_BS_SAFE_CHECK_FILE>(e => e.SAFE_CHECK_ID == guid, null, "Nav_ImgFile.Nav_File");
                            if (files != null && files.Any())
                            {
                                var Nav_Files = new List<T_BS_RISK_SUBMIT_FILE>();
                                foreach (var item in files)
                                {
                                    Nav_Files.Add(new T_BS_RISK_SUBMIT_FILE()
                                    {
                                        ID = Guid.NewGuid(),
                                        ORG_ID = modelSub.ORG_ID,
                                        RISK_SUBMIT_ID = modelSub.ID,
                                        IMG_FILE_ID = item.IMG_FILE_ID,
                                        Nav_ImgFile = item.Nav_ImgFile
                                    });
                                }
                                modelSub.Nav_Files = Nav_Files;
                            }
                        }
                    }
                    else
                    {
                        var listTemp = GetEntities<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_ID == modelSub.ID, null, "Nav_Question", "Nav_ListRiskQuestionReason.Nav_RiskReason", "Nav_User", "Nav_UserDeal", "Nav_UserCheck", "Nav_DepartmentDeal", "Nav_Department", "Nav_RiskArea");
                        if (listTemp != null && listTemp.Any())
                        {
                            modelSub.Nav_ListRiskSubmitContent = listTemp.ToList();
                        }
                        GetListContentRiskQuestionReason(modelSub.Nav_ListRiskSubmitContent);
                    }
                    //for (int i = 0; i < entity.Nav_ListSafeCheckDetail.Count; i++)
                    //{
                    //    T_BS_RISK_SUBMIT_CONTENT SubmitContent = new T_BS_RISK_SUBMIT_CONTENT();
                    //}
                    //modelSub.Nav_ListRiskSubmitContent = new List<T_BS_RISK_SUBMIT_CONTENT>();
                }
                else
                {
                    var listTemp = GetEntities<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_ID == modelSub.ID, null, "Nav_SafeCheckDetail", "Nav_CheckMain", "Nav_CheckMain.Nav_CheckProject", "Nav_Question", "Nav_User", "Nav_UserDeal", "Nav_UserCheck", "Nav_DepartmentDeal", "Nav_Department", "Nav_RiskArea");
                    if (listTemp != null && listTemp.Any())
                    {
                        modelSub.Nav_ListRiskSubmitContent = listTemp.ToList();
                        if (modelSub.Nav_ListRiskSubmitContent[0].RiskContentState == 10)
                        {
                            if (!modelSub.Nav_ListRiskSubmitContent[0].LastDateSystem.HasValue)
                            {
                                for (int i = 0; i < modelSub.Nav_ListRiskSubmitContent.Count; i++)
                                {
                                    if (modelSub.Nav_ListRiskSubmitContent[i].USER_ID.HasValue && !modelSub.Nav_ListRiskSubmitContent[i].ACTUAL_DEAL_USER_ID.HasValue)
                                    {
                                        modelSub.Nav_ListRiskSubmitContent[i].Nav_UserDeal = modelSub.Nav_ListRiskSubmitContent[i].Nav_User;
                                        modelSub.Nav_ListRiskSubmitContent[i].DEAL_USER_ID = modelSub.Nav_ListRiskSubmitContent[i].USER_ID.Value;

                                        modelSub.Nav_ListRiskSubmitContent[i].DEAL_DEPARTMENT_ID = modelSub.Nav_ListRiskSubmitContent[i].DEPARTMENT_ID.Value;
                                        modelSub.Nav_ListRiskSubmitContent[i].Nav_DepartmentDeal = modelSub.Nav_ListRiskSubmitContent[i].Nav_Department;

                                    }
                                    int delayDays = GetDealyDays(modelSub.Nav_ListRiskSubmitContent[i].QUESTION_LEVEL);
                                    modelSub.Nav_ListRiskSubmitContent[i].LastDateSystem = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")).AddDays(delayDays);
                                }
                            }
                        }
                    }

                    GetListContentRiskQuestionReason(modelSub.Nav_ListRiskSubmitContent);
                }

                return modelSub;
            });
        }


        /// <summary>
        /// 隐患待上报 改版 获取信息
        /// </summary>
        /// <param name="filter">过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("GetBS006")]
        public JsonActionResult<T_BS_RISK_SUBMIT> GetBS006([FromBody] KeywordFilter filter)
        {
            return SafeExecute<T_BS_RISK_SUBMIT>(() =>
            {
                List<FilterRule> filterRules = filter.FilterGroup.Rules.ToList();
                var guid = new Guid(filterRules[0].Value.ToString());
                var modelSub = GetEntity<T_BS_RISK_SUBMIT>(e => e.ID == guid, new string[] { "Nav_Check", "Nav_CheckType", "Nav_CheckTypeLevel.Nav_Enums", "Nav_Files.Nav_ImgFile.Nav_File", "Nav_User" });

                //上报明细 是不完整的 明细信息重新 整理

                //这两个字段作为是否操作过的标签
                //CHECK_PROJECT_ID = item.CHECK_PROJECT_ID,
                //CHECK_PROJECT_CATEGORY_ID = item.CHECK_PROJECT_CATEGORY_ID,
                //CHECKCONTENT = item.CHECKCONTENT,
                var isFirst = GetCount<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_ID == guid && (e.CHECK_PROJECT_ID.HasValue || e.CHECK_PROJECT_CATEGORY_ID.HasValue), null) == 0;
                if (isFirst)
                {
                    var listSubContents = GetEntities<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_ID == guid, null, null).ToList();
                    #region    整合  GetSubmitContent 方法

                    Expression<Func<T_BS_SAFE_CHECK_DETAIL, bool>> expression = e => e.SAFE_CHECK_ID == modelSub.CHECK_ID && !e.IS_DELETED && e.CHECKRESULT.HasValue && e.CHECKRESULT != (int)CHECKRESULTEnum.None;
                    var info = this.GetEntities(expression, null, new string[] { "Nav_ListCheckDetailQuestion.Nav_Question", "Nav_CheckArea", "Nav_CheckMain", "Nav_ListCheckDetailReason.Nav_RiskReason", "Nav_Files.Nav_ImgFile.Nav_File" });

                    List<Guid> listArearId = new List<Guid>();
                    foreach (var item in info)
                    {
                        if (!listArearId.Contains(item.RISK_AREA_ID.Value))
                        {
                            listArearId.Add(item.RISK_AREA_ID.Value);
                        }
                    }

                    List<Guid> listQID = new List<Guid>() { new Guid("55555555-5555-5555-5555-555555555555"), new Guid("66666666-6666-6666-6666-666666666666") };

                    //责任部门
                    List<T_FM_DEPARTMENT> listDep = new List<T_FM_DEPARTMENT>();
                    T_FM_DEPARTMENT depCheck = null;
                    Dictionary<Guid, T_FM_USER> dicDepSafer = new Dictionary<Guid, T_FM_USER>();
                    if (info.Any() && info.Count() > 0)
                    {
                        foreach (var item in info)
                        {
                            if (!item.DEPARTMENT_ID.HasValue)
                            {
                                continue;
                            }
                            depCheck = listDep.Find(e => e.ID == item.DEPARTMENT_ID);
                            if (depCheck == null)
                            {
                                depCheck = GetEntity<T_FM_DEPARTMENT>(item.DEPARTMENT_ID.Value, "Nav_User");
                                listDep.Add(depCheck);
                            }
                            if (depCheck == null)
                            {
                                continue;
                            }
                            foreach (var itemQ in item.Nav_ListCheckDetailQuestion)
                            {
                                if (listQID.Contains(itemQ.Nav_Question.ID))
                                {
                                    continue;
                                }

                                T_BS_RISK_SUBMIT_CONTENT model = listSubContents.FirstOrDefault(e => e.SAFE_CHECK_DETAIL_ID == item.ID);// new T_BS_RISK_SUBMIT_CONTENT();
                                if (model == null)
                                {
                                    model = new T_BS_RISK_SUBMIT_CONTENT();
                                    listSubContents.Add(model);
                                }

                                model.NAME = string.Empty;
                                model.CODE = string.Empty;
                                model.RISK_SUBMIT_ID = modelSub.ID;
                                model.CHECK_MAIN_ID = item.CHECK_MAIN_ID;
                                model.Nav_CheckMain = item.Nav_CheckMain;
                                model.REMARK = item.REMARK;

                                model.DEPARTMENT_ID = item.DEPARTMENT_ID;
                                model.Nav_Department = depCheck;
                                if (item.Nav_Files != null && item.Nav_Files.Any())
                                {
                                    List<T_BS_RISK_SUBMIT_CONTENT_FILE> listFiles = new List<T_BS_RISK_SUBMIT_CONTENT_FILE>();
                                    foreach (var itemF in item.Nav_Files)
                                    {
                                        listFiles.Add(new T_BS_RISK_SUBMIT_CONTENT_FILE()
                                        {
                                            ID = Guid.NewGuid(),
                                            RISK_SUBMIT_ID = modelSub.ID,
                                            RISK_SUBMIT_CONTENT_ID = model.ID,
                                            IMG_FILE_ID = itemF.IMG_FILE_ID,
                                            Nav_ImgFile = itemF.Nav_ImgFile,
                                            IS_DELETED = false,
                                            ORG_ID = itemF.ORG_ID,
                                            //ENTITY_ORG_TPYE=itemF.ENTITY_ORG_TPYE,
                                            //FORM_ID=null,
                                            //FLOW_STATUS= itemF.FLOW_STATUS,
                                            //FLOW_SEND_STATUS=itemF.FLOW_SEND_STATUS,
                                            //FLOW_ID=itemF.FLOW_ID,
                                            //CREATE_TIME=DateTime.Now,
                                            //MODIFY_TIME=DateTime.Now,
                                            //CREATER_ID=
                                            //MODIFIER_ID
                                            //T_BS_RISK_SUBMIT_CONTENT_BACKID
                                        });
                                    }
                                    model.Nav_Files = listFiles;
                                }
                                //wyw1114-1
                                if (!item.CHECK_MAIN_ID.HasValue || item.CHECK_MAIN_ID.Value == Guid.Empty)
                                {
                                    //检查库信息为空（手动添加组合  添加的人是谁，对应责任人就是对应隐患上报的人）
                                    model.USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                                    model.Nav_User = GetEntity<T_FM_USER>(model.USER_ID.Value);
                                }
                                else
                                {
                                    //if (item.Nav_CheckMain.RESPONOBJECT == BSPLANCHECKOBJECTEnum.Head || item.Nav_CheckMain.RESPONOBJECT == BSPLANCHECKOBJECTEnum.ClassMonitor)
                                    if (depCheck.USER_ID == depCheck.USER_ID)
                                    {
                                        model.USER_ID = depCheck.USER_ID;
                                        model.Nav_User = depCheck.Nav_User;
                                    }
                                    else
                                    {
                                        //对应的安全员
                                        if (!dicDepSafer.ContainsKey(model.DEPARTMENT_ID.Value))
                                        {
                                            var depSafer = GetEntity<T_FM_USER>(e => e.DEPARTMENT_ID == model.DEPARTMENT_ID && e.APPROVE_ROLE_ID.HasValue && e.Nav_ApproveRole.NAME.Contains("安全"), "Nav_ApproveRole");
                                            if (depSafer == null)
                                            {
                                                continue;
                                            }
                                            dicDepSafer.Add(model.DEPARTMENT_ID.Value, depSafer);
                                        }

                                        model.Nav_User = dicDepSafer[model.DEPARTMENT_ID.Value];
                                        model.USER_ID = model.Nav_User.ID;
                                    }
                                }

                                //整改责任人  默认  通知责任人 
                                if (model.USER_ID.HasValue)
                                {
                                    model.Nav_UserDeal = model.Nav_User;
                                    model.DEAL_USER_ID = model.USER_ID.Value;

                                    model.DEAL_DEPARTMENT_ID = model.DEPARTMENT_ID.Value;
                                    model.Nav_DepartmentDeal = model.Nav_Department;
                                }

                                //if (item.RISK_AREA_ID.HasValue && dicRiskUser.ContainsKey(item.RISK_AREA_ID.Value) && dicRiskUser[item.RISK_AREA_ID.Value] != null)
                                //{
                                //    model.USER_ID = dicRiskUser[item.RISK_AREA_ID.Value].ID;
                                //    model.DEPARTMENT_ID = dicRiskUser[item.RISK_AREA_ID.Value].DEPARTMENT_ID;
                                //    model.Nav_User = dicRiskUser[item.RISK_AREA_ID.Value];
                                //    model.Nav_Department = dicRiskUser[item.RISK_AREA_ID.Value].Nav_Department;
                                //}
                                //else
                                //{
                                //    model.USER_ID = null;
                                //    model.DEPARTMENT_ID = null;
                                //}


                                model.Nav_SafeCheckDetail = item;
                                model.CHECK_MAIN_ID = item.CHECK_MAIN_ID;
                                model.SAFE_CHECK_ID = item.SAFE_CHECK_ID;

                                model.CHECK_PROJECT_ID = item.CHECK_PROJECT_ID;
                                //model.Nav_CheckProject = item.Nav_CheckProject;
                                model.CHECK_PROJECT_PROJECT_CATEGORY_ID = item.CHECK_PROJECT_PROJECT_CATEGORY_ID;
                                //model.Nav_CheckProjectProjectCategory = item.Nav_CheckProjectProjectCategory;

                                model.CHECK_PROJECT_CATEGORY_ID = item.CHECK_PROJECT_CATEGORY_ID;//0927

                                model.SERIOUS_RISK = item.SERIOUS_RISK;
                                model.CHECKCONTENT = item.CHECKCONTENT;

                                model.SAFE_CHECK_DETAIL_ID = model.Nav_SafeCheckDetail.ID;
                                if (model.QUESTION_LEVEL == 0)
                                {
                                    model.QUESTION_LEVEL = item.QUESTION_LEVEL.HasValue ? item.QUESTION_LEVEL.Value : ((int)itemQ.Nav_Question.QUESTION_LEVEL);//默认等级和原来一致
                                }
                                model.QUESTION_LEVEL_SHOW = model.QUESTION_LEVEL > 0 ? ((BSQuestionLevelEnum)(model.QUESTION_LEVEL)).GetDescription() : "";//默认等级和原来一致

                                model.RISK_AREA_ID = item.RISK_AREA_ID;
                                //model.CHECK_QUESTION_ID = item.Nav_CheckMain.Nav_CheckQuestion.ID;
                                if (item.CHECKRESULT.HasValue && item.CHECKRESULT == (int)CHECKRESULTEnum.Same)
                                {
                                    model.Nav_SafeCheckDetail.REMARK_RESULT = itemQ.Nav_Question.DESCREPTION;
                                    model.Nav_Question = itemQ.Nav_Question;// item.Nav_CheckQuestion;
                                    model.DESCREPTION = itemQ.Nav_Question.DESCREPTION;//  item.Nav_CheckQuestion.DESCREPTION;//取检查问题的 描述
                                    model.DEMAND = itemQ.Nav_Question.DEMAND;//  item.Nav_CheckQuestion.DEMAND;
                                    model.CHECK_QUESTION_ID = itemQ.Nav_Question.ID;//  item.Nav_CheckQuestion.ID;
                                    model.PROOF = item.CHECKPROOF;
                                }
                                else
                                {
                                    model.Nav_SafeCheckDetail.REMARK_RESULT = item.REMARK_RESULT;
                                    model.DESCREPTION = item.REMARK_RESULT;//其他 取安全检查的 备注
                                    model.DEMAND = "";
                                    model.CHECK_QUESTION_ID = null;
                                    model.PROOF = null;
                                }

                                model.CHECK_CONTENTS_ID = item.CHECK_CONTENTS_ID;

                                model.ADDRESS = item.ADDRESS;//隐患地点

                                int delayDays = GetDealyDays(model.QUESTION_LEVEL);
                                model.LastDateSystem = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")).AddDays(delayDays);


                                //item.Nav_ListCheckDetailReason
                                //model.Nav_ListRiskQuestionReason=
                                if (item.Nav_ListCheckDetailReason != null && item.Nav_ListCheckDetailReason.Any())
                                {
                                    model.Nav_ListRiskQuestionReason = new List<T_BS_RISK_SUBMIT_CONTENT_REASON>();
                                    foreach (var itemR in item.Nav_ListCheckDetailReason)
                                    {
                                        model.Nav_ListRiskQuestionReason.Add(new T_BS_RISK_SUBMIT_CONTENT_REASON()
                                        {
                                            ID = Guid.NewGuid(),
                                            RISK_SUBMIT_CONTENT_ID = model.ID,
                                            Nav_RiskSubmitContent = model,
                                            Nav_RiskReason = itemR.Nav_RiskReason,
                                            RISK_REASON_ID = itemR.RISK_REASON_ID,
                                            IS_DELETED = false,
                                            ORG_ID = itemR.ORG_ID,
                                            //ENTITY_ORG_TPYE = ,
                                            //FORM_ID = ,
                                            //FLOW_STATUS = ,
                                            //FLOW_SEND_STATUS = ,
                                            //FLOW_ID = ,
                                            CREATE_TIME = DateTime.Now,
                                            MODIFY_TIME = DateTime.Now,
                                            //CREATER_ID = ,
                                            //MODIFIER_ID = ,
                                            //T_BS_RISK_SUBMIT_CONTENT_BACKID = ,

                                        });
                                    }
                                }

                            }
                        }

                        #region   验收人 默认为 责任组织 上一级的安全员

                        var listDepID = listSubContents.Where(e => e.DEPARTMENT_ID.HasValue).Select(e => e.DEPARTMENT_ID.Value).Distinct();
                        if (listDepID != null && listDepID.Any())
                        {
                            var listDeps = GetEntities<T_FM_DEPARTMENT>(e => listDepID.Contains(e.ID), null);
                            listDepID = listDeps.Where(e => e.PARENT_ID.HasValue).Select(e => e.PARENT_ID.Value).Distinct();
                            var listRole = GetEntities<T_PF_APPROVAL_ROLE>(e => e.NAME.Contains("安全员"), null, null);
                            if (listRole != null && listRole.Any())
                            {
                                var listRoleID = listRole.Select(e => e.ID);
                                var listHeader = GetEntities<T_FM_USER>(e => listDepID.Contains(e.DEPARTMENT_ID.Value) && e.APPROVE_ROLE_ID.HasValue && listRoleID.Contains(e.APPROVE_ROLE_ID.Value), null, null);
                                if (listHeader != null && listHeader.Any())
                                {
                                    foreach (var item in listSubContents)
                                    {
                                        if (item.DEPARTMENT_ID.HasValue)
                                        {
                                            var depThis = listDeps.FirstOrDefault(e => e.ID == item.DEPARTMENT_ID.Value);
                                            if (depThis != null && depThis.PARENT_ID.HasValue)
                                            {
                                                T_FM_USER userTemp = listHeader.FirstOrDefault(x => x.DEPARTMENT_ID == depThis.PARENT_ID.Value);
                                                if (userTemp != null)
                                                {
                                                    item.CHECK_USER_ID = userTemp.ID;
                                                    item.Nav_UserCheck = userTemp;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    modelSub.Nav_ListRiskSubmitContent = listSubContents;

                    #endregion
                }
                else
                {
                    //APP查看 需要 Nav_RiskArea
                    modelSub.Nav_ListRiskSubmitContent = GetEntities<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_ID == guid, null, "Nav_CheckMain", "Nav_RiskArea", "Nav_Files.Nav_ImgFile.Nav_File", "Nav_User", "Nav_UserDeal", "Nav_DepartmentDeal", "Nav_ListRiskQuestionReason.Nav_RiskReason").ToList();
                }
                return modelSub;
            });
        }

        /// <summary>
        /// 获得单条实体数据
        /// </summary>
        /// <param name="filter">过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("GetBack")]
        public JsonActionResult<T_BS_RISK_SUBMIT> GetBack([FromBody] KeywordFilter filter)
        {
            return SafeExecute<T_BS_RISK_SUBMIT>(() =>
            {
                List<FilterRule> filterRules = filter.FilterGroup.Rules.ToList();
                var guid = new Guid(filterRules[0].Value.ToString());//T_BS_RISK_SUBMIT_NOTICE
                T_BS_RISK_SUBMIT result = new T_BS_RISK_SUBMIT();
                //var notice = GetEntity<T_BS_RISK_SUBMIT_NOTICE>(guid);
                var listSubContent = GetEntities<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_NOTICE_ID == guid, null, "Nav_SafeCheckDetail", "Nav_ListRiskQuestionReason.Nav_RiskReason", "Nav_User", "Nav_Department", "Nav_Files.Nav_ImgFile.Nav_File", "Nav_DepartmentDeal", "Nav_UserDeal", "Nav_UserCheck");
                var submitID = Guid.Empty;
                if (listSubContent != null && listSubContent.Any())
                {
                    //这个方法在什么时候用？
                    var list = listSubContent.ToList();
                    submitID = list[0].RISK_SUBMIT_ID.Value;
                    result = GetEntity<T_BS_RISK_SUBMIT>(submitID, "Nav_Check", "Nav_Check", "Nav_CheckTypeLevel.Nav_Enums", "Nav_Files.Nav_ImgFile.Nav_File");
                    foreach (var item in list)
                    {
                        try
                        {
                            item.QUESTION_LEVEL_SHOW = ((BSQuestionLevelEnum)item.QUESTION_LEVEL).GetDescription();
                        }
                        catch { }
                    }
                    result.Nav_ListRiskSubmitContent = list;
                }
                else
                {
                    //(驳回)X类隐患上报
                    var notice = GetEntity<T_BS_RISK_SUBMIT_NOTICE>(guid);
                    if (notice != null && notice.RISK_SUBMIT_ID.HasValue)
                    {
                        result = GetEntity<T_BS_RISK_SUBMIT>(notice.RISK_SUBMIT_ID.Value, "Nav_Check", "Nav_Check", "Nav_CheckTypeLevel.Nav_Enums", "Nav_Files.Nav_ImgFile.Nav_File");
                        listSubContent = GetEntities<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_ID == notice.RISK_SUBMIT_ID.Value, null, "Nav_SafeCheckDetail", "Nav_ListRiskQuestionReason.Nav_RiskReason", "Nav_User", "Nav_Department", "Nav_Files.Nav_ImgFile.Nav_File", "Nav_DepartmentDeal", "Nav_UserDeal", "Nav_UserCheck");
                        foreach (var item in listSubContent)
                        {
                            item.QUESTION_LEVEL_SHOW = ((BSQuestionLevelEnum)item.QUESTION_LEVEL).GetDescription();
                            item.APPROVE_ID = notice.APPROVE_ID;//传到前端，不然审批驳回获取不到信息
                        }
                        result.Nav_ListRiskSubmitContent = listSubContent.ToList();
                    }
                }
                return result;
            });
        }


        /// <summary>
        /// 获取 隐患问题
        /// </summary>
        /// <param name="listContent"></param>
        public void GetListContentRiskQuestionReason(List<T_BS_RISK_SUBMIT_CONTENT> listContent)
        {
            if (listContent != null && listContent.Count > 0)
            {
                List<Guid> listContentID = listContent.Select(e => e.ID).ToList();
                var varContentReason = GetEntities<T_BS_RISK_SUBMIT_CONTENT_REASON>(e => listContentID.Contains(e.RISK_SUBMIT_CONTENT_ID), null, new string[] { "Nav_RiskReason" });
                if (varContentReason.Any())
                {
                    List<T_BS_RISK_SUBMIT_CONTENT_REASON> listContentReason = varContentReason.ToList();
                    foreach (var item in listContent)
                    {
                        item.Nav_ListRiskQuestionReason = listContentReason.FindAll(e => e.RISK_SUBMIT_CONTENT_ID == item.ID);
                    }
                }
            }
        }

        /// <summary>
        /// 排序分页查询数据
        /// </summary>
        /// <param name="pageFilter">分页过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("OrderPagedDistinctCheckContent")]
        public PagedActionResult<T_BS_CHECK_QUESTION> OrderPagedDistinctCheckContent([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData<T_BS_CHECK_QUESTION>((result) =>
            {
                Expression<Func<T_BS_CHECK_MAIN, bool>> expression = e => !e.IS_DELETED && e.ORG_ID == pageFilter.OrgId && e.Nav_CheckQuestion != null;
                string DESCREPTION = string.Empty;
                if (pageFilter.FilterGroup.Groups != null && pageFilter.FilterGroup.Groups.Any())
                {
                    var listGroups = pageFilter.FilterGroup.Groups.ToList();
                    if (listGroups[0].Rules.Count > 0)
                    {
                        var listRules = listGroups[0].Rules.ToList();
                        foreach (var item in listRules)
                        {
                            if (item.Field == "DESCREPTION")
                            {
                                DESCREPTION = item.Value.ToString();
                                listGroups[0].Rules.Remove(item);
                                pageFilter.FilterGroup.Groups = listGroups;
                                if (DESCREPTION.Length > 0)
                                {
                                    expression = expression.And(e => e.Nav_CheckQuestion.DESCREPTION.Contains(DESCREPTION));
                                }
                            }
                        }
                    }
                }

                var info = this.GetEntities<T_BS_CHECK_MAIN>(expression, pageFilter, null).Select(e => new { Nav_CheckQuestion = e.Nav_CheckQuestion, e.QUESTION_LEVEL }).Where(e => e.Nav_CheckQuestion != null).Distinct(e => e.Nav_CheckQuestion.ID).OrderBy(e => e.Nav_CheckQuestion.DESCREPTION);

                result.TotalCount = info.Count();
                List<T_BS_CHECK_QUESTION> listResult = new List<T_BS_CHECK_QUESTION>();

                var listResultTemp = info.Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit).ToList();
                foreach (var item in listResultTemp)
                {
                    //！！！！！！修改后 这个不要了 看着数据优化
                    //item.Nav_CheckQuestion.QUESTION_LEVEL = (BSQuestionLevelEnum)item.QUESTION_LEVEL;
                    listResult.Add(item.Nav_CheckQuestion);
                }

                //List<T_BS_CHECK_QUESTION> listTemp = new List<T_BS_CHECK_QUESTION>();
                //List<string> list = info.Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit).ToList();
                //for (int i = 0; i < list.Count; i++)
                //{
                //    listTemp = this.GetEntities<T_BS_CHECK_QUESTION>(e => e.DESCREPTION == list[i], null, new string[] { "Nav_CheckQuestion" }).OrderBy(e => e.ID).ToList();
                //    if (listTemp.Count > 0)
                //    {
                //        listResult.Add(listTemp[0]);
                //    }
                //}

                result.Data = listResult;
            });
        }

        ///// <summary>
        ///// 排序分页查询数据
        ///// </summary>
        ///// <param name="pageFilter">分页过滤实体</param>
        ///// <returns></returns>
        //[HttpPost, Route("OrderPagedDistinctCheckContent")]
        //public PagedActionResult<T_BS_CHECK_MAIN> OrderPagedDistinctCheckContent([FromBody] KeywordPageFilter pageFilter)
        //{
        //    return SafeGetPagedData<T_BS_CHECK_MAIN>((result) =>
        //    {
        //        Expression<Func<T_BS_CHECK_MAIN, bool>> expression = e => !e.IS_DELETED && e.ORG_ID == pageFilter.OrgId;
        //        var info = this.GetEntities<T_BS_CHECK_MAIN>(expression, pageFilter, new string[] { "Nav_CheckQuestion" }).Select(e => e.CHECKCONTENT).Distinct(e => e).OrderBy(e => e).ToList();
        //        result.TotalCount = info.Count;
        //        List<T_BS_CHECK_MAIN> listResult = new List<T_BS_CHECK_MAIN>();
        //        List<T_BS_CHECK_MAIN> listTemp = new List<T_BS_CHECK_MAIN>();
        //        List<string> list = info.Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit).ToList();
        //        for (int i = 0; i < list.Count; i++)
        //        {
        //            listTemp = this.GetEntities<T_BS_CHECK_MAIN>(e => e.CHECKCONTENT == list[i], null, new string[] { "Nav_CheckQuestion" }).OrderBy(e => e.ID).ToList();
        //            if (listTemp.Count > 0)
        //            {
        //                listResult.Add(listTemp[0]);
        //            }
        //        }
        //        result.Data = listResult;
        //    });
        //}

        /// <summary>
        /// 排序分页查询数据
        /// </summary>
        /// <param name="pageFilter">分页过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("OrderPagedCheckQuestion")]
        public PagedActionResult<T_BS_CHECK_QUESTION> OrderPagedCheckQuestion([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData<T_BS_CHECK_QUESTION>((result) =>
            {
                Guid SAFE_CHECK_ID = Guid.Empty;
                Expression<Func<T_BS_CHECK_MAIN, bool>> expression = e => !e.IS_DELETED;// GetExpression(pageFilter, "OrderPagedArea", out SAFE_CHECK_ID);
                var info = this.GetEntities<T_BS_CHECK_MAIN>(expression, pageFilter, new string[] { "Nav_CheckQuestion" }).Select(e => e.Nav_CheckQuestion).Distinct(e => e.ID).ToList();
                result.TotalCount = info.Count;
                result.Data = info.Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit).ToList<T_BS_CHECK_QUESTION>();
            });
        }

        /// <summary>
        /// 获取隐患上报内容
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetSubmitContent")]
        public PagedActionResult<T_BS_RISK_SUBMIT_CONTENT> GetSubmitContent([FromBody] KeywordFilter filter)
        {
            return SafeGetPagedData<T_BS_RISK_SUBMIT_CONTENT>((result) =>
            {
                Guid RISK_SUBMIT_ID = new Guid(filter.Keyword);
                Guid SAFE_CHECK_ID = new Guid(filter.Parameter1);
                //Guid LoginUserID=APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
                Expression<Func<T_BS_SAFE_CHECK_DETAIL, bool>> expression = e => e.SAFE_CHECK_ID == SAFE_CHECK_ID && !e.IS_DELETED && e.CHECKRESULT.HasValue && e.CHECKRESULT != (int)CHECKRESULTEnum.None;
                //&& e.Nav_ListCheckDetailUser.FirstOrDefault(e => e.ISMAINCHECK && e.Nav_User.ID == LoginUserID) != null;

                // 有问题都要上报 只是其他 要添加隐患库
                //var info = this.GetEntities<T_BS_SAFE_CHECK_DETAIL>(expression, null, new string[] { "Nav_CheckMain", "Nav_CheckMain.Nav_CheckQuestion", "Nav_CheckMain.Nav_RiskArea" });//2
                var info = this.GetEntities<T_BS_SAFE_CHECK_DETAIL>(expression, null, new string[] { "Nav_ListCheckDetailQuestion.Nav_Question", "Nav_CheckArea", "Nav_CheckMain", "Nav_ListCheckDetailReason.Nav_RiskReason", "Nav_Files.Nav_ImgFile.Nav_File" });

                List<Guid> listArearId = new List<Guid>();
                foreach (var item in info)
                {
                    if (!listArearId.Contains(item.RISK_AREA_ID.Value))
                    {
                        listArearId.Add(item.RISK_AREA_ID.Value);
                    }
                }
                //var listEvaluateRisk = this.GetEntities<T_HM_EVALUATE_RISK>(e => e.STATUS == 0 && e.AREA_ID.HasValue && listArearId.Contains(e.AREA_ID.Value), null, null).Distinct().ToList();

                //Dictionary<Guid, T_FM_USER> dicRiskUser = new Dictionary<Guid, T_FM_USER>();
                //T_FM_PERSON person = null;
                T_FM_USER user = null;
                //for (int i = 0; i < listEvaluateRisk.Count; i++)
                //{
                //    if (!listEvaluateRisk[i].AREA_ID.HasValue)
                //    {
                //        continue;
                //    }
                //    //person = GetEntity<T_FM_PERSON>(e => e.DEPARTMENT_ID == listEvaluateRisk[i].DEPARTMENT_LIABLE_ID && e.POST_ID == listEvaluateRisk[i].POST_LIABLE_ID, new string[] { "Nav_User.Nav_Department" });
                //    if (!dicRiskUser.ContainsKey(listEvaluateRisk[i].AREA_ID.Value))
                //    {
                //        user = GetEntity<T_FM_USER>(e => e.DEPARTMENT_ID == listEvaluateRisk[i].DEPARTMENT_LIABLE_ID && e.APPROVE_ROLE_ID == listEvaluateRisk[i].POST_LIABLE_ID, new string[] { "Nav_Department" });
                //        dicRiskUser.Add(listEvaluateRisk[i].AREA_ID.Value, user);
                //    }
                //}
                List<Guid> listQID = new List<Guid>() { new Guid("55555555-5555-5555-5555-555555555555") };
                //不能提交
                List<T_BS_RISK_SUBMIT_CONTENT> list = new List<T_BS_RISK_SUBMIT_CONTENT>();

                //责任部门
                List<T_FM_DEPARTMENT> listDep = new List<T_FM_DEPARTMENT>();
                T_FM_DEPARTMENT depCheck = null;
                Dictionary<Guid, T_FM_USER> dicDepSafer = new Dictionary<Guid, T_FM_USER>();
                if (info.Any() && info.Count() > 0)
                {
                    foreach (var item in info)
                    {
                        if (!item.DEPARTMENT_ID.HasValue)
                        {
                            continue;
                        }
                        depCheck = listDep.Find(e => e.ID == item.DEPARTMENT_ID);
                        if (depCheck == null)
                        {
                            depCheck = GetEntity<T_FM_DEPARTMENT>(item.DEPARTMENT_ID.Value, "Nav_User");
                            listDep.Add(depCheck);
                        }
                        if (depCheck == null)
                        {
                            continue;
                        }
                        foreach (var itemQ in item.Nav_ListCheckDetailQuestion)
                        {
                            if (listQID.Contains(itemQ.Nav_Question.ID))
                            {
                                continue;
                            }

                            T_BS_RISK_SUBMIT_CONTENT model = new T_BS_RISK_SUBMIT_CONTENT();

                            model.NAME = string.Empty;
                            model.CODE = string.Empty;
                            model.RISK_SUBMIT_ID = RISK_SUBMIT_ID;
                            model.CHECK_MAIN_ID = item.CHECK_MAIN_ID;
                            model.Nav_CheckMain = item.Nav_CheckMain;
                            model.REMARK = item.REMARK;

                            model.DEPARTMENT_ID = item.DEPARTMENT_ID;
                            model.Nav_Department = depCheck;
                            if (item.Nav_Files != null && item.Nav_Files.Any())
                            {
                                List<T_BS_RISK_SUBMIT_CONTENT_FILE> listFiles = new List<T_BS_RISK_SUBMIT_CONTENT_FILE>();
                                foreach (var itemF in item.Nav_Files)
                                {
                                    listFiles.Add(new T_BS_RISK_SUBMIT_CONTENT_FILE()
                                    {
                                        ID = Guid.NewGuid(),
                                        RISK_SUBMIT_ID = RISK_SUBMIT_ID,
                                        RISK_SUBMIT_CONTENT_ID = model.ID,
                                        IMG_FILE_ID = itemF.IMG_FILE_ID,
                                        Nav_ImgFile = itemF.Nav_ImgFile,
                                        IS_DELETED = false,
                                        ORG_ID = itemF.ORG_ID,
                                        //ENTITY_ORG_TPYE=itemF.ENTITY_ORG_TPYE,
                                        //FORM_ID=null,
                                        //FLOW_STATUS= itemF.FLOW_STATUS,
                                        //FLOW_SEND_STATUS=itemF.FLOW_SEND_STATUS,
                                        //FLOW_ID=itemF.FLOW_ID,
                                        //CREATE_TIME=DateTime.Now,
                                        //MODIFY_TIME=DateTime.Now,
                                        //CREATER_ID=
                                        //MODIFIER_ID
                                        //T_BS_RISK_SUBMIT_CONTENT_BACKID
                                    });
                                }
                                model.Nav_Files = listFiles;
                            }

                            //wyw1114-1
                            if (!item.CHECK_MAIN_ID.HasValue || item.CHECK_MAIN_ID.Value == Guid.Empty)
                            {
                                //检查库信息为空（手动添加组合  添加的人是谁，对应责任人就是对应隐患上报的人）
                                model.USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                                model.Nav_User = GetEntity<T_FM_USER>(model.USER_ID.Value);
                            }
                            else
                            {
                                //if (item.Nav_CheckMain.RESPONOBJECT == BSPLANCHECKOBJECTEnum.Head || item.Nav_CheckMain.RESPONOBJECT == BSPLANCHECKOBJECTEnum.ClassMonitor)
                                if (depCheck.USER_ID == depCheck.USER_ID)
                                {
                                    model.USER_ID = depCheck.USER_ID;
                                    model.Nav_User = depCheck.Nav_User;
                                }
                                else
                                {
                                    //对应的安全员
                                    if (!dicDepSafer.ContainsKey(model.DEPARTMENT_ID.Value))
                                    {
                                        var depSafer = GetEntity<T_FM_USER>(e => e.DEPARTMENT_ID == model.DEPARTMENT_ID && e.APPROVE_ROLE_ID.HasValue && e.Nav_ApproveRole.NAME.Contains("安全"), "Nav_ApproveRole");
                                        if (depSafer == null)
                                        {
                                            continue;
                                        }
                                        dicDepSafer.Add(model.DEPARTMENT_ID.Value, depSafer);
                                    }

                                    model.Nav_User = dicDepSafer[model.DEPARTMENT_ID.Value];
                                    model.USER_ID = model.Nav_User.ID;
                                }
                            }

                            //整改责任人  默认  通知责任人 
                            if (model.USER_ID.HasValue)
                            {
                                model.Nav_UserDeal = model.Nav_User;
                                model.DEAL_USER_ID = model.USER_ID.Value;

                                model.DEAL_DEPARTMENT_ID = model.DEPARTMENT_ID.Value;
                                model.Nav_DepartmentDeal = model.Nav_Department;
                            }

                            //if (item.RISK_AREA_ID.HasValue && dicRiskUser.ContainsKey(item.RISK_AREA_ID.Value) && dicRiskUser[item.RISK_AREA_ID.Value] != null)
                            //{
                            //    model.USER_ID = dicRiskUser[item.RISK_AREA_ID.Value].ID;
                            //    model.DEPARTMENT_ID = dicRiskUser[item.RISK_AREA_ID.Value].DEPARTMENT_ID;
                            //    model.Nav_User = dicRiskUser[item.RISK_AREA_ID.Value];
                            //    model.Nav_Department = dicRiskUser[item.RISK_AREA_ID.Value].Nav_Department;
                            //}
                            //else
                            //{
                            //    model.USER_ID = null;
                            //    model.DEPARTMENT_ID = null;
                            //}

                            model.Nav_SafeCheckDetail = item;
                            model.CHECK_MAIN_ID = item.CHECK_MAIN_ID;
                            model.SAFE_CHECK_ID = item.SAFE_CHECK_ID;

                            model.CHECK_PROJECT_ID = item.CHECK_PROJECT_ID;
                            //model.Nav_CheckProject = item.Nav_CheckProject;
                            model.CHECK_PROJECT_PROJECT_CATEGORY_ID = item.CHECK_PROJECT_PROJECT_CATEGORY_ID;
                            //model.Nav_CheckProjectProjectCategory = item.Nav_CheckProjectProjectCategory;

                            model.CHECK_PROJECT_CATEGORY_ID = item.CHECK_PROJECT_CATEGORY_ID;//0927

                            model.SERIOUS_RISK = item.SERIOUS_RISK;
                            model.CHECKCONTENT = item.CHECKCONTENT;

                            model.SAFE_CHECK_DETAIL_ID = model.Nav_SafeCheckDetail.ID;
                            model.QUESTION_LEVEL = item.QUESTION_LEVEL.HasValue ? item.QUESTION_LEVEL.Value : item.Nav_CheckMain.QUESTION_LEVEL;//默认等级和原来一致
                            model.QUESTION_LEVEL_SHOW = model.QUESTION_LEVEL > 0 ? ((BSQuestionLevelEnum)(model.QUESTION_LEVEL)).GetDescription() : "";//默认等级和原来一致

                            model.RISK_AREA_ID = item.RISK_AREA_ID;
                            //model.CHECK_QUESTION_ID = item.Nav_CheckMain.Nav_CheckQuestion.ID;
                            if (item.CHECKRESULT.HasValue && item.CHECKRESULT == (int)CHECKRESULTEnum.Same)
                            {
                                model.Nav_SafeCheckDetail.REMARK_RESULT = itemQ.Nav_Question.DESCREPTION;
                                model.Nav_Question = itemQ.Nav_Question;// item.Nav_CheckQuestion;
                                model.DESCREPTION = itemQ.Nav_Question.DESCREPTION;//  item.Nav_CheckQuestion.DESCREPTION;//取检查问题的 描述
                                model.DEMAND = itemQ.Nav_Question.DEMAND;//  item.Nav_CheckQuestion.DEMAND;
                                model.CHECK_QUESTION_ID = itemQ.Nav_Question.ID;//  item.Nav_CheckQuestion.ID;
                                model.PROOF = item.CHECKPROOF;
                            }
                            else
                            {
                                model.Nav_SafeCheckDetail.REMARK_RESULT = item.REMARK_RESULT;
                                model.DESCREPTION = item.REMARK_RESULT;//其他 取安全检查的 备注
                                model.DEMAND = "";
                                model.CHECK_QUESTION_ID = null;
                                model.PROOF = null;
                            }

                            model.CHECK_CONTENTS_ID = item.CHECK_CONTENTS_ID;

                            model.ADDRESS = item.ADDRESS;//隐患地点

                            int delayDays = GetDealyDays(model.QUESTION_LEVEL);
                            model.LastDateSystem = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")).AddDays(delayDays);


                            //item.Nav_ListCheckDetailReason
                            //model.Nav_ListRiskQuestionReason=
                            if (item.Nav_ListCheckDetailReason != null && item.Nav_ListCheckDetailReason.Any())
                            {
                                model.Nav_ListRiskQuestionReason = new List<T_BS_RISK_SUBMIT_CONTENT_REASON>();
                                foreach (var itemR in item.Nav_ListCheckDetailReason)
                                {
                                    model.Nav_ListRiskQuestionReason.Add(new T_BS_RISK_SUBMIT_CONTENT_REASON()
                                    {
                                        ID = Guid.NewGuid(),
                                        RISK_SUBMIT_CONTENT_ID = model.ID,
                                        Nav_RiskSubmitContent = model,
                                        Nav_RiskReason = itemR.Nav_RiskReason,
                                        RISK_REASON_ID = itemR.RISK_REASON_ID,
                                        IS_DELETED = false,
                                        ORG_ID = itemR.ORG_ID,
                                        //ENTITY_ORG_TPYE = ,
                                        //FORM_ID = ,
                                        //FLOW_STATUS = ,
                                        //FLOW_SEND_STATUS = ,
                                        //FLOW_ID = ,
                                        CREATE_TIME = DateTime.Now,
                                        MODIFY_TIME = DateTime.Now,
                                        //CREATER_ID = ,
                                        //MODIFIER_ID = ,
                                        //T_BS_RISK_SUBMIT_CONTENT_BACKID = ,

                                    });
                                }
                            }
                            list.Add(model);
                        }
                    }

                    #region   验收人 默认为 责任组织 上一级的安全员

                    var listDepID = list.Where(e => e.DEPARTMENT_ID.HasValue).Select(e => e.DEPARTMENT_ID.Value).Distinct();
                    if (listDepID != null && listDepID.Any())
                    {
                        var listDeps = GetEntities<T_FM_DEPARTMENT>(e => listDepID.Contains(e.ID), null);
                        listDepID = listDeps.Where(e => e.PARENT_ID.HasValue).Select(e => e.PARENT_ID.Value).Distinct();
                        var listRole = GetEntities<T_PF_APPROVAL_ROLE>(e => e.NAME.Contains("安全员"), null, null);
                        if (listRole != null && listRole.Any())
                        {
                            var listRoleID = listRole.Select(e => e.ID);
                            var listHeader = GetEntities<T_FM_USER>(e => listDepID.Contains(e.DEPARTMENT_ID.Value) && e.APPROVE_ROLE_ID.HasValue && listRoleID.Contains(e.APPROVE_ROLE_ID.Value), null, null);
                            if (listHeader != null && listHeader.Any())
                            {
                                foreach (var item in list)
                                {
                                    if (item.DEPARTMENT_ID.HasValue)
                                    {
                                        var depThis = listDeps.FirstOrDefault(e => e.ID == item.DEPARTMENT_ID.Value);
                                        if (depThis != null && depThis.PARENT_ID.HasValue)
                                        {
                                            T_FM_USER userTemp = listHeader.FirstOrDefault(x => x.DEPARTMENT_ID == depThis.PARENT_ID.Value);
                                            if (userTemp != null)
                                            {
                                                item.CHECK_USER_ID = userTemp.ID;
                                                item.Nav_UserCheck = userTemp;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
                result.Data = list;
            });
        }

        /// <summary>
        /// 获取 系统整改期限
        /// </summary>
        /// <param name="QUESTION_LEVEL"></param>
        /// <returns></returns>
        private int GetDealyDays(int QUESTION_LEVEL)
        {
            int delayDays = 0;
            var delays = GetEntity<T_BS_RISK_LEVEL_DELAY_DAYS>(e => e.QUESTION_LEVEL == QUESTION_LEVEL);
            if (delays != null)
            {
                delayDays = delays.MAX_DELAY_DAYS;
            }
            else
            {
                switch (QUESTION_LEVEL)
                {
                    case (int)BSQuestionLevelEnum.重大:
                        delayDays = (int)BSDelayDaysEnum.重大;
                        break;
                    case (int)BSQuestionLevelEnum.一般:
                        delayDays = (int)BSDelayDaysEnum.A;
                        break;
                        //case (int)BSQuestionLevelEnum.A:
                        //    delayDays = (int)BSDelayDaysEnum.A;
                        //    break;
                        //case (int)BSQuestionLevelEnum.B:
                        //    delayDays = (int)BSDelayDaysEnum.B;
                        //    break;
                        //case (int)BSQuestionLevelEnum.C:
                        //    delayDays = (int)BSDelayDaysEnum.C;
                        //    break;
                        //case (int)BSQuestionLevelEnum.D:
                        //    delayDays = (int)BSDelayDaysEnum.D;
                        break;
                    default:
                        break;
                }
            }
            return delayDays;
        }

        ///// <summary>
        ///// 获取隐患上报内容
        ///// </summary>
        ///// <param name="filter"></param>
        ///// <returns></returns>
        //[HttpPost, Route("GetSubmitContent")]
        //public PagedActionResult<T_BS_RISK_SUBMIT_CONTENT> GetSubmitContent([FromBody] KeywordFilter filter)
        //{
        //    return SafeGetPagedData<T_BS_RISK_SUBMIT_CONTENT>((result) =>
        //    {
        //        Guid RISK_SUBMIT_ID = new Guid(filter.Keyword);
        //        Guid SAFE_CHECK_ID = new Guid(filter.Parameter1);
        //        //Guid LoginUserID=APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
        //        Expression<Func<T_BS_SAFE_CHECK_DETAIL, bool>> expression = e => e.SAFE_CHECK_ID == SAFE_CHECK_ID && !e.IS_DELETED && e.CHECKRESULT.HasValue && e.CHECKRESULT != (int)CHECKRESULTEnum.None;
        //        //&& e.Nav_ListCheckDetailUser.FirstOrDefault(e => e.ISMAINCHECK && e.Nav_User.ID == LoginUserID) != null;

        //        // 有问题都要上报 只是其他 要添加隐患库
        //        //var info = this.GetEntities<T_BS_SAFE_CHECK_DETAIL>(expression, null, new string[] { "Nav_CheckMain", "Nav_CheckMain.Nav_CheckQuestion", "Nav_CheckMain.Nav_RiskArea" });//2
        //        var info = this.GetEntities<T_BS_SAFE_CHECK_DETAIL>(expression, null, new string[] { "Nav_ListCheckDetailQuestion.Nav_Question", "Nav_CheckArea", "Nav_CheckMain" });
        //        List<Guid> listArearId = new List<Guid>();
        //        foreach (var item in info)
        //        {
        //            if (!listArearId.Contains(item.RISK_AREA_ID.Value))
        //            {
        //                listArearId.Add(item.RISK_AREA_ID.Value);
        //            }
        //        }
        //        var listEvaluateRisk = this.GetEntities<T_HM_EVALUATE_RISK>(e => e.STATUS == 0 && e.AREA_ID.HasValue && listArearId.Contains(e.AREA_ID.Value), null, null).Distinct().ToList();

        //        Dictionary<Guid, T_FM_USER> dicRiskUser = new Dictionary<Guid, T_FM_USER>();
        //        //T_FM_PERSON person = null;
        //        T_FM_USER user = null;
        //        for (int i = 0; i < listEvaluateRisk.Count; i++)
        //        {
        //            if (!listEvaluateRisk[i].AREA_ID.HasValue)
        //            {
        //                continue;
        //            }
        //            //person = GetEntity<T_FM_PERSON>(e => e.DEPARTMENT_ID == listEvaluateRisk[i].DEPARTMENT_LIABLE_ID && e.POST_ID == listEvaluateRisk[i].POST_LIABLE_ID, new string[] { "Nav_User.Nav_Department" });
        //            if (!dicRiskUser.ContainsKey(listEvaluateRisk[i].AREA_ID.Value))
        //            {
        //                user = GetEntity<T_FM_USER>(e => e.DEPARTMENT_ID == listEvaluateRisk[i].DEPARTMENT_LIABLE_ID && e.APPROVE_ROLE_ID == listEvaluateRisk[i].POST_LIABLE_ID, new string[] { "Nav_Department" });
        //                dicRiskUser.Add(listEvaluateRisk[i].AREA_ID.Value, user);
        //            }
        //        }
        //        List<Guid> listQID = new List<Guid>() { new Guid("55555555-5555-5555-5555-555555555555") };
        //        //不能提交
        //        List<T_BS_RISK_SUBMIT_CONTENT> list = new List<T_BS_RISK_SUBMIT_CONTENT>();
        //        if (info.Any() && info.Count() > 0)
        //        {
        //            foreach (var item in info)
        //            {
        //                foreach (var itemQ in item.Nav_ListCheckDetailQuestion)
        //                {
        //                    if (listQID.Contains(itemQ.Nav_Question.ID))
        //                    {
        //                        continue;
        //                    }

        //                    T_BS_RISK_SUBMIT_CONTENT model = new T_BS_RISK_SUBMIT_CONTENT();

        //                    model.NAME = string.Empty;
        //                    model.CODE = string.Empty;
        //                    model.RISK_SUBMIT_ID = RISK_SUBMIT_ID;
        //                    model.CHECK_MAIN_ID = item.CHECK_MAIN_ID;
        //                    model.Nav_CheckMain = item.Nav_CheckMain;

        //                    if (item.RISK_AREA_ID.HasValue && dicRiskUser.ContainsKey(item.RISK_AREA_ID.Value) && dicRiskUser[item.RISK_AREA_ID.Value] != null)
        //                    {
        //                        model.USER_ID = dicRiskUser[item.RISK_AREA_ID.Value].ID;
        //                        model.DEPARTMENT_ID = dicRiskUser[item.RISK_AREA_ID.Value].DEPARTMENT_ID;
        //                        model.Nav_User = dicRiskUser[item.RISK_AREA_ID.Value];
        //                        model.Nav_Department = dicRiskUser[item.RISK_AREA_ID.Value].Nav_Department;
        //                    }
        //                    else
        //                    {
        //                        model.USER_ID = null;
        //                        model.DEPARTMENT_ID = null;
        //                    }
        //                    model.Nav_SafeCheckDetail = item;
        //                    model.CHECK_MAIN_ID = item.CHECK_MAIN_ID;
        //                    model.SAFE_CHECK_ID = item.SAFE_CHECK_ID;

        //                    model.CHECK_PROJECT_ID = item.CHECK_PROJECT_ID;
        //                    //model.Nav_CheckProject = item.Nav_CheckProject;
        //                    model.CHECK_PROJECT_PROJECT_CATEGORY_ID = item.CHECK_PROJECT_PROJECT_CATEGORY_ID;
        //                    //model.Nav_CheckProjectProjectCategory = item.Nav_CheckProjectProjectCategory;

        //                    model.CHECK_PROJECT_CATEGORY_ID = item.CHECK_PROJECT_CATEGORY_ID;//0927

        //                    model.SERIOUS_RISK = item.SERIOUS_RISK;
        //                    model.CHECKCONTENT = item.CHECKCONTENT;

        //                    model.SAFE_CHECK_DETAIL_ID = model.Nav_SafeCheckDetail.ID;
        //                    model.QUESTION_LEVEL = item.QUESTION_LEVEL.HasValue ? item.QUESTION_LEVEL.Value : item.Nav_CheckMain.QUESTION_LEVEL;//默认等级和原来一致
        //                    model.QUESTION_LEVEL_SHOW = model.QUESTION_LEVEL > 0 ? ((BSQuestionLevelEnum)(model.QUESTION_LEVEL)).GetDescription() : "";//默认等级和原来一致

        //                    model.RISK_AREA_ID = item.RISK_AREA_ID;
        //                    //model.CHECK_QUESTION_ID = item.Nav_CheckMain.Nav_CheckQuestion.ID;
        //                    if (item.CHECKRESULT.HasValue && item.CHECKRESULT == (int)CHECKRESULTEnum.Same)
        //                    {
        //                        model.Nav_SafeCheckDetail.REMARK_RESULT = itemQ.Nav_Question.DESCREPTION;
        //                        model.Nav_Question = itemQ.Nav_Question;// item.Nav_CheckQuestion;
        //                        model.DESCREPTION = itemQ.Nav_Question.DESCREPTION;//  item.Nav_CheckQuestion.DESCREPTION;//取检查问题的 描述
        //                        model.DEMAND = itemQ.Nav_Question.DEMAND;//  item.Nav_CheckQuestion.DEMAND;
        //                        model.CHECK_QUESTION_ID = itemQ.Nav_Question.ID;//  item.Nav_CheckQuestion.ID;
        //                        model.PROOF = item.CHECKPROOF;
        //                    }
        //                    else
        //                    {
        //                        model.Nav_SafeCheckDetail.REMARK_RESULT = item.REMARK_RESULT;
        //                        model.DESCREPTION = item.REMARK_RESULT;//其他 取安全检查的 备注
        //                        model.DEMAND = "";
        //                        model.CHECK_QUESTION_ID = null;
        //                        model.PROOF = null;
        //                    }
        //                    list.Add(model);
        //                }
        //            }
        //        }
        //        result.Data = list;
        //    });
        //}

        /// <summary>
        /// 获取辨识区域 通知责任人和责任部门
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetRiskAreaMaster")]
        public JsonActionResult<T_FM_USER> GetRiskAreaMaster([FromBody] KeywordFilter filter)
        {
            return SafeExecute<T_FM_USER>(() =>
            {
                if (string.IsNullOrEmpty(filter.Keyword))
                {
                    return null;
                }
                var AreadID = new Guid(filter.Keyword);
                var evaluateRisk = this.GetEntity<T_HM_EVALUATE_RISK>(e => e.STATUS == 0 && e.AREA_ID.HasValue && AreadID == e.AREA_ID.Value);
                if (evaluateRisk == null)
                {
                    return null;
                }
                var user = GetEntity<T_FM_USER>(e => e.DEPARTMENT_ID == evaluateRisk.DEPARTMENT_LIABLE_ID && e.APPROVE_ROLE_ID == evaluateRisk.POST_LIABLE_ID, new string[] { "Nav_Department" });
                return user;
            });
        }

        /// <summary>
        /// 隐患上报  更新
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdateOld")]
        public JsonActionResult<bool> FullUpdateOld([FromBody] T_BS_RISK_SUBMIT entity)
        {
            return SafeExecute<bool>(() =>
            {
                if (string.IsNullOrEmpty(entity.CODE))
                {
                    entity.CODE = "YHSB" + DateTime.Now.ToString("yyyyMMddHHmm");
                }

                var files = entity.Nav_Files;
                entity.Nav_Files = null;

                //附件
                List<T_BS_RISK_SUBMIT_CONTENT_FILE> listContentFile = new List<T_BS_RISK_SUBMIT_CONTENT_FILE>();

                var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;
                entity.Nav_ListRiskSubmitContent = null;
                if (listRiskSubminContentl == null || listRiskSubminContentl.Count < 1)
                {
                    throw new Exception("隐患上报明细不能为空！");
                }

                #region     数据完整性判断

                if (!entity.CHECK_ID.HasValue)
                {
                    #region    手动上报

                    if (entity.SUBMIT_STATUS != (int)BSSubmitStatusEnum.Temp)
                    {
                        //手动上报
                        if (!entity.CHECK_TYPE_ID.HasValue)
                        {
                            throw new Exception("请选择检查类型！");
                        }
                        if (!entity.CHECK_TYPE_LEVEL_ID.HasValue)
                        {
                            throw new Exception("请选择检查层级！");
                        }
                        if (files == null)
                        {
                            throw new Exception("请上传附件，手动上报必须上传附件！");
                        }
                        for (int i = 0; i < listRiskSubminContentl.Count(); i++)
                        {
                            if (string.IsNullOrEmpty(listRiskSubminContentl[i].DESCREPTION))
                            {
                                throw new Exception("行【" + (i + 1) + "】检查问题不能为空！");
                            }
                            if (listRiskSubminContentl[i].QUESTION_LEVEL == 0)
                            {
                                throw new Exception("行【" + (i + 1) + "】问题等级不能为空！");
                            }
                            if (string.IsNullOrEmpty(listRiskSubminContentl[i].DEMAND))
                            {
                                throw new Exception("行【" + (i + 1) + "】整改建议与措施不能为空！");
                            }

                            //改版没了
                            //if (listRiskSubminContentl[i].Nav_ListRiskQuestionReason == null)
                            //{
                            //    throw new Exception("行【" + (i + 1) + "】隐患原因不能为空！");
                            //}

                            if (string.IsNullOrEmpty(listRiskSubminContentl[i].ADDRESS))
                            {
                                throw new Exception("行【" + (i + 1) + "】隐患地点不能为空！");
                            }

                            //if (string.IsNullOrEmpty(listRiskSubminContentl[i].Nav_User.NAME))
                            if (listRiskSubminContentl[i].USER_ID == null || listRiskSubminContentl[i].USER_ID == Guid.Empty)
                            {
                                throw new Exception("行【" + (i + 1) + "】通知责任人不能为空！");
                            }
                            //if (string.IsNullOrEmpty(listRiskSubminContentl[i].Nav_Department.NAME))
                            if (listRiskSubminContentl[i].DEPARTMENT_ID == null || listRiskSubminContentl[i].DEPARTMENT_ID == Guid.Empty)
                            {
                                throw new Exception("行【" + (i + 1) + "】责任单位不能为空！");
                            }
                        }
                    }

                    entity.SUBMIT_TYPE = (int)SUBMIT_TYPE.User;
                    if (!entity.CHECKTIME.HasValue)
                    {
                        entity.CHECKTIME = DateTime.Now;
                    }

                    #endregion
                }
                else
                {
                    if (entity.SUBMIT_STATUS != (int)BSSubmitStatusEnum.Temp)
                    {
                        for (int i = 0; i < listRiskSubminContentl.Count(); i++)
                        {
                            if (listRiskSubminContentl[i].Nav_ListRiskQuestionReason == null)
                            {
                                throw new Exception("行【" + (i + 1) + "】隐患原因不能为空！");
                            }
                            if (string.IsNullOrEmpty(listRiskSubminContentl[i].ADDRESS))
                            {
                                throw new Exception("行【" + (i + 1) + "】隐患地点不能为空！");
                            }

                            if (listRiskSubminContentl[i].USER_ID == null || listRiskSubminContentl[i].USER_ID == Guid.Empty)
                            {
                                throw new Exception("行【" + (i + 1) + "】通知责任人不能为空！");
                            }
                            if (listRiskSubminContentl[i].DEPARTMENT_ID == null || listRiskSubminContentl[i].DEPARTMENT_ID == Guid.Empty)
                            {
                                throw new Exception("行【" + (i + 1) + "】责任单位不能为空！");
                            }

                            if (!listRiskSubminContentl[i].CHECK_QUESTION_ID.HasValue || string.IsNullOrEmpty(listRiskSubminContentl[i].DEMAND))
                            {
                                throw new Exception("行【" + (i + 1) + "】整改建议与措施不能为空！");
                            }
                        }


                    }
                }

                #endregion

                //安全检查修改为隐患已上报
                T_BS_SAFE_CHECK modelCheck = null;
                if (entity.CHECK_ID.HasValue)
                {
                    modelCheck = this.GetEntity<T_BS_SAFE_CHECK>(entity.CHECK_ID.Value, new string[] { "Nav_ListSafeCheckDetail" });
                    if (modelCheck != null)
                        modelCheck.RISKSTATE = (int)RISKSTATE.Reported;
                }

                List<T_BS_RISK_SUBMIT_CONTENT_REASON> listSubmitContentReason = new List<T_BS_RISK_SUBMIT_CONTENT_REASON>();
                List<Guid> listApproveId = new List<Guid>();
                List<Guid> listId = new List<Guid>();
                List<string> listParam = new List<string>();

                List<Guid> ListDepIDNone = new List<Guid>(); //责任部门ID
                //通知表单
                List<T_BS_RISK_SUBMIT_NOTICE> listSubmitNotice = new List<T_BS_RISK_SUBMIT_NOTICE>();
                int rowIndex = 0;
                if (listRiskSubminContentl.Any() && listRiskSubminContentl.Count > 0)
                {
                    foreach (var item in listRiskSubminContentl)
                    {
                        rowIndex++;
                        if (item.DEPARTMENT_ID.HasValue)
                        {
                            ListDepIDNone.Add(item.DEPARTMENT_ID.Value);
                        }
                        else
                        {
                            ListDepIDNone.Add(Guid.Empty);
                        }

                        if (item.Nav_Files != null && item.Nav_Files.Any())
                        {
                            listContentFile.AddRange(item.Nav_Files);
                        }
                        //foreach (var itemCheckMain in modelCheck.Nav_ListSafeCheckDetail)
                        //{
                        //    if (item.CHECK_MAIN_ID == itemCheckMain.CHECK_MAIN_ID && item.QUESTION_LEVEL == 0)
                        //    {
                        //        //不会进来
                        //        item.QUESTION_LEVEL = itemCheckMain.QUESTION_LEVEL.HasValue ? itemCheckMain.QUESTION_LEVEL.Value : ((int)BSQuestionLevelEnum.D);
                        //    }
                        //}
                        if (entity.SUBMIT_STATUS != (int)BSSubmitStatusEnum.Temp)
                        {
                            if (!listParam.Contains(item.QUESTION_LEVEL.ToString()))
                            {
                                #region      不包含此等级 添加通知

                                T_BS_RISK_SUBMIT_NOTICE modelNotice = new T_BS_RISK_SUBMIT_NOTICE();

                                modelNotice.ID = Guid.NewGuid();
                                modelNotice.CODE = entity.CODE + "_" + (listParam.Count() + 1).ToString();
                                modelNotice.NAME = entity.NAME + ((BSQuestionLevelEnum)item.QUESTION_LEVEL).GetDescription();
                                modelNotice.RISK_SUBMIT_ID = item.RISK_SUBMIT_ID.Value;
                                modelNotice.QUESTION_LEVEL = item.QUESTION_LEVEL;
                                modelNotice.NOTICETIME = DateTime.Now;
                                modelNotice.RiskContentState = (int)RiskContentState.Notice;
                                modelNotice.APPROVE_ID = Guid.NewGuid();
                                modelNotice.ORG_ID = item.ORG_ID;

                                #endregion

                                listSubmitNotice.Add(modelNotice);

                                item.APPROVE_ID = modelNotice.APPROVE_ID;
                                item.RISK_SUBMIT_NOTICE_ID = modelNotice.ID;

                                listId.Add(modelNotice.ID);
                                listParam.Add(modelNotice.QUESTION_LEVEL.ToString());
                                listApproveId.Add(modelNotice.APPROVE_ID.Value);

                            }
                            else
                            {
                                //有此隐患等级//查找对应等级的审核表信息
                                item.APPROVE_ID = listSubmitNotice.First(e => e.QUESTION_LEVEL == item.QUESTION_LEVEL).APPROVE_ID;
                                item.RISK_SUBMIT_NOTICE_ID = listSubmitNotice.First(e => e.QUESTION_LEVEL == item.QUESTION_LEVEL).ID;
                            }
                        }

                        if (item.Nav_ListRiskQuestionReason != null && item.Nav_ListRiskQuestionReason.Any())
                        {
                            foreach (var item2 in item.Nav_ListRiskQuestionReason)
                            {
                                item2.ORG_ID = entity.ORG_ID;
                            }
                            listSubmitContentReason.AddRange(item.Nav_ListRiskQuestionReason);
                        }

                        //如果 有问题ID 
                        //问题等级 和 整改建议与措施 不能修改
                        if (item.Nav_SafeCheckDetail == null && item.SAFE_CHECK_DETAIL_ID != null)
                        {
                            item.Nav_SafeCheckDetail = GetEntity<T_BS_SAFE_CHECK_DETAIL>(e => e.ID == item.SAFE_CHECK_DETAIL_ID);
                        }

                        if (item.Nav_SafeCheckDetail != null && item.Nav_SafeCheckDetail.CHECKRESULT == (int)CHECKRESULTEnum.Same)
                        {
                            if (item.Nav_CheckMain == null && item.CHECK_MAIN_ID.HasValue)
                            {
                                item.Nav_CheckMain = GetEntity<T_BS_CHECK_MAIN>(e => e.ID == item.CHECK_MAIN_ID, new string[] { "Nav_CheckQuestion" });
                            }
                            if (item.Nav_CheckMain != null && item.Nav_CheckMain.Nav_CheckQuestion != null)
                            {
                                if (item.CHECK_QUESTION_ID != item.Nav_CheckMain.Nav_CheckQuestion.ID)
                                {
                                    var checkMain = GetEntity<T_BS_CHECK_MAIN>(e => e.CHECK_QUESTION_ID == item.CHECK_QUESTION_ID && e.CHECK_PROJECT_ID == item.Nav_CheckMain.CHECK_PROJECT_ID && e.CHECK_PROJECT_CATEGORY_ID == item.Nav_CheckMain.CHECK_PROJECT_CATEGORY_ID && e.CHECK_PROJECT_CATEGORY_ID == item.Nav_CheckMain.CHECK_PROJECT_CATEGORY_ID && e.CHECKCONTENT == item.Nav_CheckMain.CHECKCONTENT);
                                    if (checkMain == null)
                                    {
                                        //检查问题与描述一致 检查问题不能修改
                                        throw new Exception("行号：【" + rowIndex.ToString() + "】的整改建议与措施【" + item.Nav_CheckMain.Nav_CheckQuestion.DEMAND + "】不能修改，操作失败！");
                                    }
                                }
                            }

                        }

                        //if (item.CHECK_QUESTION_ID.HasValue)
                        //{
                        //    if (item.Nav_Question == null)
                        //    {
                        //        item.Nav_Question = GetEntity<T_BS_CHECK_QUESTION>(item.CHECK_QUESTION_ID.Value);
                        //    }
                        //    if (item.DEMAND.Trim() != item.Nav_Question.DEMAND.Trim())
                        //    {
                        //        throw new Exception("行号：【" + rowIndex.ToString() + "】的整改建议与措施【" + item.Nav_Question.DEMAND + "】不能修改，操作失败！");
                        //    }
                        //}
                    }
                }

                entity.USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (entity.DEPARTMENT_ID == null)
                {
                    entity.DEPARTMENT_ID = GetEntity<T_FM_USER>(entity.USER_ID.Value).DEPARTMENT_ID;
                }
                if (entity.TaskID != Guid.Empty && !entity.STARTTIME.HasValue)
                {
                    var task = GetEntity<T_FM_NOTIFICATION_TASK>(entity.TaskID);
                    entity.STARTTIME = task.CREATE_TIME;
                }
                if (listContentFile.Count > 0)
                {
                    foreach (var item in listContentFile)
                    {
                        item.Nav_ImgFile = null;
                        item.RISK_SUBMIT_ID = entity.ID;
                    }
                }

                if (entity.SUBMIT_STATUS == (int)BSSubmitStatusEnum.Temp)
                {
                    this.UnifiedCommit(() =>
                    {
                        if (entity != null)
                            UpdateEntityNoCommit(entity);
                        if (modelCheck != null)
                            UpdateEntityNoCommit(modelCheck);
                        if (files != null && files.Any())
                            BantchSaveEntityNoCommit(files);
                        if (listContentFile != null && listContentFile.Any())
                            BantchSaveEntityNoCommit(listContentFile);
                        if (listRiskSubminContentl != null && listRiskSubminContentl.Any())
                            BantchSaveEntityNoCommit(listRiskSubminContentl);
                        if (listSubmitContentReason.Any())
                            BantchSaveEntityNoCommit(listSubmitContentReason);
                    });
                }
                else
                {

                    List<string> listSerialCode = new List<string>();
                    var index = entity.CODE.IndexOf(DateTime.Now.Year.ToString());
                    string yearMonth = string.Empty;
                    //if (index > 0)
                    //{
                    yearMonth = entity.CODE.Substring(index);
                    //}
                    //else
                    //{
                    yearMonth = DateTime.Now.ToString("yyyyMMddHHmmss");
                    //}

                    string code = "YHSB" + yearMonth;

                    listSerialCode.Add(code);
                    if (listParam.Count > 1)
                    {
                        for (int i = 1; i < listParam.Count; i++)
                        {
                            listSerialCode.Add(code + i.ToString());
                        }
                    }

                    //??????
                    ////给通知责任人 发送通知
                    ////通知责任人 确定 后  走审批流
                    MFlowPermitService.InsertApproveRisk(listSerialCode, "BS006", listId, "BS006_SHOWPRINT", entity.TaskID, true, () =>
                    {
                        if (entity != null)
                            UpdateEntityNoCommit(entity);
                        if (listSubmitNotice.Any())
                            BantchSaveEntityNoCommit(listSubmitNotice);
                        if (modelCheck != null)
                            UpdateEntityNoCommit(modelCheck);
                        if (files != null && files.Any())
                            BantchSaveEntityNoCommit(files);
                        if (listContentFile != null && listContentFile.Any())
                            BantchSaveEntityNoCommit(listContentFile);
                        if (listRiskSubminContentl != null && listRiskSubminContentl.Any())
                            BantchSaveEntityNoCommit(listRiskSubminContentl);
                        if (listSubmitContentReason.Any())
                            BantchSaveEntityNoCommit(listSubmitContentReason);
                    }, listParam, listApproveId, null, "BS006_VIEW", null, ListDepIDNone, FMTASKTYPE.BS_RiskUp_Audit);
                }
                return true;
            });
        }

        /// <summary>
        /// 数据删除
        /// </summary>
        /// <param name="id">过滤实体</param>
        /// <returns></returns>
        [HttpGet, Route("FullDelete")]
        public JsonActionResult<bool> FullDelete(string id)
        {
            return SafeExecute<bool>(() =>
            {
                //删除审批流
                //删除明细
                //删除主表
                //更新检查的状态

                Guid submitID = new Guid(id);
                string[] path = { "Nav_ListRiskSubmitContent", "Nav_ListRiskSubmitContent.Nav_ListRiskQuestionReason", "Nav_ListRiskSubmitContent.Nav_ApproveCheckAudit", "Nav_ListRiskSubmitContent.Nav_SubmitNoticePerson", "Nav_Files" };
                T_BS_RISK_SUBMIT entity = GetEntity<T_BS_RISK_SUBMIT>(t => t.ID == submitID, false, path);
                T_BS_SAFE_CHECK entityCheck = GetEntity<T_BS_SAFE_CHECK>(t => t.ID == entity.CHECK_ID, false, null);
                if (entityCheck != null)
                {
                    entityCheck.RISKSTATE = (int)RISKSTATE.NeedReport;
                }
                List<Guid> listSubmitContentID = new List<Guid>();
                List<Guid> listApproveId = new List<Guid>();
                List<Guid> listApproveDetailId = new List<Guid>();
                List<Guid> filesIds = new List<Guid>();
                List<Guid> listSubmitContentResionID = new List<Guid>();
                List<Guid> listNoticeID = new List<Guid>();
                List<Guid> listNoticePersonID = new List<Guid>();
                if (entity.Nav_ListRiskSubmitContent != null && entity.Nav_ListRiskSubmitContent.Count > 0)
                {
                    foreach (var item in entity.Nav_ListRiskSubmitContent)
                    {
                        if (item.Nav_ListRiskQuestionReason != null && item.Nav_ListRiskQuestionReason.Count > 0)
                        {
                            listNoticePersonID.AddRange(item.Nav_ListRiskQuestionReason.Select(e => e.ID));
                        }
                    }
                }

                foreach (var item in entity.Nav_ListRiskSubmitContent)
                {
                    listSubmitContentID.Add(item.ID);
                    if (item.APPROVE_ID.HasValue)
                    {
                        listApproveId.Add(item.APPROVE_ID.Value);
                    }
                    if (item.Nav_ListRiskQuestionReason != null && item.Nav_ListRiskQuestionReason.Any())
                    {
                        listSubmitContentResionID.AddRange(item.Nav_ListRiskQuestionReason.Select(e => e.ID));
                    }
                }

                var listApproveDetail = this.GetEntities<T_PF_APPROVE_DETAIL>(t => listApproveId.Contains(t.APPROVE_ID), null, null);
                if (listApproveDetail != null && listApproveDetail.Any())
                {
                    listApproveDetailId = listApproveDetail.Select(e => e.ID).ToList();
                }

                if (entity.Nav_Files != null && entity.Nav_Files.Any())
                {
                    var filesIdsList = entity.Nav_Files.Select(t => t.ID).ToList();
                    filesIds.AddRange(filesIdsList);
                }

                var listNotice = this.GetEntities<T_BS_RISK_SUBMIT_NOTICE>(t => t.RISK_SUBMIT_ID == entity.ID, null, null);
                if (listNotice != null && listNotice.Any())
                {
                    listNoticeID.AddRange(listNotice.Select(e => e.ID));
                }
                UnifiedCommit(() =>
                {
                    if (filesIds.Any())
                        this.BantchDeleteEntityNoCommit<T_BS_RISK_SUBMIT_FILE>(filesIds);
                    if (listApproveDetailId.Count > 0)
                        this.BantchDeleteEntityNoCommit<T_PF_APPROVE_DETAIL>(listApproveDetailId);
                    if (listApproveId.Count > 0)
                        this.BantchDeleteEntityNoCommit<T_PF_APPROVE>(listApproveId);
                    if (listSubmitContentResionID.Count > 0)
                        this.BantchDeleteEntityNoCommit<T_BS_RISK_SUBMIT_CONTENT_REASON>(listSubmitContentResionID);
                    if (listSubmitContentID.Count > 0)
                        this.BantchDeleteEntityNoCommit<T_BS_RISK_SUBMIT_CONTENT>(listSubmitContentID);
                    if (listNoticePersonID.Count > 0)
                        this.BantchDeleteEntityNoCommit<T_BS_RISK_SUBMIT_NOTICE_PERSON>(listNoticePersonID);
                    if (listNoticeID.Count > 0)
                        this.BantchDeleteEntityNoCommit<T_BS_RISK_SUBMIT_NOTICE>(listNoticeID);
                    if (entity != null)
                        this.DeleteEntityNoCommit(entity);
                    if (entityCheck != null)
                        UpdateEntity(entityCheck);
                });

                return true;
            });
        }

        #endregion


        #region    隐患整改通知



        /// <summary>
        /// 隐患上报 审核通过 给每个通知负责人发送通知
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet, Route("Notice")]
        public JsonActionResult<bool> Notice(string id)
        {
            return SafeExecute<bool>(() =>
            {
                return ApproveCallBackService.CallBack("BS/BSRiskSubmit/Notice", id);
            });
        }

        /// <summary>
        /// 获取部门和部门审批流负责人
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDpartMentNameHeader")]
        public PagedActionResult<T_FM_DEPARTMENT> GetDpartMentNameHeader([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData<T_FM_DEPARTMENT>((result) =>
            {
                Expression<Func<T_FM_DEPARTMENT, bool>> expression = e => !e.IS_DELETED && e.ORG_ID == pageFilter.OrgId;
                List<T_FM_DEPARTMENT> listDepartment = this.GetEntities<T_FM_DEPARTMENT>(expression, pageFilter, new string[] { "Nav_User" }).ToList();
                if (listDepartment != null && listDepartment.Count() > 0)
                {
                    List<Guid> listDepID = listDepartment.Select(x => x.ID).ToList();
                    List<Guid> listRoleID = new List<Guid>();
                    List<T_PF_APPROVAL_ROLE> listRole = GetEntities<T_PF_APPROVAL_ROLE>(e => e.NAME.Contains("负责人"), null, null).ToList();
                    listRoleID = listRole.Select(e => e.ID).ToList();
                    if (listDepID.Count > 0 && listRoleID.Count > 0)
                    {
                        var listHeader = GetEntities<T_FM_USER>(e => listDepID.Contains(e.DEPARTMENT_ID.Value) && e.APPROVE_ROLE_ID.HasValue && listRoleID.Contains(e.APPROVE_ROLE_ID.Value), null, null);
                        T_FM_USER userTemp = null;
                        foreach (var item in listDepartment)
                        {
                            userTemp = listHeader.FirstOrDefault(x => x.DEPARTMENT_ID == item.ID);
                            if (userTemp != null)
                                item.Nav_User = userTemp;
                        }
                    }
                }
                result.TotalCount = listDepartment.Count;
                result.Data = listDepartment;
            });
        }


        /// <summary>
        /// 获取 验收人
        /// </summary>
        /// <param name="pageFilter">分页过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("GetChcker")]
        public PagedActionResult<T_FM_USER> GetChcker([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData<T_FM_USER>((result) =>
            {
                List<FilterRule> listRules = pageFilter.FilterGroup.Rules.ToList();
                //验收人 发起部门 人员

                Guid SubmitID = Guid.Empty;
                foreach (var item in listRules)
                {
                    if (item.Field == "RISK_SUBMIT_ID")
                    {
                        SubmitID = new Guid(item.Value.ToString());
                    }
                }
                Guid LoginUserID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
                Guid LoginDEPARTMENT_ID = GetEntity<T_FM_USER>(LoginUserID).DEPARTMENT_ID.Value;

                //T_BS_RISK_SUBMIT modelSubmit = null;
                //if (SubmitID != Guid.Empty)
                //{
                //    modelSubmit = GetEntity<T_BS_RISK_SUBMIT>(SubmitID);
                //}
                //if (modelSubmit.SUBMIT_TYPE == (int)SUBMIT_TYPE.Check && modelSubmit != null)
                //{
                //    //检查上报 
                //    //"点选（在发起部门内） 通知给验收进行签字"
                //}

                Expression<Func<T_FM_USER, bool>> expression = e => !e.IS_DELETED && e.ORG_ID == pageFilter.OrgId;
                expression = expression.And(e => e.DEPARTMENT_ID == LoginDEPARTMENT_ID || (e.Nav_Department != null && e.Nav_Department.Nav_Parent.ID == LoginDEPARTMENT_ID) || (e.Nav_Department.Nav_Parent != null && e.Nav_Department.Nav_Parent.Nav_Parent.ID == LoginDEPARTMENT_ID));

                List<T_FM_USER> listResult = new List<T_FM_USER>();
                var info = this.GetEntities<T_FM_USER>(expression, pageFilter, new string[] { "Nav_Department.Nav_Parent.Nav_Parent" }).Distinct().OrderBy(e => e.NAME);
                result.TotalCount = info.Count();
                listResult = info.Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit).ToList();
                result.Data = listResult;
            });
        }


        /// <summary>
        /// 通知保存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdateNoticePerson")]
        public JsonActionResult<bool> FullUpdateNoticePerson([FromBody] T_BS_RISK_SUBMIT_NOTICE_PERSON entity)
        {
            return SafeExecute<bool>(() =>
            {
                //判断每行数据 整改期限 不能大于 系统整改期限
                //整改建议与措施不能未空
                //整改责任人和 验收人 发送整改通知单  
                //每条明细 发送隐患整改记录单
                ////查找审批流（整改责任人和验收人合并一样发一个审批流 审批流结束给每个隐患明细发送待办 ）


                var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;
                entity.Nav_ListRiskSubmitContent = null;

                if (listRiskSubminContentl == null || listRiskSubminContentl.Count < 1)
                {
                    throw new Exception("隐患通知明细不能为空!");
                }

                if (listRiskSubminContentl[0].RiskContentState == (int)RiskContentState.ArrangeDeal)
                {
                    throw new Exception("该整改信息已经设置过整改期限，并通知相关整改、验收人员，操作失败!");
                }

                if (entity.OPERATETYPE == OperateType.Temp)
                {
                    //保存行信息
                    this.UnifiedCommit(() =>
                    {
                        UpdateEntityNoCommit(entity);//保存状态
                        if (listRiskSubminContentl != null && listRiskSubminContentl.Any())//隐患上报明细表
                            BantchSaveEntity(listRiskSubminContentl);    //保存子表
                    });
                }
                else
                {
                    //List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();
                    List<Guid> ListNoticeAll = new List<Guid>();//整改责任人、验收人 去重
                    List<string> ListNoticeAllNAME = new List<string>();//整改责任人、验收人 去重

                    DateTime dtNow = DateTime.Now;
                    DateTime dtDeal = dtNow.AddMinutes(1);//控制时间 先看整体的通知 再看到处理单
                    string UserDealNAME = string.Empty;
                    //List<T_BS_RISK_SUBMIT_CONTENT_DEAL> listContentDeal = new List<T_BS_RISK_SUBMIT_CONTENT_DEAL>();
                    //T_BS_RISK_SUBMIT_CONTENT_DEAL dealTemp = null;
                    int CodeTemp = 1;
                    foreach (var item in listRiskSubminContentl)
                    {
                        if (!item.CHECK_MAIN_ID.HasValue)
                        {
                            if (!item.CHECK_PROJECT_ID.HasValue)
                                throw new Exception("请填写行【" + CodeTemp + "】检查项目!");
                            if (!item.CHECK_PROJECT_CATEGORY_ID.HasValue)
                                throw new Exception("请填写行【" + CodeTemp + "】检查项目分类!");
                        }

                        if (string.IsNullOrEmpty(item.DEMAND))
                            throw new Exception("请填写行【" + CodeTemp + "】整改建议与措施!");
                        if (item.LastDateUser == null)
                            throw new Exception("请填写行【" + CodeTemp + "】整改期限!");
                        if (item.DEAL_USER_ID == null)
                            throw new Exception("请填写行【" + CodeTemp + "】整改责任人!");
                        if (item.CHECK_USER_ID == null)
                            throw new Exception("请填写行【" + CodeTemp + "】验收人!");

                        if (item.LastDateUser > item.LastDateSystem)
                            throw new Exception("整改期限【" + item.LastDateUser + "】不能大于系统整改期限【" + item.LastDateSystem + "】!");
                        else if (item.LastDateUser < DateTime.Now.Date)
                            throw new Exception("整改期限【" + item.LastDateUser + "】不能小于当天!");
                        //数据处理

                        //item.ACTUAL_DEAL_USER_ID = item.DEAL_USER_ID;//整改落实人默认  整改责任人
                        //item.RiskContentState = (int)RiskContentState.ArrangeDeal;
                        if (item.DEAL_USER_ID.Value == item.CHECK_USER_ID.Value)
                        {
                            throw new Exception("行【" + CodeTemp + "】整改责任人和验收人不能同一个人!");
                        }

                        #region    获取通知人员信息
                        //只给验收人发送通知  待验收人【通过】后才能给整改责任人 【确认】

                        //if (item.DEAL_USER_ID != null && !ListNoticeAll.Contains(item.DEAL_USER_ID.Value))
                        //{
                        //    //整改责任人
                        //    ListNoticeAll.Add(item.DEAL_USER_ID.Value);
                        //    //数量少 每次获取 页面能选 这边就不会报错
                        //    UserDealNAME = this.GetEntity<T_FM_USER>(item.DEAL_USER_ID.Value).NAME;
                        //    ListNoticeAllNAME.Add(UserDealNAME);
                        //}

                        if (item.CHECK_USER_ID != null && !ListNoticeAll.Contains(item.CHECK_USER_ID.Value))
                        {
                            //验收人
                            ListNoticeAll.Add(item.CHECK_USER_ID.Value);
                            //数量少 每次获取 页面能选 这边就不会报错
                            ListNoticeAllNAME.Add(this.GetEntity<T_FM_USER>(item.CHECK_USER_ID.Value).NAME);
                        }

                        item.LastDateUser = item.LastDateUser.Value.Date.AddDays(1).AddSeconds(-1);
                        item.LastDateSystem = item.LastDateSystem.Value.Date.AddDays(1).AddSeconds(-1);

                        #endregion

                        //#region     隐患整改通知

                        //dealTemp = new T_BS_RISK_SUBMIT_CONTENT_DEAL();
                        //dealTemp.ID = Guid.NewGuid();
                        //dealTemp.ORG_ID = item.ORG_ID;
                        //dealTemp.RISK_SUBMIT_ID = item.RISK_SUBMIT_ID;
                        //dealTemp.RISK_SUBMIT_NOTICE_ID = item.RISK_SUBMIT_NOTICE_ID;
                        //dealTemp.RISK_SUBMIT_NOTICE_PERSON_ID = item.RISK_SUBMIT_NOTICE_PERSON_ID;
                        //dealTemp.RISK_SUBMIT_CONTENT_ID = item.ID;

                        //dealTemp.CODE = item.CODE + "_" + CodeTemp;


                        //dealTemp.NAME = item.NAME.Replace("隐患整改通知：", "");
                        ////dealTemp.ENDDATE = item.LastDateUser;//整改结束时间   
                        //dealTemp.QUESTION_LEVEL = item.QUESTION_LEVEL;
                        //dealTemp.DEALSITUATION = (int)DealSituation.Notice;
                        //dealTemp.DEAL_USER_ID = item.DEAL_USER_ID;
                        //dealTemp.ACTUAL_DEAL_USER_ID = item.ACTUAL_DEAL_USER_ID;
                        //dealTemp.CHECK_USER_ID = item.CHECK_USER_ID;

                        //listContentDeal.Add(dealTemp);

                        //#endregion

                        //每个整改责任人 收到待办
                        //var notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改单：" + dealTemp.NAME, dealTemp.ID, entity.ORG_ID, item.DEAL_USER_ID.Value, UserDealNAME, dtDeal, item.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044");
                        //notice.CREATE_TIME = dtDeal;
                        //listNoticeDeal.Add(notice);
                        CodeTemp++;
                    }
                    T_FM_NOTIFICATION_TASK task = null;
                    GetEntityTask(entity.TaskID, ref task, "BS042_SHOWPRINT");

                    //查看整体的通知单
                    var listNotice = NotificationTaskService.InsertUserNoticeTaskModels(entity.NAME, entity.ID, entity.ORG_ID, ListNoticeAll, ListNoticeAllNAME, dtNow, dtNow.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS042_SHOWPRINT");//HM001_SHOWPRINT
                    listNotice.ForEach(item => item.CREATE_TIME = dtNow);

                    //保存隐患明细中指定信息
                    //给对应的人发送通知 可能多条明细(BS042ShowPrint)
                    //逐条给责任整改人发送整改记录待办(BS044)

                    this.UnifiedCommit(() =>
                    {
                        UpdateEntityNoCommit(entity);//保存状态
                        //if (listContentDeal.Count > 0)
                        //    BantchSaveEntity(listContentDeal);//保存待整改明细
                        if (listRiskSubminContentl != null && listRiskSubminContentl.Any())//隐患上报明细表
                            BantchSaveEntity(listRiskSubminContentl);    //保存子表
                        if (listNotice != null && listNotice.Any())//每个整改责任人和验收人 都收到这个整改安排
                            BantchSaveEntity<T_FM_NOTIFICATION_TASK>(listNotice);
                        //if (listNoticeDeal != null && listNoticeDeal.Any())//整改责任人 按条数 收到整改单
                        //    BantchSaveEntity<T_FM_NOTIFICATION_TASK>(listNoticeDeal);
                        if (task != null)//代办消息 清除
                            UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    });
                }
                return true;
            });
        }

        #region       验收人确认 、整改责任人  流程顺序互换

        /// <summary>
        /// 整改责任人、验收人 确定（给责任人 发送通知 ）  驳回 （隐患通知责任人）发送通知 （BS042）
        /// 原: 整改责任人、验收人 确定   后面确定 的人 添加 待办给 整改责任人（设置整改落实人）
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("UserCheckAndSend")]
        public JsonActionResult<bool> UserCheckAndSend([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                Guid id = new Guid(filter.Keyword);
                var LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                var TaskID = new Guid(filter.Parameter1);

                //var entity = GetEntity<T_BS_RISK_SUBMIT_NOTICE_PERSON>(id, new string[] { "Nav_ListRiskSubmitContent.Nav_UserDeal", "Nav_ListRiskSubmitContent.Nav_User" });
                //var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;
                //if (listRiskSubminContentl != null && listRiskSubminContentl.Count() > 1)
                //{
                //    listRiskSubminContentl = listRiskSubminContentl.FindAll(e => e.DEAL_USER_ID == LoginID);
                //    if (listRiskSubminContentl == null || !listRiskSubminContentl.Any())
                //    {
                //        throw new Exception("只有整改责任人才能验收！");
                //    }
                //}
                //else if (listRiskSubminContentl[0].DEAL_USER_ID != LoginID)
                //{
                //    throw new Exception("只有整改责任人才能验收！");
                //}

                var entity = GetEntity<T_BS_RISK_SUBMIT_NOTICE_PERSON>(id, new string[] { "Nav_ListRiskSubmitContent.Nav_UserCheck" });//Nav_UserDeal
                if (entity.Nav_ListRiskSubmitContent[0].DEAL_USER_ID != LoginID)//.CHECK_USER_ID
                {
                    throw new Exception("只有整改责任人才能确认！");//只有整改责任人才能验收 验收人
                }

                if (filter.Parameter4 == "1")
                {
                    entity.OPERATETYPE = OperateType.Save;
                    //审核人 同意
                    List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();

                    var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;
                    //entity.Nav_ListRiskSubmitContent = null;//不能有 不然 对应外键 会被清空
                    List<Guid> ListNoticeAll = new List<Guid>();
                    List<string> ListNoticeAllNAME = new List<string>();
                    DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_Deal, entity.ORG_ID.Value, DateTime.Now, null, null);
                    listRiskSubminContentl.ForEach(item =>
                    {
                        //item.ACTUAL_DEAL_USER_ID = item.DEAL_USER_ID;//整改落实人默认  整改责任人
                        item.RiskContentState = (int)RiskContentState.CheckerCheck;//CheckerCheck CheckerCheck
                        if (string.IsNullOrEmpty(filter.Parameter3))
                        {
                            item.CHECK_USER_REFUSED_REASON = filter.Parameter3;
                        }
                        else
                        {
                            item.CHECK_USER_REFUSED_REASON = null;
                        }
                        if (item.DEAL_USER_ID == LoginID)//CHECK_USER_ID
                        {
                            item.ISDEALUSERCHECK = true;//.ISCHECKERCHECK
                        }
                        else
                        {
                            throw new Exception("只有整改责任人才能确认！");
                            //throw new Exception("只有验收人才能验收！");
                        }

                        if (!ListNoticeAll.Contains(item.CHECK_USER_ID.Value))//DEAL_USER_ID
                        {
                            //整改责任人
                            ListNoticeAll.Add(item.CHECK_USER_ID.Value);//DEAL_USER_ID
                            //数量少 每次获取 页面能选 这边就不会报错
                            ListNoticeAllNAME.Add(item.Nav_UserCheck.NAME);//Nav_UserDeal

                            //给责任人 发送通知
                            listNoticeDeal = NotificationTaskService.InsertUserNoticeTaskModels("验收人确认：" + entity.NAME.Replace("隐患整改通知：", ""), entity.ID, entity.ORG_ID, ListNoticeAll, ListNoticeAllNAME, DateTime.Now, ((item.LastDateUser.HasValue && item.LastDateUser.Value < dtEnd) ? item.LastDateUser.Value : dtEnd), (int)FMNoticeTypeEnum.消息, "BS042_SHOWPRINT");//HM001_SHOWPRINT  "整改责任人确认：" + entity.NAME.Replace("隐患整改通知：", "")
                        }
                    });

                    T_FM_NOTIFICATION_TASK task = null;
                    GetEntityTask(TaskID, ref task);

                    this.UnifiedCommit(() =>
                    {
                        UpdateEntityNoCommit(entity);//保存状态
                        if (listRiskSubminContentl != null && listRiskSubminContentl.Any())//隐患上报明细表
                            BantchSaveEntity(listRiskSubminContentl);    //保存子表
                        if (listNoticeDeal != null && listNoticeDeal.Any())//整改责任人 按条数 收到整改单
                            BantchSaveEntity(listNoticeDeal);
                        if (task != null)//代办消息 清除
                            UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    });

                    #region     ///

                    ////同意
                    //List<T_BS_RISK_SUBMIT_CONTENT_DEAL> listContentDeal = new List<T_BS_RISK_SUBMIT_CONTENT_DEAL>();
                    //List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();
                    //T_BS_RISK_SUBMIT_CONTENT_DEAL dealTemp = null;
                    //DateTime dtNow = DateTime.Now;

                    ////entity.Nav_ListRiskSubmitContent = null;//不能有 不然 对应外键 会被清空

                    //listRiskSubminContentl.ForEach(item =>
                    //{
                    //    item.ACTUAL_DEAL_USER_ID = item.DEAL_USER_ID;//整改落实人默认  整改责任人

                    //    if (item.DEAL_USER_ID == LoginID)
                    //    {
                    //        item.ISDEALUSERCHECK = true;
                    //    }
                    //    else if (item.CHECK_USER_ID == LoginID)
                    //    {
                    //        item.ISCHECKERCHECK = true;
                    //    }
                    //    if (item.ISDEALUSERCHECK && item.ISCHECKERCHECK)
                    //    {
                    //        item.RiskContentState = (int)RiskContentState.ArrangeDeal;
                    //    }
                    //});

                    ////整改责任人 和验收人 都确定后
                    //if (listRiskSubminContentl[0].RiskContentState == (int)RiskContentState.ArrangeDeal)
                    //{
                    //    DateTime dtTsakEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_ActualDeal, entity.ORG_ID.Value, DateTime.Now, null, null);
                    //    foreach (var item in listRiskSubminContentl)
                    //    {
                    //        //数据处理
                    //        CodeTemp++;

                    //        #region     隐患整改通知

                    //        dealTemp = new T_BS_RISK_SUBMIT_CONTENT_DEAL();
                    //        dealTemp.ID = Guid.NewGuid();
                    //        dealTemp.ORG_ID = item.ORG_ID;
                    //        dealTemp.RISK_SUBMIT_ID = item.RISK_SUBMIT_ID;
                    //        dealTemp.RISK_SUBMIT_NOTICE_ID = item.RISK_SUBMIT_NOTICE_ID;
                    //        dealTemp.RISK_SUBMIT_NOTICE_PERSON_ID = item.RISK_SUBMIT_NOTICE_PERSON_ID;
                    //        dealTemp.RISK_SUBMIT_CONTENT_ID = item.ID;
                    //        dealTemp.CODE = item.CODE + "_" + CodeTemp;

                    //        dealTemp.NAME = item.NAME.Replace("隐患整改通知：", "");
                    //        //dealTemp.ENDDATE = item.LastDateUser;//整改结束时间   
                    //        dealTemp.QUESTION_LEVEL = item.QUESTION_LEVEL;
                    //        dealTemp.DEALSITUATION = (int)DealSituation.Temp;
                    //        dealTemp.DEAL_USER_ID = item.DEAL_USER_ID;
                    //        dealTemp.ACTUAL_DEAL_USER_ID = item.ACTUAL_DEAL_USER_ID;
                    //        dealTemp.CHECK_USER_ID = item.CHECK_USER_ID;

                    //        listContentDeal.Add(dealTemp);

                    //        #endregion

                    //        ////每个整改责任人 收到待办
                    //        //var notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改单：" + dealTemp.NAME, dealTemp.ID, entity.ORG_ID, item.DEAL_USER_ID.Value, item.Nav_User.NAME, dtNow, item.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044");


                    //        //每个整改责任人 收到待办
                    //        var notice = NotificationTaskService.InsertUserNoticeTaskModel("指定整改落实人：" + dealTemp.NAME, item.ID, entity.ORG_ID, item.DEAL_USER_ID.Value, item.Nav_UserDeal.NAME, dtNow, (dtTsakEnd > item.LastDateUser.Value ? item.LastDateUser.Value : dtTsakEnd), (int)FMNoticeTypeEnum.消息, "BS049");

                    //        notice.CREATE_TIME = dtNow;
                    //        listNoticeDeal.Add(notice);

                    //    }
                    //}

                    //T_FM_NOTIFICATION_TASK task = null;
                    //GetEntityTask(TaskID, ref task);

                    //this.UnifiedCommit(() =>
                    //{
                    //    UpdateEntityNoCommit(entity);//保存状态
                    //    if (listContentDeal.Count > 0)
                    //        BantchSaveEntity(listContentDeal);//保存待整改明细
                    //    if (listRiskSubminContentl != null && listRiskSubminContentl.Any())//隐患上报明细表
                    //        BantchSaveEntity(listRiskSubminContentl);    //保存子表
                    //    if (listNoticeDeal != null && listNoticeDeal.Any())//整改责任人 按条数 收到整改单
                    //        BantchSaveEntity(listNoticeDeal);
                    //    if (task != null)//代办消息 清除
                    //        UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    //}); 
                    #endregion
                }
                else
                {
                    //驳回
                    //给通知责任人 发送 待办  指定 整改责任人、验收人 BS042

                    if (string.IsNullOrEmpty(filter.Parameter3))
                    {
                        throw new Exception("请填写驳回意见！");
                    }

                    //var sysFilter = new SystemCodeFilter();
                    //sysFilter.CodeType = (int)PFCodeRuleType.消息通知;
                    //sysFilter.Count = 1;
                    //sysFilter.OrgId = entity.ORG_ID;
                    //var codes = CodeRuleService.NewGenSerial(sysFilter);
                    //var codeList = codes.Split(new char[] { ',' });

                    var content = GetEntity<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_NOTICE_PERSON_ID == entity.ID, "Nav_User");
                    content.DEAL_USER_REFUSED_REASON = filter.Parameter3;//回到验收人已确定上一个状态 （不需要 就是这个状态）//CHECK_USER_REFUSED_REASON

                    //var taskAdd = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, entity.ID, entity.ORG_ID, content.USER_ID.Value, entity.Nav_User.NAME, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS042"); //驳回 传入 隐患上报明细ID 否则不明确

                    DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.Default, entity.ORG_ID.Value, DateTime.Now, null, null);

                    //如果是手动隐患上报 应该是 BS061 
                    var risk = GetEntity<T_BS_RISK_SUBMIT>(entity.RISK_SUBMIT_ID.Value, "Nav_User");
                    T_FM_NOTIFICATION_TASK taskAdd = null;
                    if (risk.SUBMIT_TYPE == (int)APT.MS.Domain.Enums.SUBMIT_TYPE.User)
                    {
                        taskAdd = NotificationTaskService.InsertUserNoticeTaskModel("信息完善", entity.RISK_SUBMIT_ID.Value, entity.ORG_ID, risk.USER_ID.Value, risk.Nav_User.NAME, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS061");
                    }
                    else
                    {
                        taskAdd = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, content.ID, entity.ORG_ID, content.USER_ID.Value, content.Nav_User.NAME, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS042");
                    }

                    T_FM_NOTIFICATION_TASK task = null;
                    GetEntityTask(TaskID, ref task);

                    this.UnifiedCommit(() =>
                    {
                        if (content != null)//填写验收人拒绝原因
                            UpdateEntityNoCommit(content);
                        if (taskAdd != null)//整改责任人 按条数 收到整改单
                            UpdateEntityNoCommit(taskAdd);
                        if (task != null)//代办消息 清除
                            UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    });

                    #region   ///

                    ////驳回
                    //if (string.IsNullOrEmpty(filter.Parameter3))
                    //{
                    //    throw new Exception("请填写驳回意见！");
                    //}

                    ////整改责任人驳回
                    ////验收人 已经审批过  整改责任人是自己 自己没审批过

                    //var listContent = entity.Nav_ListRiskSubmitContent.FindAll(e => e.DEAL_USER_ID == LoginID && !e.ISDEALUSERCHECK && e.ISCHECKERCHECK);

                    //List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();
                    //T_FM_NOTIFICATION_TASK taskTemp = null;
                    //int countTh = 0;
                    //DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.Default, filter.OrgId.Value, DateTime.Now, null, null);
                    //foreach (var item in listContent)
                    //{
                    //    item.ISCHECKERCHECK = false;
                    //    item.DEAL_USER_REFUSED_REASON = filter.Parameter3;
                    //    item.CHECK_USER_REFUSED_REASON = null;
                    //    item.RiskContentState = (int)RiskContentState.Notice;
                    //    taskTemp = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, item.ID, entity.ORG_ID, item.USER_ID.Value, entity.Nav_User.NAME, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS042");
                    //    listNoticeDeal.Add(taskTemp);
                    //    countTh++;
                    //}

                    //T_FM_NOTIFICATION_TASK task = null;
                    //GetEntityTask(TaskID, ref task);

                    //this.UnifiedCommit(() =>
                    //{
                    //    if (listContent != null)//填写整改责任人拒绝原因
                    //        BantchUpdateEntityNoCommit(listContent);
                    //    if (listNoticeDeal.Count > 0)//发送通知 给通知责任人
                    //        BantchSaveEntityNoCommit(listNoticeDeal);
                    //    if (task != null)//代办消息 清除
                    //        UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    //}); 
                    #endregion
                }

                return true;
            });
        }

        /// <summary>
        /// 验收人 确定/驳回  确定 整改责任人（设置整改落实人）
        /// 原: 验收人 确定/驳回  确定（给责任人 发送通知 ） 驳回 （隐患通知责任人）发送通知 （BS042）
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("CheckerCheck")]
        public JsonActionResult<bool> CheckerCheck([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                //确定 / 驳回  确定（给责任人 BS042_SHOWPRINT 发送通知 ） 驳回 （隐患通知责任人）发送通知 （BS042）
                Guid id = new Guid(filter.Keyword);
                DateTime dtNow = DateTime.Now;
                var LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                var TaskID = new Guid(filter.Parameter1);

                var entity = GetEntity<T_BS_RISK_SUBMIT_NOTICE_PERSON>(id, new string[] { "Nav_ListRiskSubmitContent.Nav_UserDeal", "Nav_ListRiskSubmitContent.Nav_User" });
                var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;
                if (listRiskSubminContentl != null && listRiskSubminContentl.Count() > 1)
                {
                    listRiskSubminContentl = listRiskSubminContentl.FindAll(e => e.CHECK_USER_ID == LoginID);//DEAL_USER_ID
                    if (listRiskSubminContentl == null || !listRiskSubminContentl.Any())
                    {
                        throw new Exception("只有验收人才能验收！");
                    }
                }
                else if (listRiskSubminContentl[0].CHECK_USER_ID != LoginID)//DEAL_USER_ID
                {
                    throw new Exception("只有验收人才能验收！");
                }
                if (filter.Parameter2 == "10")
                {
                    int CodeTemp = 0;
                    //同意
                    List<T_BS_RISK_SUBMIT_CONTENT_DEAL> listContentDeal = new List<T_BS_RISK_SUBMIT_CONTENT_DEAL>();
                    List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();
                    T_BS_RISK_SUBMIT_CONTENT_DEAL dealTemp = null;

                    //entity.Nav_ListRiskSubmitContent = null;//不能有 不然 对应外键 会被清空

                    listRiskSubminContentl.ForEach(item =>
                    {
                        item.ACTUAL_DEAL_USER_ID = item.DEAL_USER_ID;//整改落实人默认  整改责任人
                        if (item.CHECK_USER_ID == LoginID)
                        {
                            item.ISCHECKERCHECK = true;
                        }
                        else if (item.DEAL_USER_ID == LoginID)
                        {
                            item.ISDEALUSERCHECK = true;
                        }

                        if (item.ISDEALUSERCHECK && item.ISCHECKERCHECK)
                        {
                            item.RiskContentState = (int)RiskContentState.ArrangeDeal;
                        }
                    });

                    //整改责任人 和验收人 都确定后
                    if (listRiskSubminContentl[0].RiskContentState == (int)RiskContentState.ArrangeDeal)
                    {
                        DateTime dtTsakEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_ActualDeal, entity.ORG_ID.Value, DateTime.Now, null, null);
                        foreach (var item in listRiskSubminContentl)
                        {
                            //数据处理
                            CodeTemp++;

                            #region     隐患整改通知

                            dealTemp = new T_BS_RISK_SUBMIT_CONTENT_DEAL();
                            dealTemp.ID = Guid.NewGuid();
                            dealTemp.ORG_ID = item.ORG_ID;
                            dealTemp.RISK_SUBMIT_ID = item.RISK_SUBMIT_ID;
                            dealTemp.RISK_SUBMIT_NOTICE_ID = item.RISK_SUBMIT_NOTICE_ID;
                            dealTemp.RISK_SUBMIT_NOTICE_PERSON_ID = item.RISK_SUBMIT_NOTICE_PERSON_ID;
                            dealTemp.RISK_SUBMIT_CONTENT_ID = item.ID;
                            dealTemp.CODE = item.CODE + "_" + CodeTemp;

                            dealTemp.NAME = item.NAME.Replace("隐患整改通知：", "");
                            //dealTemp.ENDDATE = item.LastDateUser;//整改结束时间   
                            dealTemp.QUESTION_LEVEL = item.QUESTION_LEVEL;
                            dealTemp.DEALSITUATION = (int)DealSituation.Temp;
                            dealTemp.DEAL_USER_ID = item.DEAL_USER_ID;
                            dealTemp.ACTUAL_DEAL_USER_ID = item.ACTUAL_DEAL_USER_ID;
                            dealTemp.CHECK_USER_ID = item.CHECK_USER_ID;
                            dealTemp.REMARK = item.REMARK;

                            listContentDeal.Add(dealTemp);

                            #endregion

                            ////每个整改责任人 收到待办
                            //var notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改单：" + dealTemp.NAME, dealTemp.ID, entity.ORG_ID, item.DEAL_USER_ID.Value, item.Nav_User.NAME, dtNow, item.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044");


                            //每个整改责任人 收到待办
                            var notice = NotificationTaskService.InsertUserNoticeTaskModel("指定整改落实人：" + dealTemp.NAME, item.ID, entity.ORG_ID, item.DEAL_USER_ID.Value, item.Nav_UserDeal.NAME, dtNow, (dtTsakEnd > item.LastDateUser.Value ? item.LastDateUser.Value : dtTsakEnd), (int)FMNoticeTypeEnum.消息, "BS049");

                            notice.CREATE_TIME = dtNow;
                            listNoticeDeal.Add(notice);

                        }
                    }

                    T_FM_NOTIFICATION_TASK task = null;
                    GetEntityTask(TaskID, ref task);

                    this.UnifiedCommit(() =>
                    {
                        UpdateEntityNoCommit(entity);//保存状态
                        if (listContentDeal.Count > 0)
                            BantchSaveEntity(listContentDeal);//保存待整改明细
                        if (listRiskSubminContentl != null && listRiskSubminContentl.Any())//隐患上报明细表
                            BantchSaveEntity(listRiskSubminContentl);    //保存子表
                        if (listNoticeDeal != null && listNoticeDeal.Any())//整改责任人 按条数 收到整改单
                            BantchSaveEntity(listNoticeDeal);
                        if (task != null)//代办消息 清除
                            UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    });
                    #region ///

                    //entity.OPERATETYPE = OperateType.Save;
                    ////审核人 同意
                    //List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();

                    //var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;
                    ////entity.Nav_ListRiskSubmitContent = null;//不能有 不然 对应外键 会被清空
                    //List<Guid> ListNoticeAll = new List<Guid>();
                    //List<string> ListNoticeAllNAME = new List<string>();
                    //DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_Deal, entity.ORG_ID.Value, DateTime.Now, null, null);
                    //listRiskSubminContentl.ForEach(item =>
                    //{
                    //    //item.ACTUAL_DEAL_USER_ID = item.DEAL_USER_ID;//整改落实人默认  整改责任人
                    //    item.RiskContentState = (int)RiskContentState.CheckerCheck;
                    //    if (string.IsNullOrEmpty(filter.Parameter3))
                    //    {
                    //        item.CHECK_USER_REFUSED_REASON = filter.Parameter3;
                    //    }
                    //    else
                    //    {
                    //        item.CHECK_USER_REFUSED_REASON = null;
                    //    }
                    //    if (item.CHECK_USER_ID == LoginID)
                    //    {
                    //        item.ISCHECKERCHECK = true;
                    //    }
                    //    else
                    //    {
                    //        throw new Exception("只有验收人才能验收！");
                    //    }

                    //    if (!ListNoticeAll.Contains(item.DEAL_USER_ID.Value))
                    //    {

                    //        //整改责任人
                    //        ListNoticeAll.Add(item.DEAL_USER_ID.Value);
                    //        //数量少 每次获取 页面能选 这边就不会报错
                    //        ListNoticeAllNAME.Add(item.Nav_UserDeal.NAME);

                    //        //给责任人 发送通知
                    //        listNoticeDeal = NotificationTaskService.InsertUserNoticeTaskModels("整改责任人确认：" + entity.NAME.Replace("隐患整改通知：", ""), entity.ID, entity.ORG_ID, ListNoticeAll, ListNoticeAllNAME, dtNow, ((item.LastDateUser.HasValue && item.LastDateUser.Value < dtEnd) ? item.LastDateUser.Value : dtEnd), (int)FMNoticeTypeEnum.消息, "BS042_SHOWPRINT");//HM001_SHOWPRINT
                    //    }
                    //});

                    //T_FM_NOTIFICATION_TASK task = null;
                    //GetEntityTask(TaskID, ref task);

                    //this.UnifiedCommit(() =>
                    //{
                    //    UpdateEntityNoCommit(entity);//保存状态
                    //    if (listRiskSubminContentl != null && listRiskSubminContentl.Any())//隐患上报明细表
                    //        BantchSaveEntity(listRiskSubminContentl);    //保存子表
                    //    if (listNoticeDeal != null && listNoticeDeal.Any())//整改责任人 按条数 收到整改单
                    //        BantchSaveEntity(listNoticeDeal);
                    //    if (task != null)//代办消息 清除
                    //        UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    //}); 
                    #endregion
                }
                else
                {
                    //驳回
                    if (string.IsNullOrEmpty(filter.Parameter3))
                    {
                        throw new Exception("请填写驳回意见！");
                    }

                    //整改责任人驳回
                    //验收人 已经审批过  整改责任人是自己 自己没审批过

                    var listContent = entity.Nav_ListRiskSubmitContent.FindAll(e => e.CHECK_USER_ID == LoginID && e.ISDEALUSERCHECK && !e.ISCHECKERCHECK);//DEAL_USER_ID

                    List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();
                    T_FM_NOTIFICATION_TASK taskTemp = null;
                    int countTh = 0;
                    DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.Default, filter.OrgId.Value, DateTime.Now, null, null);
                    Guid? UserID = null;
                    string UserName = string.Empty;
                    foreach (var item in listContent)
                    {
                        item.ISCHECKERCHECK = false;
                        item.CHECK_USER_REFUSED_REASON = filter.Parameter3;//DEAL_USER_REFUSED_REASON
                        item.CHECK_USER_REFUSED_REASON = null;
                        item.RiskContentState = (int)RiskContentState.Notice;
                        UserID = item.CREATER_ID.HasValue ? item.CREATER_ID.Value : item.DEAL_USER_ID.Value;
                        UserName = GetEntity<T_FM_USER>(UserID.Value)?.NAME;
                        //taskTemp = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, item.ID, entity.ORG_ID, item.USER_ID.Value, entity.Nav_User.NAME, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS042");
                        taskTemp = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, item.ID, entity.ORG_ID, UserID.Value, UserName, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS042");// item.USER_ID.Value, entity.Nav_User.NAME

                        listNoticeDeal.Add(taskTemp);
                        countTh++;
                    }

                    T_FM_NOTIFICATION_TASK task = null;
                    GetEntityTask(TaskID, ref task);

                    this.UnifiedCommit(() =>
                    {
                        if (listContent != null)//填写整改责任人拒绝原因
                            BantchUpdateEntityNoCommit(listContent);
                        if (listNoticeDeal.Count > 0)//发送通知 给通知责任人
                            BantchSaveEntityNoCommit(listNoticeDeal);
                        if (task != null)//代办消息 清除
                            UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    });

                    #region ///

                    ////驳回
                    ////给通知责任人 发送 待办  指定 整改责任人、验收人 BS042

                    //if (string.IsNullOrEmpty(filter.Parameter3))
                    //{
                    //    throw new Exception("请填写驳回意见！");
                    //}

                    //var sysFilter = new SystemCodeFilter();
                    //sysFilter.CodeType = (int)PFCodeRuleType.消息通知;
                    //sysFilter.Count = 1;
                    //sysFilter.OrgId = entity.ORG_ID;
                    //var codes = CodeRuleService.NewGenSerial(sysFilter);
                    //var codeList = codes.Split(new char[] { ',' });

                    //var content = GetEntity<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_NOTICE_PERSON_ID == entity.ID, "Nav_User");
                    //content.CHECK_USER_REFUSED_REASON = filter.Parameter3;//回到验收人已确定上一个状态 （不需要 就是这个状态）

                    ////var taskAdd = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, entity.ID, entity.ORG_ID, content.USER_ID.Value, entity.Nav_User.NAME, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS042"); //驳回 传入 隐患上报明细ID 否则不明确

                    //DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.Default, entity.ORG_ID.Value, DateTime.Now, null, null);
                    //var taskAdd = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, content.ID, entity.ORG_ID, content.USER_ID.Value, content.Nav_User.NAME, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS042");

                    //T_FM_NOTIFICATION_TASK task = null;
                    //GetEntityTask(TaskID, ref task);

                    //this.UnifiedCommit(() =>
                    //{
                    //    if (content != null)//填写验收人拒绝原因
                    //        UpdateEntityNoCommit(content);
                    //    if (taskAdd != null)//整改责任人 按条数 收到整改单
                    //        UpdateEntityNoCommit(taskAdd);
                    //    if (task != null)//代办消息 清除
                    //        UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    //}); 
                    #endregion

                }

                return true;
            });
        }


        /// <summary>
        /// 验收人 确定/驳回  确定（给责任人 发送通知 ） 驳回 （隐患通知责任人）发送通知 （BS042）
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("CheckerCheckOld")]
        public JsonActionResult<bool> CheckerCheckOld([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                //确定 / 驳回  确定（给责任人 BS042_SHOWPRINT 发送通知 ） 驳回 （隐患通知责任人）发送通知 （BS042）
                Guid id = new Guid(filter.Keyword);
                DateTime dtNow = DateTime.Now;
                var entity = GetEntity<T_BS_RISK_SUBMIT_NOTICE_PERSON>(id, new string[] { "Nav_ListRiskSubmitContent.Nav_UserDeal" });
                var LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (entity.Nav_ListRiskSubmitContent[0].CHECK_USER_ID != LoginID)
                {
                    throw new Exception("只有验收人才能验收！");
                }
                var TaskID = new Guid(filter.Parameter1);
                if (filter.Parameter2 == "10")
                {
                    entity.OPERATETYPE = OperateType.Save;
                    //审核人 同意
                    List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();

                    var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;
                    //entity.Nav_ListRiskSubmitContent = null;//不能有 不然 对应外键 会被清空
                    List<Guid> ListNoticeAll = new List<Guid>();
                    List<string> ListNoticeAllNAME = new List<string>();
                    DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_Deal, entity.ORG_ID.Value, DateTime.Now, null, null);
                    listRiskSubminContentl.ForEach(item =>
                    {
                        //item.ACTUAL_DEAL_USER_ID = item.DEAL_USER_ID;//整改落实人默认  整改责任人
                        item.RiskContentState = (int)RiskContentState.CheckerCheck;
                        if (string.IsNullOrEmpty(filter.Parameter3))
                        {
                            item.CHECK_USER_REFUSED_REASON = filter.Parameter3;
                        }
                        else
                        {
                            item.CHECK_USER_REFUSED_REASON = null;
                        }
                        if (item.CHECK_USER_ID == LoginID)
                        {
                            item.ISCHECKERCHECK = true;
                        }
                        else
                        {
                            throw new Exception("只有验收人才能验收！");
                        }

                        if (!ListNoticeAll.Contains(item.DEAL_USER_ID.Value))
                        {

                            //整改责任人
                            ListNoticeAll.Add(item.DEAL_USER_ID.Value);
                            //数量少 每次获取 页面能选 这边就不会报错
                            ListNoticeAllNAME.Add(item.Nav_UserDeal.NAME);

                            //给责任人 发送通知
                            listNoticeDeal = NotificationTaskService.InsertUserNoticeTaskModels("整改责任人确认：" + entity.NAME.Replace("隐患整改通知：", ""), entity.ID, entity.ORG_ID, ListNoticeAll, ListNoticeAllNAME, dtNow, ((item.LastDateUser.HasValue && item.LastDateUser.Value < dtEnd) ? item.LastDateUser.Value : dtEnd), (int)FMNoticeTypeEnum.消息, "BS042_SHOWPRINT");//HM001_SHOWPRINT
                        }
                    });

                    T_FM_NOTIFICATION_TASK task = null;
                    GetEntityTask(TaskID, ref task);

                    this.UnifiedCommit(() =>
                    {
                        UpdateEntityNoCommit(entity);//保存状态
                        if (listRiskSubminContentl != null && listRiskSubminContentl.Any())//隐患上报明细表
                            BantchSaveEntity(listRiskSubminContentl);    //保存子表
                        if (listNoticeDeal != null && listNoticeDeal.Any())//整改责任人 按条数 收到整改单
                            BantchSaveEntity(listNoticeDeal);
                        if (task != null)//代办消息 清除
                            UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    });
                }
                else
                {
                    //驳回
                    //给通知责任人 发送 待办  指定 整改责任人、验收人 BS042

                    if (string.IsNullOrEmpty(filter.Parameter3))
                    {
                        throw new Exception("请填写驳回意见！");
                    }

                    var sysFilter = new SystemCodeFilter();
                    sysFilter.CodeType = (int)PFCodeRuleType.消息通知;
                    sysFilter.Count = 1;
                    sysFilter.OrgId = entity.ORG_ID;
                    var codes = CodeRuleService.NewGenSerial(sysFilter);
                    var codeList = codes.Split(new char[] { ',' });

                    var content = GetEntity<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_NOTICE_PERSON_ID == entity.ID, "Nav_User");
                    content.CHECK_USER_REFUSED_REASON = filter.Parameter3;//回到验收人已确定上一个状态 （不需要 就是这个状态）

                    //var taskAdd = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, entity.ID, entity.ORG_ID, content.USER_ID.Value, entity.Nav_User.NAME, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS042"); //驳回 传入 隐患上报明细ID 否则不明确

                    DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.Default, entity.ORG_ID.Value, DateTime.Now, null, null);
                    var taskAdd = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, content.ID, entity.ORG_ID, content.USER_ID.Value, content.Nav_User.NAME, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS042");

                    T_FM_NOTIFICATION_TASK task = null;
                    GetEntityTask(TaskID, ref task);

                    this.UnifiedCommit(() =>
                    {
                        if (content != null)//填写验收人拒绝原因
                            UpdateEntityNoCommit(content);
                        if (taskAdd != null)//整改责任人 按条数 收到整改单
                            UpdateEntityNoCommit(taskAdd);
                        if (task != null)//代办消息 清除
                            UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    });
                }

                return true;
            });
        }
        //BS/RiskSubmitNoticePerson/Get

        /// <summary>
        /// 整改责任人、验收人 确定   后面确定 的人 添加 待办给  整改责任人（设置整改落实人）
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("UserCheckAndSendOld")]
        public JsonActionResult<bool> UserCheckAndSendOld([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                Guid id = new Guid(filter.Keyword);
                var entity = GetEntity<T_BS_RISK_SUBMIT_NOTICE_PERSON>(id, new string[] { "Nav_ListRiskSubmitContent.Nav_UserDeal", "Nav_ListRiskSubmitContent.Nav_User" });
                var LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;

                var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;

                if (listRiskSubminContentl != null && listRiskSubminContentl.Count() > 1)
                {
                    listRiskSubminContentl = listRiskSubminContentl.FindAll(e => e.DEAL_USER_ID == LoginID);
                    if (listRiskSubminContentl == null || !listRiskSubminContentl.Any())
                    {
                        throw new Exception("只有整改责任人才能验收！");
                    }
                }
                else if (listRiskSubminContentl[0].DEAL_USER_ID != LoginID)
                {
                    throw new Exception("只有整改责任人才能验收！");
                }

                var TaskID = new Guid(filter.Parameter1);
                int CodeTemp = 0;
                if (filter.Parameter4 == "1")
                {
                    //同意

                    List<T_BS_RISK_SUBMIT_CONTENT_DEAL> listContentDeal = new List<T_BS_RISK_SUBMIT_CONTENT_DEAL>();
                    List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();
                    T_BS_RISK_SUBMIT_CONTENT_DEAL dealTemp = null;
                    DateTime dtNow = DateTime.Now;

                    //entity.Nav_ListRiskSubmitContent = null;//不能有 不然 对应外键 会被清空

                    listRiskSubminContentl.ForEach(item =>
                    {
                        item.ACTUAL_DEAL_USER_ID = item.DEAL_USER_ID;//整改落实人默认  整改责任人

                        if (item.DEAL_USER_ID == LoginID)
                        {
                            item.ISDEALUSERCHECK = true;
                        }
                        else if (item.CHECK_USER_ID == LoginID)
                        {
                            item.ISCHECKERCHECK = true;
                        }
                        if (item.ISDEALUSERCHECK && item.ISCHECKERCHECK)
                        {
                            item.RiskContentState = (int)RiskContentState.ArrangeDeal;
                        }
                    });

                    //整改责任人 和验收人 都确定后
                    if (listRiskSubminContentl[0].RiskContentState == (int)RiskContentState.ArrangeDeal)
                    {
                        DateTime dtTsakEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_ActualDeal, entity.ORG_ID.Value, DateTime.Now, null, null);
                        foreach (var item in listRiskSubminContentl)
                        {
                            //数据处理
                            CodeTemp++;

                            #region     隐患整改通知

                            dealTemp = new T_BS_RISK_SUBMIT_CONTENT_DEAL();
                            dealTemp.ID = Guid.NewGuid();
                            dealTemp.ORG_ID = item.ORG_ID;
                            dealTemp.RISK_SUBMIT_ID = item.RISK_SUBMIT_ID;
                            dealTemp.RISK_SUBMIT_NOTICE_ID = item.RISK_SUBMIT_NOTICE_ID;
                            dealTemp.RISK_SUBMIT_NOTICE_PERSON_ID = item.RISK_SUBMIT_NOTICE_PERSON_ID;
                            dealTemp.RISK_SUBMIT_CONTENT_ID = item.ID;
                            dealTemp.CODE = item.CODE + "_" + CodeTemp;

                            dealTemp.NAME = item.NAME.Replace("隐患整改通知：", "");
                            //dealTemp.ENDDATE = item.LastDateUser;//整改结束时间   
                            dealTemp.QUESTION_LEVEL = item.QUESTION_LEVEL;
                            dealTemp.DEALSITUATION = (int)DealSituation.Temp;
                            dealTemp.DEAL_USER_ID = item.DEAL_USER_ID;
                            dealTemp.ACTUAL_DEAL_USER_ID = item.ACTUAL_DEAL_USER_ID;
                            dealTemp.CHECK_USER_ID = item.CHECK_USER_ID;
                            dealTemp.REMARK = item.REMARK;

                            listContentDeal.Add(dealTemp);

                            #endregion

                            ////每个整改责任人 收到待办
                            //var notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改单：" + dealTemp.NAME, dealTemp.ID, entity.ORG_ID, item.DEAL_USER_ID.Value, item.Nav_User.NAME, dtNow, item.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044");


                            //每个整改责任人 收到待办
                            var notice = NotificationTaskService.InsertUserNoticeTaskModel("指定整改落实人：" + dealTemp.NAME, item.ID, entity.ORG_ID, item.DEAL_USER_ID.Value, item.Nav_UserDeal.NAME, dtNow, (dtTsakEnd > item.LastDateUser.Value ? item.LastDateUser.Value : dtTsakEnd), (int)FMNoticeTypeEnum.消息, "BS049");

                            notice.CREATE_TIME = dtNow;
                            listNoticeDeal.Add(notice);

                        }
                    }

                    T_FM_NOTIFICATION_TASK task = null;
                    GetEntityTask(TaskID, ref task);

                    this.UnifiedCommit(() =>
                    {
                        UpdateEntityNoCommit(entity);//保存状态
                        if (listContentDeal.Count > 0)
                            BantchSaveEntity(listContentDeal);//保存待整改明细
                        if (listRiskSubminContentl != null && listRiskSubminContentl.Any())//隐患上报明细表
                            BantchSaveEntity(listRiskSubminContentl);    //保存子表
                        if (listNoticeDeal != null && listNoticeDeal.Any())//整改责任人 按条数 收到整改单
                            BantchSaveEntity(listNoticeDeal);
                        if (task != null)//代办消息 清除
                            UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    });
                }
                else
                {
                    //驳回
                    if (string.IsNullOrEmpty(filter.Parameter3))
                    {
                        throw new Exception("请填写驳回意见！");
                    }

                    //整改责任人驳回
                    //验收人 已经审批过  整改责任人是自己 自己没审批过

                    var listContent = entity.Nav_ListRiskSubmitContent.FindAll(e => e.DEAL_USER_ID == LoginID && !e.ISDEALUSERCHECK && e.ISCHECKERCHECK);

                    List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();
                    T_FM_NOTIFICATION_TASK taskTemp = null;
                    int countTh = 0;
                    DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.Default, filter.OrgId.Value, DateTime.Now, null, null);
                    foreach (var item in listContent)
                    {
                        item.ISCHECKERCHECK = false;
                        item.DEAL_USER_REFUSED_REASON = filter.Parameter3;
                        item.CHECK_USER_REFUSED_REASON = null;
                        item.RiskContentState = (int)RiskContentState.Notice;
                        taskTemp = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, item.ID, entity.ORG_ID, item.USER_ID.Value, entity.Nav_User.NAME, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS042");
                        listNoticeDeal.Add(taskTemp);
                        countTh++;
                    }

                    T_FM_NOTIFICATION_TASK task = null;
                    GetEntityTask(TaskID, ref task);

                    this.UnifiedCommit(() =>
                    {
                        if (listContent != null)//填写整改责任人拒绝原因
                            BantchUpdateEntityNoCommit(listContent);
                        if (listNoticeDeal.Count > 0)//发送通知 给通知责任人
                            BantchSaveEntityNoCommit(listNoticeDeal);
                        if (task != null)//代办消息 清除
                            UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                    });
                }

                return true;
            });
        }

        #endregion

        ///// <summary>
        ///// 验收人、整改责任人 验收
        ///// </summary>
        ///// <param name="filter"></param>
        ///// <returns></returns>
        ///// <exception cref="Exception"></exception>
        //[HttpPost, Route("Check")]
        //public JsonActionResult<bool> Check([FromBody] KeywordFilter filter)
        //{
        //    //#endregion
        //    return SafeExecute<bool>(() =>
        //    {

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


        /// <summary>
        /// 获得单条实体数据
        /// </summary>
        /// <param name="filter">过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("GetNoticePerson")]
        public JsonActionResult<T_BS_RISK_SUBMIT_NOTICE_PERSON> GetNoticePerson([FromBody] KeywordFilter filter)
        {
            return SafeExecute<T_BS_RISK_SUBMIT_NOTICE_PERSON>(() =>
            {
                List<FilterRule> filterRules = filter.FilterGroup.Rules.ToList();
                var guid = new Guid(filterRules[0].Value.ToString());
                var modelPersonNotice = GetEntity<T_BS_RISK_SUBMIT_NOTICE_PERSON>(e => e.ID == guid, filter);

                if (modelPersonNotice == null)
                {
                    var cont = GetEntity<T_BS_RISK_SUBMIT_CONTENT>(guid, new string[] { "Nav_SubmitNoticePerson", "Nav_DepartmentDeal", "Nav_UserDeal", "Nav_UserCheck", "Nav_Files.Nav_ImgFile.Nav_File" });
                    modelPersonNotice = cont.Nav_SubmitNoticePerson;
                    modelPersonNotice.Nav_ListRiskSubmitContent = new List<T_BS_RISK_SUBMIT_CONTENT>();
                    modelPersonNotice.Nav_ListRiskSubmitContent.Add(cont);
                }
                else
                {
                    if (modelPersonNotice.Nav_ListRiskSubmitContent == null || !modelPersonNotice.Nav_ListRiskSubmitContent.Any())
                    {
                        List<string> listPath = new List<string>();
                        foreach (var item in filter.Include)
                        {
                            if (item.Contains("Nav_ListRiskSubmitContent."))
                            {
                                listPath.Add(item.Substring(26));
                            }
                        }

                        //手动添加安全检查的  隐患上报 
                        var iListContent = GetEntities<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_ID == modelPersonNotice.RISK_SUBMIT_ID, null, listPath.ToArray());
                        if (iListContent != null && iListContent.Any())
                        {
                            modelPersonNotice.Nav_ListRiskSubmitContent = iListContent.ToList();
                        }
                    }
                }
                if (DataHelper.GetRequestType(Request.Headers) == 2 && modelPersonNotice.Nav_ListRiskSubmitContent != null && modelPersonNotice.Nav_ListRiskSubmitContent.Any())
                {
                    foreach (var item in modelPersonNotice.Nav_ListRiskSubmitContent)
                    {
                        try
                        {
                            item.QUESTION_LEVEL_SHOW = ((BSQuestionLevelEnum)item.QUESTION_LEVEL).GetDescription();
                        }
                        catch { }
                    }
                }
                return modelPersonNotice;
            });
        }




        /// <summary>
        ///整改责任人  修改整改落实人  给整改落实人 发送通知
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("UpdateActualDeal")]
        public JsonActionResult<bool> UpdateActualDeal([FromBody] T_BS_RISK_SUBMIT_CONTENT entity)
        {
            return SafeExecute<bool>(() =>
            {
                if (APT.Infrastructure.Api.AppContext.CurrentSession.UserID != entity.DEAL_USER_ID)
                {
                    throw new Exception("只有整改责任人才可以指定整改落实人！");
                }
                if (entity.ACTUAL_DEAL_USER_ID == entity.CHECK_USER_ID)
                {
                    this.ThrowError("010001", "整改落实人和验收人不能是同一个人！");
                }
                var ListRiskQuestionReason = entity.Nav_ListRiskQuestionReason;
                if (ListRiskQuestionReason != null && ListRiskQuestionReason.Any())
                {
                    foreach (var item in ListRiskQuestionReason)
                    {
                        item.Nav_RiskReason = null;
                    }
                }
                if (entity.RiskContentState.Value == (int)RiskContentState.ActualDealChangeTemp)
                {
                    this.UnifiedCommit(() =>
                    {
                        UpdateEntityNoCommit(entity);//保存信息 整改落实人
                        if (ListRiskQuestionReason != null && ListRiskQuestionReason.Any())
                            BantchSaveEntityNoCommit(ListRiskQuestionReason);
                    });
                }
                else if (entity.RiskContentState.Value == (int)RiskContentState.ActualDealChange)
                {
                    //指定后 给整改落实人 发送通知
                    T_FM_NOTIFICATION_TASK task = null;
                    GetEntityTask(entity.TaskID, ref task, "BS049_SHOWPRINT");
                    if (entity.ACTUAL_DEAL_USER_ID == null)
                    {
                        throw new Exception("请填写整改落实人！");
                    }
                    if ((ListRiskQuestionReason == null || !ListRiskQuestionReason.Any()) && (DataHelper.GetRequestType(HttpContext.Request.Headers) != 2 || DateTime.Now.Month > 2))//PC都要判断非空 移动端 2月过后
                    {
                        throw new Exception("请选择隐患原因！");
                    }
                    var deal = GetEntity<T_BS_RISK_SUBMIT_CONTENT_DEAL>(e => e.RISK_SUBMIT_CONTENT_ID == entity.ID);

                    deal.ACTUAL_DEAL_USER_ID = entity.ACTUAL_DEAL_USER_ID;//整改落实人
                    List<T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE> listDealF = null;
                    if (entity.Nav_Files != null && entity.Nav_Files.Any())
                    {
                        listDealF = new List<T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE>();
                        foreach (var item in entity.Nav_Files)
                        {
                            listDealF.Add(new T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE()
                            {
                                ID = Guid.NewGuid(),
                                RISK_SUBMIT_CONTENT_DEAL_ID = deal.ID,
                                IMG_FILE_ID = item.IMG_FILE_ID,
                                IS_DELETED = false,
                                ORG_ID = item.ORG_ID,
                                ENTITY_ORG_TPYE = item.ENTITY_ORG_TPYE,
                                FLOW_STATUS = item.FLOW_STATUS,
                                FLOW_SEND_STATUS = item.FLOW_SEND_STATUS,
                                //FORM_ID
                                //FLOW_ID
                                //CREATE_TIME
                                //MODIFY_TIME
                                //CREATER_ID
                                //MODIFIER_ID

                            });
                        }
                    }

                    //var notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改通知：" + entity.NAME.Replace("隐患整改通知：", ""), deal.ID, entity.ORG_ID, entity.ACTUAL_DEAL_USER_ID.Value, entity.Nav_UserActualDeal.NAME, DateTime.Now, entity.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044_NOTICE");

                    //隐患上报结束 
                    entity.SUBMITFINISHTIME = DateTime.Now;
                    if (entity.SUBMITFINISHTIME <= entity.LastDateUser)
                        entity.ISSUBMITFINISHINTTIME = true;
                    else
                        entity.ISSUBMITFINISHINTTIME = false;


                    if (entity.ACTUAL_DEAL_USER_ID.Value != APT.Infrastructure.Api.AppContext.CurrentSession.UserID)
                    {
                        DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_ActualDealNotice, entity.ORG_ID.Value, DateTime.Now, null, null);

                        var notice = NotificationTaskService.InsertUserNoticeTaskModel(entity.NAME, deal.RISK_SUBMIT_NOTICE_PERSON_ID.Value, entity.ORG_ID, entity.ACTUAL_DEAL_USER_ID.Value, entity.Nav_UserActualDeal.NAME, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS042_ACTUALCHECK");//BS042_SHOWPRINT

                        entity.RiskContentState = (int)RiskContentState.ActualDealChange;
                        this.UnifiedCommit(() =>
                        {
                            if (listDealF != null && listDealF.Any())
                                BantchSaveEntityNoCommit(listDealF);
                            UpdateEntityNoCommit(deal);
                            UpdateEntityNoCommit(entity);//保存信息 整改落实人
                            if (ListRiskQuestionReason != null && ListRiskQuestionReason.Any())
                                BantchSaveEntityNoCommit(ListRiskQuestionReason);
                            UpdateEntityNoCommit(notice);
                            if (task != null)//代办消息 清除
                                UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                        });
                    }
                    else
                    {
                        //指定自己
                        Guid LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
                        //var entityDeal = GetEntity<T_BS_RISK_SUBMIT_CONTENT_DEAL>(e => e.RISK_SUBMIT_NOTICE_PERSON_ID == deal.RISK_SUBMIT_NOTICE_PERSON_ID.Value && e.Nav_SubmitContent.ACTUAL_DEAL_USER_ID == LoginID, new string[] { "Nav_SubmitContent.Nav_UserActualDeal" });

                        //指定后 给整改落实人 发送通知
                        //T_FM_NOTIFICATION_TASK task = null;
                        //GetEntityTask(TaskID, ref task);
                        //var entity = entityDeal.Nav_SubmitContent;

                        entity.RiskContentState = (int)RiskContentState.ActualDealCheck;//落实整改人已经查阅整改通知
                        var notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改单：" + entity.NAME.Replace("隐患整改通知：", ""), deal.ID, entity.ORG_ID, entity.ACTUAL_DEAL_USER_ID.Value, entity.Nav_UserActualDeal.NAME, DateTime.Now, entity.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044");

                        this.UnifiedCommit(() =>
                        {
                            if (listDealF != null && listDealF.Any())
                                BantchSaveEntityNoCommit(listDealF);
                            UpdateEntityNoCommit(deal);
                            UpdateEntityNoCommit(entity);//保存信息 整改落实人
                            if (ListRiskQuestionReason != null && ListRiskQuestionReason.Any())
                                BantchSaveEntityNoCommit(ListRiskQuestionReason);
                            UpdateEntityNoCommit(notice);
                            if (task != null)//代办消息 清除
                                UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                        });
                    }
                }
                else
                {
                    throw new Exception("未找到此操作！");
                }
                return true;
            });
        }



        /// <summary>
        /// 整改落实人 确认整改通知单 系统发送整改单给整改落实人
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("UpdateActualDealRecord")]
        public JsonActionResult<bool> UpdateActualDealRecord([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                Guid LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
                var DataID = new Guid(filter.Keyword);
                var TaskID = new Guid(filter.Parameter1);

                //指定后 给整改落实人 发送通知
                T_FM_NOTIFICATION_TASK task = null;
                GetEntityTask(TaskID, ref task);

                int riskContentState = (int)RiskContentState.ActualDealChange;
                var entityDeal = GetEntities<T_BS_RISK_SUBMIT_CONTENT_DEAL>(e => e.RISK_SUBMIT_NOTICE_PERSON_ID == DataID && e.Nav_SubmitContent.ACTUAL_DEAL_USER_ID == LoginID && e.Nav_SubmitContent.RiskContentState == riskContentState, null, "Nav_SubmitContent");
                List<T_FM_NOTIFICATION_TASK> listTask = new List<T_FM_NOTIFICATION_TASK>();
                List<T_BS_RISK_SUBMIT_CONTENT> listContents = new List<T_BS_RISK_SUBMIT_CONTENT>();
                IEnumerable<T_FM_USER> listUser = null;
                if (entityDeal != null && entityDeal.Any())
                {
                    var listUserID = entityDeal.Where(e => e.ACTUAL_DEAL_USER_ID.HasValue).Select(e => e.ACTUAL_DEAL_USER_ID.Value).Distinct();
                    if (listUserID != null && listUserID.Any())
                    {
                        listUser = GetEntities<T_FM_USER>(e => listUserID.Contains(e.ID), null);
                    }
                }
                DateTime? TASK_ENDDT = null;
                if (task != null)
                {
                    TASK_ENDDT = task.TASK_ENDDT;
                }
                List<T_BS_OPERATE_LOG> listLog = new List<T_BS_OPERATE_LOG>();
                foreach (var item in entityDeal)
                {
                    var entity = item.Nav_SubmitContent;
                    listContents.Add(entity);
                    entity.RiskContentState = (int)RiskContentState.ActualDealCheck;
                    listTask.Add(NotificationTaskService.InsertUserNoticeTaskModel("隐患整改单：" + entity.NAME.Replace("隐患整改通知：", ""), item.ID, entity.ORG_ID, entity.ACTUAL_DEAL_USER_ID.Value, listUser.FirstOrDefault(e => e.ID == entity.ACTUAL_DEAL_USER_ID.Value)?.NAME, DateTime.Now, item.Nav_SubmitContent.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044"));


                    listLog.AddRange(OperateLogService.GetListOperateLog(OPERATEPOINT_Enums.RiskNoticeActureCheck, entity.RISK_SUBMIT_ID.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, null, new List<Guid>() { entity.ACTUAL_DEAL_USER_ID.Value }, new List<string>() { listUser.FirstOrDefault(e => e.ID == entity.ACTUAL_DEAL_USER_ID.Value)?.NAME }, entity.ORG_ID, item.RISK_SUBMIT_CONTENT_ID, null, false, TASK_ENDDT));
                }

                this.UnifiedCommit(() =>
                {
                    //UpdateEntityNoCommit(entity);//保存信息 整改落实人
                    if (listContents != null && listContents.Any())
                        BantchSaveEntityNoCommit(listContents);
                    if (listTask != null && listTask.Any())
                        BantchSaveEntityNoCommit(listTask);
                    if (listLog != null && listLog.Any())
                        BantchSaveEntityNoCommit(listLog);
                    if (task != null)//代办消息 清除
                        UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                });

                #region   旧版有问题 通知有多条记录 就发一个整改

                //int riskContentState = (int)RiskContentState.ActualDealChange;
                //var entityDeal = GetEntity<T_BS_RISK_SUBMIT_CONTENT_DEAL>(e => e.RISK_SUBMIT_NOTICE_PERSON_ID == DataID && e.Nav_SubmitContent.ACTUAL_DEAL_USER_ID == LoginID && e.Nav_SubmitContent.RiskContentState == riskContentState, new string[] { "Nav_SubmitContent.Nav_UserActualDeal" });

                ////指定后 给整改落实人 发送通知
                //T_FM_NOTIFICATION_TASK task = null;
                //GetEntityTask(TaskID, ref task);
                //var entity = entityDeal.Nav_SubmitContent;

                //entity.RiskContentState = (int)RiskContentState.ActualDealCheck;//落实整改人已经查阅整改通知
                //                                                                //DateTime dtTaskEndTime = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_DealRisk, entity.ORG_ID.Value, DateTime.Now, null, entity.LastDateUser.Value);
                //DateTime dtTaskEndTime = entity.LastDateUser.Value;//隐患整改 按 整改结束时间
                //var notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改单：" + entity.NAME.Replace("隐患整改通知：", ""), entityDeal.ID, entity.ORG_ID, entity.ACTUAL_DEAL_USER_ID.Value, entity.Nav_UserActualDeal.NAME, DateTime.Now, dtTaskEndTime, (int)FMNoticeTypeEnum.消息, "BS044");

                //this.UnifiedCommit(() =>
                //{
                //    UpdateEntityNoCommit(entity);//保存信息 整改落实人
                //    UpdateEntityNoCommit(notice);
                //    if (task != null)//代办消息 清除
                //        UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                //});

                #endregion
                return true;
            });
        }





        /// <summary>
        /// 隐患整改通知审批结束 流向隐患整改记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet, Route("Record")]
        public JsonActionResult<bool> Record(string id)
        {
            return SafeExecute<bool>(() =>
            {


                return true;
            });
        }


        #endregion



        #region    隐患整改记录


        /// <summary>
        /// 更新或新增数据
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns></returns>
        [HttpPost, Route("UpdateDeal")]
        public JsonActionResult<bool> UpdateDeal([FromBody] T_BS_RISK_SUBMIT_CONTENT_DEAL entity)
        {
            return SafeExecute<bool>(() =>
            {
                var content = entity.Nav_SubmitContent;
                if (content == null)
                {
                    content = GetEntity<T_BS_RISK_SUBMIT_CONTENT>(entity.RISK_SUBMIT_CONTENT_ID.Value, new string[] { "Nav_UserDeal" });
                }
                Guid LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
                if (entity.OPERARTETYPE == (int)OperateType.Temp || entity.OPERARTETYPE == (int)OperateType.Save)
                {
                    //只有保存 或者保存并发送了
                    //保存并发送  给验收人 发送审核 待办 
                    #region  保存 保存并通知

                    if (!content.ACTUAL_DEAL_USER_ID.HasValue)
                    {
                        throw new Exception("请先指定整改落实人后再操作！");
                    }
                    else if (content.ACTUAL_DEAL_USER_ID.Value != LoginID)
                    {
                        throw new Exception("只有整改落实人才有权限操整改记录单！");
                    }

                    var files = entity.Nav_Files;
                    entity.Nav_Files = null;

                    var filesAfter = entity.Nav_FilesAfter;
                    entity.Nav_FilesAfter = null;

                    if (entity.OPERARTETYPE == (int)OperateType.Temp)
                    {
                        if (content.RiskContentState > (int)RiskContentState.DealTemp)
                        {
                            throw new Exception("该隐患已经进入之后流程【" + ((RiskContentState)content.RiskContentState).GetDescription() + "】，操作失败!");
                        }

                        content.RiskContentState = (int)RiskContentState.DealTemp;
                        entity.Nav_SubmitContent = null;
                        entity.DEALSITUATION = (int)DealSituation.Temp;
                        //保存草稿 保存页面数据
                        UnifiedCommit(() =>
                        {
                            UpdateEntityNoCommit(entity);//修改整改落实人
                            UpdateEntityNoCommit(content);
                            if (files != null && files.Any())//检查前附件
                                BantchSaveEntityNoCommit(files);
                            if (filesAfter != null && filesAfter.Any())//检查后附件
                                BantchSaveEntityNoCommit(filesAfter);
                        });
                    }
                    else
                    {
                        entity.DEALSITUATION = (int)DealSituation.Notice;
                        //判断是否填写好

                        entity.DATETIME_ACTUAL_DEAL = DateTime.Now;//整改落实人签字

                        if (entity.ENDDATE == null)
                        {
                            throw new Exception("请填写【整改截止时间】!");
                        }
                        if (files == null || files.Count < 1)
                        {
                            throw new Exception("请上传【附件（整改前）】!");
                        }
                        if (string.IsNullOrEmpty(entity.DEALDESCRIBE))
                        {
                            throw new Exception("请填写【整改情况描述】!");
                        }
                        if (filesAfter == null || filesAfter.Count < 1)
                        {
                            throw new Exception("请上传【附件（整改后）】!");
                        }
                        //if (entity.ACTUAL_DEAL_USER_ID != content.ACTUAL_DEAL_USER_ID)
                        //{
                        //    entity.ACTUAL_DEAL_USER_ID = content.ACTUAL_DEAL_USER_ID;
                        //}
                        //如果 操作者和整改责任人不一致 给整改责任人 添加待办
                        //如果 操作者和整改责任人一致 给验收人 添加待办
                        if (content.ACTUAL_DEAL_USER_ID != LoginID)
                        {
                            throw new Exception("只有【整改落实人】才能填写隐患整改单！");
                        }
                        //if (LoginID == entity.DEAL_USER_ID && entity.Nav_ListUserSign == null)
                        //{
                        //    throw new Exception("请签名后再提交!");
                        //}

                        string UserName = string.Empty;
                        T_FM_NOTIFICATION_TASK notice = null;
                        if (content.RiskContentState == (int)RiskContentState.DealSend)
                        {
                            throw new Exception("该整改单已经在签字阶段，操作失败!");
                        }
                        content.RiskContentState = (int)RiskContentState.DealSend;

                        if (entity.Nav_UserCheck == null)
                        {
                            entity.Nav_UserCheck = this.GetEntity<T_FM_USER>(entity.CHECK_USER_ID.Value);
                        }

                        //给验收人发送通知   => 给整改责任人发送通知
                        //content.RiskContentState = (int)RiskContentState.DealSign;//整改责任人已经签名
                        //entity.ISDEALSIGN = true;
                        //notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改验收单：" + entity.NAME, entity.ID, entity.ORG_ID, entity.CHECK_USER_ID.Value, entity.Nav_UserCheck.NAME, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS044_CHECK");

                        string userDealName = string.Empty;
                        if (entity.Nav_UserDeal == null)
                        {
                            userDealName = GetEntity<T_FM_USER>(entity.DEAL_USER_ID.Value).NAME;
                        }
                        else
                        {
                            userDealName = entity.Nav_UserDeal.NAME;
                        }

                        entity.ISDEALSIGN = false;

                        DateTime dtEndTime = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_Deal_Check, entity.ORG_ID.Value, DateTime.Now, null, content.LastDateUser);

                        notice = NotificationTaskService.InsertUserNoticeTaskModel("责任人确认整改：" + entity.NAME, entity.ID, entity.ORG_ID, entity.DEAL_USER_ID.Value, userDealName, DateTime.Now, dtEndTime, (int)FMNoticeTypeEnum.消息, "BS044_CHECK");//隐患整改记录：

                        T_FM_NOTIFICATION_TASK task = null;
                        GetEntityTask(entity.TaskID, ref task, "BS044_SHOWPRINT");
                        DateTime? TASK_ENDDT = null;
                        if (task != null)
                        {
                            TASK_ENDDT = task.TASK_ENDDT;
                        }
                        var listLog = OperateLogService.GetListOperateLog(OPERATEPOINT_Enums.RiskDeal, entity.RISK_SUBMIT_ID.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, null, new List<Guid>() { entity.DEAL_USER_ID.Value }, new List<string>() { userDealName }, entity.ORG_ID, entity.RISK_SUBMIT_CONTENT_ID, null, false, TASK_ENDDT);

                        //修改 model
                        UnifiedCommit(() =>
                        {
                            UpdateEntityNoCommit(entity);//修改整改落实人
                            UpdateEntityNoCommit(content);//修改明细已签名字
                            if (notice != null)//发送待办
                                UpdateEntityNoCommit(notice);
                            if (task != null)//代办消息 清除
                                UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                            if (files != null && files.Any())//检查前附件
                                BantchSaveEntityNoCommit(files);
                            if (filesAfter != null && filesAfter.Any())//检查后附件
                                BantchSaveEntityNoCommit(filesAfter);
                            if (listLog != null && listLog.Any())//日志
                                BantchSaveEntityNoCommit(listLog);
                            //if (signDeal != null && signDeal.Any())//整改人签名
                            //    BantchSaveEntityNoCommit(signDeal);
                        });

                    }

                    #endregion
                }

                return true;
            });
        }
        #region    旧版  待删除

        ///// <summary>
        ///// 更新或新增数据
        ///// </summary>
        ///// <param name="entity">对象实体</param>
        ///// <returns></returns>
        //[HttpPost, Route("UpdateDeal")]
        //public JsonActionResult<bool> UpdateDeal([FromBody] T_BS_RISK_SUBMIT_CONTENT_DEAL entity)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var content = entity.Nav_SubmitContent;
        //        if (content == null)
        //        {
        //            content = GetEntity<T_BS_RISK_SUBMIT_CONTENT>(entity.RISK_SUBMIT_CONTENT_ID.Value);
        //        }

        //        Guid LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
        //        if (entity.OPERARTETYPE == (int)OperateType.Other1)
        //        {
        //            #region 整改责任人 能修改 整改落实人

        //            //整改责任人 能修改 整改落实人
        //            if (entity.DEAL_USER_ID == APT.Infrastructure.Api.AppContext.CurrentSession.UserID)
        //            {
        //                if (entity.DEALSITUATION == (int)DealSituation.OK)
        //                {
        //                    throw new Exception("该整改记录已完成，不能修改整改落实人!");
        //                }
        //                if (!entity.ACTUAL_DEAL_USER_ID.HasValue)
        //                {
        //                    throw new Exception("请选择整改落实人!");
        //                }
        //                if (entity.DEAL_USER_ID == entity.ACTUAL_DEAL_USER_ID)
        //                {
        //                    throw new Exception("请选择新的整改落实人!");
        //                }

        //                //entity.Nav_UserActualDeal.NAME
        //                string UserActualDealNAME = this.GetEntity<T_FM_USER>(entity.ACTUAL_DEAL_USER_ID.Value).NAME;

        //                var notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改单：" + entity.NAME, entity.ID, entity.ORG_ID, entity.ACTUAL_DEAL_USER_ID.Value, UserActualDealNAME, entity.CREATE_TIME.Value, content.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044");
        //                //如果 有待办 把待办去掉

        //                T_FM_NOTIFICATION_TASK task = null;
        //                GetEntityTask(entity.TaskID, ref task);
        //                //if (entity.TaskID != new Guid())
        //                //{
        //                //    task = this.GetEntity<T_FM_NOTIFICATION_TASK>(entity.TaskID);
        //                //    task.TASK_DT = DateTime.Now;
        //                //    if (task.TASK_ENDDT >= task.TASK_DT)
        //                //        task.NOTICE_STATUS = FMNoticeStatusEnum.正常已办.GetInt();
        //                //    else
        //                //        task.NOTICE_STATUS = FMNoticeStatusEnum.超期办理.GetInt();
        //                //}
        //                content.RiskContentState = (int)RiskContentState.ActualDealChange;

        //                //修改 model
        //                UnifiedCommit(() =>
        //                {
        //                    UpdateEntityNoCommit(entity);//修改整改落实人
        //                    UpdateEntityNoCommit(content);//修改上报明细状态 整改落实人修改
        //                    UpdateEntityNoCommit<T_FM_NOTIFICATION_TASK>(notice);//给整改落实人发送待办
        //                    if (task != null)//代办消息 清除
        //                        UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
        //                });
        //            }
        //            else
        //            {
        //                throw new Exception("只有【整改责任人】才能修改【整改落实人】!");
        //            }
        //            #endregion
        //        }
        //        else if (entity.OPERARTETYPE == (int)OperateType.Temp || entity.OPERARTETYPE == (int)OperateType.Save)
        //        {
        //            //只有保存 或者保存并发送了
        //            //保存并发送  给验收人 发送审核 待办 
        //            #region  保存 保存并通知

        //            if (!content.ACTUAL_DEAL_USER_ID.HasValue)
        //            {
        //                throw new Exception("请先指定整改落实人后再操作！");
        //            }
        //            else if (content.ACTUAL_DEAL_USER_ID.Value != LoginID)
        //            {
        //                throw new Exception("只有整改落实人才有权限操整改记录单！");
        //            }

        //            var files = entity.Nav_Files;
        //            entity.Nav_Files = null;

        //            var filesAfter = entity.Nav_FilesAfter;
        //            entity.Nav_FilesAfter = null;

        //            if (entity.OPERARTETYPE == (int)OperateType.Temp)
        //            {
        //                if (content.RiskContentState > (int)RiskContentState.DealTemp)
        //                {
        //                    throw new Exception("该隐患已经进入之后流程【" + ((RiskContentState)content.RiskContentState).GetDescription() + "】，操作失败!");
        //                }

        //                content.RiskContentState = (int)RiskContentState.DealTemp;
        //                entity.Nav_SubmitContent = null;
        //                entity.DEALSITUATION = (int)DealSituation.Temp;
        //                //保存草稿 保存页面数据
        //                UnifiedCommit(() =>
        //                {
        //                    UpdateEntityNoCommit(entity);//修改整改落实人
        //                    UpdateEntityNoCommit(content);
        //                    if (files != null && files.Any())//检查前附件
        //                        BantchSaveEntityNoCommit(files);
        //                    if (filesAfter != null && filesAfter.Any())//检查后附件
        //                        BantchSaveEntityNoCommit(filesAfter);
        //                });
        //            }
        //            else
        //            {
        //                entity.DEALSITUATION = (int)DealSituation.Notice;
        //                //判断是否填写好

        //                if (entity.ENDDATE == null)
        //                {
        //                    throw new Exception("请填写【整改截止时间】!");
        //                }
        //                if (files == null || files.Count < 1)
        //                {
        //                    throw new Exception("请上传【附件（检查前）】!");
        //                }
        //                if (string.IsNullOrEmpty(entity.DEALDESCRIBE))
        //                {
        //                    throw new Exception("请填写【整改情况描述】!");
        //                }
        //                if (filesAfter == null || filesAfter.Count < 1)
        //                {
        //                    throw new Exception("请上传【附件（检查后）】!");
        //                }
        //                //if (entity.ACTUAL_DEAL_USER_ID != content.ACTUAL_DEAL_USER_ID)
        //                //{
        //                //    entity.ACTUAL_DEAL_USER_ID = content.ACTUAL_DEAL_USER_ID;
        //                //}
        //                //如果 操作者和整改责任人不一致 给整改责任人 添加待办
        //                //如果 操作者和整改责任人一致 给验收人 添加待办
        //                if (content.ACTUAL_DEAL_USER_ID != LoginID)
        //                {
        //                    throw new Exception("只有【整改落实人】才能填写隐患整改单！");
        //                }
        //                //if (LoginID == entity.DEAL_USER_ID && entity.Nav_ListUserSign == null)
        //                //{
        //                //    throw new Exception("请签名后再提交!");
        //                //}

        //                string UserName = string.Empty;
        //                T_FM_NOTIFICATION_TASK notice = null;
        //                if (content.RiskContentState == (int)RiskContentState.DealSend)
        //                {
        //                    throw new Exception("该整改单已经在签字阶段，操作失败!");
        //                }
        //                content.RiskContentState = (int)RiskContentState.DealSend;

        //                //if (LoginID == entity.DEAL_USER_ID)
        //                //{
        //                //    //整改责任人 就是 落实整改人
        //                //    //给验收人 发送待办
        //                //    UserName = this.GetEntity<T_FM_USER>(entity.CHECK_USER_ID.Value).NAME;
        //                //    notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改验收单" + ((!content.ISBACK.HasValue || (content.ISBACK.HasValue && !content.ISBACK.Value)) ? "" : "（返单）") + "：" + entity.NAME, entity.ID, entity.ORG_ID, entity.CHECK_USER_ID.Value, UserName, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS044");
        //                //    content.RiskContentState = (int)RiskContentState.DealSign;//整改责任人已经签名
        //                //}
        //                //else
        //                //{
        //                //    //整改责任人 不是 落实整改人
        //                //    //给整改责任人 发送待办
        //                //    UserName = this.GetEntity<T_FM_USER>(entity.DEAL_USER_ID.Value).NAME;
        //                //    notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改验收单" + ((!content.ISBACK.HasValue || (content.ISBACK.HasValue && !content.ISBACK.Value)) ? "" : "（返单）") + "：" + entity.NAME, entity.ID, entity.ORG_ID, entity.DEAL_USER_ID.Value, UserName, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS044");
        //                //}

        //                if (entity.Nav_UserCheck == null)
        //                {
        //                    entity.Nav_UserCheck = this.GetEntity<T_FM_USER>(entity.CHECK_USER_ID.Value);
        //                }
        //                //" + ((!content.ISBACK.HasValue || (content.ISBACK.HasValue && !content.ISBACK.Value)) ? "" : "（返单）") + "
        //                notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改验收单：" + entity.NAME, entity.ID, entity.ORG_ID, entity.CHECK_USER_ID.Value, entity.Nav_UserCheck.NAME, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS044_CHECK");
        //                content.RiskContentState = (int)RiskContentState.DealSign;//整改责任人已经签名


        //                T_FM_NOTIFICATION_TASK task = null;
        //                GetEntityTask(entity.TaskID, ref task);

        //                entity.ISDEALSIGN = true;

        //                //修改 model
        //                UnifiedCommit(() =>
        //                {
        //                    UpdateEntityNoCommit(entity);//修改整改落实人
        //                    UpdateEntityNoCommit(content);//修改明细已签名字
        //                    if (notice != null)//发送待办
        //                        UpdateEntityNoCommit(notice);
        //                    if (task != null)//代办消息 清除
        //                        UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
        //                    if (files != null && files.Any())//检查前附件
        //                        BantchSaveEntityNoCommit(files);
        //                    if (filesAfter != null && filesAfter.Any())//检查后附件
        //                        BantchSaveEntityNoCommit(filesAfter);
        //                    //if (signDeal != null && signDeal.Any())//整改人签名
        //                    //    BantchSaveEntityNoCommit(signDeal);
        //                });

        //            }

        //            #endregion
        //        }
        //        else if (entity.OPERARTETYPE == (int)OperateType.Check)
        //        {
        //            //验收
        //            #region 验收 
        //            if (entity.ACTUAL_DEAL_USER_ID != entity.DEAL_USER_ID && entity.DEAL_USER_ID == LoginID)
        //            {
        //                #region      整改责任人 与 整改落实人不一致   整改责任人 签名   给验收人发送待办
        //                if (content.RiskContentState == (int)RiskContentState.DealSign)
        //                {
        //                    throw new Exception("该整改记录【整改责任人】已签名，操作失败!");
        //                }
        //                entity.ISDEALSIGN = true;

        //                //var signDeal = entity.Nav_ListUserSign;
        //                //entity.Nav_ListUserSign = null;
        //                //foreach (var item in signDeal)
        //                //{
        //                //    item.ORG_ID = entity.ORG_ID;
        //                //}

        //                T_FM_USER modelUser = this.GetEntity<T_FM_USER>(entity.DEAL_USER_ID.Value, new string[] { "Nav_UserSignFiles.Nav_ImgFile.Nav_File" });

        //                //if (signDeal == null)
        //                //{
        //                //    T_BS_RISK_SUBMIT_CONTENT_DEAL_USERSIGN modelSign = GetDign(entity.DEAL_USER_ID.Value, entity.ID, LoginID, entity.ORG_ID.Value, ref modelUser);

        //                //    //T_BS_RISK_SUBMIT_CONTENT_DEAL_USERSIGN modelSign = new T_BS_RISK_SUBMIT_CONTENT_DEAL_USERSIGN();

        //                //    //modelSign.ID = Guid.NewGuid();
        //                //    //modelSign.SUBMIT_CONTENT_DEAL_ID = entity.ID;
        //                //    //modelSign.SIGNTYPE = (int)SIGNTYPE.Deal;
        //                //    //modelSign.SUSER_ID = LoginID;

        //                //    //modelSign.IMG_FILE_ID = modelUser.Nav_UserSignFiles[0].Nav_ImgFile.Nav_File.ID;

        //                //    //modelSign.ORG_ID = entity.ORG_ID;

        //                //    signDeal.Add(modelSign);
        //                //}

        //                string UserName = modelUser.NAME;

        //                var notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改验收单：" + entity.NAME, entity.ID, entity.ORG_ID, entity.CHECK_USER_ID.Value, UserName, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS044");

        //                T_FM_NOTIFICATION_TASK task = null;
        //                GetEntityTask(entity.TaskID, ref task);

        //                content.RiskContentState = (int)RiskContentState.DealSign;
        //                entity.Nav_SubmitContent = null;

        //                //修改 model
        //                UnifiedCommit(() =>
        //                {
        //                    UpdateEntityNoCommit(entity);//修改整改落实人
        //                    UpdateEntityNoCommit(content);//修改明细已签名字

        //                    if (notice != null)//发送待办
        //                        UpdateEntityNoCommit(notice);
        //                    if (task != null)//代办消息 清除
        //                        UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
        //                    //if (signDeal != null && signDeal.Any())//整改人签名
        //                    //    BantchSaveEntityNoCommit(signDeal);
        //                });


        //                #endregion

        //            }
        //            else if (entity.CHECK_USER_ID == LoginID)
        //            {
        //                #region      验收人 验收  签名 完成情况  审批流/返回  
        //                if (entity.DEALSITUATION == 10 || entity.DEALSITUATION == 30 || entity.DEALSITUATION == 40)
        //                {
        //                    //if (entity.Nav_ListUserSign == null || entity.Nav_ListUserSign.Count < 1)
        //                    //{
        //                    //    throw new Exception("请待整改责任人签名后再验收!");
        //                    //} 
        //                    if (content.RiskContentState == (int)RiskContentState.CheckSign)
        //                    {
        //                        throw new Exception("该整改记录【验收人】已签名，操作失败!");
        //                    }
        //                    else if (content.RiskContentState != (int)RiskContentState.DealSign)
        //                    {
        //                        throw new Exception("该单处于" + ((RiskContentState)content.RiskContentState).GetDescription() + "阶段，验收人不能执行验收，操作失败!");
        //                    }
        //                    entity.ISCHECKSIGN = true;
        //                    //var sign = entity.Nav_ListCheckUserSign;
        //                    //entity.Nav_ListCheckUserSign = null;
        //                    //if (sign == null || sign.Count < 1)
        //                    //{
        //                    //    throw new Exception("请签名!");
        //                    //}

        //                    //foreach (var file in sign)
        //                    //{
        //                    //    file.ORG_ID = entity.ORG_ID;
        //                    //}


        //                    if (entity.DEALSITUATION == (int)DealSituation.OK)
        //                    {
        //                        #region   验收通过

        //                        //添加审批流
        //                        string parms = string.Empty;
        //                        if (entity.QUESTION_LEVEL == 10)
        //                        {
        //                            parms = "_" + entity.QUESTION_LEVEL.ToString() + "_";
        //                        }
        //                        else
        //                        {
        //                            parms = "_20_30_40_50_";
        //                        }

        //                        var sysFilter = new SystemCodeFilter();
        //                        sysFilter.CodeType = (int)PFCodeRuleType.审批流编码;
        //                        sysFilter.Count = 1;
        //                        sysFilter.OrgId = entity.ORG_ID;
        //                        var serialCode = CodeRuleService.NewGenSerial(sysFilter);


        //                        entity.APPROVE_ID = Guid.NewGuid();
        //                        entity.CHECK_USER_ID = LoginID;


        //                        #region 检查上报 明细 状态更新  验收时间、 验收人

        //                        //T_BS_RISK_SUBMIT_CONTENT modelContent = entity.Nav_SubmitContent;
        //                        //if (modelContent == null)
        //                        //{
        //                        //    modelContent = this.GetEntity<T_BS_RISK_SUBMIT_CONTENT>(entity.RISK_SUBMIT_CONTENT_ID.Value);
        //                        //}
        //                        //switch (entity.DEALSITUATION)
        //                        //{
        //                        //    case 10:
        //                        //        content.RiskContentState = (int)RiskContentState.CheckNotOK;
        //                        //        break;
        //                        //    case 30:
        //                        //        content.RiskContentState = (int)RiskContentState.OKPart;
        //                        //        break;
        //                        //    case 40:
        //                        //        content.RiskContentState = (int)RiskContentState.OK;
        //                        //        break;
        //                        //    default:
        //                        //        break;
        //                        //}
        //                        //if (entity.ACTUAL_DEAL_USER_ID == entity.DEAL_USER_ID)
        //                        //{
        //                        //    entity.CHCECKTIME = DateTime.Now;
        //                        //}

        //                        content.CHECKDATE = entity.CHCECKTIME;
        //                        content.CHECK_USER_ID = entity.CHECK_USER_ID;
        //                        content.RiskContentState = (int)RiskContentState.CheckSign;//验收人签名 审核完成后才能ok

        //                        #endregion
        //                        if (entity.Nav_Submit == null)
        //                        {
        //                            entity.Nav_Submit = this.GetEntity<T_BS_RISK_SUBMIT>(entity.RISK_SUBMIT_ID.Value);
        //                        }

        //                        //审批流
        //                        MFlowPermitService.InsertApprove(serialCode, "BS043", parms, entity.ID, "BS044_SHOWPRINT", entity.TaskID, true, () =>
        //                        {
        //                            if (entity != null)
        //                                UpdateEntityNoCommit(entity);   //保存主表 NoCommit
        //                            //BantchSaveEntityNoCommit(sign);    //验收人签名
        //                            UpdateEntityNoCommit(content);//上报明细 修改状态
        //                        }, entity.APPROVE_ID, entity.Nav_Submit.CREATER_ID.Value);

        //                        #endregion
        //                    }
        //                    else
        //                    {
        //                        //验收人验收未通过 
        //                        //给整改落实人 添加待办
        //                        // 
        //                        #region     验收 未完成 完成部分

        //                        if (string.IsNullOrEmpty(entity.DEALOPINION))
        //                        {
        //                            throw new Exception("请填写【" + ((DealSituation)entity.DEALSITUATION).GetDescription() + "】验收意见!");
        //                        }

        //                        T_BS_RISK_SUBMIT_CONTENT modelContentBack = new T_BS_RISK_SUBMIT_CONTENT();
        //                        modelContentBack.ID = Guid.NewGuid();
        //                        modelContentBack.ISBACK = true;
        //                        modelContentBack.PARENTID = content.ID;
        //                        modelContentBack.RISK_SUBMIT_ID = content.RISK_SUBMIT_ID;
        //                        modelContentBack.CODE = content.CODE;
        //                        modelContentBack.NAME = "（返）" + content.NAME;
        //                        modelContentBack.CHECK_MAIN_ID = content.CHECK_MAIN_ID;
        //                        modelContentBack.CHECK_QUESTION_ID = content.CHECK_QUESTION_ID;
        //                        modelContentBack.ADDRESS = content.ADDRESS;
        //                        modelContentBack.USER_ID = content.USER_ID;
        //                        modelContentBack.DEPARTMENT_ID = content.DEPARTMENT_ID;
        //                        modelContentBack.IS_DELETED = content.IS_DELETED;
        //                        modelContentBack.ORG_ID = content.ORG_ID;
        //                        modelContentBack.FORM_ID = content.FORM_ID;
        //                        modelContentBack.ACTUAL_DEAL_USER_ID = content.ACTUAL_DEAL_USER_ID;
        //                        modelContentBack.CHECK_USER_ID = content.CHECK_USER_ID;
        //                        modelContentBack.DEALDATE = content.DEALDATE;
        //                        modelContentBack.DEAL_DEPARTMENT_ID = content.DEAL_DEPARTMENT_ID;
        //                        modelContentBack.DEAL_USER_ID = content.DEAL_USER_ID;
        //                        modelContentBack.DEMAND = content.DEMAND;
        //                        modelContentBack.LastDateSystem = content.LastDateSystem;
        //                        modelContentBack.LastDateUser = content.LastDateUser;
        //                        modelContentBack.NOTICEDATE = content.NOTICEDATE;
        //                        modelContentBack.OKDATE = content.OKDATE;
        //                        modelContentBack.QUESTION_LEVEL = content.QUESTION_LEVEL;
        //                        modelContentBack.REPORTDATE = content.REPORTDATE;
        //                        modelContentBack.RiskContentState = content.RiskContentState;
        //                        modelContentBack.RISK_SUBMIT_NOTICE_PERSON_ID = content.RISK_SUBMIT_NOTICE_PERSON_ID;
        //                        modelContentBack.SAFE_CHECK_DETAIL_ID = content.SAFE_CHECK_DETAIL_ID;
        //                        modelContentBack.SAFE_CHECK_ID = content.SAFE_CHECK_ID;
        //                        modelContentBack.RISK_SUBMIT_NOTICE_ID = content.RISK_SUBMIT_NOTICE_ID;
        //                        modelContentBack.RiskContentState = (int)RiskContentState.ActualDealChange;//直接从修改 验收开始
        //                        //modelBack.ENTITY_ORG_TPYE  = content.ENTITY_ORG_TPYE;
        //                        //modelBack.FLOW_STATUS      = content.FLOW_STATUS;
        //                        //modelBack.FLOW_SEND_STATUS = content.FLOW_SEND_STATUS;
        //                        //modelBack.FLOW_ID    = content.FLOW_ID;
        //                        //modelBack.CREATE_TIME= content.  ;
        //                        //modelBack.MODIFY_TIME= content.  ;
        //                        //modelBack.CREATER_ID = content.  ;
        //                        //modelBack.MODIFIER_ID= content.  ;
        //                        //modelBack.CHECKDATE  = content.  ;
        //                        //modelBack.APPROVE_ID = content.  ;

        //                        T_BS_RISK_SUBMIT_CONTENT_DEAL dealTemp = new T_BS_RISK_SUBMIT_CONTENT_DEAL();
        //                        dealTemp.ID = Guid.NewGuid();
        //                        dealTemp.ORG_ID = modelContentBack.ORG_ID;
        //                        dealTemp.RISK_SUBMIT_ID = modelContentBack.RISK_SUBMIT_ID;
        //                        dealTemp.RISK_SUBMIT_NOTICE_ID = modelContentBack.RISK_SUBMIT_NOTICE_ID;
        //                        dealTemp.RISK_SUBMIT_NOTICE_PERSON_ID = modelContentBack.RISK_SUBMIT_NOTICE_PERSON_ID;
        //                        dealTemp.RISK_SUBMIT_CONTENT_ID = modelContentBack.ID;
        //                        dealTemp.CODE = modelContentBack.CODE;
        //                        dealTemp.NAME = modelContentBack.NAME.Replace("隐患整改通知：", "");
        //                        dealTemp.QUESTION_LEVEL = modelContentBack.QUESTION_LEVEL;
        //                        dealTemp.DEALSITUATION = (int)DealSituation.Notice;
        //                        dealTemp.DEAL_USER_ID = modelContentBack.DEAL_USER_ID;
        //                        dealTemp.ACTUAL_DEAL_USER_ID = modelContentBack.ACTUAL_DEAL_USER_ID;
        //                        dealTemp.CHECK_USER_ID = modelContentBack.CHECK_USER_ID;

        //                        //添加处理单
        //                        //处理明细
        //                        //添加通知 （整改责任人 落实整改人）
        //                        //添加待办 落实整改人 
        //                        string UserNameActure = GetEntity<T_FM_USER>(e => e.ID == modelContentBack.ACTUAL_DEAL_USER_ID.Value).NAME;
        //                        var noticeActualDeal = NotificationTaskService.InsertUserNoticeTaskModel("隐患（返）整改单：" + modelContentBack.NAME.Replace("隐患整改通知：", ""), dealTemp.ID, entity.ORG_ID, modelContentBack.ACTUAL_DEAL_USER_ID.Value, UserNameActure, DateTime.Now, modelContentBack.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044");

        //                        //给责任人 和落实人添加整改单

        //                        string UserNameDeal = modelContentBack.DEAL_USER_ID == modelContentBack.ACTUAL_DEAL_USER_ID ? UserNameActure : GetEntity<T_FM_USER>(e => e.ID == modelContentBack.DEAL_USER_ID.Value).NAME;

        //                        var noticeDeal = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改通知（返）：" + entity.NAME, entity.ID, entity.ORG_ID, modelContentBack.DEAL_USER_ID.Value, UserNameDeal, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS042_SHOWPRINT");
        //                        T_FM_NOTIFICATION_TASK noticeActual = null;
        //                        //如果整改责任人和实际整改人不一致
        //                        if (modelContentBack.DEAL_USER_ID != modelContentBack.ACTUAL_DEAL_USER_ID)
        //                        {
        //                            noticeActual = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改通知（返）：" + entity.NAME, entity.ID, entity.ORG_ID, modelContentBack.ACTUAL_DEAL_USER_ID.Value, UserNameActure, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "BS042_SHOWPRINT");
        //                        }


        //                        T_FM_NOTIFICATION_TASK task = null;
        //                        GetEntityTask(entity.TaskID, ref task);

        //                        //验收未完成/完成部分
        //                        //添加新的处理单  返修明细（之前复制 添加标识符）
        //                        //发一个新单给落实整改人重新走流程 时间信息按之前的
        //                        //附属单 登记前一单信息
        //                        //放到后面
        //                        ////modelBack.ID = content.ID;

        //                        //验收未完成
        //                        //实际整改人 整改责任人 发送通知 和给实际整改人发送待办


        //                        //MFlowPermitService.InsertApprove(serialCode, "BS043", parms, entity.ID, "BS044_SHOWPRINT", entity.TaskID, true, () =>
        //                        //{
        //                        //    if (entity != null)
        //                        //        UpdateEntityNoCommit(entity);   //保存主表 NoCommit
        //                        //    BantchSaveEntityNoCommit(sign);    //验收人签名
        //                        //    UpdateEntityNoCommit(modelContent);//上报明细 修改状态
        //                        //}, entity.APPROVE_ID, entity.Nav_Submit.CREATER_ID.Value);


        //                        content.RiskContentState = (int)RiskContentState.OKNotBack;
        //                        this.UnifiedCommit(() =>
        //                        {
        //                            UpdateEntityNoCommit(entity);//审核信息 验收状态修改
        //                            UpdateEntityNoCommit(content);//明细信息修改
        //                            //BantchSaveEntityNoCommit(sign);//签名信息
        //                            UpdateEntityNoCommit(modelContentBack);//新增明细
        //                            UpdateEntityNoCommit(dealTemp);//新增明细单
        //                            UpdateEntityNoCommit(noticeActualDeal);//整改单通知
        //                            UpdateEntityNoCommit(noticeDeal);
        //                            if (noticeActual != null)
        //                                UpdateEntityNoCommit(noticeActual);
        //                            if (task != null)//代办消息 清除
        //                                UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");

        //                        });

        //                        #endregion
        //                    }
        //                }
        //                else
        //                {
        //                    throw new Exception("请选择完成情况【未完成、部分完成、已完成】!");
        //                }
        //                #endregion
        //            }
        //            else
        //            {
        //                throw new Exception("您不是整改责任人或者验收人，操作失败!");
        //            }
        //            #endregion
        //        }
        //        return true;
        //    });
        //}

        #endregion


        /// <summary>
        /// 验收
        /// 
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("CheckDeal")]
        public JsonActionResult<bool> CheckDeal([FromBody] KeywordFilter filter)
        {
            //整改责任人验收  通过 给验收人 发送待办
            //验收人验收 通过  发起审批流
            //不通过  返给 整改落实人

            //var sysFilter = new SystemCodeFilter();
            //sysFilter.CodeType = (int)PFCodeRuleType.审批流编码;
            //sysFilter.Count = 2;
            //sysFilter.OrgId = filter.OrgId;
            ////var serialCode = CodeRuleService.NewGenSerial(sysFilter);
            //List<string> listCode = CodeRuleService.NewGenSerial(sysFilter).Split(',').ToList();
            return SafeExecute<bool>(() =>
            {
                int DEALSITUATION = 0;
                try
                {
                    DEALSITUATION = int.Parse(filter.Parameter2);
                }
                catch
                {
                    throw new Exception("传参有误！");
                }
                if (DEALSITUATION != 10 && DEALSITUATION != 30 && DEALSITUATION != 40)
                {
                    throw new Exception("请选择完成情况【未完成、部分完成、已完成】!");
                }

                if (string.IsNullOrEmpty(filter.Parameter3) && DEALSITUATION != 40)
                {
                    throw new Exception("请填写【" + ((DealSituation)DEALSITUATION).GetDescription() + "】验收意见!");
                }

                var DataID = new Guid(filter.Keyword);
                var TaskID = new Guid(filter.Parameter1);
                var entity = GetEntity<T_BS_RISK_SUBMIT_CONTENT_DEAL>(DataID, new string[] { "Nav_SubmitContent.Nav_UserActualDeal", "Nav_SubmitContent.Nav_UserCheck", "Nav_Submit" });
                //指定后 给整改落实人 发送通知

                entity.DEALSITUATION = DEALSITUATION;
                //entity.DEALOPINION = filter.Parameter3;
                if (string.IsNullOrEmpty(entity.DEALOPINION))
                {
                    entity.DEALOPINION = "同意";
                }
                T_FM_NOTIFICATION_TASK task = null;
                GetEntityTask(TaskID, ref task);

                var content = entity.Nav_SubmitContent;
                //entity.Nav_SubmitContent = null;//不能加否则 做保存的时候  Nav_SubmitContent 对应的外键ID 会变成null
                var loginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;

                if (content.RiskContentState == (int)RiskContentState.DealSend)//整改责任人 驳回
                {
                    entity.DEALOPINION = filter.Parameter3;

                    if (content.DEAL_USER_ID != loginID)
                    {
                        throw new Exception("只有整改责任人才能验收！");
                    }
                    //if (content.ISDEALUSERCHECK)  //不需要 ISCHECKERCHECK  制表就确认了 在此根据状态判断
                    //{
                    //    throw new Exception("改整改记录整改责任人已验收，操作失败！");
                    //}
                }
                else if (content.RiskContentState == (int)RiskContentState.DealSign)//验收人 驳回
                {
                    entity.CHECKOPINION = filter.Parameter3;

                    if (content.CHECK_USER_ID != loginID)
                    {
                        throw new Exception("只有验收人才能验收！");
                    }
                    //不需要 ISCHECKERCHECK  制表就确认了 在此根据状态判断
                    //if (content.ISCHECKERCHECK)
                    //{
                    //    throw new Exception("改整改记录验收人已验收，操作失败！");
                    //}
                }
                DateTime? TASK_ENDDT = null;
                if (task != null)
                    TASK_ENDDT = task.TASK_ENDDT;

                if (entity.DEALSITUATION == (int)DealSituation.OK)
                {
                    //通过
                    if (content.RiskContentState == (int)RiskContentState.DealSend)//整改落实人 提交整改记录 整改责任人 验收
                    {
                        #region   整改责任人验收通过 给验收人发送审核待办 

                        content.RiskContentState = (int)RiskContentState.DealSign;//整改责任人已经签名
                        entity.ISDEALSIGN = true;
                        entity.DATETIME_DEALSIGN = DateTime.Now;
                        DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_Checker_Check, entity.ORG_ID.Value, DateTime.Now, null, content.LastDateUser);
                        var notice = NotificationTaskService.InsertUserNoticeTaskModel("验收人确认整改：" + entity.NAME, entity.ID, entity.ORG_ID, entity.CHECK_USER_ID.Value, entity.Nav_UserCheck.NAME, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS044_CHECK");//隐患整改验收单

                        var listLog = OperateLogService.GetListOperateLog(OPERATEPOINT_Enums.RiskDealDealCheck, entity.RISK_SUBMIT_ID.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, null, new List<Guid>() { entity.CHECK_USER_ID.Value }, new List<string>() { entity.Nav_UserCheck.NAME }, entity.ORG_ID, content.ID, null, false, TASK_ENDDT);

                        this.UnifiedCommit(() =>
                        {
                            UpdateEntityNoCommit(entity);//审核信息 验收状态修改  审批意见 完成情况
                            UpdateEntityNoCommit(content);//明细信息修改
                            UpdateEntityNoCommit(notice);//给验收人发送整改单通知
                            if (task != null)//代办消息 清除
                                UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                            if (listLog != null && listLog.Any())
                                BantchSaveEntityNoCommit(listLog);
                        });

                        #endregion

                    }
                    else if (content.RiskContentState == (int)RiskContentState.DealSign)//整改责任人 已验收   验收人验收
                    {

                        #region  验收人 验收通过  发起审批流

                        entity.ISCHECKSIGN = true;
                        entity.DATETIME_CHECKSIGN = DateTime.Now;
                        entity.CHCECKTIME = DateTime.Now;
                        content.CHECKDATE = DateTime.Now;//验收时间
                        entity.ENDDATE = DateTime.Now;

                        //添加审批流
                        string parms = string.Empty;
                        if (entity.QUESTION_LEVEL == 10)
                        {
                            parms = "_" + entity.QUESTION_LEVEL.ToString() + "_";
                        }
                        else
                        {
                            parms = "_20_30_40_50_";
                        }

                        entity.APPROVE_ID = Guid.NewGuid();

                        #region 检查上报 明细 状态更新  验收时间、 验收人

                        content.CHECKDATE = entity.CHCECKTIME;
                        //content.CHECK_USER_ID = entity.CHECK_USER_ID;
                        content.RiskContentState = (int)RiskContentState.CheckSign;//验收人签名 审核完成后才能ok

                        #endregion
                        if (entity.Nav_Submit == null)
                        {
                            entity.Nav_Submit = this.GetEntity<T_BS_RISK_SUBMIT>(entity.RISK_SUBMIT_ID.Value);
                        }
                        var code = DateTime.Now.ToString("yyyyMMddHHmm");
                        List<string> listCode = new List<string>() { code + "1", code + "2" };
                        Guid approveUserId = entity.Nav_Submit.CREATER_ID.Value;
                        //审批流
                        if (entity.Nav_Submit.SUBMIT_TYPE != 10)
                        {
                            //如果非检查上报 按责任人 找审批流
                            approveUserId = entity.DEAL_USER_ID.Value;
                        }
                        MFlowPermitService.InsertApprove(listCode[0], "BS043", parms, entity.ID, "BS044_SHOWPRINT", TaskID, true, () =>
                        {
                            if (entity != null)
                                UpdateEntityNoCommit(entity);   //保存主表 NoCommit
                                                                //BantchSaveEntityNoCommit(sign);    //验收人签名
                            UpdateEntityNoCommit(content);//上报明细 修改状态
                        }, entity.APPROVE_ID, approveUserId, null, null, listCode[1], "", null, "", FMTASKTYPE.BS_RiskUp_DealAudit, null, null, (int)OPERATEPOINT_Enums.RiskDealCheckerCheck, content.RISK_SUBMIT_ID, content.ID);

                        #endregion
                    }
                    else
                    {
                        throw new Exception("整改记录状态为【" + ((RiskContentState)content.RiskContentState).GetDescription() + "】操作失败！");
                    }
                }
                else
                {
                    #region  //整改责任人  驳回 附件整改后 移到整改前
                    var listFilesAfter = GetEntities<T_BS_RISK_SUBMIT_CONTENT_DEAL_AFTER_FILE>(e => e.RISK_SUBMIT_CONTENT_DEAL_ID == entity.ID, null, null);
                    List<Guid> ids = listFilesAfter.Select(e => e.ID).ToList();
                    List<T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE> listFiles = new List<T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE>();
                    if (listFilesAfter != null && listFilesAfter.Any())
                    {
                        foreach (var item in listFilesAfter)
                        {
                            listFiles.Add(new T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE()
                            {
                                ID = item.ID,//ID不变 别的不变
                                ORG_ID = item.ORG_ID,
                                RISK_SUBMIT_CONTENT_DEAL_ID = item.RISK_SUBMIT_CONTENT_DEAL_ID,
                                IMG_FILE_ID = item.IMG_FILE_ID,
                                CREATER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID,
                                CREATE_TIME = DateTime.Now
                            });
                        }
                    }

                    #endregion

                    #region   验收未通过  直接驳回给 整改落实人

                    //entity.ISCHECKSIGN = true;

                    //entity.CHCECKTIME = DateTime.Now;
                    //content.CHECKDATE = DateTime.Now;//验收时间

                    entity.ISCHECKSIGN = false;
                    entity.ISDEALSIGN = false;

                    //添加处理单
                    //处理明细
                    //添加通知 （整改责任人 落实整改人）
                    //添加待办 落实整改人 
                    var noticeActualDeal = NotificationTaskService.InsertUserNoticeTaskModel("【驳回】隐患整改单：" + content.NAME.Replace("隐患整改通知：", ""), entity.ID, entity.ORG_ID, content.ACTUAL_DEAL_USER_ID.Value, content.Nav_UserActualDeal.NAME, DateTime.Now, content.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044");//隐患(返)整改单：=>【驳回】隐患整改单：

                    //给责任人 和落实人添加整改单

                    content.RiskContentState = (int)RiskContentState.OKNotBack;

                    #region    操作日志

                    List<T_BS_OPERATE_LOG> listLog = null;
                    if (APT.Infrastructure.Api.AppContext.CurrentSession.UserID.HasValue && APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value == content.DEAL_USER_ID)
                    {
                        listLog = OperateLogService.GetListOperateLog(OPERATEPOINT_Enums.RiskDealDealCheckReject, entity.RISK_SUBMIT_ID.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, null, new List<Guid>() { content.ACTUAL_DEAL_USER_ID.Value }, new List<string>() { content.Nav_UserActualDeal.NAME }, entity.ORG_ID, entity.RISK_SUBMIT_CONTENT_ID, null, false, content.LastDateUser.Value);
                    }
                    else
                    {
                        listLog = OperateLogService.GetListOperateLog(OPERATEPOINT_Enums.RiskDealCheckerCheckReject, entity.RISK_SUBMIT_ID.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, null, new List<Guid>() { content.ACTUAL_DEAL_USER_ID.Value }, new List<string>() { content.Nav_UserActualDeal.NAME }, entity.ORG_ID, entity.RISK_SUBMIT_CONTENT_ID, null, false, content.LastDateUser.Value);
                    }

                    #endregion


                    this.UnifiedCommit(() =>
                    {
                        UpdateEntityNoCommit(entity);//审核信息 验收状态修改  审批意见 完成情况
                        UpdateEntityNoCommit(content);//明细信息修改
                        UpdateEntityNoCommit(noticeActualDeal);//整改单通知
                        if (task != null)//代办消息 清除
                            UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                        if (listFilesAfter != null && listFilesAfter.Any())
                            BantchDeleteEntityNoCommit<T_BS_RISK_SUBMIT_CONTENT_DEAL_AFTER_FILE>(ids);
                        if (listFiles != null && listFiles.Any())
                            BantchSaveEntityNoCommit(listFiles);
                        if (listLog != null && listLog.Any())
                            BantchSaveEntityNoCommit(listLog);
                    });

                    #endregion

                }

                return true;
            });
        }


        #region    验收人验收

        ///// <summary>
        ///// 整改落实人 确认整改通知单 系统发送整改单给整改落实人
        ///// </summary>
        ///// <param name="filter"></param>
        ///// <returns></returns>
        //[HttpPost, Route("CheckDeal")]
        //public JsonActionResult<bool> CheckDeal([FromBody] KeywordFilter filter)
        //{
        //    var sysFilter = new SystemCodeFilter();
        //    sysFilter.CodeType = (int)PFCodeRuleType.审批流编码;
        //    sysFilter.Count = 2;
        //    sysFilter.OrgId = filter.OrgId;
        //    //var serialCode = CodeRuleService.NewGenSerial(sysFilter);
        //    List<string> listCode = CodeRuleService.NewGenSerial(sysFilter).Split(',').ToList();
        //    return SafeExecute<bool>(() =>
        //    {
        //        int DEALSITUATION = 0;
        //        try
        //        {
        //            DEALSITUATION = int.Parse(filter.Parameter2);
        //        }
        //        catch
        //        {
        //            throw new Exception("传参有误！");
        //        }
        //        if (DEALSITUATION != 10 && DEALSITUATION != 30 && DEALSITUATION != 40)
        //        {
        //            throw new Exception("请选择完成情况【未完成、部分完成、已完成】!");
        //        }

        //        if (string.IsNullOrEmpty(filter.Parameter3) && DEALSITUATION != 40)
        //        {
        //            throw new Exception("请填写【" + ((DealSituation)DEALSITUATION).GetDescription() + "】验收意见!");
        //        }

        //        var DataID = new Guid(filter.Keyword);
        //        var TaskID = new Guid(filter.Parameter1);
        //        var entity = GetEntity<T_BS_RISK_SUBMIT_CONTENT_DEAL>(DataID, new string[] { "Nav_SubmitContent.Nav_UserActualDeal", "Nav_Submit" });
        //        //指定后 给整改落实人 发送通知

        //        entity.DEALSITUATION = DEALSITUATION;
        //        entity.DEALOPINION = filter.Parameter3;
        //        if (string.IsNullOrEmpty(entity.DEALOPINION))
        //        {
        //            entity.DEALOPINION = "同意";
        //        }
        //        T_FM_NOTIFICATION_TASK task = null;
        //        GetEntityTask(TaskID, ref task);

        //        var content = entity.Nav_SubmitContent;
        //        //entity.Nav_SubmitContent = null;//不能加否则 做保存的时候  Nav_SubmitContent 对应的外键ID 会变成null


        //        if (content.RiskContentState == (int)RiskContentState.CheckSign)
        //        {
        //            throw new Exception("该整改记录【验收人】已签名，操作失败!");
        //        }
        //        //else if (content.RiskContentState != (int)RiskContentState.DealSign)
        //        //{
        //        //    throw new Exception("该单处于" + ((RiskContentState)content.RiskContentState).GetDescription() + "阶段，验收人不能执行验收，操作失败!");
        //        //}


        //        if (entity.DEALSITUATION == (int)DealSituation.OK)
        //        {
        //            entity.ISCHECKSIGN = true;

        //            entity.CHCECKTIME = DateTime.Now;
        //            content.CHECKDATE = DateTime.Now;//验收时间


        //            entity.ENDDATE = DateTime.Now;

        //            #region   验收通过

        //            //添加审批流
        //            string parms = string.Empty;
        //            if (entity.QUESTION_LEVEL == 10)
        //            {
        //                parms = "_" + entity.QUESTION_LEVEL.ToString() + "_";
        //            }
        //            else
        //            {
        //                parms = "_20_30_40_50_";
        //            }


        //            entity.APPROVE_ID = Guid.NewGuid();



        //            #region 检查上报 明细 状态更新  验收时间、 验收人

        //            content.CHECKDATE = entity.CHCECKTIME;
        //            //content.CHECK_USER_ID = entity.CHECK_USER_ID;
        //            content.RiskContentState = (int)RiskContentState.CheckSign;//验收人签名 审核完成后才能ok

        //            #endregion
        //            if (entity.Nav_Submit == null)
        //            {
        //                entity.Nav_Submit = this.GetEntity<T_BS_RISK_SUBMIT>(entity.RISK_SUBMIT_ID.Value);
        //            }

        //            //审批流
        //            MFlowPermitService.InsertApprove(listCode[0], "BS043", parms, entity.ID, "BS044_SHOWPRINT", TaskID, true, () =>
        //            {
        //                if (entity != null)
        //                    UpdateEntityNoCommit(entity);   //保存主表 NoCommit
        //                                                    //BantchSaveEntityNoCommit(sign);    //验收人签名
        //                UpdateEntityNoCommit(content);//上报明细 修改状态
        //            }, entity.APPROVE_ID, entity.Nav_Submit.CREATER_ID.Value, null, null, listCode[1]);

        //            #endregion
        //        }
        //        else
        //        {

        //            #region   验收未通过  直接驳回给 整改落实人

        //            //entity.ISCHECKSIGN = true;

        //            //entity.CHCECKTIME = DateTime.Now;
        //            //content.CHECKDATE = DateTime.Now;//验收时间


        //            //添加处理单
        //            //处理明细
        //            //添加通知 （整改责任人 落实整改人）
        //            //添加待办 落实整改人 
        //            var noticeActualDeal = NotificationTaskService.InsertUserNoticeTaskModel("隐患（返）整改单：" + content.NAME.Replace("隐患整改通知：", ""), entity.ID, entity.ORG_ID, content.ACTUAL_DEAL_USER_ID.Value, content.Nav_UserActualDeal.NAME, DateTime.Now, content.LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044");

        //            //给责任人 和落实人添加整改单

        //            content.RiskContentState = (int)RiskContentState.OKNotBack;
        //            this.UnifiedCommit(() =>
        //            {
        //                UpdateEntityNoCommit(entity);//审核信息 验收状态修改  审批意见 完成情况
        //                UpdateEntityNoCommit(content);//明细信息修改
        //                UpdateEntityNoCommit(noticeActualDeal);//整改单通知
        //                if (task != null)//代办消息 清除
        //                    UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
        //            });

        //            #endregion


        //        }


        //        return true;
        //    });
        //} 
        #endregion




        /// <summary>
        /// 获取签名
        /// </summary>
        /// <param name="USER_ID"></param>
        /// <param name="DEAL_ID"></param>
        /// <param name="LoginID"></param>
        /// <param name="ORG_ID"></param>
        /// <param name="modelUser"></param>
        /// <returns></returns>
        public T_BS_RISK_SUBMIT_CONTENT_DEAL_USERSIGN GetDign(Guid USER_ID, Guid DEAL_ID, Guid LoginID, Guid ORG_ID, ref T_FM_USER modelUser)
        {
            modelUser = this.GetEntity<T_FM_USER>(USER_ID, new string[] { "Nav_UserSignFiles.Nav_ImgFile.Nav_File" });

            T_BS_RISK_SUBMIT_CONTENT_DEAL_USERSIGN modelSign = new T_BS_RISK_SUBMIT_CONTENT_DEAL_USERSIGN();
            modelSign.ID = Guid.NewGuid();
            modelSign.SUBMIT_CONTENT_DEAL_ID = DEAL_ID;
            modelSign.SIGNTYPE = (int)SIGNTYPE.Deal;
            modelSign.SUSER_ID = LoginID;

            modelSign.IMG_FILE_ID = modelUser.Nav_UserSignFiles[0].Nav_ImgFile.Nav_File.ID;

            modelSign.ORG_ID = ORG_ID;
            return modelSign;
        }


        /// <summary>
        /// 隐患上报  完成   修改各种状态   完善隐患库
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet, Route("DealEnd")]
        public JsonActionResult<bool> DealEnd(string id)
        {
            return SafeExecute<bool>(() =>
            {
                return ApproveCallBackService.CallBack("BS/BSRiskSubmit/DealEnd", id);
            });
        }


        ///// <summary>
        ///// 隐患上报  完成   修改各种状态   完善隐患库
        ///// api/BS/BSRiskSubmit/DealEnd
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //[HttpGet, Route("DealEnd")]
        //public JsonActionResult<bool> DealEnd(string id)
        //{
        //    return SafeExecute<bool>(() =>
        //    {
        //        var deal = GetEntity<T_BS_RISK_SUBMIT_CONTENT_DEAL>(id, new string[] { "Nav_Submit.Nav_ListRiskSubmitContent", "Nav_SubmitContent.Nav_CheckMain.Nav_CheckQuestion", "Nav_SubmitContent.Nav_SafeCheckDetail" });

        //        deal.DEALSITUATION = (int)DealSituation.End;//结束

        //        T_BS_RISK_SUBMIT subModel = deal.Nav_Submit;
        //        List<T_BS_RISK_SUBMIT_CONTENT> listContent = subModel.Nav_ListRiskSubmitContent;

        //        //如果是手动上报 都是选择检查问题 不存在隐患入库

        //        var content = deal.Nav_SubmitContent;
        //        //deal.Nav_SubmitContent = null;//不能清空  否则RISK_SUBMIT_CONTENT_ID 会被清空

        //        var modelNoOK = listContent.FirstOrDefault(e => e.ID != content.ID && (!e.ISBACK.HasValue || !e.ISBACK.Value) && e.RiskContentState.HasValue && e.RiskContentState != (int)RiskContentState.OK && e.RiskContentState != (int)RiskContentState.BackOK);
        //        if (modelNoOK == null)
        //        {
        //            subModel.ISORDEREND = true;
        //        }

        //        content.OKDATE = DateTime.Now;
        //        content.RiskContentState = (int)RiskContentState.OK;
        //        List<T_BS_RISK_SUBMIT_CONTENT> listModelContent = null;
        //        List<T_BS_RISK_SUBMIT_CONTENT_DEAL> listModelContentDetail = null;
        //        if (content.ISBACK.HasValue && content.ISBACK.Value && content.PARENTID.HasValue)
        //        {
        //            listModelContent = new List<T_BS_RISK_SUBMIT_CONTENT>();
        //            GetConnects(content.PARENTID, ref listModelContent);

        //        }
        //        if (listModelContent != null && listModelContent.Count > 0)
        //        {
        //            List<Guid> listDetailID = listModelContent.Select(x => x.ID).ToList();
        //            listModelContentDetail = GetEntities<T_BS_RISK_SUBMIT_CONTENT_DEAL>(e => e.RISK_SUBMIT_CONTENT_ID.HasValue && listDetailID.Contains(e.RISK_SUBMIT_CONTENT_ID.Value), null, null).ToList();
        //            foreach (var item in listModelContent)
        //            {
        //                item.RiskContentState = (int)RiskContentState.BackOK;
        //                item.CHECKDATE = content.CHECKDATE;
        //            }

        //            foreach (var item in listModelContentDetail)
        //            {
        //                item.CHCECKTIME = content.CHECKDATE;
        //                item.DEALSITUATION = (int)DealSituation.End;
        //            }
        //        }

        //        var check = content.Nav_CheckMain;

        //        //根据隐患上报中检查结果 
        //        //未发现此问题 无需隐患上报
        //        //以问题描述一致 无需完善隐患库

        //        //其他  手动填写 需要完善隐患库 
        //        //书写 隐患待上报 内容 发送给安环部对应的人 标准化描述 再审批流 入库   

        //        T_BS_RISK_SUBMIT_CONTENT_TEMP modelTemp = null;
        //        T_FM_NOTIFICATION_TASK notice = null;

        //        if (content.Nav_SafeCheckDetail == null || (content.Nav_SafeCheckDetail != null && content.Nav_SafeCheckDetail.CHECKRESULT != (int)CHECKRESULTEnum.Other))
        //        {
        //            //手动上报的 选择问题 不存在 隐患上报
        //            //安全检查 如果是 与问题描述一致 也不存在此问题
        //        }
        //        else
        //        {


        //            //安全检查 结果 其他  隐患上报  隐患入库
        //            modelTemp = new T_BS_RISK_SUBMIT_CONTENT_TEMP();
        //            modelTemp.CHECK_TYPE_ID = subModel.CHECK_TYPE_ID;
        //            modelTemp.CHECK_TYPE_LEVEL_ID = subModel.CHECK_TYPE_LEVEL_ID;
        //            modelTemp.CHECK_QUESTION_ID = content.CHECK_QUESTION_ID;//可能要修改 不一定有


        //            modelTemp.QUESTION_LEVEL = content.QUESTION_LEVEL;
        //            modelTemp.SERIOUS_RISK = (modelTemp.QUESTION_LEVEL == (int)BSQuestionLevelEnum.重大) ? 1 : 0;
        //            modelTemp.ISINSERT = false;

        //            modelTemp.ORG_ID = content.ORG_ID;
        //            modelTemp.CREATE_TIME = DateTime.Now;
        //            modelTemp.DEMAND = content.DEMAND;
        //            modelTemp.DESCREPTION = content.DESCREPTION;
        //            modelTemp.RISK_SUBMIT_ID = deal.RISK_SUBMIT_ID;
        //            modelTemp.RISK_SUBMIT_CONTENT_ID = deal.RISK_SUBMIT_CONTENT_ID;
        //            modelTemp.SAFE_CHECK_ID = content.SAFE_CHECK_ID.HasValue ? content.SAFE_CHECK_ID.Value : null;
        //            modelTemp.SAFE_CHECK_DETAIL_ID = content.SAFE_CHECK_DETAIL_ID.HasValue ? content.SAFE_CHECK_DETAIL_ID.Value : null;

        //            //if (check != null)
        //            //{
        //            modelTemp.CHECKOBJECT = check.CHECKOBJECT;  //如果是 安全检查来的 检查对象就是 检查对应的 类型 否则取组织模糊匹配
        //            modelTemp.CHECK_PROJECT_ID = check.CHECK_PROJECT_ID;
        //            modelTemp.RISK_AREA_ID = check.RISK_AREA_ID;
        //            modelTemp.CHECKPROOF = check.CHECKPROOF;//可能要修改
        //            modelTemp.CHECKCONTENT = check.CHECKCONTENT;//可能要修改
        //            modelTemp.CHECK_PROJECT_PROJECT_CATEGORY_ID = check.CHECK_PROJECT_PROJECT_CATEGORY_ID;//非实际外键
        //            //}
        //            //else if (content.CHECK_QUESTION_ID != null)
        //            //{
        //            //    //一定会有  CHECK_QUESTION_ID
        //            //    var QuesMain = GetEntity<T_BS_CHECK_MAIN>(e => e.CHECK_QUESTION_ID == content.CHECK_QUESTION_ID);
        //            //    modelTemp.CHECKOBJECT = QuesMain.CHECKOBJECT;
        //            //    modelTemp.CHECK_PROJECT_ID = QuesMain.CHECK_PROJECT_ID;
        //            //    modelTemp.RISK_AREA_ID = QuesMain.RISK_AREA_ID;
        //            //    modelTemp.CHECKPROOF = QuesMain.CHECKPROOF;//可能要修改
        //            //    modelTemp.CHECKCONTENT = QuesMain.CHECKCONTENT;//可能要修改
        //            //    modelTemp.CHECK_PROJECT_PROJECT_CATEGORY_ID = QuesMain.CHECK_PROJECT_PROJECT_CATEGORY_ID;//非实际外键
        //            //}
        //            //else
        //            //{
        //            //    //错误日志

        //            //    SysLogService.AddLog(content.ORG_ID.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, PFSysLogTypeEnum.RiskInsert, "PF119", "隐患整改完成审批入库数据异常",
        //            //       "T_BS_RISK_SUBMIT_CONTENT_DEAL:ID【" + id + "】 Nav_CheckMain null  CHECK_QUESTION_ID null", "隐患上报ID：【" + subModel.ID.ToString() + "】");
        //            //}

        //            #region   找安环部负责人 

        //            Guid UserID = Guid.Empty;
        //            string UserName = string.Empty;
        //            var approveRole = this.GetEntity<T_PF_APPROVAL_ROLE>(e => e.NAME.Contains("安环部负责人"));
        //            if (approveRole == null)
        //            {
        //                approveRole = this.GetEntity<T_PF_APPROVAL_ROLE>(e => e.NAME.Contains("安环部责任人"));
        //            }
        //            if (approveRole != null)
        //            {
        //                var user = GetEntity<T_FM_USER>(e => e.APPROVE_ROLE_ID.HasValue && e.APPROVE_ROLE_ID.Value == approveRole.ID);
        //                if (user != null)
        //                {
        //                    UserID = user.ID;
        //                    UserName = user.NAME;
        //                }
        //            }
        //            if (string.IsNullOrEmpty(UserName))
        //            {
        //                var deparments = GetEntity<T_FM_DEPARTMENT>(e => e.NAME.Contains("安环部") && e.Nav_User != null, null, new string[] { "Nav_User" });
        //                if (deparments != null)
        //                {
        //                    UserID = deparments.Nav_User.ID;
        //                    UserName = deparments.Nav_User.NAME;
        //                }
        //            }
        //            if (!string.IsNullOrEmpty(UserName))
        //            {
        //                modelTemp.USER_ID_EDIT = UserID;
        //            }

        //            #endregion

        //            if (!string.IsNullOrEmpty(UserName))
        //            {
        //                notice = NotificationTaskService.InsertUserNoticeTaskModel("隐患待规范后入库" + DateTime.Now.ToString("yyyyMMdd"), modelTemp.ID, modelTemp.ORG_ID, UserID, UserName, DateTime.Now, DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.消息, "BS048");
        //            }
        //        }

        //        UnifiedCommit(() =>
        //        {
        //            UpdateEntityNoCommit(deal);//修改状态 审批结束

        //            if (subModel.ISORDEREND)//隐患上报单 是否完成
        //                UpdateEntityNoCommit(subModel);
        //            UpdateEntityNoCommit(content);//隐患上报内容明细
        //            if (modelTemp != null)
        //                UpdateEntityNoCommit(modelTemp);//完善隐患库
        //            if (notice != null)
        //                UpdateEntityNoCommit(notice);//完善隐患库通知
        //            if (listModelContent != null)//返单 如果有更新
        //                BantchUpdateEntity(listModelContent);
        //            if (listModelContentDetail != null)//返单 如果有更新
        //                BantchUpdateEntity(listModelContentDetail);
        //        });
        //        return true;
        //    });
        //}

        /// <summary>
        /// 获取相关的上报（返修）明细
        /// </summary>
        /// <param name="PARENTID"></param>
        /// <param name="listResult"></param>
        private void GetConnects(Guid? PARENTID, ref List<T_BS_RISK_SUBMIT_CONTENT> listResult)
        {
            if (PARENTID != null)
            {
                T_BS_RISK_SUBMIT_CONTENT temp = GetEntity<T_BS_RISK_SUBMIT_CONTENT>(PARENTID.Value);
                if (temp != null)
                {
                    listResult.Add(temp);
                    GetConnects(temp.PARENTID, ref listResult);
                }
            }
        }
        #endregion  隐患整改记录
        /// <summary>
        /// 
        /// </summary>
        /// <param name="TaskID"></param>
        /// <param name="task"></param>
        /// <param name="SOURCE_FORMCODE">例：BS042_SHOWPRINT</param>
        public void GetEntityTask(Guid TaskID, ref T_FM_NOTIFICATION_TASK task, string SOURCE_FORMCODE = "")
        {
            if (TaskID != new Guid())
            {
                task = this.GetEntity<T_FM_NOTIFICATION_TASK>(TaskID);
                task.TASK_DT = DateTime.Now;
                if (!string.IsNullOrEmpty(SOURCE_FORMCODE))
                {
                    task.SOURCE_FORMCODE = SOURCE_FORMCODE;
                }
                if (task.TASK_ENDDT >= task.TASK_DT)
                    task.NOTICE_STATUS = FMNoticeStatusEnum.正常已办.GetInt();
                else
                    task.NOTICE_STATUS = FMNoticeStatusEnum.超期办理.GetInt();
            }
        }



        /// <summary>
        /// 排序分页查询数据
        /// </summary>
        /// <param name="pageFilter">分页过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("OrderPaged")]
        public PagedActionResult<T_BS_RISK_SUBMIT> OrderPaged([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData(delegate (PagedActionResult<T_BS_RISK_SUBMIT> result)
            {
                //bool isAll = true;
                //List<Guid> departmentIds = new List<Guid>() { APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.Value };
                //DepartmentService.GetDepartmentIds(pageFilter.OrgId.Value, new List<Guid>() { APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.Value }, ref departmentIds, ref isAll);

                Expression<Func<T_BS_RISK_SUBMIT, bool>> expression = e => !e.IS_DELETED;
                //if (!isAll)
                //{
                //    expression = expression.And(e => e.DEPARTMENT_ID.HasValue && departmentIds.Contains(e.DEPARTMENT_ID.Value));
                //}

                int parmType = 0;
                if (!string.IsNullOrEmpty(pageFilter.MenuParameter) && pageFilter.MenuParameter.Contains("SUBMIT_TYPE"))
                {
                    try
                    {
                        string iType = pageFilter.MenuParameter.Split("=")[1];
                        parmType = int.Parse(iType);
                        expression = expression.And(e => e.SUBMIT_TYPE == parmType);
                    }
                    catch { }
                    finally { }
                }
                pageFilter.MenuParameter = null;
                //List<Guid> departmentIds = new List<Guid>() { APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.Value };
                //DepartmentService.GetDepartmentIds(pageFilter.OrgId.Value, new List<Guid>() { APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.Value }, ref departmentIds);
                //Expression<Func<T_BS_RISK_SUBMIT, bool>> expression = e => !e.IS_DELETED && e.DEPARTMENT_ID.HasValue && departmentIds.Contains(e.DEPARTMENT_ID.Value);

                PagedActionResult<T_BS_RISK_SUBMIT> orderPageEntities = GetOrderPageEntities(expression, pageFilter, null);
                if (orderPageEntities.TotalCount > 0)
                {
                    var listCreateID = orderPageEntities.Data.Where(e => e.CREATER_ID.HasValue).Select(e => e.CREATER_ID.Value).Distinct();
                    if (listCreateID != null && listCreateID.Any())
                    {
                        var listUser = GetEntities<T_FM_USER>(e => listCreateID.Contains(e.ID), null, null);
                        foreach (var item in orderPageEntities.Data)
                        {
                            if (!item.CREATER_ID.HasValue)
                                continue;
                            item.CREATE_NAME = listUser.FirstOrDefault(e => e.ID == item.CREATER_ID.Value)?.NAME;
                        }
                    }
                }

                result.Data = orderPageEntities.Data;
                result.TotalCount = orderPageEntities.TotalCount;
            });
        }

        /// <summary>
        /// 排序分页查询数据
        /// </summary>
        /// <param name="pageFilter">分页过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("ContentOrderPaged")]
        public PagedActionResult<T_BS_RISK_SUBMIT_CONTENT> ContentOrderPaged([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData(delegate (PagedActionResult<T_BS_RISK_SUBMIT_CONTENT> result)
            {
                List<Guid> departmentIds = new List<Guid>() { APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.Value };
                DepartmentService.GetDepartmentIds(pageFilter.OrgId.Value, new List<Guid>() { APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.Value }, ref departmentIds);
                var loginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
                Expression<Func<T_BS_RISK_SUBMIT_CONTENT, bool>> expression = e => !e.IS_DELETED && e.DEPARTMENT_ID.HasValue && (e.USER_ID == loginID || e.DEAL_USER_ID == loginID || e.ACTUAL_DEAL_USER_ID == loginID || e.CHECK_USER_ID == loginID || departmentIds.Contains(e.DEPARTMENT_ID.Value));
                PagedActionResult<T_BS_RISK_SUBMIT_CONTENT> orderPageEntities = GetOrderPageEntities(expression, pageFilter, null);
                result.Data = orderPageEntities.Data;
                result.TotalCount = orderPageEntities.TotalCount;
            });
        }

        /// <summary>
        /// 隐患整改记录
        /// </summary>
        /// <param name="pageFilter">分页过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("ContentDetailOrderPaged")]
        public PagedActionResult<T_BS_RISK_SUBMIT_CONTENT_DEAL> ContentDetailOrderPaged([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData(delegate (PagedActionResult<T_BS_RISK_SUBMIT_CONTENT_DEAL> result)
            {
                bool isAll = true;
                List<Guid> departmentIds = new List<Guid>() { APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.Value };
                DepartmentService.GetDepartmentIds(pageFilter.OrgId.Value, new List<Guid>() { APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.Value }, ref departmentIds, ref isAll);

                var loginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;

                Expression<Func<T_BS_RISK_SUBMIT_CONTENT_DEAL, bool>> expression = e => !e.IS_DELETED && (e.DEAL_USER_ID == loginID || e.ACTUAL_DEAL_USER_ID == loginID || e.CHECK_USER_ID == loginID || (e.Nav_SubmitContent.DEPARTMENT_ID.HasValue));

                if (!isAll)
                {
                    expression = expression.And(e => departmentIds.Contains(e.Nav_SubmitContent.DEPARTMENT_ID.Value));
                }

                PagedActionResult<T_BS_RISK_SUBMIT_CONTENT_DEAL> orderPageEntities = GetOrderPageEntities(expression, pageFilter, null);
                result.Data = orderPageEntities.Data;
                result.TotalCount = orderPageEntities.TotalCount;
                if (result.TotalCount > 0 && DataHelper.GetRequestType(Request.Headers) == 2)
                {
                    result.Data.ForEach(e =>
                    {
                        if (e.DEALSITUATION > 0)
                        {
                            e.DEALSITUATION_SHOW = ((DealSituation)e.DEALSITUATION).GetDescription();
                        }
                    });
                }
            });
        }



        /// <summary>
        /// 隐患上报  手动  转给领导
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdateUser")]
        public JsonActionResult<bool> FullUpdateUser([FromBody] T_BS_RISK_SUBMIT entity)
        {
            return SafeExecute<bool>(() =>
            {
                if (string.IsNullOrEmpty(entity.CODE))
                {
                    entity.CODE = "SDSB" + DateTime.Now.ToString("yyyyMMddHHmm");
                }

                var files = entity.Nav_Files;
                entity.Nav_Files = null;
                List<T_BS_RISK_SUBMIT_CONTENT_FILE> listFile = null;
                var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;
                entity.Nav_ListRiskSubmitContent = null;
                if (listRiskSubminContentl == null || listRiskSubminContentl.Count < 1)
                {
                    throw new Exception("隐患上报明细不能为空！");
                }
                else if (listRiskSubminContentl.Count > 1)
                {
                    throw new Exception("手动隐患上报每次只能上报一个隐患！");
                }

                //List<T_BS_RISK_SUBMIT_CONTENT_REASON> listSubmitContentReason = new List<T_BS_RISK_SUBMIT_CONTENT_REASON>();

                #region    手动上报

                if (entity.SUBMIT_STATUS == (int)BSSubmitStatusEnum.Temp)
                {
                    //手动上报 保存并发送 
                    if (!entity.CHECK_TYPE_ID.HasValue)
                    {
                        throw new Exception("请选择检查类型！");
                    }
                    if (!entity.CHECK_TYPE_LEVEL_ID.HasValue)
                    {
                        throw new Exception("请选择检查层级！");
                    }
                    if (files == null)
                    {
                        throw new Exception("请上传附件，手动上报必须上传附件！");
                    }
                    for (int i = 0; i < listRiskSubminContentl.Count(); i++)
                    {
                        if (!listRiskSubminContentl[i].RISK_AREA_ID.HasValue)
                        {
                            throw new Exception("行【" + (i + 1) + "】检查区域不能为空！");
                        }
                        if (string.IsNullOrEmpty(listRiskSubminContentl[i].ADDRESS))
                        {
                            throw new Exception("行【" + (i + 1) + "】隐患地点不能为空！");
                        }
                        if (string.IsNullOrEmpty(listRiskSubminContentl[i].CHECKCONTENT))
                        {
                            throw new Exception("行【" + (i + 1) + "】检查内容不能为空！");
                        }
                        if (string.IsNullOrEmpty(listRiskSubminContentl[i].DESCREPTION))
                        {
                            throw new Exception("行【" + (i + 1) + "】检查问题不能为空！");
                        }
                        ////改版没了
                        //if (listRiskSubminContentl[i].Nav_ListRiskQuestionReason == null)
                        //{
                        //    throw new Exception("行【" + (i + 1) + "】隐患原因不能为空！");
                        //}
                    }

                    if (listRiskSubminContentl.Count == 1 && files != null && files.Any())
                    {
                        listFile = new List<T_BS_RISK_SUBMIT_CONTENT_FILE>();
                        //如果只有一条 附件直接到列表中 最后到 检查前照片
                        foreach (var item in files)
                        {
                            listFile.Add(new T_BS_RISK_SUBMIT_CONTENT_FILE()
                            {
                                ID = Guid.NewGuid(),
                                RISK_SUBMIT_ID = item.RISK_SUBMIT_ID,
                                RISK_SUBMIT_CONTENT_ID = listRiskSubminContentl[0].ID,
                                IMG_FILE_ID = item.IMG_FILE_ID,
                                IS_DELETED = false,
                                ORG_ID = item.ORG_ID,
                                ENTITY_ORG_TPYE = item.ENTITY_ORG_TPYE,
                                FORM_ID = item.FORM_ID,
                                FLOW_STATUS = item.FLOW_STATUS,
                                FLOW_SEND_STATUS = item.FLOW_SEND_STATUS,
                                FLOW_ID = item.FLOW_ID,
                                CREATE_TIME = item.CREATE_TIME,
                                MODIFY_TIME = item.MODIFY_TIME,
                                CREATER_ID = item.CREATER_ID,
                                MODIFIER_ID = item.MODIFIER_ID
                            });
                        }
                    }
                }

                entity.SUBMIT_TYPE = (int)SUBMIT_TYPE.User;
                if (!entity.CHECKTIME.HasValue)
                {
                    entity.CHECKTIME = DateTime.Now;
                }

                #endregion

                //if (listRiskSubminContentl.Any() && listRiskSubminContentl.Count > 0)
                //{
                //    foreach (var item in listRiskSubminContentl)
                //    {
                //        if (item.Nav_ListRiskQuestionReason != null && item.Nav_ListRiskQuestionReason.Any())
                //        {
                //            foreach (var item2 in item.Nav_ListRiskQuestionReason)
                //            {
                //                item2.ORG_ID = entity.ORG_ID;
                //            }
                //            listSubmitContentReason.AddRange(item.Nav_ListRiskQuestionReason);
                //        }
                //    }
                //}

                entity.USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (entity.DEPARTMENT_ID == null)
                {
                    entity.DEPARTMENT_ID = GetEntity<T_FM_USER>(entity.USER_ID.Value).DEPARTMENT_ID;
                }
                T_FM_NOTIFICATION_TASK taskMaster = null;
                //手动上报 保存并发送 通知安全员
                if (entity.SUBMIT_STATUS == (int)BSSubmitStatusEnum.Temp)
                {
                    Guid UserId = Guid.Empty;
                    string userName = String.Empty;

                    #region      //版本 1
                    ////var LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
                    //var master = GetEntity<T_FM_USER>(entity.USER_ID.Value, "Nav_Department");

                    //if (master.Nav_Department.USER_ID.HasValue && master.Nav_Department.USER_ID.Value == entity.USER_ID.Value)
                    //{
                    //    //自己就是负责人 找上级组织的安全员
                    //    if (master.Nav_Department.DEPARTMENT_TYPE == 0 || master.Nav_Department.DEPARTMENT_TYPE == 3)  //部门 公司
                    //    {
                    //        //var userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.Nav_Department.PARENT_ID && e.Nav_ApproveRole.NAME.Contains("安环部安全员"));
                    //        //if (userSafe != null)
                    //        //{
                    //        //    UserId = userSafe.ID;
                    //        //    userName = userSafe.NAME;
                    //        //}

                    //        //部门 = 0,  车间 = 1,   班组 = 2,  公司 = 3
                    //        //如果是公司级 或者安环部  就是自己
                    //        if (master.Nav_Department.DEPARTMENT_TYPE == 3 || master.Nav_Department.DEPARTMENT_STATUS == 2)
                    //        {
                    //            UserId = entity.USER_ID.Value;
                    //            userName = master.NAME;
                    //        }
                    //        else
                    //        {
                    //            var userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.Nav_Department.PARENT_ID && e.Nav_ApproveRole.NAME.Contains("安环部安全员"));
                    //            if (userSafe != null)
                    //            {
                    //                UserId = userSafe.ID;
                    //                userName = userSafe.NAME;
                    //            }
                    //        }
                    //    }
                    //    else
                    //    {
                    //        var userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.Nav_Department.PARENT_ID && e.Nav_ApproveRole.NAME.Contains("安全员"));
                    //        if (userSafe != null)
                    //        {
                    //            UserId = userSafe.ID;
                    //            userName = userSafe.NAME;
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    //    // 班组 班长 否则 安全员  FMDepartmentType 部门=0,  车间=1,   班组=2,  公司=3
                    //    if (master.Nav_Department.DEPARTMENT_TYPE == 2)
                    //    {
                    //        if (master.Nav_Department.USER_ID.HasValue)
                    //        {
                    //            UserId = master.Nav_Department.USER_ID.Value;
                    //            userName = GetEntity<T_FM_USER>(UserId)?.NAME;
                    //        }
                    //        else
                    //        {
                    //            var userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.DEPARTMENT_ID && e.Nav_ApproveRole.NAME.Contains("负责人"));
                    //            if (userSafe != null)
                    //            {
                    //                UserId = userSafe.ID;
                    //                userName = userSafe.NAME;
                    //            }
                    //        }
                    //    }
                    //    else
                    //    {
                    //        var userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.DEPARTMENT_ID && e.Nav_ApproveRole.NAME.Contains("安全员"));
                    //        if (userSafe != null)
                    //        {
                    //            UserId = userSafe.ID;
                    //            userName = userSafe.NAME;
                    //        }
                    //    }
                    //}

                    //if (UserId == Guid.Empty)//没找到给自己
                    //{
                    //    UserId = entity.USER_ID.Value;
                    //    userName = master.NAME;
                    //}
                    #endregion

                    #region     版本 2  本层级找 安全员 找不到就找负责人 （如果是负责人 就是自己）

                    var master = GetEntity<T_FM_USER>(entity.USER_ID.Value, "Nav_Department");

                    if (master.Nav_Department.USER_ID.HasValue && master.Nav_Department.USER_ID.Value == entity.USER_ID.Value)
                    {
                        //如果自己是负责人 就是自己
                        UserId = entity.USER_ID.Value;
                        userName = master.NAME;
                    }
                    else
                    {
                        //找安全员 如果没有 找负责人
                        // 班组 班长 否则 安全员  FMDepartmentType 部门=0,  车间=1,   班组=2,  公司=3
                        if (master.Nav_Department.DEPARTMENT_TYPE == 2)
                        {
                            if (master.Nav_Department.USER_ID.HasValue)
                            {
                                UserId = master.Nav_Department.USER_ID.Value;
                                userName = GetEntity<T_FM_USER>(UserId)?.NAME;
                            }
                            else
                            {
                                var userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.DEPARTMENT_ID && e.Nav_ApproveRole.NAME.Contains("负责人"));
                                if (userSafe != null)
                                {
                                    UserId = userSafe.ID;
                                    userName = userSafe.NAME;
                                }
                            }
                        }
                        else
                        {
                            var userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.DEPARTMENT_ID && e.Nav_ApproveRole.NAME.Contains("安全员"));
                            if (userSafe != null)
                            {
                                UserId = userSafe.ID;
                                userName = userSafe.NAME;
                            }
                            else
                            {
                                userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.DEPARTMENT_ID && e.Nav_ApproveRole.NAME.Contains("负责人"));
                                if (userSafe != null)
                                {
                                    UserId = userSafe.ID;
                                    userName = userSafe.NAME;
                                }
                            }
                        }
                    }

                    if (UserId == Guid.Empty)//没找到给自己
                    {
                        UserId = entity.USER_ID.Value;
                        userName = master.NAME;
                    }

                    #endregion

                    DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_PersonAdd, entity.ORG_ID.Value, DateTime.Now, null, null);
                    taskMaster = NotificationTaskService.InsertUserNoticeTaskModel("手动隐患上报-信息完善", entity.ID, entity.ORG_ID, UserId, userName, DateTime.Now, dtEnd, 0, "BS061");
                }

                this.UnifiedCommit(() =>
                {
                    if (entity != null)
                        UpdateEntityNoCommit(entity);
                    if (files != null && files.Any())
                        BantchSaveEntityNoCommit(files);
                    if (listRiskSubminContentl != null && listRiskSubminContentl.Any())
                        BantchSaveEntityNoCommit(listRiskSubminContentl);
                    if (listFile != null && listFile.Any())
                        BantchSaveEntityNoCommit(listFile);
                    //if (listSubmitContentReason.Any())
                    //    BantchSaveEntityNoCommit(listSubmitContentReason);
                    if (taskMaster != null)
                        UpdateEntityNoCommit(taskMaster);
                });

                return true;
            });
        }


        /// <summary>
        /// 隐患上报 审核通过 给每个通知负责人发送通知
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("NoticeNew")]
        public JsonActionResult<bool> NoticeNew([FromBody] T_PF_APPROVE entity)
        {
            return SafeExecute<bool>(() =>
            {
                return ApproveCallBackService.CallBackNew("BS/BSRiskSubmit/NoticeNew", entity);
            });
        }

        /// <summary>
        /// 隐患上报  完成   修改各种状态   完善隐患库
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("DealEndNew")]
        public JsonActionResult<bool> DealEndNew([FromBody] T_PF_APPROVE entity)
        {
            return SafeExecute<bool>(() =>
            {
                return ApproveCallBackService.CallBackNew("BS/BSRiskSubmit/DealEndNew", entity);
            });
        }


        /// <summary>
        /// 隐患上报 审核通过 给每个通知负责人发送通知
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("NoticeBack")]
        public JsonActionResult<bool> NoticeBack([FromBody] T_PF_APPROVE entity)
        {
            return SafeExecute<bool>(() =>
            {
                //公共 获取审批流信息
                T_PF_APPROVE modelApp = null;
                List<T_PF_APPROVE_DETAIL> listAppDetail = null;
                T_FM_NOTIFICATION_TASK taskFinish = null;
                string Msg = string.Empty;
                bool ResultGetInfo = ApproveCallBackService.GetApproject(entity, ref modelApp, ref listAppDetail, ref taskFinish, ref Msg);
                if (!ResultGetInfo)
                    throw new Exception("驳回失败！");

                if (modelApp == null || listAppDetail == null)
                    throw new Exception("获取驳回信息失败！");

                #region    驳回主体 审批  //BS062  //驳回 按通知

                //检查单
                var subNotice = GetEntity<T_BS_RISK_SUBMIT_NOTICE>(entity.DATA_ID, "Nav_Submit");
                subNotice.RiskContentState = (int)RiskContentState.ReportedReject;

                var listSubContent = GetEntities<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_NOTICE_ID == subNotice.ID, null, null);
                if (listSubContent == null || !listSubContent.Any())
                {
                    throw new Exception("获取隐患上报信息失败！");
                }

                listSubContent.ForEach(e => e.RiskContentState = (int)RiskContentState.ReportedReject);

                var submit = subNotice.Nav_Submit;
                if (!submit.CREATER_ID.HasValue)
                    throw new Exception("获取上报人员信息失败！");

                var user = GetEntity<T_FM_USER>(submit.CREATER_ID.Value);

                #endregion

                T_FM_NOTIFICATION_TASK noticeBack = new T_FM_NOTIFICATION_TASK();
                string title = taskFinish.NOTICE_TITLE;
                title = title.Replace("-", "").Replace("待审批", "").Replace(" ", "");

                noticeBack = NotificationTaskService.InsertUserNoticeTaskModel("(驳回)" + title, subNotice.ID, subNotice.ORG_ID, submit.CREATER_ID.Value, user.NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "BS062");

                UnifiedCommit(() =>
                {
                    if (modelApp != null)
                        UpdateEntityNoCommit(modelApp);
                    if (listAppDetail != null && listAppDetail.Count > 0)
                        BantchUpdateEntityNoCommit(listAppDetail);
                    if (listSubContent != null && listSubContent.Any())
                        BantchUpdateEntityNoCommit(listSubContent);
                    if (subNotice != null)
                        UpdateEntityNoCommit(subNotice);
                    if (noticeBack != null)
                        UpdateEntityNoCommit(noticeBack);
                    if (taskFinish != null)
                        UpdateEntityNoCommit(taskFinish);
                });
                return true;
            });
        }



        /// <summary>
        /// 隐患整改 审批驳回
        /// 整改落实人 重新填单
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("DealBack")]
        public JsonActionResult<bool> DealBack([FromBody] T_PF_APPROVE entity)
        {
            return SafeExecute<bool>(() =>
            {
                //公共 获取审批流信息
                T_PF_APPROVE modelApp = null;
                List<T_PF_APPROVE_DETAIL> listAppDetail = null;
                T_FM_NOTIFICATION_TASK taskFinish = null;
                string Msg = string.Empty;
                bool ResultGetInfo = ApproveCallBackService.GetApproject(entity, ref modelApp, ref listAppDetail, ref taskFinish, ref Msg);
                if (!ResultGetInfo)
                    throw new Exception("驳回失败！");

                if (modelApp == null || listAppDetail == null)
                    throw new Exception("获取驳回信息失败！");

                #region    驳回主体  给整改落实人 重新整改  BS044

                //检查单
                var contentDeal = GetEntity<T_BS_RISK_SUBMIT_CONTENT_DEAL>(entity.DATA_ID, "Nav_UserActualDeal", "Nav_SubmitContent");
                if (contentDeal == null)
                    throw new Exception("获取驳回信息失败！");

                contentDeal.DEALSITUATION = (int)DealSituation.Reject;
                contentDeal.ISDEALSIGN = false;
                contentDeal.ISCHECKSIGN = false;
                contentDeal.CHCECKTIME = null;

                var content = contentDeal.Nav_SubmitContent;
                content.RiskContentState = 70;

                #endregion

                T_FM_NOTIFICATION_TASK taskOld = GetEntity<T_FM_NOTIFICATION_TASK>(e => e.NOTICE_STATUS == 1 && e.SOURCE_DATA_ID == entity.DATA_ID && e.USER_ID == contentDeal.ACTUAL_DEAL_USER_ID.Value && e.SOURCE_FORMCODE == "BS044_SHOWPRINT" && e.NOTICE_TITLE.StartsWith("隐患整改单："));

                string title = "(驳回)";
                if (taskOld != null)
                    title += taskOld.NOTICE_TITLE;
                else
                    title += "隐患整改单";

                T_FM_NOTIFICATION_TASK noticeBack = NotificationTaskService.InsertUserNoticeTaskModel(title, contentDeal.ID, contentDeal.ORG_ID, contentDeal.ACTUAL_DEAL_USER_ID.Value, contentDeal.Nav_UserActualDeal.NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "BS044");

                #region  //整改责任人  驳回 附件整改后 移到整改前
                var listFilesAfter = GetEntities<T_BS_RISK_SUBMIT_CONTENT_DEAL_AFTER_FILE>(e => e.RISK_SUBMIT_CONTENT_DEAL_ID == contentDeal.ID, null, null);
                List<Guid> ids = listFilesAfter.Select(e => e.ID).ToList();
                List<T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE> listFiles = new List<T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE>();
                if (listFilesAfter != null && listFilesAfter.Any())
                {
                    foreach (var item in listFilesAfter)
                    {
                        listFiles.Add(new T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE()
                        {
                            ID = item.ID,//ID不变 别的不变
                            ORG_ID = item.ORG_ID,
                            RISK_SUBMIT_CONTENT_DEAL_ID = item.RISK_SUBMIT_CONTENT_DEAL_ID,
                            IMG_FILE_ID = item.IMG_FILE_ID,
                            CREATER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID,
                            CREATE_TIME = DateTime.Now
                        });
                    }
                }

                #endregion

                UnifiedCommit(() =>
                {
                    if (modelApp != null)
                        UpdateEntityNoCommit(modelApp);
                    if (listAppDetail != null && listAppDetail.Count > 0)
                        BantchUpdateEntityNoCommit(listAppDetail);
                    if (contentDeal != null)
                        UpdateEntityNoCommit(contentDeal);
                    if (content != null)
                        UpdateEntityNoCommit(content);
                    if (noticeBack != null)
                        UpdateEntityNoCommit(noticeBack);
                    if (taskFinish != null)
                        UpdateEntityNoCommit(taskFinish);
                    if (listFilesAfter != null && listFilesAfter.Any())
                        BantchDeleteEntityNoCommit<T_BS_RISK_SUBMIT_CONTENT_DEAL_AFTER_FILE>(ids);
                    if (listFiles != null && listFiles.Any())
                        BantchSaveEntityNoCommit(listFiles);
                });
                return true;
            });
        }


        #region     隐患库

        //OrderPagedRISKINFO

        /// <summary>
        /// 排序分页查询数据
        /// </summary>
        /// <param name="pageFilter">分页过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("OrderPagedRISKINFO")]
        public PagedActionResult<T_BS_RISK_SUBMIT_CONTENT_INFO> OrderPagedRISKINFO([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData(delegate (PagedActionResult<T_BS_RISK_SUBMIT_CONTENT_INFO> result)
            {
                #region  SQL

                //                var sql = @"select   T_HM_RISK_AREA.NAME, T_BS_RISK_SUBMIT_CONTENT.CHECKCONTENT,T_BS_CHECK_QUESTION.DESCREPTION,T_BS_SAFE_CHECK_DETAIL.REMARK_RESULT
                //,case T_BS_SAFE_CHECK_DETAIL.CHECKRESULT when  30 then T_BS_SAFE_CHECK_DETAIL.REMARK_RESULT else  T_BS_CHECK_QUESTION.DESCREPTION end as DESCREPTIONNEW
                //,T_BS_SAFE_CHECK_DETAIL.QUESTION_LEVEL
                // ,COUNT(1) as ThisCount
                //from T_BS_RISK_SUBMIT_CONTENT
                //inner join T_BS_SAFE_CHECK_DETAIL on T_BS_SAFE_CHECK_DETAIL.ID=T_BS_RISK_SUBMIT_CONTENT.SAFE_CHECK_DETAIL_ID
                //inner join T_BS_SAFE_CHECK_DETAIL_QUESTION on T_BS_SAFE_CHECK_DETAIL_QUESTION.SAFE_CHECK_DETAIL_ID=T_BS_SAFE_CHECK_DETAIL.ID
                //inner join T_BS_CHECK_QUESTION on T_BS_CHECK_QUESTION.ID=T_BS_SAFE_CHECK_DETAIL_QUESTION.SAFE_CHECK_QUESTION_ID
                //inner join T_HM_RISK_AREA on T_BS_RISK_SUBMIT_CONTENT.RISK_AREA_ID=T_HM_RISK_AREA.ID
                // group by T_HM_RISK_AREA.NAME, T_BS_RISK_SUBMIT_CONTENT.CHECKCONTENT,T_BS_CHECK_QUESTION.DESCREPTION,T_BS_SAFE_CHECK_DETAIL.REMARK_RESULT,T_BS_SAFE_CHECK_DETAIL.QUESTION_LEVEL
                // ,case T_BS_SAFE_CHECK_DETAIL.CHECKRESULT when  30 then T_BS_SAFE_CHECK_DETAIL.REMARK_RESULT else  T_BS_CHECK_QUESTION.DESCREPTION end  
                //order by ThisCount desc,T_HM_RISK_AREA.NAME";

                #endregion

                #region    旧版 多放组合

                //Guid qtID = new Guid("77777777-7777-7777-7777-777777777777");//系统修改 没有其他
                //Expression<Func<T_BS_RISK_SUBMIT_CONTENT, bool>> expressionSC = e => !e.IS_DELETED;
                //Expression<Func<T_BS_SAFE_CHECK_DETAIL, bool>> expressionD = e => !e.IS_DELETED && e.CHECKRESULT.HasValue && e.CHECKRESULT.Value == 20;
                //Expression<Func<T_BS_SAFE_CHECK_DETAIL_QUESTION, bool>> expressionDQ = e => !e.IS_DELETED && e.SAFE_CHECK_QUESTION_ID != qtID;//
                //Expression<Func<T_BS_CHECK_QUESTION, bool>> expressionQ = e => !e.IS_DELETED;
                //Expression<Func<T_HM_RISK_AREA, bool>> expressionA = e => !e.IS_DELETED;

                ////bool isAREANAMELimit = false;
                ////bool isCHECKCONTENTLimit = false;
                ////bool isDESCREPTIONLimit = false;
                ////bool isLEVELLimit = false;

                //string DESCREPTION = string.Empty;
                //if (pageFilter.FilterGroup.Rules.Count > 0)
                //{
                //    var IRules = pageFilter.FilterGroup.Rules;
                //    string strVal = string.Empty;
                //    foreach (var rule in IRules)
                //    {
                //        if (rule.Value == null || string.IsNullOrEmpty(rule.Value.ToString()))
                //            continue;
                //        strVal = rule.Value.ToString().Trim();
                //        if (rule.Field == "AREANAME")
                //        {
                //            //isAREANAMELimit = true;
                //            expressionA = expressionA.And(e => e.NAME.Contains(strVal));
                //        }
                //        else if (rule.Field == "CHECKCONTENT")
                //        {
                //            //isCHECKCONTENTLimit = true;
                //            expressionSC = expressionSC.And(e => e.CHECKCONTENT.Contains(strVal));
                //        }
                //        else if (rule.Field == "DESCREPTION")
                //        {
                //            //isDESCREPTIONLimit = true;
                //            DESCREPTION = strVal;

                //            //expressionSC = expressionSC.And(e => e.DESCREPTION.Contains(strVal));
                //            //expressionD = expressionD.And(e => e.REMARK_RESULT.Contains(strVal));
                //            //expressionQ = expressionQ.And(e => e.DESCREPTION.Contains(strVal));
                //        }
                //        else if (rule.Field == "QUESTION_LEVEL")
                //        {
                //            try
                //            {
                //                //isLEVELLimit = true;
                //                var level = int.Parse(strVal);
                //                expressionSC = expressionSC.And(e => e.QUESTION_LEVEL == level);
                //                expressionD = expressionD.And(e => e.QUESTION_LEVEL.HasValue && e.QUESTION_LEVEL == level);
                //                expressionQ = expressionQ.And(e => e.QUESTION_LEVEL == (BSQuestionLevelEnum)level);
                //            }
                //            catch { }
                //        }
                //    }
                //}
                //BaseFilter filterArea = new BaseFilter();
                //filterArea.SelectField = new List<string> { "ID", "NAME" };
                //BaseFilter filterQuestion = new BaseFilter();
                //filterQuestion.SelectField = new List<string> { "ID", "DESCREPTION" };
                //BaseFilter filterRiskContent = new BaseFilter();
                //filterRiskContent.SelectField = new List<string> { "ID", "QUESTION_LEVEL", "RISK_AREA_ID", "CHECKCONTENT", "SAFE_CHECK_DETAIL_ID" };
                //BaseFilter filterCheckDetail = new BaseFilter();
                //filterCheckDetail.SelectField = new List<string> { "ID", "CHECKRESULT", "RISK_AREA_ID", "QUESTION_LEVEL" };
                //BaseFilter filterCheckDetailQuestion = new BaseFilter();
                //filterCheckDetailQuestion.SelectField = new List<string> { "ID", "SAFE_CHECK_DETAIL_ID", "SAFE_CHECK_QUESTION_ID" };

                //var IlistArea = GetEntities(expressionA, filterArea, null);//<T_HM_RISK_AREA>
                //var IlistCheckQuestion = GetEntities(expressionQ, filterQuestion, null);//<T_BS_CHECK_QUESTION>
                //var IlistRiskContent = GetEntities(expressionSC, filterRiskContent, null);//<T_BS_RISK_SUBMIT_CONTENT>
                //var IlistCheckDetail = GetEntities(expressionD, filterCheckDetail, null);//<T_BS_SAFE_CHECK_DETAIL>
                //var IlistCheckDetailQuestion = GetEntities(expressionDQ, filterCheckDetailQuestion, null);//<T_BS_SAFE_CHECK_DETAIL_QUESTION>

                //var query = from rc in IlistRiskContent
                //            join cd in IlistCheckDetail on rc.SAFE_CHECK_DETAIL_ID equals cd.ID
                //            join cdq in IlistCheckDetailQuestion on cd.ID equals cdq.SAFE_CHECK_DETAIL_ID
                //            join q in IlistCheckQuestion on cdq.SAFE_CHECK_QUESTION_ID equals q.ID
                //            join are in IlistArea on rc.RISK_AREA_ID equals are.ID
                //            group rc by new
                //            {
                //                rc.QUESTION_LEVEL, //cd.QUESTION_LEVEL,
                //                are.NAME,
                //                rc.RISK_AREA_ID,//cd.RISK_AREA_ID,
                //                rc.CHECKCONTENT,
                //                q.DESCREPTION,
                //                QID = q.ID,
                //                //cd.REMARK_RESULT,
                //                cd.CHECKRESULT,
                //            }
                //            into temp
                //            select new T_BS_RISK_SUBMIT_CONTENT_INFO
                //            {
                //                AREA_ID = temp.Key.RISK_AREA_ID,
                //                AREANAME = temp.Key.NAME,
                //                CHECKCONTENT = temp.Key.CHECKCONTENT,
                //                DESCREPTION = temp.Key.DESCREPTION,
                //                //REMARK_RESULT = temp.Key.REMARK_RESULT,
                //                QUESTION_LEVEL = temp.Key.QUESTION_LEVEL,
                //                //DESCREPTIONNEW = (temp.Key.CHECKRESULT.HasValue && temp.Key.CHECKRESULT.Value == 30) ? temp.Key.REMARK_RESULT : temp.Key.CHECKCONTENT,
                //                DESCREPTIONNEW = temp.Key.DESCREPTION,
                //                COUNTRISK = temp.Count(),
                //                QID = temp.Key.QID
                //            };

                //if (!string.IsNullOrEmpty(DESCREPTION))
                //{
                //    query = query.Where(e => e.DESCREPTION.Contains(DESCREPTION));
                //}

                //result.TotalCount = query.Count();
                //var data = query.OrderByDescending(e => e.COUNTRISK).ThenBy(e => e.QUESTION_LEVEL).ThenBy(e => e.AREANAME).Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit).ToList();
                //T_BS_RISK_SUBMIT_CONTENT tempS = null;

                ////for (int i = 0; i < data.Count; i++)
                ////{
                ////    tempS = IlistRiskContent.FirstOrDefault(e => e.QUESTION_LEVEL == data[i].QUESTION_LEVEL && e.RISK_AREA_ID == data[i].AREA_ID && e.CHECKCONTENT == data[i].CHECKCONTENT);
                ////    data[i].ID = (tempS != null ? tempS.ID : Guid.Empty);
                ////}

                //bool isApp = DataHelper.GetRequestType(Request.Headers) == 2 ? true : false;
                //foreach (var item in data)
                //{
                //    if (item.QID == qtID)
                //    {
                //        tempS = IlistRiskContent.FirstOrDefault(e => e.QUESTION_LEVEL == item.QUESTION_LEVEL && e.RISK_AREA_ID == item.AREA_ID && e.CHECKCONTENT == item.CHECKCONTENT);
                //    }
                //    else
                //    {
                //        tempS = IlistRiskContent.FirstOrDefault(e => e.QUESTION_LEVEL == item.QUESTION_LEVEL && e.RISK_AREA_ID == item.AREA_ID && e.CHECKCONTENT == item.CHECKCONTENT && e.CHECK_QUESTION_ID == qtID);
                //    }
                //    item.ID = (tempS != null ? tempS.ID : Guid.Empty).ToString();

                //    item.ID += "_" + (item.AREA_ID.HasValue ? item.AREA_ID.Value : Guid.Empty) + "_" + item.CHECKCONTENT + "_" + item.DESCREPTION + "_" + item.QUESTION_LEVEL;

                //    if (isApp)
                //    {
                //        if (item.QUESTION_LEVEL != null && item.QUESTION_LEVEL.Value > 0)
                //        {
                //            item.QUESTION_LEVEL_SHOW = ((BSQuestionLevelEnum)item.QUESTION_LEVEL).GetDescription();
                //        }
                //    }
                //}

                //result.Data = data; 

                #endregion

                Guid qtID = new Guid("77777777-7777-7777-7777-777777777777");//系统修改 没有其他
                Expression<Func<T_BS_RISK_SUBMIT_CONTENT, bool>> expressionSC = e => !e.IS_DELETED && e.CHECK_QUESTION_ID.HasValue;
                Expression<Func<T_HM_RISK_AREA, bool>> expressionA = e => !e.IS_DELETED;

                if (pageFilter.FilterGroup.Rules.Count > 0)
                {
                    var IRules = pageFilter.FilterGroup.Rules;
                    string strVal = string.Empty;
                    foreach (var rule in IRules)
                    {
                        if (rule.Value == null || string.IsNullOrEmpty(rule.Value.ToString()))
                            continue;
                        strVal = rule.Value.ToString().Trim();
                        if (rule.Field == "AREANAME")
                        {
                            expressionA = expressionA.And(e => e.NAME.Contains(strVal));
                        }
                        else if (rule.Field == "CHECKCONTENT")
                        {
                            expressionSC = expressionSC.And(e => e.CHECKCONTENT.Contains(strVal));
                        }
                        else if (rule.Field == "DESCREPTION")
                        {
                            expressionSC = expressionSC.And(e => e.DESCREPTION.Contains(strVal));
                        }
                        else if (rule.Field == "QUESTION_LEVEL")
                        {
                            try
                            {
                                var level = int.Parse(strVal);
                                if (level == 0)
                                    continue;
                                expressionSC = expressionSC.And(e => e.QUESTION_LEVEL == level);
                            }
                            catch { }
                        }
                    }
                }

                BaseFilter filterRiskContent = new BaseFilter(pageFilter.OrgId);
                filterRiskContent.SelectField = new List<string> { "ID", "QUESTION_LEVEL", "RISK_AREA_ID", "CHECKCONTENT", "DESCREPTION" };
                filterRiskContent.IgnoreDataRule = true;
                var IlistRiskContent = GetEntities(expressionSC, filterRiskContent);

                BaseFilter filterArea = new BaseFilter(pageFilter.OrgId);
                filterArea.SelectField = new List<string> { "ID", "NAME" };
                var IlistArea = GetEntities(expressionA, filterArea, null);//<T_HM_RISK_AREA>

                var query = from rc in IlistRiskContent
                            join are in IlistArea on rc.RISK_AREA_ID equals are.ID
                            group rc by new
                            {
                                rc.QUESTION_LEVEL,
                                are.NAME,
                                rc.RISK_AREA_ID,
                                rc.CHECKCONTENT,
                                rc.DESCREPTION,
                                QID = rc.CHECK_QUESTION_ID.HasValue ? rc.CHECK_QUESTION_ID.Value : Guid.Empty
                            }
                            into temp
                            select new T_BS_RISK_SUBMIT_CONTENT_INFO
                            {
                                AREA_ID = temp.Key.RISK_AREA_ID,
                                AREANAME = temp.Key.NAME,
                                CHECKCONTENT = temp.Key.CHECKCONTENT,
                                DESCREPTION = temp.Key.DESCREPTION,
                                QUESTION_LEVEL = temp.Key.QUESTION_LEVEL,
                                DESCREPTIONNEW = temp.Key.DESCREPTION,
                                COUNTRISK = temp.Count(),
                                QID = temp.Key.QID
                            };

                result.TotalCount = query.Count();
                var data = query.OrderByDescending(e => e.COUNTRISK).ThenBy(e => e.QUESTION_LEVEL).ThenBy(e => e.AREANAME).Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit).ToList();

                bool isApp = DataHelper.GetRequestType(Request.Headers) == 2 ? true : false;
                foreach (var item in data)
                {
                    //item.ID = (tempS != null ? tempS.ID : Guid.Empty).ToString();
                    item.ID = item.QID.ToString() + "_" + (item.AREA_ID.HasValue ? item.AREA_ID.Value : Guid.Empty) + "_" + item.CHECKCONTENT + "_" + item.DESCREPTION + "_" + item.QUESTION_LEVEL;
                    if (isApp)
                    {
                        if (item.QUESTION_LEVEL != null && item.QUESTION_LEVEL.Value > 0)
                        {
                            item.QUESTION_LEVEL_SHOW = ((BSQuestionLevelEnum)item.QUESTION_LEVEL).GetDescription();
                        }
                    }
                }
                result.Data = data;
            });
        }


        /// <summary>
        /// 隐患库 明细
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetListRiskDetail")]
        public PagedActionResult<T_BS_RISK_SUBMIT_CONTENT_DETAIL> GetListRiskDetail([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData(delegate (PagedActionResult<T_BS_RISK_SUBMIT_CONTENT_DETAIL> result)
            {
                Guid ID = Guid.Empty;

                //item.ID += "_" + item.AREANAME + "_" + item.CHECKCONTENT + "_" + item.DESCREPTIONNEW;
                Guid AREAID = Guid.Empty;
                string CHECKCONTENT = string.Empty;
                string DESCREPTION = string.Empty;
                int? QUESTION_LEVEL = null;
                if (pageFilter.FilterGroup.Rules.Count > 0)
                {
                    var IRules = pageFilter.FilterGroup.Rules;
                    foreach (var rule in IRules)
                    {
                        if (rule.Field == "ID")
                        {
                            var val = rule.Value.ToString();
                            if (val.IndexOf('_') > -1)
                            {
                                var listParm = val.Split('_');
                                if (listParm.Length < 4)
                                    throw new Exception("获取参数有误！");
                                ID = new Guid(listParm[0]);
                                AREAID = new Guid(listParm[1]);
                                CHECKCONTENT = listParm[2];
                                DESCREPTION = listParm[3];
                                if (!string.IsNullOrEmpty(listParm[4]))
                                {
                                    QUESTION_LEVEL = int.Parse(listParm[4]);
                                }
                            }
                        }
                    }
                }

                if (AREAID == Guid.Empty || string.IsNullOrEmpty(CHECKCONTENT) || string.IsNullOrEmpty(DESCREPTION))
                {
                    throw new Exception("获取参数有误！");
                }


                #region     //旧版

                //if (ID == Guid.Empty)
                //{
                //    throw new Exception("获取参数有误！");
                //}
                //var subcontent = GetEntity<T_BS_RISK_SUBMIT_CONTENT>(ID);
                //Expression<Func<T_BS_RISK_SUBMIT_CONTENT, bool>> expression = e => e.RISK_AREA_ID == subcontent.RISK_AREA_ID && e.CHECKCONTENT == subcontent.CHECKCONTENT && e.QUESTION_LEVEL == subcontent.QUESTION_LEVEL;
                //if (!string.IsNullOrEmpty(subcontent.DESCREPTION))
                //    expression = expression.And(e => e.DESCREPTION != null && e.DESCREPTION == subcontent.DESCREPTION);
                //else
                //    expression = expression.And(e => e.DESCREPTION == null);

                #endregion

                Expression<Func<T_BS_RISK_SUBMIT_CONTENT, bool>> expression = e => !e.IS_DELETED && e.RISK_AREA_ID.HasValue;
                if (QUESTION_LEVEL != null)
                    expression = expression.And(e => QUESTION_LEVEL.Value == e.QUESTION_LEVEL);

                if (AREAID != Guid.Empty)
                    expression = expression.And(e => e.RISK_AREA_ID.Value == AREAID);

                expression = expression.And(e => CHECKCONTENT == e.CHECKCONTENT);
                expression = expression.And(e => DESCREPTION == e.DESCREPTION);
                BaseFilter fiter = new BaseFilter(pageFilter.OrgId);
                fiter.IgnoreDataRule = true;
                var listContent = GetEntities(expression, fiter, "Nav_Department", "Nav_UserActualDeal");
                if (listContent == null || !listContent.Any())
                {
                    result.TotalCount = 0;
                    result.Data = null;
                }
                else
                {
                    var listSubmitID = listContent.Select(e => e.RISK_SUBMIT_ID.Value).Distinct();
                    var listSubmit = GetEntities<T_BS_RISK_SUBMIT>(e => listSubmitID.Contains(e.ID), fiter, "Nav_User", "Nav_CheckType", "Nav_CheckTypeLevel.Nav_Enums");

                    var query = from c in listContent
                                join sub in listSubmit on c.RISK_SUBMIT_ID equals sub.ID
                                select new T_BS_RISK_SUBMIT_CONTENT_DETAIL
                                {
                                    SUBMIT_CONTENT_ID = c.ID,
                                    SAFE_CHECK_DETAIL_ID = c?.SAFE_CHECK_DETAIL_ID,
                                    DEPARTMENT_ID = c.DEPARTMENT_ID.HasValue ? c.DEPARTMENT_ID.Value : Guid.Empty,
                                    DEPARTMENT_NAME = c.Nav_Department?.NAME,
                                    CHECKTYPE_ID = sub.CHECK_TYPE_ID.HasValue ? sub.CHECK_TYPE_ID.Value : Guid.Empty,
                                    CHECKTYPE_NAME = sub.Nav_CheckType?.NAME,
                                    CHECKTYPE_LEVEL = sub.Nav_CheckTypeLevel?.Nav_Enums?.NAME,
                                    CHECKTYPE_TIME = sub.CREATE_TIME,
                                    CHECKTYPE_USERS = sub.Nav_User?.NAME,
                                    ADDRESS = c.ADDRESS,
                                    FINISH_TIME = c.SUBMITFINISHTIME,
                                    ACTURE_USERNAME = c.Nav_UserActualDeal?.NAME
                                };

                    result.TotalCount = query.Count();
                    var listResult = query.OrderByDescending(e => e.CHECKTYPE_TIME).ToList();
                    //var listResult = query.OrderByDescending(e => e.CHECKTYPE_TIME).Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit).ToList();
                    var listCheckID = listResult.Where(e => e.SAFE_CHECK_DETAIL_ID.HasValue).Select(e => e.SAFE_CHECK_DETAIL_ID);
                    if (listCheckID != null && listCheckID.Any())
                    {
                        var listCheckDetail = GetEntities<T_BS_SAFE_CHECK_DETAIL>(e => listCheckID.Contains(e.ID), null, "Nav_SafeCheck", "Nav_ListCheckDetailUser.Nav_User");
                        T_BS_SAFE_CHECK_DETAIL modelCD = null;
                        foreach (var item in listResult)
                        {
                            if (!item.SAFE_CHECK_DETAIL_ID.HasValue)
                                continue;
                            modelCD = listCheckDetail.FirstOrDefault(e => e.ID == item.SAFE_CHECK_DETAIL_ID.Value);
                            string CheckUserName = string.Empty;
                            if (modelCD != null)
                            {
                                item.CHECKTYPE_TIME = modelCD.Nav_SafeCheck.CHECKTIME;
                                CheckUserName = string.Empty;
                                foreach (var itemC in modelCD.Nav_ListCheckDetailUser)
                                {
                                    CheckUserName += (string.IsNullOrEmpty(CheckUserName) ? "" : ",") + itemC.Nav_User.NAME;
                                }
                                if (string.IsNullOrEmpty(CheckUserName))
                                {
                                    item.CHECKTYPE_USERS = CheckUserName;
                                }
                            }
                        }
                    }
                    result.Data = listResult;
                }
            });
        }


        #endregion


        #region     新版 隐患上报

        //隐患上报和通知调整，取消整改通知责任人
        //1、明确需求 哪个步骤需要取消
        //2、BS061 去除 变成 BS042  审批流（审批流按 BS061 ） 责任单位 责任通知人  获取数据 整改实施单位 整改责任人（手动） （多添加 检查项目、项目分类 判断显示隐藏）
        //     BS006 加（整改期限 系统整改期限（查看） 整改实施单位 整改责任人 验收人）

        /// <summary>
        /// 隐患上报表 (BS006)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_BS_RISK_SUBMIT entity)
        {
            return SafeExecute<bool>(() =>
            {
                if (string.IsNullOrEmpty(entity.CODE))
                {
                    entity.CODE = "YHSB" + DateTime.Now.ToString("yyyyMMddHHmm");
                }

                var files = entity.Nav_Files;
                entity.Nav_Files = null;
                if (files != null && files.Any())
                {
                    foreach (var item in files)
                    {
                        item.Nav_ImgFile = null;
                    }
                }
                //附件
                List<T_BS_RISK_SUBMIT_CONTENT_FILE> listContentFile = new List<T_BS_RISK_SUBMIT_CONTENT_FILE>();

                var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;
                entity.Nav_ListRiskSubmitContent = null;
                if (listRiskSubminContentl == null || listRiskSubminContentl.Count < 1)
                {
                    throw new Exception("隐患上报明细不能为空！");
                }

                #region     数据完整性判断

                if (!entity.CHECK_ID.HasValue)
                {
                    #region    手动上报

                    if (entity.SUBMIT_STATUS != (int)BSSubmitStatusEnum.Temp)
                    {
                        //手动上报
                        if (!entity.CHECK_TYPE_ID.HasValue)
                        {
                            throw new Exception("请选择检查类型！");
                        }
                        if (!entity.CHECK_TYPE_LEVEL_ID.HasValue)
                        {
                            throw new Exception("请选择检查层级！");
                        }
                        if (files == null)
                        {
                            throw new Exception("请上传附件，手动上报必须上传附件！");
                        }
                        for (int i = 0; i < listRiskSubminContentl.Count(); i++)
                        {
                            if (string.IsNullOrEmpty(listRiskSubminContentl[i].DESCREPTION))
                            {
                                throw new Exception("行【" + (i + 1) + "】检查问题不能为空！");
                            }
                            if (listRiskSubminContentl[i].QUESTION_LEVEL == 0)
                            {
                                throw new Exception("行【" + (i + 1) + "】问题等级不能为空！");
                            }
                            if (string.IsNullOrEmpty(listRiskSubminContentl[i].DEMAND))
                            {
                                throw new Exception("行【" + (i + 1) + "】整改建议与措施不能为空！");
                            }


                            if (string.IsNullOrEmpty(listRiskSubminContentl[i].ADDRESS))
                            {
                                throw new Exception("行【" + (i + 1) + "】隐患地点不能为空！");
                            }

                            if (!listRiskSubminContentl[i].LastDateUser.HasValue)
                            {
                                throw new Exception("行【" + (i + 1) + "】整改期限不能为空！");
                            }
                            else
                            {
                                listRiskSubminContentl[i].LastDateUser = listRiskSubminContentl[i].LastDateUser.Value.Date.AddDays(1).AddSeconds(-1);
                            }

                            if (!listRiskSubminContentl[i].DEAL_DEPARTMENT_ID.HasValue)
                            {
                                throw new Exception("行【" + (i + 1) + "】整改实施单位不能为空！");
                            }
                            if (!listRiskSubminContentl[i].DEAL_USER_ID.HasValue)
                            {
                                throw new Exception("行【" + (i + 1) + "】整改责任人不能为空！");
                            }
                            else
                            {
                                listRiskSubminContentl[i].USER_ID = listRiskSubminContentl[i].DEAL_USER_ID;
                                listRiskSubminContentl[i].DEPARTMENT_ID = listRiskSubminContentl[i].DEAL_DEPARTMENT_ID;
                            }
                            if (!listRiskSubminContentl[i].CHECK_USER_ID.HasValue)
                            {
                                throw new Exception("行【" + (i + 1) + "】验收人不能为空！");
                            }
                            if (listRiskSubminContentl[i].DEAL_USER_ID.Value == listRiskSubminContentl[i].CHECK_USER_ID)
                            {
                                throw new Exception("行【" + (i + 1) + "】整改责任人和验收人不能同一个人！");
                            }

                            if (DataHelper.GetRequestType(HttpContext.Request.Headers) != 2 || (DataHelper.GetRequestType(HttpContext.Request.Headers) == 2 && DateTime.Now.Month > 2))
                            {
                                //移动端 修改 版本兼容
                                if (!listRiskSubminContentl[i].CHECK_PROJECT_ID.HasValue)
                                {
                                    throw new Exception("请选择行【" + (i + 1) + "】的检查项目！");
                                }
                                //if (!listRiskSubminContentl[i].CHECK_PROJECT_CATEGORY_ID.HasValue)
                                //{
                                //    throw new Exception("请选择行【" + (i + 1) + "】的检查项目分类！");
                                //}
                            }
                        }
                    }

                    entity.SUBMIT_TYPE = (int)SUBMIT_TYPE.User;
                    if (!entity.CHECKTIME.HasValue)
                    {
                        entity.CHECKTIME = DateTime.Now;
                    }

                    #endregion
                }
                else
                {
                    if (entity.SUBMIT_STATUS != (int)BSSubmitStatusEnum.Temp)
                    {
                        for (int i = 0; i < listRiskSubminContentl.Count(); i++)
                        {
                            if (listRiskSubminContentl[i].Nav_ListRiskQuestionReason == null)
                            {
                                throw new Exception("行【" + (i + 1) + "】隐患原因不能为空！");
                            }
                            if (string.IsNullOrEmpty(listRiskSubminContentl[i].ADDRESS))
                            {
                                throw new Exception("行【" + (i + 1) + "】隐患地点不能为空！");
                            }
                            if (!listRiskSubminContentl[i].CHECK_QUESTION_ID.HasValue || string.IsNullOrEmpty(listRiskSubminContentl[i].DEMAND))
                            {
                                throw new Exception("行【" + (i + 1) + "】整改建议与措施不能为空！");
                            }

                            if (!listRiskSubminContentl[i].LastDateUser.HasValue)
                            {
                                throw new Exception("行【" + (i + 1) + "】整改期限不能为空！");
                            }
                            else
                            {
                                listRiskSubminContentl[i].LastDateUser = listRiskSubminContentl[i].LastDateUser.Value.Date.AddDays(1).AddSeconds(-1);
                            }

                            if (listRiskSubminContentl[i].LastDateUser.Value > listRiskSubminContentl[i].LastDateSystem.Value)
                            {
                                throw new Exception("行【" + (i + 1) + "】整改期限不能超过【" + listRiskSubminContentl[i].LastDateSystem.Value.Date.ToString("yyyy-MM-dd") + "】！");
                            }
                            if (!listRiskSubminContentl[i].DEAL_DEPARTMENT_ID.HasValue)
                            {
                                throw new Exception("行【" + (i + 1) + "】整改实施单位不能为空！");
                            }
                            if (!listRiskSubminContentl[i].DEAL_USER_ID.HasValue)
                            {
                                throw new Exception("行【" + (i + 1) + "】整改责任人不能为空！");
                            }
                            else
                            {
                                listRiskSubminContentl[i].USER_ID = listRiskSubminContentl[i].DEAL_USER_ID;
                                listRiskSubminContentl[i].DEPARTMENT_ID = listRiskSubminContentl[i].DEAL_DEPARTMENT_ID;
                            }

                            if (!listRiskSubminContentl[i].CHECK_USER_ID.HasValue)
                            {
                                throw new Exception("行【" + (i + 1) + "】验收人不能为空！");
                            }

                            if (listRiskSubminContentl[i].DEAL_USER_ID.Value == listRiskSubminContentl[i].CHECK_USER_ID)
                            {
                                throw new Exception("行【" + (i + 1) + "】整改责任人和验收人不能同一个人！");
                            }


                            //移动端 修改 版本兼容
                            if (!listRiskSubminContentl[i].CHECK_PROJECT_ID.HasValue)
                            {
                                throw new Exception("请选择行【" + (i + 1) + "】的检查项目！");
                            }
                            //if (!listRiskSubminContentl[i].CHECK_PROJECT_CATEGORY_ID.HasValue)
                            //{
                            //    throw new Exception("请选择行【" + (i + 1) + "】的检查项目分类！");
                            //}

                        }
                    }
                }

                #endregion

                //安全检查修改为隐患已上报
                T_BS_SAFE_CHECK modelCheck = null;
                if (entity.CHECK_ID.HasValue)
                {
                    modelCheck = this.GetEntity<T_BS_SAFE_CHECK>(entity.CHECK_ID.Value, new string[] { "Nav_ListSafeCheckDetail" });
                    if (modelCheck != null)
                        modelCheck.RISKSTATE = (int)RISKSTATE.Reported;
                }

                List<T_BS_RISK_SUBMIT_CONTENT_REASON> listSubmitContentReason = new List<T_BS_RISK_SUBMIT_CONTENT_REASON>();
                List<Guid> listApproveId = new List<Guid>();
                List<Guid> listId = new List<Guid>();
                List<Guid> listDataID_Sub = new List<Guid>();
                List<string> listParam = new List<string>();

                List<Guid> ListDepIDNone = new List<Guid>(); //责任部门ID
                                                             //通知表单
                List<T_BS_RISK_SUBMIT_NOTICE> listSubmitNotice = new List<T_BS_RISK_SUBMIT_NOTICE>();
                int rowIndex = 0;
                Dictionary<int, List<Guid>> dicLevelSubID = new Dictionary<int, List<Guid>>();
                List<int> listLevel = new List<int>();
                if (listRiskSubminContentl.Any() && listRiskSubminContentl.Count > 0)
                {
                    foreach (var item in listRiskSubminContentl)
                    {
                        rowIndex++;
                        if (item.DEPARTMENT_ID.HasValue)
                        {
                            ListDepIDNone.Add(item.DEPARTMENT_ID.Value);
                        }
                        else
                        {
                            ListDepIDNone.Add(Guid.Empty);
                        }

                        if (item.Nav_Files != null && item.Nav_Files.Any())
                        {
                            listContentFile.AddRange(item.Nav_Files);
                        }
                        //foreach (var itemCheckMain in modelCheck.Nav_ListSafeCheckDetail)
                        //{
                        //    if (item.CHECK_MAIN_ID == itemCheckMain.CHECK_MAIN_ID && item.QUESTION_LEVEL == 0)
                        //    {
                        //        //不会进来
                        //        item.QUESTION_LEVEL = itemCheckMain.QUESTION_LEVEL.HasValue ? itemCheckMain.QUESTION_LEVEL.Value : ((int)BSQuestionLevelEnum.D);
                        //    }
                        //}
                        if (entity.SUBMIT_STATUS != (int)BSSubmitStatusEnum.Temp)
                        {
                            var subTemp = listSubmitNotice.FirstOrDefault(e => e.QUESTION_LEVEL == item.QUESTION_LEVEL);
                            if (subTemp == null)
                            {
                                #region      不包含此等级 添加通知

                                T_BS_RISK_SUBMIT_NOTICE modelNotice = new T_BS_RISK_SUBMIT_NOTICE();

                                modelNotice.ID = Guid.NewGuid();
                                modelNotice.CODE = entity.CODE + "_" + (listParam.Count() + 1).ToString();
                                modelNotice.NAME = entity.NAME + ((BSQuestionLevelEnum)item.QUESTION_LEVEL).GetDescription() + "隐患";//级
                                modelNotice.RISK_SUBMIT_ID = item.RISK_SUBMIT_ID.Value;
                                modelNotice.QUESTION_LEVEL = item.QUESTION_LEVEL;
                                modelNotice.NOTICETIME = DateTime.Now;
                                modelNotice.RiskContentState = (int)RiskContentState.Notice;
                                modelNotice.APPROVE_ID = Guid.NewGuid();
                                modelNotice.ORG_ID = item.ORG_ID;

                                #endregion

                                listSubmitNotice.Add(modelNotice);

                                item.APPROVE_ID = modelNotice.APPROVE_ID;
                                item.RISK_SUBMIT_NOTICE_ID = modelNotice.ID;

                                listId.Add(modelNotice.ID);
                                //listDataID_Sub.Add(item.ID);
                                listLevel.Add(item.QUESTION_LEVEL);
                                listParam.Add(modelNotice.QUESTION_LEVEL.ToString());
                                listApproveId.Add(modelNotice.APPROVE_ID.Value);
                                dicLevelSubID.Add(item.QUESTION_LEVEL, new List<Guid>() { item.ID });
                            }
                            else
                            {
                                item.APPROVE_ID = subTemp.APPROVE_ID;
                                item.RISK_SUBMIT_NOTICE_ID = subTemp.ID;

                                var subIDs = dicLevelSubID[item.QUESTION_LEVEL];
                                subIDs.Add(item.ID);
                                //回头看看是否正常
                            }

                        }

                        if (item.Nav_ListRiskQuestionReason != null && item.Nav_ListRiskQuestionReason.Any())
                        {
                            foreach (var item2 in item.Nav_ListRiskQuestionReason)
                            {
                                item2.ORG_ID = entity.ORG_ID;
                            }
                            listSubmitContentReason.AddRange(item.Nav_ListRiskQuestionReason);
                        }

                        //如果 有问题ID 
                        //问题等级 和 整改建议与措施 不能修改
                        if (item.Nav_SafeCheckDetail == null && item.SAFE_CHECK_DETAIL_ID != null)
                        {
                            item.Nav_SafeCheckDetail = GetEntity<T_BS_SAFE_CHECK_DETAIL>(e => e.ID == item.SAFE_CHECK_DETAIL_ID);
                        }

                        if (item.Nav_SafeCheckDetail != null && item.Nav_SafeCheckDetail.CHECKRESULT == (int)CHECKRESULTEnum.Same)
                        {
                            if (item.Nav_CheckMain == null && item.CHECK_MAIN_ID.HasValue)
                            {
                                item.Nav_CheckMain = GetEntity<T_BS_CHECK_MAIN>(e => e.ID == item.CHECK_MAIN_ID, new string[] { "Nav_CheckQuestion" });
                            }
                            if (item.Nav_CheckMain != null && item.Nav_CheckMain.Nav_CheckQuestion != null)
                            {
                                if (item.CHECK_QUESTION_ID != item.Nav_CheckMain.Nav_CheckQuestion.ID)
                                {
                                    var checkMain = GetEntity<T_BS_CHECK_MAIN>(e => e.CHECK_QUESTION_ID == item.CHECK_QUESTION_ID && e.CHECK_PROJECT_ID == item.Nav_CheckMain.CHECK_PROJECT_ID && e.CHECKCONTENT == item.Nav_CheckMain.CHECKCONTENT);//&& e.CHECK_PROJECT_CATEGORY_ID == item.Nav_CheckMain.CHECK_PROJECT_CATEGORY_ID && e.CHECK_PROJECT_CATEGORY_ID == item.Nav_CheckMain.CHECK_PROJECT_CATEGORY_ID
                                    if (checkMain == null)
                                    {
                                        //检查问题与描述一致 检查问题不能修改
                                        throw new Exception("行号：【" + rowIndex.ToString() + "】的整改建议与措施【" + item.Nav_CheckMain.Nav_CheckQuestion.DEMAND + "】不能修改，操作失败！");
                                    }
                                }
                            }
                        }
                    }
                }

                if (!entity.USER_ID.HasValue)
                {
                    entity.USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                }
                if (entity.DEPARTMENT_ID == null)
                {
                    entity.DEPARTMENT_ID = GetEntity<T_FM_USER>(entity.USER_ID.Value).DEPARTMENT_ID;
                }
                if (entity.TaskID != Guid.Empty && !entity.STARTTIME.HasValue)
                {
                    var task = GetEntity<T_FM_NOTIFICATION_TASK>(entity.TaskID);
                    entity.STARTTIME = task.CREATE_TIME;
                }
                if (listContentFile.Count > 0)
                {
                    foreach (var item in listContentFile)
                    {
                        item.Nav_ImgFile = null;
                        item.RISK_SUBMIT_ID = entity.ID;
                    }
                }



                if (entity.SUBMIT_STATUS == (int)BSSubmitStatusEnum.Temp)
                {
                    this.UnifiedCommit(() =>
                    {
                        if (entity != null)
                            UpdateEntityNoCommit(entity);
                        if (modelCheck != null)
                            UpdateEntityNoCommit(modelCheck);
                        if (files != null && files.Any())
                            BantchSaveEntityNoCommit(files);
                        if (listContentFile != null && listContentFile.Any())
                            BantchSaveEntityNoCommit(listContentFile);
                        if (listRiskSubminContentl != null && listRiskSubminContentl.Any())
                            BantchSaveEntityNoCommit(listRiskSubminContentl);
                        if (listSubmitContentReason.Any())
                            BantchSaveEntityNoCommit(listSubmitContentReason);
                    });
                }
                else
                {

                    List<string> listSerialCode = new List<string>();
                    var index = entity.CODE.IndexOf(DateTime.Now.Year.ToString());
                    if (index == -1)
                    {
                        index = entity.CODE.IndexOf((DateTime.Now.Year - 1).ToString());
                    }
                    string yearMonth = string.Empty;
                    if (index > 0)
                    {
                        yearMonth = entity.CODE.Substring(index);
                    }
                    else
                    {
                        yearMonth = DateTime.Now.ToString("yyyyMMddHHmmss");
                    }

                    string code = "YHSB" + yearMonth;
                    if (code.Length > 20)
                    {
                        code = code.Substring(0, 15);
                    }

                    listSerialCode.Add(code);

                    if (listParam.Count > 1)
                    {
                        for (int i = 1; i < listParam.Count; i++)
                        {
                            listSerialCode.Add(code + i.ToString());
                        }
                    }


                    //如果是手动隐患上报 根据明细的 整改责任人  来走审批流 20240118
                    Guid? ApproveIDDependUserID = null;
                    if (entity.SUBMIT_TYPE == (int)APT.MS.Domain.Enums.SUBMIT_TYPE.User && listRiskSubminContentl != null && listRiskSubminContentl.Count > 0)
                    {
                        var listDealUserID = listRiskSubminContentl.Select(e => e.DEAL_USER_ID).Distinct();
                        if (listDealUserID != null && listDealUserID.Count() == 1)
                        {
                            ApproveIDDependUserID = listRiskSubminContentl[0].DEAL_USER_ID;
                        }
                    }
                    //??????
                    ////给通知责任人 发送通知
                    ////通知责任人 确定 后  走审批流
                    MFlowPermitService.InsertApproveRisk(listSerialCode, "BS006", listId, "BS006_SHOWPRINT", entity.TaskID, true, () =>
                    {
                        if (entity != null)
                            UpdateEntityNoCommit(entity);
                        if (listSubmitNotice.Any())
                            BantchSaveEntityNoCommit(listSubmitNotice);
                        if (modelCheck != null)
                            UpdateEntityNoCommit(modelCheck);
                        if (files != null && files.Any())
                            BantchSaveEntityNoCommit(files);
                        if (listContentFile != null && listContentFile.Any())
                            BantchSaveEntityNoCommit(listContentFile);
                        if (listRiskSubminContentl != null && listRiskSubminContentl.Any())
                            BantchSaveEntityNoCommit(listRiskSubminContentl);
                        if (listSubmitContentReason.Any())
                            BantchSaveEntityNoCommit(listSubmitContentReason);
                    }, listParam, listApproveId, ApproveIDDependUserID, "BS006_VIEW", null, ListDepIDNone, FMTASKTYPE.BS_RiskUp_Audit, null, null, (int)OPERATEPOINT_Enums.RiskGet, entity.ID, listLevel, dicLevelSubID);//  null =>ApproveIDDependUserID  
                }
                return true;
            });
        }


        #endregion



        #region     隐患上报 新版 



        /// <summary>
        /// 隐患上报  手动  转给领导
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdateUserNew")]
        public JsonActionResult<bool> FullUpdateUserNew([FromBody] T_BS_RISK_SUBMIT_CONTENT entity)
        {
            return SafeExecute<bool>(() =>
            {
                var files = entity.Nav_Files;
                entity.Nav_Files = null;
                //entity.RiskContentState  5 10   需要处理

                #region    必填判断

                if (entity.RiskContentState == 10)
                {
                    if (!entity.RISK_AREA_ID.HasValue)
                    {
                        throw new Exception("检查区域不能为空！");
                    }
                    if (string.IsNullOrEmpty(entity.ADDRESS))
                    {
                        throw new Exception("隐患地点不能为空！");
                    }
                }

                if (string.IsNullOrEmpty(entity.DESCRIBE))
                {
                    throw new Exception("请填写上报描述！");
                }
                else if (entity.DESCRIBE.Length > 500)
                {
                    throw new Exception("上报描述不能超过500字！");
                }
                if (files.Count < 1)
                {
                    throw new Exception("请上传附件！");
                }

                #endregion

                T_BS_RISK_SUBMIT risk = null;

                if (entity.RISK_SUBMIT_ID == null || entity.RISK_SUBMIT_ID == Guid.Empty)
                {
                    risk = new T_BS_RISK_SUBMIT();
                    risk.ID = Guid.NewGuid();
                    risk.ORG_ID = entity.ORG_ID;
                    risk.SUBMIT_STATUS = entity.RiskContentState;
                    risk.NAME = "手动隐患上报";
                    risk.CHECKOBJECT = BSMineTypeEnum.Mine;//SMS 默认露天矿
                    if (!risk.CHECKTIME.HasValue)
                        risk.CHECKTIME = DateTime.Now;

                    if (string.IsNullOrEmpty(entity.CODE))
                    {
                        if (entity.TaskID != Guid.Empty)
                        {
                            entity.CODE = "TPM" + DateTime.Now.ToString("yyyyMMddHHmm");
                            risk.SUBMIT_TYPE = (int)SUBMIT_TYPE.TPM;
                        }
                        else
                        {
                            entity.CODE = "SDSB" + DateTime.Now.ToString("yyyyMMddHHmm");
                            risk.SUBMIT_TYPE = (int)SUBMIT_TYPE.User;
                        }
                    }

                    risk.CODE = entity.CODE;
                    risk.USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                    risk.DEPARTMENT_ID = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID;

                    entity.RISK_SUBMIT_ID = risk.ID;
                }
                else
                {
                    //risk = entity.Nav_Submit;
                    risk = GetEntity<T_BS_RISK_SUBMIT>(entity.RISK_SUBMIT_ID.Value);
                    risk.SUBMIT_STATUS = entity.RiskContentState;
                }

                foreach (var item in files)
                {
                    item.RISK_SUBMIT_ID = risk.ID;
                }
                T_FM_NOTIFICATION_TASK taskMaster = null;
                T_FM_NOTIFICATION_TASK taskEnd = null;
                List<T_BS_OPERATE_LOG> listLog = null;
                //手动上报 保存并发送 通知安全员
                if (risk.SUBMIT_STATUS == (int)BSSubmitStatusEnum.Temp)
                {
                    Guid UserId = Guid.Empty;
                    string userName = String.Empty;

                    #region     版本 2  本层级找 安全员 找不到就找负责人 （如果是负责人 就是自己）

                    var master = GetEntity<T_FM_USER>(risk.USER_ID.Value, "Nav_Department");
                    if (master.Nav_Department == null)
                    {
                        throw new Exception("未获取到您的组织信息，操作失败！");
                    }
                    if (master.Nav_Department.USER_ID.HasValue && master.Nav_Department.USER_ID.Value == risk.USER_ID.Value)
                    {
                        //如果自己是负责人 就是自己
                        UserId = risk.USER_ID.Value;
                        userName = master.NAME;
                    }
                    else
                    {
                        //找安全员 如果没有 找负责人
                        // 班组 班长 否则 安全员  FMDepartmentType 部门=0,  车间=1,   班组=2,  公司=3
                        if (master.Nav_Department.DEPARTMENT_TYPE == 2)
                        {
                            if (master.Nav_Department.USER_ID.HasValue)
                            {
                                UserId = master.Nav_Department.USER_ID.Value;
                                userName = GetEntity<T_FM_USER>(UserId)?.NAME;
                            }
                            else
                            {
                                var userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.DEPARTMENT_ID && e.Nav_ApproveRole.NAME.Contains("负责人"));
                                if (userSafe != null)
                                {
                                    UserId = userSafe.ID;
                                    userName = userSafe.NAME;
                                }
                            }
                        }
                        else
                        {
                            var userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.DEPARTMENT_ID && e.Nav_ApproveRole.NAME.Contains("安全员"));
                            if (userSafe != null)
                            {
                                UserId = userSafe.ID;
                                userName = userSafe.NAME;
                            }
                            else
                            {
                                userSafe = GetEntity<T_FM_USER>(e => !e.IS_DELETED && e.DEPARTMENT_ID == master.DEPARTMENT_ID && e.Nav_ApproveRole.NAME.Contains("负责人"));
                                if (userSafe != null)
                                {
                                    UserId = userSafe.ID;
                                    userName = userSafe.NAME;
                                }
                            }
                        }
                    }

                    if (UserId == Guid.Empty)//没找到给自己
                    {
                        UserId = risk.USER_ID.Value;
                        userName = master.NAME;
                    }

                    #endregion

                    DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_PersonAdd, entity.ORG_ID.Value, DateTime.Now, null, null);
                    taskMaster = NotificationTaskService.InsertUserNoticeTaskModel("手动隐患上报-信息完善", entity.ID, risk.ORG_ID, UserId, userName, DateTime.Now, dtEnd, 0, "BS073");//原 BS061 
                    if (entity.TaskID != Guid.Empty)
                    {
                        taskEnd = NotificationTaskService.GetEntityTask(entity.TaskID, "BS072_SHOWPRINT");
                    }
                    listLog = OperateLogService.GetListOperateLog(OPERATEPOINT_Enums.RiskUpSD, risk.ID, risk.USER_ID.Value, null, new List<Guid>() { UserId }, new List<string>() { userName }, risk.ORG_ID, entity.ID);
                }

                entity.RiskContentState = null;
                this.UnifiedCommit(() =>
                {
                    if (risk != null)
                        UpdateEntityNoCommit(risk);
                    if (entity != null)
                        UpdateEntityNoCommit(entity);
                    if (files != null && files.Any())
                        BantchSaveEntityNoCommit(files);
                    if (taskMaster != null)
                        UpdateEntityNoCommit(taskMaster);
                    if (taskEnd != null)
                        UpdateEntityNoCommit(taskEnd);
                    if (listLog != null && listLog.Any())
                        BantchSaveEntityNoCommit(listLog);
                });

                return true;
            });
        }


        /// <summary>
        /// 选择整改实施单位 加载 责任人 验收人 
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDpartMentMasterInfo")]
        public PagedActionResult<T_FM_DEPARTMENT> GetDpartMentMasterInfo([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData<T_FM_DEPARTMENT>((result) =>
            {
                Expression<Func<T_FM_DEPARTMENT, bool>> expression = e => !e.IS_DELETED && e.ENABLE_STATUS == 0 && e.ORG_ID == pageFilter.OrgId;
                //var listDepartmentPage = this.GetPageEntities(expression, pageFilter, "Nav_User", "Nav_Parent.Nav_User");//框架报错
                //var c = this.GetPageEntities(expression, pageFilter);
                //result = this.GetPageEntities(expression, pageFilter, "Nav_User");//框架报错
                var sad = GetOrderPageEntities(expression, pageFilter, "Nav_User");

                var listDepartmentAll = this.GetEntities(expression, pageFilter, "Nav_User");//, "Nav_Parent"
                result.TotalCount = listDepartmentAll.Count();

                //result.Data = listDepartment;
                //result.TotalCount = listDepartment.Count();

                if (result.TotalCount > 0)
                {
                    var listDepartment = listDepartmentAll.OrderBy(e => e.NAME).Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit);
                    List<Guid> listDepID = new List<Guid>();

                    //责任人
                    listDepID = listDepartment.Where(e => !e.USER_ID.HasValue).Select(x => x.ID).ToList();
                    if (listDepID != null && listDepID.Any())
                    {
                        listDepID = listDepID.Distinct().ToList();
                        var listRole = GetEntities<T_PF_APPROVAL_ROLE>(e => e.NAME.Contains("负责人"), null, null);
                        var listRoleID = listRole.Select(e => e.ID);
                        if (listRoleID != null && listRoleID.Any())
                        {
                            var listHeader = GetEntities<T_FM_USER>(e => listDepID.Contains(e.DEPARTMENT_ID.Value) && e.APPROVE_ROLE_ID.HasValue && listRoleID.Contains(e.APPROVE_ROLE_ID.Value), null, null);
                            foreach (var item in listDepartment)
                            {
                                if (!item.USER_ID.HasValue)
                                {
                                    T_FM_USER userTemp = null;
                                    userTemp = listHeader.FirstOrDefault(x => x.DEPARTMENT_ID == item.ID);
                                    if (userTemp != null)
                                        item.Nav_User = userTemp;
                                }
                            }
                        }
                    }

                    //验收人
                    listDepID = listDepartment.Where(e => e.PARENT_ID.HasValue).Select(e => e.PARENT_ID.Value).ToList();
                    if (listDepID != null && listDepID.Any())
                    {
                        listDepID = listDepID.Distinct().ToList();
                        var listP = GetEntities<T_FM_DEPARTMENT>(e => listDepID.Contains(e.ID), null);
                        var listRole = GetEntities<T_PF_APPROVAL_ROLE>(e => e.NAME.Contains("安全员"), null, null);
                        if (listRole != null && listRole.Any())
                        {
                            var listRoleID = listRole.Select(e => e.ID);
                            var listHeader = GetEntities<T_FM_USER>(e => listDepID.Contains(e.DEPARTMENT_ID.Value) && e.APPROVE_ROLE_ID.HasValue && listRoleID.Contains(e.APPROVE_ROLE_ID.Value), null, null);
                            foreach (var item in listP)
                            {
                                T_FM_USER userTemp = null;
                                userTemp = listHeader.FirstOrDefault(x => x.DEPARTMENT_ID == item.ID);
                                if (userTemp != null)
                                    item.Nav_User = userTemp;//安全员临时装入此字段
                            }
                        }

                        //数据(父级部门及验收人)组装
                        foreach (var item in listDepartment)
                        {
                            if (item.PARENT_ID.HasValue)
                            {
                                item.Nav_Parent = listP.FirstOrDefault(e => e.ID == item.PARENT_ID.Value);
                            }
                        }
                    }
                    result.Data = listDepartment;
                }
            });
        }



        /// <summary>
        /// 手动上报 指定责任单位  选择检查问题  按 问题等级 同时带出 系统整改期限
        /// </summary>
        /// <param name="pageFilter">分页过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("OrderPagedQuestion")]
        public PagedActionResult<T_BS_CHECK_QUESTION> OrderPagedQuestion([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData(delegate (PagedActionResult<T_BS_CHECK_QUESTION> result)
            {
                var resultT = GetOrderPageEntities<T_BS_CHECK_QUESTION>(null, pageFilter, null);
                if (resultT.TotalCount > 0)
                {
                    int RequestType = DataHelper.GetRequestType(HttpContext.Request.Headers);
                    foreach (var item in resultT.Data)
                    {
                        int delayDays = GetDealyDays((int)item.QUESTION_LEVEL) + 1;
                        item.LastDateSystem = DateTime.Now.Date.AddDays(delayDays).AddSeconds(-1);//  Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")).AddDays(delayDays);
                        if (RequestType == 2)
                        {
                            if (item.QUESTION_LEVEL > 0)
                            {
                                item.QUESTION_LEVEL_SHOW = item.QUESTION_LEVEL.GetDescription();
                            }
                        }
                    }
                }
                result.Data = resultT.Data;
                result.TotalCount = resultT.TotalCount;
            });
        }


        //隐患上报和通知调整，取消整改通知责任人
        //1、明确需求 哪个步骤需要取消
        //2、BS061 去除 变成 BS042  审批流（审批流按 BS061 ） 责任单位 责任通知人  获取数据 整改实施单位 整改责任人（手动） （多添加 检查项目、项目分类 判断显示隐藏）
        //     BS006 加（整改期限 系统整改期限（查看） 整改实施单位 整改责任人 验收人）

        /// <summary>
        /// 隐患上报表 (BS073)
        /// </summary>
        /// <param name="entityContent"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost, Route("FullUpdateNew")]
        public JsonActionResult<bool> FullUpdateNew([FromBody] T_BS_RISK_SUBMIT_CONTENT entityContent)
        {
            return SafeExecute<bool>(() =>
            {
                var entity = entityContent.Nav_Submit;
                if (entity == null)
                {
                    //页面传值过来是null
                    entity = GetEntity<T_BS_RISK_SUBMIT>(entityContent.RISK_SUBMIT_ID.Value);
                    entity.SUBMIT_STATUS = entityContent.SUBMIT_STATUS;
                    if (entityContent.CHECK_TYPE_ID.HasValue)
                        entity.CHECK_TYPE_ID = entityContent.CHECK_TYPE_ID;
                    if (entityContent.CHECK_TYPE_LEVEL_ID.HasValue)
                        entity.CHECK_TYPE_LEVEL_ID = entityContent.CHECK_TYPE_LEVEL_ID;
                    if (entityContent.CHECKOBJECT.HasValue)
                        entity.CHECKOBJECT = entityContent.CHECKOBJECT;
                }
                else
                {
                    //获取页面传参
                    entity.SUBMIT_STATUS = entityContent.SUBMIT_STATUS;
                    if (entityContent.CHECK_TYPE_ID.HasValue)
                        entity.CHECK_TYPE_ID = entityContent.CHECK_TYPE_ID;
                    if (entityContent.CHECK_TYPE_LEVEL_ID.HasValue)
                        entity.CHECK_TYPE_LEVEL_ID = entityContent.CHECK_TYPE_LEVEL_ID;
                    if (entity.CHECKOBJECT == null && entityContent.CHECKOBJECT != null)
                        entity.CHECKOBJECT = entityContent.CHECKOBJECT;
                }
                var files = entityContent.Nav_Files;
                entityContent.Nav_Files = null;
                var listRiskQuestionReason = entityContent.Nav_ListRiskQuestionReason;
                entityContent.Nav_ListRiskQuestionReason = null;

                #region    数据完整性判断

                if (entity.SUBMIT_STATUS != (int)BSSubmitStatusEnum.Temp)
                {
                    //手动上报
                    if (!entity.CHECKOBJECT.HasValue)
                        throw new Exception("请选择检查范围！");
                    if (!entity.CHECK_TYPE_ID.HasValue)
                        throw new Exception("请选择检查类型！");
                    if (!entity.CHECK_TYPE_LEVEL_ID.HasValue)
                        throw new Exception("请选择检查层级！");
                    if (files == null)
                        throw new Exception("请上传附件，手动上报必须上传附件！");
                    if (DataHelper.GetRequestType(HttpContext.Request.Headers) != 2 || (DataHelper.GetRequestType(HttpContext.Request.Headers) == 2 && DateTime.Now.Month > 2))
                    {
                        //移动端 修改 版本兼容
                        if (!entityContent.CHECK_PROJECT_ID.HasValue)
                            throw new Exception("请选择的检查项目！");
                        //if (!entityContent.CHECK_PROJECT_CATEGORY_ID.HasValue)
                        //    throw new Exception("请选择的检查项目分类！");
                    }

                    if (!entityContent.RISK_AREA_ID.HasValue)
                        throw new Exception("检查区域不能为空！");
                    if (string.IsNullOrEmpty(entityContent.ADDRESS))
                        throw new Exception("隐患地点不能为空！");
                    if (!entityContent.CHECK_CONTENTS_ID.HasValue)
                        throw new Exception("检查内容不能为空！");
                    if (!entityContent.CHECK_QUESTION_ID.HasValue)
                        throw new Exception("检查问题不能为空！");
                    if (string.IsNullOrEmpty(entityContent.DESCREPTION))
                        throw new Exception("检查问题不能为空！");
                    if (entityContent.QUESTION_LEVEL == 0)
                        throw new Exception("问题等级不能为空！");
                    if (string.IsNullOrEmpty(entityContent.DEMAND))
                        throw new Exception("整改建议与措施不能为空！");

                    if (!entityContent.LastDateUser.HasValue)
                        throw new Exception("整改期限不能为空！");
                    else if (!entityContent.LastDateSystem.HasValue)
                        throw new Exception("系统整改期限不能为空！");
                    else if (entityContent.LastDateUser.Value > entityContent.LastDateSystem.Value)
                        throw new Exception("整改期限不能大于系统整改期限！");
                    else
                        entityContent.LastDateUser = entityContent.LastDateUser.Value.Date.AddDays(1).AddSeconds(-1);

                    if (listRiskQuestionReason == null || !listRiskQuestionReason.Any())
                        throw new Exception("隐患原因不能为空！");

                    if (!entityContent.DEAL_DEPARTMENT_ID.HasValue)
                        throw new Exception("整改实施单位不能为空！");
                    if (!entityContent.DEAL_USER_ID.HasValue)
                        throw new Exception("整改责任人不能为空！");
                    else
                    {
                        entityContent.USER_ID = entityContent.DEAL_USER_ID;
                        entityContent.DEPARTMENT_ID = entityContent.DEAL_DEPARTMENT_ID;
                    }
                    if (!entityContent.CHECK_USER_ID.HasValue)
                        throw new Exception("验收人不能为空！");
                    if (entityContent.DEAL_USER_ID.Value == entityContent.CHECK_USER_ID)
                        throw new Exception("整改责任人和验收人不能同一个人！");
                }

                #endregion

                //entity.SUBMIT_TYPE = (int)SUBMIT_TYPE.User;
                if (!entity.CHECKTIME.HasValue)
                    entity.CHECKTIME = DateTime.Now;

                if (string.IsNullOrEmpty(entity.CODE))
                    entity.CODE = "YHSB" + DateTime.Now.ToString("yyyyMMddHHmm");

                //安全检查修改为隐患已上报
                T_BS_SAFE_CHECK modelCheck = null;
                if (entity.CHECK_ID.HasValue)
                {
                    modelCheck = this.GetEntity<T_BS_SAFE_CHECK>(entity.CHECK_ID.Value, new string[] { "Nav_ListSafeCheckDetail" });
                    if (modelCheck != null)
                        modelCheck.RISKSTATE = (int)RISKSTATE.Reported;
                }

                List<Guid> listApproveId = new List<Guid>();
                List<Guid> listId = new List<Guid>();
                List<string> listParam = new List<string>();

                List<Guid> ListDepIDNone = new List<Guid>(); //责任部门ID
                                                             //通知表单
                List<T_BS_RISK_SUBMIT_NOTICE> listSubmitNotice = new List<T_BS_RISK_SUBMIT_NOTICE>();

                //foreach (var item in listRiskSubminContentl)
                //{
                //rowIndex++;
                if (entityContent.DEPARTMENT_ID.HasValue)
                {
                    ListDepIDNone.Add(entityContent.DEPARTMENT_ID.Value);
                }
                else
                {
                    ListDepIDNone.Add(Guid.Empty);
                }

                if (entity.SUBMIT_STATUS != (int)BSSubmitStatusEnum.Temp && string.IsNullOrEmpty(entityContent.NAME) && entityContent.QUESTION_LEVEL > 0)
                {
                    try
                    {
                        entityContent.NAME = ((BSQuestionLevelEnum)entityContent.QUESTION_LEVEL).GetDescription() + "隐患";//级
                        //手动上报车间级巡回检查A
                    }
                    catch { }
                }
                if (entity.SUBMIT_STATUS != (int)BSSubmitStatusEnum.Temp)
                {
                    var subTemp = listSubmitNotice.FirstOrDefault(e => e.QUESTION_LEVEL == entityContent.QUESTION_LEVEL);
                    if (subTemp == null)
                    {
                        #region      不包含此等级 添加通知

                        T_BS_RISK_SUBMIT_NOTICE modelNotice = new T_BS_RISK_SUBMIT_NOTICE();

                        modelNotice.ID = Guid.NewGuid();
                        modelNotice.CODE = entityContent.CODE + "_" + (listParam.Count() + 1).ToString();

                        modelNotice.NAME = ((BSQuestionLevelEnum)entityContent.QUESTION_LEVEL).GetDescription();
                        if (entityContent.NAME.Contains(entityContent.NAME))
                        {
                            modelNotice.NAME = entityContent.NAME;
                        }
                        else
                        {
                            modelNotice.NAME = entityContent.NAME + modelNotice.NAME;
                        }
                        modelNotice.RISK_SUBMIT_ID = entityContent.RISK_SUBMIT_ID.Value;
                        modelNotice.QUESTION_LEVEL = entityContent.QUESTION_LEVEL;
                        modelNotice.NOTICETIME = DateTime.Now;
                        modelNotice.RiskContentState = (int)RiskContentState.Notice;
                        modelNotice.APPROVE_ID = Guid.NewGuid();
                        modelNotice.ORG_ID = entityContent.ORG_ID;

                        #endregion

                        listSubmitNotice.Add(modelNotice);

                        entityContent.APPROVE_ID = modelNotice.APPROVE_ID;
                        entityContent.RISK_SUBMIT_NOTICE_ID = modelNotice.ID;

                        listId.Add(modelNotice.ID);
                        listParam.Add(modelNotice.QUESTION_LEVEL.ToString());
                        listApproveId.Add(modelNotice.APPROVE_ID.Value);
                    }
                    else
                    {
                        entityContent.APPROVE_ID = subTemp.APPROVE_ID;
                        entityContent.RISK_SUBMIT_NOTICE_ID = subTemp.ID;
                    }
                }

                if (listRiskQuestionReason != null && listRiskQuestionReason.Any())
                {
                    foreach (var item in listRiskQuestionReason)
                    {
                        item.ORG_ID = entity.ORG_ID;
                        item.Nav_RiskReason = null;
                    }
                }
                if (files.Count > 0)
                {
                    foreach (var item in files)
                    {
                        item.Nav_ImgFile = null;
                        item.RISK_SUBMIT_ID = entity.ID;
                    }
                }

                //如果 有问题ID 
                //问题等级 和 整改建议与措施 不能修改
                if (entityContent.Nav_SafeCheckDetail == null && entityContent.SAFE_CHECK_DETAIL_ID != null)
                {
                    entityContent.Nav_SafeCheckDetail = GetEntity<T_BS_SAFE_CHECK_DETAIL>(e => e.ID == entityContent.SAFE_CHECK_DETAIL_ID);
                }

                if (entityContent.Nav_SafeCheckDetail != null && entityContent.Nav_SafeCheckDetail.CHECKRESULT == (int)CHECKRESULTEnum.Same)
                {
                    if (entityContent.Nav_CheckMain == null && entityContent.CHECK_MAIN_ID.HasValue)
                    {
                        entityContent.Nav_CheckMain = GetEntity<T_BS_CHECK_MAIN>(e => e.ID == entityContent.CHECK_MAIN_ID, new string[] { "Nav_CheckQuestion" });
                    }
                    if (entityContent.Nav_CheckMain != null && entityContent.Nav_CheckMain.Nav_CheckQuestion != null)
                    {
                        if (entityContent.CHECK_QUESTION_ID != entityContent.Nav_CheckMain.Nav_CheckQuestion.ID)
                        {
                            var checkMain = GetEntity<T_BS_CHECK_MAIN>(e => e.CHECK_QUESTION_ID == entityContent.CHECK_QUESTION_ID && e.CHECK_PROJECT_ID == entityContent.Nav_CheckMain.CHECK_PROJECT_ID && e.CHECKCONTENT == entityContent.Nav_CheckMain.CHECKCONTENT);//&& e.CHECK_PROJECT_CATEGORY_ID == entityContent.Nav_CheckMain.CHECK_PROJECT_CATEGORY_ID 
                            {
                                //检查问题与描述一致 检查问题不能修改
                                throw new Exception("整改建议与措施【" + entityContent.Nav_CheckMain.Nav_CheckQuestion.DEMAND + "】不能修改，操作失败！");
                            }
                        }
                    }
                }

                if (!entity.USER_ID.HasValue)
                {
                    entity.USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                }
                if (entity.DEPARTMENT_ID == null)
                {
                    entity.DEPARTMENT_ID = GetEntity<T_FM_USER>(entity.USER_ID.Value).DEPARTMENT_ID;
                }
                if (entityContent.TaskID != Guid.Empty && !entity.STARTTIME.HasValue)
                {
                    var task = GetEntity<T_FM_NOTIFICATION_TASK>(entityContent.TaskID);
                    entity.STARTTIME = task.CREATE_TIME;
                }

                //记录完善人信息
                entity.CREATER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                entity.CREATE_TIME = DateTime.Now;
                if (entity.SUBMIT_STATUS == (int)BSSubmitStatusEnum.Temp)
                {
                    this.UnifiedCommit(() =>
                    {
                        if (entityContent != null)
                            UpdateEntityNoCommit(entityContent);
                        if (entity != null)
                            UpdateEntityNoCommit(entity);
                        if (modelCheck != null)
                            UpdateEntityNoCommit(modelCheck);
                        if (files != null && files.Any())
                            BantchSaveEntityNoCommit(files);
                        if (listRiskQuestionReason != null && listRiskQuestionReason.Any())
                            BantchSaveEntityNoCommit(listRiskQuestionReason);
                    });
                }
                else
                {
                    //手动隐患上报 为了让整改通知 数据权限正常 修改部门信息为 责任部门信息
                    if (entityContent.DEPARTMENT_ID.HasValue && entity.DEPARTMENT_ID != entityContent.DEPARTMENT_ID)
                    {
                        entity.DEPARTMENT_ID = entityContent.DEPARTMENT_ID;
                    }

                    List<string> listSerialCode = new List<string>();
                    var index = entity.CODE.IndexOf(DateTime.Now.Year.ToString());
                    if (index == -1)
                    {
                        index = entity.CODE.IndexOf((DateTime.Now.Year - 1).ToString());
                    }
                    string yearMonth = string.Empty;
                    if (index > 0)
                    {
                        yearMonth = entity.CODE.Substring(index);
                    }
                    else
                    {
                        yearMonth = DateTime.Now.ToString("yyyyMMddHHmmss");
                    }

                    string code = "YHSB" + yearMonth;
                    if (code.Length > 20)
                    {
                        code = code.Substring(0, 15);
                    }

                    listSerialCode.Add(code);

                    if (listParam.Count > 1)
                    {
                        for (int i = 1; i < listParam.Count; i++)
                        {
                            listSerialCode.Add(code + i.ToString());
                        }
                    }

                    //如果是手动隐患上报 根据明细的 整改责任人  来走审批流 20240118
                    Guid? ApproveIDDependUserID = entityContent.DEAL_USER_ID;
                    List<int> listLevel = new List<int>() { entityContent.QUESTION_LEVEL };
                    Dictionary<int, List<Guid>> dic = new Dictionary<int, List<Guid>>();
                    dic.Add(entityContent.QUESTION_LEVEL, new List<Guid>() { entityContent.ID });
                    //??????
                    ////给通知责任人 发送通知
                    ////通知责任人 确定 后  走审批流
                    MFlowPermitService.InsertApproveRisk(listSerialCode, "BS006", listId, "BS006_SHOWPRINT", entityContent.TaskID, true, () =>
                    {
                        if (entityContent != null)
                            UpdateEntityNoCommit(entityContent);
                        if (entity != null)
                            UpdateEntityNoCommit(entity);
                        if (listSubmitNotice.Any())
                            BantchSaveEntityNoCommit(listSubmitNotice);
                        if (modelCheck != null)
                            UpdateEntityNoCommit(modelCheck);
                        if (files != null && files.Any())
                            BantchSaveEntityNoCommit(files);
                        if (listRiskQuestionReason != null && listRiskQuestionReason.Any())
                            BantchSaveEntityNoCommit(listRiskQuestionReason);
                    }, listParam, listApproveId, ApproveIDDependUserID, "BS073_SHOWPRINT", null, ListDepIDNone, FMTASKTYPE.BS_RiskUp_Audit, null, null, ((int)OPERATEPOINT_Enums.RiskInfoCompleteSD), entity.ID, listLevel, dic);//  null =>ApproveIDDependUserID
                }
                return true;
            });
        }



        /// <summary>
        /// 验收人 确认 
        /// 按整改明细给 整改落实人发送 整改通知
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("CheckerCheckToActual")]
        public JsonActionResult<bool> CheckerCheckToActual([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {
                //确定 / 驳回  确定（给责任人 BS042_SHOWPRINT 发送通知 ） 驳回 （隐患通知责任人）发送通知 （BS042）
                Guid id = new Guid(filter.Keyword);
                DateTime dtNow = DateTime.Now;
                var LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                var TaskID = new Guid(filter.Parameter1);

                var entity = GetEntity<T_BS_RISK_SUBMIT_NOTICE_PERSON>(id, new string[] { "Nav_ListRiskSubmitContent.Nav_UserActualDeal", "Nav_ListRiskSubmitContent.Nav_Files" });
                var listRiskSubminContentl = entity.Nav_ListRiskSubmitContent;
                if (listRiskSubminContentl != null && listRiskSubminContentl.Count() > 1)
                {
                    listRiskSubminContentl = listRiskSubminContentl.FindAll(e => e.CHECK_USER_ID == LoginID);//DEAL_USER_ID
                    if (listRiskSubminContentl == null || !listRiskSubminContentl.Any())
                    {
                        throw new Exception("只有验收人才能验收！");
                    }
                }
                else if (listRiskSubminContentl[0].CHECK_USER_ID != LoginID)//DEAL_USER_ID
                {
                    throw new Exception("只有验收人才能验收！");
                }

                int CodeTemp = 0;
                //同意
                List<T_BS_RISK_SUBMIT_CONTENT_DEAL> listContentDeal = new List<T_BS_RISK_SUBMIT_CONTENT_DEAL>();
                List<T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE> listDealF = new List<T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE>();
                List<T_FM_NOTIFICATION_TASK> listNoticeDeal = new List<T_FM_NOTIFICATION_TASK>();
                T_BS_RISK_SUBMIT_CONTENT_DEAL dealTemp = null;
                List<T_BS_OPERATE_LOG> listLog = new List<T_BS_OPERATE_LOG>();
                listRiskSubminContentl.ForEach(item =>
                {
                    if (item.CHECK_USER_ID == LoginID)
                        item.ISCHECKERCHECK = true;
                    if (item.DEAL_USER_ID == LoginID)
                        item.ISDEALUSERCHECK = true;

                    if (item.ISDEALUSERCHECK && item.ISCHECKERCHECK)
                    {
                        item.RiskContentState = (int)RiskContentState.ActualDealChange;//item.RiskContentState = (int)RiskContentState.ArrangeDeal;
                    }
                });

                T_FM_NOTIFICATION_TASK task = null;
                GetEntityTask(TaskID, ref task);
                DateTime? TASK_ENDDT = null;
                if (task != null)
                {
                    TASK_ENDDT = task.TASK_ENDDT;
                }
                //给验收人 发送通知
                DateTime dtEnd = NotificationTaskService.GetTaskEndTime(FMTASKTYPE.BS_RiskUp_ActualDealNotice, entity.ORG_ID.Value, DateTime.Now, null, null);
                foreach (var item in listRiskSubminContentl)
                {
                    //数据处理
                    CodeTemp++;
                    #region     隐患整改记录

                    dealTemp = new T_BS_RISK_SUBMIT_CONTENT_DEAL();
                    dealTemp.ID = Guid.NewGuid();
                    dealTemp.ORG_ID = item.ORG_ID;
                    dealTemp.RISK_SUBMIT_ID = item.RISK_SUBMIT_ID;
                    dealTemp.RISK_SUBMIT_NOTICE_ID = item.RISK_SUBMIT_NOTICE_ID;
                    dealTemp.RISK_SUBMIT_NOTICE_PERSON_ID = item.RISK_SUBMIT_NOTICE_PERSON_ID;
                    dealTemp.RISK_SUBMIT_CONTENT_ID = item.ID;
                    dealTemp.CODE = item.CODE + "_" + CodeTemp;

                    dealTemp.NAME = item.NAME.Replace("隐患整改通知：", "");
                    //dealTemp.ENDDATE = item.LastDateUser;//整改结束时间   
                    dealTemp.QUESTION_LEVEL = item.QUESTION_LEVEL;
                    dealTemp.DEALSITUATION = (int)DealSituation.Temp;
                    dealTemp.DEAL_USER_ID = item.DEAL_USER_ID;
                    dealTemp.ACTUAL_DEAL_USER_ID = item.ACTUAL_DEAL_USER_ID;
                    dealTemp.CHECK_USER_ID = item.CHECK_USER_ID;
                    dealTemp.REMARK = item.REMARK;
                    listContentDeal.Add(dealTemp);

                    //附件
                    if (item.Nav_Files != null && item.Nav_Files.Any())
                    {
                        foreach (var itemF in item.Nav_Files)
                        {
                            listDealF.Add(new T_BS_RISK_SUBMIT_CONTENT_DEAL_FILE()
                            {
                                ID = Guid.NewGuid(),
                                RISK_SUBMIT_CONTENT_DEAL_ID = dealTemp.ID,
                                IMG_FILE_ID = itemF.IMG_FILE_ID,
                                IS_DELETED = false,
                                ORG_ID = item.ORG_ID,
                                ENTITY_ORG_TPYE = item.ENTITY_ORG_TPYE,
                                FLOW_STATUS = item.FLOW_STATUS,
                                FLOW_SEND_STATUS = item.FLOW_SEND_STATUS,
                                //FORM_ID
                                //FLOW_ID
                                //CREATE_TIME
                                //MODIFY_TIME
                                //CREATER_ID
                                //MODIFIER_ID

                            });
                        }
                    }

                    #endregion

                    //每个整改责任人 收到待办
                    //var notice = NotificationTaskService.InsertUserNoticeTaskModel("指定整改落实人：" + dealTemp.NAME, item.ID, entity.ORG_ID, item.DEAL_USER_ID.Value, item.Nav_UserDeal.NAME, dtNow, (dtTsakEnd > item.LastDateUser.Value ? item.LastDateUser.Value : dtTsakEnd), (int)FMNoticeTypeEnum.消息, "BS049");
                    var check = listNoticeDeal.FirstOrDefault(e => e.USER_ID == dealTemp.ACTUAL_DEAL_USER_ID.Value);
                    if (check == null)
                    {
                        string title = "整改落实人确认：" + entity.NAME.Replace("隐患整改通知：", "");
                        var notice = NotificationTaskService.InsertUserNoticeTaskModel(title, dealTemp.RISK_SUBMIT_NOTICE_PERSON_ID.Value, entity.ORG_ID, dealTemp.ACTUAL_DEAL_USER_ID.Value, item.Nav_UserActualDeal.NAME, DateTime.Now, dtEnd, (int)FMNoticeTypeEnum.消息, "BS042_ACTUALCHECK");//BS042_SHOWPRINT

                        notice.CREATE_TIME = dtNow;
                        listNoticeDeal.Add(notice);



                        listLog.AddRange(OperateLogService.GetListOperateLog(OPERATEPOINT_Enums.RiskNoticeCheckerCheck, entity.RISK_SUBMIT_ID.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, null, new List<Guid>() { dealTemp.ACTUAL_DEAL_USER_ID.Value }, new List<string>() { item.Nav_UserActualDeal.NAME }, entity.ORG_ID, item.ID, null, false, TASK_ENDDT));
                    }
                }


                /// 整改落实人 确认整改通知单 系统发送整改单给整改落实人
                //UpdateActualDealRecord

                if (listRiskSubminContentl[0].ACTUAL_DEAL_USER_ID.HasValue && listRiskSubminContentl[0].DEAL_USER_ID.HasValue && listRiskSubminContentl[0].ACTUAL_DEAL_USER_ID.Value == listRiskSubminContentl[0].DEAL_USER_ID.Value)
                {
                    //整改责任人 与落实人 同一个
                    //整改落实人确认 待办默认处理
                    listNoticeDeal[0].TASK_DT = DateTime.Now;
                    if (listNoticeDeal[0].TASK_ENDDT >= listNoticeDeal[0].TASK_DT)
                        listNoticeDeal[0].NOTICE_STATUS = FMNoticeStatusEnum.正常已办.GetInt();
                    else
                        listNoticeDeal[0].NOTICE_STATUS = FMNoticeStatusEnum.超期办理.GetInt();

                    //状态修改
                    listRiskSubminContentl[0].RiskContentState = (int)RiskContentState.ActualDealCheck;

                    //发送待办（隐患整改单）
                    listNoticeDeal.Add(NotificationTaskService.InsertUserNoticeTaskModel("隐患整改单：" + listRiskSubminContentl[0].NAME.Replace("隐患整改通知：", ""), listContentDeal[0].ID, listRiskSubminContentl[0].ORG_ID, listRiskSubminContentl[0].ACTUAL_DEAL_USER_ID.Value, listRiskSubminContentl[0].Nav_UserActualDeal.NAME, DateTime.Now, listRiskSubminContentl[0].LastDateUser.Value, (int)FMNoticeTypeEnum.消息, "BS044"));
                }


                //OperateLogService.GetListOperateLog(OPERATEPOINT_Enums.RiskAssignActure, entity.RISK_SUBMIT_ID.Value, APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value, null, ListNoticeAll, ListNoticeAllNAME, entity.ORG_ID, item.ID, null, false, TASK_ENDDT);


                this.UnifiedCommit(() =>
                {
                    UpdateEntityNoCommit(entity);//保存状态
                    if (listContentDeal.Count > 0)
                        BantchSaveEntity(listContentDeal);//保存待整改明细
                    if (listDealF != null && listDealF.Any())//附件
                        BantchSaveEntity(listDealF);    //附件
                    if (listRiskSubminContentl != null && listRiskSubminContentl.Any())//隐患上报明细表
                        BantchSaveEntity(listRiskSubminContentl);    //保存子表
                    if (listNoticeDeal != null && listNoticeDeal.Any())//整改责任人 按条数 收到整改单
                        BantchSaveEntity(listNoticeDeal);
                    if (listLog != null && listLog.Any())//操作日志
                        BantchSaveEntity(listLog);
                    if (task != null)//代办消息 清除
                        UpdateEntityNoCommit(task, "NOTICE_STATUS", "TASK_DT", "MODIFIER_ID");
                });

                return true;
            });
        }


        /// <summary>
        /// 隐患上报信息完善 添加删除事件
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpGet, Route("RiskDel")]
        public JsonActionResult<bool> RiskDel(Guid ID)
        {
            return SafeExecute<bool>(() =>
            {
                var entityContent = GetEntity<T_BS_RISK_SUBMIT_CONTENT>(ID);
                if (entityContent == null)
                {
                    throw new Exception("获取操作信息失败！");
                }
                if (entityContent.RiskContentState == (int)RiskContentState.ReportedReject)
                {
                    throw new Exception("该单已删除，点击右上角[X]按钮关闭该页面！");
                }
                var task = GetEntity<T_FM_NOTIFICATION_TASK>(e => e.SOURCE_DATA_ID.HasValue && e.SOURCE_DATA_ID.Value == ID && e.NOTICE_STATUS == 0);
                if (task == null)
                {
                    throw new Exception("获取待办信息失败！");
                }
                if (task.USER_ID != APT.Infrastructure.Api.AppContext.CurrentSession.UserID)
                {
                    throw new Exception("您不是该单的信息完善人员，操作失败！");
                }
                task.NOTICE_STATUS = (int)FMNoticeStatusEnum.关闭;
                task.MODIFY_TIME = DateTime.Now;
                task.MODIFIER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (entityContent.DESCRIBE.Length < 480)
                {
                    entityContent.DESCRIBE = task.USER_NAME + ":终止上报信息完善";
                }
                entityContent.RiskContentState = (int)RiskContentState.ReportedReject;
                T_BS_RISK_SUBMIT sub = null;
                if (entityContent.RISK_SUBMIT_ID.HasValue)
                {
                    sub = GetEntity<T_BS_RISK_SUBMIT>(entityContent.RISK_SUBMIT_ID.Value);
                    sub.SUBMIT_STATUS = (int)BSSubmitStatusEnum.AuditRefuse;
                }

                this.UnifiedCommit(() =>
                {
                    if (sub != null)
                        UpdateEntityNoCommit(sub);
                    if (entityContent != null)
                        UpdateEntityNoCommit(entityContent);
                    if (task != null)
                        UpdateEntityNoCommit(task);
                });
                return true;
            });
        }

        #endregion
    }
}
