222 lines
10 KiB
C#
222 lines
10 KiB
C#
|
using Kingdee.CDP.WebApi.SDK;
|
|||
|
using MyCode.Project.Domain.Message.Act.PurchaseOrder;
|
|||
|
using MyCode.Project.Domain.Message.Common;
|
|||
|
using MyCode.Project.Domain.Message.Request.InvoiceOrder;
|
|||
|
using MyCode.Project.Domain.Message.Request.KingDee;
|
|||
|
using MyCode.Project.Domain.Message.Request.PurchaseOrder;
|
|||
|
using MyCode.Project.Domain.Message.Response.InvoiceOrder;
|
|||
|
using MyCode.Project.Domain.Message.Response.PurchaseOrder;
|
|||
|
using MyCode.Project.Domain.Message.Response.User;
|
|||
|
using MyCode.Project.Domain.Model;
|
|||
|
using MyCode.Project.Domain.Repositories;
|
|||
|
using MyCode.Project.Infrastructure.Common;
|
|||
|
using MyCode.Project.Infrastructure.Exceptions;
|
|||
|
using MyCode.Project.Infrastructure.Extensions;
|
|||
|
using MyCode.Project.OutSideService;
|
|||
|
using MyCode.Project.Repositories;
|
|||
|
using MyCode.Project.Repositories.Common;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Configuration;
|
|||
|
using System.Linq;
|
|||
|
using System.Runtime.CompilerServices;
|
|||
|
|
|||
|
namespace MyCode.Project.Services.Implementation
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 发货通知单 相关服务
|
|||
|
/// </summary>
|
|||
|
public class InvoiceOrderService : ServiceBase , IInvoiceOrderService
|
|||
|
{
|
|||
|
private IWorkProcessService _workProcessService;
|
|||
|
private IKingDeeService _kingDeeService;
|
|||
|
private IPurchaseOrderRepository _purchaseOrderRepository;
|
|||
|
private IPurchaseOrderItemRepository _purchaseOrderItemRepository;
|
|||
|
private IInvoiceOrderItemRepository _invoiceOrderItemRepository;
|
|||
|
private IInvoiceOrderRepository _invoiceOrderRepository;
|
|||
|
|
|||
|
|
|||
|
public InvoiceOrderService(IPurchaseOrderRepository purchaseOrderRepository
|
|||
|
, IPurchaseOrderItemRepository purchaseOrderItemRepository
|
|||
|
, IInvoiceOrderItemRepository invoiceOrderItemRepository
|
|||
|
, IInvoiceOrderRepository invoiceOrderRepository
|
|||
|
, IWorkProcessService workProcessService
|
|||
|
, IKingDeeService kingDeeService)
|
|||
|
{
|
|||
|
_purchaseOrderItemRepository = purchaseOrderItemRepository;
|
|||
|
_purchaseOrderRepository = purchaseOrderRepository;
|
|||
|
_invoiceOrderItemRepository = invoiceOrderItemRepository;
|
|||
|
_invoiceOrderRepository = invoiceOrderRepository;
|
|||
|
_workProcessService = workProcessService;
|
|||
|
_kingDeeService = kingDeeService;
|
|||
|
}
|
|||
|
|
|||
|
#region GetPageList(发货通知单分页列表)
|
|||
|
/// <summary>
|
|||
|
/// 发货通知单分页列表
|
|||
|
/// </summary>
|
|||
|
/// <param name="pagedSearch"></param>
|
|||
|
/// <param name="loginInfo"></param>
|
|||
|
/// <returns></returns>
|
|||
|
|
|||
|
public PageResult<InvoiceOrderPageList> GetPageList(PagedSearch<InvoiceOrderPageSearch> pagedSearch, LoginInfo loginInfo)
|
|||
|
{
|
|||
|
return _invoiceOrderRepository.GetPageList(pagedSearch, loginInfo.SupplierId, loginInfo.FPurchaseOrgId);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region DeleteOrder(删除某个发货订单)
|
|||
|
/// <summary>
|
|||
|
/// 删除某个发货订单
|
|||
|
/// </summary>
|
|||
|
/// <param name="formId"></param>
|
|||
|
/// <param name="billdelete"></param>
|
|||
|
/// <returns></returns>
|
|||
|
/// <exception cref="Exception"></exception>
|
|||
|
[TransactionCallHandler]
|
|||
|
public void DeleteOrder(IdAct act, LoginInfo loginInfo)
|
|||
|
{
|
|||
|
var orderItems = _invoiceOrderItemRepository.Queryable().Where(t => t.Id == act.Id).ToList();
|
|||
|
Guid pid = orderItems.Select(t => t.InvoiceOrderId.Value).FirstOrDefault();
|
|||
|
var orderHead = _invoiceOrderRepository.Queryable().Where(t => t.SupplierId == loginInfo.SupplierId && t.Id == pid).First();
|
|||
|
if (orderHead == null)
|
|||
|
{
|
|||
|
throw new BaseException("订单数据不正确");
|
|||
|
}
|
|||
|
BillDelete billDelete = new BillDelete();
|
|||
|
billDelete.Numbers = orderHead.FBillNo;
|
|||
|
try
|
|||
|
{
|
|||
|
var result = _kingDeeService.Delete("PUR_ReceiveBill", billDelete);
|
|||
|
LogHelper.Info(result);
|
|||
|
_invoiceOrderItemRepository.Delete(t => t.Id == act.Id);
|
|||
|
_invoiceOrderRepository.Delete(t=>t.Id== orderHead.Id);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw new BaseException($"删除失败,原因是{ex.Message}");
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
#region
|
|||
|
/// <summary>
|
|||
|
/// 根据收料通知单号查列表
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public string QueryList(string FbillNo, string FSupplierId)
|
|||
|
{
|
|||
|
BillQuery queryParam = new BillQuery();
|
|||
|
queryParam = new BillQuery()
|
|||
|
{
|
|||
|
FormId = "PUR_ReceiveBill",
|
|||
|
FieldKeys = $@"FID,FBillNo,FMaterialId.FNumber,FSupplierLot,FLot.fname,FSUPDELQTY,FDetailEntity_FEntryId",
|
|||
|
TopRowCount = 100000,
|
|||
|
Limit = 20000,
|
|||
|
StartRow = 0,
|
|||
|
};
|
|||
|
FilterList filterString = new FilterList(false);
|
|||
|
|
|||
|
|
|||
|
//FilterItem FDocumentStatusItem = new FilterItem("FBillNo", "67", "C", "0");
|
|||
|
//FilterItem FCancelStatusItem = new FilterItem("FCancelStatus", "105", "A", "0");
|
|||
|
FilterItem FCancelStatusItem1 = new FilterItem { FieldName = "FBillNo", Compare = "67", Value = FbillNo, Logic = "0" };
|
|||
|
FilterItem FCancelStatusItem2 = new FilterItem { FieldName = "FSupplierId.FNumber", Compare = "67", Value = FSupplierId, Logic = "0" };
|
|||
|
//FilterItem FCancelStatusItem3 = new FilterItem { FieldName = "FSupplierId.FNumber", Compare = "67", Value = FSupplierId.ToString(), Logic = "0" };
|
|||
|
//FilterItem FCancelStatusItem4 = new FilterItem { FieldName = "FBaseDeliveryMaxQty", Compare = "21", Value = "0", Logic = "0" };
|
|||
|
|
|||
|
filterString.AddFilterItem(FCancelStatusItem1).AddFilterItem(FCancelStatusItem2);
|
|||
|
////.AddFilterItem(FCancelStatusItem4)
|
|||
|
//.AddFilterItem(FCancelStatusItem2).AddFilterItem(FCancelStatusItem3);
|
|||
|
queryParam.FilterString = filterString.GetFilterString();
|
|||
|
var result = _kingDeeService.QueryList(queryParam);
|
|||
|
|
|||
|
return result;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region SetMSSSupplierLot(查询金蝶的美塞斯批号)
|
|||
|
/// <summary>
|
|||
|
/// 写入金蝶的美塞斯批号
|
|||
|
/// </summary>
|
|||
|
/// <param name="sheet"></param>
|
|||
|
/// <exception cref="BaseException"></exception>
|
|||
|
public void SetMSSSupplierLot(string sheet)
|
|||
|
{
|
|||
|
var sheetOrder = _invoiceOrderRepository.Queryable().Where(t => t.Sheet == sheet).First();
|
|||
|
if (sheetOrder == null)
|
|||
|
return;
|
|||
|
var result = QueryList(sheetOrder.FBillNo, sheetOrder.SupplierId);
|
|||
|
LogHelper.Info(sheet + "的收料订单数据");
|
|||
|
LogHelper.Info(result);
|
|||
|
/**
|
|||
|
* *
|
|||
|
* [{"FID":100160,"FBillNo":"CGSL000148","FMaterialId.FNumber":"89833-001","FSupplierLot":"AA5","FLot.fname":"A1","FSUPDELQTY":100.0000000000,"FDetailEntity.FEntryId":100299}
|
|||
|
* ,{"FID":100160,"FBillNo":"CGSL000148","FMaterialId.FNumber":"89834-002","FSupplierLot":"aa6","FLot.fname":"A2","FSUPDELQTY":100.0000000000,"FDetailEntity.FEntryId":100300}]
|
|||
|
*
|
|||
|
* */
|
|||
|
List<dynamic> data = JsonHelper.ToObject<List<dynamic>>(result);
|
|||
|
//List<dynamic> data = System.Text.Json.JsonSerializer.Deserialize<List<dynamic>>(result);
|
|||
|
if (data.Count > 0)
|
|||
|
{
|
|||
|
int fid = 0;
|
|||
|
Guid ida = Guid.Empty;
|
|||
|
List<int> fids = data.Select(k => int.Parse((string)k["FID"])).ToList().Distinct().ToList();
|
|||
|
|
|||
|
var oldOrderItemList = _invoiceOrderItemRepository.Queryable().Where(g => g.InvoiceOrderId == sheetOrder.Id).ToList();
|
|||
|
List<int?> entityIdList = new List<int?>();
|
|||
|
|
|||
|
foreach (var item in data)
|
|||
|
{
|
|||
|
int fido = int.Parse((string)item["FID"]);
|
|||
|
string FSupplierLot = (string)item["FSupplierLot"];
|
|||
|
if (string.IsNullOrWhiteSpace(FSupplierLot))
|
|||
|
FSupplierLot = FSupplierLot.Trim();
|
|||
|
else
|
|||
|
FSupplierLot = "";
|
|||
|
var oldItems = oldOrderItemList.Where(k => k.MaterialCode == (string)item["FMaterialId.FNumber"] && k.Qty == (decimal)item["FSUPDELQTY"]
|
|||
|
).ToList();
|
|||
|
var oldItem = oldItems.FirstOrDefault();
|
|||
|
if (oldItems.Count > 1)
|
|||
|
{
|
|||
|
oldItem= oldItems.FirstOrDefault(h=>h.FSupplierLot== FSupplierLot);
|
|||
|
}
|
|||
|
if (oldItem == null)
|
|||
|
{
|
|||
|
//throw new BaseException((string)item["FMaterialId.FNumber"] + (decimal)item["FSUPDELQTY"] + item["FSupplierLot"] + "找不到对应的明细");
|
|||
|
continue;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
|
|||
|
oldItem.Fid = item["FID"];
|
|||
|
oldItem.MSSSupplierLot = item["FLot.fname"];
|
|||
|
oldItem.EntityId = item["FDetailEntity.FEntryId"];
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
_invoiceOrderItemRepository.Update(oldOrderItemList);
|
|||
|
//物料编码,数量,收料通知单号,供应商批号,key
|
|||
|
AddTiaoMa addTiao = new AddTiaoMa();
|
|||
|
List<AddTiaoMa> addTiaoMas = new List<AddTiaoMa>();
|
|||
|
addTiaoMas = oldOrderItemList.Select(t => new AddTiaoMa
|
|||
|
{
|
|||
|
FBarCode = $@"{t.MaterialCode}*{t.Qty.Value.ToString("F2")}*{sheetOrder.FBillNo}*{t.FSupplierLot}",
|
|||
|
FBarCodeRule = "03",
|
|||
|
FBillCode = sheetOrder.FBillNo,
|
|||
|
FSupplierLot = t.FSupplierLot == null ? "" : t.FSupplierLot,
|
|||
|
FMaterialId = t.MaterialCode,
|
|||
|
FLot=t.MSSSupplierLot,
|
|||
|
FQty = t.Qty.Value.ToString()
|
|||
|
}).ToList();
|
|||
|
_workProcessService.Add<IKingDeeService>(this.MerchantId, "AddTiaoMa", "生成条码档案", JsonHelper.ToJson(addTiaoMas), 5);
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|