This commit is contained in:
ditiqi 2025-02-28 09:23:36 +08:00
parent e7013895ef
commit 5c5d08c1d6
6 changed files with 39 additions and 19 deletions

View File

@ -9,17 +9,22 @@ export class VisitService extends BaseService<Prisma.VisitDelegate> {
} }
async create(args: Prisma.VisitCreateArgs, staff?: UserProfile) { async create(args: Prisma.VisitCreateArgs, staff?: UserProfile) {
const { postId, lectureId, messageId } = args.data; const { postId, lectureId, messageId } = args.data;
const visitorId = args.data.visitorId || staff?.id; const visitorId = args.data?.visitorId || staff?.id;
let result; let result;
console.log(args.data.type);
console.log(visitorId);
console.log(postId);
const existingVisit = await db.visit.findFirst({ const existingVisit = await db.visit.findFirst({
where: { where: {
type: args.data.type, type: args.data.type,
visitorId, // visitorId: visitorId ? visitorId : null,
OR: [{ postId }, { lectureId }, { messageId }], OR: [{ postId }, { messageId }],
}, },
}); });
console.log('result', existingVisit);
if (!existingVisit) { if (!existingVisit) {
result = await super.create(args); result = await super.create(args);
console.log('createdResult', result);
} else if (args.data.type === VisitType.READED) { } else if (args.data.type === VisitType.READED) {
result = await super.update({ result = await super.update({
where: { id: existingVisit.id }, where: { id: existingVisit.id },

View File

@ -31,6 +31,7 @@ export class GenDevService {
domainDepts: Record<string, Department[]> = {}; domainDepts: Record<string, Department[]> = {};
staffs: Staff[] = []; staffs: Staff[] = [];
deptGeneratedCount = 0; deptGeneratedCount = 0;
courseGeneratedCount = 1;
constructor( constructor(
private readonly appConfigService: AppConfigService, private readonly appConfigService: AppConfigService,
@ -194,8 +195,9 @@ export class GenDevService {
cate.id, cate.id,
randomLevelId, randomLevelId,
); );
this.courseGeneratedCount++;
this.logger.log( this.logger.log(
`Generated ${this.deptGeneratedCount}/${total} departments`, `Generated ${this.courseGeneratedCount}/${total} course`,
); );
} }
} }

View File

@ -1,4 +1,3 @@
import { Input, Layout, Avatar, Button, Dropdown } from "antd"; import { Input, Layout, Avatar, Button, Dropdown } from "antd";
import { import {
EditFilled, EditFilled,
@ -30,7 +29,6 @@ export function MainHeader() {
<NavigationMenu /> <NavigationMenu />
</div> </div>
{/* 右侧区域 - 可以灵活收缩 */} {/* 右侧区域 - 可以灵活收缩 */}
<div className="flex justify-end gap-2 md:gap-4 flex-shrink"> <div className="flex justify-end gap-2 md:gap-4 flex-shrink">
<div className="flex items-center gap-2 md:gap-4"> <div className="flex items-center gap-2 md:gap-4">
@ -43,7 +41,9 @@ export function MainHeader() {
className="w-full md:w-96 rounded-full" className="w-full md:w-96 rounded-full"
value={searchValue} value={searchValue}
onClick={(e) => { onClick={(e) => {
if (!window.location.pathname.startsWith("/search")) { if (
!window.location.pathname.startsWith("/search")
) {
navigate(`/search`); navigate(`/search`);
window.scrollTo({ window.scrollTo({
top: 0, top: 0,
@ -53,7 +53,9 @@ export function MainHeader() {
}} }}
onChange={(e) => setSearchValue(e.target.value)} onChange={(e) => setSearchValue(e.target.value)}
onPressEnter={(e) => { onPressEnter={(e) => {
if (!window.location.pathname.startsWith("/search")) { if (
!window.location.pathname.startsWith("/search")
) {
navigate(`/search`); navigate(`/search`);
window.scrollTo({ window.scrollTo({
top: 0, top: 0,
@ -74,8 +76,7 @@ export function MainHeader() {
: "/course/editor"; : "/course/editor";
navigate(url); navigate(url);
}} }}
type="primary" type="primary">
>
{id ? "编辑课程" : "创建课程"} {id ? "编辑课程" : "创建课程"}
</Button> </Button>
</> </>
@ -87,7 +88,8 @@ export function MainHeader() {
onClick={() => { onClick={() => {
window.location.href = "/path/editor"; window.location.href = "/path/editor";
}} }}
ghost type="primary" ghost
type="primary"
icon={<PlusOutlined></PlusOutlined>}> icon={<PlusOutlined></PlusOutlined>}>
</Button> </Button>
@ -100,7 +102,6 @@ export function MainHeader() {
size="large" size="large"
shape="round" shape="round"
onClick={() => navigate("/login")} onClick={() => navigate("/login")}
icon={<UserOutlined />}> icon={<UserOutlined />}>
</Button> </Button>
@ -110,4 +111,3 @@ export function MainHeader() {
</div> </div>
); );
} }

View File

@ -79,17 +79,28 @@ export function CourseDetailProvider({
); );
useEffect(() => { useEffect(() => {
if (lecture?.id) { if (lectureId) {
console.log(123); console.log(123);
console.log(lectureId);
read.mutateAsync({ read.mutateAsync({
data: { data: {
visitorId: user?.id || null, visitorId: user?.id || null,
postId: lecture?.id, postId: lectureId,
type: VisitType.READED,
},
});
} else {
console.log(321);
console.log(editId);
read.mutateAsync({
data: {
visitorId: user?.id || null,
postId: editId,
type: VisitType.READED, type: VisitType.READED,
}, },
}); });
} }
}, [course]); }, [editId, lectureId]);
useEffect(() => { useEffect(() => {
if (lectureId !== selectedLectureId) { if (lectureId !== selectedLectureId) {
navigate(`/course/${editId}/detail/${selectedLectureId}`); navigate(`/course/${editId}/detail/${selectedLectureId}`);

View File

@ -54,7 +54,9 @@ export default function CourseDetailTitle() {
<div className="flex gap-1"> <div className="flex gap-1">
<EyeOutlined></EyeOutlined> <EyeOutlined></EyeOutlined>
<div>{`观看次数${ <div>{`观看次数${
!selectedLectureId ? course?.views : lecture?.views || 0 !selectedLectureId
? course?.views || 0
: lecture?.views || 0
}`}</div> }`}</div>
</div> </div>
<div className="flex gap-1"> <div className="flex gap-1">

View File

@ -286,8 +286,8 @@ model Visit {
views Int @default(1) @map("views") views Int @default(1) @map("views")
// sourceIP String? @map("source_ip") // sourceIP String? @map("source_ip")
// 关联关系 // 关联关系
visitorId String @map("visitor_id") visitorId String? @map("visitor_id")
visitor Staff @relation(fields: [visitorId], references: [id]) visitor Staff? @relation(fields: [visitorId], references: [id])
postId String? @map("post_id") postId String? @map("post_id")
post Post? @relation(fields: [postId], references: [id]) post Post? @relation(fields: [postId], references: [id])
message Message? @relation(fields: [messageId], references: [id]) message Message? @relation(fields: [messageId], references: [id])