Skip to content

Commit

Permalink
修复新用户因初始配置缺失导致的系列错误
Browse files Browse the repository at this point in the history
  • Loading branch information
GalensGan committed Feb 24, 2022
1 parent 55d9df3 commit 753ebf1
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 12 deletions.
6 changes: 5 additions & 1 deletion Server/Server/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ protected override void ConfigureIoC(IStyletIoCBuilder builder)
// 注册 IoC
var userConfig = new UserConfig();
builder.Bind<UserConfig>().ToInstance(userConfig);
builder.Bind<LiteDBManager>().ToInstance(new LiteDBManager(userConfig));
var liteDb = new LiteDBManager(userConfig);
builder.Bind<LiteDBManager>().ToInstance(liteDb);

// 进行系统层面的初始化
// 暂无

base.ConfigureIoC(builder);
}
Expand Down
6 changes: 3 additions & 3 deletions Server/Server/Database/Models/SendBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public class SendBox : EmailInfo
/// <summary>
/// 发件箱设置
/// </summary>
public SendBoxSetting settings { get; set; }
public SendBoxSetting settings { get; set; } = new SendBoxSetting();

/// <summary>
/// 递增发件量
/// </summary>
/// <returns>true:可以继续发件;false:发件已达到最大数量</returns>
public bool IncreaseSentCount(LiteDBManager liteDb,Setting globalSetting)
public bool IncreaseSentCount(LiteDBManager liteDb, Setting globalSetting)
{
// 判断日期是否是今天,如果不是,则将当天发件数置 0
string date = DateTime.Now.ToString("yyyy-MM-dd");
Expand Down Expand Up @@ -53,7 +53,7 @@ public class SendBoxSetting
public bool asSender { get; set; } = true;

// 单日最大发件量
public int maxEmailsPerDay { get; set; }
public int maxEmailsPerDay { get; set; } = 40;

// 总发件量
// 系统自动增加
Expand Down
21 changes: 21 additions & 0 deletions Server/Server/Database/Models/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace Server.Database.Models
{
public class Setting:AutoObjectId
{
/// <summary>
/// 用户名
/// </summary>
public string userId { get; set; }

/// <summary>
Expand All @@ -31,5 +34,23 @@ public class Setting:AutoObjectId

// 单日最大发件量
public int maxEmailsPerDay { get; set; }

/// <summary>
/// 生成默认配置
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public static Setting DefaultSetting(string userId)
{
return new Setting()
{
userId = userId,
maxEmailsPerDay = 40,
isAutoResend = true,
sendInterval_max = 8,
sendInterval_min = 3,
sendWithImageAndHtml = false,
};
}
}
}
2 changes: 1 addition & 1 deletion Server/Server/Http/Controller/BaseControllerAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Server.Http.Controller
/// <summary>
/// 具有异步的 controller 基类
/// </summary>
public class BaseControllerAsync : BaseController
public abstract class BaseControllerAsync : BaseController
{
// 异步发送数据
private async Task SendJObjectAsync(object obj)
Expand Down
16 changes: 13 additions & 3 deletions Server/Server/Http/Controller/Ctrler_Report.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,21 @@ public async Task GetINboxTypeAndCount()
var userId = Token.UserId;
// 获取用户发送的历史组
var historyGroups = LiteDb.Fetch<HistoryGroup>(g => g.userId == userId).ToList();
var defaultValueString = "[{'name':'未发件','value':0}]";
var defaultResults = new JArray()
{
new JObject(){ { "name","未发件"},{ "value",0} }
};
if (historyGroups.Count < 1)
{
// 返回默认值
await ResponseSuccessAsync(JObject.Parse(defaultValueString));
try
{
await ResponseSuccessAsync(defaultResults);
}
catch (Exception e)
{
;
}
return;
};

Expand All @@ -76,7 +86,7 @@ public async Task GetINboxTypeAndCount()
if (sendItems.Count < 1)
{
// 返回1
await ResponseSuccessAsync(JObject.Parse(defaultValueString));
await ResponseSuccessAsync(defaultResults);
return;
}

Expand Down
3 changes: 3 additions & 0 deletions Server/Server/Http/Controller/Ctrler_User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public async Task UserLogin()
password = password,
createDate = DateTime.Now
});

// 新建用户后,同时给用户建立默认配置
LiteDb.Insert(Setting.DefaultSetting(userId));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Server/Server/Http/HttpServiceMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private WebServer CreateWebServer(string url)
Type baseType = typeof(BaseController);
List<Type> controllers = types.Where(t =>
{
return baseType == t.BaseType;
return !t.IsAbstract && baseType.IsAssignableFrom(t);
}).ToList();
string baseRout = UserConfig.Instance.BaseRoute;
server.WithWebApi(baseRout, m => {
Expand Down
4 changes: 2 additions & 2 deletions Server/Server/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.3.0")]
[assembly: AssemblyFileVersion("0.4.3.0")]
[assembly: AssemblyVersion("0.4.4.0")]
[assembly: AssemblyFileVersion("0.4.4.0")]

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Config\\log4net.config", Watch = true)]
1 change: 0 additions & 1 deletion UI/src/views/dashboard/components/inboxTypes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import 'echarts-liquidfill'
import * as echarts from 'echarts'
import resize from '@/components/Echarts/mixins/resize'
import _ from 'lodash'
import { getInboxCountOfTyes } from '@/api/report'
export default {
Expand Down

0 comments on commit 753ebf1

Please sign in to comment.