From eed04ed7d7b2cca4ce406c8ca1a156c6cbb18f61 Mon Sep 17 00:00:00 2001
From: Yang <903110162@qq.com>
Date: Sat, 28 Oct 2023 22:06:37 +0800
Subject: [PATCH] commit by yzf
---
 .../Controllers/FormulaController.cs          | 165 +++++++++++++++++-
 FactorySystemBll/FormulaBll.cs                |  74 ++++++++
 FactorySystemModel/FactorySystemModel.csproj  |   1 +
 .../ResponseModel/FormulaRow.cs               |   5 +
 .../SqlSugarModel/TFS_UpdateFormula.cs        |  87 +++++++++
 5 files changed, 328 insertions(+), 4 deletions(-)
 create mode 100644 FactorySystemModel/SqlSugarModel/TFS_UpdateFormula.cs
diff --git a/FactorySystemApi/Controllers/FormulaController.cs b/FactorySystemApi/Controllers/FormulaController.cs
index c419b7e..08ec4c2 100644
--- a/FactorySystemApi/Controllers/FormulaController.cs
+++ b/FactorySystemApi/Controllers/FormulaController.cs
@@ -14,6 +14,7 @@ using FactorySystemModel.RequestModel;
 using FactorySystemApi.Plm_Formula;
 using System.Web.UI.WebControls;
 using Newtonsoft.Json;
+using Aspose.Cells;
 
 namespace FactorySystemApi.Controllers
 {
@@ -62,7 +63,19 @@ namespace FactorySystemApi.Controllers
                 apiResult.Data = FormulaBll.GetFormulaList();
             }, apiResult, Request);
         }
-
+        /// 
+        /// 获取修改配方集合
+        /// 
+        /// 
+        [HttpPost]
+        public ApiResult GetUpdateFormulaList() 
+        {
+            ApiResult apiResult = new ApiResult();
+            return ExceptionHelper.TryReturnException(() =>
+            {
+                apiResult.Data = FormulaBll.GetUpdateFormulaList();
+            }, apiResult, Request);
+        }
 
         /// 
         /// 分业请求
@@ -80,6 +93,65 @@ namespace FactorySystemApi.Controllers
                 };
             }, apiResult, Request);
         }
+        /// 
+        /// 获取配方变更列表
+        /// 
+        /// 
+        /// 
+        [HttpPost]
+
+        public ApiResult GetUpdateFormulaPageList(FormulaQuery fq)
+        {
+            ApiResult apiResult = new ApiResult();
+            return ExceptionHelper.TryReturnException(() =>
+            {
+                apiResult.Data = new
+                {
+                    List = FormulaBll.GetUpdateFormulaList(fq, out var totalNumber),
+                    Total = totalNumber
+                };
+            }, apiResult, Request);
+        }
+
+        /// 
+        /// 更新修改配方的描述及状态
+        /// 
+        /// 
+        /// 
+        [HttpPost]
+        public ApiResult EditUpdateFormula(Dictionary inParam) 
+        {
+            ApiResult apiResult = new ApiResult();
+            apiResult.Data = 0;
+            return ExceptionHelper.TryReturnException(() =>
+            {
+                if (inParam == null)
+                {
+                    apiResult.Error("未接收到参数");
+                }
+                if (!inParam.ContainsKey("FID")) 
+                {
+                    apiResult.Error("未接收到参数FID");
+                }
+                if (!inParam.ContainsKey("Remark"))
+                {
+                    apiResult.Error("未填写备注说明");
+                }
+                else 
+                {
+                    int userId = -1;
+                    userId = Request.Properties["token"] is ApiAuthInfo user ? user.FID : userId;
+                    int fid = int.Parse(inParam["FID"].ToString());
+                    TFS_UpdateFormula model = FormulaBll.GetUpdateFormulaByFID(fid);
+                    model.Update_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm");
+                    model.Remark = inParam["Remark"].ToString();
+                    model.Status = "已处理";
+                    model.Update_User = userId.ToString();
+
+                    apiResult.Data= FormulaBll.EditUpdateFormula(model);
+                }
+            }, apiResult, Request, inParam);
+        }
 
         /// 
         /// 对接配方数据(对方写入)
@@ -171,6 +243,8 @@ namespace FactorySystemApi.Controllers
                         int userId = -1;
                         if (Request.Properties.ContainsKey("token"))
                         {
+                         
+
                             userId = Request.Properties["token"] is ApiAuthInfo user ? user.FID : userId;
                             apiResult.Data = FormulaBll.DockingRecipeData(new List() { formula }, userId);
                         }
@@ -183,6 +257,83 @@ namespace FactorySystemApi.Controllers
             }, apiResult, Request, inParam);
         }
 
+        [HttpPost]
+        public ApiResult DockingChangeData(Dictionary inParam) 
+        {
+            ApiResult apiResult = new ApiResult();
+            apiResult.Data = 0;
+
+            return ExceptionHelper.TryReturnException(() =>
+            {
+                if (inParam == null)
+                {
+                    apiResult.Error("未接收到参数");
+                }
+                else
+                {
+
+
+
+                    if (!inParam.ContainsKey("SP"))
+                    {
+                        apiResult.Error("PLM规格内码不能为空");
+                    }
+                    else if (!inParam.ContainsKey("SP_VERSION"))
+                    {
+                        apiResult.Error("版本号不能为空");
+                    }
+                    else if (!inParam.ContainsKey("Name"))
+                    {
+                        apiResult.Error("配方中文名称不能为空");
+                    }
+                    else if (!inParam.ContainsKey("Type"))
+                    {
+                        apiResult.Error("配方类型不能为空");
+                    }
+                    else if (!inParam.ContainsKey("SP_AUTHOR"))
+                    {
+                        apiResult.Error("修改人不能为空");
+                    }
+                    else
+                    {
+                        //int userId = -1;
+                        if (Request.Properties.ContainsKey("token"))
+                        {
+                            string sVersion = inParam["SP_VERSION"].ToString();
+                            double dVersion;
+
+                            bool isVersionNum = double.TryParse(sVersion, out dVersion);
+
+                            if (isVersionNum)
+                            {
+                                sVersion = string.Format("{0:F4}", dVersion);
+                            }
+                            TFS_UpdateFormula tFS_UpdateFormula = new TFS_UpdateFormula()
+                            {
+                                SP = inParam["SP"].ToString(),
+                                SP_VERSION = sVersion,
+                                SP_VALUE = inParam["SP_VALUE"].ToString(),
+                                Name = inParam["Name"].ToString(),
+                                Type = inParam["Type"].ToString(),
+                                SP_AUTHOR = inParam["SP_AUTHOR"].ToString(),
+                                //Change_Content = inParam["Change_Content"].ToString(),
+                                Change_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm"),
+                                Change_Content = inParam.ContainsKey("Change_List")?inParam["Change_List"].ToString():"",
+                            };
+                            apiResult.Data = FormulaBll.SevaTFS_UpdateFormula(tFS_UpdateFormula);
+
+                            //userId = Request.Properties["token"] is ApiAuthInfo user ? user.FID : userId;
+                            //apiResult.Data = FormulaBll.DockingRecipeData(new List() { formula }, userId);
+                        }
+                        else
+                        {
+                            apiResult.Error("token信息不存在");
+                        }
+                    }
+                }
+            }, apiResult, Request, inParam);
+        }
+
         /// 
         /// (对接)SAP配方同步
         /// 
@@ -523,7 +674,7 @@ namespace FactorySystemApi.Controllers
                         FPlmCode = item.Code,
                         FName = item.Name,
                         //FCode = item.Code,
-                        FType = item.Type.ToLower(),
+                        FType = item.Type!=null? item.Type.ToLower():"",
                         //FTestCode = item.TestNO,
                         FVersionCode = item.Version,
                         FParentID = parentId
@@ -539,6 +690,8 @@ namespace FactorySystemApi.Controllers
                         FLevel = materLevel,
                         FBomMaterialID = material.FID
                     };
+
+                    
                     if (material.FType == "a" || material.FType == "f")
                     {
                         material.FType = "20";
@@ -603,13 +756,17 @@ namespace FactorySystemApi.Controllers
                             }
                         }
                     }
+                    if (string.IsNullOrWhiteSpace(item.AMaterialCode)) 
+                    {
+                        item.AMaterialCode = "空";
+                    }
                     item.ABomType = "kg";
 
-                    if (item.Name.Contains("@"))
+                    if (item.Name!=null&&item.Name.Contains("@"))
                     {
                         item.EnName = "甜味";
                     }
-                    else if (item.Name.Contains("□"))
+                    else if (item.Name != null && item.Name.Contains("□"))
                     {
                         item.EnName = "咸味";
                     }
diff --git a/FactorySystemBll/FormulaBll.cs b/FactorySystemBll/FormulaBll.cs
index 7933097..3301e55 100644
--- a/FactorySystemBll/FormulaBll.cs
+++ b/FactorySystemBll/FormulaBll.cs
@@ -29,6 +29,25 @@ namespace FactorySystemBll
             return AppSettingsHelper.GetSqlSugar().Queryable().Where(s => s.FDeleted != isDelete).Distinct().ToList();
         }
 
+
+
+        /// 
+        /// 获取修改配方信息
+        /// 
+        public static List GetUpdateFormulaList()
+        {
+            return AppSettingsHelper.GetSqlSugar().Queryable().Distinct().OrderByDescending(m=>m.Change_Time).ToList();
+        }
+
+        /// 
+        /// 获取修改配方信息更具ID获取
+        /// 
+        public static TFS_UpdateFormula GetUpdateFormulaByFID(int fid)
+        {
+            return AppSettingsHelper.GetSqlSugar().Queryable().Where(m=>m.FID==fid).Distinct().OrderByDescending(m => m.Change_Time).ToList().LastOrDefault();
+        }
+
+
         public List GetFormulaListById(int id)
         {
             int isDelete = (int)Constant.DeleteCode.已删除;
@@ -50,6 +69,23 @@ namespace FactorySystemBll
                 .WhereIF(tr.FName != null, s => s.FName.Contains(tr.FName) || s.FPlmCode.Contains(tr.FPlmCode) || s.FTestCode.Contains(tr.FTestCode) || s.FVersionCode.Contains(tr.FVersionCode))
                 .Select("*").ToPageList(tr.FPageIndex, tr.FPageSize, ref totalNumber);
         }
+        /// 
+        /// 获取配方变更列表
+        /// 
+        /// 
+        /// 
+        /// 
+        public List