diff --git a/FactorySystemApi/Controllers/TeamworkController - 副本.cs b/FactorySystemApi/Controllers/TeamworkController - 副本.cs new file mode 100644 index 0000000..502b7f3 --- /dev/null +++ b/FactorySystemApi/Controllers/TeamworkController - 副本.cs @@ -0,0 +1,1149 @@ +using FactorySystemBll; +using FactorySystemCommon; +using FactorySystemModel.BusinessModel; +using FactorySystemModel.EnumModel; +using FactorySystemModel.ResponseModel; +using FactorySystemModel.SqlSugarModel; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Web.Http; +using System.Data; +using System.IO; +using Newtonsoft.Json.Linq; +using FactorySystemApi.Plm_Formula; +using System.Linq; +using SqlSugar; + +namespace FactorySystemApi.Controllers +{ + /// + /// 协同接口 + /// + [UserLoginFilter] + public class TeamworkController : BaseController + { + /// + /// 数据处理层 + /// + public readonly TeamworkBll TeamworkBll = new TeamworkBll(); + /// + /// 事项操作日志 + /// + public readonly OperateLogBll OperateLogBll = new OperateLogBll(); + /// + /// 初始化 + /// + public TeamworkController() + { + //设置可新增、修改字段 + InsertField = UpdateField = ""; + } + + /// + /// 获取子项集合 + /// + [HttpPost] + public ApiResult GetTeamworkPageList(Dictionary pageParam) + { + ApiResult apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => + { + ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + apiResult.Data = new + { + List = TeamworkBll.GetTeamworkPageList(pageParam, user.FID, out int totalCount), + Total = totalCount + }; + }, apiResult, Request, pageParam); + } + + /// + /// 获取流程集合 + /// + [HttpPost] + public ApiResult GetTeamProcessList(Dictionary pageParam) + { + return GetTPageList(pageParam, null, "FGroup,FType"); + } + + /// + /// 新增协同 + /// + [HttpPost] + public override ApiResult InsertDataModel(Dictionary inParam) + { + ApiResult apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => + { + //对接获取 + //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())) + { + apiResult.Error("获取MDM失败"); + } + else if (TeamworkBll.CheckTeamName(inParam["FSaleCode"].ToString())) + { + apiResult.Error("销售号已存在!"); + } + 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["factoryValue"].ToString())); + if (inParam.ContainsKey("factoryValue")) + { + inParam.Remove("factoryValue"); + } + 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.FTestCode, teamwork.FVersionCode); + if (materialList.Count == 0) { + TeamworkBll.CreateProductView(teamwork, null, user.FID); + //开始BOM下载 + DockGetBomData(teamwork.FID, user.FID); + } + else { + TeamworkBll.CreateProductView(teamwork, materialList, user.FID); + TeamworkBll.HasMaterialTestCode(teamwork); + //补充包材规格 + BaseBll.CreateTaskData(teamId, user.FID, "14"); + //成品视图 + BaseBll.CreateTaskData(teamwork.FID, user.FID, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); + //成品视图物料组复核,有权限的所有 + BaseBll.CreateTaskData(teamwork.FID, user.FID, "12"); + teamwork = BaseBll.GetTempModel(teamId); + if (teamwork.FPackID == -1) { + //新增新包材事项 + BaseBll.CreateTaskData(teamId, user.FID, "9"); + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); + } else { + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); + } + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.成品视图, 2, 1); + } + } + else + { + BaseBll.CreateTaskData(teamId, user.FID, ((int)Constant.TaskType.配方选择).ToString()); + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.协同发起, 1, 1); + } + } + else + { + BaseBll.DeleteDataById(teamId, "TFS_FTeamwork", true); + apiResult.Error("流程创建失败,请稍后重试"); + } + TeamworkBll.ChangeTeamProcess(teamId); + } + } + }, apiResult, Request, inParam); + } + + /// + /// 修改协同 + /// + [HttpPost] + public override ApiResult UpdateDataModel(Dictionary inParam) + { + ApiResult apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => + { + ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + inParam.TryGetValue("FState", out object state); + if (null == state) { inParam["FState"] = state = 1; } + inParam.Remove("FEditUser"); + inParam.Remove("FEditDate"); + inParam.Add("FEditUser", user.FID); + inParam.Add("FEditDate", DateTime.Now); + apiResult.Data = UpdateData(inParam); + int updateCount = BaseBll.UpdateDataModel(inParam, "TFS_FTeamwork"); + if (updateCount > 0) + { + if (state.ToString().Contains("1")) + { + int teamId = int.Parse(inParam["FID"].ToString()); + TFS_FTeamwork teamwork = BaseBll.GetTempModel(teamId); + List materialList = TeamworkBll.CheckMaterialListByTest(teamwork.FTestCode, teamwork.FVersionCode); + if (materialList.Count == 0) + { + TeamworkBll.CreateProductView(teamwork, null, user.FID); + //开始BOM下载 + DockGetBomData(teamwork.FID, user.FID); + } + else + { + TeamworkBll.CreateProductView(teamwork, materialList, user.FID); + TeamworkBll.HasMaterialTestCode(teamwork); + + if (teamwork.FPackID == -1) + { + BaseBll.CreateTaskData(teamId, user.FID, "9");//新增新包材事项 + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); + } + else + { + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); + } + BaseBll.CreateTaskData(teamId, user.FID, "14");//补充包材规格 + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.成品视图, 2, 1); + } + TeamworkBll.ChangeTeamProcess(teamId); + } + } + apiResult.Data = inParam["FID"]; + }, apiResult, Request, inParam); + } + + /// + /// 手动对接BOM下载 + /// + [HttpPost] + public ApiResult DockDownBomData(Dictionary inParam) + { + ApiResult apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => + { + if (inParam.ContainsKey("FTeamID")) + { + ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + int teamId = int.Parse(inParam["FTeamID"].ToString()); + apiResult.Data = DockGetBomData(teamId, user.FID); + } + else + { + apiResult.Error("获取协同信息失败"); + } + }, apiResult, Request, inParam); + } + + /// + /// 获取协同视图信息 + /// + [HttpPost] + public ApiResult GetTeamworkView(Dictionary inParam) + { + ApiResult apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => + { + if (inParam.ContainsKey("FTeamID")) + { + inParam.TryGetValue("FViewType", out object objType); + int intType = null == objType ? (int)Constant.TeamViewType.物料视图 : int.Parse(objType.ToString()); + string selectSql = "", joinSql = "", whereSql = string.Format("TFS_FTeamwork.FID={0} ", inParam["FTeamID"]); + string basePath = AppDomain.CurrentDomain.BaseDirectory.Trim('\\'); + string savePath = basePath + string.Format("\\File\\Temp\\{0}_{1}\\", inParam["FTeamID"], intType); + if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath); + string tempPath = savePath.Replace("\\File\\Temp\\", "\\File\\View\\"); + if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath); + switch (intType) + { + case (int)Constant.TeamViewType.配方视图: + savePath += Constant.TeamViewType.配方视图.ToString(); + //原始配方 + whereSql = string.Format(@"dbo.StrExistInStr(TFS_ViewMaterial.FMaterialID,(select FMaterialFormulaIDs from TFS_FTeamwork where FID={0}))>0 + and TFS_ViewMaterial.FFactoryID=(select FProdFactoryID from TFS_FTeamwork where FID={0})", inParam["FTeamID"]); + //生产、计划配方 + joinSql = string.Format(@"(dbo.StrExistInStr(TFS_ViewMaterial.FMaterialID,(select FMaterialFormulaIDs from TFS_FTeamwork where FID={0}))>0 + and TFS_Material.FSuccedaneumID<1)and TFS_ViewMaterial.FFactoryID=(select FProdFactoryID from TFS_FTeamwork where FID={0})", + inParam["FTeamID"]); + break; + case (int)Constant.TeamViewType.生产工艺路线视图: + savePath += Constant.TeamViewType.生产工艺路线视图.ToString(); + //只要生产工厂 + whereSql += string.Format(" and TFS_ViewMaterial.FFactoryID in(select FID from TFS_Factory where FType={0})", (int)Constant.FactoryType.单工厂); + //视图类型 + List tempInt3_1 = new List + { + (int)Constant.ViewType.成品视图, + (int)Constant.ViewType.半成品视图, + (int)Constant.ViewType.香基视图, + (int)Constant.ViewType.中间品视图 + }; + whereSql += string.Format(" and TFS_ViewMaterial.FViewType in({0})", string.Join(",", tempInt3_1)); + break; + case (int)Constant.TeamViewType.生产版本视图: + savePath += Constant.TeamViewType.生产版本视图.ToString(); + //只要生产工厂 + whereSql += string.Format(" and TFS_ViewMaterial.FFactoryID in(select FID from TFS_Factory where FType={0})", (int)Constant.FactoryType.单工厂); + //视图类型 + List tempInt4_1 = new List + { + (int)Constant.ViewType.成品视图, + (int)Constant.ViewType.半成品视图, + (int)Constant.ViewType.中间品视图, + (int)Constant.ViewType.香基视图 + }; + whereSql += string.Format(" and TFS_ViewMaterial.FViewType in({0})", string.Join(",", tempInt4_1)); + break; + case (int)Constant.TeamViewType.组装BOM视图: + savePath += Constant.TeamViewType.组装BOM视图.ToString(); + //一级半成品、包材→无替代料的 + whereSql = string.Format(@"(dbo.StrExistInStr(TFS_ViewMaterial.FMaterialID,(select FMaterialHalfIDs from TFS_FTeamwork where FID={0}))>0 or + TFS_ViewMaterial.FMaterialID in(select FMaterialID from TFS_PackageChild where FTeamID={0} or + FPackageID=(select FPackID from TFS_FTeamwork where FID={0}))) + ", inParam["FTeamID"]); + //只要生产工厂 + whereSql += string.Format(" and TFS_ViewMaterial.FFactoryID=(select FProdFactoryID from TFS_FTeamwork where FID={0})", inParam["FTeamID"]); + break; + case (int)Constant.TeamViewType.物料视图: + default: + savePath += Constant.TeamViewType.物料视图.ToString(); + whereSql += " and TFS_ViewMaterial.FMaterialID>0"; + break; + } + savePath += ".xlsx"; + + bool hasFinish = inParam.ContainsKey("FFinish"); + if (hasFinish) savePath = savePath.Replace("\\File\\Temp\\", "\\File\\View\\"); + if (!File.Exists(savePath) || !hasFinish) + { + if (inParam.ContainsKey("HalfId")) { + CreateExeclFile(intType, savePath, selectSql, whereSql, joinSql, inParam["FTeamID"].ToString(), inParam["HalfId"].ToString()); + } else { + CreateExeclFile(intType, savePath, selectSql, whereSql, joinSql, inParam["FTeamID"].ToString(), ""); + } + } + if (inParam.TryGetValue("FType", out objType) && objType.ToString().Equals("1")) + { + if (intType == (int)Constant.TeamViewType.配方视图) + { + apiResult.Data = new + { + List1 = NPOIHelper.ImportExceltoDt(savePath.Replace(".xlsx", "1.xlsx")), + List2 = NPOIHelper.ImportExceltoDt(savePath.Replace(".xlsx", "2.xlsx")), + List3 = NPOIHelper.ImportExceltoDt(savePath.Replace(".xlsx", "3.xlsx")) + }; + } + else if (intType == (int)Constant.TeamViewType.生产版本视图 || intType == (int)Constant.TeamViewType.组装BOM视图) + { + //生产和计划 + apiResult.Data = new + { + List1 = NPOIHelper.ImportExceltoDt(savePath.Replace(".xlsx", "1.xlsx")), + List2 = NPOIHelper.ImportExceltoDt(savePath.Replace(".xlsx", "2.xlsx")), + }; + } + else + { + apiResult.Data = new + { + List1 = NPOIHelper.ImportExceltoDt(savePath) + }; + } + } + else + { + apiResult.Data = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, "") + savePath.Replace(basePath, "").Replace("\\", "/"); + } + } + else + { + apiResult.Error("获取协同信息失败"); + } + }, apiResult, Request, inParam); + } + + /// + /// 更新物料分类 + /// + /// + /// + [HttpPost] + public ApiResult EditTypeList(Dictionary inParam) + { + ApiResult apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => { + if (inParam["tempId"] != null && inParam["taskId"]!=null) + { + string sql = ""; + JArray item = JArray.Parse(inParam["list"].ToString()); + for (int i = 0; i < item.Count; i++) + { + JObject a = JObject.Parse(item[i].ToString()); + sql += string.Format("update TFS_Material set FTypeID1={0},FTypeID2={1} where FID={2};", a["FTypeID1"].ToString(), a["FTypeID2"].ToString(), a["FMaterialID"].ToString()); + } + int count = TeamworkBll.ExecSql(sql); + apiResult.Data = NextTask(int.Parse(inParam["tempId"].ToString()),int.Parse(inParam["taskId"].ToString())); + } + + + }, apiResult, Request, inParam); + + } + + #region 对接相关 + + + private int NextTask(int teamId,int taskId) + { + int result = 0; + List specifList = new List() { new Specifications() }; + TFS_FTeamwork teamwork = BaseBll.GetTempModel(teamId); + try + { + ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + TFS_Formula formula = BaseBll.GetTempModel(teamwork.FFormulaID); + OAService oAService = new OAService(); + specifList[0].Code = formula.FTestCode; + specifList[0].Version = formula.FVersionCode; + RestResult restResult = oAService.GetSpecificationsList(specifList.ToArray()); + string bomStr = restResult.data == null ? "[]" : restResult.data.ToString(); + ExceptionHelper.AddSystemJournal(Request, specifList[0], restResult,user.FID, "DockGetBomData"); + List bomList = JsonConvert.DeserializeObject>(bomStr); + + + if (bomList != null && bomList.Count > 0) + { + + //修改协同主数据 + Dictionary upParam = new Dictionary + { + { "FID", teamwork.FID }, + { "FBomState", 1 }, + { "FBomJson", bomStr } + }; + BaseBll.UpdateDataModel(upParam, "TFS_FTeamwork"); + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.物料分类, 2, 2); + int count= TeamworkBll.ExecSql(BaseBll.GetTaskSql(taskId, 2, teamId, (int)Constant.ProcessType.物料分类)); + + + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.替代品确认, 2, 1); + BaseBll.CreateTaskData(teamwork.FID, user.FID, "16");//替代品确认 + + + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); + + if (teamwork.FPackID == -1) + { + BaseBll.CreateTaskData(teamwork.FID, user.FID, "9");//新增新包材事项 + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); + } + else + { + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); + } + //等类型修改结束使用 + //成品视图 + BaseBll.CreateTaskData(teamwork.FID, user.FID, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); + //补充包材规格 + BaseBll.CreateTaskData(teamwork.FID, user.FID, "14"); + //成品视图物料组复核,有权限的所有 + BaseBll.CreateTaskData(teamwork.FID, user.FID, "12"); + TeamworkBll.ChangeTeamProcess(teamwork.FID); + result = 1; + } + + } + catch (Exception) + { + + throw; + } + return result; + } + + /// + /// 对接获取Bom数据 + /// + private int DockGetBomData(int teamId, int userId) + { + int result = 0; + List specifList = new List() { new Specifications() }; + TFS_FTeamwork teamwork = BaseBll.GetTempModel(teamId); + try + { + TFS_Formula formula = BaseBll.GetTempModel(teamwork.FFormulaID); + OAService oAService = new OAService(); + specifList[0].Code = formula.FTestCode; + specifList[0].Version = formula.FVersionCode; + RestResult restResult = oAService.GetSpecificationsList(specifList.ToArray()); + string bomStr = restResult.data == null ? "[]" : restResult.data.ToString(); + ExceptionHelper.AddSystemJournal(Request, specifList[0], restResult, userId, "DockGetBomData"); + List bomList = JsonConvert.DeserializeObject>(bomStr); + if (bomList != null && bomList.Count > 0) + { + //BOM数据梳理 + Dictionary bomResult = CheckBomMaterial(bomList, 0, new Random()); + bomResult["formulaIds"] = bomResult["formulaIds"].ToString().Replace(",,", ",").Trim(','); + bomResult["halfIds"] = bomResult["halfIds"].ToString().Replace(",,", ",").Trim(','); + List mateList = (List)bomResult["mateList"]; + List viewList = (List)bomResult["viewList"]; + //日志分开写12 + ExceptionHelper.AddSystemJournal(Request, null, mateList, userId, "CheckBomMaterial1"); + ExceptionHelper.AddSystemJournal(Request, null, viewList, userId, "CheckBomMaterial2"); + //BOM数据处理 + if (TeamworkBll.AnalysisBomData(mateList, viewList, teamwork.FID, userId, null, bomResult["halfIds"].ToString())) + { + mateList.Clear(); viewList.Clear(); + List formulaList = (List)bomResult["formulaList"]; + //日志分开写3 + ExceptionHelper.AddSystemJournal(Request, null, new { formulaIds = bomResult["formulaIds"], halfIds = bomResult["halfIds"], formulaList }, userId, "CheckBomMaterial3"); + //2022-09-22:要求写入配方中间表(有子集就是配方,走配方逻辑) + new FormulaBll().DockingRecipeData(formulaList, userId); + //修改协同主数据 + Dictionary upParam = new Dictionary + { + { "FID", teamwork.FID }, + { "FBomState", 1 }, + { "FBomJson", bomStr } + }; + BaseBll.UpdateDataModel(upParam, "TFS_FTeamwork"); + //协同发起事项 + //BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.物料分类, 2, 1); + //改 + //if (teamwork.FPackID == -1) + //{ + // + + // //BaseBll.CreateTaskData(teamwork.FID, userId, "9");//新增新包材事项 + // //BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); + //} + //else + //{ + // BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); + //} + ///等类型修改结束使用 + ////成品视图 + //BaseBll.CreateTaskData(teamwork.FID, userId, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); + ////补充包材规格 + //BaseBll.CreateTaskData(teamwork.FID, userId, "14"); + ////成品视图物料组复核,有权限的所有 + //BaseBll.CreateTaskData(teamwork.FID, userId, "12"); + BaseBll.CreateTaskData(teamwork.FID, userId, "15");//新增新包材事项 + OperateLogBll.Add(teamwork.FID, 2, "BOM下载成功", userId); + TeamworkBll.ChangeTeamProcess(teamwork.FID); + result = 1; + } + } + else + { + OperateLogBll.Add(teamwork.FID, 2, "BOM下载失败,BOM数据为空", userId); + BaseBll.CreateTaskData(teamwork.FID, userId, ((int)Constant.TaskType.BOM下载).ToString()); + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 2, 1); + TeamworkBll.ChangeTeamProcess(teamwork.FID); + } + } + catch (Exception ex) + { + OperateLogBll.Add(teamwork.FID, 2, "BOM下载失败,请稍后重试(对接)", userId); + BaseBll.CreateTaskData(teamwork.FID, userId, ((int)Constant.TaskType.BOM下载).ToString()); + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 2, 1); + ExceptionHelper.AddSystemJournal(Request, specifList[0], ex.Message, userId, "DockGetBomData"); + } + //日志添加 + return result; + } + + + + + + /// + /// 递归梳理BOM + /// + /// 需要解析的集合 + /// 层级 + /// 内部定义会有问题,需要外部传入 + /// 父子级关系ID + private Dictionary CheckBomMaterial(List dataList, int materLevel, Random random, int parentId = -1) + { + List mateList = new List(); + List viewList = new List(); + List formulaList = new List(); + string ids1 = "", ids2 = "";//需求变更ids2弃用 + if (dataList != null && dataList.Count > 0) + { + foreach (BomModel item in dataList) + { + int dataId = random.Next(1, 99) * random.Next(1, 99); + dataId += random.Next(10, 99) * random.Next(10, 99) * 2; + dataId += random.Next(1, 99) * random.Next(1, 99) * 10; + TFS_Material material = new TFS_Material() + { + FID = DateTime.Now.DayOfYear * 10 + dataId, + FPlmCode = item.Code, + FName = item.Name, + //FCode = item.Code, + FType = item.Type.ToLower(), + FTestCode = item.TestNO, + FVersionCode = item.Version, + FParentID = parentId + }; + + TFS_ViewMaterial view = new TFS_ViewMaterial() + { + //FBaseFameCode = "", + //FBaseMaterialCode = material.FCode, + FBaseTestCode = material.FTestCode, + FExtraQuantity = item.Quantity, + FBaseMaterialDesc = material.FName, + FLevel = materLevel, + FBomMaterialID = material.FID + }; + if (material.FType == "a" || material.FType == "f") + { + material.FType = "20"; + } + else if (material.FType == "b" || material.FType == "bb" || material.FType == "i" || material.FType == "iz") + { + material.FType = "30"; + } + else + { + material.FType = "40"; + } + + if (materLevel == 0) + { + material.FType = "20"; + ids2 = material.FID + ""; + } + if (material.FType == "40") + { + material.FCode = material.FPlmCode; + material.FPlmCode = ""; + } + + int.TryParse(material.FType, out int mType); + if (materLevel == 1) ids1 += material.FID + ","; + switch (mType) + { + case (int)Constant.MaterialType.产成品: + view.FViewType = 1; + break; + case (int)Constant.MaterialType.半成品: + view.FViewType = (int)Constant.ViewType.半成品视图; + break; + case (int)Constant.MaterialType.中间品: + view.FViewType = material.FName.Contains("香基") ? (int)Constant.ViewType.香基视图 : (int)Constant.ViewType.中间品视图; + break; + case (int)Constant.MaterialType.原辅料: + view.FViewType = (int)Constant.ViewType.原料视图; + view.FBaseMaterialCode = material.FCode; + //默认值不同 + view.FPurchaseCompany = "kg"; + view.FPurchaseCompanyCount = "1"; + view.FPurchaseBaseCompanyCount = "1000"; + view.FSaleAccountSettingGroup = "15"; + view.FStorageTotalShelfLife = "7300"; + view.FMRP2ExternalStoragePlace = "1000"; + view.FPlanUnlimitedOverDelivery = ""; + view.FAccountPriceControl = "V"; + view.FAccountPriceDetermine = "2"; + view.FAccountAccessType = "1000"; + view.FAccountSaleOrderInventory = "1010"; + break; + } + mateList.Add(material); + viewList.Add(view); + + if (item.Specifications != null && item.Specifications.Count > 0) + { + Dictionary childData = CheckBomMaterial(item.Specifications, materLevel + 1, random, material.FID); + if (materLevel >= 1) + { + formulaList.Add(new TFS_Formula() + { + FID = -1, + FName = material.FName, + FType = material.FType, + FTestCode = material.FTestCode, + FVersionCode = material.FVersionCode, + FPlmCode = string.IsNullOrEmpty(material.FPlmCode) ? material.FCode : material.FPlmCode + }); + } + mateList.AddRange((List)childData["mateList"]); + viewList.AddRange((List)childData["viewList"]); + formulaList.AddRange((List)childData["formulaList"]); + ids1 = ids1.Trim(',') + "," + childData["formulaIds"] + ","; + ids2 = ids2.Trim(',') + "," + childData["halfIds"] + ","; + } + } + } + return new Dictionary + { + { "mateList", mateList }, + { "viewList", viewList }, + { "formulaList", formulaList }, + { "formulaIds", ids1.Trim(',') }, + { "halfIds", ids2.Trim(',') } + }; + } + + /// + /// 获取JObject值 + /// + private string GetValue(JObject item, string optStr) + { + string[] options = optStr.Split('&'); + for (int i = 0; i < options.Length; i++) + { + if (item.ContainsKey(options[i])) return item[options[i]].ToString(); + } + return ""; + } + + #endregion + + #region 内部方法 + + /// + /// 创建Excel文件 + /// + private void CreateExeclFile(int intType, string savePath, string selectSql, string whereSql, string joinSql, string teamId, string halfId) + { + List filedList = TeamworkBll.GetTeamworkViewField(intType); + foreach (TFS_ViewFieldInfo field in filedList) + { + if (string.IsNullOrEmpty(field.FField)) + { + selectSql += string.Format("'{0}' as '{1}'", string.IsNullOrEmpty(field.FDefault) ? "" : field.FDefault, field.FName); + } + else + { + selectSql += string.Format("isnull({0},'') as '{1}'", field.FField, field.FName); + } + selectSql += ","; + } + selectSql = selectSql.Replace("@FTeamID@", teamId); + selectSql = selectSql.Replace("@FMaterialID@", halfId); + DataTable dataList = new DataTable(); + if (intType == (int)Constant.TeamViewType.组装BOM视图) + { + dataList = TeamworkBll.GetTeamworkViewData2(selectSql.Trim(','), whereSql, joinSql); + dataList.Columns.Remove("FMaterialID"); + DataTable dataList2 = dataList.Copy(); + List hasField = new List(); + hasField.Add(dataList.Columns.Contains("BOM用途")); + hasField.Add(dataList.Columns.Contains("子项序号")); + hasField.Add(dataList.Columns.Contains("组件损耗率")); + hasField.Add(dataList.Columns.Contains("固定损耗数量")); + int rowCount = dataList.Rows.Count; + + //生产组装BOM处理 + for (int i = 0; i < rowCount; i++) + { + if (hasField[0]) dataList.Rows[i]["BOM用途"] = "Y"; + if (hasField[1]) dataList.Rows[i]["子项序号"] = (i + 1) * 10; + if (hasField[2]) dataList.Rows[i]["组件损耗率"] = ""; + if (hasField[3]) dataList.Rows[i]["固定损耗数量"] = ""; + dataList.Rows[i]["可选文本"] = "生产组装BOM"; + } + NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath.Replace(".xlsx", "1.xlsx")); + + //计划组装BOM处理 + DataTable dataList3 = dataList2.Copy(); + for (int i = 0; i < rowCount; i++) + { + if (hasField[1]) + { + dataList2.Rows[i]["子项序号"] = (i + 1) * 10; + } + if (hasField[3] && !string.IsNullOrEmpty(dataList2.Rows[i]["固定损耗数量"].ToString()) && !dataList2.Rows[i]["固定损耗数量"].ToString().Equals("0")) + { + dataList3.Rows[i]["组件数量"] = ""; + dataList3.Rows[i]["组件损耗率"] = ""; + dataList3.Rows[i]["固定损耗数量"] = "X"; + if (hasField[1]) dataList3.Rows[i]["子项序号"] = (i + rowCount + 1) * 10; + dataList3.Rows[i]["可选文本"] = "计划组装BOM"; + dataList2.ImportRow(dataList3.Rows[i]); + } + dataList2.Rows[i]["固定损耗数量"] = ""; + dataList2.Rows[i]["可选文本"] = "计划组装BOM"; + } + NPOIHelper.ExportDTtoExcel(dataList2, "Sheet1", savePath.Replace(".xlsx", "2.xlsx")); + for (int i = 0; i < dataList2.Rows.Count; i++) + { + if (i == 0) dataList.Rows.Add("[换色]"); + dataList.ImportRow(dataList2.Rows[i]); + } + } + else if (intType == (int)Constant.TeamViewType.配方视图) + { + //原始配方 + DataTable dataList1 = TeamworkBll.GetTeamworkViewData2(selectSql.Trim(','), whereSql); + TFS_FTeamwork teamwork = BaseBll.GetTempModel("FID=" + teamId); + List bfList = JsonConvert.DeserializeObject>(teamwork.FBomFormula); + //SetBFData(null, bfList, dataList1); + List forIdList = teamwork.FMaterialFormulaIDs.Split(',').ToList(); + + DataTable tempTable = dataList1.Copy(); + tempTable.Rows.Clear(); + DataTable totalTable = tempTable.Copy(); + + List rowList = SetXHData(null, bfList, dataList1, forIdList, 1); + foreach (var item in rowList) + { + tempTable.Rows.Add(item.ItemArray); + totalTable.Rows.Add(item.ItemArray); + } + tempTable.Columns.Remove("FMaterialID"); + NPOIHelper.ExportDTtoExcel(tempTable, "Sheet1", savePath.Replace(".xlsx", "1.xlsx")); + tempTable = dataList1.Copy(); + tempTable.Rows.Clear(); + + rowList = SetXHData(null, bfList, dataList1, forIdList, 2); + totalTable.Rows.Add("[换色]"); + foreach (var item in rowList) + { + tempTable.Rows.Add(item.ItemArray); + totalTable.Rows.Add(item.ItemArray); + } + tempTable.Columns.Remove("FMaterialID"); + NPOIHelper.ExportDTtoExcel(tempTable, "Sheet1", savePath.Replace(".xlsx", "2.xlsx")); + tempTable = dataList1.Copy(); + tempTable.Rows.Clear(); + + rowList = SetXHData(null, bfList, dataList1, forIdList, 3); + totalTable.Rows.Add("[换色]"); + foreach (var item in rowList) + { + tempTable.Rows.Add(item.ItemArray); + totalTable.Rows.Add(item.ItemArray); + } + tempTable.Columns.Remove("FMaterialID"); + NPOIHelper.ExportDTtoExcel(tempTable, "Sheet1", savePath.Replace(".xlsx", "3.xlsx")); + tempTable.Rows.Clear(); + + dataList = totalTable; + dataList.Columns.Remove("FMaterialID"); + + /*dataList1.Columns.Remove("FMaterialID"); + List hasField = new List + { + dataList1.Columns.Contains("BOM用途"), + dataList1.Columns.Contains("子项序号"), + dataList1.Columns.Contains("组件损耗率"), + dataList1.Columns.Contains("固定损耗数量"), + dataList1.Columns.Contains("BOM项目文本2") + }; + int rowCount = dataList1.Rows.Count; + for (int i = 0; i < rowCount; i++) + { + //if (hasField[0]) dataList1.Rows[i]["BOM用途"] = "1"; + if (hasField[1]) dataList1.Rows[i]["子项序号"] = (i + 1) * 10; + if (hasField[2]) dataList1.Rows[i]["组件损耗率"] = ""; + if (hasField[3]) dataList1.Rows[i]["固定损耗数量"] = ""; + if (hasField[4]) dataList1.Rows[i]["BOM项目文本2"] = ""; + dataList1.Rows[i]["可选文本"] = "原始BOM配方"; + dataList.ImportRow(dataList1.Rows[i]); + } + NPOIHelper.ExportDTtoExcel(dataList1, "Sheet1", savePath.Replace(".xlsx", "1.xlsx")); + dataList = dataList1.Copy(); + //生产配方 + DataTable dataList2 = TeamworkBll.GetTeamworkViewData2(selectSql.Trim(','), joinSql.Trim(',')); + SetBFData(null, bfList, dataList2); + dataList2.Columns.Remove("FMaterialID"); + DataTable dataList3 = dataList2.Copy(); + string fuIds = ""; + dataList.Rows.Add("[换色]"); + rowCount = dataList2.Rows.Count; + for (int i = 0; i < rowCount; i++) + { + if (hasField[0]) dataList2.Rows[i]["BOM用途"] = "Y"; + if (hasField[1]) dataList2.Rows[i]["子项序号"] = (i + 1) * 10; + if (hasField[2]) dataList2.Rows[i]["组件损耗率"] = ""; + if (hasField[3]) dataList2.Rows[i]["固定损耗数量"] = ""; + if (hasField[4]) + { + if (!string.IsNullOrEmpty(dataList3.Rows[i]["BOM项目文本2"].ToString())) + { + fuIds += dataList3.Rows[i]["BOM项目文本2"].ToString() + ","; + } + dataList2.Rows[i]["BOM项目文本2"] = ""; + } + dataList2.Rows[i]["可选文本"] = "生产BOM配方"; + dataList.ImportRow(dataList2.Rows[i]); + } + if (!string.IsNullOrEmpty(fuIds)) + { + joinSql = string.Format("TFS_ViewMaterial.FMaterialID in({0}) and ", fuIds.Trim(',')) + joinSql.Substring(joinSql.IndexOf("TFS_ViewMaterial.FFactoryID")); + DataTable tempList = TeamworkBll.GetTeamworkViewData2(selectSql.Trim(','), joinSql.Trim(',')); + tempList.Columns.Remove("FMaterialID"); + foreach (DataRow dr in tempList.Rows) + { + dataList2.ImportRow(dr); + dataList3.ImportRow(dr); + if (hasField[0]) + { + dataList2.Rows[dataList2.Rows.Count - 1]["BOM用途"] = "Y"; + dataList3.Rows[dataList3.Rows.Count - 1]["BOM用途"] = "1"; + } + if (hasField[1]) + { + dataList2.Rows[dataList2.Rows.Count - 1]["子项序号"] = dataList2.Rows.Count * 10; + dataList3.Rows[dataList3.Rows.Count - 1]["子项序号"] = dataList2.Rows.Count * 10; + } + if (hasField[2]) + { + dataList2.Rows[dataList2.Rows.Count - 1]["组件损耗率"] = ""; + dataList3.Rows[dataList3.Rows.Count - 1]["组件损耗率"] = ""; + } + if (hasField[3]) + { + dataList2.Rows[dataList2.Rows.Count - 1]["固定损耗数量"] = ""; + } + if (hasField[4]) + { + dataList2.Rows[dataList2.Rows.Count - 1]["BOM项目文本2"] = ""; + dataList3.Rows[dataList3.Rows.Count - 1]["BOM项目文本2"] = ""; + } + dataList2.Rows[dataList2.Rows.Count - 1]["可选文本"] = "生产BOM配方"; + dataList3.Rows[dataList3.Rows.Count - 1]["可选文本"] = "计划BOM配方"; + dataList.ImportRow(dataList2.Rows[dataList2.Rows.Count - 1]); + } + } + NPOIHelper.ExportDTtoExcel(dataList2, "Sheet1", savePath.Replace(".xlsx", "2.xlsx")); + //计划配方 + dataList.Rows.Add("[换色]"); + rowCount = dataList3.Rows.Count; + for (int i = 0; i < rowCount; i++) + { + if (hasField[0]) dataList3.Rows[i]["BOM用途"] = "1"; + if (hasField[1]) dataList3.Rows[i]["子项序号"] = (i + 1) * 10; + if (hasField[3]) + { + if (!string.IsNullOrEmpty(dataList3.Rows[i]["固定损耗数量"].ToString())) + { + DataRow dr = dataList3.Copy().Rows[i]; + dr["组件数量"] = dataList3.Rows[i]["固定损耗数量"]; + dr["组件损耗率"] = ""; + dr["固定损耗数量"] = "X"; + if (hasField[4]) dr["BOM项目文本2"] = ""; + if (hasField[1]) dr["子项序号"] = (dataList3.Rows.Count + 1) * 10; + dr["可选文本"] = "计划BOM配方"; + dataList3.ImportRow(dr); + } + dataList3.Rows[i]["固定损耗数量"] = ""; + if (hasField[4]) dataList3.Rows[i]["BOM项目文本2"] = ""; + } + dataList3.Rows[i]["可选文本"] = "计划BOM配方"; + } + NPOIHelper.ExportDTtoExcel(dataList3, "Sheet1", savePath.Replace(".xlsx", "3.xlsx")); + rowCount = dataList3.Rows.Count; + for (int i = 0; i < rowCount; i++) { dataList.ImportRow(dataList3.Rows[i]); }*/ + } + else + { + dataList = TeamworkBll.GetTeamworkViewData(selectSql.Trim(','), whereSql, joinSql); + dataList.Columns.Remove("FMaterialID"); + if (intType == (int)Constant.TeamViewType.生产版本视图) + { + NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath.Replace(".xlsx", "1.xlsx")); + int rowCount = dataList.Rows.Count; + bool isChange = dataList.Columns.Contains("BOM用途"); + + DataTable dataList2 = dataList.Copy(); + for (int i = 0; i < rowCount; i++) + { + if (isChange && dataList2.Rows[i]["BOM用途"].ToString() == "1") + { + dataList2.Rows[i]["BOM用途"] = "Y"; + } + } + NPOIHelper.ExportDTtoExcel(dataList2, "Sheet1", savePath.Replace(".xlsx", "2.xlsx")); + for (int i = 0; i < rowCount; i++) + { + if (i == 0) dataList.Rows.Add("[换色]"); + dataList.ImportRow(dataList2.Rows[i]); + } + } + } + if (intType == (int)Constant.TeamViewType.物料视图) + { + //處理名字點 + } + NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath); + } + + /// + /// 梳理父项 + /// + private void SetBFData(TFS_ViewMaterial parent, List bfList, DataTable dtList) + { + if (bfList != null && bfList.Count > 0) + { + foreach (var item in bfList) + { + if (parent != null) + { + DataRow[] rows = dtList.Select("FMaterialID=" + item.mId); + foreach (var row in rows) + { + row["父项编码"] = parent.FBaseMaterialCode; + row["父项描述"] = parent.FBaseMaterialDesc; + row["基本数量"] = parent.FExtraQuantity; + } + } + if (item.childs.Count > 0) + { + SetBFData(BaseBll.GetTempModel("FMaterialID=" + item.mId), item.childs, dtList); + } + } + } + } + + /// + /// 梳理序号(type:1原始,2生产,3计划) + /// + private List SetXHData(BomFormulaDto parent, List bfList, DataTable dtList, List forIdList, int type) + { + if (bfList != null && bfList.Count > 0) + { + //物料、替代、副产、固损 + List> rowList = new List>() { new List(), new List(), new List(), new List() }; + foreach (BomFormulaDto item in bfList) + { + DataRow[] rows = dtList.Select("FMaterialID=" + item.mId); + if (rows != null && rows.Length > 0) + { + string mId = rows[0]["FMaterialID"].ToString(); + if (forIdList.IndexOf(mId) != -1) + { + DataRow main = dtList.Copy().Select("FMaterialID=" + item.mId)[0]; + if (parent != null) + { + TFS_ViewMaterial temp = BaseBll.GetTempModel("FMaterialID=" + parent.mId); + if (temp != null) + { + main["父项编码"] = temp.FBaseMaterialCode; + main["父项描述"] = temp.FBaseMaterialDesc; + main["基本数量"] = temp.FExtraQuantity; + } + } + main["BOM项目文本2"] = ""; + //固定损耗 + if (type == 3 && !string.IsNullOrEmpty(main["固定损耗数量"].ToString())) + { + DataRow drGu = dtList.Copy().Select("FMaterialID=" + item.mId)[0]; + drGu["组件数量"] = main["固定损耗数量"]; + drGu["组件损耗率"] = ""; + drGu["固定损耗数量"] = "X"; + drGu["BOM项目文本2"] = ""; + drGu["可选文本"] = "计划BOM配方"; + rowList[3].Add(drGu); + } + if (type > 1) + { + { + //副产物判断 + TFS_Material mTi = BaseBll.GetTempModel(string.Format("FID=(select a.FFuProductsID from TFS_Material a where a.FID={0})", mId)); + if (mTi != null) + { + DataRow drFu = dtList.Copy().Select("FMaterialID=" + item.mId)[0]; + TFS_ViewMaterial vTi = BaseBll.GetTempModel(string.Format("FMaterialID={0}", mTi.FID)); + TFS_MaterialInfo iTi = BaseBll.GetTempModel(string.Format("FType=2 and FDataID={0}", mTi.FID)); + if (iTi == null) iTi = new TFS_MaterialInfo(); + DataRow drTi = dtList.Copy().Select("FMaterialID=" + item.mId)[0]; + drFu["子项编码"] = vTi == null ? mTi.FCode : vTi.FBaseMaterialCode; + drFu["子件描述"] = vTi == null ? mTi.FName : vTi.FBaseMaterialDesc; + drFu["组件数量"] = vTi == null ? drTi["组件数量"] : vTi.FExtraQuantity; + drFu["计量单位"] = vTi == null ? mTi.FBaseUnit : vTi.FBaseBasicMeter; + drFu["物料供应标识符"] = mTi == null ? iTi.FCustomerCode : mTi.FSupplyCode; + drFu["生产仓储地点"] = vTi == null ? iTi.FStoreHouse : vTi.FMRP2ExternalStoragePlace; + drFu["成本核算标识相关"] = (mTi != null ? mTi.FSupplyCode : drTi["物料供应标识符"].ToString()) == "K" ? "" : "X"; + drFu["固定损耗数量"] = mTi == null ? iTi.FFixedLoss : mTi.FFixedLoss; + if (type == 3) drFu["BOM用途"] = "Y"; + rowList[2].Add(drFu); + } + } + { + //替代料判断 + TFS_Material mTi = BaseBll.GetTempModel(string.Format("FID=(select a.FSuccedaneumID from TFS_Material a where a.FID={0})", mId)); + if (mTi != null) + { + TFS_ViewMaterial vTi = BaseBll.GetTempModel(string.Format("FMaterialID={0}", mTi.FID)); + TFS_MaterialInfo iTi = BaseBll.GetTempModel(string.Format("FType=2 and FDataID={0}", mTi.FID)); + if (iTi == null) iTi = new TFS_MaterialInfo(); + DataRow drTi = dtList.Copy().Select("FMaterialID=" + item.mId)[0]; + drTi["子项编码"] = vTi == null ? mTi.FCode : vTi.FBaseMaterialCode; + drTi["子件描述"] = vTi == null ? mTi.FName : vTi.FBaseMaterialDesc; + drTi["组件数量"] = vTi == null ? drTi["组件数量"] : vTi.FExtraQuantity; + drTi["计量单位"] = vTi == null ? mTi.FBaseUnit : vTi.FBaseBasicMeter; + drTi["物料供应标识符"] = mTi == null ? iTi.FCustomerCode : mTi.FSupplyCode; + drTi["生产仓储地点"] = vTi == null ? iTi.FStoreHouse : vTi.FMRP2ExternalStoragePlace; + drTi["成本核算标识相关"] = (mTi != null ? mTi.FSupplyCode : drTi["物料供应标识符"].ToString()) == "K" ? "" : "X"; + drTi["固定损耗数量"] = mTi == null ? iTi.FFixedLoss : mTi.FFixedLoss; + main = drTi; + } + } + } + if (type == 2) main["BOM用途"] = "Y"; + rowList[0].Add(main); + } + } + } + if (type != 1) { rowList[0].AddRange(rowList[1]); rowList[0].AddRange(rowList[2]); } + if (type == 3) rowList[0].AddRange(rowList[3]); + for (int i = 0; i < rowList[0].Count; i++) + { + rowList[0][i]["子项序号"] = (i + 1) * 10; + switch (type) + { + case 1: rowList[0][i]["可选文本"] = "原始BOM配方"; break; + case 2: rowList[0][i]["可选文本"] = "生产BOM配方"; break; + case 3: rowList[0][i]["可选文本"] = "计划BOM配方"; break; + } + } + foreach (BomFormulaDto item in bfList) + { + if (item.childs != null && item.childs.Count > 0) + { + List temps = SetXHData(item, item.childs, dtList, forIdList, type); + if (temps.Count > 0) rowList[0].AddRange(temps); + } + } + return rowList[0]; + } + return new List(); + } + + #endregion + } +} diff --git a/FactorySystemApi/Controllers/TeamworkController.cs b/FactorySystemApi/Controllers/TeamworkController.cs index 502b7f3..fd3db46 100644 --- a/FactorySystemApi/Controllers/TeamworkController.cs +++ b/FactorySystemApi/Controllers/TeamworkController.cs @@ -148,22 +148,31 @@ namespace FactorySystemApi.Controllers else { TeamworkBll.CreateProductView(teamwork, materialList, user.FID); TeamworkBll.HasMaterialTestCode(teamwork); - //补充包材规格 - BaseBll.CreateTaskData(teamId, user.FID, "14"); - //成品视图 - BaseBll.CreateTaskData(teamwork.FID, user.FID, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); - //成品视图物料组复核,有权限的所有 - BaseBll.CreateTaskData(teamwork.FID, user.FID, "12"); - teamwork = BaseBll.GetTempModel(teamId); - if (teamwork.FPackID == -1) { - //新增新包材事项 - BaseBll.CreateTaskData(teamId, user.FID, "9"); - BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); - } else { - BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); - } - BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); - BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.成品视图, 2, 1); + + /** + * 20230414 需求变更 + * 在创建各类事项前,先创建物料分类事项 + * 此处创建各类事项流程中断,转移至物料分类事项提交后进行 + * **/ + BaseBll.CreateTaskData(teamwork.FID, user.FID, "15"); //新增物料分类事项 + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.物料分类, 2, 1); // 更新物料分类流程 + + ////补充包材规格 + //BaseBll.CreateTaskData(teamId, user.FID, "14"); + ////成品视图 + //BaseBll.CreateTaskData(teamwork.FID, user.FID, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); + ////成品视图物料组复核,有权限的所有 + //BaseBll.CreateTaskData(teamwork.FID, user.FID, "12"); + //teamwork = BaseBll.GetTempModel(teamId); + //if (teamwork.FPackID == -1) { + // //新增新包材事项 + // BaseBll.CreateTaskData(teamId, user.FID, "9"); + // BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); + //} else { + // BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); + //} + //BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); + //BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.成品视图, 2, 1); } } else @@ -219,18 +228,26 @@ namespace FactorySystemApi.Controllers TeamworkBll.CreateProductView(teamwork, materialList, user.FID); TeamworkBll.HasMaterialTestCode(teamwork); - if (teamwork.FPackID == -1) - { - BaseBll.CreateTaskData(teamId, user.FID, "9");//新增新包材事项 - BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); - } - else - { - BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); - } - BaseBll.CreateTaskData(teamId, user.FID, "14");//补充包材规格 - BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); - BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.成品视图, 2, 1); + /** + * 20230414 需求变更 + * 在创建各类事项前,先创建物料分类事项 + * 此处创建各类事项流程中断,转移至物料分类事项提交后进行 + * **/ + BaseBll.CreateTaskData(teamwork.FID, user.FID, "15"); //新增物料分类事项 + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.物料分类, 2, 1); // 更新物料分类流程 + + //if (teamwork.FPackID == -1) + //{ + // BaseBll.CreateTaskData(teamId, user.FID, "9");//新增新包材事项 + // BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); + //} + //else + //{ + // BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); + //} + //BaseBll.CreateTaskData(teamId, user.FID, "14");//补充包材规格 + //BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); + //BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.成品视图, 2, 1); } TeamworkBll.ChangeTeamProcess(teamId); } @@ -533,29 +550,33 @@ namespace FactorySystemApi.Controllers { "FBomJson", bomStr } }; BaseBll.UpdateDataModel(upParam, "TFS_FTeamwork"); - //协同发起事项 + + /** + * 20230414 需求变更 + * 在创建各类事项前,先创建物料分类事项 + * 此处创建各类事项流程中断,转移至物料分类事项提交后进行 + * **/ + BaseBll.CreateTaskData(teamwork.FID, userId, "15"); //新增物料分类事项 + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.物料分类, 2, 1); // 更新物料分类流程 + + ////协同发起事项 //BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); - BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.物料分类, 2, 1); - //改 + //BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.成品视图, 2, 1); //if (teamwork.FPackID == -1) //{ - // - - // //BaseBll.CreateTaskData(teamwork.FID, userId, "9");//新增新包材事项 - // //BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); + // BaseBll.CreateTaskData(teamwork.FID, userId, "9");//新增新包材事项 + // BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); //} //else //{ // BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); //} - ///等类型修改结束使用 ////成品视图 //BaseBll.CreateTaskData(teamwork.FID, userId, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); ////补充包材规格 //BaseBll.CreateTaskData(teamwork.FID, userId, "14"); ////成品视图物料组复核,有权限的所有 //BaseBll.CreateTaskData(teamwork.FID, userId, "12"); - BaseBll.CreateTaskData(teamwork.FID, userId, "15");//新增新包材事项 OperateLogBll.Add(teamwork.FID, 2, "BOM下载成功", userId); TeamworkBll.ChangeTeamProcess(teamwork.FID); result = 1; diff --git a/FactorySystemApi/Controllers/UserController.cs b/FactorySystemApi/Controllers/UserController.cs index 1d98d98..b8444d3 100644 --- a/FactorySystemApi/Controllers/UserController.cs +++ b/FactorySystemApi/Controllers/UserController.cs @@ -279,5 +279,62 @@ namespace FactorySystemApi.Controllers apiResult.Data = UserBll.GetFPowerList(); }, apiResult, Request); } + + /// + /// 获取冻结列 + /// + /// + [HttpPost] + public ApiResult GetFreezingColumns() + { + ApiResult apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => + { + ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + apiResult.Data = UserBll.GetFreezingColumns(user.FID); + + }, apiResult, Request); + } + + /// + /// 修改删除冻结列 + /// + /// + /// + [HttpPost] + public ApiResult EditFreezingColumns(string freezingColumns) + { + ApiResult apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => + { + ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + TFS_FreezingColumns fc = (TFS_FreezingColumns)UserBll.GetFreezingColumns(user.FID); + + if (fc == null) + { + fc = new TFS_FreezingColumns(); + fc.FUserID = user.FID; + fc.FFreezingColumns = freezingColumns; + fc.FAddDate = DateTime.Now; + fc.FAddUser = user.FID; + + List fcl = new List + { + fc + }; + + apiResult.Data = UserBll.CreateFreezingColumns(user.FID, fcl); + } + else + { + fc.FFreezingColumns = freezingColumns; + fc.FEditUser = user.FID; + fc.FEditDate = DateTime.Now; + + apiResult.Data = UserBll.UpdateFreezingColumns(fc); + } + + }, apiResult, Request); + } } } diff --git a/FactorySystemApi/Controllers/ViewController.cs b/FactorySystemApi/Controllers/ViewController.cs index ae5897e..7e524ff 100644 --- a/FactorySystemApi/Controllers/ViewController.cs +++ b/FactorySystemApi/Controllers/ViewController.cs @@ -7,6 +7,8 @@ using FactorySystemModel.ResponseModel; using FactorySystemModel.SqlSugarModel; using Microsoft.Ajax.Utilities; using Newtonsoft.Json; +using FactorySystemModel.EnumModel; +using Aspose.Cells; namespace FactorySystemApi.Controllers { @@ -116,7 +118,58 @@ namespace FactorySystemApi.Controllers List> infoList = JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(infoObj)); int teamId = int.Parse(inParam["FTeamID"].ToString()); int viewType = int.Parse(inParam["FViewType"].ToString()); - _viewBll.UpdateBatchById2(viewList, materialList, infoList, teamId, viewType, user.FID); + apiResult.Data = _viewBll.UpdateBatchById2(viewList, materialList, infoList, teamId, viewType, user.FID); + + if (viewType == 10) + { + // 创建物料视图事项 + TFS_FTeamwork teamwork = BaseBll.GetTempModel(teamId); + List> vml = _viewBll.GetListByTeamId(teamId, viewType, user.FID, out List materialId, out string FGuaranteePeriod, out string FStorageConditions, true); + Dictionary hasNewView = new Dictionary(); + + if (vml != null) + { + foreach(Dictionary row in vml) + { + int materialType = (int)(long)row["FViewType"]; + string factoryId = row["FFactoryID"].ToString(); + + if (materialType == 2 || materialType == 3 || materialType == 4 || materialType == 5) + { + if (hasNewView.ContainsKey(materialType)) + { + hasNewView[materialType] = hasNewView[materialType] + factoryId + ","; + } + else + { + hasNewView.Add(materialType, factoryId + ","); + } + } + } + TeamworkBll TeamworkBll = new TeamworkBll(); + TeamworkBll.CreateMaterialTask(hasNewView, teamwork, user.FID); + } + + //补充包材规格 + BaseBll.CreateTaskData(teamId, user.FID, "14"); + //成品视图 + BaseBll.CreateTaskData(teamwork.FID, user.FID, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); + //成品视图物料组复核,有权限的所有 + BaseBll.CreateTaskData(teamwork.FID, user.FID, "12"); + teamwork = BaseBll.GetTempModel(teamId); + if (teamwork.FPackID == -1) + { + //新增新包材事项 + BaseBll.CreateTaskData(teamId, user.FID, "9"); + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); + } + else + { + BaseBll.UpdateTeamProcess(teamId, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); + } + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); + BaseBll.UpdateTeamProcess(teamwork.FID, (int)Constant.ProcessType.成品视图, 2, 1); + } } }, apiResult, Request); } diff --git a/FactorySystemBll/TaskBll.cs b/FactorySystemBll/TaskBll.cs index 8cddc20..f344032 100644 --- a/FactorySystemBll/TaskBll.cs +++ b/FactorySystemBll/TaskBll.cs @@ -37,7 +37,7 @@ namespace FactorySystemBll .WhereIF(tq.FUserID != null, a => (',' + a.FUserID + ',').Contains(',' + tq.FUserID + ',')) // 协同 .WhereIF(tq.FTeamID > 0, a => a.FTeamID == tq.FTeamID).OrderBy((a, b, c) => a.FID, OrderByType.Desc) - .Select("a.*,b.FSaleCode,b.FFormulaTestCode as FTestCode,b.FMdmCode,b.FFormulaName,b.FMaterialHalfIDs,cast(substring(c.FRemark,4,1)as int)as FViewType") + .Select("a.*,b.FSaleCode,b.FFormulaTestCode as FTestCode,b.FMdmCode,b.FFormulaName,b.FMaterialHalfIDs,cast(substring(c.FRemark,4,2)as int)as FViewType") .ToPageList(tq.FPageIndex, tq.FPageSize, ref totalNumber); } diff --git a/FactorySystemBll/TeamworkBll.cs b/FactorySystemBll/TeamworkBll.cs index 6415ee5..0727eab 100644 --- a/FactorySystemBll/TeamworkBll.cs +++ b/FactorySystemBll/TeamworkBll.cs @@ -7,6 +7,7 @@ using SqlSugar; using System; using System.Collections.Generic; using System.Data; +using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -389,12 +390,89 @@ namespace FactorySystemBll formulaIds += first.FID + "," + fids; } } + //if (hasNewView.Count() > 0) + //{ + // hasNewView.OrderBy(s => s.Key); + // string facoryIds = ""; bool hasOther = false; + // foreach (var item in hasNewView) + // { + // //创建视图事项 + // string factorys = item.Value.Trim(','); + // BaseBll.CreateTaskData(teamInfo.FID, userId, (item.Key + 2).ToString(), factorys); + // facoryIds += factorys; + // if (item.Key != (int)Constant.ViewType.原料视图) hasOther = true; + // } + // if (hasNewView.ContainsKey((int)Constant.ViewType.原料视图)) + // { + // proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.新原料视图, "F2", 1); + // } + // else + // { + // proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.新原料视图, "F4", 2); + // } + // if (hasOther) + // { + // proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.新半成品中间品香基, "F2", 1); + // } + // else + // { + // proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.新半成品中间品香基, "F4", 2); + // } + // if (hasNewView.ContainsKey((int)Constant.ViewType.中间品视图) || hasNewView.ContainsKey((int)Constant.ViewType.香基视图) + // || hasNewView.ContainsKey((int)Constant.ViewType.半成品视图)) + // { + // proSql += string.Format("update TFS_FTeamwork set FViewType=FViewType+',3,4' where FID={0};", teamInfo.FID); + // BaseBll.CreateTaskData(teamId, userId, "8"); + // } + // proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.配方视图, "F2", 1); + //} + //else + //{ + // proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.配方视图, "F2", 2); + // proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.新半成品中间品香基, "F4", 2); + // proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.新原料视图, "F4", 2); + //} + ////下面两个要根据包材判断,先改成进行中,hasNewView == 0 && 包材是旧的,完成 + //int pVersion = (hasNewView.Count == 0 && teamInfo.FPackID < 1) ? 2 : 1; + //proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.生产工艺路线, "F2", pVersion); + //proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.生成版本, "F2", pVersion); + + string updateSql = ""; + + formulaIds = formulaIds.Replace(",,", ",").Replace(",,", ",").Replace(",,", ",").Trim(','); + if (!string.IsNullOrEmpty(formulaIds)) + { + updateSql += string.Format("FMaterialFormulaIDs='{0}',FViewType=FViewType+',2',", formulaIds); + updateSql += string.Format("FBomFormula='{0}',", JsonConvert.SerializeObject(bfList)); + } + if (!string.IsNullOrEmpty(halfIds)) updateSql += string.Format("FMaterialHalfIDs='{0}',", halfIds); + if (!string.IsNullOrEmpty(updateSql)) proSql += string.Format("update TFS_FTeamwork set {1} where FID={0};", teamInfo.FID, updateSql.Trim(',')); + proSql += BaseBll.GetTaskSql(-1, 2, teamId, (int)Constant.TaskType.BOM下载, 2); + db.Ado.ExecuteCommand(proSql.Trim(';')); + db.CommitTran(); + } + catch (Exception ex) + { + db.RollbackTran(); + return false; + } + return true; + } + + public bool CreateMaterialTask(Dictionary hasNewView, TFS_FTeamwork teamInfo, int userId) + { + string proSql = ""; + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + db.BeginTran(); + + try + { if (hasNewView.Count() > 0) { hasNewView.OrderBy(s => s.Key); string facoryIds = ""; bool hasOther = false; foreach (var item in hasNewView) - { + { //创建视图事项 string factorys = item.Value.Trim(','); BaseBll.CreateTaskData(teamInfo.FID, userId, (item.Key + 2).ToString(), factorys); @@ -421,7 +499,7 @@ namespace FactorySystemBll || hasNewView.ContainsKey((int)Constant.ViewType.半成品视图)) { proSql += string.Format("update TFS_FTeamwork set FViewType=FViewType+',3,4' where FID={0};", teamInfo.FID); - BaseBll.CreateTaskData(teamId, userId, "8"); + BaseBll.CreateTaskData(teamInfo.FID, userId, "8"); } proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.配方视图, "F2", 1); } @@ -435,28 +513,16 @@ namespace FactorySystemBll int pVersion = (hasNewView.Count == 0 && teamInfo.FPackID < 1) ? 2 : 1; proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.生产工艺路线, "F2", pVersion); proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.生成版本, "F2", pVersion); - - string updateSql = ""; - - formulaIds = formulaIds.Replace(",,", ",").Replace(",,", ",").Replace(",,", ",").Trim(','); - if (!string.IsNullOrEmpty(formulaIds)) - { - updateSql += string.Format("FMaterialFormulaIDs='{0}',FViewType=FViewType+',2',", formulaIds); - updateSql += string.Format("FBomFormula='{0}',", JsonConvert.SerializeObject(bfList)); - } - if (!string.IsNullOrEmpty(halfIds)) updateSql += string.Format("FMaterialHalfIDs='{0}',", halfIds); - if (!string.IsNullOrEmpty(updateSql)) proSql += string.Format("update TFS_FTeamwork set {1} where FID={0};", teamInfo.FID, updateSql.Trim(',')); - proSql += BaseBll.GetTaskSql(-1, 2, teamId, (int)Constant.TaskType.BOM下载, 2); - db.Ado.ExecuteCommand(proSql.Trim(';')); - db.CommitTran(); } catch (Exception ex) { db.RollbackTran(); return false; } + return true; - } + + } private List GetBomFormulaChild(TFS_Material first, List formulaList, out string fids) { @@ -542,7 +608,7 @@ namespace FactorySystemBll FTeamID = teamInfo.FID, FFactoryID = teamInfo.FCreateFactoryID, FFactoryCode = teamInfo.FCreateFactoryCode, - FViewType = (int)Constant.ViewType.成品视图, + FViewType = (int)Constant.ViewType.物料分类视图, FLevel = 1, FEditUser = userId, FBaseMaterialCode = teamInfo.FMdmCode, diff --git a/FactorySystemBll/UserBll.cs b/FactorySystemBll/UserBll.cs index 577cdcd..3e584da 100644 --- a/FactorySystemBll/UserBll.cs +++ b/FactorySystemBll/UserBll.cs @@ -394,5 +394,46 @@ namespace FactorySystemBll return new List(); } #endregion + + /// + /// 获取冻结列 + /// + public object GetFreezingColumns(int userId) + { + TFS_FreezingColumns tc = null; + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + List tcl = db.Queryable().Where(fc => fc.FDeleted != 1 && fc.FUserID == userId).ToList(); + + if (tcl != null && tcl.Count > 0) + { + tc = tcl[0]; + } + + return tc; + } + + public int CreateFreezingColumns(int userId, List list) + { + int result = 0; + + if (list.Count() > 0) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + db.Deleteable().Where(s => s.FUserID == userId).ExecuteCommand(); + result = db.Insertable(list).ExecuteCommand(); + } + + return result; + } + + public int UpdateFreezingColumns(TFS_FreezingColumns fc) + { + int result = 0; + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + + result = db.Updateable(fc).IgnoreColumns(true).ExecuteCommand(); + + return result; + } } } diff --git a/FactorySystemBll/ViewBll.cs b/FactorySystemBll/ViewBll.cs index 51022de..5231dc3 100644 --- a/FactorySystemBll/ViewBll.cs +++ b/FactorySystemBll/ViewBll.cs @@ -23,14 +23,39 @@ namespace FactorySystemBll FStorageConditions = ""; if (byFactory == true) currUser = BaseBll.GetTempModel(currUserId, "FFactoryID"); var db = AppSettingsHelper.GetSqlSugar(); - List> viewList = db.Queryable((a, b) => - new JoinQueryInfos(JoinType.Inner, a.FMaterialID == b.FID)) - .Where((a, b) => a.FTeamID == teamId) - .WhereIF(currUser != null, (a, b) => a.FFactoryID == currUser.FFactoryID) - .WhereIF(viewType > 0, (a, b) => a.FViewType == viewType) - .Select("distinct a.*,b.FTypeID1,b.FTypeID2,b.FK3Code,b.FK3Name,b.FK3ShortCode,b.FTestCode,b.FRelationCode,b.FRelationName,b.FSAPCode,b.FSAPDescription,b.FMaterialGroup,b.FMaterialType,b.FCustomerCode,b.FStoreHouse," + - "b.FBomEntry,b.FLineHouse,b.FProductDesc,b.FWorkCenter,b.FCraftExplain,b.FIidentifier,b.FGuaranteePeriod,b.FBStorageConditions,b.FSafetyStock,b.FTriggerRatio,b.FMinAmount,b.FMaxAmount,b.FYield,b.FFixedLoss,b.FTheoryYield," + - "b.FQualityTest1,b.FQualityTest2").ToDictionaryList(); + + /** + * 20230414 需求变更 + * 新增物料分类视图获取逻辑 + * 物料分类的viewType=10,此时,取所有下载的bomList中的视图,a.FViewType in (2,3,4,5) + * 分别对应半成品视图、中间品视图、香基视图、原料视图 + * 此处的viewType来自TBasicCode中FType=33时,的FRemark字段 + * **/ + List> viewList = new List>(); + + if (viewType == 10) + { + viewList = db.Queryable((a, b) => + new JoinQueryInfos(JoinType.Inner, a.FMaterialID == b.FID)) + .Where((a, b) => a.FTeamID == teamId) + .WhereIF(currUser != null, (a, b) => a.FFactoryID == currUser.FFactoryID) + .WhereIF(viewType > 0, (a, b) => a.FViewType == 2 || a.FViewType == 3 || a.FViewType == 4 || a.FViewType == 5) + .Select("distinct a.*,b.FTypeID1,b.FTypeID2,b.FK3Code,b.FK3Name,b.FK3ShortCode,b.FTestCode,b.FRelationCode,b.FRelationName,b.FSAPCode,b.FSAPDescription,b.FMaterialGroup,b.FMaterialType,b.FCustomerCode,b.FStoreHouse," + + "b.FBomEntry,b.FLineHouse,b.FProductDesc,b.FWorkCenter,b.FCraftExplain,b.FIidentifier,b.FGuaranteePeriod,b.FBStorageConditions,b.FSafetyStock,b.FTriggerRatio,b.FMinAmount,b.FMaxAmount,b.FYield,b.FFixedLoss,b.FTheoryYield," + + "b.FQualityTest1,b.FQualityTest2").ToDictionaryList(); + } + else + { + viewList = db.Queryable((a, b) => + new JoinQueryInfos(JoinType.Inner, a.FMaterialID == b.FID)) + .Where((a, b) => a.FTeamID == teamId) + .WhereIF(currUser != null, (a, b) => a.FFactoryID == currUser.FFactoryID) + .WhereIF(viewType > 0, (a, b) => a.FViewType == viewType) + .Select("distinct a.*,b.FTypeID1,b.FTypeID2,b.FK3Code,b.FK3Name,b.FK3ShortCode,b.FTestCode,b.FRelationCode,b.FRelationName,b.FSAPCode,b.FSAPDescription,b.FMaterialGroup,b.FMaterialType,b.FCustomerCode,b.FStoreHouse," + + "b.FBomEntry,b.FLineHouse,b.FProductDesc,b.FWorkCenter,b.FCraftExplain,b.FIidentifier,b.FGuaranteePeriod,b.FBStorageConditions,b.FSafetyStock,b.FTriggerRatio,b.FMinAmount,b.FMaxAmount,b.FYield,b.FFixedLoss,b.FTheoryYield," + + "b.FQualityTest1,b.FQualityTest2").ToDictionaryList(); + } + if (viewType == 1) { List> viewList1 = db.Queryable((a, b) => new JoinQueryInfos(JoinType.Inner, a.FMaterialID == b.FID)) @@ -242,6 +267,10 @@ namespace FactorySystemBll if (viewList != null && viewList.Count > 0) { string sqlWhere = string.Format("FViewType={0} and FTeamID={1}", viewType, teamId); + if (viewType == 10) + { + sqlWhere = string.Format("FViewType in (2, 3, 4, 5) and FTeamID={1}", viewType, teamId); + } result += db.Updateable(viewList).AS("TFS_ViewMaterial").WhereColumns("FMaterialID").Where(sqlWhere).ExecuteCommand(); result += UnionModifyData(viewList, "TFS_ViewMaterial", teamId, db, "FMaterialID"); } @@ -253,7 +282,14 @@ namespace FactorySystemBll materialList[i].Remove("FMaterialID"); if (materialList[i].TryGetValue("FK3Code", out object k3Code)) { - materialList[i].Add("FK3ShortCode", k3Code.ToString().Split('.').Last()); + if (materialList[i].ContainsKey("FK3ShortCode")) + { + materialList[i]["FK3ShortCode"] = k3Code.ToString().Split('.').Last(); + } + else + { + materialList[i].Add("FK3ShortCode", k3Code.ToString().Split('.').Last()); + } } } result += db.Updateable(materialList).AS("TFS_Material").WhereColumns("FID").ExecuteCommand(); @@ -285,10 +321,17 @@ namespace FactorySystemBll string okResult = ""; if (string.IsNullOrEmpty(okResult) || okResult == "0") { - //视图类型+2是事项,除了包材 - taskType += 2; + if (taskType != 10) + { + //视图类型+2是事项,除了包材 + taskType += 2; + if (taskType >= (int)Constant.TaskType.组编号申请) taskType = (int)Constant.TaskType.新包材视图; + } + else + { + taskType = 15; + } string taskSql = ""; - if (taskType >= (int)Constant.TaskType.组编号申请) taskType = (int)Constant.TaskType.新包材视图; int proType = -2; string appSql = " and(select count(1) from TFS_Task t where t.FTeamID=a.FTeamID and t.FType in({0}) and t.FState!=2)=0"; switch (taskType) @@ -305,11 +348,14 @@ namespace FactorySystemBll case 7://新原料视图:7→新原料视图:4 proType = 4; break; + case 15://物料分类视图:15→物料分类视图:0 + proType = 0; + break; case 11://新包材视图:7→新原料视图:8 proType = 8; break; } - if (proType > 0) taskSql = BaseBll.GetProcessSql(teamId, proType, "F3", 2, string.Format(appSql, taskType)); + if (taskType == 15 || proType > 0) taskSql = BaseBll.GetProcessSql(teamId, proType, "F3", 2, string.Format(appSql, taskType)); taskSql = BaseBll.GetTaskSql(-1, 2, teamId, taskType, -1, string.Format("','+a.FUserID+',' like ',%{0}%,'", userId)) + taskSql; result += db.Ado.ExecuteCommand(taskSql); TeamworkBll.ChangeTeamProcess(teamId); diff --git a/FactorySystemModel/EnumModel/Constant.cs b/FactorySystemModel/EnumModel/Constant.cs index 3b188aa..75c5f74 100644 --- a/FactorySystemModel/EnumModel/Constant.cs +++ b/FactorySystemModel/EnumModel/Constant.cs @@ -78,7 +78,8 @@ namespace FactorySystemModel.EnumModel 香基视图 = 4, 原料视图 = 5, 包材视图 = 6, - 物料主表 = 7 + 物料主表 = 7, + 物料分类视图 = 10 } /// diff --git a/FactorySystemModel/FactorySystemModel.csproj b/FactorySystemModel/FactorySystemModel.csproj index 51c5cc9..e802be9 100644 --- a/FactorySystemModel/FactorySystemModel.csproj +++ b/FactorySystemModel/FactorySystemModel.csproj @@ -64,6 +64,7 @@ + diff --git a/FactorySystemModel/SqlSugarModel/TFS_FreezingColumns.cs b/FactorySystemModel/SqlSugarModel/TFS_FreezingColumns.cs new file mode 100644 index 0000000..b1c5e65 --- /dev/null +++ b/FactorySystemModel/SqlSugarModel/TFS_FreezingColumns.cs @@ -0,0 +1,73 @@ +using System; +using SqlSugar; + +namespace FactorySystemModel.SqlSugarModel +{ + /// + ///用户冻结表 + /// + [SugarTable("TFS_FreezingColumns")] + public partial class TFS_FreezingColumns + { + + public TFS_FreezingColumns() + { + + } + /// + /// Desc:主键 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int FID { get; set; } + + /// + /// Desc:用户ID + /// Default: + /// Nullable:False + /// + public int FUserID { get; set; } + + /// + /// Desc:冻结列 + /// Default: + /// Nullable:False + /// + public string FFreezingColumns { get; set; } + + /// + /// Desc:是否删除 + /// Default:0 + /// Nullable:False + /// + public int FDeleted { get; set; } + + /// + /// Desc:添加人 + /// Default:-1 + /// Nullable:False + /// + public int FAddUser { get; set; } + + /// + /// Desc:添加时间 + /// Default:DateTime.Now + /// Nullable:False + /// + public DateTime FAddDate { get; set; } + + /// + /// Desc:修改人 + /// Default:-1 + /// Nullable:False + /// + public int FEditUser { get; set; } + /// + /// Desc:修改时间 + /// Default:DateTime.Now + /// Nullable:False + /// + public DateTime FEditDate { get; set; } + } +} diff --git a/FactorySystemModel/SqlSugarModel/TFS_MaterialInfo.cs b/FactorySystemModel/SqlSugarModel/TFS_MaterialInfo.cs index da52ae6..4cbef37 100644 --- a/FactorySystemModel/SqlSugarModel/TFS_MaterialInfo.cs +++ b/FactorySystemModel/SqlSugarModel/TFS_MaterialInfo.cs @@ -1043,7 +1043,7 @@ namespace FactorySystemModel.SqlSugarModel /// Default:'' /// Nullable:TRUE /// - public string FMStorageConditions { get; set; } + public string FBStorageConditions { get; set; } /// /// Desc:基础视图.一级分类.类型 @@ -1561,7 +1561,7 @@ namespace FactorySystemModel.SqlSugarModel /// Default:0 /// Nullable:FALSE /// - public string FMStorageConditionsType { get; set; } + public string FBStorageConditionsType { get; set; } /// /// Desc:仓储视图.批次管理.类型