授权验证

客户端与大简云端接口
main
wanghaomei 1 year ago
parent 3b9d322e95
commit 733be1e3da

1
.gitignore vendored

@ -7,3 +7,4 @@
/CustomerBaoGuan/CustomerBaoGuan/CustomerBaoGuan.Application/bin
/CustomerBaoGuan/CustomerBaoGuan/CustomerBaoGuan.Application/obj
/CustomerBaoGuan/.vs
/CustomerBaoGuan/CustomerBaoGuan/CustomerBaoGuan.Web.Entry/logs

@ -21,13 +21,46 @@ namespace CustomerBaoGuan.Application
/// <summary>
/// 日志-客户报关文件
/// 日志-客户报关
/// </summary>
public const string BaoGuanLogTypeBaoGuan = "BaoGuan";
/// <summary>
/// 日志-海关文件
/// 日志-海关
/// </summary>
public const string BaoGuanLogTypeCustoms = "Customs";
/// <summary>
/// 状态-客户-已录入
/// </summary>
public const string StatusBaoGuanCreate = "已录入";
/// <summary>
/// 状态-客户-已发送
/// </summary>
public const string StatusBaoGuanSent = "已发送";
/// <summary>
/// 状态-客户-已驳回
/// </summary>
public const string StatusBaoGuanReject = "已驳回";
/// <summary>
/// 状态-大简云-待审核
/// </summary>
public const string StatusDjyAudit = "待审核";
/// <summary>
/// 状态-大简云-已接收
/// </summary>
public const string StatusDjyAccept = "已接收";
/// <summary>
/// 状态-大简云-已驳回
/// </summary>
public const string StatusDjyReject = "已驳回";
}
}

@ -16,12 +16,42 @@
</member>
<member name="F:CustomerBaoGuan.Application.BaoGuanConst.BaoGuanLogTypeBaoGuan">
<summary>
日志-客户报关文件
日志-客户报关
</summary>
</member>
<member name="F:CustomerBaoGuan.Application.BaoGuanConst.BaoGuanLogTypeCustoms">
<summary>
日志-海关文件
日志-海关
</summary>
</member>
<member name="F:CustomerBaoGuan.Application.BaoGuanConst.StatusBaoGuanCreate">
<summary>
状态-客户-已录入
</summary>
</member>
<member name="F:CustomerBaoGuan.Application.BaoGuanConst.StatusBaoGuanSent">
<summary>
状态-客户-已发送
</summary>
</member>
<member name="F:CustomerBaoGuan.Application.BaoGuanConst.StatusBaoGuanReject">
<summary>
状态-客户-已驳回
</summary>
</member>
<member name="F:CustomerBaoGuan.Application.BaoGuanConst.StatusDjyAudit">
<summary>
状态-大简云-待审核
</summary>
</member>
<member name="F:CustomerBaoGuan.Application.BaoGuanConst.StatusDjyAccept">
<summary>
状态-大简云-已接收
</summary>
</member>
<member name="F:CustomerBaoGuan.Application.BaoGuanConst.StatusDjyReject">
<summary>
状态-大简云-已驳回
</summary>
</member>
<member name="T:CustomerBaoGuan.Application.BaoGuanSaveDto">
@ -99,14 +129,14 @@
列表dto
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanListOutput.StatusCustomer">
<member name="P:CustomerBaoGuan.Application.BaoGuanListOutput.Id">
<summary>
客户端状态
主键
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanListOutput.StatusDjy">
<member name="P:CustomerBaoGuan.Application.BaoGuanListOutput.StatusCustomer">
<summary>
大简云端状态
客户端状态
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanListOutput.BLNO">
@ -149,6 +179,46 @@
公司名称
</summary>
</member>
<member name="T:CustomerBaoGuan.Application.BaoGuanAuditListOutput">
<summary>
审核列表dto
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanAuditListOutput.Id">
<summary>
主键
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanAuditListOutput.StatusDjy">
<summary>
大简云端状态
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanAuditListOutput.BLNO">
<summary>
提单号
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanAuditListOutput.BSType">
<summary>
业务类型
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanAuditListOutput.CreatedUserName">
<summary>
创建人名称
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanAuditListOutput.CreatedTime">
<summary>
创建时间
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanAuditListOutput.CompanyName">
<summary>
公司名称
</summary>
</member>
<member name="T:CustomerBaoGuan.Application.BaoGuanSaveInput">
<summary>
保存dto
@ -169,6 +239,16 @@
保存返回dto
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanSaveOutput.StatusCustomer">
<summary>
客户端状态
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanSaveOutput.StatusDjy">
<summary>
大简云端状态
</summary>
</member>
<member name="P:CustomerBaoGuan.Application.BaoGuanSaveOutput.FileListBaoGuan">
<summary>
客户文件列表
@ -219,41 +299,62 @@
创建时间
</summary>
</member>
<member name="T:CustomerBaoGuan.Application.BaoGuanAppService">
<member name="T:CustomerBaoGuan.Application.BaoGuanService">
<summary>
报关服务接口
</summary>
</member>
<member name="M:CustomerBaoGuan.Application.BaoGuanAppService.BaoGuanList(CustomerBaoGuan.Application.BaoGuanListInput)">
<member name="M:CustomerBaoGuan.Application.BaoGuanService.BaoGuanList(CustomerBaoGuan.Application.BaoGuanListInput)">
<summary>
查询客户报关台账
</summary>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Application.BaoGuanAppService.Save(CustomerBaoGuan.Application.BaoGuanSaveInput)">
<member name="M:CustomerBaoGuan.Application.BaoGuanService.Save(CustomerBaoGuan.Application.BaoGuanSaveInput)">
<summary>
保存
</summary>
<param name="dto"></param>
</member>
<member name="M:CustomerBaoGuan.Application.BaoGuanAppService.Detail(System.Int64)">
<member name="M:CustomerBaoGuan.Application.BaoGuanService.Detail(System.Int64)">
<summary>
获取详情
</summary>
</member>
<member name="M:CustomerBaoGuan.Application.BaoGuanAppService.UploadTempFile(Microsoft.AspNetCore.Http.IFormFile)">
<member name="M:CustomerBaoGuan.Application.BaoGuanService.UploadTempFile(Microsoft.AspNetCore.Http.IFormFile)">
<summary>
上传临时文件
</summary>
<param name="file"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Application.BaoGuanAppService.GetFile(System.Int64)">
<member name="M:CustomerBaoGuan.Application.BaoGuanService.GetFile(System.Int64)">
<summary>
下载查看上传的文件
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Application.BaoGuanService.Submit(System.Collections.Generic.List{System.Int64})">
<summary>
提交
</summary>
</member>
<member name="M:CustomerBaoGuan.Application.BaoGuanService.BaoGuanAuditList(CustomerBaoGuan.Application.BaoGuanListInput)">
<summary>
审核报关台账
</summary>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Application.BaoGuanService.Audit(System.Int64,System.Boolean,System.String)">
<summary>
审核
</summary>
</member>
<member name="M:CustomerBaoGuan.Application.BaoGuanService.LogBaoGuan(System.Int64,System.String,System.String)">
<summary>
记录报关操作状态日志
</summary>
</member>
</members>
</doc>

@ -86,14 +86,14 @@ namespace CustomerBaoGuan.Application
public class BaoGuanListOutput
{
/// <summary>
/// 客户端状态
/// 主键
/// </summary>
public string StatusCustomer { get; set; }
public long Id { get; set; }
/// <summary>
/// 大简云端状态
/// 客户端状态
/// </summary>
public string StatusDjy { get; set; }
public string StatusCustomer { get; set; }
/// <summary>
/// 提单号
@ -137,6 +137,48 @@ namespace CustomerBaoGuan.Application
public string CompanyName { get; set; }
}
/// <summary>
/// 审核列表dto
/// </summary>
public class BaoGuanAuditListOutput
{
/// <summary>
/// 主键
/// </summary>
public long Id { get; set; }
/// <summary>
/// 大简云端状态
/// </summary>
public string StatusDjy { get; set; }
/// <summary>
/// 提单号
/// </summary>
public string BLNO { get; set; }
/// <summary>
/// 业务类型
/// </summary>
public string BSType { get; set; }
/// <summary>
/// 创建人名称
/// </summary>
public string CreatedUserName { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public string CreatedTime { get; set; }
/// <summary>
/// 公司名称
/// </summary>
public string CompanyName { get; set; }
}
/// <summary>
/// 保存dto
/// </summary>
@ -160,6 +202,16 @@ namespace CustomerBaoGuan.Application
/// </summary>
public class BaoGuanSaveOutput : BaoGuanSaveDto
{
/// <summary>
/// 客户端状态
/// </summary>
public string StatusCustomer { get; set; }
/// <summary>
/// 大简云端状态
/// </summary>
public string StatusDjy { get; set; }
/// <summary>
/// 客户文件列表
/// </summary>
@ -210,7 +262,7 @@ namespace CustomerBaoGuan.Application
/// <summary>
/// 创建时间
/// </summary>
public DateTime? CreatedTime { get; set; }
public string CreatedTime { get; set; }
}
}

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomerBaoGuan.Application
{
}

@ -1,220 +0,0 @@
using CustomerBaoGuan.Core.ConfigOption;
using CustomerBaoGuan.Core.DB;
using Newtonsoft.Json;
using Yitter.IdGenerator;
namespace CustomerBaoGuan.Application
{
/// <summary>
/// 报关服务接口
/// </summary>
[ApiDescriptionSettings("BaoGuan", Name = "BaoGuan", Order = 1)]
public class BaoGuanAppService : IDynamicApiController, ITransient
{
public BaoGuanAppService()
{
}
#region 公用
/// <summary>
/// 查询客户报关台账
/// </summary>
/// <returns></returns>
[HttpPost("/BaoGuanApp/BaoGuanList")]
public string BaoGuanList(BaoGuanListInput input)
{
return JsonConvert.SerializeObject(DbContext.Instance.Queryable<DjyCustomerBaoguan>()
.ToList());
}
#endregion
#region 客户操作相关
/// <summary>
/// 保存
/// </summary>
/// <param name="dto"></param>
[HttpPost("/BaoGuan/Save")]
public async Task<BaoGuanSaveOutput> Save(BaoGuanSaveInput dto)
{
DjyCustomerBaoguan model = null;
if (dto.Id == 0)
{
model = dto.Adapt<DjyCustomerBaoguan>();
model.Id = YitIdHelper.NextId();
DbContext.Instance.Insertable(model).ExecuteCommand();
}
else
{
model = DbContext.Instance.Queryable<DjyCustomerBaoguan>().First(x => x.Id == dto.Id);
dto.Adapt(model);
DbContext.Instance.Updateable(model).ExecuteCommand();
}
//文件
var dbFiles = DbContext.Instance.Queryable<DjyFile>().Where(x => x.BussinessId == model.Id).ToList();
var opt = App.GetOptions<BaoGuanFileOptions>();
var dirAbs = string.Empty;
if (string.IsNullOrEmpty(opt.BasePath))
{
dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.RelativePath);
}
else
{
dirAbs = Path.Combine(opt.BasePath, opt.RelativePath);
}
if (!Directory.Exists(dirAbs))
Directory.CreateDirectory(dirAbs);
//清除前端已删除的文件
if (dto.Files != null && dto.Files.Count() > 0)
{
var delIds = dbFiles.Where(x => !dto.Files.Contains(x.Id)).Select(x => x.Id);
await DbContext.Instance.Deleteable<DjyFile>(x => delIds.Contains(x.Id)).ExecuteCommandAsync();
}
else
{
await DbContext.Instance.Deleteable<DjyFile>(x => x.BussinessId == model.Id).ExecuteCommandAsync();
}
//临时文件转为正式文件
if (dto.TempFileNames != null && dto.TempFileNames.Count() > 0)
{
var optTempFile = App.GetOptions<TempFileOptions>().Path;
foreach (var tmpFile in dto.TempFileNames)
{
var tempPath = Path.Combine(optTempFile, tmpFile);
if (File.Exists(tempPath))
{
var saveFileName = $"{DateTime.Now.Ticks}{Path.GetExtension(tmpFile)}";
var fileRelaPath = Path.Combine(opt.RelativePath, saveFileName).ToLower();
var fileAbsPath = Path.Combine(dirAbs, saveFileName).ToLower();
File.Copy(tempPath, fileAbsPath, true);
var newFile = new DjyFile
{
Id = YitIdHelper.NextId(),
FileName = Path.GetFileName(tmpFile),
FilePath = fileRelaPath,
TypeCode = "",
TypeName = "",
BussinessId = model.Id,
Moudle = BaoGuanConst.DjyFileModuleCustBaoGuan
};
await DbContext.Instance.Insertable(newFile).ExecuteCommandAsync();
}
}
}
return await Detail(model.Id);
}
/// <summary>
/// 获取详情
/// </summary>
[HttpPost("/BaoGuan/Detail")]
public async Task<BaoGuanSaveOutput> Detail(long id)
{
var model = await DbContext.Instance.Queryable<DjyCustomerBaoguan>().FirstAsync(x => x.Id == id);
var dto = model.Adapt<BaoGuanSaveOutput>();
//文件
var files = await DbContext.Instance.Queryable<DjyFile>()
.Where(x => x.BussinessId == id && !x.IsDeleted.Value)
.Select(x => new { x.Id, x.FileName, x.Moudle })
.ToListAsync();
dto.FileListBaoGuan = files.Where(x => x.Moudle == BaoGuanConst.DjyFileModuleCustBaoGuan).ToDictionary(x => x.Id, y => y.FileName);
dto.FileListCustoms = files.Where(x => x.Moudle == BaoGuanConst.DjyFileModuleCustoms).ToDictionary(x => x.Id, y => y.FileName);
//日志信息
var logs = await DbContext.Instance.Queryable<DjyCustomerBaoguanStatusLog>()
.Where(x => x.BussinessId == id && !x.IsDeleted.Value)
.ToListAsync();
dto.LogListBuss = logs.Where(x => x.Type == BaoGuanConst.BaoGuanLogTypeBaoGuan).Adapt<List<BaoGuanLogDto>>();
dto.LogListCustoms = logs.Where(x => x.Type == BaoGuanConst.BaoGuanLogTypeCustoms).Adapt<List<BaoGuanLogDto>>();
return dto;
}
/// <summary>
/// 上传临时文件
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
[HttpPost("/BaoGuan/UploadTempFile")]
public async Task<string> UploadTempFile(IFormFile file)
{
//未上传文件
if (file == null || file.Length == 0)
{
throw Oops.Bah("未上传任何文件");
}
var optTempFile = App.GetOptions<TempFileOptions>().Path;
var tempFilePath = $"{DateTime.Now.Ticks}"; //临时存放目录
var tempSavePath = Path.Combine(optTempFile, tempFilePath);
Directory.CreateDirectory(tempSavePath);
var fileFullPath = Path.Combine(tempSavePath, file.FileName);//服务器路径
using (var stream = File.Create(fileFullPath))
{
await file.CopyToAsync(stream);
}
return Path.Combine(tempFilePath, file.FileName);
}
/// <summary>
/// 下载查看上传的文件
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("/BaoGuan/GetFile"), AllowAnonymous]
public async Task<IActionResult> GetFile(long id)
{
var savedFile = await DbContext.Instance.Queryable<DjyFile>().FirstAsync(u => u.Id == id);
if (savedFile == null)
{
throw Oops.Oh("文件不存在");
}
var opt = App.GetOptions<BaoGuanFileOptions>();
var dirAbs = opt.BasePath;
if (string.IsNullOrEmpty(dirAbs))
{
dirAbs = App.WebHostEnvironment.WebRootPath;
}
var fileFullPath = Path.Combine(dirAbs, savedFile.FilePath);
if (!File.Exists(fileFullPath))
{
throw Oops.Oh("文件不存在");
}
//var fileName = HttpUtility.UrlEncode(savedFile.FileName, Encoding.GetEncoding("UTF-8"));
var result = new FileStreamResult(new FileStream(fileFullPath, FileMode.Open), "application/octet-stream") { FileDownloadName = savedFile.FileName };
return result;
}
#endregion
#region 大简云操作相关
#endregion
[HttpGet("/BaoGuanApp/test")]
public Company Test()
{
return DbContext.Instance.Queryable<Company>().First();
}
}
}

@ -0,0 +1,346 @@
using CustomerBaoGuan.Core;
using CustomerBaoGuan.Core.ConfigOption;
using CustomerBaoGuan.Core.DB;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Yitter.IdGenerator;
namespace CustomerBaoGuan.Application
{
/// <summary>
/// 报关服务接口
/// </summary>
[ApiDescriptionSettings("BaoGuan", Name = "BaoGuan", Order = 1)]
public class BaoGuanService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<DjyCustomerBaoguan> _rep;
private readonly SqlSugarRepository<DjyFile> _repFile;
private readonly SqlSugarRepository<DjyCustomerBaoguanStatusLog> _repStatusLog;
private readonly SqlSugarRepository<User> _repUser;
private readonly SqlSugarRepository<Company> _repCompany;
private readonly ILogger<DjyCustomerBaoguan> _logger;
public BaoGuanService(SqlSugarRepository<DjyCustomerBaoguan> rep,
SqlSugarRepository<DjyFile> repFile,
SqlSugarRepository<DjyCustomerBaoguanStatusLog> repStatusLog,
ILogger<DjyCustomerBaoguan> logger,
SqlSugarRepository<User> repUser,
SqlSugarRepository<Company> repCompany)
{
_rep = rep;
_repFile = repFile;
_repStatusLog = repStatusLog;
_logger = logger;
_repUser = repUser;
_repCompany = repCompany;
}
#region 客户操作相关
/// <summary>
/// 查询客户报关台账
/// </summary>
/// <returns></returns>
[HttpPost("/BaoGuan/List")]
public async Task<SqlSugarPagedList<BaoGuanListOutput>> BaoGuanList(BaoGuanListInput input)
{
return await _rep.AsQueryable()
.Where(x => x.CompanyId == UserManager.CompanyId)
.WhereIF(!string.IsNullOrEmpty(input.BLNO), x => x.BLNO.Contains(input.BLNO))
.WhereIF(!string.IsNullOrEmpty(input.ShipperName), x => x.ShipperName.Contains(input.ShipperName))
.WhereIF(!string.IsNullOrEmpty(input.BSType), x => x.BSType == input.BSType)
.WhereIF(!string.IsNullOrEmpty(input.CustomsCode), x => x.CustomsCode.Contains(input.CustomsCode))
.WhereIF(!string.IsNullOrEmpty(input.CustomsStatus), x => x.CustomsStatus.Contains(input.CustomsStatus))
.WhereIF(input.CreatedTimeStart.HasValue, x => x.CreatedTime > input.CreatedTimeStart.Value)
.WhereIF(input.CreatedTimeEnd.HasValue, x => x.CreatedTime < input.CreatedTimeEnd.Value.AddDays(1))
.Select<BaoGuanListOutput>()
.ToPagedListAsync(input.PageIndex, input.PageSize);
}
/// <summary>
/// 保存
/// </summary>
/// <param name="dto"></param>
[HttpPost("/BaoGuan/Save")]
public async Task<BaoGuanSaveOutput> Save(BaoGuanSaveInput dto)
{
DjyCustomerBaoguan model = null;
if (dto.Id == 0)
{
model = dto.Adapt<DjyCustomerBaoguan>();
model.Id = YitIdHelper.NextId();
model.StatusCustomer = BaoGuanConst.StatusBaoGuanCreate;
await _rep.InsertAsync(model);
LogBaoGuan(model.Id, BaoGuanConst.StatusBaoGuanCreate, "");
}
else
{
model = await _rep.FirstOrDefaultAsync(x => x.Id == dto.Id);
if (model.StatusCustomer != BaoGuanConst.StatusBaoGuanCreate && model.StatusCustomer != BaoGuanConst.StatusBaoGuanReject)
{
throw Oops.Bah("当前状态不允许修改");
}
dto.Adapt(model);
model.StatusCustomer = BaoGuanConst.StatusBaoGuanCreate;
await _rep.UpdateAsync(model);
}
//文件
var dbFiles = await _repFile.Where(x => x.BussinessId == model.Id).ToListAsync();
var opt = App.GetOptions<BaoGuanFileOptions>();
var dirAbs = string.Empty;
if (string.IsNullOrEmpty(opt.BasePath))
{
dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.RelativePath);
}
else
{
dirAbs = Path.Combine(opt.BasePath, opt.RelativePath);
}
if (!Directory.Exists(dirAbs))
Directory.CreateDirectory(dirAbs);
//清除前端已删除的文件
if (dto.Files != null && dto.Files.Count() > 0)
{
var delIds = dbFiles.Where(x => !dto.Files.Contains(x.Id)).Select(x => x.Id);
await _repFile.DeleteAsync(x => delIds.Contains(x.Id));
}
else
{
await _repFile.DeleteAsync(x => x.BussinessId == model.Id);
}
//临时文件转为正式文件
if (dto.TempFileNames != null && dto.TempFileNames.Count() > 0)
{
var optTempFile = App.GetOptions<TempFileOptions>().Path;
foreach (var tmpFile in dto.TempFileNames)
{
var tempPath = Path.Combine(optTempFile, tmpFile);
if (File.Exists(tempPath))
{
var saveFileName = $"{DateTime.Now.Ticks}{Path.GetExtension(tmpFile)}";
var fileRelaPath = Path.Combine(opt.RelativePath, saveFileName).ToLower();
var fileAbsPath = Path.Combine(dirAbs, saveFileName).ToLower();
File.Copy(tempPath, fileAbsPath, true);
var newFile = new DjyFile
{
Id = YitIdHelper.NextId(),
FileName = Path.GetFileName(tmpFile),
FilePath = fileRelaPath,
TypeCode = "",
TypeName = "",
BussinessId = model.Id,
Moudle = BaoGuanConst.DjyFileModuleCustBaoGuan
};
await _repFile.InsertAsync(newFile);
}
}
}
return await Detail(model.Id);
}
/// <summary>
/// 获取详情
/// </summary>
[HttpPost("/BaoGuan/Detail")]
public async Task<BaoGuanSaveOutput> Detail(long id)
{
var model = await _rep.FirstOrDefaultAsync(x => x.Id == id);
var dto = model.Adapt<BaoGuanSaveOutput>();
//文件
var files = await _repFile
.Where(x => x.BussinessId == id && !x.IsDeleted.Value)
.Select(x => new { x.Id, x.FileName, x.Moudle })
.ToListAsync();
dto.FileListBaoGuan = files.Where(x => x.Moudle == BaoGuanConst.DjyFileModuleCustBaoGuan).ToDictionary(x => x.Id, y => y.FileName);
dto.FileListCustoms = files.Where(x => x.Moudle == BaoGuanConst.DjyFileModuleCustoms).ToDictionary(x => x.Id, y => y.FileName);
//日志信息
var logs = await _repStatusLog
.Where(x => x.BussinessId == id && !x.IsDeleted.Value)
.ToListAsync();
dto.LogListBuss = logs.Where(x => x.Type == BaoGuanConst.BaoGuanLogTypeBaoGuan).Adapt<List<BaoGuanLogDto>>();
dto.LogListCustoms = logs.Where(x => x.Type == BaoGuanConst.BaoGuanLogTypeCustoms).Adapt<List<BaoGuanLogDto>>();
return dto;
}
/// <summary>
/// 上传临时文件
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
[HttpPost("/BaoGuan/UploadTempFile")]
public async Task<string> UploadTempFile(IFormFile file)
{
//未上传文件
if (file == null || file.Length == 0)
{
throw Oops.Bah("未上传任何文件");
}
var optTempFile = App.GetOptions<TempFileOptions>().Path;
var tempFilePath = $"{DateTime.Now.Ticks}"; //临时存放目录
var tempSavePath = Path.Combine(optTempFile, tempFilePath);
Directory.CreateDirectory(tempSavePath);
var fileFullPath = Path.Combine(tempSavePath, file.FileName);//服务器路径
using (var stream = File.Create(fileFullPath))
{
await file.CopyToAsync(stream);
}
return Path.Combine(tempFilePath, file.FileName);
}
/// <summary>
/// 下载查看上传的文件
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("/BaoGuan/GetFile"), AllowAnonymous]
public async Task<IActionResult> GetFile(long id)
{
var savedFile = await _repFile.FirstOrDefaultAsync(u => u.Id == id);
if (savedFile == null)
{
throw Oops.Oh("文件不存在");
}
var opt = App.GetOptions<BaoGuanFileOptions>();
var dirAbs = opt.BasePath;
if (string.IsNullOrEmpty(dirAbs))
{
dirAbs = App.WebHostEnvironment.WebRootPath;
}
var fileFullPath = Path.Combine(dirAbs, savedFile.FilePath);
if (!File.Exists(fileFullPath))
{
throw Oops.Oh("文件不存在");
}
//var fileName = HttpUtility.UrlEncode(savedFile.FileName, Encoding.GetEncoding("UTF-8"));
var result = new FileStreamResult(new FileStream(fileFullPath, FileMode.Open), "application/octet-stream") { FileDownloadName = savedFile.FileName };
return result;
}
/// <summary>
/// 提交
/// </summary>
[HttpPost("/BaoGuan/Submit")]
public async Task Submit(List<long> idList)
{
var modelList = await _rep.Where(x => idList.Contains(x.Id)).ToListAsync();
if (modelList.Count(x => x.StatusCustomer != BaoGuanConst.StatusBaoGuanCreate && x.StatusCustomer != BaoGuanConst.StatusBaoGuanReject) > 0)
{
throw Oops.Bah("当前状态不能提交");
}
foreach (var model in modelList)
{
model.StatusCustomer = BaoGuanConst.StatusBaoGuanSent;
model.StatusDjy = BaoGuanConst.StatusDjyAudit;
await _rep.UpdateAsync(model);
LogBaoGuan(model.Id, BaoGuanConst.StatusBaoGuanSent, "");
}
}
#endregion
#region 大简云操作相关
/// <summary>
/// 审核报关台账
/// </summary>
/// <returns></returns>
[HttpPost("/BaoGuan/AuditList")]
public async Task<SqlSugarPagedList<BaoGuanAuditListOutput>> BaoGuanAuditList(BaoGuanListInput input)
{
return await _rep.AsQueryable()
.Where(x => x.StatusCustomer == BaoGuanConst.StatusBaoGuanSent)
.WhereIF(!string.IsNullOrEmpty(input.BLNO), x => x.BLNO.Contains(input.BLNO))
.WhereIF(!string.IsNullOrEmpty(input.ShipperName), x => x.ShipperName.Contains(input.ShipperName))
.WhereIF(!string.IsNullOrEmpty(input.BSType), x => x.BSType == input.BSType)
.WhereIF(!string.IsNullOrEmpty(input.CustomsCode), x => x.CustomsCode.Contains(input.CustomsCode))
.WhereIF(!string.IsNullOrEmpty(input.CustomsStatus), x => x.CustomsStatus.Contains(input.CustomsStatus))
.WhereIF(input.CreatedTimeStart.HasValue, x => x.CreatedTime > input.CreatedTimeStart.Value)
.WhereIF(input.CreatedTimeEnd.HasValue, x => x.CreatedTime < input.CreatedTimeEnd.Value.AddDays(1))
.Select<BaoGuanAuditListOutput>()
.ToPagedListAsync(input.PageIndex, input.PageSize);
}
/// <summary>
/// 审核
/// </summary>
[HttpPost("/BaoGuan/Audit")]
public async Task Audit(long id, bool accept, string remark)
{
var model = await _rep.FirstOrDefaultAsync(x => x.Id == id);
if (model == null)
{
throw Oops.Bah("未找到业务信息");
}
if (model.StatusCustomer != BaoGuanConst.StatusBaoGuanSent || model.StatusDjy != BaoGuanConst.StatusDjyAudit)
{
throw Oops.Bah("当前状态不能审核");
}
if (accept)
{
model.StatusCustomer = BaoGuanConst.StatusBaoGuanSent;
model.StatusDjy = BaoGuanConst.StatusDjyAccept;
LogBaoGuan(model.Id, BaoGuanConst.StatusDjyAccept, remark);
}
else
{
model.StatusCustomer = BaoGuanConst.StatusBaoGuanReject;
model.StatusDjy = BaoGuanConst.StatusDjyReject;
LogBaoGuan(model.Id, BaoGuanConst.StatusDjyReject, remark);
}
await _rep.UpdateAsync(model);
}
#endregion
#region 其他
/// <summary>
/// 记录报关操作状态日志
/// </summary>
private async void LogBaoGuan(long bussId, string status, string remark)
{
var staLog = new DjyCustomerBaoguanStatusLog();
staLog.Id = YitIdHelper.NextId();
staLog.BussinessId = bussId;
staLog.StatusName = status;
staLog.Remark = remark;
staLog.Type = BaoGuanConst.BaoGuanLogTypeBaoGuan;
await _repStatusLog.InsertAsync(staLog);
}
#endregion
}
}

@ -18,6 +18,7 @@
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.8.8.18" />
<PackageReference Include="Furion.Pure" Version="4.8.8.18" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.73" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.3" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
</ItemGroup>

@ -719,6 +719,21 @@
条数
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.DescriptionExtension.GetDescription(System.Enum)">
<summary>
获取枚举的描述信息
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.DescriptionExtension.GetDescription(System.Type,System.String)">
<summary>
获取属性的描述信息
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.DescriptionExtension.GetDescription(System.Reflection.MemberInfo)">
<summary>
获取属性的描述信息
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.JsonExtension.GetJObjectValue(Newtonsoft.Json.Linq.JObject,System.String)">
<summary>
获取JObject
@ -791,6 +806,20 @@
<param name="prop"></param>
<returns></returns>
</member>
<member name="T:CustomerBaoGuan.Core.PagedQueryableExtensions">
<summary>
分页拓展类
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.PagedQueryableExtensions.ToPagedListAsync``1(SqlSugar.ISugarQueryable{``0},System.Int32,System.Int32)">
<summary>
分页拓展
</summary>
<param name="query"></param>
<param name="pageIndex"></param>
<param name="pageSize"></param>
<returns></returns>
</member>
<member name="T:CustomerBaoGuan.Core.LoggingFileComponent">
<summary>
日志写入文件的组件
@ -815,6 +844,551 @@
<param name="builder"></param>
<returns></returns>
</member>
<member name="T:CustomerBaoGuan.Core.UserManager">
<summary>
用户管理
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.UserManager.UserId">
<summary>
用户id
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.UserManager.Account">
<summary>
账号
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.UserManager.Name">
<summary>
名称
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.UserManager.CompanyId">
<summary>
公司id
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.UserManager.CompanyName">
<summary>
公司名称
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.UserManager.TEl">
<summary>
电话
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.UserManager.Phone">
<summary>
手机
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.UserManager.Email">
<summary>
邮箱
</summary>
</member>
<member name="T:CustomerBaoGuan.Core.SqlSugarPagedList`1">
<summary>
分页泛型集合
</summary>
<typeparam name="TEntity"></typeparam>
</member>
<member name="P:CustomerBaoGuan.Core.SqlSugarPagedList`1.PageIndex">
<summary>
页码
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.SqlSugarPagedList`1.PageSize">
<summary>
页容量
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.SqlSugarPagedList`1.TotalCount">
<summary>
总条数
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.SqlSugarPagedList`1.TotalPages">
<summary>
总页数
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.SqlSugarPagedList`1.Items">
<summary>
当前页集合
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.SqlSugarPagedList`1.HasPrevPages">
<summary>
是否有上一页
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.SqlSugarPagedList`1.HasNextPages">
<summary>
是否有下一页
</summary>
</member>
<member name="T:CustomerBaoGuan.Core.PagedModel">
<summary>
分页集合
</summary>
</member>
<member name="T:CustomerBaoGuan.Core.SqlSugarRepository`1">
<summary>
SqlSugar 仓储实现类
</summary>
<typeparam name="TEntity"></typeparam>
</member>
<member name="F:CustomerBaoGuan.Core.SqlSugarRepository`1._db">
<summary>
初始化 SqlSugar 客户端
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.SqlSugarRepository`1.Context">
<summary>
数据库上下文
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.#ctor(SqlSugar.ISqlSugarClient)">
<summary>
构造函数
</summary>
<param name="db"></param>
</member>
<member name="P:CustomerBaoGuan.Core.SqlSugarRepository`1.Entities">
<summary>
实体集合
</summary>
</member>
<member name="P:CustomerBaoGuan.Core.SqlSugarRepository`1.Ado">
<summary>
原生 Ado 对象
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Count(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
获取总数
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.CountAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
获取总数
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Any(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
检查是否存在
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.AnyAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
检查是否存在
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Single(System.Object)">
<summary>
通过主键获取实体
</summary>
<param name="Id"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Single(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
获取一个实体
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.SingleAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
获取一个实体
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.FirstOrDefault(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
获取一个实体
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.FirstOrDefaultAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
获取一个实体
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.ToList">
<summary>
获取列表
</summary>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.ToList(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
获取列表
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.ToList(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}},System.Linq.Expressions.Expression{System.Func{`0,System.Object}},SqlSugar.OrderByType)">
<summary>
获取列表
</summary>
<param name="whereExpression"></param>
<param name="orderByExpression"></param>
<param name="orderByType"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.ToListAsync">
<summary>
获取列表
</summary>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.ToListAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
获取列表
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.ToListAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}},System.Linq.Expressions.Expression{System.Func{`0,System.Object}},SqlSugar.OrderByType)">
<summary>
获取列表
</summary>
<param name="whereExpression"></param>
<param name="orderByExpression"></param>
<param name="orderByType"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Insert(`0)">
<summary>
新增一条记录
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Insert(`0[])">
<summary>
新增多条记录
</summary>
<param name="entities"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Insert(System.Collections.Generic.IEnumerable{`0})">
<summary>
新增多条记录
</summary>
<param name="entities"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.InsertReturnIdentity(`0)">
<summary>
新增一条记录返回自增Id
</summary>
<param name="insertObj"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.InsertReturnSnowflakeId(`0)">
<summary>
新增一条记录返回雪花Id
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.InsertReturnEntity(`0)">
<summary>
新增一条记录返回实体
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.InsertAsync(`0)">
<summary>
新增一条记录
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.InsertAsync(`0[])">
<summary>
新增多条记录
</summary>
<param name="entities"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.InsertAsync(System.Collections.Generic.IEnumerable{`0})">
<summary>
新增多条记录
</summary>
<param name="entities"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.InsertReturnIdentityAsync(`0)">
<summary>
新增一条记录返回自增Id
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.InsertReturnSnowflakeIdAsync(`0)">
<summary>
新增一条记录返回雪花Id
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.InsertReturnEntityAsync(`0)">
<summary>
新增一条记录返回实体
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Update(`0)">
<summary>
更新一条记录
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Update(`0[])">
<summary>
更新多条记录
</summary>
<param name="entities"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Update(System.Collections.Generic.IEnumerable{`0})">
<summary>
更新多条记录
</summary>
<param name="entities"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.UpdateAsync(`0)">
<summary>
更新一条记录
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Update(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}},System.Linq.Expressions.Expression{System.Func{`0,`0}})">
<summary>
更新记录
</summary>
<param name="predicate">更新的条件</param>
<param name="content">更新的内容</param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.UpdateAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}},System.Linq.Expressions.Expression{System.Func{`0,`0}})">
<summary>
更新记录
</summary>
<param name="predicate">更新的条件</param>
<param name="content">更新的内容</param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.UpdateAsync(`0[])">
<summary>
更新多条记录
</summary>
<param name="entities"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.UpdateAsync(System.Collections.Generic.IEnumerable{`0})">
<summary>
更新多条记录
</summary>
<param name="entities"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Delete(`0)">
<summary>
删除一条记录
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Delete(System.Object)">
<summary>
删除一条记录
</summary>
<param name="key"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Delete(System.Object[])">
<summary>
删除多条记录
</summary>
<param name="keys"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Delete(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
自定义条件删除记录
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.DeleteAsync(`0)">
<summary>
删除一条记录
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.DeleteAsync(System.Object)">
<summary>
删除一条记录
</summary>
<param name="key"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.DeleteAsync(System.Object[])">
<summary>
删除多条记录
</summary>
<param name="keys"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.DeleteAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
自定义条件删除记录
</summary>
<param name="whereExpression"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Where(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
根据表达式查询多条记录
</summary>
<param name="predicate"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Where(System.Boolean,System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
根据表达式查询多条记录
</summary>
<param name="condition"></param>
<param name="predicate"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.AsQueryable">
<summary>
构建查询分析器
</summary>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.AsQueryable(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
构建查询分析器
</summary>
<param name="predicate"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.AsEnumerable">
<summary>
直接返回数据库结果
</summary>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.AsEnumerable(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
直接返回数据库结果
</summary>
<param name="predicate"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.AsAsyncEnumerable">
<summary>
直接返回数据库结果
</summary>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.AsAsyncEnumerable(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
直接返回数据库结果
</summary>
<param name="predicate"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.Change``1">
<summary>
切换仓储(注意使用环境)
</summary>
<typeparam name="T">实体类型</typeparam>
<returns>仓储</returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.CurrentBeginTran">
<summary>
当前db
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.CurrentCommitTran">
<summary>
当前db
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.CurrentRollbackTran">
<summary>
当前db
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.BeginTran">
<summary>
所有db
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.CommitTran">
<summary>
所有db
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarRepository`1.RollbackTran">
<summary>
所有db
</summary>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarSetup.SqlSugarScopeConfigure(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary>
SqlsugarScope的配置
Scope必须用单例注入
不可以用Action委托注入
</summary>
<param name="services"></param>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarSetup.AddSqlSugar(Microsoft.Extensions.DependencyInjection.IServiceCollection,SqlSugar.ConnectionConfig,System.Action{SqlSugar.ISqlSugarClient})">
<summary>
添加 SqlSugar 拓展
</summary>
<param name="services"></param>
<param name="config"></param>
<param name="buildAction"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Core.SqlSugarSetup.AddSqlSugar(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Collections.Generic.List{SqlSugar.ConnectionConfig},System.Action{SqlSugar.ISqlSugarClient})">
<summary>
添加 SqlSugar 拓展
</summary>
<param name="services"></param>
<param name="configs"></param>
<param name="buildAction"></param>
<returns></returns>
</member>
<member name="T:Myshipping.Core.Service.AuthService">
<summary>
登录授权相关服务
@ -827,5 +1401,11 @@
<param name="code"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Core.Service.AuthService.LoginDevelop">
<summary>
登录 开发调试使用
</summary>
<returns></returns>
</member>
</members>
</doc>

@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace CustomerBaoGuan.Core.DB
{
[Tenant("baoguan")]
public class EntityBase
{
/// <summary>
@ -28,7 +29,7 @@ namespace CustomerBaoGuan.Core.DB
/// <summary>
/// 创建人ID
/// </summary>
public long? CreatedUserId { get; set; }
public string CreatedUserId { get; set; }
/// <summary>
/// 创建人名称
@ -38,7 +39,7 @@ namespace CustomerBaoGuan.Core.DB
/// <summary>
/// 修改人ID
/// </summary>
public long? UpdatedUserId { get; set; }
public string UpdatedUserId { get; set; }
/// <summary>
/// 修改人名称
@ -48,7 +49,7 @@ namespace CustomerBaoGuan.Core.DB
/// <summary>
/// 删除标志
/// </summary>
public bool? IsDeleted { get; set; }
public bool? IsDeleted { get; set; } = false;
/// <summary>
/// 公司ID

@ -11,11 +11,11 @@ namespace CustomerBaoGuan.Core.Dto
/// <summary>
/// 页码
/// </summary>
public int PageIndex { get; set; }
public int PageIndex { get; set; } = 1;
/// <summary>
/// 条数
/// </summary>
public int PageSize { get;set; }
public int PageSize { get; set; } = 20;
}
}

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace CustomerBaoGuan.Core
{
public static class DescriptionExtension
{
/// <summary>
/// 获取枚举的描述信息
/// </summary>
public static string GetDescription(this Enum em)
{
Type type = em.GetType();
FieldInfo fd = type.GetField(em.ToString());
string des = fd.GetDescription();
return des;
}
/// <summary>
/// 获取属性的描述信息
/// </summary>
public static string GetDescription(this Type type, string proName)
{
PropertyInfo pro = type.GetProperty(proName);
string des = proName;
if (pro != null)
{
des = pro.GetDescription();
}
return des;
}
/// <summary>
/// 获取属性的描述信息
/// </summary>
public static string GetDescription(this MemberInfo info)
{
var attrs = (DescriptionAttribute[])info.GetCustomAttributes(typeof(DescriptionAttribute), false);
string des = info.Name;
foreach (DescriptionAttribute attr in attrs)
{
des = attr.Description;
}
return des;
}
}
}

@ -0,0 +1,35 @@
using SqlSugar;
using System;
using System.Threading.Tasks;
namespace CustomerBaoGuan.Core;
/// <summary>
/// 分页拓展类
/// </summary>
public static class PagedQueryableExtensions
{
/// <summary>
/// 分页拓展
/// </summary>
/// <param name="query"></param>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
public static async Task<SqlSugarPagedList<TEntity>> ToPagedListAsync<TEntity>(this ISugarQueryable<TEntity> query, int pageIndex, int pageSize)
{
RefAsync<int> totalCount = 0;
var items = await query.ToPageListAsync(pageIndex, pageSize, totalCount);
var totalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
return new SqlSugarPagedList<TEntity>
{
PageIndex = pageIndex,
PageSize = pageSize,
Items = items,
TotalCount = (int)totalCount,
TotalPages = totalPages,
HasNextPages = pageIndex < totalPages,
HasPrevPages = pageIndex - 1 > 0
};
}
}

@ -0,0 +1,53 @@

using Furion;
namespace CustomerBaoGuan.Core;
/// <summary>
/// 用户管理
/// </summary>
public static class UserManager
{
/// <summary>
/// 用户id
/// </summary>
public static string UserId => App.User.FindFirst(ClaimConst.UserId)?.Value;
/// <summary>
/// 账号
/// </summary>
public static string Account => App.User.FindFirst(ClaimConst.Account)?.Value;
/// <summary>
/// 名称
/// </summary>
public static string Name => App.User.FindFirst(ClaimConst.Name)?.Value;
/// <summary>
/// 公司id
/// </summary>
public static string CompanyId => App.User.FindFirst(ClaimConst.CompanyId)?.Value;
/// <summary>
/// 公司名称
/// </summary>
public static string CompanyName => App.User.FindFirst(ClaimConst.CompanyName)?.Value;
/// <summary>
/// 电话
/// </summary>
public static string TEl => App.User.FindFirst(ClaimConst.Tel)?.Value;
/// <summary>
/// 手机
/// </summary>
public static string Phone => App.User.FindFirst(ClaimConst.Phone)?.Value;
/// <summary>
/// 邮箱
/// </summary>
public static string Email => App.User.FindFirst(ClaimConst.Email)?.Value;
}

@ -95,12 +95,31 @@ public class AuthService : IDynamicApiController, ITransient
var comname = jData.GetStringValue("comname");
var userId = jData.GetStringValue("gid");
var showname = jData.GetStringValue("showname");
var codename = jData.GetStringValue("codename");
var company = DbContext.Instance.Queryable<Company>().First(x => x.CompId == compId);
var user = DbContext.Instance.Queryable<User>().First(u => u.GID == userId);
var userBaseInfo = DbContext.Instance.Queryable<UserBaseInfo>().First(u => u.USERID == userId);
// 生成Token令牌
var accessToken = JWTEncryption.Encrypt(new Dictionary<string, object>
{
{ClaimConst.UserId, userId},
{ClaimConst.CompanyId, compId},
{ClaimConst.Account, codename},
{ClaimConst.Name, showname},
{ ClaimConst.CompanyName, comname },
//{ ClaimConst.Tel, userBaseInfo.OFFICEPHONE },
//{ ClaimConst.Phone, userBaseInfo.MOBILE },
//{ ClaimConst.Email, userBaseInfo.EMAIL1 },
});
// 设置Swagger自动登录
_httpContextAccessor.HttpContext.SigninToSwagger(accessToken);
// 生成刷新Token令牌
var refreshToken = JWTEncryption.GenerateRefreshToken(accessToken, 30);
// 设置刷新Token令牌
_httpContextAccessor.HttpContext.Response.Headers["x-access-token"] = refreshToken;
return await GetLoginToken(user, userBaseInfo, company);
return accessToken;
}
else
@ -116,31 +135,98 @@ public class AuthService : IDynamicApiController, ITransient
}
private async Task<string> GetLoginToken(User user, UserBaseInfo userBaseInfo, Company company)
/// <summary>
/// 登录 开发调试使用
/// </summary>
/// <returns></returns>
[AllowAnonymous]
[HttpPost("/loginDevelop")]
public async Task<string> LoginDevelop()
{
// 生成Token令牌
var accessToken = JWTEncryption.Encrypt(new Dictionary<string, object>
var djyAuthUrl = App.Configuration.GetSection("DjyAuthUrl").Value;
if (!djyAuthUrl.EndsWith("/"))
{
djyAuthUrl += "/";
}
var loginUrl = djyAuthUrl + "user/login";
var infoUrl = djyAuthUrl + "user/info";
_logger.LogInformation($"统一登录:{loginUrl}");
//跳转登录
var result = await loginUrl
.SetBody(new
{
LoginName = "YGH",
Password = "666666"
}, "application/json")
.PostAsStringAsync();
_logger.LogInformation($"登录返回:{result}");
var jRtn = JObject.Parse(result);
if (jRtn.GetIntValue("code") == 200)
{
{ClaimConst.UserId, user.GID},
{ClaimConst.CompanyId, company.CompId},
{ClaimConst.Account, user.CODENAME},
{ClaimConst.Name, user.SHOWNAME},
{ ClaimConst.CompanyName, company.CompName },
{ ClaimConst.Tel, userBaseInfo.OFFICEPHONE },
{ ClaimConst.Phone, userBaseInfo.MOBILE },
{ ClaimConst.Email, userBaseInfo.EMAIL1 },
var jData = jRtn.GetJObjectValue("data");
var token = jData.GetStringValue("token");
var headers = new Dictionary<string, object>();
headers.Add("Authorization", $"Bearer {token}");
_logger.LogInformation($"获取登录信息:{infoUrl}");
//获取登录信息
result = await infoUrl
.SetHeaders(headers)
.GetAsStringAsync();
_logger.LogInformation($"登录信息返回:{result}");
jRtn = JObject.Parse(result);
if (jRtn.GetIntValue("code") == 200)
{
jData = jRtn.GetJObjectValue("data");
var compId = jData.GetStringValue("compId");
var comname = jData.GetStringValue("comname");
var userId = jData.GetStringValue("gid");
var showname = jData.GetStringValue("showname");
var codename = jData.GetStringValue("codename");
// 生成Token令牌
var accessToken = JWTEncryption.Encrypt(new Dictionary<string, object>
{
{ClaimConst.UserId, userId},
{ClaimConst.CompanyId, compId},
{ClaimConst.Account, codename},
{ClaimConst.Name, showname},
{ ClaimConst.CompanyName, comname },
//{ ClaimConst.Tel, userBaseInfo.OFFICEPHONE },
//{ ClaimConst.Phone, userBaseInfo.MOBILE },
//{ ClaimConst.Email, userBaseInfo.EMAIL1 },
});
// 设置Swagger自动登录
_httpContextAccessor.HttpContext.SigninToSwagger(accessToken);
// 设置Swagger自动登录
_httpContextAccessor.HttpContext.SigninToSwagger(accessToken);
// 生成刷新Token令牌
var refreshToken = JWTEncryption.GenerateRefreshToken(accessToken, 30);
// 生成刷新Token令牌
var refreshToken = JWTEncryption.GenerateRefreshToken(accessToken, 30);
// 设置刷新Token令牌
_httpContextAccessor.HttpContext.Response.Headers["x-access-token"] = refreshToken;
// 设置刷新Token令牌
_httpContextAccessor.HttpContext.Response.Headers["x-access-token"] = refreshToken;
return accessToken;
}
else
{
throw Oops.Bah(jRtn.GetStringValue("message"));
}
}
else
{
throw Oops.Bah(jRtn.GetStringValue("message"));
}
return accessToken;
}
}

@ -0,0 +1,52 @@
using System.Collections.Generic;
namespace CustomerBaoGuan.Core;
/// <summary>
/// 分页泛型集合
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public class SqlSugarPagedList<TEntity>
{
/// <summary>
/// 页码
/// </summary>
public int PageIndex { get; set; }
/// <summary>
/// 页容量
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// 总条数
/// </summary>
public int TotalCount { get; set; }
/// <summary>
/// 总页数
/// </summary>
public int TotalPages { get; set; }
/// <summary>
/// 当前页集合
/// </summary>
public IEnumerable<TEntity> Items { get; set; }
/// <summary>
/// 是否有上一页
/// </summary>
public bool HasPrevPages { get; set; }
/// <summary>
/// 是否有下一页
/// </summary>
public bool HasNextPages { get; set; }
}
/// <summary>
/// 分页集合
/// </summary>
public class PagedModel : SqlSugarPagedList<object>
{
}

@ -0,0 +1,663 @@
using Furion;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace CustomerBaoGuan.Core;
/// <summary>
/// SqlSugar 仓储实现类
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public partial class SqlSugarRepository<TEntity>
where TEntity : class, new()
{
private readonly string[] UpdateIgnoreColumns=new string[] { "CreatedTime", "CreatedUserId", "CreatedUserName" };
#region 属性
/// <summary>
/// 初始化 SqlSugar 客户端
/// </summary>
private readonly SqlSugarScope _db;
/// <summary>
/// 数据库上下文
/// </summary>
public virtual SqlSugarScope Context { get; }
public virtual SqlSugarProvider EntityContext { get; }
/// <summary>
/// 构造函数
/// </summary>
/// <param name="db"></param>
public SqlSugarRepository(ISqlSugarClient db)
{
Context = _db = (SqlSugarScope)db;
EntityContext = _db.GetConnectionWithAttr<TEntity>();
Ado = EntityContext.Ado;
}
/// <summary>
/// 实体集合
/// </summary>
public virtual ISugarQueryable<TEntity> Entities => EntityContext.Queryable<TEntity>();
/// <summary>
/// 原生 Ado 对象
/// </summary>
public virtual IAdo Ado { get; }
#endregion
#region 查询
/// <summary>
/// 获取总数
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public int Count(Expression<Func<TEntity, bool>> whereExpression)
{
return Entities.Count(whereExpression);
}
/// <summary>
/// 获取总数
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public Task<int> CountAsync(Expression<Func<TEntity, bool>> whereExpression)
{
return Entities.CountAsync(whereExpression);
}
/// <summary>
/// 检查是否存在
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public bool Any(Expression<Func<TEntity, bool>> whereExpression)
{
return Entities.Any(whereExpression);
}
/// <summary>
/// 检查是否存在
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public async Task<bool> AnyAsync(Expression<Func<TEntity, bool>> whereExpression)
{
return await Entities.AnyAsync(whereExpression);
}
/// <summary>
/// 通过主键获取实体
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public TEntity Single(dynamic Id)
{
return Entities.InSingle(Id);
}
/// <summary>
/// 获取一个实体
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public TEntity Single(Expression<Func<TEntity, bool>> whereExpression)
{
return Entities.Single(whereExpression);
}
/// <summary>
/// 获取一个实体
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public Task<TEntity> SingleAsync(Expression<Func<TEntity, bool>> whereExpression)
{
return Entities.SingleAsync(whereExpression);
}
/// <summary>
/// 获取一个实体
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public TEntity FirstOrDefault(Expression<Func<TEntity, bool>> whereExpression)
{
return Entities.First(whereExpression);
}
/// <summary>
/// 获取一个实体
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public async Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> whereExpression)
{
return await Entities.FirstAsync(whereExpression);
}
/// <summary>
/// 获取列表
/// </summary>
/// <returns></returns>
public List<TEntity> ToList()
{
return Entities.ToList();
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public List<TEntity> ToList(Expression<Func<TEntity, bool>> whereExpression)
{
return Entities.Where(whereExpression).ToList();
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="whereExpression"></param>
/// <param name="orderByExpression"></param>
/// <param name="orderByType"></param>
/// <returns></returns>
public List<TEntity> ToList(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
{
return Entities.OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToList();
}
/// <summary>
/// 获取列表
/// </summary>
/// <returns></returns>
public Task<List<TEntity>> ToListAsync()
{
return Entities.ToListAsync();
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public Task<List<TEntity>> ToListAsync(Expression<Func<TEntity, bool>> whereExpression)
{
return Entities.Where(whereExpression).ToListAsync();
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="whereExpression"></param>
/// <param name="orderByExpression"></param>
/// <param name="orderByType"></param>
/// <returns></returns>
public Task<List<TEntity>> ToListAsync(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
{
return Entities.OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToListAsync();
}
#endregion
#region 新增
public virtual IInsertable<TEntity> AsInsertable(TEntity entity)
{
return EntityContext.Insertable(entity);
}
public virtual IInsertable<TEntity> AsInsertable(params TEntity[] entities)
{
return EntityContext.Insertable(entities);
}
/// <summary>
/// 新增一条记录
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual int Insert(TEntity entity)
{
return EntityContext.Insertable(entity).ExecuteCommand();
}
/// <summary>
/// 新增多条记录
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
public virtual int Insert(params TEntity[] entities)
{
return EntityContext.Insertable(entities).ExecuteCommand();
}
/// <summary>
/// 新增多条记录
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
public virtual int Insert(IEnumerable<TEntity> entities)
{
return EntityContext.Insertable(entities.ToArray()).ExecuteCommand();
}
/// <summary>
/// 新增一条记录返回自增Id
/// </summary>
/// <param name="insertObj"></param>
/// <returns></returns>
public virtual int InsertReturnIdentity(TEntity insertObj)
{
return EntityContext.Insertable(insertObj).ExecuteReturnIdentity();
}
/// <summary>
/// 新增一条记录返回雪花Id
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual long InsertReturnSnowflakeId(TEntity entity)
{
return EntityContext.Insertable(entity).ExecuteReturnSnowflakeId();
}
/// <summary>
/// 新增一条记录返回实体
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual TEntity InsertReturnEntity(TEntity entity)
{
return EntityContext.Insertable(entity).ExecuteReturnEntity();
}
/// <summary>
/// 新增一条记录
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual Task<int> InsertAsync(TEntity entity)
{
return EntityContext.Insertable(entity).ExecuteCommandAsync();
}
/// <summary>
/// 新增多条记录
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
public virtual Task<int> InsertAsync(params TEntity[] entities)
{
return EntityContext.Insertable(entities).ExecuteCommandAsync();
}
/// <summary>
/// 新增多条记录
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
public virtual Task<int> InsertAsync(IEnumerable<TEntity> entities)
{
if (entities != null && entities.Any())
{
return EntityContext.Insertable(entities.ToArray()).ExecuteCommandAsync();
}
return Task.FromResult(0);
}
/// <summary>
/// 新增一条记录返回自增Id
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual async Task<long> InsertReturnIdentityAsync(TEntity entity)
{
return await EntityContext.Insertable(entity).ExecuteReturnBigIdentityAsync();
}
/// <summary>
/// 新增一条记录返回雪花Id
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual async Task<long> InsertReturnSnowflakeIdAsync(TEntity entity)
{
return await EntityContext.Insertable(entity).ExecuteReturnSnowflakeIdAsync();
}
/// <summary>
/// 新增一条记录返回实体
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual async Task<TEntity> InsertReturnEntityAsync(TEntity entity)
{
return await EntityContext.Insertable(entity).ExecuteReturnEntityAsync();
}
#endregion
#region 更新
/// <summary>
/// 更新一条记录
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual int Update(TEntity entity)
{
return EntityContext.Updateable(entity).IgnoreColumns(UpdateIgnoreColumns).ExecuteCommand();
}
/// <summary>
/// 更新多条记录
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
public virtual int Update(params TEntity[] entities)
{
return EntityContext.Updateable(entities).IgnoreColumns(UpdateIgnoreColumns).ExecuteCommand();
}
/// <summary>
/// 更新多条记录
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
public virtual int Update(IEnumerable<TEntity> entities)
{
return EntityContext.Updateable(entities.ToArray()).IgnoreColumns(UpdateIgnoreColumns).ExecuteCommand();
}
/// <summary>
/// 更新一条记录
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual async Task<int> UpdateAsync(TEntity entity)
{
return await EntityContext.Updateable(entity).IgnoreColumns(UpdateIgnoreColumns).ExecuteCommandAsync();
}
/// <summary>
/// 更新记录
/// </summary>
/// <param name="predicate">更新的条件</param>
/// <param name="content">更新的内容</param>
/// <returns></returns>
public virtual int Update(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, TEntity>> content)
{
return EntityContext.Updateable(content).Where(predicate).IgnoreColumns(UpdateIgnoreColumns).ExecuteCommand();
}
/// <summary>
/// 更新记录
/// </summary>
/// <param name="predicate">更新的条件</param>
/// <param name="content">更新的内容</param>
/// <returns></returns>
public virtual async Task<int> UpdateAsync(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, TEntity>> content)
{
return await EntityContext.Updateable(content).Where(predicate).IgnoreColumns(UpdateIgnoreColumns).ExecuteCommandAsync();
}
/// <summary>
/// 更新多条记录
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
public virtual Task<int> UpdateAsync(params TEntity[] entities)
{
return EntityContext.Updateable(entities).IgnoreColumns(UpdateIgnoreColumns).ExecuteCommandAsync();
}
/// <summary>
/// 更新多条记录
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
public virtual Task<int> UpdateAsync(IEnumerable<TEntity> entities)
{
return EntityContext.Updateable(entities.ToArray()).IgnoreColumns(UpdateIgnoreColumns).ExecuteCommandAsync();
}
public virtual IUpdateable<TEntity> AsUpdateable(TEntity entity)
{
return EntityContext.Updateable(entity).IgnoreColumns(UpdateIgnoreColumns);
}
public virtual IUpdateable<TEntity> AsUpdateable(IEnumerable<TEntity> entities)
{
return EntityContext.Updateable<TEntity>(entities).IgnoreColumns(UpdateIgnoreColumns);
}
#endregion
#region 删除
/// <summary>
/// 删除一条记录
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual int Delete(TEntity entity)
{
return EntityContext.Deleteable(entity).ExecuteCommand();
}
/// <summary>
/// 删除一条记录
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public virtual int Delete(object key)
{
return EntityContext.Deleteable<TEntity>().In(key).ExecuteCommand();
}
/// <summary>
/// 删除多条记录
/// </summary>
/// <param name="keys"></param>
/// <returns></returns>
public virtual int Delete(params object[] keys)
{
return EntityContext.Deleteable<TEntity>().In(keys).ExecuteCommand();
}
/// <summary>
/// 自定义条件删除记录
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public int Delete(Expression<Func<TEntity, bool>> whereExpression)
{
return EntityContext.Deleteable<TEntity>().Where(whereExpression).ExecuteCommand();
}
/// <summary>
/// 删除一条记录
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public virtual Task<int> DeleteAsync(TEntity entity)
{
return EntityContext.Deleteable(entity).ExecuteCommandAsync();
}
/// <summary>
/// 删除一条记录
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public virtual Task<int> DeleteAsync(object key)
{
return EntityContext.Deleteable<TEntity>().In(key).ExecuteCommandAsync();
}
/// <summary>
/// 删除多条记录
/// </summary>
/// <param name="keys"></param>
/// <returns></returns>
public virtual Task<int> DeleteAsync(params object[] keys)
{
return EntityContext.Deleteable<TEntity>().In(keys).ExecuteCommandAsync();
}
/// <summary>
/// 自定义条件删除记录
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public async Task<int> DeleteAsync(Expression<Func<TEntity, bool>> whereExpression)
{
return await EntityContext.Deleteable<TEntity>().Where(whereExpression).ExecuteCommandAsync();
}
#endregion
#region 其他
/// <summary>
/// 根据表达式查询多条记录
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public virtual ISugarQueryable<TEntity> Where(Expression<Func<TEntity, bool>> predicate)
{
return AsQueryable(predicate);
}
/// <summary>
/// 根据表达式查询多条记录
/// </summary>
/// <param name="condition"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public virtual ISugarQueryable<TEntity> Where(bool condition, Expression<Func<TEntity, bool>> predicate)
{
return AsQueryable().WhereIF(condition, predicate);
}
/// <summary>
/// 构建查询分析器
/// </summary>
/// <returns></returns>
public virtual ISugarQueryable<TEntity> AsQueryable()
{
return Entities;
}
/// <summary>
/// 构建查询分析器
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public virtual ISugarQueryable<TEntity> AsQueryable(Expression<Func<TEntity, bool>> predicate)
{
return Entities.Where(predicate);
}
/// <summary>
/// 直接返回数据库结果
/// </summary>
/// <returns></returns>
public virtual List<TEntity> AsEnumerable()
{
return AsQueryable().ToList();
}
/// <summary>
/// 直接返回数据库结果
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public virtual List<TEntity> AsEnumerable(Expression<Func<TEntity, bool>> predicate)
{
return AsQueryable(predicate).ToList();
}
/// <summary>
/// 直接返回数据库结果
/// </summary>
/// <returns></returns>
public virtual Task<List<TEntity>> AsAsyncEnumerable()
{
return AsQueryable().ToListAsync();
}
/// <summary>
/// 直接返回数据库结果
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public virtual Task<List<TEntity>> AsAsyncEnumerable(Expression<Func<TEntity, bool>> predicate)
{
return AsQueryable(predicate).ToListAsync();
}
public virtual bool IsExists(Expression<Func<TEntity, bool>> whereExpression)
{
return Entities.Any(whereExpression);
}
public virtual Task<bool> IsExistsAsync(Expression<Func<TEntity, bool>> whereExpression)
{
return Entities.AnyAsync(whereExpression);
}
#endregion
#region 仓储事务
/// <summary>
/// 切换仓储(注意使用环境)
/// </summary>
/// <typeparam name="T">实体类型</typeparam>
/// <returns>仓储</returns>
public virtual SqlSugarRepository<T> Change<T>()
where T : class, new()
{
return App.GetService<SqlSugarRepository<T>>();
}
/// <summary>
/// 当前db
/// </summary>
public void CurrentBeginTran()
{
Ado.BeginTran();
}
/// <summary>
/// 当前db
/// </summary>
public void CurrentCommitTran()
{
Ado.CommitTran();
}
/// <summary>
/// 当前db
/// </summary>
public void CurrentRollbackTran()
{
Ado.RollbackTran();
}
/// <summary>
/// 所有db
/// </summary>
public void BeginTran()
{
Context.BeginTran();
}
/// <summary>
/// 所有db
/// </summary>
public void CommitTran()
{
Context.CommitTran();
}
/// <summary>
/// 所有db
/// </summary>
public void RollbackTran()
{
Context.RollbackTran();
}
#endregion
}

@ -0,0 +1,181 @@
using CustomerBaoGuan.Core.DB;
using Furion;
using Furion.Logging.Extensions;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Linq.Expressions;
namespace CustomerBaoGuan.Core;
public static class SqlSugarSetup
{
/// <summary>
/// SqlsugarScope的配置
/// Scope必须用单例注入
/// 不可以用Action委托注入
/// </summary>
/// <param name="services"></param>
public static void SqlSugarScopeConfigure(this IServiceCollection services)
{
//数据库序号从0开始,默认数据库为0
var configList = App.GetConfig<List<ConnectionConfig>>("ConnectionConfigs");
List<Type> types = App.EffectiveTypes.Where(a => !a.IsAbstract && a.IsClass && a.GetCustomAttributes(typeof(SugarTable), true)?.FirstOrDefault() != null).ToList();
SqlSugarScope sqlSugarScope = new SqlSugarScope(configList,
//全局上下文生效
db =>
{
/*
* /
*/
foreach (var c in configList)
{
var dbProvider = db.GetConnectionScope((string)c.ConfigId);
//执行超时时间
dbProvider.Ado.CommandTimeOut = 30;
dbProvider.Aop.OnLogExecuting = (sql, pars) =>
{
$"DB:{c.ConfigId}, Sql:\r\n\r\n { UtilMethods.GetSqlString(c.DbType, sql, pars)}".LogInformation();
};
dbProvider.Aop.DataExecuting = (oldValue, entityInfo) =>
{
// 新增操作
if (entityInfo.OperationType == DataFilterType.InsertByObject)
{
// 主键(long)-赋值雪花Id
if (entityInfo.EntityColumnInfo.IsPrimarykey && entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(long))
{
var id = ((dynamic)entityInfo.EntityValue).Id;
if (id == null || id == 0)
entityInfo.SetValue(Yitter.IdGenerator.YitIdHelper.NextId());
}
if (entityInfo.PropertyName == "CreatedTime")
entityInfo.SetValue(DateTime.Now);
if (App.User != null)
{
if (entityInfo.PropertyName == "CompanyId")
{
var compId = ((dynamic)entityInfo.EntityValue).CompanyId;
if (string.IsNullOrEmpty(compId))
entityInfo.SetValue(App.User.FindFirst(ClaimConst.CompanyId)?.Value);
}
if (entityInfo.PropertyName == "CompanyName")
{
var compName = ((dynamic)entityInfo.EntityValue).CompanyName;
if (string.IsNullOrEmpty(compName))
entityInfo.SetValue(App.User.FindFirst(ClaimConst.CompanyName)?.Value);
}
if (entityInfo.PropertyName == "CreatedUserId")
{
var createUserId = ((dynamic)entityInfo.EntityValue).CreatedUserId;
if (string.IsNullOrEmpty(createUserId))
entityInfo.SetValue(App.User.FindFirst(ClaimConst.UserId)?.Value);
}
if (entityInfo.PropertyName == "CreatedUserName")
{
var CreatedUserName = ((dynamic)entityInfo.EntityValue).CreatedUserName;
if (string.IsNullOrEmpty(CreatedUserName))
entityInfo.SetValue(App.User.FindFirst(ClaimConst.Name)?.Value);
}
}
}
// 更新操作
if (entityInfo.OperationType == DataFilterType.UpdateByObject)
{
if (entityInfo.PropertyName == "UpdatedTime")
entityInfo.SetValue(DateTime.Now);
if (entityInfo.PropertyName == "UpdatedUserId")
{
var UpdatedUserId = ((dynamic)entityInfo.EntityValue).UpdatedUserId;
if (string.IsNullOrEmpty(UpdatedUserId))
entityInfo.SetValue(App.User?.FindFirst(ClaimConst.UserId)?.Value);
}
if (entityInfo.PropertyName == "UpdatedUserName")
{
var UpdatedUserName = ((dynamic)entityInfo.EntityValue).UpdatedUserName;
if (string.IsNullOrEmpty(UpdatedUserName))
entityInfo.SetValue(App.User?.FindFirst(ClaimConst.Name)?.Value);
}
}
};
//全局过滤器
foreach (var entityType in types)
{
// 配置加删除全局过滤器
if (entityType.GetProperty("IsDeleted")!=null)
{ //判断实体类中包含IsDeleted属性
//构建动态Lambda
var lambda = DynamicExpressionParser.ParseLambda
(new[] { Expression.Parameter(entityType, "it") },
typeof(bool), $"{nameof(EntityBase.IsDeleted)} == @0",
false);
dbProvider.QueryFilter.Add(new TableFilterItem<object>(entityType, lambda)
{
IsJoinQuery = true
}); //将Lambda传入过滤器
}
}
}
});
services.AddSingleton<ISqlSugarClient>(sqlSugarScope);
// 注册 SqlSugar 仓储
services.AddScoped(typeof(SqlSugarRepository<>));
}
/// <summary>
/// 添加 SqlSugar 拓展
/// </summary>
/// <param name="services"></param>
/// <param name="config"></param>
/// <param name="buildAction"></param>
/// <returns></returns>
public static IServiceCollection AddSqlSugar(this IServiceCollection services, ConnectionConfig config, Action<ISqlSugarClient> buildAction = default)
{
var list = new List<ConnectionConfig>();
list.Add(config);
return services.AddSqlSugar(list, buildAction);
}
/// <summary>
/// 添加 SqlSugar 拓展
/// </summary>
/// <param name="services"></param>
/// <param name="configs"></param>
/// <param name="buildAction"></param>
/// <returns></returns>
public static IServiceCollection AddSqlSugar(this IServiceCollection services, List<ConnectionConfig> configs, Action<ISqlSugarClient> buildAction = default)
{
// 注册 SqlSugar 客户端
services.AddScoped<ISqlSugarClient>(u =>
{
var db = new SqlSugarClient(configs);
buildAction?.Invoke(db);
return db;
});
// 注册 SqlSugar 仓储
services.AddScoped(typeof(SqlSugarRepository<>));
return services;
}
}

@ -4,5 +4,27 @@
<name>CustomerBaoGuan.Web.Core</name>
</assembly>
<members>
<member name="M:CustomerBaoGuan.Web.Core.JwtHandler.HandleAsync(Microsoft.AspNetCore.Authorization.AuthorizationHandlerContext)">
<summary>
重写 Handler 添加自动刷新
</summary>
<param name="context"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Web.Core.JwtHandler.PipelineAsync(Microsoft.AspNetCore.Authorization.AuthorizationHandlerContext,Microsoft.AspNetCore.Http.DefaultHttpContext)">
<summary>
授权判断逻辑,授权通过返回 true否则返回 false
</summary>
<param name="context"></param>
<param name="httpContext"></param>
<returns></returns>
</member>
<member name="M:CustomerBaoGuan.Web.Core.JwtHandler.CheckAuthorzieAsync(Microsoft.AspNetCore.Http.DefaultHttpContext)">
<summary>
检查权限
</summary>
<param name="httpContext"></param>
<returns></returns>
</member>
</members>
</doc>

@ -1,4 +1,6 @@
using Furion.Authorization;
using CustomerBaoGuan.Core;
using Furion.Authorization;
using Furion.DataEncryption;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
@ -7,11 +9,41 @@ namespace CustomerBaoGuan.Web.Core
{
public class JwtHandler : AppAuthorizeHandler
{
public override Task<bool> PipelineAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)
/// <summary>
/// 重写 Handler 添加自动刷新
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override async Task HandleAsync(AuthorizationHandlerContext context)
{
// 这里写您的授权判断逻辑,授权通过返回 true否则返回 false
// 自动刷新Token
if (JWTEncryption.AutoRefreshToken(context, context.GetCurrentHttpContext()))
{
await AuthorizeHandleAsync(context);
}
else context.Fail(); // 授权失败
}
return Task.FromResult(true);
/// <summary>
/// 授权判断逻辑,授权通过返回 true否则返回 false
/// </summary>
/// <param name="context"></param>
/// <param name="httpContext"></param>
/// <returns></returns>
public override async Task<bool> PipelineAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)
{
// 此处已经自动验证 Jwt Token的有效性了无需手动验证
return await CheckAuthorzieAsync(httpContext);
}
/// <summary>
/// 检查权限
/// </summary>
/// <param name="httpContext"></param>
/// <returns></returns>
private static async Task<bool> CheckAuthorzieAsync(DefaultHttpContext httpContext)
{
return !string.IsNullOrEmpty(UserManager.UserId);
}
}
}

@ -1,4 +1,5 @@
using CustomerBaoGuan.Core.ConfigOption;
using CustomerBaoGuan.Core;
using CustomerBaoGuan.Core.ConfigOption;
using Furion;
using Furion.VirtualFileServer;
using Microsoft.AspNetCore.Builder;
@ -17,7 +18,10 @@ namespace CustomerBaoGuan.Web.Core
services.AddConfigurableOptions<BaoGuanFileOptions>();
services.AddConsoleFormatter();
services.AddJwt<JwtHandler>();
services.AddJwt<JwtHandler>(enableGlobalAuthorize: true);
services.SqlSugarScopeConfigure();
services.AddCorsAccessor();

@ -10,15 +10,14 @@
"AllowedHosts": "*",
"ConnectionConfigs": [
{
"ConnectionString": "server=60.209.125.238,32009;uid=sa;pwd=sa@djy.net;database=TestPubliceData",
"DbType": "SqlServer",
"IsAutoCloseConnection": true
"ConfigId": "baoguan",
"ConnectionString": "server=60.209.125.238,32009;uid=sa;pwd=sa@djy.net;database=TestPubliceData;MultipleActiveResultSets=True;",
"DbType": "SqlServer"
},
{
"ConfigId": "myshipping",
"ConnectionString": "server=60.209.125.238,32009;uid=sa;pwd=sa@djy.net;database=DevDsPingTai",
"DbType": "SqlServer",
"IsAutoCloseConnection": true
"ConnectionString": "server=60.209.125.238,32009;uid=sa;pwd=sa@djy.net;database=DevDsPingTai;MultipleActiveResultSets=True;",
"DbType": "SqlServer"
}
],
"DjyAuthUrl": "http://60.209.125.238:40501"

Loading…
Cancel
Save