diff --git a/Myshipping.Application/Entity/BookingOrder.cs b/Myshipping.Application/Entity/BookingOrder.cs index 7ced34df..67ec330e 100644 --- a/Myshipping.Application/Entity/BookingOrder.cs +++ b/Myshipping.Application/Entity/BookingOrder.cs @@ -1009,5 +1009,15 @@ namespace Myshipping.Application.Entity /// public string IsBookingYZ { get; set; } + + /// + /// 最后格式单比对状态 NO_DIFF-无异常;DIFF-有差异; + /// + public string LstDraftCompareRlt { get; set; } + + /// + /// 最后格式单比对时间 + /// + public Nullable LstDraftCompareDate { get; set; } } } \ No newline at end of file diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index eb791e4c..3d5c10c3 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -986,6 +986,8 @@ namespace Myshipping.Application it.LstShipOrderCompareDate, it.LstShipOrderCompareRlt, it.LstShipOrderCompareRltName, + it.LstDraftCompareDate, + it.LstDraftCompareRlt, //it.ATD, it.ETA, //it.StartETA, diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index ed2643f3..cdff5608 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -521,7 +521,9 @@ namespace Myshipping.Application it.LstShipOrderCompareDate, it.LstShipOrderCompareRlt, it.LstShipOrderCompareRltName, - it.LstShipOrderCompareMode + it.LstShipOrderCompareMode, + it.LstDraftCompareRlt, + it.LstDraftCompareDate }).ExecuteCommandAsync(); await _bookingorderservice.SaveLog(it, old); await _bookingorderservice.SendBookingOrder(new long[] { it.Id }); diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/CompareDraftDataInfo.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/CompareDraftDataInfo.cs new file mode 100644 index 00000000..f63924b1 --- /dev/null +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/CompareDraftDataInfo.cs @@ -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 +{ + /// + /// Draft(格式单)比对请求 + /// + public class CompareDraftDataInfo + { + /// + /// 船名英文名 + /// + [Description("船名")] + public string VesselName { get; set; } + + /// + /// 航次号 + /// + [Description("航次")] + public string VoyNo { get; set; } + + /// + /// 主提单号 + /// + [Description("主提单号")] + public string MasterBlNo { get; set; } + + /// + /// 分提单号 + /// + [Description("分提单号")] + public string HouseBlNo { get; set; } + + /// + /// 订舱编号 + /// + [Description("订舱编号")] + public string BookingNo { get; set; } + + /// + /// 发货人 + /// + [Description("发货人")] + public string Shipper { get; set; } + + /// + /// 收货人 + /// + [Description("收货人")] + public string Consignee { get; set; } + + /// + /// 通知人 + /// + [Description("通知人")] + public string NotifyParty { get; set; } + + /// + /// 收货地 + /// + [Description("收货地")] + public string PlaceReceiptId { get; set; } + + /// + /// 收货地名称 + /// + [Description("收货地名称")] + public string PlaceReceipt { get; set; } + + /// + /// 装货港 + /// + [Description("装货港")] + public string PortLoadId { get; set; } + + /// + /// 装货港名称 + /// + [Description("装货港名称")] + public string PortLoad { get; set; } + + /// + /// 卸货港 + /// + [Description("卸货港")] + public string PortDischargeId { get; set; } + + /// + /// 卸货港名称 + /// + [Description("卸货港名称")] + public string PortDischarge { get; set; } + + /// + /// 交货地 + /// + [Description("交货地")] + public string PlaceDeliveryId { get; set; } + + /// + /// 交货地名称 + /// + [Description("交货地名称")] + public string PlaceDelivery { get; set; } + + /// + /// 唛头 + /// + [Description("唛头")] + public string Marks { get; set; } + + /// + /// 货描 + /// + [Description("货描")] + public string GoodsDescription { get; set; } + + /// + /// 运费 + /// + [Description("运费")] + public string Freight { get; set; } + + /// + /// 运费支付地点 + /// + [Description("运费支付地点")] + public string FreightPrepaidAt { get; set; } + + /// + /// 签单地点 + /// + [Description("签单地点")] + public string IssuePlaceId { get; set; } + + /// + /// 签单地点名称 + /// + [Description("签单地点名称")] + public string IssuePlace { get; set; } + + /// + /// 签单日期 + /// + [Description("签单日期")] + public string IssueDate { get; set; } + + /// + /// 汇率 + /// + [Description("汇率")] + public Nullable ExchangeRate { get; set; } + + /// + /// 提单份数 + /// + [Description("提单份数")] + public string NoBill { get; set; } + + /// + /// 提单签发时间 + /// + [Description("提单签发时间")] + public Nullable BLDate { get; set; } + + /// + /// 承运人公司 + /// + [Description("承运人公司")] + public string CarrierCompany { get; set; } + + /// + /// 件数 + /// + [Description("件数")] + public Int32 PKGs { get; set; } + + /// + /// 毛重 + /// + [Description("重量")] + public Nullable KGs { get; set; } + + /// + /// 体积 + /// + [Description("体积")] + public Nullable CBM { get; set; } + + /// + /// 包装 + /// + [Description("包装")] + public string KindPKGs { get; set; } + + /// + /// 箱明细 + /// + public List ContaList { get; set; } + } + + public class CompareDraftDataContaInfo + { + /// + /// 集装箱箱型代码 + /// + [Description("箱型")] + public string ContaType { get; set; } + + /// + /// 集装箱箱型名称 + /// + [Description("箱型名称")] + public string ContaTypeName { get; set; } + + /// + /// 集装箱箱号 + /// + [Description("箱号")] + public string ContaNo { get; set; } + + /// + /// 铅封号 + /// + [Description("铅封号")] + public string SealNo { get; set; } + + /// + /// 包装 + /// + [Description("包装")] + public string KindPKGs { get; set; } + + /// + /// 皮重 + /// + [Description("箱皮重")] + public Nullable TareWeight { get; set; } + + /// + /// 件数 + /// + [Description("箱件数")] + public Int32 PKGs { get; set; } + + /// + /// 毛重 + /// + [Description("箱重量")] + public Nullable KGs { get; set; } + + /// + /// 尺码 + /// + [Description("箱体积")] + public Nullable CBM { get; set; } + } +} diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskDraftCompareMessageInfo.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskDraftCompareMessageInfo.cs index 0f697685..4b74a213 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskDraftCompareMessageInfo.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskDraftCompareMessageInfo.cs @@ -23,6 +23,19 @@ namespace Myshipping.Application } public class TaskDraftMessageMainInfo + { + /// + /// Draft识别详情 + /// + public CompareDraftDataInfo DraftInfo { get; set; } + + /// + /// 业务详情 + /// + public BusinessInfo BusinessInfo { get; set; } + } + + public class BusinessInfo { /// /// 业务惟一主键 @@ -281,6 +294,7 @@ namespace Myshipping.Application public string GoodsDescription { get; set; } } + /// /// 箱信息 /// diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskDraftCompareService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskDraftCompareService.cs index ca527c74..b0774a7c 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskDraftCompareService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskDraftCompareService.cs @@ -16,6 +16,7 @@ using Myshipping.Application.Entity; using Myshipping.Core; using Myshipping.Core.Entity; using Myshipping.Core.Service; +using Org.BouncyCastle.Asn1.X9; using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -74,31 +75,100 @@ namespace Myshipping.Application TaskManageExcuteResultDto result = new TaskManageExcuteResultDto(); + DateTime nowDate = DateTime.Now; /* 1、接收报文里的文件信息,优先写入本地文件暂存。 - 2、判断对应的订舱提单号。如果没有对应的订舱提单号,则写入任务表失败记录。 - 3、写入任务表。 - 4、异步请求格式单比对接口。 - 5、接收比对结果更新任务表。 - 6、更新订舱表,并更新状态。 + 2、请求解析Draft文件解析,并等待解析结果。 + 3、判断对应的订舱提单号。如果没有对应的订舱提单号,则写入任务表失败记录。 + 4、写入任务表。 + 5、异步请求格式单比对接口。 + 6、接收比对结果更新任务表。 + 7、更新订舱表,并更新状态。 */ try { var model = GetJsonMessageInfo(jsonData, batchNo); - var bookingOrder = _bookingOrderRepository.AsQueryable().Filter(null, true) - .First(a => a.MBLNO.Equals(model.Main.MBlNo)); + 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", + } + }; - if (model == null) - throw Oops.Oh($"提单号{model.Main.MBlNo}无法获取业务信息"); + //附件暂存 + var fileFullName = await FileAttachHelper.TempSaveWebFile(model.Head.GID, file, batchNo, CONST_DRAFT_FILE_CODE); - _logger.LogInformation("批次={no}获取订舱数据完成", batchNo); + //Draft文件解析 + NameValueCollection par = new NameValueCollection(); + par.Add("jsonMessage", JSON.Serialize(readFileMessageInfo)); - //附件暂存 - var fileFullName = await FileAttachHelper.TempSaveWebFile(bookingOrder.Id.ToString(), file, batchNo, CONST_DRAFT_FILE_CODE); + byte[] bytes = file.ToByteArray(); - DateTime nowDate = DateTime.Now; + 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(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) + .First(a => a.MBLNO.Equals(billNo)); + + if (model == null) + { + _logger.LogInformation("批次={no} 提单号{billNo}无法获取业务信息", batchNo, billNo); + + throw Oops.Oh($"提单号{billNo}无法获取业务信息"); + } + + _logger.LogInformation("批次={no}获取订舱数据完成", batchNo); + TaskDraftCompareMessageInfo msgModel = new TaskDraftCompareMessageInfo { Head = new TaskMessageHead { @@ -111,11 +181,12 @@ namespace Myshipping.Application Version = "1.0", RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"), RequestAction = "Compare", - } + }, + Main = new TaskDraftMessageMainInfo() }; //请求格式单比对接口 - var mainInfo = bookingOrder.Adapt(); + var mainInfo = bookingOrder.Adapt(); var userInfo = _sysUserRepository.AsQueryable().First(a => a.Id == bookingOrder.CreatedUserId); @@ -134,34 +205,40 @@ namespace Myshipping.Application mainInfo.ContaList = contaList.Adapt>(); } - 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(); - par.Add("jsonMessage", JSON.Serialize(msgModel)); + var compareResult = await ExcuteDraftCompare(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 - { - file = "file", - fileName = file.FileName, - fileBytes = bytes - }); + _logger.LogInformation("批次={no} 对应请求报文完成 msg={msg}", batchNo, JSON.Serialize(msgModel)); - DateTime eDate = DateTime.Now; - TimeSpan ts = eDate.Subtract(bDate); - var timeDiff = ts.TotalMilliseconds; + var entity = _bookingOrderRepository.AsQueryable().Filter(null, true) + .First(a => a.Id == bookingOrder.Id); + + 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); - //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); @@ -199,16 +276,16 @@ namespace Myshipping.Application } #endregion - #region 请求格式单比对 + #region 解析格式单文件 /// - /// 请求格式单比对 + /// 解析格式单文件 /// /// 请求参数 /// 文件 /// 请求类型 /// 返回回执 [NonAction] - private async Task ExcuteCompare(NameValueCollection nameValueCollection, dynamic fileInfo, + private async Task ExcuteReadPDF(NameValueCollection nameValueCollection, dynamic fileInfo, string contentType = "application/json") { TaskManageExcuteResultDto model = null; @@ -252,7 +329,7 @@ namespace Myshipping.Application #endregion //请求 - var response = httpClient.PostAsync(App.Configuration["DraftCompareUrl"], reduceAttach).Result; + var response = httpClient.PostAsync(App.Configuration["DraftReadUrl"], reduceAttach).Result; result = response.Content.ReadAsStringAsync().Result; model = JSON.Deserialize(result); @@ -271,6 +348,47 @@ namespace Myshipping.Application } #endregion + #region 请求格式单比对 + /// + /// 请求格式单比对 + /// + /// 请求报文 + /// + private async Task 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(userResult); + } + } + catch (Exception ex) + { + //写日志 + if (ex is HttpRequestException) + throw Oops.Oh(10000002); + } + + return model; + } + #endregion + #region 异步写入订舱附件表 /// /// 异步写入订舱附件表 @@ -334,7 +452,9 @@ namespace Myshipping.Application RequestAction = "Compare", }, Main = new TaskDraftMessageMainInfo { - BusiPKId = bookingId.ToString() + BusinessInfo = new BusinessInfo { + BusiPKId = bookingId.ToString() + } } }; diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageCompareMapper.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageCompareMapper.cs index f79c67b3..bb031198 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageCompareMapper.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageCompareMapper.cs @@ -49,7 +49,7 @@ namespace Myshipping.Application .Map(dest => dest.KGs, src => src.KGS) .Map(dest => dest.CBM, src => src.CBM); - config.ForType() + config.ForType() .Map(dest => dest.BookingNo, src => src.BOOKINGNO) .Map(dest => dest.TenantId, src => src.TenantId) .Map(dest => dest.TenantName, src => src.TenantName) diff --git a/Myshipping.Web.Core/applicationconfig.json b/Myshipping.Web.Core/applicationconfig.json index ab88dbd2..47f89bae 100644 --- a/Myshipping.Web.Core/applicationconfig.json +++ b/Myshipping.Web.Core/applicationconfig.json @@ -128,5 +128,6 @@ "BCOrDraftUserSecret": "228b2db5952d13291f228d441018c1b6", "ServiceStatusOpenAuto": "0", "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" } \ No newline at end of file diff --git a/ServiceProjectSyncWin/Program.cs b/ServiceProjectSyncWin/Program.cs index 2d2bb9bb..55eb651f 100644 --- a/ServiceProjectSyncWin/Program.cs +++ b/ServiceProjectSyncWin/Program.cs @@ -1 +1,103 @@ -Serve.Run(); \ No newline at end of file +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() + 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((gs, cfg) => gs.ConfigId == cfg.Id) + .InnerJoin((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); + } + + */ + } +} \ No newline at end of file diff --git a/ServiceProjectSyncWin/ServiceProjectSyncWin.csproj b/ServiceProjectSyncWin/ServiceProjectSyncWin.csproj index 8a1b2ea6..286dfa60 100644 --- a/ServiceProjectSyncWin/ServiceProjectSyncWin.csproj +++ b/ServiceProjectSyncWin/ServiceProjectSyncWin.csproj @@ -8,7 +8,14 @@ - + + + + + + + Always + diff --git a/ServiceProjectSyncWin/SqlsugarSetup.cs b/ServiceProjectSyncWin/SqlsugarSetup.cs new file mode 100644 index 00000000..6f25487b --- /dev/null +++ b/ServiceProjectSyncWin/SqlsugarSetup.cs @@ -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 + 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(sqlSugar);//这边是SqlSugarScope用AddSingleton + } + } +} diff --git a/ServiceProjectSyncWin/appsettings.json b/ServiceProjectSyncWin/appsettings.json new file mode 100644 index 00000000..d625d3a6 --- /dev/null +++ b/ServiceProjectSyncWin/appsettings.json @@ -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;" + } +} \ No newline at end of file