修改格式单比对功能,修改服务同步服务

optimize
jianghaiqing 1 year ago
parent 130cb1c06f
commit bb00bd43d1

@ -1009,5 +1009,15 @@ namespace Myshipping.Application.Entity
/// </summary> /// </summary>
public string IsBookingYZ { get; set; } public string IsBookingYZ { get; set; }
/// <summary>
/// 最后格式单比对状态 NO_DIFF-无异常;DIFF-有差异;
/// </summary>
public string LstDraftCompareRlt { get; set; }
/// <summary>
/// 最后格式单比对时间
/// </summary>
public Nullable<DateTime> LstDraftCompareDate { get; set; }
} }
} }

@ -986,6 +986,8 @@ namespace Myshipping.Application
it.LstShipOrderCompareDate, it.LstShipOrderCompareDate,
it.LstShipOrderCompareRlt, it.LstShipOrderCompareRlt,
it.LstShipOrderCompareRltName, it.LstShipOrderCompareRltName,
it.LstDraftCompareDate,
it.LstDraftCompareRlt,
//it.ATD, //it.ATD,
it.ETA, it.ETA,
//it.StartETA, //it.StartETA,

@ -521,7 +521,9 @@ namespace Myshipping.Application
it.LstShipOrderCompareDate, it.LstShipOrderCompareDate,
it.LstShipOrderCompareRlt, it.LstShipOrderCompareRlt,
it.LstShipOrderCompareRltName, it.LstShipOrderCompareRltName,
it.LstShipOrderCompareMode it.LstShipOrderCompareMode,
it.LstDraftCompareRlt,
it.LstDraftCompareDate
}).ExecuteCommandAsync(); }).ExecuteCommandAsync();
await _bookingorderservice.SaveLog(it, old); await _bookingorderservice.SaveLog(it, old);
await _bookingorderservice.SendBookingOrder(new long[] { it.Id }); await _bookingorderservice.SendBookingOrder(new long[] { it.Id });

@ -0,0 +1,263 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// Draft(格式单)比对请求
/// </summary>
public class CompareDraftDataInfo
{
/// <summary>
/// 船名英文名
/// </summary>
[Description("船名")]
public string VesselName { get; set; }
/// <summary>
/// 航次号
/// </summary>
[Description("航次")]
public string VoyNo { get; set; }
/// <summary>
/// 主提单号
/// </summary>
[Description("主提单号")]
public string MasterBlNo { get; set; }
/// <summary>
/// 分提单号
/// </summary>
[Description("分提单号")]
public string HouseBlNo { get; set; }
/// <summary>
/// 订舱编号
/// </summary>
[Description("订舱编号")]
public string BookingNo { get; set; }
/// <summary>
/// 发货人
/// </summary>
[Description("发货人")]
public string Shipper { get; set; }
/// <summary>
/// 收货人
/// </summary>
[Description("收货人")]
public string Consignee { get; set; }
/// <summary>
/// 通知人
/// </summary>
[Description("通知人")]
public string NotifyParty { get; set; }
/// <summary>
/// 收货地
/// </summary>
[Description("收货地")]
public string PlaceReceiptId { get; set; }
/// <summary>
/// 收货地名称
/// </summary>
[Description("收货地名称")]
public string PlaceReceipt { get; set; }
/// <summary>
/// 装货港
/// </summary>
[Description("装货港")]
public string PortLoadId { get; set; }
/// <summary>
/// 装货港名称
/// </summary>
[Description("装货港名称")]
public string PortLoad { get; set; }
/// <summary>
/// 卸货港
/// </summary>
[Description("卸货港")]
public string PortDischargeId { get; set; }
/// <summary>
/// 卸货港名称
/// </summary>
[Description("卸货港名称")]
public string PortDischarge { get; set; }
/// <summary>
/// 交货地
/// </summary>
[Description("交货地")]
public string PlaceDeliveryId { get; set; }
/// <summary>
/// 交货地名称
/// </summary>
[Description("交货地名称")]
public string PlaceDelivery { get; set; }
/// <summary>
/// 唛头
/// </summary>
[Description("唛头")]
public string Marks { get; set; }
/// <summary>
/// 货描
/// </summary>
[Description("货描")]
public string GoodsDescription { get; set; }
/// <summary>
/// 运费
/// </summary>
[Description("运费")]
public string Freight { get; set; }
/// <summary>
/// 运费支付地点
/// </summary>
[Description("运费支付地点")]
public string FreightPrepaidAt { get; set; }
/// <summary>
/// 签单地点
/// </summary>
[Description("签单地点")]
public string IssuePlaceId { get; set; }
/// <summary>
/// 签单地点名称
/// </summary>
[Description("签单地点名称")]
public string IssuePlace { get; set; }
/// <summary>
/// 签单日期
/// </summary>
[Description("签单日期")]
public string IssueDate { get; set; }
/// <summary>
/// 汇率
/// </summary>
[Description("汇率")]
public Nullable<decimal> ExchangeRate { get; set; }
/// <summary>
/// 提单份数
/// </summary>
[Description("提单份数")]
public string NoBill { get; set; }
/// <summary>
/// 提单签发时间
/// </summary>
[Description("提单签发时间")]
public Nullable<DateTime> BLDate { get; set; }
/// <summary>
/// 承运人公司
/// </summary>
[Description("承运人公司")]
public string CarrierCompany { get; set; }
/// <summary>
/// 件数
/// </summary>
[Description("件数")]
public Int32 PKGs { get; set; }
/// <summary>
/// 毛重
/// </summary>
[Description("重量")]
public Nullable<decimal> KGs { get; set; }
/// <summary>
/// 体积
/// </summary>
[Description("体积")]
public Nullable<decimal> CBM { get; set; }
/// <summary>
/// 包装
/// </summary>
[Description("包装")]
public string KindPKGs { get; set; }
/// <summary>
/// 箱明细
/// </summary>
public List<CompareDraftDataContaInfo> ContaList { get; set; }
}
public class CompareDraftDataContaInfo
{
/// <summary>
/// 集装箱箱型代码
/// </summary>
[Description("箱型")]
public string ContaType { get; set; }
/// <summary>
/// 集装箱箱型名称
/// </summary>
[Description("箱型名称")]
public string ContaTypeName { get; set; }
/// <summary>
/// 集装箱箱号
/// </summary>
[Description("箱号")]
public string ContaNo { get; set; }
/// <summary>
/// 铅封号
/// </summary>
[Description("铅封号")]
public string SealNo { get; set; }
/// <summary>
/// 包装
/// </summary>
[Description("包装")]
public string KindPKGs { get; set; }
/// <summary>
/// 皮重
/// </summary>
[Description("箱皮重")]
public Nullable<decimal> TareWeight { get; set; }
/// <summary>
/// 件数
/// </summary>
[Description("箱件数")]
public Int32 PKGs { get; set; }
/// <summary>
/// 毛重
/// </summary>
[Description("箱重量")]
public Nullable<decimal> KGs { get; set; }
/// <summary>
/// 尺码
/// </summary>
[Description("箱体积")]
public Nullable<decimal> CBM { get; set; }
}
}

@ -23,6 +23,19 @@ namespace Myshipping.Application
} }
public class TaskDraftMessageMainInfo public class TaskDraftMessageMainInfo
{
/// <summary>
/// Draft识别详情
/// </summary>
public CompareDraftDataInfo DraftInfo { get; set; }
/// <summary>
/// 业务详情
/// </summary>
public BusinessInfo BusinessInfo { get; set; }
}
public class BusinessInfo
{ {
/// <summary> /// <summary>
/// 业务惟一主键 /// 业务惟一主键
@ -281,6 +294,7 @@ namespace Myshipping.Application
public string GoodsDescription { get; set; } public string GoodsDescription { get; set; }
} }
/// <summary> /// <summary>
/// 箱信息 /// 箱信息
/// </summary> /// </summary>

@ -16,6 +16,7 @@ using Myshipping.Application.Entity;
using Myshipping.Core; using Myshipping.Core;
using Myshipping.Core.Entity; using Myshipping.Core.Entity;
using Myshipping.Core.Service; using Myshipping.Core.Service;
using Org.BouncyCastle.Asn1.X9;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
@ -74,30 +75,99 @@ namespace Myshipping.Application
TaskManageExcuteResultDto result = new TaskManageExcuteResultDto(); TaskManageExcuteResultDto result = new TaskManageExcuteResultDto();
DateTime nowDate = DateTime.Now;
/* /*
1 1
2 2Draft
3 3
4 4
5 5
6 6
7
*/ */
try try
{ {
var model = GetJsonMessageInfo(jsonData, batchNo); var model = GetJsonMessageInfo(jsonData, batchNo);
TaskDraftCompareMessageInfo readFileMessageInfo = new TaskDraftCompareMessageInfo
{
Head = new TaskMessageHead
{
GID = batchNo,
MessageType = "DRAFT_COMPARE",
SenderId = App.Configuration["RulesEngineSender"],
SenderName = App.Configuration["RulesEngineSenderName"],
ReceiverId = "RulesEngine",
ReceiverName = "大简云规则引擎",
Version = "1.0",
RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"),
RequestAction = "Compare",
}
};
//附件暂存
var fileFullName = await FileAttachHelper.TempSaveWebFile(model.Head.GID, file, batchNo, CONST_DRAFT_FILE_CODE);
//Draft文件解析
NameValueCollection par = new NameValueCollection();
par.Add("jsonMessage", JSON.Serialize(readFileMessageInfo));
byte[] bytes = file.ToByteArray();
DateTime bDate = DateTime.Now;
var readResult = await ExcuteReadPDF(par, new
{
file = "file",
fileName = file.FileName,
fileBytes = bytes
});
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} 请求Draft文件解析完成,耗时:{timeDiff}ms. 结果{msg} 报文={message}", batchNo, timeDiff,
readResult.succ ? "成功" : "失败",
JSON.Serialize(readResult));
if(!readResult.succ)
{
_logger.LogInformation("批次={no} 请求Draft文件解析失败 原因={reason}", batchNo, readResult.msg);
throw Oops.Oh($"请求Draft文件解析失败 原因={readResult.msg}");
}
//通过解析提单号匹配订舱的详情
var readModel = JSON.Deserialize<CompareDraftDataInfo>(JSON.Serialize(readResult.extra));
string billNo = string.Empty;
if(!string.IsNullOrWhiteSpace(readModel.MasterBlNo))
{
billNo = readModel.MasterBlNo;
}
if(string.IsNullOrWhiteSpace(billNo))
{
_logger.LogInformation("批次={no} 请求Draft文件解析未获取到有效提单号", batchNo);
throw Oops.Oh($"请求Draft文件解析未获取到有效提单号");
}
var bookingOrder = _bookingOrderRepository.AsQueryable().Filter(null, true) var bookingOrder = _bookingOrderRepository.AsQueryable().Filter(null, true)
.First(a => a.MBLNO.Equals(model.Main.MBlNo)); .First(a => a.MBLNO.Equals(billNo));
if (model == null) if (model == null)
throw Oops.Oh($"提单号{model.Main.MBlNo}无法获取业务信息"); {
_logger.LogInformation("批次={no} 提单号{billNo}无法获取业务信息", batchNo, billNo);
_logger.LogInformation("批次={no}获取订舱数据完成", batchNo);
//附件暂存 throw Oops.Oh($"提单号{billNo}无法获取业务信息");
var fileFullName = await FileAttachHelper.TempSaveWebFile(bookingOrder.Id.ToString(), file, batchNo, CONST_DRAFT_FILE_CODE); }
DateTime nowDate = DateTime.Now; _logger.LogInformation("批次={no}获取订舱数据完成", batchNo);
TaskDraftCompareMessageInfo msgModel = new TaskDraftCompareMessageInfo { TaskDraftCompareMessageInfo msgModel = new TaskDraftCompareMessageInfo {
Head = new TaskMessageHead Head = new TaskMessageHead
@ -111,11 +181,12 @@ namespace Myshipping.Application
Version = "1.0", Version = "1.0",
RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"), RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"),
RequestAction = "Compare", RequestAction = "Compare",
} },
Main = new TaskDraftMessageMainInfo()
}; };
//请求格式单比对接口 //请求格式单比对接口
var mainInfo = bookingOrder.Adapt<TaskDraftMessageMainInfo>(); var mainInfo = bookingOrder.Adapt<BusinessInfo>();
var userInfo = _sysUserRepository.AsQueryable().First(a => a.Id == bookingOrder.CreatedUserId); var userInfo = _sysUserRepository.AsQueryable().First(a => a.Id == bookingOrder.CreatedUserId);
@ -134,34 +205,40 @@ namespace Myshipping.Application
mainInfo.ContaList = contaList.Adapt<List<TaskDraftMessageCtnInfo>>(); mainInfo.ContaList = contaList.Adapt<List<TaskDraftMessageCtnInfo>>();
} }
msgModel.Main = mainInfo; msgModel.Main.BusinessInfo = mainInfo;
_logger.LogInformation("批次={no} 对应请求报文完成 msg={msg}", batchNo, JSON.Serialize(msgModel)); //推送Draft比对
DateTime bCompareDate = DateTime.Now;
NameValueCollection par = new NameValueCollection(); var compareResult = await ExcuteDraftCompare(msgModel);
par.Add("jsonMessage", JSON.Serialize(msgModel));
byte[] bytes = file.ToByteArray(); DateTime eCompareDate = DateTime.Now;
TimeSpan tsCompare = bCompareDate.Subtract(eCompareDate);
var timeDiffCompare = tsCompare.TotalMilliseconds;
DateTime bDate = DateTime.Now; _logger.LogInformation("批次={no} 请求Draft比对完成,耗时:{timeDiff}ms. 结果{msg} 报文={message}", batchNo, timeDiffCompare,
compareResult.succ ? "成功" : "失败",
JSON.Serialize(compareResult));
var compareResult = await ExcuteCompare(par, new _logger.LogInformation("批次={no} 对应请求报文完成 msg={msg}", batchNo, JSON.Serialize(msgModel));
{
file = "file",
fileName = file.FileName,
fileBytes = bytes
});
DateTime eDate = DateTime.Now; var entity = _bookingOrderRepository.AsQueryable().Filter(null, true)
TimeSpan ts = eDate.Subtract(bDate); .First(a => a.Id == bookingOrder.Id);
var timeDiff = ts.TotalMilliseconds;
entity.LstDraftCompareRlt = compareResult.extra2.Any(a => a.IsDiff) ? "DIFF" : "";
entity.LstDraftCompareDate = nowDate;
_logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg}", batchNo, timeDiff, compareResult.succ ? "成功" : "失败"); //更新订舱相关
await _bookingOrderRepository.AsUpdateable(entity).UpdateColumns(it => new
{
it.LstDraftCompareDate,
it.LstDraftCompareRlt
}).ExecuteCommandAsync();
//如果确认文件读取成功 //如果确认文件读取成功
var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), fileFullName, batchNo); var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), fileFullName, batchNo);
//new System.IO.FileInfo(bookFilePath).Name
//将格式单附件写入订舱的附件 //将格式单附件写入订舱的附件
await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(fileFullName).Name, CONST_DRAFT_FILE_CODE, CONST_DRAFT_FILE_NAME); await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(fileFullName).Name, CONST_DRAFT_FILE_CODE, CONST_DRAFT_FILE_NAME);
@ -199,16 +276,16 @@ namespace Myshipping.Application
} }
#endregion #endregion
#region 请求格式单比对 #region 解析格式单文件
/// <summary> /// <summary>
/// 请求格式单比对 /// 解析格式单文件
/// </summary> /// </summary>
/// <param name="nameValueCollection">请求参数</param> /// <param name="nameValueCollection">请求参数</param>
/// <param name="fileInfo">文件</param> /// <param name="fileInfo">文件</param>
/// <param name="contentType">请求类型</param> /// <param name="contentType">请求类型</param>
/// <returns>返回回执</returns> /// <returns>返回回执</returns>
[NonAction] [NonAction]
private async Task<TaskManageExcuteResultDto> ExcuteCompare(NameValueCollection nameValueCollection, dynamic fileInfo, private async Task<TaskManageExcuteResultDto> ExcuteReadPDF(NameValueCollection nameValueCollection, dynamic fileInfo,
string contentType = "application/json") string contentType = "application/json")
{ {
TaskManageExcuteResultDto model = null; TaskManageExcuteResultDto model = null;
@ -252,7 +329,7 @@ namespace Myshipping.Application
#endregion #endregion
//请求 //请求
var response = httpClient.PostAsync(App.Configuration["DraftCompareUrl"], reduceAttach).Result; var response = httpClient.PostAsync(App.Configuration["DraftReadUrl"], reduceAttach).Result;
result = response.Content.ReadAsStringAsync().Result; result = response.Content.ReadAsStringAsync().Result;
model = JSON.Deserialize<TaskManageExcuteResultDto>(result); model = JSON.Deserialize<TaskManageExcuteResultDto>(result);
@ -271,6 +348,47 @@ namespace Myshipping.Application
} }
#endregion #endregion
#region 请求格式单比对
/// <summary>
/// 请求格式单比对
/// </summary>
/// <param name="info">请求报文</param>
/// <returns></returns>
private async Task<TaskManageExcuteResultDto> ExcuteDraftCompare(TaskDraftCompareMessageInfo info)
{
TaskManageExcuteResultDto model = null;
var url = App.Configuration["DraftCompareUrl"];
try
{
var res = await url.SetHttpMethod(HttpMethod.Post)
.SetBody(JSON.Serialize(info), "application/json")
.SetContentEncoding(Encoding.UTF8)
.PostAsync();
_logger.LogInformation("批次={no} 对应请求报文完成 res={res}", info.Head.GID, JSON.Serialize(res));
if (res.StatusCode == System.Net.HttpStatusCode.OK)
{
var userResult = await res.Content.ReadAsStringAsync();
_logger.LogInformation("对应请求报文 userResult={userResult}", userResult);
model = JSON.Deserialize<TaskManageExcuteResultDto>(userResult);
}
}
catch (Exception ex)
{
//写日志
if (ex is HttpRequestException)
throw Oops.Oh(10000002);
}
return model;
}
#endregion
#region 异步写入订舱附件表 #region 异步写入订舱附件表
/// <summary> /// <summary>
/// 异步写入订舱附件表 /// 异步写入订舱附件表
@ -334,8 +452,10 @@ namespace Myshipping.Application
RequestAction = "Compare", RequestAction = "Compare",
}, },
Main = new TaskDraftMessageMainInfo { Main = new TaskDraftMessageMainInfo {
BusinessInfo = new BusinessInfo {
BusiPKId = bookingId.ToString() BusiPKId = bookingId.ToString()
} }
}
}; };
_logger.LogInformation($"开始请求查询 msg={JSON.Serialize(msgModel)}"); _logger.LogInformation($"开始请求查询 msg={JSON.Serialize(msgModel)}");

@ -49,7 +49,7 @@ namespace Myshipping.Application
.Map(dest => dest.KGs, src => src.KGS) .Map(dest => dest.KGs, src => src.KGS)
.Map(dest => dest.CBM, src => src.CBM); .Map(dest => dest.CBM, src => src.CBM);
config.ForType<BookingOrder, TaskDraftMessageMainInfo>() config.ForType<BookingOrder, BusinessInfo>()
.Map(dest => dest.BookingNo, src => src.BOOKINGNO) .Map(dest => dest.BookingNo, src => src.BOOKINGNO)
.Map(dest => dest.TenantId, src => src.TenantId) .Map(dest => dest.TenantId, src => src.TenantId)
.Map(dest => dest.TenantName, src => src.TenantName) .Map(dest => dest.TenantName, src => src.TenantName)

@ -128,5 +128,6 @@
"BCOrDraftUserSecret": "228b2db5952d13291f228d441018c1b6", "BCOrDraftUserSecret": "228b2db5952d13291f228d441018c1b6",
"ServiceStatusOpenAuto": "0", "ServiceStatusOpenAuto": "0",
"DraftCompareUrl": "http://localhost:5110/api/TaskDraftCompare/ExcuteDraftCompare", "DraftCompareUrl": "http://localhost:5110/api/TaskDraftCompare/ExcuteDraftCompare",
"GetDraftCompareUrl": "http://localhost:5110/api/TaskDraftCompare/DraftCompareResult" "GetDraftCompareUrl": "http://localhost:5110/api/TaskDraftCompare/DraftCompareResult",
"DraftReadUrl": "http://localhost:5110/api/TaskDraftCompare/ExcuteDraftFileRead"
} }

@ -1 +1,103 @@
Serve.Run(); using Furion;
using Furion.DatabaseAccessor;
using Microsoft.Extensions.DependencyInjection;
using ServiceProjectSyncWin;
using SqlSugar;
Serve.RunGeneric(additional: services =>
{
services.AddRemoteRequest();
services.AddSqlsugarSetup(App.Configuration);
}, true, true);
Console.WriteLine("开始准备同步历史服务状态数据");
Console.ReadKey();
public class SyncHisRecord
{
SqlSugar.ISqlSugarClient _db;
public SyncHisRecord(ISqlSugarClient db)
{
_db = db;
}
public void SyncServiceProjectRecord()
{
/*
//_db.Queryable<Order>()
var tenantInfo = _sysTenantRepository.AsQueryable().Filter(null, true).First(a => a.Id == tenantId);
/*
1
2
3
4
maxId = _serviceStatusBookingSyncHisInfoRepository.AsQueryable().Max(a => a.ORG_STATUS_ID);
_logger.LogInformation("批次={no} 获取最后同步服务状态的ID={maxId}", batchNo, maxId);
int takeNum = 1000;
while (true)
{
var takeList = _bookingGoodsStatusRepository.AsQueryable().Filter(null, true)
.InnerJoin<BookingGoodsStatusConfig>((gs, cfg) => gs.ConfigId == cfg.Id)
.InnerJoin<BookingOrder>((gs, cfg, bk) => gs.bookingId == bk.Id)
.Where((gs, cfg, bk) =>
gs.FinishTime.HasValue && gs.TenantId == tenantId
&& !bk.IsDeleted && gs.FinishUserId != 142307070910551
&& (maxId == 0 || gs.Id > maxId))
.OrderBy((gs, cfg, bk) => gs.Id)
.Select((gs, cfg, bk) => new { GS = gs, CFG = cfg, BK = bk })
.Take(takeNum).ToList();
totalSyncNum += takeList.Count;
_logger.LogInformation("批次={no} 同步待处理任务 totalSyncNum={totalSyncNum}", batchNo, totalSyncNum);
//没有记录跳出循环
if (takeList.Count == 0)
break;
maxId = takeList.Max(a => a.GS.Id);
_logger.LogInformation("批次={no} 获取最后同步服务状态的 maxId={maxId}", batchNo, maxId);
//写入记录表
takeList.ForEach(async record => {
var entity = new ServiceStatusBookingSyncHisInfo
{
PK_ID = IDGen.NextID().ToString(),
ORG_STATUS_ID = record.GS.Id,
BOOKING_ID = record.BK.Id,
FINISH_TIME = record.GS.FinishTime.Value,
FINISH_USER_ID = record.GS.FinishUserId.Value,
FINISH_USER_NAME = record.GS.FinishUser,
MBL_NO = record.BK.MBLNO,
SORT_NO = record.CFG.Sort,
STATUS_SKU_CODE = record.CFG.SystemCode,
STATUS_SKU_NAME = record.CFG.StatusName,
STATUS_REMARK = record.GS.Remark,
STATUS_VAL = record.GS.ExtData,
TENANT_ID = record.GS.TenantId.Value,
TENANT_NAME = tenantInfo.Name,
VESSEL = record.BK.VESSEL,
VOYNO = record.BK.VOYNO,
};
await _serviceStatusBookingSyncHisInfoRepository.InsertAsync(entity);
succSyncNum++;
});
Thread.Sleep(500);
}
*/
}
}

@ -8,7 +8,14 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Furion" Version="4.3.9" /> <PackageReference Include="Furion" Version="4.8.8.40" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.102" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -0,0 +1,37 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServiceProjectSyncWin
{
public static class SqlsugarSetup
{
public static void AddSqlsugarSetup(this IServiceCollection services, IConfiguration configuration, string dbName = "db_master")
{
//如果多个数数据库传 List<ConnectionConfig>
var configConnection = new ConnectionConfig()
{
DbType = SqlSugar.DbType.MySql,
ConnectionString = configuration.GetConnectionString(dbName),
IsAutoCloseConnection = true,
};
SqlSugarScope sqlSugar = new SqlSugarScope(configConnection,
db =>
{
//单例参数配置,所有上下文生效
db.Aop.OnLogExecuting = (sql, pars) =>
{
//Console.WriteLine(sql);//输出sql
};
});
services.AddSingleton<ISqlSugarClient>(sqlSugar);//这边是SqlSugarScope用AddSingleton
}
}
}

@ -0,0 +1,5 @@
{
"ConnectionStrings": {
"db_master": "Data Source=60.209.125.238;Database=booking_hechuan_dev;User ID=root;Password=Djy@Mysql.test;pooling=true;port=32006;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;"
}
}
Loading…
Cancel
Save