From 2b49f7643d15b74889d190f216630559006ed93a Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期一, 01 十二月 2025 09:48:43 +0800
Subject: [PATCH] pad和后端的优化

---
 新建文件夹/WIDESEA_WMSServer/ClassLibrary2/MaterielInfoService.cs |  304 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 304 insertions(+), 0 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/MaterielInfoService.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/MaterielInfoService.cs"
index e6c5208..11985c4 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/MaterielInfoService.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/MaterielInfoService.cs"
@@ -1,17 +1,20 @@
 锘縰sing HslCommunication;
 using Newtonsoft.Json;
 using Quartz.Util;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Helper;
 using WIDESEA_IWMsInfoServices;
 using WIDESEA_Model.Models;
+using static WIDESEA_DTO.SquareCabin.OrderDto;
 using static WIDESEA_DTO.SquareCabin.TowcsDto;
 
 namespace WIDESEA_WMsInfoServices
@@ -22,6 +25,289 @@
         {
         }
         public IRepository<Dt_MaterielInfo> Repository => BaseDal;
+
+
+        static string SearchDate = "2016-11-01 00:00:00";
+
+        /// <summary>
+        /// 鑾峰彇鑽搧鍩虹淇℃伅鍚屾鎺ュ彛
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent GetMedicineGoodsInfom()
+        {
+            var responseContent = new WebResponseContent();
+            try
+            {
+
+                var url = "http://192.168.1.100:80/GYZ2/95fck/goodsInfo";
+                if (string.IsNullOrEmpty(SearchDate))
+                {
+                    // 榛樿鏌ヨ杩囧幓24灏忔椂鐨勬暟鎹�
+                    SearchDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                }
+                string getDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                // 璇锋眰鍙傛暟
+                var requestData = new
+                {
+                    searchDate = SearchDate
+                };
+
+                // 鍙戣捣璇锋眰
+                var result = HttpHelper.Post(url, requestData.ToJsonString());
+
+                // 鍙嶅簭鍒楀寲
+                var response = JsonConvert.DeserializeObject<UpstreamResponse<MedicationsInfo>>(result);
+
+                if (response == null || response.resultCode != "0")
+                {
+                    // 璋冪敤寮傚父鎺ュ彛
+                    //SendErrorToUpstream(5, "", response.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触", "");
+                    return responseContent.Error(response?.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触");
+                }
+                if (response.data.Count < 1)
+                {
+                    SearchDate = getDate;
+                    return responseContent.OK("鏃犳柊鑽搧鏁版嵁");
+                }
+
+                var codes = response.data.Select(x => x.goods_no).ToList();
+
+                //鑾峰彇鎵�鏈夊凡瀛樺湪鐨勫晢鍝佺紪鍙�
+                var existingGoodsNos = BaseDal.QueryData(x => codes.Contains(x.MaterielCode)).Select(x => x.MaterielCode).ToList();
+
+                // 鏀堕泦鎵�鏈夎鎻掑叆鐨勫疄浣�
+                var entityList = response.data.Where(Medicat => !existingGoodsNos.Contains(Medicat.goods_no)).Select(Medicat => new Dt_MaterielInfo
+                {
+                    MaterielCode = Medicat.goods_no,
+                    MaterielErpType = Medicat.goods_type,
+                    item = Medicat.goods_tym, //閫氱敤鍚�
+                    MaterielName = Medicat.goods_spm,//鐗╂枡鍚嶇О
+                    Dosage_form = Medicat.dosage_form,//鑽墏
+                    Barcode = Medicat.barcode,//鏉″舰鍚�
+                    MaterielSpec = Medicat.model,
+                    Factory = Medicat.factory,
+                    MaterielUnit = Medicat.unit,//鍗曚綅
+                    MaterielSourceType = MaterielSourceTypeEnum.PurchasePart,
+                    // 浣跨敤 ?? 杩愮畻绗︽彁渚涢粯璁ゅ��
+                    MaterielLength = (float?)Medicat.item_length,
+                    MaterielWide = (float?)Medicat.item_width,
+                    MaterielHeight = (float?)Medicat.item_hight,
+                    MaterielVolume = (float?)Medicat.item_volumn,
+                    MaterielWeight = (float?)Medicat.item_weight,
+                    MaterielStoragecondition = float.TryParse(Medicat.storage_confition, out var val) ? val : null, //鍌ㄥ瓨鏉′欢
+                    Remark = Medicat.remark,
+                    GoodStatusState = "鏈笅鍙�",
+                    ModifyDate = Medicat.modify_date
+                }).ToList();
+                // 涓�娆℃�ф壒閲忔彃鍏ユ暟鎹簱
+                BaseDal.AddData(entityList);
+                SearchDate = getDate;
+                //ProductSynchronous();
+                return responseContent.OK("鍚屾鎴愬姛");
+            }
+
+            catch (Exception ex)
+            {
+                Console.WriteLine("鑾峰彇ERP鐗╂枡淇℃伅寮傚父锛�" + ex.Message);
+                //SendErrorToUpstream(5, "", ex.Message, "");
+                return responseContent.Error(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 鍒涘缓鑽墏瀛楀吀
+        /// </summary>
+        private static readonly Dictionary<string, string> _dosageFormMap = new Dictionary<string, string>
+        {
+            {"001", "鐗囧墏"}, {"002", "鐗囧墏"}, {"003", "鐗囧墏"}, {"004", "鐗囧墏"}, {"005", "鐗囧墏"},
+            {"006", "鐗囧墏"}, {"007", "鐗囧墏"}, {"008", "鐗囧墏"}, {"009", "鐗囧墏"}, {"010", "鐗囧墏"},
+            {"011", "鍏跺畠"}, {"012", "鐗囧墏"}, {"013", "鍏跺畠"}, {"014", "鐗囧墏"}, {"015", "鐗囧墏"},
+            {"016", "鐗囧墏"}, {"017", "鐗囧墏"}, {"018", "鍏跺畠"}, {"019", "鍏跺畠"}, {"020", "鍏跺畠"},
+            {"021", "閽堝墏"}, {"022", "閽堝墏"}, {"023", "閽堝墏"}, {"024", "閽堝墏"}, {"025", "涓垚鑽�"},
+            {"026", "涓垚鑽�"}, {"027", "鍏跺畠"}, {"028", "鍏跺畠"}, {"029", "鍏跺畠"}, {"030", "鍏跺畠"},
+            {"031", "鍏跺畠"}, {"032", "鍏跺畠"}, {"033", "鍏跺畠"}, {"034", "涓垚鑽�"}, {"035", "涓垚鑽�"},
+            {"036", "涓垚鑽�"}, {"037", "涓垚鑽�"}, {"038", "鍏跺畠"}, {"039", "鍏跺畠"}, {"040", "鍏跺畠"},
+            {"041", "涓垚鑽�"}, {"042", "涓垚鑽�"}, {"043", "涓垚鑽�"}, {"044", "鍏跺畠"}, {"045", "涓垚鑽�"},
+            {"046", "涓垚鑽�"}, {"047", "涓垚鑽�"}, {"048", "涓垚鑽�"}, {"049", "涓垚鑽�"}, {"050", "涓垚鑽�"},
+            {"051", "涓垚鑽�"}, {"052", "涓垚鑽�"}, {"053", "涓垚鑽�"}, {"054", "涓垚鑽�"}, {"055", "涓垚鑽�"},
+            {"056", "鍏跺畠"}, {"057", "鍏跺畠"}, {"058", "鍏跺畠"}, {"059", "鍏跺畠"}, {"060", "鍏跺畠"},
+            {"061", "鍏跺畠"}, {"062", "鍏跺畠"}, {"063", "鍏跺畠"}, {"064", "鍏跺畠"}, {"065", "鍏跺畠"},
+            {"066", "鍏跺畠"}, {"067", "涓垚鑽�"}, {"068", "涓垚鑽�"}, {"069", "涓垚鑽�"}, {"070", "鍏跺畠"},
+            {"071", "鍏跺畠"}, {"072", "鍏跺畠"}, {"073", "涓垚鑽�"}, {"074", "鍏跺畠"}, {"075", "鍏跺畠"},
+            {"076", "涓垚鑽�"}, {"077", "鍏跺畠"}, {"078", "鍏跺畠"}, {"079", "涓垚鑽�"}, {"080", "涓垚鑽�"},
+            {"081", "涓垚鑽�"}, {"082", "涓垚鑽�"}, {"083", "鍏跺畠"}, {"084", "涓垚鑽�"}, {"085", "鍏跺畠"},
+            {"086", "涓垚鑽�"}, {"087", "鍏跺畠"}, {"088", "鍏跺畠"}, {"089", "涓垚鑽�"}, {"090", "涓垚鑽�"},
+            {"091", "鍏跺畠"}, {"092", "鍏跺畠"}, {"093", "鍏跺畠"}, {"094", "涓垚鑽�"}, {"095", "鍏跺畠"},
+            {"096", "鍏跺畠"}, {"097", "鍏跺畠"}, {"098", "鍏跺畠"}, {"099", "鍏跺畠"}, {"100", "鍏跺畠"},
+            {"101", "鍏跺畠"}, {"102", "鍏跺畠"}, {"103", "鍏跺畠"}, {"104", "鍏跺畠"}, {"105", "鍏跺畠"},
+            {"106", "鍏跺畠"}, {"107", "鍏跺畠"}, {"108", "鍏跺畠"}, {"109", "鍏跺畠"}, {"110", "鍏跺畠"},
+            {"111", "鍏跺畠"}, {"112", "鍏跺畠"}, {"113", "鍏跺畠"}, {"114", "鍏跺畠"}, {"115", "鍏跺畠"},
+            {"116", "鍏跺畠"}, {"117", "鍏朵粬"}
+        };
+
+        /// <summary>
+        /// 鏍规嵁鍓傚瀷缂栧彿鑾峰彇鍓傚瀷鍒嗙被
+        /// </summary>
+        /// <param name="dosageCode">鍓傚瀷缂栧彿(001-117)</param>
+        /// <returns>鍓傚瀷鍒嗙被(鐗囧墏/閽堝墏/涓垚鑽�/鍏跺畠/鍏朵粬)</returns>
+        public static string GetDosageForm(string dosageCode)
+        {
+            if (string.IsNullOrEmpty(dosageCode))
+                return "鏈煡";
+
+            // 澶勭悊缂栧彿鏍煎紡锛岀‘淇濇槸3浣嶆暟瀛�
+            if (dosageCode.Length == 1)
+                dosageCode = "00" + dosageCode;
+            else if (dosageCode.Length == 2)
+                dosageCode = "0" + dosageCode;
+
+            if (_dosageFormMap.TryGetValue(dosageCode, out string form))
+            {
+                return form;
+            }
+
+            return "鏈煡";
+        }
+
+
+        /// <summary>
+        /// 鍙戠粰涓嬫父wcs鍚屾鑽搧淇℃伅 
+        /// </summary>
+        /// <returns></returns>
+        #region 鍚屾涓嬫父鐗╂枡鎺ュ彛
+        //public WebResponseContent ProductSynchronous()
+        //{
+        //    try
+        //    {
+        //        List<Dt_MaterielInfo> materielInfos = BaseDal.QueryData(x => x.MaterielSourceType == MaterielSourceTypeEnum.SelfMadePart && x.BoxQty > 0 && x.MinQty > 0 && x.GoodStatusState == "鏈笅鍙�").ToList();
+        //        if (materielInfos.Count < 1) return WebResponseContent.Instance.Error("鏃犳湭涓嬪彂鑽搧");
+        //        var url = "http://172.16.1.2:9357/file-admin/api/product/productSynchronous";
+        //        foreach (var item in materielInfos)
+        //        {
+        //            var medicineDTO = new ProductInfo
+        //            {
+        //                //鐢ㄦ埛code
+        //                customerCode = "905",
+        //                //鐗╂枡绫诲瀷
+        //                materialCode = item.MaterielErpType,
+        //                //浜у搧缂栫爜
+        //                productCode = item.MaterielCode,
+        //                //浜у搧鍚�
+        //                productName = item.MaterielName,
+        //                //浜у搧鏉$爜
+        //                productBarCode = item.Barcode,
+
+        //                //鑽墏
+        //                medicine = item.Dosage_form,//杩欓噷瑕佽皟鐢ㄦ柟娉曪紝杞寲鏂规硶
+
+        //                //瑙勬牸
+        //                productSpecifications = item.MaterielSpec,
+        //                //鍗曚綅
+        //                unit = item.MaterielUnit,
+        //                //闀�
+        //                singleProductLongNum = (item.MaterielLength ?? 0).ToString(),
+        //                //瀹�
+        //                singleProductWideNum = (item.MaterielWide ?? 0).ToString(),
+        //                //楂�
+        //                singleProductHighNum = (item.MaterielHeight ?? 0).ToString(),
+        //                //閲嶉噺
+        //                singleProductWeight = (item.MaterielWeight ?? 0).ToString(),
+        //                //浣撶Н
+        //                singleProductVolume = (item.MaterielVolume ?? 0).ToString(),
+        //                //鏄惁鍙栨秷 0鏄笉鍒犻櫎锛�1鍒犻櫎
+        //                isDelete = "0"
+        //            };
+        //            var result = HttpHelper.Post(url, medicineDTO.ToJsonString());
+        //            var resp = JsonConvert.DeserializeObject<TowcsResponse<object>>(result);
+        //            if (resp != null && resp.code == "0") item.GoodStatusState = "涓嬪彂瀹屾垚";
+        //        }
+        //        BaseDal.UpdateData(materielInfos);
+        //        return WebResponseContent.Instance.OK();
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        Console.WriteLine("涓嬪彂WCS鐗╂枡淇℃伅寮傚父锛�" + ex.Message);
+        //        return WebResponseContent.Instance.Error(ex.Message);
+        //    }
+        //}
+        #endregion
+
+
+        #region 鎵嬪姩鍏抽棴鏁版嵁搴撹繛鎺� 鍚屾涓嬫父鐗╂枡 
+        public WebResponseContent ProductSynchronous()
+        {
+            using (var db = new SqlSugarClient(new ConnectionConfig
+            {
+                ConnectionString = "Data Source=.;Initial Catalog=WIDESEA_WMSDBF_Z22;User ID=sa;Password=48PYX_h7KS@f;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
+                DbType = DbType.SqlServer,
+                IsAutoCloseConnection = true,  // 鍏抽敭閰嶇疆锛岃嚜鍔ㄥ叧闂繛鎺�
+                MoreSettings = new ConnMoreSettings()
+                {
+                    IsAutoRemoveDataCache = true
+                }
+            }))
+            {
+                try
+                {
+                    List<Dt_MaterielInfo> materielInfos = db.Queryable<Dt_MaterielInfo>().Where(x => x.MaterielSourceType == MaterielSourceTypeEnum.SelfMadePart && x.BoxQty > 0 && x.MinQty > 0 && x.GoodStatusState == "鏈笅鍙�").ToList();
+                    if (materielInfos.Count < 1)
+                    {
+
+                        return WebResponseContent.Instance.Error("鏃犳湭涓嬪彂鑽搧");
+                    }
+                    var url = "http://172.16.1.2:9357/file-admin/api/product/productSynchronous";
+                    foreach (var item in materielInfos)
+                    {
+                        var medicineDTO = new ProductInfo
+                        {
+                            //鐢ㄦ埛code
+                            customerCode = "905",
+                            //鐗╂枡绫诲瀷
+                            materialCode = item.MaterielErpType,
+                            //浜у搧缂栫爜
+                            productCode = item.MaterielCode,
+                            //浜у搧鍚�
+                            productName = item.MaterielName,
+                            //浜у搧鏉$爜
+                            productBarCode = item.Barcode,
+
+                            //鑽墏
+                            medicine = item.Dosage_form,//杩欓噷瑕佽皟鐢ㄦ柟娉曪紝杞寲鏂规硶
+
+                            //瑙勬牸
+                            productSpecifications = item.MaterielSpec,
+                            //鍗曚綅
+                            unit = item.MaterielUnit,
+                            //闀�
+                            singleProductLongNum = (item.MaterielLength ?? 0).ToString(),
+                            //瀹�
+                            singleProductWideNum = (item.MaterielWide ?? 0).ToString(),
+                            //楂�
+                            singleProductHighNum = (item.MaterielHeight ?? 0).ToString(),
+                            //閲嶉噺
+                            singleProductWeight = (item.MaterielWeight ?? 0).ToString(),
+                            //浣撶Н
+                            singleProductVolume = (item.MaterielVolume ?? 0).ToString(),
+                            //鏄惁鍙栨秷 0鏄笉鍒犻櫎锛�1鍒犻櫎
+                            isDelete = "0"
+                        };
+                        var result = HttpHelper.Post(url, medicineDTO.ToJsonString());
+                        var resp = JsonConvert.DeserializeObject<TowcsResponse<object>>(result);
+                        if (resp != null && resp.code == "0") item.GoodStatusState = "涓嬪彂瀹屾垚";
+                    }
+                    db.Updateable(materielInfos).ExecuteCommand();
+
+                    return WebResponseContent.Instance.OK();
+                }
+                catch (Exception ex)
+                {
+                    Console.WriteLine("涓嬪彂WCS鐗╂枡淇℃伅寮傚父锛�" + ex.Message);
+                    return WebResponseContent.Instance.Error(ex.Message);
+                }
+            }
+        }
+        #endregion
+
         public override WebResponseContent DeleteData(object[] keys)
         {
             WebResponseContent content = new WebResponseContent();
@@ -74,5 +360,23 @@
             }
             return content;
         }
+
+
+
+        public override WebResponseContent UpdateData(SaveModel saveModel)
+        {
+            if (saveModel.MainData["goodStatusState"].ToString() != "鏈笅鍙�")
+            {
+                saveModel.MainData.Remove("goodStatusState");
+                saveModel.MainData.Add("goodStatusState", "鏈笅鍙�");
+            }
+            // 濡傛灉鐜板湪杩欎釜鐗╂枡淇℃伅鏄皬浠跺苟涓旂瑙勬垨鑰呮渶浣庡簱瀛樹负0锛岄偅涔堝氨瑕佹彁绀轰粬
+            if (saveModel.MainData["materielSourceType"].ToString() == "SelfMadePart" && (saveModel.MainData["boxQty"].ToString() == "0" || saveModel.MainData["minQty"].ToString() == "0"))
+            {
+                // 杩欓噷娣诲姞浣犵殑閫昏緫
+                return WebResponseContent.Instance.Error("绠辫鍜屾渶灏忓簱瀛樻暟涓嶅彲宸蹭负0");
+            }
+            return base.UpdateData(saveModel);
+        }
     }
 }

--
Gitblit v1.9.3