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) {
const { postId, lectureId, messageId } = args.data;
const visitorId = args.data.visitorId || staff?.id;
const visitorId = args.data?.visitorId || staff?.id;
let result;
console.log(args.data.type);
console.log(visitorId);
console.log(postId);
const existingVisit = await db.visit.findFirst({
where: {
type: args.data.type,
visitorId,
OR: [{ postId }, { lectureId }, { messageId }],
// visitorId: visitorId ? visitorId : null,
OR: [{ postId }, { messageId }],
},
});
console.log('result', existingVisit);
if (!existingVisit) {
result = await super.create(args);
console.log('createdResult', result);
} else if (args.data.type === VisitType.READED) {
result = await super.update({
where: { id: existingVisit.id },

View File

@ -31,6 +31,7 @@ export class GenDevService {
domainDepts: Record<string, Department[]> = {};
staffs: Staff[] = [];
deptGeneratedCount = 0;
courseGeneratedCount = 1;
constructor(
private readonly appConfigService: AppConfigService,
@ -194,8 +195,9 @@ export class GenDevService {
cate.id,
randomLevelId,
);
this.courseGeneratedCount++;
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 {
EditFilled,
@ -30,7 +29,6 @@ export function MainHeader() {
<NavigationMenu />
</div>
{/* 右侧区域 - 可以灵活收缩 */}
<div className="flex justify-end gap-2 md:gap-4 flex-shrink">
<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"
value={searchValue}
onClick={(e) => {
if (!window.location.pathname.startsWith("/search")) {
if (
!window.location.pathname.startsWith("/search")
) {
navigate(`/search`);
window.scrollTo({
top: 0,
@ -53,7 +53,9 @@ export function MainHeader() {
}}
onChange={(e) => setSearchValue(e.target.value)}
onPressEnter={(e) => {
if (!window.location.pathname.startsWith("/search")) {
if (
!window.location.pathname.startsWith("/search")
) {
navigate(`/search`);
window.scrollTo({
top: 0,
@ -74,8 +76,7 @@ export function MainHeader() {
: "/course/editor";
navigate(url);
}}
type="primary"
>
type="primary">
{id ? "编辑课程" : "创建课程"}
</Button>
</>
@ -87,7 +88,8 @@ export function MainHeader() {
onClick={() => {
window.location.href = "/path/editor";
}}
ghost type="primary"
ghost
type="primary"
icon={<PlusOutlined></PlusOutlined>}>
</Button>
@ -100,7 +102,6 @@ export function MainHeader() {
size="large"
shape="round"
onClick={() => navigate("/login")}
icon={<UserOutlined />}>
</Button>
@ -110,4 +111,3 @@ export function MainHeader() {
</div>
);
}

View File

@ -79,17 +79,28 @@ export function CourseDetailProvider({
);
useEffect(() => {
if (lecture?.id) {
if (lectureId) {
console.log(123);
console.log(lectureId);
read.mutateAsync({
data: {
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,
},
});
}
}, [course]);
}, [editId, lectureId]);
useEffect(() => {
if (lectureId !== selectedLectureId) {
navigate(`/course/${editId}/detail/${selectedLectureId}`);

View File

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

View File

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