You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
6.3 KiB

7 months ago
using Common.Enum;
using Entity.Base;
using Entity.DbModel.System;
7 months ago
using Entity.Dto.Req;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
7 months ago
using Mapster;
using Repository.System;
using SqlSugar;
namespace Service.System.Dict
{
[Scope("SingleInstance")]
public class SysDictDataService : BaseServices<SysDictData>
{
private readonly SysDicDataRepository _sysDictDataRep;
public SysDictDataService(SysDicDataRepository sysDictDataRep)
{
_sysDictDataRep = sysDictDataRep;
base.BaseDal = sysDictDataRep;
}
/// <summary>
/// 获取字典值分页列表 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<PageResult<SysDictData>> Page(PageDictDataReq input)
7 months ago
{
RefAsync<int> total = 0;
var items = await _sysDictDataRep.QueryListByClauseAsync(
u => u.DictTypeId == input.DictTypeId,
!string.IsNullOrEmpty(input.Code?.Trim()), u => u.Code.Contains(input.Code),
!string.IsNullOrEmpty(input.Value?.Trim()), u => u.Value.Contains(input.Value),
u => new { u.OrderNo, u.Code }, input.PageNum, input.PageSize, total);
return new PageResult<SysDictData>()
{
PageNum = input.PageNum,
PageSize = input.PageSize,
ToTal = total,
Rows = items,
};
7 months ago
}
/// <summary>
/// 获取字典值列表 🔖
/// </summary>
/// <returns></returns>
public async Task<List<SysDictData>> GetList(GetDataDictDataReq input)
{
return await GetDictDataListByDictTypeId(input.DictTypeId);
}
/// <summary>
/// 增加字典值 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> AddDictData(AddDictDataReq input)
{
string result = "";
var isExist = await _sysDictDataRep.QueryByClauseAsync(u => u.Code == input.Code && u.DictTypeId == input.DictTypeId);
if (isExist != null)
result = "字典值已存在,名称或编码重复";
await _sysDictDataRep.InsertAsync(input.Adapt<SysDictData>());
return result;
}
/// <summary>
/// 更新字典值 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> UpdateDictData(UpdateDictDataReq input)
{
string result = "";
var isExist = await _sysDictDataRep.QueryByClauseAsync(u => u.Id == input.Id);
if (isExist == null)
result = "字典值不存在";
isExist = await _sysDictDataRep.QueryByClauseAsync(u => u.Code == input.Code && u.DictTypeId == input.DictTypeId && u.Id != input.Id);
if (isExist != null)
result = "字典值已存在,名称或编码重复";
await _sysDictDataRep.UpdateAsync(input.Adapt<SysDictData>());
return result;
}
/// <summary>
/// 删除字典值 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> DeleteDictData(DeleteDictDataReq input)
{
string result = "";
var dictData = await _sysDictDataRep.QueryByClauseAsync(u => u.Id == input.Id);
if (dictData == null)
result = "字典值不存在";
await _sysDictDataRep.DeleteAsync(dictData);
return result;
}
/// <summary>
/// 获取字典值详情 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<SysDictData> GetDetail(DictDataReq input)
{
return await _sysDictDataRep.QueryByClauseAsync(u => u.Id == input.Id);
}
/// <summary>
/// 修改字典值状态 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> SetStatus(DictDataReq input)
{
string result = "";
var dictData = await _sysDictDataRep.QueryByClauseAsync(u => u.Id == input.Id);
if (dictData == null)
result = "字典值不存在";
if (!Enum.IsDefined(typeof(StatusEnum), input.Status))
result = "字典状态错误";
dictData.Status = input.Status;
await _sysDictDataRep.UpdateAsync(dictData);
return result;
}
/// <summary>
/// 根据字典类型Id获取字典值集合
/// </summary>
/// <param name="dictTypeId"></param>
/// <returns></returns>
public async Task<List<SysDictData>> GetDictDataListByDictTypeId(long dictTypeId)
{
return await _sysDictDataRep.QueryByOrderByClauseAsync(
u => u.DictTypeId == dictTypeId, u => new { u.OrderNo, u.Code });
}
/// <summary>
/// 根据字典类型编码获取字典值集合 🔖
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public async Task<List<SysDictData>> GetDataList(string code)
{
return await _sysDictDataRep.QueryByClauseAsync<SysDictType, SysDictData, SysDictData>(
(u, a) => u.Id == a.DictTypeId,
(u, a) => u.Code == code && u.Status == StatusEnum.Enable && a.Status == StatusEnum.Enable,
(u, a) => new { a.OrderNo, a.Code },
(u, a) => a);
}
/// <summary>
/// 根据查询条件获取字典值集合 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<List<SysDictData>> GetDataList(QueryDictDataReq input)
{
return await _sysDictDataRep.QueryByClauseAsync<SysDictType, SysDictData, SysDictData>(
(u, a) => u.Id == a.DictTypeId, (u, a) => u.Code == input.Code,
input.Status.HasValue, (u, a) => a.Status == (StatusEnum)input.Status.Value,
(u, a) => new { a.OrderNo, a.Code },
(u, a) => a);
}
}
}