using APT.BaseData.Domain.Entities.FM;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.SC.PT;
using APT.MS.Domain.Enums;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq.Expressions;

namespace APT.SC.WebApi.Controllers.Api.PTController
{
    /// <summary>
    ///  触发时间配置表
    /// </summary>
    [Route("api/PT/PTTimeSet")]
    public partial class TimeSetController : AuthorizeApiController<T_PT_TIME_SET>
    {
        /// <summary>
        /// 更新或新增数据
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_PT_TIME_SET entity)
        {
            switch (entity.PLANCHECKFREQUENCY)
            {
                case MS.Domain.Enums.BSPLANCHECKFREQUENCYEnum.Month:
                    entity.RUNSETTIME = DateTime.Parse(DateTime.Now.Year +"-" + DateTime.Now.Month+"-" + entity.DATA+" " + entity.RUNSETTIME.Value.TimeOfDay);
                    break;
                case MS.Domain.Enums.BSPLANCHECKFREQUENCYEnum.Quarter:
                    break;
                case MS.Domain.Enums.BSPLANCHECKFREQUENCYEnum.Year:
                    break;
                default:
                    break;
            }
            return WitUpdate(entity);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("OrderPagedNew")]
        public PagedActionResult<T_PT_TIME_SET> OrderPagedNew([FromBody] KeywordPageFilter pageFilter)
        {
            Expression<Func<T_PT_TIME_SET, bool>> express = t => !t.IS_DELETED;
            express = express.And(t => t.SET_TYPE == PTSetTypeEnum.CorrectivePreventive || t.SET_TYPE == PTSetTypeEnum.SafetyMonitorPlan || t.SET_TYPE == PTSetTypeEnum.SafetyMonitorRecord || t.SET_TYPE == PTSetTypeEnum.SafetyEvaluationPlan);
            var result = this.WitOrderPaged(express, pageFilter);
            return result;
        }
    }
}
