From bfc11f87e2b64420c9917c0b9881b3e327d6f796 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期二, 04 十一月 2025 22:19:59 +0800
Subject: [PATCH] 优化调拨出入库

---
 代码管理/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/MedicineGoodsServices.cs |  144 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 125 insertions(+), 19 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/MedicineGoodsServices.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/MedicineGoodsServices.cs"
index 7ca4ca4..deeb0e9 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/MedicineGoodsServices.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/MedicineGoodsServices.cs"
@@ -2,6 +2,7 @@
 using Masuit.Tools;
 using Newtonsoft.Json;
 using SharpCompress.Common;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -14,8 +15,8 @@
 using WIDESEA_ISquareCabinRepository;
 using WIDESEA_ISquareCabinServices;
 using WIDESEA_Model.Models;
-using WIDESEA_SquareCabinRepository;
 using static WIDESEA_DTO.SquareCabin.OrderDto;
+using static WIDESEA_DTO.SquareCabin.TowcsDto;
 
 namespace WIDESEA_SquareCabinServices
 {
@@ -59,26 +60,49 @@
                     return responseContent.OK("鏃犳柊鑽搧鏁版嵁");
                 }
 
-                foreach (var Medicat in response.data)
+                #region
+                //foreach (var Medicat in response.data)
+                //{
+                //    var entity = new Dt_MedicineGoods
+                //    {
+                //        Goods_no = Medicat.goods_no,
+                //        Goods_spm = Medicat.goods_spm,
+                //        Model = Medicat.model,
+                //        Factory = Medicat.factory,
+                //        Unit = Medicat.unit,
+                //        Item_Iength = Medicat.item_length,
+                //        Item_weight = Medicat.item_weight,
+                //        Item_hight = Medicat.item_hight,
+                //        Item_volumn = Medicat.item_volumn,
+                //        Storage_cond = Medicat.storage_cond,
+                //        Remark = Medicat.remark,
+                //        GoodStatus = "鏈笅鍙�",
+                //        ModifyDate = Medicat.modify_date
+                //    };
+                //    AddData(entity);
+                //}
+                #endregion
+                // 鏀堕泦鎵�鏈夎鎻掑叆鐨勫疄浣�
+                var entityList = response.data.Select(Medicat => new Dt_MedicineGoods
                 {
-                    var entity = new Dt_MedicineGoods
-                    {
-                        Goods_no = Medicat.goods_no,
-                        Goods_spm = Medicat.goods_spm,
-                        Model = Medicat.model,
-                        Factory= Medicat.factory,
-                        Unit= Medicat.unit,
-                        Item_Iength=Medicat.item_length,
-                        Item_weight = Medicat.item_weight,
-                        Item_hight = Medicat.item_hight,
-                        Item_volumn = Medicat.item_volumn,
-                        Storage_cond=Medicat.storage_cond,
-                        Remark=Medicat.remark,
+                    Goods_no = Medicat.goods_no,
+                    Goods_spm = Medicat.goods_spm,
+                    Model = Medicat.model,
+                    Factory = Medicat.factory,
+                    Unit = Medicat.unit,
+                    Item_Iength = Medicat.item_length,
+                    Item_weight = Medicat.item_weight,
+                    Item_hight = Medicat.item_hight,
+                    Item_volumn = Medicat.item_volumn,
+                    Storage_cond = Medicat.storage_cond,
+                    Remark = Medicat.remark,
+                    GoodStatus = "鏈笅鍙�",
+                    ModifyDate = Medicat.modify_date
+                }).ToList();
+                // 涓�娆℃�ф壒閲忔彃鍏ユ暟鎹簱
+                BaseDal.Db.Insertable(entityList).ExecuteCommand();
 
-                        ModifyDate = Medicat.modify_date
-                    };
-                    AddData(entity);
-                }
+                ProductSynchronous();
                 return responseContent.OK("鍚屾鎴愬姛");
             }
             
@@ -88,6 +112,86 @@
                 return responseContent.Error(ex.Message);
             }
         }
+
+
+        /// <summary>
+        /// 鍙戠粰涓嬫父wcs鍚屾鑽搧淇℃伅
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent ProductSynchronous()
+        {
+            try
+            {
+                //鍏堟壘鍒版墍鏈夋湭涓嬪彂鐨勮嵂鍝�
+                var list = BaseDal.QueryData(x => x.GoodStatus == "鏈笅鍙�").ToList();
+                if (list == null || !list.Any())
+                {
+                    return new WebResponseContent().OK("鏃犳湭涓嬪彂鑽搧");
+                }
+                //鎵惧埌浜嗗氨灏嗘暣涓猯ist鍙戠粰涓嬫父绯荤粺
+                foreach (var item in list)
+                {
+                    var medicineDTO = new ProductInfo
+                    {
+                        //鐢ㄦ埛code
+                        customerCode = "905",
+                        //鐗╂枡绫诲瀷
+                        materialCode = "YY",
+                        //浜у搧缂栫爜
+                        productCode= item.Goods_no,
+                        //浜у搧鍚�
+                        productName =item.Goods_spm ,
+                        //浜у搧鏉$爜
+                        productBarCode= item.Goods_no,
+
+                        //瑙勬牸
+                        productSpecifications=item.Model,
+                        //鍗曚綅
+                        unit = item.Unit,
+                        //闀�
+                        singleProductLongNum = item.Item_Iength.ToString(),
+                        //瀹�
+                        singleProductWideNum = item.Item_weight.ToString(),
+                        //楂�
+                        singleProductHighNum = item.Item_hight.ToString(),
+                        //閲嶉噺
+                        singleProductWeight = item.Item_weight.ToString(),
+                        //浣撶Н
+                        singleProductVolume = item.Item_volumn.ToString(),
+                        //鏄惁鍙栨秷
+                        Is_delete = "0"
+                    };
+                    var url = "http://172.16.1.2:9357/file-admin/api/product/productSynchronous";
+                    var result = HttpHelper.Post(url, medicineDTO.ToJsonString());
+                    var resp = JsonConvert.DeserializeObject<TowcsResponse<object>>(result);
+
+                    if (resp!=null&&resp.code=="0")
+                    {
+                        //鏇存柊鑽搧鐘舵��-宸插畬鎴�
+                        BaseDal.Db.Updateable<Dt_MedicineGoods>()
+                            .SetColumns(x => x.GoodStatus == "涓嬪彂瀹屾垚")
+                            .Where(x => x.Goods_no == item.Goods_no)
+                            .ExecuteCommand();  
+                    }
+                    else
+                    {
+                        SendErrorToUpstream(5, medicineDTO.materialCode, resp?.msg ?? "WCS鑽搧淇℃伅鍚屾澶辫触", "");
+                      
+                        return new WebResponseContent { Status = false, Message = "璁㈠崟鎺ㄩ�佸け璐�" };
+                    }
+
+                }
+                return new WebResponseContent { Status = true, Message = "鎴愬姛" };
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine("ProductSynchronous 寮傚父锛�" + ex.Message);
+                return new WebResponseContent { Status = false, Message = ex.Message };
+            }
+
+        }
+
+
 
         /// <summary>
         /// 鎺ㄩ�佸紓甯镐俊鎭粰涓婃父绯荤粺1.鍏ュ簱鍗曟帴鍙o紱2.鍏ュ簱鍗曟姤瀹屾垚鎺ュ彛锛�3.鍑哄簱鍗曟帴鍙o紱4.鍑哄簱鎶ュ畬鎴愭帴鍙o紱5.鑽搧鍩虹淇℃伅鍚屾鎺ュ彛锛�6.渚涘簲鍟嗕俊鎭帴鍙o紱7.瀹㈡埛淇℃伅鎺ュ彛锛�8.搴撳瓨
@@ -115,5 +219,7 @@
                 Console.WriteLine("寮傚父鎺ュ彛鎺ㄩ�佸け璐ワ細" + e.Message);
             }
         }
+
+       
     }
 }

--
Gitblit v1.9.3