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

using APT.Utility;namespace APT.FM.WebApi.Controllers.Api.FM
{
	/// <summary>
	/// 自动打印记录
	/// </summary>
	[Route("api/FM/AutoPrintRecord")]
	public class AutoPrintRecordController : AuthorizeApiController<T_FM_AUTO_PRINT_RECORD>
	{

		/// <summary>
		/// 查询
		/// </summary>
		/// <param name="filter"></param>
		/// <returns></returns>
		[HttpPost, Route("Entities")]
		public JsonActionResult<IEnumerable<T_FM_AUTO_PRINT_RECORD>> Entities([FromBody]KeywordFilter filter)
		{
			return WitEntities(null, filter);
		}
		/// <summary>
		/// 查询
		/// </summary>
		/// <param name="filter"></param>
		/// <returns></returns>
		/// 

		[HttpPost, Route("OrderEntities")]
		public JsonActionResult<IEnumerable<T_FM_AUTO_PRINT_RECORD>> OrderEntities([FromBody]KeywordFilter filter)
		{
			return WitOrderEntities(null, filter);
		}
		/// <summary>
		/// 查询
		/// </summary>
		/// <param name="pageFilter"></param>
		/// <returns></returns>
		[HttpPost, Route("Paged")]
		public PagedActionResult<T_FM_AUTO_PRINT_RECORD> Paged([FromBody]KeywordPageFilter pageFilter)
		{
			return WitPaged(null, pageFilter);
		}
		/// <summary>
		/// 查询
		/// </summary>
		/// <param name="pageFilter"></param>
		/// <returns></returns>
		[HttpPost, Route("OrderPaged")]
		public PagedActionResult<T_FM_AUTO_PRINT_RECORD> OrderPaged([FromBody]KeywordPageFilter pageFilter)
		{
			return WitOrderPaged(null, pageFilter);
		}
		/// <summary>
		/// 删除
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpGet, Route("Delete")]
		public JsonActionResult<bool> Delete(string id)
		{
			return WitDelete(id);
		}

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

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


		/// <summary>
		/// 获得单条实体数据
		/// </summary>
		/// <param name="filter"></param>
		/// <returns></returns>
		[HttpPost, Route("Get")]
		public JsonActionResult<T_FM_AUTO_PRINT_RECORD> Get([FromBody] KeywordFilter filter)
		{
			return WitEntity(null, filter);
		}



		/// <summary>更新打印状态</summary>
		/// <param name="filter"></param>
		/// <returns></returns>
		[HttpPost, Route("UpdatePrintStatus")]
		public JsonActionResult<bool> UpdatePrintStatus([FromBody] KeywordFilter filter)
		{
			return SafeExecute<bool>(() =>
			{
				if (string.IsNullOrEmpty(filter.Keyword))
					throw new Exception("参数为空");
				List<Guid> recordIds = filter.Keyword.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(i=>new Guid(i)).ToList();
				if (recordIds == null || !recordIds.Any())
					throw new Exception("参数为空");

				int printstatus = 1;
				if (!string.IsNullOrEmpty(filter.Parameter1))
					printstatus = Convert.ToInt32(filter.Parameter1);

				var records = this.GetEntities<T_FM_AUTO_PRINT_RECORD>(t => recordIds.Contains(t.ID), new BaseFilter(filter.OrgId)).ToList();
				records.ForEach(t => t.PRINT_STATUS = printstatus);
				this.BantchUpdateEntity(records);
				return true;
			});
		}
	}
}
