You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PLT-PDA/Admin.Core.Service/Sys/SysDictDataService.cs

119 lines
3.9 KiB
C#

//----------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
{
/// <summary>
/// 字典数据表Service
/// </summary>
public partial class SysDictDataService : BaseServices<SysDictData>, ISysDictDataService
{
IBaseRepository<SysDictData> dal;
public SysDictDataService(IBaseRepository<SysDictData> dal)
{
this.dal = dal;
BaseDal = dal;
}
/// <summary>
/// 根据条件分页查询字典类型
/// </summary>
/// <param name="SysDictData"> 字典类型信息 </param>
/// <returns> 字典类型集合信息 </returns>
public async Task<PageModel<SysDictData>> SelectDictDataList(PageQuery<SysDictData> pageQuery)
{
Expression<Func<SysDictData, bool>> 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;
}
/// <summary>
/// 根据字典类型和字典键值查询字典数据信息
/// </summary>
/// <param name="dictType"> 字典类型 </param>
/// <param name="dictValue"> 字典键值 </param>
/// <returns> 字典标签 </returns>
public async Task<string> SelectDictLabel(string dictType, string dictValue)
{
var datas = await dal.QueryAsync(x => x.DictType == dictType && x.DictValue == dictValue);
return datas.FirstOrDefault()?.DictLabel;
}
/// <summary>
/// 根据字典数据ID查询信息
/// </summary>
/// <param name="dictCode"> 字典数据ID </param>
/// <returns> 字典数据 </returns>
public async Task<SysDictData> SelectDictDataById(int dictCode)
{
return await dal.QueryByIdAsync(dictCode);
}
/// <summary>
/// 批量删除字典数据信息
/// </summary>
/// <param name="dictCodes"> 需要删除的字典数据ID </param>
/// <returns> 结果 </returns>
public async Task<bool> DeleteDictDataByIds(List<int> dictCodes)
{
var datas = await dal.QueryAsync(x => dictCodes.Contains(x.DictCode));
return await dal.DeletesAsync(datas);
}
/// <summary>
/// 新增保存字典数据信息
/// </summary>
/// <param name="data"> 字典数据信息 </param>
/// <returns> 结果 </returns>
public async Task<int> InsertDictData(SysDictData data)
{
data.CreateTime = DateTime.Now;
data.UpdateTime = DateTime.Now;
return await dal.AddAsync(data);
}
/// <summary>
/// 修改保存字典数据信息
/// </summary>
/// <param name="data"> 字典数据信息 </param>
/// <returns> 结果 </returns>
public async Task<bool> UpdateDictData(SysDictData data)
{
data.UpdateTime = DateTime.Now;
return await dal.UpdateAsync(data);
}
}
}
//----------SysDictData结束----------