195 lines
11 KiB
C#
195 lines
11 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.Common.Security;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json.Linq;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Consts;
|
|
using Tnb.WarehouseMgr.Entities.Dto;
|
|
using Tnb.WarehouseMgr.Entities.Dto.ErpInputs;
|
|
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
|
|
using Tnb.WarehouseMgr.Entities.Enums;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// 库存报表服务类
|
|
/// </summary>
|
|
[OverideVisualDev(ModuleConsts.MODULE_WMSCARRYSTOCKREPORT_ID)]
|
|
public class WmsCarryStockReportService : BaseWareHouseService
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public WmsCarryStockReportService(ISqlSugarRepository<WmsCarryCode> repository, IUserManager userManager)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_userManager = userManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转库单
|
|
/// </summary>
|
|
[HttpPost, NonUnify, AllowAnonymous]
|
|
public async Task<dynamic> CarryStock(CarryStockInput input)
|
|
{
|
|
var warehouse_id = "";
|
|
var carry_id = "";
|
|
var material_id = "";
|
|
if (!input.queryJson.IsNullOrWhiteSpace())
|
|
{
|
|
warehouse_id = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.warehouse_id));
|
|
carry_id = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.carry_id));
|
|
material_id = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.material_id));
|
|
}
|
|
|
|
|
|
|
|
List<WmsCarryStockReport> items = await _db.Queryable<BasLocation>()
|
|
.LeftJoin<WmsCarryH>((a, b) => b.location_id == a.id)
|
|
.InnerJoin<BasWarehouse>((a, b, c) => a.wh_id == c.id)
|
|
.LeftJoin<WmsCarrystd>((a, b, c, d) => d.id == b.carrystd_id)
|
|
.LeftJoin<WmsCarryCode>((a, b, c, d, e) => e.carry_id == b.id)
|
|
.LeftJoin<BasMaterial>((a, b, c, d, e, f) => f.id == e.material_id)
|
|
.Where((a, b, c, d, e) => a.is_type == ((int)EnumLocationType.存储库位).ToString() && a.is_use == "1"
|
|
&& ((!string.IsNullOrEmpty(b.carry_code) && b.carry_status != "0" && b.carry_status != "6") || string.IsNullOrEmpty(b.carry_code)))
|
|
.WhereIF(!string.IsNullOrEmpty(warehouse_id), (a, b, c, d) => c.id == warehouse_id)
|
|
.WhereIF(!string.IsNullOrEmpty(carry_id), (a, b, c, d) => b.id == carry_id)
|
|
.WhereIF(!string.IsNullOrEmpty(material_id), (a, b, c, d, e, f) => f.id == material_id)
|
|
.OrderByDescending((a, b, c, d, e, f) => b.carry_code)
|
|
.Select((a, b, c, d, e, f) => new WmsCarryStockReport
|
|
{
|
|
仓库名称 = c.whname,
|
|
carry_id = b.id,
|
|
载具编码 = string.IsNullOrEmpty(b.carry_code) ? "空托盘堆垛" : b.carry_code,
|
|
载具名称 = string.IsNullOrEmpty(b.carry_code) ? "空托盘堆垛" : b.carry_name,
|
|
载具状态 = b.is_lock == 1 ? "锁定" : "未锁定",
|
|
载具类型 = d.carrystd_name,
|
|
库位编码 = a.location_code,
|
|
库位名称 = a.location_name,
|
|
库位状态 = b.is_lock == 1 ? "锁定" : "未锁定",
|
|
入库时间 = b.instock_time != null ? b.instock_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
|
|
条码 = e.barcode,
|
|
批次 = e.code_batch,
|
|
数量 = e.codeqty,
|
|
material_id = e.material_id,
|
|
物料编码 = e.material_code,
|
|
物料名称 = f.name,
|
|
单位 = e.unit_id,
|
|
操作用户 = e.create_id,
|
|
绑定时间 = e.create_time != null ? e.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""
|
|
})
|
|
.ToListAsync();
|
|
|
|
|
|
// 料架
|
|
List<WmsCarryStockReport> items_LJ = await _db.Queryable<BasLocation>()
|
|
.LeftJoin<WmsCarryH>((a, b) => b.location_id == a.id)
|
|
.InnerJoin<BasWarehouse>((a, b, c) => a.wh_id == c.id)
|
|
.InnerJoin<WmsCarrystd>((a, b, c, d) => d.id == b.carrystd_id)
|
|
.InnerJoin<WmsCarryD>((a, b, c, d, e) => e.carry_id == b.id)
|
|
.InnerJoin<WmsCarryCode>((a, b, c, d, e, f) => f.carry_id == e.membercarry_id)
|
|
.InnerJoin<BasMaterial>((a, b, c, d, e, f, g) => g.id == f.material_id)
|
|
.InnerJoin<WmsCarryH>((a, b, c, d, e, f, g, h) => h.id == e.membercarry_id)
|
|
.Where((a, b, c, d, e) => a.is_type == ((int)EnumLocationType.存储库位).ToString() && a.is_use == "1" && b.carry_status != "0" && b.carry_status != "6")
|
|
.WhereIF(!string.IsNullOrEmpty(warehouse_id), (a, b, c, d) => c.id == warehouse_id)
|
|
.WhereIF(!string.IsNullOrEmpty(carry_id), (a, b, c, d, e) => b.id == carry_id || e.membercarry_id == carry_id)
|
|
.WhereIF(!string.IsNullOrEmpty(material_id), (a, b, c, d, e, f, g) => g.id == material_id)
|
|
.Select((a, b, c, d, e, f, g, h) => new WmsCarryStockReport
|
|
{
|
|
仓库名称 = c.whname,
|
|
carry_id = b.id,
|
|
载具编码 = b.carry_code,
|
|
载具名称 = b.carry_name,
|
|
子载具编码 = h.carry_code,
|
|
子载具名称 = h.carry_name,
|
|
载具状态 = b.is_lock == 1 ? "锁定" : "未锁定",
|
|
载具类型 = d.carrystd_name,
|
|
库位编码 = a.location_code,
|
|
库位名称 = a.location_name,
|
|
库位状态 = b.is_lock == 1 ? "锁定" : "未锁定",
|
|
入库时间 = b.instock_time != null ? b.instock_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
|
|
条码 = f.barcode,
|
|
批次 = f.code_batch,
|
|
数量 = f.codeqty,
|
|
material_id = f.material_id,
|
|
物料编码 = f.material_code,
|
|
物料名称 = g.name,
|
|
单位 = f.unit_id,
|
|
操作用户 = f.create_id,
|
|
绑定时间 = f.create_time != null ? f.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""
|
|
})
|
|
.ToListAsync();
|
|
|
|
items.AddRange(items_LJ);
|
|
|
|
// d.carrystd_name != "料架"
|
|
var storeMap = items.DistinctBy(x => new { x.carry_id }).ToDictionary(x => new { x.carry_id }, x => x);
|
|
|
|
IEnumerable<WmsCarryStockReportH> result = items.GroupBy(g => new { g.carry_id }).Select(itGroup =>
|
|
{
|
|
_ = storeMap.TryGetValue(itGroup.Key, out WmsCarryStockReport? report);
|
|
WmsCarryStockReportH stockReport = report.Adapt<WmsCarryStockReportH>();
|
|
|
|
if (report.载具编码 != "空托盘堆垛")
|
|
{
|
|
List<WmsCarryStockReport> curCarryCodes = items.FindAll(x => x.carry_id == itGroup.Key.carry_id);
|
|
|
|
List<WmsCarryStockReportCode> wmsCarryStockReportCodes = new List<WmsCarryStockReportCode>();
|
|
int index = 0;
|
|
curCarryCodes.ForEach(x =>
|
|
{
|
|
index++;
|
|
WmsCarryStockReportCode wmsCarryStockReportCode = new();
|
|
wmsCarryStockReportCode.序号 = index;
|
|
//wmsCarryStockReportCode.carry_id = x.carry_id;
|
|
wmsCarryStockReportCode.载具编码 = !string.IsNullOrEmpty(x.子载具编码) ? x.子载具编码 : x.载具编码;
|
|
wmsCarryStockReportCode.载具名称 = !string.IsNullOrEmpty(x.子载具名称) ? x.子载具名称 : x.载具名称;
|
|
//wmsCarryStockReportCode.material_id = x.material_id;
|
|
wmsCarryStockReportCode.物料编号 = x.物料编码;
|
|
wmsCarryStockReportCode.物料名称 = x.物料编码;
|
|
wmsCarryStockReportCode.条码 = x.条码;
|
|
wmsCarryStockReportCode.批次 = x.批次;
|
|
wmsCarryStockReportCode.数量 = x.数量;
|
|
wmsCarryStockReportCode.单位 = x.单位;
|
|
//wmsCarryStockReportCode.创建用户 = x.操作用户;
|
|
wmsCarryStockReportCode.绑定时间 = x.绑定时间;
|
|
|
|
wmsCarryStockReportCodes.Add(wmsCarryStockReportCode);
|
|
});
|
|
|
|
if (input.showDetails == 1)
|
|
{
|
|
stockReport.Details = wmsCarryStockReportCodes;
|
|
}
|
|
}
|
|
|
|
return stockReport;
|
|
});
|
|
|
|
int rowIndex = 0;
|
|
List<WmsCarryStockReportH> pages = result.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList();
|
|
pages.ForEach(page => { rowIndex++; page.序号 = rowIndex; });
|
|
|
|
SqlSugarPagedList<WmsCarryStockReportH> pagedList = new()
|
|
{
|
|
list = pages,
|
|
pagination = new()
|
|
{
|
|
CurrentPage = input.currentPage,
|
|
PageSize = input.pageSize,
|
|
Total = result.Count()
|
|
}
|
|
};
|
|
return PageResult<WmsCarryStockReportH>.SqlSugarPageResult(pagedList);
|
|
}
|
|
}
|
|
}
|