diff --git a/FactorySystemApi/Controllers/MaterialTaskController.cs b/FactorySystemApi/Controllers/MaterialTaskController.cs index 97f1619..441a955 100644 --- a/FactorySystemApi/Controllers/MaterialTaskController.cs +++ b/FactorySystemApi/Controllers/MaterialTaskController.cs @@ -24,22 +24,21 @@ namespace FactorySystemApi.Controllers /// 根据当前用户获取任务列表 /// [HttpPost] - public ApiResult GetPageList(TaskQuery tq) + public ApiResult GetPageList(MaterialTaskQuery mtq) { ApiResult apiResult = new ApiResult(); return ExceptionHelper.TryReturnException(() => { - if (tq.FIsUser && Request.Properties["token"] is ApiAuthInfo user) + if (mtq.FIsUser && Request.Properties["token"] is ApiAuthInfo user) { - tq.FUserID = user.FID.ToString(); + mtq.FUserID = user.FID.ToString(); } apiResult.Data = new { - List = _taskBll.GetList(tq, out var totalNumber), + List = _taskBll.GetList(mtq, out var totalNumber), Total = totalNumber }; }, apiResult, Request); } - } } diff --git a/FactorySystemApi/Controllers/MaterialTeamworkController.cs b/FactorySystemApi/Controllers/MaterialTeamworkController.cs index 0087a12..50c28f9 100644 --- a/FactorySystemApi/Controllers/MaterialTeamworkController.cs +++ b/FactorySystemApi/Controllers/MaterialTeamworkController.cs @@ -14,6 +14,7 @@ using Newtonsoft.Json.Linq; using FactorySystemApi.Plm_Formula; using System.Linq; using SqlSugar; +using FactorySystemModel.RequestModel; namespace FactorySystemApi.Controllers { @@ -21,12 +22,24 @@ namespace FactorySystemApi.Controllers /// 协同接口 /// [UserLoginFilter] - public class MaterialTeamworkController : BaseController + public class MaterialTeamworkController : ApiController { /// /// 数据处理层 /// - public readonly MaterialTeamworkBll MaterialTeamworkBll = new MaterialTeamworkBll(); + public readonly BaseBll BaseBll = new BaseBll(); + /// + /// 数据处理层-物料处理 + /// + public readonly MaterialBll MaterialBll = new MaterialBll(); + /// + /// 数据处理层-视图处理 + /// + public readonly ViewBll ViewBll = new ViewBll(); + /// + /// 数据处理层-路线处理 + /// + private readonly MaterialTeamworkBll _taskBll = new MaterialTeamworkBll(); /// /// 事项操作日志 /// @@ -36,1190 +49,183 @@ namespace FactorySystemApi.Controllers /// public MaterialTeamworkController() { - //设置可新增、修改字段 - InsertField = UpdateField = ""; } /// - /// 获取子项集合 + /// 新增物料路线 /// [HttpPost] - public ApiResult GetTeamworkPageList(Dictionary pageParam) + public ApiResult InsertDataModel(Dictionary inParam) { ApiResult apiResult = new ApiResult(); return ExceptionHelper.TryReturnException(() => { ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; - apiResult.Data = new - { - List = MaterialTeamworkBll.GetTeamworkPageList(pageParam, user.FID, out int totalCount), - Total = totalCount - }; - }, apiResult, Request, pageParam); - } + TFS_Factory factory = BaseBll.GetTempModel(int.Parse(inParam["FCreateFactoryID"].ToString())); + Dictionary result = new Dictionary(); - /// - /// 获取流程集合 - /// - [HttpPost] - public ApiResult GetTeamProcessList(Dictionary pageParam) - { - return GetTPageList(pageParam, null, "FGroup,FType"); - } - - /// - /// 新增协同 - /// - [HttpPost] - public override ApiResult InsertDataModel(Dictionary inParam) - { - List ids = null; - 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 - { - try - { - ids = MaterialTeamworkBll.UpdateFormula(inParam["FTestCode"].ToString(), inParam["FNewTestCode"].ToString()); - 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); - } - if (!inParam.ContainsKey("FSaleCode")) - { - inParam.Add("FSaleCode", ""); - } - - //创建 TFS_FTeamwork - int teamId = BaseBll.InsertDataModel(inParam, "TFS_MaterialFTeamwork"); - apiResult.Data = teamId; - if (teamId > 0) - { - inParam.Add("FID", teamId); - //创建流程 - int resultProcessCreate = MaterialTeamworkBll.CreateProcessData(teamId, user.FID); - if (resultProcessCreate > 0) - { - //直接走下一步 - if (state.ToString().Contains("1")) - { - TFS_MaterialFTeamwork teamwork = BaseBll.GetTempModel(teamId); - List materialList = MaterialTeamworkBll.CheckMaterialListByTest2(teamwork.FNewTestCode, teamwork.FCreateFactoryID); - if (materialList.Count == 0) - { - MaterialTeamworkBll.CreateProductView(teamwork, null, user.FID); - //开始BOM下载 - DockGetBomData(teamwork.FID, user.FID); - } - else - { - MaterialTeamworkBll.CreateProductView(teamwork, materialList, user.FID); - MaterialTeamworkBll.HasMaterialTestCode(teamwork); + inParam.Remove("FID"); - /** - * 20230414 需求变更 - * 在创建各类事项前,先创建物料分类事项 - * 此处创建各类事项流程中断,转移至物料分类事项提交后进行 - * **/ - BaseBll.CreateTaskData2(teamwork.FID, user.FID, "15"); //新增物料分类事项 - BaseBll.UpdateTeamProcess2(teamId, (int)Constant.ProcessType.物料分类, 2, 1); // 更新物料分类流程 + string materialName = inParam["FMaterialName"].ToString(); - ////补充包材规格 - //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.CreateTaskData2(teamId, user.FID, ((int)Constant.TaskType.配方选择).ToString()); - BaseBll.UpdateTeamProcess2(teamId, (int)Constant.ProcessType.协同发起, 1, 1); - } - } - else - { - BaseBll.DeleteDataById(teamId, "TFS_FTeamwork", true); - apiResult.Error("流程创建失败,请稍后重试"); - } - MaterialTeamworkBll.ChangeTeamProcess(teamId); - } - } - catch (Exception ex) - { - //失败则把修改的更新回去 - ids = MaterialTeamworkBll.UpdateFormula(inParam["FTestCode"].ToString(), inParam["FNewTestCode"].ToString(),string.Join(",",ids)); - throw; - } - - } - }, 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 (null == state) { - if (state.ToString().Contains("1")) - { - int teamId = int.Parse(inParam["FID"].ToString()); - TFS_MaterialFTeamwork teamwork = BaseBll.GetTempModel(teamId); - List materialList = MaterialTeamworkBll.CheckMaterialListByTest(teamwork.FTestCode, teamwork.FVersionCode); - if (materialList.Count == 0) - { - MaterialTeamworkBll.CreateProductView(teamwork, null, user.FID); - //开始BOM下载 - DockGetBomData(teamwork.FID, user.FID); - } - else - { - MaterialTeamworkBll.CreateProductView(teamwork, materialList, user.FID); - MaterialTeamworkBll.HasMaterialTestCode(teamwork); - - /** - * 20230414 需求变更 - * 在创建各类事项前,先创建物料分类事项 - * 此处创建各类事项流程中断,转移至物料分类事项提交后进行 - * **/ - BaseBll.CreateTaskData2(teamwork.FID, user.FID, "15"); //新增物料分类事项 - BaseBll.UpdateTeamProcess2(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); - } - MaterialTeamworkBll.ChangeTeamProcess(teamId); - } + inParam["FState"] = state = 1; } - 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")) + if (inParam.ContainsKey("FAddUser")) { - ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; - int teamId = int.Parse(inParam["FTeamID"].ToString()); - apiResult.Data = DockGetBomData(teamId, user.FID); + inParam["FAddUser"] = user.FID; } else { - apiResult.Error("获取协同信息失败"); + inParam.Add("FAddUser", user.FID); } - }, apiResult, Request, inParam); - } - /// - /// 获取协同视图信息 - /// - [HttpPost] - public ApiResult GetTeamworkView(Dictionary inParam) - { - ApiResult apiResult = new ApiResult(); - return ExceptionHelper.TryReturnException(() => - { - if (inParam.ContainsKey("FTeamID")) + if (inParam.ContainsKey("FAddDate")) { - 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("\\", "/"); - } + inParam["FAddDate"] = DateTime.Now; } else { - apiResult.Error("获取协同信息失败"); + inParam.Add("FEditDate", DateTime.Now); } - }, apiResult, Request, inParam); - } - /// - /// 更新物料分类 - /// - /// - /// - [HttpPost] - public ApiResult EditTypeList(Dictionary inParam) - { - ApiResult apiResult = new ApiResult(); - return ExceptionHelper.TryReturnException(() => { - if (inParam["tempId"] != null && inParam["taskId"]!=null) + if (inParam.ContainsKey("FEditUser")) { - 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 = MaterialTeamworkBll.ExecSql(sql); - apiResult.Data = NextTask(int.Parse(inParam["tempId"].ToString()),int.Parse(inParam["taskId"].ToString())); - } - - - }, apiResult, Request, inParam); - - } - - - /// - /// 更新试验号 - /// - /// - /// - //public ApiResult UpdateFormula(Dictionary inParam) - //{ - - // ApiResult apiResult = new ApiResult(); - // return ExceptionHelper.TryReturnException(() => - // { - // if (!inParam.ContainsKey("formula1")) - // { - // apiResult.Error("视图信息获取失败"); - // } - // else - // { - // MaterialTeamworkBll.UpdateFormula(inParam["formula1"].ToString(), inParam["formula2"].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_MaterialFTeamwork"); - BaseBll.UpdateTeamProcess2(teamwork.FID, (int)Constant.ProcessType.物料分类, 2, 2); - int count= MaterialTeamworkBll.ExecSql(BaseBll.GetTaskSql(taskId, 2, teamId, (int)Constant.ProcessType.物料分类)); - - - BaseBll.UpdateTeamProcess2(teamwork.FID, (int)Constant.ProcessType.替代品确认, 2, 1); - BaseBll.CreateTaskData2(teamwork.FID, user.FID, "16");//替代品确认 - - - BaseBll.UpdateTeamProcess2(teamwork.FID, (int)Constant.ProcessType.协同发起, 3, 2); - - if (teamwork.FPackID == -1) - { - BaseBll.CreateTaskData2(teamwork.FID, user.FID, "9");//新增新包材事项 - BaseBll.UpdateTeamProcess2(teamwork.FID, (int)Constant.ProcessType.组装BOM包含新包材, 2, 1); - } - else - { - BaseBll.UpdateTeamProcess2(teamwork.FID, (int)Constant.ProcessType.组装BOM包含新包材, 3, 2); - } - //等类型修改结束使用 - //成品视图 - BaseBll.CreateTaskData2(teamwork.FID, user.FID, "3", teamwork.FCreateFactoryID + "," + teamwork.FProdFactoryID); - //补充包材规格 - BaseBll.CreateTaskData2(teamwork.FID, user.FID, "14"); - //成品视图物料组复核,有权限的所有 - BaseBll.CreateTaskData2(teamwork.FID, user.FID, "12"); - MaterialTeamworkBll.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_MaterialFTeamwork 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 (MaterialTeamworkBll.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_MaterialFTeamwork"); - - /** - * 20230414 需求变更 - * 在创建各类事项前,先创建物料分类事项 - * 此处创建各类事项流程中断,转移至物料分类事项提交后进行 - * **/ - BaseBll.CreateTaskData2(teamwork.FID, userId, "15"); //新增物料分类事项 - BaseBll.UpdateTeamProcess2(teamId, (int)Constant.ProcessType.物料分类, 2, 1); // 更新物料分类流程 - - ////协同发起事项 - //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"); - OperateLogBll.Add(teamwork.FID, 2, "BOM下载成功", userId); - MaterialTeamworkBll.ChangeTeamProcess(teamwork.FID); - result = 1; - } + inParam["FEditUser"] = user.FID; } else { - OperateLogBll.Add(teamwork.FID, 2, "BOM下载失败,BOM数据为空", userId); - BaseBll.CreateTaskData2(teamwork.FID, userId, ((int)Constant.TaskType.BOM下载).ToString()); - BaseBll.UpdateTeamProcess2(teamwork.FID, (int)Constant.ProcessType.协同发起, 2, 1); - MaterialTeamworkBll.ChangeTeamProcess(teamwork.FID); + inParam.Add("FEditUser", user.FID); } - } - catch (Exception ex) - { - OperateLogBll.Add(teamwork.FID, 2, "BOM下载失败,请稍后重试(对接)", userId); - BaseBll.CreateTaskData2(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) + if (inParam.ContainsKey("FEditDate")) { - 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 = MaterialTeamworkBll.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); + inParam["FEditDate"] = DateTime.Now; } else { - selectSql += string.Format("isnull({0},'') as '{1}'", field.FField, field.FName); + inParam.Add("FEditDate", DateTime.Now); } - selectSql += ","; - } - selectSql = selectSql.Replace("@FTeamID@", teamId); - selectSql = selectSql.Replace("@FMaterialID@", halfId); - DataTable dataList = new DataTable(); - if (intType == (int)Constant.TeamViewType.组装BOM视图) - { - dataList = MaterialTeamworkBll.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 (inParam.ContainsKey("FCreateFactoryID")) { - 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"; + inParam.Remove("FCreateFactoryID"); } - NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath.Replace(".xlsx", "1.xlsx")); - - //计划组装BOM处理 - DataTable dataList3 = dataList2.Copy(); - for (int i = 0; i < rowCount; i++) + inParam.Add("FCreateFactoryID", factory.FID); + inParam.Add("FCreateFactoryCode", factory.FCode); + inParam.Add("FCreateFactoryType", factory.FType); + if (factory.FType != (int)Constant.FactoryType.单工厂) { - 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"; + TFS_Factory prodFactory = BaseBll.GetTempModel(factory.FFactoryID); + inParam.Add("FProdFactoryID", prodFactory.FID); + inParam.Add("FProdFactoryCode", prodFactory.FCode); } - NPOIHelper.ExportDTtoExcel(dataList2, "Sheet1", savePath.Replace(".xlsx", "2.xlsx")); - for (int i = 0; i < dataList2.Rows.Count; i++) + else { - if (i == 0) dataList.Rows.Add("[换色]"); - dataList.ImportRow(dataList2.Rows[i]); + inParam.Add("FProdFactoryID", factory.FID); + inParam.Add("FProdFactoryCode", factory.FCode); } - } - else if (intType == (int)Constant.TeamViewType.配方视图) - { - //原始配方 - DataTable dataList1 = MaterialTeamworkBll.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(); + inParam.Add("FTeamworkType", 1); - 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(); + int teamId = BaseBll.InsertDataModel(inParam, "TFS_FMaterialTeamwork"); + result.Add("TeamId", teamId); - rowList = SetXHData(null, bfList, dataList1, forIdList, 2); - totalTable.Rows.Add("[换色]"); - foreach (var item in rowList) + if (teamId > 0) { - 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(); + inParam.Add("FID", teamId); - 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 (state.ToString().Contains("1")) { - 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 = MaterialTeamworkBll.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用途"); + TFS_FMaterialTeamwork teamwork = BaseBll.GetTempModel(teamId); - DataTable dataList2 = dataList.Copy(); - for (int i = 0; i < rowCount; i++) - { - if (isChange && dataList2.Rows[i]["BOM用途"].ToString() == "1") + // 创建物料和物料视图 + Dictionary materialInfo = CreateMaterial(inParam, factory, teamwork); + foreach(string key in materialInfo.Keys) { - dataList2.Rows[i]["BOM用途"] = "Y"; + result.Add(key, materialInfo[key]); } - } - 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]); + + // 创建物料分类任务 + int taskId = BaseBll.CreateMaterialTask(teamId, user.FID, 15, factory.FID); + result.Add("TaskId", taskId); } } - } - if (intType == (int)Constant.TeamViewType.物料视图) - { - //處理名字點 - } - NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath); + + apiResult.Data = result; + }, apiResult, Request, inParam); } /// - /// 梳理父项 + /// 查询物料路线 /// - private void SetBFData(TFS_ViewMaterial parent, List bfList, DataTable dtList) + [HttpPost] + public ApiResult GetPageList(MaterialTeamworkQuery mtq) { - if (bfList != null && bfList.Count > 0) + ApiResult apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => { - foreach (var item in bfList) + if (mtq.FIsUser && Request.Properties["token"] is ApiAuthInfo user) { - 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); - } + mtq.FUserID = user.FID; } - } + apiResult.Data = new + { + List = _taskBll.GetList(mtq, out var totalNumber), + Total = totalNumber + }; + }, apiResult, Request); } - /// - /// 梳理序号(type:1原始,2生产,3计划) - /// - private List SetXHData(BomFormulaDto parent, List bfList, DataTable dtList, List forIdList, int type) + private Dictionary CreateMaterial(Dictionary inParam, TFS_Factory factory, TFS_FMaterialTeamwork teamwork) { - 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]; + Dictionary result = new Dictionary(); + // 创建物料(物料表新增数据) + TFS_Material material = new TFS_Material(); + material.FName = inParam["FMaterialName"].ToString(); // 物料名称 + material.FDesc = inParam["FMaterialName"].ToString(); // 物料描述 + material.FMaterialGroup = inParam["FMaterialGroup"].ToString(); // 物料组 + material.FBaseUnit = inParam["FWeightUnit"].ToString(); // 计量单位 + material.FFactoryID = factory.FFactoryID; // 工厂 + material.FFactoryCode = factory.FCode; // 工厂标识 + material.FTestCode = inParam["FTestCode"].ToString(); // 试验号 + + int materialId = MaterialBll.InsertMaterial(material); + + result.Add("MaterialId", materialId); + + // 创建物料视图 + TFS_ViewMaterial viewMaterial = new TFS_ViewMaterial(); + viewMaterial.FTeamID = teamwork.FID; // 路线ID + viewMaterial.FMaterialID = materialId; // 物料ID + viewMaterial.FFactoryID = teamwork.FCreateFactoryID; // 工厂ID + viewMaterial.FFactoryCode = teamwork.FCreateFactoryCode; // 工厂Code + viewMaterial.FAddDate = DateTime.Now; // 创建日期 + viewMaterial.FTeamType = 1; // 路线类型 + + int vmId = ViewBll.InsertMaterialView(viewMaterial); + result.Add("ViewId", vmId); + + // 创建委托工厂视图 + if (!teamwork.FCreateFactoryID.Equals(teamwork.FProdFactoryID)) + { + viewMaterial = new TFS_ViewMaterial(); + viewMaterial.FTeamID = teamwork.FID; // 路线ID + viewMaterial.FMaterialID = materialId; // 物料ID + viewMaterial.FFactoryID = teamwork.FProdFactoryID; // 工厂ID + viewMaterial.FFactoryCode = teamwork.FProdFactoryCode; // 工厂Code + viewMaterial.FAddDate = DateTime.Now; // 创建日期 + viewMaterial.FTeamType = 1; // 路线类型 + + int prodVmId = ViewBll.InsertMaterialView(viewMaterial); + result.Add("ProdViewId", prodVmId); } - return new List(); - } - #endregion + return result; + } } } diff --git a/FactorySystemApi/Controllers/ViewController.cs b/FactorySystemApi/Controllers/ViewController.cs index ca7e973..b3d7c94 100644 --- a/FactorySystemApi/Controllers/ViewController.cs +++ b/FactorySystemApi/Controllers/ViewController.cs @@ -57,6 +57,33 @@ namespace FactorySystemApi.Controllers }, apiResult, Request); } + /// + /// 根据物料路线ID获取物料视图 + /// + [HttpPost] + public ApiResult GetMaterialViewsByTeamId(Dictionary inParam) + { + var apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => + { + if (Request.Properties["token"] is ApiAuthInfo user) + { + int teamId = int.Parse(inParam["teamId"].ToString()); + int viewType = int.Parse(inParam["viewType"].ToString()); + int teamType = int.Parse(inParam["teamType"].ToString()); + + apiResult.Data = new + { + columns = _viewBll.GetColumns(), + rows = _viewBll.GetMaterialViewsByTeamId(teamId, viewType, teamType, user.FID, out List materialId, out string FGuaranteePeriod, out string FStorageConditions, !inParam.ContainsKey("FAllView")), + infos = _viewBll.GetMaterialInfoList(materialId, FGuaranteePeriod, FStorageConditions, user.FID), + types = _viewBll.GetMaterialTypeList() + }; + + } + }, apiResult, Request); + } + /// /// 根据协同ID获取基础表集合 /// diff --git a/FactorySystemBll/BaseBll.cs b/FactorySystemBll/BaseBll.cs index 7bb4c7e..cd0cda2 100644 --- a/FactorySystemBll/BaseBll.cs +++ b/FactorySystemBll/BaseBll.cs @@ -422,6 +422,58 @@ namespace FactorySystemBll } } + + public static int CreateMaterialTask(int teamId, int userId, int type, int factoryId) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + int funcType = (int)Constant.RoleType.物料视图编辑; + string tType = "10"; + int taskId = -1; + + try + { + List funcVal = db.Queryable().Where(s => s.FType == (int)Constant.BasicCode.物料视图编辑 && s.F1 == tType && s.FState == 1).Select(s => s.FValue).ToList(); + List users = db.Queryable((a, b) => new JoinQueryInfos(JoinType.Left, a.FRoleID == b.FRoleID)) + .Where((a, b) => a.FState == 1 && a.FDeleted != 1 && b.FType == funcType && funcVal.Contains(b.FFunctionID.ToString())) + .Where(string.Format("a.FFactoryID in({0})", factoryId)) + .GroupBy("a.FID,a.FFactoryID,a.FName,a.FUser").Select("a.FID,a.FFactoryID,a.FName,a.FUser").ToList(); + + if (users.Count > 0) { + + TFS_FMaterialTask materialTask = new TFS_FMaterialTask(); + materialTask.FMaterialTeamID = teamId; + materialTask.FType = type; + materialTask.FFactoryID = factoryId; + materialTask.FCanEdit = 1; + materialTask.FAddUser = userId; + materialTask.FAddDate = DateTime.Now; + materialTask.FState = 1; + + if (type == 15) + { + materialTask.FName = "物料分类"; + materialTask.FDesc = "物料分类选择"; + } + else + { + materialTask.FName = "物料视图"; + materialTask.FDesc = "物料视图编辑"; + } + + materialTask.FUserID = string.Join(",", users.GroupBy(ss => ss.FID).Select(sss => sss.Key)); + materialTask.FUserName = string.Join("、", users.GroupBy(ss => ss.FName).Select(sss => sss.Key)); + + taskId = db.Insertable(materialTask).IgnoreColumns(true).ExecuteReturnIdentity(); + } + } + catch (Exception ex) + { + taskId = -1; + } + + return taskId; + } + /// /// 更换试验号流程创建事项 /// diff --git a/FactorySystemBll/FactorySystemBll.csproj b/FactorySystemBll/FactorySystemBll.csproj index 8da7ace..aeaab62 100644 --- a/FactorySystemBll/FactorySystemBll.csproj +++ b/FactorySystemBll/FactorySystemBll.csproj @@ -51,6 +51,8 @@ + + diff --git a/FactorySystemBll/MaterialBll.cs b/FactorySystemBll/MaterialBll.cs index d02aa9d..727162c 100644 --- a/FactorySystemBll/MaterialBll.cs +++ b/FactorySystemBll/MaterialBll.cs @@ -106,7 +106,6 @@ namespace FactorySystemBll .Where((a, b) => b.FTeamID == tempId).Select((a, b) => a).ToList(); } - /// /// 物料子数据比对 /// @@ -1329,24 +1328,18 @@ namespace FactorySystemBll return db.Ado.ExecuteCommand(sql); } - /// - /// 更新配方 - /// - /// 原配方 - /// 新配方 - /// - public bool UpdateFormula(string testCode,string testCode2) + public List GetMaterialByFName(string fname) { SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + List mainsList = db.Queryable().Where(s => s.FDeleted != (int)Constant.DeleteCode.已删除 && s.FName.Equals(fname)).ToList(); - List materialList=db.Queryable().Where(m=>m.FTestCode== testCode).ToList(); - List ids = materialList.Select(m => m.FID).ToList(); - //更新配方 - string sql = string.Format("update TFS_Material set FFTestCode={0} WHERE FID in ({1})", testCode2, string.Join(",", ids)); - - return false; + return mainsList; } - + public int InsertMaterial(TFS_Material material) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + return db.Insertable(material).IgnoreColumns(true).ExecuteReturnIdentity(); + } } } \ No newline at end of file diff --git a/FactorySystemBll/MaterialTaskBll.cs b/FactorySystemBll/MaterialTaskBll.cs index ab6b4f7..f32779d 100644 --- a/FactorySystemBll/MaterialTaskBll.cs +++ b/FactorySystemBll/MaterialTaskBll.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using FactorySystemCommon; -using FactorySystemModel.EnumModel; +using FactorySystemCommon; using FactorySystemModel.RequestModel; using FactorySystemModel.ResponseModel; using FactorySystemModel.SqlSugarModel; -using Newtonsoft.Json; using SqlSugar; +using System; +using System.Collections.Generic; namespace FactorySystemBll { @@ -16,29 +13,26 @@ namespace FactorySystemBll /// /// 获取任务列表 /// - public List GetList(TaskQuery tq, out int totalNumber) + public List GetList(MaterialTaskQuery mtq, out int totalNumber) { totalNumber = 0; var db = AppSettingsHelper.GetSqlSugar(); - return db.Queryable((a, b, c,d) => new JoinQueryInfos(JoinType.Inner, a.FTeamID == b.FID, - JoinType.Inner, c.FType == 33 && a.FType == int.Parse(c.FValue), JoinType.Left, b.FNewTestCode == d.FTestCode)) - // 事项状态 - .WhereIF(tq.FState > 0 && tq.FState != 99, (a, b) => a.FState == tq.FState) + return db.Queryable((a, b) => new JoinQueryInfos(JoinType.Inner, a.FMaterialTeamID == b.FID)) // 事项状态 - .WhereIF(tq.FState == 99, (a, b) => a.FState <= 1) - // 销售号 - .WhereIF(tq.FSaleCode != null, (a, b) => b.FSaleCode.Contains(tq.FSaleCode)) - // 当前流程 - .WhereIF(tq.FType > 0, (a, b) => a.FType == tq.FType) - // 发起时间1 - .WhereIF(tq.FDateRange != null && tq.FDateRange[0] != "", (a, b) => a.FAddDate >= DateTime.Parse(tq.FDateRange[0])) - .WhereIF(tq.FDateRange != null && tq.FDateRange[1] != "", (a, b) => a.FAddDate <= DateTime.Parse(tq.FDateRange[1])) + .WhereIF(mtq.FState > 0 && mtq.FState != 99, (a, b) => a.FState == mtq.FState) + // 物料号 + .WhereIF(!string.IsNullOrEmpty(mtq.FMaterialCode), (a, b) => b.FMaterialCode.Equals(mtq.FMaterialCode)) + // 类型 + .WhereIF(mtq.FTeamworkType > 0, (a, b) => b.FTeamworkType == mtq.FTeamworkType) + // 发起时间 + .WhereIF(mtq.FDateRange != null && mtq.FDateRange[0] != "", (a, b) => a.FAddDate >= DateTime.Parse(mtq.FDateRange[0])) + .WhereIF(mtq.FDateRange != null && mtq.FDateRange[1] != "", (a, b) => a.FAddDate <= DateTime.Parse(mtq.FDateRange[1])) // 责任人 - .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.FNewTestCode,d.FVersionCode,d.FType as 'FormulaType',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); + //.WhereIF(mtq.FUserID != null, (a, b) => (',' + a.FUserID + ',').Contains(',' + mtq.FUserID + ',') || a.FAddUser.Equals(mtq.FUserID)) + //// 协同 + //.WhereIF(mtq.FMaterialTeamID > 0, (a, b) => a.FMaterialTeamID == mtq.FMaterialTeamID).OrderBy((a, b) => a.FID, OrderByType.Desc) + .Select("a.*,b.FMaterialName,b.FMaterialCode,b.FTestCode,b.FMaterialType") + .ToPageList(mtq.FPageIndex, mtq.FPageSize, ref totalNumber); } } } diff --git a/FactorySystemBll/MaterialTeamworkBll.cs b/FactorySystemBll/MaterialTeamworkBll.cs index c1dfe2f..6971d4c 100644 --- a/FactorySystemBll/MaterialTeamworkBll.cs +++ b/FactorySystemBll/MaterialTeamworkBll.cs @@ -1,807 +1,38 @@ using FactorySystemCommon; -using FactorySystemModel.BusinessModel; -using FactorySystemModel.EnumModel; +using FactorySystemModel.RequestModel; +using FactorySystemModel.ResponseModel; using FactorySystemModel.SqlSugarModel; -using Newtonsoft.Json; using SqlSugar; using System; using System.Collections.Generic; -using System.Data; -using System.Globalization; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; namespace FactorySystemBll { - public class MaterialTeamworkBll { - /// - /// 公共列表接口 - /// - //public object GetTeamworkPageList(Dictionary inParam, int userId, out int totalCount) - //{ - // totalCount = 0; - // int pageIndex = 1, pageSize = 15; - // List paramName = new List() { "FDeleted!=1" }; - // List paramVal = new List(); - // if (inParam != null && inParam.Count > 0) - // { - // foreach (var item in inParam) - // { - // if (item.Key == "FPageIndex" || item.Key == "PageIndex") - // { - // int.TryParse(item.Value.ToString(), out pageIndex); - // } - // else if (item.Key == "FPageSize" || item.Key == "PageSize") - // { - // int.TryParse(item.Value.ToString(), out pageSize); - // } - // else if (item.Key == "FAddDate" || item.Key == "AddDate") - // { - // paramName.Add("convert(varchar(10),FAddDate,120)=@FAddDate"); - // paramVal.Add(new SugarParameter("@FAddDate", item.Value.ToString())); - // } - // else if (item.Key == "FDataType" || item.Key == "DataType") - // { - // if (item.Value.ToString() == "1")//我发起的 - // { - // paramName.Add("FAddUser=@FAddUser"); - // paramVal.Add(new SugarParameter("@FAddUser", userId)); - // } - // else if (item.Value.ToString() == "2")//我参与的 - // { - // paramName.Add(string.Format(@"FID in(select distinct FTeamID from TFS_FTeamProcess where ','+FChargeID+',' like '%,{0},%' - // union select distinct FTeamID from TFS_Task where ',' + FUserID + ',' like '%,{0},%')", userId)); - // } - // } - // else if (item.Key == "FProgress" || item.Key == "FProgress") - // { - // string pVal = item.Value.ToString(); - // if (!string.IsNullOrEmpty(pVal)) - // { - // if (pVal == "100" || pVal == "100%") - // { - // paramName.Add("FProgress='100'"); - // } - // else - // { - // paramName.Add("FProgress!='100'"); - // } - // } - // } - // else - // { - // //检索,全转成字符串 - // paramName.Add("','+cast(" + item.Key + " as varchar)+',' like '%'+@" + item.Key + "+'%'"); - // paramVal.Add(new SugarParameter("@" + item.Key, item.Value.ToString())); - // } - // } - // } - // string searchKey = "a.FID,a.FSaleCode,a.FTestCode,a.FViewType,a.FMdmCode,a.FFormulaID,a.FWeightUnit,a.FBomState,a.FProgress," + - // "a.FDeleted,a.FAddUser,a.FAddDate,a.FEditDate,b.FName FAddUserName,a.FFormulaName,a.FFormulaTestCode,a.FMaterialHalfIDs"; - // SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - // var temp = db.Queryable((a, b) => new JoinQueryInfos(JoinType.Left, a.FAddUser == b.FID)).Select(searchKey); - // List resultList = db.Queryable(temp).Where(string.Join(" and ", paramName), paramVal) - // .OrderBy("FID desc").ToPageList(pageIndex, pageSize, ref totalCount); - // if (resultList.Count() > 0) - // { - // List teamIds = resultList.Select(s => s.FID).ToList(); - // List taskList = db.Queryable().Where(s => teamIds.Contains(s.FTeamID) && s.FState == 1) - // .Select("FTeamID,FType,FName").GroupBy("FTeamID,FType,FName").OrderBy("FType").ToList(); - // if (taskList.Count() > 0) - // { - // foreach (TFS_FTeamwork item in resultList) - // { - // item.FTaskList = taskList.Where(s => s.FTeamID == item.FID).ToList(); - // } - // } - // } - // return resultList; - //} - - - public object GetTeamworkPageList(Dictionary inParam, int userId, out int totalCount) - { - totalCount = 0; - int pageIndex = 1, pageSize = 15; - - List paramName = new List() { "FDeleted!=1" }; - List paramVal = new List(); - //if (inParam != null && inParam.Count > 0) - //{ - // foreach (var item in inParam) - // { - // if (item.Key == "FPageIndex" || item.Key == "PageIndex") - // { - // int.TryParse(item.Value.ToString(), out pageIndex); - // } - // else if (item.Key == "FPageSize" || item.Key == "PageSize") - // { - // int.TryParse(item.Value.ToString(), out pageSize); - // } - // else if (item.Key == "FAddDate" || item.Key == "AddDate") - // { - // paramName.Add("convert(varchar(10),FAddDate,120)=@FAddDate"); - // paramVal.Add(new SugarParameter("@FAddDate", item.Value.ToString())); - // } - // else if (item.Key == "FDataType" || item.Key == "DataType") - // { - // if (item.Value.ToString() == "1")//我发起的 - // { - // paramName.Add("FAddUser=@FAddUser"); - // paramVal.Add(new SugarParameter("@FAddUser", userId)); - // } - // else if (item.Value.ToString() == "2")//我参与的 - // { - // paramName.Add(string.Format(@"FID in(select distinct FTeamID from TFS_FTeamProcess where ','+FChargeID+',' like '%,{0},%' - // union select distinct FTeamID from TFS_Task where ',' + FUserID + ',' like '%,{0},%')", userId)); - // } - // } - // else if (item.Key == "FProgress" || item.Key == "FProgress") - // { - // string pVal = item.Value.ToString(); - // if (!string.IsNullOrEmpty(pVal)) - // { - // if (pVal == "100" || pVal == "100%") - // { - // paramName.Add("FProgress='100'"); - // } - // else - // { - // paramName.Add("FProgress!='100'"); - // } - // } - // } - // else - // { - // //检索,全转成字符串 - // paramName.Add("','+cast(" + item.Key + " as varchar)+',' like '%'+@" + item.Key + "+'%'"); - // paramVal.Add(new SugarParameter("@" + item.Key, item.Value.ToString())); - // } - // } - //} - - SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - string searchKey = string.Format(@"a.FID AS 'FID',a.FTestCode AS 'FTestCode',b.FVersionCode AS 'FVersionCode',a.FNewTestCode AS 'NewFTestCode',c.FVersionCode AS 'NewFVersionCode',c.FType,a.FAddDate,d.FName,a.FDeleted AS 'FDeleted'"); - var temp =db.Queryable((a, b, c, d) => new JoinQueryInfos(JoinType.Left, a.FTestCode == b.FTestCode, JoinType.Left, a.FNewTestCode == c.FTestCode, JoinType.Left, a.FAddUser == d.FID)).Select(searchKey); - - List result = db.Queryable(temp).Where(string.Join(" and ", paramName), paramVal) - .OrderBy("FID desc").ToPageList(pageIndex, pageSize, ref totalCount).ToList(); - return result; - } - - /// - /// 创建流程(仅仅创建,进度各个事项判断) - /// - public int CreateProcessData(int teamId, int userId) - { - SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - try - { - List typeList = db.Queryable().Where(s => s.FType == (int)Constant.BasicCode.流程类型 && s.FState == 1).ToList(); - List taskList = new List(); - foreach (var item in typeList) - { - TFS_MaterialFTeamProcess process = new TFS_MaterialFTeamProcess() - { - FState = 0,//默认未开始 - FProgress = 1,//默认F1文字 - FDesc = item.F1, - FTeamID = teamId, - FName = item.FName, - FEditUser = userId, - FAddDate = DateTime.Now, - FEditDate = DateTime.Now, - FType = int.Parse(item.FValue), - FGroup = int.Parse(item.FCode), - FChargeID = "", - FChargeName = "" - }; - List users = null; - int proType = int.Parse(item.FValue); - switch (proType) - { - case (int)Constant.ProcessType.物料分类: - case (int)Constant.ProcessType.替代品确认: - case (int)Constant.ProcessType.协同发起: - string funcIds1 = "1,2,3";//36 - users = db.Queryable().Where(string.Format(@"FState=1 and FRoleID in(select distinct FRoleID from - TRole_Right where FType={1} and FFunctionID in({0}))", funcIds1, (int)Constant.RoleType.事项权限)).ToList(); - break; - case (int)Constant.ProcessType.成品视图: - string funcIds2 = "1";//30 - users = db.Queryable().Where(string.Format(@"FState=1 and FRoleID in(select distinct FRoleID from - TRole_Right where FType={1} and FFunctionID in(select FValue from TBasicCode where FType={0} and F1={2}))", - (int)Constant.BasicCode.物料视图编辑, (int)Constant.RoleType.物料视图编辑, funcIds2)).ToList(); - break; - case (int)Constant.ProcessType.新半成品中间品香基: - string funcIds3 = "2,3,4";//30 - users = db.Queryable().Where(string.Format(@"FState=1 and FRoleID in(select distinct FRoleID from - TRole_Right where FType={1} and FFunctionID in(select FValue from TBasicCode where FType={0} and F1 in({2})))", - (int)Constant.BasicCode.物料视图编辑, (int)Constant.RoleType.物料视图编辑, funcIds3)).ToList(); - break; - case (int)Constant.ProcessType.新原料视图: - string funcIds4 = "5";//30 - users = db.Queryable().Where(string.Format(@"FState=1 and FRoleID in(select distinct FRoleID from - TRole_Right where FType={1} and FFunctionID in(select FValue from TBasicCode where FType={0} and F1={2}))", - (int)Constant.BasicCode.物料视图编辑, (int)Constant.RoleType.物料视图编辑, funcIds4)).ToList(); - break; - case (int)Constant.ProcessType.配方视图: - string funcIds5 = "2,7";//39 - users = db.Queryable().Where(string.Format(@"FState=1 and FRoleID in(select distinct FRoleID from - TRole_Right where FType={1} and FFunctionID in({0}))", funcIds5, (int)Constant.RoleType.视图权限)).ToList(); - break; - case (int)Constant.ProcessType.生产工艺路线: - string funcIds6 = "3,8";//39 - users = db.Queryable().Where(string.Format(@"FState=1 and FRoleID in(select distinct FRoleID from - TRole_Right where FType={1} and FFunctionID in({0}))", funcIds6, (int)Constant.RoleType.视图权限)).ToList(); - break; - case (int)Constant.ProcessType.生成版本: - string funcIds7 = "4,9";//39 - users = db.Queryable().Where(string.Format(@"FState=1 and FRoleID in(select distinct FRoleID from - TRole_Right where FType={1} and FFunctionID in({0}))", funcIds7, (int)Constant.RoleType.视图权限)).ToList(); - break; - case (int)Constant.ProcessType.组装BOM包含新包材: - string funcIds8 = "5,6";//36 - users = db.Queryable().Where(string.Format(@"FState=1 and (FRoleID in(select distinct FRoleID from - TRole_Right where FType={1} and FFunctionID in(select FValue from TBasicCode where FType={0} and F1={2})) - or FRoleID in(select distinct FRoleID from TRole_Right where FType={3} and FFunctionID in({4})) )", - (int)Constant.BasicCode.物料视图编辑, (int)Constant.RoleType.物料视图编辑, (int)Constant.ViewType.包材视图, - (int)Constant.RoleType.事项权限, funcIds8)).ToList(); - break; - case (int)Constant.ProcessType.流程完成: - string funcIds9 = "7";//36 - users = db.Queryable().Where(string.Format(@"FState=1 and FRoleID in(select distinct FRoleID from - TRole_Right where FType={1} and FFunctionID in({0}))", funcIds9, (int)Constant.RoleType.事项权限)).ToList(); - break; - } - if (users != null && users.Count > 0) - { - foreach (var user in users) - { - process.FChargeID += user.FID + ","; - process.FChargeName += user.FName + "、"; - } - process.FChargeID = process.FChargeID.Trim(','); - process.FChargeName = process.FChargeName.Trim('、'); - } - else - { - process.FChargeName = "暂无"; - process.FChargeID = "-1"; - } - taskList.Add(process); - } - if (taskList.Count() > 0) return db.Insertable(taskList).ExecuteCommand(); - } - catch (Exception) - { - //创建失败,删除 - db.Deleteable().Where(s => s.FTeamID == teamId).ExecuteCommand(); - } - return 0; - } - - /// - /// 旧配方处理流程进度 - /// - public void HasMaterialTestCode(TFS_MaterialFTeamwork teamInfo) - { - string proSql = BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.新半成品中间品香基, "F5", 2); - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.新原料视图, "F5", 2); - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.配方视图, "F3", 2); - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.生产工艺路线, "F3", 2); - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.生成版本, "F4", 2); - AppSettingsHelper.GetSqlSugar().Ado.ExecuteCommand(proSql.Trim(';')); - ChangeTeamProcess(teamInfo.FID); - } - - /// - /// 获取协同视图字段信息 - /// - public List GetTeamworkViewField(int intType) - { - return AppSettingsHelper.GetSqlSugar().Queryable().Where(s => s.FType == intType - && s.FDeleted != (int)Constant.DeleteCode.已删除).OrderBy(s => s.FOrder).ToList(); - } - - - - - - - - - /// - /// 获取协同视图结果信息 - /// - public DataTable GetTeamworkViewData(string selectSql, string whereSql, string joinSql = "") - { - SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - string strSql = string.Format(@"select distinct {0},TFS_ViewMaterial.FMaterialID from TFS_FTeamwork left join TFS_ViewMaterial on - TFS_FTeamwork.FID=TFS_ViewMaterial.FTeamID left join TFS_Material on TFS_Material.FID=TFS_ViewMaterial.FMaterialID - {2} where {1}", selectSql, whereSql, string.IsNullOrEmpty(joinSql) ? "" : joinSql); - return db.Ado.GetDataTable(strSql); - } - - /// - /// 获取协同视图结果信息 - /// - public DataTable GetTeamworkViewData2(string selectSql, string whereSql, string joinSql = "") - { - SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - string strSql = string.Format(@"select distinct {0},TFS_ViewMaterial.FMaterialID from TFS_ViewMaterial - left join TFS_Material on TFS_Material.FID=TFS_ViewMaterial.FMaterialID - left join TFS_MaterialInfo on TFS_ViewMaterial.FMaterialID=TFS_MaterialInfo.FDataID and TFS_MaterialInfo.FType=2 - left join TFS_PackageChild on TFS_PackageChild.FMaterialID =TFS_ViewMaterial.FMaterialID - {2} where {1}", selectSql, whereSql, string.IsNullOrEmpty(joinSql) ? "" : joinSql); - return db.Ado.GetDataTable(strSql); - } - - public int ExecSql(string sql) - { - SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - return db.Ado.ExecuteCommand(sql); - } - - /// - /// BOM梳理结果数据处理 - /// - public bool AnalysisBomData(List mateList, List viewList, int teamId, int userId, string formulaIds, string halfIds) - { - SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - db.BeginTran(); - try - { - viewList = viewList.OrderBy(s => s.FLevel).ToList(); - List formulaList = new List(); - TFS_MaterialFTeamwork teamInfo = db.Queryable().Where(s => s.FID == teamId).First(); - TFS_Factory factory = null; - string proSql = ""; - Dictionary hasNewView = new Dictionary(); - for (int i = 0; i < viewList.Count; i++) - { - TFS_ViewMaterial vItem = viewList[i]; - TFS_Material mItem = mateList.Find(s => s.FID == vItem.FBomMaterialID); - - int oldId = mItem.FID, oldParent = mItem.FParentID; - Expression> expression; - if (string.IsNullOrEmpty(mItem.FCode)) expression = s => s.FPlmCode == mItem.FPlmCode && s.FVersionCode == mItem.FVersionCode; - else expression = s => s.FCode == mItem.FCode && s.FVersionCode == mItem.FVersionCode; - - TFS_Material mData = db.Queryable().Where(expression).First(); - if (mData == null)//没物料新增物料 - { - if (factory == null) - { - string tempSql = @"select * from TFS_Factory where FID=(SELECT FCreateFactoryID FROM TFS_MaterialFTeamwork WHERE FID={0})"; - factory = db.SqlQueryable(string.Format(tempSql, teamId)).First(); - } - if (factory != null) - { - mItem.FFactoryID = factory.FID; - mItem.FFactoryCode = factory.FCode; - } - mItem.FID = db.Insertable(mItem).IgnoreColumns(true).ExecuteReturnIdentity(); - //if (vItem.FLevel > 1) formulaIds += "," + mItem.FID; - } - else - { - string name = string.IsNullOrEmpty(mData.FName) ? mItem.FName : mData.FName; - viewList[i].FBaseMaterialDesc = name; - mItem = mData; - } - //formulaIds = formulaIds.Replace(oldId.ToString(), mItem.FID.ToString()); - halfIds = halfIds.Replace(oldId.ToString(), mItem.FID.ToString()); - bool hasCreate = false; - bool isAddFormula = false; - //是否有委外视图 - TFS_ViewMaterial vData = db.Queryable().Where(s => s.FFactoryID == teamInfo.FCreateFactoryID - && s.FMaterialID == mItem.FID).First(); - if (vData == null) - { - hasCreate = isAddFormula = true; - vItem.FFactoryID = teamInfo.FCreateFactoryID; - vItem.FFactoryCode = teamInfo.FCreateFactoryCode; - vItem.FTeamID = teamInfo.FID; - vItem.FMaterialID = mItem.FID; - vItem.FBaseMaterialGroup = mItem.FMaterialGroup; - vItem.FBaseBasicMeter = mItem.FBaseUnit; - db.Insertable(vItem).IgnoreColumns(true).ExecuteCommand(); - if (!hasNewView.ContainsKey(vItem.FViewType)) hasNewView.Add(vItem.FViewType, vItem.FFactoryID.ToString() + ","); - else hasNewView[vItem.FViewType] = hasNewView[vItem.FViewType] + vItem.FFactoryID.ToString() + ","; - } - //是否有工厂视图 - vData = db.Queryable().Where(s => s.FFactoryID == teamInfo.FProdFactoryID && s.FMaterialID == mItem.FID).First(); - if (vData == null) - { - isAddFormula = true; - vItem.FFactoryID = teamInfo.FProdFactoryID; - vItem.FFactoryCode = teamInfo.FProdFactoryCode; - vItem.FTeamID = teamInfo.FID; - vItem.FMaterialID = mItem.FID; - vItem.FBaseMaterialGroup = mItem.FMaterialGroup; - vItem.FBaseBasicMeter = mItem.FBaseUnit; - //所谓固定字段,但是分工厂且视图还不一样 - if (vItem.FViewType == (int)Constant.ViewType.半成品视图 || vItem.FViewType == (int)Constant.ViewType.中间品视图 - || vItem.FViewType == (int)Constant.ViewType.香基视图) - { - vItem.FQualityType3 = "04"; - vItem.FQualityType5 = "09"; - } - else if (vItem.FViewType == (int)Constant.ViewType.原料视图) - { - if (hasCreate) vItem.FQualityType4 = "05"; - } - else if (vItem.FViewType == (int)Constant.ViewType.包材视图) - { - if (hasCreate) vItem.FQualityType4 = "05"; - else vItem.FQualityType1 = "01"; - } - db.Insertable(vItem).IgnoreColumns(true).ExecuteCommand(); - if (!hasNewView.ContainsKey(vItem.FViewType)) hasNewView.Add(vItem.FViewType, vItem.FFactoryID.ToString() + ","); - else hasNewView[vItem.FViewType] = hasNewView[vItem.FViewType] + vItem.FFactoryID.ToString() + ","; - } - mItem.FIsNew = isAddFormula; - mItem.FOldID = oldId; - mItem.FLevelID = vItem.FLevel; - mItem.FParentID = oldParent; - if (mItem.FLevelID >= 1) formulaList.Add(mItem); - } - - formulaIds = ""; - //2022-09-27:生成BOM层级关系,生成配方视图的时候再根据这个处理父子 - List bfList = new List(); - if (formulaList.Count > 0) - { - foreach (TFS_Material first in formulaList.Where(s => s.FLevelID == 1)) - { - bfList.Add(new BomFormulaDto() { mId = first.FID, isNew = first.FIsNew, childs = GetBomFormulaChild(first, formulaList, out string fids) }); - 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_MaterialFTeamwork set {1} where FID={0};", teamInfo.FID, updateSql.Trim(',')); - proSql += BaseBll.GetTaskSql2(-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_MaterialFTeamwork 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.CreateTaskData2(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.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.新原料视图, "F2", 1); - } - else - { - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.新原料视图, "F4", 2); - } - if (hasOther) - { - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.新半成品中间品香基, "F2", 1); - } - else - { - proSql += BaseBll.GetProcessSql2(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_MaterialFTeamwork set FViewType=FViewType+',3,4' where FID={0};", teamInfo.FID); - BaseBll.CreateTaskData2(teamInfo.FID, userId, "8"); - } - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.配方视图, "F2", 1); - } - else - { - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.配方视图, "F2", 2); - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.新半成品中间品香基, "F4", 2); - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.新原料视图, "F4", 2); - } - //下面两个要根据包材判断,先改成进行中,hasNewView == 0 && 包材是旧的,完成 - int pVersion = (hasNewView.Count == 0 && teamInfo.FPackID < 1) ? 2 : 1; - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.生产工艺路线, "F2", pVersion); - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.生成版本, "F2", pVersion); - } - catch (Exception ex) - { - db.RollbackTran(); - return false; - } - - return true; - - } - - private List GetBomFormulaChild(TFS_Material first, List formulaList, out string fids) - { - List dtoList = new List(); - List temps = formulaList.Where(s => s.FParentID == first.FOldID).ToList(); - fids = ""; - if (temps != null && temps.Count > 0) - { - foreach (TFS_Material item in temps) - { - if (first.FIsNew || item.FIsNew) fids += item.FID + ",";//父级新则子一级全部都要、自己是新 - dtoList.Add(new BomFormulaDto() { mId = item.FID, isNew = item.FIsNew, childs = GetBomFormulaChild(item, formulaList, out string nextIds) }); - if (!string.IsNullOrEmpty(nextIds)) fids += nextIds + ","; - } - } - return dtoList; - } - - /// - /// 创建成品视图和包材判断 - /// - public bool CreateProductView(TFS_MaterialFTeamwork teamInfo, List materialList, int userId) - { - SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - db.BeginTran(); - try - { - TFS_PackageMain package = null; - string proSql = ""; - //包材信息判断 - { - //string packCode = teamInfo.FPackCode; - //List names = teamInfo.FSaleCode.Split('-').ToList(); - //string name = names.Where(s => s.Contains("@")).FirstOrDefault(); - //if (string.IsNullOrEmpty(name)) - //{ - // name = names.Where(s => s.Contains("□")).FirstOrDefault(); - // if (!string.IsNullOrEmpty(name)) packCode = name.Substring(0, name.IndexOf("□")); - //} - //else - //{ - // packCode = name.Substring(0, name.IndexOf("@")); - //} - //if (!string.IsNullOrEmpty(packCode)) - //{ - // teamInfo.FPackCode = packCode; - //} - package = db.Queryable().Where(s => s.FCode == teamInfo.FPackCode).OrderBy(s => s.FID, OrderByType.Desc).First(); - if (package == null) - { - db.Updateable(new { FPackCode = teamInfo.FPackCode }).Where(s => s.FID == teamInfo.FID).ExecuteCommand(); - //BaseBll.CreateTaskData(teamInfo.FID, userId, "9");//新增新包材事项 - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.组装BOM包含新包材, "F2", 0);//新包材流程进行中 - } else - { - db.Updateable(new { FPackID = package.FID, FPackCode = teamInfo.FPackCode }).Where(s => s.FID == teamInfo.FID).ExecuteCommand(); - proSql += BaseBll.GetProcessSql2(teamInfo.FID, (int)Constant.ProcessType.组装BOM包含新包材, "F3", 0);//新包材流程完成 - } - if (materialList != null && materialList.Count > 0) - { - TFS_Material material = materialList.Find(s => s.FType == "20");//默认取第一个20的,没找到取第一个 - if (material == null) material = materialList.FirstOrDefault(); - db.Updateable(new { FMaterialHalfIDs = material.FID }).Where(s => s.FID == teamInfo.FID).ExecuteCommand(); - } - } - //物料和成品视图 - { - TFS_Material mainMater = new TFS_Material() - { - FName = teamInfo.FSaleCode, - FDesc = teamInfo.FSaleCode, - FType = "10", - FCode = teamInfo.FMdmCode, - FTestCode = teamInfo.FFormulaTestCode, - FFactoryID = teamInfo.FCreateFactoryID, - FFactoryCode = teamInfo.FCreateFactoryCode, - FEditUser = userId - }; - mainMater.FID = db.Insertable(mainMater).IgnoreColumns(true).ExecuteReturnIdentity(); - TFS_ViewMaterial mainView = new TFS_ViewMaterial() - { - FMaterialID = mainMater.FID, - FTeamID = teamInfo.FID, - FFactoryID = teamInfo.FCreateFactoryID, - FFactoryCode = teamInfo.FCreateFactoryCode, - FViewType = (int)Constant.ViewType.物料分类视图, - FLevel = 1, - FEditUser = userId, - FBaseMaterialCode = teamInfo.FMdmCode, - FBaseTestCode = teamInfo.FTestCode, - FBaseBasicMeter = teamInfo.FWeightUnit, - FBaseMaterialDesc = teamInfo.FSaleCode, - FBaseMaterialGroup = teamInfo.FMaterialGroup, - //默认值不同 - FOrganizeMaterialType = teamInfo.FMaterialType, - FAccountPriceUnit = "1", - FAccountAccessType = "3000", - FAccountSaleOrderInventory = "3010", - FAccountCostAccountBatch = "1", - //2022-10-08 所谓的成品字段值是包材的规格、毛重、净重 - FBaseSpecification = package != null ? package.FSpecs : "", - FBaseGrossWeight = package != null ? package.FGrossWeight : "", - FBaseNetWeight = package != null ? package.FNetWeight : "", - FTeamType=2 - }; - db.Insertable(mainView).IgnoreColumns(true).ExecuteCommand(); - if (teamInfo.FProdFactoryID != teamInfo.FCreateFactoryID) - { - - mainMater.FFactoryID = teamInfo.FProdFactoryID; - mainMater.FFactoryCode = teamInfo.FProdFactoryCode; - mainMater.FID = db.Insertable(mainMater).IgnoreColumns(true).ExecuteReturnIdentity(); - - mainView.FFactoryID = teamInfo.FProdFactoryID; - mainView.FFactoryCode = teamInfo.FProdFactoryCode; - mainView.FMaterialID = mainMater.FID; - db.Insertable(mainView).IgnoreColumns(true).ExecuteCommand(); - } - //成品视图 - //BaseBll.CreateTaskData(teamInfo.FID, userId, "3", teamInfo.FCreateFactoryID + "," + teamInfo.FProdFactoryID); - } - //成品视图物料组复核,有权限的所有 - //BaseBll.CreateTaskData(teamInfo.FID, userId, "12"); - //修改流程状态(协同发起完成,成品视图进行中) - //proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.协同发起, "F2", 1); - //proSql += BaseBll.GetProcessSql(teamInfo.FID, (int)Constant.ProcessType.成品视图, "F2", 1); - proSql += BaseBll.GetTaskSql2(-1, 2, teamInfo.FID, (int)Constant.TaskType.配方选择, 2); - proSql = proSql.Trim(';'); - int result = db.Ado.ExecuteCommand(proSql); - db.CommitTran(); - } - catch (Exception ex) - { - db.RollbackTran(); - return false; - } - return true; - } - - /// - /// 判断物料表里有这个实验号的数量 - /// - public List CheckMaterialListByTest(string testCode, string versionCode) - { - return AppSettingsHelper.GetSqlSugar().Queryable().Where(s => s.FTestCode == testCode && s.FVersionCode == versionCode).ToList(); - } - - /// - /// 根据模式,试验号判断物料表里有这个实验号的数量 - /// - public List CheckMaterialListByTest2(string testCode, int FFactoryID) - { - return AppSettingsHelper.GetSqlSugar().Queryable().Where(s => s.FTestCode == testCode && s.FFactoryID == FFactoryID).ToList(); - } - - /// - /// 更新协同主信息进度 - /// - public static void ChangeTeamProcess(int teamId, SqlSugarClient db = null) - { - if (db == null) db = AppSettingsHelper.GetSqlSugar(); - db.Ado.ExecuteCommand(string.Format(@" - declare @process1 int; - set @process1=(select count(1) from TFS_MaterialFTeamProcess where FTeamID={0} and FState=2)*8; - set @process1+=(select count(1) from TFS_MaterialTask where FTeamID={0} and FState=2)*5; - update TFS_MaterialFTeamwork set FProgress=(case when @process1>99 then '99' else @process1 end) - where FID={0} and FProgress!='100'; - ", teamId)); - } - - /// - /// 更具描述查询是否有重复名称 - /// - /// - /// - public bool CheckTeamName(string name) - { - SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - return db.Queryable().Any(m => m.FSaleCode == name&&m.FDeleted!= (int)Constant.DeleteCode.已删除); - } - - /// - /// 更新配方 - /// - /// 原配方 - /// 新配方 - /// - public List UpdateFormula(string testCode, string testCode2, string idList="") - { - SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); - - List materialList = db.Queryable().Where(m => m.FTestCode == testCode).ToList(); - List ids = materialList.Select(m => m.FID).ToList(); - //更新配方 - string sql = ""; - - - if (string.IsNullOrWhiteSpace(idList)) - { - sql = string.Format("update TFS_Material set FTestCode='{0}' WHERE FID in ({1})", testCode2, string.Join(",", ids)); - } - else - { - sql = string.Format("update TFS_Material set FTestCode='{0}' WHERE FID in ({1})", testCode, idList); - } - - db.Ado.ExecuteCommand(sql); - - return ids; + public class MaterialTeamworkBll + { + /// + /// 获取路线列表 + /// + public List GetList(MaterialTeamworkQuery mtq, out int totalNumber) + { + totalNumber = 0; + var db = AppSettingsHelper.GetSqlSugar(); + return db.Queryable() + // 事项状态 + .WhereIF(mtq.FState > 0 && mtq.FState != 99, a => a.FState == mtq.FState) + // 物料号 + .WhereIF(!string.IsNullOrEmpty(mtq.FMaterialCode), a => a.FMaterialCode.Equals(mtq.FMaterialCode)) + // 类型 + .WhereIF(mtq.FTeamworkType > 0, a => a.FTeamworkType == mtq.FTeamworkType) + // 发起时间 + .WhereIF(mtq.FDateRange != null && mtq.FDateRange[0] != "",a => a.FAddDate >= DateTime.Parse(mtq.FDateRange[0])) + .WhereIF(mtq.FDateRange != null && mtq.FDateRange[1] != "", a => a.FAddDate <= DateTime.Parse(mtq.FDateRange[1])) + // 责任人 + //.WhereIF(mtq.FUserID != null, (a, b) => (',' + a.FUserID + ',').Contains(',' + mtq.FUserID + ',') || a.FAddUser.Equals(mtq.FUserID)) + //// 协同 + //.WhereIF(mtq.FMaterialTeamID > 0, (a, b) => a.FMaterialTeamID == mtq.FMaterialTeamID).OrderBy((a, b) => a.FID, OrderByType.Desc) + .Select() + .ToPageList(mtq.FPageIndex, mtq.FPageSize, ref totalNumber); } } } diff --git a/FactorySystemBll/ViewBll.cs b/FactorySystemBll/ViewBll.cs index cb3b502..0e0d6bc 100644 --- a/FactorySystemBll/ViewBll.cs +++ b/FactorySystemBll/ViewBll.cs @@ -93,6 +93,45 @@ namespace FactorySystemBll return viewList; } + /// + /// 根据协同ID获取物料视图 + /// + public List> GetMaterialViewsByTeamId(int teamId, int viewType, int teamType, 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(); + + 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) + .Where((a, b) => a.FTeamType == teamType) + .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(); + } + else + { + viewList = db.Queryable((a, b) => + new JoinQueryInfos(JoinType.Inner, a.FMaterialID == b.FID)) + .Where((a, b) => a.FTeamID == teamId) + .Where((a, b) => a.FTeamType == teamType) + .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(); + } + materialId = viewList.GroupBy(s => s["FMaterialID"]).Select(s => int.Parse(s.Key.ToString())).ToList(); + return viewList; + } /// /// 根据协同ID获取物料视图 @@ -423,5 +462,11 @@ namespace FactorySystemBll return db.Ado.SqlQuery(sql); } + + public int InsertMaterialView(TFS_ViewMaterial view) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + return db.Insertable(view).IgnoreColumns(true).ExecuteReturnIdentity(); + } } } diff --git a/FactorySystemModel/FactorySystemModel.csproj b/FactorySystemModel/FactorySystemModel.csproj index e6ced9b..f29bc02 100644 --- a/FactorySystemModel/FactorySystemModel.csproj +++ b/FactorySystemModel/FactorySystemModel.csproj @@ -57,13 +57,18 @@ + + + + + @@ -76,6 +81,7 @@ + diff --git a/FactorySystemModel/RequestModel/MaterialTaskQuery.cs b/FactorySystemModel/RequestModel/MaterialTaskQuery.cs new file mode 100644 index 0000000..d6f2d23 --- /dev/null +++ b/FactorySystemModel/RequestModel/MaterialTaskQuery.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using FactorySystemModel.ResponseModel; + +namespace FactorySystemModel.RequestModel +{ + public class MaterialTaskQuery : MaterialTaskRow + { + public MaterialTaskQuery() + { + FIsUser = true; + } + /// + /// Desc:发起时间的时间段 + /// Default: + /// Nullable:True + /// + public List FDateRange { get; set; } + + // 路线类型 + public int FTeamworkType { get; set; } + + public int FPageIndex { get; set; } + + public int FPageSize { get; set; } + /// + /// 是否根据全选出数据 + /// + public bool FIsUser { get; set; } + } +} \ No newline at end of file diff --git a/FactorySystemModel/RequestModel/MaterialTeamworkQuery.cs b/FactorySystemModel/RequestModel/MaterialTeamworkQuery.cs new file mode 100644 index 0000000..4bed91b --- /dev/null +++ b/FactorySystemModel/RequestModel/MaterialTeamworkQuery.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using FactorySystemModel.ResponseModel; + +namespace FactorySystemModel.RequestModel +{ + public class MaterialTeamworkQuery : MaterialTeamworkRow + { + public MaterialTeamworkQuery() + { + FIsUser = true; + } + + // 用户 + public int FUserID { get; set; } + + /// + /// Desc:发起时间的时间段 + /// Default: + /// Nullable:True + /// + public List FDateRange { get; set; } + + public int FPageIndex { get; set; } + + public int FPageSize { get; set; } + /// + /// 是否根据全选出数据 + /// + public bool FIsUser { get; set; } + } +} \ No newline at end of file diff --git a/FactorySystemModel/ResponseModel/MaterialTaskRow.cs b/FactorySystemModel/ResponseModel/MaterialTaskRow.cs new file mode 100644 index 0000000..be5cb07 --- /dev/null +++ b/FactorySystemModel/ResponseModel/MaterialTaskRow.cs @@ -0,0 +1,35 @@ +using FactorySystemModel.SqlSugarModel; + +namespace FactorySystemModel.ResponseModel +{ + public class MaterialTaskRow : TFS_FMaterialTask + { + /// + /// Desc:物料号 + /// Default: + /// Nullable:False + /// + public string FMaterialCode { get; set; } + + /// + /// Desc:物料描述 + /// Default: + /// Nullable:False + /// + public string FMaterialName { get; set; } + + /// + /// Desc:试验号 + /// Default: + /// Nullable:False + /// + public string FTestCode { get; set; } + + /// + /// Desc:物料类型(产品分类):TBasicCode.FType=32 + /// Default: + /// Nullable:False + /// + public string FMaterialType { get; set; } + } +} \ No newline at end of file diff --git a/FactorySystemModel/ResponseModel/MaterialTeamworkRow.cs b/FactorySystemModel/ResponseModel/MaterialTeamworkRow.cs new file mode 100644 index 0000000..b681a3b --- /dev/null +++ b/FactorySystemModel/ResponseModel/MaterialTeamworkRow.cs @@ -0,0 +1,13 @@ +using FactorySystemModel.SqlSugarModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactorySystemModel.ResponseModel +{ + public class MaterialTeamworkRow : TFS_FMaterialTeamwork + { + } +} diff --git a/FactorySystemModel/SqlSugarModel/TFS_FMaterialTask.cs b/FactorySystemModel/SqlSugarModel/TFS_FMaterialTask.cs new file mode 100644 index 0000000..7656045 --- /dev/null +++ b/FactorySystemModel/SqlSugarModel/TFS_FMaterialTask.cs @@ -0,0 +1,120 @@ +using System; +using SqlSugar; + +namespace FactorySystemModel.SqlSugarModel +{ + /// + ///物料新增待办事项 + /// + [SugarTable("TFS_FMaterialTask")] + public partial class TFS_FMaterialTask + { + public TFS_FMaterialTask() { } + + /// + /// Desc:唯一标识 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int FID { get; set; } + + /// + /// Desc:物料路线ID + /// Default:-1 + /// Nullable:False + /// + public int FMaterialTeamID { get; set; } + + /// + /// Desc:类型:TBasicCode.FType=33 + /// Default: + /// Nullable:False + /// + public int FType { get; set; } + + /// + /// Desc:名称 + /// Default: + /// Nullable:False + /// + public string FName { get; set; } + + /// + /// Desc:描述 + /// Default: + /// Nullable:False + /// + public string FDesc { get; set; } + + /// + /// Desc:工厂Id + /// Default: + /// Nullable:False + /// + public int FFactoryID { get; set; } + + /// + /// Desc:负责用户 + /// Default: + /// Nullable:False + /// + public string FUserID { get; set; } + + /// + /// Desc:负责用户 + /// Default: + /// Nullable:False + /// + public string FUserName { get; set; } + + /// + /// Desc:状态:0未开始,1进行中,2已完成 + /// Default:-1 + /// Nullable:False + /// + public int FState { get; set; } + + /// + /// Desc:修改状态:1可修改,0不可修改 + /// Default:-1 + /// Nullable:False + /// + public int? FCanEdit { get; set; } + + /// + /// Desc:完成时间 + /// Default:DateTime.Now + /// Nullable:False + /// + public DateTime? FFinishDate { 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_FMaterialTeamwork.cs b/FactorySystemModel/SqlSugarModel/TFS_FMaterialTeamwork.cs new file mode 100644 index 0000000..dece448 --- /dev/null +++ b/FactorySystemModel/SqlSugarModel/TFS_FMaterialTeamwork.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using SqlSugar; + +namespace FactorySystemModel.SqlSugarModel +{ + /// + ///物料路线表 + /// + [SugarTable("TFS_FMaterialTeamwork")] + public partial class TFS_FMaterialTeamwork + { + public TFS_FMaterialTeamwork() + { + FAddUserName = null; + FTaskList = new List(); + } + + /// + /// Desc:唯一标识 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int FID { get; set; } + + /// + /// Desc:物料描述 + /// Default: + /// Nullable:False + /// + public string FMaterialName { get; set; } + + /// + /// Desc:物料编号 + /// Default: + /// Nullable:False + /// + public string FMaterialCode { get; set; } + + /// + /// Desc:试验号 + /// Default: + /// Nullable:False + /// + public string FTestCode { get; set; } + + /// + /// Desc:物料类型(产品分类):TBasicCode.FType=32 + /// Default: + /// Nullable:False + /// + public string FMaterialType { get; set; } + + /// + /// Desc:路线类型:1新增,2修改 + /// Default:0 + /// Nullable:False + /// + public int FTeamworkType { get; set; } + + /// + /// Desc:状态:1已增,0暂存 + /// Default:-1 + /// Nullable:False + /// + public int FState { get; set; } + + /// + /// Desc:进度 + /// Default:0% + /// Nullable:False + /// + public string FProgress { 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; } + + /// + /// Desc:删除状态:1删除,0未删除 + /// Default:0 + /// Nullable:False + /// + public int FDeleted { get; set; } + + /// + /// 添加人(仅插入的时候不操作此列) + /// + [SugarColumn(IsIgnore = true)] + public string FAddUserName { get; set; } + + /// + /// 当前事项 + /// + [SugarColumn(IsIgnore = true)] + public List FTaskList { get; set; } + + /// + /// Desc:工厂编号 + /// Default:-1 + /// Nullable:False + /// + public int FCreateFactoryID { get; set; } + + /// + /// Desc:工厂代码 + /// Default:-1 + /// Nullable:False + /// + public string FCreateFactoryCode { get; set; } + + /// + /// Desc:工厂模式 + /// Default: + /// Nullable:False + /// + public int FCreateFactoryType { get; set; } + + /// + /// Desc:是否原料:1是,0否 + /// Default:0 + /// Nullable:False + /// + public int FIsRaw { get; set; } + + /// + /// Desc:工厂编号 + /// Default:-1 + /// Nullable:False + /// + public int FProdFactoryID { get; set; } + + /// + /// Desc:工厂代码 + /// Default:-1 + /// Nullable:False + /// + public string FProdFactoryCode { get; set; } + + /// + /// Desc:物料组:TDataCode.FType=2 + /// Default:-1 + /// Nullable:False + /// + public string FMaterialGroup { get; set; } + + /// + /// Desc:计量单位 + /// Default:-1 + /// Nullable:False + /// + public string FWeightUnit { get; set; } + } +}