From fe684f4b29466d897581124cf4f08230db667980 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 29 Aug 2023 22:35:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E6=96=B9=E6=B8=85?= =?UTF-8?q?=E5=8D=95=E7=94=B3=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/FormulaController.cs | 130 ++++++++++++++++++ FactorySystemBll/FormulaBll.cs | 93 +++++++++++++ FactorySystemModel/FactorySystemModel.csproj | 3 + .../RequestModel/SearchFormulaQuery.cs | 11 ++ .../ResponseModel/ApplyFormulaRow.cs | 21 +++ .../SqlSugarModel/TFS_FormualApplyHistory.cs | 62 +++++++++ 6 files changed, 320 insertions(+) create mode 100644 FactorySystemModel/RequestModel/SearchFormulaQuery.cs create mode 100644 FactorySystemModel/ResponseModel/ApplyFormulaRow.cs create mode 100644 FactorySystemModel/SqlSugarModel/TFS_FormualApplyHistory.cs diff --git a/FactorySystemApi/Controllers/FormulaController.cs b/FactorySystemApi/Controllers/FormulaController.cs index e7d1187..2e2e345 100644 --- a/FactorySystemApi/Controllers/FormulaController.cs +++ b/FactorySystemApi/Controllers/FormulaController.cs @@ -11,6 +11,7 @@ using System.Reflection; using System.Web.Http; using FactorySystemModel.EnumModel; using FactorySystemModel.RequestModel; +using FactorySystemApi.Plm_Formula; namespace FactorySystemApi.Controllers { @@ -248,6 +249,135 @@ namespace FactorySystemApi.Controllers }, apiResult, Request, null); } + /// + /// 获取用户是否具备申请查询配方权限 + /// + /// + [HttpPost] + public ApiResult GetApplyBomPower() + { + ApiResult apiResult = new ApiResult(); + return ExceptionHelper.TryReturnException(() => + { + bool hasPower = false; + ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + + List powerList = FormulaBll.GetTaskPower(user.FID); + List applyBomPowers = powerList.FindAll(p => ((IDictionary)p)["FFunctionID"].ToString().Equals("12")).ToList(); + + if (applyBomPowers.Count > 0) + { + hasPower = true; + } + + apiResult.Data = hasPower; + }, apiResult, Request); + } + + /// + /// 获取用户是否具备申请查询配方权限 + /// + /// + /// + [HttpPost] + public ApiResult GetFormulaByTestCode(Dictionary inParam) + { + ApiResult apiResult = new ApiResult(); + + return ExceptionHelper.TryReturnException(() => + { + SearchFormulaQuery searchFormulaQuery = new SearchFormulaQuery(); + string testCode = inParam["FTestCode"] == null ? "" : inParam["FTestCode"].ToString(); + string pageIndex = inParam["FPageIndex"] == null ? "0" : inParam["FPageIndex"].ToString(); + string pageSize = inParam["FPageSize"] == null ? "5" : inParam["FPageSize"].ToString(); + + int nPageIndex = 0; + int nPageSize = 0; + + int.TryParse(pageIndex, out nPageIndex); + int.TryParse(pageSize, out nPageSize); + + searchFormulaQuery.FTestCode = testCode; + searchFormulaQuery.FPageIndex = nPageIndex; + searchFormulaQuery.FPageSize = nPageSize; + + apiResult.Data = new + { + List = FormulaBll.GetListByTestCode(searchFormulaQuery, out var totalNumber), + Total = totalNumber + }; + + }, apiResult, Request); + } + + /// + /// 获取配方清单 + /// + /// + /// + [HttpPost] + public ApiResult GetBomList(Dictionary inParam) + { + ApiResult apiResult = new ApiResult(); + ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo; + + return ExceptionHelper.TryReturnException(() => + { + string fid = inParam["FID"] == null ? "" : inParam["FID"].ToString(); + int nFid = 0; + + int.TryParse(fid, out nFid); + + List formulas = FormulaBll.GetFormulaListById(nFid); + + if (formulas != null && formulas.Count > 0) + { + TFS_Formula formula = formulas[0]; + OAService oAService = new OAService(); + + List specifList = new List() { new Specifications() }; + + specifList[0].SP = formula.FPlmCode; + specifList[0].SP_Version = formula.FVersionCode; + + InputSpecifications oaParam = new InputSpecifications(); + oaParam.USERNAME = AppSettingsHelper.GetAppSettingVal("Plm_Formula_Username"); + oaParam.PASSWORD = AppSettingsHelper.GetAppSettingVal("Plm_Formula_Password"); + + oaParam.Specifications = specifList.ToArray(); + + RestResult restResult = oAService.GetSpecificationsList(oaParam); + + apiResult.Data = restResult.data; + + if (restResult.data != null) + { + FormulaBll.AddFormulaApplyHistroy(formula, user.FName, user.FID); + } + + } + }, apiResult, Request); + } + + /// + /// 根据物料号列表获取物料列表 + /// + /// + /// + [HttpPost] + public ApiResult GetMaterialList(Dictionary inParam) + { + ApiResult apiResult = new ApiResult(); + + return ExceptionHelper.TryReturnException(() => + { + string materialCodes = inParam["materialCodes"] == null ? "" : inParam["materialCodes"].ToString(); + + List materialList = FormulaBll.GetMaterialList(materialCodes); + apiResult.Data = materialList; + }, apiResult, Request); + } + #region 内部方法 /// diff --git a/FactorySystemBll/FormulaBll.cs b/FactorySystemBll/FormulaBll.cs index 40762f9..3780699 100644 --- a/FactorySystemBll/FormulaBll.cs +++ b/FactorySystemBll/FormulaBll.cs @@ -29,6 +29,12 @@ namespace FactorySystemBll return AppSettingsHelper.GetSqlSugar().Queryable().Where(s => s.FDeleted != isDelete).Distinct().ToList(); } + public List GetFormulaListById(int id) + { + int isDelete = (int)Constant.DeleteCode.已删除; + return AppSettingsHelper.GetSqlSugar().Queryable().Where(s => s.FID == id && s.FDeleted != isDelete).Distinct().ToList(); + } + public object GetFormulaByFTestCode(string code) { int isDelete = (int)Constant.DeleteCode.已删除; @@ -278,5 +284,92 @@ namespace FactorySystemBll } return okCount; } + + // 获取用户事项权限 + public List GetTaskPower(int userId) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + + List powers = db.Queryable((a, b) => new JoinQueryInfos( + JoinType.Full, b.FRole.Equals(a.FRoleID.ToString()) + )) + .Where((a, b) => b.FUserID.Equals(userId.ToString())) + .Where((a, b) => a.FType == 2) + .Select("a.FRoleID, a.FType, a.FFunctionID, b.FFactoryID").Distinct() + .ToList(); + + return powers; + } + + // 根据试验号获取配方信息+查询记录 + public List GetListByTestCode(SearchFormulaQuery sfq, out int totalNumber) + { + totalNumber = 0; + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + List formulas; + + if (string.IsNullOrEmpty(sfq.FTestCode)) + { + formulas = null; + totalNumber = 0; + } + else + { + formulas = db.Queryable((a, b) => new JoinQueryInfos( + JoinType.Left, a.FID == b.FFormulaID + )) + .Where((a, b) => a.FTestCode.Equals(sfq.FTestCode)) + .OrderBy((a, b) => a.FID) + .Select("a. *, b.FUserName, b.FApplyTime") + .ToPageList(sfq.FPageIndex, sfq.FPageSize, ref totalNumber); + } + + return formulas; + } + + // 根据物料编号列表获取物料信息列表 + public List GetMaterialList(string materialCodes) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + List materials; + + if (string.IsNullOrEmpty(materialCodes)) + { + materials = null; + } + else + { + materials = db.Queryable() + .Where((a) => materialCodes.Contains("," + a.FCode + ",")) + .Select("FCode, FSuccedaneumID, FSuccedaneumInfo, FSuccedaneumType, FSuccedaneumCode") + .ToList(); + } + + return materials; + } + + public int AddFormulaApplyHistroy(TFS_Formula formula, string userName, int userId) + { + SqlSugarClient db = AppSettingsHelper.GetSqlSugar(); + int okCount = 0; + + if (formula != null) + { + TFS_FormulaApplyHistory formulaApplyHistory = new TFS_FormulaApplyHistory(); + formulaApplyHistory.FFormulaID = formula.FID; + formulaApplyHistory.FFormulaName = formula.FName; + formulaApplyHistory.FTestCode = formula.FTestCode; + formulaApplyHistory.FVersionCode = formula.FVersionCode; + formulaApplyHistory.FUserID = userId; + formulaApplyHistory.FUserName = userName; + formulaApplyHistory.FApplyTime = DateTime.Now; + formulaApplyHistory.FApplyNumber = 0; + formulaApplyHistory.FRemark = ""; + + okCount += db.Insertable(formulaApplyHistory).IgnoreColumns(true).ExecuteCommand(); + } + + return okCount; + } } } diff --git a/FactorySystemModel/FactorySystemModel.csproj b/FactorySystemModel/FactorySystemModel.csproj index 4ec1b15..a36b92d 100644 --- a/FactorySystemModel/FactorySystemModel.csproj +++ b/FactorySystemModel/FactorySystemModel.csproj @@ -59,9 +59,11 @@ + + @@ -70,6 +72,7 @@ + diff --git a/FactorySystemModel/RequestModel/SearchFormulaQuery.cs b/FactorySystemModel/RequestModel/SearchFormulaQuery.cs new file mode 100644 index 0000000..dd42125 --- /dev/null +++ b/FactorySystemModel/RequestModel/SearchFormulaQuery.cs @@ -0,0 +1,11 @@ +namespace FactorySystemModel.RequestModel +{ + public class SearchFormulaQuery + { + public string FTestCode { get; set; } + + public int FPageIndex { get; set; } + + public int FPageSize { get; set; } + } +} diff --git a/FactorySystemModel/ResponseModel/ApplyFormulaRow.cs b/FactorySystemModel/ResponseModel/ApplyFormulaRow.cs new file mode 100644 index 0000000..769c044 --- /dev/null +++ b/FactorySystemModel/ResponseModel/ApplyFormulaRow.cs @@ -0,0 +1,21 @@ +using System; + +namespace FactorySystemModel.ResponseModel +{ + public class ApplyFormulaRow : FormulaRow + { + /// + /// Desc:最近查询用户 + /// Default: + /// Nullable:False + /// + public string FUserName { get; set; } + + /// + /// Desc:最近查询时间 + /// Default:DateTime.Now + /// Nullable:False + /// + public DateTime? FSearchTime { get; set; } + } +} diff --git a/FactorySystemModel/SqlSugarModel/TFS_FormualApplyHistory.cs b/FactorySystemModel/SqlSugarModel/TFS_FormualApplyHistory.cs new file mode 100644 index 0000000..2ee3944 --- /dev/null +++ b/FactorySystemModel/SqlSugarModel/TFS_FormualApplyHistory.cs @@ -0,0 +1,62 @@ +using System; +using SqlSugar; + +namespace FactorySystemModel.SqlSugarModel +{ + /// + ///基础数据字典 + /// + [SugarTable("TFS_FormulaApplyHistory")] + public partial class TFS_FormulaApplyHistory + { + public TFS_FormulaApplyHistory() + { + + } + /// + /// Desc:唯一标识 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int FID { get; set; } + /// + /// 配方ID + /// + public int FFormulaID { get; set; } + /// + /// 配方名称 + /// + public string FFormulaName { get; set; } + /// + /// 试验号 + /// + public string FTestCode { get; set; } + /// + /// 版本号 + /// + public string FVersionCode { get; set; } + /// + /// 用户ID + /// + public int FUserID { get; set; } + /// + /// 用户名 + /// + public string FUserName { get; set; } + /// + /// 申请时间 + /// + public DateTime FApplyTime { get; set; } + /// + /// 申请数量 + /// + public int FApplyNumber { get; set; } + /// + /// 备注 + /// + public string FRemark { get; set; } + + + } +}