master
wet 3 years ago
parent bf83663faf
commit a90b36c3f1

@ -35,6 +35,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
<PackageReference Include="cd.dapper.extension" Version="1.0.6" />
<PackageReference Include="Dapper" Version="2.0.90" />
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
<PackageReference Include="DotNetCore.CAP" Version="5.1.1" />
@ -65,6 +66,7 @@
<PackageReference Include="NPOI" Version="2.5.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.2" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="5.13.18" />
</ItemGroup>

@ -1,5 +1,4 @@

using Dapper;
using Dapper;
using Dapper.Contrib.Extensions;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
@ -9,16 +8,19 @@ using System.Threading.Tasks;
using Common;
using Microsoft.EntityFrameworkCore;
using Common.Interface;
using System.Linq.Expressions;
using System;
using System.Linq;
namespace Common
{
/// <summary>
/// Dapper帮助类
/// </summary>
public class DapperDBBase : DbContext, IDapperDBBase
public class DapperDBBase : DbContext,IDapperDBBase
{
private string sqlConnection;
public DapperDBBase()
{
@ -33,9 +35,9 @@ namespace Common
if (string.IsNullOrEmpty(sqlConnection))
sqlConnection = sysOptionConfig.YsWebconfig.DapperDbString;
IDbConnection conn = new SqlConnection(sqlConnection);
conn.Open();
return conn;
IDbConnection conn = new SqlConnection(sqlConnection);
conn.Open();
return conn;
}
/// <summary>
@ -410,7 +412,6 @@ namespace Common
/// <summary>
/// 根据查询SQL直接返回datatable
/// Author GHB 2021-6-15
/// </summary>
/// <param name="entitys">实体模型</param>
/// <returns></returns>
@ -426,7 +427,7 @@ namespace Common
}
/// <summary>
/// 执行SQL语句返回结果gjg
/// 执行SQL语句返回结果
/// </summary>
/// <param name="insertSql"></param>
/// <param name="parms"></param>
@ -438,6 +439,11 @@ namespace Common
return await Conn.ExecuteScalarAsync<T>(Sql, parms);
}
}
/// <summary>
/// 执行中包含事务sql
/// </summary>
@ -501,45 +507,18 @@ namespace Common
/// 数据库连接名
private static string _connection = string.Empty;
/// 获取连接名
private static string Connection
public long Insert<T>(T model) where T : class, new()
{
get { return _connection; }
set { _connection = value; }
}
/// 定义一个标识确保线程同步
private static readonly object locker = new object();
private static DapperDBBase uniqueInstance;
/// <summary>
/// 获取实例,这里为单例模式,保证只存在一个实例
/// </summary>
/// <returns></returns>
public static DapperDBBase GetInstance()
{
// 双重锁定实现单例模式,在外层加个判空条件主要是为了减少加锁、释放锁的不必要的损耗
if (uniqueInstance == null)
using (IDbConnection Conn = GetConn())
{
lock (locker)
{
if (uniqueInstance == null)
{
uniqueInstance = new DapperDBBase();
}
}
return Conn.Insert<T>(model);
}
return uniqueInstance;
}
}
}

@ -21,13 +21,13 @@ namespace Common.DjyService
/// <summary>
///独立的大简云publice库
/// </summary>
public const string djypublicedb = "djydb";
public const string djydb = "djydb";
/// <summary>
///大简云平台老库
/// </summary>
public const string djyolddb = "djyolddb";
/// <summary>
/// 账单中心库
/// AMS
/// </summary>
public const string AMSCenter = "AMS";
/// <summary>

@ -1,6 +1,8 @@
using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace Common.Interface
@ -207,5 +209,7 @@ namespace Common.Interface
/// <param name="listSql"></param>
/// <returns></returns>
Task<int> ExecSqlTransAsync(List<string> listSql);
}
}

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using djy.Model;
using Common;
using Common.Djy;
using djy.Model.AmsDto;
namespace djy.Paas.IService
{
@ -14,8 +15,14 @@ namespace djy.Paas.IService
/// </summary>
public interface IAmsService:IsBase
{
/// <summary>
/// 新增
/// </summary>
/// <param name="dto"></param>
/// <param name="userid"></param>
void SaveInfo(AMSDto dto,string userid);
List<AMSDto> GetAll();
}
}

@ -19,8 +19,10 @@ namespace djy.Model.Ams
/// 父键
/// </summary>
public string HID { get; set; }
/// <summary>
/// 业务id
/// </summary>
public string PID { get; set; }
/// <summary>
/// 箱号

@ -2,27 +2,52 @@
using System;
using System.Collections.Generic;
namespace AMSDto
namespace djy.Model.AmsDto
{
public class AMSSaveDto
public class AMSDto
{
/// <summary>
/// 主键
/// </summary>
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>
/// 船公司id
/// </summary>
public string CARRIERID { get; set; }
/// <summary>
/// 船公司
/// </summary>
public string CARRIER { get; set; }
/// <summary>
/// 提单号
/// </summary>
@ -60,6 +85,7 @@ namespace AMSDto
/// </summary>
public string LastNoUsPort { get; set; }
/// <summary>
/// 卸货港
/// </summary>
@ -76,6 +102,9 @@ namespace AMSDto
/// </summary>
public DateTime? ETD { get; set; }
public DateTime? CreateTime { get; set; }
public DateTime? LastUpdate { get; set; }
public List<AMS_HouseDto> HouseDto { get; set; }
}

@ -10,7 +10,9 @@ using System.Data.SqlClient;
using Common;
using djy.Model.Ams;
using Common.DjyService;
using AMSDto;
using djy.Model.AmsDto;
using Common.Extensions;
using Common.DJYModel;
namespace djy.Service.Ams
{
@ -19,13 +21,65 @@ namespace djy.Service.Ams
/// </summary>
public class AmsService : ServBase, IAmsService
{
DapperDBBase dapper = new DapperDBBase();
public async void SaveInfo(AMSSaveDto dto)
public List<AMSDto> GetAll()
{
throw new NotImplementedException();
}
public async void SaveInfo(AMSDto dto,string userid)
{
if (dto.GID.IsNull())
{
using (var transaction = dapper.BeginTransaction(dapper.GetConn()))
{
try
{
var user = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == userid).ToOne();
AMS_Master master = dto.MapTo<AMS_Master>();
master.CreateTime = DateTime.Now;
master.LastUpdate = DateTime.Now;
master.GID = Guid.NewGuid().ToString("N");
master.UserID = user.GID;
master.UserName = user.SHOWNAME;
master.CompID = user.CompId;
master.CompName = user.COMNAME;
dapper.Insert<AMS_Master>(master);
foreach (var item in dto.HouseDto)
{
AMS_House house = dto.MapTo<AMS_House>();
house.GID = Guid.NewGuid().ToString("N");
house.PID = master.GID;
dapper.Insert<AMS_House>(house);
foreach (var it in item.CntrnoDto)
{
AMS_Cntrno cntrno = dto.MapTo<AMS_Cntrno>();
cntrno.GID = Guid.NewGuid().ToString("N");
cntrno.PID = master.GID;
cntrno.HID = house.GID;
dapper.Insert<AMS_Cntrno>(cntrno);
}
}
transaction.Rollback();
}
catch (Exception ex)
{
transaction.Rollback();
}
}
}
else {
}
}
}
}

@ -10,6 +10,12 @@
<None Remove="Tools\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.18" />
<PackageReference Include="System.Linq.Expressions" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Djy.Common\Common.csproj" />
<ProjectReference Include="..\djy.IService\djy.IService.csproj" />

@ -1,8 +1,8 @@
using AMSDto;
using Common;
using Common;
using Common.DjyService;
using Common.Utilities;
using djy.Model.Ams;
using djy.Model.AmsDto;
using djy.Service;
using djy.Service.Ams;
using Microsoft.AspNetCore.Authorization;
@ -14,36 +14,24 @@ namespace djy_AmsApi.Controllers
[AllowAnonymous]
public class AmsController : ApiBase
{
DapperDBBase dapper = new DapperDBBase();
AmsService ser =new AmsService();
[HttpPost("Add")]
public Response Add(AMSSaveDto Dto)
[HttpPost("AddOrUpdate")]
public Response AddOrUpdate(AMSDto Dto)
{
var result = new Response();
AMS_Master master = Dto.MapTo<AMS_Master>();
using (var transaction = dapper.BeginTransaction(dapper.GetConn()))
{
try
{
master.CreateTime = DateTime.Now;
var gid = dapper.InsertByEntityAsync(master);
}
catch (Exception ex)
{
transaction.Rollback();
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
}
//if (GetLoginId==null) {
// result.Code = 401;
// result.Message = "登录过期,请重新登录!";
//}
if (Dto == null)
{
result.Code = 500;
result.Message = "无效数据!";
}
ser.SaveInfo(Dto, "d85fd590-d9f6-4410-93a1-f6fac77b606e");
return result;
}

@ -34,7 +34,6 @@
{
"SysKey": "AMS",
"TitleName": "AMS",
"Index": 100,
"DataType": 1,
@ -43,12 +42,11 @@
},
{
"SysKey": "djydb",
"TitleName": "大简云新库",
"TitleName": "pingtai",
"Index": 100,
"DataType": 1,
"Status": 0,
"ConnString": "Data Source =192.168.1.205,1433; Initial Catalog=TestPubliceData; Persist Security Info=True; User ID =test; Password=test123;pooling=true"
"ConnString": "Data Source =123.234.225.158,28000; Initial Catalog=DevDsPingTai; Persist Security Info=True; User ID =dev; Password=dev123;pooling=true"
},
{
@ -57,17 +55,7 @@
"Index": 100,
"DataType": 1,
"Status": 0,
"ConnString": "Data Source =192.168.1.205,1433; Initial Catalog=TestDjyLogs; Persist Security Info=True; User ID =test; Password=test123;pooling=true"
},
{
"SysKey": "djyolddb",
"TitleName": "大简云老库",
"Index": 100,
"DataType": 1,
"Status": 0,
"ConnString": "Data Source =192.168.1.205,1433; Initial Catalog=TestDsPingTai; Persist Security Info=True; User ID =test; Password=test123;pooling=true"
"ConnString": "Data Source =172.31.85.154,1433; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true"
}

@ -32,7 +32,6 @@
{
"SysKey": "AMS",
"TitleName": "AMS",
"Index": 100,
"DataType": 1,
@ -41,13 +40,11 @@
},
{
"SysKey": "djydb",
"TitleName": "大简云新库",
"TitleName": "pingtai",
"Index": 100,
"DataType": 1,
"Status": 0,
// "ConnString": "Data Source =172.17.0.3; Initial Catalog=djy_PaasData; Persist Security Info=True; User ID =sa; Password=QDdjy2021*;pooling=true",
"ConnString": "Data Source =172.31.85.154; Initial Catalog=djy_PubliceData; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true"
"ConnString": "Data Source =123.234.225.158,28000; Initial Catalog=DevDsPingTai; Persist Security Info=True; User ID =dev; Password=dev123;pooling=true"
},
{
@ -56,19 +53,8 @@
"Index": 100,
"DataType": 1,
"Status": 0,
// "ConnString": "Data Source =172.17.0.3; Initial Catalog=djy_logs; Persist Security Info=True; User ID = sa; Password=QDdjy2021*;pooling=true",
"ConnString": "Data Source =172.31.85.154; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true"
},
{
"SysKey": "djyolddb",
"ConnString": "Data Source =172.31.85.154,1433; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true"
"TitleName": "大简云老库",
"Index": 100,
"DataType": 1,
"Status": 0,
// "ConnString": "Data Source =172.17.0.3; Initial Catalog=MYSHIPPINGTEST8; Persist Security Info=True; User ID =sa; Password=QDdjy2021*;pooling=true",
//"ConnString": "Data Source =172.31.85.154; Initial Catalog=MYSHIPPINGTEST8; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true",
"ConnString": "Data Source =172.31.85.154; Initial Catalog=DsPingTai; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true"
}

@ -40,12 +40,11 @@
},
{
"SysKey": "djydb",
"TitleName": "大简云新库",
"TitleName": "pingtai",
"Index": 100,
"DataType": 1,
"Status": 0,
"ConnString": "Data Source =172.31.85.154,1433; Initial Catalog=djy_PubliceData; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true"
"ConnString": "Data Source =123.234.225.158,28000; Initial Catalog=DevDsPingTai; Persist Security Info=True; User ID =dev; Password=dev123;pooling=true"
},
{
@ -56,17 +55,8 @@
"Status": 0,
"ConnString": "Data Source =172.31.85.154,1433; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true"
},
{
"SysKey": "djyolddb",
"TitleName": "大简云老库",
"Index": 100,
"DataType": 1,
"Status": 0,
"ConnString": "Data Source =172.31.85.154,1433; Initial Catalog=DsPingTai; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true"
}
]

Loading…
Cancel
Save