using APT.BaseData.Domain.ApiModel.PF;
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.Api;
using APT.Infrastructure.Core;
using APT.Migrations;
using APT.MS.Domain.ApiModel.BS;
using APT.MS.Domain.Entities.BS;
using APT.MS.Domain.Entities.HM;
using APT.MS.Domain.Entities.SC.SC;
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;
using System.Reflection;

namespace APT.BS.WebApi.Controllers.Api
{
    [Route("api/BS/BSOperateLog")]
    public partial class BSOperateLogController : AuthorizeApiController<T_BS_OPERATE_LOG>
    {
        /// <summary>
        /// 排序查询所有数据
        /// </summary>
        /// <param name="filter">过滤实体</param>
        /// <returns></returns>

        [HttpPost, Route("OrderEntities")]
        public JsonActionResult<IEnumerable<T_BS_OPERATE_LOG>> OrderEntities([FromBody] KeywordFilter filter)
        {
            return SafeExecute<IEnumerable<T_BS_OPERATE_LOG>>(() =>
            {
                if (string.IsNullOrEmpty(filter.Keyword))
                {
                    return new List<T_BS_OPERATE_LOG>();
                }
                else
                {
                    string Keyword = filter.Keyword;
                    var ids = Keyword.Split("_");
                    Guid? CheckID = null;
                    Guid? SubmitID = null;
                    for (int i = 0; i < ids.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(ids[i]))
                        {
                            if (i == 0)
                                CheckID = new Guid(ids[i]);
                            else
                                SubmitID = new Guid(ids[i]);
                        }
                    }
                    List<T_BS_OPERATE_LOG> result = new List<T_BS_OPERATE_LOG>();
                    if (CheckID != null)
                    {
                        result.AddRange(GetEntities<T_BS_OPERATE_LOG>(e => e.DATA_ID == CheckID.Value, null, null).OrderBy(e => e.OPERATEPOINT).ToList());
                    }
                    if (SubmitID != null)
                    {
                        result.AddRange(GetEntities<T_BS_OPERATE_LOG>(e => e.DATA_ID == SubmitID.Value, null, null).OrderBy(e => e.DATA_ID_SUB).ThenBy(e => e.OPERATEPOINT).ToList());
                    }
                    return result;
                }
            });
        }
    }
}