263 lines
14 KiB
C#
263 lines
14 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.Common.Security;
|
|
using JNPF.Systems.Entitys.System;
|
|
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.Entity;
|
|
using Tnb.WarehouseMgr.Entities.Enums;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// 库存报表服务类
|
|
/// </summary>
|
|
[OverideVisualDev(ModuleConsts.MODULE_WMSSTOCKREPORT_ID)]
|
|
public class WmsStockReportService : BaseWareHouseService
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public WmsStockReportService(ISqlSugarRepository<WmsCarryCode> repository, IUserManager userManager)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_userManager = userManager;
|
|
}
|
|
|
|
|
|
[HttpPost, AllowAnonymous]
|
|
public async Task<dynamic> MaterialStock(VisualDevModelListQueryInput input)
|
|
{
|
|
var warehouse_id = "";
|
|
var supplier_code = "";
|
|
var code_batch = "";
|
|
var material_specification = "";
|
|
var container_no = "";
|
|
var material_code = "";
|
|
if (!input.queryJson.IsNullOrWhiteSpace())
|
|
{
|
|
warehouse_id = JObject.Parse(input.queryJson).Value<string>("warehouse_id");
|
|
supplier_code = JObject.Parse(input.queryJson).Value<string>("supplier_code");
|
|
code_batch = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.code_batch));
|
|
material_specification = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.material_specification));
|
|
container_no = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.container_no));
|
|
material_code = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.material_code));
|
|
}
|
|
|
|
List<WmsStockReportH?> result = new List<WmsStockReportH?>();
|
|
if (string.IsNullOrEmpty(supplier_code))
|
|
{
|
|
List<WmsStockReportH> items = await _db.Queryable<WmsCarryCode>().InnerJoin<WmsCarryH>((a, b) => a.carry_id == b.id)
|
|
.InnerJoin<BasLocation>((a, b, c) => b.location_id == c.id).InnerJoin<BasWarehouse>((a, b, c, d) => c.wh_id == d.id)
|
|
.LeftJoin<WmsTempCode>((a, b, c, d, e) => e.barcode == a.barcode)
|
|
.InnerJoin<BasMaterial>((a, b, c, d, e, f) => f.id == a.material_id)
|
|
.LeftJoin<WmsPurchaseD>((a, b, c, d, e, f, g) => e.require_id == g.id)
|
|
.LeftJoin<WmsPurchaseH>((a, b, c, d, e, f, g, h) => h.id == g.bill_id)
|
|
.LeftJoin<DictionaryDataEntity>((a, b, c, d, e, f, g, h, i) => i.EnCode == f.unit_id && i.DictionaryTypeId == WmsWareHouseConst.UNITTYPEID)
|
|
.WhereIF(!string.IsNullOrEmpty(material_specification), (a, b, c, d, e, f) => f.material_specification.Contains(material_specification))
|
|
.WhereIF(!string.IsNullOrEmpty(code_batch), (a, b, c, d, e, f) => a.code_batch.Contains(code_batch))
|
|
.WhereIF(!string.IsNullOrEmpty(container_no), (a, b, c, d, e, f) => f.material_standard.Contains(container_no))
|
|
.WhereIF(!string.IsNullOrEmpty(material_code), (a, b, c, d, e, f) => f.code.Contains(material_code))
|
|
.WhereIF(!string.IsNullOrEmpty(warehouse_id), (a, b, c, d, e, f) => c.wh_id == warehouse_id)
|
|
.Where((a, b, c, d, e, f) => c.is_type == ((int)EnumLocationType.存储库位).ToString())
|
|
.Select((a, b, c, d, e, f, g, h, i) => new WmsStockReportH
|
|
{
|
|
org_id = e.org_id,
|
|
warehouse_id = c.wh_id,
|
|
warehouse_code = d.whcode,
|
|
warehouse_name = d.whname,
|
|
material_name = f.name,
|
|
material_specification = f.material_specification,
|
|
container_no = f.material_standard,
|
|
create_time = a.create_time,
|
|
create_id = a.create_id,
|
|
code_batch = a.code_batch,
|
|
supplier_code = "",
|
|
supplier_name = "",
|
|
qc_res = SqlFunc.IF(a.qc_res.Equals("await") || string.IsNullOrEmpty(a.qc_res)).Return("待检").ElseIF(a.qc_res.Equals("vergeOk")).Return("让步接收").ElseIF(a.qc_res.Equals("ok")).Return("合格").ElseIF(a.qc_res.Equals("no")).Return("不合格").End(""),
|
|
auxprop_gys = a.auxprop_gys,
|
|
auxprop_xph = a.auxprop_xph,
|
|
unit_id = i.FullName,
|
|
}, true).ToListAsync();
|
|
|
|
List<WmsCarryCode> carryCodes = await _db.Queryable<WmsCarryCode>()
|
|
.InnerJoin<WmsCarryH>((a, b) => a.carry_id == b.id)
|
|
.InnerJoin<BasLocation>((a, b, c) => b.location_id == c.id).Select((a, b, c) => new WmsCarryCode
|
|
{
|
|
warehouse_id = c.wh_id
|
|
}, true).ToListAsync();
|
|
var storeMap = items.DistinctBy(x => new { x.warehouse_id, x.material_id, x.code_batch }).ToDictionary(x => new { x.warehouse_id, x.material_id, x.code_batch }, x => x);
|
|
|
|
var group = items.GroupBy(g => new { g.warehouse_id, g.material_id, g.code_batch });
|
|
foreach (var itGroup in group)
|
|
{
|
|
_ = storeMap.TryGetValue(itGroup.Key, out WmsStockReportH? stockReport);
|
|
|
|
List<WmsCarryCode> curCarryCodes = carryCodes.FindAll(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id
|
|
&& x.code_batch == itGroup.Key.code_batch);
|
|
stockReport.codeqty = 0;
|
|
curCarryCodes.ForEach(x =>
|
|
{
|
|
stockReport.codeqty += x.codeqty;
|
|
});
|
|
|
|
//stockReport.Details = curCarryCodes.Adapt<List<WmsStockReportCode>>();
|
|
|
|
//stockReport.codeqty = 0;
|
|
//stockReport.Details.ForEach(x =>
|
|
//{
|
|
// x.id = SnowflakeIdHelper.NextId();
|
|
// x.report_id = stockReport.id;
|
|
// x.warehouse_id = stockReport.warehouse_id;
|
|
// x.warehouse_code = stockReport.warehouse_code;
|
|
// x.warehouse_name = stockReport.warehouse_name;
|
|
// x.material_specification = stockReport.material_specification;
|
|
// x.container_no = stockReport.container_no;
|
|
|
|
// stockReport.codeqty += x.codeqty;
|
|
//});
|
|
//return stockReport;
|
|
result.Add(stockReport);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
List<WmsStockReportH> items = await _db.Queryable<WmsCarryCode>().InnerJoin<WmsCarryH>((a, b) => a.carry_id == b.id)
|
|
.InnerJoin<BasLocation>((a, b, c) => b.location_id == c.id).InnerJoin<BasWarehouse>((a, b, c, d) => c.wh_id == d.id)
|
|
.LeftJoin<WmsTempCode>((a, b, c, d, e) => e.barcode == a.barcode)
|
|
.InnerJoin<BasMaterial>((a, b, c, d, e, f) => f.id == a.material_id)
|
|
.LeftJoin<WmsPurchaseD>((a, b, c, d, e, f, g) => e.require_id == g.id)
|
|
.LeftJoin<WmsPurchaseH>((a, b, c, d, e, f, g, h) => h.id == g.bill_id)
|
|
.LeftJoin<DictionaryDataEntity>((a, b, c, d, e, f, g, h, i) => i.EnCode == f.unit_id && i.DictionaryTypeId == WmsWareHouseConst.UNITTYPEID)
|
|
.WhereIF(!string.IsNullOrEmpty(material_specification), (a, b, c, d, e, f) => f.material_specification.Contains(material_specification))
|
|
.WhereIF(!string.IsNullOrEmpty(code_batch), (a, b, c, d, e, f) => a.code_batch.Contains(code_batch))
|
|
.WhereIF(!string.IsNullOrEmpty(supplier_code), (a, b, c, d, e, f, g, h) => h.supplier_code.Contains(supplier_code))
|
|
.WhereIF(!string.IsNullOrEmpty(container_no), (a, b, c, d, e, f, g, h) => f.material_standard.Contains(container_no))
|
|
.WhereIF(!string.IsNullOrEmpty(material_code), (a, b, c, d, e, f) => f.code.Contains(material_code))
|
|
.WhereIF(!string.IsNullOrEmpty(warehouse_id), (a, b, c, d, e, f) => c.wh_id == warehouse_id)
|
|
.Where((a, b, c, d, e, f) => c.is_type == ((int)EnumLocationType.存储库位).ToString())
|
|
.Select((a, b, c, d, e, f, g, h, i) => new WmsStockReportH
|
|
{
|
|
org_id = e.org_id,
|
|
warehouse_id = c.wh_id,
|
|
warehouse_code = d.whcode,
|
|
warehouse_name = d.whname,
|
|
material_name = f.name,
|
|
material_specification = f.material_specification,
|
|
container_no = f.material_standard,
|
|
create_time = a.create_time,
|
|
create_id = a.create_id,
|
|
code_batch = a.code_batch,
|
|
supplier_code = h.supplier_code,
|
|
supplier_name = h.supplier_name,
|
|
qc_res = SqlFunc.IF(a.qc_res.Equals("await") || string.IsNullOrEmpty(a.qc_res)).Return("待检").ElseIF(a.qc_res.Equals("vergeOk")).Return("让步接收").ElseIF(a.qc_res.Equals("ok")).Return("合格").ElseIF(a.qc_res.Equals("no")).Return("不合格").End(""),
|
|
auxprop_gys = a.auxprop_gys,
|
|
auxprop_xph = a.auxprop_xph,
|
|
unit_id = i.FullName,
|
|
}, true).ToListAsync();
|
|
|
|
List<WmsCarryCode> carryCodes = await _db.Queryable<WmsCarryCode>()
|
|
.InnerJoin<WmsCarryH>((a, b) => a.carry_id == b.id)
|
|
.InnerJoin<BasLocation>((a, b, c) => b.location_id == c.id).Select((a, b, c) => new WmsCarryCode
|
|
{
|
|
warehouse_id = c.wh_id
|
|
}, true).ToListAsync();
|
|
var storeMap = items.DistinctBy(x => new { x.warehouse_id, x.material_id, x.code_batch, x.supplier_code }).ToDictionary(x => new { x.warehouse_id, x.material_id, x.code_batch, x.supplier_code }, x => x);
|
|
|
|
var group = items.GroupBy(g => new { g.warehouse_id, g.material_id, g.code_batch, g.supplier_code });
|
|
foreach (var itGroup in group)
|
|
{
|
|
_ = storeMap.TryGetValue(itGroup.Key, out WmsStockReportH? stockReport);
|
|
|
|
List<WmsStockReportCode> curCarryCodes = carryCodes.Adapt<List<WmsStockReportCode>>().FindAll(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id
|
|
&& x.code_batch == itGroup.Key.code_batch && x.supplier_code == itGroup.Key.supplier_code);
|
|
stockReport.codeqty = 0;
|
|
curCarryCodes.ForEach(x =>
|
|
{
|
|
stockReport.codeqty += x.codeqty;
|
|
});
|
|
result.Add(stockReport);
|
|
}
|
|
}
|
|
|
|
|
|
List<WmsStockReportH> pages = result.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList();
|
|
SqlSugarPagedList<WmsStockReportH> pagedList = new()
|
|
{
|
|
list = pages,
|
|
pagination = new()
|
|
{
|
|
CurrentPage = input.currentPage,
|
|
PageSize = input.pageSize,
|
|
Total = result.Count()
|
|
}
|
|
};
|
|
return PageResult<WmsStockReportH>.SqlSugarPageResult(pagedList);
|
|
}
|
|
|
|
|
|
[HttpPost, AllowAnonymous]
|
|
public async Task<dynamic> OutinStockDetail(VisualDevModelListQueryInput input)
|
|
{
|
|
var code_batch = "";
|
|
var material_specification = "";
|
|
if (!input.queryJson.IsNullOrWhiteSpace())
|
|
{
|
|
code_batch = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.code_batch));
|
|
material_specification = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.material_specification));
|
|
}
|
|
|
|
IEnumerable<dynamic> result = null;
|
|
|
|
result = await _db.Queryable<WmsOutinStockDetail>()
|
|
.InnerJoin<WmsOutinStockCode>((a, b) => a.id == b.bill_d_id)
|
|
.InnerJoin<BasWarehouse>((a, b, c) => a.warehouse_id == c.id)
|
|
.InnerJoin<BasMaterial>((a, b, c, d) => b.material_id == d.id)
|
|
.WhereIF(!string.IsNullOrEmpty(code_batch), (a, b, c, d) => b.code_batch.Contains(code_batch))
|
|
.WhereIF(!string.IsNullOrEmpty(material_specification), (a, b, c, d) => b.material_specification.Contains(material_specification))
|
|
.Select((a, b, c) => new
|
|
{
|
|
act_start_date = a.act_start_date,
|
|
act_end_date = a.act_end_date,
|
|
whname = c.whname,
|
|
material_id = b.material_id,
|
|
material_code = b.material_code,
|
|
material_name = b.material_name,
|
|
material_specification = b.material_specification,
|
|
container_no = b.container_no,
|
|
code_batch = b.code_batch,
|
|
location_id = a.endlocation_id,
|
|
location_code = a.endlocation_code,
|
|
unit_id = b.unit_id,
|
|
unit_code = b.unit_code,
|
|
start_qty = b.start_qty,
|
|
end_qty = b.end_qty,
|
|
type = a.type
|
|
}).ToListAsync();
|
|
|
|
List<dynamic> pages = result.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList();
|
|
SqlSugarPagedList<dynamic> pagedList = new()
|
|
{
|
|
list = pages,
|
|
pagination = new()
|
|
{
|
|
CurrentPage = input.currentPage,
|
|
PageSize = input.pageSize,
|
|
Total = result.Count()
|
|
}
|
|
};
|
|
return PageResult<dynamic>.SqlSugarPageResult(pagedList);
|
|
}
|
|
}
|
|
}
|