master
wet 3 years ago
parent 335b2f384e
commit 647e3975cc

@ -6,35 +6,32 @@ using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Common;
using Microsoft.EntityFrameworkCore;
namespace Shared.Repository
{
/// <summary>
/// Dapper帮助类
/// </summary>
public sealed class DapperDBBase : IDapperDBBase
public class DapperDBBase : DbContext, IDapperDBBase
{
private string sqlConnection;
private readonly IConfiguration _configuration;
/// <summary>
///
/// </summary>
/// <param name="configuration"></param>
public DapperDBBase(IConfiguration configuration)
public DapperDBBase()
{
_configuration = configuration;
sqlConnection = configuration.GetConnectionString("OpenAuthDBContext");
sqlConnection = sysOptionConfig.YsWebconfig.DapperDbString;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public IDbConnection GetConn()
public IDbConnection GetConn(string type = null)
{
if (string.IsNullOrEmpty(sqlConnection))
sqlConnection = _configuration.GetConnectionString("OpenAuthDBContext");
sqlConnection = sysOptionConfig.YsWebconfig.DapperDbString;
IDbConnection conn = new SqlConnection(sqlConnection);
conn.Open();
return conn;
@ -470,29 +467,78 @@ namespace Shared.Repository
}
return iResult;
}
//以下为使用方法
//public async Task<Users> GetUserDetailAsync(int Id)
//{
// string detailSql = @"SELECT ID, UserName, Password, Gender, Birthday, CreateDate, IsDelete FROM [dbo].[Users] WHERE Id=@Id";
// return await base.Detail(Id, detailSql);
//}
//public async Task<List<Users>> GetUsersAsync()
//{
// string selectSql = @"SELECT userName,Password,Gender ,Birthday ,CreateDate ,IsDelete FROM [dbo].[Users]";
// return await base.Select(selectSql);
//}
//public async Task PostUserAsync(Users entity)
//{
// string insertSql = @"INSERT INTO [dbo].[Users](Id, UserName, Password, Gender, Birthday, CreateDate, IsDelete) VALUES(@Id, @UserName, @Password, @Gender, @Birthday, @CreateDate, @IsDelete)";
// await base.Insert(entity, insertSql);
//}
//public async Task PutUserAsync(Users entity)
//{
// string updateSql = "UPDATE [dbo].[Users] SET UserName=@UserName, Password=@Password, Gender=@Gender, Birthday=@Birthday, CreateDate=@CreateDate, IsDelete=@IsDelete WHERE Id=@Id";
// await base.Update(entity, updateSql);
//}
/// <summary>
/// 开启事务
/// </summary>
/// <param name="conn"></param>
/// <returns></returns>
public IDbTransaction BeginTransaction(IDbConnection conn)
{
IDbTransaction tran = conn.BeginTransaction();
return tran;
}
/// <summary>
/// 提交事务
/// </summary>
/// <param name="tran"></param>
/// <param name="conn"></param>
public void Commit(IDbTransaction tran, IDbConnection conn)
{
tran.Commit();
}
/// <summary>
/// 回滚事务
/// </summary>
/// <param name="tran"></param>
/// <param name="conn"></param>
public void Rollback(IDbTransaction tran, IDbConnection conn)
{
tran.Rollback();
}
/// 数据库连接名
private static string _connection = string.Empty;
/// 获取连接名
private static string Connection
{
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)
{
lock (locker)
{
if (uniqueInstance == null)
{
uniqueInstance = new DapperDBBase();
}
}
}
return uniqueInstance;
}
}
}

@ -112,6 +112,9 @@ namespace Common
/// </summary>
public int ShopPower { get; set; } = 2;
public string DapperDbString { get; set; }
#region jwt认证配置
/// <summary>
/// jwt发行者

File diff suppressed because it is too large Load Diff

@ -14,7 +14,7 @@ namespace Common.Repository.Interface
///
/// </summary>
/// <returns></returns>
IDbConnection GetConn();
IDbConnection GetConn(string type=null);
/// <summary>
/// 无参数存储过程
/// </summary>

@ -12,8 +12,11 @@
// <summary>仓储接口</summary>
// ***********************************************************************
using Common.Repository.Core;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
@ -89,4 +92,8 @@ namespace Common.Repository.Interface
#endregion
}
}

@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.Model.Ams
{
[Table("AMS_Cntrno")]
public class AMS_Cntrno
{
/// <summary>

@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.Model.Ams
{
[Table("AMS_House")]
public class AMS_House
{
/// <summary>

@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.Model.Ams
{
public class AMSMaster
[Table("AMS_Master")]
public class AMS_Master
{
/// <summary>
/// 主键

@ -2,11 +2,9 @@
using System;
using System.Collections.Generic;
namespace djy.Model.Ams
namespace AMSDto
{
public class AMSDto
{
}
public class AMSSaveDto
{

@ -1,17 +0,0 @@
using djy.Model.Ams;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.IService.Ams
{
public interface IAms
{
void SaveInfo(AMSSaveDto Dto);
}
}

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using djy.Model;
using Common;
using AMSDto;
namespace djy.Paas.IService
{
/// <summary>
/// 账单中心模块
/// </summary>
public interface IAmsService:IsBase
{
/// <summary>
///保存单据
/// </summary>
/// <returns></returns>
public void SaveInfo(AMSSaveDto dto);
}
}

@ -0,0 +1,43 @@
using AMSDto;
using djy.Paas.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Data;
using System.Data.SqlClient;
using Common;
using djy.Model.Ams;
using Shared.Repository;
namespace djy.Service.Ams
{
/// <summary>
/// AMS
/// </summary>
public class AmsService : ServBase, IAmsService
{
DapperDBBase dapper = new DapperDBBase();
public async void SaveInfo(AMSSaveDto dto)
{
AMS_Master master = dto.MapTo<AMS_Master>();
using (var transaction = dapper.BeginTransaction(dapper.GetConn()))
{
master.CreateTime = DateTime.Now;
var gid = await dapper.InsertByEntityAsync(master);
transaction.Rollback();
}
}
}
}

@ -1,25 +0,0 @@
using Common.Repository;
using Common.Repository.Interface;
using djy.IService.Ams;
using djy.Model.Ams;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.Service.Ams
{
public class ServiceAms : IAms
{
private IDapperDBBase dapperDB;
public void SaveInfo(AMSSaveDto Dto)
{
}
}
}

@ -8,11 +8,9 @@ using System.Reflection;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using djy.Paas.IService;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;
using djy.Model;
namespace djy_AmsApi.Controllers
namespace djy.Service
{
/// <summary>
@ -177,6 +175,17 @@ namespace djy_AmsApi.Controllers
/// </summary>
protected string GetLoginName { get { return GetClaimsValue("loginname"); } }
/// <summary>
/// 获取登录公司名称
/// </summary>
protected string GetLoginComptName { get { return GetClaimsValue("COMNAME"); } }
/// <summary>
/// 获取登录公司id
/// </summary>
protected string GetLoginCompId { get { return GetClaimsValue("CompId"); } }
/// <summary>
/// 获取登录类型
/// </summary>
@ -305,4 +314,7 @@ namespace djy_AmsApi.Controllers
}
}

@ -0,0 +1,74 @@
// ***********************************************************************
// Assembly : FairUtility
// Author : Yubao Li
// Created : 08-27-2015
//
// Last Modified By : Yubao Li
// Last Modified On : 08-27-2015
// ***********************************************************************
// <copyright file="AutoMapperExt.cs" company="">
// Copyright (c) . All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using AutoMapper;
using System;
using System.Collections;
using System.Collections.Generic;
namespace djy.Service
{
public static class AutoMapperExt
{
/// <summary>
/// 类型映射
/// </summary>
public static T MapTo<T>(this object obj)
{
if (obj == null) return default(T);
var config = new MapperConfiguration(cfg => cfg.CreateMap(obj.GetType(), typeof(T)));
var mapper = config.CreateMapper();
return mapper.Map<T>(obj);
}
/// <summary>
/// 集合列表类型映射
/// </summary>
public static List<TDestination> MapToList<TDestination>(this IEnumerable source)
{
Type sourceType = source.GetType().GetGenericArguments()[0]; //获取枚举的成员类型
var config = new MapperConfiguration(cfg => cfg.CreateMap(sourceType, typeof(TDestination)));
var mapper = config.CreateMapper();
return mapper.Map<List<TDestination>>(source);
}
/// <summary>
/// 集合列表类型映射
/// </summary>
public static List<TDestination> MapToList<TSource, TDestination>(this IEnumerable<TSource> source)
{
var config = new MapperConfiguration(cfg => cfg.CreateMap(typeof(TSource), typeof(TDestination)));
var mapper = config.CreateMapper();
return mapper.Map<List<TDestination>>(source);
}
/// <summary>
/// 类型映射
/// </summary>
public static TDestination MapTo<TSource, TDestination>(this TSource source, TDestination destination)
where TSource : class
where TDestination : class
{
if (source == null) return destination;
var config = new MapperConfiguration(cfg => cfg.CreateMap(typeof(TSource), typeof(TDestination)));
var mapper = config.CreateMapper();
return mapper.Map<TDestination>(source);
}
}
}

@ -9,6 +9,9 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Common;
using System.Data;
using Shared.Repository;
namespace djy.Service
{
/// <summary>
@ -27,7 +30,7 @@ namespace djy.Service
/// <summary>
/// 账单中心库
/// </summary>
public const string BillCenter = "billcenter";
public const string AMSCenter = "AMS";
/// <summary>
/// 日志库
/// </summary>
@ -44,8 +47,6 @@ namespace djy.Service
/// </summary>
public static IdleBus<IFreeSql> DbBus=new IdleBus<IFreeSql>(TimeSpan.FromSeconds(20));
//public static IFreeSql DbBus.Get(DbList.djypublicedb);
/// <summary>
/// RedisDB
/// </summary>
@ -74,7 +75,6 @@ namespace djy.Service
else
{
DbBus.Register(item.SysKey, () => new FreeSqlBuilder().UseConnectionString((DataType)item.DataType, item.ConnString)
// .UseAutoSyncStructure(sysOptionConfig.YsWebconfig.IsDev)
.UseAutoSyncStructure(false)
.UseNoneCommandParameter(true)
.UseMonitorCommand(cmd =>
@ -90,17 +90,13 @@ namespace djy.Service
return true;
}
///// <summary>
///// 数据库初始化
///// </summary>
//public static ReturnResult<string> DbInit()
//{
// var rs = new ReturnResult<string>();
// DbBus.Get(DbList.djypublicedb).CodeFirst.SyncStructure<tb_BaoguanContainer>();
// DbBus.Get(DbList.djypublicedb).CodeFirst.SyncStructure<tb_BaoguanDecList>();
// rs.OK("生成成功!");
// return rs;
//}
}
}

@ -1,16 +1,18 @@
using Common;
using Common.Repository.Interface;
using djy.Model.Ams;
using AMSDto;
using Common;
using djy.Service;
using djy.Service.Ams;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
namespace djy_AmsApi.Controllers
{
[AllowAnonymous]
public class AmsController : ApiBase
{
private ServiceAms ams;
AmsService ser =new AmsService();
[HttpPost("Add")]
public Response Add(AMSSaveDto Dto)
@ -18,7 +20,8 @@ namespace djy_AmsApi.Controllers
var result = new Response();
try
{
ams.Add(Dto);
ser.SaveInfo(Dto);
}
catch (Exception ex)
{

@ -18,6 +18,9 @@ using System.Net.Mime;
using AutoMapper;
using djy_AmsApi;
using djy.Service;
using Common.Repository.Interface;
using Shared.Repository;
namespace djy_AmsApi
{

@ -28,13 +28,14 @@
"Rbmq_UserName": "djy_paas",
"Rbmq_Password": "123qwe",
"Rbmq_Sqlhost": "Data Source =192.168.1.205,1433; Initial Catalog=TestDjyLogs; Persist Security Info=True; User ID =test; Password=test123;pooling=true",
"DapperDbString": "Data Source =123.234.225.158,28000; Initial Catalog=DevAMS; Persist Security Info=True; User ID =dev; Password=dev123;pooling=true;max pool size=2",
"DataConnList": [
{
"SysKey": "AMS",
"TitleName": "账单数据库",
"TitleName": "AMS",
"Index": 100,
"DataType": 1,
"Status": 0,

@ -27,17 +27,17 @@
"Rbmq_UserName": "admin",
"Rbmq_Password": "admin",
"Rbmq_Sqlhost": "Data Source =172.31.85.154; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true",
"DapperDbString": "Data Source =123.234.225.158,28000; Initial Catalog=DevAMS; Persist Security Info=True; User ID =dev; Password=dev123;pooling=true;max pool size=2",
"DataConnList": [
{
"SysKey": "billcenter",
"SysKey": "AMS",
"TitleName": "账单数据库",
"TitleName": "AMS",
"Index": 100,
"DataType": 1,
"Status": 0,
"ConnString": "Data Source =172.31.85.154; Initial Catalog=BillCenter; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true;max pool size=2"
"ConnString": "Data Source =123.234.225.158,28000; Initial Catalog=DevAMS; Persist Security Info=True; User ID =dev; Password=dev123;pooling=true;max pool size=2"
},
{
"SysKey": "djydb",

@ -27,17 +27,16 @@
"Rbmq_UserName": "admin",
"Rbmq_Password": "admin",
"Rbmq_Sqlhost": "Data Source =172.31.85.154; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true",
"DapperDbString": "Data Source =123.234.225.158,28000; Initial Catalog=DevAMS; Persist Security Info=True; User ID =dev; Password=dev123;pooling=true;max pool size=2",
"DataConnList": [
{
"SysKey": "billcenter",
"TitleName": "账单数据库",
"SysKey": "AMS",
"TitleName": "AMS",
"Index": 100,
"DataType": 1,
"Status": 0,
"ConnString": "Data Source =172.31.85.154; Initial Catalog=BillCenter; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true;max pool size=2"
"ConnString": "Data Source =123.234.225.158,28000; Initial Catalog=DevAMS; Persist Security Info=True; User ID =dev; Password=dev123;pooling=true;max pool size=2"
},
{
"SysKey": "djydb",
@ -46,8 +45,6 @@
"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 =djypaas.myshipping.net,5099; Initial Catalog=djy_PubliceData; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true""ConnString": "Data Source =djypaas.myshipping.net,5099; Initial Catalog=djy_PubliceData; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true"
"ConnString": "Data Source =172.31.85.154,1433; Initial Catalog=djy_PubliceData; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true"
},
@ -57,8 +54,6 @@
"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 =djypaas.myshipping.net,5099; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;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"
},
@ -69,9 +64,6 @@
"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 =djypaas.myshipping.net,5099; Initial Catalog=DsPingTai; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true",
"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