委外收货
This commit is contained in:
@@ -8,6 +8,7 @@ using JNPF.Common.Extension;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
@@ -15,10 +16,14 @@ using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.BasicData.Interfaces;
|
||||
using Tnb.Common.Utils;
|
||||
using Tnb.ProductionMgr.Entities.Entity;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Entities.Consts;
|
||||
using Tnb.WarehouseMgr.Entities.Dto;
|
||||
@@ -33,20 +38,23 @@ namespace Tnb.WarehouseMgr
|
||||
/// <summary>
|
||||
/// 委外收货订单
|
||||
/// </summary>
|
||||
[OverideVisualDev(ModuleConsts.MODULE_WMSOUTSOURCEORDER_ID)]
|
||||
[OverideVisualDev(ModuleConsts.MODULE_WMSOUTSOURCE_ID)]
|
||||
public class WmsOutsourceService : BaseWareHouseService
|
||||
{
|
||||
private const string ModuleId = ModuleConsts.MODULE_WMSOUTSOURCE_ID;
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IBillRullService _billRullService;
|
||||
private readonly IRunService _runService;
|
||||
private readonly IVisualDevService _visualDevService;
|
||||
private readonly IWareHouseService _wareHouseService;
|
||||
private readonly IThirdApiRecordService _thirdApiRecordService;
|
||||
public WmsOutsourceService(
|
||||
ISqlSugarRepository<WmsOutsourceH> repository,
|
||||
IUserManager userManager,
|
||||
IBillRullService billRullService,
|
||||
IRunService runService,
|
||||
IThirdApiRecordService thirdApiRecordService,
|
||||
IVisualDevService visualDevService, IWareHouseService wareHouseService)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
@@ -55,6 +63,7 @@ namespace Tnb.WarehouseMgr
|
||||
_runService = runService;
|
||||
_visualDevService = visualDevService;
|
||||
_wareHouseService = wareHouseService;
|
||||
_thirdApiRecordService = thirdApiRecordService;
|
||||
}
|
||||
|
||||
public override async Task ModifyAsync(WareHouseUpInput input)
|
||||
@@ -171,5 +180,237 @@ namespace Tnb.WarehouseMgr
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 采购收货
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<dynamic> Purchase(PurchaseAndReceiveUpInput input)
|
||||
{
|
||||
var blFlag = true;
|
||||
try
|
||||
{
|
||||
WmsPurchaseH wmsPurchaseH = await _db.Queryable<WmsPurchaseH>().Where(r => r.bill_code == input.bill_code).FirstAsync();
|
||||
if (wmsPurchaseH.make_method == "自制")
|
||||
{
|
||||
throw Oops.Bah("自制采购收货单不能操作此按钮");
|
||||
}
|
||||
await _db.Ado.BeginTranAsync();
|
||||
WmsInstockH? instock = null;
|
||||
var purchaseDs = await PurchaseAndSaleUpdate(input);
|
||||
List<WmsInstockD> instockDs = new();
|
||||
if (purchaseDs?.Count > 0)
|
||||
{
|
||||
instock = input.Adapt<WmsInstockH>();
|
||||
instock.id = SnowflakeIdHelper.NextId();
|
||||
instock.bill_code = await _billRullService.GetBillNumber(WmsWareHouseConst.WMS_INSTOCK_ENCODE);
|
||||
instock.create_id = _userManager.UserId;
|
||||
instock.create_time = DateTime.Now;
|
||||
instock.org_id = _userManager.User.OrganizeId;
|
||||
if (instock.source_code != null)
|
||||
{
|
||||
instock.sync_status = WmsWareHouseConst.SYNC_STATUS__NOTSYNC;
|
||||
}
|
||||
else
|
||||
{
|
||||
instock.sync_status = WmsWareHouseConst.SYNC_STATUS_NONEEDSYNC;
|
||||
}
|
||||
instock.audit_status = 0;
|
||||
instock.print_status = "0";
|
||||
instock.is_check = 0;
|
||||
await _db.Insertable(instock).ExecuteCommandAsync();
|
||||
|
||||
instockDs = purchaseDs.Adapt<List<WmsInstockD>>();
|
||||
instockDs.ForEach(instockD =>
|
||||
{
|
||||
instockD.bill_id = instock.id;
|
||||
instockD.create_id = _userManager.UserId;
|
||||
instockD.create_time = DateTime.Now;
|
||||
instockD.org_id = _userManager.User.OrganizeId;
|
||||
});
|
||||
await _db.Insertable(instockDs).ExecuteCommandAsync();
|
||||
|
||||
var purchase = await _db.Queryable<WmsPurchaseH>().FirstAsync(it => it.id == purchaseDs.First().bill_id);
|
||||
|
||||
if (string.IsNullOrEmpty(purchase.supplier_id))
|
||||
{
|
||||
BasSupplier basSupplier = await _db.Queryable<BasSupplier>().Where(x => x.supplier_code == purchase.supplier_code).FirstAsync();
|
||||
if (basSupplier != null)
|
||||
{
|
||||
await _db.Updateable<WmsPurchaseH>()
|
||||
.SetColumns(x => x.supplier_id == basSupplier.id)
|
||||
.Where(x => x.id == purchase.id)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
purchase.supplier_id = basSupplier.id;
|
||||
}
|
||||
}
|
||||
|
||||
//purchase.supplier_code
|
||||
|
||||
|
||||
|
||||
List<WmsPurchaseD> dList = await _db.Queryable<WmsPurchaseD>().Where(x => x.bill_id == purchaseDs.First().bill_id).OrderBy(x => x.id).ToListAsync();
|
||||
List<String> materialIds = purchaseDs.Select(x => x.material_id).Distinct().ToList();
|
||||
List<String> unitCodes = purchaseDs.Select(x => x.unit_id).Distinct().ToList();
|
||||
List<DictionaryDataEntity> unitDatas = await _db.Queryable<DictionaryTypeEntity>()
|
||||
.LeftJoin<DictionaryDataEntity>((x, y) => x.Id == y.DictionaryTypeId)
|
||||
.Where((x, y) => x.EnCode == DictConst.MeasurementUnit && (unitCodes.Contains(y.EnCode) || unitCodes.Contains(y.Id)))
|
||||
.Select((x, y) => y)
|
||||
.ToListAsync();
|
||||
List<WmsErpWarehouserelaH> erpWarehouserelaHs = await _db.Queryable<WmsErpWarehouserelaH>().Where(x => x.id != null).ToListAsync();
|
||||
WmsPurchaseOrderH wmsPurchaseOrderH = await _db.Queryable<WmsPurchaseOrderH>().SingleAsync(x => x.id == purchase.erp_bill_code);
|
||||
//todo 先取采购订单第一条
|
||||
//WmsPurchaseOrderD wmsPurchaseOrderDs = await _db.Queryable<WmsPurchaseOrderD>().FirstAsync(x=>x.fk_wms_purchase_order_id==purchase.erp_bill_code);
|
||||
|
||||
//自制的不调erp接口
|
||||
if (!string.IsNullOrEmpty(wmsPurchaseOrderH.erp_bill_code))
|
||||
{
|
||||
List<string> ids = new List<string>();
|
||||
// ids.Add(_userManager.UserId);
|
||||
// ids.Add(WmsWareHouseConst.AdministratorUserId);
|
||||
ids.Add(WmsWareHouseConst.AdministratorOrgId);
|
||||
ids.Add(purchase.warehouse_id);
|
||||
ids.AddRange(materialIds);
|
||||
ids.Add(wmsPurchaseOrderH.supplier_id);
|
||||
ids.AddRange(unitDatas.Select(x => x.Id).ToList());
|
||||
|
||||
string userId = _userManager.UserId ?? WmsWareHouseConst.AdministratorUserId;
|
||||
ids.Add(userId);
|
||||
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x => ids.Contains(x.table_id)).ToListAsync();
|
||||
// string erpCreateId = erpExtendFields.Find(x=>x.table_id==userId)?.user_id ?? WmsWareHouseConst.ERPUSERID;
|
||||
string erpCreateId = WmsWareHouseConst.ERPUSERID;
|
||||
ErpExtendField erpOrg = erpExtendFields.Find(x => x.table_id == (WmsWareHouseConst.AdministratorOrgId));
|
||||
string nowStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
List<Dictionary<string, object>> requestData = new List<Dictionary<string, object>>();
|
||||
Dictionary<string, object> erpRequestData = new Dictionary<string, object>();
|
||||
erpRequestData.Add("approver", erpCreateId);
|
||||
erpRequestData.Add("billmaker", erpCreateId);
|
||||
erpRequestData.Add("creationtime", nowStr);
|
||||
erpRequestData.Add("creator", erpCreateId);
|
||||
erpRequestData.Add("dbilldate", purchase.create_time.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
erpRequestData.Add("dmakedate", nowStr);
|
||||
erpRequestData.Add("ntotalastnum", purchaseDs.Sum(x => x.purchase_arriveqty));
|
||||
erpRequestData.Add("pk_arriveorder", null);
|
||||
// erpRequestData.Add("pk_dept","1001A1100000001JFOPQ");
|
||||
// erpRequestData.Add("pk_dept_v","0001A1100000000AOMIQ");
|
||||
erpRequestData.Add("Pk_receivepsndoc", erpCreateId);
|
||||
erpRequestData.Add("pk_org", erpOrg.pk_org);
|
||||
erpRequestData.Add("pk_org_v", erpOrg.pk_org_v);
|
||||
erpRequestData.Add("pk_group", erpOrg.pk_group);
|
||||
erpRequestData.Add("pk_pupsndoc", "");
|
||||
erpRequestData.Add("csourceid", wmsPurchaseOrderH?.erp_pk ?? "");
|
||||
erpRequestData.Add("pk_purchaseorg", erpOrg.pk_org);
|
||||
erpRequestData.Add("pk_purchaseorg_v", erpOrg.pk_org_v);
|
||||
erpRequestData.Add("pk_supplier", erpExtendFields.Find(x => x.table_id == purchase.supplier_id)?.supplier_id ?? "");//先写死
|
||||
erpRequestData.Add("pk_supplier_v", erpExtendFields.Find(x => x.table_id == purchase.supplier_id)?.supplier_vid ?? "");//先写死
|
||||
erpRequestData.Add("vbillcode", purchase.bill_code);
|
||||
erpRequestData.Add("vmemo", purchase.remark);
|
||||
erpRequestData.Add("vtrantypecode", "");
|
||||
|
||||
List<Dictionary<string, object>> erpRequestDataDetails = new List<Dictionary<string, object>>();
|
||||
foreach (WmsPurchaseD item in dList)
|
||||
{
|
||||
erpRequestDataDetails.Add(new Dictionary<string, object>()
|
||||
{
|
||||
["castunitid"] = erpExtendFields.Find(x => x.table_id == (unitDatas.Find(x => x.EnCode == item.unit_id || x.Id == item.unit_id)?.Id ?? ""))?.cunitid ?? "",
|
||||
["cfirstbid"] = wmsPurchaseOrderH?.erp_pk ?? "",
|
||||
["cfirstid"] = item.erp_purchase_order_d_pk,
|
||||
["cfirsttypecode"] = "",
|
||||
["crececountryid"] = "0001Z010000000079UJJ",
|
||||
["crowno"] = item.erp_purchase_order_d_lineno,
|
||||
["csendcountryid"] = "0001Z010000000079UJJ",
|
||||
["csourcetypecode"] = "",
|
||||
["ctaxcountryid"] = "0001Z010000000079UJJ",
|
||||
["cunitid"] = erpExtendFields.Find(x => x.table_id == (unitDatas.Find(x => x.EnCode == item.unit_id || x.Id == item.unit_id)?.Id ?? ""))?.cunitid ?? "",
|
||||
["dbilldate"] = purchase.create_time.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
["dplanreceivedate"] = purchase.create_time.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
["dproducedate"] = purchase.create_time.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
// ["fbuysellflag"] = 2,
|
||||
["fproductclass"] = 1,
|
||||
// ["naccumchecknum"] = 0,
|
||||
// ["nastnum"] = item.purchase_arriveqty,
|
||||
["nnum"] = item.purchase_arriveqty,
|
||||
// ["nplanastnum"] = 0,
|
||||
["nplannum"] = item.purchase_qty,
|
||||
["pk_apfinanceorg"] = erpOrg.corpoid,
|
||||
["pk_apfinanceorg_v"] = erpOrg.corpvid,
|
||||
["pk_arriveorder"] = null,
|
||||
["pk_arriveorder_b"] = null,
|
||||
["pk_group"] = erpOrg.pk_group,
|
||||
["pk_material"] = erpExtendFields.Find(x => x.table_id == item.material_id)?.cmaterialoid ?? "",
|
||||
["pk_order"] = wmsPurchaseOrderH?.erp_pk ?? "",
|
||||
["pk_order_b"] = item.erp_purchase_order_d_pk,
|
||||
["pk_org"] = erpOrg.pk_org,
|
||||
["pk_org_v"] = erpOrg.pk_org_v,
|
||||
["pk_psfinanceorg"] = erpOrg.corpoid,
|
||||
["pk_psfinanceorg_v"] = erpOrg.corpvid,
|
||||
// ["pk_receivestore"] = erpExtendFields.Find(x=>x.table_id==purchase.warehouse_id)?.cotherwhid ?? "",
|
||||
// ["pk_receivestore"] = erpWarehouserelaHs.Find(x => x.erp_warehousecode == item.erp_wh_type)?.erp_warehouseid ?? "",
|
||||
["pk_receivestore"] = item.erp_wh_type,
|
||||
["pk_reqstoorg"] = erpOrg.pk_org,
|
||||
["pk_reqstoorg_v"] = erpOrg.pk_org_v,
|
||||
["pk_srcmaterial"] = erpExtendFields.Find(x => x.table_id == item.material_id)?.cmaterialoid ?? "",
|
||||
["vbatchcode"] = item.code_batch,
|
||||
["Vfree1"] = item.code_batch,
|
||||
["mes_detail_id"] = item.id,
|
||||
["bpresent"] = item.gift == 1,
|
||||
["csourceid"] = wmsPurchaseOrderH?.erp_pk ?? "",
|
||||
["vsourcecode"] = wmsPurchaseOrderH.erp_bill_code,
|
||||
["csourcebid"] = item.erp_purchase_order_d_pk,
|
||||
["IsType"] = 0,
|
||||
["csourcetypecode"] = null,
|
||||
["vsourcerowno"] = null,
|
||||
["vsourcetrantype"] = null,
|
||||
["cproductorid"] = item.production_unit,
|
||||
});
|
||||
}
|
||||
erpRequestData.Add("dtls", erpRequestDataDetails);
|
||||
requestData.Add(erpRequestData);
|
||||
BasFactoryConfig config = await _db.Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.BIPURL);
|
||||
|
||||
ThirdWebapiRecord thirdWebapiRecord = new ThirdWebapiRecord();
|
||||
thirdWebapiRecord.id = SnowflakeIdHelper.NextId();
|
||||
thirdWebapiRecord.third_name = WmsWareHouseConst.BIP;
|
||||
thirdWebapiRecord.name = "采购到货";
|
||||
thirdWebapiRecord.method = "POST";
|
||||
// thirdWebapiRecord.url = config.value+"uapws/rest/purarrvial/save";
|
||||
thirdWebapiRecord.url = WmsWareHouseConst.BIP_DOMAIN + "uapws/rest/purarrvial/save";
|
||||
thirdWebapiRecord.request_data = JsonConvert.SerializeObject(erpRequestData);
|
||||
thirdWebapiRecord.create_time = DateTime.Now;
|
||||
thirdWebapiRecord.remark = $"【WmsPurchaseService Purchase】erp采购订单:{wmsPurchaseOrderH.erp_bill_code}";
|
||||
|
||||
await _db.Insertable(thirdWebapiRecord).ExecuteCommandAsync();
|
||||
BasFactoryConfig callErp = await _db.Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.CALLERP);
|
||||
if (callErp.value == "1")
|
||||
{
|
||||
await _thirdApiRecordService.Send(new List<ThirdWebapiRecord> { thirdWebapiRecord }, "自动", _db);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//通知Mes接口
|
||||
//_ = SyncMesData(instock.id, instockDs.Select(x => x.material_id).ToList(), EnumTriggerEvent.入厂检按物料编号);
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
blFlag = false;
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
Log.Error("采购收货失败", ex);
|
||||
throw;
|
||||
}
|
||||
return await Task.FromResult(blFlag);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user