CMS根据栏目查询,增加包含下级栏目的文章

This commit is contained in:
thinkgem
2023-04-08 13:34:00 +08:00
parent 063d137afd
commit 30acc93b3c
4 changed files with 19 additions and 17 deletions

View File

@@ -25,7 +25,7 @@ import java.util.Date;
*/ */
@Table(name = "${_prefix}cms_article", alias = "a", columns = { @Table(name = "${_prefix}cms_article", alias = "a", columns = {
@Column(name = "id", attrName = "id", label = "编号", isPK = true), @Column(name = "id", attrName = "id", label = "编号", isPK = true),
@Column(name = "category_code", attrName = "category.categoryCode", label = "栏目编码"), @Column(name = "category_code", attrName = "category.categoryCode", label = "栏目编码", isQuery = false),
@Column(name = "module_type", attrName = "moduleType", label = "模块类型"), @Column(name = "module_type", attrName = "moduleType", label = "模块类型"),
@Column(name = "title", attrName = "title", label = "内容标题", queryType = QueryType.LIKE), @Column(name = "title", attrName = "title", label = "内容标题", queryType = QueryType.LIKE),
@Column(name = "href", attrName = "href", label = "外部链接"), @Column(name = "href", attrName = "href", label = "外部链接"),
@@ -44,15 +44,16 @@ import java.util.Date;
@Column(name = "custom_content_view", attrName = "customContentView", label = "自定义内容视图"), @Column(name = "custom_content_view", attrName = "customContentView", label = "自定义内容视图"),
@Column(name = "view_config", attrName = "viewConfig", label = "视图配置"), @Column(name = "view_config", attrName = "viewConfig", label = "视图配置"),
@Column(name = "status", attrName = "status", label = "状态", isUpdate = false), @Column(name = "status", attrName = "status", label = "状态", isUpdate = false),
@Column(name="create_by", attrName="createBy", label="创建者", isUpdate=true), @Column(name = "create_by", attrName = "createBy", label = "创建者"),
@Column(name = "create_date", attrName = "createDate", label = "创建时间", isUpdate = false, isQuery = false), @Column(name = "create_date", attrName = "createDate", label = "创建时间", isUpdate = false, isQuery = false),
@Column(name="update_by", attrName="updateBy", label="更新者", isUpdate=true), @Column(name = "update_by", attrName = "updateBy", label = "更新者"),
@Column(name="update_date", attrName="updateDate", label="更新时间", isUpdate=true, isQuery=false), @Column(name = "update_date", attrName = "updateDate", label = "更新时间", isQuery = false),
@Column(name = "remarks", attrName = "remarks", label = "备注信息", queryType = QueryType.LIKE), @Column(name = "remarks", attrName = "remarks", label = "备注信息", queryType = QueryType.LIKE),
@Column(includeEntity = BaseEntity.class), @Column(includeEntity = BaseEntity.class),
}, joinTable = { }, joinTable = {
@JoinTable(entity = Category.class, alias = "c", @JoinTable(entity = Category.class, alias = "c",
on = "c.category_code = a.category_code", columns = { on = "c.category_code = a.category_code", columns = {
@Column(name = "category_code", isPK = true),
@Column(name = "category_name"), @Column(name = "category_name"),
}), }),
@JoinTable(entity = Site.class, attrName = "category.site", alias = "s", @JoinTable(entity = Site.class, attrName = "category.site", alias = "s",

View File

@@ -70,7 +70,7 @@ public class ArticleController extends BaseController {
// 栏目展现模式当为3简介类栏目栏目第一条内容自动维护第一条内容 // 栏目展现模式当为3简介类栏目栏目第一条内容自动维护第一条内容
if (Category.SHOW_MODES_FIRST_CONTENT.equals(article.getCategory().getShowModes())) { if (Category.SHOW_MODES_FIRST_CONTENT.equals(article.getCategory().getShowModes())) {
// 获取文章内容 // 获取文章内容
Page<Article> page = new Page<Article>(1, 1, -1); Page<Article> page = new Page<>(1, 1, -1);
article.setPage(page); article.setPage(page);
page = articleService.findPage(article); page = articleService.findPage(article);
if (page.getList().size() > 0) { if (page.getList().size() > 0) {
@@ -94,8 +94,12 @@ public class ArticleController extends BaseController {
if (StringUtils.isBlank(article.getCategory().getSite().getSiteCode())) { if (StringUtils.isBlank(article.getCategory().getSite().getSiteCode())) {
article.getCategory().setSite(new Site(Site.getCurrentSiteCode())); article.getCategory().setSite(new Site(Site.getCurrentSiteCode()));
} }
// 查询指定栏目以及下级栏目的文章(如果不需要,可以注释掉)
if (StringUtils.isNotBlank(article.getCategory().getCategoryCode())) {
article.getCategory().setIsQueryChildren(true);
}
// 是否查询全部,不过滤权限 // 是否查询全部,不过滤权限
if (!(isAll != null && isAll)) { if (!(isAll != null && isAll) || Global.isStrictMode()){
articleService.addDataScopeFilter(article); articleService.addDataScopeFilter(article);
} }
if (!article.currentUser().isAdmin()) { if (!article.currentUser().isAdmin()) {
@@ -123,14 +127,11 @@ public class ArticleController extends BaseController {
categoryParam.setParentCode(article.getCategory().getCategoryCode()); categoryParam.setParentCode(article.getCategory().getCategoryCode());
List<Category> list = categoryService.findList(categoryParam); List<Category> list = categoryService.findList(categoryParam);
if (list.size() > 0) { if (list.size() > 0) {
article.setCategory(null); article.setCategory(null); // 不允许在父节点上添加文章
} else { } else {
article.setCategory(categoryService.get(article.getCategory().getId())); article.setCategory(CmsUtils.getCategory(article.getCategory().getCategoryCode()));
} }
} }
// if (article.getCategory()=null && StringUtils.isNotBlank(article.getCategory().getId())){
// Category category = categoryService.get(article.getCategory().getId());
// }
if (StringUtils.isBlank(article.getId())) { if (StringUtils.isBlank(article.getId())) {
article.setStatus(Article.STATUS_DRAFT); article.setStatus(Article.STATUS_DRAFT);
} }

View File

@@ -103,7 +103,7 @@ public class CategoryController extends BaseController {
// 创建并初始化下一个节点信息 // 创建并初始化下一个节点信息
category = createNextNode(category); category = createNextNode(category);
if (category.getParent() != null && StringUtils.isNotBlank(category.getParent().getId())) { if (category.getParent() != null && StringUtils.isNotBlank(category.getParent().getId())) {
category.setParent(categoryService.get(category.getParent().getCategoryCode())); category.setParent(CmsUtils.getCategory(category.getParent().getCategoryCode()));
if (category.getIsNewRecord()) { if (category.getIsNewRecord()) {
Category categoryChild = new Category(); Category categoryChild = new Category();
categoryChild.setParent(new Category(category.getParentCode())); categoryChild.setParent(new Category(category.getParentCode()));
@@ -270,7 +270,7 @@ public class CategoryController extends BaseController {
category.setModuleType(module); category.setModuleType(module);
} }
// 是否查询全部,不过滤权限 // 是否查询全部,不过滤权限
if (!(isAll != null && isAll)) { if (!(isAll != null && isAll) || Global.isStrictMode()){
categoryService.addDataScopeFilter(category); categoryService.addDataScopeFilter(category);
} }
list = categoryService.findList(category); list = categoryService.findList(category);

View File

@@ -24,7 +24,7 @@
<#form:treeselect id="category" title="${text('所属栏目')}" <#form:treeselect id="category" title="${text('所属栏目')}"
path="category.categoryCode" labelPath="category.categoryName" path="category.categoryCode" labelPath="category.categoryName"
url="${ctx}/cms/category/treeData?excludeCode=${article.category.categoryCode}" url="${ctx}/cms/category/treeData?excludeCode=${article.category.categoryCode}"
class="required" allowClear="true" canSelectRoot="true" canSelectParent="true" /> class="required" allowClear="false" canSelectRoot="true" canSelectParent="false" />
</div> </div>
</div> </div>
</div> </div>