using Edu.Common.Encrypt;
using Edu.Model.ViewModel.User;
using Edu.Repository.User;
using System;
using System.Collections.Generic;
using VT.FW.DB;
namespace Edu.Module.User
{
///
/// 账号管理处理类
///
public class AccountModule
{
///
/// 账号管理处理类对象
///
private readonly RB_AccountRepository accountRepository = new RB_AccountRepository();
///
/// 获取账号列表
///
///
///
public List GetAccountListModule(RB_Account_ViewModel query)
{
return accountRepository.GetAccountListRepository(query);
}
///
/// 获取账号分页列表
///
///
///
///
///
///
public List GetAccountPageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Account_ViewModel query)
{
return accountRepository.GetAccountPageListRepository(pageIndex, pageSize, out rowsCount, query);
}
///
/// 获取账号列表扩展列表
///
///
///
public List GetAccountListExtModule(RB_Account_ViewModel query)
{
return accountRepository.GetAccountListExtRepository(query);
}
///
/// 添加修改账号
///
///
///
public bool SetAccountModule(RB_Account_ViewModel model)
{
bool flag;
if (model.Id > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Account_ViewModel.Account),model.Account.Trim() },
{nameof(RB_Account_ViewModel.AccountType),model.AccountType},
{nameof(RB_Account_ViewModel.AccountId),model.AccountId},
{nameof(RB_Account_ViewModel.UpdateBy),model.UpdateBy},
{nameof(RB_Account_ViewModel.UpdateTime),model.UpdateTime},
};
flag = accountRepository.Update(fileds, new WhereHelper(nameof(RB_Account_ViewModel.Id), model.Id));
}
else
{
var newId = accountRepository.Insert(model);
model.Id = newId;
flag = newId > 0;
}
return flag;
}
///
/// 修改账号状态
///
///
///
public bool SetAccountStatusModule(RB_Account_ViewModel model)
{
bool flag;
Dictionary fileds = new Dictionary()
{
{nameof(RB_Account_ViewModel.Status),(int)model.Status },
{nameof(RB_Account_ViewModel.UpdateTime),model.UpdateTime },
};
List list = new List()
{
new WhereHelper(nameof(RB_Account_ViewModel.AccountId),model.AccountId),
new WhereHelper(nameof(RB_Account_ViewModel.AccountType),(int)model.AccountType),
};
flag = accountRepository.Update(fileds, list);
return flag;
}
///
/// 重置密码
///
///
///
public (bool reuslt,string newPass) SetResetPassword(RB_Account_ViewModel model)
{
bool flag;
//生成随机新密码
var newPwd = PwHelper.MakePassword(8);
Dictionary fileds = new Dictionary()
{
{nameof(RB_Account_ViewModel.Password), Common.DES.Encrypt(newPwd)}
};
var wheres = new List
{
new WhereHelper(nameof(RB_Account_ViewModel.AccountId), model.AccountId),
new WhereHelper(nameof(RB_Account_ViewModel.AccountType), model.AccountType),
new WhereHelper(nameof(RB_Account_ViewModel.Group_Id), model.Group_Id)
};
flag = accountRepository.Update(fileds, wheres);
return (flag, newPwd);
}
}
}