From 18ef8c37e6290ba6f47cbd5bbd26e56a682d767e Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期一, 29 九月 2025 16:34:15 +0800
Subject: [PATCH] 1
---
代码管理/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs | 346 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 304 insertions(+), 42 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs"
index 6f6940f..74bb6a5 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs"
@@ -6,15 +6,18 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using WIDESEA_Common.FangCang;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Helper;
+using WIDESEA_DTO.SquareCabin;
using WIDESEA_ISquareCabinRepository;
using WIDESEA_ISquareCabinServices;
using WIDESEA_Model.Models;
using WIDESEA_SquareCabinRepository;
using static System.Net.WebRequestMethods;
using static WIDESEA_DTO.SquareCabin.OrderDto;
+using static WIDESEA_DTO.SquareCabin.TowcsDto;
namespace WIDESEA_SquareCabinServices
{
@@ -23,13 +26,109 @@
public CabinOrderServices(ICabinOrderRepository BaseDal) : base(BaseDal)
{
}
+ static string SearchDate = "";
/// <summary>
/// 鑾峰彇涓婃父绯荤粺鐨勫叆搴撳崟
/// </summary>
/// <param name="searchDate"></param>
/// <returns></returns>
- public WebResponseContent GetUpstreamOrder(DateTime searchDate)
+ //public WebResponseContent GetUpstreamOrder(DateTime searchDate)
+ //{
+ // var responseContent = new WebResponseContent();
+
+ // try
+ // {
+ // // 璇锋眰鍦板潃
+ // var url = "http://127.0.0.1:9090/GYZ2/95fck/inOrder";
+
+ // //// 璇锋眰鍙傛暟
+ // var requestData = new
+ // {
+ // searchDate = searchDate.ToString("yyyy-MM-dd HH:mm:ss")
+ // };
+
+ // // 鍙戣捣璇锋眰
+ // var result = HttpHelper.Post(url, requestData.ToJsonString());
+
+ // // 鍙嶅簭鍒楀寲
+ // var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstreamOrderInfo>>(result);
+
+ // if (response.resultCode != "0")
+ // {
+ // // 璋冪敤寮傚父鎺ュ彛
+ // SendErrorToUpstream(1, "", response.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触", "");
+ // return responseContent.Error(response.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触");
+ // }
+
+ // if (response.data == null || !response.data.Any())
+ // {
+ // return responseContent.OK("鏃犳柊鍏ュ簱鍗曟暟鎹�");
+ // }
+
+ // Db.Ado.BeginTran();
+ // List<Dt_CabinOrder> _CabinOrders = new List<Dt_CabinOrder>();
+ // foreach (var order in response.data)
+ // {
+ // try
+ // {
+ // // 鎻掑叆鍏ュ簱鍗曡〃
+ // var entityOrder = new Dt_CabinOrder
+ // {
+
+ // Order_no = order.order_no,
+ // Order_type = order.order_type,
+ // Supplier_no = order.supplier_no,
+ // Account_tiem = order.account_time,
+ // OdrderStatus = "鏂板缓",
+ // };
+ // //var orderId = Db.Insertable(entityOrder).ExecuteReturnIdentity(); //灏辨槸杩斿洖涓婚敭ID銆�
+
+ // // 鎻掑叆鍏ュ簱鏄庣粏琛�
+ // var detailEntities = order.details.Select(d => new Dt_CabinOrderDetail
+ // {
+ // //OrderId= orderId,
+ // Goods_no = d.goods_no,
+ // Order_qty = d.order_qty,
+ // Batch_num = d.batch_num,
+ // Exp_date = d.exp_date,
+ // Warehouse_no = d.warehouse_no,
+ // Status = 0,
+ // }).ToList();
+ // entityOrder.Details.AddRange(detailEntities); //寤虹珛涓诲璞′笌瀛愬璞$殑鍏宠仈鍏崇郴
+ // _CabinOrders.Add(entityOrder);
+
+ // //鑷繁
+ // /// Db.Insertable(detailEntities).ExecuteCommand();
+
+ // //杩欓噷瑕佽皟鐢ㄤ竴涓帴鍙e皢涓婇潰鐨勪俊鎭紶缁檞cs锛岀劧鍚庢敼鍙樼姸鎬�
+ // }
+ // catch (Exception innerEx)
+ // {
+ // // 閽堝鏌愭潯璁㈠崟鎶ラ敊鏃讹紝鎺ㄩ�佸紓甯哥粰涓婃父
+ // SendErrorToUpstream(1, order.order_no, innerEx.Message, "");
+ // throw; // 鎶涘嚭寮傚父锛岃澶栧眰鎹曡幏鍥炴粴
+ // }
+ // }
+ // // 鎵归噺鎻掑叆锛圫qlSugar鑷姩澶勭悊涓诲閿叧绯伙級
+ // Db.Insertable(_CabinOrders).ExecuteCommand();
+ // Db.Ado.CommitTran();
+
+ // //濡傛灉EdiIn瀹屾垚閭d箞灏辫皟鐢–ompleteOrder鎺ュ彛
+
+ // return responseContent.OK("鍚屾鍏ュ簱鍗曟垚鍔�");
+ // }
+ // catch (Exception ex)
+ // {
+ // // 鍏ㄥ眬寮傚父鏃讹紝涔熸帹閫佸紓甯哥粰涓婃父
+ // SendErrorToUpstream(1, "", ex.Message, "");
+ // Db.Ado.RollbackTran();
+ // return responseContent.Error("鍚屾澶辫触: " + ex.Message);
+ // }
+ //}
+
+
+ public WebResponseContent GetUpstreamOrder()
{
var responseContent = new WebResponseContent();
@@ -37,17 +136,16 @@
{
// 璇锋眰鍦板潃
var url = "http://127.0.0.1:9090/GYZ2/95fck/inOrder";
-
- // 璇锋眰鍙傛暟
+ if (string.IsNullOrEmpty(SearchDate)) SearchDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+ //// 璇锋眰鍙傛暟
var requestData = new
{
- searchDate = searchDate.ToString("yyyy-MM-dd HH:mm:ss")
+ searchDate = SearchDate
};
-
+ SearchDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
// 鍙戣捣璇锋眰
var result = HttpHelper.Post(url, requestData.ToJsonString());
-
// 鍙嶅簭鍒楀寲
var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstreamOrderInfo>>(result);
@@ -64,56 +162,189 @@
}
Db.Ado.BeginTran();
-
- foreach (var order in response.data)
+ try
{
- try
+ List<Dt_CabinOrder> _CabinOrders = new List<Dt_CabinOrder>();
+ //瀛樺偍鍏ュ簱鍗曞彿
+ List<string> orderNos = new List<string>();
+
+ foreach (var order in response.data)
{
- // 鎻掑叆鍏ュ簱鍗曡〃
var entityOrder = new Dt_CabinOrder
{
Order_no = order.order_no,
Order_type = order.order_type,
Supplier_no = order.supplier_no,
- Account_tiem= order.account_time,
+ Account_tiem = order.account_time,
+ OdrderStatus = "鏂板缓",
+ Details = order.details.Select(d => new Dt_CabinOrderDetail
+ {
+ Goods_no = d.goods_no,
+ Order_qty = d.order_qty,
+ Batch_num = d.batch_num,
+ Exp_date = d.exp_date,
+ Warehouse_no = d.warehouse_no,
+ OrderDetailStatus="鏂板缓",
+ Status = d.warehouse_no== "001" ? 0 : 2, //濡傛灉鏄�001鎴块偅涔堝氨鏄湭鍚屾鐘舵�侊紝濡傛灉涓嶆槸001鎴块偅涔堝氨鏄棤闇�鍚屾鐘舵��
+ }).ToList()
};
+ _CabinOrders.Add(entityOrder);
+ orderNos.Add(order.order_no);
+ };
+ BaseDal.Db.InsertNav(_CabinOrders).Include(x => x.Details).ExecuteCommand();
- var orderId = Db.Insertable(entityOrder).ExecuteReturnIdentity(); //灏辨槸杩斿洖涓婚敭ID銆�
-
- // 鎻掑叆鍏ュ簱鏄庣粏琛�
- var detailEntities = order.details.Select(d => new Dt_CabinOrderDetail
- {
- OrderId = orderId,
- Goods_no = d.goods_no,
- Order_qty = d.order_qty,
- Batch_num = d.batch_num,
- Exp_date = d.exp_date,
- Warehouse_no = d.warehouse_no,
- Status = 0,
- }).ToList();
-
- Db.Insertable(detailEntities).ExecuteCommand();
- }
- catch (Exception innerEx)
+ //鍦ㄤ笅鍙戠粰wcs
+ var reslut= EdiIn(); //鍙戠粰涓嬫父
+ //濡傛灉杩欎釜鏂规硶鎴愬姛浜嗭紝閭d箞灏辫皟鐢–ompleteOrder鎺ュ彛锛岀劧鍚庢敼鍙�
+ if (reslut.Status==true)
{
- // 閽堝鏌愭潯璁㈠崟鎶ラ敊鏃讹紝鎺ㄩ�佸紓甯哥粰涓婃父
- SendErrorToUpstream(1, order.order_no, innerEx.Message, "");
- throw; // 鎶涘嚭寮傚父锛岃澶栧眰鎹曡幏鍥炴粴
+ //濡傛灉EdiIn瀹屾垚閭d箞灏辫皟鐢–ompleteOrder鎺ュ彛锛屽皢鐘舵�佹敼涓篣pOrderStatus == "宸插畬鎴�
+ foreach (var no in orderNos)
+ {
+ //CompleteOrder(no); // 浣跨敤鏀堕泦鐨勫崟鍙�
+
+ //Db.Updateable<Dt_CabinOrder>()
+ // .SetColumns(o => o.UpOrderStatus == "宸插畬鎴�") // 鏇存柊涓婃父鐘舵��
+ // .Where(o => o.Order_no == no && o.OdrderStatus == "宸插畬鎴�")
+ // .ExecuteCommand();
+ }
}
+ Db.Ado.CommitTran();
+ return responseContent.OK("鍚屾鍏ュ簱鍗曟垚鍔�");
}
-
- Db.Ado.CommitTran();
-
- return responseContent.OK("鍚屾鍏ュ簱鍗曟垚鍔�");
+ catch (Exception ex)
+ {
+ Db.Ado.RollbackTran();
+ SendErrorToUpstream(1, "", ex.Message, "");
+ return responseContent.Error("鍚屾澶辫触: " + ex.Message);
+ }
}
catch (Exception ex)
{
// 鍏ㄥ眬寮傚父鏃讹紝涔熸帹閫佸紓甯哥粰涓婃父
SendErrorToUpstream(1, "", ex.Message, "");
- Db.Ado.RollbackTran();
return responseContent.Error("鍚屾澶辫触: " + ex.Message);
}
}
+
+ /// <summary>
+ /// 浼犵粰wcs
+ /// </summary>
+ public WebResponseContent EdiIn()
+ {
+ try
+ {
+ // 1. 鍏堟壘鍑鸿嚦灏戞湁涓�鏉$鍚堟潯浠剁殑鏄庣粏瀵瑰簲鐨勮鍗旾D
+ //var validOrderIds = Db.Queryable<Dt_CabinOrderDetail>()
+ // .Where(d => d.Status == 0 || d.Status == 2)
+ // .Select(d => d.OrderId)
+ // .Distinct()
+ // .ToList();
+
+ // 2. 鏌ヨ绗﹀悎鏉′欢鐨勮鍗曪紙琛ㄥご=鏂板缓 && 鍖呭惈鏈夋晥鏄庣粏锛�
+ var orders = BaseDal.Db.Queryable<Dt_CabinOrder>()
+ .Where(o => o.OdrderStatus == "鏂板缓")
+ .Includes(o => o.Details, d => d.MedicineGoods)
+ .ToList();
+ // 3. 鍐嶈繃婊ゆ帀涓嶇鍚堟潯浠剁殑鏄庣粏锛堝彧淇濈暀 Status=0锛�
+ foreach (var order in orders)
+ {
+ order.Details = order.Details.Where(d => d.Status == 0).ToList();
+ }
+
+ if (orders == null || !orders.Any())
+ {
+ Console.WriteLine("娌℃湁绗﹀悎鏉′欢鐨勮鍗曢渶瑕佹帹閫�");
+ return WebResponseContent.Instance.Error("娌℃湁绗﹀悎鏉′欢鐨勮鍗曢渶瑕佹帹閫�");
+ }
+
+ // 4. 閬嶅巻璁㈠崟锛岀粍瑁� DTO 骞舵帹閫�
+ foreach (var order in orders)
+ {
+ var ediDto = new ToediInInfo
+ {
+ //瀹㈡埛浠g爜
+ customerCode = "905",
+ //鐗╂枡绫诲瀷
+ materialCode = "YY",
+ //鍏ュ簱鍗曞彿
+ externalOrderNo = order.Order_no,
+ //鍏ュ簱鍗曠被鍨�
+ inOrderType = order.Order_type == "1" ? "10" : "20",
+ //浼樺厛绾�
+ priority = 0,
+ //鏄惁鍙栨秷
+ Is_cancel = 0,
+ details = order.Details.Select(d => new ToediInDetail
+ {
+ //鎵瑰彿
+ batchNo = d.Batch_num,
+ //浜у搧
+ productCode = d.Goods_no,
+ //sku鍚嶇О
+ productName = d.MedicineGoods?.Goods_spm,
+ //sku瑙勬牸
+ productSpecifications = d.MedicineGoods?.Model,
+ //鏁伴噺
+ quantity = (int)d.Order_qty,
+ //鏁堟湡
+ validityPeriod = d.Exp_date,
+ //鐢熶骇鍘傚
+ manufacturer = d.MedicineGoods?.Factory,
+ //鎴垮彿
+ libraryNo = d.Warehouse_no,
+ //鐩樼泩鍏ュ簱
+ //stocktakingDetails = new List<ToediInStock>()
+ //stocktakingDetails = new List<ToediInStock>()
+ //{
+ // new ToediInStock
+ // {
+ // //鏂欑鍙�
+ // palletCode = "PDA001",
+ // //鏁伴噺
+ // quantity = d.Order_qty.ToString()
+ // }
+ // }
+ }).ToList()
+ };
+
+ var url = "http://172.16.1.2:9357/file-admin/api/in/ediIn";
+ var result = HttpHelper.Post(url, ediDto.ToJsonString());
+ var resp = JsonConvert.DeserializeObject<TowcsResponse<object>>(result);
+
+ if (resp != null && resp.code == "0")
+ {
+ // 鏇存柊琛ㄥご鐘舵��
+ Db.Updateable<Dt_CabinOrder>()
+ .SetColumns(o => new Dt_CabinOrder { OdrderStatus = "寮�濮�" })
+ .Where(o => o.Id == order.Id)
+ .ExecuteCommand();
+
+ // 鏇存柊鏄庣粏鐘舵�佷负宸插悓姝�
+ Db.Updateable<Dt_CabinOrderDetail>()
+ .SetColumns(d => new Dt_CabinOrderDetail { Status = 1, OrderDetailStatus = "宸插畬鎴�" })
+ .Where(d => d.OrderId == order.Id && d.Status == 0)
+ .ExecuteCommand();
+
+ Console.WriteLine($"璁㈠崟 {order.Order_no} 鎺ㄩ�佹垚鍔�");
+ }
+ else
+ {
+ SendErrorToUpstream(3, order.Order_no, resp?.msg ?? "WCS 鎺ㄩ�佸け璐�", "");
+ Console.WriteLine($"璁㈠崟 {order.Order_no} 鎺ㄩ�佸け璐ワ細{resp?.msg}");
+ return new WebResponseContent { Status = false, Message = "璁㈠崟鎺ㄩ�佸け璐�" };
+ }
+ }
+ return new WebResponseContent { Status = true, Message = "鎺ㄩ�佹垚鍔�" };
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("EdiIn 寮傚父锛�" + ex.Message);
+ return new WebResponseContent { Status = false, Message = ex.Message };
+ }
+ }
+
+
/// <summary>
/// 鍏ュ簱鎶ュ畬鎴愭帴鍙�
@@ -129,24 +360,54 @@
{
return responseContent.Error("鍏ュ簱鍗曞彿涓嶅彲浠ヤ负绌�");
}
- var url = " http://127.0.0.1:9090/GYZ2/95fck/inOrderOk";
- var reslut=HttpHelper.Post(url, new {order_no }.ToJsonString());
- var response = JsonConvert.DeserializeObject<UpstreamOrderResponse>(reslut);
+
+ var url = "http://127.0.0.1:9090/GYZ2/95fck/inOrderOk";
+ var result = HttpHelper.Post(url, new { order_no }.ToJsonString());
+ var response = JsonConvert.DeserializeObject<UpstreamOrderResponse>(result);
+
if (response.resultCode != "0")
{
SendErrorToUpstream(2, "", "涓婃父鎺ュ彛杩斿洖澶辫触", "");
return responseContent.Error(response.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触");
}
- return responseContent.OK("鎿嶄綔鎴愬姛");
+
+ // 鍏堟煡琛ㄥご
+ var order = Db.Queryable<Dt_CabinOrder>()
+ .First(o => o.Order_no == order_no);
+
+ if (order == null)
+ {
+ return responseContent.Error($"鏈壘鍒板叆搴撳崟鍙�: {order_no}");
+ }
+
+ // 鏌ヨ鎵�鏈夋槑缁嗘槸鍚﹂兘宸插畬鎴�
+ var allDetailsCompleted = Db.Queryable<Dt_CabinOrderDetail>()
+ .Where(d => d.OrderId == order.Id&&d.OrderDetailStatus=="宸插畬鎴�") // 鏄庣粏琛ㄧ敤 OrderId 鍏宠仈涓昏〃
+ .Count();
+
+ if (allDetailsCompleted>0)
+ {
+ // 鏇存柊琛ㄥご鐘舵�佷负宸插畬鎴�
+ Db.Updateable<Dt_CabinOrder>()
+ .SetColumns(o => o.OdrderStatus == "宸插畬鎴�")
+ .Where(o => o.Order_no == order_no)
+ .ExecuteCommand();
+
+ return responseContent.OK("鎿嶄綔鎴愬姛锛屽叆搴撳崟鍙婃槑缁嗗叏閮ㄥ畬鎴�");
+ }
+ else
+ {
+ return responseContent.OK("鎿嶄綔鎴愬姛锛屼絾浠嶆湁鏈畬鎴愮殑鏄庣粏");
+ }
+ //鍒犻櫎鍏ㄩ儴鐘朵负宸插畬鎴愮殑鏄庣粏鍜岃〃澶达紝绉诲叆鍘嗗彶琛�
}
-
catch (Exception ex)
{
SendErrorToUpstream(1, "", ex.Message, "");
return responseContent.Error("鍚屾澶辫触: " + ex.Message);
}
-
}
+
/// <summary>
/// 鎺ㄩ�佸紓甯镐俊鎭粰涓婃父绯荤粺1.鍏ュ簱鍗曟帴鍙o紱2.鍏ュ簱鍗曟姤瀹屾垚鎺ュ彛锛�3.鍑哄簱鍗曟帴鍙o紱4.鍑哄簱鎶ュ畬鎴愭帴鍙o紱5.鑽搧鍩虹淇℃伅鍚屾鎺ュ彛锛�6.渚涘簲鍟嗕俊鎭帴鍙o紱7.瀹㈡埛淇℃伅鎺ュ彛锛�8.搴撳瓨
@@ -179,5 +440,6 @@
+
}
}
--
Gitblit v1.9.3