|
|
|
|
using Myshipping.Core;
|
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Furion;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Furion.DataEncryption;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Furion.FriendlyException;
|
|
|
|
|
using Furion.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Myshipping.Application.ConfigOption;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Yitter.IdGenerator;
|
|
|
|
|
using Myshipping.Core.Entity;
|
|
|
|
|
using Furion.RemoteRequest.Extensions;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
|
using Myshipping.Application.Service.DataSync.Dto;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数据同步服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings("Application", Name = "DataSync", Order = 1), AllowAnonymous]
|
|
|
|
|
public class DataSyncService : IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<BookingOrderService> _logger;
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
private readonly SqlSugarRepository<BookingOrder> _rep;
|
|
|
|
|
private readonly SqlSugarRepository<BookingCtn> _repCtn;
|
|
|
|
|
private readonly SqlSugarRepository<SysUser> _repUser;
|
|
|
|
|
private readonly SqlSugarRepository<SysTenant> _repTenant;
|
|
|
|
|
private readonly SqlSugarRepository<DjyCustomer> _djycustomer;
|
|
|
|
|
private readonly SqlSugarRepository<DjyCustomerContact> _djycustomercontact;
|
|
|
|
|
private readonly SqlSugarRepository<DjyVesselInfo> _vesselinfo;
|
|
|
|
|
|
|
|
|
|
public DataSyncService(ILogger<BookingOrderService> logger, ISysCacheService cache, SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn,
|
|
|
|
|
SqlSugarRepository<SysUser> repUser, SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<DjyCustomer> djycustomer,
|
|
|
|
|
SqlSugarRepository<DjyCustomerContact> djycustomercontact, SqlSugarRepository<DjyVesselInfo> vesselinfo)
|
|
|
|
|
{
|
|
|
|
|
this._logger = logger;
|
|
|
|
|
this._rep = rep;
|
|
|
|
|
this._repCtn = repCtn;
|
|
|
|
|
this._cache = cache;
|
|
|
|
|
this._repUser = repUser;
|
|
|
|
|
this._repTenant = repTenant;
|
|
|
|
|
this._djycustomer = djycustomer;
|
|
|
|
|
this._djycustomercontact = djycustomercontact;
|
|
|
|
|
this._vesselinfo = vesselinfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 上传数据
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 同步客户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/DataSync/SyncCustomer"),ApiUser(ApiCode= "SyncCustomer")]
|
|
|
|
|
public async Task<long> SyncCustomer(DjyCustomerSyncDto model)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.BSNO)) {
|
|
|
|
|
throw Oops.Bah("BSNO未录入");
|
|
|
|
|
}
|
|
|
|
|
var m = await _djycustomer.Where(x => x.BSNO == model.BSNO).FirstAsync();
|
|
|
|
|
var entity = model.Adapt<DjyCustomer>();
|
|
|
|
|
if (m == null)
|
|
|
|
|
{
|
|
|
|
|
await _djycustomer.InsertAsync(entity);
|
|
|
|
|
foreach (var item in model.ContactList)
|
|
|
|
|
{
|
|
|
|
|
var contact = item.Adapt<DjyCustomerContact>();
|
|
|
|
|
contact.CustomerId = entity.Id;
|
|
|
|
|
await _djycustomercontact.InsertAsync(contact);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
entity.Id=m.Id;
|
|
|
|
|
await _djycustomer.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
await _djycustomercontact.DeleteAsync(x => x.CustomerId == entity.Id);
|
|
|
|
|
foreach (var item in model.ContactList)
|
|
|
|
|
{
|
|
|
|
|
var contact = item.Adapt<DjyCustomerContact>();
|
|
|
|
|
contact.CustomerId = entity.Id;
|
|
|
|
|
await _djycustomercontact.InsertAsync(contact);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 同步船期
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/DataSync/SyncVesselDate"), ApiUser(ApiCode = "SyncVesselDate")]
|
|
|
|
|
public async Task<long> SyncVesselDate(DjyVesselInfoDto model)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.BSNO))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("BSNO未录入");
|
|
|
|
|
}
|
|
|
|
|
var m = await _vesselinfo.Where(x => x.BSNO==model.BSNO).FirstAsync();
|
|
|
|
|
var entity = model.Adapt<DjyVesselInfo>();
|
|
|
|
|
entity.Vessel = model.Vessel.ToUpper().Trim();
|
|
|
|
|
if (m == null)
|
|
|
|
|
{
|
|
|
|
|
await _vesselinfo.InsertAsync(entity);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
entity.Id = m.Id;
|
|
|
|
|
await _vesselinfo.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 同步订舱
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/DataSync/SyncBooking"), ApiUser(ApiCode = "SyncBooking")]
|
|
|
|
|
public async Task<long> SyncBooking(SyncBookingOrderDto model)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.BSNO)) {
|
|
|
|
|
throw Oops.Bah("主单BSNO未录入");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.CreatedUserName)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 下载数据
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 其他
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 测试用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/DataSync/Test"), ApiUser(ApiCode = "Test")]
|
|
|
|
|
public async Task<string> Test()
|
|
|
|
|
{
|
|
|
|
|
return $"当前用户:{UserManager.UserId} {UserManager.Name} ,当前租户:{UserManager.TENANT_ID} {UserManager.TENANT_NAME},管理员类型:{(UserManager.IsSuperAdmin ? "超级管理员" : (UserManager.IsTenantAdmin ? "租户管理员" : "普通用户"))}";
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|