232 lines
14 KiB
C#
232 lines
14 KiB
C#
using System.Collections;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.EventBus;
|
|
using JNPF.Logging;
|
|
using JNPF.Systems.Entitys.System;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using Tnb.ProductionMgr;
|
|
using Tnb.WarehouseMgr.Entities.Entity;
|
|
using Tnb.WarehouseMgr.Entities.Consts;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.BasicData;
|
|
using Tnb.ProductionMgr.Entities.Entity;
|
|
using ModuleConst = Tnb.ProductionMgr.ModuleConst;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// 采购收货子表
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
[OverideVisualDev(ModelId)]
|
|
// [OverideVisualDev(ModuleId)]
|
|
public class WmsPurchaseDService : IOverideVisualDevService, IDynamicApiController, ITransient
|
|
{
|
|
|
|
public const string ModelId = "35017584657685";
|
|
private readonly ISqlSugarRepository<WmsPurchaseD> _repository;
|
|
private readonly DataBaseManager _dbManager;
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
private readonly IDictionaryDataService _dictionaryDataService;
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
|
|
public WmsPurchaseDService(
|
|
ISqlSugarRepository<WmsPurchaseD> repository,
|
|
DataBaseManager dbManager,
|
|
IUserManager userManager,
|
|
IDictionaryDataService dictionaryDataService)
|
|
{
|
|
_repository = repository;
|
|
_db = repository.AsSugarClient();
|
|
_dbManager = dbManager;
|
|
_userManager = userManager;
|
|
_dictionaryDataService = dictionaryDataService;
|
|
}
|
|
|
|
public async Task<String> SaveCheckResult(Dictionary<string, string> dic)
|
|
{
|
|
try
|
|
{
|
|
string id = dic["id"];
|
|
string qcRes = dic["qc_res"];
|
|
|
|
WmsPurchaseD wmsPurchaseD = await _db.Queryable<WmsPurchaseD>().SingleAsync(x => x.id == id);
|
|
|
|
string purchaseHId = wmsPurchaseD?.bill_id ?? "";
|
|
WmsPurchaseH wmsPurchaseH = await _db.Queryable<WmsPurchaseH>().SingleAsync(x => x.id == purchaseHId);
|
|
|
|
List<WmsOutinStockDetail> wmsOutinStockDetails = await _db.Queryable<WmsOutinStockDetail>()
|
|
.Where(x => x.source_detail_id == wmsPurchaseD.id && x.source_type == WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID)
|
|
.ToListAsync();
|
|
List<Dictionary<string, object>> requestData = new List<Dictionary<string, object>>();
|
|
List<string> carryIds = wmsOutinStockDetails.Select(x => x.carry_id).ToList();
|
|
foreach (var wmsOutinStockDetail in wmsOutinStockDetails)
|
|
{
|
|
WmsDistaskH wmsDistaskH = await _db.Queryable<WmsDistaskH>().FirstAsync(x=>x.bill_code==wmsOutinStockDetail.distask_code);
|
|
WmsInstockH instock = await _db.Queryable<WmsInstockH>().SingleAsync(x=>x.id==wmsDistaskH.require_id);
|
|
List<WmsInstockD> allInstockDetails = await _db.Queryable<WmsInstockD>().Where(it => it.bill_id == instock.id).ToListAsync();
|
|
|
|
// WmsTempCode wmsTempCode = await _db.Queryable<WmsCarryCode>()
|
|
// .LeftJoin<WmsTempCode>((a, b) => a.barcode == b.barcode)
|
|
// .Where((a, b) => a.carry_id == wmsDistaskH.carry_id)
|
|
// .Select((a, b) => b)
|
|
// .FirstAsync();
|
|
|
|
string wmsPurchaseOrderHId = wmsPurchaseH?.erp_bill_code ?? "";
|
|
WmsPurchaseOrderH wmsPurchaseOrderH = await _db.Queryable<WmsPurchaseOrderH>().SingleAsync(x => x.id == wmsPurchaseOrderHId);
|
|
WmsPurchaseOrderD wmsPurchaseOrderDs = await _db.Queryable<WmsPurchaseOrderD>().FirstAsync(x => x.fk_wms_purchase_order_id == wmsPurchaseOrderHId);
|
|
BasWarehouse basWarehouse = await _db.Queryable<BasWarehouse>().SingleAsync(x=>x.id==instock.warehouse_id);
|
|
|
|
List<String> materialIds = allInstockDetails.Select(x => x.material_id).Distinct().ToList();
|
|
List<String> unitCodes = allInstockDetails.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))
|
|
.Select((x, y) => y)
|
|
.ToListAsync();
|
|
List<WmsErpWarehouserelaH> erpWarehouserelaHs = await _db.Queryable<WmsErpWarehouserelaH>().Where(x=>x.id!=null).ToListAsync();
|
|
|
|
DictionaryDataEntity tranType = await _db.Queryable<DictionaryDataEntity>().Where(x=>x.DictionaryTypeId=="25043925951909" && x.EnCode==wmsPurchaseH.transaction_type).FirstAsync();
|
|
string tranTypeId = tranType?.Id ?? "";
|
|
string supplierId = wmsPurchaseOrderH?.supplier_id ?? "";
|
|
List<string> tableIds = new List<string>();
|
|
tableIds.Add(_userManager.UserId);
|
|
tableIds.Add(WmsWareHouseConst.AdministratorOrgId);
|
|
tableIds.Add(instock.warehouse_id);
|
|
tableIds.AddRange(materialIds);
|
|
tableIds.Add(supplierId);
|
|
tableIds.Add(tranTypeId);
|
|
tableIds.AddRange(unitDatas.Select(x => x.Id).ToList());
|
|
|
|
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x => tableIds.Contains(x.table_id)).ToListAsync();
|
|
string erpCreateId = erpExtendFields.Find(x => x.table_id == instock.create_id)?.user_id ?? "";
|
|
ErpExtendField erpOrg = erpExtendFields.Find(x => x.table_id == (WmsWareHouseConst.AdministratorOrgId));
|
|
string nowStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
Dictionary<string, object> erpRequestData = new Dictionary<string, object>();
|
|
erpRequestData.Add("approver", erpCreateId);
|
|
erpRequestData.Add("billmaker", erpCreateId);
|
|
erpRequestData.Add("bitinbill", false);
|
|
erpRequestData.Add("cgeneralhid", null);
|
|
erpRequestData.Add("corpoid", erpOrg.corpoid);
|
|
erpRequestData.Add("corpvid", erpOrg.corpvid);
|
|
erpRequestData.Add("creationtime", nowStr);
|
|
erpRequestData.Add("creator", erpCreateId);
|
|
erpRequestData.Add("ctrantypeid", erpExtendFields.Find(x => x.table_id == tranTypeId)?.transaction_type_id ?? "");
|
|
erpRequestData.Add("cvendorid", erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_id ?? "");
|
|
erpRequestData.Add("cvendorvid", erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_vid ?? "");
|
|
// erpRequestData.Add("cwarehouseid", erpExtendFields.Find(x => x.table_id == instock.warehouse_id)?.cotherwhid ?? "");//类型视图里取
|
|
erpRequestData.Add("cwarehouseid", erpWarehouserelaHs.Find(x => x.erp_warehousecode == wmsPurchaseD.erp_wh_type)?.erp_warehouseid ?? "");//类型视图里取
|
|
erpRequestData.Add("dbilldate", nowStr);
|
|
erpRequestData.Add("dmakedate", nowStr);
|
|
erpRequestData.Add("fbillflag", 2);
|
|
erpRequestData.Add("fbuysellflag", 2);
|
|
erpRequestData.Add("ntotalnum", allInstockDetails.Sum(x => x.qty));
|
|
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("vbillcode", instock.bill_code);
|
|
erpRequestData.Add("vtrantypecode", tranType?.EnCode ?? "");
|
|
|
|
List<Dictionary<string, object>> erpRequestDataDetails = new List<Dictionary<string, object>>();
|
|
foreach (WmsInstockD item in allInstockDetails)
|
|
{
|
|
erpRequestDataDetails.Add(new Dictionary<string, object>()
|
|
{
|
|
["castunitid"] = erpExtendFields.Find(x => x.table_id == (unitDatas.Find(x => x.EnCode == item.unit_id)?.Id ?? ""))?.cunitid ?? "",
|
|
["cbodytranstypecode"] = erpExtendFields.Find(x => x.table_id == tranTypeId)?.transaction_type_id ?? "",
|
|
// ["cbodywarehouseid"] = erpExtendFields.Find(x => x.table_id == instock.warehouse_id)?.cotherwhid ?? "",
|
|
["cbodywarehouseid"] = erpWarehouserelaHs.Find(x => x.erp_warehousecode == basWarehouse.whcode)?.erp_warehouseid ?? "",
|
|
["cgeneralbid"] = "",
|
|
["cgeneralhid"] = "",
|
|
["cmaterialoid"] = erpExtendFields.Find(x => x.table_id == item.material_id)?.cmaterialoid ?? "",
|
|
["cmaterialvid"] = erpExtendFields.Find(x => x.table_id == item.material_id)?.cmaterialvid ?? "",
|
|
["corpoid"] = erpOrg.corpoid,
|
|
["corpvid"] = erpOrg.corpvid,
|
|
["crowno"] = (allInstockDetails.FindIndex(x => x.id == item.id) + 1) * 10,
|
|
["cunitid"] = erpExtendFields.Find(x => x.table_id == (unitDatas.Find(x => x.EnCode == item.unit_id)?.Id ?? ""))?.cunitid ?? "",
|
|
["cvendorid"] = erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_id ?? "",
|
|
["cvendorvid"] = erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_vid ?? "",
|
|
["dbizdate"] = instock.create_time.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
["nnum"] = item.qty,
|
|
["nshouldnum"] = item.pr_qty,
|
|
// ["pk_creqwareid"] = erpExtendFields.Find(x => x.table_id == instock.warehouse_id)?.cotherwhid ?? "",
|
|
["pk_creqwareid"] = erpWarehouserelaHs.Find(x => x.erp_warehousecode == basWarehouse.whcode)?.erp_warehouseid ?? "",
|
|
["pk_group"] = erpOrg.pk_group,
|
|
["pk_org"] = erpOrg.pk_org,
|
|
["pk_org_v"] = erpOrg.pk_org_v,
|
|
["pseudocolumn"] = (allInstockDetails.FindIndex(x => x.id == item.id) + 1) * 10,
|
|
["vbatchcode"] = item.code_batch,
|
|
["csourcebillhid"] = wmsPurchaseH?.erp_arriveorder_pk ?? "",
|
|
["csourcebillbid"] = wmsPurchaseD?.erp_arriveorder_b_pk ?? "",
|
|
["vsourcebillcode"] = wmsPurchaseH?.bill_code ?? "",
|
|
["lineno"] = wmsPurchaseOrderDs?.lineno ?? "",
|
|
["vfree1"] = erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_id ?? "",
|
|
["bpresent"] = wmsPurchaseD.gift==1,
|
|
["ntaxprice"] = wmsPurchaseD.price,
|
|
|
|
});
|
|
}
|
|
erpRequestData.Add("dtls", erpRequestDataDetails);
|
|
requestData.Add(erpRequestData);
|
|
}
|
|
|
|
await _db.Ado.BeginTranAsync();
|
|
await _db.Updateable<WmsPurchaseD>()
|
|
.SetColumns(x => x.qc_res == qcRes)
|
|
.Where(x => x.id == id)
|
|
.ExecuteCommandAsync();
|
|
|
|
Dictionary<string, int> dic2 = new()
|
|
{
|
|
{ "ok", 1 },
|
|
{ "no", 2 },
|
|
{ "barelyOk", 4 },
|
|
{ "await", 8 },
|
|
{ "temporarily", 16 },
|
|
{ "checking", 32 },
|
|
};
|
|
string isCheck = dic2[qcRes].ToString();
|
|
//await _db.Updateable<WmsCarryH>()
|
|
// .SetColumns(x => x.is_check == isCheck)
|
|
// .Where(x => carryIds.Contains(x.id))
|
|
// .ExecuteCommandAsync();
|
|
|
|
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/purchaseIn/save";
|
|
thirdWebapiRecord.url = WmsWareHouseConst.BIP_DOMAIN + "uapws/rest/purchaseIn/save";
|
|
thirdWebapiRecord.request_data = JsonConvert.SerializeObject(requestData);
|
|
thirdWebapiRecord.create_time = DateTime.Now;
|
|
thirdWebapiRecord.remark = "采购收货单号:" + (wmsPurchaseH?.bill_code ?? "");
|
|
|
|
await _db.Insertable(thirdWebapiRecord).ExecuteCommandAsync();
|
|
|
|
await _db.Ado.CommitTranAsync();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
await _db.Ado.RollbackTranAsync();
|
|
Log.Error(e.Message,e);
|
|
}
|
|
|
|
return "保存成功";
|
|
}
|
|
}
|
|
} |