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;
using Microsoft.AspNetCore.Http;
namespace IStation.Application
{
///
/// InspectContent
///
[Route("Inspect/Content/Mgr")]
[ApiDescriptionSettings("Inspect", Name = "巡检内容项(管理)", Order = 991)]
public class InspectContent_MgrController : IDynamicApiController
{
#region Query
///
/// 通过 ProductID 获取
///
[Route("GetItemsByProductID@V1.0")]
[HttpGet]
public Dto.InspectionContentBundle4MgrGetProductID GetItemsByProductID([FromQuery][Required] Dto.InspectionContentBundle4MgrGetProductID.Input input)
{
Service.ProductInspectionContentGrp the_grp_service = new Service.ProductInspectionContentGrp();
var list_grp_models = the_grp_service.GetByProductID(input.ProductID);
if (list_grp_models == null || list_grp_models.Count == 0)
return null;
Service.ProductInspectionContentItem the_item_service = new Service.ProductInspectionContentItem();
var list_item_models = the_item_service.GetByProductID(input.ProductID);
var vm = new Dto.InspectionContentBundle4MgrGetProductID();
vm.GrpList = list_grp_models.Select(x => x.Adapt()).ToList();
if (list_item_models != null && list_item_models.Count > 0)
vm.ItemList = list_item_models?.Select(x => x.Adapt()).ToList();
return vm;
}
///
/// 通过 ItemID 获取 值
///
[Route("GetValuesByItemID@V1.0")]
[HttpGet]
public List GetValuesByItemID([FromQuery][Required] Dto.InspectionContentValue4MgrGet.Input input)
{
Service.ProductInspectionContentValue the_grp_service = new Service.ProductInspectionContentValue();
var list_item_models = the_grp_service.GetByItemID(input.ItemID);
if (list_item_models == null || list_item_models.Count == 0)
return null;
return list_item_models .Select(x => x.Adapt()).ToList();
}
#endregion
#region Insert
///
/// 插入一条
///
[Route("InsertGrp@V1.0")]
[HttpPost]
public long InsertGrp([Required] IStation.Dto.AddProductInspectionContentGrpInput input)
{
if (input == null)
return default;
var model = input.Adapt();
model.UseStatus = Model.ProductInspectionContentGrp.eUseStatus.有效;
Service.ProductInspectionContentGrp the_service = new Service.ProductInspectionContentGrp();
var id = the_service.Insert(model);
return id;
}
///
/// 插入多条
///
[Route("InsertGrps@V1.0")]
[HttpPost]
public bool InsertGrps([Required] List inputList)
{
if (inputList == null || inputList.Count < 1)
return false;
var list = inputList.Select(x => x.Adapt()).ToList();
foreach (var item in list)
item.UseStatus = Model.ProductInspectionContentGrp.eUseStatus.有效;
Service.ProductInspectionContentGrp the_service = new Service.ProductInspectionContentGrp();
var bol = the_service.Inserts(list);
return bol;
}
///
/// 插入一条
///
[Route("InsertItem@V1.0")]
[HttpPost]
public long InsertItem([Required] IStation.Dto.AddProductInspectionContentItemInput input)
{
if (input == null)
return default;
var model_item = input.Adapt();
model_item.UseStatus = Model.ProductInspectionContentItem.eUseStatus.有效;
model_item.ProductID = input.ProductID;
List list = null;
if (input.ValueList != null && input.ValueList.Count > 0)
{
list = input.ValueList.Select(x => x.Adapt()).ToList();
foreach (var item in list)
{
item.UseStatus = Model.ProductInspectionContentValue.eUseStatus.有效;
item.CreateUserID = input.CreateUserID;
}
}
Service.ProductInspectionContentItem the_service = new Service.ProductInspectionContentItem();
var id = the_service.Insert(model_item, list);
return id;
}
#endregion
#region Update
///
/// 更新一条
///
[Route("UpdateGrp@V1.0")]
[HttpPut]
public bool UpdateGrp([Required] IStation.Dto.UpdateProductInspectionContentGrpInput input)
{
if (input == null)
return false;
Service.ProductInspectionContentGrp the_service = new Service.ProductInspectionContentGrp();
var model = input.Adapt();
var bol = the_service.Update(model);
return bol;
}
///
/// 更新多条
///
[Route("UpdateGrps@V1.0")]
[HttpPut]
public bool UpdateGrps([Required] List inputList)
{
if (inputList == null || inputList.Count() < 1)
{
return false;
}
var corpIds = inputList.Select(x => x.CorpID).Distinct().ToList();
if (corpIds.Count > 1)
return false;
Service.ProductInspectionContentGrp the_service = new Service.ProductInspectionContentGrp();
List model_list = new List();
inputList.ForEach(input =>
{
var model = input.Adapt();
model_list.Add(model);
});
var bol = the_service.Updates(model_list);
return bol;
}
///
/// 更新一条
///
[Route("UpdateItem@V1.0")]
[HttpPut]
public bool UpdateItem([Required] IStation.Dto.UpdateProductInspectionContentItemInput input)
{
if (input == null)
return false;
Service.ProductInspectionContentItem the_service = new Service.ProductInspectionContentItem();
var model = input.Adapt();
if (model.ID <= 0)
return false;
List list = null;
if (input.ValueList != null && input.ValueList.Count > 0)
{
list = input.ValueList.Select(x => x.Adapt()).ToList();
foreach (var vvv in list)
{
vvv.ItemID = model.ID;
if(vvv.ID <= 0)
{
vvv.CreateTime = DateTime.Now;
vvv.CreateUserID = input.UpdateUserID;
}
vvv.UpdateUserID = input.UpdateUserID;
}
}
var bol = the_service.Update(model, list);
return bol;
}
///
/// 更新排序码
///
[Route("UpdateGrpSortCode@V1.0")]
[HttpPut]
public bool UpdateGrpSortCode([Required] UpdateSortCodeUnderCorpInput input)
{
Service.ProductInspectionContentGrp the_service = new Service.ProductInspectionContentGrp();
var bol = the_service.UpdateSortCode(input.CorpID, input.ID, input.SortCode, UserManager.UserID );
return bol;
}
///
/// 更新排序码
///
[Route("UpdateItemSortCode@V1.0")]
[HttpPut]
public bool UpdateItemSortCode([Required] UpdateSortCodeUnderCorpInput input)
{
Service.ProductInspectionContentItem the_service = new Service.ProductInspectionContentItem();
var bol = the_service.UpdateSortCode(input.CorpID, input.ID, input.SortCode, UserManager.UserID);
return bol;
}
///
/// 更新排序码
///
[Route("UpdateValueSortCode@V1.0")]
[HttpPut]
public bool UpdateValueSortCode([Required] UpdateSortCodeUnderCorpInput input)
{
Service.ProductInspectionContentValue the_service = new Service.ProductInspectionContentValue();
var bol = the_service.UpdateSortCode(input.CorpID, input.ID, input.SortCode, UserManager.UserID);
return bol;
}
///
/// 更新排序
///
[Route("UpdateGrpSorter@V1.0")]
[HttpPut]
public bool UpdateGrpSorter([Required] UpdateSorterUnderCorpInput input)
{
if (input.Sorters == null || input.Sorters.Count < 1)
return false;
var list = input.Sorters.Select(x => x.Adapt()).ToList();
Service.ProductInspectionContentGrp the_service = new Service.ProductInspectionContentGrp();
var bol = the_service.UpdateSorter(input.CorpID, list);
return bol;
}
///
/// 更新排序
///
[Route("UpdateItemSorter@V1.0")]
[HttpPut]
public bool UpdateItemSorter([Required] UpdateSorterUnderCorpInput input)
{
if (input.Sorters == null || input.Sorters.Count < 1)
return false;
var list = input.Sorters.Select(x => x.Adapt()).ToList();
Service.ProductInspectionContentItem the_service = new Service.ProductInspectionContentItem();
var bol = the_service.UpdateSorter(input.CorpID, list);
return bol;
}
///
/// 更新排序
///
[Route("UpdateValueSorter@V1.0")]
[HttpPut]
public bool UpdateValueSorter([Required] UpdateSorterUnderCorpInput input)
{
if (input.Sorters == null || input.Sorters.Count < 1)
return false;
var list = input.Sorters.Select(x => x.Adapt()).ToList();
Service.ProductInspectionContentValue the_service = new Service.ProductInspectionContentValue();
var bol = the_service.UpdateSorter(input.CorpID, list);
return bol;
}
///
/// 更新使用状态
///
[Route("UpdateGrpUseStatus@V1.0")]
[HttpPut]
public bool UpdateGrpUseStatus([Required] UpdateUseStatusUnderCorpInput input)
{
Service.ProductInspectionContentGrp the_service = new Service.ProductInspectionContentGrp();
var bol = the_service.UpdateUseStatus(input.CorpID, input.ID, input.UseStatus, UserManager.UserID );
return bol;
}
///
/// 更新使用状态
///
[Route("UpdateItemUseStatus@V1.0")]
[HttpPut]
public bool UpdateItemUseStatus([Required] UpdateUseStatusUnderCorpInput input)
{
Service.ProductInspectionContentItem the_service = new Service.ProductInspectionContentItem();
var bol = the_service.UpdateUseStatus(input.CorpID, input.ID, input.UseStatus, UserManager.UserID);
return bol;
}
///
/// 更新使用状态
///
[Route("UpdateValueUseStatus@V1.0")]
[HttpPut]
public bool UpdateValueUseStatus([Required] UpdateUseStatusUnderCorpInput input)
{
Service.ProductInspectionContentValue the_service = new Service.ProductInspectionContentValue();
var bol = the_service.UpdateUseStatus(input.CorpID, input.ID, input.UseStatus, UserManager.UserID);
return bol;
}
#endregion
#region Delete
///
/// 删除
///
[Route("DeleteGrpByID@V1.0")]
[HttpDelete]
public DeleteReasonOutput DeleteGrpByID([FromQuery][Required] IDUnderCorpInput input)
{
Service.ProductInspectionContentGrp the_service = new Service.ProductInspectionContentGrp();
var bol = the_service.DeleteByID(input.CorpID, input.ID, out string Msg);
return new DeleteReasonOutput() { Success = bol, Reason = Msg };
}
///
/// 删除
///
[Route("DeleteItemByID@V1.0")]
[HttpDelete]
public DeleteReasonOutput DeleteItemByID([FromQuery][Required] IDUnderCorpInput input)
{
Service.ProductInspectionContentItem the_service = new Service.ProductInspectionContentItem();
var bol = the_service.DeleteByID(input.CorpID, input.ID, out string Msg);
return new DeleteReasonOutput() { Success = bol, Reason = Msg };
}
///
/// 删除
///
[Route("DeleteValueByID@V1.0")]
[HttpDelete]
public DeleteReasonOutput DeleteValueByID([FromQuery][Required] IDUnderCorpInput input)
{
Service.ProductInspectionContentValue the_service = new Service.ProductInspectionContentValue();
var bol = the_service.DeleteByID(input.CorpID, input.ID, out string Msg);
return new DeleteReasonOutput() { Success = bol, Reason = Msg };
}
#endregion
}
}