From 38e3e2daa5f33cb78fb9019553b9b2d53e63ec54 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 14 Sep 2023 20:59:26 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E9=85=8D=E6=96=B9?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E7=BB=93=E6=9E=9C=E5=90=84=E5=88=97=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8F=96=E5=80=BC=202=E3=80=81=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=85=8D=E6=96=B9=E5=AF=BC=E5=87=BA=E6=AC=A1=E6=95=B0=E5=92=8C?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=97=A5=E6=9C=9F=203=E3=80=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=85=8D=E6=96=B9=E7=94=B3=E8=AF=B7=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=88=97=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=AC=A1=E6=95=B0=E5=92=8C=E6=9C=80=E5=90=8E=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/FormulaController.cs | 110 ++++++++++++++++-- FactorySystemBll/FormulaBll.cs | 60 +++++++++- FactorySystemModel/BusinessModel/BomModel.cs | 9 ++ .../SqlSugarModel/TFS_FormualApplyHistory.cs | 9 +- 4 files changed, 176 insertions(+), 12 deletions(-) diff --git a/FactorySystemApi/Controllers/FormulaController.cs b/FactorySystemApi/Controllers/FormulaController.cs index 81a5de7..047c3f2 100644 --- a/FactorySystemApi/Controllers/FormulaController.cs +++ b/FactorySystemApi/Controllers/FormulaController.cs @@ -359,6 +359,7 @@ namespace FactorySystemApi.Controllers { ApiResult apiResult = new ApiResult(); ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + Dictionary resultObj = new Dictionary(); return ExceptionHelper.TryReturnException(() => { @@ -373,6 +374,7 @@ namespace FactorySystemApi.Controllers { TFS_Formula formula = formulas[0]; OAService oAService = new OAService(); + string bomListStr = ""; List specifList = new List() { new Specifications() }; @@ -387,13 +389,87 @@ namespace FactorySystemApi.Controllers RestResult restResult = oAService.GetSpecificationsList(oaParam); - apiResult.Data = restResult.data; - - if (restResult.data != null) + if (restResult != null && restResult.data != null) { - FormulaBll.AddFormulaApplyHistroy(formula, user.FName, user.FID); + List bomList = JsonConvert.DeserializeObject>(restResult.data.ToString()); + string materialCodes = ","; + string testCodes = ","; + + if (bomList != null && bomList.Count > 0) + { + List subBomList = bomList[0].Specifications; + + if (subBomList != null && subBomList.Count > 0) + { + foreach(BomModel bom in subBomList) + { + if (bom.Type == "a" || bom.Type == "f") + { + bom.ABomType = "20"; + } + else if (bom.Type == "b" || bom.Type == "bb" || bom.Type == "i" || bom.Type == "iz") + { + bom.ABomType = "30"; + } + else + { + bom.ABomType = "40"; + } + + if ("40".Equals(bom.ABomType)) + { + bom.ASapCode = bom.SP_VALUE; + materialCodes = materialCodes + bom.ASapCode + ","; + } + else + { + bom.ATestCode = bom.SP_VALUE; + testCodes = testCodes + bom.ATestCode + ","; + } + } + + List viewsByMaterialCodes = FormulaBll.GetViewByMaterialCodes(materialCodes); + List viewsByTestCodes = FormulaBll.GetViewByTestCodes(testCodes); + + foreach (BomModel bom in subBomList) + { + if ("40".Equals(bom.ABomType)) + { + if (viewsByMaterialCodes != null && viewsByMaterialCodes.Count > 0) + { + TFS_ViewMaterial view = viewsByMaterialCodes.Find(v => v.FBaseMaterialCode.Equals(bom.ASapCode)); + if (view != null) + { + bom.AMaterialCode = view.FSaleOldMaterialCode; + } + } + } + else + { + if (viewsByTestCodes != null && viewsByTestCodes.Count > 0) + { + TFS_ViewMaterial view = viewsByTestCodes.Find(v => v.FBaseTestCode.Equals(bom.ATestCode)); + if (view != null) + { + bom.AMaterialCode = view.FSaleOldMaterialCode; + bom.ASapCode = view.FBaseMaterialCode; + } + } + } + } + + int formulaApplyHistoryId = FormulaBll.AddFormulaApplyHistroy(formula, user.FName, user.FID); + + resultObj.Add("applyHistoryId", formulaApplyHistoryId); + resultObj.Add("bomList", bomList); + + bomListStr = JsonConvert.SerializeObject(resultObj); + } + } } + apiResult.Data = bomListStr; + } }, apiResult, Request); } @@ -465,11 +541,16 @@ namespace FactorySystemApi.Controllers List> bomList = JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(bomObj)); inParam.TryGetValue("FID", out object oFid); + inParam.TryGetValue("ApplyHisId", out object oApplyHisId); string sFid = oFid != null ? oFid.ToString() : "-1"; - int nFid = 0; + int nFid = -1; int.TryParse(sFid, out nFid); + string sApplyHisId = oApplyHisId != null ? oApplyHisId.ToString() : "-1"; + int nApplyHisId = -1; + int.TryParse(sApplyHisId, out nApplyHisId); + string testCode = ""; string userName = user.FName; string productNumber = ""; @@ -489,6 +570,15 @@ namespace FactorySystemApi.Controllers if (exportResult) { apiResult.Data = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, "").Trim('/') + savePath; + + TFS_FormulaApplyHistory formulaApplyHistory = FormulaBll.GetFormulaApplyHistory(nApplyHisId); + if (formulaApplyHistory != null) + { + formulaApplyHistory.FExportTimes = formulaApplyHistory.FExportTimes + 1; + formulaApplyHistory.FLastExportTime = DateTime.Now; + + FormulaBll.UpdateFormulaApplyHistory(formulaApplyHistory); + } } else { @@ -528,7 +618,8 @@ namespace FactorySystemApi.Controllers dataList.Columns.Add("申请人"); dataList.Columns.Add("试验号"); dataList.Columns.Add("产品名称"); - dataList.Columns.Add("申请数量"); + dataList.Columns.Add("导出次数"); + dataList.Columns.Add("最后导出时间"); dataList.Columns.Add("备注"); foreach (Dictionary his in hisList) @@ -539,14 +630,17 @@ namespace FactorySystemApi.Controllers string userName = his["FUserName"] != null ? his["FUserName"].ToString() : ""; string testCode = his["FTestCode"] != null ? his["FTestCode"].ToString() : ""; string formulaName = his["FFormulaName"] != null ? his["FFormulaName"].ToString() : ""; - string applyNumber = his["FApplyNumber"] != null ? his["FApplyNumber"].ToString() : ""; + string applyNumber = his["FApplyNumber"] != null ? his["FApplyNumber"].ToString() : "0"; + string exportTimes = his["FExportTimes"] != null ? his["FExportTimes"].ToString() : "0"; + string lastExportTime = string.Compare(exportTimes, "0") > 0 && his["FLastExportTime"] != null ? his["FLastExportTime"].ToString() : ""; string remark = his["FRemark"] != null ? his["FRemark"].ToString() : ""; row["申请日期"] = applyTime; row["申请人"] = userName; row["试验号"] = testCode; row["产品名称"] = formulaName; - row["申请数量"] = applyNumber; + row["导出次数"] = exportTimes; + row["最后导出时间"] = lastExportTime; row["备注"] = remark; dataList.Rows.Add(row); diff --git a/FactorySystemBll/FormulaBll.cs b/FactorySystemBll/FormulaBll.cs index 939ad85..c21f9af 100644 --- a/FactorySystemBll/FormulaBll.cs +++ b/FactorySystemBll/FormulaBll.cs @@ -351,7 +351,7 @@ namespace FactorySystemBll public int AddFormulaApplyHistroy(TFS_Formula formula, string userName, int userId) { SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - int okCount = 0; + int fid = -1; if (formula != null) { @@ -366,10 +366,10 @@ namespace FactorySystemBll formulaApplyHistory.FApplyNumber = 0; formulaApplyHistory.FRemark = ""; - okCount += db.Insertable(formulaApplyHistory).IgnoreColumns(true).ExecuteCommand(); + fid = db.Insertable(formulaApplyHistory).IgnoreColumns(true).ExecuteReturnIdentity(); } - return okCount; + return fid; } public List GetFormulaApplyHistory(int formulaId, int pageIndex, int pageSize) @@ -396,5 +396,59 @@ namespace FactorySystemBll return formulaApplyHistory; } + + public TFS_FormulaApplyHistory GetFormulaApplyHistory(int fid) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + TFS_FormulaApplyHistory formulaApplyHistory = null; + + formulaApplyHistory = db.Queryable() + .Where((fah) => fah.FID == fid) + .Select("*") + .First(); + + return formulaApplyHistory; + } + + public int UpdateFormulaApplyHistory(TFS_FormulaApplyHistory fah) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + int result = -1; + + result = db.Updateable(fah).IgnoreColumns(true).WhereColumns("FID").ExecuteCommand(); + + return result; + } + + public List GetViewByMaterialCodes(string codes) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + List views = null; + + if (!string.IsNullOrEmpty(codes.Replace(",", ""))) { + views = db.Queryable() + .Where((vm) => codes.Contains(vm.FBaseMaterialCode)) + .Select("*") + .ToList(); + } + + return views; + } + + public List GetViewByTestCodes(string codes) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + List views = null; + + if (!string.IsNullOrEmpty(codes.Replace(",", ""))) + { + views = db.Queryable() + .Where((vm) => codes.Contains(vm.FBaseTestCode)) + .Select("*") + .ToList(); + } + + return views; + } } } diff --git a/FactorySystemModel/BusinessModel/BomModel.cs b/FactorySystemModel/BusinessModel/BomModel.cs index d7cf343..2d25b4d 100644 --- a/FactorySystemModel/BusinessModel/BomModel.cs +++ b/FactorySystemModel/BusinessModel/BomModel.cs @@ -34,6 +34,15 @@ namespace FactorySystemModel.BusinessModel public string Version { get; set; } public string Quantity { get; set; } public string TestNO { get; set; } + + public string AMaterialCode { get; set; } + + public string ASapCode { get; set; } + + public string ATestCode { get; set; } + + public string ABomType { get; set; } + public List Specifications { get; set; } } diff --git a/FactorySystemModel/SqlSugarModel/TFS_FormualApplyHistory.cs b/FactorySystemModel/SqlSugarModel/TFS_FormualApplyHistory.cs index 2ee3944..5e9d2e0 100644 --- a/FactorySystemModel/SqlSugarModel/TFS_FormualApplyHistory.cs +++ b/FactorySystemModel/SqlSugarModel/TFS_FormualApplyHistory.cs @@ -56,7 +56,14 @@ namespace FactorySystemModel.SqlSugarModel /// 备注 /// public string FRemark { get; set; } - + /// + /// 导出次数 + /// + public int FExportTimes { get; set; } + /// + /// 最后导出时间 + /// + public DateTime FLastExportTime { get; set; } } }