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.Data;
|
using System.Data.SqlClient;
|
using System.Dynamic;
|
using System.Text;
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
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<dynamic>> GetListPage(PageQuery query)
|
{
|
var _sbWhere = new StringBuilder(" 1=1" + query.keyWhere);
|
var _sbBy =new StringBuilder(query.sortName + " " + query.sortOrder);
|
|
int currentPage = query.currentPage;
|
int everyPageSize = query.everyPageSize;
|
string sortName = query.sortName;
|
string keyWhere = query.keyWhere;
|
SqlParameter[] parameters =
|
{
|
new("@inCurrentPage", currentPage),
|
new("@inEveryPageSize", everyPageSize),
|
new("@inSortName", sortName),
|
new("@inSortOrder", query.sortOrder),
|
new("@inQueryWhere", keyWhere),
|
new("@inFid", ""),
|
new("@inP1", ""),
|
new("@inP2", ""),
|
new("@inP3", ""),
|
new("@inP4", _userGuid)//当前登录用户guid,将根据他读取仓管员
|
};
|
var dset = new DataSet();
|
var _pglist = new PageList<dynamic>
|
{
|
total = 0,
|
everyPageSize = 0,
|
pages = 0,
|
list = new List<dynamic>()
|
};
|
try
|
{
|
dset = DbHelperSQL.RunProcedure("prc_qcdy_lst", parameters, "0");
|
if (dset != null && dset.Tables.Count > 0 &&
|
dset.Tables[0].Rows.Count > 0) //有数据
|
{
|
var intTotal = int.Parse(dset.Tables[1].Rows[0]["intTotal"].ToString());
|
var pages = intTotal % everyPageSize != 0
|
? intTotal / everyPageSize + 1
|
: intTotal / everyPageSize;
|
_pglist.total = intTotal;
|
_pglist.everyPageSize = everyPageSize;
|
_pglist.pages = pages;
|
var _dy = dset.Tables[0].TableToDynamicList();
|
_pglist.list = _dy;
|
//currentId = dset.Tables[1].Rows[0]["mrCgy"].ToString();
|
}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Debug(ToString(), ex.Message);
|
return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
|
ReturnCode.Exception, "读取失败!");
|
}
|
|
return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
|
ReturnCode.Success, "读取成功");
|
|
//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<ExpandoObject> GetModel(
|
[FromBody] dynamic model)
|
{
|
|
string guid = model.guid.ToString();
|
dynamic m = new ExpandoObject();
|
m.list = new List<dynamic>();
|
m.list2 = new List<dynamic>();
|
SqlParameter[] parameters =
|
{
|
new("@inMainGuid", guid),
|
new("@inP1", ""),
|
new("@inP2", ""),
|
new("@inP3", ""),
|
new("@inP4", ""),
|
new("@userGuid", _userGuid)
|
};
|
var dset = new DataSet();
|
try
|
{
|
dset = DbHelperSQL.RunProcedure("[prc_qcdy_mx]", parameters,
|
"0");
|
if (dset != null && dset.Tables.Count > 0 &&
|
dset.Tables[0].Rows.Count > 0)
|
{
|
var dr = dset.Tables[0].Rows[0];
|
m = dr.RowToDynamic();
|
var _tb = dset.Tables[1].TableToDynamicList();
|
m.list = _tb;
|
//var _tb2 = dset.Tables[2].TableToDynamicList();
|
//m.list2 = _tb2;
|
|
}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Debug(ToString(), ex.Message);
|
}
|
|
if (m != null)
|
return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success,
|
"读取成功!");
|
return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
|
|
//// 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 && b.Barcodetype== "初期物料")
|
.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;
|
}
|
}
|