From 7142250dd64ca5b0e67154db0ed6e97d7a6d2a6e Mon Sep 17 00:00:00 2001 From: Yang <903110162@qq.com> Date: Sun, 23 Apr 2023 09:55:28 +0800 Subject: [PATCH] commit by yzf --- .../Controllers/ViewController.cs | 58 +++---- FactorySystemBll/ViewBll.cs | 153 +++++++++++++++++- 2 files changed, 180 insertions(+), 31 deletions(-) diff --git a/FactorySystemApi/Controllers/ViewController.cs b/FactorySystemApi/Controllers/ViewController.cs index 0b3cd43..d1ee45d 100644 --- a/FactorySystemApi/Controllers/ViewController.cs +++ b/FactorySystemApi/Controllers/ViewController.cs @@ -256,39 +256,39 @@ namespace FactorySystemApi.Controllers List ids = new List { 2,3,4,5,10}; if (ids.Contains(viewType)) { - // 创建物料视图事项 - TFS_HalfMaterialFTeamwork 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 (ids.Contains(materialType)) - { - if (hasNewView.ContainsKey(materialType)) - { - hasNewView[materialType] = hasNewView[materialType] + factoryId + ","; - } - else - { - hasNewView.Add(materialType, factoryId + ","); - } - } - } - HalfMaterialTeamworkBll TeamworkBll = new HalfMaterialTeamworkBll(); - TeamworkBll.CreateMaterialTask(hasNewView, teamwork, user.FID); - } + //// 创建物料视图事项 + //TFS_HalfMaterialFTeamwork teamwork = BaseBll.GetTempModel(teamId); + //List> vml = _viewBll.GetHalfMaterialListByTeamId(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 (ids.Contains(materialType)) + // { + // if (hasNewView.ContainsKey(materialType)) + // { + // hasNewView[materialType] = hasNewView[materialType] + factoryId + ","; + // } + // else + // { + // hasNewView.Add(materialType, factoryId + ","); + // } + // } + // } + // HalfMaterialTeamworkBll TeamworkBll = new HalfMaterialTeamworkBll(); + // TeamworkBll.CreateMaterialTask(hasNewView, teamwork, user.FID); + //} HalfMaterialTaskBll halfMaterialTaskBll = new HalfMaterialTaskBll(); halfMaterialTaskBll.CloseHalfMaterialTask(teamId, user.FID, (int)Constant.HalfMaterialProcessType.物料分类); BaseBll.CreateTaskData2(teamId, user.FID, "2"); - BaseBll.UpdateTeamProcess2(teamwork.FID, (int)Constant.HalfMaterialProcessType.物料分类, 2, 2); - BaseBll.UpdateTeamProcess2(teamwork.FID, (int)Constant.HalfMaterialProcessType.物料编辑, 2, 1); + BaseBll.UpdateTeamProcess2(teamId, (int)Constant.HalfMaterialProcessType.物料分类, 2, 2); + BaseBll.UpdateTeamProcess2(teamId, (int)Constant.HalfMaterialProcessType.物料编辑, 2, 1); } } diff --git a/FactorySystemBll/ViewBll.cs b/FactorySystemBll/ViewBll.cs index bcb7cf5..766fb8b 100644 --- a/FactorySystemBll/ViewBll.cs +++ b/FactorySystemBll/ViewBll.cs @@ -112,6 +112,113 @@ namespace FactorySystemBll return viewList; } + + + /// + /// 根据协同ID获取物料视图 + /// + public List> GetHalfMaterialListByTeamId(int teamId, int viewType, int currUserId, out List materialId, out string FGuaranteePeriod, out string FStorageConditions, bool byFactory = true) + { + TUser currUser = null; + FGuaranteePeriod = ""; + FStorageConditions = ""; + if (byFactory == true) currUser = BaseBll.GetTempModel(currUserId, "FFactoryID"); + var db = AppSettingsHelper.GetSqlSugar(); + + /** + * 20230414 需求变更 + * 新增物料分类视图获取逻辑 + * 物料分类的viewType=10,此时,取所有下载的bomList中的视图,a.FViewType in (2,3,4,5) + * 分别对应半成品视图、中间品视图、香基视图、原料视图 + * 此处的viewType来自TBasicCode中FType=33时,的FRemark字段 + * **/ + List> viewList = new List>(); + List viewTypes = new List { 2, 3, 4, 5 }; + if (viewTypes.Contains(viewType)) + { + viewList = db.Queryable((a, b) => + new JoinQueryInfos(JoinType.Inner, a.FMaterialID == b.FID)) + .Where((a, b) => a.FHalfMaterialTeamID == 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(); + } + else 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) + .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(); + + TFS_HalfMaterialFTeamwork teamWork = db.Queryable().Where(s => s.FID == teamId).First(); + TFS_PackageMain packAge = db.Queryable().Where(s => s.FCode == teamWork.FPackCode).First(); + + if (packAge != null) + { + viewList[0].Remove("FBaseGrossWeight"); + viewList[0].Add("FBaseGrossWeight", packAge.FGrossWeight); + viewList[0].Remove("FBaseNetWeight"); + viewList[0].Add("FBaseNetWeight", packAge.FNetWeight); + viewList[0].Remove("FBaseSpecification"); + viewList[0].Add("FBaseSpecification", packAge.FSpecs); + viewList[0].Add("HalfCode", teamWork.FMaterialHalfIDs); + } + var FBaseMaterialDesc = viewList.GroupBy(s => s["FBaseMaterialDesc"]).Select(s => s.Key).ToList(); + + if (FBaseMaterialDesc.Count > 0) + { + viewList[0].Add("HalfDesc", FBaseMaterialDesc[0]); + } + } + + if (viewType == 1) + { + viewList = db.Queryable((a, b) => + new JoinQueryInfos(JoinType.Inner, a.FMaterialID == b.FID)) + .Where((a, b) => a.FHalfMaterialTeamID == teamId) + .WhereIF(currUser != null, (a, b) => a.FFactoryID == currUser.FFactoryID) + .WhereIF(viewType > 0, (a, b) => a.FViewType == 2) + .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(); + List Minfo = GetMaterialInfoList(viewList.GroupBy(s => s["FMaterialID"]).Select(s => int.Parse(s.Key.ToString())).ToList(), "", "", currUserId); + if (Minfo.Count > 0) + { + FGuaranteePeriod = Minfo[0].FGuaranteePeriod; + FStorageConditions = Minfo[0].FStorageConditions; + } + + TFS_HalfMaterialFTeamwork teamWork = db.Queryable().Where(s => s.FID == teamId).First(); + TFS_PackageMain packAge = db.Queryable().Where(s => s.FCode == teamWork.FPackCode).First(); + + if (packAge != null) + { + viewList[0].Remove("FBaseGrossWeight"); + viewList[0].Add("FBaseGrossWeight", packAge.FGrossWeight); + viewList[0].Remove("FBaseNetWeight"); + viewList[0].Add("FBaseNetWeight", packAge.FNetWeight); + viewList[0].Remove("FBaseSpecification"); + viewList[0].Add("FBaseSpecification", packAge.FSpecs); + viewList[0].Add("HalfCode", teamWork.FMaterialHalfIDs); + } + var FBaseMaterialDesc = viewList.GroupBy(s => s["FBaseMaterialDesc"]).Select(s => s.Key).ToList(); + + if (FBaseMaterialDesc.Count > 0) + { + viewList[0].Add("HalfDesc", FBaseMaterialDesc[0]); + } + } + materialId = viewList.GroupBy(s => s["FMaterialID"]).Select(s => int.Parse(s.Key.ToString())).ToList(); + return viewList; + } + + + /// /// 根据协同ID获取物料视图 /// @@ -547,7 +654,7 @@ namespace FactorySystemBll 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"); + result += HalfMaterialUnionModifyData(viewList, "TFS_ViewMaterial", teamId, db, "FMaterialID"); } if (materialList != null && materialList.Count > 0) { @@ -568,7 +675,7 @@ namespace FactorySystemBll } } result += db.Updateable(materialList).AS("TFS_Material").WhereColumns("FID").ExecuteCommand(); - result += UnionModifyData(materialList, "TFS_Material", teamId, db); + result += HalfMaterialUnionModifyData(materialList, "TFS_Material", teamId, db); } if (infoList != null && infoList.Count > 0) { @@ -689,6 +796,48 @@ namespace FactorySystemBll } + + + private int HalfMaterialUnionModifyData(List> dataList, string srcTable, int teamId, SqlSugarClient db = null, string colName = "FID") + { + int result = 0; + if (dataList != null && dataList.Count > 0) + { + if (db == null) db = AppSettingsHelper.GetSqlSugar(); + List unionList = db.Queryable().Where(s => s.FDeleted != 1 && s.FTableOriginal == srcTable).ToList(); + if (unionList.Count > 0) + { + List sqlList = new List() { "update {0} set {0}.{1}={2}.{3} from {0} left join {2} on {4} where {2}.{5}='{6}' {7}" }; + foreach (Dictionary data in dataList) + { + foreach (TFS_UnionModify union in unionList) + { + if (data.TryGetValue(union.FColumnOriginal, out object srcVal)) + { + string sqlWhere = ""; + if (union.FTableTarget == "TFS_ViewMaterial" || union.FTableOriginal == "TFS_ViewMaterial") + { + sqlWhere = " and TFS_ViewMaterial.FHalfMaterialTeamID=" + teamId; + } + sqlList.Add(string.Format(sqlList[0], union.FTableTarget, union.FColumnTarget, + union.FTableOriginal, union.FColumnOriginal, union.FUnionCondition, colName, + data[colName], sqlWhere)); + } + } + } + sqlList.RemoveAt(0); + if (sqlList.Count > 0) + { + string updateSql = string.Join(";", sqlList); + try { result = db.Ado.ExecuteCommand(updateSql); } + catch (Exception) { } + } + } + } + return result; + } + + public object EexcSql(int tempId=0) { string sql = "";