This commit is contained in:
94
Api/Dilon.Core/Service/Dict/Dto/DictDataInput.cs
Normal file
94
Api/Dilon.Core/Service/Dict/Dto/DictDataInput.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using Furion.DataValidation;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dilon.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典值参数
|
||||
/// </summary>
|
||||
public class DictDataInput : PageInputBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典类型Id
|
||||
/// </summary>
|
||||
public virtual long TypeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
public virtual string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 编码
|
||||
/// </summary>
|
||||
public virtual string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public virtual int Sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public virtual string Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态(字典 0正常 1停用 2删除)
|
||||
/// </summary>
|
||||
public virtual CommonStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public class QueryDictDataListInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典类型Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典类型Id不能为空"), DataValidation(ValidationTypes.Numeric)]
|
||||
public long TypeId { get; set; }
|
||||
}
|
||||
|
||||
public class AddDictDataInput : DictDataInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典类型Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典类型Id不能为空"), DataValidation(ValidationTypes.Numeric)]
|
||||
public override long TypeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典值不能为空")]
|
||||
public override string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 编码
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典值编码不能为空")]
|
||||
public override string Code { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteDictDataInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典值Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典值Id不能为空"), DataValidation(ValidationTypes.Numeric)]
|
||||
public long Id { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateDictDataInput : AddDictDataInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典值Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典值Id不能为空"), DataValidation(ValidationTypes.Numeric)]
|
||||
public long Id { get; set; }
|
||||
}
|
||||
|
||||
public class QueryDictDataInput : DeleteDictDataInput
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
13
Api/Dilon.Core/Service/Dict/Dto/DictDataOutput.cs
Normal file
13
Api/Dilon.Core/Service/Dict/Dto/DictDataOutput.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Dilon.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典值参数
|
||||
/// </summary>
|
||||
public class DictDataOutput : DictDataInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典Id
|
||||
/// </summary>
|
||||
public virtual long Id { get; set; }
|
||||
}
|
||||
}
|
||||
35
Api/Dilon.Core/Service/Dict/Dto/DictTreeOutput.cs
Normal file
35
Api/Dilon.Core/Service/Dict/Dto/DictTreeOutput.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dilon.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典类型与字典值构造的树
|
||||
/// </summary>
|
||||
public class DictTreeOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父Id
|
||||
/// </summary>
|
||||
public long Pid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 编码-对应字典值的编码
|
||||
/// </summary>
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称-对应字典值的value
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子节点集合
|
||||
/// </summary>
|
||||
public List<DictTreeOutput> Children { get; set; } = new List<DictTreeOutput>();
|
||||
}
|
||||
}
|
||||
82
Api/Dilon.Core/Service/Dict/Dto/DictTypeInput.cs
Normal file
82
Api/Dilon.Core/Service/Dict/Dto/DictTypeInput.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dilon.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典类型参数
|
||||
/// </summary>
|
||||
public class DictTypeInput : PageInputBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public virtual string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 编码
|
||||
/// </summary>
|
||||
public virtual string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public virtual int Sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public virtual string Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态(字典 0正常 1停用 2删除)
|
||||
/// </summary>
|
||||
public virtual CommonStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public class AddDictTypeInput : DictTypeInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典类型名称不能为空")]
|
||||
public override string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 编码
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典类型编码不能为空")]
|
||||
public override string Code { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteDictTypeInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 编号Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典类型Id不能为空")]
|
||||
public long Id { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateDictTypeInput : AddDictTypeInput
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典类型Id不能为空")]
|
||||
public long Id { get; set; }
|
||||
}
|
||||
|
||||
public class DropDownDictTypeInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 编码
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "字典类型编码不能为空")]
|
||||
public string Code { get; set; }
|
||||
}
|
||||
|
||||
public class QueryDictTypeInfoInput : DeleteDictTypeInput
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
18
Api/Dilon.Core/Service/Dict/ISysDictDataService.cs
Normal file
18
Api/Dilon.Core/Service/Dict/ISysDictDataService.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Dilon.Core.Service
|
||||
{
|
||||
public interface ISysDictDataService
|
||||
{
|
||||
Task AddDictData(AddDictDataInput input);
|
||||
Task ChangeDictDataStatus(UpdateDictDataInput input);
|
||||
Task DeleteByTypeId(long dictTypeId);
|
||||
Task DeleteDictData(DeleteDictDataInput input);
|
||||
Task<dynamic> GetDictData([FromQuery] QueryDictDataInput input);
|
||||
Task<dynamic> GetDictDataList([FromQuery] QueryDictDataListInput input);
|
||||
Task<dynamic> GetDictDataListByDictTypeId(long dictTypeId);
|
||||
Task<dynamic> QueryDictDataPageList([FromQuery] DictDataInput input);
|
||||
Task UpdateDictData(UpdateDictDataInput input);
|
||||
}
|
||||
}
|
||||
19
Api/Dilon.Core/Service/Dict/ISysDictTypeService.cs
Normal file
19
Api/Dilon.Core/Service/Dict/ISysDictTypeService.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Dilon.Core.Service
|
||||
{
|
||||
public interface ISysDictTypeService
|
||||
{
|
||||
Task AddDictType(AddDictTypeInput input);
|
||||
Task ChangeDictTypeStatus(UpdateDictTypeInput input);
|
||||
Task DeleteDictType(DeleteDictTypeInput input);
|
||||
Task<List<DictTreeOutput>> GetDictTree();
|
||||
Task<dynamic> GetDictType([FromQuery] QueryDictTypeInfoInput input);
|
||||
Task<dynamic> GetDictTypeDropDown([FromQuery] DropDownDictTypeInput input);
|
||||
Task<dynamic> GetDictTypeList();
|
||||
Task<dynamic> QueryDictTypePageList([FromQuery] DictTypeInput input);
|
||||
Task UpdateDictType(UpdateDictTypeInput input);
|
||||
}
|
||||
}
|
||||
164
Api/Dilon.Core/Service/Dict/SysDictDataService.cs
Normal file
164
Api/Dilon.Core/Service/Dict/SysDictDataService.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Dilon.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典值服务
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "DictData", Order = 100)]
|
||||
public class SysDictDataService : ISysDictDataService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysDictData> _sysDictDataRep; // 字典类型表仓储
|
||||
|
||||
public SysDictDataService(IRepository<SysDictData> sysDictDataRep)
|
||||
{
|
||||
_sysDictDataRep = sysDictDataRep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询字典值
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysDictData/page")]
|
||||
public async Task<dynamic> QueryDictDataPageList([FromQuery] DictDataInput input)
|
||||
{
|
||||
var code = !string.IsNullOrEmpty(input.Code?.Trim());
|
||||
var value = !string.IsNullOrEmpty(input.Value?.Trim());
|
||||
var dictDatas = await _sysDictDataRep.DetachedEntities
|
||||
.Where(u => u.TypeId == input.TypeId)
|
||||
.Where((code, u => EF.Functions.Like(u.Code, $"%{input.Code.Trim()}%")),
|
||||
(value, u => EF.Functions.Like(u.Value, $"%{input.Value.Trim()}%")))
|
||||
.Where(u => u.Status != CommonStatus.DELETED).OrderBy(u => u.Sort)
|
||||
.Select(u => u.Adapt<DictDataOutput>())
|
||||
.ToPagedListAsync(input.PageNo, input.PageSize);
|
||||
return XnPageResult<DictDataOutput>.PageResult(dictDatas);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取某个字典类型下字典值列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysDictData/list")]
|
||||
public async Task<dynamic> GetDictDataList([FromQuery] QueryDictDataListInput input)
|
||||
{
|
||||
return await _sysDictDataRep.DetachedEntities.Where(u => u.TypeId == input.TypeId).Where(u => u.Status != CommonStatus.DELETED).OrderBy(u => u.Sort).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加字典值
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysDictData/add")]
|
||||
public async Task AddDictData(AddDictDataInput input)
|
||||
{
|
||||
var isExist = await _sysDictDataRep.AnyAsync(u => (u.Code == input.Code || u.Value == input.Value) && u.TypeId == input.TypeId, false);
|
||||
if (isExist) throw Oops.Oh(ErrorCode.D3003);
|
||||
|
||||
var dictData = input.Adapt<SysDictData>();
|
||||
await _sysDictDataRep.InsertAsync(dictData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除字典值
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysDictData/delete")]
|
||||
public async Task DeleteDictData(DeleteDictDataInput input)
|
||||
{
|
||||
var dictData = await _sysDictDataRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
if (dictData == null) throw Oops.Oh(ErrorCode.D3004);
|
||||
|
||||
await dictData.DeleteAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新字典值
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysDictData/edit")]
|
||||
public async Task UpdateDictData(UpdateDictDataInput input)
|
||||
{
|
||||
var isExist = await _sysDictDataRep.AnyAsync(u => u.Id == input.Id, false);
|
||||
if (!isExist) throw Oops.Oh(ErrorCode.D3004);
|
||||
|
||||
// 排除自己并且判断与其他是否相同
|
||||
isExist = await _sysDictDataRep.AnyAsync(u => (u.Value == input.Value || u.Code == input.Code) && u.TypeId == input.TypeId && u.Id != input.Id, false);
|
||||
if (isExist) throw Oops.Oh(ErrorCode.D3003);
|
||||
|
||||
var dictData = input.Adapt<SysDictData>();
|
||||
await _sysDictDataRep.UpdateAsync(dictData, ignoreNullValues: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典值详情
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysDictData/detail")]
|
||||
public async Task<dynamic> GetDictData([FromQuery] QueryDictDataInput input)
|
||||
{
|
||||
return await _sysDictDataRep.FirstOrDefaultAsync(u => u.Id == input.Id, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改字典值状态
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysDictData/changeStatus")]
|
||||
public async Task ChangeDictDataStatus(UpdateDictDataInput input)
|
||||
{
|
||||
var dictData = await _sysDictDataRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
if (dictData == null) throw Oops.Oh(ErrorCode.D3004);
|
||||
|
||||
if (!Enum.IsDefined(typeof(CommonStatus), input.Status))
|
||||
throw Oops.Oh(ErrorCode.D3005);
|
||||
dictData.Status = input.Status;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据字典类型Id获取字典值集合
|
||||
/// </summary>
|
||||
/// <param name="dictTypeId"></param>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public async Task<dynamic> GetDictDataListByDictTypeId(long dictTypeId)
|
||||
{
|
||||
return await _sysDictDataRep.DetachedEntities.Where(u => u.SysDictType.Id == dictTypeId)
|
||||
.Where(u => u.Status != CommonStatus.DELETED).OrderBy(u => u.Sort)
|
||||
.Select(u => new
|
||||
{
|
||||
u.Code,
|
||||
u.Value
|
||||
}).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除字典下所有值
|
||||
/// </summary>
|
||||
/// <param name="dictTypeId"></param>
|
||||
[NonAction]
|
||||
public async Task DeleteByTypeId(long dictTypeId)
|
||||
{
|
||||
var dictDatas = await _sysDictDataRep.Where(u => u.TypeId == dictTypeId).ToListAsync();
|
||||
dictDatas.ForEach(u =>
|
||||
{
|
||||
u.Delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
175
Api/Dilon.Core/Service/Dict/SysDictTypeService.cs
Normal file
175
Api/Dilon.Core/Service/Dict/SysDictTypeService.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Dilon.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典类型服务
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "DictType", Order = 100)]
|
||||
public class SysDictTypeService : ISysDictTypeService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysDictType> _sysDictTypeRep; // 字典类型表仓储
|
||||
private readonly ISysDictDataService _sysDictDataService;
|
||||
|
||||
public SysDictTypeService(ISysDictDataService sysDictDataService,
|
||||
IRepository<SysDictType> sysDictTypeRep)
|
||||
{
|
||||
_sysDictDataService = sysDictDataService;
|
||||
_sysDictTypeRep = sysDictTypeRep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询字典类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysDictType/page")]
|
||||
public async Task<dynamic> QueryDictTypePageList([FromQuery] DictTypeInput input)
|
||||
{
|
||||
var code = !string.IsNullOrEmpty(input.Code?.Trim());
|
||||
var name = !string.IsNullOrEmpty(input.Name?.Trim());
|
||||
var dictTypes = await _sysDictTypeRep.DetachedEntities
|
||||
.Where((code, u => EF.Functions.Like(u.Code, $"%{input.Code.Trim()}%")),
|
||||
(name, u => EF.Functions.Like(u.Name, $"%{input.Name.Trim()}%")))
|
||||
.Where(u => u.Status != CommonStatus.DELETED).OrderBy(u => u.Sort)
|
||||
.ToPagedListAsync(input.PageNo, input.PageSize);
|
||||
return XnPageResult<SysDictType>.PageResult(dictTypes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取字典类型列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysDictType/list")]
|
||||
public async Task<dynamic> GetDictTypeList()
|
||||
{
|
||||
return await _sysDictTypeRep.DetachedEntities.Where(u => u.Status != CommonStatus.DELETED).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取字典类型下所有字典值
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("/sysDictType/dropDown")]
|
||||
public async Task<dynamic> GetDictTypeDropDown([FromQuery] DropDownDictTypeInput input)
|
||||
{
|
||||
var dictType = await _sysDictTypeRep.FirstOrDefaultAsync(u => u.Code == input.Code, false);
|
||||
if (dictType == null) throw Oops.Oh(ErrorCode.D3000);
|
||||
return await _sysDictDataService.GetDictDataListByDictTypeId(dictType.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加字典类型
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysDictType/add")]
|
||||
public async Task AddDictType(AddDictTypeInput input)
|
||||
{
|
||||
var isExist = await _sysDictTypeRep.AnyAsync(u => u.Name == input.Name || u.Code == input.Code, false);
|
||||
if (isExist) throw Oops.Oh(ErrorCode.D3001);
|
||||
|
||||
var dictType = input.Adapt<SysDictType>();
|
||||
await _sysDictTypeRep.InsertAsync(dictType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除字典类型
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysDictType/delete")]
|
||||
public async Task DeleteDictType(DeleteDictTypeInput input)
|
||||
{
|
||||
var dictType = await _sysDictTypeRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
if (dictType == null) throw Oops.Oh(ErrorCode.D3000);
|
||||
|
||||
var dictDatas = await _sysDictDataService.GetDictDataListByDictTypeId(input.Id); //_sysDictDataService.DeleteByTypeId(input.Id);
|
||||
if (dictDatas != null && dictDatas.Count > 0) throw Oops.Oh(ErrorCode.D3002);
|
||||
|
||||
await dictType.DeleteAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新字典类型
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysDictType/edit"),]
|
||||
public async Task UpdateDictType(UpdateDictTypeInput input)
|
||||
{
|
||||
var isExist = await _sysDictTypeRep.AnyAsync(u => u.Id == input.Id, false);
|
||||
if (!isExist) throw Oops.Oh(ErrorCode.D3000);
|
||||
|
||||
// 排除自己并且判断与其他是否相同
|
||||
isExist = await _sysDictTypeRep.AnyAsync(u => (u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id, false);
|
||||
if (isExist) throw Oops.Oh(ErrorCode.D3001);
|
||||
|
||||
var dictType = input.Adapt<SysDictType>();
|
||||
await _sysDictTypeRep.UpdateAsync(dictType, ignoreNullValues: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典类型详情
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysDictType/detail")]
|
||||
public async Task<dynamic> GetDictType([FromQuery] QueryDictTypeInfoInput input)
|
||||
{
|
||||
return await _sysDictTypeRep.FirstOrDefaultAsync(u => u.Id == input.Id, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新字典类型状态
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysDictType/changeStatus")]
|
||||
public async Task ChangeDictTypeStatus(UpdateDictTypeInput input)
|
||||
{
|
||||
var dictType = await _sysDictTypeRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
if (dictType == null) throw Oops.Oh(ErrorCode.D3000);
|
||||
|
||||
if (!Enum.IsDefined(typeof(CommonStatus), input.Status))
|
||||
throw Oops.Oh(ErrorCode.D3005);
|
||||
dictType.Status = input.Status;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典类型与字典值构造的字典树
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("/sysDictType/tree")]
|
||||
public async Task<List<DictTreeOutput>> GetDictTree()
|
||||
{
|
||||
return await _sysDictTypeRep.DetachedEntities.Select(u => new DictTreeOutput
|
||||
{
|
||||
Id = u.Id,
|
||||
Code = u.Code,
|
||||
Name = u.Name,
|
||||
Children = u.SysDictDatas.Select(c => new DictTreeOutput
|
||||
{
|
||||
Id = c.Id,
|
||||
Pid = c.TypeId,
|
||||
Code = c.Code,
|
||||
Name = c.Value
|
||||
}).ToList()
|
||||
}).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user