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

namespace APT.BS.WebApi.Controllers.Api
{
    [Route("api/BS/BSRiskSubmitNotice")]
    public partial class BSRiskSubmitNoticeController : AuthorizeApiController<T_BS_RISK_SUBMIT_NOTICE>
    {
        IFMFlowPermitService MFlowPermitService { get; set; }
        IFMNotificationTaskService NotificationTaskService { get; set; }
        IPFCodeRuleService CodeRuleService { get; set; }
        IPFApproveCallBackService ApproveCallBackService { get; set; }
        IFMDepartmentService DepartmentService { get; set; }
        public BSRiskSubmitNoticeController(IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFCodeRuleService codeRuleService, IPFApproveCallBackService approveCallBackService, IFMDepartmentService departmentService)
        {
            NotificationTaskService = notificationTaskService;
            MFlowPermitService = mFlowPermitService;
            CodeRuleService = codeRuleService;
            ApproveCallBackService = approveCallBackService;
            DepartmentService = departmentService;
        }


        /// <summary>
        /// 获取整改落实人验收
        /// </summary>
        /// <param name="filter">过滤实体</param>
        /// <returns></returns>
        [HttpPost, Route("GetNotice")]
        public JsonActionResult<T_BS_RISK_SUBMIT_NOTICE> GetNotice([FromBody] KeywordFilter filter)
        {
            return SafeExecute(() =>
            {
                Guid ID = Guid.Empty;
                if (filter.FilterGroup.Rules.Count > 0)
                {
                    List<FilterRule> listR = filter.FilterGroup.Rules.ToList();
                    foreach (FilterRule rule in listR)
                    {
                        if (rule.Field == "ID")
                        {
                            ID = new Guid(rule.Value.ToString());
                        }
                    }
                }
                var Nitoce = GetEntity<T_BS_RISK_SUBMIT_NOTICE>(e => e.ID == ID, new string[] { "Nav_Submit.Nav_CheckType", "Nav_Submit.Nav_CheckTypeLevel.Nav_Enums", "Nav_Submit.Nav_Files.Nav_ImgFile.Nav_File", "Nav_Approve.Nav_ApproveDetails.Nav_ApproveUser.Nav_UserSignFiles.Nav_ImgFile.Nav_File" });
                var listRiskSubmitContentT = GetEntities<T_BS_RISK_SUBMIT_CONTENT>(e => e.RISK_SUBMIT_NOTICE_ID == ID, null, new string[] { "Nav_SafeCheckDetail", "Nav_Question", "Nav_ListRiskQuestionReason.Nav_RiskReason", "Nav_Files.Nav_ImgFile.Nav_File", "Nav_DepartmentDeal", "Nav_UserDeal", "Nav_UserCheck", "Nav_User", "Nav_Department" });//"Nav_User", "Nav_Department", 不需要了 BS006ShowPrint   隐患通知责任人  责任单位
                //DOTO 等移动端升级后 再取消 "Nav_User", "Nav_Department" 
                if (listRiskSubmitContentT != null && listRiskSubmitContentT.Any())
                {
                    Nitoce.Nav_ListRiskSubmitContent = listRiskSubmitContentT.ToList();
                    if (Nitoce.Nav_ListRiskSubmitContent != null && Nitoce.Nav_ListRiskSubmitContent.Count > 0 && DataHelper.GetRequestType(Request.Headers) == 2)
                    {
                        Nitoce.Nav_ListRiskSubmitContent.ForEach(e =>
                        {
                            try
                            {
                                if (e.QUESTION_LEVEL > 0)
                                    e.QUESTION_LEVEL_SHOW = ((BSQuestionLevelEnum)e.QUESTION_LEVEL).GetDescription();
                            }
                            catch { }
                        });
                    }
                }
                else
                {
                    Nitoce.Nav_ListRiskSubmitContent = new List<T_BS_RISK_SUBMIT_CONTENT>();
                }

                return Nitoce;
            });

        }
    }
}