869 lines
		
	
	
		
			46 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			869 lines
		
	
	
		
			46 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
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.HM;
 | 
						||
using APT.MS.Domain.Entities.OH;
 | 
						||
using APT.MS.Domain.Entities.PF;
 | 
						||
using APT.MS.Domain.Entities.SC;
 | 
						||
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/OHHealthExamNotice")]
 | 
						||
    public class OHHealthExamNoticeController : AuthorizeApiController<T_OH_HEALTH_EXAM_NOTICE>
 | 
						||
    {
 | 
						||
        IFMFlowPermitService MFlowPermitService { get; set; }
 | 
						||
        IPFApproveCallBackService ApproveCallBackService { get; set; }
 | 
						||
        IAEAccidentEventReportService AccidentEventReportService { get; set; }
 | 
						||
        IFMNotificationTaskService NotificationTaskService { get; set; }
 | 
						||
        IFMUserService UserService { get; set; }
 | 
						||
        IFMDepartmentService DepartmentService { get; set; }
 | 
						||
        public OHHealthExamNoticeController(IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService, IAEAccidentEventReportService accidentEventReportService, IFMNotificationTaskService notificationTaskService, IFMUserService userService, IFMDepartmentService departmentService)
 | 
						||
        {
 | 
						||
            MFlowPermitService = mFlowPermitService;
 | 
						||
            ApproveCallBackService = approveCallBackService;
 | 
						||
            AccidentEventReportService = accidentEventReportService;
 | 
						||
            NotificationTaskService = notificationTaskService;
 | 
						||
            UserService = userService;
 | 
						||
            DepartmentService = departmentService;
 | 
						||
        }
 | 
						||
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 排序分页查询数据 体检批次(Time)
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="pageFilter">分页过滤实体</param>
 | 
						||
        /// <returns></returns>
 | 
						||
        [HttpPost, Route("OrderPagedBanch")]
 | 
						||
        public PagedActionResult<T_OH_HEALTH_EXAM_BATCH> OrderPagedBanch([FromBody] KeywordPageFilter pageFilter)
 | 
						||
        {
 | 
						||
            return SafeGetPagedData(delegate (PagedActionResult<T_OH_HEALTH_EXAM_BATCH> result)
 | 
						||
            {
 | 
						||
                DateTime dtNow = DateTime.Now.Date;
 | 
						||
                pageFilter.Sort = "BATCH";
 | 
						||
                //Guid? PLAN_ID_DEP = null;
 | 
						||
                if (pageFilter.FilterGroup.Rules.Count > 0)
 | 
						||
                {
 | 
						||
                    foreach (var item in pageFilter.FilterGroup.Rules)
 | 
						||
                    {
 | 
						||
                        //体检通知表 选择 体检批次
 | 
						||
                        if (item.Field == "DateAdd")
 | 
						||
                        {
 | 
						||
                            dtNow = dtNow.AddDays(int.Parse(item.Value.ToString()));
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
                    pageFilter.FilterGroup.Rules.Clear();
 | 
						||
                }
 | 
						||
 | 
						||
                //不做组织筛选
 | 
						||
                PagedActionResult<T_OH_HEALTH_EXAM_BATCH> orderPageEntities = GetOrderPageEntities<T_OH_HEALTH_EXAM_BATCH>(e => e.END_TIME > dtNow, pageFilter, null);//e.START_TIME >= dtNow
 | 
						||
                //var dateDep = orderPageEntities.Data.Where(e=>e.DEPARTMENT_ID);
 | 
						||
                result.Data = orderPageEntities.Data;
 | 
						||
                foreach (var item in result.Data)
 | 
						||
                {
 | 
						||
                    if (item.START_TIME != DateTime.MinValue && item.END_TIME != DateTime.MinValue)
 | 
						||
                    {
 | 
						||
                        //item.TIME = item.START_TIME.ToString("yyyy-MM-dd") + " ~ " + item.END_TIME.ToString("MM-dd"); //HH: mm
 | 
						||
                        item.TIME = GetTimeShow(item.START_TIME, item.END_TIME);
 | 
						||
                    }
 | 
						||
                }
 | 
						||
                result.TotalCount = orderPageEntities.TotalCount;
 | 
						||
            });
 | 
						||
        }
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 显示时间
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="START_TIME"></param>
 | 
						||
        /// <param name="END_TIME"></param>
 | 
						||
        /// <returns></returns>
 | 
						||
        private string GetTimeShow(DateTime? START_TIME, DateTime? END_TIME)
 | 
						||
        {
 | 
						||
            if (!START_TIME.HasValue || !END_TIME.HasValue || START_TIME == DateTime.MinValue)
 | 
						||
            {
 | 
						||
                return "";
 | 
						||
            }
 | 
						||
            else if (START_TIME.Value.Date == END_TIME.Value.Date)
 | 
						||
            {
 | 
						||
                return START_TIME.Value.ToString("MM-dd HH:mm") + " ~ " + END_TIME.Value.ToString("HH:mm");
 | 
						||
            }
 | 
						||
            else
 | 
						||
            {
 | 
						||
                return START_TIME.Value.ToString("MM-dd") + " ~ " + END_TIME.Value.ToString("MM-dd");
 | 
						||
            }
 | 
						||
        }
 | 
						||
        /// <summary>
 | 
						||
        /// 获得单条实体数据
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="filter">过滤实体</param>
 | 
						||
        /// <returns></returns>
 | 
						||
        [HttpPost, Route("GetNotice")]
 | 
						||
        public JsonActionResult<T_OH_HEALTH_EXAM_NOTICE> GetNotice([FromBody] KeywordFilter filter)
 | 
						||
        {
 | 
						||
            //return WitEntity(null, filter);
 | 
						||
            return SafeExecute(() =>
 | 
						||
            {
 | 
						||
                T_OH_HEALTH_EXAM_NOTICE Notice = null;
 | 
						||
                Guid NoticeID = Guid.Empty;
 | 
						||
                if (filter.FilterGroup.Rules.Count > 0)
 | 
						||
                {
 | 
						||
                    foreach (var item in filter.FilterGroup.Rules)
 | 
						||
                    {
 | 
						||
                        if (item.Field == "ID")
 | 
						||
                        {
 | 
						||
                            NoticeID = new Guid(item.Value.ToString());
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
                    filter.FilterGroup.Rules.Clear();
 | 
						||
                }
 | 
						||
                if (NoticeID != Guid.Empty)
 | 
						||
                {
 | 
						||
                    Notice = GetEntity<T_OH_HEALTH_EXAM_NOTICE>(e => e.ID == NoticeID, filter, new string[] { "Nav_Files.Nav_ImgFile" });
 | 
						||
                    Notice.Nav_ListNoticeRegister = GetEntities<T_OH_HEALTH_EXAM_NOTICE_REGISTER>(e => e.NOTICE_ID == NoticeID && !e.IS_DELETED, null, new string[] { "Nav_Department", "Nav_User.Nav_Person.Nav_Post", "Nav_ExamBatch", "Nav_ListOccHazard.Nav_Hazard" }).ToList();
 | 
						||
 | 
						||
                    //if (Notice.Nav_ListNoticeRegister != null && Notice.Nav_ListNoticeRegister.Any())
 | 
						||
                    //{
 | 
						||
                    //    foreach (var item in Notice.Nav_ListNoticeRegister)
 | 
						||
                    //    {
 | 
						||
                    //        if (item.EXAM_BATCH_ID.HasValue)
 | 
						||
                    //        {
 | 
						||
                    //            //体检时间
 | 
						||
                    //            item.Nav_ExamBatch.TIME = item.Nav_ExamBatch.START_TIME.ToString("yyyy-MM-dd") + " ~ " + item.Nav_ExamBatch.END_TIME.ToString("MM-dd");
 | 
						||
                    //        }
 | 
						||
                    //    }
 | 
						||
                    //}
 | 
						||
 | 
						||
                    var batch = Notice.Nav_ListNoticeRegister.Where(e => e.EXAM_BATCH_ID.HasValue && e.Nav_ExamBatch.USER_ID.HasValue).Select(e => e.Nav_ExamBatch.USER_ID);
 | 
						||
                    if (batch != null && batch.Any())
 | 
						||
                    {
 | 
						||
                        var listUser = GetEntities<T_FM_USER>(e => batch.Contains(e.ID), null, null);
 | 
						||
                        foreach (var item in Notice.Nav_ListNoticeRegister)
 | 
						||
                        {
 | 
						||
                            if (item.EXAM_BATCH_ID.HasValue)
 | 
						||
                            {
 | 
						||
                                item.Nav_ExamBatch.Nav_User = listUser.FirstOrDefault(e => e.ID == item.Nav_ExamBatch.USER_ID);
 | 
						||
                            }
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
                    else
 | 
						||
                    {
 | 
						||
                        //根据部门 自动匹配
 | 
						||
                        List<T_OH_HEALTH_EXAM_BATCH> listBatchSuit = GetEntities<T_OH_HEALTH_EXAM_BATCH>(e => e.START_TIME >= DateTime.Now.Date && e.Nav_ListDepartment != null, null, new string[] { "Nav_User", "Nav_ListDepartment" }).OrderBy(e => e.START_TIME).ToList();
 | 
						||
                        List<T_OH_HEALTH_EXAM_BATCH_DEPARTMENT> listBatchDep = new List<T_OH_HEALTH_EXAM_BATCH_DEPARTMENT>();
 | 
						||
                        for (int i = listBatchSuit.Count - 1; i > -1; i--)
 | 
						||
                        {
 | 
						||
                            if (listBatchSuit[i].Nav_ListDepartment == null || !listBatchSuit[i].Nav_ListDepartment.Any())
 | 
						||
                            {
 | 
						||
                                listBatchSuit.RemoveAt(i);
 | 
						||
                                continue;
 | 
						||
                            }
 | 
						||
                            listBatchDep.AddRange(listBatchSuit[i].Nav_ListDepartment.ToList());
 | 
						||
                        }
 | 
						||
                        T_OH_HEALTH_EXAM_BATCH batchCheck = null;
 | 
						||
                        foreach (var item in Notice.Nav_ListNoticeRegister)
 | 
						||
                        {
 | 
						||
                            //TODO   体检人所在部门 0512 修改一对多
 | 
						||
                            //if (item.DEPARTMENT_ID_WORKSHOP.HasValue)
 | 
						||
                            //{
 | 
						||
                            //    batchCheck = listBatchSuit.FirstOrDefault(e => e.DEPARTMENT_ID == item.DEPARTMENT_ID_WORKSHOP);
 | 
						||
                            //}
 | 
						||
                            //else if (item.DEPARTMENT_ID.HasValue)
 | 
						||
                            //{
 | 
						||
                            //    batchCheck = listBatchSuit.FirstOrDefault(e => e.DEPARTMENT_ID == item.DEPARTMENT_ID);
 | 
						||
                            //}
 | 
						||
                            batchCheck = listBatchDep.FirstOrDefault(e => e.DEPARTMENT_ID == item.DEPARTMENT_ID)?.Nav_Batch;
 | 
						||
                            if (batchCheck != null)
 | 
						||
                            {
 | 
						||
                                item.EXAM_BATCH_ID = batchCheck.ID;
 | 
						||
                                item.Nav_ExamBatch = batchCheck;
 | 
						||
                                //item.THISDATE = batchCheck.START_TIME;
 | 
						||
                            }
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
                    if (Notice.Nav_ListNoticeRegister != null && Notice.Nav_ListNoticeRegister.Any())
 | 
						||
                    {
 | 
						||
                        foreach (var item in Notice.Nav_ListNoticeRegister)
 | 
						||
                        {
 | 
						||
                            if (item.EXAM_BATCH_ID.HasValue)
 | 
						||
                            {
 | 
						||
                                //体检时间
 | 
						||
                                //if (item.Nav_ExamBatch.START_TIME.Date == item.Nav_ExamBatch.END_TIME.Date)
 | 
						||
                                //{
 | 
						||
                                //    item.Nav_ExamBatch.TIME = item.Nav_ExamBatch.START_TIME.ToString("MM-dd HH:mm") + " ~ " + item.Nav_ExamBatch.END_TIME.ToString("HH:mm");
 | 
						||
                                //}
 | 
						||
                                //else
 | 
						||
                                //{
 | 
						||
                                //    item.Nav_ExamBatch.TIME = item.Nav_ExamBatch.START_TIME.ToString("MM-dd") + " ~ " + item.Nav_ExamBatch.END_TIME.ToString("MM-dd");
 | 
						||
                                //}
 | 
						||
                                item.Nav_ExamBatch.TIME = GetTimeShow(item.Nav_ExamBatch.START_TIME, item.Nav_ExamBatch.END_TIME);
 | 
						||
                            }
 | 
						||
                            item.Nav_ListOccHazard = item.Nav_ListOccHazard.OrderBy(e => e.HAZARD_ID).ToList();
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
                    //Notice.Nav_ListNoticeRegister = Notice.Nav_ListNoticeRegister.OrderBy(e => e.DEPARTMENT_ID_WORKSHOP).ThenByDescending(e => e.Nav_User.APPROVE_ROLE_ID).ThenBy(e => e.Nav_User.NAME).ToList();
 | 
						||
                    Notice.Nav_ListNoticeRegister = Notice.Nav_ListNoticeRegister.OrderBy(e => e.DEPARTMENT_ID).ThenBy(e => e.Nav_User.NAME).ToList();
 | 
						||
                }
 | 
						||
                return Notice;
 | 
						||
            });
 | 
						||
        }
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 体检通知 修改
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="entity"></param>
 | 
						||
        /// <returns></returns>
 | 
						||
        [HttpPost, Route("FullUpdate")]
 | 
						||
        public JsonActionResult<bool> FullUpdate([FromBody] T_OH_HEALTH_EXAM_NOTICE entity)
 | 
						||
        {
 | 
						||
            return SafeExecute<bool>(() =>
 | 
						||
            {
 | 
						||
                //保存并发送的时候  给各个带队人 发送 带队通知
 | 
						||
                if (string.IsNullOrEmpty(entity.NAME))
 | 
						||
                {
 | 
						||
                    throw new Exception("请填写体检计划名称");
 | 
						||
                }
 | 
						||
 | 
						||
                var listNoticeRegister = entity.Nav_ListNoticeRegister;
 | 
						||
                entity.Nav_ListNoticeRegister = null;
 | 
						||
                var Files = entity.Nav_Files;
 | 
						||
                entity.Nav_Files = null;
 | 
						||
 | 
						||
                if (listNoticeRegister == null || !listNoticeRegister.Any())
 | 
						||
                {
 | 
						||
                    throw new Exception("未获取到体检人员!");
 | 
						||
                }
 | 
						||
                List<T_OH_EXAM_NOTICE_OCC_HAZARD> listHaz = new List<T_OH_EXAM_NOTICE_OCC_HAZARD>();
 | 
						||
                foreach (var item in listNoticeRegister)
 | 
						||
                {
 | 
						||
                    if (item.Nav_ListOccHazard != null && item.Nav_ListOccHazard.Any())
 | 
						||
                    {
 | 
						||
                        listHaz.AddRange(item.Nav_ListOccHazard);
 | 
						||
                        item.Nav_ListOccHazard = null;
 | 
						||
                    }
 | 
						||
                }
 | 
						||
                //if (entity.STATUS == PFStandardStatus.Sign)
 | 
						||
                //{
 | 
						||
                //    var listNotMatchBatch = listNoticeRegister.Where(e => !e.EXAM_BATCH_ID.HasValue);
 | 
						||
                //    if (listNotMatchBatch != null && listNotMatchBatch.Any())
 | 
						||
                //    {
 | 
						||
                //        List<Guid> listUserID = listNotMatchBatch.Where(e => !e.EXAM_BATCH_ID.HasValue).Select(e => e.USER_ID.Value).ToList();
 | 
						||
                //        List<string> listName = GetEntities<T_FM_USER>(e => listUserID.Contains(e.ID), null, null).Select(e => e.NAME).ToList();
 | 
						||
                //        throw new Exception("请完善体检批次:" + string.Join(",", listName) + "!");
 | 
						||
                //    }
 | 
						||
                //}
 | 
						||
 | 
						||
                if (entity.STATUS == PFStandardStatus.Draft)
 | 
						||
                {
 | 
						||
                    //草稿
 | 
						||
                    this.UnifiedCommit(() =>
 | 
						||
                    {
 | 
						||
                        if (entity != null)
 | 
						||
                            UpdateEntityNoCommit(entity);   //事故事件上报
 | 
						||
                        if (Files != null && Files.Any())//附件
 | 
						||
                            BantchSaveEntityNoCommit(Files);
 | 
						||
                        if (listNoticeRegister != null && listNoticeRegister.Any())//体检人
 | 
						||
                            BantchSaveEntityNoCommit(listNoticeRegister);
 | 
						||
                        if (listHaz != null && listHaz.Any())
 | 
						||
                            BantchSaveEntityNoCommit(listHaz);
 | 
						||
                    });
 | 
						||
                }
 | 
						||
                else
 | 
						||
                {
 | 
						||
                    List<int> listIndex = new List<int>();
 | 
						||
                    int rowIndex = 1;
 | 
						||
                    foreach (var item in listNoticeRegister)
 | 
						||
                    {
 | 
						||
                        if (!item.EXAM_BATCH_ID.HasValue)
 | 
						||
                        {
 | 
						||
                            listIndex.Add(rowIndex);
 | 
						||
                        }
 | 
						||
                        rowIndex++;
 | 
						||
                    }
 | 
						||
                    if (listIndex.Count > 0)
 | 
						||
                    {
 | 
						||
                        throw new Exception("体检批次不能为空:行" + String.Join(",", listIndex) + "!");
 | 
						||
                    }
 | 
						||
 | 
						||
                    //原来 的一个 通知 变成 按体检批次变成多个通知
 | 
						||
                    List<T_OH_HEALTH_EXAM_NOTICE> listNotice = new List<T_OH_HEALTH_EXAM_NOTICE>();//通知 插入 更新
 | 
						||
                    List<T_OH_HEALTH_EXAM_NOTICE_FILE> listNoticeFile = new List<T_OH_HEALTH_EXAM_NOTICE_FILE>();//通知文件插入 更新
 | 
						||
 | 
						||
                    Dictionary<Guid, T_OH_HEALTH_EXAM_NOTICE> dicBatchIDModelNotice = new Dictionary<Guid, T_OH_HEALTH_EXAM_NOTICE>();//体检批次 - 体检通知
 | 
						||
                    //T_OH_HEALTH_EXAM_BATCH
 | 
						||
 | 
						||
                    List<Guid> listBatchID = listNoticeRegister.Select(e => e.EXAM_BATCH_ID.Value).Distinct().ToList();
 | 
						||
                    List<T_OH_HEALTH_EXAM_BATCH> listBatch = GetEntities<T_OH_HEALTH_EXAM_BATCH>(e => listBatchID.Contains(e.ID), null, new string[] { "Nav_User" }).ToList();
 | 
						||
                    DateTime dtEnd = DateTime.Now;//本次体检 最迟结束时间 (用于发送通知给人事专员录入体检结果)
 | 
						||
                    foreach (var item in listBatch)
 | 
						||
                    {
 | 
						||
                        if (item.END_TIME > dtEnd)
 | 
						||
                        {
 | 
						||
                            dtEnd = item.END_TIME;
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
 | 
						||
                    entity.EXAM_BATCH_ID = listBatchID[0];
 | 
						||
                    entity.NOTICEIMPORTSTATE = NoticeImportState.Draft;
 | 
						||
                    entity.END_TIME = dtEnd;
 | 
						||
                    dicBatchIDModelNotice.Add(listBatchID[0], entity);
 | 
						||
 | 
						||
                    DateTime dtNow = DateTime.Now;
 | 
						||
                    entity.PARENTID = entity.ID;
 | 
						||
                    for (int i = 1; i < listBatchID.Count; i++)
 | 
						||
                    {
 | 
						||
                        T_OH_HEALTH_EXAM_NOTICE notice = new T_OH_HEALTH_EXAM_NOTICE();
 | 
						||
                        notice.PARENTID = entity.ID;
 | 
						||
                        notice.ID = Guid.NewGuid();
 | 
						||
                        notice.CODE = entity.CODE + i;
 | 
						||
                        notice.NAME = entity.NAME;
 | 
						||
                        notice.OTHER_STUFF = entity.OTHER_STUFF;
 | 
						||
                        notice.STATUS = entity.STATUS;
 | 
						||
                        //notice.APPROVE_ID =;
 | 
						||
                        notice.IS_DELETED = false;
 | 
						||
                        notice.ORG_ID = entity.ORG_ID;
 | 
						||
                        //notice.ENTITY_ORG_TPYE =;
 | 
						||
                        //notice.FORM_ID =;
 | 
						||
                        //notice.FLOW_STATUS =;
 | 
						||
                        //notice.FLOW_SEND_STATUS =;
 | 
						||
                        //notice.FLOW_ID =;
 | 
						||
                        //notice.CREATE_TIME =;
 | 
						||
                        //notice.MODIFY_TIME =;
 | 
						||
                        //notice.CREATER_ID =;
 | 
						||
                        //notice.MODIFIER_ID =;
 | 
						||
 | 
						||
                        if (Files != null && Files.Any())
 | 
						||
                        {
 | 
						||
                            foreach (var item in Files)
 | 
						||
                            {
 | 
						||
                                T_OH_HEALTH_EXAM_NOTICE_FILE noticeFile = new T_OH_HEALTH_EXAM_NOTICE_FILE();
 | 
						||
                                noticeFile.ID = Guid.NewGuid();
 | 
						||
                                noticeFile.NOTICE_ID = notice.ID;
 | 
						||
                                noticeFile.IMG_FILE_ID = item.IMG_FILE_ID;
 | 
						||
                                noticeFile.ORG_ID = item.ORG_ID;
 | 
						||
                                noticeFile.IS_DELETED = item.IS_DELETED;
 | 
						||
                                listNoticeFile.Add(noticeFile);//通知文件
 | 
						||
                            }
 | 
						||
                        }
 | 
						||
 | 
						||
                        listNotice.Add(notice);//通知
 | 
						||
 | 
						||
                        notice.EXAM_BATCH_ID = listBatchID[i];
 | 
						||
                        notice.NOTICEIMPORTSTATE = NoticeImportState.Draft;
 | 
						||
                        notice.END_TIME = dtEnd;
 | 
						||
                        dicBatchIDModelNotice.Add(listBatchID[i], notice);
 | 
						||
                    }
 | 
						||
 | 
						||
                    //带队人(每个批次一个通知)
 | 
						||
                    List<string> listTitle = new List<string>();
 | 
						||
                    List<Guid> listUserID = new List<Guid>();
 | 
						||
                    List<string> listUserName = new List<string>();
 | 
						||
                    List<Guid> DataId = new List<Guid>();
 | 
						||
                    foreach (var item in dicBatchIDModelNotice)
 | 
						||
                    {
 | 
						||
                        listTitle.Add("体检通知-带队");//通知标题
 | 
						||
                        listUserID.Add(listBatch.Find(e => e.ID == item.Key).USER_ID.Value);
 | 
						||
                        listUserName.Add(listBatch.Find(e => e.ID == item.Key).Nav_User.NAME);//带队人
 | 
						||
                        DataId.Add(item.Value.ID);//体检通知ID
 | 
						||
                    }
 | 
						||
 | 
						||
                    //通知人
 | 
						||
                    List<string> listRegTitle = new List<string>();
 | 
						||
                    List<Guid> listRegUserID = new List<Guid>();
 | 
						||
                    List<string> listRegUserName = new List<string>();
 | 
						||
 | 
						||
                    List<T_FM_NOTIFICATION_TASK> listTask = new List<T_FM_NOTIFICATION_TASK>();
 | 
						||
                    T_OH_HEALTH_EXAM_BATCH examBatch = null;
 | 
						||
                    T_FM_USER userNotice = null;
 | 
						||
                    var listUserNoticeID = listNoticeRegister.Select(e => e.USER_ID);
 | 
						||
                    var listUserNotice = GetEntities<T_FM_USER>(e => listUserNoticeID.Contains(e.ID), null, null);
 | 
						||
 | 
						||
 | 
						||
                    //体检周期  //体检批次
 | 
						||
                    DateTime dtNextTime = DateTime.Now;
 | 
						||
 | 
						||
 | 
						||
                    List<T_OH_HEALTH_EXAM_CYCLE> listCycle = null;
 | 
						||
                    T_OH_HEALTH_EXAM_CYCLE cycleTemp = null;
 | 
						||
                    var listCYCLEID = listNoticeRegister.Where(e => e.CYCLE_ID.HasValue).Select(e => e.CYCLE_ID);//体检周期
 | 
						||
                    if (listCYCLEID != null && listCYCLEID.Any())
 | 
						||
                    {
 | 
						||
                        listCycle = GetEntities<T_OH_HEALTH_EXAM_CYCLE>(e => listCYCLEID.Contains(e.ID), null, null).ToList();
 | 
						||
                    }
 | 
						||
 | 
						||
                    foreach (var item in listNoticeRegister)
 | 
						||
                    {
 | 
						||
                        userNotice = listUserNotice.First(e => e.ID == item.USER_ID);
 | 
						||
                        examBatch = listBatch.Find(e => e.ID == item.EXAM_BATCH_ID);
 | 
						||
 | 
						||
                        T_FM_NOTIFICATION_TASK PerTask = NotificationTaskService.InsertUserNoticeTaskModel("请于" + examBatch.START_TIME.ToString("yyyy-MM-dd") + " ~ " + examBatch.END_TIME.ToString("MM-dd") + "参加体检", item.ID, item.ORG_ID, item.USER_ID.Value, userNotice.NAME, dtNow, examBatch.END_TIME, 2, ""); //FMNoticeTypeEnum.今日提醒 2
 | 
						||
                        listTask.Add(PerTask);
 | 
						||
                        //清除导航属性
 | 
						||
 | 
						||
                        //通知赋值
 | 
						||
                        if (dicBatchIDModelNotice.ContainsKey(item.EXAM_BATCH_ID.Value))
 | 
						||
                        {
 | 
						||
                            item.NOTICE_ID = dicBatchIDModelNotice[item.EXAM_BATCH_ID.Value].ID;
 | 
						||
 | 
						||
                            if (!item.NEXTDATE.HasValue && item.CYCLE_ID.HasValue)
 | 
						||
                            {
 | 
						||
                                //下次体检日期= 体检批次 开始时间或当前时间(取大值) + 体检周期的月 
 | 
						||
                                cycleTemp = listCycle.Find(e => e.ID == item.CYCLE_ID.Value);
 | 
						||
                                //item.NEXTDATE = (examBatch.START_TIME > dtNow ? examBatch.START_TIME : dtNow).AddMonths(cycleTemp.HEALTH_EXAM_CYCLE);
 | 
						||
                                item.THISDATE = examBatch.START_TIME > dtNow ? examBatch.START_TIME : dtNow;
 | 
						||
                                item.NEXTDATE = item.THISDATE.Value.AddMonths(cycleTemp.HEALTH_EXAM_CYCLE);
 | 
						||
                            }
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
 | 
						||
                    NotificationTaskService.SendAndFinishNotificationTask(listTitle, DataId, entity.ORG_ID, listUserID, listUserName, DateTime.Now, DateTime.Now.AddDays(1), 0, "OH010_SHOWPRINT", entity.TaskID, () =>
 | 
						||
                    {
 | 
						||
                        if (entity != null)
 | 
						||
                            UpdateEntityNoCommit(entity);   //事故事件上报
 | 
						||
                        if (Files != null && Files.Any())//附件
 | 
						||
                            BantchSaveEntityNoCommit(Files);
 | 
						||
 | 
						||
                        if (listNotice != null && listNotice.Any())//通知
 | 
						||
                            BantchSaveEntityNoCommit(listNotice);
 | 
						||
                        if (listNoticeFile != null && listNoticeFile.Any())//通知附件
 | 
						||
                            BantchSaveEntityNoCommit(listNoticeFile);
 | 
						||
 | 
						||
                        if (listNoticeRegister != null && listNoticeRegister.Any())//体检人
 | 
						||
                            BantchSaveEntityNoCommit(listNoticeRegister);
 | 
						||
                        if (listHaz != null && listHaz.Any())//职业危害
 | 
						||
                            BantchSaveEntityNoCommit(listHaz);
 | 
						||
                        if (listTask != null && listTask.Any())//体检人 今日提醒
 | 
						||
                            BantchSaveEntityNoCommit(listTask);
 | 
						||
 | 
						||
                    }, "OH010_SHOWPRINT");
 | 
						||
                }
 | 
						||
                return true;
 | 
						||
            });
 | 
						||
        }
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 带队人 确认
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="filter"></param>
 | 
						||
        /// <returns></returns>
 | 
						||
        [HttpPost, Route("NoticeSign")]
 | 
						||
        public JsonActionResult<bool> NoticeSign([FromBody] KeywordFilter filter)
 | 
						||
        {
 | 
						||
            return SafeExecute<bool>(() =>
 | 
						||
            {
 | 
						||
                var TaskID = new Guid(filter.Parameter1);
 | 
						||
                if (TaskID == Guid.Empty)
 | 
						||
                {
 | 
						||
                    throw new Exception("获取数据【待办ID】传参失败!");
 | 
						||
                }
 | 
						||
                var task = NotificationTaskService.GetEntityTask(TaskID);
 | 
						||
 | 
						||
                if (task.SOURCE_DATA_ID != new Guid(filter.Keyword))
 | 
						||
                {
 | 
						||
                    throw new Exception("传参有误!");
 | 
						||
                }
 | 
						||
 | 
						||
                var entity = GetEntity<T_OH_HEALTH_EXAM_NOTICE>(task.SOURCE_DATA_ID.Value, null);
 | 
						||
                entity.STATUS = PFStandardStatus.Approving;//带队人确认
 | 
						||
                this.UnifiedCommit(() =>
 | 
						||
                {
 | 
						||
                    if (task != null)//待办
 | 
						||
                        UpdateEntityNoCommit(task);
 | 
						||
                    if (entity != null)//待办
 | 
						||
                        UpdateEntityNoCommit(entity);
 | 
						||
                });
 | 
						||
 | 
						||
                return true;
 | 
						||
            });
 | 
						||
        }
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 体检通知新增选择人(不定期体检)
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="filter"></param>
 | 
						||
        /// <returns></returns>
 | 
						||
        [HttpPost, Route("GetCombinNoticeRegister")]
 | 
						||
        public JsonActionResult<T_OH_HEALTH_EXAM_NOTICE_REGISTER> GetCombinNoticeRegister([FromBody] KeywordFilter filter)
 | 
						||
        {
 | 
						||
            return SafeExecute(() =>
 | 
						||
            {
 | 
						||
                if (string.IsNullOrEmpty(filter.Keyword))
 | 
						||
                {
 | 
						||
                    ThrowError("获取选择人员信息传参失败!");
 | 
						||
                }
 | 
						||
                if (string.IsNullOrEmpty(filter.Parameter1))
 | 
						||
                {
 | 
						||
                    ThrowError("获取体检计划信息传参失败!");
 | 
						||
                }
 | 
						||
                OHHealthExamType? examType = null;
 | 
						||
                Guid NOTICE_ID = new Guid(filter.Parameter1);//页面ID
 | 
						||
                Guid UserID = new Guid(filter.Keyword);//用户ID
 | 
						||
                Guid ID = new Guid(filter.Parameter2);//行ID
 | 
						||
                if (!string.IsNullOrEmpty(filter.Parameter3))
 | 
						||
                {
 | 
						||
                    examType = (OHHealthExamType)(int.Parse(filter.Parameter3));
 | 
						||
                }
 | 
						||
                Guid? DEPARTMENT_ID = null;
 | 
						||
                //Guid? DEPARTMENT_ID_WORKSHOP = null;
 | 
						||
                T_FM_DEPARTMENT Department = null;
 | 
						||
                //T_FM_DEPARTMENT DepartmentWorkshop = null;
 | 
						||
 | 
						||
                var User = GetEntity<T_FM_USER>(UserID, "Nav_Department", "Nav_Person");//
 | 
						||
                                                                                        //部门=0,  车间=1,   班组=2,   公司=3 
 | 
						||
                #region   获取部门信息
 | 
						||
 | 
						||
                DEPARTMENT_ID = User.DEPARTMENT_ID.Value;
 | 
						||
                Department = User.Nav_Department;
 | 
						||
                //if (User.Nav_Department.DEPARTMENT_TYPE == 3)
 | 
						||
                //{
 | 
						||
                //    DEPARTMENT_ID = User.DEPARTMENT_ID.Value;
 | 
						||
                //    Department = User.Nav_Department;
 | 
						||
                //}
 | 
						||
                //else if (User.Nav_Department.DEPARTMENT_TYPE == 2)
 | 
						||
                //{
 | 
						||
                //    DEPARTMENT_ID_WORKSHOP = User.Nav_Department.PARENT_ID.Value;
 | 
						||
                //    DepartmentWorkshop = GetEntity<T_FM_DEPARTMENT>(DEPARTMENT_ID_WORKSHOP.Value, "Nav_Parent");
 | 
						||
 | 
						||
                //    DEPARTMENT_ID = DepartmentWorkshop.PARENT_ID.Value;
 | 
						||
                //    Department = GetEntity<T_FM_DEPARTMENT>(DEPARTMENT_ID.Value);
 | 
						||
 | 
						||
                //}
 | 
						||
                //else if (User.Nav_Department.DEPARTMENT_TYPE == 1)
 | 
						||
                //{
 | 
						||
                //    DEPARTMENT_ID_WORKSHOP = User.DEPARTMENT_ID.Value;
 | 
						||
                //    DEPARTMENT_ID = User.Nav_Department.PARENT_ID.Value;
 | 
						||
 | 
						||
                //    DepartmentWorkshop = User.Nav_Department;
 | 
						||
                //    Department = GetEntity<T_FM_DEPARTMENT>(DEPARTMENT_ID.Value);
 | 
						||
                //}
 | 
						||
                //else if (User.Nav_Department.DEPARTMENT_TYPE == 0)
 | 
						||
                //{
 | 
						||
                //    DEPARTMENT_ID = User.DEPARTMENT_ID.Value;
 | 
						||
                //    Department = User.Nav_Department;
 | 
						||
                //}
 | 
						||
 | 
						||
                #endregion
 | 
						||
 | 
						||
                //根据   这个 责任制岗位  设置的体检周期表 查找 职业危害类型
 | 
						||
 | 
						||
                //User.Nav_Person.POST_ID;
 | 
						||
                //List<T_OH_HEALTH_EAXM_CYCLE_POST_MID> listPostCycle = null;
 | 
						||
                List<T_OH_HEALTH_EXAM_CYCLE_DEPARTMENTINFO_POST> listDepPost = null;
 | 
						||
                if (User.Nav_Person.POST_ID.HasValue)
 | 
						||
                {
 | 
						||
                    listDepPost = GetEntities<T_OH_HEALTH_EXAM_CYCLE_DEPARTMENTINFO_POST>(e => e.POST_ID == User.Nav_Person.POST_ID.Value && e.Nav_DepartmentInfo.DEPARTMENT_ID == User.DEPARTMENT_ID.Value && !e.IS_DELETED && !e.Nav_DepartmentInfo.IS_DELETED, null, "Nav_DepartmentInfo").OrderByDescending(e => e.CREATE_TIME).ToList();
 | 
						||
 | 
						||
 | 
						||
                    //List<T_SC_POST_DEPOST> listDpost = GetEntities<T_SC_POST_DEPOST>(e => e.DEPOST_ID == User.Nav_Person.POST_ID.Value, null, "Nav_Post").ToList();
 | 
						||
                    //if (listDpost != null && listDpost.Any())
 | 
						||
                    //{
 | 
						||
                    //    List<Guid> listPostID = listDpost.Select(e => e.POST_ID).ToList();
 | 
						||
                    //    //TODO
 | 
						||
                    //    //责任制岗位修改 0511
 | 
						||
                    //    //listPostCycle = GetEntities<T_OH_HEALTH_EAXM_CYCLE_POST_MID>(e => listPostID.Contains(e.SC_POST_ID) && e.Nav_Record.DEPARTMENT_ID.HasValue && e.Nav_Record.DEPARTMENT_ID.Value == DEPARTMENT_ID, null, new string[] { "Nav_Record.Nav_ListOccHazard.Nav_Hazard" }).ToList();
 | 
						||
                    //}
 | 
						||
                }
 | 
						||
 | 
						||
                T_OH_HEALTH_EXAM_NOTICE_REGISTER modelCombin = new T_OH_HEALTH_EXAM_NOTICE_REGISTER();
 | 
						||
                modelCombin.ID = ID;
 | 
						||
                modelCombin.NOTICE_ID = NOTICE_ID;
 | 
						||
                modelCombin.USER_ID = UserID;
 | 
						||
                modelCombin.Nav_User = User;
 | 
						||
 | 
						||
                modelCombin.DEPARTMENT_ID = DEPARTMENT_ID;
 | 
						||
                modelCombin.Nav_Department = Department;
 | 
						||
                //modelCombin.Nav_DepartmentWorkshop = DepartmentWorkshop;
 | 
						||
                //modelCombin.DEPARTMENT_ID_WORKSHOP = DEPARTMENT_ID_WORKSHOP;
 | 
						||
                //modelCombin.CYCLE_ID
 | 
						||
                //modelCombin.EXAM_BATCH_ID
 | 
						||
                if (examType.HasValue)
 | 
						||
                {
 | 
						||
                    modelCombin.TYPE = examType.Value;
 | 
						||
                }
 | 
						||
                modelCombin.STATUS = OHHealthExamNoticeRegisterStatus.WaitNotice;
 | 
						||
                modelCombin.IS_DELETED = false;
 | 
						||
                modelCombin.ORG_ID = filter.OrgId;
 | 
						||
 | 
						||
                //自动匹配 体检批次
 | 
						||
 | 
						||
                var listBanchDep = GetEntities<T_OH_HEALTH_EXAM_BATCH_DEPARTMENT>(e => e.DEPARTMENT_ID == DEPARTMENT_ID && !e.IS_DELETED && e.Nav_Batch != null && !e.Nav_Batch.IS_DELETED && e.Nav_Batch.START_TIME > DateTime.Now, null, "Nav_Batch.Nav_User");
 | 
						||
                if (listBanchDep != null && listBanchDep.Any())
 | 
						||
                {
 | 
						||
                    //TODO   体检人所在部门 0512 修改一对多
 | 
						||
                    var banchTemp = listBanchDep.OrderBy(e => e.Nav_Batch.START_TIME).ToList()[0];
 | 
						||
                    modelCombin.EXAM_BATCH_ID = banchTemp.BATCH_ID;
 | 
						||
                    modelCombin.Nav_ExamBatch = banchTemp.Nav_Batch;
 | 
						||
                    modelCombin.Nav_ExamBatch.TIME = modelCombin.Nav_ExamBatch.START_TIME.ToString("yyyy-MM-dd") + "~" + modelCombin.Nav_ExamBatch.END_TIME.ToString("MM-dd");
 | 
						||
 | 
						||
                    modelCombin.THISDATE = modelCombin.Nav_ExamBatch.START_TIME;//本次体检时间
 | 
						||
 | 
						||
                }
 | 
						||
                //modelCombin.ENTITY_ORG_TPYE
 | 
						||
                //modelCombin.FORM_ID
 | 
						||
                //modelCombin.FLOW_STATUS
 | 
						||
                //modelCombin.FLOW_SEND_STATUS
 | 
						||
                //modelCombin.FLOW_ID
 | 
						||
                //modelCombin.CREATE_TIME
 | 
						||
                //modelCombin.MODIFY_TIME
 | 
						||
                //modelCombin.CREATER_ID
 | 
						||
                //modelCombin.MODIFIER_ID
 | 
						||
 | 
						||
                //modelCombin.PLAN_ID_DEP
 | 
						||
                //modelCombin.PLAN_REGISTER_ID
 | 
						||
                //modelCombin.NEXTDATE
 | 
						||
 | 
						||
                #region    获取上次体检时间
 | 
						||
 | 
						||
                BaseFilter basFiliter = new BaseFilter();
 | 
						||
                basFiliter.Order = DbOrder.DESC;
 | 
						||
                basFiliter.Orders.Add(new DataOrder() { Field = "THISDATE", Order = DbOrder.DESC });
 | 
						||
                var modelLast = GetEntity<T_OH_HEALTH_EXAM_NOTICE_REGISTER>(e => !e.IS_DELETED && e.USER_ID == UserID && e.STATUS >= OHHealthExamNoticeRegisterStatus.NoticeResult, basFiliter, "");
 | 
						||
                if (modelLast != null && modelLast.THISDATE.HasValue)
 | 
						||
                {
 | 
						||
                    modelCombin.LASTDATE = modelLast.THISDATE;//上次体检时间 就是上次通知的本次时间
 | 
						||
                }
 | 
						||
 | 
						||
                #endregion
 | 
						||
 | 
						||
                if (listDepPost != null && listDepPost.Any())
 | 
						||
                {
 | 
						||
                    modelCombin.CYCLE_ID = listDepPost[0].Nav_DepartmentInfo.EXAM_CYCLE_ID;
 | 
						||
 | 
						||
                    //T_OH_HEALTH_EXAM_CYCLE_DEPARTMENTINFO_POST
 | 
						||
                    List<T_OH_EXAM_NOTICE_OCC_HAZARD> listHazard = new List<T_OH_EXAM_NOTICE_OCC_HAZARD>();
 | 
						||
                    var examCycle = GetEntity<T_OH_HEALTH_EXAM_CYCLE>(e => e.ID == modelCombin.CYCLE_ID, "Nav_ListOccHazard.Nav_Hazard");
 | 
						||
                    foreach (var item in examCycle.Nav_ListOccHazard)
 | 
						||
                    {
 | 
						||
                        listHazard.Add(new T_OH_EXAM_NOTICE_OCC_HAZARD()
 | 
						||
                        {
 | 
						||
                            ID = Guid.NewGuid(),
 | 
						||
                            REGISTER_ID = modelCombin.ID,
 | 
						||
                            HAZARD_ID = item.HAZARD_ID,
 | 
						||
                            Nav_Hazard = item.Nav_Hazard,
 | 
						||
                            IS_DELETED = false,
 | 
						||
                            ORG_ID = item.ORG_ID,
 | 
						||
                            //ENTITY_ORG_TPYE
 | 
						||
                            //FORM_ID
 | 
						||
                            //FLOW_STATUS
 | 
						||
                            //FLOW_SEND_STATUS
 | 
						||
                            //FLOW_ID
 | 
						||
                            //CREATE_TIME
 | 
						||
                            //MODIFY_TIME
 | 
						||
                            //CREATER_ID
 | 
						||
                            //MODIFIER_ID
 | 
						||
                        });
 | 
						||
                    }
 | 
						||
                    modelCombin.Nav_ListOccHazard = listHazard;
 | 
						||
                }
 | 
						||
 | 
						||
                //if (listPostCycle != null && listPostCycle.Count > 0)
 | 
						||
                //{
 | 
						||
                //    if (listPostCycle.Count == 1)
 | 
						||
                //    {
 | 
						||
                //        modelCombin.CYCLE_ID = listPostCycle[0].RECORD_ID;
 | 
						||
                //    }
 | 
						||
                //    List<T_OH_EXAM_NOTICE_OCC_HAZARD> listHazard = new List<T_OH_EXAM_NOTICE_OCC_HAZARD>();
 | 
						||
                //    foreach (var item in listPostCycle)
 | 
						||
                //    {
 | 
						||
                //        foreach (var itemOcc in item.Nav_Record.Nav_ListOccHazard)
 | 
						||
                //        {
 | 
						||
                //            if (itemOcc?.Nav_Hazard?.RISK_TYPE == HMRiskTypeEnmu.职业危害辨识)
 | 
						||
                //            {
 | 
						||
                //                //职业危害辨识
 | 
						||
                //                listHazard.Add(new T_OH_EXAM_NOTICE_OCC_HAZARD()
 | 
						||
                //                {
 | 
						||
                //                    ID = Guid.NewGuid(),
 | 
						||
                //                    REGISTER_ID = modelCombin.ID,
 | 
						||
                //                    HAZARD_ID = itemOcc.HAZARD_ID,
 | 
						||
                //                    Nav_Hazard = itemOcc.Nav_Hazard,
 | 
						||
                //                    IS_DELETED = false,
 | 
						||
                //                    ORG_ID = item.ORG_ID,
 | 
						||
                //                    //ENTITY_ORG_TPYE
 | 
						||
                //                    //FORM_ID
 | 
						||
                //                    //FLOW_STATUS
 | 
						||
                //                    //FLOW_SEND_STATUS
 | 
						||
                //                    //FLOW_ID
 | 
						||
                //                    //CREATE_TIME
 | 
						||
                //                    //MODIFY_TIME
 | 
						||
                //                    //CREATER_ID
 | 
						||
                //                    //MODIFIER_ID
 | 
						||
                //                });
 | 
						||
                //            }
 | 
						||
                //        }
 | 
						||
                //    }
 | 
						||
                //    modelCombin.Nav_ListOccHazard = listHazard;
 | 
						||
                //}
 | 
						||
 | 
						||
                return modelCombin;
 | 
						||
            });
 | 
						||
        }
 | 
						||
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 自动推送 体检通知 
 | 
						||
        /// 加载体检人员
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="filter"></param>
 | 
						||
        /// <returns></returns>
 | 
						||
        [HttpPost, Route("GetNoticeCycle")]
 | 
						||
        public JsonActionResult<T_OH_HEALTH_EXAM_NOTICE> GetNoticeCycle([FromBody] KeywordFilter filter)
 | 
						||
        {
 | 
						||
            return SafeExecute(() =>
 | 
						||
            {
 | 
						||
                T_OH_HEALTH_EXAM_NOTICE NoticeCycle = GetEntity<T_OH_HEALTH_EXAM_NOTICE>(null, filter, new string[] { "Nav_ListNoticeRegister.Nav_User", "Nav_ListNoticeRegister.Nav_Department", "Nav_ListNoticeRegister.Nav_DepartmentWorkshop", "Nav_ListNoticeRegister.Nav_Cycle", "Nav_ListNoticeRegister.Nav_ExamBatch", "Nav_ListNoticeRegister.Nav_ListOccHazard.Nav_Hazard", "Nav_Files" });
 | 
						||
                if (NoticeCycle == null)
 | 
						||
                {
 | 
						||
                    throw new Exception("获取体检通知信息失败!");
 | 
						||
                }
 | 
						||
                if (NoticeCycle.ISSYSTEM)
 | 
						||
                {
 | 
						||
                    var ListNoticeRegister = NoticeCycle.Nav_ListNoticeRegister;
 | 
						||
 | 
						||
                    //下次体检时间
 | 
						||
                    DateTime dtNoticeEnd = DateTime.Now.Date.AddDays(16).AddSeconds(-1);
 | 
						||
 | 
						||
                    //半个月以内要体检的人
 | 
						||
                    var listNoticeReg = GetEntities<T_OH_HEALTH_EXAM_NOTICE_REGISTER>(e => e.NEXTDATE.HasValue && e.NEXTDATE <= dtNoticeEnd && !e.IS_DELETED, null, new string[] { "Nav_User", "Nav_Department", "Nav_DepartmentWorkshop", "Nav_Cycle", "Nav_ListOccHazard.Nav_Hazard" }).OrderBy(e => e.DEPARTMENT_ID);
 | 
						||
                    if (listNoticeReg != null && listNoticeReg.Any())
 | 
						||
                    {
 | 
						||
                        //根据部门 自动匹配
 | 
						||
                        //体检批次 开始时间 半个月以内的
 | 
						||
                        List<T_OH_HEALTH_EXAM_BATCH> listBatchSuit = GetEntities<T_OH_HEALTH_EXAM_BATCH>(e => e.START_TIME > DateTime.Now && e.START_TIME < dtNoticeEnd && e.Nav_ListDepartment != null && !e.IS_DELETED, null, new string[] { "Nav_User", "Nav_ListDepartment" }).OrderBy(e => e.START_TIME).ToList();
 | 
						||
                        //Nav_Department
 | 
						||
                        List<T_OH_HEALTH_EXAM_BATCH_DEPARTMENT> listBatchDep = new List<T_OH_HEALTH_EXAM_BATCH_DEPARTMENT>();
 | 
						||
                        for (int i = listBatchSuit.Count - 1; i > -1; i--)
 | 
						||
                        {
 | 
						||
                            if (listBatchSuit[i].Nav_ListDepartment == null || !listBatchSuit[i].Nav_ListDepartment.Any())
 | 
						||
                            {
 | 
						||
                                listBatchSuit.RemoveAt(i);
 | 
						||
                            }
 | 
						||
                            listBatchDep.AddRange(listBatchSuit[i].Nav_ListDepartment.ToList());
 | 
						||
                        }
 | 
						||
 | 
						||
                        List<T_OH_HEALTH_EXAM_BATCH> listBatchCheck = null;
 | 
						||
                        T_OH_HEALTH_EXAM_NOTICE_REGISTER modelCheck = null;
 | 
						||
                        List<T_OH_EXAM_NOTICE_OCC_HAZARD> ListOccHazard = null;
 | 
						||
                        foreach (var item in listNoticeReg)
 | 
						||
                        {
 | 
						||
                            modelCheck = ListNoticeRegister.FirstOrDefault(e => e.USER_ID == item.USER_ID);
 | 
						||
                            if (modelCheck == null)
 | 
						||
                            {
 | 
						||
                                modelCheck = new T_OH_HEALTH_EXAM_NOTICE_REGISTER();
 | 
						||
                                modelCheck.ID = Guid.NewGuid();
 | 
						||
                                modelCheck.NOTICE_ID = NoticeCycle.ID;
 | 
						||
                                modelCheck.USER_ID = item.USER_ID;
 | 
						||
                                modelCheck.Nav_User = item.Nav_User;
 | 
						||
                                modelCheck.Nav_Department = item.Nav_Department;
 | 
						||
                                modelCheck.Nav_DepartmentWorkshop = item.Nav_DepartmentWorkshop;
 | 
						||
                                modelCheck.Nav_Cycle = item.Nav_Cycle;
 | 
						||
                                if (item.Nav_ListOccHazard != null && item.Nav_ListOccHazard.Any())
 | 
						||
                                {
 | 
						||
                                    ListOccHazard = new List<T_OH_EXAM_NOTICE_OCC_HAZARD>();
 | 
						||
                                    foreach (var itemHaz in item.Nav_ListOccHazard)
 | 
						||
                                    {
 | 
						||
                                        ListOccHazard.Add(new T_OH_EXAM_NOTICE_OCC_HAZARD()
 | 
						||
                                        {
 | 
						||
                                            ID = Guid.NewGuid(),
 | 
						||
                                            REGISTER_ID = modelCheck.ID,
 | 
						||
                                            HAZARD_ID = itemHaz.HAZARD_ID,
 | 
						||
                                            Nav_Hazard = itemHaz.Nav_Hazard,
 | 
						||
                                            IS_DELETED = false,
 | 
						||
                                            ORG_ID = itemHaz.ORG_ID,
 | 
						||
                                            //ENTITY_ORG_TPYE =,
 | 
						||
                                            //FORM_ID =,
 | 
						||
                                            //FLOW_STATUS =,
 | 
						||
                                            //FLOW_SEND_STATUS =,
 | 
						||
                                            //FLOW_ID =,
 | 
						||
                                            //CREATE_TIME =,
 | 
						||
                                            //MODIFY_TIME =,
 | 
						||
                                            //CREATER_ID =,
 | 
						||
                                            //MODIFIER_ID =,
 | 
						||
                                        });
 | 
						||
                                    }
 | 
						||
 | 
						||
                                    modelCheck.Nav_ListOccHazard = ListOccHazard;
 | 
						||
                                }
 | 
						||
                                modelCheck.DEPARTMENT_ID = item.DEPARTMENT_ID;
 | 
						||
                                modelCheck.DEPARTMENT_ID_WORKSHOP = item.DEPARTMENT_ID_WORKSHOP;
 | 
						||
                                modelCheck.CYCLE_ID = item.CYCLE_ID;
 | 
						||
                                //modelCheck.EXAM_BATCH_ID = item.EXAM_BATCH_ID;
 | 
						||
 | 
						||
 | 
						||
                                //TODO   体检人所在部门 0512 修改一对多
 | 
						||
                                ////根据实际 重新匹配 体检批次
 | 
						||
                                //listBatchCheck = listBatchSuit.FindAll(e => e.DEPARTMENT_ID == modelCheck.Nav_User.DEPARTMENT_ID).OrderBy(e => e.START_TIME).ToList();
 | 
						||
                                //if ((listBatchCheck == null || !listBatchCheck.Any()) && modelCheck.DEPARTMENT_ID_WORKSHOP.HasValue)
 | 
						||
                                //{
 | 
						||
                                //    listBatchCheck = listBatchSuit.FindAll(e => e.DEPARTMENT_ID == modelCheck.DEPARTMENT_ID_WORKSHOP).OrderBy(e => e.START_TIME).ToList();
 | 
						||
                                //}
 | 
						||
                                //if ((listBatchCheck == null || !listBatchCheck.Any()) && modelCheck.DEPARTMENT_ID.HasValue)
 | 
						||
                                //{
 | 
						||
                                //    listBatchCheck = listBatchSuit.FindAll(e => e.DEPARTMENT_ID == modelCheck.DEPARTMENT_ID).OrderBy(e => e.START_TIME).ToList();
 | 
						||
                                //}
 | 
						||
 | 
						||
                                listBatchCheck = listBatchSuit.FindAll(e => e.Nav_ListDepartment.FirstOrDefault(e => e.DEPARTMENT_ID == modelCheck.Nav_User.DEPARTMENT_ID) != null).OrderBy(e => e.START_TIME).ToList();
 | 
						||
 | 
						||
                                if (listBatchCheck != null && listBatchCheck.Any())
 | 
						||
                                {
 | 
						||
                                    modelCheck.EXAM_BATCH_ID = listBatchCheck[0].ID;
 | 
						||
                                    modelCheck.Nav_ExamBatch = listBatchCheck[0];
 | 
						||
                                    modelCheck.Nav_ExamBatch.TIME = listBatchCheck[0].START_TIME.ToString("yyyy-MM-dd") + " ~ " + listBatchCheck[0].END_TIME.ToString("MM-dd");
 | 
						||
                                }                                ////根据实际 重新匹配 体检批次
 | 
						||
                                //listBatchCheck = listBatchSuit.FindAll(e => e.DEPARTMENT_ID == modelCheck.Nav_User.DEPARTMENT_ID).OrderBy(e => e.START_TIME).ToList();
 | 
						||
 | 
						||
                                //if ((listBatchCheck == null || !listBatchCheck.Any()) && modelCheck.DEPARTMENT_ID_WORKSHOP.HasValue)
 | 
						||
                                //{
 | 
						||
                                //    listBatchCheck = listBatchSuit.FindAll(e => e.DEPARTMENT_ID == modelCheck.DEPARTMENT_ID_WORKSHOP).OrderBy(e => e.START_TIME).ToList();
 | 
						||
                                //}
 | 
						||
                                //if ((listBatchCheck == null || !listBatchCheck.Any()) && modelCheck.DEPARTMENT_ID.HasValue)
 | 
						||
                                //{
 | 
						||
                                //    listBatchCheck = listBatchSuit.FindAll(e => e.DEPARTMENT_ID == modelCheck.DEPARTMENT_ID).OrderBy(e => e.START_TIME).ToList();
 | 
						||
                                //}
 | 
						||
 | 
						||
                                //if (listBatchCheck != null && listBatchCheck.Any())
 | 
						||
                                //{
 | 
						||
                                //    modelCheck.EXAM_BATCH_ID = listBatchCheck[0].ID;
 | 
						||
                                //    modelCheck.Nav_ExamBatch = listBatchCheck[0];
 | 
						||
                                //    modelCheck.Nav_ExamBatch.TIME = listBatchCheck[0].START_TIME.ToString("yyyy-MM-dd") + " ~ " + listBatchCheck[0].END_TIME.ToString("MM-dd");
 | 
						||
                                //}
 | 
						||
 | 
						||
                                modelCheck.TYPE = item.TYPE;
 | 
						||
                                modelCheck.STATUS = OHHealthExamNoticeRegisterStatus.WaitNotice;
 | 
						||
                                modelCheck.IS_DELETED = item.IS_DELETED;
 | 
						||
                                modelCheck.ORG_ID = item.ORG_ID;
 | 
						||
                                //modelCheck.ENTITY_ORG_TPYE =item.  ;
 | 
						||
                                //modelCheck.FORM_ID    =item.;
 | 
						||
                                //modelCheck.FLOW_STATUS=item.;
 | 
						||
                                //modelCheck.FLOW_SEND_STATUS=item.  ;
 | 
						||
                                //modelCheck.FLOW_ID     =item.;
 | 
						||
                                //modelCheck.CREATE_TIME =item.;
 | 
						||
                                //modelCheck.MODIFY_TIME =item.;
 | 
						||
                                //modelCheck.CREATER_ID  =item.;
 | 
						||
                                //modelCheck.MODIFIER_ID =item.;
 | 
						||
                                modelCheck.PLAN_ID_DEP = item.PLAN_ID_DEP;
 | 
						||
                                modelCheck.PLAN_REGISTER_ID = item.PLAN_REGISTER_ID;
 | 
						||
                                //modelCheck.NEXTDATE = item.  ;
 | 
						||
                            }
 | 
						||
                            ListNoticeRegister.Add(modelCheck);
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
                    NoticeCycle.Nav_ListNoticeRegister = ListNoticeRegister;
 | 
						||
                }
 | 
						||
                return NoticeCycle;
 | 
						||
            });
 | 
						||
        }
 | 
						||
    }
 | 
						||
} |