using APT.BaseData.Domain.Entities;
using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.Enums;
using APT.BaseData.Domain.Enums.PF;
using APT.BaseData.Domain.IServices;
using APT.BaseData.Domain.IServices.FM;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.SK;
using APT.MS.Domain.Enums;
using APT.MS.Domain.Enums.SK;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualStudio.Web.CodeGeneration.Utils;
using MySqlX.XDevAPI.Common;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;

namespace APT.SK.WebApi.Controllers.Api
{
    /// <summary>
    ///  安全风险评估表
    /// </summary>
    [Route("api/SK/SKRiskEvaluation")]
    public partial class RiskEvaluationController : AuthorizeApiController<T_SK_RISK_EVALUATION>
    {
        IPFApproveCallBackService ApproveCallBackService { get; set; }
        IFMNotificationTaskService NotificationTaskService { get; set; }
        IPFCodeRuleService CodeRuleService { get; set; }
        IFMFlowPermitService MFlowPermitService { get; set; }
        public RiskEvaluationController(IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFCodeRuleService codeRuleService, IPFApproveCallBackService approveCallBackService)
        {
            NotificationTaskService = notificationTaskService;
            MFlowPermitService = mFlowPermitService;
            CodeRuleService = codeRuleService;
            ApproveCallBackService = approveCallBackService;
        }
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_SK_RISK_EVALUATION entity)
        {
            return SafeExecute<bool>(() =>
            {
                var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                var departId = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID;
                if (entity.APPLY_USER_ID == null)
                    entity.APPLY_USER_ID = userId;
                if (entity.APPLY_DEPARTMENT_ID == null)
                    entity.APPLY_DEPARTMENT_ID = departId;
                if (entity.IDENTIFY_EVALUATION_PLAN_ID == null)
                    entity.APPLY_DEPARTMENT_ID = this.GetEntity<T_SK_IDENTIFY_EVALUATION_PLAN>(t => t.START_DATE.Value.Date == entity.START_DATE.Value.Date && t.STATUS == PFStandardStatus.Archived && t.ISSEND == true)?.ID;
                var details = entity.Nav_Details;
                entity.Nav_Details = null;
                var requires = entity.Nav_Requires;
                entity.Nav_Requires = null;
                var files = entity.Nav_Files;
                entity.Nav_Files = null;
                entity.ApplyDepartmentName = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == departId).NAME;
                entity.ApplyPostName = this.GetEntity<T_FM_USER>(t => t.ID == userId, "Nav_Person.Nav_Post")?.Nav_Person?.Nav_Post?.NAME;
                List<Guid> deleteMeasureIds = new List<Guid>();
                List<Guid> deleteDepartIds = new List<Guid>();
                List<Guid> deletePostIds = new List<Guid>();
                List<Guid> deletePostDetIds = new List<Guid>();
                List<Guid> deleteDetailIds = new List<Guid>();
                List<T_SK_RISK_EVALUATION_DETAIL> detailList = new List<T_SK_RISK_EVALUATION_DETAIL>();
                List<T_SK_RISK_EVALUATION_DETAIL_MEASURE> measureList = new List<T_SK_RISK_EVALUATION_DETAIL_MEASURE>();
                List<T_SK_RISK_EVALUATION_DETAIL_DEPART> departList = new List<T_SK_RISK_EVALUATION_DETAIL_DEPART>();
                List<T_SK_RISK_EVALUATION_DETAIL_POST> postList = new List<T_SK_RISK_EVALUATION_DETAIL_POST>();
                List<T_SK_RISK_EVALUATION_DETAIL_POST_DETAIL> postDetList = new List<T_SK_RISK_EVALUATION_DETAIL_POST_DETAIL>();
                //更新标识字段
                var record = this.GetEntity<T_SK_RISK_EVALUATION>(t => t.ID == entity.ID, "Nav_Details");
                if (record != null && record.Nav_Details != null && record.Nav_Details.Any() && details != null && details.Any())
                {
                    deleteDetailIds = record.Nav_Details.Select(t => t.ID).ToList();
                    var detailMes = this.GetEntities<T_SK_RISK_EVALUATION_DETAIL_MEASURE>(t => deleteDetailIds.Contains(t.RISK_EVALUATION_DETAIL_ID), new BaseFilter(entity.ORG_ID)).ToList();
                    deleteMeasureIds = detailMes.Select(t => t.ID).ToList();
                    deleteDepartIds = this.GetEntities<T_SK_RISK_EVALUATION_DETAIL_DEPART>(t => deleteDetailIds.Contains(t.RISK_EVALUATION_DETAIL_ID), new BaseFilter(entity.ORG_ID)).Select(t => t.ID).ToList();
                    deletePostIds = this.GetEntities<T_SK_RISK_EVALUATION_DETAIL_POST>(t => deleteDetailIds.Contains(t.RISK_EVALUATION_DETAIL_ID), new BaseFilter(entity.ORG_ID)).Select(t => t.ID).ToList();
                    deletePostDetIds = this.GetEntities<T_SK_RISK_EVALUATION_DETAIL_POST_DETAIL>(t => deletePostIds.Contains(t.RISK_EVALUATION_DETAIL_POST_ID), new BaseFilter(entity.ORG_ID)).Select(t => t.ID).ToList();
                    foreach (var item in details)
                    {
                        var temp = record.Nav_Details.FirstOrDefault(t => t.PRODUCTION_UNIT_ID == item.PRODUCTION_UNIT_ID && t.AREA_ID == item.AREA_ID && t.TYPE_ID == item.TYPE_ID && t.RISK_NAME == item.RISK_NAME && t.RISK_DESCRIPTION == item.RISK_DESCRIPTION
                                 && t.EMERGENCY == item.EMERGENCY && t.ENABLE_STATUS == item.ENABLE_STATUS);
                        if (temp == null && item.MARK != SKMarkEnum.Add)
                        {
                            item.MARK = SKMarkEnum.Update;
                        }
                        if (item.Nav_DetailMeasures != null && item.Nav_DetailMeasures.Any())
                        {
                            foreach (var mes in item.Nav_DetailMeasures)
                            {
                                var newMes = detailMes.FirstOrDefault(t => t.MEASURES_NAME == mes.MEASURES_NAME && t.RISK_EVALUATION_DETAIL_ID == item.ID);
                                if (newMes == null && item.MARK != SKMarkEnum.Add)
                                {
                                    item.MARK = SKMarkEnum.Update;
                                }
                            }
                        }
                    }
                    //record.Nav_Details.ForEach(t =>
                    //{
                    //    if (t.Nav_DetailMeasures != null && t.Nav_DetailMeasures.Any())
                    //    {
                    //        var tempIds = t.Nav_DetailMeasures.Select(m => m.ID).ToList();
                    //        deleteMeasureIds.AddRange(tempIds);
                    //    }
                    //    if (t.Nav_DetailDeparts != null && t.Nav_DetailDeparts.Any())
                    //    {
                    //        var tempIds = t.Nav_DetailDeparts.Select(m => m.ID).ToList();
                    //        deleteDepartIds.AddRange(tempIds);
                    //    }
                    //    if (t.Nav_DetailPosts != null && t.Nav_DetailPosts.Any())
                    //    {
                    //        var tempIds = t.Nav_DetailPosts.Select(m => m.ID).ToList();
                    //        deletePostIds.AddRange(tempIds);
                    //    }
                    //    deleteDetailIds.Add(t.ID);
                    //});
                }
                if (details != null && details.Any())
                {
                    foreach (var item in details)
                    {
                        T_SK_RISK_EVALUATION_DETAIL de = new T_SK_RISK_EVALUATION_DETAIL();
                        de.ORG_ID = entity.ORG_ID;
                        de.RISK_EVALUATION_ID = entity.ID;
                        de.PRODUCTION_UNIT_ID = item.PRODUCTION_UNIT_ID;
                        de.AREA_ID = item.AREA_ID;
                        de.RISK_NAME = item.RISK_NAME;
                        de.RISK_DESCRIPTION = item.RISK_DESCRIPTION;
                        de.TYPE_ID = item.TYPE_ID;
                        de.ENABLE_STATUS = item.ENABLE_STATUS;
                        de.MARK = item.MARK;
                        de.EMERGENCY = item.EMERGENCY;
                        de.ENTERPRISE_LIBRARY_ID = item.ENTERPRISE_LIBRARY_ID;
                        if (item.Nav_DetailMeasures != null && item.Nav_DetailMeasures.Any())
                        {
                            foreach (var mm in item.Nav_DetailMeasures)
                            {
                                T_SK_RISK_EVALUATION_DETAIL_MEASURE item2 = new T_SK_RISK_EVALUATION_DETAIL_MEASURE();
                                item2.ORG_ID = entity.ORG_ID;
                                item2.RISK_EVALUATION_DETAIL_ID = de.ID;
                                item2.NUM = mm.NUM;
                                item2.MEASURES_NAME = mm.MEASURES_NAME;
                                measureList.Add(item2);
                                var temp = (item2.NUM == null || item2.NUM == 0) ? "1" : item2.NUM + "、" + item2.MEASURES_NAME + Environment.NewLine;
                                de.MEASURE = de.MEASURE + temp;
                            }
                        }
                        detailList.Add(de);
                        item.Nav_DetailMeasures = null;
                        if (item.Nav_DetailDeparts != null && item.Nav_DetailDeparts.Any())
                        {
                            foreach (var mm in item.Nav_DetailDeparts)
                            {
                                T_SK_RISK_EVALUATION_DETAIL_DEPART item2 = new T_SK_RISK_EVALUATION_DETAIL_DEPART();
                                item2.ORG_ID = entity.ORG_ID;
                                item2.RISK_EVALUATION_DETAIL_ID = de.ID;
                                item2.DEPARTMENT_TYPE = mm.DEPARTMENT_TYPE;
                                item2.DEPARTMENT_ID = mm.DEPARTMENT_ID;
                                departList.Add(item2);
                            }
                        }
                        item.Nav_DetailDeparts = null;
                        if (item.Nav_DetailPosts != null && item.Nav_DetailPosts.Any())
                        {
                            foreach (var mm in item.Nav_DetailPosts)
                            {
                                T_SK_RISK_EVALUATION_DETAIL_POST item2 = new T_SK_RISK_EVALUATION_DETAIL_POST();
                                item2.ORG_ID = entity.ORG_ID;
                                item2.RISK_EVALUATION_DETAIL_ID = de.ID;
                                item2.DEPARTMENT_ID = mm.DEPARTMENT_ID;
                                postList.Add(item2);
                                if (item2.Nav_PostDetails != null && item2.Nav_PostDetails.Any())
                                {
                                    foreach (var nn in item2.Nav_PostDetails)
                                    {
                                        T_SK_RISK_EVALUATION_DETAIL_POST_DETAIL item3 = new T_SK_RISK_EVALUATION_DETAIL_POST_DETAIL();
                                        item3.ORG_ID = entity.ORG_ID;
                                        item3.RISK_EVALUATION_DETAIL_POST_ID = item2.ID;
                                        item3.POST_ID = nn.POST_ID;
                                        postDetList.Add(item3);
                                    }
                                }
                            }
                        }
                        item.Nav_DetailPosts = null;
                        if (item.EVALUATE_LEVEL == SKEvaluateLevelEnum.重大风险)
                        {
                            if (!string.IsNullOrEmpty(item.DEPARTMENT_TYPE) && !item.DEPARTMENT_TYPE.Contains("公司级"))
                            {
                                //throw new Exception("第" + item.NUM + "行，重大风险管控层级必须包含公司级");
                            }
                        }
                        if (item.EVALUATE_LEVEL == SKEvaluateLevelEnum.较大风险)
                        {
                            if (!string.IsNullOrEmpty(item.DEPARTMENT_TYPE) && !item.DEPARTMENT_TYPE.Contains("部门级") && !item.DEPARTMENT_TYPE.Contains("公司级"))
                            {
                                //throw new Exception("第" + item.NUM + "行，较大风险管控层级必须大于部门级");
                            }
                        }
                        if (item.EVALUATE_LEVEL == SKEvaluateLevelEnum.一般风险)
                        {
                            if (!string.IsNullOrEmpty(item.DEPARTMENT_TYPE) && !item.DEPARTMENT_TYPE.Contains("部门级") && !item.DEPARTMENT_TYPE.Contains("公司级") && !item.DEPARTMENT_TYPE.Contains("车间级"))
                            {
                                //throw new Exception("第" + item.NUM + "行，一般风险管控层级必须大于车间级");
                            }
                        }
                        if (item.EVALUATE_LEVEL == SKEvaluateLevelEnum.低风险)
                        {
                            if (!string.IsNullOrEmpty(item.DEPARTMENT_TYPE) && !item.DEPARTMENT_TYPE.Contains("部门级") && !item.DEPARTMENT_TYPE.Contains("公司级") && !item.DEPARTMENT_TYPE.Contains("车间级") && !item.DEPARTMENT_TYPE.Contains("班组级"))
                            {
                                //throw new Exception("第" + item.NUM + "行，低风险管控层级必须大于班组级");
                            }
                        }
                    }
                }
                if (files != null && files.Any())
                {
                    foreach (var item in files)
                    {
                        item.ORG_ID = entity.ORG_ID;
                        item.RISK_EVALUATION_ID = entity.ID;
                        item.Nav_ImgFile = null;
                    }
                }
                if (requires != null && requires.Any())
                {
                    foreach (var item in requires)
                    {
                        item.ORG_ID = entity.ORG_ID;
                        item.RISK_EVALUATION_ID = entity.ID;
                        item.Nav_Require = null;
                    }
                }
                List<T_FM_NOTIFICATION_TASK> notices = new List<T_FM_NOTIFICATION_TASK>();
                if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
                {
                    //if (departList.Where(t => t.IS_DELETED == false).Count() == 0)
                    //{
                    //    throw new Exception("管控层级不能为空");
                    //}
                    var department = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == entity.APPLY_DEPARTMENT_ID && t.ENABLE_STATUS == 0);
                    var param = Enum.GetName(typeof(SKDepartmentTypeEnum), department.DEPARTMENT_TYPE);
                    if (department.DEPARTMENT_STATUS == 2)
                    {
                        param = "公司级";
                    }
                    entity.STATUS = PFStandardStatus.Approving;
                    //取审批流水码
                    var sysFilter = new SystemCodeFilter();
                    sysFilter.CodeType = (int)PFCodeRuleType.审批流编码;
                    sysFilter.Count = 1;
                    sysFilter.OrgId = entity.ORG_ID;
                    var codes = CodeRuleService.NewGenSerial(sysFilter);
                    var serialCode = codes.Split(new char[] { ',' });
                    MFlowPermitService.InsertApprove(serialCode[0], "SK039", param, entity.ID, "SK039_SHOWPRINT", entity.TaskID, true, () =>
                    {
                        if (deleteMeasureIds != null && deleteMeasureIds.Any())
                            this.BantchDeleteEntityNoCommit<T_SK_RISK_EVALUATION_DETAIL_MEASURE>(deleteMeasureIds);
                        if (deleteDepartIds != null && deleteDepartIds.Any())
                            this.BantchDeleteEntityNoCommit<T_SK_RISK_EVALUATION_DETAIL_DEPART>(deleteDepartIds);
                        if (deletePostDetIds != null && deletePostDetIds.Any())
                            this.BantchDeleteEntityNoCommit<T_SK_RISK_EVALUATION_DETAIL_POST_DETAIL>(deletePostDetIds);
                        if (deletePostIds != null && deletePostIds.Any())
                            this.BantchDeleteEntityNoCommit<T_SK_RISK_EVALUATION_DETAIL_POST>(deletePostIds);
                        if (deleteDetailIds != null && deleteDetailIds.Any())
                            this.BantchDeleteEntityNoCommit<T_SK_RISK_EVALUATION_DETAIL>(deleteDetailIds);
                        if (entity != null)
                            UpdateEntityNoCommit(entity);
                        if (detailList != null && detailList.Any())
                            BantchSaveEntityNoCommit(detailList);
                        if (files != null && files.Any())
                            BantchSaveEntityNoCommit(files);
                        if (requires != null && requires.Any())
                            BantchSaveEntityNoCommit(requires);
                        if (measureList != null && measureList.Any())
                            BantchSaveEntityNoCommit(measureList);
                        if (departList != null && departList.Any())
                            BantchSaveEntityNoCommit(departList);
                        if (postList != null && postList.Any())
                            BantchSaveEntityNoCommit(postList);
                        if (postDetList != null && postDetList.Any())
                            BantchSaveEntityNoCommit(postDetList);
                    }, null, null, null, null, null, "SK039_SHOWPRINT", null, "安全风险评估表审批");
                    return true;
                }
                this.UnifiedCommit(() =>
                {
                    if (deleteMeasureIds != null && deleteMeasureIds.Any())
                        this.BantchDeleteEntityNoCommit<T_SK_RISK_EVALUATION_DETAIL_MEASURE>(deleteMeasureIds);
                    if (deleteDepartIds != null && deleteDepartIds.Any())
                        this.BantchDeleteEntityNoCommit<T_SK_RISK_EVALUATION_DETAIL_DEPART>(deleteDepartIds);
                    if (deletePostDetIds != null && deletePostDetIds.Any())
                        this.BantchDeleteEntityNoCommit<T_SK_RISK_EVALUATION_DETAIL_POST_DETAIL>(deletePostDetIds);
                    if (deletePostIds != null && deletePostIds.Any())
                        this.BantchDeleteEntityNoCommit<T_SK_RISK_EVALUATION_DETAIL_POST>(deletePostIds);
                    if (deleteDetailIds != null && deleteDetailIds.Any())
                        this.BantchDeleteEntityNoCommit<T_SK_RISK_EVALUATION_DETAIL>(deleteDetailIds);
                    if (entity != null)
                        UpdateEntityNoCommit(entity);
                    if (detailList != null && detailList.Any())
                        BantchSaveEntityNoCommit(detailList);
                    if (files != null && files.Any())
                        BantchSaveEntityNoCommit(files);
                    if (requires != null && requires.Any())
                        BantchSaveEntityNoCommit(requires);
                    if (measureList != null && measureList.Any())
                        BantchSaveEntityNoCommit(measureList);
                    if (departList != null && departList.Any())
                        BantchSaveEntityNoCommit(departList);
                    if (postList != null && postList.Any())
                        BantchSaveEntityNoCommit(postList);
                    if (postDetList != null && postDetList.Any())
                        BantchSaveEntityNoCommit(postDetList);
                });
                return true;
            });
        }
        /// <summary>
        /// 获得单条实体数据
        /// </summary>
        /// <param name="filter">过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("SKGet")]
        public JsonActionResult<T_SK_RISK_EVALUATION> SKGet([FromBody] KeywordFilter filter)
        {
            return SafeExecute(() =>
            {
                var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString();
                if (string.IsNullOrEmpty(id))
                    this.ThrowError("060010");
                filter.IgnoreDataRule = true;
                var result = this.GetEntity<T_SK_RISK_EVALUATION>(id, new string[] { "Nav_ApplyUser", "Nav_ApplyDepartment","Nav_Require",
           "Nav_Files.Nav_ImgFile","Nav_Requires.Nav_Require"});
                if (result != null)
                {
                    var details = this.GetEntities<T_SK_RISK_EVALUATION_DETAIL>(t => t.RISK_EVALUATION_ID == result.ID, new BaseFilter(filter.OrgId), "Nav_Area", "Nav_Type", "Nav_RiskName", "Nav_SCOREL", "Nav_SCOREE", "Nav_SCOREC", "Nav_ProductionUnit", "Nav_DetailMeasures", "Nav_DetailPosts.Nav_PostDetails.Nav_Post", "Nav_DetailDeparts.Nav_Department", "Nav_DetailDeparts.Nav_User");
                    if (details.Any())
                    {
                        var detailIds = details.Select(t => t.ID).ToList();
                        var measures = this.GetEntities<T_SK_RISK_EVALUATION_DETAIL_MEASURE>(t => detailIds.Contains(t.RISK_EVALUATION_DETAIL_ID), new BaseFilter(filter.OrgId));
                        var departs = this.GetEntities<T_SK_RISK_EVALUATION_DETAIL_DEPART>(t => detailIds.Contains(t.RISK_EVALUATION_DETAIL_ID), new BaseFilter(filter.OrgId), "Nav_Department", "Nav_User");
                        var posts = this.GetEntities<T_SK_RISK_EVALUATION_DETAIL_POST>(t => detailIds.Contains(t.RISK_EVALUATION_DETAIL_ID), new BaseFilter(filter.OrgId), "Nav_Department", "Nav_PostDetails.Nav_Post");
                        foreach (var detail in details)
                        {
                            var measureTemps = measures.Where(t => t.RISK_EVALUATION_DETAIL_ID == detail.ID).ToList();
                            detail.Nav_DetailMeasures = measureTemps.OrderBy(t => t.NUM).ToList();
                            var departTemps = departs.Where(t => t.RISK_EVALUATION_DETAIL_ID == detail.ID).ToList();
                            detail.Nav_DetailDeparts = departTemps.OrderBy(t => t.DEPARTMENT_TYPE).ThenBy(m => m.Nav_Department.NUM).ToList();
                            var postTemps = posts.Where(t => t.RISK_EVALUATION_DETAIL_ID == detail.ID).ToList();
                            detail.Nav_DetailPosts = postTemps.OrderBy(t => t.DEPARTMENT_ID).ToList();
                        }
                    }
                    result.Nav_Details = details.OrderBy(m => m.MineType).ThenBy(m => m.AREA_ID).ThenBy(n => n.TYPE_ID).ToList();
                    if (result.STATUS == PFStandardStatus.Rejected)
                    {
                        result.CONTEXT = ApproveCallBackService.RejectContent(result.ID);
                    }
                }
                return result;
            });
            //var result = WitEntity(null, filter);
            //if (result != null && result.Data != null && result.Data.STATUS ==  PFStandardStatus.Rejected)
            //{
            //    result.Data.CONTEXT = ApproveCallBackService.RejectContent(result.Data.ID);
            //}
            //return result;
        }

        /// <summary>
        /// 回调函数
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("BackUpdateNew")]
        public JsonActionResult<bool> BackUpdateNew([FromBody] T_PF_APPROVE entity)
        {
            return SafeExecute(() =>
            {
                return ApproveCallBackService.CallBackNew("SK/SKRiskEvaluation/BackUpdateNew", entity);
            });
        }
        /// <summary>
        /// 驳回
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("RejectUpdate")]
        public JsonActionResult<bool> RejectUpdate([FromBody] T_PF_APPROVE model)
        {
            return SafeExecute(() =>
            {
                //公共 获取审批流信息
                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(model, ref modelApp, ref listAppDetail, ref taskFinish, ref Msg);
                if (!ResultGetInfo)
                    throw new Exception("驳回失败！");
                if (modelApp == null || listAppDetail == null)
                    throw new Exception("获取驳回信息失败！");
                var entity = this.GetEntity<T_SK_RISK_EVALUATION>(model.DATA_ID, new string[] { "Nav_ApplyUser" });
                entity.STATUS = PFStandardStatus.Rejected;
                T_FM_NOTIFICATION_TASK notice = new T_FM_NOTIFICATION_TASK();
                if (entity.APPLY_USER_ID != null)
                {
                    //发消息
                    notice = NotificationTaskService.InsertUserNoticeTaskModel("安全风险评估表被驳回", entity.ID, entity.ORG_ID, (Guid)entity.APPLY_USER_ID, entity.Nav_ApplyUser?.NAME, DateTime.Now,
               DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "SK039");
                }
                UnifiedCommit(() =>
                {
                    if (entity != null)
                        this.UpdateEntityNoCommit(entity);
                    if (notice != null)
                        this.UpdateEntityNoCommit(notice);
                    if (modelApp != null)
                        UpdateEntityNoCommit(modelApp);
                    if (listAppDetail != null && listAppDetail.Count > 0)
                        BantchUpdateEntityNoCommit(listAppDetail);
                    if (taskFinish != null)
                        UpdateEntityNoCommit(taskFinish);
                });
                return true;
                //return ApproveCallBackService.CallReject("HM/HMLicenseAnalysis/RejectUpdate", id);
            });
        }
    }
}
