diff --git a/src/Shentun.Peis.Application.Contracts/AuditedEntityDtoName.cs b/src/Shentun.Peis.Application.Contracts/AuditedEntityDtoName.cs index 6d8cfe6c..f9ed9553 100644 --- a/src/Shentun.Peis.Application.Contracts/AuditedEntityDtoName.cs +++ b/src/Shentun.Peis.Application.Contracts/AuditedEntityDtoName.cs @@ -29,4 +29,19 @@ namespace Shentun.Peis /// public string LastModifierName { get; set; } } + + public class AuditedEntityDtoNameString : AuditedEntityDto + { + /// + /// 创建者 + /// + public string CreatorName { get; set; } + + /// + /// 最后修改者 + /// + public string LastModifierName { get; set; } + } + + } diff --git a/src/Shentun.Peis.Application.Contracts/CommonTableTypes/CommonTableTypeDto.cs b/src/Shentun.Peis.Application.Contracts/CommonTableTypes/CommonTableTypeDto.cs new file mode 100644 index 00000000..b0129d41 --- /dev/null +++ b/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 + { + /// + /// 名称 + /// + public string DisplayName { get; set; } + + /// + /// 简拼 + /// + public string SimpleCode { get; set; } + + /// + /// + /// + public int DisplayOrder { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/CommonTableTypes/CommonTableTypeIdInputDto.cs b/src/Shentun.Peis.Application.Contracts/CommonTableTypes/CommonTableTypeIdInputDto.cs new file mode 100644 index 00000000..abb1dc50 --- /dev/null +++ b/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; } + + } +} diff --git a/src/Shentun.Peis.Application.Contracts/CommonTableTypes/CreateCommonTableTypeDto.cs b/src/Shentun.Peis.Application.Contracts/CommonTableTypes/CreateCommonTableTypeDto.cs new file mode 100644 index 00000000..0e423484 --- /dev/null +++ b/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 + { + /// + /// 主键 + /// + public string CommonTableTypeId { get; set; } + + /// + /// 名称 + /// + public string DisplayName { get; set; } + + } +} diff --git a/src/Shentun.Peis.Application.Contracts/CommonTableTypes/UpdateCommonTableTypeDto.cs b/src/Shentun.Peis.Application.Contracts/CommonTableTypes/UpdateCommonTableTypeDto.cs new file mode 100644 index 00000000..9608011a --- /dev/null +++ b/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 + { + /// + /// 主键 + /// + public string CommonTableTypeId { get; set; } + + /// + /// 名称 + /// + public string DisplayName { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/CommonTableTypes/UpdateManySortCommonTableTypeInputDto.cs b/src/Shentun.Peis.Application.Contracts/CommonTableTypes/UpdateManySortCommonTableTypeInputDto.cs new file mode 100644 index 00000000..92454fe3 --- /dev/null +++ b/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 + { + + /// + /// 需要修改的ID + /// + public string CommonTableTypeId { get; set; } + + /// + /// 修改方式:1 置顶 2 置底 + /// + public int SortType { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/CommonTables/CommonTableDto.cs b/src/Shentun.Peis.Application.Contracts/CommonTables/CommonTableDto.cs new file mode 100644 index 00000000..32c0629f --- /dev/null +++ b/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 + { + /// + /// 对照值 + /// + public string DataCode { get; set; } = null!; + + /// + /// 名称 + /// + public string DisplayName { get; set; } = null!; + + /// + /// 通用字段对照类别 + /// + public string CommonTableTypeId { get; set; } + + + public string SimpleCode { get; set; } = null!; + + public int DisplayOrder { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/CommonTables/CommonTableIdInputDto.cs b/src/Shentun.Peis.Application.Contracts/CommonTables/CommonTableIdInputDto.cs new file mode 100644 index 00000000..7a488dc9 --- /dev/null +++ b/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;} + } +} diff --git a/src/Shentun.Peis.Application.Contracts/CommonTables/CreateCommonTableDto.cs b/src/Shentun.Peis.Application.Contracts/CommonTables/CreateCommonTableDto.cs new file mode 100644 index 00000000..f0a07845 --- /dev/null +++ b/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 + { + /// + /// 对照值 + /// + public string DataCode { get; set; } = null!; + + /// + /// 名称 + /// + public string DisplayName { get; set; } = null!; + + /// + /// 通用字段对照类别 + /// + public string CommonTableTypeId { get; set; } + + + + } +} diff --git a/src/Shentun.Peis.Application.Contracts/CommonTables/UpdateCommonTableDto.cs b/src/Shentun.Peis.Application.Contracts/CommonTables/UpdateCommonTableDto.cs new file mode 100644 index 00000000..e54734b1 --- /dev/null +++ b/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; } + + /// + /// 对照值 + /// + public string DataCode { get; set; } = null!; + + /// + /// 名称 + /// + public string DisplayName { get; set; } = null!; + + /// + /// 通用字段对照类别 + /// + public string CommonTableTypeId { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/CommonTables/UpdateManySortCommonTableInputDto.cs b/src/Shentun.Peis.Application.Contracts/CommonTables/UpdateManySortCommonTableInputDto.cs new file mode 100644 index 00000000..83b0ae42 --- /dev/null +++ b/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 + { + /// + /// 需要修改的ID + /// + public Guid CommonTableId { get; set; } + + /// + /// 修改方式:1 置顶 2 置底 + /// + public int SortType { get; set; } + } + +} diff --git a/src/Shentun.Peis.Application/CommonTableTypes/CommonTableTypeAppService.cs b/src/Shentun.Peis.Application/CommonTableTypes/CommonTableTypeAppService.cs new file mode 100644 index 00000000..2c0a9286 --- /dev/null +++ b/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 +{ + + /// + /// 通用字段对照类别 + /// + [ApiExplorerSettings(GroupName = "Work")] + [Authorize] + public class CommonTableTypeAppService : ApplicationService + { + private readonly IRepository _commonTableTypeRepository; + private readonly CommonTableTypeManager _commonTableTypeManager; + private readonly CacheService _cacheService; + + public CommonTableTypeAppService( + IRepository commonTableTypeRepository, + CommonTableTypeManager commonTableTypeManager, + CacheService cacheService) + { + _commonTableTypeRepository = commonTableTypeRepository; + _commonTableTypeManager = commonTableTypeManager; + _cacheService = cacheService; + } + + /// + /// 获取通过主键 + /// + /// + /// + [HttpPost("api/app/CommonTableType/Get")] + public async Task GetAsync(CommonTableTypeIdInputDto input) + { + var commonTableTypeEnt = await _commonTableTypeRepository.GetAsync(input.CommonTableTypeId); + var entityDto = ObjectMapper.Map(commonTableTypeEnt); + entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId); + entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId); + return entityDto; + } + + + /// + /// 获取列表 + /// + /// + [HttpPost("api/app/CommonTableType/GetList")] + public async Task> 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; + + + } + + /// + /// 创建 + /// + /// + /// + [HttpPost("api/app/CommonTableType/Create")] + public async Task CreateAsync(CreateCommonTableTypeDto input) + { + var createEntity = ObjectMapper.Map(input); + var entity = await _commonTableTypeManager.CreateAsync(createEntity, input.CommonTableTypeId); + entity = await _commonTableTypeRepository.InsertAsync(entity); + var dto = ObjectMapper.Map(entity); + dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId); + dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId); + return dto; + } + + /// + /// 更新 + /// + /// + /// + [HttpPost("api/app/CommonTableType/Update")] + public async Task UpdateAsync(UpdateCommonTableTypeDto input) + { + var entity = await _commonTableTypeRepository.GetAsync(input.CommonTableTypeId); + var sourceEntity = ObjectMapper.Map(input); + await _commonTableTypeManager.UpdateAsync(sourceEntity, entity); + entity = await _commonTableTypeRepository.UpdateAsync(entity); + var dto = ObjectMapper.Map(entity); + dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId); + dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId); + return dto; + } + + + /// + /// 删除 + /// + /// + /// + [HttpPost("api/app/CommonTableType/Delete")] + public async Task DeleteAsync(CommonTableTypeIdInputDto input) + { + await _commonTableTypeManager.CheckAndDeleteAsync(input.CommonTableTypeId); + } + + + + /// + /// 修改排序 置顶,置底 + /// + /// + /// + [HttpPost("api/app/CommonTableType/UpdateManySort")] + public async Task UpdateManySortAsync(UpdateManySortCommonTableTypeInputDto input) + { + await _commonTableTypeManager.UpdateManySortAsync(input.CommonTableTypeId, input.SortType); + } + + /// + /// 修改排序 拖拽 + /// + /// + /// + [HttpPost("api/app/CommonTableType/UpdateSortMany")] + public async Task UpdateSortManyAsync(UpdateSortManyCommonDto input) + { + await _commonTableTypeManager.UpdateSortManyAsync(input); + } + } +} diff --git a/src/Shentun.Peis.Application/CommonTables/CommonTableAppService.cs b/src/Shentun.Peis.Application/CommonTables/CommonTableAppService.cs new file mode 100644 index 00000000..77bb3eaf --- /dev/null +++ b/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 +{ + + /// + /// 通用字段对照 + /// + [ApiExplorerSettings(GroupName = "Work")] + [Authorize] + public class CommonTableAppService : ApplicationService + { + private readonly IRepository _commonTableTypeRepository; + private readonly IRepository _commonTableRepository; + private readonly CommonTableManager _commonTableManager; + private readonly CacheService _cacheService; + + public CommonTableAppService( + IRepository commonTableTypeRepository, + CommonTableManager commonTableManager, + CacheService cacheService, + IRepository commonTableRepository) + { + _commonTableTypeRepository = commonTableTypeRepository; + _commonTableManager = commonTableManager; + _cacheService = cacheService; + _commonTableRepository = commonTableRepository; + } + + /// + /// 获取通过主键 + /// + /// + /// + [HttpPost("api/app/CommonTable/Get")] + public async Task GetAsync(CommonTableIdInputDto input) + { + var commonTableEnt = await _commonTableRepository.GetAsync(input.CommonTableId); + var entityDto = ObjectMapper.Map(commonTableEnt); + entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId); + entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId); + return entityDto; + } + + + /// + /// 获取列表 + /// + /// + [HttpPost("api/app/CommonTable/GetList")] + public async Task> 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; + + + } + + /// + /// 创建 + /// + /// + /// + [HttpPost("api/app/CommonTable/Create")] + public async Task CreateAsync(CreateCommonTableDto input) + { + var createEntity = ObjectMapper.Map(input); + var entity = await _commonTableManager.CreateAsync(createEntity); + entity = await _commonTableRepository.InsertAsync(entity); + var dto = ObjectMapper.Map(entity); + dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId); + dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId); + return dto; + } + + /// + /// 更新 + /// + /// + /// + [HttpPost("api/app/CommonTable/Update")] + public async Task UpdateAsync(UpdateCommonTableDto input) + { + var entity = await _commonTableRepository.GetAsync(input.CommonTableId); + var sourceEntity = ObjectMapper.Map(input); + await _commonTableManager.UpdateAsync(sourceEntity, entity); + entity = await _commonTableRepository.UpdateAsync(entity); + var dto = ObjectMapper.Map(entity); + dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId); + dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId); + return dto; + } + + + /// + /// 删除 + /// + /// + /// + [HttpPost("api/app/CommonTable/Delete")] + public async Task DeleteAsync(CommonTableIdInputDto input) + { + await _commonTableManager.CheckAndDeleteAsync(input.CommonTableId); + } + + + + /// + /// 修改排序 置顶,置底 + /// + /// + /// + [HttpPost("api/app/CommonTable/UpdateManySort")] + public async Task UpdateManySortAsync(UpdateManySortCommonTableInputDto input) + { + await _commonTableManager.UpdateManySortAsync(input.CommonTableId, input.SortType); + } + + /// + /// 修改排序 拖拽 + /// + /// + /// + [HttpPost("api/app/CommonTable/UpdateSortMany")] + public async Task UpdateSortManyAsync(UpdateSortManyCommonDto input) + { + await _commonTableManager.UpdateSortManyAsync(input); + } + } +} diff --git a/src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs b/src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs index 1056ad2d..76f8baeb 100644 --- a/src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs +++ b/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(); CreateMap(); + //ֶͨζ + CreateMap(); + CreateMap(); + CreateMap(); + + //ֶͨζ + CreateMap(); + CreateMap(); + CreateMap(); } } diff --git a/src/Shentun.Peis.Domain/CommonTableTypes/CommonTableType.cs b/src/Shentun.Peis.Domain/CommonTableTypes/CommonTableType.cs index 8e2727e1..a22d9c31 100644 --- a/src/Shentun.Peis.Domain/CommonTableTypes/CommonTableType.cs +++ b/src/Shentun.Peis.Domain/CommonTableTypes/CommonTableType.cs @@ -20,6 +20,11 @@ namespace Shentun.Peis.Models [Table("common_table_type")] public class CommonTableType : AuditedEntity, IDisplayName, IDisplayOrder, IHasConcurrencyStamp { + public CommonTableType(string Id) : base(Id) + { + CommonTables = new HashSet(); + } + public CommonTableType() { CommonTables = new HashSet(); @@ -33,7 +38,7 @@ namespace Shentun.Peis.Models public string DisplayName { get; set; } = null!; /// - /// 名称 + /// 简拼 /// [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 CommonTables { get; set; } - + } } diff --git a/src/Shentun.Peis.Domain/CommonTableTypes/CommonTableTypeManager.cs b/src/Shentun.Peis.Domain/CommonTableTypes/CommonTableTypeManager.cs new file mode 100644 index 00000000..81795fa6 --- /dev/null +++ b/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 _commonTableTypeRepository; + private readonly IRepository _commonTableRepository; + + public CommonTableTypeManager( + IRepository commonTableTypeRepository, + IRepository commonTableRepository) + { + _commonTableTypeRepository = commonTableTypeRepository; + _commonTableRepository = commonTableRepository; + } + + /// + /// 创建 + /// + /// + /// + public async Task CreateAsync( + CommonTableType entity, string CommonTableTypeId + ) + { + DataHelper.CheckEntityIsNull(entity); + DataHelper.CheckStringIsNull(entity.DisplayName, "名称"); + await EntityHelper.CheckSameName(_commonTableTypeRepository, entity.DisplayName); + return new CommonTableType(CommonTableTypeId) + { + DisplayName = entity.DisplayName, + SimpleCode = LanguageConverter.GetPYSimpleCode(entity.DisplayName), + DisplayOrder = await EntityHelper.CreateMaxDisplayOrder(_commonTableTypeRepository) + }; + } + + /// + /// 更新 + /// + /// + /// + /// + 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(_commonTableTypeRepository, sourceEntity.DisplayName, targetEntity); + targetEntity.DisplayName = sourceEntity.DisplayName; + targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.DisplayName); + } + + } + + + /// + /// 删除 + /// + /// + /// + /// + 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); + + } + + + + + /// + /// 修改排序 置顶,置底 + /// + /// 需要修改的ID + /// 修改方式:1 置顶 2 置底 + /// + public async Task UpdateManySortAsync(string id, int SortType) + { + await EntityHelper.UpdateManySortCommonAsync(_commonTableTypeRepository, id, SortType); + } + + + + /// + /// 修改排序 拖拽 + /// + /// + /// + /// + /// + public async Task UpdateSortManyAsync(UpdateSortManyCommonDto input) + { + await EntityHelper.UpdateSortManyCommonAsync(_commonTableTypeRepository, input); + } + } +} diff --git a/src/Shentun.Peis.Domain/CommonTables/CommonTable.cs b/src/Shentun.Peis.Domain/CommonTables/CommonTable.cs index 672d7d05..12ad97d1 100644 --- a/src/Shentun.Peis.Domain/CommonTables/CommonTable.cs +++ b/src/Shentun.Peis.Domain/CommonTables/CommonTable.cs @@ -21,7 +21,7 @@ namespace Shentun.Peis.Models { /// - /// 名称 + /// 对照值 /// [Column("data_code")] [StringLength(50)] diff --git a/src/Shentun.Peis.Domain/CommonTables/CommonTableManager.cs b/src/Shentun.Peis.Domain/CommonTables/CommonTableManager.cs new file mode 100644 index 00000000..81afff39 --- /dev/null +++ b/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 _commonTableTypeRepository; + private readonly IRepository _commonTableRepository; + + public CommonTableManager( + IRepository commonTableTypeRepository, + IRepository commonTableRepository) + { + _commonTableTypeRepository = commonTableTypeRepository; + _commonTableRepository = commonTableRepository; + } + + /// + /// 创建 + /// + /// + /// + public async Task 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(_commonTableRepository) + }; + } + + /// + /// 更新 + /// + /// + /// + /// + 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; + + } + + + /// + /// 删除 + /// + /// + /// + /// + public async Task CheckAndDeleteAsync(Guid id) + { + await _commonTableRepository.DeleteAsync(id); + } + + + + + /// + /// 修改排序 置顶,置底 + /// + /// 需要修改的ID + /// 修改方式:1 置顶 2 置底 + /// + public async Task UpdateManySortAsync(Guid id, int SortType) + { + await EntityHelper.UpdateManySortCommonAsync(_commonTableRepository, id, SortType); + } + + + + /// + /// 修改排序 拖拽 + /// + /// + /// + /// + /// + public async Task UpdateSortManyAsync(UpdateSortManyCommonDto input) + { + await EntityHelper.UpdateSortManyCommonAsync(_commonTableRepository, input); + } + } +} diff --git a/src/Shentun.Peis.Domain/EntityHelper.cs b/src/Shentun.Peis.Domain/EntityHelper.cs index d636fd1a..05635f5c 100644 --- a/src/Shentun.Peis.Domain/EntityHelper.cs +++ b/src/Shentun.Peis.Domain/EntityHelper.cs @@ -139,7 +139,7 @@ namespace Shentun.Peis } - public static async Task UpdateManySortAsync(IRepository repository, TKey id, int SortType) + public static async Task UpdateManySortAsync(IRepository repository, TKey id, int SortType) where TEntity : class, IEntity, IDisplayOrder { var entity = await repository.GetAsync(id); @@ -355,7 +355,7 @@ namespace Shentun.Peis } - + /// /// 修改排序 拖拽 Char类型ID /// @@ -405,7 +405,99 @@ namespace Shentun.Peis } + #region 通用 + + /// + /// 修改排序 置顶,置底 + /// + /// + /// + /// 需要修改的ID + /// 修改方式:1 置顶 2 置底 + /// 排序规则 0、升序 1、降序 (默认降序) + /// + public static async Task UpdateManySortCommonAsync(IRepository repository, Key id, int SortType) + where TEntity : class, IEntity, IDisplayOrder + { + var entity = await repository.GetAsync(id); + + List UptList = new List(); + + + 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); + + } + + /// + /// 修改排序 通用 + /// + /// + /// + /// + /// + public static async Task UpdateSortManyCommonAsync(IRepository repository, UpdateSortManyCommonDto input) + where TEntity : class, IEntity, 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 /// /// 检查同名 @@ -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); } diff --git a/src/Shentun.Peis.Domain/HelperDto/UpdateSortManyDto.cs b/src/Shentun.Peis.Domain/HelperDto/UpdateSortManyDto.cs index 36f19f84..991800e0 100644 --- a/src/Shentun.Peis.Domain/HelperDto/UpdateSortManyDto.cs +++ b/src/Shentun.Peis.Domain/HelperDto/UpdateSortManyDto.cs @@ -7,6 +7,20 @@ using System.Threading.Tasks; namespace Shentun.Peis.HelperDto { + + public class UpdateSortManyCommonDto + { + public List ItemList { get; set; } + } + + public class UpdateSortManyCommon + { + public object Id { get; set; } + public int DisplayOrder { get; set; } + } + + + public class UpdateSortManyDto { public List ItemList { get; set; } diff --git a/src/Shentun.Peis.EntityFrameworkCore/EntityFrameworkCore/PeisDbContext.cs b/src/Shentun.Peis.EntityFrameworkCore/EntityFrameworkCore/PeisDbContext.cs index 040b933c..4ef59709 100644 --- a/src/Shentun.Peis.EntityFrameworkCore/EntityFrameworkCore/PeisDbContext.cs +++ b/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())