using Gs.Entity.BaseInfo;
|
using Gs.Entity.Sys;
|
using Gs.Entity.Warehouse;
|
using Gs.Toolbox;
|
using Gs.Toolbox.ApiCore.Abstract.Mvc;
|
using Gs.Toolbox.ApiCore.Common.Mvc;
|
using Gs.Toolbox.ApiCore.Group;
|
using Gs.Warehouse.Dto;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using SqlSugar;
|
using System.Text;
|
|
namespace Gs.Warehouse.Services;
|
|
[ApiGroup(ApiGroupNames.PerMission)]
|
public class MesInvItemBarcodesManager : Repository<MesInvItemBarcodes>,
|
IRomteService
|
{
|
private readonly IHttpContextAccessor _http;
|
|
private readonly string _userCode, _userGuid, _orgFids;
|
|
public MesInvItemBarcodesManager(IHttpContextAccessor httpContextAccessor)
|
{
|
_http = httpContextAccessor;
|
(_userCode, _userGuid, _orgFids) =
|
UtilityHelper.GetUserGuidAndOrgGuid(_http);
|
}
|
|
/// <summary>
|
/// 查询列表,支持分页
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<PageList<MesItems>> GetListPage(PageQuery query)
|
{
|
var _sbWhere = new StringBuilder(" 1=1" + query.keyWhere);
|
var _sbBy =new StringBuilder(query.sortName + " " + query.sortOrder);
|
var pageList = new PageList<MesItems>();
|
try
|
{
|
var totalCount = GetPageTotalCount(null, query, out var itemsList, _sbWhere, _sbBy);
|
pageList = new PageList<MesItems>(itemsList, totalCount,
|
query.everyPageSize);
|
return ReturnDto<PageList<MesItems>>.QuickReturn(pageList,
|
ReturnCode.Success, "读取成功");
|
}
|
catch (Exception ex)
|
{
|
return ReturnDto<PageList<MesItems>>.QuickReturn(pageList,
|
ReturnCode.Default, ex.Message);
|
}
|
}
|
|
private int GetPageTotalCount(Guid? guid, PageQuery query,
|
out List<MesItems> itemsList,System.Text.StringBuilder _sbWhere, StringBuilder _sbBy)
|
{
|
var totalCount = 0;
|
itemsList = Db.Queryable<MesItems, MesUnit, SysOrganization>(
|
(a, b, org) =>
|
new object[]
|
{
|
JoinType.Left, a.Storeunit == b.Id.ToString(),
|
JoinType.Left, a.FSubsidiary == org.Fid.ToString()
|
})
|
.WhereIF(UtilityHelper.CheckGuid(guid),
|
(a, b, org) => a.Guid == guid)
|
.Select((a, b, org) => new MesItems
|
{
|
Guid = a.Guid,
|
Id = a.Id,
|
Fumbrella = a.Fumbrella,
|
FSubsidiary = "(" + org.FNumber + ")" + org.Name,
|
FSubsidiaryFId = org.Fid,
|
ItemNo = a.ItemNo,
|
ItemId = a.ItemId,
|
ItemName = a.ItemName,
|
ItemModel = a.ItemModel,
|
ItemUnit = b.Fname,
|
PsnQty = 0, // Assuming decimal type
|
ICount = 0, // Assuming int type
|
WorkNo = "",
|
SuppNo = "",
|
SuppName = "",
|
CreateDate1 = DateTime.Now.ToString("yyyy-MM-dd"),
|
Tc = "否"
|
}).Where(_sbWhere.ToString())
|
.OrderBy(_sbBy.ToString())
|
.ToPageList(query.currentPage, query.everyPageSize,
|
ref totalCount);
|
return totalCount;
|
}
|
|
/// <summary>
|
/// 根据主表id读取主表和子表
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<InitialBarcode> GetModel(
|
[FromBody] MesItems model)
|
{
|
// var m = base.GetById(model.Guid);
|
var query = new PageQuery
|
{
|
currentPage = 1,
|
everyPageSize = 1
|
};
|
System.Text.StringBuilder sb = new StringBuilder();
|
System.Text.StringBuilder order = new StringBuilder();
|
order.Append(" org.FNumber asc ,a.item_no asc");
|
var pageTotalCount = GetPageTotalCount(model.Guid, query, out var itemsList, sb, order);
|
|
var barcode = new InitialBarcode();
|
|
if (pageTotalCount == 0)
|
return ReturnDto<InitialBarcode>.QuickReturn(barcode,
|
ReturnCode.Default,
|
"读取失败!");
|
|
var mesItems = itemsList.FirstOrDefault();
|
|
|
if (mesItems == null)
|
return ReturnDto<InitialBarcode>.QuickReturn(barcode,
|
ReturnCode.Default,
|
"读取失败!");
|
|
barcode.from = mesItems;
|
|
barcode.barcodes = GetMesInvItemBarcodes(mesItems.Id);
|
|
return ReturnDto<InitialBarcode>.QuickReturn(barcode,
|
ReturnCode.Success, "读取成功!");
|
}
|
|
private List<MesInvItemBarcodes> GetMesInvItemBarcodes(long? ItemId)
|
{
|
var result = Db
|
.Queryable<MesInvItemBarcodes, MesInvItemStocks, MesDepots, MesSupplier>(
|
(b, c, d, e) => new object[]
|
{
|
JoinType.Left, b.ItemBarcode == c.ItemBarcode,
|
JoinType.Left, c.DepotId == d.DepotId,
|
JoinType.Left,e.Id.ToString()==b.SuppID
|
})
|
.Where((b, c, d) => b.ComeFlg == 0 && b.ItemId == ItemId)
|
.OrderBy((b) => b.ItemBarcode)//写Select前面用法,正常都这么用
|
.Select((b, c, d, e) => new MesInvItemBarcodes
|
{
|
Guid = b.Guid,
|
ItemBarcode = b.ItemBarcode,
|
TrLotno = b.TrLotno,
|
LotNo = b.LotNo,
|
Quantity = b.Quantity,
|
LotDate = b.LotDate,
|
CreateBy = b.CreateBy,
|
SuppID = e.SuppName,
|
CreateDate = b.CreateDate,
|
DepotSectionsCode = c.DepotSectionsCode,
|
DepotsCode = c.DepotsCode,
|
DepotName = d.DepotName,
|
RkUser = c.IndepUserCode,
|
RkDate = c.IndepDate,
|
InChk = string.IsNullOrEmpty(c.IndepUserCode) ? false : true
|
})
|
.ToList();
|
return result;
|
}
|
}
|