From d5008820dc1474f640629b7662912b35f5de747d Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 30 Jul 2023 18:00:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=B9=E9=87=8F=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=8D=8F=E5=90=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/TeamworkController.cs | 299 +++++++++++++++++- FactorySystemBll/TeamworkBll.cs | 13 + 2 files changed, 297 insertions(+), 15 deletions(-) diff --git a/FactorySystemApi/Controllers/TeamworkController.cs b/FactorySystemApi/Controllers/TeamworkController.cs index c1de017..d78476f 100644 --- a/FactorySystemApi/Controllers/TeamworkController.cs +++ b/FactorySystemApi/Controllers/TeamworkController.cs @@ -16,6 +16,7 @@ using System.Linq; using SqlSugar; using Aspose.Cells; using System.Web; +using System.Web.Http.Results; namespace FactorySystemApi.Controllers { @@ -812,6 +813,7 @@ namespace FactorySystemApi.Controllers public ApiResult UploadTeamworkFile() { ApiResult apiResult = new ApiResult(); + Dictionary> result = null; string filePath = ""; return ExceptionHelper.TryReturnException(() => @@ -835,8 +837,12 @@ namespace FactorySystemApi.Controllers } ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + + result = ReadTeamworkExcel(filePath); //apiResult.Data = CheckUploadFile(fileList, FFuncType, user.FID); } + + apiResult.Data = result; } }, apiResult, Request); @@ -845,33 +851,296 @@ namespace FactorySystemApi.Controllers /// /// 批量上传协同信息 /// - public int ReadTeamworkExcel(string file) + private Dictionary> ReadTeamworkExcel(string file) { - int teams = 0; - Workbook wb = new Workbook("file"); + Dictionary> result = new Dictionary>(); + List okList = new List(); + List errorList = new List(); + + result.Add("ok", okList); + result.Add("error", errorList); + + Workbook wb = new Workbook(file); Worksheet ws = wb.Worksheets[0]; // 遍历工作表中的所有单元格,读取其中的数据 for (int row = 1; row <= ws.Cells.MaxDataRow; row++) { + string okStr = row + ":ok"; + string errStr = row + ":"; + bool isOk = true; //ws.Cells[row, 0].Value; Dictionary inParam = new Dictionary(); + var saleCode = ws.Cells[row, 0].Value; // 新增销售号 + var packCode = ws.Cells[row, 1].Value; // 包规 + var factoryName = ws.Cells[row, 2].Value; // 模式 要变化为工厂ID + var materialGroup = ws.Cells[row, 3].Value; // 物料组 要变换为物料组ID + var weightUnit = ws.Cells[row, 4].Value; // 计量单位 + var testCode = ws.Cells[row, 5].Value; // 试验号 要跟版本号一起查询出配方 + var versionCode = ws.Cells[row, 6].Value; // 版本号 + var state = ws.Cells[row, 7].Value; // 创建方式(新增/暂存) + + if (state != null && state.ToString().Equals("新增")) + { + state = 1; + } + else + { + state = 0; + } + + // 新增时进行非空校验 + if (state.ToString().Equals("1")) + { + if (saleCode == null || string.IsNullOrEmpty(saleCode.ToString())) + { + errStr = errStr + "新增销售号不能为空;"; + isOk = false; + } + + if (packCode == null || string.IsNullOrEmpty(packCode.ToString())) + { + errStr = errStr + "包规不能为空;"; + isOk = false; + } + + if (factoryName == null || string.IsNullOrEmpty(factoryName.ToString())) + { + errStr = errStr + "模式不能为空;"; + isOk = false; + } + + if (materialGroup == null || string.IsNullOrEmpty(materialGroup.ToString())) + { + errStr = errStr + "物料组不能为空;"; + isOk = false; + } + + if (weightUnit == null || string.IsNullOrEmpty(weightUnit.ToString())) + { + errStr = errStr + "计量单位不能为空;"; + isOk = false; + } + + if (testCode == null || string.IsNullOrEmpty(testCode.ToString())) + { + errStr = errStr + "试验号不能为空;"; + isOk = false; + } + + if (versionCode == null || string.IsNullOrEmpty(versionCode.ToString())) + { + errStr = errStr + "版本号不能为空;"; + isOk = false; + } + } + + // 校验未通过,继续下一条 + if (!isOk) + { + errorList.Add(errStr); + continue; + } + + // 获取需要转换的值 + // 获取工厂ID + TFS_Factory factory = TeamworkBll.GetFactoryIdByName(factoryName.ToString()); + if (factory == null) + { + errStr = errStr + "模式不正确;"; + isOk = false; + } + var createFactoryId = factory.FID; + + // 获取物料组Id + if (!materialGroup.ToString().Contains("+")) + { + errStr = errStr + "物料组不正确;"; + isOk = false; + } + var materialGroupId = materialGroup.ToString().Split('+')[0]; + + // 获取配方 + TFS_Formula formula = TeamworkBll.GetFormulaByTestCodeAndVersion(testCode.ToString(), versionCode.ToString()); + if (formula == null) + { + errStr = errStr + "试验号或版本号不正确;"; + isOk = false; + } + var formulaName = formula.FName + "+" + formula.FTestCode + "+" + formula.FVersionCode; + var formulaId = formula.FID; + + // 校验未通过,继续下一条 + if (!isOk) + { + errorList.Add(errStr); + continue; + } + inParam.Add("FMaterialType", "ZMAT"); - inParam.Add("FSaleCode", ws.Cells[row, 0].Value); - inParam.Add("FPackCode", ws.Cells[row, 1].Value); - inParam.Add("FCreateFactoryID", ws.Cells[row, 2].Value); - inParam.Add("FMaterialGroup", ws.Cells[row, 3].Value); - inParam.Add("FTestCode", ws.Cells[row, 4].Value); - inParam.Add("FWeightUnit", ws.Cells[row, 5].Value); - inParam.Add("FFormulaName", ws.Cells[row, 6].Value); - inParam.Add("FState", ws.Cells[row, 7].Value); - inParam.Add("FFormulaID", ""); - inParam.Add("FVersionCode", ""); - inParam.Add("FFormulaTestCode", ""); + inParam.Add("FSaleCode", saleCode); + inParam.Add("FPackCode", packCode); + inParam.Add("FCreateFactoryID", createFactoryId); + inParam.Add("FMaterialGroup", materialGroupId); + inParam.Add("FTestCode", testCode); + inParam.Add("FWeightUnit", weightUnit); + inParam.Add("FFormulaName", formulaName); + inParam.Add("FState", state); + inParam.Add("FFormulaID", formulaId); + inParam.Add("FVersionCode", versionCode); + inParam.Add("FFormulaTestCode", testCode); + + string addTeamResult = AddTeam(inParam); + + if (!string.IsNullOrEmpty(addTeamResult)) + { + errStr = errStr + addTeamResult + ";"; + errorList.Add(errStr); + continue; + } + + okList.Add(okStr); + } + + return result; + } + + private string AddTeam(Dictionary inParam) + { + string result = ""; + //对接获取 + inParam.Add("FMdmCode", GetMdmCode(inParam)); + //var ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); + //inParam.Add("FMdmCode", ts.TotalSeconds.ToString("F0")); + if (!inParam.ContainsKey("FMdmCode") || string.IsNullOrEmpty(inParam["FMdmCode"].ToString().Trim())) + { + result = "获取MDM失败"; + } + else if (TeamworkBll.CheckTeamName(inParam["FSaleCode"].ToString())) + { + result = "销售号已存在"; } + else + { + inParam.TryGetValue("FState", out object state); + if (null == state) + { + inParam["FState"] = state = 1; + } + inParam.Remove("FID"); + ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + if (inParam.ContainsKey("FAddUser")) + { + inParam["FAddUser"] = user.FID; + } + else + { + inParam.Add("FAddUser", user.FID); + } + if (inParam.ContainsKey("FEditUser")) + { + inParam["FEditUser"] = user.FID; + } + else + { + inParam.Add("FEditUser", user.FID); + } + if (inParam.ContainsKey("FEditDate")) + { + inParam["FEditDate"] = DateTime.Now; + } + else + { + inParam.Add("FEditDate", DateTime.Now); + } + //TUser tUser = BaseBll.GetTempModel(user.FID); + TFS_Factory factory = BaseBll.GetTempModel(int.Parse(inParam["FCreateFactoryID"].ToString())); + if (inParam.ContainsKey("FCreateFactoryID")) + { + inParam.Remove("FCreateFactoryID"); + } + inParam.Add("FCreateFactoryID", factory.FID); + inParam.Add("FCreateFactoryCode", factory.FCode); + inParam.Add("FCreateFactoryType", factory.FType); + if (factory.FType != (int)Constant.FactoryType.单工厂) + { + factory = BaseBll.GetTempModel(factory.FFactoryID); + inParam.Add("FProdFactoryID", factory.FID); + inParam.Add("FProdFactoryCode", factory.FCode); + } + else + { + inParam.Add("FProdFactoryID", factory.FID); + inParam.Add("FProdFactoryCode", factory.FCode); + } + //创建 TFS_FTeamwork + int teamId = BaseBll.InsertDataModel(inParam, "TFS_FTeamwork"); + //apiResult.Data = teamId; + if (teamId > 0) + { + inParam.Add("FID", teamId); + //创建流程 + int resultProcessCreate = TeamworkBll.CreateProcessData(teamId, user.FID); + if (resultProcessCreate > 0) + { + //直接走下一步 + if (state.ToString().Contains("1")) + { + TFS_FTeamwork teamwork = BaseBll.GetTempModel(teamId); + List materialList = TeamworkBll.CheckMaterialListByTest(teamwork.FFormulaTestCode, teamwork.FVersionCode); + if (materialList.Count == 0) + { + TeamworkBll.CreateProductView(teamwork, null, user.FID); + + // 20230726 不论新增或暂存,都在创建协同时生成成品事项 + BaseBll.CreateTaskData(teamwork.FID, user.FID, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.成品视图, 2, 1); + + //开始BOM下载 + DockGetBomData(teamwork.FID, user.FID); + } + else + { + TeamworkBll.CreateProductView(teamwork, materialList, user.FID); + + // 20230726 不论新增或暂存,都在创建协同时生成成品事项 + BaseBll.CreateTaskData(teamwork.FID, user.FID, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.成品视图, 2, 1); + + TeamworkBll.HasMaterialTestCode(teamwork); - return teams; + /** + * 20230414 需求变更 + * 在创建各类事项前,先创建物料分类事项 + * 此处创建各类事项流程中断,转移至物料分类事项提交后进行 + * **/ + BaseBll.CreateTaskData(teamwork.FID, user.FID, "15"); //新增物料分类事项 + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.物料分类, 2, 1); // 更新物料分类流程 + } + } + else + { + // 20230726 不论新增或暂存,都在创建协同时生成成品事项 + TFS_FTeamwork teamwork = BaseBll.GetTempModel(teamId); + TeamworkBll.CreateProductView(teamwork, null, user.FID); + BaseBll.CreateTaskData(teamwork.FID, user.FID, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.成品视图, 2, 1); + + BaseBll.CreateTaskData(teamId, user.FID, ((int)Constant.TaskType.配方选择).ToString()); + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.协同发起, 1, 1); + } + } + else + { + BaseBll.DeleteDataById(teamId, "TFS_FTeamwork", true); + result = "流程创建失败,请稍后重试"; + } + TeamworkBll.ChangeTeamProcess(teamId); + } + } + + return result; } #endregion diff --git a/FactorySystemBll/TeamworkBll.cs b/FactorySystemBll/TeamworkBll.cs index a2ecb4a..2b2f38a 100644 --- a/FactorySystemBll/TeamworkBll.cs +++ b/FactorySystemBll/TeamworkBll.cs @@ -11,6 +11,7 @@ using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Xml.Linq; namespace FactorySystemBll { @@ -820,5 +821,17 @@ namespace FactorySystemBll SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); return db.Queryable().Any(m => m.FSaleCode == name&&m.FDeleted!= (int)Constant.DeleteCode.已删除); } + + public TFS_Factory GetFactoryIdByName(string name) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + return db.Queryable().Where(f => f.FName.Equals(name) && f.FDeleted != (int)Constant.DeleteCode.已删除).First(); + } + + public TFS_Formula GetFormulaByTestCodeAndVersion(string testCode, string version) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + return db.Queryable().Where(f => f.FTestCode.Equals(testCode) && f.FVersionCode.Equals(version) && f.FDeleted != (int)Constant.DeleteCode.已删除).First(); + } } }