You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
5.7 KiB
C#

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.Service.BookingOrder.Dto;
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;
2 years ago
using System.Reflection.Emit;
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;
2 years ago
private readonly SqlSugarRepository<DjyCustomer> _djycustomer;
private readonly SqlSugarRepository<DjyCustomerContact> _djycustomercontact;
2 years ago
private readonly SqlSugarRepository<DjyVesselInfo> _vesselinfo;
public DataSyncService(ILogger<BookingOrderService> logger, ISysCacheService cache, SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn,
2 years ago
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;
2 years ago
this._djycustomer = djycustomer;
this._djycustomercontact = djycustomercontact;
2 years ago
this._vesselinfo = vesselinfo;
}
#region 上传数据
2 years ago
/// <summary>
/// 同步客户
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
2 years ago
[HttpPost("/DataSync/SyncCustomer"),ApiUser(ApiCode="")]
public async Task<long> SyncCustomer(DjyCustomerSyncDto model)
{
2 years ago
if (string.IsNullOrWhiteSpace(model.CodeName)) {
throw Oops.Bah("请上传正确数据,Code未录入");
}
var m = await _djycustomer.Where(x => x.CodeName == model.CodeName).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;
}
2 years ago
2 years ago
/// <summary>
/// 同步船期
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("/DataSync/SyncVesselInfo"), ApiUser]
public async Task<long> SyncVesselInfo(DjyVesselInfoDto model)
{
if (string.IsNullOrWhiteSpace(model.Vessel)|| string.IsNullOrWhiteSpace(model.CARRIERID))
{
throw Oops.Bah("请上传正确数据,船公司或船名未录入");
}
var m = await _vesselinfo.Where(x => x.Vessel==model.Vessel.ToUpper().Trim()&&x.CARRIERID==model.CARRIERID).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;
}
2 years ago
#endregion
#region 下载数据
#endregion
2 years ago
#region 其他
[HttpGet("/DataSync/Test"), ApiUser]
public async Task<string> Test()
{
return $"当前用户:{UserManager.UserId} {UserManager.Name} ,当前租户:{UserManager.TENANT_ID} {UserManager.TENANT_NAME},管理员类型:{(UserManager.IsSuperAdmin ? "" : (UserManager.IsTenantAdmin ? "" : ""))}";
}
#endregion
}
}