盘点单
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Transactions;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities.Dto.ErpInputs
|
||||
{
|
||||
public class InventorycheckInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 盘点单号
|
||||
/// </summary>
|
||||
public string? erp_bill_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部门编码
|
||||
/// </summary>
|
||||
public string? dept_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 业务员编码
|
||||
/// </summary>
|
||||
public string? biller { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 盘点仓库编码
|
||||
/// </summary>
|
||||
public string? warehouse_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主表pk
|
||||
/// </summary>
|
||||
public string? erp_pk { get; set; }
|
||||
|
||||
public List<InventorycheckInputDetail> details { get; set; }
|
||||
}
|
||||
public class InventorycheckInputDetail
|
||||
{
|
||||
/// <summary>
|
||||
/// 行号
|
||||
/// </summary>
|
||||
public string? lineno { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物品代码
|
||||
/// </summary>
|
||||
public string? material_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单位代码
|
||||
/// </summary>
|
||||
public string? unit_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 采购数量
|
||||
/// </summary>
|
||||
public decimal? qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 批次
|
||||
/// </summary>
|
||||
public string? code_batch { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 生产日期
|
||||
/// </summary>
|
||||
public DateTime? production_date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子表主键
|
||||
/// </summary>
|
||||
public string erp_line_pk { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 盘点明细
|
||||
/// </summary>
|
||||
[SugarTable("wms_inventorycheck_d")]
|
||||
public partial class WmsInventorycheckD : BaseEntity<string>
|
||||
{
|
||||
public WmsInventorycheckD()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 盘点单id
|
||||
/// </summary>
|
||||
public string? bill_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
public string? modify_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime? modify_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属组织
|
||||
/// </summary>
|
||||
public string? org_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物料id
|
||||
/// </summary>
|
||||
public string? material_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物料编号
|
||||
/// </summary>
|
||||
public string? material_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物料名称
|
||||
/// </summary>
|
||||
public string? material_name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 规格型号
|
||||
/// </summary>
|
||||
public string? material_specification { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 批次
|
||||
/// </summary>
|
||||
public string? code_batch { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单位id
|
||||
/// </summary>
|
||||
public string? unit_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单位编码
|
||||
/// </summary>
|
||||
public string? unit_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数量
|
||||
/// </summary>
|
||||
public decimal? qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 生产日期
|
||||
/// </summary>
|
||||
public DateTime? production_date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// erp_line_pk
|
||||
/// </summary>
|
||||
public string? erp_line_pk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 行号
|
||||
/// </summary>
|
||||
public string? lineno { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 实际数量
|
||||
/// </summary>
|
||||
public decimal? actual_qty { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 盘点单
|
||||
/// </summary>
|
||||
[SugarTable("wms_inventorycheck_h")]
|
||||
public partial class WmsInventorycheckH : BaseEntity<string>
|
||||
{
|
||||
public WmsInventorycheckH()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
public string? modify_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime? modify_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属组织
|
||||
/// </summary>
|
||||
public string? org_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 盘点单号
|
||||
/// </summary>
|
||||
public string? bill_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库id
|
||||
/// </summary>
|
||||
public string? warehouse_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库编码
|
||||
/// </summary>
|
||||
public string? warehouse_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库名称
|
||||
/// </summary>
|
||||
public string? warehouse_name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部门编码
|
||||
/// </summary>
|
||||
public string? dept_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 业务员编码
|
||||
/// </summary>
|
||||
public string? biller { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// erp_pk
|
||||
/// </summary>
|
||||
public string? erp_pk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// erp_bill_code
|
||||
/// </summary>
|
||||
public string? erp_bill_code { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 盘点记录
|
||||
/// </summary>
|
||||
[SugarTable("wms_inventorycheck_record")]
|
||||
public partial class WmsInventorycheckRecord : BaseEntity<string>
|
||||
{
|
||||
public WmsInventorycheckRecord()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
public string? modify_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime? modify_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 盘点单id
|
||||
/// </summary>
|
||||
public string? bill_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 盘点单明细id
|
||||
/// </summary>
|
||||
public string? mat_bill_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 载具id
|
||||
/// </summary>
|
||||
public string? carry_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 载具编码
|
||||
/// </summary>
|
||||
public string? carry_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 库位id
|
||||
/// </summary>
|
||||
public string? location_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 库位编码
|
||||
/// </summary>
|
||||
public string? location_code { get; set; }
|
||||
|
||||
}
|
||||
@@ -2244,6 +2244,158 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 盘点单
|
||||
/// </summary>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Entities.Dto.Outputs.Result> Inventorycheck(InventorycheckInput input)
|
||||
{
|
||||
|
||||
LoggerErp2Mes.LogInformation($"【Inventorycheck】ERP传入数据:{JsonConvert.SerializeObject(input)}");
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【Inventorycheck】主表主键不能为空!");
|
||||
throw new AppFriendlyException($@"主表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【Inventorycheck】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsInventorychecksDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsInventorychecksDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【Inventorycheck】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
|
||||
WmsErpWarehouserelaH wmsErpWarehouserelaH = await db.Queryable<WmsErpWarehouserelaH>().Where(r => r.erp_warehousecode == input.warehouse_code).FirstAsync();
|
||||
if (wmsErpWarehouserelaH == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【Inventorycheck】不存在erp仓库类型{input.warehouse_code}对应wms系统的映射关系!");
|
||||
throw new AppFriendlyException($@"不存在erp仓库类型{input.warehouse_code}对应wms系统的映射关系!", 500);
|
||||
}
|
||||
|
||||
string warehouse_code = wmsErpWarehouserelaH.wms_warehousecode;
|
||||
|
||||
BasWarehouse warehouse = await db.Queryable<BasWarehouse>().Where(r => r.whcode == warehouse_code).FirstAsync();
|
||||
if (warehouse == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【Inventorycheck】无法查询到出库仓库{warehouse_code}的档案记录!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到出库仓库{warehouse_code}的档案记录!");
|
||||
}
|
||||
await db.Ado.BeginTranAsync();
|
||||
|
||||
// 判断是否重复传输
|
||||
WmsInventorycheckH wmsInventorycheckHRep = await db.Queryable<WmsInventorycheckH>().Where(r => r.erp_pk == input.erp_pk).FirstAsync();
|
||||
if (wmsInventorycheckHRep != null)
|
||||
{
|
||||
// 判断单据是否已经下发
|
||||
List<WmsInventorycheckD> _wmsSaleDs = await db.Queryable<WmsInventorycheckD>().Where(r => r.bill_id == wmsInventorycheckHRep.id).ToListAsync();
|
||||
bool isxf = _wmsSaleDs.Where(r => r.actual_qty > 0).Any();
|
||||
if (isxf)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【Inventorycheck】wms已下发使用盘点单{input.erp_bill_code}!");
|
||||
throw new AppFriendlyException($@"wms已下发使用盘点单{input.erp_bill_code}!", 500);
|
||||
}
|
||||
else // 删除数据重新插入
|
||||
{
|
||||
await db.Deleteable<WmsInventorycheckH>().Where(r => r.id == wmsInventorycheckHRep.id).ExecuteCommandAsync();
|
||||
await db.Deleteable<WmsInventorycheckD>().Where(r => r.bill_id == wmsInventorycheckHRep.id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
WmsInventorycheckH wmsInventorycheckH = new WmsInventorycheckH();
|
||||
string Code = await _billRuleService.GetBillNumber("CheckStockCode");
|
||||
|
||||
wmsInventorycheckH.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsInventorycheckH.create_time = DateTime.Now;
|
||||
wmsInventorycheckH.org_id = WmsWareHouseConst.AdministratorOrgId;
|
||||
wmsInventorycheckH.bill_code = Code;
|
||||
|
||||
wmsInventorycheckH.warehouse_id = warehouse.id;
|
||||
wmsInventorycheckH.warehouse_code = warehouse.whcode;
|
||||
wmsInventorycheckH.warehouse_name = warehouse.whname;
|
||||
wmsInventorycheckH.dept_code = input.dept_code;
|
||||
wmsInventorycheckH.biller = input.biller;
|
||||
wmsInventorycheckH.erp_bill_code = input.erp_bill_code;
|
||||
wmsInventorycheckH.erp_pk = input.erp_pk;
|
||||
|
||||
await db.Insertable(wmsInventorycheckH).ExecuteCommandAsync();
|
||||
|
||||
|
||||
List<WmsInventorycheckD> wmsInventorycheckDs = new List<WmsInventorycheckD>();
|
||||
foreach (var detail in input.details)
|
||||
{
|
||||
WmsInventorycheckD wmsInventorycheckD = new WmsInventorycheckD();
|
||||
|
||||
wmsInventorycheckD.bill_id = wmsInventorycheckH.id;
|
||||
wmsInventorycheckD.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsInventorycheckD.create_time = DateTime.Now;
|
||||
wmsInventorycheckD.org_id = WmsWareHouseConst.AdministratorOrgId;
|
||||
wmsInventorycheckD.production_date = detail.production_date;
|
||||
|
||||
var material = await db.Queryable<BasMaterial>().Where(p => p.code == detail.material_code).FirstAsync();
|
||||
if (material != null)
|
||||
{
|
||||
wmsInventorycheckD.material_id = material.id;
|
||||
wmsInventorycheckD.material_code = material.code;
|
||||
wmsInventorycheckD.material_name = material.name;
|
||||
wmsInventorycheckD.material_specification = material.material_specification;
|
||||
}
|
||||
|
||||
wmsInventorycheckD.qty = detail.qty;
|
||||
wmsInventorycheckD.actual_qty = 0;
|
||||
wmsInventorycheckD.code_batch = detail.code_batch;
|
||||
wmsInventorycheckD.erp_line_pk = detail.erp_line_pk;
|
||||
wmsInventorycheckD.lineno = detail.lineno;
|
||||
|
||||
var erpExtendField = await db.Queryable<ErpExtendField>().InnerJoin<DictionaryDataEntity>((a, b) => a.table_id == b.Id).Where((a, b) => b.EnCode == detail.unit_code).Select((a, b) => b).FirstAsync();
|
||||
if (erpExtendField != null)
|
||||
{
|
||||
wmsInventorycheckD.unit_id = erpExtendField.Id;
|
||||
wmsInventorycheckD.unit_code = erpExtendField.EnCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【Inventorycheck】表体明细中单位{detail.unit_code}在wms系统中未找到!");
|
||||
throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500);
|
||||
}
|
||||
|
||||
wmsInventorycheckDs.Add(wmsInventorycheckD);
|
||||
}
|
||||
|
||||
await db.Insertable(wmsInventorycheckDs).ExecuteCommandAsync();
|
||||
|
||||
await db.Ado.CommitTranAsync();
|
||||
|
||||
LoggerErp2Mes.LogInformation($"【Inventorycheck】成功生成单据:{Code}");
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LoggerErp2Mes.LogError($"【Inventorycheck】{ex.Message}");
|
||||
LoggerErp2Mes.LogError($"【Inventorycheck】{ex.StackTrace}");
|
||||
await db.Ado.RollbackTranAsync();
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected Task<Entities.Dto.Outputs.Result> ToApiResult(HttpStatusCode statusCode, string msg)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user