using System;
using System.Collections.Generic;
using System.Web.Http;
using FactorySystemApi.Sap_Group;
using FactorySystemBll;
using FactorySystemCommon;
using FactorySystemModel.BusinessModel;
using FactorySystemModel.EnumModel;
using FactorySystemModel.RequestModel;
using FactorySystemModel.ResponseModel;
using FactorySystemModel.SqlSugarModel;

namespace FactorySystemApi.Controllers
{
    /// <summary>
    /// 任务
    /// </summary>
    [UserLoginFilter]
    public class MaterialTaskController : ApiController
    {
        private readonly MaterialTaskBll MaterialTaskBll = new MaterialTaskBll();

        /// <summary>
        /// 根据当前用户获取任务列表
        /// </summary>
        [HttpPost]
        public ApiResult GetPageList(MaterialTaskQuery mtq)
        {
            ApiResult apiResult = new ApiResult();
            return ExceptionHelper.TryReturnException(() =>
            {
                if (mtq.FIsUser && Request.Properties["token"] is ApiAuthInfo user)
                {
                    mtq.FUserID = user.FID.ToString();
                }
                apiResult.Data = new
                {
                    List = MaterialTaskBll.GetList(mtq, out var totalNumber),
                    Total = totalNumber
                };
            }, apiResult, Request);
        }
    }
}
