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.Entities.BS;
using APT.MS.Domain.Entities.HM;
using APT.MS.Domain.Enums;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace APT.HM.WebApi.Controllers.Api
{
    [Route("api/HM/HMRiskTask")]
    public partial class RiskTaskController : AuthorizeApiController<T_HM_RISK_TASK>
    {
        IFMFlowPermitService MFlowPermitService { get; set; }
        IFMNotificationTaskService NotificationTaskService { get; set; }
        IPFCodeRuleService CodeRuleService { get; set; }
        IPFApproveCallBackService ApproveCallBackService { get; set; }

        IFMUserService UserService { get; set; }

        public RiskTaskController(IFMNotificationTaskService notificationTaskService, IPFCodeRuleService codeRuleService, IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService, IFMUserService userService)
        {
            NotificationTaskService = notificationTaskService;
            CodeRuleService = codeRuleService;
            MFlowPermitService = mFlowPermitService;
            ApproveCallBackService = approveCallBackService;
            UserService = userService;
        }
        /// <summary>
        /// HM062更新
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_HM_RISK_TASK entity)
        {
            return SafeExecute<bool>(() =>
            {
                var files = entity.Nav_Files;
                var riskDetail = entity.Nav_Detail;
                var identifyings = entity.Nav_Identifyings;
                if (identifyings.Count == 0)
                {
                    throw new Exception("请选择辨识对象!");
                }
                var areas = entity.Nav_Areas;
                List<T_HM_RISK_TASK_USER> users = new List<T_HM_RISK_TASK_USER>();
                foreach (var detail in riskDetail)
                {
                    if (detail.AREA_ID == Guid.Empty || detail.AREA_ID == null)
                    {
                        throw new Exception("请填写区域!");
                    }
                    if (detail.RECORD_USER_ID == Guid.Empty || detail.AREA_ID == null)
                    {
                        throw new Exception("请选择记录人员!");
                    }
                    if (detail.Nav_Users != null)
                    {
                        detail.Nav_Users.ForEach(user =>
                        {
                            if (user.USER_ID != detail.RECORD_USER_ID)
                            {
                                user.ROW_NO = 999;
                            }
                        });
                        users.AddRange(detail.Nav_Users);
                        detail.Nav_Users = null;
                    }
                };
                if (entity.LIABLE_USER_ID == Guid.Empty || entity.LIABLE_USER_ID == null)
                {
                    entity.LIABLE_USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                }
                entity.Nav_Files = null;
                entity.Nav_Detail = null;
                entity.Nav_Identifyings = null;
                entity.Nav_Areas = null;
                identifyings?.ForEach(identifying => { identifying.Nav_Identifying = null; identifying.Nav_Task = null; });
                areas?.ForEach(areas => { areas.Nav_Area = null; areas.Nav_Task = null; });

                if (entity.INITIATING_DEPARTMENT == null)
                {
                    var user = GetEntity<T_FM_USER>(t => t.ID == APT.Infrastructure.Api.AppContext.CurrentSession.UserID);
                    if (user != null)
                        entity.INITIATING_DEPARTMENT = user.DEPARTMENT_ID;
                }
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId;
                entity.STATUS = FOPreMeetingStatusEnum.草稿;
                entity.APPROVECODE = null;
                    //是否需要发审批流，false不发，true的时候默认只发当前审核人
                    var isSendApprove = false;
                    //var isFinish = Guid.Empty;
                    T_FM_NOTIFICATION_TASK task = null;
                if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
                {
                    entity.STATUS = FOPreMeetingStatusEnum.审核中;
                    isSendApprove = true;
                    entity.APPROVECODE = DateTime.Now.ToString("yyyyMMddHHmmss");
                        //isFinish = entity.TaskID;
                        if (entity.TaskID != Guid.Empty)
                    {
                        task = NotificationTaskService.GetEntityTask(entity.TaskID, "HM061_SHOWPRINT");
                        if (task.SOURCE_DATA_ID == null)
                            task.SOURCE_DATA_ID = entity.ID;
                    }
                }
                var param = "";
                    //0908 修改按最高层级触发审批
                    if (entity.LEVEL.Contains("3"))
                {
                    param = "GS";
                }
                else if (entity.LEVEL.Contains("0"))
                {
                    param = "BM";
                }
                else
                {
                    param = "CJ";
                }

                MFlowPermitService.InsertApprove(entity.APPROVECODE, "HM062", param, entity.ID, "HM061_SHOWPRINT", null, isSendApprove, () =>
                {
                    if (entity != null)
                        UpdateEntityNoCommit(entity);   //保存主表
                        if (task != null)
                        UpdateEntityNoCommit(task);
                    if (files != null && files.Any())
                        BantchSaveEntityNoCommit(files);    //保存子表
                        if (identifyings != null && identifyings.Any())
                        BantchSaveEntityNoCommit(identifyings);
                    if (riskDetail != null && riskDetail.Any())
                        BantchSaveEntityNoCommit(riskDetail);
                    if (areas != null && areas.Any())
                        BantchSaveEntityNoCommit(areas);
                    if (users.Any())
                        BantchSaveEntityNoCommit(users);    //保存孙表
                    });
                return true;
            });
        }

        /// <summary>
        /// 审批流回调
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet, Route("PersonalApprove")]
        public JsonActionResult<bool> PersonalApprove(string id)
        {
            return SafeExecute<bool>(() =>
            {
                return ApproveCallBackService.CallBack("HM/HMRiskTask/PersonalApprove", id);
            });
        }
        /// <summary>
        /// 获取个人的班组前会议活动
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetUserDealStatus")]
        public JsonActionResult<bool> GetUserDealStatus([FromBody] T_HM_RISK_TASK entity)
        {
            return SafeExecute<bool>(() =>
            {
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId;
                BaseFilter filter = new BaseFilter(orgId);
                filter.Include = new string[] { "Nav_Detail.Nav_Users.Nav_User" };
                var model = GetEntity<T_HM_RISK_TASK>(t => t.ID == entity.ID, filter);
                //if (model.STATUS != FOPreMeetingStatusEnum.签到中)
                //    return false;
                var userID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                var userBool = false;
                foreach (var detail in model.Nav_Detail)
                {
                    var count = detail.Nav_Users.Count(t => t.USER_ID == userID && t.DEAL_STATUS == 0);
                    if (count > 0)  //该用户在该记录中是否参与且未同意则显示同意按钮
                    {
                        userBool = true;
                        break;
                    }
                    else
                    {
                        userBool = false;
                    }
                }
                return userBool;

            });
        }
        /// <summary>
        /// 签到
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("UserSignin")]
        public JsonActionResult<bool> UserSignin([FromBody] T_HM_RISK_TASK riskTask)
        {
            return SafeExecute<bool>(() =>
            {
                var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId;
                var userID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                var allTaskUsers = GetEntities<T_HM_RISK_TASK_USER>(t => t.Nav_Task_Detail.TASK_ID == riskTask.ID, new BaseFilter(orgId));
                var filter = new BaseFilter(orgId);
                filter.Include = new string[] { "Nav_Area", "Nav_User" };
                var allTaskDetails = GetEntities<T_HM_RISK_TASK_DETAIL>(t => t.TASK_ID == riskTask.ID, filter);
                var currUser = allTaskUsers.Where(t => t.USER_ID == userID);
                var currDetail = allTaskDetails.Where(t => t.RECORD_USER_ID == userID);
                foreach (var useritem in currUser)
                {
                    useritem.DEAL_STATUS = FOUserShiftStatusEnum.已处理;
                }
                foreach (var useritem in currDetail)
                {
                    useritem.DEAL_STATUS = FOUserShiftStatusEnum.已处理;
                }
                var todoCount = currDetail.Count(t => t.DEAL_STATUS == 0);
                T_HM_RISK_TASK entity = null;
                List<T_HM_RISK_RECORD> models = new List<T_HM_RISK_RECORD>();
                List<T_HM_RISK_RECORD_USER> allUsers = new List<T_HM_RISK_RECORD_USER>();
                List<T_HM_RISK_RECORD_IDENTIFYING> allIdentifyings = new List<T_HM_RISK_RECORD_IDENTIFYING>();
                List<T_HM_RISK_RECORD_FILE> allFiles = new List<T_HM_RISK_RECORD_FILE>();
                List<T_HM_RISK_RECORD_DETAIL> details = new List<T_HM_RISK_RECORD_DETAIL>();
                List<T_HM_RISK_RECORD_DETAIL_WORKDUTY> workdutys = new List<T_HM_RISK_RECORD_DETAIL_WORKDUTY>();
                List<T_HM_RISK_RECORD_DETAIL_EQUIPMENT> equipments = new List<T_HM_RISK_RECORD_DETAIL_EQUIPMENT>();
                List<T_HM_RISK_RECORD_DETAIL_FACILITIES> facilities = new List<T_HM_RISK_RECORD_DETAIL_FACILITIES>();
                List<T_FM_NOTIFICATION_TASK> sendNotices = null;
                T_FM_NOTIFICATION_TASK finishNotice = null;
                if (todoCount == 0 && currDetail.Any())
                {
                    entity = GetEntity<T_HM_RISK_TASK>(riskTask.ID, new string[] { "Nav_Identifyings", "Nav_Files", "Nav_Detail.Nav_Area", "Nav_Detail.Nav_User" });
                    var noticeTitles = new List<string>();
                    var noticeUserIds = new List<Guid>();
                    var noticeUserNames = new List<string>();
                    var noticeDataIds = new List<Guid>();
                    T_HM_RISK_RECORD riskRecord = new T_HM_RISK_RECORD();
                    riskRecord.ID = Guid.NewGuid();
                    var sysFilter1 = new SystemCodeFilter();
                    sysFilter1.CodeType = (int)PFCodeRuleType.风险辨识记录编号;
                    sysFilter1.Count = 1;
                    sysFilter1.OrgId = orgId;
                    var codes1 = CodeRuleService.NewGenSerial(sysFilter1);
                    riskRecord.CODE = codes1;
                    var userdepartment = GetEntity<T_FM_USER>(t => t.ID == userID && t.ENABLE_STATUS == 0);
                    if (userdepartment != null)
                    {
                        riskRecord.INITIATING_DEPARTMENT = userdepartment.DEPARTMENT_ID;
                    }
                    riskRecord.NOTE_TAKER_ID = userID;
                    riskRecord.STATUS = (int)FOPreMeetingStatusEnum.草稿;
                    riskRecord.START_TIME = entity.START_TIME;
                    riskRecord.END_TIME = entity.END_TIME;
                    riskRecord.REQUEST_ID = (Guid)entity.REQUEST_ID;
                    riskRecord.ORG_ID = orgId;
                    riskRecord.LIABLE_USER_ID = entity.LIABLE_USER_ID;
                    riskRecord.PLAN_ID = entity.PLAN_ID;
                    riskRecord.LEVEL = currDetail.FirstOrDefault().LEVEL;
                    riskRecord.TASK_ID = riskTask.ID;
                    models.Add(riskRecord);
                    noticeTitles.Add("危险源辨识记录" + DateTime.Now.ToShortDateString());
                    noticeUserIds.Add((Guid)userID);
                    noticeUserNames.Add(currDetail.FirstOrDefault().Nav_User.NAME);
                    noticeDataIds.Add(riskRecord.ID);
                    if (currDetail.Any())
                    {
                        var areaList = currDetail.Select(t => t.AREA_ID).ToList();
                        BaseFilter baseFilter = new BaseFilter(orgId);
                        baseFilter.Include = new string[] { "Nav_EvaluateRiskWorkduty", "Nav_EvaluateRiskEquipment", "Nav_DepartmentLiable", "Nav_PostLiable" };
                        var identifyings = entity.Nav_Identifyings.Select(x => x.IDENTIFYING_ID).Distinct();
                        var dangerDB = this.GetEntities<T_HM_EVALUATE_RISK>(t => areaList.Contains((Guid)t.AREA_ID) && identifyings.Contains((Guid)t.IDENTIFYING_ID) && t.STATUS == (int)HMOperationStepEnum.有效, baseFilter);
                        foreach (var detail in currDetail)
                        {
                            var dangerDBAreas = dangerDB.Where(t => t.AREA_ID == detail.AREA_ID && t.LEVEL == detail.LEVEL);
                            if (dangerDBAreas.Any())
                            {
                                foreach (var danger in dangerDBAreas)
                                {
                                    T_HM_RISK_RECORD_DETAIL recordDetail = new T_HM_RISK_RECORD_DETAIL();
                                    recordDetail.ID = Guid.NewGuid();
                                    recordDetail.RECORD_ID = riskRecord.ID;
                                    recordDetail.AREA_ID = detail.AREA_ID;
                                    recordDetail.IDENTIFYING_ID = danger.IDENTIFYING_ID;
                                    recordDetail.ORG_ID = orgId;
                                    if (danger.TYPE_ID == null)
                                    {
                                        throw new Exception("危险源数据库中名称:  " + danger.NAME + "  的风险类别不能为空!");
                                    }
                                    recordDetail.TYPE_ID = danger.TYPE_ID;
                                    recordDetail.RISK_NAME = danger.NAME;
                                    recordDetail.RISK_PLACE = danger.RISK_PLACE;
                                    recordDetail.EVALUATE_RISK_ID = danger.ID;
                                    recordDetail.OPERATION_STEP_ID = danger.OPERATION_STEP_ID;
                                    recordDetail.RISK_STATUS = (HMOperationStepEnum)danger.STATUS;
                                    recordDetail.MODIFY_TYPE = HMModifyEnum.数据库;
                                    recordDetail.DEPARTMENT_LIABLE_ID = danger.DEPARTMENT_LIABLE_ID;
                                    recordDetail.POST_LIABLE_ID = danger.POST_LIABLE_ID;
                                    var liableUser = GetEntity<T_FM_USER>(t => t.DEPARTMENT_ID == danger.DEPARTMENT_LIABLE_ID && t.APPROVE_ROLE_ID == danger.POST_LIABLE_ID);
                                    if (liableUser == null)
                                    {
                                        throw new Exception("危险源数据库中未能找到责任单位:  " + danger.Nav_DepartmentLiable.NAME + " 与责任岗位:  " + danger.Nav_PostLiable.NAME + " 对应的责任人!");
                                    }
                                    else
                                    {
                                        recordDetail.LIABLE_USER_ID = liableUser.ID;
                                    }
                                    if (danger.Nav_EvaluateRiskWorkduty != null)
                                    {
                                        foreach (var item3 in danger.Nav_EvaluateRiskWorkduty)
                                        {
                                            T_HM_RISK_RECORD_DETAIL_WORKDUTY workduty = new T_HM_RISK_RECORD_DETAIL_WORKDUTY();
                                            workduty.WORKDUTY_ID = item3.POST_ID;
                                            workduty.RISK_RECORD_DETAIL_ID = recordDetail.ID;
                                            workduty.ORG_ID = orgId;
                                            workdutys.Add(workduty);
                                        }
                                    }
                                    if (danger.Nav_EvaluateRiskEquipment != null)
                                    {
                                        foreach (var item3 in danger.Nav_EvaluateRiskEquipment)
                                        {
                                            T_HM_RISK_RECORD_DETAIL_EQUIPMENT equipment = new T_HM_RISK_RECORD_DETAIL_EQUIPMENT();
                                            equipment.EQUIPMENT_ID = item3.EQUIPMENT_ID;
                                            equipment.RISK_RECORD_DETAIL_ID = recordDetail.ID;
                                            equipment.ORG_ID = orgId;
                                            equipments.Add(equipment);
                                        }
                                    }
                                    details.Add(recordDetail);
                                }
                            }
                            var taskUsers = allTaskUsers.Where(t => t.TASK_DETAIL_ID == detail.ID);
                            //添加人员
                            foreach (var user in taskUsers)
                            {
                                T_HM_RISK_RECORD_USER recordUser = new T_HM_RISK_RECORD_USER();
                                recordUser.RECORD_ID = riskRecord.ID;
                                recordUser.AREA_ID = detail.AREA_ID;
                                recordUser.USER_ID = user.USER_ID;
                                recordUser.ORG_ID = detail.ORG_ID;
                                if (user.USER_ID != userID)
                                {
                                    recordUser.DEAL_STATUS = FOUserShiftStatusEnum.待处理;
                                }
                                else
                                {
                                    recordUser.DEAL_STATUS = FOUserShiftStatusEnum.已处理;
                                }
                                allUsers.Add(recordUser);
                            }
                            allUsers = allUsers.DistinctBy(u => new { u.USER_ID, u.AREA_ID }).ToList();
                        }

                        //添加辨识对象
                        if (entity.Nav_Identifyings != null)
                        {
                            foreach (var item in entity.Nav_Identifyings)
                            {
                                T_HM_RISK_RECORD_IDENTIFYING identifying = new T_HM_RISK_RECORD_IDENTIFYING();
                                identifying.RECORD_ID = riskRecord.ID;
                                identifying.IDENTIFYING_ID = item.IDENTIFYING_ID;
                                identifying.ORG_ID = orgId;
                                allIdentifyings.Add(identifying);
                            }
                        }
                        //添加附件
                        if (entity.Nav_Files != null)
                        {
                            foreach (var fileitem in entity.Nav_Files)
                            {
                                T_HM_RISK_RECORD_FILE file = new T_HM_RISK_RECORD_FILE();
                                file.RECORD_ID = riskRecord.ID;
                                file.IMG_FILE_ID = (Guid)fileitem.IMG_FILE_ID;
                                file.ORG_ID = orgId;
                                allFiles.Add(file);
                            }
                        }
                        var isallDone = allTaskUsers.Where(t => t.DEAL_STATUS == 0);
                        if (!isallDone.Any())
                        {
                            entity.STATUS = FOPreMeetingStatusEnum.归档;
                        }
                        sendNotices = NotificationTaskService.InsertUserNoticeTaskModels(noticeTitles, noticeDataIds, orgId, noticeUserIds, noticeUserNames, DateTime.Now, DateTime.Parse(DateTime.Now.AddDays(7).ToShortDateString() + " 23:59:59"), 0, "HM064");
                    }
                    if (riskTask.TaskID != null)
                    {
                        finishNotice = NotificationTaskService.FOGetTaskFinishModel(riskTask.TaskID, riskTask.ID);
                    }
                }
                UnifiedCommit(() =>
                {
                    BantchUpdateEntityNoCommit(currUser, "DEAL_STATUS", "MODIFY_TIME");
                    if (entity != null)
                        UpdateEntityNoCommit(entity, "STATUS");
                    if (models != null && models.Any())
                        BantchAddEntityNoCommit(models);
                    if (allUsers != null && allUsers.Any())
                        BantchAddEntityNoCommit(allUsers);
                    if (allIdentifyings != null && allIdentifyings.Any())
                        BantchAddEntityNoCommit(allIdentifyings);
                    if (allFiles != null && allFiles.Any())
                        BantchAddEntityNoCommit(allFiles);
                    if (details != null && details.Any())
                        BantchAddEntityNoCommit(details);
                    if (workdutys != null && workdutys.Any())
                        BantchAddEntityNoCommit(workdutys);
                    if (equipments != null && equipments.Any())
                        BantchAddEntityNoCommit(equipments);
                    if (facilities != null && facilities.Any())
                        BantchAddEntityNoCommit(facilities);
                    if (sendNotices != null && sendNotices.Any())
                        BantchAddEntityNoCommit(sendNotices);
                    if (finishNotice != null)
                        UpdateEntityNoCommit(finishNotice);
                });
                return true;
            });
        }
        /// 排序分页查询数据
        /// </summary>
        /// <param name="pageFilter">分页过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("OrderPagedAreaMineType")]
        public PagedActionResult<T_HM_RISK_AREA> OrderPagedAreaMineType([FromBody] KeywordPageFilter pageFilter)
        {
            return SafeGetPagedData<T_HM_RISK_AREA>((result) =>
            {
                Expression<Func<T_HM_RISK_AREA, bool>> expression = null;
                List<int> listMineType = new List<int>();
                if (pageFilter.FilterGroup.Groups.Count() > 0)
                {
                    var filterGroup = pageFilter.FilterGroup.Groups.ToList()[0];
                    if (filterGroup.Rules.Count() > 0)
                    {
                        foreach (var item in filterGroup.Rules)
                        {
                            if (item.Field == "CHECKOBJECT")
                            {
                                try
                                {
                                    listMineType.Add(int.Parse(item.Value.ToString()));
                                }
                                catch { }
                                filterGroup.Rules.Remove(item);
                                break;
                            }
                        }
                    }
                }

                if (listMineType == null)
                {
                    listMineType = UserService.GetMineType();
                }
                if (listMineType != null && listMineType.Count > 0)
                {
                    var listDepUnit = GetEntities<T_FM_DEPARTMENT_PRODUCTION_UNIT>(e => e.Nav_Enums != null && listMineType.Contains(e.Nav_Enums.VALUE), null, "Nav_Enums");
                    if (listDepUnit != null && listDepUnit.Any())
                    {
                        List<Guid> listDepID = listDepUnit.Select(e => e.DEPARTMENT_ID).ToList();
                        var listDep = GetEntities<T_FM_DEPARTMENT>(e => !e.MineType.HasValue || listDepID.Contains(e.ID), null, null);
                        List<Guid> listDepId = new List<Guid>();
                        if (listDep != null && listDep.Any())
                        {
                            listDepId = listDep.Select(e => e.ID).ToList();
                        }
                        if (listDepId.Count > 0)
                        {
                            expression = e => !e.DEPARTMENT_ID.HasValue || listDepId.Contains(e.DEPARTMENT_ID.Value);
                        }
                        else
                        {
                            expression = e => !e.DEPARTMENT_ID.HasValue;
                        }
                    }
                }


                PagedActionResult<T_HM_RISK_AREA> orderPageEntities = GetOrderPageEntities<T_HM_RISK_AREA>(expression, pageFilter, null);
                result.Data = orderPageEntities.Data;
                result.TotalCount = orderPageEntities.TotalCount;
            });
        }
        /// <summary>
        /// 审批流回调
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("RejectUpdate")]
        public JsonActionResult<bool> RejectUpdate([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;
                var record = GetEntity<T_HM_RISK_TASK>(entity.DATA_ID, new string[] { "Nav_LiableUser" });
                bool ResultGetInfo = ApproveCallBackService.GetApproject(entity, ref modelApp, ref listAppDetail, ref taskFinish, ref Msg);
                if (!ResultGetInfo)
                    throw new Exception("驳回失败！");
                record.STATUS = FOPreMeetingStatusEnum.审批拒绝;
                var sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("风险源辨识任务-驳回", entity.DATA_ID, record.ORG_ID, (Guid)record.LIABLE_USER_ID, record.Nav_LiableUser.NAME, DateTime.Now, DateTime.Now.AddHours(24), 0, "HM062");
                UnifiedCommit(() =>
                {
                    if (record != null)
                        UpdateEntityNoCommit(record);   //保存主表
                    if (sendNotice != null)
                        AddEntityNoCommit(sendNotice);
                });

                return true;


            });
        }
    }
}
