调试完成

This commit is contained in:
2025-11-24 16:06:01 +08:00
parent 18b211daa0
commit 99a757f517
5 changed files with 57 additions and 64 deletions

View File

@@ -68,7 +68,7 @@ namespace MyCode.Project.Services.Implementation
if (goodsDocIn.Status ==2 )
{
throw new BaseException($"采购入库单 {goodsDocIn.GoodsdocNo} 已经推送过,状态为:{goodsDocIn.Status},不允许重复推送");
throw new BaseException($"{goodsDocIn.InOutDate2}+{goodsDocIn.VendCustomerName}的采购入库单已经推送过,状态为:{goodsDocIn.Status},不允许重复推送");
}
var param = _yTKJTShopParameterRepository
@@ -93,16 +93,8 @@ namespace MyCode.Project.Services.Implementation
if (response.IsSuccess)
{
var allRecords = _pushKingDeeGoodsDocInRepository
.Queryable()
.Where(t => t.GoodsdocNo == goodsDocIn.GoodsdocNo)
.ToList();
foreach (var record in allRecords)
{
record.Status = 2;
_pushKingDeeGoodsDocInRepository.Update(record);
}
goodsDocIn.Status = 2;
_pushKingDeeGoodsDocInRepository.Update(goodsDocIn);
}
return result;
@@ -116,52 +108,32 @@ namespace MyCode.Project.Services.Implementation
// 从BusiOrderGoodsDocIn表获取明细数据
var detailList = _busiOrderGoodsDocInRepository
.Queryable()
.Where(t => t.SourceBillNo == goodsDocIn.GoodsdocNo)
.Where(t => t.InOutDate2.Value.ToString("yyyy-MM-dd") == goodsDocIn.InOutDate2.Value.ToString("yyyy-MM-dd") && t.VendCode==goodsDocIn.VendCode )
.ToList();
if (detailList == null || detailList.Count == 0)
{
throw new BaseException($"采购入库单 {goodsDocIn.GoodsdocNo} 没有找到明细数据,无法推送");
throw new BaseException($"没有找到明细数据,无法推送");
}
var vendorCodes = detailList.Where(d => !string.IsNullOrEmpty(d.VendCode))
.Select(d => d.VendCode)
.Distinct()
.ToList();
if (vendorCodes.Count > 1)
{
throw new BaseException($"采购入库单 {goodsDocIn.GoodsdocNo} 明细行中存在不同的供应商编码:{string.Join(",", vendorCodes)},无法推送");
}
// 获取第一条明细用于主表信息
var firstDetail = detailList.FirstOrDefault();
if (firstDetail == null)
{
throw new BaseException($"采购入库单 {goodsDocIn.GoodsdocNo} 明细数据为空,无法推送");
throw new BaseException($" 明细数据为空,无法推送");
}
// 获取采购组织ID
string purchaseOrgId = param.FPURCHASEORGID?.ToString() ?? param.FSALEORGID?.ToString() ?? DEFAULT_ORG;
// 获取仓库编码
string warehouseCode = firstDetail.WarehouseCode ?? param.FPURCHASINGWAREHOUSECODE ?? "";
// 数据校验
if (string.IsNullOrEmpty(firstDetail.VendCode))
{
throw new BaseException($"采购入库单 {goodsDocIn.GoodsdocNo} 供应商编码为空,无法推送");
}
if (string.IsNullOrEmpty(warehouseCode))
{
throw new BaseException($"采购入库单 {goodsDocIn.GoodsdocNo} 仓库编码为空,无法推送");
}
string warehouseCode =param.FPURCHASINGWAREHOUSECODE ;
// 构建金蝶API的明细行数据
var entryList = detailList.Select((n, index) => BuildEntryItem(n, param, purchaseOrgId, warehouseCode)).ToList();
if (entryList.Count == 0)
{
throw new BaseException($"采购入库单 {goodsDocIn.GoodsdocNo} 明细数据转换失败,无法推送");
throw new BaseException($"采购入库单明细数据转换失败,无法推送");
}
// 构建金蝶API的主表数据
@@ -255,11 +227,12 @@ namespace MyCode.Project.Services.Implementation
private PurchaseStockInModel BuildMainModel(PushKingDeeGoodsDocIn goodsDocIn, BusiOrderGoodsDocIn firstDetail, YTKJTShopParameter param, string orgId, List<FPurchaseStockInEntryItem> entryList)
{
//JKCR+年月日+自增ID三位
string dateStr = goodsDocIn.InOutDate2?.ToString("yyyy-MM-dd HH:mm:ss") ?? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string FBillNo = GenerateBillNo(goodsDocIn.SortId, goodsDocIn.InOutDate2.Value);
return new PurchaseStockInModel()
{
FBillNo= goodsDocIn.GoodsdocNo,
FBillNo= FBillNo,
FID = 0,
FBillTypeID = new FBillTypeID()
{
@@ -317,6 +290,23 @@ namespace MyCode.Project.Services.Implementation
FInStockEntry = entryList
};
}
/**
* JKXC+年月日+自增ID三位--销售出库单
JKXT+年月日+自增ID三位--销售退货单
JKCR+年月日+自增ID三位--采购入库单
JKCT+年月日+自增ID三位--采购退货单
**/
private string GenerateBillNo(int Sheet, DateTime date)
{
string prefix = "JKCR" + date.ToString("yyyyMMdd");
string numberPart = (Sheet > 0 ? Sheet.ToString() : "").PadLeft(3, '0');
numberPart = numberPart.Length > 3 ? numberPart.Substring(numberPart.Length - 3) : numberPart;
// 组合并确保只取最后3位数字
string combined = prefix + numberPart;
return combined;
}
}
}