Browse Source

提交

master
gwbvipvip 8 months ago
parent
commit
17a3d4a1dd
17 changed files with 1077 additions and 0 deletions
  1. +17
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/BaseEPDto.cs
  2. +63
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs
  3. +55
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResultSAASManageDto.cs
  4. +22
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/UserAnalysis.cs
  5. +59
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs
  6. +11
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Authorization/AuthServices.cs
  7. +38
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/CheckServices.cs
  8. +109
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs
  9. +22
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/ICheckServices.cs
  10. +158
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Dtos/MaterialDto.cs
  11. +72
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/MaterialServices.cs
  12. +47
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/IMaterialServices.cs
  13. +238
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs
  14. +17
    -0
      BPA.SAAS.Manage.Core/Base/PageUtil.cs
  15. +15
    -0
      BPA.SAAS.Manage.Core/CurrentUser.cs
  16. +21
    -0
      BPA.SAAS.Manage.Core/DataBase/BPA_PlatformAuthorization.cs
  17. +113
    -0
      BPA.SAAS.Manage.Core/SqlSugarDb.cs

+ 17
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/BaseEPDto.cs View File

@@ -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; }

}

}

+ 63
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs View File

@@ -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
{



/// <summary>
/// Dto参数验证
/// </summary>
public static class DtoValidator
{

/// <summary>
/// 获取签名
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
/// <param name="otype">0-不排序 1-按名称ASCII排序</param>
/// <returns></returns>
public static string GetSign<T>(T t, int otype = 1)
{
string retstr = "";
//定义PropertyInfo的List
List<PropertyInfo> proplist = new List<PropertyInfo>();
//遍历泛型类的每个属性加入到List里面
Array.ForEach<PropertyInfo>(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;
}
}
}

+ 55
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResultSAASManageDto.cs View File

@@ -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<T>
{
public int statusCode { get; set; }

public ResultSAASManageDataDto<T> 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<T>
{
public List<T> 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; }
}

}

+ 22
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/UserAnalysis.cs View File

@@ -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"];
}
}
}

+ 59
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs View File

@@ -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
{
/// <summary>
/// 系统错误码
/// </summary>
[ErrorCodeType]
[Description("系统错误码")]
public enum ErrorCodeEnum
{
/// <summary>
/// 用户没有注册
/// </summary>
[ErrorCodeItemMetadata("用户没有注册")]
Code1000,

/// <summary>
/// 操作错误
/// </summary>
[ErrorCodeItemMetadata("操作错误")]
Code1001,

/// <summary>
/// 重复添加
/// </summary>
[ErrorCodeItemMetadata("重复添加")]
Code1002,

/// <summary>
/// 操作数据不存在
/// </summary>
[ErrorCodeItemMetadata("操作数据不存在")]
Code1003,

/// <summary>
/// key不正确
/// </summary>
[ErrorCodeItemMetadata("key不正确")]
Code1004,

/// <summary>
/// 签名错误
/// </summary>
[ErrorCodeItemMetadata("签名错误")]
Code1005,

/// <summary>
/// 签名错误
/// </summary>
[ErrorCodeItemMetadata("签名过期")]
Code1006,
}
}

+ 11
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Authorization/AuthServices.cs View File

@@ -0,0 +1,11 @@

namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Authorization
{


[ApiDescriptionSettings("开放平台", Tag = "授权管理"), AllowAnonymous, NonUnify]
public class AuthServices : IDynamicApiController
{
}
}

+ 38
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/CheckServices.cs View File

@@ -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;
}

/// <summary>
///检查Sign
/// </summary>
public async Task CheckSign<T>(T dto)
{
await _checkServices.CheckSign(dto);
}


}
}

+ 109
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs View File

@@ -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
{
/// <summary>
///检查Sign
/// </summary>
public async Task CheckSign<T>(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);
}
}



/// <summary>
/// 获取模型值
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
/// <returns></returns>
public string GetModelValue<T>(T t, string name)
{
string retstr = "";
//定义PropertyInfo的List
List<PropertyInfo> proplist = new List<PropertyInfo>();
//遍历泛型类的每个属性加入到List里面
Array.ForEach<PropertyInfo>(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 "";
}

/// <summary>
/// 检查平key验证
/// </summary>
/// <param name="key"></param>
public async Task CheckKey(string key)
{
var data = await SqlSugarDb.Db.Queryable<BPA_PlatformAuthorization>()
.FirstAsync(x => x.Key == key);
if (data == null)
{
throw Oops.Oh(ErrorCodeEnum.Code1004);
}

}

/// <summary>
/// 检查租户
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task CheckTenant(string tenantId)
{
var data = await SqlSugarDb.Db.Queryable<BPA_Company>().FirstAsync(x => x.Id == tenantId);

if (data == null)
{
throw Oops.Oh(ErrorCodeEnum.Code1000);
}

}
}
}

+ 22
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/ICheckServices.cs View File

@@ -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
{
/// <summary>
///检查Sign
/// </summary>
Task CheckSign<T>(T dto);
}
}

+ 158
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Dtos/MaterialDto.cs View File

@@ -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
{
/// <summary>
/// 当前页码
/// </summary>
private int current;
public virtual int Current
{
get
{
return current;
}
set
{

current = value;
if (current <= 0)
{
current = 1;
}
}
}

/// <summary>
/// 页码容量
/// </summary>
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; }
/// <summary>
/// 原料编码
/// </summary>
public string Code { get; set; }

/// <summary>
/// 原料名称
/// </summary>
public string Name { get; set; }

///// <summary>
///// 原料类型
///// </summary>
//public string TypeId { get; set; }

/// <summary>
/// 原料类型名称
/// </summary>
public string TypeName { get; set; }

///// <summary>
///// 物料单位
///// </summary>
//public string UintId { get; set; }


/// <summary>
/// 物料单位名称
/// </summary>
public string UintName { get; set; }

}

public class DelMaterialDto : BaseEPDto
{
public string MaterialId { get; set; }

}

public class MaterialCreateDto : BaseEPDto
{
/// <summary>
/// 原料编码
/// </summary>
public string Code { get; set; }

/// <summary>
/// 原料名称
/// </summary>
public string Name { get; set; }


/// <summary>
/// 原料类型名称
/// </summary>
public string TypeName { get; set; }



/// <summary>
/// 物料单位名称
/// </summary>
public string UintName { get; set; }

}

public class MaterialUpdateDto : BaseEPDto
{
public string Id { get; set; }

/// <summary>
/// 原料编码
/// </summary>
public string Code { get; set; }

/// <summary>
/// 原料名称
/// </summary>
public string Name { get; set; }


/// <summary>
/// 原料类型名称
/// </summary>
public string TypeName { get; set; }


/// <summary>
/// 物料单位名称
/// </summary>
public string UintName { get; set; }

}

}

+ 72
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/MaterialServices.cs View File

@@ -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;
}

/// <summary>
/// 分页查询物料
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
[HttpPost("/api/ExternalPlatform/Material/GetMaterialPageList")]
public async Task<PageUtil<List<MaterialDto>>> GetMaterialPageList(MaterialPageInputDto inputDto)
{
return await _materialServices.GetMaterialPageList(inputDto);
}


/// <summary>
/// 添加物料
/// </summary>
/// <param name="InputDto"></param>
/// <returns></returns>
[HttpPost("/api/ExternalPlatform/Material/AddMaterial")]
public async Task<bool> AddMaterial(MaterialCreateDto InputDto)
{
return await _materialServices.AddMaterial(InputDto);
}

/// <summary>
/// 删除物料
/// </summary>
/// <param name="MaterialId"></param>
/// <returns></returns>
[HttpPost("/api/ExternalPlatform/Material/DelMaterial")]
public async Task<bool> DelMaterial(DelMaterialDto inputDto)
{
return await _materialServices.DelMaterial(inputDto);
}


/// <summary>
/// 修改物料
/// </summary>
/// <param name="InputDto"></param>
/// <returns></returns>
[HttpPost("/api/ExternalPlatform/Material/UpdateMateria")]
public async Task<bool> UpdateMateria(MaterialUpdateDto InputDto)
{
return await _materialServices.UpdateMateria(InputDto);
}
}
}

+ 47
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/IMaterialServices.cs View File

@@ -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
{
/// <summary>
/// 分页查询物料
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
Task<PageUtil<List<MaterialDto>>> GetMaterialPageList(MaterialPageInputDto inputDto);


/// <summary>
/// 添加物料
/// </summary>
/// <param name="InputDto"></param>
/// <returns></returns>
Task<bool> AddMaterial(MaterialCreateDto inputDto);

/// <summary>
/// 删除物料
/// </summary>
/// <param name="MaterialId"></param>
/// <returns></returns>
Task<bool> DelMaterial(DelMaterialDto inputDto);


/// <summary>
/// 修改物料
/// </summary>
/// <param name="InputDto"></param>
/// <returns></returns>
Task<bool> UpdateMateria(MaterialUpdateDto inputDto);
}
}

+ 238
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs View File

@@ -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;
}

/// <summary>
/// 分页查询物料
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
public async Task<PageUtil<List<MaterialDto>>> GetMaterialPageList(MaterialPageInputDto inputDto)
{
//验签
await _checkServices.CheckSign(inputDto);

int total = new RefAsync<int>();
var data = SqlSugarDb.Db.Queryable<BPA_Batching, BPA_BatchingType, BPA_BatchingUint>((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<List<MaterialDto>>()
{
Total = total,
Data = data
};
}


/// <summary>
/// 添加物料
/// </summary>
/// <param name="InputDto"></param>
/// <returns></returns>
public async Task<bool> AddMaterial(MaterialCreateDto inputDto)
{

try
{
//验签
await _checkServices.CheckSign(inputDto);

SqlSugarDb.Db.Ado.BeginTran();
//1.物料单位查询
var typeData = await SqlSugarDb.Db.Queryable<BPA_BatchingType>().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<BPA_BatchingUint>()
.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<BPA_Batching>().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);
}
}

/// <summary>
/// 删除物料
/// </summary>
/// <param name="MaterialId"></param>
/// <returns></returns>
public async Task<bool> DelMaterial(DelMaterialDto inputDto)
{
//验签
await _checkServices.CheckSign(inputDto);

var materialData = await SqlSugarDb.Db.Queryable<BPA_Batching>().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;
}

/// <summary>
/// 修改物料
/// </summary>
/// <param name="InputDto"></param>
/// <returns></returns>
public async Task<bool> UpdateMateria(MaterialUpdateDto inputDto)
{
try
{
//验签
await _checkServices.CheckSign(inputDto);

SqlSugarDb.Db.Ado.BeginTran();
//1.物料单位查询
var typeData = await SqlSugarDb.Db.Queryable<BPA_BatchingType>().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<BPA_BatchingUint>()
.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<BPA_Batching>().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);
}
}
}
}

+ 17
- 0
BPA.SAAS.Manage.Core/Base/PageUtil.cs View File

@@ -22,4 +22,21 @@ namespace BPA.SAAS.Manage.Core.Base

public int Total { get; set; }
}

/// <summary>
/// 分页实体
/// </summary>
public class PageUtil<T>
{
/// <summary>
/// Data
/// </summary>

public T Data { get; set; }
/// <summary>
/// Total
/// </summary>

public int Total { get; set; }
}
}

+ 15
- 0
BPA.SAAS.Manage.Core/CurrentUser.cs View File

@@ -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; }
}
}

+ 21
- 0
BPA.SAAS.Manage.Core/DataBase/BPA_PlatformAuthorization.cs View File

@@ -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
{
/// <summary>
/// 平台授权
/// </summary>
[SugarTable("bpa_platformauthorization")]
public class BPA_PlatformAuthorization : IBaseEntity, IGroupId
{
public string Key { get; set; }

public string GroupId { get; set; }
}
}

+ 113
- 0
BPA.SAAS.Manage.Core/SqlSugarDb.cs View File

@@ -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 全局过滤器及配置
/// <summary>
/// 全局过滤
/// </summary>
private static void TableFilterItem(SqlSugarClient db)
{

//添加默认值
DataExecuting(db);
}

/// <summary>
/// 附默认值
/// </summary>
/// <param name="db"></param>
private static void DataExecuting(SqlSugarClient db)
{
//全局字段赋值
db.Aop.DataExecuting = (oldValue, entityInfo) =>
{
InsertByObject(entityInfo);
UpdateByObject(oldValue, entityInfo);
};

}
/// <summary>
///插入数据时附默认值
/// </summary>
/// <param name="entityInfo"></param>
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;
}
}

/// <summary>
/// 修改数据时附默认值
/// </summary>
/// <param name="oldValue"></param>
/// <param name="entityInfo"></param>
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
}
}

Loading…
Cancel
Save