feat: 完成激活码功能
This commit is contained in:
@@ -35,20 +35,29 @@ public class ActivationCodeService : ApplicationService, IActivationCodeService
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[HttpPost("activationCode/Batch")]
|
||||
public async Task<ActivationCodeCreateOutput> CreateBatchAsync(ActivationCodeCreateInput input)
|
||||
public async Task<ActivationCodeCreateListOutput> CreateBatchAsync(ActivationCodeCreateListInput input)
|
||||
{
|
||||
var entities = await _activationCodeManager.CreateBatchAsync(
|
||||
input.GoodsType,
|
||||
input.Count,
|
||||
input.IsReusable,
|
||||
input.IsSameTypeOnce,
|
||||
input.Remark);
|
||||
|
||||
return new ActivationCodeCreateOutput
|
||||
if (input.Items == null || input.Items.Count == 0)
|
||||
{
|
||||
GoodsType = input.GoodsType,
|
||||
Count = input.Count,
|
||||
Codes = entities.Select(x => x.Code).ToList()
|
||||
throw new UserFriendlyException("生成列表不能为空");
|
||||
}
|
||||
|
||||
var entities = await _activationCodeManager.CreateBatchAsync(
|
||||
input.Items.Select(x => (x.GoodsType, x.Count)).ToList());
|
||||
|
||||
var outputs = entities
|
||||
.GroupBy(x => x.GoodsType)
|
||||
.Select(group => new ActivationCodeCreateOutput
|
||||
{
|
||||
GoodsType = group.Key,
|
||||
Count = group.Count(),
|
||||
Codes = group.Select(x => x.Code).ToList()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return new ActivationCodeCreateListOutput
|
||||
{
|
||||
Items = outputs
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user