bug修复

This commit is contained in:
张锐 committed 2026-11-25 18:10:14 +08:00
1 parent 4dfce9b521
commit 75f67bf08c
7 files changed
+67 -19

No files matched your search

@@ -36,9 +36,14 @@ public class ContentRepositoryService {
/** 统计站点指定类型及发布状态的内容。 */ public long countByStatus(String siteCode, String type, String status) { return mapper.selectCount(Wrappers.<ContentEntity>lambdaQuery().eq(ContentEntity::getSiteCode, siteCode).eq(ContentEntity::getDeleted, 0).eq(ContentEntity::getContentType, type).eq(ContentEntity::getStatus, status)); } /** 统计站点指定类型及发布状态的内容。 */ public long countByStatus(String siteCode, String type, String status) { return mapper.selectCount(Wrappers.<ContentEntity>lambdaQuery().eq(ContentEntity::getSiteCode, siteCode).eq(ContentEntity::getDeleted, 0).eq(ContentEntity::getContentType, type).eq(ContentEntity::getStatus, status)); }
/** 查询站点指定类型的已发布内容列表。 */ /** 查询站点指定类型的已发布内容列表。 */
public List<ContentEntity> listPublished(String siteCode, String type) { public List<ContentEntity> listPublished(String siteCode, String type) {
return mapper.selectList(Wrappers.<ContentEntity>lambdaQuery().eq(ContentEntity::getSiteCode, siteCode) return listPublished(siteCode, type, null);
.eq(ContentEntity::getContentType, type).eq(ContentEntity::getStatus, "PUBLISHED") }
.orderByDesc(ContentEntity::getFeaturedFlag).orderByDesc(ContentEntity::getPublishTime)); /** 按分类查询站点指定类型的已发布内容列表。 */
public List<ContentEntity> listPublished(String siteCode, String type, String categoryCode) {
var query = Wrappers.<ContentEntity>lambdaQuery().eq(ContentEntity::getSiteCode, siteCode)
.eq(ContentEntity::getContentType, type).eq(ContentEntity::getStatus, "PUBLISHED");
if (categoryCode != null && !categoryCode.isBlank()) query.eq(ContentEntity::getPrimaryCategoryCode, categoryCode);
return mapper.selectList(query.orderByDesc(ContentEntity::getFeaturedFlag).orderByDesc(ContentEntity::getPublishTime));
} }
/** 新增内容。 */ public int insert(ContentEntity entity) { return mapper.insert(entity); } /** 新增内容。 */ public int insert(ContentEntity entity) { return mapper.insert(entity); }
/** 按内容业务编号更新。 */ /** 按内容业务编号更新。 */
@@ -12,7 +12,7 @@ import org.springframework.stereotype.Component;
public class SiteContentFacade { public class SiteContentFacade {
private final SiteContentService service; private final SiteContentService service;
/** 注入内容业务。 */ public SiteContentFacade(SiteContentService service) { this.service = service; } /** 注入内容业务。 */ public SiteContentFacade(SiteContentService service) { this.service = service; }
/** 查询内容列表。 */ public ContentListSiteRes list(ContentListSiteReq req) { return service.list(req.contentType().name()); } /** 查询内容列表。 */ public ContentListSiteRes list(ContentListSiteReq req) { return service.list(req.contentType().name(), req.categoryCode()); }
/** 查询内容详情。 */ public ContentDetailSiteRes detail(ContentDetailSiteReq req) { return service.detail(req.contentType().name(), req.slug()); } /** 查询内容详情。 */ public ContentDetailSiteRes detail(ContentDetailSiteReq req) { return service.detail(req.contentType().name(), req.slug()); }
} }
@@ -2,8 +2,11 @@ package com.shoplix.site.modules.content.req;
import com.shoplix.modules.content.enums.ContentTypeEnum; import com.shoplix.modules.content.enums.ContentTypeEnum;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
/** 前台站内容列表请求。 */ /** 前台站内容列表请求。 */
public record ContentListSiteReq(@NotNull ContentTypeEnum contentType) { public record ContentListSiteReq(
/** 内容类型。 */ @NotNull ContentTypeEnum contentType,
/** 分类业务编号,为空时查询全部分类。 */ @Size(max = 16) String categoryCode) {
} }
@@ -20,8 +20,8 @@ public class SiteContentService {
this.repository = repository; this.mediaRepository = mediaRepository; this.repository = repository; this.mediaRepository = mediaRepository;
} }
/** 查询当前站点指定类型已发布内容。 */ /** 查询当前站点指定类型已发布内容。 */
public ContentListSiteRes list(String type) { public ContentListSiteRes list(String type, String categoryCode) {
List<ContentItemSiteRes> items = repository.listPublished(SiteContextHolder.getRequired().siteCode(), type).stream() List<ContentItemSiteRes> items = repository.listPublished(SiteContextHolder.getRequired().siteCode(), type, categoryCode).stream()
.map(item -> new ContentItemSiteRes(item.getContentCode(), item.getContentType(), item.getTitle(), item.getSlug(), .map(item -> new ContentItemSiteRes(item.getContentCode(), item.getContentType(), item.getTitle(), item.getSlug(),
item.getSummary(), item.getCoverMediaCode(), resolveMediaUrl(item), item.getPublishTime())).toList(); item.getSummary(), item.getCoverMediaCode(), resolveMediaUrl(item), item.getPublishTime())).toList();
return new ContentListSiteRes(items); return new ContentListSiteRes(items);
@@ -0,0 +1,35 @@
package com.shoplix.site.facade;
import com.shoplix.modules.content.enums.ContentTypeEnum;
import com.shoplix.site.modules.content.req.ContentListSiteReq;
import com.shoplix.site.modules.content.res.ContentListSiteRes;
import com.shoplix.site.service.SiteContentService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** 前台内容分类查询参数测试。 */
@ExtendWith(MockitoExtension.class)
class SiteContentFacadeTest {
@Mock private SiteContentService service;
/** 内容列表查询应将类型和分类编号完整传递给业务服务。 */
@Test
void passesCategoryCodeToContentService() {
ContentListSiteRes expected = new ContentListSiteRes(List.of());
when(service.list("NEWS", "CCT0000000000001")).thenReturn(expected);
SiteContentFacade facade = new SiteContentFacade(service);
ContentListSiteRes actual = facade.list(new ContentListSiteReq(ContentTypeEnum.NEWS, "CCT0000000000001"));
assertSame(expected, actual);
verify(service).list("NEWS", "CCT0000000000001");
}
}
+2 -2
View File
@@ -170,7 +170,7 @@ export default function NavigationManager() {
type: "PRODUCT_CATEGORY", type: "PRODUCT_CATEGORY",
code: category.categoryCode, code: category.categoryCode,
label: category.categoryName, label: category.categoryName,
url: `/products/category/${category.slug}`, url: `/products?category=${category.categoryCode}`,
}), }),
); );
value(2).forEach((product: any) => value(2).forEach((product: any) =>
@@ -209,7 +209,7 @@ export default function NavigationManager() {
type: meta.categoryType, type: meta.categoryType,
code: category.categoryCode, code: category.categoryCode,
label: category.categoryName, label: category.categoryName,
url: `/${meta.prefix}/category/${category.slug}`, url: `/${meta.prefix}?category=${category.categoryCode}`,
}), }),
); );
value(4 + offset * 2).forEach((content: any) => value(4 + offset * 2).forEach((content: any) =>
+15 -10
View File
@@ -165,6 +165,7 @@ function usePageSeo(pageType: string, targetCode = "") {
}, [pageType, targetCode]); }, [pageType, targetCode]);
} }
const nav = [ const nav = [
["Home", "/"],
["Products", "/products"], ["Products", "/products"],
["Cases", "/cases"], ["Cases", "/cases"],
["News", "/news"], ["News", "/news"],
@@ -193,11 +194,13 @@ function NavigationLinks({ items }: { items: NavigationItem[] }) {
} }
function route() { function route() {
const p = location.pathname.split("/").filter(Boolean); const p = location.pathname.split("/").filter(Boolean);
const previewPage = new URLSearchParams(location.search).get("previewPage") || undefined; const parameters = new URLSearchParams(location.search);
if (!p.length) return { kind: "home", previewPage }; const previewPage = parameters.get("previewPage") || undefined;
const categoryCode = parameters.get("category") || undefined;
if (!p.length) return { kind: "home", previewPage, categoryCode };
if (["products", "news", "cases", "help"].includes(p[0])) if (["products", "news", "cases", "help"].includes(p[0]))
return { kind: p[0], slug: p[1], previewPage }; return { kind: p[0], slug: p[1], previewPage, categoryCode };
return { kind: "page", slug: p[0], previewPage }; return { kind: "page", slug: p[0], previewPage, categoryCode };
} }
function App() { function App() {
const r = route(); const r = route();
@@ -212,10 +215,10 @@ function App() {
const runtime = <CustomCodeRuntime />; const runtime = <CustomCodeRuntime />;
const seoRuntime = <SeoRuntime current={r} />; const seoRuntime = <SeoRuntime current={r} />;
if (r.kind === "home") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || "HOME"} fallback={<><Header /><main><Home /></main><Footer /></>} /></>; if (r.kind === "home") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || "HOME"} fallback={<><Header /><main><Home /></main><Footer /></>} /></>;
if (r.kind === "products") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "PRODUCT_DETAIL" : "PRODUCT_CATEGORY")} fallback={<><Header /><main><Collection title="Products" type="products" slug={r.slug} /></main><Footer /></>} /></>; if (r.kind === "products") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "PRODUCT_DETAIL" : "PRODUCT_CATEGORY")} fallback={<><Header /><main><Collection title="Products" type="products" slug={r.slug} categoryCode={r.categoryCode} /></main><Footer /></>} /></>;
if (r.kind === "news") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "NEWS_DETAIL" : "NEWS_CATEGORY")} fallback={<><Header /><main><Collection title="News" type="NEWS" slug={r.slug} /></main><Footer /></>} /></>; if (r.kind === "news") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "NEWS_DETAIL" : "NEWS_CATEGORY")} fallback={<><Header /><main><Collection title="News" type="NEWS" slug={r.slug} categoryCode={r.categoryCode} /></main><Footer /></>} /></>;
if (r.kind === "cases") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "CASE_DETAIL" : "CASE_CATEGORY")} fallback={<><Header /><main><Collection title="Case Studies" type="CASE" slug={r.slug} /></main><Footer /></>} /></>; if (r.kind === "cases") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "CASE_DETAIL" : "CASE_CATEGORY")} fallback={<><Header /><main><Collection title="Case Studies" type="CASE" slug={r.slug} categoryCode={r.categoryCode} /></main><Footer /></>} /></>;
if (r.kind === "help") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "HELP_DETAIL" : "HELP_CATEGORY")} fallback={<><Header /><main><Collection title="Help Center" type="HELP" slug={r.slug} /></main><Footer /></>} /></>; if (r.kind === "help") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "HELP_DETAIL" : "HELP_CATEGORY")} fallback={<><Header /><main><Collection title="Help Center" type="HELP" slug={r.slug} categoryCode={r.categoryCode} /></main><Footer /></>} /></>;
return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug === "about-us" ? "ABOUT_US" : "CUSTOM_PAGE")} fallback={<><Header /><main><Page slug={r.slug!} /></main><Footer /></>} /></>; return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug === "about-us" ? "ABOUT_US" : "CUSTOM_PAGE")} fallback={<><Header /><main><Page slug={r.slug!} /></main><Footer /></>} /></>;
} }
function SeoRuntime({ current }: { current: ReturnType<typeof route> }) { function SeoRuntime({ current }: { current: ReturnType<typeof route> }) {
@@ -376,10 +379,12 @@ function Collection({
title, title,
type, type,
slug, slug,
categoryCode,
}: { }: {
title: string; title: string;
type: "products" | ContentType; type: "products" | ContentType;
slug?: string; slug?: string;
categoryCode?: string;
}) { }) {
const [data, setData] = useState<Item[] | Record<string, unknown>>([]); const [data, setData] = useState<Item[] | Record<string, unknown>>([]);
const [error, setError] = useState(""); const [error, setError] = useState("");
@@ -396,7 +401,7 @@ function Collection({
} else { } else {
const x = await post( const x = await post(
type === "products" ? "/products/list" : "/contents/list", type === "products" ? "/products/list" : "/contents/list",
type === "products" ? {} : { contentType: type }, type === "products" ? { categoryCode } : { contentType: type, categoryCode },
); );
setData(x.items || []); setData(x.items || []);
} }
@@ -405,7 +410,7 @@ function Collection({
} }
}; };
void run(); void run();
}, [type, slug]); }, [type, slug, categoryCode]);
if (error) return <ErrorState message={error} />; if (error) return <ErrorState message={error} />;
if (slug && !Array.isArray(data)) { if (slug && !Array.isArray(data)) {
const d = data as Record<string, any>; const d = data as Record<string, any>;