using Microsoft.AspNetCore.Mvc;
|
using System.Net;
|
using System.Net.Http.Headers;
|
using Microsoft.Extensions.Hosting.Internal;
|
using Microsoft.AspNetCore.Http.Extensions;
|
using IStation.Untity;
|
using Furion.DynamicApiController;
|
using System.ComponentModel.DataAnnotations;
|
using Mapster;
|
|
|
namespace IStation.Application
|
{
|
/// <summary>
|
/// IotPaymentRecord
|
/// </summary>
|
[Route("Product/IotPaymentRecord")]
|
[ApiDescriptionSettings("Product", Name = "物联卡缴费记录", Order = 1000)]
|
public class IotPaymentRecord_Controller : IDynamicApiController
|
{
|
private readonly Service.IotPaymentRecord _service = new Service.IotPaymentRecord();
|
|
#region Query
|
|
/// <summary>
|
/// 通过 CorpID 获取
|
/// </summary>
|
[Route("GetByCorpID@V1.0")]
|
[HttpGet]
|
public List<IotPaymentRecordDto> GetByCorpID([FromQuery][Required] CorpIDInput input)
|
{
|
var list = _service.GetByCorpID(input.CorpID);
|
var vm_list = list?.Select(x => x.Adapt<Model.IotPaymentRecord, IotPaymentRecordDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
[Route("GetByID@V1.0")]
|
[HttpGet]
|
public IotPaymentRecordDto GetByID([FromQuery][Required] IDUnderCorpInput input)
|
{
|
var model = _service.GetByID(input.CorpID, input.ID);
|
return model?.Adapt<Model.IotPaymentRecord, IotPaymentRecordDto>();
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
[Route("GetByIds@V1.0")]
|
[HttpGet]
|
public List<IotPaymentRecordDto> GetByIds([FromQuery][Required] IdsUnderCorpInput input)
|
{
|
var ids = LongListHelper.ToList(input.Ids);
|
var list = _service.GetByIds(input.CorpID, ids);
|
var vm_list = list?.Select(x => x.Adapt<Model.IotPaymentRecord, IotPaymentRecordDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 ProductID 获取
|
/// </summary>
|
[Route("GetByProductID@V1.0")]
|
[HttpGet]
|
public List<IotPaymentRecordDto> GetByProductID([FromQuery] ProductIDUnderCorpInput input)
|
{
|
var list = _service.GetByProductID(input.CorpID, input.ProductID);
|
var vmList = list?.Select(x => new IotPaymentRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 ProductIds 获取
|
/// </summary>
|
[Route("GetByProductIds@V1.0")]
|
[HttpGet]
|
public List<IotPaymentRecordDto> GetByProductIds([FromQuery] ProductIdsUnderCorpInput input)
|
{
|
var productIds = LongListHelper.ToList(input.ProductIds);
|
var list = _service.GetByProductIds(input.CorpID, productIds);
|
var vmList = list?.Select(x => new IotPaymentRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 BelongType and BelongID获取
|
/// </summary>
|
[Route("GetByBelongTypeAndBelongID@V1.0")]
|
[HttpGet]
|
public List<IotPaymentRecordDto> GetByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input)
|
{
|
var list = _service.GetByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID);
|
var vmList = list?.Select(x => new IotPaymentRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
[Route("Insert@V1.0")]
|
[HttpPost]
|
public long Insert(AddIotPaymentRecordInput input)
|
{
|
if (input == null)
|
return default;
|
var model = input.Adapt<AddIotPaymentRecordInput, Model.IotPaymentRecord>();
|
var id = _service.Insert(model);
|
return id;
|
}
|
|
/// <summary>
|
/// 插入多条
|
/// </summary>
|
[Route("Inserts@V1.0")]
|
[HttpPost]
|
public bool Inserts(List<AddIotPaymentRecordInput> inputList)
|
{
|
if (inputList == null || inputList.Count < 1)
|
return false;
|
var list = inputList.Select(x => x.Adapt<AddIotPaymentRecordInput, Model.IotPaymentRecord>()).ToList();
|
var bol = _service.Inserts(list);
|
return bol;
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
[Route("Update@V1.0")]
|
[HttpPut]
|
public bool Update(UpdateIotPaymentRecordInput input)
|
{
|
if (input == null)
|
return false;
|
var model = _service.GetByID(input.CorpID, input.ID);
|
if (model == null)
|
return false;
|
var rhs = new Model.IotPaymentRecord(model);
|
input.Adapt(rhs);
|
var bol = _service.Update(rhs);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新多条
|
/// </summary>
|
[Route("Updates@V1.0")]
|
[HttpPut]
|
public bool Updates(List<UpdateIotPaymentRecordInput> inputList)
|
{
|
if (inputList == null || inputList.Count() < 1)
|
{
|
return false;
|
}
|
var corpIds = inputList.Select(x => x.CorpID).Distinct().ToList();
|
if (corpIds.Count > 1)
|
return false;
|
var modelList = _service.GetByIds(corpIds[0], inputList.Select(x => x.ID).ToList());
|
if (modelList == null || modelList.Count < 1)
|
return false;
|
var rhsList = new List<Model.IotPaymentRecord>();
|
modelList.ForEach(x => {
|
var input = inputList.Find(t => t.ID == x.ID);
|
if (input != null)
|
{
|
var rhs = new Model.IotPaymentRecord(x);
|
input.Adapt(rhs);
|
rhsList.Add(rhs);
|
}
|
});
|
if (rhsList.Count < 1)
|
return false;
|
var bol = _service.Updates(rhsList);
|
return bol;
|
}
|
|
#endregion
|
|
#region Delete
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
[Route("DeleteByID@V1.0")]
|
[HttpDelete]
|
public DeleteReasonOutput DeleteByID([FromQuery][Required] IDUnderCorpInput input)
|
{
|
var bol = _service.DeleteByID(input.CorpID, input.ID, out string Msg);
|
return new DeleteReasonOutput() { Success = bol, Reason = Msg };
|
}
|
|
#endregion
|
|
|
}
|
}
|