Compare commits

..

27 Commits

Author SHA1 Message Date
橙子
f7d9effa07 feat: 上线ai股市模块 2025-03-15 00:58:10 +08:00
橙子
cec28faaf7 perf: 优化提示词 2025-03-14 00:14:44 +08:00
橙子
bcdcca82eb fix: 修复排序问题 2025-03-14 00:10:31 +08:00
chenchun
4e0cc9a24a feat: 完善前端界面 2025-03-13 20:45:23 +08:00
chenchun
53a402a656 feat: 优化提示词 2025-03-13 15:30:24 +08:00
橙子
85ed4df1e4 fix: 修复记录时间 2025-03-11 22:00:11 +08:00
chenchun
8ef91ebd03 feat: 完成股票价格生成job 2025-03-11 13:43:26 +08:00
chenchun
ccaebb8ec2 feat: 完善提示词 2025-03-11 13:40:15 +08:00
橙子
4afc1cc492 feat: 新增job db选择 2025-03-10 22:27:54 +08:00
橙子
ddba0f9aa1 style: 修改默认redisdb 2025-03-10 22:08:38 +08:00
橙子
c782246a1d feat: 完成提示词工程 2025-03-09 23:51:30 +08:00
橙子
afa5fad8c6 Merge remote-tracking branch 'origin/stock' into stock 2025-03-09 16:21:52 +08:00
橙子
d605809932 feat: 完善对接接口 2025-03-09 16:21:47 +08:00
橙子
30250db0fb feat: 完善对接接口 2025-03-09 16:21:39 +08:00
橙子
b48f584db8 style: 修改定时任务种子数据 2025-03-08 23:36:03 +08:00
橙子
56d850d74b chorm: 构建 2025-03-08 23:22:01 +08:00
橙子
3ef1323f05 stly: 更换样式 2025-03-08 22:49:08 +08:00
橙子
d9ed547a20 stly: 更换样式 2025-03-08 22:47:30 +08:00
橙子
82865631fc feat: ai完成stock模块搭建 2025-03-08 22:14:26 +08:00
橙子
337088c908 feat: 补充部分功能 2025-03-07 00:35:32 +08:00
橙子
c092ee46e9 feat: 完成ai生成 2025-03-05 23:08:58 +08:00
橙子
287634cf99 feat: 新增ai-stock模块 2025-03-02 01:54:12 +08:00
橙子
c1535fd116 perf: 优化错误提示 2025-03-01 23:43:19 +08:00
橙子
d7d4fd8a48 perf: 优化排行榜页面 2025-03-01 14:58:21 +08:00
橙子
1552b00516 perf: 优化首页 2025-03-01 02:41:33 +08:00
橙子
a40d9b79b4 feat:新增stock页面 2025-03-01 01:53:55 +08:00
橙子
0bc5b1a940 feat:新增stock页面 2025-03-01 01:53:42 +08:00
73 changed files with 4440 additions and 244 deletions

View File

@@ -174,17 +174,17 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.WeChat.MiniPro
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.BackgroundWorkers.Hangfire", "framework\Yi.Framework.BackgroundWorkers.Hangfire\Yi.Framework.BackgroundWorkers.Hangfire.csproj", "{862CA181-BEE6-4870-82D2-B662E527ED8C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "stock", "stock", "{DB46873F-981A-43D8-91B0-D464CCB65943}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ai-stock", "ai-stock", "{DB46873F-981A-43D8-91B0-D464CCB65943}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Application", "module\stock\Yi.Framework.Stock.Application\Yi.Framework.Stock.Application.csproj", "{B79CE23C-10F8-48A5-A039-5940A188CF5A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Application", "module\ai-stock\Yi.Framework.Stock.Application\Yi.Framework.Stock.Application.csproj", "{B79CE23C-10F8-48A5-A039-5940A188CF5A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Application.Contracts", "module\stock\Yi.Framework.Stock.Application.Contracts\Yi.Framework.Stock.Application.Contracts.csproj", "{846B781A-B77E-4F86-A31F-0B5B57AB0775}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Application.Contracts", "module\ai-stock\Yi.Framework.Stock.Application.Contracts\Yi.Framework.Stock.Application.Contracts.csproj", "{846B781A-B77E-4F86-A31F-0B5B57AB0775}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Domain", "module\stock\Yi.Framework.Stock.Domain\Yi.Framework.Stock.Domain.csproj", "{162821E4-8FE0-4A68-B3C0-49BD6596446F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Domain", "module\ai-stock\Yi.Framework.Stock.Domain\Yi.Framework.Stock.Domain.csproj", "{162821E4-8FE0-4A68-B3C0-49BD6596446F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Domain.Shared", "module\stock\Yi.Framework.Stock.Domain.Shared\Yi.Framework.Stock.Domain.Shared.csproj", "{10273544-715D-4BB3-893C-6F010D947BDD}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Domain.Shared", "module\ai-stock\Yi.Framework.Stock.Domain.Shared\Yi.Framework.Stock.Domain.Shared.csproj", "{10273544-715D-4BB3-893C-6F010D947BDD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.SqlSugarCore", "module\stock\Yi.Framework.Stock.SqlSugarCore\Yi.Framework.Stock.SqlSugarCore.csproj", "{5F49318F-E6C7-4194-BAE0-83D4FB8D1983}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.SqlSugarCore", "module\ai-stock\Yi.Framework.Stock.SqlSugarCore\Yi.Framework.Stock.SqlSugarCore.csproj", "{5F49318F-E6C7-4194-BAE0-83D4FB8D1983}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@@ -0,0 +1,66 @@
using System;
using Volo.Abp.Application.Dtos;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockHolding
{
/// <summary>
/// 用户股票持仓DTO
/// </summary>
public class StockHoldingDto : EntityDto<Guid>
{
/// <summary>
/// 用户ID
/// </summary>
public Guid UserId { get; set; }
/// <summary>
/// 股票ID
/// </summary>
public Guid StockId { get; set; }
/// <summary>
/// 股票代码
/// </summary>
public string StockCode { get; set; }
/// <summary>
/// 股票名称
/// </summary>
public string StockName { get; set; }
/// <summary>
/// 持有数量
/// </summary>
public int Quantity { get; set; }
/// <summary>
/// 持仓成本
/// </summary>
public decimal CostPrice { get; set; }
/// <summary>
/// 当前价格
/// </summary>
public decimal CurrentPrice { get; set; }
/// <summary>
/// 持仓市值
/// </summary>
public decimal MarketValue { get; set; }
/// <summary>
/// 盈亏金额
/// </summary>
public decimal ProfitLoss { get; set; }
/// <summary>
/// 盈亏百分比
/// </summary>
public decimal ProfitLossPercentage { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreationTime { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using System;
using Volo.Abp.Application.Dtos;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockHolding
{
/// <summary>
/// 获取用户持仓列表的输入DTO
/// </summary>
public class StockHoldingGetListInputDto : PagedAndSortedResultRequestDto
{
/// <summary>
/// 股票代码
/// </summary>
public string? StockCode { get; set; }
/// <summary>
/// 股票名称
/// </summary>
public string? StockName { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
using System;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockMarket
{
/// <summary>
/// 买入股票输入DTO
/// </summary>
public class BuyStockInputDto
{
/// <summary>
/// 股票ID
/// </summary>
public Guid StockId { get; set; }
/// <summary>
/// 买入数量
/// </summary>
public int Quantity { get; set; }
}
}

View File

@@ -0,0 +1,23 @@
using System;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockMarket;
/// <summary>
/// 创建股市输入DTO
/// </summary>
public class CreateStockMarketInputDto
{
/// <summary>
/// 股市代码
/// </summary>
public string MarketCode { get; set; }
/// <summary>
/// 股市名称
/// </summary>
public string MarketName { get; set; }
/// <summary>
/// 股市描述
/// </summary>
public string Description { get; set; }
}

View File

@@ -0,0 +1,20 @@
using System;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockMarket
{
/// <summary>
/// 卖出股票输入DTO
/// </summary>
public class SellStockInputDto
{
/// <summary>
/// 股票ID
/// </summary>
public Guid StockId { get; set; }
/// <summary>
/// 卖出数量
/// </summary>
public int Quantity { get; set; }
}
}

View File

@@ -0,0 +1,36 @@
using System;
using Volo.Abp.Application.Dtos;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockMarket
{
/// <summary>
/// 股市信息DTO
/// </summary>
public class StockMarketDto : EntityDto<Guid>
{
/// <summary>
/// 股市代码
/// </summary>
public string MarketCode { get; set; }
/// <summary>
/// 股市名称
/// </summary>
public string MarketName { get; set; }
/// <summary>
/// 股市描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// 状态
/// </summary>
public bool State { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreationTime { get; set; }
}
}

View File

@@ -0,0 +1,26 @@
using System;
using Volo.Abp.Application.Dtos;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockMarket
{
/// <summary>
/// 获取股市列表的输入DTO
/// </summary>
public class StockMarketGetListInputDto : PagedAndSortedResultRequestDto
{
/// <summary>
/// 股市代码
/// </summary>
public string? MarketCode { get; set; }
/// <summary>
/// 股市名称
/// </summary>
public string? MarketName { get; set; }
/// <summary>
/// 状态
/// </summary>
public bool? State { get; set; }
}
}

View File

@@ -0,0 +1,41 @@
using System;
using Volo.Abp.Application.Dtos;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockNews
{
/// <summary>
/// 股市新闻DTO
/// </summary>
public class StockNewsDto : EntityDto<Guid>
{
/// <summary>
/// 新闻标题
/// </summary>
public string Title { get; set; }
/// <summary>
/// 新闻内容
/// </summary>
public string Content { get; set; }
/// <summary>
/// 发布时间
/// </summary>
public DateTime PublishTime { get; set; }
/// <summary>
/// 新闻来源
/// </summary>
public string Source { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreationTime { get; set; }
/// <summary>
/// 排序号
/// </summary>
public int OrderNum { get; set; }
}
}

View File

@@ -0,0 +1,37 @@
using System;
using Volo.Abp.Application.Dtos;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockNews
{
/// <summary>
/// 获取股市新闻列表的输入DTO
/// </summary>
public class StockNewsGetListInputDto : PagedAndSortedResultRequestDto
{
/// <summary>
/// 新闻标题关键词
/// </summary>
public string? Title { get; set; }
/// <summary>
/// 新闻来源
/// </summary>
public string? Source { get; set; }
/// <summary>
/// 开始时间
/// </summary>
public DateTime? StartTime { get; set; }
/// <summary>
/// 结束时间
/// </summary>
public DateTime? EndTime { get; set; }
/// <summary>
/// 是否只显示最近10天的新闻
/// </summary>
/// <remarks>默认为true查询最近10天的新闻</remarks>
public bool IsRecent { get; set; } = true;
}
}

View File

@@ -0,0 +1,47 @@
using System;
using Volo.Abp.Application.Dtos;
using Yi.Framework.Stock.Domain.Shared;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockPrice
{
/// <summary>
/// 股市价格记录DTO
/// </summary>
public class StockPriceRecordDto : EntityDto<Guid>
{
/// <summary>
/// 股票ID
/// </summary>
public Guid StockId { get; set; }
/// <summary>
/// 记录时间
/// </summary>
public DateTime CreationTime { get; set; }
/// <summary>
/// 当前价
/// </summary>
public decimal CurrentPrice { get; set; }
/// <summary>
/// 交易量
/// </summary>
public long Volume { get; set; }
/// <summary>
/// 交易额
/// </summary>
public decimal Turnover { get; set; }
/// <summary>
/// 时间周期类型
/// </summary>
public PeriodTypeEnum PeriodType { get; set; }
/// <summary>
/// 记录时间
/// </summary>
public DateTime RecordTime { get; set; }
}
}

View File

@@ -0,0 +1,32 @@
using System;
using Volo.Abp.Application.Dtos;
using Yi.Framework.Stock.Domain.Shared;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockPrice
{
/// <summary>
/// 获取股市价格记录的输入DTO
/// </summary>
public class StockPriceRecordGetListInputDto : PagedAndSortedResultRequestDto
{
/// <summary>
/// 股票ID
/// </summary>
public Guid? StockId { get; set; }
/// <summary>
/// 开始时间
/// </summary>
public DateTime? StartTime { get; set; }
/// <summary>
/// 结束时间
/// </summary>
public DateTime? EndTime { get; set; }
/// <summary>
/// 时间周期类型
/// </summary>
public PeriodTypeEnum? PeriodType { get; set; }
}
}

View File

@@ -0,0 +1,62 @@
using System;
using Volo.Abp.Application.Dtos;
using Yi.Framework.Stock.Domain.Shared;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockTransaction
{
/// <summary>
/// 股票交易记录DTO
/// </summary>
public class StockTransactionDto : EntityDto<Guid>
{
/// <summary>
/// 用户ID
/// </summary>
public Guid UserId { get; set; }
/// <summary>
/// 股票ID
/// </summary>
public Guid StockId { get; set; }
/// <summary>
/// 股票代码
/// </summary>
public string StockCode { get; set; }
/// <summary>
/// 股票名称
/// </summary>
public string StockName { get; set; }
/// <summary>
/// 交易类型
/// </summary>
public TransactionTypeEnum TransactionType { get; set; }
/// <summary>
/// 交易价格
/// </summary>
public decimal Price { get; set; }
/// <summary>
/// 交易数量
/// </summary>
public int Quantity { get; set; }
/// <summary>
/// 交易总额
/// </summary>
public decimal TotalAmount { get; set; }
/// <summary>
/// 交易费用
/// </summary>
public decimal Fee { get; set; }
/// <summary>
/// 交易时间
/// </summary>
public DateTime CreationTime { get; set; }
}
}

View File

@@ -0,0 +1,37 @@
using System;
using Volo.Abp.Application.Dtos;
using Yi.Framework.Stock.Domain.Shared;
namespace Yi.Framework.Stock.Application.Contracts.Dtos.StockTransaction
{
/// <summary>
/// 获取交易记录的输入DTO
/// </summary>
public class StockTransactionGetListInputDto : PagedAndSortedResultRequestDto
{
/// <summary>
/// 股票代码
/// </summary>
public string? StockCode { get; set; }
/// <summary>
/// 股票名称
/// </summary>
public string? StockName { get; set; }
/// <summary>
/// 交易类型
/// </summary>
public TransactionTypeEnum? TransactionType { get; set; }
/// <summary>
/// 开始时间
/// </summary>
public DateTime? StartTime { get; set; }
/// <summary>
/// 结束时间
/// </summary>
public DateTime? EndTime { get; set; }
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Yi.Framework.Stock.Application.Contracts.Dtos.StockHolding;
using Yi.Framework.Stock.Application.Contracts.Dtos.StockTransaction;
namespace Yi.Framework.Stock.Application.Contracts.IServices
{
/// <summary>
/// 用户持仓服务接口
/// </summary>
public interface IStockHoldingService : IApplicationService
{
/// <summary>
/// 获取当前用户的持仓列表
/// </summary>
/// <param name="input">查询条件</param>
/// <returns>持仓列表</returns>
Task<PagedResultDto<StockHoldingDto>> GetUserHoldingsAsync(StockHoldingGetListInputDto input);
/// <summary>
/// 获取当前用户的交易记录
/// </summary>
/// <param name="input">查询条件</param>
/// <returns>交易记录列表</returns>
Task<PagedResultDto<StockTransactionDto>> GetUserTransactionsAsync(StockTransactionGetListInputDto input);
}
}

View File

@@ -0,0 +1,49 @@
using System;
using System.Threading.Tasks;
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;
namespace Yi.Framework.Stock.Application.Contracts.IServices
{
/// <summary>
/// 股市服务接口
/// </summary>
public interface IStockMarketService : IApplicationService
{
/// <summary>
/// 获取股市列表
/// </summary>
/// <param name="input">查询条件</param>
/// <returns>股市列表</returns>
Task<PagedResultDto<StockMarketDto>> GetStockMarketListAsync(StockMarketGetListInputDto input);
/// <summary>
/// 获取股市价格记录看板
/// </summary>
/// <param name="input">查询条件</param>
/// <returns>股价记录列表</returns>
Task<PagedResultDto<StockPriceRecordDto>> GetStockPriceRecordListAsync(StockPriceRecordGetListInputDto input);
/// <summary>
/// 买入股票
/// </summary>
/// <param name="input">买入股票参数</param>
/// <returns>操作结果</returns>
Task BuyStockAsync(BuyStockInputDto input);
/// <summary>
/// 卖出股票
/// </summary>
/// <param name="input">卖出股票参数</param>
/// <returns>操作结果</returns>
Task SellStockAsync(SellStockInputDto input);
/// <summary>
/// 生成最新股票记录
/// </summary>
/// <returns>操作结果</returns>
Task GenerateStocksAsync();
}
}

View File

@@ -0,0 +1,20 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Yi.Framework.Stock.Application.Contracts.Dtos.StockNews;
namespace Yi.Framework.Stock.Application.Contracts.IServices
{
/// <summary>
/// 股市新闻服务接口
/// </summary>
public interface IStockNewsService : IApplicationService
{
/// <summary>
/// 获取股市新闻列表
/// </summary>
/// <param name="input">查询条件</param>
/// <returns>新闻列表</returns>
Task<PagedResultDto<StockNewsDto>> GetStockNewsListAsync(StockNewsGetListInputDto input);
}
}

View File

@@ -9,7 +9,6 @@
<PackageReference Include="Volo.Abp.SettingManagement.Application.Contracts" Version="$(AbpVersion)" />
</ItemGroup>
<ItemGroup>
<Folder Include="Dtos\" />
<Folder Include="IServices\" />
</ItemGroup>

View File

@@ -0,0 +1,107 @@
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.StockHolding;
using Yi.Framework.Stock.Application.Contracts.Dtos.StockTransaction;
using Yi.Framework.Stock.Application.Contracts.IServices;
using Yi.Framework.Stock.Domain.Entities;
using Yi.Framework.SqlSugarCore.Abstractions;
using Volo.Abp.Users;
namespace Yi.Framework.Stock.Application.Services
{
/// <summary>
/// 用户持仓服务实现
/// </summary>
[Authorize]
public class StockHoldingService : ApplicationService, IStockHoldingService
{
private readonly ISqlSugarRepository<StockHoldingAggregateRoot> _stockHoldingRepository;
private readonly ISqlSugarRepository<StockTransactionEntity> _stockTransactionRepository;
public StockHoldingService(
ISqlSugarRepository<StockHoldingAggregateRoot> stockHoldingRepository,
ISqlSugarRepository<StockTransactionEntity> stockTransactionRepository)
{
_stockHoldingRepository = stockHoldingRepository;
_stockTransactionRepository = stockTransactionRepository;
}
/// <summary>
/// 获取当前用户的持仓列表
/// </summary>
[Authorize]
[HttpGet("stock/user-holdings")]
public async Task<PagedResultDto<StockHoldingDto>> GetUserHoldingsAsync(StockHoldingGetListInputDto input)
{
Guid userId = CurrentUser.GetId();
RefAsync<int> total = 0;
var query = _stockHoldingRepository._DbQueryable
.Where(h => h.UserId == userId)
.WhereIF(!string.IsNullOrEmpty(input.StockCode), h => h.StockCode.Contains(input.StockCode))
.WhereIF(!string.IsNullOrEmpty(input.StockName), h => h.StockName.Contains(input.StockName))
.OrderByIF(!string.IsNullOrEmpty(input.Sorting),input.Sorting)
.OrderByIF(string.IsNullOrEmpty(input.Sorting),t=>t.CreationTime,OrderByType.Desc);
var list = await query
.Select(h => new StockHoldingDto
{
Id = h.Id,
UserId = h.UserId,
StockId = h.StockId,
StockCode = h.StockCode,
StockName = h.StockName,
Quantity = h.Quantity,
CreationTime = h.CreationTime
})
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<StockHoldingDto>(total, list);
}
/// <summary>
/// 获取当前用户的交易记录
/// </summary>
[Authorize]
[HttpGet("stock/user-transactions")]
public async Task<PagedResultDto<StockTransactionDto>> GetUserTransactionsAsync(StockTransactionGetListInputDto input)
{
Guid userId = CurrentUser.GetId();
RefAsync<int> total = 0;
var query = _stockTransactionRepository._DbQueryable
.Where(t => t.UserId == userId)
.WhereIF(!string.IsNullOrEmpty(input.StockCode), t => t.StockCode.Contains(input.StockCode))
.WhereIF(!string.IsNullOrEmpty(input.StockName), t => t.StockName.Contains(input.StockName))
.WhereIF(input.TransactionType.HasValue, t => t.TransactionType == input.TransactionType.Value)
.WhereIF(input.StartTime.HasValue, t => t.CreationTime >= input.StartTime.Value)
.WhereIF(input.EndTime.HasValue, t => t.CreationTime <= input.EndTime.Value)
.OrderByIF(!string.IsNullOrEmpty(input.Sorting),input.Sorting)
.OrderByIF(string.IsNullOrEmpty(input.Sorting),t=>t.CreationTime,OrderByType.Desc);
var list = await query
.Select(t => new StockTransactionDto
{
Id = t.Id,
UserId = t.UserId,
StockId = t.StockId,
StockCode = t.StockCode,
StockName = t.StockName,
TransactionType = t.TransactionType,
Price = t.Price,
Quantity = t.Quantity,
TotalAmount = t.TotalAmount,
Fee = t.Fee,
CreationTime = t.CreationTime
})
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<StockTransactionDto>(total, list);
}
}
}

View File

@@ -0,0 +1,166 @@
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 Volo.Abp.Users;
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;
using Yi.Framework.Stock.Domain.Managers;
using Mapster;
namespace Yi.Framework.Stock.Application.Services
{
/// <summary>
/// 股市服务实现
/// </summary>
public class StockMarketService : ApplicationService, IStockMarketService
{
private readonly ISqlSugarRepository<StockMarketAggregateRoot> _stockMarketRepository;
private readonly ISqlSugarRepository<StockPriceRecordEntity> _stockPriceRecordRepository;
private readonly StockMarketManager _stockMarketManager;
public StockMarketService(
ISqlSugarRepository<StockMarketAggregateRoot> stockMarketRepository,
ISqlSugarRepository<StockPriceRecordEntity> stockPriceRecordRepository,
StockMarketManager stockMarketManager)
{
_stockMarketRepository = stockMarketRepository;
_stockPriceRecordRepository = stockPriceRecordRepository;
_stockMarketManager = stockMarketManager;
}
/// <summary>
/// 创建股市
/// </summary>
[HttpPost("stock/markets")]
[Authorize]
public async Task<StockMarketDto> CreateStockMarketAsync(CreateStockMarketInputDto input)
{
// 使用映射将输入DTO转换为实体
var stockMarket = input.Adapt<StockMarketAggregateRoot>();
// 保存到数据库
var result = await _stockMarketRepository.InsertReturnEntityAsync(stockMarket);
// 使用映射将实体转换为返回DTO
return result.Adapt<StockMarketDto>();
}
/// <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.RecordTime >= input.StartTime.Value)
.WhereIF(input.EndTime.HasValue, p => p.RecordTime <= 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.RecordTime);
var list = await query
.Select(p => new StockPriceRecordDto
{
Id = p.Id,
StockId = p.StockId,
CreationTime = p.CreationTime,
RecordTime = p.RecordTime,
CurrentPrice = p.CurrentPrice,
Volume = p.Volume,
Turnover = p.Turnover,
PeriodType = p.PeriodType
})
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<StockPriceRecordDto>(total, list);
}
/// <summary>
/// 买入股票
/// </summary>
[HttpPost("stock/buy")]
[Authorize]
public async Task BuyStockAsync(BuyStockInputDto input)
{
// 获取当前登录用户ID
var userId = CurrentUser.GetId();
// 调用领域服务进行股票购买
await _stockMarketManager.BuyStockAsync(
userId,
input.StockId,
input.Quantity
);
}
/// <summary>
/// 卖出股票
/// </summary>
[HttpDelete("stock/sell")]
[Authorize]
public async Task SellStockAsync(SellStockInputDto input)
{
// 获取当前登录用户ID
var userId = CurrentUser.GetId();
// 调用领域服务进行股票卖出
await _stockMarketManager.SellStockAsync(
userId,
input.StockId,
input.Quantity
);
}
/// <summary>
/// 生成最新股票记录
/// </summary>
[HttpPost("stock/generate")]
[Authorize]
public async Task GenerateStocksAsync()
{
await _stockMarketManager.GenerateStocksAsync();
}
}
}

View File

@@ -0,0 +1,80 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Yi.Framework.Stock.Application.Contracts.Dtos.StockNews;
using Yi.Framework.Stock.Application.Contracts.IServices;
using Yi.Framework.Stock.Domain.Entities;
using Yi.Framework.SqlSugarCore.Abstractions;
using Yi.Framework.Stock.Domain.Managers;
namespace Yi.Framework.Stock.Application.Services
{
/// <summary>
/// 股市新闻服务实现
/// </summary>
public class StockNewsService : ApplicationService, IStockNewsService
{
private readonly ISqlSugarRepository<StockNewsAggregateRoot> _stockNewsRepository;
private readonly NewsManager _newsManager;
public StockNewsService(
ISqlSugarRepository<StockNewsAggregateRoot> stockNewsRepository,
NewsManager newsManager)
{
_stockNewsRepository = stockNewsRepository;
_newsManager = newsManager;
}
/// <summary>
/// 获取股市新闻列表
/// </summary>
[HttpGet("/api/app/stock/news")]
public async Task<PagedResultDto<StockNewsDto>> GetStockNewsListAsync(StockNewsGetListInputDto input)
{
RefAsync<int> total = 0;
// 计算10天前的日期
DateTime tenDaysAgo = DateTime.Now.AddDays(-10);
var query = _stockNewsRepository._DbQueryable
.WhereIF(!string.IsNullOrEmpty(input.Title), n => n.Title.Contains(input.Title))
.WhereIF(!string.IsNullOrEmpty(input.Source), n => n.Source.Contains(input.Source))
.WhereIF(input.StartTime.HasValue, n => n.PublishTime >= input.StartTime.Value)
.WhereIF(input.EndTime.HasValue, n => n.PublishTime <= input.EndTime.Value)
// 如果IsRecent为true则只查询最近10天的新闻
.WhereIF(input.IsRecent, n => n.PublishTime >= tenDaysAgo)
.OrderByIF(!string.IsNullOrEmpty(input.Sorting),input.Sorting)
.OrderByIF(string.IsNullOrEmpty(input.Sorting),n=>n.OrderNum,OrderByType.Asc)
.OrderByIF(string.IsNullOrEmpty(input.Sorting),n=>n.PublishTime,OrderByType.Desc) ;
var list = await query
.Select(n => new StockNewsDto
{
Id = n.Id,
Title = n.Title,
Content = n.Content,
PublishTime = n.PublishTime,
Source = n.Source,
CreationTime = n.CreationTime,
OrderNum = n.OrderNum
})
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<StockNewsDto>(total, list);
}
/// <summary>
/// 生成股市新闻
/// </summary>
/// <returns>生成结果</returns>
[HttpPost("/api/app/stock/news/generate")]
public async Task GenerateNewsAsync()
{
await _newsManager.GenerateNewsAsync();
}
}
}

View File

@@ -0,0 +1,41 @@
namespace Yi.Framework.Stock.Domain.Shared
{
/// <summary>
/// 时间周期类型枚举
/// </summary>
/// <remarks>
/// 用于定义股票价格记录的时间周期类型
/// </remarks>
public enum PeriodTypeEnum
{
/// <summary>
/// 分钟
/// </summary>
Minute = 0,
/// <summary>
/// 小时
/// </summary>
Hour = 1,
/// <summary>
/// 天
/// </summary>
Day = 2,
/// <summary>
/// 周
/// </summary>
Week = 3,
/// <summary>
/// 月
/// </summary>
Month = 4,
/// <summary>
/// 年
/// </summary>
Year = 5
}
}

View File

@@ -0,0 +1,18 @@
namespace Yi.Framework.Stock.Domain.Shared
{
/// <summary>
/// 交易类型枚举
/// </summary>
public enum TransactionTypeEnum
{
/// <summary>
/// 买入
/// </summary>
Buy = 0,
/// <summary>
/// 卖出
/// </summary>
Sell = 1
}
}

View File

@@ -0,0 +1,56 @@
using System;
using Yi.Framework.Stock.Domain.Shared;
namespace Yi.Framework.Stock.Domain.Shared.Etos
{
/// <summary>
/// 股票交易事件数据传输对象
/// </summary>
public class StockTransactionEto
{
/// <summary>
/// 用户ID
/// </summary>
public Guid UserId { get; set; }
/// <summary>
/// 股票ID
/// </summary>
public Guid StockId { get; set; }
/// <summary>
/// 股票代码
/// </summary>
public string StockCode { get; set; }
/// <summary>
/// 股票名称
/// </summary>
public string StockName { get; set; }
/// <summary>
/// 交易类型
/// </summary>
public TransactionTypeEnum TransactionType { get; set; }
/// <summary>
/// 交易价格
/// </summary>
public decimal Price { get; set; }
/// <summary>
/// 交易数量
/// </summary>
public int Quantity { get; set; }
/// <summary>
/// 交易总额
/// </summary>
public decimal TotalAmount { get; set; }
/// <summary>
/// 交易费用
/// </summary>
public decimal Fee { get; set; }
}
}

View File

@@ -14,5 +14,8 @@
<Folder Include="Enums\" />
<Folder Include="Etos\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\bbs\Yi.Framework.Bbs.Domain.Shared\Yi.Framework.Bbs.Domain.Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,141 @@
using SqlSugar;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Yi.Framework.Core.Data;
namespace Yi.Framework.Stock.Domain.Entities
{
/// <summary>
/// 用户股票持仓聚合根
/// </summary>
/// <remarks>
/// 记录用户持有的股票数量和相关信息
/// </remarks>
[SugarTable("Stock_Holding")]
public class StockHoldingAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject
{
/// <summary>
/// 逻辑删除
/// </summary>
public bool IsDeleted { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreationTime { get; set; } = DateTime.Now;
/// <summary>
/// 创建者
/// </summary>
public Guid? CreatorId { get; set; }
/// <summary>
/// 最后修改者
/// </summary>
public Guid? LastModifierId { get; set; }
/// <summary>
/// 最后修改时间
/// </summary>
public DateTime? LastModificationTime { get; set; }
/// <summary>
/// 用户ID
/// </summary>
/// <remarks>关联到持有股票的用户</remarks>
public Guid UserId { get; set; }
/// <summary>
/// 股票ID
/// </summary>
/// <remarks>关联到具体的股票</remarks>
public Guid StockId { get; set; }
/// <summary>
/// 股票代码
/// </summary>
/// <remarks>冗余字段,方便查询</remarks>
public string StockCode { get; set; } = string.Empty;
/// <summary>
/// 股票名称
/// </summary>
/// <remarks>冗余字段,方便查询</remarks>
public string StockName { get; set; } = string.Empty;
/// <summary>
/// 持有数量
/// </summary>
/// <remarks>用户持有的股票数量</remarks>
public int Quantity { get; set; }
/// <summary>
/// 平均成本价
/// </summary>
/// <remarks>用户购买这些股票的平均成本价</remarks>
public decimal AverageCostPrice { get; set; }
/// <summary>
/// 持仓成本
/// </summary>
/// <remarks>总投入成本 = 平均成本价 * 持有数量</remarks>
[SugarColumn(IsIgnore = true)]
public decimal TotalCost => AverageCostPrice * Quantity;
public StockHoldingAggregateRoot() { }
public StockHoldingAggregateRoot(
Guid userId,
Guid stockId,
string stockCode,
string stockName,
int quantity,
decimal averageCostPrice)
{
UserId = userId;
StockId = stockId;
StockCode = stockCode;
StockName = stockName;
Quantity = quantity;
AverageCostPrice = averageCostPrice;
}
/// <summary>
/// 增加持仓数量
/// </summary>
/// <param name="quantity">增加的数量</param>
/// <param name="price">本次购买价格</param>
public void AddQuantity(int quantity, decimal price)
{
if (quantity <= 0)
throw new ArgumentException("增加的数量必须大于0");
// 计算新的平均成本价
decimal totalCost = AverageCostPrice * Quantity + price * quantity;
Quantity += quantity;
AverageCostPrice = totalCost / Quantity;
}
/// <summary>
/// 减少持仓数量
/// </summary>
/// <param name="quantity">减少的数量</param>
public void ReduceQuantity(int quantity)
{
if (quantity <= 0)
throw new ArgumentException("减少的数量必须大于0");
if (quantity > Quantity)
throw new ArgumentException("减少的数量不能大于持有数量");
Quantity -= quantity;
// 如果数量为0标记为删除
if (Quantity == 0)
{
IsDeleted = true;
}
}
}
}

View File

@@ -0,0 +1,79 @@
using SqlSugar;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Yi.Framework.Core.Data;
namespace Yi.Framework.Stock.Domain.Entities
{
/// <summary>
/// 股市聚合根实体
/// </summary>
/// <remarks>
/// 用于定义有哪些公司上架的股市
/// </remarks>
[SugarTable("Stock_Market")]
public class StockMarketAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
{
/// <summary>
/// 逻辑删除
/// </summary>
public bool IsDeleted { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreationTime { get; set; }
/// <summary>
/// 创建者
/// </summary>
public Guid? CreatorId { get; set; }
/// <summary>
/// 最后修改者
/// </summary>
public Guid? LastModifierId { get; set; }
/// <summary>
/// 最后修改时间
/// </summary>
public DateTime? LastModificationTime { get; set; }
/// <summary>
/// 排序
/// </summary>
public int OrderNum { get; set; } = 0;
/// <summary>
/// 状态
/// </summary>
public bool State { get; set; } = true;
/// <summary>
/// 股市代码
/// </summary>
public string MarketCode { get; set; } = string.Empty;
/// <summary>
/// 股市名称
/// </summary>
public string MarketName { get; set; } = string.Empty;
/// <summary>
/// 股市描述
/// </summary>
public string Description { get; set; } = string.Empty;
public StockMarketAggregateRoot() { }
public StockMarketAggregateRoot(
string marketCode,
string marketName,
string description = "")
{
MarketCode = marketCode;
MarketName = marketName;
Description = description;
}
}
}

View File

@@ -0,0 +1,86 @@
using SqlSugar;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Yi.Framework.Core.Data;
namespace Yi.Framework.Stock.Domain.Entities
{
/// <summary>
/// 股市新闻聚合根实体
/// </summary>
/// <remarks>
/// 用于记录影响股市波动的新闻事件
/// </remarks>
[SugarTable("Stock_News")]
public class StockNewsAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum
{
/// <summary>
/// 逻辑删除
/// </summary>
public bool IsDeleted { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreationTime { get; set; }
/// <summary>
/// 创建者ID
/// </summary>
public Guid? CreatorId { get; set; }
/// <summary>
/// 最后修改时间
/// </summary>
public DateTime? LastModificationTime { get; set; }
/// <summary>
/// 最后修改者ID
/// </summary>
public Guid? LastModifierId { get; set; }
/// <summary>
/// 排序号
/// </summary>
public int OrderNum { get; set; } = 0;
/// <summary>
/// 新闻标题
/// </summary>
public string Title { get; set; } = string.Empty;
/// <summary>
/// 新闻内容
/// </summary>
public string Content { get; set; } = string.Empty;
/// <summary>
/// 发布时间
/// </summary>
public DateTime PublishTime { get; set; }
/// <summary>
/// 新闻来源
/// </summary>
public string Source { get; set; } = string.Empty;
/// <summary>
/// 新闻摘要
/// </summary>
public string Summary { get; set; } = string.Empty;
public StockNewsAggregateRoot() { }
public StockNewsAggregateRoot(
string title,
string content,
string source = "")
{
Title = title;
Content = content;
Source = source;
PublishTime = DateTime.Now;
}
}
}

View File

@@ -0,0 +1,78 @@
using SqlSugar;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Auditing;
using Yi.Framework.Stock.Domain.Shared;
namespace Yi.Framework.Stock.Domain.Entities
{
/// <summary>
/// 股票价格记录实体
/// </summary>
/// <remarks>
/// 用于记录每支股票在不同时间点的价格数据,支持趋势分析和图表展示
/// </remarks>
[SugarTable("Stock_PriceRecord")]
public class StockPriceRecordEntity : Entity<Guid>, IHasCreationTime
{
/// <summary>
/// 股票ID
/// </summary>
/// <remarks>关联到具体的股票</remarks>
public Guid StockId { get; set; }
/// <summary>
/// 创建时间(审计日志)
/// </summary>
public DateTime CreationTime { get; set; }
/// <summary>
/// 记录时间
/// </summary>
/// <remarks>价格记录的实际时间点</remarks>
public DateTime RecordTime { get; set; }
/// <summary>
/// 当前价
/// </summary>
public decimal CurrentPrice { get; set; }
/// <summary>
/// 交易量
/// </summary>
/// <remarks>该时间段内的交易股数</remarks>
public long Volume { get; set; }
/// <summary>
/// 交易额
/// </summary>
/// <remarks>该时间段内的交易金额</remarks>
public decimal Turnover { get; set; }
/// <summary>
/// 时间周期类型
/// </summary>
/// <remarks>
/// 记录的时间周期类型:分钟、小时、日、周、月等
/// </remarks>
public PeriodTypeEnum PeriodType { get; set; }
public StockPriceRecordEntity() { }
public StockPriceRecordEntity(
Guid stockId,
decimal currentPrice,
long volume = 0,
decimal turnover = 0,
PeriodTypeEnum periodType = PeriodTypeEnum.Day)
{
StockId = stockId;
CreationTime = DateTime.Now;
RecordTime = DateTime.Now;
CurrentPrice = currentPrice;
Volume = volume;
Turnover = turnover;
PeriodType = periodType;
}
}
}

View File

@@ -0,0 +1,121 @@
using SqlSugar;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Auditing;
using Yi.Framework.Stock.Domain.Shared;
namespace Yi.Framework.Stock.Domain.Entities
{
/// <summary>
/// 股票交易记录实体
/// </summary>
/// <remarks>
/// 用于记录用户买入或卖出股票的交易历史
/// </remarks>
[SugarTable("Stock_Transaction")]
public class StockTransactionEntity : Entity<Guid>, IAuditedObject
{
/// <summary>
/// 用户ID
/// </summary>
/// <remarks>进行交易的用户</remarks>
public Guid UserId { get; set; }
/// <summary>
/// 股票ID
/// </summary>
/// <remarks>交易的股票</remarks>
public Guid StockId { get; set; }
/// <summary>
/// 股票代码
/// </summary>
/// <remarks>冗余字段,方便查询</remarks>
public string StockCode { get; set; } = string.Empty;
/// <summary>
/// 股票名称
/// </summary>
/// <remarks>冗余字段,方便查询</remarks>
public string StockName { get; set; } = string.Empty;
/// <summary>
/// 交易类型
/// </summary>
public TransactionTypeEnum TransactionType { get; set; }
/// <summary>
/// 交易价格
/// </summary>
/// <remarks>股票的单价</remarks>
public decimal Price { get; set; }
/// <summary>
/// 交易数量
/// </summary>
/// <remarks>买入或卖出的股票数量</remarks>
public int Quantity { get; set; }
/// <summary>
/// 交易总额
/// </summary>
/// <remarks>价格 × 数量</remarks>
public decimal TotalAmount { get; set; }
/// <summary>
/// 交易费用
/// </summary>
/// <remarks>手续费、佣金等</remarks>
public decimal Fee { get; set; }
/// <summary>
/// 创建时间
/// </summary>
/// <remarks>交易发生时间</remarks>
public DateTime CreationTime { get; set; }
/// <summary>
/// 创建者ID
/// </summary>
public Guid? CreatorId { get; set; }
/// <summary>
/// 最后修改时间
/// </summary>
public DateTime? LastModificationTime { get; set; }
/// <summary>
/// 最后修改者ID
/// </summary>
public Guid? LastModifierId { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; } = string.Empty;
public StockTransactionEntity() { }
public StockTransactionEntity(
Guid userId,
Guid stockId,
string stockCode,
string stockName,
TransactionTypeEnum transactionType,
decimal price,
int quantity,
decimal fee = 0)
{
Id = Guid.NewGuid();
UserId = userId;
StockId = stockId;
StockCode = stockCode;
StockName = stockName;
TransactionType = transactionType;
Price = price;
Quantity = quantity;
TotalAmount = price * quantity;
Fee = fee;
CreationTime = DateTime.Now;
}
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;
using Yi.Framework.Stock.Domain.Entities;
using Yi.Framework.Stock.Domain.Shared.Etos;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Stock.Domain.EventHandlers
{
/// <summary>
/// 股票交易事件处理器
/// </summary>
public class StockTransactionEventHandler : ILocalEventHandler<StockTransactionEto>, ITransientDependency
{
private readonly ISqlSugarRepository<StockTransactionEntity> _transactionRepository;
public StockTransactionEventHandler(
ISqlSugarRepository<StockTransactionEntity> transactionRepository)
{
_transactionRepository = transactionRepository;
}
public async Task HandleEventAsync(StockTransactionEto eventData)
{
// 创建交易记录实体
var transaction = new StockTransactionEntity(
eventData.UserId,
eventData.StockId,
eventData.StockCode,
eventData.StockName,
eventData.TransactionType,
eventData.Price,
eventData.Quantity,
eventData.Fee
);
// 保存交易记录
await _transactionRepository.InsertAsync(transaction);
}
}
}

View File

@@ -0,0 +1,91 @@
using Volo.Abp.Domain.Services;
using Yi.Framework.SqlSugarCore.Abstractions;
using Yi.Framework.Stock.Domain.Entities;
using Yi.Framework.Stock.Domain.Managers.SemanticKernel;
using Yi.Framework.Stock.Domain.Managers.SemanticKernel.Plugins;
using System.Text;
using System.IO;
namespace Yi.Framework.Stock.Domain.Managers;
public class NewsManager:DomainService
{
private SemanticKernelClient _skClient;
private ISqlSugarRepository<StockNewsAggregateRoot> _newsRepository;
public NewsManager(SemanticKernelClient skClient,ISqlSugarRepository<StockNewsAggregateRoot> newsRepository)
{
_skClient = skClient;
_newsRepository = newsRepository;
}
/// <summary>
/// 获取最近的新闻
/// </summary>
/// <param name="count">获取数量</param>
/// <returns>最近的新闻列表</returns>
public async Task<List<StockNewsAggregateRoot>> GetRecentNewsAsync(int count = 10)
{
return await _newsRepository._DbQueryable
.OrderByDescending(n => n.CreationTime)
.Take(count)
.Select(n => new StockNewsAggregateRoot
{
Title = n.Title,
Summary = n.Summary,
Source = n.Source,
CreationTime = n.CreationTime
})
.ToListAsync();
}
/// <summary>
/// 生成一个新闻
/// </summary>
/// <returns></returns>
public async Task GenerateNewsAsync()
{
// 获取最近10条新闻
var recentNews = await GetRecentNewsAsync(10);
// 构建新闻背景上下文
var newsContext = new StringBuilder();
if (recentNews.Any())
{
newsContext.AppendLine("以下是最近的新闻简介:");
foreach (var news in recentNews)
{
newsContext.AppendLine($"- {news.CreationTime:yyyy-MM-dd} 来源:{news.Source}");
newsContext.AppendLine($" 标题:{news.Title}");
newsContext.AppendLine($" 简介:{news.Summary}");
newsContext.AppendLine();
}
}
else
{
newsContext.AppendLine("目前没有最近的新闻记录。");
}
var promptPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "stock", "newsPrompt.txt");
var question = await File.ReadAllTextAsync(promptPath);
question = question.Replace("{{newsContext}}", newsContext.ToString());
await _skClient.ChatCompletionAsync(question, ("NewsPlugins","save_news"));
}
public async Task SaveNewsAsync(NewsModel news)
{
var newsEntity = new StockNewsAggregateRoot(
title: news.Title,
content: news.Content,
source: news.Source
)
{
Summary = news.Summary,
CreationTime = DateTime.Now,
IsDeleted = false,
OrderNum = 0
};
await _newsRepository.InsertAsync(newsEntity);
}
}

View File

@@ -0,0 +1,42 @@
using System.ComponentModel;
using System.Text.Json.Serialization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
namespace Yi.Framework.Stock.Domain.Managers.SemanticKernel.Plugins;
public class NewsPlugins
{
private readonly IServiceProvider _serviceProvider;
public NewsPlugins(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
[KernelFunction("save_news"), Description("生成并保存一个新闻")]
public async Task SaveAsync(NewsModel news)
{
var newsManager = _serviceProvider.GetRequiredService<NewsManager>();
await newsManager.SaveNewsAsync(news);
}
}
public class NewsModel
{
[JsonPropertyName("title")]
[DisplayName("新闻标题")]
public string Title { get; set; }
[JsonPropertyName("content")]
[DisplayName("新闻内容")]
public string Content { get; set; }
[JsonPropertyName("summary")]
[DisplayName("新闻简介")]
public string Summary { get; set; }
[JsonPropertyName("source")]
[DisplayName("新闻来源")]
public string Source { get; set; }
}

View File

@@ -0,0 +1,34 @@
using System.ComponentModel;
using System.Text.Json.Serialization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
namespace Yi.Framework.Stock.Domain.Managers.SemanticKernel.Plugins;
public class StockPlugins
{
private readonly IServiceProvider _serviceProvider;
public StockPlugins(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
[KernelFunction("save_stocks"), Description("生成并且保存多个股票记录")]
public async Task SaveAsync(List<StockModel> stockModels)
{
var stockMarketManager= _serviceProvider.GetRequiredService<StockMarketManager>();
await stockMarketManager.SaveStockAsync(stockModels);
}
}
public class StockModel
{
[JsonPropertyName("id")]
[DisplayName("股票id")]
public Guid Id { get; set; }
[JsonPropertyName("values")]
[DisplayName("股票未来24小时价格")]
public decimal[] Values { get; set; }
}

View File

@@ -0,0 +1,55 @@
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Volo.Abp.DependencyInjection;
namespace Yi.Framework.Stock.Domain.Managers.SemanticKernel;
public class SemanticKernelClient:ITransientDependency
{
public Kernel Kernel { get;}
public SemanticKernelClient(Kernel kernel)
{
this.Kernel = kernel;
}
/// <summary>
/// 执行插件
/// </summary>
/// <param name="input"></param>
/// <param name="pluginName"></param>
/// <param name="functionName"></param>
/// <returns></returns>
public async Task<string> InovkerFunctionAsync(string input, string pluginName, string functionName)
{
KernelFunction jsonFun = this.Kernel.Plugins.GetFunction(pluginName, functionName);
var result = await this.Kernel.InvokeAsync(function: jsonFun, new KernelArguments() { ["input"] = input });
return result.GetValue<string>();
}
/// <summary>
/// 聊天对话,调用方法
/// </summary>
/// <returns></returns>
public async Task<IReadOnlyList<ChatMessageContent>> ChatCompletionAsync(string question,params (string,string)[] functions)
{
if (functions is null)
{
throw new Exception("请选择插件");
}
var openSettings = new OpenAIPromptExecutionSettings()
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(functions.Select(x=>this.Kernel.Plugins.GetFunction(x.Item1, x.Item2)).ToList(),true),
// ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions,
MaxTokens =1000
};
var chatCompletionService = this.Kernel.GetRequiredService<IChatCompletionService>();
var results =await chatCompletionService.GetChatMessageContentsAsync(
question,
executionSettings: openSettings,
kernel: Kernel);
return results;
}
}

View File

@@ -0,0 +1,9 @@
namespace Yi.Framework.Stock.Domain.Managers.SemanticKernel
{
public class SemanticKernelOptions
{
public string ModelId { get; set; }
public string Endpoint { get; set; }
public string ApiKey { get; set; }
}
}

View File

@@ -0,0 +1,445 @@
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Services;
using Volo.Abp.EventBus.Local;
using Yi.Framework.Bbs.Domain.Shared.Etos;
using Yi.Framework.Stock.Domain.Entities;
using Yi.Framework.Stock.Domain.Shared;
using Yi.Framework.Stock.Domain.Shared.Etos;
using Yi.Framework.SqlSugarCore.Abstractions;
using Yi.Framework.Stock.Domain.Managers.SemanticKernel;
using Yi.Framework.Stock.Domain.Managers.SemanticKernel.Plugins;
using Microsoft.Extensions.Hosting;
using System.Text;
using System.IO;
namespace Yi.Framework.Stock.Domain.Managers
{
/// <summary>
/// 股市领域服务
/// </summary>
/// <remarks>
/// 处理股票交易相关业务,例如买入、卖出等
/// </remarks>
public class StockMarketManager : DomainService
{
private readonly ISqlSugarRepository<StockHoldingAggregateRoot> _stockHoldingRepository;
private readonly ISqlSugarRepository<StockTransactionEntity> _stockTransactionRepository;
private readonly ISqlSugarRepository<StockPriceRecordEntity> _stockPriceRecordRepository;
private readonly ISqlSugarRepository<StockMarketAggregateRoot> _stockMarketRepository;
private readonly ILocalEventBus _localEventBus;
private readonly SemanticKernelClient _skClient;
private readonly IHostEnvironment _hostEnvironment;
private readonly NewsManager _newsManager;
public StockMarketManager(
ISqlSugarRepository<StockHoldingAggregateRoot> stockHoldingRepository,
ISqlSugarRepository<StockTransactionEntity> stockTransactionRepository,
ISqlSugarRepository<StockPriceRecordEntity> stockPriceRecordRepository,
ISqlSugarRepository<StockMarketAggregateRoot> stockMarketRepository,
ILocalEventBus localEventBus,
SemanticKernelClient skClient,
IHostEnvironment hostEnvironment,
NewsManager newsManager)
{
_stockHoldingRepository = stockHoldingRepository;
_stockTransactionRepository = stockTransactionRepository;
_stockPriceRecordRepository = stockPriceRecordRepository;
_stockMarketRepository = stockMarketRepository;
_localEventBus = localEventBus;
_skClient = skClient;
_hostEnvironment = hostEnvironment;
_newsManager = newsManager;
}
/// <summary>
/// 购买股票
/// </summary>
/// <param name="userId">用户ID</param>
/// <param name="stockId">股票ID</param>
/// <param name="quantity">购买数量</param>
/// <returns></returns>
public async Task BuyStockAsync(Guid userId, Guid stockId, int quantity)
{
if (quantity <= 0)
{
throw new UserFriendlyException("购买数量必须大于0");
}
// 通过stockId查询获取股票信息
var stockInfo = await _stockMarketRepository.GetFirstAsync(s => s.Id == stockId);
if (stockInfo == null)
{
throw new UserFriendlyException("找不到指定的股票");
}
string stockCode = stockInfo.MarketCode; // 根据实际字段调整
string stockName = stockInfo.MarketName; // 根据实际字段调整
// 获取当前股票价格
decimal currentPrice = await GetCurrentStockPriceAsync(stockId);
// 计算总金额和手续费
decimal totalAmount = currentPrice * quantity;
decimal fee = CalculateTradingFee(totalAmount, TransactionTypeEnum.Buy);
decimal totalCost = totalAmount + fee;
// 扣减用户资金
await _localEventBus.PublishAsync(
new MoneyChangeEventArgs { UserId = userId, Number = -totalCost }, false);
// 更新或创建用户持仓
var holding = await _stockHoldingRepository.GetFirstAsync(h =>
h.UserId == userId &&
h.StockId == stockId &&
!h.IsDeleted);
if (holding == null)
{
// 创建新持仓
holding = new StockHoldingAggregateRoot(
userId,
stockId,
stockCode,
stockName,
quantity,
currentPrice);
await _stockHoldingRepository.InsertAsync(holding);
}
else
{
// 更新现有持仓
holding.AddQuantity(quantity, currentPrice);
await _stockHoldingRepository.UpdateAsync(holding);
}
// 发布交易事件
await _localEventBus.PublishAsync(new StockTransactionEto
{
UserId = userId,
StockId = stockId,
StockCode = stockCode,
StockName = stockName,
TransactionType = TransactionTypeEnum.Buy,
Price = currentPrice,
Quantity = quantity,
TotalAmount = totalAmount,
Fee = fee
}, false);
}
/// <summary>
/// 卖出股票
/// </summary>
/// <param name="userId">用户ID</param>
/// <param name="stockId">股票ID</param>
/// <param name="quantity">卖出数量</param>
/// <returns></returns>
public async Task SellStockAsync(Guid userId, Guid stockId, int quantity)
{
// 验证卖出时间
VerifySellTime();
if (quantity <= 0)
{
throw new UserFriendlyException("卖出数量必须大于0");
}
// 获取用户持仓
var holding = await _stockHoldingRepository.GetFirstAsync(h =>
h.UserId == userId &&
h.StockId == stockId &&
!h.IsDeleted);
if (holding == null)
{
throw new UserFriendlyException("您没有持有该股票");
}
if (holding.Quantity < quantity)
{
throw new UserFriendlyException("持仓数量不足");
}
// 获取当前股票价格
decimal currentPrice = await GetCurrentStockPriceAsync(stockId);
// 计算总金额和手续费
decimal totalAmount = currentPrice * quantity;
decimal fee = CalculateTradingFee(totalAmount, TransactionTypeEnum.Sell);
decimal actualIncome = totalAmount - fee;
// 增加用户资金
await _localEventBus.PublishAsync(
new MoneyChangeEventArgs { UserId = userId, Number = actualIncome }, false);
// 更新用户持仓
holding.ReduceQuantity(quantity);
if (holding.Quantity > 0)
{
await _stockHoldingRepository.UpdateAsync(holding);
}
else
{
await _stockHoldingRepository.DeleteAsync(holding);
}
// 发布交易事件
await _localEventBus.PublishAsync(new StockTransactionEto
{
UserId = userId,
StockId = stockId,
StockCode = holding.StockCode,
StockName = holding.StockName,
TransactionType = TransactionTypeEnum.Sell,
Price = currentPrice,
Quantity = quantity,
TotalAmount = totalAmount,
Fee = fee
}, false);
}
/// <summary>
/// 获取股票当前价格
/// </summary>
/// <param name="stockId">股票ID</param>
/// <returns>当前价格</returns>
public async Task<decimal> GetCurrentStockPriceAsync(Guid stockId)
{
// 获取最新的价格记录
var latestPriceRecord = await _stockPriceRecordRepository._DbQueryable
.Where(p => p.StockId == stockId)
.OrderByDescending(p => p.RecordTime)
.FirstAsync();
if (latestPriceRecord == null)
{
throw new UserFriendlyException("无法获取股票价格信息");
}
return latestPriceRecord.CurrentPrice;
}
/// <summary>
/// 计算交易手续费
/// </summary>
/// <param name="amount">交易金额</param>
/// <param name="transactionType">交易类型</param>
/// <returns>手续费</returns>
private decimal CalculateTradingFee(decimal amount, TransactionTypeEnum transactionType)
{
// 买入不收手续费卖出收2%
decimal feeRate = transactionType == TransactionTypeEnum.Buy ? 0m : 0.02m;
return amount * feeRate;
}
/// <summary>
/// 验证卖出时间
/// </summary>
/// <exception cref="UserFriendlyException">如果不在允许卖出的时间范围内</exception>
private void VerifySellTime()
{
// 如果是开发环境,跳过验证
if (_hostEnvironment.IsDevelopment())
{
return;
}
DateTime now = DateTime.Now;
// 检查是否为工作日(周一到周五)
if (now.DayOfWeek == DayOfWeek.Saturday || now.DayOfWeek == DayOfWeek.Sunday)
{
throw new UserFriendlyException("股票只能在工作日(周一至周五)卖出");
}
// 检查是否在下午5点到6点之间
if (now.Hour < 17 || now.Hour >= 18)
{
throw new UserFriendlyException("股票只能在下午5点到6点之间卖出");
}
}
/// <summary>
/// 批量保存多个股票的最新价格记录
/// </summary>
/// <param name="priceRecords">价格记录列表</param>
/// <returns>保存的记录数量</returns>
public async Task BatchSaveStockPriceRecordsAsync(List<StockPriceRecordEntity> priceRecords)
{
if (priceRecords == null || !priceRecords.Any())
{
return;
}
// 验证数据
for (int i = 0; i < priceRecords.Count; i++)
{
var record = priceRecords[i];
if (record.CurrentPrice <= 0)
{
throw new UserFriendlyException($"股票ID {record.StockId} 的价格必须大于0");
}
// 计算交易额(如果未设置)
if (record.Turnover == 0 && record.Volume > 0)
{
record.Turnover = record.CurrentPrice * record.Volume;
}
}
await _stockPriceRecordRepository.InsertManyAsync(priceRecords);
}
public async Task SaveStockAsync(List<StockModel> stockModels)
{
if (stockModels == null || !stockModels.Any())
{
return;
}
// 收集所有股票ID
var stockIds = stockModels.Select(m => m.Id).ToList();
// 一次性查询所有相关股票信息
var stockMarkets = await _stockMarketRepository.GetListAsync(s => stockIds.Contains(s.Id));
// 构建字典以便快速查找
var stockMarketsDict = stockMarkets.ToDictionary(s => s.Id);
// 将StockModel转换为StockPriceRecordEntity
var priceRecords = new List<StockPriceRecordEntity>();
// 获取当前小时的起始时间点
var currentHour = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0);
foreach (var stockModel in stockModels)
{
if (stockModel.Values == null || !stockModel.Values.Any())
{
continue;
}
// 从字典中查找股票信息,而不是每次查询数据库
if (!stockMarketsDict.TryGetValue(stockModel.Id, out var stockMarket))
{
continue;
}
// 为每个价格点创建一个记录,并设置递增的时间
for (int i = 0; i < stockModel.Values.Count(); i++)
{
var priceValue = stockModel.Values[i];
var recordTime = currentHour.AddHours(i); // 从当前小时开始每个价格点加1小时
var priceRecord = new StockPriceRecordEntity
{
StockId = stockMarket.Id,
CurrentPrice = priceValue,
Volume = 0, // 可以根据实际情况设置
Turnover = 0, // 可以根据实际情况设置
PeriodType = PeriodTypeEnum.Hour,
RecordTime = recordTime // 直接在这里设置时间
};
priceRecords.Add(priceRecord);
}
}
// 批量保存价格记录
if (priceRecords.Any())
{
await _stockPriceRecordRepository.InsertManyAsync(priceRecords);
}
}
/// <summary>
/// 获取所有活跃股票的最新价格
/// </summary>
/// <returns>股票ID和最新价格的字典</returns>
private async Task<Dictionary<Guid, decimal>> GetLatestStockPricesAsync()
{
// 获取所有活跃的股票
var activeStocks = await _stockMarketRepository.GetListAsync(s => s.State && !s.IsDeleted);
var result = new Dictionary<Guid, decimal>();
foreach (var stock in activeStocks)
{
try
{
var price = await GetCurrentStockPriceAsync(stock.Id);
result.Add(stock.Id, price);
}
catch
{
// 如果获取价格失败使用默认价格10
result.Add(stock.Id, 10m);
}
}
return result;
}
/// <summary>
/// 生成最新股票记录
/// </summary>
/// <returns></returns>
public async Task GenerateStocksAsync()
{
// 获取所有活跃股票的最新价格
var stockPrices = await GetLatestStockPricesAsync();
if (!stockPrices.Any())
{
return; // 没有股票数据,直接返回
}
// 获取所有活跃股票信息,用于构建提示词
var activeStocks = await _stockMarketRepository.GetListAsync(s =>
s.State && !s.IsDeleted && stockPrices.Keys.Contains(s.Id));
// 获取最近10条新闻
var recentNews = await _newsManager.GetRecentNewsAsync(10);
// 构建新闻上下文
var newsContext = new StringBuilder();
if (recentNews.Any())
{
newsContext.AppendLine("以下是最近的新闻摘要:");
foreach (var news in recentNews)
{
newsContext.AppendLine($"- {news.CreationTime:yyyy-MM-dd}: {news.Title}");
newsContext.AppendLine($" {news.Summary}");
newsContext.AppendLine();
}
}
else
{
newsContext.AppendLine("最近没有重要新闻报道。");
}
// 构建股票信息上下文
var stocksContext = new StringBuilder();
stocksContext.AppendLine("以下是需要预测的股票信息:");
foreach (var stock in activeStocks)
{
if (stockPrices.TryGetValue(stock.Id, out var price))
{
stocksContext.AppendLine($"{stock.MarketName}id:{stock.Id},简介:{stock.Description} 最后一次价格:{price:F2}");
}
}
// 从文件读取问题模板
string promptTemplate = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "stock", "marketPrompt.txt"));
// 替换变量
string question = promptTemplate
.Replace("{{newsContext}}", newsContext.ToString())
.Replace("{{stocksContext}}", stocksContext.ToString());
await _skClient.ChatCompletionAsync(question, ("StockPlugins", "save_stocks"));
}
}
}

View File

@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.props" />
<ItemGroup>
<PackageReference Include="Microsoft.SemanticKernel" Version="1.40.0" />
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="$(AbpVersion)" />
<PackageReference Include="Volo.Abp.Caching" Version="$(AbpVersion)" />
@@ -14,8 +15,6 @@
<ItemGroup>
<Folder Include="EventHandlers\" />
<Folder Include="Entities\" />
<Folder Include="Managers\" />
<Folder Include="Repositories\" />
</ItemGroup>

View File

@@ -0,0 +1,50 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using Volo.Abp.Caching;
using Volo.Abp.Domain;
using Yi.Framework.Mapster;
using Yi.Framework.Stock.Domain.Managers;
using Yi.Framework.Stock.Domain.Managers.SemanticKernel;
using Yi.Framework.Stock.Domain.Managers.SemanticKernel.Plugins;
using Yi.Framework.Stock.Domain.Shared;
namespace Yi.Framework.Stock.Domain
{
[DependsOn(
typeof(YiFrameworkStockDomainSharedModule),
typeof(YiFrameworkMapsterModule),
typeof(AbpDddDomainModule),
typeof(AbpCachingModule)
)]
public class YiFrameworkStockDomainModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var services = context.Services;
// 配置绑定
var semanticKernelSection = configuration.GetSection("SemanticKernel");
services.Configure<SemanticKernelOptions>(configuration.GetSection("SemanticKernel"));
services.AddHttpClient();
#pragma warning disable SKEXP0010
// 从配置中获取值
var options = semanticKernelSection.Get<SemanticKernelOptions>();
services.AddKernel()
.AddOpenAIChatCompletion(
modelId: options.ModelId,
endpoint: new Uri(options.Endpoint),
apiKey: options.ApiKey);
#pragma warning restore SKEXP0010
// 添加插件
services.AddSingleton<KernelPlugin>(sp => KernelPluginFactory.CreateFromType<NewsPlugins>(serviceProvider: sp));
services.AddSingleton<KernelPlugin>(sp => KernelPluginFactory.CreateFromType<StockPlugins>(serviceProvider: sp));
// 注册NewsManager
services.AddTransient<NewsManager>();
}
}
}

View File

@@ -34,7 +34,7 @@ public class DiscussLableRepository : SqlSugarRepository<DiscussLableAggregateRo
return entities.Adapt<List<DiscussLableCacheItem>>();
}, () =>
new DistributedCacheEntryOptions()
{ AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(2) }
{ AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(2) },hideErrors:true
);
return cahce.ToDictionary(x => x.Id);
}

View File

@@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.Net;
using Microsoft.Extensions.Options;
using OpenAI;
using OpenAI.Managers;
using OpenAI.ObjectModels;
using OpenAI.ObjectModels.RequestModels;
using OpenAI.ObjectModels.ResponseModels;
// using OpenAI;
// using OpenAI.Managers;
// using OpenAI.ObjectModels;
// using OpenAI.ObjectModels.RequestModels;
// using OpenAI.ObjectModels.ResponseModels;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Services;
using Yi.Framework.ChatHub.Domain.Shared.Dtos;
@@ -16,58 +16,59 @@ namespace Yi.Framework.ChatHub.Domain.Managers
{
public AiManager(IOptions<AiOptions> options)
{
this.OpenAIService = new OpenAIService(new OpenAiOptions()
{
ApiKey = options.Value.ApiKey,
BaseDomain = options.Value.BaseDomain
});
// this.OpenAIService = new OpenAIService(new OpenAiOptions()
// {
// ApiKey = options.Value.ApiKey,
// BaseDomain = options.Value.BaseDomain
// });
}
private OpenAIService OpenAIService { get; }
// private OpenAIService OpenAIService { get; }
public async IAsyncEnumerable<string> ChatAsStreamAsync(string model, List<AiChatContextDto> aiChatContextDtos)
{
if (aiChatContextDtos.Count == 0)
{
yield return null;
}
List<ChatMessage> messages = aiChatContextDtos.Select(x =>
{
if (x.AnswererType == AnswererTypeEnum.Ai)
{
return ChatMessage.FromSystem(x.Message);
}
else
{
return ChatMessage.FromUser(x.Message);
}
}).ToList();
var completionResult = OpenAIService.ChatCompletion.CreateCompletionAsStream(new ChatCompletionCreateRequest
{
Messages = messages,
Model =model
});
HttpStatusCode? error = null;
await foreach (var result in completionResult)
{
if (result.Successful)
{
yield return result.Choices.FirstOrDefault()?.Message.Content ?? null;
}
else
{
error = result.HttpStatusCode;
break;
}
}
if (error == HttpStatusCode.PaymentRequired)
{
yield return "余额不足,请联系站长充值";
}
throw new NotImplementedException("准备sk重构");
yield break;
// if (aiChatContextDtos.Count == 0)
// {
// yield return null;
// }
//
// List<ChatMessage> messages = aiChatContextDtos.Select(x =>
// {
// if (x.AnswererType == AnswererTypeEnum.Ai)
// {
// return ChatMessage.FromSystem(x.Message);
// }
// else
// {
// return ChatMessage.FromUser(x.Message);
// }
// }).ToList();
// var completionResult = OpenAIService.ChatCompletion.CreateCompletionAsStream(new ChatCompletionCreateRequest
// {
// Messages = messages,
// Model =model
// });
//
// HttpStatusCode? error = null;
// await foreach (var result in completionResult)
// {
// if (result.Successful)
// {
// yield return result.Choices.FirstOrDefault()?.Message.Content ?? null;
// }
// else
// {
// error = result.HttpStatusCode;
// break;
// }
//
// }
// if (error == HttpStatusCode.PaymentRequired)
// {
// yield return "余额不足,请联系站长充值";
//
// }
}
}
}

View File

@@ -7,7 +7,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Betalgo.OpenAI" Version="8.6.1" />
<PackageReference Include="Volo.Abp.AspNetCore.SignalR" Version="$(AbpVersion)" />
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="$(AbpVersion)" />

View File

@@ -182,18 +182,16 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsDeleted = false
};
entities.Add(server);
//定时任务
MenuAggregateRoot task = new MenuAggregateRoot(_guidGenerator.Create(), monitoring.Id)
{
MenuName = "定时任务",
PermissionCode = "monitor:job:list",
MenuType = MenuTypeEnum.Menu,
Router = "job",
Router = "http://ccnetcore.com:16001/hangfire",
IsShow = true,
IsLink = false,
IsCache = true,
Component = "monitor/job/index",
IsLink = true,
MenuIcon = "job",
OrderNum = 97,
IsDeleted = false
@@ -219,7 +217,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
{
MenuName = "接口文档",
MenuType = MenuTypeEnum.Menu,
Router = "http://localhost:19001/swagger",
Router = "http://ccnetcore.com:16001/swagger",
IsShow = true,
IsLink = true,
MenuIcon = "list",

View File

@@ -1,15 +0,0 @@
using Volo.Abp.Application.Services;
namespace Yi.Framework.Stock.Application.Services
{
/// <summary>
/// 常用魔改及扩展示例
/// </summary>
public class TestService : ApplicationService
{
public string TTT()
{
return "你好";
}
}
}

View File

@@ -1,19 +0,0 @@
using Volo.Abp.Caching;
using Volo.Abp.Domain;
using Yi.Framework.Stock.Domain.Shared;
using Yi.Framework.Mapster;
namespace Yi.Framework.Stock.Domain
{
[DependsOn(
typeof(YiFrameworkStockDomainSharedModule),
typeof(YiFrameworkMapsterModule),
typeof(AbpDddDomainModule),
typeof(AbpCachingModule)
)]
public class YiFrameworkStockDomainModule : AbpModule
{
}
}

View File

@@ -30,7 +30,6 @@ namespace Yi.Abp.Application.Services
public ISqlSugarRepository<BannerAggregateRoot> sqlSugarRepository { get; set; }
/// <summary>
/// 动态Api
/// </summary>
/// <param name="name"></param>
/// <returns></returns>

View File

@@ -10,7 +10,7 @@
<ProjectReference Include="..\..\module\digital-collectibles\Yi.Framework.DigitalCollectibles.Application\Yi.Framework.DigitalCollectibles.Application.csproj" />
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.Application\Yi.Framework.Rbac.Application.csproj" />
<ProjectReference Include="..\..\module\setting-management\Yi.Framework.SettingManagement.Application\Yi.Framework.SettingManagement.Application.csproj" />
<ProjectReference Include="..\..\module\stock\Yi.Framework.Stock.Application\Yi.Framework.Stock.Application.csproj" />
<ProjectReference Include="..\..\module\ai-stock\Yi.Framework.Stock.Application\Yi.Framework.Stock.Application.csproj" />
<ProjectReference Include="..\..\module\tenant-management\Yi.Framework.TenantManagement.Application\Yi.Framework.TenantManagement.Application.csproj" />
<ProjectReference Include="..\Yi.Abp.Application.Contracts\Yi.Abp.Application.Contracts.csproj" />
<ProjectReference Include="..\Yi.Abp.Domain\Yi.Abp.Domain.csproj" />

View File

@@ -11,7 +11,7 @@
<ProjectReference Include="..\..\module\digital-collectibles\Yi.Framework.DigitalCollectibles.SqlSugarCore\Yi.Framework.DigitalCollectibles.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.SqlSugarCore\Yi.Framework.Rbac.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\setting-management\Yi.Framework.SettingManagement.SqlSugarCore\Yi.Framework.SettingManagement.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\stock\Yi.Framework.Stock.SqlSugarCore\Yi.Framework.Stock.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\ai-stock\Yi.Framework.Stock.SqlSugarCore\Yi.Framework.Stock.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\tenant-management\Yi.Framework.TenantManagement.SqlSugarCore\Yi.Framework.TenantManagement.SqlSugarCore.csproj" />
<ProjectReference Include="..\Yi.Abp.Domain\Yi.Abp.Domain.csproj" />
</ItemGroup>

View File

@@ -0,0 +1,34 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.BackgroundWorkers.Hangfire;
using Yi.Framework.Stock.Domain.Managers;
namespace Yi.Abp.Web.Jobs.ai_stock
{
public class GenerateNewsJob : HangfireBackgroundWorkerBase
{
private NewsManager _newsManager;
public GenerateNewsJob(NewsManager newsManager)
{
_newsManager = newsManager;
RecurringJobId = "AI股票新闻生成";
//每个小时整点执行一次
CronExpression = "0 0 * * * ?";
}
public override async Task DoWorkAsync(CancellationToken cancellationToken = new CancellationToken())
{
// 每次触发只有2/24的概率执行生成新闻
var random = new Random();
var probability = random.Next(0, 24);
if (probability < 2)
{
await _newsManager.GenerateNewsAsync();
}
}
}
}

View File

@@ -0,0 +1,26 @@
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.BackgroundWorkers.Hangfire;
using Yi.Framework.Stock.Domain.Managers;
namespace Yi.Abp.Web.Jobs.ai_stock
{
public class GenerateStockPricesJob : HangfireBackgroundWorkerBase
{
private readonly StockMarketManager _stockMarketManager;
public GenerateStockPricesJob(StockMarketManager stockMarketManager)
{
_stockMarketManager = stockMarketManager;
RecurringJobId = "AI股票价格生成";
//每天凌晨1点执行一次
CronExpression = "0 0 1 * * ?";
}
public override async Task DoWorkAsync(CancellationToken cancellationToken = new CancellationToken())
{
await _stockMarketManager.GenerateStocksAsync();
}
}
}

View File

@@ -47,6 +47,15 @@
<Content Update="appsettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\plugins\news\config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\plugins\news\skprompt.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\stock\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>

View File

@@ -27,6 +27,7 @@ using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.Auditing;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs.Hangfire;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Caching;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Swashbuckle;
@@ -94,7 +95,7 @@ namespace Yi.Abp.Web
options.ConventionalControllers.Create(typeof(YiFrameworkDigitalCollectiblesApplicationModule).Assembly,
options => options.RemoteServiceName = "digital-collectibles");
options.ConventionalControllers.Create(typeof(YiFrameworkStockApplicationModule).Assembly,
options => options.RemoteServiceName = "stock");
options => options.RemoteServiceName = "ai-stock");
//统一前缀
options.ConventionalControllers.ConventionalControllerSettings.ForEach(x => x.RootPath = "api/app");
});
@@ -106,6 +107,15 @@ namespace Yi.Abp.Web
var host = context.Services.GetHostingEnvironment();
var service = context.Services;
//本地开发环境,禁用作业执行
if (host.IsDevelopment())
{
Configure<AbpBackgroundWorkerOptions> (options =>
{
options.IsEnabled = false;
});
}
//请求日志
Configure<AbpAuditingOptions>(options =>
{
@@ -197,10 +207,12 @@ namespace Yi.Abp.Web
bool.TryParse( configuration["Redis:IsEnabled"], out var redisEnabled);
if (redisEnabled)
{
var jobDb=configuration.GetSection("Redis").GetValue<int>("JobDb");
config.UseRedisStorage(
ConnectionMultiplexer.Connect(redisConfiguration),
new RedisStorageOptions()
{
Db =jobDb,
InvisibilityTimeout = TimeSpan.FromHours(1), //JOB允许执行1小时
Prefix = "Yi:HangfireJob:"
}).WithJobExpirationTimeout(TimeSpan.FromHours(1));

View File

@@ -53,14 +53,15 @@
//redis使用freeesql参数在“FreeSqlOptions的ConnectionStringBuilder中”
"Redis": {
"IsEnabled": false,
"Configuration": "127.0.0.1:6379,password=123,defaultDatabase=13"
"Configuration": "127.0.0.1:6379,password=123,defaultDatabase=13",
"JobDb": 13
},
//鉴权
"JwtOptions": {
"Issuer": "https://ccnetcore.com",
"Audience": "https://ccnetcore.com",
"SecurityKey": "zqxwcevrbtnymu312412ihe9rfwhe78rh23djoi32hrui3ryf9e8wfh34iuj54y0934uti4h97fgw7hf97wyh8yy69520",
"SecurityKey": "qqxwcevrbtnymu312412ihe9rfwhe78rh23djoi32hrui3ryf9e8wfh34iuj54y0934uti4h97fgw7hf97wyh8yy69522",
"ExpiresMinuteTime": 86400
},
//刷新token
@@ -108,5 +109,13 @@
"AiOptions": {
"ApiKey": "",
"BaseDomain": ""
},
//语义内核
"SemanticKernel": {
"ModelId": "gpt-4o",
"Endpoint": "https://xxx.com/v1",
"ApiKey": "sk-xxxxxx"
}
}

View File

@@ -0,0 +1,27 @@
根据最近的新闻和当前股票价格预测多家股票未来24小时的价格走势
{{newsContext}}
{{stocksContext}}
请分析上述新闻对各个股票可能产生的影响并预测每支股票未来24小时的价格变动
1. 考虑新闻中提到的行业、公司或经济趋势
2. 分析这些因素对不同股票的积极或消极影响
3. 根据分析生成合理的价格波动
4. 股票的简介是该股票行业、类型等信息准确的定位
对每支股票,请返回:
- 股票id
- 一个长度为24的价格数组表示未来24小时每小时整点的预测价格
价格变动应当符合以下规则:
- 每个小时相邻时间点的价格波动通常不超过前值的20%
- 考虑市场开盘和收盘时间可能带来的较大波动
- 不同股票之间的相关性(如同行业股票可能有类似走势)
- 部分股票可能对某些新闻更敏感,价格会大幅度变化
- 一天24小时下来整体价格变化的趋势应该比较连贯可以部分小时的价格大幅度变化
- 变化幅度可以大一些,为了更吸引用户
- 可能下跌,可能上涨
- 最低价值为1最高价值为100
请确保数据格式正确,以便系统能够自动处理。

View File

@@ -0,0 +1,19 @@
基于以下最近的新闻背景,预测趋势生成一条其他新闻。
{{newsContext}}
包含以下要素:
1. 新闻标题:吸引人且简短,涉及不同行业
2. 新闻内容:详细且符合逻辑的报道,篇幅不要太多,并且内容需要通俗易懂
3. 新闻简介:简明扼要的总结
4. 新闻来源:提供一个虚拟的媒体或机构名称
注意:
- 新闻内容需要以一件具体的事件为内容,可以是现实中发生的进行修改
- 新闻内容不要以某公司为主题,应该是一件有趣的事件
- 内容应当暗示可能对不同行业公司产生某种影响(积极或消极),不能太过于明显
- 行业焦点可以包括娱乐、科技、金融、医疗、食品等多个领域
- 新闻有很小的概率造假,如果是造假的,新闻来源就得来自小的工作室
- 不要一直重复着一个公司、一个行业的新闻
- 可以加一些很离谱的元素增加新闻的趣味性
- 只需生成一次即可

View File

@@ -0,0 +1,67 @@
import request from "@/config/axios/service";
// 获取股票新闻列表
export function getStockNews(params) {
return request({
url: "/stock/news",
method: "get",
params
});
}
// 获取用户股票持仓
export function getUserHoldings() {
return request({
url: "/stock/user-holdings",
method: "get"
});
}
// 获取用户交易记录
export function getUserTransactions(stockCode) {
return request({
url: "/stock/user-transactions",
method: "get",
params: { stockCode }
});
}
// 获取股票价格记录
export function getStockPriceRecords(stockId, startTime, endTime, periodType = 'Hour') {
return request({
url: "/stock/price-records",
method: "get",
params: {
StockId: stockId,
StartTime: startTime,
EndTime: endTime,
PeriodType: periodType
}
});
}
// 获取股市列表
export function getStockMarkets() {
return request({
url: "/stock/markets",
method: "get"
});
}
// 买入股票
export function buyStock(data) {
return request({
url: "/stock/buy",
method: "post",
data
});
}
// 卖出股票
export function sellStock(params) {
return request({
url: "/stock/sell",
method: "delete",
params
});
}

View File

@@ -75,9 +75,9 @@ export function getUserProfile() {
}
// 查询bbs个人信息
export function getBbsUserProfile(userName) {
export function getBbsUserProfile(userNameOrId) {
return request({
url: `/bbs-user/${userName}`,
url: `/bbs-user/${userNameOrId}`,
method: "get",
});
}

View File

@@ -37,16 +37,10 @@
</template>
<script setup>
import useUserStore from "@/stores/user";
import { reactive, watch, onMounted, computed, ref } from "vue";
import { upload } from "@/apis/fileApi";
import useAuths from "@/hooks/useAuths";
import { reactive, watch, onMounted, ref } from "vue";
import UserInfoCard from "./UserInfoCard/index.vue";
import UserLimitTag from "./UserLimitTag.vue";
const { getToken } = useAuths();
const isHasToken = getToken();
//userInfo
//{icon,name,role,id},根据判断userInfo是否等于未定义来觉得是当前登录用户信息还是其他人信息
const props = defineProps([

View File

@@ -0,0 +1,147 @@
<template>
<div class="stock-board">
<h2>股票看板</h2>
<div class="stock-list">
<div v-for="stock in stocks" :key="stock.code" class="stock-item">
<div class="stock-info">
<h3>{{ stock.name }} ({{ stock.code }})</h3>
<p :class="getPriceClass(stock)">¥{{ stock.currentPrice }}</p>
<p>涨跌幅: <span :class="getPriceClass(stock)">{{ stock.changePercent }}%</span></p>
</div>
<div class="stock-actions">
<button @click="handleBuy(stock)">买入</button>
<button @click="handleSell(stock)">卖出</button>
</div>
</div>
</div>
<!-- 交易弹窗 -->
<div v-if="showTradeModal" class="trade-modal">
<h3>{{ tradeType === 'buy' ? '买入' : '卖出' }} {{ selectedStock.name }}</h3>
<p>当前价格: ¥{{ selectedStock.currentPrice }}</p>
<div class="form-group">
<label>数量:</label>
<input v-model="tradeAmount" type="number" min="1" />
</div>
<div class="form-group">
<label>总金额: ¥{{ totalAmount }}</label>
</div>
<div class="modal-actions">
<button @click="confirmTrade">确认</button>
<button @click="cancelTrade">取消</button>
</div>
</div>
</div>
</template>
<script setup>
import { ref, computed } from 'vue'
import { useStocks } from '@/composables/useStocks'
import { useTrades } from '@/composables/useTrades'
const { stocks } = useStocks()
const { executeTrade } = useTrades()
const showTradeModal = ref(false)
const selectedStock = ref({})
const tradeType = ref('')
const tradeAmount = ref(1)
const totalAmount = computed(() => {
return (selectedStock.value.currentPrice * tradeAmount.value).toFixed(2)
})
function getPriceClass(stock) {
return {
'price-up': stock.changePercent > 0,
'price-down': stock.changePercent < 0,
'price-unchanged': stock.changePercent === 0
}
}
function handleBuy(stock) {
selectedStock.value = stock
tradeType.value = 'buy'
showTradeModal.value = true
}
function handleSell(stock) {
selectedStock.value = stock
tradeType.value = 'sell'
showTradeModal.value = true
}
function confirmTrade() {
executeTrade({
stockCode: selectedStock.value.code,
stockName: selectedStock.value.name,
price: selectedStock.value.currentPrice,
amount: tradeAmount.value,
type: tradeType.value,
date: new Date().toISOString()
})
cancelTrade()
}
function cancelTrade() {
showTradeModal.value = false
tradeAmount.value = 1
}
</script>
<style scoped>
.stock-board {
padding: 1rem;
}
.stock-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 1rem;
}
.stock-item {
border: 1px solid #eee;
border-radius: 8px;
padding: 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.price-up {
color: #ff4d4f;
}
.price-down {
color: #52c41a;
}
.price-unchanged {
color: #666;
}
.trade-modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
z-index: 1000;
}
.form-group {
margin: 1rem 0;
}
.modal-actions {
display: flex;
justify-content: flex-end;
gap: 1rem;
margin-top: 1rem;
}
</style>

View File

@@ -13,8 +13,8 @@
<el-menu-item index="2" @click="enterStart"
>开始</el-menu-item>
<el-menu-item index="3" @click="enterBook" style="color: red;font-weight: bolder;font-size: large;"
>面试宝典</el-menu-item>
<el-menu-item index="3" @click="enterTemp" style="color: red;font-weight: bolder;font-size: large;"
>Ai炒股</el-menu-item>
<el-menu-item index="4" @click="enterShop"
>商城</el-menu-item>
<!-- <el-sub-menu index="4">-->
@@ -233,8 +233,8 @@ const enterStart = () => {
router.push("/start");
}
const enterBook=()=>{
router.push("/book");
const enterTemp=()=>{
router.push("/stock");
}
const enterShop=()=>{
router.push("/shop");

View File

@@ -195,7 +195,14 @@ const router = createRouter({
},
],
},
{
name: "stock",
path: "/stock",
component: () => import("../views/stock/Index.vue"),
meta: {
title: "股票",
},
},
{
path: "/hub",
name: "hub",

View File

@@ -108,10 +108,10 @@ margin: 10px auto;">
<el-col v-if="!isIcp" :span="24">
<InfoCard header="活动">
<template #content>
<div class="top">祝各位蛇年大吉~</div>
<div class="top">与AI同行创造无限可能</div>
<el-row class="active">
<el-col style="padding: 5px 0px;" v-for="item in activeList" :span="6" @click="handleToRouter(item.path)">
<el-col style="padding: 5px 0px;box-shadow:none" v-for="item in activeList" :span="6" @click="handleToRouter(item.path)">
<el-icon color="#70aafb" size="30px">
<component :is="item.icon"></component>
@@ -132,7 +132,9 @@ margin: 10px auto;">
</template>
</InfoCard>
<el-dialog v-model="accessLogDialogVisible" title="全站历史统计" width="1200px" center>
</el-col>
<el-dialog v-model="accessLogDialogVisible" title="全站历史统计" width="1200px" center>
<el-tabs v-model="accessLogTab">
<el-tab-pane label="访问统计近3月" name="AccessLogChart"
style="display: flex;justify-content: center;">
@@ -147,8 +149,6 @@ margin: 10px auto;">
</el-dialog>
</el-col>
<el-col :span="24">
<InfoCard header="简介" text="">
<template #content>
@@ -214,7 +214,7 @@ margin: 10px auto;">
</template>
</el-col>
<el-col :span="24" style="background: transparent">
<el-col :span="24" style="background-color: #ffffff;">
<BottomInfo/>
</el-col>
</el-row>
@@ -311,10 +311,11 @@ const activeList = [
{name: "排行榜", path: "/money", icon: "Money"},
{name: "开始", path: "/start", icon: "Position"},
{name: "聊天室", path: "/chat", icon: "ChatRound"},
{name: "商城", path: "/shop", icon: "ShoppingCart"},
{name: "数字藏品", path: "/dc", icon: "Trophy"},
{name: "面试宝典", path: "/book", icon: "Memo"},
{name: "AI炒股", path: "/stock", icon: "TrendCharts"},
// {name: "小程序", path: "/", icon: "Position"},
// {name: "公众号", path: "/", icon: "ChatRound"},
];
@@ -431,7 +432,6 @@ const registerLogOptins = computed(() => {
});
const onClickMoneyTop = () => {
router.push("/money");
};
@@ -526,29 +526,43 @@ const onClickToWeChat = () => {
</script>
<style scoped lang="scss">
.home-box {
width: 1300px;
height: 100%;
width: 100%; /* 改为100%使其更具响应性 */
max-width: 1300px; /* 保持最大宽度限制 */
margin: 0 auto; /* 居中显示 */
.left-div .el-col,
.right-div .el-col {
background-color: #ffffff;
margin-bottom: 1rem;
border-radius: 8px; /* 增加圆角 */
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05); /* 添加微妙阴影 */
transition: all 0.3s ease; /* 过渡效果 */
&:hover {
transform: translateY(-5px); /* 悬停时微抬升 */
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1); /* 悬停时增强阴影 */
}
}
/* 简介卡片样式特别处理 */
.introduce {
color: rgba(0, 0, 0, 0.45);
font-size: small;
color: rgba(0, 0, 0, 0.65); /* 更深的颜色提高对比度 */
font-size: 14px; /* 稍微增大字体 */
line-height: 1.6; /* 增加行高 */
padding: 15px 5px; /* 增加内边距 */
letter-spacing: 0.5px; /* 字间距 */
span {
color: #1890ff;
font-weight: 600; /* 加粗 */
padding: 0 2px; /* 增加内边距 */
}
}
.plate {
background: transparent !important;
}
.left-div .el-col {
background-color: #ffffff;
margin-bottom: 1rem;
}
.right-div .el-col {
background-color: #ffffff;
margin-bottom: 1rem;
}
.carousel-font {
position: absolute;
z-index: 1;
@@ -633,43 +647,40 @@ const onClickToWeChat = () => {
.active {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
align-items: center;
color: #8a919f;
/* gap: 10px; */
/* padding: 15px; */
/* background-color: #f9f9f9; */
border-radius: 8px;
.el-col {
flex-direction: column;
align-items: center;
display: flex;
cursor: pointer;
padding: 10px 0px;
}
.el-col:hover {
background-color: #cce1ff;
/* 悬浮时背景色变化 */
color: #70aafb;
/* 悬浮时文字颜色变化 */
}
&-btn {
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
width: 74px;
height: 36px;
border-radius: 4px;
border: 1px solid rgba(30, 128, 255, 0.3);
background-color: rgba(30, 128, 255, 0.1);
color: #1e80ff;
padding: 15px 0; /* 增加内边距 */
border-radius: 6px; /* 圆角 */
transition: all 0.3s ease;
.el-icon {
font-size: 24px; /* 增大图标 */
margin-bottom: 8px; /* 增加与文字间距 */
color: #606266; /* 初始颜色 */
}
&:hover {
background-color: #ebf5ff; /* 更柔和的悬停色 */
color: #409eff; /* 文字颜色变化 */
.el-icon {
color: #409eff; /* 图标颜色跟随变化 */
transform: scale(1.1); /* 图标微放大 */
}
}
}
}
.VisitsLineChart > > > .el-card__body {
padding: 0.5rem;
}
.VisitsLineChart p {
display: flex;
@@ -727,21 +738,92 @@ const onClickToWeChat = () => {
}
/* 设置滚动条样式 */
/* 美化滚动条样式 */
.scrollable-div::-webkit-scrollbar {
width: 3px; /* 设置滚动条的宽度 */
width: 6px; /* 稍微加宽 */
}
.scrollable-div::-webkit-scrollbar-track {
background: #f1f1f1; /* 滚动条轨道背景 */
background: #f5f5f5;
border-radius: 10px;
}
.scrollable-div::-webkit-scrollbar-thumb {
background: #cccccc; /* 滚动条的颜色 */
border-radius: 10px; /* 设置圆角 */
background: linear-gradient(to bottom, #e0e0e0, #bdbdbd); /* 渐变色滚动条 */
border-radius: 10px;
border: 2px solid transparent;
background-clip: content-box;
}
.scrollable-div::-webkit-scrollbar-thumb:hover {
background: #555; /* 滚动条 hover 时的颜色 */
background: linear-gradient(to bottom, #bdbdbd, #9e9e9e); /* 悬停时颜色变深 */
}
/* 优化切换按钮 */
.switch-span {
display: inline-block;
padding: 5px 12px;
background-color: #ecf5ff;
color: #409eff;
border-radius: 20px; /* 更圆润的形状 */
font-size: 13px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 6px rgba(64, 158, 255, 0.15); /* 添加微妙阴影 */
position: relative;
overflow: hidden;
&:hover {
background-color: #409eff;
color: #fff !important;/* 悬浮时文字变为白色 */
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(64, 158, 255, 0.25);
}
&:active {
transform: translateY(0); /* 点击时回到原位 */
box-shadow: 0 1px 3px rgba(64, 158, 255, 0.2); /* 点击时减弱阴影 */
}
/* 添加图标指示切换功能 */
&::after {
content: "⟳"; /* 添加旋转图标 */
margin-left: 5px;
display: inline-block;
transition: transform 0.3s ease;
}
&:hover::after {
transform: rotate(180deg); /* 悬停时图标旋转 */
}
}
// /* 媒体查询添加对不同屏幕尺寸的适应 */
// @media (max-width: 1400px) {
// .home-box {
// width: 95%;
// }
// }
// @media (max-width: 768px) {
// .home-box {
// width: 100%;
// .analyse {
// flex-direction: column;
// height: auto;
// .item {
// width: 90%;
// margin-bottom: 15px;
// }
// }
// .active {
// .el-col {
// width: 25%; /* 小屏幕时每行显示4个 */
// }
// }
// }
// }
</style>

View File

@@ -69,37 +69,88 @@ const handleClickTabs=async (pane) => {
<template>
<div class="content-body">
<el-tabs v-model="tabSelect" @tab-click="handleClickTabs" class="tabs">
<el-tab-pane label="钱钱" name="money"><p class="tab-title">钱钱排行榜</p></el-tab-pane>
<el-tab-pane label="价值" name="value"><p class="tab-title">价值排行榜</p></el-tab-pane>
<el-tab-pane label="积分" name="points"><p class="tab-title">积分排行榜</p></el-tab-pane>
</el-tabs>
<AwardPedestal v-show="isFirstPage" :goldUserInfo="pointList[0]" :silverUserInfo="pointList[1]"
:bronzeUserInfo="pointList[2]" />
<div v-for="item in pointListFilter" :key="item.id" class="list-div">
<div class="list-left">
<span> {{ item.order }}</span>
<AvatarInfo :userInfo="item" :isSelf="false" />
<span class="money">
{{ item.money }}
</span>
</div>
<div class="list-right">
关注
</div>
<div class="header-banner">
<h1 class="main-title">{{ tabSelect === 'money' ? '钱钱排行榜' : tabSelect === 'value' ? '价值排行榜' : '积分排行榜' }}</h1>
</div>
<el-tabs v-model="tabSelect" @tab-click="handleClickTabs" class="tabs">
<el-tab-pane label="钱钱" name="money"></el-tab-pane>
<el-tab-pane label="价值" name="value"></el-tab-pane>
<el-tab-pane label="积分" name="points"></el-tab-pane>
</el-tabs>
<transition name="fade">
<AwardPedestal v-show="isFirstPage" :goldUserInfo="pointList[0]" :silverUserInfo="pointList[1]"
:bronzeUserInfo="pointList[2]" />
</transition>
<div class="list-container">
<transition-group name="list" tag="div">
<div v-for="(item, index) in pointListFilter" :key="item.id" class="list-div" :style="{'--delay': `${index * 0.05}s`}">
<div class="list-left">
<span class="rank-number" :class="{'top-ten': item.order <= 10}"> {{ item.order }}</span>
<AvatarInfo :userInfo="item" :isSelf="false" />
<span class="money">
{{ item.money }}
</span>
</div>
<div class="list-right">
<el-button type="primary" size="small" class="follow-btn">关注</el-button>
</div>
</div>
</transition-group>
</div>
<el-pagination background layout="total, sizes, prev, pager, next, jumper" :total="total"
:page-sizes="[10, 30, 50, 100]" v-model:current-page="moneyQuery.skipCount"
v-model:page-size="moneyQuery.maxResultCount" @current-change="changePage" @size-change="changePage" />
v-model:page-size="moneyQuery.maxResultCount" @current-change="changePage" @size-change="changePage" class="pagination" />
</div>
</template>
<style scoped lang="scss">
.el-pagination {
.header-banner {
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
padding: 30px 0;
border-radius: 10px;
margin-bottom: 30px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}
padding: 10px;
.main-title {
color: white;
text-align: center;
font-size: 2.5rem;
margin: 0;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.fade-enter-active, .fade-leave-active {
transition: opacity 0.5s;
}
.fade-enter-from, .fade-leave-to {
opacity: 0;
}
.list-container {
max-width: 900px;
margin: 0 auto;
}
.list-enter-active, .list-leave-active {
transition: all 0.5s ease;
}
.list-enter-from {
opacity: 0;
transform: translateX(-30px);
}
.list-leave-to {
opacity: 0;
transform: translateX(30px);
}
.el-pagination {
padding: 20px;
display: flex;
justify-content: center;
margin-top: 20px;
}
.content-body {
@@ -107,51 +158,132 @@ const handleClickTabs=async (pane) => {
margin-top: 20px;
padding: 20px;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}
.list-div {
justify-content: space-between;
border-radius: 4px;
border-radius: 8px;
display: flex;
background-color: #ffffff;
height: 80px;
width: 850px;
width: 100%;
cursor: pointer;
padding: 16px 12px;
padding: 16px 20px;
margin-bottom: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
transition: all 0.3s ease;
animation: slideIn 0.5s ease backwards;
animation-delay: var(--delay);
.list-left {
display: flex;
align-items: center;
span {
.rank-number {
width: 40px;
height: 40px;
margin-right: 20px;
color: #515767;
font-size: 1.5rem;
font-weight: 600;
line-height: 2rem;
display: flex;
align-content: center;
flex-wrap: wrap;
align-items: center;
justify-content: center;
position: relative;
&.top-ten {
color: white;
background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 99%, #fad0c4 100%);
border-radius: 50%;
box-shadow: 0 4px 8px rgba(255, 154, 158, 0.3);
}
}
.money {
font-size: 1.0rem;
color: #ff0000;
font-size: 1.2rem;
color: #ff5252;
font-weight: bold;
margin-left: 15px;
}
}
.list-right {
display: flex;
align-items: center;
.follow-btn {
transition: all 0.3s;
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
border: none;
&:hover {
transform: translateY(-2px);
box-shadow: 0 5px 10px rgba(118, 75, 162, 0.3);
}
}
}
}
.list-div:hover {
background-color: #f7f8fa;
background-color: #f8f9ff;
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
}
.tabs :deep(.el-tabs__nav-wrap)
{
.tabs :deep(.el-tabs__nav-wrap) {
display: flex;
justify-content: center !important;
}
.tab-title
{
text-align: center;
font-size: 30px;
margin-bottom: 20px;
.tabs :deep(.el-tabs__item) {
font-size: 18px;
padding: 0 30px;
transition: all 0.3s;
&.is-active {
font-weight: bold;
color: #6a11cb;
transform: scale(1.05);
}
&:hover {
color: #6a11cb;
}
}
.tabs :deep(.el-tabs__active-bar) {
background-color: #6a11cb;
height: 3px;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.pagination {
:deep(.el-pagination__sizes),
:deep(.btn-prev),
:deep(.btn-next),
:deep(.el-pager li) {
transition: all 0.3s;
&:hover {
transform: translateY(-2px);
}
}
:deep(.el-pager li.active) {
background-color: #6a11cb;
color: white;
}
}
</style>

View File

@@ -1,34 +1,52 @@
<script setup>
import AvatarInfo from "@/components/AvatarInfo.vue";
import { ref, onMounted } from "vue";
const props = defineProps([
"goldUserInfo",
"silverUserInfo",
"bronzeUserInfo",
]);
const isVisible = ref(false);
onMounted(() => {
setTimeout(() => {
isVisible.value = true;
}, 300);
});
</script>
<template>
<div class="podium">
<div class="avatar">
<AvatarInfo :userInfo="silverUserInfo" :isSelf="true" />
<div class="tier silver">
<h2>第二</h2>
<h3>{{ silverUserInfo?.money }}</h3>
<div class="podium-container">
<div class="podium" :class="{ 'visible': isVisible }">
<div class="avatar silver-position">
<div class="avatar-wrapper">
<AvatarInfo style="display: flex;" :userInfo="{nick:'123'}" :isSelf="true" />
</div>
<div class="tier silver">
<h2>第二</h2>
<h3>{{ silverUserInfo?.money }}</h3>
</div>
</div>
</div>
<div class="avatar">
<AvatarInfo :userInfo="goldUserInfo" :isSelf="true" :size="50" />
<div class="tier gold">
<h2>第一</h2>
<h3>{{ goldUserInfo?.money }}</h3>
<div class="avatar gold-position">
<div class="avatar-wrapper">
<AvatarInfo :userInfo="goldUserInfo" :isSelf="true" :size="50" />
</div>
<div class="tier gold">
<h2>第一</h2>
<h3>{{ goldUserInfo?.money }}</h3>
</div>
</div>
</div>
<div class="avatar">
<AvatarInfo :userInfo="bronzeUserInfo" :isSelf="true" />
<div class="tier bronze">
<h2>第三</h2>
<h3>{{ bronzeUserInfo?.money }}</h3>
<div class="avatar bronze-position">
<div class="avatar-wrapper">
<AvatarInfo :userInfo="bronzeUserInfo" :isSelf="true" />
</div>
<div class="tier bronze">
<h2>第三</h2>
<h3>{{ bronzeUserInfo?.money }}</h3>
</div>
</div>
</div>
</div>
@@ -36,14 +54,107 @@ const props = defineProps([
<style scoped>
h2{
margin: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
h3{
margin: 10px;
font-size: 1.5rem;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.podium-container {
position: relative;
margin: 40px 0;
}
.avatar {
display: flex;
justify-content: center;
flex-direction: column;
position: relative;
transition: all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.visible .gold-position {
transform: translateY(0);
opacity: 1;
transition-delay: 0.3s;
}
.visible .silver-position {
transform: translateY(0);
opacity: 1;
transition-delay: 0.6s;
}
.visible .bronze-position {
transform: translateY(0);
opacity: 1;
transition-delay: 0.9s;
}
.medal-icon {
position: absolute;
width: 30px;
height: 30px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
top: -10px;
right: 55px;
z-index: 2;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.gold-medal {
background: #ffd700;
}
.silver-medal {
background: #c0c0c0;
}
.bronze-medal {
background: #cd7f32;
}
.crown {
position: absolute;
top: -30px;
left: 50%;
z-index: 10;
transform: translateX(-53px);
}
.gold-crown:before,
.gold-crown:after {
content: "";
position: absolute;
bottom: 0;
width: 0;
height: 0;
}
.gold-crown {
width: 30px;
height: 20px;
background: #ffd700;
border-radius: 4px 4px 0 0;
}
.gold-crown:before {
left: -12px;
border-left: 18px solid transparent;
border-right: 0px solid transparent;
border-bottom: 30px solid #ffd700;
}
.gold-crown:after {
right: -12px;
border-left: 0px solid transparent;
border-right: 18px solid transparent;
border-bottom: 30px solid #ffd700;
}
.podium {
@@ -51,6 +162,7 @@ h3{
display: flex;
align-items: flex-end;
position: relative;
padding: 20px 0;
}
.tier {
@@ -65,33 +177,48 @@ h3{
color: white;
font-size: 24px;
position: relative;
transform: perspective(1000px) rotateX(5deg);
transition: all 0.3s ease;
}
.gold:hover {
box-shadow: 0 0 40px 20px rgba(255, 215, 0, 0.7); /* 金色光辉效果 */
}
box-shadow: 0 0 40px 20px rgba(255, 215, 0, 0.7);
transform: perspective(1000px) rotateX(0deg) scale(1.05);
}
.gold {
background: linear-gradient(to bottom, #ffd700 0%, #ffcc00 100%);
height: 250px;
box-shadow: 0 8px 20px rgba(255, 215, 0, 0.5);
z-index: 3;
}
.silver:hover {
box-shadow: 0 0 20px 10px rgba(192, 192, 192, 0.7); /* 金色光辉效果 */
box-shadow: 0 0 20px 10px rgba(192, 192, 192, 0.7);
transform: perspective(1000px) rotateX(0deg) scale(1.05);
}
.silver {
background: linear-gradient(to bottom, #c0c0c0 0%, #d3d3d3 100%);
height: 200px;
box-shadow: 0 6px 18px rgba(192, 192, 192, 0.5);
z-index: 2;
}
.bronze:hover {
box-shadow: 0 0 20px 10px rgba(205, 127, 50, 0.7); /* 金色光辉效果 */
box-shadow: 0 0 20px 10px rgba(205, 127, 50, 0.7);
transform: perspective(1000px) rotateX(0deg) scale(1.05);
}
.bronze {
background: linear-gradient(to bottom, #cd7f32 0%, #a0522d 100%);
height: 170px;
box-shadow: 0 4px 16px rgba(205, 127, 50, 0.5);
z-index: 1;
}
.avatar-wrapper {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 10px;
z-index: 10;
position: relative;
}
</style>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,169 @@
<template>
<div class="stock-chart-container" ref="chartContainer"></div>
</template>
<script setup>
import { ref, onMounted, watch } from 'vue';
import * as echarts from 'echarts/core';
import { LineChart } from 'echarts/charts';
import {
TitleComponent,
TooltipComponent,
GridComponent,
LegendComponent,
MarkLineComponent,
MarkPointComponent
} from 'echarts/components';
import { SVGRenderer } from 'echarts/renderers';
// 注册必要的组件
echarts.use([
TitleComponent,
TooltipComponent,
GridComponent,
LegendComponent,
LineChart,
SVGRenderer,
MarkLineComponent,
MarkPointComponent
]);
const props = defineProps({
stockData: {
type: Array,
required: true
}
});
const chartContainer = ref(null);
let myChart = null;
const initChart = () => {
if (!chartContainer.value) return;
myChart = echarts.init(chartContainer.value);
const option = {
backgroundColor: 'transparent',
title: {
text: '股票价格走势',
textStyle: {
color: '#e6edf3'
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985'
}
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,
data: props.stockData.map(item => item.date),
axisLine: {
lineStyle: {
color: '#30363d'
}
},
axisLabel: {
color: '#8b949e'
}
},
yAxis: {
type: 'value',
axisLine: {
lineStyle: {
color: '#30363d'
}
},
splitLine: {
lineStyle: {
color: '#21262d'
}
},
axisLabel: {
color: '#8b949e'
}
},
series: [{
name: '价格',
type: 'line',
stack: '总量',
data: props.stockData.map(item => item.value),
smooth: true,
symbol: 'none',
lineStyle: {
width: 3,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#58a6ff' },
{ offset: 1, color: '#39d353' }
])
},
areaStyle: {
opacity: 0.4,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: 'rgba(88, 166, 255, 0.5)' },
{ offset: 1, color: 'rgba(57, 211, 83, 0.1)' }
])
}
}]
};
myChart.setOption(option);
window.addEventListener('resize', () => {
myChart && myChart.resize();
});
};
// 监听数据变化重新渲染图表
watch(() => props.stockData, () => {
if (myChart) {
myChart.setOption({
xAxis: {
data: props.stockData.map(item => item.date)
},
series: [{
data: props.stockData.map(item => item.value)
}]
});
}
}, { deep: true });
onMounted(() => {
initChart();
});
</script>
<style scoped>
.stock-chart-container {
width: 100%;
height: 100%;
min-height: 300px;
}
:deep(.el-empty) {
padding: 20px 0;
height: auto;
max-height: 150px;
}
:deep(.el-empty__image) {
width: 60px;
height: 60px;
}
:deep(.el-empty__description) {
margin-top: 10px;
}
</style>