using APT.BaseData.Domain.Entities;
using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.Enums.PF;
using APT.BaseData.Domain.IServices;
using APT.BaseData.Domain.IServices.AE;
using APT.BaseData.Domain.IServices.FM;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.OH;
using APT.MS.Domain.Entities.TI;
using APT.MS.Domain.Enums;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace APT.SC.WebApi.Controllers.Api.OH
{
    [Route("api/OH/OHHazardMonitorJob")]
    public class OHHazardMonitorJobController : AuthorizeApiController<T_OH_HAZARD_MONITOR_JOB>
    {
        IFMFlowPermitService MFlowPermitService { get; set; }
        IPFApproveCallBackService ApproveCallBackService { get; set; }
        IAEAccidentEventReportService AccidentEventReportService { get; set; }
        IFMNotificationTaskService NotificationTaskService { get; set; }
        IFMUserService UserService { get; set; }
        public OHHazardMonitorJobController(IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService, IAEAccidentEventReportService accidentEventReportService, IFMNotificationTaskService notificationTaskService, IFMUserService userService)
        {
            MFlowPermitService = mFlowPermitService;
            ApproveCallBackService = approveCallBackService;
            AccidentEventReportService = accidentEventReportService;
            NotificationTaskService = notificationTaskService;
            UserService = userService;
        }

        /// <summary>
        /// 体检周期表 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_OH_HAZARD_MONITOR_JOB entity)
        {
            return SafeExecute<bool>(() =>
            {
                #region     值判断

                if (entity.TYPE_ID == null)
                {
                    throw new Exception("请选择监测类型");
                }
                var LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
                if (entity.USER_ID_GET.HasValue && LoginID.HasValue && entity.USER_ID.Value != LoginID.Value && entity.MODIFY_TIME != null && entity.CREATE_TIME != entity.MODIFY_TIME)//如果有人操作过
                {
                    throw new Exception("您同组织同岗人员已经操作过此单，操作失败！");
                }
                if (!entity.USER_ID_GET.HasValue)
                {
                    entity.USER_ID_GET = LoginID.Value;//操作人赋值
                }

                var Detail = entity.Nav_Detail;
                entity.Nav_Detail = null;

                if (Detail == null || !Detail.Any())
                {
                    throw new Exception("请输入检测记录明细！");
                }
                //Dictionary<T_OH_HAZARD_MONITOR_JOB_DETAIL, string> dicOverLimit = new Dictionary<T_OH_HAZARD_MONITOR_JOB_DETAIL, string>();
                T_FM_NOTIFICATION_TASK task = null;
                IEnumerable<T_FM_NOTIFICATION_TASK> listTaskNoDo = null;//对应记录的部门岗位如果有多个人 其余不需要处理
                //超限 通知 
                List<T_FM_NOTIFICATION_TASK> listTask = new List<T_FM_NOTIFICATION_TASK>();
                //穿戴提醒通知  （如果有多个缺少  一个人（部门安全员） 收到 1 条）
                List<T_FM_NOTIFICATION_TASK> listTaskWear = new List<T_FM_NOTIFICATION_TASK>();
                T_FM_NOTIFICATION_TASK TaskWearCheck = null;
                if (entity.STATUS == OHHazardMonitorJobStatusEnum.Finish)
                {
                    if (entity.MONITOR_TYPE == OHHazardMonitorFormTypeEnum.WaterMonitoring)
                    {
                        if (string.IsNullOrEmpty(entity.SAMPLE_PEOPLE))
                        {
                            throw new Exception("请输入取样人！");
                        }
                    }
                    else
                    {
                        if (!entity.USER_ID.HasValue)
                        {
                            throw new Exception("请选择检测人！");
                        }
                        //仪器名称 DEVICE_NAME   规格 / 型号  DEVICE_SPEC   监测方法 MONITOR_METHOD
                    }

                    if (entity.TaskID != Guid.Empty)
                    {
                        task = NotificationTaskService.GetEntityTask(entity.TaskID, "OH024_SHOWPRINT");

                        //别人的
                        listTaskNoDo = GetEntities<T_FM_NOTIFICATION_TASK>(e => e.ID != task.ID && e.SOURCE_DATA_ID == task.SOURCE_DATA_ID && e.SOURCE_FORMCODE == "OH024", null, null);
                        if (listTaskNoDo != null && listTaskNoDo.Any())
                        {
                            foreach (var item in listTaskNoDo)
                            {
                                item.SOURCE_FORMCODE = "OH024_SHOWPRINT";
                                item.TASK_DT = DateTime.Now;
                                item.NOTICE_STATUS = (int)FMNoticeStatusEnum.超时无需办理;
                            }
                        }
                    }

                    var listRule = GetEntities<T_OH_HAZARD_MONITOR_RULE>(e => e.TYPE_ID.HasValue && e.Nav_Type.MONITOR_TYPE == entity.MONITOR_TYPE, null, new string[] { "Nav_Type", "Nav_DepartmentWorkshop" });//"Nav_WarnPost.Nav_Users.Nav_User"
                    T_OH_HAZARD_MONITOR_RULE rule = null;
                    int i = 1;
                    string Warm = string.Empty;
                    DateTime dtWarmEnd = NotificationTaskService.GetTaskEndTime(BaseData.Domain.Enums.FMTASKTYPE.OH_MonitorJob_Warm, entity.ORG_ID.Value, DateTime.Now, null, null);

                    IEnumerable<T_FM_USER> IListUser = null;//警示人员
                    switch (entity.MONITOR_TYPE)
                    {
                        case OHHazardMonitorFormTypeEnum.DustMonitoring:
                            #region   粉尘

                            foreach (var item in Detail)
                            {
                                if (string.IsNullOrEmpty(item.SAMPLE_SOURCE))
                                {
                                    throw new Exception("请填写，行" + i + "扬尘来源！");
                                }
                                if (!item.JOB_STATUS.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "作业状态！");
                                }
                                if (!item.PROTECT_STATUS.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "个体防护情况！");
                                }
                                if (!item.MONITOR_RESULT_LOW.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "最低测定结果！");
                                }
                                if (!item.MONITOR_RESULT_HIGH.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "最高测定结果！");
                                }
                                if (item.MONITOR_RESULT_LOW.HasValue && item.MONITOR_RESULT_HIGH.HasValue && item.MONITOR_RESULT_LOW.Value > item.MONITOR_RESULT_HIGH.Value)
                                {
                                    throw new Exception("行" + i + "最低测定结果不能大于最高测定结果！");
                                }

                                rule = listRule.FirstOrDefault(e => e.ID == item.RULE_ID);

                                //最高值 大于  粉尘浓度阈值 超限
                                item.OVER_LIMIT = (item.MONITOR_RESULT_HIGH.Value > rule.THRESHOLD_DUST || item.MONITOR_RESULT_LOW.Value > rule.THRESHOLD_DUST) ? YesNoEnum.Yes : YesNoEnum.No;
                                if (item.OVER_LIMIT.Value == YesNoEnum.Yes)
                                {
                                    //3、是否超限为是时，推送今日提醒给警示推送人；消息类型：其他；消息内容：“监测车间”＋“监测地点”＋“扬尘类别”超限
                                    //dicOverLimit.Add(item, item.Nav_Rule.Nav_DepartmentWorkshop.NAME + item.Nav_Rule.LOCATION + entity.Nav_Type.NAME + entity.Nav_Type.SMALL_TYPE + "超限");

                                    IListUser = GetEntities<T_FM_USER>(e => e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == rule.DEPARTMENT_ID_WARN && e.Nav_Person.POST_ID == rule.WARN_POST_ID, null, "Nav_Person");

                                    //if (rule.Nav_WarnPost.Nav_Users == null || !rule.Nav_WarnPost.Nav_Users.Any())
                                    if (IListUser == null || !IListUser.Any())
                                    {
                                        throw new Exception("未找到警示推送人");
                                    }
                                    else
                                    {

                                        Warm = rule.Nav_DepartmentWorkshop.NAME + rule.LOCATION + rule.Nav_Type.NAME + "（" + rule.Nav_Type.SMALL_TYPE + "）" + "超限";
                                        foreach (var itemU in IListUser)//rule.Nav_WarnPost.Nav_Users
                                        {
                                            T_FM_NOTIFICATION_TASK taskWarm = NotificationTaskService.InsertUserNoticeTaskModel(Warm, Guid.Empty, itemU.ORG_ID, itemU.ID, itemU.NAME, DateTime.Now, dtWarmEnd, (int)FMNoticeTypeEnum.今日提醒, "");//, itemU.USER_ID, itemU.Nav_User.NAME
                                            listTask.Add(taskWarm);
                                        }
                                    }

                                    //int j = 0;
                                    //foreach (var itemU in rule.Nav_WarnPost.Nav_Users)
                                    //{
                                    //    j++;
                                    //    if (rule.DEPARTMENT_ID == itemU.Nav_User.DEPARTMENT_ID)
                                    //    {
                                    //        T_FM_NOTIFICATION_TASK taskWarm = NotificationTaskService.InsertUserNoticeTaskModel(rule.Nav_DepartmentWorkshop.NAME + rule.LOCATION + rule.Nav_Type.NAME + "（" + rule.Nav_Type.SMALL_TYPE + "）" + "超限", Guid.Empty, itemU.ORG_ID, itemU.USER_ID, itemU.Nav_User.NAME, DateTime.Now, DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.今日提醒, "");
                                    //        listTask.Add(taskWarm);
                                    //        break;
                                    //    }
                                    //    else if (j == rule.Nav_WarnPost.Nav_Users.Count)
                                    //    {
                                    //        throw new Exception("未找到警示推送人");
                                    //    }
                                    //}

                                }
                                //穿戴  缺少 时 给 安全员 发送待办
                                SafeWarm(item, rule, listTaskWear, TaskWearCheck);
                            }
                            i++;

                            #endregion
                            break;
                        case OHHazardMonitorFormTypeEnum.WorkPlaceMonitoring:

                            #region   噪音

                            foreach (var item in Detail)
                            {
                                if (string.IsNullOrEmpty(item.SAMPLE_SOURCE))
                                {
                                    throw new Exception("请填写，行" + i + "噪声来源！");
                                }
                                if (!item.JOB_STATUS.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "作业状态！");
                                }
                                if (!item.PROTECT_STATUS.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "个体防护情况！");
                                }
                                if (!item.MONITOR_RESULT_LOW.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "最低测定结果！");
                                }
                                if (!item.MONITOR_RESULT_HIGH.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "最高测定结果！");
                                }
                                if (item.MONITOR_RESULT_LOW.HasValue && item.MONITOR_RESULT_HIGH.HasValue && item.MONITOR_RESULT_LOW.Value > item.MONITOR_RESULT_HIGH.Value)
                                {
                                    throw new Exception("行" + i + "最低测定结果不能大于最高测定结果！");
                                }

                                rule = listRule.FirstOrDefault(e => e.ID == item.RULE_ID);
                                //最高值 大于  噪声阈值 超限
                                item.OVER_LIMIT = (item.MONITOR_RESULT_HIGH.Value > rule.THRESHOLD_NOISE || item.MONITOR_RESULT_LOW.Value > rule.THRESHOLD_NOISE) ? YesNoEnum.Yes : YesNoEnum.No;

                                if (item.OVER_LIMIT.Value == YesNoEnum.Yes)
                                {
                                    IListUser = GetEntities<T_FM_USER>(e => e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == rule.DEPARTMENT_ID_WARN && e.Nav_Person.POST_ID == rule.WARN_POST_ID, null, "Nav_Person");
                                    //if (rule.Nav_WarnPost.Nav_Users == null || !rule.Nav_WarnPost.Nav_Users.Any())
                                    if (IListUser == null || !IListUser.Any())
                                    {
                                        throw new Exception("未找到警示推送人");
                                    }
                                    else
                                    {
                                        Warm = rule.Nav_DepartmentWorkshop.NAME + rule.LOCATION + rule.Nav_Type.NAME + "（" + rule.Nav_Type.SMALL_TYPE + "）" + "超限";
                                        foreach (var itemU in IListUser)
                                        {
                                            T_FM_NOTIFICATION_TASK taskWarm = NotificationTaskService.InsertUserNoticeTaskModel(Warm, Guid.Empty, itemU.ORG_ID, itemU.ID, itemU.NAME, DateTime.Now, dtWarmEnd, (int)FMNoticeTypeEnum.今日提醒, "");
                                            listTask.Add(taskWarm);
                                        }
                                    }

                                    //3、是否超限为是时，推送今日提醒给警示推送人；消息类型：其他；消息内容：“监测车间”＋“监测地点”噪声超限。
                                    //int j = 0;
                                    //foreach (var itemU in rule.Nav_WarnPost.Nav_Users)
                                    //{
                                    //    j++;
                                    //    if (rule.DEPARTMENT_ID == itemU.Nav_User.DEPARTMENT_ID)
                                    //    {
                                    //        T_FM_NOTIFICATION_TASK taskWarm = NotificationTaskService.InsertUserNoticeTaskModel(rule.Nav_DepartmentWorkshop.NAME + rule.LOCATION + rule.Nav_Type.NAME + "（" + rule.Nav_Type.SMALL_TYPE + "）" + "超限", Guid.Empty, itemU.ORG_ID, itemU.USER_ID, itemU.Nav_User.NAME, DateTime.Now, DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.今日提醒, "");
                                    //        listTask.Add(taskWarm);
                                    //        break;
                                    //    }
                                    //    else if (j == rule.Nav_WarnPost.Nav_Users.Count)
                                    //    {
                                    //        throw new Exception("未找到警示推送人");
                                    //    }
                                    //}
                                }
                                //if (item.PROTECT_STATUS.Value == OHHazardMonitorJobProtectEnum.WearPart)
                                //    //2、个体防护情况填写结果为缺少，触发今日提醒给部门安全员；消息类型：其他；消息内容：请进行劳动防护用品需求评估。
                                //穿戴  缺少 时 给 安全员 发送待办
                                SafeWarm(item, rule, listTaskWear, TaskWearCheck);
                            }
                            i++;

                            #endregion
                            break;
                        case OHHazardMonitorFormTypeEnum.RadiationMonitoring:
                            #region  放射性
                            foreach (var item in Detail)
                            {
                                if (!item.MONITOR_RESULT_05.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "0.5m处监测值！");
                                }
                                if (!item.MONITOR_RESULT_10.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "1m处监测值！");
                                }
                                if (!item.MONITOR_RESULT_AROUND.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "周围环境值！");
                                }

                                rule = listRule.FirstOrDefault(e => e.ID == item.RULE_ID);
                                //最高值 大于  噪声阈值 超限
                                item.OVER_LIMIT = (item.MONITOR_RESULT_05.Value > rule.THRESHOLD_RADIATION_05 || item.MONITOR_RESULT_10.Value > rule.THRESHOLD_RADIATION_10 || item.MONITOR_RESULT_AROUND.Value > rule.THRESHOLD_RADIATION_AROUND) ? YesNoEnum.Yes : YesNoEnum.No;
                                if (item.OVER_LIMIT.Value == YesNoEnum.Yes)
                                {
                                    IListUser = GetEntities<T_FM_USER>(e => e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == rule.DEPARTMENT_ID_WARN && e.Nav_Person.POST_ID == rule.WARN_POST_ID, null, "Nav_Person");
                                    if (IListUser == null || !IListUser.Any())
                                    {
                                        throw new Exception("未找到警示推送人");
                                    }
                                    else
                                    {
                                        Warm = rule.Nav_DepartmentWorkshop.NAME + rule.LOCATION + rule.Nav_Type.NAME + "（" + rule.Nav_Type.SMALL_TYPE + "）" + "超限";
                                        foreach (var itemU in IListUser)
                                        {
                                            T_FM_NOTIFICATION_TASK taskWarm = NotificationTaskService.InsertUserNoticeTaskModel(Warm, Guid.Empty, itemU.ORG_ID, itemU.ID, itemU.NAME, DateTime.Now, dtWarmEnd, (int)FMNoticeTypeEnum.今日提醒, "");
                                            listTask.Add(taskWarm);
                                        }
                                    }

                                    ////3、是否超限为是时，推送今日提醒给警示推送人；消息类型：其他；消息内容：“监测车间”＋“监测地点”＋“类别”超限 
                                    //int j = 0;
                                    //foreach (var itemU in rule.Nav_WarnPost.Nav_Users)
                                    //{
                                    //    j++;
                                    //    if (rule.DEPARTMENT_ID == itemU.Nav_User.DEPARTMENT_ID)
                                    //    {
                                    //        T_FM_NOTIFICATION_TASK taskWarm = NotificationTaskService.InsertUserNoticeTaskModel(rule.Nav_DepartmentWorkshop.NAME + rule.LOCATION + rule.Nav_Type.NAME + "（" + rule.Nav_Type.SMALL_TYPE + "）" + "超限", Guid.Empty, itemU.ORG_ID, itemU.USER_ID, itemU.Nav_User.NAME, DateTime.Now, DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.今日提醒, "");
                                    //        listTask.Add(taskWarm);
                                    //        break;
                                    //    }
                                    //    else if (j == rule.Nav_WarnPost.Nav_Users.Count)
                                    //    {
                                    //        throw new Exception("未找到警示推送人");
                                    //    }
                                    //}
                                }
                            }
                            i++;

                            #endregion
                            break;
                        case OHHazardMonitorFormTypeEnum.WaterMonitoring:

                            #region   水质监测

                            foreach (var item in Detail)
                            {
                                if (string.IsNullOrEmpty(item.SAMPLE_SOURCE))
                                {
                                    throw new Exception("请填写，行" + i + "水来源！");
                                }
                                if (!item.SAMPLE_TIME.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "取样时间！");
                                }
                                if (!item.TEST_TIME.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "化验时间！");
                                }
                                if (!item.MONITOR_RESULT.HasValue)
                                {
                                    throw new Exception("请填写，行" + i + "监测数据！");
                                }
                                if (string.IsNullOrEmpty(item.TEST_DEPARTMENT))
                                {
                                    throw new Exception("请填写，行" + i + "化验部门！");
                                }
                                if (string.IsNullOrEmpty(item.TESTER))
                                {
                                    throw new Exception("请填写，行" + i + "化验人！");
                                }

                                rule = listRule.FirstOrDefault(e => e.ID == item.RULE_ID);
                                //监测数据 小于最低值 或者 大于最高值 超限
                                item.OVER_LIMIT = (item.MONITOR_RESULT.Value < rule.THRESHOLD_WARTER_LOW || item.MONITOR_RESULT.Value > rule.THRESHOLD_WARTER_HIGH) ? YesNoEnum.Yes : YesNoEnum.No;
                                if (item.OVER_LIMIT.Value == YesNoEnum.Yes)
                                {
                                    IListUser = GetEntities<T_FM_USER>(e => e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == rule.DEPARTMENT_ID_WARN && e.Nav_Person.POST_ID == rule.WARN_POST_ID, null, "Nav_Person");
                                    if (IListUser == null || !IListUser.Any())
                                    {
                                        throw new Exception("未找到警示推送人");
                                    }
                                    else
                                    {
                                        Warm = rule.Nav_DepartmentWorkshop.NAME + rule.LOCATION + rule.Nav_Type.NAME + "（" + rule.Nav_Type.SMALL_TYPE + "）" + "超限";
                                        foreach (var itemU in IListUser)
                                        {
                                            T_FM_NOTIFICATION_TASK taskWarm = NotificationTaskService.InsertUserNoticeTaskModel(Warm, Guid.Empty, itemU.ORG_ID, itemU.ID, itemU.NAME, DateTime.Now, dtWarmEnd, (int)FMNoticeTypeEnum.今日提醒, "");
                                            listTask.Add(taskWarm);
                                        }
                                    }

                                    //2、是否超限为是时，推送今日提醒给警示推送人；消息类型：其他；消息内容：“取样车间”＋“取样地点”＋水质超限
                                    //int j = 0;
                                    //foreach (var itemU in rule.Nav_WarnPost.Nav_Users)
                                    //{
                                    //    j++;
                                    //    if (rule.DEPARTMENT_ID == itemU.Nav_User.DEPARTMENT_ID)
                                    //    {
                                    //        T_FM_NOTIFICATION_TASK taskWarm = NotificationTaskService.InsertUserNoticeTaskModel(rule.Nav_DepartmentWorkshop.NAME + rule.LOCATION + rule.Nav_Type.NAME + "（" + rule.Nav_Type.SMALL_TYPE + "）" + "超限", Guid.Empty, itemU.ORG_ID, itemU.USER_ID, itemU.Nav_User.NAME, DateTime.Now, DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.今日提醒, "");
                                    //        listTask.Add(taskWarm);
                                    //        break;
                                    //    }
                                    //    else if (j == rule.Nav_WarnPost.Nav_Users.Count)
                                    //    {
                                    //        throw new Exception("未找到警示推送人");
                                    //    }
                                    //}
                                }
                            }
                            i++;
                            #endregion
                            break;
                        default:
                            break;
                    }
                }

                #endregion


                this.UnifiedCommit(() =>
                {
                    if (entity != null)
                        UpdateEntityNoCommit(entity);
                    if (Detail != null && Detail.Any())
                        BantchSaveEntityNoCommit(Detail);
                    if (listTask != null && listTask.Any())//超标 提醒 
                        BantchSaveEntityNoCommit(listTask);
                    if (listTaskWear != null && listTaskWear.Any())//缺少穿戴 提醒安全员 
                        BantchSaveEntityNoCommit(listTaskWear);
                    if (task != null)//待办
                        UpdateEntityNoCommit(task);
                    if (listTaskNoDo != null && listTaskNoDo.Any())//待办
                        BantchSaveEntityNoCommit(listTaskNoDo);

                });

                return true;
            });
        }


        /// <summary>
        /// 给责任部门 安全员 发送
        /// </summary>
        /// <param name="item"></param>
        /// <param name="listTaskWear"></param>
        /// <param name="TaskWearCheck"></param>
        /// <exception cref="Exception"></exception>
        public void SafeWarm(T_OH_HAZARD_MONITOR_JOB_DETAIL item, T_OH_HAZARD_MONITOR_RULE rule, List<T_FM_NOTIFICATION_TASK> listTaskWear, T_FM_NOTIFICATION_TASK TaskWearCheck)
        {
            if (item.PROTECT_STATUS.Value == OHHazardMonitorJobProtectEnum.WearPart)
            {
                //2、个体防护情况填写结果为缺少，触发今日提醒给部门安全员；消息类型：其他；消息内容：请进行劳动防护用品需求评估。
                string Msg = string.Empty;
                T_FM_USER userSafe = UserService.GetRoleUser(ref Msg, "安全员", rule.DEPARTMENT_ID, 0);
                if (userSafe == null)
                {
                    if (!string.IsNullOrEmpty(Msg))
                    {
                        throw new Exception(Msg);
                    }
                    else
                    {
                        throw new Exception("未找到责任部门的安全员");
                    }
                }
                //listTaskWear 
                TaskWearCheck = listTaskWear.FirstOrDefault(e => e.USER_ID == userSafe.ID);
                if (TaskWearCheck == null)
                {
                    //添加安全员 今日提醒
                    //2、个体防护情况填写结果为缺少，触发今日提醒给部门安全员；消息类型：其他；消息内容：请进行劳动防护用品需求评估。
                    TaskWearCheck = NotificationTaskService.InsertUserNoticeTaskModel("请进行劳动防护用品需求评估", Guid.Empty, item.ORG_ID, userSafe.ID, userSafe.NAME, DateTime.Now, (int)FMNoticeTypeEnum.今日提醒, "", BaseData.Domain.Enums.FMTASKTYPE.OH_MonitorJob_NotWear);
                    listTaskWear.Add(TaskWearCheck);
                }
            }
        }
    }
}