1.05
All checks were successful
Build and Deploy / deploy (push) Successful in 1m8s

1.05
This commit is contained in:
zzh 2026-10-12 15:03:12 +08:00
commit 0a865b9d1a
3 changed files with 22 additions and 16 deletions

View File

@ -273,15 +273,12 @@ public class InterfaceService : ApplicationService
var entity = await ServiceProviderRepository.GetFirstAsync(x => x.Id == serviceProviderId); var entity = await ServiceProviderRepository.GetFirstAsync(x => x.Id == serviceProviderId);
if (entity == null) throw new BusinessException("服务商不存在,系统接口自己定义code谢谢配合"); if (entity == null) throw new BusinessException("服务商不存在,系统接口自己定义code谢谢配合");
string res = entity.Code; // 取末三位序号最大值,不能按 Id 取最后一条(删除/手工建码会导致 Id 与序号不一致)
var maxSequence = await InterfaceRepository.GetMaxCodeSequenceBySpId(serviceProviderId);
if (maxSequence >= 999)
throw new BusinessException("该服务商接口代码已达上限(999)");
// tips:要考虑并发 return entity.Code + (maxSequence + 1).ToString().PadLeft(3, '0');
var code = await InterfaceRepository.GetCurrentCodeBySpId(serviceProviderId);
int count = 0;
if (!string.IsNullOrEmpty(code)) count = int.Parse(code.Substring(code.Length - 3, 3));
res += (count + 1).ToString().PadLeft(3, '0');
return res;
} }
private async Task UpdateInterfaceAsync(SaveInterfaceInput input) private async Task UpdateInterfaceAsync(SaveInterfaceInput input)

View File

@ -27,11 +27,11 @@ namespace InterfaceForward.Repositories.Interface.Services
Task<List<InterfaceParameterOutputValueObject>> GetParameterListByIdAsync(int id, bool onlyLeafs = false); Task<List<InterfaceParameterOutputValueObject>> GetParameterListByIdAsync(int id, bool onlyLeafs = false);
/// <summary> /// <summary>
/// 获取服务商接口当前用到的code /// 获取服务商下游接口 code 末三位序号的最大值(含软删,避免复用已占用序号)
/// </summary> /// </summary>
/// <param name="spId"></param> /// <param name="spId"></param>
/// /// <returns></returns> /// <returns>无记录时返回 0</returns>
Task<string> GetCurrentCodeBySpId(int spId); Task<int> GetMaxCodeSequenceBySpId(int spId);
Task<PagedResult<InterfacePaginatedOutputValueObject>> GetInterfacePaginatedListAsync(InterfacePaginatedInputObjectValue input); Task<PagedResult<InterfacePaginatedOutputValueObject>> GetInterfacePaginatedListAsync(InterfacePaginatedInputObjectValue input);
} }

View File

@ -68,16 +68,25 @@ public class InterfaceRepository : BasicRepository<InterfaceEntity>, IInterfaceR
} }
/// <inheritdoc /> /// <inheritdoc />
public async Task<string> GetCurrentCodeBySpId(int spId) public async Task<int> GetMaxCodeSequenceBySpId(int spId)
{ {
var code = await AsQueryable() var codes = await AsQueryable()
.Where(x => x.ServiceProviderId == spId && !x.IsUpStream) .Where(x => x.ServiceProviderId == spId && !x.IsUpStream)
.Filter(null, true) .Filter(null, true)
.OrderByDescending(x => x.Id)
.Select(x => x.Code) .Select(x => x.Code)
.FirstAsync(); .ToListAsync();
return code; var max = 0;
foreach (var code in codes)
{
if (string.IsNullOrEmpty(code) || code.Length < 3)
continue;
if (int.TryParse(code.AsSpan(code.Length - 3, 3), out var sequence) && sequence > max)
max = sequence;
}
return max;
} }
/// <inheritdoc /> /// <inheritdoc />