Skip to content

Commit 4ed0fec

Browse files
committed
1.配置增加mssql
2.可以通过配置走不通的数据库 3.升级到2.2 4.修复菜单逻辑删除bug 5.修复系统用户修改接口bug
1 parent 6816c7a commit 4ed0fec

File tree

16 files changed

+104
-30
lines changed

16 files changed

+104
-30
lines changed

ant.mgr/Configuration/Configuration/Configuration.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
55
</PropertyGroup>
66

77
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

ant.mgr/DBModels/DBModels/DbContext.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,46 @@
22
using System;
33
using System.Diagnostics;
44
using System.Linq;
5+
using Configuration;
56
using Infrastructure.Logging;
67
using Infrastructure.Web;
78

89
namespace DbModel
910
{
1011
public class DbContext
1112
{
12-
public static MysqlDbContext<AntEntity> DB
13+
/// <summary>
14+
/// 后台系统采用的是什么数据库
15+
/// </summary>
16+
private static readonly string dbType;
17+
static DbContext()
18+
{
19+
20+
try
21+
{
22+
//读取当前采用的是什么数据库
23+
dbType = ConfigHelper.GetConfig<string>("AntDbType");
24+
}
25+
catch (Exception)
26+
{
27+
dbType = "mysql";
28+
}
29+
30+
if (string.IsNullOrEmpty(dbType)) dbType = "mysql";
31+
}
32+
public static DbContext<AntEntity> DB
1333
{
1434
get
1535
{
16-
var db = new MysqlDbContext<AntEntity>("ant_mysql");
36+
DbContext<AntEntity> db;
37+
if (dbType.ToLower().Equals("mysql"))
38+
{
39+
db = new MysqlDbContext<AntEntity>("ant_mysql");
40+
}
41+
else
42+
{
43+
db = new SqlServerlDbContext<AntEntity>("ant_sqlserver");
44+
}
1745
#if DEBUG
1846
db.IsEnableLogTrace = true;
1947
db.OnLogTrace = OnCustomerTraceConnection;
@@ -43,15 +71,15 @@ private static void OnCustomerTraceConnection(CustomerTraceInfo customerTraceInf
4371
sql += Environment.NewLine;
4472
foreach (var detail in customerTraceInfo.RunTimeList)
4573
{
46-
74+
4775
var sencond = (int)detail.Duration.TotalSeconds;
4876
var time = sencond + "秒";
4977
if (sencond < 1)
5078
{
5179
time = detail.Duration.TotalMilliseconds + "豪秒";
5280
}
53-
sql += $"Server:{detail.Server},DB名称:{detail.DbName}, 执行时间:{time}" +Environment.NewLine + "#####################################################" + Environment.NewLine;
54-
LogHelper.Info("SQL",sql);
81+
sql += $"Server:{detail.Server},DB名称:{detail.DbName}, 执行时间:{time}" + Environment.NewLine + "#####################################################" + Environment.NewLine;
82+
LogHelper.Info("SQL", sql);
5583
}
5684
}
5785
catch (Exception)

ant.mgr/DBModels/DBModels/DbModel.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
55
<AssemblyName>DbModel</AssemblyName>
66
<RootNamespace>DbModel</RootNamespace>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -13,11 +13,11 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<None Remove="ant.db.json" />
16+
<None Remove="ant.mssql.json" />
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<Content Include="ant.db.json">
20+
<Content Include="ant.mssql.json">
2121
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2222
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
2323
</Content>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"NamespaceName": "DbModel", //必填:设置生成代码的命名空间
3+
4+
"BaseEntityClass": "LinqToDBEntity", //生成的DTo继父类class名称 (必填 代码生成的时候会用到)
5+
6+
"DataContextName": "AntEntity", //自定义生成的数据库Entity的name( 如果不填会有默认值为db的名称+Entitys)
7+
8+
"EntitySuffix": "", //自定义生成的每张表对应class的后缀 例如统一加一个 "DTO"
9+
10+
"AssociationPrefix": "", //定义生成外键的字段名称的前缀 例如 “FK_”
11+
12+
"AssociationAppendByFieldName": true, //定义生成外键的字段名称是否根据增加 "By" + 他的字段名称
13+
14+
"GenerateAssociations": true, //是否生成外键
15+
16+
"ConnectionString": "Server=.\\;Database=antmgr;Trusted_Connection=True;Enlist=False;", //DB链接字符串
17+
18+
"OutFileName": "DbModels", //生成的cs文件名称
19+
20+
"SetFkList": [ //逻辑(非物理,不提倡物理建外键)
21+
//格式: A表名称,A表字段,B表名称,B表字段,外键关系(OneToOne,OneToMany,ManyToOne) 例如 "good_category,GoodTid,goods,Tid,OneToOne"
22+
],
23+
"UsingList": [ //设置Using
24+
25+
],
26+
"SetColumnTypeList": [ //自定义设置属性的类型 格式为 table.filedName=xxxxxx 例如:"person.Gender=GenderEnum"
27+
28+
]
29+
}

ant.mgr/Infrastructure/Infrastructure/CodeGen/CrudTemplete/Controller.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using Repository.Interface;
99
using ServicesModel;
1010
using ViewModels.Result;
1111
using ViewModels.Reuqest;
12+
using ant.mgr.core.Areas.Admin.Controllers;
1213

1314
namespace ant.mgr.core.Controllers
1415
{

ant.mgr/Infrastructure/Infrastructure/Infrastructure.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
55
</PropertyGroup>
66

77
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

ant.mgr/Mapping/Mapping/Mapping.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
55
</PropertyGroup>
66

77
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

ant.mgr/Repository/Repository/AdminRepository/AccountRespository.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,11 @@ public async Task<Tuple<bool, string>> UserDelete(long userTid)
269269
/// <returns></returns>
270270
public async Task<Tuple<bool, string>> ChangeField(ChangeFieldVm model)
271271
{
272-
if (model == null || string.IsNullOrEmpty(model.Field) || string.IsNullOrEmpty(model.Value) || !string.IsNullOrEmpty(model.Tid))
272+
if (model == null || string.IsNullOrEmpty(model.Field) || string.IsNullOrEmpty(model.Value) || model.Tid < 1)
273273
{
274274
return new Tuple<bool, string>(false, Tip.BadRequest);
275275
}
276-
IUpdatable<SystemUsers> updateQuery = null;
277-
278-
updateQuery = this.Entity.Where(r => r.Tid.Equals(model.Tid))
276+
IUpdatable<SystemUsers> updateQuery = this.Entity.Where(r => r.Tid.Equals(model.Tid))
279277
.Set2(model.Field, model.Value)
280278
.Set(r => r.DataChangeLastTime, DateTime.Now);
281279

@@ -362,7 +360,7 @@ public async Task<string> UpdateUserInfo(SystemUsers user)
362360

363361
if (string.IsNullOrEmpty(user.UserName) && string.IsNullOrEmpty(user.Phone)) return Tip.BadRequest;
364362

365-
var query = this.Entity.Where(r => r.Eid.Equals(user.Eid)).Set(r=>r.DataChangeLastTime,DateTime.Now);
363+
var query = this.Entity.Where(r => r.Eid.Equals(user.Eid)).Set(r => r.DataChangeLastTime, DateTime.Now);
366364

367365
if (!string.IsNullOrEmpty(user.UserName))
368366
{
@@ -404,7 +402,7 @@ public async Task<string> UpdatePwd(UpdatePwdVm user)
404402
}
405403

406404
var newPwd = CodingUtils.MD5(user.Pwd);
407-
var rt = this.Entity.Where(r => r.Eid.Equals(user.Eid)).Set(r => r.DataChangeLastTime, DateTime.Now).Set(r=>r.Pwd,newPwd).Update()>0;
405+
var rt = this.Entity.Where(r => r.Eid.Equals(user.Eid)).Set(r => r.DataChangeLastTime, DateTime.Now).Set(r => r.Pwd, newPwd).Update() > 0;
408406
if (!rt) return Tip.UpdateError;
409407
return string.Empty;
410408
}

ant.mgr/Repository/Repository/AdminRepository/MenuRespository.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace Repository
2525
public class MenuRespository : BaseRepository<SystemMenu>, IMenuRespository
2626
{
2727

28+
private static readonly int DisableMenuLevel = 88;
2829
private static readonly ConcurrentDictionary<string, List<SystemMenuSM>> _cache = new ConcurrentDictionary<string, List<SystemMenuSM>>();
2930

3031
/// <summary>
@@ -72,9 +73,13 @@ public long HaveMenuPermission(string currentUrl, string menuRights)
7273
if (menu == null)
7374
{
7475
return 0;
75-
//menu = DB.Query<SystemMenu>("select * from system_menu where url like @url ",new {url="~/"+controlname +"%"}).FirstOrDefault();
76-
//if(menu == null)return 0;
7776
}
77+
78+
if (menu.Level.HasValue && menu.Level.Value == DisableMenuLevel)//已经被逻辑删除了
79+
{
80+
return 0;
81+
}
82+
7883
var rights = new BigInteger(menuRights);
7984
if (!rights.TestBit((int)menu.Tid))
8085
{
@@ -171,7 +176,7 @@ public List<SystemMenuSM> GetMenuTree(long roleId, Token userToken, long roleSen
171176
}
172177
else
173178
{
174-
allMenusList = this.Entity.MappperTo<SystemMenuSM>().ToList();
179+
allMenusList = this.Entity.Where(r=>r.Level != DisableMenuLevel).MappperTo<SystemMenuSM>().ToList();
175180

176181
}
177182
var parentMenu = allMenusList.Where(r => r.ParentTid.Equals(0))
@@ -201,7 +206,8 @@ public string DisableMenu(long menuTid)
201206
{
202207
var updateResult = this.Entity.Where(r => r.Tid.Equals(menuTid))
203208
.Set(r => r.DataChangeLastTime, DateTime.Now)
204-
.Set(r => r.IsActive, false)
209+
.Set(r=>r.IsActive,false)
210+
.Set(r => r.Level, DisableMenuLevel)//目前最多支持2级。。 88是代表这个菜单不用了
205211
.Update() > 0;
206212
if (!updateResult)
207213
{
@@ -305,7 +311,7 @@ public string AddMenu(AddMenuVm model)
305311
/// <returns></returns>
306312
public List<SystemMenuSM> GetSubMenus(long menuTid)
307313
{
308-
var allMenus = this.Entity.Where(r => r.ParentTid == menuTid)
314+
var allMenus = this.Entity.Where(r => r.ParentTid == menuTid && r.Level != DisableMenuLevel)
309315
.OrderBy(r => r.OrderRule)
310316
.MappperTo<SystemMenuSM>()
311317
.ToList();
@@ -318,7 +324,7 @@ public List<SystemMenuSM> GetSubMenus(long menuTid)
318324
/// <returns></returns>
319325
public List<SystemMenuSM> GetAllParentMenus()
320326
{
321-
var allMenus = this.Entity.Where(r => r.ParentTid == 0)
327+
var allMenus = this.Entity.Where(r => r.ParentTid == 0 && r.Level!=DisableMenuLevel)
322328
.OrderBy(r => r.OrderRule)
323329
.MappperTo<SystemMenuSM>().ToList();
324330
return allMenus;
@@ -442,7 +448,7 @@ private List<SystemMenuSM> GetAllRightsMenusTwo(string eid, string menuRights, b
442448
return new List<SystemMenuSM>();
443449
}
444450
var right = new BigInteger(menuRights ?? "0");
445-
var allMenus = this.Entity.MappperTo<SystemMenuSM>().ToList();
451+
var allMenus = this.Entity.Where(r=>r.Level!=DisableMenuLevel).MappperTo<SystemMenuSM>().ToList();
446452
var parentMenu = allMenus.Where(r => r.ParentTid.Equals(0) && (right.TestBit((int)r.Tid) || isGlod))
447453
.OrderBy(r => r.OrderRule).ToList();
448454
//递归构建

ant.mgr/Repository/Repository/Repository.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
55
</PropertyGroup>
66

77
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

ant.mgr/ServicesModel/ServicesModel/ServicesModel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
</PropertyGroup>
77

ant.mgr/ViewModels/ViewModels/Admin/AccountVm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ChangeFieldVm
4040
/// <summary>
4141
/// 主键
4242
/// </summary>
43-
public string Tid { get; set; }
43+
public long Tid { get; set; }
4444

4545
/// <summary>
4646
/// 字段

ant.mgr/ViewModels/ViewModels/ViewModels.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
</PropertyGroup>
77

ant.mgr/mgr.core/ant.mgr.core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
</PropertyGroup>
77

@@ -15,7 +15,7 @@
1515
<PackageReference Include="Autofac.Annotation" Version="1.0.6" />
1616
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.3.1" />
1717
<PackageReference Include="Microsoft.AspNetCore.App" />
18-
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
18+
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
1919
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.9" />
2020
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
2121
<PackageReference Include="NLog.Extensions.Logging" Version="1.3.0" />

ant.mgr/mgr.core/appsettings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"AllowedHosts": "*",
99
"GoldList": "[zdyu]",
10+
"AntDbType": "mysql",
1011
"dal": [
1112
{
1213
"Provider": "mysql",
@@ -18,6 +19,17 @@
1819
"DatabaseType": "Master"
1920
}
2021
]
22+
},
23+
{
24+
"Provider": "sqlserver",
25+
"Name": "ant_sqlserver",
26+
"ConnectionItemList": [
27+
{
28+
"Name": "ant_sqlserver",
29+
"ConnectionString": "Server=.\\;Database=antmgr;Trusted_Connection=True;Enlist=False;",
30+
"DatabaseType": "Master"
31+
}
32+
]
2133
}
2234
]
2335
}

0 commit comments

Comments
 (0)