Compare commits
458 Commits
abp
...
1eca2cb273
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1eca2cb273 | ||
|
|
28452b4c07 | ||
|
|
340e2016d6 | ||
|
|
5dfaead60e | ||
|
|
c8acb12e4a | ||
|
|
5fbcb8cbd9 | ||
|
|
fd8d4399d3 | ||
|
|
63490484e9 | ||
|
|
6f1efafd86 | ||
|
|
2714a507d9 | ||
|
|
9a9230786b | ||
|
|
4a8b58a65c | ||
|
|
7d81f88658 | ||
|
|
0ce3c0bbdd | ||
|
|
981235e6e9 | ||
|
|
d0ecb232a1 | ||
|
|
c7a52604e7 | ||
|
|
da81b2d8a3 | ||
|
|
7b14fdd8de | ||
|
|
1fc2734eb7 | ||
|
|
f3bef72ebb | ||
|
|
7e6d2e829b | ||
|
|
944626960b | ||
|
|
c073868989 | ||
|
|
d2981100fa | ||
|
|
ce4f7e5711 | ||
|
|
cc812ba2cb | ||
|
|
5ed79c6dd0 | ||
|
|
6e2ca8f1c3 | ||
|
|
a46a552097 | ||
|
|
53e56134d4 | ||
|
|
f90105ebb4 | ||
|
|
67ed1ac1e3 | ||
|
|
69b84f6613 | ||
|
|
433d616b9b | ||
|
|
53aa575ad4 | ||
|
|
b7847c7e7d | ||
|
|
94eb41996e | ||
|
|
381b712b25 | ||
|
|
c319b0b4e4 | ||
|
|
1a32fa9e20 | ||
|
|
909406238c | ||
|
|
54a1d2a66f | ||
|
|
8dcbfcad33 | ||
|
|
f64fd43951 | ||
|
|
bfda33280a | ||
|
|
8d0411f1f4 | ||
|
|
3995d4acab | ||
|
|
6ff5727156 | ||
|
|
f654386dfe | ||
|
|
c03ef82643 | ||
|
|
525545329b | ||
|
|
755cb6f509 | ||
|
|
55469708f0 | ||
|
|
94c52c62fe | ||
|
|
37b4709d76 | ||
|
|
86555af6ce | ||
|
|
ddb00879f4 | ||
|
|
2d0ca08314 | ||
|
|
b78ecf27d5 | ||
|
|
02a5f69958 | ||
|
|
cf5bf746ef | ||
|
|
0a5e40ee25 | ||
|
|
51a266ef58 | ||
|
|
1f0901c90c | ||
|
|
a725c06396 | ||
|
|
54547f0d7c | ||
|
|
afe9c8bcae | ||
|
|
688d93e5c1 | ||
|
|
4c65b2398d | ||
|
|
41435f1aa3 | ||
|
|
20206bbc44 | ||
|
|
f2dc0d1825 | ||
|
|
51b4d1b072 | ||
|
|
9180799e4e | ||
|
|
9788b9182b | ||
|
|
260b9a4795 | ||
|
|
9380e3daa8 | ||
|
|
bb894e14a4 | ||
|
|
b492d82442 | ||
|
|
d7bcad9da7 | ||
|
|
04e11d15e2 | ||
|
|
97e3dc5eed | ||
|
|
695bd56a27 | ||
|
|
7919383be3 | ||
|
|
d6cc3c5d96 | ||
|
|
19f0d05a69 | ||
|
|
3c5e575e9b | ||
|
|
f875617de1 | ||
|
|
9976e8a6e2 | ||
|
|
38e8cbc5ca | ||
|
|
d95c14c903 | ||
|
|
ffb2f2fb4c | ||
|
|
4bd2fc357d | ||
|
|
da23d17af8 | ||
|
|
c1a6046107 | ||
|
|
d21f61646a | ||
|
|
eecdf442fb | ||
|
|
8e8338743d | ||
|
|
1b4c3cbb8d | ||
|
|
b7756e2112 | ||
|
|
cb49059e84 | ||
|
|
690cabfd96 | ||
|
|
771ecd9d81 | ||
|
|
a9b2979a21 | ||
|
|
17337b8d78 | ||
|
|
09fb43ee14 | ||
|
|
477c0e3f2c | ||
|
|
2e4f520dac | ||
|
|
067b25b9af | ||
|
|
36370c215d | ||
|
|
e24731acfe | ||
|
|
927e9df7de | ||
|
|
114b41144e | ||
|
|
5019a36138 | ||
|
|
e15eb6149b | ||
|
|
9d401a9c93 | ||
|
|
eacf86e118 | ||
|
|
c4b631c815 | ||
|
|
fb25e75a3a | ||
|
|
e9099bbe04 | ||
|
|
f02fb91175 | ||
|
|
5beef22269 | ||
|
|
933cbb91d8 | ||
|
|
efd917d184 | ||
|
|
e906208f4a | ||
|
|
cf137f6307 | ||
|
|
e6b991fe86 | ||
|
|
3e75792e43 | ||
|
|
dd3f6325bb | ||
|
|
108ba348f6 | ||
|
|
bcdcec40e0 | ||
|
|
2ce8baea42 | ||
|
|
c6425ca206 | ||
|
|
acb359ec33 | ||
|
|
a1395d9a33 | ||
|
|
609de29e71 | ||
|
|
2efed4f4a5 | ||
|
|
aec90ec9d6 | ||
|
|
1aaff2942d | ||
|
|
cdbfc5383d | ||
|
|
f302555e0c | ||
|
|
86c5890476 | ||
|
|
a13ee395c7 | ||
|
|
9abcd72aca | ||
|
|
4ddea6d468 | ||
|
|
867a2dc861 | ||
|
|
4a72e3fa0d | ||
|
|
8b4371aabb | ||
|
|
799dd08ec0 | ||
|
|
c5c22224cf | ||
|
|
2dae47e85c | ||
|
|
375dd4f797 | ||
|
|
acb2db8397 | ||
|
|
b7a3e76d0b | ||
|
|
48150b712a | ||
|
|
6db9dfc308 | ||
|
|
2d6c1f3c46 | ||
|
|
161e10d2d1 | ||
|
|
a9a2a91183 | ||
|
|
1c9a6f108e | ||
|
|
d6adf9b736 | ||
|
|
959eb3f782 | ||
|
|
7a53e0c90c | ||
|
|
533b87fc5b | ||
|
|
15713cf7fe | ||
|
|
31dc756868 | ||
|
|
52f6b6130f | ||
|
|
16945b3d5b | ||
|
|
bdc664fc44 | ||
|
|
9555ef10e0 | ||
|
|
49e6cb26fc | ||
|
|
3ace29e692 | ||
|
|
aa9dd0129b | ||
|
|
1464271fbd | ||
|
|
754f145559 | ||
|
|
6afd0cb955 | ||
|
|
d32906702a | ||
|
|
9bcdaf6bd8 | ||
|
|
db82a8cf08 | ||
|
|
a9e8b2b01f | ||
|
|
85bd1ce8d6 | ||
|
|
4d09243efd | ||
|
|
5934056fe6 | ||
|
|
2a81062fa3 | ||
|
|
fdc868323f | ||
|
|
593b3a4cdd | ||
|
|
2b12e18e6c | ||
|
|
345ed80ec8 | ||
|
|
29dc1ae250 | ||
|
|
9fdd41b134 | ||
|
|
31ee5e8ffb | ||
|
|
d7922bb71d | ||
|
|
fa3ac91ba4 | ||
|
|
e7c152e955 | ||
|
|
0223b5c104 | ||
|
|
9e41a7c446 | ||
|
|
2ba0ffc1b7 | ||
|
|
7d038e1266 | ||
|
|
b98285f314 | ||
|
|
73438da666 | ||
|
|
85f2e1b579 | ||
|
|
ece89ebad0 | ||
|
|
6e2dd39246 | ||
|
|
a61286e534 | ||
|
|
4f944a5466 | ||
|
|
d29aac088a | ||
|
|
8abd122773 | ||
|
|
08084aa0bc | ||
|
|
e69cd5a73c | ||
|
|
76aa3bdc64 | ||
|
|
93251104af | ||
|
|
3cae477f3e | ||
|
|
25c736dc0a | ||
|
|
96a09d8980 | ||
|
|
72387235a0 | ||
|
|
1b00e505b7 | ||
|
|
1c54e47b9e | ||
|
|
ba07e2c905 | ||
|
|
bde4611a50 | ||
|
|
e7326fea7b | ||
|
|
d13b23ad2e | ||
|
|
8b1830a711 | ||
|
|
b70c530754 | ||
|
|
d90e24f9ed | ||
|
|
1fbd521d1a | ||
|
|
2ae6183e7f | ||
|
|
7905911624 | ||
|
|
c5b6b33d8e | ||
|
|
5d29fd6d3b | ||
|
|
ad8f48f36b | ||
|
|
f9843c13d4 | ||
|
|
6bd561b094 | ||
|
|
d2c6238df1 | ||
|
|
1d108983e8 | ||
|
|
b768bca638 | ||
|
|
28fcd6c9ce | ||
|
|
10559a925c | ||
|
|
942e218a9e | ||
|
|
f6af9edc38 | ||
|
|
e0f6331ec3 | ||
|
|
06f0c6caa7 | ||
|
|
56ec260e3a | ||
|
|
176cf84369 | ||
|
|
6de3b722ed | ||
|
|
2cf6326764 | ||
|
|
ec27ee58b4 | ||
|
|
4e42e2202e | ||
|
|
e60d8eceb7 | ||
|
|
08fb939b38 | ||
|
|
482dd73afd | ||
|
|
f09a9fee75 | ||
|
|
9a31d14b41 | ||
|
|
2fd7f88f04 | ||
|
|
9d4cc802e9 | ||
|
|
ee6b4827fa | ||
|
|
48d8c528f6 | ||
|
|
40c0a5ac64 | ||
|
|
3a60bcc174 | ||
|
|
2b3fad16fd | ||
|
|
f0cf6bf5c8 | ||
|
|
0ba4e3240b | ||
|
|
9332b17fc1 | ||
|
|
4ec4023f40 | ||
|
|
d9971541f2 | ||
|
|
7b0e4fcc73 | ||
|
|
cfde73d13a | ||
|
|
c17c9000a8 | ||
|
|
42d537a68b | ||
|
|
25eebec8f7 | ||
|
|
bbe5b01872 | ||
|
|
6b31536de5 | ||
|
|
2e5db5500f | ||
|
|
7038d31c53 | ||
|
|
3eb27c3d35 | ||
|
|
a9c3a1bcec | ||
|
|
384926e73a | ||
|
|
4335c12659 | ||
|
|
e6e4829164 | ||
|
|
f3c67cf598 | ||
|
|
4681d468ce | ||
|
|
63e7d3d5f5 | ||
|
|
f47d8c8ce3 | ||
|
|
6f69f45ddc | ||
|
|
e73678c788 | ||
|
|
09a2f91cbf | ||
|
|
29da7499a4 | ||
|
|
5b024e9443 | ||
|
|
225932eff1 | ||
|
|
65d5f5ae86 | ||
|
|
3e647ef14d | ||
|
|
7cb3aea2e6 | ||
|
|
7f4b8f1c8a | ||
|
|
0a2710b865 | ||
|
|
2a301c4983 | ||
|
|
faa8131a1b | ||
|
|
71bd885bd0 | ||
|
|
691a1e50f0 | ||
|
|
ef6e9fd16d | ||
|
|
17f9ac6d54 | ||
|
|
3f8e6e48c0 | ||
|
|
bda4fdf69d | ||
|
|
5c85ed13fd | ||
|
|
1986901031 | ||
|
|
e1d3ec21e5 | ||
|
|
f45283dade | ||
|
|
31c44d8df7 | ||
|
|
bf443963c8 | ||
|
|
a0eb234539 | ||
|
|
b6d670c240 | ||
|
|
b5fb2c42c6 | ||
|
|
d72cc529ba | ||
|
|
660bd00cae | ||
|
|
b5489711ec | ||
|
|
76717c4f8a | ||
|
|
3d53d0bcd6 | ||
|
|
c7c9428b68 | ||
|
|
991a970d6a | ||
|
|
cbe93b9f7e | ||
|
|
5d7217b775 | ||
|
|
d6836b8bcf | ||
|
|
c367651c78 | ||
|
|
77123fd971 | ||
|
|
9d73a6837b | ||
|
|
651f0157dc | ||
|
|
90e8dbe449 | ||
|
|
ccba2667bc | ||
|
|
3ce9fc9790 | ||
|
|
2f24dd77bf | ||
|
|
2bc07cb3df | ||
|
|
30678dbbb4 | ||
|
|
c5b0f69b51 | ||
|
|
e593f2cba4 | ||
|
|
10f7499066 | ||
|
|
36b7e495f7 | ||
|
|
94b96e3c19 | ||
|
|
0d1ee18da0 | ||
|
|
cab0b61ee0 | ||
|
|
8e6611d76d | ||
|
|
1ef82e5f93 | ||
|
|
43dc962606 | ||
|
|
020d674ca2 | ||
|
|
bb0e1081cc | ||
|
|
5162f9ce3b | ||
|
|
57fae7fe4b | ||
|
|
17412d7de7 | ||
|
|
d59f40dfba | ||
|
|
5953be63cb | ||
|
|
58a4311947 | ||
|
|
c5a9b9a15f | ||
|
|
716c344780 | ||
|
|
9af8c4897b | ||
|
|
ca72024a68 | ||
|
|
0d2bc585a9 | ||
|
|
4e3edefb35 | ||
|
|
9408242726 | ||
|
|
4710208e81 | ||
|
|
4fc6a1e818 | ||
|
|
c9b79a074b | ||
|
|
2e79eb346f | ||
|
|
3f88bd4158 | ||
|
|
f58e079741 | ||
|
|
6f1eb1f4b9 | ||
|
|
826d529997 | ||
|
|
43e60eab4a | ||
|
|
6c33024790 | ||
|
|
d27e625fde | ||
|
|
23cecb9360 | ||
|
|
7e4c835ced | ||
|
|
aff460f555 | ||
|
|
52961b459e | ||
|
|
0af2f867fc | ||
|
|
85e291e0b8 | ||
|
|
6d8a859b20 | ||
|
|
a70dfb0769 | ||
|
|
c637d412e6 | ||
|
|
e996bc2d7f | ||
|
|
15be047371 | ||
|
|
0a0e0bca10 | ||
|
|
9a8f3bd161 | ||
|
|
7e2c035692 | ||
|
|
44b2ade9bc | ||
|
|
1200d02fbf | ||
|
|
b020f48325 | ||
|
|
917857f1ff | ||
|
|
69d8ff1034 | ||
|
|
9a334101ca | ||
|
|
ee53b3d9c4 | ||
|
|
01a5ad5302 | ||
|
|
f12f0e1f84 | ||
|
|
6aefcdbed8 | ||
|
|
3d22a2ef65 | ||
|
|
a33c6dbf1a | ||
|
|
2b7c779e14 | ||
|
|
0e36f7c0b3 | ||
|
|
228a309545 | ||
|
|
b15ad8eb5e | ||
|
|
a525735b0b | ||
|
|
6a58af8dfb | ||
|
|
0089e63832 | ||
|
|
d4f00eb89f | ||
|
|
d15e6e395b | ||
|
|
39eb4bef07 | ||
|
|
03de576d8c | ||
|
|
216b57a4c7 | ||
|
|
5383d2d40e | ||
|
|
1d7a2013e3 | ||
|
|
24d2908cca | ||
|
|
330845a387 | ||
|
|
bbedd01a72 | ||
|
|
2b07061c18 | ||
|
|
01a3c81359 | ||
|
|
96e275efa6 | ||
|
|
12eb6c73c3 | ||
|
|
4166eddd28 | ||
|
|
6ea1592c19 | ||
|
|
f8799a073c | ||
|
|
0eb83fc930 | ||
|
|
a5dd3946f8 | ||
|
|
2732df24af | ||
|
|
f0ae27a50b | ||
|
|
c5037ea397 | ||
|
|
695aaedfba | ||
|
|
4f71d874bd | ||
|
|
c69729fadd | ||
|
|
64d04996af | ||
|
|
8eea510583 | ||
|
|
04c2b246f6 | ||
|
|
a46eb176d7 | ||
|
|
2bea88f1a3 | ||
|
|
06617de984 | ||
|
|
6459d7c024 | ||
|
|
bd4af8039f | ||
|
|
8aaa22cea3 | ||
|
|
7d902682f8 | ||
|
|
a81be99100 | ||
|
|
b6dfe93d2c | ||
|
|
35aa022984 | ||
|
|
dfe2d4cc37 | ||
|
|
1d16502d32 | ||
|
|
25c88187a3 | ||
|
|
ac04e846fa | ||
|
|
29985e2118 | ||
|
|
3b74dfd49a | ||
|
|
6abcc49ed4 | ||
|
|
f16e1cd7a6 | ||
|
|
4341b8a24b | ||
|
|
a89e11d132 | ||
|
|
bc91a8cff2 | ||
|
|
8040010b98 | ||
|
|
b39f15c798 | ||
|
|
c3cf49c63e | ||
|
|
899bd7e316 | ||
|
|
890727d495 | ||
|
|
8a8e69596a | ||
|
|
58fcc92e4d | ||
|
|
0cd795f57a | ||
|
|
4830be6388 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -265,6 +265,7 @@ src/Acme.BookStore.Blazor.Server.Tiered/Logs/*
|
||||
**/wwwroot/libs/*
|
||||
public
|
||||
dist
|
||||
dist - 副本
|
||||
.vscode
|
||||
/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Development.json
|
||||
/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Production.json
|
||||
@@ -277,3 +278,5 @@ database_backup
|
||||
/Yi.Abp.Net8/src/Yi.Abp.Web/yi-abp-dev.db
|
||||
|
||||
package-lock.json
|
||||
|
||||
.claude
|
||||
|
||||
10
Yi.Abp.Net8/.claude/settings.local.json
Normal file
10
Yi.Abp.Net8/.claude/settings.local.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(dotnet build \"E:\\code\\github\\Yi\\Yi.Abp.Net8\\module\\ai-hub\\Yi.Framework.AiHub.Application\\Yi.Framework.AiHub.Application.csproj\" --no-restore)",
|
||||
"Read(//e/code/github/Yi/Yi.Ai.Vue3/**)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
}
|
||||
}
|
||||
@@ -186,6 +186,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Domain.S
|
||||
EndProject
|
||||
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
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ai-hub", "ai-hub", "{7AD5DBAE-44F9-474B-8F7B-837EDE908934}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AiHub.Application", "module\ai-hub\Yi.Framework.AiHub.Application\Yi.Framework.AiHub.Application.csproj", "{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AiHub.Application.Contracts", "module\ai-hub\Yi.Framework.AiHub.Application.Contracts\Yi.Framework.AiHub.Application.Contracts.csproj", "{123D1C81-D667-4060-8E85-FFE7FB4584AD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AiHub.Domain", "module\ai-hub\Yi.Framework.AiHub.Domain\Yi.Framework.AiHub.Domain.csproj", "{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AiHub.Domain.Shared", "module\ai-hub\Yi.Framework.AiHub.Domain.Shared\Yi.Framework.AiHub.Domain.Shared.csproj", "{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AiHub.SqlSugarCore", "module\ai-hub\Yi.Framework.AiHub.SqlSugarCore\Yi.Framework.AiHub.SqlSugarCore.csproj", "{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -468,6 +480,26 @@ Global
|
||||
{5F49318F-E6C7-4194-BAE0-83D4FB8D1983}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5F49318F-E6C7-4194-BAE0-83D4FB8D1983}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5F49318F-E6C7-4194-BAE0-83D4FB8D1983}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{123D1C81-D667-4060-8E85-FFE7FB4584AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{123D1C81-D667-4060-8E85-FFE7FB4584AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{123D1C81-D667-4060-8E85-FFE7FB4584AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{123D1C81-D667-4060-8E85-FFE7FB4584AD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -551,6 +583,12 @@ Global
|
||||
{162821E4-8FE0-4A68-B3C0-49BD6596446F} = {DB46873F-981A-43D8-91B0-D464CCB65943}
|
||||
{10273544-715D-4BB3-893C-6F010D947BDD} = {DB46873F-981A-43D8-91B0-D464CCB65943}
|
||||
{5F49318F-E6C7-4194-BAE0-83D4FB8D1983} = {DB46873F-981A-43D8-91B0-D464CCB65943}
|
||||
{7AD5DBAE-44F9-474B-8F7B-837EDE908934} = {2317227D-7796-4E7B-BEDB-7CD1CAE7B853}
|
||||
{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895} = {7AD5DBAE-44F9-474B-8F7B-837EDE908934}
|
||||
{123D1C81-D667-4060-8E85-FFE7FB4584AD} = {7AD5DBAE-44F9-474B-8F7B-837EDE908934}
|
||||
{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D} = {7AD5DBAE-44F9-474B-8F7B-837EDE908934}
|
||||
{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48} = {7AD5DBAE-44F9-474B-8F7B-837EDE908934}
|
||||
{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1} = {7AD5DBAE-44F9-474B-8F7B-837EDE908934}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {23D6FBC9-C970-4641-BC1E-2AEA59F51C18}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Yi.Framework.Core.Authentication;
|
||||
|
||||
namespace Yi.Framework.AspNetCore.Microsoft.AspNetCore.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// 可刷新的鉴权提供者
|
||||
/// </summary>
|
||||
public class RefreshAuthenticationHandlerProvider : IRefreshAuthenticationHandlerProvider
|
||||
{
|
||||
private Dictionary<string, IAuthenticationHandler> _handlerMap =
|
||||
new Dictionary<string, IAuthenticationHandler>((IEqualityComparer<string>)StringComparer.Ordinal);
|
||||
|
||||
/// <summary>Constructor.</summary>
|
||||
/// <param name="schemes">The <see cref="T:Microsoft.AspNetCore.Authentication.IAuthenticationHandlerProvider" />.</param>
|
||||
public RefreshAuthenticationHandlerProvider(IAuthenticationSchemeProvider schemes)
|
||||
{
|
||||
this.Schemes = schemes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="T:Microsoft.AspNetCore.Authentication.IAuthenticationHandlerProvider" />.
|
||||
/// </summary>
|
||||
public IAuthenticationSchemeProvider Schemes { get; }
|
||||
|
||||
/// <summary>Returns the handler instance that will be used.</summary>
|
||||
/// <param name="context">The context.</param>
|
||||
/// <param name="authenticationScheme">The name of the authentication scheme being handled.</param>
|
||||
/// <returns>The handler instance.</returns>
|
||||
public async Task<IAuthenticationHandler?> GetHandlerAsync(
|
||||
HttpContext context,
|
||||
string authenticationScheme)
|
||||
{
|
||||
IAuthenticationHandler handlerAsync;
|
||||
if (this._handlerMap.TryGetValue(authenticationScheme, out handlerAsync))
|
||||
return handlerAsync;
|
||||
AuthenticationScheme schemeAsync = await this.Schemes.GetSchemeAsync(authenticationScheme);
|
||||
if (schemeAsync == null)
|
||||
return (IAuthenticationHandler)null;
|
||||
|
||||
if ((context.RequestServices.GetService(schemeAsync.HandlerType) ??
|
||||
ActivatorUtilities.CreateInstance(context.RequestServices, schemeAsync.HandlerType)) is
|
||||
IAuthenticationHandler handler)
|
||||
{
|
||||
handlerAsync = handler;
|
||||
await handler.InitializeAsync(schemeAsync, context);
|
||||
this._handlerMap[authenticationScheme] = handler;
|
||||
}
|
||||
|
||||
return handlerAsync;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 刷新鉴权
|
||||
/// </summary>
|
||||
public void RefreshAuthentication()
|
||||
{
|
||||
_handlerMap = new Dictionary<string, IAuthenticationHandler>((IEqualityComparer<string>)StringComparer.Ordinal);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,12 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
using Volo.Abp.AspNetCore.Mvc.Conventions;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Options;
|
||||
|
||||
namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
using Volo.Abp.AspNetCore.WebClientInfo;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Modularity;
|
||||
using Yi.Framework.AspNetCore.Mvc;
|
||||
using Yi.Framework.AspNetCore.Microsoft.AspNetCore.Authentication;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Core.Authentication;
|
||||
|
||||
namespace Yi.Framework.AspNetCore
|
||||
{
|
||||
@@ -37,6 +26,12 @@ namespace Yi.Framework.AspNetCore
|
||||
typeof(IWebClientInfoProvider),
|
||||
typeof(RealIpHttpContextWebClientInfoProvider),
|
||||
ServiceLifetime.Transient));
|
||||
|
||||
// 替换默认的AuthenticationHandlerProvider为支持刷新鉴权
|
||||
services.Replace(new ServiceDescriptor(
|
||||
typeof(IAuthenticationHandlerProvider),
|
||||
typeof(RefreshAuthenticationHandlerProvider),
|
||||
ServiceLifetime.Scoped));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Hangfire;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Volo.Abp.BackgroundJobs.Hangfire;
|
||||
using Volo.Abp.BackgroundWorkers;
|
||||
using Volo.Abp.BackgroundWorkers.Hangfire;
|
||||
@@ -32,6 +33,12 @@ public sealed class YiFrameworkBackgroundWorkersHangfireModule : AbpModule
|
||||
/// <param name="context">应用程序初始化上下文</param>
|
||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
if (!context.ServiceProvider.GetRequiredService<IOptions<AbpBackgroundWorkerOptions>>().Value.IsEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 获取后台任务管理器和所有 Hangfire 后台任务
|
||||
var backgroundWorkerManager = context.ServiceProvider.GetRequiredService<IBackgroundWorkerManager>();
|
||||
var workers = context.ServiceProvider.GetServices<IHangfireBackgroundWorker>();
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Yi.Framework.Core.Authentication;
|
||||
|
||||
public static class AuthenticationExtensions
|
||||
{
|
||||
public static void RefreshAuthentication(this HttpContext context)
|
||||
{
|
||||
var currentAuthenticationHandler =
|
||||
context.RequestServices.GetRequiredService<IAuthenticationHandlerProvider>();
|
||||
if (currentAuthenticationHandler is IRefreshAuthenticationHandlerProvider refreshAuthenticationHandler)
|
||||
{
|
||||
refreshAuthenticationHandler.RefreshAuthentication();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
|
||||
namespace Yi.Framework.Core.Authentication;
|
||||
|
||||
public interface IRefreshAuthenticationHandlerProvider: IAuthenticationHandlerProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 刷新鉴权
|
||||
/// </summary>
|
||||
void RefreshAuthentication();
|
||||
}
|
||||
@@ -199,11 +199,11 @@ namespace Yi.Framework.Ddd.Application
|
||||
/// <summary>
|
||||
/// 批量删除实体
|
||||
/// </summary>
|
||||
/// <param name="ids">实体ID集合</param>
|
||||
/// <param name="id">实体ID集合</param>
|
||||
[RemoteService(isEnabled: true)]
|
||||
public virtual async Task DeleteAsync(IEnumerable<TKey> ids)
|
||||
public virtual async Task DeleteAsync(IEnumerable<TKey> id)
|
||||
{
|
||||
await Repository.DeleteManyAsync(ids);
|
||||
await Repository.DeleteManyAsync(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.Core\Yi.Framework.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SemanticKernel" Version="1.57.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,15 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.SemanticKernel;
|
||||
using Yi.Framework.Core.Options;
|
||||
|
||||
namespace Yi.Framework.SemanticKernel;
|
||||
|
||||
public class YiFrameworkSemanticKernelModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
var configuration = context.Services.GetConfiguration();
|
||||
var services = context.Services;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Linq.Expressions;
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Nito.AsyncEx;
|
||||
using SqlSugar;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using Yi.Framework.Rbac.Domain.Shared.Dtos;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
|
||||
public class AiUserRoleMenuDto:UserRoleMenuDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否绑定服务号
|
||||
/// </summary>
|
||||
public bool IsBindFuwuhao { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为VIP用户
|
||||
/// </summary>
|
||||
public bool IsVip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// VIP到期时间
|
||||
/// </summary>
|
||||
public DateTime? VipExpireTime { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Announcement;
|
||||
|
||||
/// <summary>
|
||||
/// 公告缓存 DTO
|
||||
/// </summary>
|
||||
public class AnnouncementCacheDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 版本号
|
||||
/// </summary>
|
||||
public string Version { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 公告日志列表
|
||||
/// </summary>
|
||||
public List<AnnouncementLogDto> Logs { get; set; } = new List<AnnouncementLogDto>();
|
||||
|
||||
/// <summary>
|
||||
/// 跳转链接
|
||||
/// </summary>
|
||||
public string? Url { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Announcement;
|
||||
|
||||
/// <summary>
|
||||
/// 公告日志 DTO
|
||||
/// </summary>
|
||||
public class AnnouncementLogDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 内容列表
|
||||
/// </summary>
|
||||
public List<string> Content { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 图片url
|
||||
/// </summary>
|
||||
public string? ImageUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间(系统公告时间、活动开始时间)
|
||||
/// </summary>
|
||||
public DateTime StartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 活动结束时间
|
||||
/// </summary>
|
||||
public DateTime? EndTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 公告类型(系统、活动)
|
||||
/// </summary>
|
||||
public AnnouncementTypeEnum Type{ get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 跳转链接
|
||||
/// </summary>
|
||||
public string? Url { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Announcement;
|
||||
|
||||
/// <summary>
|
||||
/// 公告输出 DTO
|
||||
/// </summary>
|
||||
public class AnnouncementOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 版本号
|
||||
/// </summary>
|
||||
public string Version { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 公告日志列表
|
||||
/// </summary>
|
||||
public List<AnnouncementLogDto> Logs { get; set; } = new List<AnnouncementLogDto>();
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌任务状态输出
|
||||
/// </summary>
|
||||
public class CardFlipStatusOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 本周总翻牌次数
|
||||
/// </summary>
|
||||
public int TotalFlips { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 剩余免费次数
|
||||
/// </summary>
|
||||
public int RemainingFreeFlips { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 剩余赠送次数
|
||||
/// </summary>
|
||||
public int RemainingBonusFlips { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 剩余邀请解锁次数
|
||||
/// </summary>
|
||||
public int RemainingInviteFlips { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以翻牌
|
||||
/// </summary>
|
||||
public bool CanFlip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户的邀请码
|
||||
/// </summary>
|
||||
public string? MyInviteCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 本周邀请人数
|
||||
/// </summary>
|
||||
public int InvitedCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌记录
|
||||
/// </summary>
|
||||
public List<CardFlipRecord> FlipRecords { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 下次可翻牌提示
|
||||
/// </summary>
|
||||
public string? NextFlipTip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户是否已经填写过邀请码
|
||||
/// </summary>
|
||||
public bool IsFilledInviteCode { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌记录
|
||||
/// </summary>
|
||||
public class CardFlipRecord
|
||||
{
|
||||
/// <summary>
|
||||
/// 翻牌序号(1-10)
|
||||
/// </summary>
|
||||
public int FlipNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已翻
|
||||
/// </summary>
|
||||
public bool IsFlipped { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否中奖
|
||||
/// </summary>
|
||||
public bool IsWin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 奖励金额(token数)
|
||||
/// </summary>
|
||||
public long? RewardAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌类型描述
|
||||
/// </summary>
|
||||
public string? FlipTypeDesc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 在翻牌顺序中的位置(1-10,表示第几个翻)
|
||||
/// </summary>
|
||||
public int FlipOrderIndex { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌输入
|
||||
/// </summary>
|
||||
public class FlipCardInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 翻牌序号(1-10)
|
||||
/// </summary>
|
||||
public int FlipNumber { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌输出
|
||||
/// </summary>
|
||||
public class FlipCardOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 翻牌序号(1-10)
|
||||
/// </summary>
|
||||
public int FlipNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否中奖
|
||||
/// </summary>
|
||||
public bool IsWin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 奖励金额(token数)
|
||||
/// </summary>
|
||||
public long? RewardAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 奖励描述
|
||||
/// </summary>
|
||||
public string? RewardDesc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 剩余可翻次数
|
||||
/// </summary>
|
||||
public int RemainingFlips { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||
|
||||
/// <summary>
|
||||
/// 邀请码信息输出
|
||||
/// </summary>
|
||||
public class InviteCodeOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 我的邀请码
|
||||
/// </summary>
|
||||
public string? MyInviteCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 本周邀请人数
|
||||
/// </summary>
|
||||
public int InvitedCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已被邀请
|
||||
/// </summary>
|
||||
public bool IsInvited { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 邀请历史记录
|
||||
/// </summary>
|
||||
public List<InvitationHistoryItem> InvitationHistory { get; set; } = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 邀请历史记录项
|
||||
/// </summary>
|
||||
public class InvitationHistoryItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 被邀请人昵称(脱敏)
|
||||
/// </summary>
|
||||
public string InvitedUserName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 邀请时间
|
||||
/// </summary>
|
||||
public DateTime InvitationTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 本周所在
|
||||
/// </summary>
|
||||
public string WeekDescription { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||
|
||||
/// <summary>
|
||||
/// 使用邀请码输入
|
||||
/// </summary>
|
||||
public class UseInviteCodeInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 邀请码
|
||||
/// </summary>
|
||||
public string InviteCode { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.DailyTask;
|
||||
|
||||
/// <summary>
|
||||
/// 领取任务奖励输入
|
||||
/// </summary>
|
||||
public class ClaimTaskRewardInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务等级(1=1000w任务,2=3000w任务)
|
||||
/// </summary>
|
||||
public int TaskLevel { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.DailyTask;
|
||||
|
||||
/// <summary>
|
||||
/// 每日任务状态输出
|
||||
/// </summary>
|
||||
public class DailyTaskStatusOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 今日消耗的尊享包Token数
|
||||
/// </summary>
|
||||
public long TodayConsumedTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务列表
|
||||
/// </summary>
|
||||
public List<DailyTaskItem> Tasks { get; set; } = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每日任务项
|
||||
/// </summary>
|
||||
public class DailyTaskItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务等级(1=1000w任务,2=3000w任务)
|
||||
/// </summary>
|
||||
public int Level { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务名称
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 任务描述
|
||||
/// </summary>
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 任务要求的Token消耗量
|
||||
/// </summary>
|
||||
public long RequiredTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 奖励的Token数量
|
||||
/// </summary>
|
||||
public long RewardTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务状态:0=未完成,1=可领取,2=已领取
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务进度百分比(0-100)
|
||||
/// </summary>
|
||||
public decimal Progress { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.FileMaster;
|
||||
|
||||
public class VerifyNextInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件数
|
||||
/// </summary>
|
||||
public int FileCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件夹数
|
||||
/// </summary>
|
||||
public int DirectoryCount { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Fuwuhao;
|
||||
|
||||
public class QrCodeOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// Qrcode url
|
||||
/// </summary>
|
||||
public string QrCodeUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 场景值
|
||||
/// </summary>
|
||||
public string Scene { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums.Fuwuhao;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Fuwuhao;
|
||||
|
||||
public class QrCodeResultOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回状态
|
||||
/// </summary>
|
||||
public SceneResultEnum SceneResult { get; set; } = SceneResultEnum.Wait;
|
||||
|
||||
/// <summary>
|
||||
/// 如果是已登录,返回token
|
||||
/// </summary>
|
||||
public string? Token { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 刷新token
|
||||
/// </summary>
|
||||
public string? RefreshToken { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums.Fuwuhao;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Fuwuhao;
|
||||
|
||||
public class SceneCacheDto
|
||||
{
|
||||
public SceneResultEnum SceneResult { get; set; } = SceneResultEnum.Wait;
|
||||
|
||||
public SceneTypeEnum SceneType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 如果是绑定类型,需要用户id
|
||||
/// </summary>
|
||||
public Guid? UserId { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using Volo.Abp.Application.Dtos;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
|
||||
public class MessageDto : FullAuditedEntityDto<Guid>
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public Guid SessionId { get; set; }
|
||||
public string Content { get; set; }
|
||||
public string Role { get; set; }
|
||||
public string ModelId { get; set; }
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Yi.Framework.Ddd.Application.Contracts;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
|
||||
public class MessageGetListInput:PagedAllResultRequestDto
|
||||
{
|
||||
[Required]
|
||||
public Guid SessionId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Model;
|
||||
|
||||
/// <summary>
|
||||
/// API类型选项
|
||||
/// </summary>
|
||||
public class ModelApiTypeOption
|
||||
{
|
||||
/// <summary>
|
||||
/// 显示名称
|
||||
/// </summary>
|
||||
public string Label { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 枚举值
|
||||
/// </summary>
|
||||
public int Value { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Extensions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Model;
|
||||
|
||||
/// <summary>
|
||||
/// 模型库展示数据
|
||||
/// </summary>
|
||||
public class ModelLibraryDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 模型ID
|
||||
/// </summary>
|
||||
public string ModelId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型描述
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型类型
|
||||
/// </summary>
|
||||
public ModelTypeEnum ModelType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型类型名称
|
||||
/// </summary>
|
||||
public string ModelTypeName => ModelType.GetDescription();
|
||||
|
||||
/// <summary>
|
||||
/// 模型支持的API类型
|
||||
/// </summary>
|
||||
public List<ModelApiTypeOutput> ModelApiTypes { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 模型显示倍率
|
||||
/// </summary>
|
||||
public decimal MultiplierShow { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 供应商分组名称
|
||||
/// </summary>
|
||||
public string? ProviderName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型图标URL
|
||||
/// </summary>
|
||||
public string? IconUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为尊享模型(PremiumChat类型)
|
||||
/// </summary>
|
||||
public bool IsPremium { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int OrderNum { get; set; }
|
||||
}
|
||||
|
||||
public class ModelApiTypeOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 模型类型
|
||||
/// </summary>
|
||||
public ModelApiTypeEnum ModelApiType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型类型名称
|
||||
/// </summary>
|
||||
public string ModelApiTypeName => ModelApiType.GetDescription();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
using Yi.Framework.Ddd.Application.Contracts;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Model;
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型库列表查询参数
|
||||
/// </summary>
|
||||
public class ModelLibraryGetListInput : PagedAllResultRequestDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 搜索关键词(搜索模型名称、模型ID)
|
||||
/// </summary>
|
||||
public string? SearchKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 供应商名称筛选
|
||||
/// </summary>
|
||||
public List<string>? ProviderNames { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型类型筛选
|
||||
/// </summary>
|
||||
public List<ModelTypeEnum>? ModelTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// API类型筛选
|
||||
/// </summary>
|
||||
public List<ModelApiTypeEnum>? ModelApiTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否只显示尊享模型
|
||||
/// </summary>
|
||||
public bool? IsPremiumOnly { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Model;
|
||||
|
||||
/// <summary>
|
||||
/// 模型类型选项
|
||||
/// </summary>
|
||||
public class ModelTypeOption
|
||||
{
|
||||
/// <summary>
|
||||
/// 显示名称
|
||||
/// </summary>
|
||||
public string Label { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 枚举值
|
||||
/// </summary>
|
||||
public int Value { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
|
||||
public class ModelGetListOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 模型ID
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型分类
|
||||
/// </summary>
|
||||
public string Category { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 模型id
|
||||
/// </summary>
|
||||
public string ModelId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型名称
|
||||
/// </summary>
|
||||
public string ModelName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型描述
|
||||
/// </summary>
|
||||
public string? ModelDescribe { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型价格
|
||||
/// </summary>
|
||||
public double ModelPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型类型
|
||||
/// </summary>
|
||||
public string ModelType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型展示状态
|
||||
/// </summary>
|
||||
public string ModelShow { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 系统提示
|
||||
/// </summary>
|
||||
public string SystemPrompt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// API 主机地址
|
||||
/// </summary>
|
||||
public string ApiHost { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// API 密钥
|
||||
/// </summary>
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注信息
|
||||
/// </summary>
|
||||
public string? Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为尊享包
|
||||
/// </summary>
|
||||
public bool IsPremiumPackage { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
|
||||
|
||||
/// <summary>
|
||||
/// 创建订单输入DTO
|
||||
/// </summary>
|
||||
public class CreateOrderInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品类型
|
||||
/// </summary>
|
||||
[Required]
|
||||
public GoodsTypeEnum GoodsType { get; set; }
|
||||
|
||||
public string? ReturnUrl{ get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
|
||||
|
||||
/// <summary>
|
||||
/// 创建订单输出DTO
|
||||
/// </summary>
|
||||
public class CreateOrderOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 订单ID
|
||||
/// </summary>
|
||||
public Guid OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商家订单号
|
||||
/// </summary>
|
||||
public string OutTradeNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付页面HTML内容
|
||||
/// </summary>
|
||||
public object PaymentPageHtml { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品列表输入DTO
|
||||
/// </summary>
|
||||
public class GetGoodsListInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品类别(可选)
|
||||
/// 如果不传,则返回所有商品
|
||||
/// 如果传了,则只返回指定类别的商品(VIP服务或尊享包)
|
||||
/// </summary>
|
||||
public GoodsCategoryType? GoodsCategoryType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
|
||||
|
||||
/// <summary>
|
||||
/// 商品列表输出DTO
|
||||
/// </summary>
|
||||
public class GoodsListOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品名称
|
||||
/// </summary>
|
||||
public string GoodsName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品原价
|
||||
/// </summary>
|
||||
public decimal OriginalPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品参考价格
|
||||
/// </summary>
|
||||
public decimal ReferencePrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品实际价格(折扣后的价格)
|
||||
/// </summary>
|
||||
public decimal GoodsPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 折扣金额(仅尊享包)
|
||||
/// </summary>
|
||||
public decimal? DiscountAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品类别
|
||||
/// </summary>
|
||||
public string GoodsCategory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 折扣说明(仅尊享包)
|
||||
/// </summary>
|
||||
public string? DiscountDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品类型
|
||||
/// </summary>
|
||||
public GoodsTypeEnum GoodsType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
|
||||
|
||||
/// <summary>
|
||||
/// 查询订单状态输入DTO
|
||||
/// </summary>
|
||||
public class QueryOrderStatusInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 商家订单号
|
||||
/// </summary>
|
||||
public string OutTradeNo { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
|
||||
|
||||
/// <summary>
|
||||
/// 查询订单状态输出DTO
|
||||
/// </summary>
|
||||
public class QueryOrderStatusOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 订单ID
|
||||
/// </summary>
|
||||
public Guid OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商家订单号
|
||||
/// </summary>
|
||||
public string OutTradeNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付宝交易号
|
||||
/// </summary>
|
||||
public string? TradeNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 交易状态
|
||||
/// </summary>
|
||||
public TradeStatusEnum TradeStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 交易状态描述
|
||||
/// </summary>
|
||||
public string TradeStatusDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单金额
|
||||
/// </summary>
|
||||
public decimal TotalAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品名称
|
||||
/// </summary>
|
||||
public string GoodsName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品类型
|
||||
/// </summary>
|
||||
public GoodsTypeEnum GoodsType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime CreationTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后修改时间
|
||||
/// </summary>
|
||||
public DateTime? LastModificationTime { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Recharge;
|
||||
|
||||
public class RechargeCreateInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 充值金额
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Range(0.01, double.MaxValue, ErrorMessage = "充值金额必须大于0")]
|
||||
public decimal RechargeAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 充值内容
|
||||
/// </summary>
|
||||
[Required]
|
||||
[StringLength(500, ErrorMessage = "充值内容不能超过500个字符")]
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// VIP月数(为空或0表示永久VIP)
|
||||
/// </summary>
|
||||
[Range(0, int.MaxValue, ErrorMessage = "月数必须大于等于0")]
|
||||
public int? Months { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
[StringLength(1000, ErrorMessage = "备注不能超过1000个字符")]
|
||||
public string? Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 联系方式
|
||||
/// </summary>
|
||||
[StringLength(200, ErrorMessage = "联系方式不能超过200个字符")]
|
||||
public string? ContactInfo { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Recharge;
|
||||
|
||||
public class RechargeGetListOutput
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 充值金额
|
||||
/// </summary>
|
||||
public decimal RechargeAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户
|
||||
/// </summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 充值内容
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 到期时间
|
||||
/// </summary>
|
||||
public DateTime? ExpireDateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 联系方式
|
||||
/// </summary>
|
||||
public string? ContactInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime CreationTime { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
|
||||
public class SendMessageInput
|
||||
{
|
||||
public List<Message> Messages { get; set; }
|
||||
public string Model { get; set; }
|
||||
|
||||
public Guid? SessionId{ get; set; }
|
||||
}
|
||||
|
||||
public class Message
|
||||
{
|
||||
public string Role { get; set; }
|
||||
public string Content { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
|
||||
public class SendMessageStreamOutputDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一标识符
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 对象类型
|
||||
/// </summary>
|
||||
public string Object { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间,Unix时间戳格式
|
||||
/// </summary>
|
||||
public long Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型名称
|
||||
/// </summary>
|
||||
public string Model { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 选择项列表
|
||||
/// </summary>
|
||||
public List<Choice> Choices { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 系统指纹(可能为空)
|
||||
/// </summary>
|
||||
public string SystemFingerprint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 使用情况信息
|
||||
/// </summary>
|
||||
public Usage Usage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择项类,表示模型返回的一个选择
|
||||
/// </summary>
|
||||
public class Choice
|
||||
{
|
||||
/// <summary>
|
||||
/// 选择索引
|
||||
/// </summary>
|
||||
public int Index { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 变化内容,包括内容字符串和角色
|
||||
/// </summary>
|
||||
public Delta Delta { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束原因,可能为空
|
||||
/// </summary>
|
||||
public string? FinishReason { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 内容过滤结果
|
||||
/// </summary>
|
||||
public ContentFilterResults ContentFilterResults { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 变化内容
|
||||
/// </summary>
|
||||
public class Delta
|
||||
{
|
||||
/// <summary>
|
||||
/// 内容文本
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 角色,例如"assistant"
|
||||
/// </summary>
|
||||
public string Role { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内容过滤结果
|
||||
/// </summary>
|
||||
public class ContentFilterResults
|
||||
{
|
||||
public FilterStatus Hate { get; set; }
|
||||
public FilterStatus SelfHarm { get; set; }
|
||||
public FilterStatus Sexual { get; set; }
|
||||
public FilterStatus Violence { get; set; }
|
||||
public FilterStatus Jailbreak { get; set; }
|
||||
public FilterStatus Profanity { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 过滤状态,表示是否经过过滤以及检测是否命中
|
||||
/// </summary>
|
||||
public class FilterStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否被过滤
|
||||
/// </summary>
|
||||
public bool Filtered { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否检测到该类型(例如 Jailbreak 中存在此字段)
|
||||
/// </summary>
|
||||
public bool? Detected { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用情况,记录 token 数量等信息
|
||||
/// </summary>
|
||||
public class Usage
|
||||
{
|
||||
/// <summary>
|
||||
/// 提示词数量
|
||||
/// </summary>
|
||||
public int PromptTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 补全词数量
|
||||
/// </summary>
|
||||
public int CompletionTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总的 Token 数量
|
||||
/// </summary>
|
||||
public int TotalTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 提示词详细信息
|
||||
/// </summary>
|
||||
public PromptTokensDetails PromptTokensDetails { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 补全文字详细信息
|
||||
/// </summary>
|
||||
public CompletionTokensDetails CompletionTokensDetails { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提示词相关 token 详细信息
|
||||
/// </summary>
|
||||
public class PromptTokensDetails
|
||||
{
|
||||
public int AudioTokens { get; set; }
|
||||
public int CachedTokens { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 补全相关 token 详细信息
|
||||
/// </summary>
|
||||
public class CompletionTokensDetails
|
||||
{
|
||||
public int AudioTokens { get; set; }
|
||||
|
||||
public int ReasoningTokens { get; set; }
|
||||
|
||||
public int AcceptedPredictionTokens { get; set; }
|
||||
|
||||
public int RejectedPredictionTokens { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
|
||||
public class SessionCreateAndUpdateInput
|
||||
{
|
||||
public string SessionTitle { get; set; }
|
||||
public string SessionContent { get; set; }
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using Volo.Abp.Application.Dtos;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
|
||||
public class SessionDto : FullAuditedEntityDto<Guid>
|
||||
{
|
||||
public string SessionTitle { get; set; }
|
||||
public string SessionContent { get; set; }
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Yi.Framework.Ddd.Application.Contracts;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
|
||||
public class SessionGetListInput:PagedAllResultRequestDto
|
||||
{
|
||||
public string? SessionTitle { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Token;
|
||||
|
||||
/// <summary>
|
||||
/// 创建Token输入
|
||||
/// </summary>
|
||||
public class TokenCreateInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称(同一用户不能重复)
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "名称不能为空")]
|
||||
[StringLength(100, ErrorMessage = "名称长度不能超过100个字符")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 过期时间(空为永不过期)
|
||||
/// </summary>
|
||||
public DateTime? ExpireTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 尊享包额度限制(空为不限制)
|
||||
/// </summary>
|
||||
public long? PremiumQuotaLimit { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Token;
|
||||
|
||||
/// <summary>
|
||||
/// Token列表输出
|
||||
/// </summary>
|
||||
public class TokenGetListOutputDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Token Id
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Token密钥
|
||||
/// </summary>
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 过期时间(空为永不过期)
|
||||
/// </summary>
|
||||
public DateTime? ExpireTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 尊享包额度限制(空为不限制)
|
||||
/// </summary>
|
||||
public long? PremiumQuotaLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 尊享包已使用额度
|
||||
/// </summary>
|
||||
public long PremiumUsedQuota { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否禁用
|
||||
/// </summary>
|
||||
public bool IsDisabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime CreationTime { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Token;
|
||||
|
||||
public class TokenOutput
|
||||
{
|
||||
public string? ApiKey { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Token;
|
||||
|
||||
public class TokenSelectListOutputDto
|
||||
{
|
||||
public Guid TokenId { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool IsDisabled { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Token;
|
||||
|
||||
/// <summary>
|
||||
/// 编辑Token输入
|
||||
/// </summary>
|
||||
public class TokenUpdateInput
|
||||
{
|
||||
/// <summary>
|
||||
/// Token Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "Id不能为空")]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称(同一用户不能重复)
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "名称不能为空")]
|
||||
[StringLength(100, ErrorMessage = "名称长度不能超过100个字符")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 过期时间(空为永不过期)
|
||||
/// </summary>
|
||||
public DateTime? ExpireTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 尊享包额度限制(空为不限制)
|
||||
/// </summary>
|
||||
public long? PremiumQuotaLimit { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.UsageStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// 每日Token使用量统计DTO
|
||||
/// </summary>
|
||||
public class DailyTokenUsageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 日期
|
||||
/// </summary>
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Token消耗量
|
||||
/// </summary>
|
||||
public long Tokens { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.UsageStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// 模型Token使用量统计DTO
|
||||
/// </summary>
|
||||
public class ModelTokenUsageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 模型ID
|
||||
/// </summary>
|
||||
public string Model { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总消耗量
|
||||
/// </summary>
|
||||
public long Tokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 占比(百分比)
|
||||
/// </summary>
|
||||
public decimal Percentage { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.UsageStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// 尊享服务Token用量统计DTO
|
||||
/// </summary>
|
||||
public class PremiumTokenUsageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 总Token数
|
||||
/// </summary>
|
||||
public long PremiumTotalTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 已使用Token数
|
||||
/// </summary>
|
||||
public long PremiumUsedTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 剩余Token数
|
||||
/// </summary>
|
||||
public long PremiumRemainingTokens { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Yi.Framework.Ddd.Application.Contracts;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.UsageStatistics;
|
||||
|
||||
public class PremiumTokenUsageGetListInput : PagedAllResultRequestDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否免费
|
||||
/// </summary>
|
||||
public bool? IsFree { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Yi.Framework.Ddd.Application.Contracts;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.UsageStatistics;
|
||||
|
||||
public class PremiumTokenUsageGetListOutput : CreationAuditedEntityDto
|
||||
{
|
||||
/// <summary>
|
||||
/// id
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 包名称
|
||||
/// </summary>
|
||||
public string PackageName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总用量(总token数)
|
||||
/// </summary>
|
||||
public long TotalTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 剩余用量(剩余token数)
|
||||
/// </summary>
|
||||
public long RemainingTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 已使用token数
|
||||
/// </summary>
|
||||
public long UsedTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 到期时间
|
||||
/// </summary>
|
||||
public DateTime? ExpireDateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否激活
|
||||
/// </summary>
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 购买金额
|
||||
/// </summary>
|
||||
public decimal PurchaseAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.UsageStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// 尊享包不同Token用量占比DTO(饼图)
|
||||
/// </summary>
|
||||
public class TokenPremiumUsageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Token Id
|
||||
/// </summary>
|
||||
public Guid TokenId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Token名称
|
||||
/// </summary>
|
||||
public string TokenName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Token消耗量
|
||||
/// </summary>
|
||||
public long Tokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 占比(百分比)
|
||||
/// </summary>
|
||||
public decimal Percentage { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.UsageStatistics;
|
||||
|
||||
public class UsageStatisticsGetInput
|
||||
{
|
||||
/// <summary>
|
||||
/// tokenId
|
||||
/// </summary>
|
||||
public Guid? TokenId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Announcement;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
|
||||
/// <summary>
|
||||
/// 公告服务接口
|
||||
/// </summary>
|
||||
public interface IAnnouncementService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取公告信息
|
||||
/// </summary>
|
||||
/// <returns>公告信息</returns>
|
||||
Task<List<AnnouncementLogDto>> GetAsync();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌服务接口
|
||||
/// </summary>
|
||||
public interface ICardFlipService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取本周翻牌任务状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<CardFlipStatusOutput> GetWeeklyTaskStatusAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌
|
||||
/// </summary>
|
||||
/// <param name="input">翻牌输入</param>
|
||||
/// <returns></returns>
|
||||
Task<FlipCardOutput> FlipCardAsync(FlipCardInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 使用邀请码解锁翻牌次数
|
||||
/// </summary>
|
||||
/// <param name="input">邀请码输入</param>
|
||||
/// <returns></returns>
|
||||
Task UseInviteCodeAsync(UseInviteCodeInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 获取我的邀请码信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<InviteCodeOutput> GetMyInviteCodeAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 生成我的邀请码(如果没有)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<string> GenerateMyInviteCodeAsync();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Model;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
|
||||
/// <summary>
|
||||
/// 模型服务接口
|
||||
/// </summary>
|
||||
public interface IModelService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取模型库列表(公开接口,无需登录)
|
||||
/// </summary>
|
||||
/// <param name="input">查询参数</param>
|
||||
/// <returns>分页模型列表</returns>
|
||||
Task<PagedResultDto<ModelLibraryDto>> GetListAsync(ModelLibraryGetListInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 获取供应商列表(公开接口,无需登录)
|
||||
/// </summary>
|
||||
/// <returns>供应商列表</returns>
|
||||
Task<List<string>> GetProviderListAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型类型选项列表(公开接口,无需登录)
|
||||
/// </summary>
|
||||
/// <returns>模型类型选项</returns>
|
||||
Task<List<ModelTypeOption>> GetModelTypeOptionsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 获取API类型选项列表(公开接口,无需登录)
|
||||
/// </summary>
|
||||
/// <returns>API类型选项</returns>
|
||||
Task<List<ModelApiTypeOption>> GetApiTypeOptionsAsync();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
|
||||
/// <summary>
|
||||
/// 支付服务接口
|
||||
/// </summary>
|
||||
public interface IPayService : IApplicationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建订单并发起支付
|
||||
/// </summary>
|
||||
/// <param name="input">创建订单输入</param>
|
||||
/// <returns>订单创建结果</returns>
|
||||
Task<CreateOrderOutput> CreateOrderAsync(CreateOrderInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 支付宝异步通知处理
|
||||
/// </summary>
|
||||
/// <param name="form">表单数据</param>
|
||||
/// <returns></returns>
|
||||
Task<string> AlipayNotifyAsync([FromForm] IFormCollection form);
|
||||
|
||||
/// <summary>
|
||||
/// 查询订单状态
|
||||
/// </summary>
|
||||
/// <param name="input">查询订单状态输入</param>
|
||||
/// <returns>订单状态信息</returns>
|
||||
Task<QueryOrderStatusOutput> QueryOrderStatusAsync([FromQuery] QueryOrderStatusInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品列表
|
||||
/// </summary>
|
||||
/// <param name="input">获取商品列表输入</param>
|
||||
/// <returns>商品列表</returns>
|
||||
Task<List<GoodsListOutput>> GetGoodsListAsync([FromQuery] GetGoodsListInput input);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Recharge;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
|
||||
public interface IRechargeService
|
||||
{
|
||||
/// <summary>
|
||||
/// 移除用户vip及角色
|
||||
/// </summary>
|
||||
Task RemoveVipRoleByExpireAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 给用户充值VIP
|
||||
/// </summary>
|
||||
/// <param name="input">充值输入参数</param>
|
||||
/// <returns></returns>
|
||||
Task RechargeVipAsync(RechargeCreateInput input);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.UsageStatistics;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
|
||||
/// <summary>
|
||||
/// 使用量统计服务接口
|
||||
/// </summary>
|
||||
public interface IUsageStatisticsService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取当前用户近7天的Token消耗统计
|
||||
/// </summary>
|
||||
/// <returns>每日Token使用量列表</returns>
|
||||
Task<List<DailyTokenUsageDto>> GetLast7DaysTokenUsageAsync(UsageStatisticsGetInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户各个模型的Token消耗量及占比
|
||||
/// </summary>
|
||||
/// <returns>模型Token使用量列表</returns>
|
||||
Task<List<ModelTokenUsageDto>> GetModelTokenUsageAsync(UsageStatisticsGetInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户尊享服务Token用量统计
|
||||
/// </summary>
|
||||
/// <returns>尊享服务Token用量统计</returns>
|
||||
Task<PremiumTokenUsageDto> GetPremiumTokenUsageAsync();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\..\..\common.props" />
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.Ddd.Application.Contracts\Yi.Framework.Ddd.Application.Contracts.csproj" />
|
||||
<ProjectReference Include="..\..\rbac\Yi.Framework.Rbac.Application.Contracts\Yi.Framework.Rbac.Application.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.AiHub.Domain.Shared\Yi.Framework.AiHub.Domain.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,21 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Yi.Framework.AiHub.Domain.Shared;
|
||||
using Yi.Framework.Ddd.Application.Contracts;
|
||||
using Yi.Framework.Rbac.Application.Contracts;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(YiFrameworkAiHubDomainSharedModule),
|
||||
typeof(YiFrameworkDddApplicationContractsModule),
|
||||
|
||||
typeof(YiFrameworkRbacApplicationContractsModule)
|
||||
)]
|
||||
public class YiFrameworkAiHubApplicationContractsModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
var build = context.Services.GetConfiguration();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.AiHub.Domain.Extensions;
|
||||
using Yi.Framework.AiHub.Domain.Managers;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌服务 - 应用层组合服务
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
public class CardFlipService : ApplicationService, ICardFlipService
|
||||
{
|
||||
private readonly CardFlipManager _cardFlipManager;
|
||||
private readonly InviteCodeManager _inviteCodeManager;
|
||||
private readonly ISqlSugarRepository<PremiumPackageAggregateRoot> _premiumPackageRepository;
|
||||
private readonly ILogger<CardFlipService> _logger;
|
||||
|
||||
public CardFlipService(
|
||||
CardFlipManager cardFlipManager,
|
||||
InviteCodeManager inviteCodeManager,
|
||||
ISqlSugarRepository<PremiumPackageAggregateRoot> premiumPackageRepository,
|
||||
ILogger<CardFlipService> logger)
|
||||
{
|
||||
_cardFlipManager = cardFlipManager;
|
||||
_inviteCodeManager = inviteCodeManager;
|
||||
_premiumPackageRepository = premiumPackageRepository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本周翻牌任务状态
|
||||
/// </summary>
|
||||
public async Task<CardFlipStatusOutput> GetWeeklyTaskStatusAsync()
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var weekStart = CardFlipManager.GetWeekStartDate(DateTime.Now);
|
||||
|
||||
// 获取本周任务
|
||||
var task = await _cardFlipManager.GetOrCreateWeeklyTaskAsync(userId, weekStart, createIfNotExists: false);
|
||||
|
||||
// 获取邀请码信息
|
||||
var inviteCode = await _inviteCodeManager.GetUserInviteCodeAsync(userId);
|
||||
|
||||
// 统计本周邀请人数
|
||||
var invitedCount = await _inviteCodeManager.GetWeeklyInvitationCountAsync(userId, weekStart);
|
||||
|
||||
//当前用户是否已填写过邀请码
|
||||
var isFilledInviteCode = await _inviteCodeManager.IsFilledInviteCodeAsync(userId);
|
||||
var output = new CardFlipStatusOutput
|
||||
{
|
||||
TotalFlips = task?.TotalFlips ?? 0,
|
||||
RemainingFreeFlips = CardFlipManager.MAX_FREE_FLIPS - (task?.FreeFlipsUsed ?? 0),
|
||||
RemainingBonusFlips = 0, // 已废弃
|
||||
RemainingInviteFlips = CardFlipManager.MAX_INVITE_FLIPS - (task?.InviteFlipsUsed ?? 0),
|
||||
CanFlip = _cardFlipManager.CanFlipCard(task),
|
||||
MyInviteCode = inviteCode?.Code,
|
||||
InvitedCount = invitedCount,
|
||||
FlipRecords = BuildFlipRecords(task),
|
||||
IsFilledInviteCode = isFilledInviteCode
|
||||
};
|
||||
|
||||
// 生成提示信息
|
||||
output.NextFlipTip = GenerateNextFlipTip(output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌
|
||||
/// </summary>
|
||||
public async Task<FlipCardOutput> FlipCardAsync(FlipCardInput input)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var weekStart = CardFlipManager.GetWeekStartDate(DateTime.Now);
|
||||
|
||||
// 执行翻牌逻辑(由Manager处理验证和翻牌)
|
||||
var result = await _cardFlipManager.ExecuteFlipAsync(userId, input.FlipNumber, weekStart);
|
||||
|
||||
// 如果中奖,发放奖励
|
||||
if (result.IsWin)
|
||||
{
|
||||
await GrantRewardAsync(userId, result.RewardAmount, $"翻牌活动-序号{input.FlipNumber}中奖");
|
||||
}
|
||||
|
||||
// 构建输出
|
||||
var output = new FlipCardOutput
|
||||
{
|
||||
FlipNumber = result.FlipNumber,
|
||||
IsWin = result.IsWin,
|
||||
RewardAmount = result.RewardAmount,
|
||||
RewardDesc = result.RewardDesc,
|
||||
RemainingFlips = CardFlipManager.TOTAL_MAX_FLIPS - input.FlipNumber
|
||||
};
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用邀请码解锁翻牌次数
|
||||
/// </summary>
|
||||
public async Task UseInviteCodeAsync(UseInviteCodeInput input)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var weekStart = CardFlipManager.GetWeekStartDate(DateTime.Now);
|
||||
|
||||
// 获取本周任务
|
||||
var task = await _cardFlipManager.GetOrCreateWeeklyTaskAsync(userId, weekStart, createIfNotExists: true);
|
||||
|
||||
// 验证是否已经使用了所有邀请解锁次数
|
||||
if (task.InviteFlipsUsed >= CardFlipManager.MAX_INVITE_FLIPS)
|
||||
{
|
||||
throw new UserFriendlyException("本周邀请解锁次数已用完");
|
||||
}
|
||||
|
||||
// 使用邀请码(由Manager处理验证和邀请逻辑)
|
||||
await _inviteCodeManager.UseInviteCodeAsync(userId, input.InviteCode);
|
||||
|
||||
_logger.LogInformation($"用户 {userId} 使用邀请码 {input.InviteCode} 解锁翻牌次数成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取我的邀请码信息
|
||||
/// </summary>
|
||||
public async Task<InviteCodeOutput> GetMyInviteCodeAsync()
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var weekStart = CardFlipManager.GetWeekStartDate(DateTime.Now);
|
||||
|
||||
// 获取我的邀请码
|
||||
var inviteCode = await _inviteCodeManager.GetUserInviteCodeAsync(userId);
|
||||
|
||||
// 统计本周邀请人数
|
||||
var invitedCount = await _inviteCodeManager.GetWeeklyInvitationCountAsync(userId, weekStart);
|
||||
|
||||
// 获取邀请历史
|
||||
var invitationHistory = await _inviteCodeManager.GetInvitationHistoryAsync(userId, 10);
|
||||
|
||||
return new InviteCodeOutput
|
||||
{
|
||||
MyInviteCode = inviteCode?.Code,
|
||||
InvitedCount = invitedCount,
|
||||
InvitationHistory = invitationHistory.Select(x => new InvitationHistoryItem
|
||||
{
|
||||
InvitedUserName = x.InvitedUserName,
|
||||
InvitationTime = x.InvitationTime,
|
||||
WeekDescription = GetWeekDescription(x.InvitationTime)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成我的邀请码
|
||||
/// </summary>
|
||||
public async Task<string> GenerateMyInviteCodeAsync()
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
|
||||
// 生成邀请码(由Manager处理)
|
||||
var code = await _inviteCodeManager.GenerateInviteCodeForUserAsync(userId);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
#region 私有辅助方法
|
||||
|
||||
/// <summary>
|
||||
/// 构建翻牌记录列表
|
||||
/// </summary>
|
||||
private List<CardFlipRecord> BuildFlipRecords(CardFlipTaskAggregateRoot? task)
|
||||
{
|
||||
var records = new List<CardFlipRecord>();
|
||||
|
||||
// 获取已翻牌的顺序
|
||||
var flippedOrder = task != null ? _cardFlipManager.GetFlippedOrder(task) : new List<int>();
|
||||
var flippedNumbers = new HashSet<int>(flippedOrder);
|
||||
|
||||
// 获取中奖记录
|
||||
var winRecords = task?.WinRecords ?? new Dictionary<int, long>();
|
||||
|
||||
// 构建记录,按照原始序号1-10排列
|
||||
for (int i = 1; i <= CardFlipManager.TOTAL_MAX_FLIPS; i++)
|
||||
{
|
||||
var record = new CardFlipRecord
|
||||
{
|
||||
FlipNumber = i,
|
||||
IsFlipped = flippedNumbers.Contains(i),
|
||||
IsWin = false,
|
||||
FlipTypeDesc = CardFlipManager.GetFlipTypeDesc(i),
|
||||
// 设置在翻牌顺序中的位置(0表示未翻,>0表示第几个翻的)
|
||||
FlipOrderIndex = flippedOrder.IndexOf(i) >= 0 ? flippedOrder.IndexOf(i) + 1 : 0
|
||||
};
|
||||
|
||||
// 设置中奖信息
|
||||
// 判断这张卡是第几次翻的
|
||||
if (task != null && flippedNumbers.Contains(i))
|
||||
{
|
||||
var flipOrderIndex = flippedOrder.IndexOf(i) + 1; // 第几次翻的(1-based)
|
||||
|
||||
// 检查这次翻牌是否中奖
|
||||
if (winRecords.TryGetValue(flipOrderIndex, out var rewardAmount))
|
||||
{
|
||||
record.IsWin = true;
|
||||
record.RewardAmount = rewardAmount;
|
||||
}
|
||||
}
|
||||
|
||||
records.Add(record);
|
||||
}
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成下次翻牌提示
|
||||
/// </summary>
|
||||
private string GenerateNextFlipTip(CardFlipStatusOutput status)
|
||||
{
|
||||
if (status.TotalFlips >= CardFlipManager.TOTAL_MAX_FLIPS)
|
||||
{
|
||||
return "本周翻牌次数已用完,请下周再来!";
|
||||
}
|
||||
|
||||
if (status.RemainingFreeFlips > 0)
|
||||
{
|
||||
return $"本周您还有{status.RemainingFreeFlips}次免费翻牌机会";
|
||||
}
|
||||
else if (status.RemainingInviteFlips > 0)
|
||||
{
|
||||
if (status.TotalFlips >= 7)
|
||||
{
|
||||
return $"本周使用他人邀请码或他人使用你的邀请码,可解锁{status.RemainingInviteFlips}次翻牌,且必中大奖!每次中奖最大额度将翻倍!";
|
||||
}
|
||||
|
||||
return $"本周使用他人邀请码或他人使用你的邀请码,可解锁{status.RemainingInviteFlips}次翻牌,必中大奖!每次中奖最大额度将翻倍!";
|
||||
}
|
||||
|
||||
return "继续加油!";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发放奖励
|
||||
/// </summary>
|
||||
private async Task GrantRewardAsync(Guid userId, long amount, string description)
|
||||
{
|
||||
var premiumPackage = new PremiumPackageAggregateRoot(userId, amount, description)
|
||||
{
|
||||
PurchaseAmount = 0, // 奖励不需要付费
|
||||
Remark = $"翻牌活动奖励:{amount / 10000}w tokens"
|
||||
};
|
||||
|
||||
await _premiumPackageRepository.InsertAsync(premiumPackage);
|
||||
|
||||
_logger.LogInformation($"用户 {userId} 获得翻牌奖励 {amount / 10000}w tokens");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取周描述
|
||||
/// </summary>
|
||||
private string GetWeekDescription(DateTime date)
|
||||
{
|
||||
var weekStart = CardFlipManager.GetWeekStartDate(date);
|
||||
var weekEnd = weekStart.AddDays(6);
|
||||
|
||||
return $"{weekStart:MM-dd} 至 {weekEnd:MM-dd}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.DailyTask;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.AiHub.Domain.Entities.Chat;
|
||||
using Yi.Framework.AiHub.Domain.Extensions;
|
||||
using Yi.Framework.AiHub.Domain.Managers;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 每日任务服务
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
public class DailyTaskService : ApplicationService
|
||||
{
|
||||
private readonly ISqlSugarRepository<DailyTaskRewardRecordAggregateRoot> _dailyTaskRepository;
|
||||
private readonly ISqlSugarRepository<MessageAggregateRoot> _messageRepository;
|
||||
private readonly ISqlSugarRepository<PremiumPackageAggregateRoot> _premiumPackageRepository;
|
||||
private readonly ILogger<DailyTaskService> _logger;
|
||||
|
||||
// 任务配置
|
||||
private readonly Dictionary<int, (long RequiredTokens, long RewardTokens, string Name, string Description)>
|
||||
_taskConfigs = new()
|
||||
{
|
||||
{ 1, (10000000, 1000000, "尊享包1000w token任务", "累积使用尊享包 1000w token") }, // 1000w消耗 -> 100w奖励
|
||||
{ 2, (30000000, 2000000, "尊享包3000w token任务", "累积使用尊享包 3000w token") } // 3000w消耗 -> 200w奖励
|
||||
};
|
||||
|
||||
public DailyTaskService(
|
||||
ISqlSugarRepository<DailyTaskRewardRecordAggregateRoot> dailyTaskRepository,
|
||||
ISqlSugarRepository<MessageAggregateRoot> messageRepository,
|
||||
ISqlSugarRepository<PremiumPackageAggregateRoot> premiumPackageRepository,
|
||||
ILogger<DailyTaskService> logger)
|
||||
{
|
||||
_dailyTaskRepository = dailyTaskRepository;
|
||||
_messageRepository = messageRepository;
|
||||
_premiumPackageRepository = premiumPackageRepository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取今日任务状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<DailyTaskStatusOutput> GetTodayTaskStatusAsync()
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var today = DateTime.Today;
|
||||
|
||||
// 1. 统计今日尊享包Token消耗量
|
||||
var todayConsumed = await GetTodayPremiumTokenConsumptionAsync(userId, today);
|
||||
|
||||
// 2. 查询今日已领取的任务
|
||||
var claimedTasks = await _dailyTaskRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId && x.TaskDate == today)
|
||||
.Select(x => new { x.TaskLevel, x.IsRewarded })
|
||||
.ToListAsync();
|
||||
|
||||
// 3. 构建任务列表
|
||||
var tasks = new List<DailyTaskItem>();
|
||||
foreach (var (level, config) in _taskConfigs)
|
||||
{
|
||||
var claimed = claimedTasks.FirstOrDefault(x => x.TaskLevel == level);
|
||||
int status;
|
||||
|
||||
if (claimed != null && claimed.IsRewarded)
|
||||
{
|
||||
status = 2; // 已领取
|
||||
}
|
||||
else if (todayConsumed >= config.RequiredTokens)
|
||||
{
|
||||
status = 1; // 可领取
|
||||
}
|
||||
else
|
||||
{
|
||||
status = 0; // 未完成
|
||||
}
|
||||
|
||||
var progress = todayConsumed >= config.RequiredTokens
|
||||
? 100
|
||||
: Math.Round((decimal)todayConsumed / config.RequiredTokens * 100, 2);
|
||||
|
||||
tasks.Add(new DailyTaskItem
|
||||
{
|
||||
Level = level,
|
||||
Name = config.Name,
|
||||
Description = config.Description,
|
||||
RequiredTokens = config.RequiredTokens,
|
||||
RewardTokens = config.RewardTokens,
|
||||
Status = status,
|
||||
Progress = progress
|
||||
});
|
||||
}
|
||||
|
||||
return new DailyTaskStatusOutput
|
||||
{
|
||||
TodayConsumedTokens = todayConsumed,
|
||||
Tasks = tasks
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 领取任务奖励
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ClaimTaskRewardAsync(ClaimTaskRewardInput input)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var today = DateTime.Today;
|
||||
|
||||
// 1. 验证任务等级
|
||||
if (!_taskConfigs.TryGetValue(input.TaskLevel, out var taskConfig))
|
||||
{
|
||||
throw new UserFriendlyException($"无效的任务等级: {input.TaskLevel}");
|
||||
}
|
||||
|
||||
// 2. 检查是否已领取
|
||||
var existingRecord = await _dailyTaskRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId && x.TaskDate == today && x.TaskLevel == input.TaskLevel)
|
||||
.FirstAsync();
|
||||
|
||||
if (existingRecord != null)
|
||||
{
|
||||
throw new UserFriendlyException("今日该任务奖励已领取,请明天再来!");
|
||||
}
|
||||
|
||||
// 3. 验证今日Token消耗是否达标
|
||||
var todayConsumed = await GetTodayPremiumTokenConsumptionAsync(userId, today);
|
||||
if (todayConsumed < taskConfig.RequiredTokens)
|
||||
{
|
||||
throw new UserFriendlyException(
|
||||
$"Token消耗未达标!需要 {taskConfig.RequiredTokens / 10000}w,当前 {todayConsumed / 10000}w");
|
||||
}
|
||||
|
||||
// 4. 创建奖励包(使用 PremiumPackageManager)
|
||||
|
||||
var premiumPackage =
|
||||
new PremiumPackageAggregateRoot(userId, taskConfig.RewardTokens, $"每日任务:{taskConfig.Name}")
|
||||
{
|
||||
PurchaseAmount = 0, // 奖励不需要付费
|
||||
Remark = $"{today:yyyy-MM-dd} 每日任务奖励"
|
||||
};
|
||||
|
||||
await _premiumPackageRepository.InsertAsync(premiumPackage);
|
||||
|
||||
// 5. 记录领取记录
|
||||
var record = new DailyTaskRewardRecordAggregateRoot(userId, input.TaskLevel, today, taskConfig.RewardTokens)
|
||||
{
|
||||
Remark = $"完成任务{input.TaskLevel},名称:{taskConfig.Name},消耗 {todayConsumed / 10000}w token"
|
||||
};
|
||||
|
||||
await _dailyTaskRepository.InsertAsync(record);
|
||||
|
||||
_logger.LogInformation(
|
||||
$"用户 {userId} 领取每日任务 {input.TaskLevel} 奖励成功,获得 {taskConfig.RewardTokens / 10000}w tokens");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取今日尊享包Token消耗量
|
||||
/// </summary>
|
||||
/// <param name="userId">用户ID</param>
|
||||
/// <param name="today">今日日期</param>
|
||||
/// <returns>消耗的Token总数</returns>
|
||||
private async Task<long> GetTodayPremiumTokenConsumptionAsync(Guid userId, DateTime today)
|
||||
{
|
||||
var tomorrow = today.AddDays(1);
|
||||
|
||||
// 查询今日所有使用尊享包模型的消息(role=system 表示消耗)
|
||||
var totalTokens = await _messageRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId)
|
||||
.Where(x => x.Role == "system") // system角色表示实际消耗
|
||||
.Where(x => PremiumPackageConst.ModeIds.Contains(x.ModelId)) // 尊享包模型
|
||||
.Where(x => x.CreationTime >= today && x.CreationTime < tomorrow)
|
||||
.SumAsync(x => x.TokenUsage.TotalTokenCount);
|
||||
|
||||
return totalTokens;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Dtos;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
using Yi.Framework.AiHub.Domain.Extensions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
public class AiAccountService : ApplicationService
|
||||
{
|
||||
private IAccountService _accountService;
|
||||
private ISqlSugarRepository<AiUserExtraInfoEntity> _userRepository;
|
||||
private ISqlSugarRepository<AiRechargeAggregateRoot> _rechargeRepository;
|
||||
private ISqlSugarRepository<PremiumPackageAggregateRoot> _premiumPackageRepository;
|
||||
|
||||
public AiAccountService(
|
||||
IAccountService accountService,
|
||||
ISqlSugarRepository<AiUserExtraInfoEntity> userRepository,
|
||||
ISqlSugarRepository<AiRechargeAggregateRoot> rechargeRepository,
|
||||
ISqlSugarRepository<PremiumPackageAggregateRoot> premiumPackageRepository)
|
||||
{
|
||||
_accountService = accountService;
|
||||
_userRepository = userRepository;
|
||||
_rechargeRepository = rechargeRepository;
|
||||
_premiumPackageRepository = premiumPackageRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取ai用户信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
[HttpGet("account/ai")]
|
||||
public async Task<AiUserRoleMenuDto> GetAsync()
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var userAccount = await _accountService.GetAsync(null, null, userId: CurrentUser.GetId());
|
||||
var output = userAccount.Adapt<AiUserRoleMenuDto>();
|
||||
|
||||
// 是否绑定服务号
|
||||
output.IsBindFuwuhao = await _userRepository.IsAnyAsync(x => userId == x.UserId);
|
||||
|
||||
// 是否为VIP用户
|
||||
output.IsVip = CurrentUser.IsAiVip();
|
||||
|
||||
// 获取VIP到期时间
|
||||
if (output.IsVip)
|
||||
{
|
||||
var recharges = await _rechargeRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId)
|
||||
.ToListAsync();
|
||||
|
||||
if (recharges.Any())
|
||||
{
|
||||
// 如果有任何一个充值记录的过期时间为null,说明是永久VIP
|
||||
if (recharges.Any(x => !x.ExpireDateTime.HasValue))
|
||||
{
|
||||
output.VipExpireTime = null; // 永久VIP
|
||||
}
|
||||
else
|
||||
{
|
||||
// 取最大的过期时间
|
||||
output.VipExpireTime = recharges
|
||||
.Where(x => x.ExpireDateTime.HasValue)
|
||||
.Max(x => x.ExpireDateTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取利润统计数据
|
||||
/// </summary>
|
||||
/// <param name="currentCost">当前成本(RMB)</param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
[HttpGet("account/profit-statistics")]
|
||||
public async Task<string> GetProfitStatisticsAsync([FromQuery] decimal currentCost)
|
||||
{
|
||||
if (CurrentUser.UserName != "Guo" && CurrentUser.UserName != "cc")
|
||||
{
|
||||
throw new UserFriendlyException("您暂无权限访问");
|
||||
}
|
||||
|
||||
// 1. 获取尊享包总消耗和剩余库存
|
||||
var premiumPackages = await _premiumPackageRepository._DbQueryable.ToListAsync();
|
||||
long totalUsedTokens = premiumPackages.Sum(p => p.UsedTokens);
|
||||
long totalRemainingTokens = premiumPackages.Sum(p => p.RemainingTokens);
|
||||
|
||||
// 2. 计算1亿Token成本
|
||||
decimal costPerHundredMillion = totalUsedTokens > 0
|
||||
? currentCost / (totalUsedTokens / 100000000m)
|
||||
: 0;
|
||||
|
||||
// 3. 计算总成本(剩余+已使用的总成本)
|
||||
long totalTokens = totalUsedTokens + totalRemainingTokens;
|
||||
decimal totalCost = totalTokens > 0
|
||||
? (totalTokens / 100000000m) * costPerHundredMillion
|
||||
: 0;
|
||||
|
||||
// 4. 获取总收益(RechargeType=PremiumPackage的充值金额总和)
|
||||
decimal totalRevenue = await _rechargeRepository._DbQueryable
|
||||
.Where(x => x.RechargeType == Domain.Shared.Enums.RechargeTypeEnum.PremiumPackage)
|
||||
.SumAsync(x => x.RechargeAmount);
|
||||
|
||||
// 5. 计算利润率
|
||||
decimal profitRate = totalCost > 0
|
||||
? (totalRevenue / totalCost - 1) * 100
|
||||
: 0;
|
||||
|
||||
// 6. 按200售价计算成本
|
||||
decimal costAt200Price = totalRevenue > 0
|
||||
? (totalCost / totalRevenue) * 200
|
||||
: 0;
|
||||
|
||||
// 7. 格式化输出
|
||||
var today = DateTime.Now;
|
||||
string dayOfWeek = today.ToString("dddd", new System.Globalization.CultureInfo("zh-CN"));
|
||||
string weekDay = dayOfWeek switch
|
||||
{
|
||||
"星期一" => "周1",
|
||||
"星期二" => "周2",
|
||||
"星期三" => "周3",
|
||||
"星期四" => "周4",
|
||||
"星期五" => "周5",
|
||||
"星期六" => "周6",
|
||||
"星期日" => "周日",
|
||||
_ => dayOfWeek
|
||||
};
|
||||
|
||||
var result = $@"{today:M月d日} {weekDay}
|
||||
尊享包已消耗({totalUsedTokens / 100000000m:F2}亿){totalUsedTokens}
|
||||
尊享包剩余库存({totalRemainingTokens / 100000000m:F2}亿){totalRemainingTokens}
|
||||
当前成本:{currentCost:F2}RMB
|
||||
1亿Token成本:{costPerHundredMillion:F2} RMB=1亿 Token
|
||||
总成本:{totalCost:F2} RMB
|
||||
总收益:{totalRevenue:F2}RMB
|
||||
利润率: {profitRate:F1}%
|
||||
按200售价来算,成本在{costAt200Price:F2}";
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Caching;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Announcement;
|
||||
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 公告服务
|
||||
/// </summary>
|
||||
public class AnnouncementService : ApplicationService, IAnnouncementService
|
||||
{
|
||||
private readonly ISqlSugarRepository<AnnouncementAggregateRoot> _announcementRepository;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IDistributedCache<AnnouncementCacheDto> _announcementCache;
|
||||
private const string AnnouncementCacheKey = "AiHub:Announcement";
|
||||
|
||||
public AnnouncementService(
|
||||
ISqlSugarRepository<AnnouncementAggregateRoot> announcementRepository,
|
||||
IConfiguration configuration,
|
||||
IDistributedCache<AnnouncementCacheDto> announcementCache)
|
||||
{
|
||||
_announcementRepository = announcementRepository;
|
||||
_configuration = configuration;
|
||||
_announcementCache = announcementCache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取公告信息
|
||||
/// </summary>
|
||||
public async Task<List<AnnouncementLogDto>> GetAsync()
|
||||
{
|
||||
// 使用 GetOrAddAsync 从缓存获取或添加数据,缓存1小时
|
||||
var cacheData = await _announcementCache.GetOrAddAsync(
|
||||
AnnouncementCacheKey,
|
||||
async () => await LoadAnnouncementDataAsync(),
|
||||
() => new DistributedCacheEntryOptions
|
||||
{
|
||||
AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1)
|
||||
}
|
||||
);
|
||||
|
||||
return cacheData?.Logs ?? new List<AnnouncementLogDto>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库加载公告数据
|
||||
/// </summary>
|
||||
private async Task<AnnouncementCacheDto> LoadAnnouncementDataAsync()
|
||||
{
|
||||
// 查询所有公告日志,按日期降序排列
|
||||
var logs = await _announcementRepository._DbQueryable
|
||||
.OrderByDescending(x => x.StartTime)
|
||||
.ToListAsync();
|
||||
|
||||
// 转换为 DTO
|
||||
var logDtos = logs.Adapt<List<AnnouncementLogDto>>();
|
||||
return new AnnouncementCacheDto
|
||||
{
|
||||
Logs = logDtos
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using OpenAI.Chat;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.AiHub.Domain.Entities.Model;
|
||||
using Yi.Framework.AiHub.Domain.Extensions;
|
||||
using Yi.Framework.AiHub.Domain.Managers;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Dtos;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Dtos;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// ai服务
|
||||
/// </summary>
|
||||
public class AiChatService : ApplicationService
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ISqlSugarRepository<AiModelEntity> _aiModelRepository;
|
||||
private readonly AiBlacklistManager _aiBlacklistManager;
|
||||
private readonly ILogger<AiChatService> _logger;
|
||||
private readonly AiGateWayManager _aiGateWayManager;
|
||||
private readonly PremiumPackageManager _premiumPackageManager;
|
||||
|
||||
public AiChatService(IHttpContextAccessor httpContextAccessor,
|
||||
AiBlacklistManager aiBlacklistManager,
|
||||
ISqlSugarRepository<AiModelEntity> aiModelRepository,
|
||||
ILogger<AiChatService> logger, AiGateWayManager aiGateWayManager, PremiumPackageManager premiumPackageManager)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_aiBlacklistManager = aiBlacklistManager;
|
||||
_aiModelRepository = aiModelRepository;
|
||||
_logger = logger;
|
||||
_aiGateWayManager = aiGateWayManager;
|
||||
_premiumPackageManager = premiumPackageManager;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询已登录的账户信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("ai-chat/account")]
|
||||
[Authorize]
|
||||
public async Task<UserRoleMenuDto> GetAsync()
|
||||
{
|
||||
var accountService = LazyServiceProvider.GetRequiredService<IAccountService>();
|
||||
var output = await accountService.GetAsync();
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<ModelGetListOutput>> GetModelAsync()
|
||||
{
|
||||
var output = await _aiModelRepository._DbQueryable
|
||||
.Where(x => x.ModelType == ModelTypeEnum.Chat)
|
||||
.Where(x => x.ModelApiType == ModelApiTypeEnum.OpenAi)
|
||||
.OrderByDescending(x => x.OrderNum)
|
||||
.Select(x => new ModelGetListOutput
|
||||
{
|
||||
Id = x.Id,
|
||||
Category = "chat",
|
||||
ModelId = x.ModelId,
|
||||
ModelName = x.Name,
|
||||
ModelDescribe = x.Description,
|
||||
ModelPrice = 0,
|
||||
ModelType = "1",
|
||||
ModelShow = "0",
|
||||
SystemPrompt = null,
|
||||
ApiHost = null,
|
||||
ApiKey = null,
|
||||
Remark = x.Description,
|
||||
IsPremiumPackage = PremiumPackageConst.ModeIds.Contains(x.ModelId)
|
||||
}).ToListAsync();
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="sessionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("ai-chat/send")]
|
||||
public async Task PostSendAsync([FromBody] ThorChatCompletionsRequest input, [FromQuery] Guid? sessionId,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
//除了免费模型,其他的模型都要校验
|
||||
if (!input.Model.Contains("DeepSeek-R1"))
|
||||
{
|
||||
//有token,需要黑名单校验
|
||||
if (CurrentUser.IsAuthenticated)
|
||||
{
|
||||
await _aiBlacklistManager.VerifiyAiBlacklist(CurrentUser.GetId());
|
||||
if (!CurrentUser.IsAiVip())
|
||||
{
|
||||
throw new UserFriendlyException("该模型需要VIP用户才能使用,请购买VIP后重新登录重试");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UserFriendlyException("未登录用户,只能使用未加速的DeepSeek-R1,请登录后重试");
|
||||
}
|
||||
}
|
||||
|
||||
//如果是尊享包服务,需要校验是是否尊享包足够
|
||||
if (CurrentUser.IsAuthenticated && PremiumPackageConst.ModeIds.Contains(input.Model))
|
||||
{
|
||||
// 检查尊享token包用量
|
||||
var availableTokens = await _premiumPackageManager.GetAvailableTokensAsync(CurrentUser.GetId());
|
||||
if (availableTokens <= 0)
|
||||
{
|
||||
throw new UserFriendlyException("尊享token包用量不足,请先购买尊享token包");
|
||||
}
|
||||
}
|
||||
|
||||
//ai网关代理httpcontext
|
||||
await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
||||
CurrentUser.Id, sessionId, null, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("ai-chat/FileMaster/send")]
|
||||
public async Task PostFileMasterSendAsync([FromBody] ThorChatCompletionsRequest input,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(input.Model))
|
||||
{
|
||||
throw new BusinessException("当前接口不支持第三方使用");
|
||||
}
|
||||
|
||||
if (CurrentUser.IsAuthenticated)
|
||||
{
|
||||
await _aiBlacklistManager.VerifiyAiBlacklist(CurrentUser.GetId());
|
||||
if (CurrentUser.IsAiVip())
|
||||
{
|
||||
input.Model = "gpt-5-chat";
|
||||
}
|
||||
else
|
||||
{
|
||||
input.Model = "gpt-4.1-mini";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
input.Model = "DeepSeek-R1-0528";
|
||||
}
|
||||
|
||||
//ai网关代理httpcontext
|
||||
await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
||||
CurrentUser.Id, null, null, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Mapster;
|
||||
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.AiHub.Application.Contracts.Dtos;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.AiHub.Domain.Entities.Chat;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
public class MessageService : ApplicationService
|
||||
{
|
||||
private readonly ISqlSugarRepository<MessageAggregateRoot> _repository;
|
||||
|
||||
public MessageService(ISqlSugarRepository<MessageAggregateRoot> repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询消息
|
||||
/// 需要会话id
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public async Task<PagedResultDto<MessageDto>> GetListAsync([FromQuery]MessageGetListInput input)
|
||||
{
|
||||
RefAsync<int> total = 0;
|
||||
var userId = CurrentUser.GetId();
|
||||
var entities = await _repository._DbQueryable
|
||||
.Where(x => x.SessionId == input.SessionId)
|
||||
.Where(x=>x.UserId == userId)
|
||||
.OrderBy(x => x.Id)
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||
return new PagedResultDto<MessageDto>(total, entities.Adapt<List<MessageDto>>());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Model;
|
||||
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
using Yi.Framework.AiHub.Domain.Entities.Model;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Extensions;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// 模型服务
|
||||
/// </summary>
|
||||
public class ModelService : ApplicationService, IModelService
|
||||
{
|
||||
private readonly ISqlSugarRepository<AiModelEntity, Guid> _modelRepository;
|
||||
|
||||
public ModelService(ISqlSugarRepository<AiModelEntity, Guid> modelRepository)
|
||||
{
|
||||
_modelRepository = modelRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型库列表(公开接口,无需登录)
|
||||
/// </summary>
|
||||
public async Task<PagedResultDto<ModelLibraryDto>> GetListAsync(ModelLibraryGetListInput input)
|
||||
{
|
||||
RefAsync<int> total = 0;
|
||||
|
||||
// 查询所有未删除的模型,使用WhereIF动态添加筛选条件
|
||||
var modelIds = (await _modelRepository._DbQueryable
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), x =>
|
||||
x.Name.Contains(input.SearchKey) || x.ModelId.Contains(input.SearchKey))
|
||||
.WhereIF(input.ProviderNames is not null, x =>
|
||||
input.ProviderNames.Contains(x.ProviderName))
|
||||
.WhereIF(input.ModelTypes is not null, x =>
|
||||
input.ModelTypes.Contains(x.ModelType))
|
||||
.WhereIF(input.ModelApiTypes is not null, x =>
|
||||
input.ModelApiTypes.Contains(x.ModelApiType))
|
||||
.WhereIF(input.IsPremiumOnly == true, x =>
|
||||
PremiumPackageConst.ModeIds.Contains(x.ModelId))
|
||||
.GroupBy(x => x.ModelId)
|
||||
.Select(x => x.ModelId)
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total));
|
||||
|
||||
var entities = await _modelRepository._DbQueryable.Where(x => modelIds.Contains(x.ModelId))
|
||||
.OrderBy(x => x.OrderNum)
|
||||
.OrderBy(x => x.Name).ToListAsync();
|
||||
|
||||
var output= entities.GroupBy(x => x.ModelId).Select(x => new ModelLibraryDto
|
||||
{
|
||||
ModelId = x.First().ModelId,
|
||||
Name = x.First().Name,
|
||||
Description = x.First().Description,
|
||||
ModelType = x.First().ModelType,
|
||||
ModelApiTypes = x.Select(y => new ModelApiTypeOutput { ModelApiType = y.ModelApiType }).ToList(),
|
||||
MultiplierShow = x.First().MultiplierShow,
|
||||
ProviderName = x.First().ProviderName,
|
||||
IconUrl = x.First().IconUrl,
|
||||
IsPremium = PremiumPackageConst.ModeIds.Contains(x.First().ModelId),
|
||||
OrderNum = x.First().OrderNum
|
||||
}).ToList();
|
||||
|
||||
return new PagedResultDto<ModelLibraryDto>(total, output);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取供应商列表(公开接口,无需登录)
|
||||
/// </summary>
|
||||
public async Task<List<string>> GetProviderListAsync()
|
||||
{
|
||||
var providers = await _modelRepository._DbQueryable
|
||||
.Where(x => !x.IsDeleted)
|
||||
.Where(x => !string.IsNullOrEmpty(x.ProviderName))
|
||||
.GroupBy(x => x.ProviderName)
|
||||
.OrderBy(x => x.ProviderName)
|
||||
.Select(x => x.ProviderName)
|
||||
.ToListAsync();
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型类型选项列表(公开接口,无需登录)
|
||||
/// </summary>
|
||||
public Task<List<ModelTypeOption>> GetModelTypeOptionsAsync()
|
||||
{
|
||||
var options = Enum.GetValues<ModelTypeEnum>()
|
||||
.Select(e => new ModelTypeOption
|
||||
{
|
||||
Label = e.GetDescription(),
|
||||
Value = (int)e
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Task.FromResult(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取API类型选项列表(公开接口,无需登录)
|
||||
/// </summary>
|
||||
public Task<List<ModelApiTypeOption>> GetApiTypeOptionsAsync()
|
||||
{
|
||||
var options = Enum.GetValues<ModelApiTypeEnum>()
|
||||
.Select(e => new ModelApiTypeOption
|
||||
{
|
||||
Label = e.GetDescription(),
|
||||
Value = (int)e
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Task.FromResult(options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.AiHub.Domain.Entities.Chat;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
public class SessionService : CrudAppService<SessionAggregateRoot, SessionDto, Guid,SessionGetListInput,SessionCreateAndUpdateInput>
|
||||
{
|
||||
private readonly ISqlSugarRepository<SessionAggregateRoot, Guid> _repository;
|
||||
public readonly ISqlSugarRepository<MessageAggregateRoot, Guid> _messageRepository;
|
||||
public SessionService(ISqlSugarRepository<SessionAggregateRoot, Guid> repository, ISqlSugarRepository<MessageAggregateRoot, Guid> messageRepository) : base(repository)
|
||||
{
|
||||
_repository = repository;
|
||||
_messageRepository = messageRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建会话
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public override async Task<SessionDto> CreateAsync(SessionCreateAndUpdateInput input)
|
||||
{
|
||||
var entity = await MapToEntityAsync(input);
|
||||
entity.UserId = CurrentUser.GetId();
|
||||
await _repository.InsertAsync(entity);
|
||||
return entity.Adapt<SessionDto>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 详情会话
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public override Task<SessionDto> GetAsync(Guid id)
|
||||
{
|
||||
return base.GetAsync(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑会话
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public override Task<SessionDto> UpdateAsync(Guid id, SessionCreateAndUpdateInput input)
|
||||
{
|
||||
return base.UpdateAsync(id, input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除会话
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public override async Task DeleteAsync(Guid id)
|
||||
{
|
||||
await base.DeleteAsync(id);
|
||||
//对应的消息一起删除
|
||||
await _messageRepository.DeleteAsync(x => x.SessionId == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询会话
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public override async Task<PagedResultDto<SessionDto>> GetListAsync(SessionGetListInput input)
|
||||
{
|
||||
RefAsync<int> total = 0;
|
||||
var userId = CurrentUser.GetId();
|
||||
var entities = await _repository._DbQueryable
|
||||
.Where(x=>x.UserId == userId)
|
||||
.OrderByDescending(x => x.Id)
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||
return new PagedResultDto<SessionDto>(total, entities.Adapt<List<SessionDto>>());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
using Dm.util;
|
||||
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.AiHub.Application.Contracts.Dtos.Token;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.AiHub.Domain.Entities.OpenApi;
|
||||
using Yi.Framework.AiHub.Domain.Extensions;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
using Yi.Framework.Ddd.Application.Contracts;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Token服务
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
public class TokenService : ApplicationService
|
||||
{
|
||||
private readonly ISqlSugarRepository<TokenAggregateRoot> _tokenRepository;
|
||||
private readonly ISqlSugarRepository<UsageStatisticsAggregateRoot> _usageStatisticsRepository;
|
||||
|
||||
public TokenService(
|
||||
ISqlSugarRepository<TokenAggregateRoot> tokenRepository,
|
||||
ISqlSugarRepository<UsageStatisticsAggregateRoot> usageStatisticsRepository)
|
||||
{
|
||||
_tokenRepository = tokenRepository;
|
||||
_usageStatisticsRepository = usageStatisticsRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户的Token列表
|
||||
/// </summary>
|
||||
[HttpGet("token/list")]
|
||||
public async Task<PagedResultDto<TokenGetListOutputDto>> GetListAsync([FromQuery] PagedAllResultRequestDto input)
|
||||
{
|
||||
RefAsync<int> total = 0;
|
||||
var userId = CurrentUser.GetId();
|
||||
|
||||
var tokens = await _tokenRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId)
|
||||
.OrderByDescending(x => x.CreationTime)
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||
|
||||
if (!tokens.Any())
|
||||
{
|
||||
return new PagedResultDto<TokenGetListOutputDto>();
|
||||
}
|
||||
|
||||
// 获取尊享包模型ID列表
|
||||
var premiumModelIds = PremiumPackageConst.ModeIds;
|
||||
|
||||
// 批量查询所有Token的尊享包已使用额度
|
||||
var tokenIds = tokens.Select(t => t.Id).ToList();
|
||||
var usageStats = await _usageStatisticsRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId && tokenIds.Contains(x.TokenId) && premiumModelIds.Contains(x.ModelId))
|
||||
.GroupBy(x => x.TokenId)
|
||||
.Select(g => new
|
||||
{
|
||||
TokenId = g.TokenId,
|
||||
UsedQuota = SqlFunc.AggregateSum(g.TotalTokenCount)
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var result = tokens.Select(t =>
|
||||
{
|
||||
var usedQuota = usageStats.FirstOrDefault(u => u.TokenId == t.Id)?.UsedQuota ?? 0;
|
||||
return new TokenGetListOutputDto
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
ApiKey = t.Token,
|
||||
ExpireTime = t.ExpireTime,
|
||||
PremiumQuotaLimit = t.PremiumQuotaLimit,
|
||||
PremiumUsedQuota = usedQuota,
|
||||
IsDisabled = t.IsDisabled,
|
||||
CreationTime = t.CreationTime
|
||||
};
|
||||
}).ToList();
|
||||
|
||||
return new PagedResultDto<TokenGetListOutputDto>(total, result);
|
||||
}
|
||||
|
||||
[HttpGet("token/select-list")]
|
||||
public async Task<List<TokenSelectListOutputDto>> GetSelectListAsync()
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var tokens = await _tokenRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId)
|
||||
.OrderBy(x => x.IsDisabled)
|
||||
.OrderByDescending(x => x.CreationTime)
|
||||
.Select(x => new TokenSelectListOutputDto
|
||||
{
|
||||
TokenId = x.Id,
|
||||
Name = x.Name,
|
||||
IsDisabled = x.IsDisabled
|
||||
}).ToListAsync();
|
||||
|
||||
tokens.Insert(0,new TokenSelectListOutputDto
|
||||
{
|
||||
TokenId = Guid.Empty,
|
||||
Name = "默认",
|
||||
IsDisabled = false
|
||||
});
|
||||
return tokens;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建Token
|
||||
/// </summary>
|
||||
[HttpPost("token")]
|
||||
public async Task<TokenGetListOutputDto> CreateAsync([FromBody] TokenCreateInput input)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
|
||||
// 检查用户是否为VIP
|
||||
if (!CurrentUser.IsAiVip())
|
||||
{
|
||||
throw new UserFriendlyException("充值成为Vip,畅享第三方token服务");
|
||||
}
|
||||
|
||||
// 检查名称是否重复
|
||||
var exists = await _tokenRepository._DbQueryable
|
||||
.AnyAsync(x => x.UserId == userId && x.Name == input.Name);
|
||||
if (exists)
|
||||
{
|
||||
throw new UserFriendlyException($"名称【{input.Name}】已存在,请使用其他名称");
|
||||
}
|
||||
|
||||
var token = new TokenAggregateRoot(userId, input.Name)
|
||||
{
|
||||
ExpireTime = input.ExpireTime,
|
||||
PremiumQuotaLimit = input.PremiumQuotaLimit
|
||||
};
|
||||
|
||||
await _tokenRepository.InsertAsync(token);
|
||||
|
||||
return new TokenGetListOutputDto
|
||||
{
|
||||
Id = token.Id,
|
||||
Name = token.Name,
|
||||
ApiKey = token.Token,
|
||||
ExpireTime = token.ExpireTime,
|
||||
PremiumQuotaLimit = token.PremiumQuotaLimit,
|
||||
PremiumUsedQuota = 0,
|
||||
IsDisabled = token.IsDisabled,
|
||||
CreationTime = token.CreationTime
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑Token
|
||||
/// </summary>
|
||||
[HttpPut("token")]
|
||||
public async Task UpdateAsync([FromBody] TokenUpdateInput input)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
|
||||
var token = await _tokenRepository._DbQueryable
|
||||
.FirstAsync(x => x.Id == input.Id && x.UserId == userId);
|
||||
|
||||
if (token is null)
|
||||
{
|
||||
throw new UserFriendlyException("Token不存在或无权限操作");
|
||||
}
|
||||
|
||||
// 检查名称是否重复(排除自己)
|
||||
var exists = await _tokenRepository._DbQueryable
|
||||
.AnyAsync(x => x.UserId == userId && x.Name == input.Name && x.Id != input.Id);
|
||||
if (exists)
|
||||
{
|
||||
throw new UserFriendlyException($"名称【{input.Name}】已存在,请使用其他名称");
|
||||
}
|
||||
|
||||
token.Name = input.Name;
|
||||
token.ExpireTime = input.ExpireTime;
|
||||
token.PremiumQuotaLimit = input.PremiumQuotaLimit;
|
||||
|
||||
await _tokenRepository.UpdateAsync(token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除Token
|
||||
/// </summary>
|
||||
[HttpDelete("token/{id}")]
|
||||
public async Task DeleteAsync(Guid id)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
|
||||
var token = await _tokenRepository._DbQueryable
|
||||
.FirstAsync(x => x.Id == id && x.UserId == userId);
|
||||
|
||||
if (token is null)
|
||||
{
|
||||
throw new UserFriendlyException("Token不存在或无权限操作");
|
||||
}
|
||||
|
||||
await _tokenRepository.DeleteAsync(token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启用Token
|
||||
/// </summary>
|
||||
[HttpPost("token/{id}/enable")]
|
||||
public async Task EnableAsync(Guid id)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
|
||||
var token = await _tokenRepository._DbQueryable
|
||||
.FirstAsync(x => x.Id == id && x.UserId == userId);
|
||||
|
||||
if (token is null)
|
||||
{
|
||||
throw new UserFriendlyException("Token不存在或无权限操作");
|
||||
}
|
||||
|
||||
token.Enable();
|
||||
await _tokenRepository.UpdateAsync(token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 禁用Token
|
||||
/// </summary>
|
||||
[HttpPost("token/{id}/disable")]
|
||||
public async Task DisableAsync(Guid id)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
|
||||
var token = await _tokenRepository._DbQueryable
|
||||
.FirstAsync(x => x.Id == id && x.UserId == userId);
|
||||
|
||||
if (token is null)
|
||||
{
|
||||
throw new UserFriendlyException("Token不存在或无权限操作");
|
||||
}
|
||||
|
||||
token.Disable();
|
||||
await _tokenRepository.UpdateAsync(token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.FileMaster;
|
||||
using Yi.Framework.AiHub.Domain.Managers;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services.FileMaster;
|
||||
|
||||
public class FileMasterService : ApplicationService
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly AiGateWayManager _aiGateWayManager;
|
||||
private readonly AiBlacklistManager _aiBlacklistManager;
|
||||
|
||||
public FileMasterService(IHttpContextAccessor httpContextAccessor, AiGateWayManager aiGateWayManager,
|
||||
AiBlacklistManager aiBlacklistManager)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_aiGateWayManager = aiGateWayManager;
|
||||
_aiBlacklistManager = aiBlacklistManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验下一步
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("FileMaster/VerifyNext")]
|
||||
public Task<string> VerifyNextAsync(VerifyNextInput input)
|
||||
{
|
||||
if (!CurrentUser.IsAuthenticated)
|
||||
{
|
||||
if (input.DirectoryCount + input.FileCount >= 20)
|
||||
{
|
||||
throw new UserFriendlyException("未登录用户,文件夹与文件数量不能大于20个,请登录后解锁全部功能");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input.DirectoryCount + input.FileCount >= 100)
|
||||
{
|
||||
throw new UserFriendlyException("为防止无限制暴力使用,当前文件整理大师Vip最多支持100文件与文件夹数量");
|
||||
}
|
||||
}
|
||||
|
||||
return Task.FromResult("success");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 对话
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("FileMaster/chat/completions")]
|
||||
public async Task ChatCompletionsAsync([FromBody] ThorChatCompletionsRequest input,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (CurrentUser.IsAuthenticated)
|
||||
{
|
||||
input.Model = "gpt-5-chat";
|
||||
}
|
||||
else
|
||||
{
|
||||
input.Model = "gpt-5-chat";
|
||||
}
|
||||
|
||||
Guid? userId = CurrentUser.IsAuthenticated ? CurrentUser.GetId() : null;
|
||||
if (userId is not null)
|
||||
{
|
||||
await _aiBlacklistManager.VerifiyAiBlacklist(userId.Value);
|
||||
}
|
||||
|
||||
//ai网关代理httpcontext
|
||||
if (input.Stream == true)
|
||||
{
|
||||
await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
||||
userId, null, null, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _aiGateWayManager.CompleteChatForStatisticsAsync(_httpContextAccessor.HttpContext, input, userId,
|
||||
null, null,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using Medallion.Threading;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Fuwuhao;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.AiHub.Domain.Managers.Fuwuhao;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums.Fuwuhao;
|
||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.Account;
|
||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services.Fuwuhao;
|
||||
|
||||
/// <summary>
|
||||
/// 服务号服务
|
||||
/// </summary>
|
||||
public class FuwuhaoService : ApplicationService
|
||||
{
|
||||
private readonly ILogger<FuwuhaoService> _logger;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly FuwuhaoManager _fuwuhaoManager;
|
||||
private IDistributedCache<SceneCacheDto> _sceneCache;
|
||||
private IDistributedCache<string> _openIdToSceneCache;
|
||||
private ISqlSugarRepository<AiUserExtraInfoEntity> _userRepository;
|
||||
private IAccountService _accountService;
|
||||
private IFileService _fileService;
|
||||
public IDistributedLockProvider DistributedLock => LazyServiceProvider.LazyGetService<IDistributedLockProvider>();
|
||||
|
||||
public FuwuhaoService(ILogger<FuwuhaoService> logger, IHttpContextAccessor accessor, FuwuhaoManager fuwuhaoManager,
|
||||
IDistributedCache<SceneCacheDto> sceneCache, IAccountService accountService, IFileService fileService,
|
||||
IDistributedCache<string> openIdToSceneCache, ISqlSugarRepository<AiUserExtraInfoEntity> userRepositroy)
|
||||
{
|
||||
_logger = logger;
|
||||
_accessor = accessor;
|
||||
_fuwuhaoManager = fuwuhaoManager;
|
||||
_sceneCache = sceneCache;
|
||||
_accountService = accountService;
|
||||
_fileService = fileService;
|
||||
_openIdToSceneCache = openIdToSceneCache;
|
||||
_userRepository = userRepositroy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 服务器号测试回调
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("fuwuhao/callback")]
|
||||
public async Task<string> GetCallbackAsync([FromQuery] string signature, [FromQuery] string timestamp,
|
||||
[FromQuery] string nonce, [FromQuery] string echostr)
|
||||
{
|
||||
return echostr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 服务号关注回调
|
||||
/// </summary>
|
||||
/// <param name="signature"></param>
|
||||
/// <param name="timestamp"></param>
|
||||
/// <param name="nonce"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("fuwuhao/callback")]
|
||||
public async Task<string> PostCallbackAsync([FromQuery] string signature, [FromQuery] string timestamp,
|
||||
[FromQuery] string nonce)
|
||||
{
|
||||
_fuwuhaoManager.ValidateCallback(signature, timestamp, nonce);
|
||||
var request = _accessor.HttpContext.Request;
|
||||
// 1. 读取原始 XML 内容
|
||||
using var reader = new StreamReader(request.Body, Encoding.UTF8);
|
||||
var xmlString = await reader.ReadToEndAsync();
|
||||
|
||||
var serializer = new XmlSerializer(typeof(FuwuhaoCallModel));
|
||||
using var stringReader = new StringReader(xmlString);
|
||||
var body = (FuwuhaoCallModel)serializer.Deserialize(stringReader);
|
||||
|
||||
//获取场景值,后续通过场景值设置缓存状态,前端轮询这个场景值用户是否已操作即可
|
||||
var scene = body.EventKey.Replace("qrscene_", "");
|
||||
if (!(body.Event is "SCAN" or "subscribe"))
|
||||
{
|
||||
throw new UserFriendlyException("当前回调只处理扫码 与 关注");
|
||||
}
|
||||
|
||||
if (scene is null)
|
||||
{
|
||||
throw new UserFriendlyException("服务号返回无场景值");
|
||||
}
|
||||
|
||||
//制作幂等
|
||||
await using (var handle =
|
||||
await DistributedLock.TryAcquireLockAsync($"Yi:fuwuhao:callbacklock:{scene}"))
|
||||
{
|
||||
if (handle == null)
|
||||
{
|
||||
return "success"; // 跳过直接返回成功
|
||||
}
|
||||
|
||||
var cache = await _sceneCache.GetAsync($"{FuwuhaoConst.SceneCacheKey}{scene}");
|
||||
if (cache == null)
|
||||
{
|
||||
return "success"; // 跳过直接返回成功
|
||||
}
|
||||
|
||||
if (cache.SceneResult != SceneResultEnum.Wait)
|
||||
{
|
||||
return "success"; // 跳过直接返回成功
|
||||
}
|
||||
|
||||
//根据操作类型,进行业务处理,返回处理结果,再写入缓存,10s过去,相当于用户10s扫完app后,轮询要在10秒内完成
|
||||
var scenResult =
|
||||
await _fuwuhaoManager.CallBackHandlerAsync(cache.SceneType, body.FromUserName, cache.UserId);
|
||||
cache.SceneResult = scenResult.SceneResult;
|
||||
cache.UserId = scenResult.UserId;
|
||||
await _sceneCache.SetAsync($"{FuwuhaoConst.SceneCacheKey}{scene}", cache,
|
||||
new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(120) });
|
||||
|
||||
//如果是注册,将OpenId与Scene进行绑定,代表用户有30分钟进行注册
|
||||
if (scenResult.SceneResult == SceneResultEnum.Register)
|
||||
{
|
||||
await _openIdToSceneCache.SetAsync($"{FuwuhaoConst.OpenIdToSceneCacheKey}{body.FromUserName}", scene,
|
||||
new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30) });
|
||||
|
||||
var replyMessage =
|
||||
_fuwuhaoManager.BuildRegisterMessage(body.FromUserName);
|
||||
return replyMessage;
|
||||
}
|
||||
}
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建带参数的二维码
|
||||
/// </summary>
|
||||
/// <returns>二维码URL</returns>
|
||||
[HttpPost("fuwuhao/qrcode")]
|
||||
public async Task<QrCodeOutput> GetQrCodeAsync([FromQuery] SceneTypeEnum sceneType)
|
||||
{
|
||||
if (sceneType == SceneTypeEnum.Bind && CurrentUser.Id is null)
|
||||
{
|
||||
throw new UserFriendlyException("绑定微信,需登录用户,请重新登录后重试");
|
||||
}
|
||||
|
||||
//生成一个随机场景值
|
||||
var scene = Guid.NewGuid().ToString("N");
|
||||
var qrCodeUrl = await _fuwuhaoManager.CreateQrCodeAsync(scene);
|
||||
await _sceneCache.SetAsync($"{FuwuhaoConst.SceneCacheKey}{scene}", new SceneCacheDto()
|
||||
{
|
||||
UserId = CurrentUser.IsAuthenticated ? CurrentUser.GetId() : null,
|
||||
SceneType = sceneType
|
||||
}, new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10) });
|
||||
return new QrCodeOutput()
|
||||
{
|
||||
QrCodeUrl = qrCodeUrl,
|
||||
Scene = scene
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫码登录/注册/绑定,轮询接口
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("fuwuhao/qrcode/result")]
|
||||
public async Task<QrCodeResultOutput> GetQrCodeResultAsync([FromQuery] string scene)
|
||||
{
|
||||
var output = new QrCodeResultOutput();
|
||||
var cache = await _sceneCache.GetAsync($"{FuwuhaoConst.SceneCacheKey}{scene}");
|
||||
if (cache is null)
|
||||
{
|
||||
output.SceneResult = SceneResultEnum.Expired;
|
||||
return output;
|
||||
}
|
||||
|
||||
output.SceneResult = cache.SceneResult;
|
||||
switch (output.SceneResult)
|
||||
{
|
||||
case SceneResultEnum.Login:
|
||||
if (cache.UserId is null)
|
||||
{
|
||||
throw new ApplicationException("获取用户id异常,请重试");
|
||||
}
|
||||
|
||||
var loginInfo = await _accountService.PostLoginAsync(cache.UserId!.Value);
|
||||
output.Token = loginInfo.Token;
|
||||
output.RefreshToken = loginInfo.RefreshToken;
|
||||
break;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册账号,需要微信code
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("fuwuhao/register")]
|
||||
public async Task<IActionResult> RegisterByCodeAsync([FromQuery] string code)
|
||||
{
|
||||
var message = await RegisterByCodeForMessageAsync(code);
|
||||
//var message = "恭喜注册";
|
||||
var filePath = Path.Combine("wwwroot", "aihub", "auth.html");
|
||||
var html = await File.ReadAllTextAsync(filePath);
|
||||
var result = new ContentResult
|
||||
{
|
||||
Content = html.Replace("{{message}}", message),
|
||||
ContentType = "text/html",
|
||||
StatusCode = 200
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private async Task<string> RegisterByCodeForMessageAsync(string code)
|
||||
{
|
||||
//根据code获取到openid、微信用户昵称、头像
|
||||
var userInfo = await _fuwuhaoManager.GetUserInfoByCodeAsync(code);
|
||||
if (userInfo is null)
|
||||
{
|
||||
return "当前注册已经失效,请重新扫码注册!";
|
||||
}
|
||||
|
||||
var scene = await _openIdToSceneCache.GetAsync($"{FuwuhaoConst.OpenIdToSceneCacheKey}{userInfo.OpenId}");
|
||||
if (scene is null)
|
||||
{
|
||||
return "当前注册已经过期,请重新扫码注册!";
|
||||
}
|
||||
|
||||
var files = new FormFileCollection();
|
||||
// 下载头像并添加到系统文件中
|
||||
if (!string.IsNullOrEmpty(userInfo.HeadImgUrl))
|
||||
{
|
||||
using var httpClient = new HttpClient();
|
||||
var imageBytes = await httpClient.GetByteArrayAsync(userInfo.HeadImgUrl);
|
||||
var imageStream = new MemoryStream(imageBytes);
|
||||
|
||||
// 从URL中提取文件扩展名,默认为png
|
||||
var fileName = $"avatar_{userInfo.OpenId}.png";
|
||||
var formFile = new FormFile(imageStream, 0, imageBytes.Length, "avatar", fileName)
|
||||
{
|
||||
Headers = new HeaderDictionary(),
|
||||
ContentType = "image/png"
|
||||
};
|
||||
files.Add(formFile);
|
||||
}
|
||||
|
||||
var result = await _fileService.Post(files);
|
||||
|
||||
//由于存在查询/编辑在同一个事务操作,上锁防止并发
|
||||
await using (await DistributedLock.AcquireLockAsync($"fuwuhao:RegisterLock:{userInfo.OpenId}",
|
||||
TimeSpan.FromMinutes(1)))
|
||||
{
|
||||
if (await _userRepository.IsAnyAsync(x => x.FuwuhaoOpenId == userInfo.OpenId))
|
||||
{
|
||||
return "你已注册过意社区账号!";
|
||||
}
|
||||
|
||||
Guid userId;
|
||||
try
|
||||
{
|
||||
userId = await _accountService.PostSystemRegisterAsync(new RegisterDto
|
||||
{
|
||||
UserName = $"wx{Random.Shared.Next(100000, 999999)}",
|
||||
Password = Guid.NewGuid().ToString("N"),
|
||||
Phone = null,
|
||||
Email = null,
|
||||
Nick = userInfo.Nickname,
|
||||
Icon = result.FirstOrDefault()?.Id.ToString()
|
||||
});
|
||||
}
|
||||
catch (UserFriendlyException e)
|
||||
{
|
||||
return e.Message;
|
||||
}
|
||||
|
||||
|
||||
await _userRepository.InsertAsync(new AiUserExtraInfoEntity(userId, userInfo.OpenId));
|
||||
await _sceneCache.SetAsync($"{FuwuhaoConst.SceneCacheKey}{scene}", new SceneCacheDto
|
||||
{
|
||||
UserId = userId,
|
||||
SceneResult = SceneResultEnum.Login
|
||||
},
|
||||
new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(120) });
|
||||
}
|
||||
|
||||
return "恭喜你成功注册意社区账号!";
|
||||
}
|
||||
}
|
||||
|
||||
[XmlRoot("xml")]
|
||||
public class FuwuhaoCallModel
|
||||
{
|
||||
[XmlElement("ToUserName")] public string ToUserName { get; set; }
|
||||
[XmlElement("FromUserName")] public string FromUserName { get; set; }
|
||||
[XmlElement("CreateTime")] public string CreateTime { get; set; }
|
||||
[XmlElement("MsgType")] public string MsgType { get; set; }
|
||||
[XmlElement("Event")] public string Event { get; set; }
|
||||
[XmlElement("EventKey")] public string EventKey { get; set; }
|
||||
[XmlElement("Ticket")] public string Ticket { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.AiHub.Domain.Entities.Model;
|
||||
using Yi.Framework.AiHub.Domain.Extensions;
|
||||
using Yi.Framework.AiHub.Domain.Managers;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Dtos.Anthropic;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi.Embeddings;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi.Images;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi.Responses;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
public class OpenApiService : ApplicationService
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ILogger<OpenApiService> _logger;
|
||||
private readonly TokenManager _tokenManager;
|
||||
private readonly AiGateWayManager _aiGateWayManager;
|
||||
private readonly ISqlSugarRepository<AiModelEntity> _aiModelRepository;
|
||||
private readonly AiBlacklistManager _aiBlacklistManager;
|
||||
private readonly IAccountService _accountService;
|
||||
private readonly PremiumPackageManager _premiumPackageManager;
|
||||
|
||||
public OpenApiService(IHttpContextAccessor httpContextAccessor, ILogger<OpenApiService> logger,
|
||||
TokenManager tokenManager, AiGateWayManager aiGateWayManager,
|
||||
ISqlSugarRepository<AiModelEntity> aiModelRepository, AiBlacklistManager aiBlacklistManager,
|
||||
IAccountService accountService, PremiumPackageManager premiumPackageManager)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_logger = logger;
|
||||
_tokenManager = tokenManager;
|
||||
_aiGateWayManager = aiGateWayManager;
|
||||
_aiModelRepository = aiModelRepository;
|
||||
_aiBlacklistManager = aiBlacklistManager;
|
||||
_accountService = accountService;
|
||||
_premiumPackageManager = premiumPackageManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对话
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("openApi/v1/chat/completions")]
|
||||
public async Task ChatCompletionsAsync([FromBody] ThorChatCompletionsRequest input,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
//前面都是校验,后面才是真正的调用
|
||||
var httpContext = this._httpContextAccessor.HttpContext;
|
||||
var tokenValidation = await _tokenManager.ValidateTokenAsync(GetTokenByHttpContext(httpContext), input.Model);
|
||||
var userId = tokenValidation.UserId;
|
||||
var tokenId = tokenValidation.TokenId;
|
||||
await _aiBlacklistManager.VerifiyAiBlacklist(userId);
|
||||
|
||||
//如果是尊享包服务,需要校验是是否尊享包足够
|
||||
if (PremiumPackageConst.ModeIds.Contains(input.Model))
|
||||
{
|
||||
// 检查尊享token包用量
|
||||
var availableTokens = await _premiumPackageManager.GetAvailableTokensAsync(userId);
|
||||
if (availableTokens <= 0)
|
||||
{
|
||||
throw new UserFriendlyException("尊享token包用量不足,请先购买尊享token包");
|
||||
}
|
||||
}
|
||||
|
||||
//ai网关代理httpcontext
|
||||
if (input.Stream == true)
|
||||
{
|
||||
await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
||||
userId, null, tokenId, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _aiGateWayManager.CompleteChatForStatisticsAsync(_httpContextAccessor.HttpContext, input, userId,
|
||||
null, tokenId,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 图片生成
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("openApi/v1/images/generations")]
|
||||
public async Task ImagesGenerationsAsync([FromBody] ImageCreateRequest input, CancellationToken cancellationToken)
|
||||
{
|
||||
var httpContext = this._httpContextAccessor.HttpContext;
|
||||
Intercept(httpContext);
|
||||
var tokenValidation = await _tokenManager.ValidateTokenAsync(GetTokenByHttpContext(httpContext), input.Model);
|
||||
var userId = tokenValidation.UserId;
|
||||
var tokenId = tokenValidation.TokenId;
|
||||
await _aiBlacklistManager.VerifiyAiBlacklist(userId);
|
||||
await _aiGateWayManager.CreateImageForStatisticsAsync(httpContext, userId, null, input, tokenId);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 向量生成
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("openApi/v1/embeddings")]
|
||||
public async Task EmbeddingAsync([FromBody] ThorEmbeddingInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
var httpContext = this._httpContextAccessor.HttpContext;
|
||||
Intercept(httpContext);
|
||||
var tokenValidation = await _tokenManager.ValidateTokenAsync(GetTokenByHttpContext(httpContext), input.Model);
|
||||
var userId = tokenValidation.UserId;
|
||||
var tokenId = tokenValidation.TokenId;
|
||||
await _aiBlacklistManager.VerifiyAiBlacklist(userId);
|
||||
await _aiGateWayManager.EmbeddingForStatisticsAsync(httpContext, userId, null, input, tokenId);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("openApi/v1/models")]
|
||||
public async Task<ModelsListDto> ModelsAsync()
|
||||
{
|
||||
var data = await _aiModelRepository._DbQueryable
|
||||
.Where(x => x.ModelType == ModelTypeEnum.Chat)
|
||||
.OrderByDescending(x => x.OrderNum)
|
||||
.Select(x => new ModelsDataDto
|
||||
{
|
||||
Id = x.ModelId,
|
||||
@object = "model",
|
||||
Created = DateTime.Now.ToUnixTimeSeconds(),
|
||||
OwnedBy = "organization-owner",
|
||||
Type = x.ModelId
|
||||
}).ToListAsync();
|
||||
|
||||
return new ModelsListDto()
|
||||
{
|
||||
Data = data
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Anthropic对话(尊享服务专用)
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("openApi/v1/messages")]
|
||||
public async Task MessagesAsync([FromBody] AnthropicInput input,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
//前面都是校验,后面才是真正的调用
|
||||
var httpContext = this._httpContextAccessor.HttpContext;
|
||||
var tokenValidation = await _tokenManager.ValidateTokenAsync(GetTokenByHttpContext(httpContext), input.Model);
|
||||
var userId = tokenValidation.UserId;
|
||||
var tokenId = tokenValidation.TokenId;
|
||||
await _aiBlacklistManager.VerifiyAiBlacklist(userId);
|
||||
|
||||
// 验证用户是否为VIP
|
||||
var userInfo = await _accountService.GetAsync(null, null, userId);
|
||||
if (userInfo == null)
|
||||
{
|
||||
throw new UserFriendlyException("用户信息不存在");
|
||||
}
|
||||
|
||||
// 检查是否为VIP(使用RoleCodes判断)
|
||||
if (!userInfo.RoleCodes.Contains(AiHubConst.VipRole) && userInfo.User.UserName != "cc")
|
||||
{
|
||||
throw new UserFriendlyException("该接口为尊享服务专用,需要VIP权限才能使用");
|
||||
}
|
||||
|
||||
// 检查尊享token包用量
|
||||
var availableTokens = await _premiumPackageManager.GetAvailableTokensAsync(userId);
|
||||
if (availableTokens <= 0)
|
||||
{
|
||||
throw new UserFriendlyException("尊享token包用量不足,请先购买尊享token包");
|
||||
}
|
||||
|
||||
//ai网关代理httpcontext
|
||||
if (input.Stream)
|
||||
{
|
||||
await _aiGateWayManager.AnthropicCompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext,
|
||||
input,
|
||||
userId, null, tokenId, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _aiGateWayManager.AnthropicCompleteChatForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
||||
userId,
|
||||
null, tokenId,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 响应-Openai新规范 (尊享服务专用)
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("openApi/v1/responses")]
|
||||
public async Task ResponsesAsync([FromBody] OpenAiResponsesInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
//前面都是校验,后面才是真正的调用
|
||||
var httpContext = this._httpContextAccessor.HttpContext;
|
||||
var tokenValidation = await _tokenManager.ValidateTokenAsync(GetTokenByHttpContext(httpContext), input.Model);
|
||||
var userId = tokenValidation.UserId;
|
||||
var tokenId = tokenValidation.TokenId;
|
||||
await _aiBlacklistManager.VerifiyAiBlacklist(userId);
|
||||
|
||||
// 验证用户是否为VIP
|
||||
var userInfo = await _accountService.GetAsync(null, null, userId);
|
||||
if (userInfo == null)
|
||||
{
|
||||
throw new UserFriendlyException("用户信息不存在");
|
||||
}
|
||||
|
||||
// 检查是否为VIP(使用RoleCodes判断)
|
||||
if (!userInfo.RoleCodes.Contains(AiHubConst.VipRole) && userInfo.User.UserName != "cc")
|
||||
{
|
||||
throw new UserFriendlyException("该接口为尊享服务专用,需要VIP权限才能使用");
|
||||
}
|
||||
|
||||
// 检查尊享token包用量
|
||||
var availableTokens = await _premiumPackageManager.GetAvailableTokensAsync(userId);
|
||||
if (availableTokens <= 0)
|
||||
{
|
||||
throw new UserFriendlyException("尊享token包用量不足,请先购买尊享token包");
|
||||
}
|
||||
|
||||
//ai网关代理httpcontext
|
||||
if (input.Stream == true)
|
||||
{
|
||||
await _aiGateWayManager.OpenAiResponsesStreamForStatisticsAsync(_httpContextAccessor.HttpContext,
|
||||
input,
|
||||
userId, null, tokenId, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _aiGateWayManager.OpenAiResponsesAsyncForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
||||
userId,
|
||||
null, tokenId,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 私有
|
||||
|
||||
private string? GetTokenByHttpContext(HttpContext httpContext)
|
||||
{
|
||||
// 优先从 x-api-key 获取
|
||||
string apiKeyHeader = httpContext.Request.Headers["x-api-key"];
|
||||
if (!string.IsNullOrWhiteSpace(apiKeyHeader))
|
||||
{
|
||||
return apiKeyHeader.Trim();
|
||||
}
|
||||
|
||||
// 再检查 Authorization 头
|
||||
string authHeader = httpContext.Request.Headers["Authorization"];
|
||||
if (!string.IsNullOrWhiteSpace(authHeader) &&
|
||||
authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return authHeader.Substring("Bearer ".Length).Trim();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void Intercept(HttpContext httpContext)
|
||||
{
|
||||
if (httpContext.Request.Host.Value == "yxai.chat")
|
||||
{
|
||||
throw new UserFriendlyException("当前海外站点不支持大流量接口,请使用转发站点:https://ai.ccnetcore.com");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Yi.Framework.AiHub.Domain.Alipay;
|
||||
using Yi.Framework.AiHub.Domain.Managers;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
using Volo.Abp;
|
||||
using Yi.Framework.AiHub.Domain.Entities.Pay;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Recharge;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 支付服务
|
||||
/// </summary>
|
||||
public class PayService : ApplicationService, IPayService
|
||||
{
|
||||
private readonly AlipayManager _alipayManager;
|
||||
private readonly PayManager _payManager;
|
||||
private readonly ILogger<PayService> _logger;
|
||||
private readonly ISqlSugarRepository<PayOrderAggregateRoot, Guid> _payOrderRepository;
|
||||
private readonly IRechargeService _rechargeService;
|
||||
private readonly PremiumPackageManager _premiumPackageManager;
|
||||
|
||||
public PayService(
|
||||
AlipayManager alipayManager,
|
||||
PayManager payManager,
|
||||
ILogger<PayService> logger,
|
||||
ISqlSugarRepository<PayOrderAggregateRoot, Guid> payOrderRepository,
|
||||
IRechargeService rechargeService,
|
||||
PremiumPackageManager premiumPackageManager)
|
||||
{
|
||||
_alipayManager = alipayManager;
|
||||
_payManager = payManager;
|
||||
_logger = logger;
|
||||
_payOrderRepository = payOrderRepository;
|
||||
_rechargeService = rechargeService;
|
||||
_premiumPackageManager = premiumPackageManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建订单并发起支付
|
||||
/// </summary>
|
||||
/// <param name="input">创建订单输入</param>
|
||||
/// <returns>订单创建结果</returns>
|
||||
[Authorize]
|
||||
[HttpPost("pay/Order")]
|
||||
public async Task<CreateOrderOutput> CreateOrderAsync(CreateOrderInput input)
|
||||
{
|
||||
// 1. 通过PayManager创建订单(内部会验证VIP资格)
|
||||
var order = await _payManager.CreateOrderAsync(input.GoodsType);
|
||||
|
||||
// 2. 通过AlipayManager发起页面支付
|
||||
var paymentPageHtml = await _alipayManager.PaymentPageAsync(
|
||||
order.GoodsName,
|
||||
order.OutTradeNo,
|
||||
order.TotalAmount,
|
||||
input.ReturnUrl);
|
||||
|
||||
// 3. 返回结果
|
||||
return new CreateOrderOutput
|
||||
{
|
||||
OrderId = order.Id,
|
||||
OutTradeNo = order.OutTradeNo,
|
||||
PaymentPageHtml = paymentPageHtml.Body
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 支付宝异步通知处理
|
||||
/// </summary>
|
||||
/// <param name="form">表单数据</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("pay/AlipayNotify")]
|
||||
[AllowAnonymous]
|
||||
public async Task<string> AlipayNotifyAsync([FromForm] IFormCollection form)
|
||||
{
|
||||
// 1. 将表单数据转换为字典,保持原始顺序
|
||||
var notifyData = new Dictionary<string, string>();
|
||||
foreach (var item in form)
|
||||
{
|
||||
notifyData[item.Key] = item.Value.ToString();
|
||||
}
|
||||
|
||||
var signStr = string.Join("&", notifyData.Select(kv => $"{kv.Key}={kv.Value}"));
|
||||
_logger.LogInformation($"收到支付宝回调通知:{signStr}");
|
||||
|
||||
// 2. 验证签名
|
||||
await _alipayManager.VerifyNotifyAsync(notifyData);
|
||||
|
||||
// 3. 记录支付通知
|
||||
await _payManager.RecordPayNoticeAsync(notifyData, signStr);
|
||||
|
||||
// 4. 更新订单状态
|
||||
var outTradeNo = notifyData.GetValueOrDefault("out_trade_no", string.Empty);
|
||||
var tradeStatus = notifyData.GetValueOrDefault("trade_status", string.Empty);
|
||||
var tradeNo = notifyData.GetValueOrDefault("trade_no", string.Empty);
|
||||
|
||||
if (!string.IsNullOrEmpty(outTradeNo) && !string.IsNullOrEmpty(tradeStatus))
|
||||
{
|
||||
var status = ParseTradeStatus(tradeStatus);
|
||||
var order = await _payManager.UpdateOrderStatusAsync(outTradeNo, status, tradeNo);
|
||||
|
||||
_logger.LogInformation("订单状态更新成功,订单号:{OutTradeNo},状态:{TradeStatus}", outTradeNo, tradeStatus);
|
||||
|
||||
// 验证交易状态,只有交易成功才执行充值逻辑
|
||||
if (status != TradeStatusEnum.TRADE_SUCCESS)
|
||||
{
|
||||
_logger.LogError($"订单 {outTradeNo} 状态为 {tradeStatus},不执行充值逻辑");
|
||||
return "success";
|
||||
}
|
||||
|
||||
// 5. 根据商品类型进行不同的处理
|
||||
if (order.GoodsType.IsPremiumPackage())
|
||||
{
|
||||
// 处理尊享包商品:创建尊享包记录
|
||||
await _premiumPackageManager.CreatePremiumPackageAsync(
|
||||
order.UserId,
|
||||
order.GoodsType,
|
||||
order.TotalAmount,
|
||||
expireMonths: null // 尊享包不设置过期时间,或者可以根据需求设置
|
||||
);
|
||||
|
||||
_logger.LogInformation(
|
||||
$"用户 {order.UserId} 购买尊享包成功,订单号:{outTradeNo},商品:{order.GoodsName}");
|
||||
}
|
||||
else if (order.GoodsType.IsVipService())
|
||||
{
|
||||
// 处理VIP服务商品:充值VIP
|
||||
await _rechargeService.RechargeVipAsync(new RechargeCreateInput
|
||||
{
|
||||
UserId = order.UserId,
|
||||
RechargeAmount = order.TotalAmount,
|
||||
Content = order.GoodsName,
|
||||
Months = order.GoodsType.GetValidMonths(),
|
||||
Remark = "自助充值",
|
||||
ContactInfo = null
|
||||
});
|
||||
|
||||
_logger.LogInformation(
|
||||
$"用户 {order.UserId} 充值VIP成功,订单号:{outTradeNo},月数:{order.GoodsType.GetValidMonths()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning($"未知的商品类型:{order.GoodsType},订单号:{outTradeNo}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlipayException($"回调格式错误");
|
||||
}
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询订单状态
|
||||
/// </summary>
|
||||
/// <param name="input">查询订单状态输入</param>
|
||||
/// <returns>订单状态信息</returns>
|
||||
[HttpGet("pay/OrderStatus")]
|
||||
[Authorize]
|
||||
public async Task<QueryOrderStatusOutput> QueryOrderStatusAsync([FromQuery] QueryOrderStatusInput input)
|
||||
{
|
||||
// 通过PayManager查询订单
|
||||
var order = await _payOrderRepository.GetFirstAsync(x => x.OutTradeNo == input.OutTradeNo);
|
||||
if (order == null)
|
||||
{
|
||||
throw new UserFriendlyException($"订单不存在:{input.OutTradeNo}");
|
||||
}
|
||||
|
||||
return new QueryOrderStatusOutput
|
||||
{
|
||||
OrderId = order.Id,
|
||||
OutTradeNo = order.OutTradeNo,
|
||||
TradeNo = order.TradeNo,
|
||||
TradeStatus = order.TradeStatus,
|
||||
TradeStatusDescription = GetTradeStatusDescription(order.TradeStatus),
|
||||
TotalAmount = order.TotalAmount,
|
||||
GoodsName = order.GoodsName,
|
||||
GoodsType = order.GoodsType,
|
||||
CreationTime = order.CreationTime,
|
||||
LastModificationTime = order.LastModificationTime
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品列表
|
||||
/// </summary>
|
||||
/// <param name="input">获取商品列表输入</param>
|
||||
/// <returns>商品列表</returns>
|
||||
[HttpGet("pay/GoodsList")]
|
||||
public async Task<List<GoodsListOutput>> GetGoodsListAsync([FromQuery] GetGoodsListInput input)
|
||||
{
|
||||
var goodsList = new List<GoodsListOutput>();
|
||||
|
||||
// 获取当前用户的累加充值金额(仅已登录用户)
|
||||
decimal totalRechargeAmount = 0m;
|
||||
if (CurrentUser.IsAuthenticated)
|
||||
{
|
||||
totalRechargeAmount = await _payManager.GetUserTotalRechargeAmountAsync(CurrentUser.GetId());
|
||||
}
|
||||
|
||||
// 遍历所有商品枚举
|
||||
foreach (GoodsTypeEnum goodsType in Enum.GetValues(typeof(GoodsTypeEnum)))
|
||||
{
|
||||
// 如果指定了商品类别,则过滤
|
||||
if (input.GoodsCategoryType.HasValue)
|
||||
{
|
||||
var goodsCategory = goodsType.GetGoodsCategory();
|
||||
if (goodsCategory != input.GoodsCategoryType.Value)
|
||||
{
|
||||
continue; // 跳过不匹配的商品
|
||||
}
|
||||
}
|
||||
|
||||
var originalPrice = goodsType.GetTotalAmount();
|
||||
decimal actualPrice = originalPrice;
|
||||
decimal? discountAmount = null;
|
||||
string? discountDescription = null;
|
||||
|
||||
// 如果是尊享包商品,计算折扣
|
||||
if (goodsType.IsPremiumPackage())
|
||||
{
|
||||
|
||||
|
||||
if (CurrentUser.IsAuthenticated)
|
||||
{
|
||||
discountAmount = goodsType.CalculateDiscount(totalRechargeAmount);
|
||||
actualPrice = goodsType.GetDiscountedPrice(totalRechargeAmount);
|
||||
if (discountAmount > 0)
|
||||
{
|
||||
discountDescription = $"根据累积充值已优惠 ¥{discountAmount:F2}";
|
||||
}
|
||||
else
|
||||
{
|
||||
discountDescription = $"累积充值过低,暂无优惠";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
discountDescription = $"登录后查看优惠";
|
||||
}
|
||||
}
|
||||
|
||||
var goodsItem = new GoodsListOutput
|
||||
{
|
||||
GoodsName = goodsType.GetChineseName(),
|
||||
OriginalPrice = originalPrice,
|
||||
ReferencePrice = goodsType.GetReferencePrice(),
|
||||
GoodsPrice = actualPrice,
|
||||
GoodsCategory = goodsType.GetGoodsCategory().ToString(),
|
||||
Remark = goodsType.GetRemark(),
|
||||
DiscountAmount = discountAmount,
|
||||
DiscountDescription = discountDescription,
|
||||
GoodsType = goodsType
|
||||
};
|
||||
|
||||
goodsList.Add(goodsItem);
|
||||
}
|
||||
|
||||
return goodsList;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取交易状态描述
|
||||
/// </summary>
|
||||
/// <param name="tradeStatus">交易状态</param>
|
||||
/// <returns>状态描述</returns>
|
||||
private string GetTradeStatusDescription(TradeStatusEnum tradeStatus)
|
||||
{
|
||||
var fieldInfo = tradeStatus.GetType().GetField(tradeStatus.ToString());
|
||||
var descriptionAttribute = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
|
||||
return descriptionAttribute?.Description ?? "未知状态";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析交易状态
|
||||
/// </summary>
|
||||
/// <param name="tradeStatus">状态字符串</param>
|
||||
/// <returns></returns>
|
||||
private TradeStatusEnum ParseTradeStatus(string tradeStatus)
|
||||
{
|
||||
if (Enum.TryParse<TradeStatusEnum>(tradeStatus, out var result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return TradeStatusEnum.WAIT_TRADE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Recharge;
|
||||
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.AiHub.Domain.Managers;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services
|
||||
{
|
||||
public class RechargeService : ApplicationService, IRechargeService
|
||||
{
|
||||
private readonly ISqlSugarRepository<AiRechargeAggregateRoot> _repository;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IRoleService _roleService;
|
||||
private readonly AiRechargeManager _aiMessageManager;
|
||||
|
||||
public RechargeService(
|
||||
ISqlSugarRepository<AiRechargeAggregateRoot> repository,
|
||||
ICurrentUser currentUser,
|
||||
IUserService userService, IRoleService roleService, AiRechargeManager aiMessageManager)
|
||||
{
|
||||
_repository = repository;
|
||||
_currentUser = currentUser;
|
||||
_userService = userService;
|
||||
_roleService = roleService;
|
||||
_aiMessageManager = aiMessageManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询已登录的账户充值记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("recharge/account")]
|
||||
[Authorize]
|
||||
public async Task<List<RechargeGetListOutput>> GetListByAccountAsync()
|
||||
{
|
||||
var userId = CurrentUser.Id;
|
||||
var entities = await _repository._DbQueryable.Where(x => x.UserId == userId)
|
||||
.OrderByDescending(x => x.CreationTime)
|
||||
.ToListAsync();
|
||||
var output = entities.Adapt<List<RechargeGetListOutput>>();
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给用户充值VIP
|
||||
/// </summary>
|
||||
/// <param name="input">充值输入参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("recharge/vip")]
|
||||
public async Task RechargeVipAsync(RechargeCreateInput input)
|
||||
{
|
||||
DateTime? expireDateTime = null;
|
||||
|
||||
// 如果传入了月数,计算过期时间
|
||||
if (input.Months.HasValue && input.Months.Value > 0)
|
||||
{
|
||||
// 直接查询该用户最大的过期时间
|
||||
var maxExpireTime = await _repository._DbQueryable
|
||||
.Where(x => x.RechargeType == RechargeTypeEnum.Vip)
|
||||
.Where(x => x.UserId == input.UserId && x.ExpireDateTime.HasValue)
|
||||
.MaxAsync(x => x.ExpireDateTime);
|
||||
|
||||
// 如果最大过期时间大于现在时间,从最大过期时间开始计算
|
||||
// 否则从当天开始计算
|
||||
DateTime baseDateTime = maxExpireTime.HasValue && maxExpireTime.Value > DateTime.Now
|
||||
? maxExpireTime.Value
|
||||
: DateTime.Now;
|
||||
// 计算新的过期时间
|
||||
expireDateTime = baseDateTime.AddMonths(input.Months.Value);
|
||||
}
|
||||
// 如果月数为空或0,表示永久VIP,ExpireDateTime保持为null
|
||||
|
||||
// 创建充值记录
|
||||
var rechargeRecord = new AiRechargeAggregateRoot
|
||||
{
|
||||
UserId = input.UserId,
|
||||
RechargeAmount = input.RechargeAmount,
|
||||
Content = input.Content,
|
||||
ExpireDateTime = expireDateTime,
|
||||
Remark = input.Remark,
|
||||
ContactInfo = input.ContactInfo,
|
||||
RechargeType = RechargeTypeEnum.Vip
|
||||
};
|
||||
|
||||
// 保存充值记录到数据库
|
||||
await _repository.InsertAsync(rechargeRecord);
|
||||
|
||||
// 使用UserService给用户添加VIP角色
|
||||
await _userService.AddUserRoleByRoleCodeAsync(input.UserId,
|
||||
new List<string>() { AiHubConst.VipRole, "default" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除用户vip及角色
|
||||
/// </summary>
|
||||
[RemoteService(isEnabled: false)]
|
||||
public async Task RemoveVipRoleByExpireAsync()
|
||||
{
|
||||
var expiredUserIds = await _aiMessageManager.RemoveVipByExpireAsync();
|
||||
if (expiredUserIds is not null)
|
||||
{
|
||||
await _roleService.RemoveUserRoleByRoleCodeAsync(expiredUserIds, AiHubConst.VipRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
using Mapster;
|
||||
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.AiHub.Application.Contracts.Dtos.UsageStatistics;
|
||||
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.AiHub.Domain.Entities.Chat;
|
||||
using Yi.Framework.AiHub.Domain.Entities.OpenApi;
|
||||
using Yi.Framework.AiHub.Domain.Extensions;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
using Yi.Framework.Ddd.Application.Contracts;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 使用量统计服务
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
public class UsageStatisticsService : ApplicationService, IUsageStatisticsService
|
||||
{
|
||||
private readonly ISqlSugarRepository<MessageAggregateRoot> _messageRepository;
|
||||
private readonly ISqlSugarRepository<UsageStatisticsAggregateRoot> _usageStatisticsRepository;
|
||||
private readonly ISqlSugarRepository<PremiumPackageAggregateRoot> _premiumPackageRepository;
|
||||
private readonly ISqlSugarRepository<TokenAggregateRoot> _tokenRepository;
|
||||
|
||||
public UsageStatisticsService(
|
||||
ISqlSugarRepository<MessageAggregateRoot> messageRepository,
|
||||
ISqlSugarRepository<UsageStatisticsAggregateRoot> usageStatisticsRepository,
|
||||
ISqlSugarRepository<PremiumPackageAggregateRoot> premiumPackageRepository,
|
||||
ISqlSugarRepository<TokenAggregateRoot> tokenRepository)
|
||||
{
|
||||
_messageRepository = messageRepository;
|
||||
_usageStatisticsRepository = usageStatisticsRepository;
|
||||
_premiumPackageRepository = premiumPackageRepository;
|
||||
_tokenRepository = tokenRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户近7天的Token消耗统计
|
||||
/// </summary>
|
||||
/// <returns>每日Token使用量列表</returns>
|
||||
public async Task<List<DailyTokenUsageDto>> GetLast7DaysTokenUsageAsync([FromQuery]UsageStatisticsGetInput input)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var endDate = DateTime.Today;
|
||||
var startDate = endDate.AddDays(-6); // 近7天
|
||||
|
||||
// 从Message表统计近7天的token消耗
|
||||
var dailyUsage = await _messageRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId)
|
||||
.Where(x => x.Role == "assistant" || x.Role == "system")
|
||||
.Where(x => x.CreationTime >= startDate && x.CreationTime < endDate.AddDays(1))
|
||||
.WhereIF(input.TokenId.HasValue,x => x.TokenId == input.TokenId)
|
||||
.GroupBy(x => x.CreationTime.Date)
|
||||
.Select(g => new
|
||||
{
|
||||
Date = g.CreationTime.Date,
|
||||
Tokens = SqlFunc.AggregateSum(g.TokenUsage.TotalTokenCount)
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
// 生成完整的7天数据,包括没有使用记录的日期
|
||||
var result = new List<DailyTokenUsageDto>();
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
var date = startDate.AddDays(i);
|
||||
var usage = dailyUsage.FirstOrDefault(x => x.Date == date);
|
||||
|
||||
result.Add(new DailyTokenUsageDto
|
||||
{
|
||||
Date = date,
|
||||
Tokens = usage?.Tokens ?? 0
|
||||
});
|
||||
}
|
||||
|
||||
return result.OrderBy(x => x.Date).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户各个模型的Token消耗量及占比
|
||||
/// </summary>
|
||||
/// <returns>模型Token使用量列表</returns>
|
||||
public async Task<List<ModelTokenUsageDto>> GetModelTokenUsageAsync([FromQuery]UsageStatisticsGetInput input)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
|
||||
// 从UsageStatistics表获取各模型的token消耗统计(按ModelId聚合,因为同一模型可能有多个TokenId的记录)
|
||||
var modelUsages = await _usageStatisticsRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId)
|
||||
.WhereIF(input.TokenId.HasValue,x => x.TokenId == input.TokenId)
|
||||
.GroupBy(x => x.ModelId)
|
||||
.Select(x => new
|
||||
{
|
||||
ModelId = x.ModelId,
|
||||
TotalTokenCount = SqlFunc.AggregateSum(x.TotalTokenCount)
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
if (!modelUsages.Any())
|
||||
{
|
||||
return new List<ModelTokenUsageDto>();
|
||||
}
|
||||
|
||||
// 计算总token数
|
||||
var totalTokens = modelUsages.Sum(x => x.TotalTokenCount);
|
||||
|
||||
// 计算各模型占比
|
||||
var result = modelUsages.Select(x => new ModelTokenUsageDto
|
||||
{
|
||||
Model = x.ModelId,
|
||||
Tokens = x.TotalTokenCount,
|
||||
Percentage = totalTokens > 0 ? Math.Round((decimal)x.TotalTokenCount / totalTokens * 100, 2) : 0
|
||||
}).OrderByDescending(x => x.Tokens).ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户尊享服务Token用量统计
|
||||
/// </summary>
|
||||
/// <returns>尊享服务Token用量统计</returns>
|
||||
public async Task<PremiumTokenUsageDto> GetPremiumTokenUsageAsync()
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
|
||||
// 获取尊享包Token信息
|
||||
var premiumPackages = await _premiumPackageRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId && x.IsActive)
|
||||
.ToListAsync();
|
||||
|
||||
var result = new PremiumTokenUsageDto();
|
||||
|
||||
if (premiumPackages.Any())
|
||||
{
|
||||
// 过滤掉已过期、禁用的包,不过滤用量负数的包
|
||||
var validPackages = premiumPackages
|
||||
.Where(p => p.IsAvailable(false))
|
||||
.ToList();
|
||||
|
||||
result.PremiumTotalTokens = validPackages.Sum(x => x.TotalTokens);
|
||||
result.PremiumUsedTokens = validPackages.Sum(x => x.UsedTokens);
|
||||
result.PremiumRemainingTokens = validPackages.Sum(x => x.RemainingTokens);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户尊享服务token用量统计列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("usage-statistics/premium-token-usage/list")]
|
||||
public async Task<PagedResultDto<PremiumTokenUsageGetListOutput>> GetPremiumTokenUsageListAsync(
|
||||
PremiumTokenUsageGetListInput input)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
RefAsync<int> total = 0;
|
||||
// 获取尊享包Token信息
|
||||
var entities = await _premiumPackageRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId)
|
||||
.WhereIF(input.IsFree == false, x => x.PurchaseAmount > 0)
|
||||
.WhereIF(input.IsFree == true, x => x.PurchaseAmount == 0)
|
||||
.WhereIF(input.StartTime is not null && input.EndTime is not null,
|
||||
x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
|
||||
.OrderByDescending(x => x.CreationTime)
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||
return new PagedResultDto<PremiumTokenUsageGetListOutput>(total,
|
||||
entities.Adapt<List<PremiumTokenUsageGetListOutput>>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户尊享包不同Token用量占比(饼图)
|
||||
/// </summary>
|
||||
/// <returns>各Token的尊享模型用量及占比</returns>
|
||||
[HttpGet("usage-statistics/premium-token-usage/by-token")]
|
||||
public async Task<List<TokenPremiumUsageDto>> GetPremiumTokenUsageByTokenAsync()
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var premiumModelIds = PremiumPackageConst.ModeIds;
|
||||
|
||||
// 从UsageStatistics表获取尊享模型的token消耗统计(按TokenId聚合)
|
||||
var tokenUsages = await _usageStatisticsRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId && premiumModelIds.Contains(x.ModelId))
|
||||
.GroupBy(x => x.TokenId)
|
||||
.Select(x => new
|
||||
{
|
||||
TokenId = x.TokenId,
|
||||
TotalTokenCount = SqlFunc.AggregateSum(x.TotalTokenCount)
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
if (!tokenUsages.Any())
|
||||
{
|
||||
return new List<TokenPremiumUsageDto>();
|
||||
}
|
||||
|
||||
// 获取用户的所有Token信息用于名称映射
|
||||
var tokenIds = tokenUsages.Select(x => x.TokenId).ToList();
|
||||
var tokens = await _tokenRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId && tokenIds.Contains(x.Id))
|
||||
.Select(x => new { x.Id, x.Name })
|
||||
.ToListAsync();
|
||||
|
||||
var tokenNameDict = tokens.ToDictionary(x => x.Id, x => x.Name);
|
||||
|
||||
// 计算总token数
|
||||
var totalTokens = tokenUsages.Sum(x => x.TotalTokenCount);
|
||||
|
||||
// 计算各Token占比
|
||||
var result = tokenUsages.Select(x => new TokenPremiumUsageDto
|
||||
{
|
||||
TokenId = x.TokenId,
|
||||
TokenName = x.TokenId == Guid.Empty ? "默认" : (tokenNameDict.TryGetValue(x.TokenId, out var name) ? name : "其他"),
|
||||
Tokens = x.TotalTokenCount,
|
||||
Percentage = totalTokens > 0 ? Math.Round((decimal)x.TotalTokenCount / totalTokens * 100, 2) : 0
|
||||
}).OrderByDescending(x => x.Tokens).ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\..\..\common.props" />
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.Ddd.Application\Yi.Framework.Ddd.Application.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.AiHub.Application.Contracts\Yi.Framework.AiHub.Application.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.AiHub.Domain\Yi.Framework.AiHub.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,15 @@
|
||||
using Yi.Framework.AiHub.Application.Contracts;
|
||||
using Yi.Framework.AiHub.Domain;
|
||||
using Yi.Framework.Ddd.Application;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(YiFrameworkAiHubApplicationContractsModule),
|
||||
typeof(YiFrameworkAiHubDomainModule),
|
||||
typeof(YiFrameworkDddApplicationModule)
|
||||
)]
|
||||
public class YiFrameworkAiHubApplicationModule : AbpModule
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
|
||||
public class AiHubConst
|
||||
{
|
||||
public const string VipRole = "YiXinAi-Vip";
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
|
||||
public class FuwuhaoConst
|
||||
{
|
||||
public const string SceneCacheKey = "fuwuhao:scene:";
|
||||
public const string OpenIdToSceneCacheKey = "fuwuhao:OpenIdToScene:";
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||
|
||||
public class PremiumPackageConst
|
||||
{
|
||||
public static List<string> ModeIds =
|
||||
[
|
||||
"claude-sonnet-4-5-20250929",
|
||||
"claude-haiku-4-5-20251001",
|
||||
"claude-opus-4-5-20251101",
|
||||
"gemini-3-pro-preview",
|
||||
"gpt-5.1-codex-max",
|
||||
"gpt-5.2"
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos;
|
||||
|
||||
public class AiModelDescribe
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用id
|
||||
/// </summary>
|
||||
public Guid AppId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 应用名称
|
||||
/// </summary>
|
||||
public string AppName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 应用终结点
|
||||
/// </summary>
|
||||
public string Endpoint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 应用key
|
||||
/// </summary>
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int OrderNum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 处理名
|
||||
/// </summary>
|
||||
public string HandlerName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型id
|
||||
/// </summary>
|
||||
public string ModelId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型名称
|
||||
/// </summary>
|
||||
public string ModelName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型描述
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 额外url
|
||||
/// </summary>
|
||||
public string? AppExtraUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型额外信息
|
||||
/// </summary>
|
||||
public string? ModelExtraInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型倍率
|
||||
/// </summary>
|
||||
public decimal Multiplier { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.Anthropic;
|
||||
|
||||
public sealed class AnthropicCacheControl
|
||||
{
|
||||
[JsonPropertyName("type")]
|
||||
public string Type { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.Anthropic;
|
||||
|
||||
public class AnthropicStreamDto
|
||||
{
|
||||
[JsonPropertyName("type")] public string? Type { get; set; }
|
||||
|
||||
[JsonPropertyName("index")] public int? Index { get; set; }
|
||||
|
||||
[JsonPropertyName("content_block")] public AnthropicChatCompletionDtoContentBlock? ContentBlock { get; set; }
|
||||
|
||||
[JsonPropertyName("delta")] public AnthropicChatCompletionDtoDelta? Delta { get; set; }
|
||||
|
||||
[JsonPropertyName("message")] public AnthropicChatCompletionDto? Message { get; set; }
|
||||
|
||||
[JsonPropertyName("usage")] public AnthropicCompletionDtoUsage? Usage { get; set; }
|
||||
|
||||
[JsonPropertyName("error")] public AnthropicStreamErrorDto? Error { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public ThorUsageResponse TokenUsage => new ThorUsageResponse
|
||||
{
|
||||
PromptTokens = Usage?.InputTokens + Usage?.CacheCreationInputTokens + Usage?.CacheReadInputTokens,
|
||||
InputTokens = Usage?.InputTokens + Usage?.CacheCreationInputTokens + Usage?.CacheReadInputTokens,
|
||||
OutputTokens = Usage?.OutputTokens,
|
||||
InputTokensDetails = null,
|
||||
CompletionTokens = Usage?.OutputTokens,
|
||||
TotalTokens = Usage?.InputTokens + Usage?.CacheCreationInputTokens + Usage?.CacheReadInputTokens +
|
||||
Usage?.OutputTokens,
|
||||
PromptTokensDetails = null,
|
||||
CompletionTokensDetails = null
|
||||
};
|
||||
|
||||
|
||||
public void SupplementalMultiplier(decimal multiplier)
|
||||
{
|
||||
if (this.Usage is not null)
|
||||
{
|
||||
this.Usage.CacheCreationInputTokens =
|
||||
(int)Math.Round((this.Usage.CacheCreationInputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.CacheReadInputTokens =
|
||||
(int)Math.Round((this.Usage.CacheReadInputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.InputTokens =
|
||||
(int)Math.Round((this.Usage.InputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.OutputTokens =
|
||||
(int)Math.Round((this.Usage.OutputTokens ?? 0) * multiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AnthropicStreamErrorDto
|
||||
{
|
||||
[JsonPropertyName("type")] public string? Type { get; set; }
|
||||
|
||||
[JsonPropertyName("message")] public string? Message { get; set; }
|
||||
}
|
||||
|
||||
public class AnthropicChatCompletionDtoDelta
|
||||
{
|
||||
[JsonPropertyName("type")] public string? Type { get; set; }
|
||||
|
||||
[JsonPropertyName("text")] public string? Text { get; set; }
|
||||
|
||||
[JsonPropertyName("thinking")] public string? Thinking { get; set; }
|
||||
|
||||
[JsonPropertyName("partial_json")] public string? PartialJson { get; set; }
|
||||
|
||||
[JsonPropertyName("stop_reason")] public string? StopReason { get; set; }
|
||||
}
|
||||
|
||||
public class AnthropicChatCompletionDtoContentBlock
|
||||
{
|
||||
[JsonPropertyName("type")] public string? Type { get; set; }
|
||||
|
||||
[JsonPropertyName("thinking")] public string? Thinking { get; set; }
|
||||
|
||||
[JsonPropertyName("signature")] public string? Signature { get; set; }
|
||||
|
||||
[JsonPropertyName("id")] public string? Id { get; set; }
|
||||
|
||||
[JsonPropertyName("name")] public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("input")] public object? Input { get; set; }
|
||||
|
||||
[JsonPropertyName("server_name")] public string? ServerName { get; set; }
|
||||
|
||||
[JsonPropertyName("is_error")] public bool? IsError { get; set; }
|
||||
|
||||
[JsonPropertyName("tool_use_id")] public string? ToolUseId { get; set; }
|
||||
|
||||
[JsonPropertyName("content")] public object? Content { get; set; }
|
||||
|
||||
[JsonPropertyName("text")] public string? Text { get; set; }
|
||||
}
|
||||
|
||||
public class AnthropicChatCompletionDto
|
||||
{
|
||||
public string id { get; set; }
|
||||
|
||||
public string type { get; set; }
|
||||
|
||||
public string role { get; set; }
|
||||
|
||||
public AnthropicChatCompletionDtoContent[] content { get; set; }
|
||||
|
||||
public string model { get; set; }
|
||||
|
||||
public string stop_reason { get; set; }
|
||||
|
||||
public object stop_sequence { get; set; }
|
||||
|
||||
public AnthropicCompletionDtoUsage? Usage { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public ThorUsageResponse TokenUsage => new ThorUsageResponse
|
||||
{
|
||||
PromptTokens = Usage?.InputTokens + Usage?.CacheCreationInputTokens + Usage?.CacheReadInputTokens,
|
||||
InputTokens = Usage?.InputTokens + Usage?.CacheCreationInputTokens + Usage?.CacheReadInputTokens,
|
||||
OutputTokens = Usage?.OutputTokens,
|
||||
InputTokensDetails = null,
|
||||
CompletionTokens = Usage?.OutputTokens,
|
||||
TotalTokens = Usage?.InputTokens + Usage?.CacheCreationInputTokens + Usage?.CacheReadInputTokens +
|
||||
Usage?.OutputTokens,
|
||||
PromptTokensDetails = null,
|
||||
CompletionTokensDetails = null
|
||||
};
|
||||
|
||||
public void SupplementalMultiplier(decimal multiplier)
|
||||
{
|
||||
if (this.Usage is not null)
|
||||
{
|
||||
this.Usage.CacheCreationInputTokens =
|
||||
(int)Math.Round((this.Usage?.CacheCreationInputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.CacheReadInputTokens =
|
||||
(int)Math.Round((this.Usage?.CacheReadInputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.InputTokens =
|
||||
(int)Math.Round((this.Usage?.InputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.OutputTokens =
|
||||
(int)Math.Round((this.Usage?.OutputTokens ?? 0) * multiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AnthropicChatCompletionDtoContent
|
||||
{
|
||||
public string type { get; set; }
|
||||
|
||||
public string? text { get; set; }
|
||||
|
||||
public string? id { get; set; }
|
||||
|
||||
public string? name { get; set; }
|
||||
|
||||
public object? input { get; set; }
|
||||
|
||||
[JsonPropertyName("thinking")] public string? Thinking { get; set; }
|
||||
|
||||
[JsonPropertyName("partial_json")] public string? PartialJson { get; set; }
|
||||
|
||||
public string? signature { get; set; }
|
||||
}
|
||||
|
||||
public class AnthropicCompletionDtoUsage
|
||||
{
|
||||
[JsonPropertyName("input_tokens")] public int? InputTokens { get; set; }
|
||||
|
||||
[JsonPropertyName("cache_creation_input_tokens")]
|
||||
public int? CacheCreationInputTokens { get; set; }
|
||||
|
||||
[JsonPropertyName("cache_read_input_tokens")]
|
||||
public int? CacheReadInputTokens { get; set; }
|
||||
|
||||
[JsonPropertyName("output_tokens")] public int? OutputTokens { get; set; }
|
||||
|
||||
[JsonPropertyName("server_tool_use")] public AnthropicServerToolUse? ServerToolUse { get; set; }
|
||||
}
|
||||
|
||||
public class AnthropicServerToolUse
|
||||
{
|
||||
[JsonPropertyName("web_search_requests")]
|
||||
public int? WebSearchRequests { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.Anthropic;
|
||||
|
||||
public sealed class AnthropicInput
|
||||
{
|
||||
[JsonPropertyName("stream")] public bool Stream { get; set; }
|
||||
|
||||
[JsonPropertyName("model")] public string Model { get; set; }
|
||||
|
||||
[JsonPropertyName("max_tokens")] public int? MaxTokens { get; set; }
|
||||
|
||||
[JsonPropertyName("messages")] public IList<AnthropicMessageInput> Messages { get; set; }
|
||||
|
||||
[JsonPropertyName("tools")] public IList<AnthropicMessageTool>? Tools { get; set; }
|
||||
|
||||
[JsonPropertyName("tool_choice")]
|
||||
public object? ToolChoiceCalculated
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(ToolChoiceString))
|
||||
{
|
||||
return ToolChoiceString;
|
||||
}
|
||||
|
||||
if (ToolChoice?.Type == "function")
|
||||
{
|
||||
return ToolChoice;
|
||||
}
|
||||
|
||||
return ToolChoice?.Type;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value is JsonElement jsonElement)
|
||||
{
|
||||
if (jsonElement.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
ToolChoiceString = jsonElement.GetString();
|
||||
}
|
||||
else if (jsonElement.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
ToolChoice = jsonElement.Deserialize<AnthropicTooChoiceInput>(ThorJsonSerializer.DefaultOptions);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ToolChoice = (AnthropicTooChoiceInput)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore] public string? ToolChoiceString { get; set; }
|
||||
|
||||
[JsonIgnore] public AnthropicTooChoiceInput? ToolChoice { get; set; }
|
||||
|
||||
[JsonIgnore] public IList<AnthropicMessageContent>? Systems { get; set; }
|
||||
|
||||
[JsonIgnore] public string? System { get; set; }
|
||||
|
||||
[JsonPropertyName("system")]
|
||||
public object? SystemCalculated
|
||||
{
|
||||
get
|
||||
{
|
||||
if (System is not null && Systems is not null)
|
||||
{
|
||||
throw new ValidationException("System 和 Systems 字段不能同时有值");
|
||||
}
|
||||
|
||||
if (System is not null)
|
||||
{
|
||||
return System;
|
||||
}
|
||||
|
||||
return Systems!;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value is JsonElement str)
|
||||
{
|
||||
if (str.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
System = value?.ToString();
|
||||
}
|
||||
else if (str.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
Systems = JsonSerializer.Deserialize<IList<AnthropicMessageContent>>(value?.ToString(),
|
||||
ThorJsonSerializer.DefaultOptions);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System = value?.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("thinking")] public AnthropicThinkingInput? Thinking { get; set; }
|
||||
|
||||
[JsonPropertyName("temperature")] public double? Temperature { get; set; }
|
||||
|
||||
[JsonPropertyName("metadata")] public Dictionary<string, object>? Metadata { get; set; }
|
||||
}
|
||||
|
||||
public class AnthropicThinkingInput
|
||||
{
|
||||
[JsonPropertyName("type")] public string? Type { get; set; }
|
||||
[JsonPropertyName("budget_tokens")] public int? BudgetTokens { get; set; }
|
||||
|
||||
[JsonPropertyName("signature")] public string? Signature { get; set; }
|
||||
|
||||
[JsonPropertyName("thinking")] public string? Thinking { get; set; }
|
||||
|
||||
[JsonPropertyName("data")] public string? Data { get; set; }
|
||||
|
||||
[JsonPropertyName("text")] public string? Text { get; set; }
|
||||
}
|
||||
|
||||
public class AnthropicTooChoiceInput
|
||||
{
|
||||
[JsonPropertyName("type")] public string? Type { get; set; }
|
||||
|
||||
[JsonPropertyName("name")] public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public class AnthropicMessageTool
|
||||
{
|
||||
[JsonPropertyName("name")] public string? name { get; set; }
|
||||
|
||||
[JsonPropertyName("description")] public string? Description { get; set; }
|
||||
|
||||
[JsonPropertyName("input_schema")] public Input_schema? InputSchema { get; set; }
|
||||
}
|
||||
|
||||
public class Input_schema
|
||||
{
|
||||
[JsonPropertyName("type")] public string? Type { get; set; }
|
||||
|
||||
[JsonPropertyName("properties")] public Dictionary<string, InputSchemaValue>? Properties { get; set; }
|
||||
|
||||
[JsonPropertyName("required")] public string[]? Required { get; set; }
|
||||
}
|
||||
|
||||
public class InputSchemaValue
|
||||
{
|
||||
public string? type { get; set; }
|
||||
|
||||
public string? description { get; set; }
|
||||
|
||||
public InputSchemaValueItems? items { get; set; }
|
||||
}
|
||||
|
||||
public class InputSchemaValueItems
|
||||
{
|
||||
public string? type { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.Anthropic;
|
||||
|
||||
public class AnthropicMessageContent
|
||||
{
|
||||
[JsonPropertyName("cache_control")] public AnthropicCacheControl? CacheControl { get; set; }
|
||||
|
||||
[JsonPropertyName("type")] public string Type { get; set; }
|
||||
|
||||
[JsonPropertyName("text")] public string? Text { get; set; }
|
||||
|
||||
[JsonPropertyName("tool_use_id")] public string? ToolUseId { get; set; }
|
||||
|
||||
[JsonPropertyName("name")] public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("id")] public string? Id { get; set; }
|
||||
|
||||
[JsonPropertyName("thinking")] public string? Thinking { get; set; }
|
||||
|
||||
[JsonPropertyName("signature")] public string? Signature { get; set; }
|
||||
|
||||
[JsonPropertyName("input")] public object? Input { get; set; }
|
||||
|
||||
[JsonPropertyName("content")]
|
||||
public object? Content
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_content is not null && _contents is not null)
|
||||
{
|
||||
throw new ValidationException("Messages 中 Content 和 Contents 字段不能同时有值");
|
||||
}
|
||||
|
||||
if (_content is not null)
|
||||
{
|
||||
return _content;
|
||||
}
|
||||
|
||||
return _contents;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value is JsonElement str)
|
||||
{
|
||||
if (str.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
_content = value?.ToString();
|
||||
}
|
||||
else if (str.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
_contents = JsonSerializer.Deserialize<List<AnthropicMessageContent>>(value?.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_content = value?.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string? _content;
|
||||
|
||||
private List<AnthropicMessageContent>? _contents;
|
||||
|
||||
public class AnthropicMessageContentSource
|
||||
{
|
||||
[JsonPropertyName("type")] public string Type { get; set; }
|
||||
|
||||
[JsonPropertyName("media_type")] public string? MediaType { get; set; }
|
||||
|
||||
[JsonPropertyName("data")] public string? Data { get; set; }
|
||||
}
|
||||
|
||||
[JsonPropertyName("source")] public AnthropicMessageContentSource? Source { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.Anthropic;
|
||||
|
||||
public class AnthropicMessageInput
|
||||
{
|
||||
[JsonPropertyName("role")]
|
||||
public string Role { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public string? Content;
|
||||
|
||||
[JsonPropertyName("content")]
|
||||
public object? ContentCalculated
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Content is not null && Contents is not null)
|
||||
{
|
||||
throw new ValidationException("Messages 中 Content 和 Contents 字段不能同时有值");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Content))
|
||||
{
|
||||
return Content;
|
||||
}
|
||||
// 如果 Contents 为空或 null,返回空字符串而不是 null
|
||||
if (Contents == null || Contents.Count == 0)
|
||||
{
|
||||
return "_"; // 兼容客户端空值问题
|
||||
}
|
||||
return Contents!;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value is JsonElement str)
|
||||
{
|
||||
if (str.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
Content = value?.ToString();
|
||||
}
|
||||
else if (str.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
Contents = JsonSerializer.Deserialize<IList<AnthropicMessageContent>>(value?.ToString(),ThorJsonSerializer.DefaultOptions);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Content = value?.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public IList<AnthropicMessageContent>? Contents;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.Anthropic;
|
||||
|
||||
public static class ThorJsonSerializer
|
||||
{
|
||||
public static JsonSerializerOptions DefaultOptions => new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos;
|
||||
|
||||
public class MessageInputDto
|
||||
{
|
||||
public string? Content { get; set; }
|
||||
public string Role { get; set; }
|
||||
public string ModelId { get; set; }
|
||||
public string? Remark { get; set; }
|
||||
|
||||
public ThorUsageResponse? TokenUsage { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi.Embeddings;
|
||||
|
||||
//TODO add model validation
|
||||
//TODO check what is string or array for prompt,..
|
||||
public record EmbeddingCreateRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Input text to get embeddings for, encoded as a string or array of tokens. To get embeddings for multiple inputs
|
||||
/// in a single request, pass an array of strings or array of token arrays. Each input must not exceed 2048 tokens in
|
||||
/// length.
|
||||
/// Unless your are embedding code, we suggest replacing newlines (`\n`) in your input with a single space, as we have
|
||||
/// observed inferior results when newlines are present.
|
||||
/// </summary>
|
||||
/// <see href="https://platform.openai.com/docs/api-reference/embeddings/create#embeddings/create-input" />
|
||||
[JsonIgnore]
|
||||
public List<string>? InputAsList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Input text to get embeddings for, encoded as a string or array of tokens. To get embeddings for multiple inputs
|
||||
/// in a single request, pass an array of strings or array of token arrays. Each input must not exceed 2048 tokens in
|
||||
/// length.
|
||||
/// Unless your are embedding code, we suggest replacing newlines (`\n`) in your input with a single space, as we have
|
||||
/// observed inferior results when newlines are present.
|
||||
/// </summary>
|
||||
/// <see href="https://platform.openai.com/docs/api-reference/embeddings/create#embeddings/create-input" />
|
||||
[JsonIgnore]
|
||||
public string? Input { get; set; }
|
||||
|
||||
|
||||
[JsonPropertyName("input")]
|
||||
public IList<string>? InputCalculated
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Input != null && InputAsList != null)
|
||||
{
|
||||
throw new ValidationException(
|
||||
"Input and InputAsList can not be assigned at the same time. One of them is should be null.");
|
||||
}
|
||||
|
||||
if (Input != null)
|
||||
{
|
||||
return new List<string> { Input };
|
||||
}
|
||||
|
||||
return InputAsList;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your
|
||||
/// available models, or see our [Model overview](/docs/models/overview) for descriptions of them.
|
||||
/// </summary>
|
||||
/// <see href="https://platform.openai.com/docs/api-reference/embeddings/create#embeddings/create-model" />
|
||||
[JsonPropertyName("model")]
|
||||
public string? Model { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.
|
||||
/// </summary>
|
||||
/// <see href="https://platform.openai.com/docs/api-reference/embeddings/create#embeddings-create-dimensions" />
|
||||
[JsonPropertyName("dimensions")]
|
||||
public int? Dimensions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The format to return the embeddings in. Can be either float or base64.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[JsonPropertyName("encoding_format")]
|
||||
public string? EncodingFormat { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using System.Buffers;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi.Embeddings;
|
||||
|
||||
public record EmbeddingCreateResponse : ThorBaseResponse
|
||||
{
|
||||
[JsonPropertyName("model")] public string Model { get; set; }
|
||||
|
||||
[JsonPropertyName("data")] public List<EmbeddingResponse> Data { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 类型转换,如果类型是base64,则将float[]转换为base64,如果是空或是float和原始类型一样,则不转换
|
||||
/// </summary>
|
||||
public void ConvertEmbeddingData(string? encodingFormat)
|
||||
{
|
||||
if (Data.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (encodingFormat)
|
||||
{
|
||||
// 判断第一个是否是float[],如果是则不转换
|
||||
case null or "float" when Data[0].Embedding is float[]:
|
||||
return;
|
||||
// 否则转换成float[]
|
||||
case null or "float":
|
||||
{
|
||||
foreach (var embeddingResponse in Data)
|
||||
{
|
||||
if (embeddingResponse.Embedding is string base64)
|
||||
{
|
||||
embeddingResponse.Embedding = Convert.FromBase64String(base64);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
// 判断第一个是否是string,如果是则不转换
|
||||
case "base64" when Data[0].Embedding is string:
|
||||
return;
|
||||
// 否则转换成base64
|
||||
case "base64":
|
||||
{
|
||||
foreach (var embeddingResponse in Data)
|
||||
{
|
||||
if (embeddingResponse.Embedding is JsonElement str)
|
||||
{
|
||||
if (str.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
var floats = str.EnumerateArray().Select(element => element.GetSingle()).ToArray();
|
||||
|
||||
embeddingResponse.Embedding = ConvertFloatArrayToBase64(floats);
|
||||
}
|
||||
}
|
||||
else if (embeddingResponse.Embedding is IList<double> doubles)
|
||||
{
|
||||
embeddingResponse.Embedding = ConvertFloatArrayToBase64(doubles.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConvertFloatArrayToBase64(double[] floatArray)
|
||||
{
|
||||
// 将 float[] 转换成 byte[]
|
||||
byte[] byteArray = ArrayPool<byte>.Shared.Rent(floatArray.Length * sizeof(float));
|
||||
try
|
||||
{
|
||||
Buffer.BlockCopy(floatArray, 0, byteArray, 0, byteArray.Length);
|
||||
|
||||
// 将 byte[] 转换成 base64 字符串
|
||||
return Convert.ToBase64String(byteArray);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(byteArray);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConvertFloatArrayToBase64(float[] floatArray)
|
||||
{
|
||||
// 将 float[] 转换成 byte[]
|
||||
byte[] byteArray = ArrayPool<byte>.Shared.Rent(floatArray.Length * sizeof(float));
|
||||
try
|
||||
{
|
||||
Buffer.BlockCopy(floatArray, 0, byteArray, 0, floatArray.Length);
|
||||
|
||||
// 将 byte[] 转换成 base64 字符串
|
||||
return Convert.ToBase64String(byteArray);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(byteArray);
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("usage")] public ThorUsageResponse? Usage { get; set; }
|
||||
}
|
||||
|
||||
public record EmbeddingResponse
|
||||
{
|
||||
[JsonPropertyName("object")] public string Object { get; set; } = "embedding";
|
||||
|
||||
[JsonPropertyName("index")] public int? Index { get; set; }
|
||||
|
||||
[JsonPropertyName("embedding")] public object Embedding { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi.Embeddings;
|
||||
|
||||
public sealed class ThorEmbeddingInput
|
||||
{
|
||||
[JsonPropertyName("model")]
|
||||
public string Model { get; set; }
|
||||
|
||||
[JsonPropertyName("input")]
|
||||
public object Input { get; set; }
|
||||
|
||||
[JsonPropertyName("encoding_format")]
|
||||
public string? EncodingFormat { get; set; }
|
||||
|
||||
[JsonPropertyName("dimensions")]
|
||||
public int? Dimensions { get; set; }
|
||||
|
||||
[JsonPropertyName("user")]
|
||||
public string? User { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi.Images;
|
||||
|
||||
/// <summary>
|
||||
/// Image Create Request Model
|
||||
/// </summary>
|
||||
public record ImageCreateRequest : SharedImageRequestBaseModel
|
||||
{
|
||||
public ImageCreateRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public ImageCreateRequest(string prompt)
|
||||
{
|
||||
Prompt = prompt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A text description of the desired image(s). The maximum length is 1000 characters for dall-e-2 and 4000 characters for dall-e-3
|
||||
/// </summary>
|
||||
[JsonPropertyName("prompt")]
|
||||
public string Prompt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The quality of the image that will be generated. Possible values are 'standard' or 'hd' (default is 'standard').
|
||||
/// Hd creates images with finer details and greater consistency across the image.
|
||||
/// This param is only supported for dall-e-3 model.
|
||||
/// <br /><br />Check <see cref="StaticValues.ImageStatics.Quality"/> for possible values
|
||||
/// </summary>
|
||||
[JsonPropertyName("quality")]
|
||||
public string? Quality { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The style of the generated images. Must be one of vivid or natural.
|
||||
/// Vivid causes the model to lean towards generating hyper-real and dramatic images.
|
||||
/// Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported for dall-e-3.
|
||||
/// <br /><br />Check <see cref="StaticValues.ImageStatics.Style"/> for possible values
|
||||
/// </summary>
|
||||
[JsonPropertyName("style")]
|
||||
public string? Style { get; set; }
|
||||
|
||||
[JsonPropertyName("background")]
|
||||
public string? Background { get; set; }
|
||||
|
||||
[JsonPropertyName("moderation")]
|
||||
public string? Moderation { get; set; }
|
||||
|
||||
[JsonPropertyName("output_compression")]
|
||||
public string? OutputCompression { get; set; }
|
||||
|
||||
[JsonPropertyName("output_format")]
|
||||
public string? OutputFormat { get; set; }
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user