Files
Yi.Admin/Yi.Abp.Net8/module/ai-stock/Yi.Framework.Stock.Application/Services/StockMarketService.cs
2025-03-02 01:54:12 +08:00

95 lines
4.1 KiB
C#

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Yi.Framework.Stock.Application.Contracts.Dtos.StockMarket;
using Yi.Framework.Stock.Application.Contracts.Dtos.StockPrice;
using Yi.Framework.Stock.Application.Contracts.IServices;
using Yi.Framework.Stock.Domain.Entities;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Stock.Application.Services
{
/// <summary>
/// 股市服务实现
/// </summary>
public class StockMarketService : ApplicationService, IStockMarketService
{
private readonly ISqlSugarRepository<StockMarketAggregateRoot> _stockMarketRepository;
private readonly ISqlSugarRepository<StockPriceRecordEntity> _stockPriceRecordRepository;
public StockMarketService(
ISqlSugarRepository<StockMarketAggregateRoot> stockMarketRepository,
ISqlSugarRepository<StockPriceRecordEntity> stockPriceRecordRepository)
{
_stockMarketRepository = stockMarketRepository;
_stockPriceRecordRepository = stockPriceRecordRepository;
}
/// <summary>
/// 获取股市列表
/// </summary>
[HttpGet("stock/markets")]
public async Task<PagedResultDto<StockMarketDto>> GetStockMarketListAsync(StockMarketGetListInputDto input)
{
RefAsync<int> total = 0;
var query = _stockMarketRepository._DbQueryable
.WhereIF(!string.IsNullOrEmpty(input.MarketCode), m => m.MarketCode.Contains(input.MarketCode))
.WhereIF(!string.IsNullOrEmpty(input.MarketName), m => m.MarketName.Contains(input.MarketName))
.WhereIF(input.State.HasValue, m => m.State == input.State.Value)
.OrderByIF(!string.IsNullOrEmpty(input.Sorting),input.Sorting)
.OrderByIF(string.IsNullOrEmpty(input.Sorting),m=>m.OrderNum,OrderByType.Asc)
.OrderByIF(string.IsNullOrEmpty(input.Sorting),m=>m.CreationTime,OrderByType.Desc);
var list = await query
.Select(m => new StockMarketDto
{
Id = m.Id,
MarketCode = m.MarketCode,
MarketName = m.MarketName,
Description = m.Description,
State = m.State,
CreationTime = m.CreationTime
})
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<StockMarketDto>(total, list);
}
/// <summary>
/// 获取股市价格记录看板
/// </summary>
[HttpGet("stock/price-records")]
public async Task<PagedResultDto<StockPriceRecordDto>> GetStockPriceRecordListAsync(StockPriceRecordGetListInputDto input)
{
RefAsync<int> total = 0;
var query = _stockPriceRecordRepository._DbQueryable
.WhereIF(input.StockId.HasValue, p => p.StockId == input.StockId.Value)
.WhereIF(input.StartTime.HasValue, p => p.CreationTime >= input.StartTime.Value)
.WhereIF(input.EndTime.HasValue, p => p.CreationTime <= input.EndTime.Value)
.WhereIF(input.PeriodType.HasValue, p => p.PeriodType == input.PeriodType.Value)
.OrderByIF(!string.IsNullOrEmpty(input.Sorting),input.Sorting)
.OrderByIF(string.IsNullOrEmpty(input.Sorting),p=>p.CreationTime,OrderByType.Desc);
var list = await query
.Select(p => new StockPriceRecordDto
{
Id = p.Id,
StockId = p.StockId,
CreationTime = p.CreationTime,
CurrentPrice = p.CurrentPrice,
Volume = p.Volume,
Turnover = p.Turnover,
PeriodType = p.PeriodType
})
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<StockPriceRecordDto>(total, list);
}
}
}