添加项目文件。
This commit is contained in:
@@ -0,0 +1,384 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AdminDomain.BeautifulNumber;
|
||||
using AdminDomain.Entity;
|
||||
using AdminService.BeautifulNumber;
|
||||
using Common;
|
||||
using CommonInfrastructure;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using UserDomain.Entity;
|
||||
|
||||
namespace AdminApi.BeautifulNumber
|
||||
{
|
||||
[ApiController, Route("adminapi/[controller]")]
|
||||
[Authorize]
|
||||
|
||||
public class BeautifulNumberController : BaseController
|
||||
{
|
||||
private readonly IBeautifulNumberService _beautifulNumberService;
|
||||
|
||||
public BeautifulNumberController(IBeautifulNumberService beautifulNumberService)
|
||||
{
|
||||
_beautifulNumberService = beautifulNumberService;
|
||||
}
|
||||
|
||||
[HttpGet("list")]
|
||||
public async Task<PageResponse<BeautifulNumberDto>> GetList([FromQuery] BeautifulNumberListParam param)
|
||||
{
|
||||
param.page = param.page > 0 ? param.page : 1;
|
||||
param.size = param.size > 0 ? param.size : 20;
|
||||
var result = await _beautifulNumberService.GetList(param);
|
||||
var dtos = result.list.Select(MapToDto).ToList();
|
||||
return this.ToPageResult(dtos, (int)result.count);
|
||||
}
|
||||
|
||||
[HttpGet("available")]
|
||||
public async Task<PageResponse<BeautifulNumberDto>> GetAvailableList([FromQuery] BeautifulNumberListParam param)
|
||||
{
|
||||
param.page = param.page > 0 ? param.page : 1;
|
||||
param.size = param.size > 0 ? param.size : 20;
|
||||
param.status = (int)BeautifulNumberStatus.Available;
|
||||
var result = await _beautifulNumberService.GetList(param);
|
||||
var dtos = result.list.Select(MapToDto).ToList();
|
||||
return this.ToPageResult(dtos, (int)result.count);
|
||||
}
|
||||
|
||||
[HttpGet("check/{number}")]
|
||||
public async Task<BaseResponse<BeautifulNumberDto>> CheckNumber(string number)
|
||||
{
|
||||
var result = await _beautifulNumberService.CheckNumber(number);
|
||||
return this.ToResult(MapToDto(result));
|
||||
}
|
||||
|
||||
private static BeautifulNumberDto MapToDto(BeautifulNumberConfig entity)
|
||||
{
|
||||
if (entity == null) return new BeautifulNumberDto();
|
||||
return new BeautifulNumberDto
|
||||
{
|
||||
Id = entity.Id ?? "",
|
||||
Number = entity.Number ?? "",
|
||||
RuleName = entity.RuleName ?? "",
|
||||
Level = entity.Level ?? "",
|
||||
Price = entity.Price,
|
||||
Status = (int)entity.Status,
|
||||
SaleTime = entity.SaleTime,
|
||||
BuyerUserId = entity.BuyerUserId ?? "",
|
||||
UserId = entity.UserId ?? "",
|
||||
Remark = entity.Remark ?? "",
|
||||
CreateTime = entity.CreateTime
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPost("delete")]
|
||||
public async Task<BaseResponse<string>> Delete([FromBody] DeleteBeautifulNumberParam param)
|
||||
{
|
||||
var result = await _beautifulNumberService.Delete(param.Id);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("set-normal")]
|
||||
public async Task<BaseResponse<string>> SetToNormal([FromBody] DeleteBeautifulNumberParam param)
|
||||
{
|
||||
var result = await _beautifulNumberService.SetToNormal(param.Id);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("freeze")]
|
||||
public async Task<BaseResponse<string>> Freeze([FromBody] DeleteBeautifulNumberParam param)
|
||||
{
|
||||
var result = await _beautifulNumberService.Freeze(param.Id);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("unfreeze")]
|
||||
public async Task<BaseResponse<string>> Unfreeze([FromBody] DeleteBeautifulNumberParam param)
|
||||
{
|
||||
var result = await _beautifulNumberService.Unfreeze(param.Id);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("update-price")]
|
||||
public async Task<BaseResponse<string>> UpdatePrice([FromBody] UpdateBeautifulNumberPriceParam param)
|
||||
{
|
||||
var result = await _beautifulNumberService.UpdatePrice(param.Id, param.Price);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("update-number")]
|
||||
public async Task<BaseResponse<string>> UpdateNumber([FromBody] UpdateBeautifulNumberParam param)
|
||||
{
|
||||
var result = await _beautifulNumberService.UpdateNumber(param.Id, param.Level, param.Price);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpGet("rules")]
|
||||
public async Task<BaseResponse<List<BeautifulNumberRuleDto>>> GetRules()
|
||||
{
|
||||
var result = await _beautifulNumberService.GetRules();
|
||||
var dtos = result.Select(MapRuleToDto).ToList();
|
||||
return this.ToResult(dtos);
|
||||
}
|
||||
|
||||
private static BeautifulNumberRuleDto MapRuleToDto(BeautifulNumberRule entity)
|
||||
{
|
||||
if (entity == null) return new BeautifulNumberRuleDto();
|
||||
return new BeautifulNumberRuleDto
|
||||
{
|
||||
Id = entity.Id ?? "",
|
||||
RuleName = entity.RuleName ?? "",
|
||||
Level = entity.Level ?? "",
|
||||
Price = entity.Price,
|
||||
Sort = entity.Sort,
|
||||
IsEnable = entity.IsEnable
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPost("update-rules")]
|
||||
public async Task<BaseResponse<string>> UpdateRules([FromBody] List<UpdateBeautifulNumberRuleParam> paramList)
|
||||
{
|
||||
var rules = new List<BeautifulNumberRule>();
|
||||
foreach (var param in paramList)
|
||||
{
|
||||
rules.Add(new BeautifulNumberRule
|
||||
{
|
||||
Id = param.Id,
|
||||
RuleName = param.RuleName,
|
||||
Level = param.Level,
|
||||
Price = param.Price,
|
||||
Sort = param.Sort,
|
||||
IsEnable = param.IsEnable
|
||||
});
|
||||
}
|
||||
var result = await _beautifulNumberService.UpdateRules(rules);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("init-rules")]
|
||||
public async Task<BaseResponse<string>> InitRules()
|
||||
{
|
||||
var result = await _beautifulNumberService.InitRules();
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("add-rule")]
|
||||
public async Task<BaseResponse<string>> AddRule([FromBody] BeautifulNumberRule rule)
|
||||
{
|
||||
var result = await _beautifulNumberService.AddRule(rule);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("update-rule")]
|
||||
public async Task<BaseResponse<string>> UpdateRule([FromBody] BeautifulNumberRule rule)
|
||||
{
|
||||
var result = await _beautifulNumberService.UpdateRule(rule);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("delete-rule")]
|
||||
public async Task<BaseResponse<string>> DeleteRule([FromBody] DeleteBeautifulNumberRuleParam param)
|
||||
{
|
||||
var result = await _beautifulNumberService.DeleteRule(param.Id);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("give-to-user")]
|
||||
public async Task<BaseResponse<string>> GiveToUser([FromBody] GiveBeautifulNumberParam param)
|
||||
{
|
||||
var result = await _beautifulNumberService.GiveToUser(param.Number, param.UserId);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("init-numbers")]
|
||||
public async Task<BaseResponse<string>> InitNumbers()
|
||||
{
|
||||
var result = await _beautifulNumberService.InitBeautifulNumbers();
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("add-number")]
|
||||
public async Task<BaseResponse<string>> AddNumber([FromBody] AddBeautifulNumberParam param)
|
||||
{
|
||||
var result = await _beautifulNumberService.AddNumber(param.Number, param.Level, param.Price);
|
||||
if (result.isok)
|
||||
return this.ToResult<string>(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("batch-add-numbers")]
|
||||
public async Task<BaseResponse<BatchAddResult>> BatchAddNumbers([FromBody] BatchAddBeautifulNumbersParam param)
|
||||
{
|
||||
var result = await _beautifulNumberService.BatchAddNumbers(param.Numbers, param.Level, param.Price);
|
||||
return this.ToResult(new BatchAddResult { SuccessCount = result.successCount, FailCount = result.failCount, Message = result.msg });
|
||||
}
|
||||
}
|
||||
|
||||
public class BatchAddResult
|
||||
{
|
||||
public int SuccessCount { get; set; }
|
||||
public int FailCount { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
public class BeautifulNumberDto
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Number { get; set; }
|
||||
public string RuleName { get; set; }
|
||||
public string Level { get; set; }
|
||||
public long Price { get; set; }
|
||||
public int Status { get; set; }
|
||||
public long SaleTime { get; set; }
|
||||
public string BuyerUserId { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public string Remark { get; set; }
|
||||
public long CreateTime { get; set; }
|
||||
}
|
||||
|
||||
public class BeautifulNumberRuleDto
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string RuleName { get; set; }
|
||||
public string Level { get; set; }
|
||||
public long Price { get; set; }
|
||||
public int Sort { get; set; }
|
||||
public bool IsEnable { get; set; }
|
||||
}
|
||||
|
||||
public class BatchAddBeautifulNumbersParam
|
||||
{
|
||||
public List<string> Numbers { get; set; }
|
||||
|
||||
public string Level { get; set; }
|
||||
|
||||
public long Price { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class GiveBeautifulNumberParam
|
||||
{
|
||||
public string Number { get; set; }
|
||||
|
||||
public string UserId { get; set; }
|
||||
}
|
||||
|
||||
public class AddBeautifulNumberParam
|
||||
{
|
||||
public string Number { get; set; }
|
||||
|
||||
public string Level { get; set; }
|
||||
|
||||
public long Price { get; set; }
|
||||
|
||||
public int Sort { get; set; }
|
||||
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
public class UpdateBeautifulNumberParam
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public string Level { get; set; }
|
||||
|
||||
public long Price { get; set; }
|
||||
|
||||
}
|
||||
public class DeleteBeautifulNumberParam
|
||||
{
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateBeautifulNumberPriceParam
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public long Price { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class UpdateBeautifulNumberRuleParam
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
|
||||
|
||||
public string RuleName { get; set; }
|
||||
|
||||
|
||||
|
||||
public string Level { get; set; }
|
||||
|
||||
public long Price { get; set; }
|
||||
|
||||
public int Sort { get; set; }
|
||||
|
||||
public bool IsEnable { get; set; }
|
||||
}
|
||||
|
||||
public class AddBeautifulNumberRuleParam
|
||||
{
|
||||
public string RuleName { get; set; }
|
||||
public string Level { get; set; }
|
||||
public long Price { get; set; }
|
||||
public int Sort { get; set; }
|
||||
public bool IsEnable { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateSingleBeautifulNumberRuleParam
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string RuleName { get; set; }
|
||||
public string Level { get; set; }
|
||||
public long Price { get; set; }
|
||||
public int Sort { get; set; }
|
||||
public bool IsEnable { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteBeautifulNumberRuleParam
|
||||
{
|
||||
public string Id { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user