2021-08-23 16:57:25 +08:00
|
|
|
|
using Infrastructure;
|
|
|
|
|
|
using Infrastructure.Attribute;
|
2022-09-21 21:43:05 +08:00
|
|
|
|
using SqlSugar;
|
2022-09-16 08:20:09 +08:00
|
|
|
|
using System;
|
2022-12-24 17:16:06 +08:00
|
|
|
|
using System.Linq;
|
2021-11-28 11:11:34 +08:00
|
|
|
|
using ZR.Model;
|
2021-08-23 16:57:25 +08:00
|
|
|
|
using ZR.Model.System;
|
2021-09-16 19:35:17 +08:00
|
|
|
|
using ZR.Service.System.IService;
|
2021-08-23 16:57:25 +08:00
|
|
|
|
|
|
|
|
|
|
namespace ZR.Service.System
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 字典类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[AppService(ServiceType = typeof(ISysDictService), ServiceLifetime = LifeTime.Transient)]
|
2021-11-27 09:43:04 +08:00
|
|
|
|
public class SysDictService : BaseService<SysDictType>, ISysDictService
|
2021-09-06 15:56:53 +08:00
|
|
|
|
{
|
2022-09-21 21:43:05 +08:00
|
|
|
|
private ISysDictDataService DictDataService;
|
2021-08-23 16:57:25 +08:00
|
|
|
|
|
2022-09-21 21:43:05 +08:00
|
|
|
|
public SysDictService(ISysDictDataService dictDataRepository)
|
2021-08-23 16:57:25 +08:00
|
|
|
|
{
|
2022-09-21 21:43:05 +08:00
|
|
|
|
this.DictDataService = dictDataRepository;
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
2021-11-21 15:48:24 +08:00
|
|
|
|
public List<SysDictType> GetAll()
|
|
|
|
|
|
{
|
2022-09-21 21:43:05 +08:00
|
|
|
|
return Queryable().ToList();
|
2021-11-21 15:48:24 +08:00
|
|
|
|
}
|
2021-08-23 16:57:25 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询字段类型列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dictType">实体模型</param>
|
2022-09-21 21:43:05 +08:00
|
|
|
|
/// <param name="pager"></param>
|
2021-08-23 16:57:25 +08:00
|
|
|
|
/// <returns></returns>
|
2022-09-21 21:43:05 +08:00
|
|
|
|
public PagedInfo<SysDictType> SelectDictTypeList(SysDictType dictType, PagerInfo pager)
|
2021-08-23 16:57:25 +08:00
|
|
|
|
{
|
2022-09-21 21:43:05 +08:00
|
|
|
|
var exp = Expressionable.Create<SysDictType>();
|
|
|
|
|
|
exp.AndIF(!string.IsNullOrEmpty(dictType.DictName), it => it.DictName.Contains(dictType.DictName));
|
|
|
|
|
|
exp.AndIF(!string.IsNullOrEmpty(dictType.Status), it => it.Status == dictType.Status);
|
|
|
|
|
|
exp.AndIF(!string.IsNullOrEmpty(dictType.DictType), it => it.DictType.Contains(dictType.DictType));
|
|
|
|
|
|
exp.AndIF(!string.IsNullOrEmpty(dictType.Type), it => it.Type.Equals(dictType.Type));
|
|
|
|
|
|
|
|
|
|
|
|
return GetPages(exp.ToExpression(), pager, f => f.DictId, OrderByType.Desc);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 校验字典类型称是否唯一
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dictType">字典类型</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public string CheckDictTypeUnique(SysDictType dictType)
|
|
|
|
|
|
{
|
2022-09-21 21:43:05 +08:00
|
|
|
|
SysDictType sysDictType = GetFirst(f => f.DictType == dictType.DictType);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
if (sysDictType != null && sysDictType.DictId != dictType.DictId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
return UserConstants.UNIQUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 批量删除字典数据信息
|
|
|
|
|
|
/// </summary>
|
2022-09-21 21:43:05 +08:00
|
|
|
|
/// <param name="dictIds"></param>
|
2021-08-23 16:57:25 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int DeleteDictTypeByIds(long[] dictIds)
|
|
|
|
|
|
{
|
2022-12-24 17:16:06 +08:00
|
|
|
|
int sysCount = Count(s => s.Type == "Y" && dictIds.Contains(s.DictId));
|
|
|
|
|
|
if (sysCount > 0) { throw new CustomException($"删除失败Id: 系统内置参数不能删除!"); }
|
2021-08-23 16:57:25 +08:00
|
|
|
|
foreach (var dictId in dictIds)
|
|
|
|
|
|
{
|
2022-09-21 21:43:05 +08:00
|
|
|
|
SysDictType dictType = GetFirst(x => x.DictId == dictId);
|
|
|
|
|
|
if (DictDataService.Count(f => f.DictType == dictType.DictType) > 0)
|
2021-08-23 16:57:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
throw new CustomException($"{dictType.DictName}已分配,不能删除");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-09-21 21:43:05 +08:00
|
|
|
|
int count = Context.Deleteable<SysDictType>().In(dictIds).ExecuteCommand();
|
2021-08-23 16:57:25 +08:00
|
|
|
|
//if (count > 0)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// DictUtils.clearDictCache();
|
|
|
|
|
|
//}
|
|
|
|
|
|
return count;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 插入字典类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sysDictType"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public long InsertDictType(SysDictType sysDictType)
|
|
|
|
|
|
{
|
2022-09-21 21:43:05 +08:00
|
|
|
|
return InsertReturnBigIdentity(sysDictType);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改字典类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sysDictType"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int UpdateDictType(SysDictType sysDictType)
|
|
|
|
|
|
{
|
2022-09-21 21:43:05 +08:00
|
|
|
|
SysDictType oldDict = GetFirst(x => x.DictId == sysDictType.DictId);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
if (sysDictType.DictType != oldDict.DictType)
|
|
|
|
|
|
{
|
|
|
|
|
|
//同步修改 dict_data表里面的DictType值
|
2022-09-21 21:43:05 +08:00
|
|
|
|
DictDataService.UpdateDictDataType(oldDict.DictType, sysDictType.DictType);
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
2022-09-21 21:43:05 +08:00
|
|
|
|
return Context.Updateable(sysDictType).IgnoreColumns(it => new { sysDictType.Create_by }).ExecuteCommand();
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
2021-09-27 16:07:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取字典信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dictId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public SysDictType GetInfo(long dictId)
|
|
|
|
|
|
{
|
2022-09-21 21:43:05 +08:00
|
|
|
|
return GetFirst(f => f.DictId == dictId);
|
2021-09-27 16:07:55 +08:00
|
|
|
|
}
|
2022-09-16 08:20:09 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据字典类型查询自定义sql
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dictType"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public List<SysDictData> SelectDictDataByCustomSql(string dictType)
|
|
|
|
|
|
{
|
2022-09-21 21:43:05 +08:00
|
|
|
|
var dictInfo = Queryable()
|
2022-09-16 08:20:09 +08:00
|
|
|
|
.Where(f => f.DictType == dictType).First();
|
|
|
|
|
|
if (dictInfo == null || !dictInfo.CustomSql.StartsWith("select", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2022-09-21 21:43:05 +08:00
|
|
|
|
return DictDataService.SelectDictDataByCustomSql(dictInfo);
|
2022-09-16 08:20:09 +08:00
|
|
|
|
}
|
2021-08-23 16:57:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|