using System; using System.Collections.Generic; using System.Linq; using System.Threading; using CK.SCP.Models; using CK.SCP.Models.Enums; using CK.SCP.Models.ScpEntity; using CK.SCP.Models.UniApiEntity; //using xxscm_tx_mstr = ChangKeTec.Wms.Models.UniApi.xxscm_tx_mstr; //using xxscm_ctrl = ChangKeTec.Wms.Models.UniApi.xxscm_ctrl; //using xxscm_inv_det = ChangKeTec.Wms.Models.UniApi.xxscm_inv_det; //using xxscm_ld_det = ChangKeTec.Wms.Models.UniApi.xxscm_ld_det; //using xxscm_tx_det = ChangKeTec.Wms.Models.UniApi.xxscm_tx_det; //using xxscm_pod_det = ChangKeTec.Wms.Models.UniApi.xxscm_pod_det; //using xxscm_rt_det = ChangKeTec.Wms.Models.UniApi.xxscm_rt_det; //using xxscm_soiss_det = ChangKeTec.Wms.Models.UniApi.xxscm_soiss_det; //using xxscm_tag_det = ChangKeTec.Wms.Models.UniApi.xxscm_tag_det; //using xxscm_tr_det = ChangKeTec.Wms.Models.UniApi.xxscm_tr_det; namespace CK.SCP.UniApi.Controller { public static class OdbcApiScpController { private static string CreateSeq(string pre) { return ScpCache.Config.QAD域 + "_" + DateTime.Now.ToString(ScpCache.Config.SCP接口数据流水号格式); } private static void PutScpCtrl(UniApiEntities idb, string seq, string tableName, int rowCount) { var wmsCtrl = new xxscm_ctrl { xxscm_seq = seq, xxscm_table = tableName, xxscm_table_qty = rowCount, xxscm_qad = ((int)UniApiState.待执行).ToString(), xxscm_mes = ((int)UniApiState.待执行).ToString(), xxscm_scm = ((int)UniApiState.待执行).ToString(), xxscm_wms = ((int)UniApiState.待执行).ToString(), xxscm_rmks = "", xxscm_domain = ScpCache.Config.QAD域, xxscm_site = ScpCache.Config.QAD地点, //xxscm_create_time = DateTime.Now, }; idb.xxscm_ctrl.Add(wmsCtrl); } public static void PutAll(ScpEntities sdb, UniApiEntities idb, List dataList) { var billNumList = dataList.Select(p => p.BillNum).Distinct(); foreach (string billNum in billNumList) { var list = dataList.Where(p => p.BillNum == billNum).ToList(); //if (GlobalVar.ApiConfig.Scm采购订单) // PutScmPo(idb, // list.Where(p => p.InterfaceType == UniApiType.PO.ToString()).ToList()); if (GlobalVar.ApiConfig.Scm发货单) PutScmAsn(idb, list.Where(p => p.InterfaceType == UniApiType.Receive.ToString()).ToList()); if (GlobalVar.ApiConfig.Scm条码明细) PutScmBarcode(idb, list.Where(p => p.InterfaceType == UniApiType.BarCode.ToString()).ToList()); if (GlobalVar.ApiConfig.Scm发票) PutScmInvoice(idb, list.Where(p => p.InterfaceType == UniApiType.Invoice.ToString()).ToList()); Thread.Sleep(10); } } /// /// 发货单 /// /// /// private static void PutScmAsn(UniApiEntities idb, List dataList) { var seq = CreateSeq("SP"); var tableName = ScmTableName.xxscm_tx_mstr.ToString(); var qadDataList = new List(); foreach (var wmsData in dataList) { var qadData = qadDataList.SingleOrDefault(p => p.xxscm_tx_nbr == wmsData.BillNum && p.xxscm_tx_site == ScpCache.Config.QAD地点 && p.xxscm_tx_part == wmsData.PartCode); if (qadData == null) { qadData = new xxscm_tx_mstr { xxscm_tx_seq = seq, xxscm_tx_nbr = wmsData.BillNum, xxscm_tx_site = ScpCache.Config.QAD地点, xxscm_tx_part = wmsData.PartCode, xxscm_tx_qadread = ((int)UniApiState.待执行).ToString(), xxscm_tx_wmsread = ((int)UniApiState.待执行).ToString(), xxscm_tx_scmread = ((int)UniApiState.待执行).ToString(), xxscm_tx_mesread = ((int)UniApiState.待执行).ToString(), xxscm_tx_createur = wmsData.CreateOper, xxscm_tx_createdt = wmsData.CreateTime, xxscm_tx_updateur = "", xxscm_tx_updatedt = DateTime.Now, xxscm_tx_rmks = "", xxscm_tx_domain = ScpCache.Config.QAD域, xxscm_tx_po_nbr = wmsData.ErpBillNum, xxscm_tx_po_line = wmsData.ErpLineNum.ToString(), xxscm_tx_conv = wmsData.UmConv, xxscm_tx_date_Promise = wmsData.ValidDate, xxscm_tx_date_due = wmsData.ValidDate, xxscm_tx_date_ship = wmsData.CreateTime, xxscm_tx_loc_um = wmsData.LocUnit == null ? "" : wmsData.LocUnit, xxscm_tx_po_um = wmsData.PoUnit == null ? "" : wmsData.PoUnit, xxscm_tx_pprice = wmsData.Price, xxscm_tx_qty_std = wmsData.PackQty, xxscm_tx_qty_total = wmsData.Qty, xxscm_tx_status = ((int)FormState.开放).ToString(), xxscm_tx_type = "", xxscm_tx_vend = wmsData.VendId, xxscm_tx_vend_batch = wmsData.VendBatch, xxscm_tx_ware = "", xxscm_tx_ware_class = "", }; qadDataList.Add(qadData); } wmsData.State = (int)BillState.Finish; wmsData.PutTime = DateTime.Now; } if (qadDataList.Count == 0) return; idb.xxscm_tx_mstr.AddRange(qadDataList); Console.WriteLine($"新增 发货单 数据:{qadDataList.Count} 条"); PutScpCtrl(idb, seq, tableName, qadDataList.Count); } /// /// 采购订单 /// /// /// < param name="dataList"> //private static void PutScmPo(UniApiEntities idb, List dataList) //{ // var seq = CreateSeq("PO"); // var tableName = ScmTableName.xxscm_pod_det.ToString(); // var qadDataList = new List(); // foreach (var wmsData in dataList) // { // var qadData = qadDataList.SingleOrDefault(p => p.xxscm_pod_nbr == wmsData.ErpBillNum // && p.xxscm_pod_line == wmsData.ErpLineNum // && p.xxscm_pod_site == ScpCache.Config.QAD地点 // && p.xxscm_pod_part == wmsData.PartCode); // if (qadData == null) // { // if (wmsData.PartCode != null) // qadData = new xxscm_pod_det // { // xxscm_pod_seq = seq, // xxscm_pod_nbr = wmsData.ErpBillNum, // xxscm_pod_part = wmsData.PartCode, // xxscm_pod_site = ScpCache.Config.QAD地点, // xxscm_pod_vend = wmsData.VendId, // xxscm_pod_loc_um = wmsData.LocUnit, // xxscm_pod_qadread = ((int)UniApiState.待执行).ToString(), // xxscm_pod_wmsread = ((int)UniApiState.待执行).ToString(), // xxscm_pod_scmread = ((int)UniApiState.待执行).ToString(), // xxscm_pod_mesread = ((int)UniApiState.待执行).ToString(), // xxscm_pod_createur = wmsData.CreateOper, // xxscm_pod_createdt = wmsData.CreateTime, // xxscm_pod_updateur = "", // xxscm_pod_updatedt = DateTime.Now, // xxscm_pod_rmks = "", // xxscm_pod_domain = ScpCache.Config.QAD域, // xxscm_pod_attn = wmsData.Attn, // xxscm_pod_buyer = wmsData.Buyer, // xxscm_pod_buyer_phone = wmsData.BuyerPhone, // xxscm_pod_confirm = false, // xxscm_pod_curr = wmsData.Currency, // xxscm_pod_desc = ScpCache.GetPartDesc(wmsData.PartCode), // xxscm_pod_due_date = wmsData.ValidDate, // xxscm_pod_line = wmsData.ErpLineNum, // xxscm_pod_made = "", // xxscm_pod_modtype = wmsData.ModType, // xxscm_pod_name = "", // xxscm_pod_price = wmsData.Price, // xxscm_pod_qty_ord = wmsData.PackQty, // xxscm_pod_qty_std = wmsData.Qty, // xxscm_pod_qty_rct = 0, // xxscm_pod_ship = wmsData.SourceBillNum, // xxscm_pod_status = wmsData.State.ToString(), // xxscm_pod_um = wmsData.PoUnit, // xxscm_pod_um_conv = wmsData.UmConv, // }; // qadDataList.Add(qadData); // } // wmsData.State = (int)BillState.Finish; // wmsData.PutTime = DateTime.Now; // } // if (qadDataList.Count == 0) return; // idb.xxscm_pod_det.AddRange(qadDataList); // Console.WriteLine($"新增 采购订单 数据:{qadDataList.Count} 条"); // PutScpCtrl(idb, seq, tableName, qadDataList.Count); //} /// /// 条码 /// /// /// private static void PutScmBarcode(UniApiEntities idb, List dataList) { var seq = CreateSeq("BA"); var tableName = ScmTableName.xxscm_tx_det.ToString(); var qadDataList = new List(); foreach (var wmsData in dataList) { var qadData = qadDataList.SingleOrDefault(p => p.xxscm_tx_nbr == wmsData.BillNum && p.xxscm_tx_boxcode == wmsData.Barcode); if (qadData == null) { qadData = new xxscm_tx_det { xxscm_tx_seq = seq, xxscm_tx_nbr = wmsData.BillNum, xxscm_tx_part = wmsData.PartCode, xxscm_tx_qadread = ((int)UniApiState.待执行).ToString(), xxscm_tx_wmsread = ((int)UniApiState.待执行).ToString(), xxscm_tx_scmread = ((int)UniApiState.待执行).ToString(), xxscm_tx_mesread = ((int)UniApiState.待执行).ToString(), xxscm_tx_createur = wmsData.CreateOper, xxscm_tx_createdt = wmsData.CreateTime, xxscm_tx_updateur = "", xxscm_tx_updatedt = DateTime.Now, xxscm_tx_rmks = "", xxscm_tx_domain = ScpCache.Config.QAD域, xxscm_tx_vend = wmsData.VendId, xxscm_tx_batch = wmsData.VendBatch, xxscm_tx_boxcode = wmsData.Barcode, xxscm_tx_qty_real = wmsData.Qty, }; qadDataList.Add(qadData); } wmsData.State = (int)BillState.Finish; wmsData.PutTime = DateTime.Now; } if (qadDataList.Count == 0) return; idb.xxscm_tx_det.AddRange(qadDataList); Console.WriteLine($"新增 条码 数据:{qadDataList.Count} 条"); PutScpCtrl(idb, seq, tableName, qadDataList.Count); } /// /// 发票 /// /// /// private static void PutScmInvoice(UniApiEntities idb, List dataList) { var seq = CreateSeq("IV"); var tableName = ScmTableName.xxscm_inv_det.ToString(); var qadDataList = new List(); foreach (var wmsData in dataList) { var qadData = qadDataList.SingleOrDefault(p => p.xxscm_inv_nbr == wmsData.BillNum && p.xxscm_inv_site == ScpCache.Config.QAD地点 && p.xxscm_inv_part == wmsData.PartCode && p.xxscm_inv_line == wmsData.ErpLineNum.ToString()); if (qadData == null) { qadData = new xxscm_inv_det { xxscm_inv_seq = seq, xxscm_inv_nbr = wmsData.BillNum, xxscm_inv_site = ScpCache.Config.QAD地点, xxscm_inv_part = wmsData.PartCode, xxscm_inv_qty = wmsData.Qty, xxscm_inv_date = wmsData.ValidDate, xxscm_inv_qadread = ((int)UniApiState.待执行).ToString(), xxscm_inv_wmsread = ((int)UniApiState.待执行).ToString(), xxscm_inv_scmread = ((int)UniApiState.待执行).ToString(), xxscm_inv_mesread = ((int)UniApiState.待执行).ToString(), xxscm_inv_createur = wmsData.CreateOper, xxscm_inv_createdt = wmsData.CreateTime, xxscm_inv_updateur = "", xxscm_inv_updatedt = DateTime.Now, xxscm_inv_rmks = "", xxscm_inv_domain = ScpCache.Config.QAD域, xxscm_inv_amt = wmsData.Price, xxscm_inv_asn = wmsData.SourceBillNum, xxscm_inv_curr = wmsData.Currency, xxscm_inv_vend = wmsData.VendId, xxscm_inv_line = wmsData.ErpLineNum.ToString(), xxscm_inv_invoice = wmsData.Invoice, xxscm_inv_order = wmsData.ErpBillNum, xxscm_inv_price = wmsData.Price, xxscm_inv_taxamt = wmsData.TaxAmt, xxscm_inv_receiver = wmsData.Receiver, xxscm_inv_taxt = wmsData.Tax, }; qadDataList.Add(qadData); } wmsData.State = (int)BillState.Finish; wmsData.PutTime = DateTime.Now; } if (qadDataList.Count == 0) return; idb.xxscm_inv_det.AddRange(qadDataList); Console.WriteLine($"新增 发票 数据:{qadDataList.Count} 条"); PutScpCtrl(idb, seq, tableName, qadDataList.Count); } } }