From 17a3d4a1dd345fa832f6813ca510038ea7de4422 Mon Sep 17 00:00:00 2001 From: gwbvipvip Date: Thu, 29 Feb 2024 17:53:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AExternalPlatform/BaseDto/BaseEPDto.cs | 17 ++ .../AExternalPlatform/BaseDto/DtoValidator.cs | 63 +++++ .../BaseDto/ResultSAASManageDto.cs | 55 ++++ .../AExternalPlatform/BaseDto/UserAnalysis.cs | 22 ++ .../AExternalPlatform/Enum/ErrorCodeEnum.cs | 59 +++++ .../Service/Authorization/AuthServices.cs | 11 + .../Service/CheckService/CheckServices.cs | 38 +++ .../CheckService/Services/CheckServices.cs | 109 ++++++++ .../CheckService/Services/ICheckServices.cs | 22 ++ .../Service/Material/Dtos/MaterialDto.cs | 158 ++++++++++++ .../Service/Material/MaterialServices.cs | 72 ++++++ .../Material/Services/IMaterialServices.cs | 47 ++++ .../Material/Services/MaterialService.cs | 238 ++++++++++++++++++ BPA.SAAS.Manage.Core/Base/PageUtil.cs | 17 ++ BPA.SAAS.Manage.Core/CurrentUser.cs | 15 ++ .../DataBase/BPA_PlatformAuthorization.cs | 21 ++ BPA.SAAS.Manage.Core/SqlSugarDb.cs | 113 +++++++++ 17 files changed, 1077 insertions(+) create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/BaseEPDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResultSAASManageDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/UserAnalysis.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Authorization/AuthServices.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/CheckServices.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/ICheckServices.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Dtos/MaterialDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/MaterialServices.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/IMaterialServices.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs create mode 100644 BPA.SAAS.Manage.Core/CurrentUser.cs create mode 100644 BPA.SAAS.Manage.Core/DataBase/BPA_PlatformAuthorization.cs create mode 100644 BPA.SAAS.Manage.Core/SqlSugarDb.cs diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/BaseEPDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/BaseEPDto.cs new file mode 100644 index 0000000..1225b44 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/BaseEPDto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto +{ + public class BaseEPDto + { + public string Sign { get; set; } + + public string Key { get; set; } + + } + +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs new file mode 100644 index 0000000..9f60559 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs @@ -0,0 +1,63 @@ + +using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; +using BPA.SAAS.Manage.Core; +using BPA.SAAS.Manage.Core.DataBase; +using BPA.SAAS.Manage.Core.Org; +using Furion.JsonSerialization; +using Newtonsoft.Json; +using NPOI.Util.ArrayExtensions; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Reflection; +using System.Text; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto +{ + + + + /// + /// Dto参数验证 + /// + public static class DtoValidator + { + + + /// + /// 获取签名 + /// + /// + /// + /// 0-不排序 1-按名称ASCII排序 + /// + public static string GetSign(T t, int otype = 1) + { + string retstr = ""; + //定义PropertyInfo的List + List proplist = new List(); + //遍历泛型类的每个属性加入到List里面 + Array.ForEach(typeof(T).GetProperties(), + p => proplist.Add(p)); + //根据参数进行排序 0-不排序 1-按名称ASCII码排序 + if (otype == 1) + proplist = proplist.OrderBy(k => k.Name).ToList(); + + //遍历List泛型生成我们要签名的字符串 + proplist.ForEach(p => + { + if (p.Name.ToLower() != "sign".ToLower()) + { + if (p.GetValue(t, null) != null && p.GetValue(t, null).ToString() != "") + { + retstr = retstr + p.Name + "=" + p.GetValue(t, null) + "&"; + } + + } + }); + //把字符串最后一位截断 + retstr = retstr.Substring(0, retstr.Length - 1); + //输出字符串 + return retstr; + } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResultSAASManageDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResultSAASManageDto.cs new file mode 100644 index 0000000..45b78a2 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResultSAASManageDto.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto +{ + public class ResultSAASManageDto + { + public int statusCode { get; set; } + + public ResultSAASManageDataDto data { get; set; } + + public string succeeded { get; set; } + + public string errors { get; set; } + + public string extras { get; set; } + + public int timestamp { get; set; } + } + + public class ResultSAASManageDataDto + { + public List data { get; set; } + + public int total { get; set; } + } + public class ResultTenantDataItemDto + { + public string id { get; set; } + + public string name { get; set; } + + public string adminName { get; set; } + + public string email { get; set; } + + public string phone { get; set; } + + public string remark { get; set; } + + public string logo { get; set; } + + public string createAt { get; set; } + + public int status { get; set; } + + public string sysRoleId { get; set; } + + public int type { get; set; } + } + +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/UserAnalysis.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/UserAnalysis.cs new file mode 100644 index 0000000..97e10be --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/UserAnalysis.cs @@ -0,0 +1,22 @@ +using BPA.SAAS.KitChenManage.Core; +using BPA.SAAS.Manage.Core; +using Furion; +using Microsoft.AspNetCore.Http; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto +{ + public class UserAnalysis + { + public UserAnalysis() + { + + CurrentUser.GroupId = App.HttpContext.Request.Headers["TenantId"]; + // CurrentUser.Sign = App.HttpContext.Request.Headers["Sign"]; + } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs new file mode 100644 index 0000000..5b0a505 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Enum +{ + /// + /// 系统错误码 + /// + [ErrorCodeType] + [Description("系统错误码")] + public enum ErrorCodeEnum + { + /// + /// 用户没有注册 + /// + [ErrorCodeItemMetadata("用户没有注册")] + Code1000, + + /// + /// 操作错误 + /// + [ErrorCodeItemMetadata("操作错误")] + Code1001, + + /// + /// 重复添加 + /// + [ErrorCodeItemMetadata("重复添加")] + Code1002, + + /// + /// 操作数据不存在 + /// + [ErrorCodeItemMetadata("操作数据不存在")] + Code1003, + + /// + /// key不正确 + /// + [ErrorCodeItemMetadata("key不正确")] + Code1004, + + /// + /// 签名错误 + /// + [ErrorCodeItemMetadata("签名错误")] + Code1005, + + /// + /// 签名错误 + /// + [ErrorCodeItemMetadata("签名过期")] + Code1006, + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Authorization/AuthServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Authorization/AuthServices.cs new file mode 100644 index 0000000..48c53c5 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Authorization/AuthServices.cs @@ -0,0 +1,11 @@ + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Authorization +{ + + + [ApiDescriptionSettings("开放平台", Tag = "授权管理"), AllowAnonymous, NonUnify] + public class AuthServices : IDynamicApiController + { + + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/CheckServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/CheckServices.cs new file mode 100644 index 0000000..8216799 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/CheckServices.cs @@ -0,0 +1,38 @@ +using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Dtos; +using BPA.SAAS.Manage.Comm.Enum; +using BPA.SAAS.Manage.Core.Base; +using BPA.SAAS.Manage.Core.DataBase; +using BPA.SAAS.Manage.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components.Forms; +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.CheckService.Services; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.CheckService +{ + + [ApiDescriptionSettings("开放平台", Tag = "检查"), AllowAnonymous] + public class CheckServices : IDynamicApiController + { + private readonly ICheckServices _checkServices; + public CheckServices(ICheckServices checkServices) + { + _checkServices = checkServices; + } + + /// + ///检查Sign + /// + public async Task CheckSign(T dto) + { + await _checkServices.CheckSign(dto); + } + + + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs new file mode 100644 index 0000000..b57b6a4 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs @@ -0,0 +1,109 @@ +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; +using BPA.SAAS.Manage.Core.DataBase; +using BPA.SAAS.Manage.Core.Org; +using BPA.SAAS.Manage.Core; +using NPOI.Util.ArrayExtensions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using BPA.SAAS.KitChenManage.Core; +using BPA.KitChen.GroupMeal.SqlSugar; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.CheckService.Services +{ + public class CheckServices : ICheckServices, ITransient + { + /// + ///检查Sign + /// + public async Task CheckSign(T dto) + { + + var key = GetModelValue(dto, "Key"); + var sign = GetModelValue(dto, "Sign"); + var timestamp = GetModelValue(dto, "TimeStamp"); + + + //检查租户 + await CheckTenant(CurrentUser.GroupId); + + //检查key + await CheckKey(key); + + var thisSign = DtoValidator.GetSign(dto)+"&"+ key; + + + if (MD5Encryption.Encrypt(thisSign).ToUpper() != sign.ToUpper()) + { + throw Oops.Oh(ErrorCodeEnum.Code1005); + } + } + + + + /// + /// 获取模型值 + /// + /// + /// + /// + public string GetModelValue(T t, string name) + { + string retstr = ""; + //定义PropertyInfo的List + List proplist = new List(); + //遍历泛型类的每个属性加入到List里面 + Array.ForEach(typeof(T).GetProperties(), + p => proplist.Add(p)); + + foreach (PropertyInfo prop in proplist) + { + if (prop.Name.ToLower() == name.ToLower()) + { + var data = prop.GetValue(t, null); + if (data != null) + { + return data.ToString(); + } + } + } + + return ""; + } + + /// + /// 检查平key验证 + /// + /// + public async Task CheckKey(string key) + { + var data = await SqlSugarDb.Db.Queryable() + .FirstAsync(x => x.Key == key); + if (data == null) + { + throw Oops.Oh(ErrorCodeEnum.Code1004); + } + + } + + /// + /// 检查租户 + /// + /// + /// + public async Task CheckTenant(string tenantId) + { + var data = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Id == tenantId); + + if (data == null) + { + throw Oops.Oh(ErrorCodeEnum.Code1000); + } + + } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/ICheckServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/ICheckServices.cs new file mode 100644 index 0000000..043730c --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/ICheckServices.cs @@ -0,0 +1,22 @@ +using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Dtos; +using BPA.SAAS.Manage.Comm.Enum; +using BPA.SAAS.Manage.Core.Base; +using BPA.SAAS.Manage.Core.DataBase; +using BPA.SAAS.Manage.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.CheckService.Services +{ + public interface ICheckServices + { + /// + ///检查Sign + /// + Task CheckSign(T dto); + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Dtos/MaterialDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Dtos/MaterialDto.cs new file mode 100644 index 0000000..a0ab82b --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Dtos/MaterialDto.cs @@ -0,0 +1,158 @@ +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +using BPA.SAAS.Manage.Comm.Enum; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Dtos +{ + public class MaterialPageInputDto: BaseEPDto + { + /// + /// 当前页码 + /// + private int current; + public virtual int Current + { + get + { + return current; + } + set + { + + current = value; + if (current <= 0) + { + current = 1; + } + } + } + + /// + /// 页码容量 + /// + private int pagesize; + public virtual int PageSize + { + get + { + return pagesize; + } + set + { + + pagesize = value; + if (pagesize <= 0) + { + pagesize = 10; + } + } + } + + public string Name { get; set; } + } + public class MaterialDto + { + public string Id { get; set; } + /// + /// 原料编码 + /// + public string Code { get; set; } + + /// + /// 原料名称 + /// + public string Name { get; set; } + + ///// + ///// 原料类型 + ///// + //public string TypeId { get; set; } + + /// + /// 原料类型名称 + /// + public string TypeName { get; set; } + + ///// + ///// 物料单位 + ///// + //public string UintId { get; set; } + + + /// + /// 物料单位名称 + /// + public string UintName { get; set; } + + } + + public class DelMaterialDto : BaseEPDto + { + public string MaterialId { get; set; } + + } + + public class MaterialCreateDto : BaseEPDto + { + /// + /// 原料编码 + /// + public string Code { get; set; } + + /// + /// 原料名称 + /// + public string Name { get; set; } + + + + /// + /// 原料类型名称 + /// + public string TypeName { get; set; } + + + + + /// + /// 物料单位名称 + /// + public string UintName { get; set; } + + } + + public class MaterialUpdateDto : BaseEPDto + { + public string Id { get; set; } + + /// + /// 原料编码 + /// + public string Code { get; set; } + + /// + /// 原料名称 + /// + public string Name { get; set; } + + + + /// + /// 原料类型名称 + /// + public string TypeName { get; set; } + + + /// + /// 物料单位名称 + /// + public string UintName { get; set; } + + } + + +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/MaterialServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/MaterialServices.cs new file mode 100644 index 0000000..d2e7018 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/MaterialServices.cs @@ -0,0 +1,72 @@ +using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Dtos; +using BPA.SAAS.Manage.Comm.Enum; +using BPA.SAAS.Manage.Core.Base; +using BPA.SAAS.Manage.Core.DataBase; +using BPA.SAAS.Manage.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components.Forms; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Services +{ + + [ApiDescriptionSettings("开放平台", Tag = "物料管理"), AllowAnonymous] + public class Material11Services : IDynamicApiController + { + private readonly IMaterialServices _materialServices; + public Material11Services(IMaterialServices materialServices) + { + _materialServices=materialServices; + } + + /// + /// 分页查询物料 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Material/GetMaterialPageList")] + public async Task>> GetMaterialPageList(MaterialPageInputDto inputDto) + { + return await _materialServices.GetMaterialPageList(inputDto); + } + + + /// + /// 添加物料 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Material/AddMaterial")] + public async Task AddMaterial(MaterialCreateDto InputDto) + { + return await _materialServices.AddMaterial(InputDto); + } + + /// + /// 删除物料 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Material/DelMaterial")] + public async Task DelMaterial(DelMaterialDto inputDto) + { + return await _materialServices.DelMaterial(inputDto); + } + + + /// + /// 修改物料 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Material/UpdateMateria")] + public async Task UpdateMateria(MaterialUpdateDto InputDto) + { + return await _materialServices.UpdateMateria(InputDto); + } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/IMaterialServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/IMaterialServices.cs new file mode 100644 index 0000000..7d937fa --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/IMaterialServices.cs @@ -0,0 +1,47 @@ +using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Dtos; +using BPA.SAAS.Manage.Comm.Enum; +using BPA.SAAS.Manage.Core.Base; +using BPA.SAAS.Manage.Core.DataBase; +using BPA.SAAS.Manage.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Services +{ + public interface IMaterialServices + { + /// + /// 分页查询物料 + /// + /// + /// + Task>> GetMaterialPageList(MaterialPageInputDto inputDto); + + + /// + /// 添加物料 + /// + /// + /// + Task AddMaterial(MaterialCreateDto inputDto); + + /// + /// 删除物料 + /// + /// + /// + Task DelMaterial(DelMaterialDto inputDto); + + + /// + /// 修改物料 + /// + /// + /// + Task UpdateMateria(MaterialUpdateDto inputDto); + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs new file mode 100644 index 0000000..dce264d --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs @@ -0,0 +1,238 @@ +using BPA.KitChen.GroupMeal.SqlSugar; +using BPA.SAAS.KitChenManage.Core; +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.CheckService.Services; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Dtos; +using BPA.SAAS.Manage.Comm.Enum; +using BPA.SAAS.Manage.Core; +using BPA.SAAS.Manage.Core.Base; +using BPA.SAAS.Manage.Core.DataBase; +using Microsoft.AspNetCore.Components.Forms; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Services +{ + public class MaterialService : UserAnalysis, IMaterialServices, ITransient + { + private readonly ICheckServices _checkServices; + public MaterialService(ICheckServices checkServices) + { + _checkServices = checkServices; + } + + /// + /// 分页查询物料 + /// + /// + /// + public async Task>> GetMaterialPageList(MaterialPageInputDto inputDto) + { + //验签 + await _checkServices.CheckSign(inputDto); + + int total = new RefAsync(); + var data = SqlSugarDb.Db.Queryable((a, b, c) => + new JoinQueryInfos(JoinType.Left, a.Batching_Type == b.Id, + JoinType.Left, a.StockUint == c.Id)) + .Where((a, b, c) => a.IsDeleted == 0) + .WhereIF(!string.IsNullOrEmpty(inputDto.Name), (a, b, c) => a.Batching_Name.Contains(inputDto.Name)) + .Select((a, b, c) => new MaterialDto() + { + Id= a.Id, + Code = a.Code, + Name = a.Batching_Name, + //TypeId = b.Id, + TypeName = b.Name, + // UintId = c.Id, + UintName = c.Name, + + }).ToPageList(inputDto.Current, inputDto.PageSize, ref total); + + return new PageUtil>() + { + Total = total, + Data = data + }; + } + + + /// + /// 添加物料 + /// + /// + /// + public async Task AddMaterial(MaterialCreateDto inputDto) + { + + try + { + //验签 + await _checkServices.CheckSign(inputDto); + + SqlSugarDb.Db.Ado.BeginTran(); + //1.物料单位查询 + var typeData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Name == inputDto.TypeName); + if (typeData == null) + { + + typeData = new BPA_BatchingType() + { + GroupId = CurrentUser.GroupId, + Id = Guid.NewGuid().ToString(), + Name = string.IsNullOrEmpty(inputDto.TypeName) ? "默认分类" : inputDto.TypeName, + }; + SqlSugarDb.Db.Insertable(typeData).ExecuteCommand(); + } + + //2.单位查询 + var uintData = await SqlSugarDb.Db.Queryable() + .FirstAsync(x => x.Name == inputDto.UintName); + if (uintData == null) + { + uintData = new BPA_BatchingUint() + { + GroupId = CurrentUser.GroupId, + Id = Guid.NewGuid().ToString(), + Name = string.IsNullOrEmpty(inputDto.UintName) ? "默认分类" : inputDto.UintName, + }; + SqlSugarDb.Db.Insertable(uintData).ExecuteCommand(); + } + //3.物料查询 + var materialData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Batching_Name == inputDto.Name); + if (materialData == null) + { + materialData = new BPA_Batching() + { + Id = Guid.NewGuid().ToString(), + GroupId = CurrentUser.GroupId, + Aittribute = 0, + Batching_Name = inputDto.Name, + Batching_Type = typeData.Id, + Code = inputDto.Code, + Price = 0, + Specs = "", + outstockUint = uintData.Id, + Status = CommonStatus.ENABLE, + StockUint = uintData.Id, + TypeID = typeData.Id, + IsDeleted = 0, + }; + + SqlSugarDb.Db.Insertable(materialData).ExecuteCommand(); + } + else + { + throw Oops.Oh(ErrorCodeEnum.Code1002); + } + + + SqlSugarDb.Db.Ado.CommitTran(); + return true; + } + catch (Exception e) + { + SqlSugarDb.Db.Ado.RollbackTran(); + throw Oops.Oh(ErrorCodeEnum.Code1001); + } + } + + /// + /// 删除物料 + /// + /// + /// + public async Task DelMaterial(DelMaterialDto inputDto) + { + //验签 + await _checkServices.CheckSign(inputDto); + + var materialData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Id == inputDto.MaterialId); + if (materialData == null) + { + throw Oops.Oh(ErrorCodeEnum.Code1003); + } + var res = await SqlSugarDb.Db.Deleteable(materialData).ExecuteCommandAsync(); + return res > 0; + } + + /// + /// 修改物料 + /// + /// + /// + public async Task UpdateMateria(MaterialUpdateDto inputDto) + { + try + { + //验签 + await _checkServices.CheckSign(inputDto); + + SqlSugarDb.Db.Ado.BeginTran(); + //1.物料单位查询 + var typeData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Name == inputDto.TypeName); + if (typeData == null) + { + + typeData = new BPA_BatchingType() + { + GroupId = CurrentUser.GroupId, + Id = Guid.NewGuid().ToString(), + Name = string.IsNullOrEmpty(inputDto.TypeName) ? "默认分类" : inputDto.TypeName, + }; + SqlSugarDb.Db.Insertable(typeData).ExecuteCommand(); + } + + //2.单位查询 + var uintData = await SqlSugarDb.Db.Queryable() + .FirstAsync(x => x.Name == inputDto.UintName); + if (uintData == null) + { + uintData = new BPA_BatchingUint() + { + GroupId = CurrentUser.GroupId, + Id = Guid.NewGuid().ToString(), + Name = string.IsNullOrEmpty(inputDto.UintName) ? "默认分类" : inputDto.UintName, + }; + SqlSugarDb.Db.Insertable(uintData).ExecuteCommand(); + } + //3.物料查询 + var materialData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Batching_Name == inputDto.Name); + if (materialData == null) + { + throw Oops.Oh(ErrorCodeEnum.Code1003); + + + } + else + { + materialData = new BPA_Batching() + { + Id = Guid.NewGuid().ToString(), + GroupId = CurrentUser.GroupId, + Aittribute = 0, + Batching_Name = inputDto.Name, + Batching_Type = typeData.Id, + Code = inputDto.Code, + Price = 0, + Specs = "", + outstockUint = uintData.Id, + Status = CommonStatus.ENABLE, + StockUint = uintData.Id, + TypeID = typeData.Id, + IsDeleted = 0, + }; + SqlSugarDb.Db.Updateable(materialData).ExecuteCommand(); + } + + + SqlSugarDb.Db.Ado.CommitTran(); + return true; + } + catch (Exception e) + { + SqlSugarDb.Db.Ado.RollbackTran(); + throw Oops.Oh(ErrorCodeEnum.Code1001); + } + } + } +} diff --git a/BPA.SAAS.Manage.Core/Base/PageUtil.cs b/BPA.SAAS.Manage.Core/Base/PageUtil.cs index deb171c..d5571f2 100644 --- a/BPA.SAAS.Manage.Core/Base/PageUtil.cs +++ b/BPA.SAAS.Manage.Core/Base/PageUtil.cs @@ -22,4 +22,21 @@ namespace BPA.SAAS.Manage.Core.Base public int Total { get; set; } } + + /// + /// 分页实体 + /// + public class PageUtil + { + /// + /// Data + /// + + public T Data { get; set; } + /// + /// Total + /// + + public int Total { get; set; } + } } diff --git a/BPA.SAAS.Manage.Core/CurrentUser.cs b/BPA.SAAS.Manage.Core/CurrentUser.cs new file mode 100644 index 0000000..0be2e66 --- /dev/null +++ b/BPA.SAAS.Manage.Core/CurrentUser.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.KitChenManage.Core +{ + public static class CurrentUser + { + public static string GroupId { get; set; } + + public static string key { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Core/DataBase/BPA_PlatformAuthorization.cs b/BPA.SAAS.Manage.Core/DataBase/BPA_PlatformAuthorization.cs new file mode 100644 index 0000000..46eb491 --- /dev/null +++ b/BPA.SAAS.Manage.Core/DataBase/BPA_PlatformAuthorization.cs @@ -0,0 +1,21 @@ +using BPA.SAAS.Manage.Core.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Core.DataBase +{ + /// + /// 平台授权 + /// + [SugarTable("bpa_platformauthorization")] + public class BPA_PlatformAuthorization : IBaseEntity, IGroupId + { + public string Key { get; set; } + + public string GroupId { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Core/SqlSugarDb.cs b/BPA.SAAS.Manage.Core/SqlSugarDb.cs new file mode 100644 index 0000000..3049d11 --- /dev/null +++ b/BPA.SAAS.Manage.Core/SqlSugarDb.cs @@ -0,0 +1,113 @@ + +using BPA.SAAS.KitChenManage.Core; +using BPA.SAAS.Manage.Core.Base; +using Furion; +using SqlSugar; +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + +namespace BPA.KitChen.GroupMeal.SqlSugar +{ + public class SqlSugarDb + { + + + + public static SqlSugarScope Db { get; set; } + + public static SqlSugarScope SqlSugarScope(ConnectionConfig configConnection) + { + //全局过滤 + + Db = new SqlSugarScope(configConnection, db => + { + //全局过滤 + TableFilterItem(db); + db.Aop.OnLogExecuting = (sql, pars) => + { + //sql 执行前 + }; + db.Aop.OnLogExecuted = (sql, pars) => + { + //sql 执行后 + }; + db.Aop.OnError = ex => + { + //sql 异常 + }; + }); + + return Db; + } + + #region 全局过滤器及配置 + /// + /// 全局过滤 + /// + private static void TableFilterItem(SqlSugarClient db) + { + + //添加默认值 + DataExecuting(db); + } + + /// + /// 附默认值 + /// + /// + private static void DataExecuting(SqlSugarClient db) + { + //全局字段赋值 + db.Aop.DataExecuting = (oldValue, entityInfo) => + { + InsertByObject(entityInfo); + UpdateByObject(oldValue, entityInfo); + }; + + } + /// + ///插入数据时附默认值 + /// + /// + private static void InsertByObject(DataFilterModel entityInfo) + { + if (entityInfo.OperationType != DataFilterType.InsertByObject) return; + switch (entityInfo.PropertyName) + { + case "CreateAt": + entityInfo.SetValue(DateTime.Now); + break; + case "CreateBy": + entityInfo.SetValue(""); + break; + case "GroupId": + entityInfo.SetValue(CurrentUser.GroupId); + break; + } + } + + /// + /// 修改数据时附默认值 + /// + /// + /// + private static void UpdateByObject(object oldValue, DataFilterModel entityInfo) + { + if (entityInfo.OperationType != DataFilterType.UpdateByObject) return; + + switch (entityInfo.PropertyName) + { + case "UpdateAt": + entityInfo.SetValue(DateTime.Now); + break; + case "UpdateBy": + entityInfo.SetValue(""); + break; + } + + } + #endregion + } +}