//----------SysDictData开始----------
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Admin.Core.IRepository;
using Admin.Core.Model;
using System.Linq;
using System.Linq.Expressions;
using Admin.Core.Common;
using Admin.Core.IService.ISys;
using Admin.Core.Model.Sys;
namespace Admin.Core.Service.Sys
{
///
/// 字典数据表Service
///
public partial class SysDictDataService : BaseServices, ISysDictDataService
{
IBaseRepository dal;
public SysDictDataService(IBaseRepository dal)
{
this.dal = dal;
BaseDal = dal;
}
///
/// 根据条件分页查询字典类型
///
/// 字典类型信息
/// 字典类型集合信息
public async Task> SelectDictDataList(PageQuery pageQuery)
{
Expression> whereExpression = x => true;
if (pageQuery.Query.DictLabel.IsNotEmptyOrNull())
{
whereExpression = whereExpression.And(x => x.DictLabel.Contains(pageQuery.Query.DictLabel));
}
if (pageQuery.Query.DictType.IsNotEmptyOrNull())
{
whereExpression = whereExpression.And(x => x.DictType.Contains(pageQuery.Query.DictType));
}
if (pageQuery.Query.Status.IsNotEmptyOrNull())
{
whereExpression = whereExpression.And(x => x.Status == pageQuery.Query.Status);
}
var data = await dal.QueryPageAsync(whereExpression, pageQuery.Page, pageQuery.PageSize, "DictSort asc");
return data;
}
///
/// 根据字典类型和字典键值查询字典数据信息
///
/// 字典类型
/// 字典键值
/// 字典标签
public async Task SelectDictLabel(string dictType, string dictValue)
{
var datas = await dal.QueryAsync(x => x.DictType == dictType && x.DictValue == dictValue);
return datas.FirstOrDefault()?.DictLabel;
}
///
/// 根据字典数据ID查询信息
///
/// 字典数据ID
/// 字典数据
public async Task SelectDictDataById(int dictCode)
{
return await dal.QueryByIdAsync(dictCode);
}
///
/// 批量删除字典数据信息
///
/// 需要删除的字典数据ID
/// 结果
public async Task DeleteDictDataByIds(List dictCodes)
{
var datas = await dal.QueryAsync(x => dictCodes.Contains(x.DictCode));
return await dal.DeletesAsync(datas);
}
///
/// 新增保存字典数据信息
///
/// 字典数据信息
/// 结果
public async Task InsertDictData(SysDictData data)
{
data.CreateTime = DateTime.Now;
data.UpdateTime = DateTime.Now;
return await dal.AddAsync(data);
}
///
/// 修改保存字典数据信息
///
/// 字典数据信息
/// 结果
public async Task UpdateDictData(SysDictData data)
{
data.UpdateTime = DateTime.Now;
return await dal.UpdateAsync(data);
}
}
}
//----------SysDictData结束----------