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>
|
/// ProductModifyRecord
|
/// </summary>
|
[Route("Product/ProductModifyRecord")]
|
[ApiDescriptionSettings("Product", Name = "设备变更记录", Order = 590)]
|
public class ProductModifyRecord_Controller : IDynamicApiController
|
{
|
private Service.ProductModifyRecord _service = new Service.ProductModifyRecord();
|
|
#region Query
|
|
/// <summary>
|
/// 通过 CorpID 获取
|
/// </summary>
|
[Route("GetByCorpID@V1.0")]
|
[HttpGet]
|
public List<ProductModifyRecordDto> GetByCorpID([FromQuery][Required] CorpIDInput input)
|
{
|
var list = _service.GetByCorpID(input.CorpID);
|
var vmList = list?.Select(x => new ProductModifyRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
[Route("GetByID@V1.0")]
|
[HttpGet]
|
public ProductModifyRecordDto GetByID([FromQuery][Required] IDUnderCorpInput input)
|
{
|
var model = _service.GetByID(input.CorpID, input.ID);
|
if (model == null)
|
return default;
|
var vm = new ProductModifyRecordDto(model);
|
return vm;
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
[Route("GetByIds@V1.0")]
|
[HttpGet]
|
public List<ProductModifyRecordDto> GetByIds([FromQuery][Required] IdsUnderCorpInput input)
|
{
|
var ids = LongListHelper.ToList(input.Ids);
|
var list = _service.GetByIds(input.CorpID, ids);
|
var vmList=list?.Select(x => new ProductModifyRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 ProductID 获取
|
/// </summary>
|
[Route("GetByProductID@V1.0")]
|
[HttpGet]
|
public List<ProductModifyRecordDto> GetByProductID([FromQuery] ProductIDUnderCorpInput input)
|
{
|
var list = _service.GetByProductID(input.CorpID, input.ProductID);
|
var vmList=list?.Select(x => new ProductModifyRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 ProductID 获取拓展文件数量
|
/// </summary>
|
[Route("GetExFileCountByProductID@V1.0")]
|
[HttpGet]
|
public List<ProductModifyRecordExFileCountOutput> GetExFileCountByProductID([FromQuery] ProductIDUnderCorpInput input)
|
{
|
var list = _service.GetByProductID(input.CorpID, input.ProductID);
|
var vmList= list?.Select(x => new ProductModifyRecordExFileCountOutput(x)).ToList();
|
if (vmList != null && vmList.Count > 0)
|
{
|
var serviceFile = new Service.AttachmentFile();
|
vmList.ForEach(x => x.FileCount = serviceFile.GetCountByAttachTypeAndAttachID(x.CorpID, IStation.ObjectType.ProductModifyRecord, x.ID));
|
}
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 ProductID 获取内容拓展文件数量
|
/// </summary>
|
[Route("GetContentExFileCountByProductID@V1.0")]
|
[HttpGet]
|
public List<ProductModifyRecordContentExFileCountOutput> GetContentExFileCountByProductID([FromQuery] ProductIDUnderCorpInput input)
|
{
|
var list = _service.GetByProductID(input.CorpID, input.ProductID);
|
var vmList=list?.Select(x => new ProductModifyRecordContentExFileCountOutput(x)).ToList();
|
|
if (vmList != null && vmList.Count > 0)
|
{
|
var serviceFile = new Service.AttachmentFile();
|
vmList.ForEach(x => x.FileCount = serviceFile.GetCountByAttachTypeAndAttachID(x.CorpID, IStation.ObjectType.ProductModifyRecord, x.ID));
|
}
|
|
return vmList;
|
}
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
[Route("Insert@V1.0")]
|
[HttpPost]
|
public long Insert(AddProductModifyRecordInput input)
|
{
|
if (input == null)
|
return default;
|
var model = input.Adapt<AddProductModifyRecordInput, Model.ProductModifyRecord>();
|
var id = _service.Insert(model);
|
return id;
|
}
|
|
/// <summary>
|
/// 插入多条
|
/// </summary>
|
[Route("Inserts@V1.0")]
|
[HttpPost]
|
public bool Inserts(List<AddProductModifyRecordInput> inputList)
|
{
|
if (inputList == null || inputList.Count < 1)
|
return false;
|
var list = inputList.Select(x => x.Adapt<AddProductModifyRecordInput, Model.ProductModifyRecord>()).ToList();
|
var bol = _service.Inserts(list);
|
return bol;
|
}
|
|
#endregion
|
|
#region Update
|
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
[Route("Update@V1.0")]
|
[HttpPut]
|
public bool Update(UpdateProductModifyRecordInput input)
|
{
|
if (input == null)
|
return false;
|
var model = _service.GetByID(input.CorpID, input.ID);
|
if (model == null)
|
return false;
|
var rhs = new Model.ProductModifyRecord(model);
|
input.Adapt(rhs);
|
var bol = _service.Update(rhs);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新多条
|
/// </summary>
|
[Route("Updates@V1.0")]
|
[HttpPut]
|
public bool Updates(List<UpdateProductModifyRecordInput> 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.ProductModifyRecord>();
|
modelList.ForEach(x => {
|
var input = inputList.Find(t => t.ID == x.ID);
|
if (input != null)
|
{
|
var rhs = new Model.ProductModifyRecord(x);
|
input.Adapt(rhs);
|
rhsList.Add(rhs);
|
}
|
});
|
if (rhsList.Count < 1)
|
return false;
|
var bol = _service.Updates(rhsList);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新排序码
|
/// </summary>
|
[Route("UpdateSortCode@V1.0")]
|
[HttpPut]
|
public bool UpdateSortCode([Required] UpdateSortCodeUnderCorpInput input)
|
{
|
var bol = _service.UpdateSortCode(input.CorpID, input.ID, input.SortCode, UserManager.UserID, DateTime.Now);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新排序
|
/// </summary>
|
[Route("UpdateSorter@V1.0")]
|
[HttpPut]
|
public bool UpdateSorter([Required] UpdateSorterUnderCorpInput input)
|
{
|
if (input.Sorters == null || input.Sorters.Count < 1)
|
return false;
|
var list = input.Sorters.Select(x => x.Adapt<UpdateSortCodeInput, Model.TraceSorter>()).ToList();
|
var bol = _service.UpdateSorter(input.CorpID, list);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新使用状态
|
/// </summary>
|
[Route("UpdateUseStatus@V1.0")]
|
[HttpPut]
|
public bool UpdateUseStatus([Required] UpdateUseStatusUnderCorpInput input)
|
{
|
var bol = _service.UpdateUseStatus(input.CorpID, input.ID, input.UseStatus, UserManager.UserID, DateTime.Now);
|
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
|
|
|
}
|
}
|