Browse Source

通用字段对照

master
wxd 2 years ago
parent
commit
430f103079
  1. 15
      src/Shentun.Peis.Application.Contracts/AuditedEntityDtoName.cs
  2. 26
      src/Shentun.Peis.Application.Contracts/CommonTableTypes/CommonTableTypeDto.cs
  3. 12
      src/Shentun.Peis.Application.Contracts/CommonTableTypes/CommonTableTypeIdInputDto.cs
  4. 20
      src/Shentun.Peis.Application.Contracts/CommonTableTypes/CreateCommonTableTypeDto.cs
  5. 19
      src/Shentun.Peis.Application.Contracts/CommonTableTypes/UpdateCommonTableTypeDto.cs
  6. 20
      src/Shentun.Peis.Application.Contracts/CommonTableTypes/UpdateManySortCommonTableTypeInputDto.cs
  7. 31
      src/Shentun.Peis.Application.Contracts/CommonTables/CommonTableDto.cs
  8. 11
      src/Shentun.Peis.Application.Contracts/CommonTables/CommonTableIdInputDto.cs
  9. 27
      src/Shentun.Peis.Application.Contracts/CommonTables/CreateCommonTableDto.cs
  10. 26
      src/Shentun.Peis.Application.Contracts/CommonTables/UpdateCommonTableDto.cs
  11. 20
      src/Shentun.Peis.Application.Contracts/CommonTables/UpdateManySortCommonTableInputDto.cs
  12. 157
      src/Shentun.Peis.Application/CommonTableTypes/CommonTableTypeAppService.cs
  13. 159
      src/Shentun.Peis.Application/CommonTables/CommonTableAppService.cs
  14. 11
      src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs
  15. 11
      src/Shentun.Peis.Domain/CommonTableTypes/CommonTableType.cs
  16. 120
      src/Shentun.Peis.Domain/CommonTableTypes/CommonTableTypeManager.cs
  17. 2
      src/Shentun.Peis.Domain/CommonTables/CommonTable.cs
  18. 122
      src/Shentun.Peis.Domain/CommonTables/CommonTableManager.cs
  19. 98
      src/Shentun.Peis.Domain/EntityHelper.cs
  20. 14
      src/Shentun.Peis.Domain/HelperDto/UpdateSortManyDto.cs
  21. 1
      src/Shentun.Peis.EntityFrameworkCore/EntityFrameworkCore/PeisDbContext.cs

15
src/Shentun.Peis.Application.Contracts/AuditedEntityDtoName.cs

@ -29,4 +29,19 @@ namespace Shentun.Peis
/// </summary>
public string LastModifierName { get; set; }
}
public class AuditedEntityDtoNameString : AuditedEntityDto<string>
{
/// <summary>
/// 创建者
/// </summary>
public string CreatorName { get; set; }
/// <summary>
/// 最后修改者
/// </summary>
public string LastModifierName { get; set; }
}
}

26
src/Shentun.Peis.Application.Contracts/CommonTableTypes/CommonTableTypeDto.cs

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Shentun.Peis.CommonTableTypes
{
public class CommonTableTypeDto: AuditedEntityDtoNameString
{
/// <summary>
/// 名称
/// </summary>
public string DisplayName { get; set; }
/// <summary>
/// 简拼
/// </summary>
public string SimpleCode { get; set; }
/// <summary>
///
/// </summary>
public int DisplayOrder { get; set; }
}
}

12
src/Shentun.Peis.Application.Contracts/CommonTableTypes/CommonTableTypeIdInputDto.cs

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.CommonTableTypes
{
public class CommonTableTypeIdInputDto
{
public string CommonTableTypeId { get; set; }
}
}

20
src/Shentun.Peis.Application.Contracts/CommonTableTypes/CreateCommonTableTypeDto.cs

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.CommonTableTypes
{
public class CreateCommonTableTypeDto
{
/// <summary>
/// 主键
/// </summary>
public string CommonTableTypeId { get; set; }
/// <summary>
/// 名称
/// </summary>
public string DisplayName { get; set; }
}
}

19
src/Shentun.Peis.Application.Contracts/CommonTableTypes/UpdateCommonTableTypeDto.cs

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.CommonTableTypes
{
public class UpdateCommonTableTypeDto
{
/// <summary>
/// 主键
/// </summary>
public string CommonTableTypeId { get; set; }
/// <summary>
/// 名称
/// </summary>
public string DisplayName { get; set; }
}
}

20
src/Shentun.Peis.Application.Contracts/CommonTableTypes/UpdateManySortCommonTableTypeInputDto.cs

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.CommonTableTypes
{
public class UpdateManySortCommonTableTypeInputDto
{
/// <summary>
/// 需要修改的ID
/// </summary>
public string CommonTableTypeId { get; set; }
/// <summary>
/// 修改方式:1 置顶 2 置底
/// </summary>
public int SortType { get; set; }
}
}

31
src/Shentun.Peis.Application.Contracts/CommonTables/CommonTableDto.cs

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Shentun.Peis.CommonTables
{
public class CommonTableDto : AuditedEntityDtoName
{
/// <summary>
/// 对照值
/// </summary>
public string DataCode { get; set; } = null!;
/// <summary>
/// 名称
/// </summary>
public string DisplayName { get; set; } = null!;
/// <summary>
/// 通用字段对照类别
/// </summary>
public string CommonTableTypeId { get; set; }
public string SimpleCode { get; set; } = null!;
public int DisplayOrder { get; set; }
}
}

11
src/Shentun.Peis.Application.Contracts/CommonTables/CommonTableIdInputDto.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.CommonTables
{
public class CommonTableIdInputDto
{
public Guid CommonTableId { get; set;}
}
}

27
src/Shentun.Peis.Application.Contracts/CommonTables/CreateCommonTableDto.cs

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.CommonTables
{
public class CreateCommonTableDto
{
/// <summary>
/// 对照值
/// </summary>
public string DataCode { get; set; } = null!;
/// <summary>
/// 名称
/// </summary>
public string DisplayName { get; set; } = null!;
/// <summary>
/// 通用字段对照类别
/// </summary>
public string CommonTableTypeId { get; set; }
}
}

26
src/Shentun.Peis.Application.Contracts/CommonTables/UpdateCommonTableDto.cs

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.CommonTables
{
public class UpdateCommonTableDto
{
public Guid CommonTableId { get; set; }
/// <summary>
/// 对照值
/// </summary>
public string DataCode { get; set; } = null!;
/// <summary>
/// 名称
/// </summary>
public string DisplayName { get; set; } = null!;
/// <summary>
/// 通用字段对照类别
/// </summary>
public string CommonTableTypeId { get; set; }
}
}

20
src/Shentun.Peis.Application.Contracts/CommonTables/UpdateManySortCommonTableInputDto.cs

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.CommonTables
{
public class UpdateManySortCommonTableInputDto
{
/// <summary>
/// 需要修改的ID
/// </summary>
public Guid CommonTableId { get; set; }
/// <summary>
/// 修改方式:1 置顶 2 置底
/// </summary>
public int SortType { get; set; }
}
}

157
src/Shentun.Peis.Application/CommonTableTypes/CommonTableTypeAppService.cs

@ -0,0 +1,157 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.CommonCharTypes;
using Shentun.Peis.HelperDto;
using Shentun.Peis.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
using Shentun.Peis.CommonTableTypes;
namespace Shentun.Peis.CommonTableTypes
{
/// <summary>
/// 通用字段对照类别
/// </summary>
[ApiExplorerSettings(GroupName = "Work")]
[Authorize]
public class CommonTableTypeAppService : ApplicationService
{
private readonly IRepository<CommonTableType, string> _commonTableTypeRepository;
private readonly CommonTableTypeManager _commonTableTypeManager;
private readonly CacheService _cacheService;
public CommonTableTypeAppService(
IRepository<CommonTableType, string> commonTableTypeRepository,
CommonTableTypeManager commonTableTypeManager,
CacheService cacheService)
{
_commonTableTypeRepository = commonTableTypeRepository;
_commonTableTypeManager = commonTableTypeManager;
_cacheService = cacheService;
}
/// <summary>
/// 获取通过主键
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTableType/Get")]
public async Task<CommonTableTypeDto> GetAsync(CommonTableTypeIdInputDto input)
{
var commonTableTypeEnt = await _commonTableTypeRepository.GetAsync(input.CommonTableTypeId);
var entityDto = ObjectMapper.Map<CommonTableType, CommonTableTypeDto>(commonTableTypeEnt);
entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
return entityDto;
}
/// <summary>
/// 获取列表
/// </summary>
/// <returns></returns>
[HttpPost("api/app/CommonTableType/GetList")]
public async Task<List<CommonTableTypeDto>> GetListAsync()
{
var entlist = await _commonTableTypeRepository.GetQueryableAsync();
var entdto = entlist.Select(s => new CommonTableTypeDto
{
CreationTime = s.CreationTime,
CreatorId = s.CreatorId,
DisplayName = s.DisplayName,
DisplayOrder = s.DisplayOrder,
Id = s.Id,
LastModificationTime = s.LastModificationTime,
LastModifierId = s.LastModifierId,
SimpleCode = s.SimpleCode,
CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result
}).OrderBy(o => o.DisplayOrder).ToList();
return entdto;
}
/// <summary>
/// 创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTableType/Create")]
public async Task<CommonTableTypeDto> CreateAsync(CreateCommonTableTypeDto input)
{
var createEntity = ObjectMapper.Map<CreateCommonTableTypeDto, CommonTableType>(input);
var entity = await _commonTableTypeManager.CreateAsync(createEntity, input.CommonTableTypeId);
entity = await _commonTableTypeRepository.InsertAsync(entity);
var dto = ObjectMapper.Map<CommonTableType, CommonTableTypeDto>(entity);
dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId);
dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId);
return dto;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTableType/Update")]
public async Task<CommonTableTypeDto> UpdateAsync(UpdateCommonTableTypeDto input)
{
var entity = await _commonTableTypeRepository.GetAsync(input.CommonTableTypeId);
var sourceEntity = ObjectMapper.Map<UpdateCommonTableTypeDto, CommonTableType>(input);
await _commonTableTypeManager.UpdateAsync(sourceEntity, entity);
entity = await _commonTableTypeRepository.UpdateAsync(entity);
var dto = ObjectMapper.Map<CommonTableType, CommonTableTypeDto>(entity);
dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId);
dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId);
return dto;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTableType/Delete")]
public async Task DeleteAsync(CommonTableTypeIdInputDto input)
{
await _commonTableTypeManager.CheckAndDeleteAsync(input.CommonTableTypeId);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTableType/UpdateManySort")]
public async Task UpdateManySortAsync(UpdateManySortCommonTableTypeInputDto input)
{
await _commonTableTypeManager.UpdateManySortAsync(input.CommonTableTypeId, input.SortType);
}
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTableType/UpdateSortMany")]
public async Task UpdateSortManyAsync(UpdateSortManyCommonDto input)
{
await _commonTableTypeManager.UpdateSortManyAsync(input);
}
}
}

159
src/Shentun.Peis.Application/CommonTables/CommonTableAppService.cs

@ -0,0 +1,159 @@
using AutoMapper.Internal.Mappers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.CommonTables;
using Shentun.Peis.HelperDto;
using Shentun.Peis.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace Shentun.Peis.CommonTables
{
/// <summary>
/// 通用字段对照
/// </summary>
[ApiExplorerSettings(GroupName = "Work")]
[Authorize]
public class CommonTableAppService : ApplicationService
{
private readonly IRepository<CommonTableType, string> _commonTableTypeRepository;
private readonly IRepository<CommonTable, Guid> _commonTableRepository;
private readonly CommonTableManager _commonTableManager;
private readonly CacheService _cacheService;
public CommonTableAppService(
IRepository<CommonTableType, string> commonTableTypeRepository,
CommonTableManager commonTableManager,
CacheService cacheService,
IRepository<CommonTable, Guid> commonTableRepository)
{
_commonTableTypeRepository = commonTableTypeRepository;
_commonTableManager = commonTableManager;
_cacheService = cacheService;
_commonTableRepository = commonTableRepository;
}
/// <summary>
/// 获取通过主键
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTable/Get")]
public async Task<CommonTableDto> GetAsync(CommonTableIdInputDto input)
{
var commonTableEnt = await _commonTableRepository.GetAsync(input.CommonTableId);
var entityDto = ObjectMapper.Map<CommonTable, CommonTableDto>(commonTableEnt);
entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
return entityDto;
}
/// <summary>
/// 获取列表
/// </summary>
/// <returns></returns>
[HttpPost("api/app/CommonTable/GetList")]
public async Task<List<CommonTableDto>> GetListAsync()
{
var entlist = await _commonTableRepository.GetQueryableAsync();
var entdto = entlist.Select(s => new CommonTableDto
{
CreationTime = s.CreationTime,
CreatorId = s.CreatorId,
DisplayName = s.DisplayName,
DisplayOrder = s.DisplayOrder,
Id = s.Id,
CommonTableTypeId = s.CommonTableTypeId,
DataCode = s.DataCode,
LastModificationTime = s.LastModificationTime,
LastModifierId = s.LastModifierId,
SimpleCode = s.SimpleCode,
CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result
}).OrderBy(o => o.DisplayOrder).ToList();
return entdto;
}
/// <summary>
/// 创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTable/Create")]
public async Task<CommonTableDto> CreateAsync(CreateCommonTableDto input)
{
var createEntity = ObjectMapper.Map<CreateCommonTableDto, CommonTable>(input);
var entity = await _commonTableManager.CreateAsync(createEntity);
entity = await _commonTableRepository.InsertAsync(entity);
var dto = ObjectMapper.Map<CommonTable, CommonTableDto>(entity);
dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId);
dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId);
return dto;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTable/Update")]
public async Task<CommonTableDto> UpdateAsync(UpdateCommonTableDto input)
{
var entity = await _commonTableRepository.GetAsync(input.CommonTableId);
var sourceEntity = ObjectMapper.Map<UpdateCommonTableDto, CommonTable>(input);
await _commonTableManager.UpdateAsync(sourceEntity, entity);
entity = await _commonTableRepository.UpdateAsync(entity);
var dto = ObjectMapper.Map<CommonTable, CommonTableDto>(entity);
dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId);
dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId);
return dto;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTable/Delete")]
public async Task DeleteAsync(CommonTableIdInputDto input)
{
await _commonTableManager.CheckAndDeleteAsync(input.CommonTableId);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTable/UpdateManySort")]
public async Task UpdateManySortAsync(UpdateManySortCommonTableInputDto input)
{
await _commonTableManager.UpdateManySortAsync(input.CommonTableId, input.SortType);
}
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/CommonTable/UpdateSortMany")]
public async Task UpdateSortManyAsync(UpdateSortManyCommonDto input)
{
await _commonTableManager.UpdateSortManyAsync(input);
}
}
}

11
src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs

@ -11,6 +11,8 @@ using Shentun.Peis.CollectItemTypes;
using Shentun.Peis.ColumnReferences;
using Shentun.Peis.CommonChars;
using Shentun.Peis.CommonCharTypes;
using Shentun.Peis.CommonTables;
using Shentun.Peis.CommonTableTypes;
using Shentun.Peis.ContactMethods;
using Shentun.Peis.ContactPersons;
using Shentun.Peis.CustomerOrgGroupDetails;
@ -547,5 +549,14 @@ public class PeisApplicationAutoMapperProfile : Profile
CreateMap<CreateRoomDto, Room>();
CreateMap<UpdateRoomDto, Room>();
//通用字段对照类别
CreateMap<CommonTableType, CommonTableTypeDto>();
CreateMap<CreateCommonTableTypeDto, CommonTableType>();
CreateMap<UpdateCommonTableTypeDto, CommonTableType>();
//通用字段对照
CreateMap<CommonTable, CommonTableDto>();
CreateMap<CreateCommonTableDto, CommonTable>();
CreateMap<UpdateCommonTableDto, CommonTable>();
}
}

11
src/Shentun.Peis.Domain/CommonTableTypes/CommonTableType.cs

@ -20,6 +20,11 @@ namespace Shentun.Peis.Models
[Table("common_table_type")]
public class CommonTableType : AuditedEntity<string>, IDisplayName, IDisplayOrder, IHasConcurrencyStamp
{
public CommonTableType(string Id) : base(Id)
{
CommonTables = new HashSet<CommonTable>();
}
public CommonTableType()
{
CommonTables = new HashSet<CommonTable>();
@ -33,7 +38,7 @@ namespace Shentun.Peis.Models
public string DisplayName { get; set; } = null!;
/// <summary>
/// 名称
/// 简拼
/// </summary>
[Column("simple_code")]
[StringLength(50)]
@ -50,11 +55,11 @@ namespace Shentun.Peis.Models
public string ConcurrencyStamp { get; set; }
[InverseProperty(nameof(CommonTable.CommonTableType))]
public virtual ICollection<CommonTable> CommonTables { get; set; }
}
}

120
src/Shentun.Peis.Domain/CommonTableTypes/CommonTableTypeManager.cs

@ -0,0 +1,120 @@
using Shentun.Peis.HelperDto;
using Shentun.Peis.Models;
using Shentun.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp;
using Volo.Abp.Domain.Services;
namespace Shentun.Peis.CommonTableTypes
{
public class CommonTableTypeManager : DomainService
{
private readonly IRepository<CommonTableType, string> _commonTableTypeRepository;
private readonly IRepository<CommonTable, Guid> _commonTableRepository;
public CommonTableTypeManager(
IRepository<CommonTableType, string> commonTableTypeRepository,
IRepository<CommonTable, Guid> commonTableRepository)
{
_commonTableTypeRepository = commonTableTypeRepository;
_commonTableRepository = commonTableRepository;
}
/// <summary>
/// 创建
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public async Task<CommonTableType> CreateAsync(
CommonTableType entity, string CommonTableTypeId
)
{
DataHelper.CheckEntityIsNull(entity);
DataHelper.CheckStringIsNull(entity.DisplayName, "名称");
await EntityHelper.CheckSameName<CommonTableType, string>(_commonTableTypeRepository, entity.DisplayName);
return new CommonTableType(CommonTableTypeId)
{
DisplayName = entity.DisplayName,
SimpleCode = LanguageConverter.GetPYSimpleCode(entity.DisplayName),
DisplayOrder = await EntityHelper.CreateMaxDisplayOrder<CommonTableType>(_commonTableTypeRepository)
};
}
/// <summary>
/// 更新
/// </summary>
/// <param name="sourceEntity"></param>
/// <param name="targetEntity"></param>
/// <returns></returns>
public async Task UpdateAsync(
CommonTableType sourceEntity,
CommonTableType targetEntity
)
{
DataHelper.CheckEntityIsNull(sourceEntity);
DataHelper.CheckEntityIsNull(targetEntity);
DataHelper.CheckStringIsNull(sourceEntity.DisplayName, "名称");
if (sourceEntity.DisplayName != targetEntity.DisplayName)
{
await EntityHelper.CheckSameName<CommonTableType, string>(_commonTableTypeRepository, sourceEntity.DisplayName, targetEntity);
targetEntity.DisplayName = sourceEntity.DisplayName;
targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.DisplayName);
}
}
/// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task CheckAndDeleteAsync(string id)
{
var commonTableEnt = await _commonTableRepository.FirstOrDefaultAsync(m => m.CommonTableTypeId == id);
if (commonTableEnt != null)
{
throw new UserFriendlyException($"类型已被使用,不能删除");
}
await _commonTableTypeRepository.DeleteAsync(id);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <returns></returns>
public async Task UpdateManySortAsync(string id, int SortType)
{
await EntityHelper.UpdateManySortCommonAsync(_commonTableTypeRepository, id, SortType);
}
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="repository"></param>
/// <param name="input"></param>
/// <returns></returns>
public async Task UpdateSortManyAsync(UpdateSortManyCommonDto input)
{
await EntityHelper.UpdateSortManyCommonAsync(_commonTableTypeRepository, input);
}
}
}

2
src/Shentun.Peis.Domain/CommonTables/CommonTable.cs

@ -21,7 +21,7 @@ namespace Shentun.Peis.Models
{
/// <summary>
/// 名称
/// 对照值
/// </summary>
[Column("data_code")]
[StringLength(50)]

122
src/Shentun.Peis.Domain/CommonTables/CommonTableManager.cs

@ -0,0 +1,122 @@
using Shentun.Peis.HelperDto;
using Shentun.Peis.Models;
using Shentun.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp;
using Volo.Abp.Domain.Services;
namespace Shentun.Peis.CommonTables
{
public class CommonTableManager : DomainService
{
private readonly IRepository<CommonTableType, string> _commonTableTypeRepository;
private readonly IRepository<CommonTable, Guid> _commonTableRepository;
public CommonTableManager(
IRepository<CommonTableType, string> commonTableTypeRepository,
IRepository<CommonTable, Guid> commonTableRepository)
{
_commonTableTypeRepository = commonTableTypeRepository;
_commonTableRepository = commonTableRepository;
}
/// <summary>
/// 创建
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public async Task<CommonTable> CreateAsync(
CommonTable entity
)
{
DataHelper.CheckEntityIsNull(entity);
DataHelper.CheckStringIsNull(entity.DisplayName, "名称");
DataHelper.CheckStringIsNull(entity.DataCode, "对照值");
DataHelper.CheckStringIsNull(entity.CommonTableTypeId, "通用字段对照类别");
await EntityHelper.CheckSameName(_commonTableRepository, entity.DisplayName);
return new CommonTable
{
DisplayName = entity.DisplayName,
CommonTableTypeId = entity.CommonTableTypeId,
DataCode = entity.DataCode,
SimpleCode = LanguageConverter.GetPYSimpleCode(entity.DisplayName),
DisplayOrder = await EntityHelper.CreateMaxDisplayOrder<CommonTable>(_commonTableRepository)
};
}
/// <summary>
/// 更新
/// </summary>
/// <param name="sourceEntity"></param>
/// <param name="targetEntity"></param>
/// <returns></returns>
public async Task UpdateAsync(
CommonTable sourceEntity,
CommonTable targetEntity
)
{
DataHelper.CheckEntityIsNull(sourceEntity);
DataHelper.CheckEntityIsNull(targetEntity);
DataHelper.CheckStringIsNull(sourceEntity.DisplayName, "名称");
DataHelper.CheckStringIsNull(sourceEntity.DataCode, "对照值");
DataHelper.CheckStringIsNull(sourceEntity.CommonTableTypeId, "通用字段对照类别");
if (sourceEntity.DisplayName != targetEntity.DisplayName)
{
await EntityHelper.CheckSameName(_commonTableRepository, sourceEntity.DisplayName, targetEntity);
targetEntity.DisplayName = sourceEntity.DisplayName;
targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.DisplayName);
}
targetEntity.DataCode = sourceEntity.DataCode;
targetEntity.CommonTableTypeId = sourceEntity.CommonTableTypeId;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task CheckAndDeleteAsync(Guid id)
{
await _commonTableRepository.DeleteAsync(id);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <returns></returns>
public async Task UpdateManySortAsync(Guid id, int SortType)
{
await EntityHelper.UpdateManySortCommonAsync(_commonTableRepository, id, SortType);
}
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="repository"></param>
/// <param name="input"></param>
/// <returns></returns>
public async Task UpdateSortManyAsync(UpdateSortManyCommonDto input)
{
await EntityHelper.UpdateSortManyCommonAsync(_commonTableRepository, input);
}
}
}

98
src/Shentun.Peis.Domain/EntityHelper.cs

@ -139,7 +139,7 @@ namespace Shentun.Peis
}
public static async Task UpdateManySortAsync<TEntity,TKey>(IRepository<TEntity, TKey> repository, TKey id, int SortType)
public static async Task UpdateManySortAsync<TEntity, TKey>(IRepository<TEntity, TKey> repository, TKey id, int SortType)
where TEntity : class, IEntity<TKey>, IDisplayOrder
{
var entity = await repository.GetAsync(id);
@ -355,7 +355,7 @@ namespace Shentun.Peis
}
/// <summary>
/// 修改排序 拖拽 Char类型ID
/// </summary>
@ -405,7 +405,99 @@ namespace Shentun.Peis
}
#region 通用
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="repository"></param>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <param name="orderby">排序规则 0、升序 1、降序 (默认降序)</param>
/// <returns></returns>
public static async Task UpdateManySortCommonAsync<TEntity, Key>(IRepository<TEntity, Key> repository, Key id, int SortType)
where TEntity : class, IEntity<Key>, IDisplayOrder
{
var entity = await repository.GetAsync(id);
List<TEntity> UptList = new List<TEntity>();
if (SortType == 2)
{
UptList = (await repository.GetListAsync(o => o.DisplayOrder > entity.DisplayOrder)).OrderBy(o => o.DisplayOrder).ToList();
if (UptList.Count > 0)
{
int indexnum = entity.DisplayOrder; //原有值
entity.DisplayOrder = UptList[UptList.Count - 1].DisplayOrder; //修改当前排序值为最大
//置顶操作,往上一行开始,逐渐替换
foreach (var item in UptList)
{
int dqnum = item.DisplayOrder;
item.DisplayOrder = indexnum;
indexnum = dqnum;
}
}
}
else
{
UptList = (await repository.GetListAsync(o => o.DisplayOrder < entity.DisplayOrder)).OrderByDescending(o => o.DisplayOrder).ToList(); ;
if (UptList.Count > 0)
{
int indexnum = entity.DisplayOrder; //原有值
entity.DisplayOrder = UptList[UptList.Count - 1].DisplayOrder; //修改当前排序值为最小
//置底操作,往下一行开始,逐渐替换
foreach (var item in UptList)
{
int dqnum = item.DisplayOrder;
item.DisplayOrder = indexnum;
indexnum = dqnum;
}
}
}
UptList.Add(entity);
await repository.UpdateManyAsync(UptList);
}
/// <summary>
/// 修改排序 通用
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="repository"></param>
/// <param name="input"></param>
/// <returns></returns>
public static async Task UpdateSortManyCommonAsync<TEntity, Key>(IRepository<TEntity, Key> repository, UpdateSortManyCommonDto input)
where TEntity : class, IEntity<Key>, IDisplayOrder
{
var entitylist = await repository.GetListAsync(o => input.ItemList.Select(s => s.Id).Contains(o.Id));
foreach (var entity in entitylist)
{
foreach (var item in input.ItemList)
{
var IdType = entity.Id.GetType();
if (item.Id.Equals(entity.Id))
entity.DisplayOrder = item.DisplayOrder;
}
}
await repository.UpdateManyAsync(entitylist);
}
#endregion
/// <summary>
/// 检查同名
@ -429,7 +521,7 @@ namespace Shentun.Peis
}
else
{
existEntity = await repository.FirstOrDefaultAsync(o => o.Id.ToString() != updatedEntity.Id.ToString() && o.DisplayName == name);
existEntity = await repository.FirstOrDefaultAsync(o => !o.Id.Equals(updatedEntity.Id) && o.DisplayName == name);
}

14
src/Shentun.Peis.Domain/HelperDto/UpdateSortManyDto.cs

@ -7,6 +7,20 @@ using System.Threading.Tasks;
namespace Shentun.Peis.HelperDto
{
public class UpdateSortManyCommonDto
{
public List<UpdateSortManyCommon> ItemList { get; set; }
}
public class UpdateSortManyCommon
{
public object Id { get; set; }
public int DisplayOrder { get; set; }
}
public class UpdateSortManyDto
{
public List<UpdateSortMany> ItemList { get; set; }

1
src/Shentun.Peis.EntityFrameworkCore/EntityFrameworkCore/PeisDbContext.cs

@ -582,7 +582,6 @@ public class PeisDbContext :
.ApplyConfiguration(new TenantConnectionStringDbMapping())
.ApplyConfiguration(new PermissionGrantDbMapping())
.ApplyConfiguration(new SettingDbMapping())
.ApplyConfiguration(new SettingDbMapping())
.ApplyConfiguration(new HelloADbMapping())
.ApplyConfiguration(new RoleMenuInfoDbMapping())
.ApplyConfiguration(new MenuInfoDbMapping())

Loading…
Cancel
Save