using APT.Infrastructure.Core;
using APT.BaseData.Domain.Entities.FM;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

using APT.Utility;
using APT.BaseData.Domain.Enums;
using APT.Infrastructure.Api;
namespace APT.FM.WebApi.Controllers.Api.FM
{
	/// <summary>设备集成信息同步</summary>
	[Route("api/FM/EquipmentIntegrationTask")]
    public class EquipmentIntegrationTaskController : APTApiController<T_FM_EQUIPMENT_INTEGRATION_TASK>
    {
        /// <summary>
		/// 查询
		/// </summary>
		/// <param name="filter"></param>
		/// <returns></returns>
		[HttpPost, Route("Entities")]
        public JsonActionResult<IEnumerable<T_FM_EQUIPMENT_INTEGRATION_TASK>> Entities([FromBody]KeywordFilter filter)
        {
            return WitEntities(null, filter);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        /// 
        [HttpPost, Route("OrderEntities")]
        public JsonActionResult<IEnumerable<T_FM_EQUIPMENT_INTEGRATION_TASK>> OrderEntities([FromBody]KeywordFilter filter)
        {
            return WitOrderEntities(null, filter);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("Paged")]
        public PagedActionResult<T_FM_EQUIPMENT_INTEGRATION_TASK> Paged([FromBody]KeywordPageFilter pageFilter)
        {
            return WitPaged(null, pageFilter);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("OrderPaged")]
        public PagedActionResult<T_FM_EQUIPMENT_INTEGRATION_TASK> OrderPaged([FromBody]KeywordPageFilter pageFilter)
        {

            var model = WitOrderPaged(null, pageFilter);
            return model;

        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet, Route("Delete")]
        public JsonActionResult<bool> Delete(string id)
        {
            return WitRealDelete(id);
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("Update")]
        public JsonActionResult<bool> Update([FromBody]T_FM_EQUIPMENT_INTEGRATION_TASK entity)
        {
            return WitUpdate(entity);
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("BantchUpdate")]
        public JsonActionResult<bool> BantchUpdate([FromBody]List<T_FM_EQUIPMENT_INTEGRATION_TASK> entitys)
        {
            return WitBantchUpdate(entitys);
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet, Route("BatchDelete")]
        public JsonActionResult<bool> BatchDelete(string ids)
        {
            return WitRealBatchDelete(ids);
        }


        /// <summary>
        /// 获得单条实体数据
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("Get")]
        public JsonActionResult<T_FM_EQUIPMENT_INTEGRATION_TASK> Get([FromBody] KeywordFilter filter)
        {
            return WitEntity(null, filter);
        }
        /// <summary>
		/// 更新
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpPost, Route("Add")]
        public JsonActionResult<bool> Add([FromBody]T_FM_EQUIPMENT_INTEGRATION_TASK entity)
        {
            //entity.NEXT_START_TIME = entity.TASK_START_TIME.AddDays(entity.PERIODIC_TIME);
            var dt = entity.TASK_START_TIME;
            entity.NEXT_START_TIME = (entity.SYNC_UNIT == (int)TimeUnitEnum.秒) ? dt.AddSeconds(entity.PERIODIC_TIME) : (entity.SYNC_UNIT == (int)TimeUnitEnum.分 ? dt.AddMinutes(entity.PERIODIC_TIME) : (entity.SYNC_UNIT == (int)TimeUnitEnum.时 ? dt.AddHours(entity.PERIODIC_TIME) : dt.AddDays(entity.PERIODIC_TIME)));
            return WitUpdate(entity);
        }
    }
}
