AFR对接

master
zhangxiaofeng 11 months ago
parent 96e7b57169
commit 53adb7ffde

@ -8,6 +8,7 @@
<Product>Common</Product>
<Description>Common包</Description>
<Version>1.2.1</Version>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

@ -0,0 +1,123 @@
using System;
using System.IO;
using System.Threading;
namespace Common.Helpers
{
public class LogLock
{
//private static readonly ILog log = LogManager.GetLogger(typeof(LogLock));
private static ReaderWriterLockSlim LogWriteLock = new();
//private static int WritedCount = 0;
//private static int FailedCount = 0;
private static string _contentRoot = string.Empty;
public LogLock(string contentPath)
{
_contentRoot = contentPath;
}
public static void LogRecordAccess(string[] dataParas, bool IsHeader = true, bool isWrt = false)
{
OutSql2LogToFile("RecordAccessLog", dataParas, IsHeader, isWrt);
}
public static void LogInfo(string[] dataParas, bool IsHeader = true, bool isWrt = false)
{
OutSql2LogToFile("InfoLog", dataParas, IsHeader, isWrt);
}
public static void LogSql(string[] dataParas, bool IsHeader = true, bool isWrt = false)
{
OutSql2LogToFile("SqlLog", dataParas, IsHeader, isWrt);
}
public static void OutSql2LogToFile(string prefix, string[] dataParas, bool IsHeader = true, bool isWrt = false)
{
try
{
//设置读写锁为写入模式独占资源,其他写入请求需要等待本次写入结束之后才能继续写入
//注意:长时间持有读线程锁或写线程锁会使其他线程发生饥饿 (starve)。 为了得到最好的性能,需要考虑重新构造应用程序以将写访问的持续时间减少到最小。
// 从性能方面考虑,请求进入写入模式应该紧跟文件操作之前,在此处进入写入模式仅是为了降低代码复杂度
// 因进入与退出写入模式应在同一个try finally语句块内所以在请求进入写入模式之前不能触发异常否则释放次数大于请求次数将会触发异常
LogWriteLock.EnterWriteLock();
string folderPath = Path.Combine(_contentRoot, "Log", prefix);
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
//string logFilePath = Path.Combine(path, $@"{filename}.log");
//string logFilePath = FileHelper.GetAvailableFileWithPrefixOrderSize(folderPath, prefix, 3145728);
string logFilePath = Path.Combine(folderPath, $@"{prefix}_{DateTime.Now.ToString("yyyy-MM-dd")}.log");
DateTime now = DateTime.Now;
string logContent;
if (IsHeader)
{
logContent = (
"--------------------------------\r\n" +
DateTime.Now + "|\r\n" +
String.Join("\r\n", dataParas) + "\r\n"
);
}
else
{
logContent = String.Join("\r\n", dataParas);
}
if (isWrt)
{
File.WriteAllText(logFilePath, logContent);
}
else
{
File.AppendAllText(logFilePath, logContent);
}
//WritedCount++;
}
catch (Exception e)
{
Console.Write(e.Message);
//FailedCount++;
}
finally
{
//退出写入模式,释放资源占用
//注意:一次请求对应一次释放
// 若释放次数大于请求次数将会触发异常[写入锁定未经保持即被释放]
// 若请求处理完成后未释放将会触发异常[此模式不下允许以递归方式获取写入锁定]
LogWriteLock.ExitWriteLock();
}
}
//public static void OutSql2LogToDB(string prefix, string[] dataParas, bool IsHeader = true)
//{
// string logContent = String.Join("", dataParas);
// if (IsHeader)
// {
// logContent = (String.Join("", dataParas));
// }
// switch (prefix)
// {
// case "AOPLog":
// log.Info(logContent);
// break;
// case "AOPLogEx":
// log.Error(logContent);
// break;
// case "RequestIpInfoLog":
// log.Debug(logContent);
// break;
// case "RecordAccessLogs":
// log.Debug(logContent);
// break;
// case "SqlLog":
// log.Info(logContent);
// break;
// case "RequestResponseLog":
// log.Debug(logContent);
// break;
// default:
// break;
// }
//}
}
}

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
namespace Common.Utilities
{
public class PageModel<T>
{
/// <summary>
/// 第几页从1开始
/// </summary>
public int PageNumber { get; set; } = 1;
/// <summary>
/// 总页数
/// </summary>
public int PageCount => (int)Math.Ceiling((decimal)Count / PageSize);
/// <summary>
/// 查询的记录数量
/// </summary>
public long Count { get; set; } = 0;
/// <summary>
/// 每页大小
/// </summary>
public int PageSize { set; get; } = 20;
/// <summary>
/// 返回数据
/// </summary>
public List<T> Result { get; set; }
public PageModel() { }
public PageModel(int pageNumber, long count, int pageSize, List<T> result)
{
PageNumber = pageNumber;
Count = count;
PageSize = pageSize;
Result = result;
}
}
}

@ -1,4 +1,7 @@
namespace Common.Utilities
using System;
using System.Collections.Generic;
namespace Common.Utilities
{
/// <summary>
///
@ -17,10 +20,10 @@
/// 操作状态码200为正常
/// </summary>
public int Code { get; set; }
/// <summary>
///
/// </summary>
public int Total { get; set; }
///// <summary>
/////
///// </summary>
//public int Total { get; set; }
/// <summary>
///
/// </summary>
@ -43,4 +46,33 @@
/// </summary>
public T Result { get; set; }
}
/// <summary>
/// WEBAPI通用返回泛型基类
/// </summary>
/// <typeparam name="T"></typeparam>
public class ResponsePage<T> : Response
{
/// <summary>
/// 第几页从1开始
/// </summary>
public int PageNumber { get; set; }
/// <summary>
/// 每页多少
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// 查询的记录数量
/// </summary>
public long Count { get; set; }
/// <summary>
/// 总页数
/// </summary>
public int PageCount => (int)Math.Ceiling((decimal)Count / PageSize);
/// <summary>
/// 回传的结果
/// </summary>
public List<T> Result { get; set; }
}
}

@ -1,12 +1,28 @@
using System;
using Common.Utilities;
using djy.Model.Afr;
using djy.Model.AFRDto;
using djy.Model.AmsDto;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.IService.Afr
{
public interface IAfrService
{
#region 字典接口
List<CommonCNEN> GetCountry(string strlink, int page, int limit);
List<CommonMappiCode> GetCARRIER();
List<CommonCodeValue> GetCTNALL();
List<CommonCodeValue> GetPackage();
List<CodeDangerGradeDto> GetDangerousGoods(string strlink);
List<CommonCodeValue> GetPort(string strlink, int page, int limit);
List<CommonCodeValue> GetVessel(string strlink, int page, int limit);
#endregion
Task<PageModel<AFRMaster>> Load(AFRMasterInputDto input);
Task SaveInfo(AFRMasterDto input);
Task Delete(string ids);
Task Send(string ids, string msgType);
Task SaveReceipt(AFRReceiptDto input);
}
}

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>
<ItemGroup>

@ -0,0 +1,50 @@
using FreeSql.DataAnnotations;
using System;
namespace djy.Model.AFR
{
public class AFRBaseModel
{
/// <summary>
/// 主键
/// </summary>
[Column(IsPrimary = true)]
public string GID { get; set; }
/// <summary>
/// 用户ID
/// </summary>
public string UserID { get; set; }
/// <summary>
/// 用户名称
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 公司ID
/// </summary>
public string CompID { get; set; }
/// <summary>
/// 公司名称
/// </summary>
public string CompName { get; set; }
/// <summary>
/// 是否删除
/// </summary>
public bool? IsDel { get; set; }
/// <summary>
/// 最后修改时间
/// </summary>
[Column(CanInsert = false)]
public DateTime? LastUpdate { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[Column(CanUpdate =false)]
public DateTime? CreateTime { get; set; }
}
}

@ -1,4 +1,5 @@
using FreeSql.DataAnnotations;
using djy.Model.AFR;
using FreeSql.DataAnnotations;
using System;
namespace djy.Model.Afr
@ -8,28 +9,14 @@ namespace djy.Model.Afr
///
/// </summary>
[Table(Name = "AFR_Cntrno", DisableSyncStructure = true)]
public partial class AFRCntrno
public partial class AFRCntrno: AFRBaseModel
{
/// <summary>
///
/// </summary>
public string GID { get; set; }
/// <summary>
/// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致
/// </summary>
public string BusinessId { get; set; }
/// <summary>
///
/// </summary>
public string CompID { get; set; }
/// <summary>
///
/// </summary>
public string CompName { get; set; }
/// <summary>
/// 货主箱标志
/// </summary>
@ -45,11 +32,6 @@ namespace djy.Model.Afr
/// </summary>
public string ContainerType { get; set; }
/// <summary>
///
/// </summary>
public DateTime? CreateTime { get; set; }
/// <summary>
/// 危品联系人(选填)
/// </summary>
@ -95,16 +77,6 @@ namespace djy.Model.Afr
/// </summary>
public string Ignite { get; set; }
/// <summary>
///
/// </summary>
public bool? IsDel { get; set; }
/// <summary>
///
/// </summary>
public DateTime? LastUpdate { get; set; }
/// <summary>
/// 原产国(选填)
/// </summary>
@ -145,21 +117,9 @@ namespace djy.Model.Afr
/// </summary>
public string UnCode { get; set; }
/// <summary>
///
/// </summary>
public string UserID { get; set; }
/// <summary>
///
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 体积
/// </summary>
public double? Volume { get; set; }
}
}

@ -1,4 +1,6 @@
using FreeSql.DataAnnotations;
using djy.Model.AFR;
using FreeSql.DataAnnotations;
using NetTopologySuite.Geometries.Prepared;
using System;
namespace djy.Model.Afr
@ -8,49 +10,23 @@ namespace djy.Model.Afr
///
/// </summary>
[Table(Name = "AFR_House", DisableSyncStructure = true)]
public partial class AFRHouse
public partial class AFRHouse: AFRBaseModel
{
/// <summary>
///
/// </summary>
public string GID { get; set; }
public string PID { get; set; }
/// <summary>
/// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致
/// </summary>
public string BusinessId { get; set; }
/// <summary>
///
/// </summary>
public string CompID { get; set; }
/// <summary>
///
/// </summary>
public string CompName { get; set; }
/// <summary>
///
/// </summary>
public DateTime? CreateTime { get; set; }
/// <summary>
/// 货代提单号 修改报文,该值不可以变更
///
/// </summary>
public string HouseBillNo { get; set; }
/// <summary>
///
/// </summary>
public bool? IsDel { get; set; }
/// <summary>
///
/// </summary>
public DateTime? LastUpdate { get; set; }
/// <summary>
/// 通知人地址
@ -161,17 +137,6 @@ namespace djy.Model.Afr
/// 货代单运编号(选填)
/// </summary>
public string ShippingNo { get; set; }
/// <summary>
///
/// </summary>
public string UserID { get; set; }
/// <summary>
///
/// </summary>
public string UserName { get; set; }
}
}

@ -1,5 +1,8 @@
using FreeSql.DataAnnotations;
using djy.Model.AFR;
using djy.Model.Ams;
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
namespace djy.Model.Afr
{
@ -7,38 +10,18 @@ namespace djy.Model.Afr
///
/// </summary>
[Table(Name = "AFR_Master", DisableSyncStructure = true)]
public partial class AFRMaster
public partial class AFRMaster : AFRBaseModel
{
/// <summary>
///
/// </summary>
public string GID { get; set; }
/// <summary>
/// 运输条款代码
/// </summary>
public string Clause { get; set; }
/// <summary>
///
/// </summary>
public string CompID { get; set; }
/// <summary>
///
/// </summary>
public string CompName { get; set; }
/// <summary>
/// 整箱/拼箱
/// </summary>
public string ConsignmentType { get; set; }
/// <summary>
///
/// </summary>
public DateTime? CreateTime { get; set; }
/// <summary>
/// 卸货港全称
@ -60,10 +43,6 @@ namespace djy.Model.Afr
/// </summary>
public string FilingType { get; set; }
/// <summary>
///
/// </summary>
public bool? IsDel { get; set; }
/// <summary>
/// 交货地全称条件申报运输类型Tranship时必填
@ -75,10 +54,6 @@ namespace djy.Model.Afr
/// </summary>
public string LastForeignHarbourCode { get; set; }
/// <summary>
///
/// </summary>
public DateTime? LastUpdate { get; set; }
/// <summary>
/// 预计开船日期
@ -113,22 +88,21 @@ namespace djy.Model.Afr
/// <summary>
///
/// </summary>
public string UserID { get; set; }
public string Vessel { get; set; }
/// <summary>
///
/// </summary>
public string UserName { get; set; }
public string Voyno { get; set; }
/// <summary>
///
/// </summary>
public string Vessel { get; set; }
#region 导航属性
/// <summary>
///
/// 分单列表
/// </summary>
public string Voyno { get; set; }
[Navigate(nameof(AMS_Master.GID))]
public List<AMS_House> Houses { get; set; }
#endregion
}

@ -1,4 +1,8 @@
using System;
using djy.Model.Afr;
using djy.Model.AFR;
using djy.Model.Ams;
using FreeSql.Internal.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -6,7 +10,11 @@ using System.Threading.Tasks;
namespace djy.Model.AFRDto
{
public class AFRMasterDto
public class AFRMasterDto : AFRMaster
{
/// <summary>
/// 分单列表
/// </summary>
List<AMS_House> Houses { get; set; }
}
}

@ -0,0 +1,49 @@
using FreeSql.Internal.Model;
using System;
namespace djy.Model.AFRDto
{
public class AFRMasterInputDto : BasePagingInfo
{
/// <summary>
/// 查询类型1草稿箱列表 2已发送列表
/// </summary>
public int Type { get; set; }
/// <summary>
/// 船东提单号
/// </summary>
public string MBLNO { get; set; }
/// <summary>
/// 货代提单号 修改报文,该值不可以变更
/// </summary>
public string HouseBillNo { get; set; }
/// <summary>
/// 按创建时间查询的开始时间
/// </summary>
public DateTime? CreateTimeStart { get; set; }
/// <summary>
/// 按创建时间查询的结束时间
/// </summary>
public DateTime? CreateTimeEnd{ get; set; }
/// <summary>
/// 操作用户名称
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 卸货港名称
/// </summary>
public string DischargeHarbour { get; set; }
/// <summary>
/// 用户Id
/// </summary>
public string UserId { get; set; }
/// <summary>
/// 公司企业Id
/// </summary>
public string CompanyId { get; set; }
}
}

@ -1,20 +0,0 @@
namespace djy.Model.AFRDto
{
public class AFRMasterPageDataDto
{
/// <summary>
/// 查询类型1草稿箱列表 2已发送列表
/// </summary>
public int Type { get; set; }
/// <summary>
/// 当前页
/// </summary>
public int Page { get; set; }
/// <summary>
/// 每页数量
/// </summary>
public int Limit { get; set; }
}
}

@ -0,0 +1,21 @@
namespace djy.Model.AFRDto
{
public class AFRReceiptDto
{
public string businessId { get; set; }
public string content { get; set; }
public string houseBillNo { get; set; }
/// <summary>
/// 值有Accept、Warning、Reject、Matched、Hold、Cancel
/// </summary>
public string status { get; set; }
}
}
//样例:
//{
// businessId:"63401",
// content:"<Accept> 海关已接收 Master B/L Registration Status 13RHPASU8027790980",
// houseBillNo:"KMTCNBO6178011",
// status:"Accept"
//}

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

@ -1,5 +1,13 @@
using djy.IService.Afr;
using Common.DJYModel;
using Common.Extensions;
using Common.Utilities;
using djy.IService.Afr;
using djy.Model.Afr;
using djy.Model.AFRDto;
using djy.Model.Ams;
using djy.Model.AmsDto;
using djy.Service.DjyService;
using FreeSql.Internal.Model;
using System;
using System.Collections.Generic;
using System.Linq;
@ -10,6 +18,225 @@ namespace djy.Service.AFR
{
public class AfrService : DbContext, IAfrService
{
#region 下拉接口
public List<CommonCNEN> GetCountry(string strlink, int page, int limit)
{
try
{
if (page == 0 && limit == 0)
{
var List = DbBus.Get(DbList.Common).Select<CodeCountry>().ToList().Select(x => new CommonCNEN
{
Code = x.Code,
ENName = x.EnName,
CNName = x.CnName,
}).Distinct().ToList();
return List;
}
else
{
var List = DbBus.Get(DbList.Common).Select<CodeCountry>().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.EnName.Contains(strlink.Trim()) || x.CnName.Contains(strlink.Trim())).Page(page, limit).ToList().Select(x => new CommonCNEN
{
Code = x.Code,
ENName = x.EnName,
CNName = x.CnName,
}).Distinct().ToList();
return List;
}
}
catch (Exception e)
{
throw;
}
}
public List<CommonMappiCode> GetCARRIER()
{
try
{
var List = DbBus.Get(DbList.Common).Select<CodeCarrier, MappingCarrier>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "Afr").ToList((cc, map) => new CommonMappiCode
{
Code = cc.Code,
Value = cc.EnName,
MapCode = map.MapCode
}).Distinct().ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
public List<CommonCodeValue> GetCTNALL()
{
try
{
var List = DbBus.Get(DbList.Common).Select<CodeCtn, MappingCtn>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "Afr").ToList((cc, map) => new CommonCodeValue
{
Code = cc.Code,
Value = cc.Name,
}).Distinct().ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
public List<CommonCodeValue> GetPackage()
{
try
{
var List = DbBus.Get(DbList.Common).Select<CodePackage, MappingPackage>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "Afr").ToList((cc, map) => new CommonCodeValue
{
Code = cc.Code,
Value = cc.Name,
}).Distinct().ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
public List<CodeDangerGradeDto> GetDangerousGoods(string strlink)
{
try
{
var List = DbBus.Get(DbList.Common).Select<CodeDangerGrade>().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.Grade.Contains(strlink.Trim())).ToList().Select(x => new CodeDangerGradeDto
{
Code = x.Code,
Grade = x.Grade,
}).Distinct().ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
public List<CommonCodeValue> GetPort(string strlink, int page, int limit)
{
try
{
if (page == 0 && limit == 0)
{
var List = DbBus.Get(DbList.Common).Select<CodePort>().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.EnName.Contains(strlink.Trim())).ToList().Select(x => new CommonCodeValue
{
Code = x.Code,
Value = x.EnName,
}).Distinct().ToList();
return List;
}
else
{
var List = DbBus.Get(DbList.Common).Select<CodePort>().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.EnName.Contains(strlink.Trim())).Page(page, limit).ToList().Select(x => new CommonCodeValue
{
Code = x.Code,
Value = x.EnName,
}).Distinct().ToList();
return List;
}
}
catch (Exception e)
{
throw;
}
}
public List<CommonCodeValue> GetVessel(string strlink, int page, int limit)
{
try
{
if (page == 0 && limit == 0)
{
var List = DbBus.Get(DbList.Common).Select<CodeVessel>().WhereIf(strlink != "", x => x.Name.Contains(strlink.Trim())).ToList().Select(x => new CommonCodeValue
{
Code = x.Name,
Value = x.Name,
}).Distinct().ToList();
return List;
}
else
{
var List = DbBus.Get(DbList.Common).Select<CodeVessel>().WhereIf(strlink != "", x => x.Name.Contains(strlink.Trim())).Page(page, limit).ToList().Select(x => new CommonCodeValue
{
Code = x.Name,
Value = x.Name,
}).Distinct().ToList();
return List;
}
}
catch (Exception e)
{
throw;
}
}
#endregion
public async Task<PageModel<AFRMaster>> Load(AFRMasterInputDto input)
{
// 查询草稿箱列表
if (input.Type == 1)
{
var select = DbBus.Get(DbList.AMSCenter)
.Select<AFRMaster>()
.LeftJoin<AFRHouse>((m, h) => m.GID == h.PID)
.Where((m) => m.IsDel == false)
.WhereIf(!string.IsNullOrEmpty(input.CompanyId), m => m.CompID == input.CompanyId)
.WhereIf(!string.IsNullOrEmpty(input.UserId), m => m.UserID == input.UserId)
.WhereIf(!string.IsNullOrEmpty(input.MBLNO), m => m.MBLNO.Contains(input.MBLNO))
.WhereIf(!string.IsNullOrEmpty(input.UserName), m => m.UserName.Contains(input.UserName))
.WhereIf(!string.IsNullOrEmpty(input.DischargeHarbour), m => m.DischargeHarbour.Contains(input.DischargeHarbour))
.WhereIf(input.CreateTimeStart != null, m => m.CreateTime >= input.CreateTimeStart)
.WhereIf(input.CreateTimeEnd != null, m => m.CreateTime <= input.CreateTimeEnd);
if (!string.IsNullOrEmpty(input.HouseBillNo))
{
select.Where<AFRHouse>((m, h) => h.HouseBillNo == input.HouseBillNo);
}
List<AFRMaster> result = await select.Page(input)
.IncludeMany(m => m.Houses)
.OrderByDescending(m => m.CreateTime)
.ToListAsync();
return new PageModel<AFRMaster>(input.PageNumber,
input.Count,
input.PageSize,
result);
}
// 查询已发送列表
else
{
return default;
}
//HouseBillNo
}
public Task SaveInfo(AFRMasterDto input)
{
throw new NotImplementedException();
}
public Task Delete(string ids)
{
throw new NotImplementedException();
}
public Task Send(string ids, string msgType)
{
throw new NotImplementedException();
}
public Task SaveReceipt(AFRReceiptDto input)
{
throw new NotImplementedException();
}
}
}

@ -10,6 +10,7 @@ using System.Threading;
using System.Threading.Tasks;
using Common;
using System.Data;
using Common.Helpers;
namespace djy.Service.DjyService
{
@ -83,17 +84,32 @@ namespace djy.Service.DjyService
}
else
{
DbBus.Register(item.SysKey, () => new FreeSqlBuilder().UseConnectionString((DataType)item.DataType, item.ConnString)
.UseAutoSyncStructure(false)
.UseNoneCommandParameter(true)
.UseMonitorCommand(cmd =>
DbBus.Register(item.SysKey, () =>
{
Trace.WriteLine("\r\n" + Thread.CurrentThread.ManagedThreadId + ":" + cmd.CommandText);
})
.Build());
IFreeSql freeSql = new FreeSqlBuilder().UseConnectionString((DataType)item.DataType, item.ConnString)
.UseAutoSyncStructure(false)
.UseNoneCommandParameter(true)
.UseMonitorCommand(cmd =>
{
Trace.WriteLine("\r\n" + Thread.CurrentThread.ManagedThreadId + ":" + cmd.CommandText);
})
.Build();
if (item.SysKey == DbList.AMSCenter)
{
freeSql.Aop.CurdAfter += (s, e) =>
{
string msg = $"ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}; FullName:{e.EntityType.FullName} ElapsedMilliseconds:{e.ElapsedMilliseconds}ms{Environment.NewLine}{Environment.NewLine}{e.Sql}";
Parallel.For(0, 1, e2 =>
{
LogLock.LogSql(new string[] { msg });
});
};
}
return freeSql;
});
}
}
return true;

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>
<ItemGroup>

@ -1,23 +1,30 @@
using Common.Utilities;
using Common.DJYModel;
using Common.Utilities;
using djy.IService.Afr;
using djy.Model;
using djy.Model.Afr;
using djy.Model.AFRDto;
using djy.Model.IsfDto;
using djy_AfrApi.HttpContextUser;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Org.BouncyCastle.Crypto;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace djy_AfrApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class AfrController : ApiBase
{
private readonly ILogger logger;
private readonly IUser user;
private readonly IAfrService afrService;
private readonly IAfrService _afrService;
//private readonly ILogger bigLogger;
@ -27,7 +34,7 @@ namespace djy_AfrApi.Controllers
{
this.logger = logger;
this.user = user;
this.afrService = afrService;
this._afrService = afrService;
// 获取ILogger对象
//ILoggerFactory loggerFactory,
@ -35,33 +42,59 @@ namespace djy_AfrApi.Controllers
}
#region 查询接口
[HttpGet("[action]")]
public async Task<MessageModel<List<AFRMaster>>> PageData(AFRMasterPageDataDto input)
[HttpGet("PageData")]
public async Task<ResponsePage<AFRMaster>> PageData(AFRMasterInputDto input)
{
var data = afrService.Load();
UserAuthorityDto aut = GetUserAuthorityToFormDto("modIsfList");
return default;
}
input.CompanyId = aut.CompayId?.ToString();
input.UserId = aut.UserId?.ToString();
[HttpGet("[action]")]
[AllowAnonymous]
public async Task<MessageModel> Reveive()
{
var r = MessageModel.Success("555", new { ff = "44", fff = "33" });
return r;
var pageData = await _afrService.Load(input);
return SuccessPage(pageData);
}
#endregion
#region 新增/编辑
[HttpPost("AddOrUpdate")]
public async Task<Response> AddOrUpdateAsync([FromBody] AFRMasterDto input)
{
await _afrService.SaveInfo(input);
return SuccessResp();
}
#endregion
#region 删除
[HttpPost("Del")]
public async Task<Response> Delete(string ids)
{
await _afrService.Delete(ids);
return SuccessResp();
}
#endregion
#region 第三方接口
[HttpGet("Send")]
public async Task<Response> Send(string ids, string msgType)
{
await _afrService.Send(ids, msgType);
return SuccessResp();
}
[AllowAnonymous]
[HttpPost("Receipt")]
public async Task<Response> SaveReceiptAsync(AFRReceiptDto input)
{
await _afrService.SaveReceipt(input);
return SuccessResp("接收成功");
}
#endregion
[AllowAnonymous]
[HttpGet("[action]")]
public Response GetTime()
{
return SuccessResp(DateTime.Now.ToString());
}
}
}

@ -2,8 +2,8 @@
using Common.DJYModel;
using Common.Extensions;
using Common.Tools;
using Common.Utilities;
using djy.IService.Djy;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
@ -15,14 +15,35 @@ namespace djy_AfrApi.Controllers
/// <summary>
/// api接口基类
/// </summary>
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class ApiBase : Controller
{
#region http数据获取
#region 构建响应对象
[NonAction]
protected ResponsePage<T> SuccessPage<T>(PageModel<T> pageModel)
{
return new ResponsePage<T>()
{
Code = 200,
Message = "查询成功",
Result = pageModel.Result,
Count = pageModel.Count,
PageNumber = pageModel.PageNumber,
PageSize = pageModel.PageSize
};
}
[NonAction]
protected Response SuccessResp(string message = "操作成功")
{
return new Response()
{
Code = 200,
Message = message
};
}
#endregion
#region http数据获取
/// <summary>
/// 创建日志
/// </summary>
@ -42,14 +63,16 @@ namespace djy_AfrApi.Controllers
/// </summary>
/// <param name="KeyName">keyname标识</param>
/// <returns></returns>
protected DJyUserAuthorityDto GetDJyUserAuthority(string KeyName) {
protected DJyUserAuthorityDto GetDJyUserAuthority(string KeyName)
{
var _djyserver = IOC.AddServer<IDjyUserService>();
var rs= _djyserver.GetUserAuthority(GetLoginId,KeyName);
var rs = _djyserver.GetUserAuthority(GetLoginId, KeyName);
if (rs.Status)
{
return rs.Data;
}
else {
else
{
return null;
}
}
@ -57,7 +80,7 @@ namespace djy_AfrApi.Controllers
/// 获取登录详情信息
/// </summary>
/// <param name="UserGid"></param>
protected User GetUserInfo(Guid? UserGid = null)
protected User GetUserInfo(Guid? UserGid = null)
{
var _suser = IOC.AddServer<IDjyUserService>();
if (UserGid == null)
@ -79,7 +102,8 @@ namespace djy_AfrApi.Controllers
/// <param name="KeyName">模块keyname标识</param>
/// <param name="type">0 查询查看权限 1 操作更新权限 默认 0</param>
/// <returns></returns>
protected UserAuthorityDto GetUserAuthorityToFormDto(string KeyName,int type=0 ) {
protected UserAuthorityDto GetUserAuthorityToFormDto(string KeyName, int type = 0)
{
//本人的绑定UserId 全部 userid 和 compayid不做绑定 注册公司的 绑定 companyid 没有权限则指定userid和companyid 为不存的guid值
var RetrunData = new UserAuthorityDto();
var _djyserver = IOC.AddServer<IDjyUserService>();
@ -87,9 +111,9 @@ namespace djy_AfrApi.Controllers
User = null;
var uuid = GetLoginId.ToString();
var userrs = _djyserver.GetUserInfo(GetLoginId.ToString());
var notguid = Guid.Parse("00000000-0000-0000-0000-000000000001");
RetrunData.CompayId = null;
if (userrs.Status)
@ -107,11 +131,13 @@ namespace djy_AfrApi.Controllers
if (aut != null)
{//根据权限处理 _userid 和 _companyid 值
RetrunData.IsPower = true;
var _useraut= aut.Visiblerange;
if (type == 1) {
var _useraut = aut.Visiblerange;
if (type == 1)
{
_useraut = aut.Operaterange;
}
switch (_useraut) {
switch (_useraut)
{
case 0://全部
RetrunData.UserId = null;
@ -134,12 +160,12 @@ namespace djy_AfrApi.Controllers
case 7://注册公司
RetrunData.UserId = null;
RetrunData.CompayId = Guid.Parse( User.CompId);
RetrunData.CompayId = Guid.Parse(User.CompId);
break;
default:
RetrunData.UserId = notguid;
RetrunData.CompayId = notguid;
break;
break;
}
}
@ -152,9 +178,9 @@ namespace djy_AfrApi.Controllers
//if (sysOptionConfig.Webconfig.IsDev)
//{
// RetrunData.UserId = null;
// RetrunData.CompayId =null;
// RetrunData.IsPower = true;
// RetrunData.UserId = null;
// RetrunData.CompayId =null;
// RetrunData.IsPower = true;
//}
return RetrunData;
@ -165,7 +191,7 @@ namespace djy_AfrApi.Controllers
/// <summary>
/// 获取登录Id
/// </summary>
protected Guid? GetLoginId { get { return Guid.Parse(GetClaimsValue("loginid")); } }
protected Guid? GetLoginId { get { return Guid.Parse(GetClaimsValue("loginid")); } }
/// <summary>
/// 获取登录类型
@ -204,8 +230,9 @@ namespace djy_AfrApi.Controllers
return IsDecrtypt ? _DecryptDES(id.Value) : id.Value;
}
catch {
return null;
catch
{
return null;
}
}
@ -220,82 +247,4 @@ namespace djy_AfrApi.Controllers
}
#endregion
}
/// <summary>
///api接口基类
/// </summary>
/// <typeparam name="IS">接口类型比如 Iservice</typeparam>
public class ApiBase<IS> : ApiBase
{
/// <summary>
///
/// </summary>
protected IS _server = IOC.AddServer<IS>();
/// <summary>
/// 执行指定的方法
/// </summary>
/// <param name="methodName">方法名称</param>
/// <param name="parameters">参数对象队列</param>
/// <returns></returns>
protected object _InvokeServer(string methodName, object[] parameters)
{
return _server.GetType().GetMethod(methodName).Invoke(_server, parameters);
}
}
/// <summary>
/// api接口基类
/// </summary>
/// <typeparam name="IS">接口类型比如 Iservice</typeparam>
/// <typeparam name="D">Dto Model</typeparam>
/// <typeparam name="T">Tables数据表model</typeparam>
public class ApiBase<IS, D, T> : ApiBase<IS>
{
/// <summary>
/// 根据Id获取实体
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
protected virtual object _GetId(long Id)
{
return _InvokeServer("GetId", new object[] { Id });
}
/// <summary>
///基础的创建接口 提交创建对象
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
protected virtual object _Add(T Dto)
{
return _InvokeServer("Add", new object[] { Dto });
}
/// <summary>
/// 最基础的更新接口 传递要更新的数据对象 必须有Id
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
protected virtual object _Up(T Dto)
{
return _InvokeServer("Up", new object[] { Dto, null, null });
}
/// <summary>
/// 最基础的删除接口 [1,2,3]
/// </summary>
/// <param name="Idlist"></param>
/// <returns></returns>
protected virtual object _Del(long[] Idlist)
{
return _InvokeServer("Del", new object[] { Idlist });
}
}
}

@ -0,0 +1,224 @@
using Common;
using Common.Utilities;
using djy.IService.Afr;
using djy.Model.AmsDto;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
namespace djy_AfrApi.Controllers.Common
{
public class CommonController
{
IAfrService ser = IOC.AddServer<IAfrService>();
#region 下拉接口
/// <summary>
/// 下拉获取国家
/// </summary>
/// <returns></returns>
[HttpGet("GetCountry")]
public Response<List<CommonCNEN>> GetCountry(string strlink = "", int page = 0, int limit = 0)
{
var result = new Response<List<CommonCNEN>>();
try
{
result.Result = ser.GetCountry(strlink, page, limit);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 下拉获取船公司
/// </summary>
/// <returns></returns>
[HttpGet("GetCARRIER")]
public Response<List<CommonMappiCode>> GetCARRIER()
{
var result = new Response<List<CommonMappiCode>>();
try
{
result.Result = ser.GetCARRIER();
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 下拉获取箱型
/// </summary>
/// <returns></returns>
[HttpGet("GetCTNALL")]
public Response<List<CommonCodeValue>> GetCTNALL()
{
var result = new Response<List<CommonCodeValue>>();
try
{
result.Result = ser.GetCTNALL();
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 下拉获取包装单位
/// </summary>
/// <returns></returns>
[HttpGet("GetPackage")]
public Response<List<CommonCodeValue>> GetPackage()
{
var result = new Response<List<CommonCodeValue>>();
try
{
result.Result = ser.GetPackage();
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 下拉获取危品等级及 CODE
/// </summary>
/// <returns></returns>
[HttpGet("GetDangerousGoods")]
public Response<List<CodeDangerGradeDto>> GetDangerousGoods(string strlink = "",int page = 0, int limit = 0)
{
var result = new Response<List<CodeDangerGradeDto>>();
try
{
result.Result = ser.GetDangerousGoods(strlink);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
///// <summary>
///// 下拉获取起运港口
///// </summary>
///// <returns></returns>
//[HttpGet("GetCodePortLoad")]
//public Response<List<CommonCodeValue>> GetCodePortLoad()
//{
// var result = new Response<List<CommonCodeValue>>();
// try
// {
// result.Result = ser.GetCodePortLoad();
// }
// catch (Exception ex)
// {
// result.Code = 500;
// result.Message = ex.InnerException?.Message ?? ex.Message;
// }
// return result;
//}
/// <summary>
/// 下拉获取港口
/// </summary>
/// <returns></returns>
[HttpGet("GetPort")]
public Response<List<CommonCodeValue>> GetPort(string strlink = "", int page = 0, int limit = 0)
{
var result = new Response<List<CommonCodeValue>>();
try
{
result.Result = ser.GetPort(strlink, page, limit);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 下拉获取船名
/// </summary>
/// <returns></returns>
[HttpGet("GetVessel")]
public Response<List<CommonCodeValue>> GetVessel(string strlink = "", int page = 0,int limit =0)
{
var result = new Response<List<CommonCodeValue>>();
try
{
result.Result = ser.GetVessel(strlink, page,limit);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
///// <summary>
///// 下拉获取省份
///// </summary>
///// <returns></returns>
//[HttpGet("GetCodeProvince")]
//public Response<List<CommonCodeValue>> GetCodeProvince(string code)
//{
// var result = new Response<List<CommonCodeValue>>();
// try
// {
// result.Result = ser.GetCodeProvince(code);
// }
// catch (Exception ex)
// {
// result.Code = 500;
// result.Message = ex.InnerException?.Message ?? ex.Message;
// }
// return result;
//}
///// <summary>
///// 下拉获取城市 邮编
///// </summary>
///// <returns></returns>
//[HttpGet("GetCodeCity")]
//public Response<List<CodeCityDto>> GetCodeCity(string provinceCode)
//{
// var result = new Response<List<CodeCityDto>>();
// try
// {
// result.Result = ser.GetCodeCity(provinceCode);
// }
// catch (Exception ex)
// {
// result.Code = 500;
// result.Message = ex.InnerException?.Message ?? ex.Message;
// }
// return result;
//}
#endregion
}
}

@ -1,10 +1,6 @@
using Common.Helpers;
using Common.Utilities;
using djy.Service.DjyService;
using Microsoft.AspNetCore.Hosting;
using Common.Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

@ -0,0 +1,33 @@
--------------------------------
2023/12/27 15:41:20|
ManagedThreadId:19; FullName:djy.Model.Afr.AFRMaster ElapsedMilliseconds:30ms
SELECT count(1) as1
FROM [AFR_Master] a
LEFT JOIN [AFR_House] h ON a.[GID] = h.[PID]
WHERE (a.[IsDel] = 0) AND ((a.[UserName]) LIKE N'%朱洋%') AND (a.[CreateTime] >= '1991-04-18 21:23:40.000') AND (a.[CreateTime] <= '1988-04-22 20:14:18.000') AND (h.[HouseBillNo] = N'sunt laborum')
--------------------------------
2023/12/27 15:42:50|
ManagedThreadId:7; FullName:djy.Model.Afr.AFRMaster ElapsedMilliseconds:44ms
SELECT count(1) as1
FROM [AFR_Master] a
LEFT JOIN [AFR_House] h ON a.[GID] = h.[PID]
WHERE (a.[IsDel] = 0) AND ((a.[UserName]) LIKE N'%朱洋%') AND (a.[CreateTime] >= '1991-04-18 21:23:40.000') AND (a.[CreateTime] <= '1988-04-22 20:14:18.000') AND (h.[HouseBillNo] = N'sunt laborum')
--------------------------------
2023/12/27 15:45:04|
ManagedThreadId:12; FullName:djy.Model.Afr.AFRMaster ElapsedMilliseconds:46ms
SELECT count(1) as1
FROM [AFR_Master] a
LEFT JOIN [AFR_House] h ON a.[GID] = h.[PID]
WHERE (a.[IsDel] = 0) AND ((a.[UserName]) LIKE N'%朱洋%') AND (a.[CreateTime] >= '1991-04-18 21:23:40.000') AND (a.[CreateTime] <= '1988-04-22 20:14:18.000') AND (h.[HouseBillNo] = N'sunt laborum')
--------------------------------
2023/12/27 15:45:04|
ManagedThreadId:5; FullName:djy.Model.Afr.AFRMaster ElapsedMilliseconds:330ms
SELECT TOP 10 a.[GID], a.[UserID], a.[UserName], a.[CompID], a.[CompName], a.[IsDel], a.[LastUpdate], a.[CreateTime], a.[Clause], a.[ConsignmentType], a.[DischargeHarbour], a.[DischargeHarbourCode], a.[EstimatedArrivalTime], a.[FilingType], a.[LastForeignHarbour], a.[LastForeignHarbourCode], a.[LoadDate], a.[LoadHarbour], a.[LoadHarbourCode], a.[MBLNO], a.[ShipCompany], a.[ShippingNo], a.[Vessel], a.[Voyno]
FROM [AFR_Master] a
LEFT JOIN [AFR_House] h ON a.[GID] = h.[PID]
WHERE (a.[IsDel] = 0) AND ((a.[UserName]) LIKE N'%朱洋%') AND (a.[CreateTime] >= '1991-04-18 21:23:40.000') AND (a.[CreateTime] <= '1988-04-22 20:14:18.000') AND (h.[HouseBillNo] = N'sunt laborum')
ORDER BY a.[CreateTime] DESC

@ -1,4 +1,5 @@
using djy.Model;
using Common.Utilities;
using djy.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
@ -23,7 +24,7 @@ namespace djy_AfrApi.Middlewares
{
try
{
_ = int.Parse("");
//_ = int.Parse("");
await _next(context);
}
catch (Exception ex)
@ -35,7 +36,7 @@ namespace djy_AfrApi.Middlewares
private async Task HandleExceptionAsync(HttpContext context, Exception e)
{
if (e == null) return;
logger.LogError(WriteLog("ExceptionHandlerMiddleware中捕获的全局异常", e));
await WriteExceptionAsync(context, e).ConfigureAwait(false);
@ -57,7 +58,7 @@ namespace djy_AfrApi.Middlewares
context.Response.ContentType = "application/json";
await context.Response
.WriteAsync(JsonConvert.SerializeObject(new MessageModel() { code = 500, message = message }))
.WriteAsync(JsonConvert.SerializeObject(new Response() { Code = 500, Message = message }))
.ConfigureAwait(false);
}

@ -26,7 +26,7 @@ namespace djy_AfrApi.Milldlewares
public async Task InvokeAsync(HttpContext context)
{
var endpoint = context.GetEndpoint();
if (endpoint?.Metadata.GetMetadata<IAllowAnonymous>() == null)
if (endpoint?.Metadata.GetMetadata<IAllowAnonymous>() == null && context.Request.Path.Value.ToLower().Contains("/api/afr"))
{
// 因为ISF/AMS这步验证始终都无效所以这里先不做验证
//if (context.Request.Path.Value.Contains("/Load"))
@ -39,10 +39,10 @@ namespace djy_AfrApi.Milldlewares
var user = _userService.GetUserInfo(userId);
if (user.Data == null)
{
MessageModel result = new MessageModel()
Response result = new Response()
{
code = 401,
message = "登录过期(未查询到此用户),请重新登录!"
Code = 401,
Message = "登录过期(未查询到此用户),请重新登录!"
};
context.Response.ContentType = "application/json";

@ -1,4 +1,5 @@
using djy.Model;
using Common.Utilities;
using djy.Model;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System.Threading.Tasks;
@ -25,10 +26,10 @@ namespace djy_AfrApi.Milldlewares
await context.Response
.WriteAsync(JsonConvert.SerializeObject(
new MessageModel()
new Response()
{
code = context.Response.StatusCode,
message = "授权验证失败或已过期,请重新登录!"
Code = context.Response.StatusCode,
Message = "授权验证失败或已过期,请重新登录!"
}))
.ConfigureAwait(false);
}

@ -2,7 +2,7 @@
"profiles": {
"djy_AfrApi": {
"commandName": "Project",
"launchBrowser": false,
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>
<ItemGroup>

Loading…
Cancel
Save