init local code
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package com.yunhai.cms.repository;
|
||||
|
||||
import com.yunhai.cms.entity.CmsArticle;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CmsArticleRepository extends JpaRepository<CmsArticle, Integer>,
|
||||
JpaSpecificationExecutor<CmsArticle> {
|
||||
|
||||
Optional<CmsArticle> findByIdAndSiteId(Integer id, Integer siteId);
|
||||
|
||||
long countByCategoryId(Integer categoryId);
|
||||
|
||||
/** 学校工作台规模计数(docs/09 §3.3,管理端口径含未发布) */
|
||||
long countBySiteId(Integer siteId);
|
||||
|
||||
/** 栏目列表页:已发布,发布时间倒序(置顶由 Specification/排序组合处理) */
|
||||
Page<CmsArticle> findBySiteIdAndCategoryIdAndStatus(Integer siteId, Integer categoryId,
|
||||
Integer status, Pageable pageable);
|
||||
|
||||
/** 栏目聚合查询(D1-2/D1-3):父栏目区块/列表页聚合列表型子孙栏目的文章 */
|
||||
Page<CmsArticle> findBySiteIdAndCategoryIdInAndStatus(Integer siteId, Collection<Integer> categoryIds,
|
||||
Integer status, Pageable pageable);
|
||||
|
||||
/** 门户:首页按站点取已发布(置顶优先),条数由 Pageable 控制 */
|
||||
List<CmsArticle> findBySiteIdAndStatus(Integer siteId, Integer status, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 详情页上下篇:publish_time 相同(如同秒批量导入)时以 id 决胜,
|
||||
* 约定列表排序 = publish_time desc, id desc,上一篇文章是该序中的后继。
|
||||
*/
|
||||
@Query("select a from CmsArticle a where a.siteId = :siteId and a.status = :status"
|
||||
+ " and (a.publishTime < :pt or (a.publishTime = :pt and a.id < :id))"
|
||||
+ " order by a.publishTime desc, a.id desc")
|
||||
List<CmsArticle> findPrevPublished(@Param("siteId") Integer siteId, @Param("status") Integer status,
|
||||
@Param("pt") LocalDateTime pt, @Param("id") Integer id,
|
||||
Pageable pageable);
|
||||
|
||||
@Query("select a from CmsArticle a where a.siteId = :siteId and a.status = :status"
|
||||
+ " and (a.publishTime > :pt or (a.publishTime = :pt and a.id > :id))"
|
||||
+ " order by a.publishTime asc, a.id asc")
|
||||
List<CmsArticle> findNextPublished(@Param("siteId") Integer siteId, @Param("status") Integer status,
|
||||
@Param("pt") LocalDateTime pt, @Param("id") Integer id,
|
||||
Pageable pageable);
|
||||
|
||||
/** 站内搜索(title/summary LIKE,MVP 不上 ES,方案 §2) */
|
||||
Page<CmsArticle> findBySiteIdAndStatusAndTitleContainingOrSiteIdAndStatusAndSummaryContaining(
|
||||
Integer siteId, Integer status, String title, Integer siteId2, Integer status2, String summary,
|
||||
Pageable pageable);
|
||||
|
||||
/** 定时发布扫描:草稿且发布时间已到 */
|
||||
List<CmsArticle> findByStatusAndPublishTimeNotNullAndPublishTimeLessThanEqual(Integer status,
|
||||
LocalDateTime now);
|
||||
|
||||
/** 定时下架扫描:已发布且下架时间已到 */
|
||||
List<CmsArticle> findByStatusAndOfflineTimeNotNullAndOfflineTimeLessThanEqual(Integer status,
|
||||
LocalDateTime now);
|
||||
|
||||
/** 浏览量异步累加(fire-and-forget,失败忽略,方案 §5.2) */
|
||||
@Modifying
|
||||
@Query("update CmsArticle a set a.viewCount = a.viewCount + 1 where a.id = :id")
|
||||
int incrementViewCount(@Param("id") Integer id);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.yunhai.cms.repository;
|
||||
|
||||
import com.yunhai.cms.entity.CmsAttachment;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CmsAttachmentRepository extends JpaRepository<CmsAttachment, Integer> {
|
||||
|
||||
Page<CmsAttachment> findBySiteId(Integer siteId, Pageable pageable);
|
||||
|
||||
List<CmsAttachment> findByArticleId(Integer articleId);
|
||||
|
||||
/** 编辑器图片上传时先按路径去重绑定,避免重复行 */
|
||||
long countBySiteIdAndFilePath(Integer siteId, String filePath);
|
||||
|
||||
/** 孤儿附件(文章已删除:article_id is null) */
|
||||
Page<CmsAttachment> findBySiteIdAndArticleIdIsNull(Integer siteId, Pageable pageable);
|
||||
|
||||
long countBySiteIdAndArticleIdIsNull(Integer siteId);
|
||||
|
||||
@Modifying
|
||||
@Query("update CmsAttachment a set a.articleId = :articleId where a.id in :ids")
|
||||
int bindArticle(@Param("articleId") Integer articleId, @Param("ids") List<Integer> ids);
|
||||
|
||||
/** 文章删除:附件转孤儿 */
|
||||
@Modifying
|
||||
@Query("update CmsAttachment a set a.articleId = null where a.articleId = :articleId")
|
||||
int unbindArticle(@Param("articleId") Integer articleId);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.yunhai.cms.repository;
|
||||
|
||||
import com.yunhai.cms.entity.CmsBanner;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CmsBannerRepository extends JpaRepository<CmsBanner, Integer> {
|
||||
|
||||
/** 管理端:展示位全量(含停用,按排序) */
|
||||
List<CmsBanner> findBySiteIdAndPositionOrderBySortNoAscIdAsc(Integer siteId, String position);
|
||||
|
||||
List<CmsBanner> findBySiteIdOrderByPositionAscSortNoAscIdAsc(Integer siteId);
|
||||
|
||||
/** 引用完整性(删除拦截用):指定跳转类型下是否存在指向目标 id 的轮播(跨站也拦,link_value 全局比对) */
|
||||
boolean existsByLinkTypeAndLinkValue(Integer linkType, String linkValue);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yunhai.cms.repository;
|
||||
|
||||
import com.yunhai.cms.entity.CmsCategory;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CmsCategoryRepository extends JpaRepository<CmsCategory, Integer> {
|
||||
|
||||
/** 栏目树数据源(内存组树,站点数 ≤20 栏目量级小) */
|
||||
List<CmsCategory> findBySiteIdOrderBySortNoAscIdAsc(Integer siteId);
|
||||
|
||||
long countBySiteId(Integer siteId);
|
||||
|
||||
long countByParentId(Integer parentId);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.yunhai.cms.repository;
|
||||
|
||||
import com.yunhai.cms.entity.CmsLink;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CmsLinkRepository extends JpaRepository<CmsLink, Integer> {
|
||||
|
||||
List<CmsLink> findBySiteIdOrderByGroupNameAscSortNoAscIdAsc(Integer siteId);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yunhai.cms.repository;
|
||||
|
||||
import com.yunhai.cms.entity.CmsSite;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CmsSiteRepository extends JpaRepository<CmsSite, Integer> {
|
||||
|
||||
Optional<CmsSite> findByCode(String code);
|
||||
|
||||
/** 启用站点(B-5:显式按 id 升序,/portal 默认入口跳转目标确定) */
|
||||
List<CmsSite> findByStatusOrderByIdAsc(Integer status);
|
||||
|
||||
/** 本校可管理的站点(非超管按 currentRole.schId 过滤) */
|
||||
List<CmsSite> findBySchId(Integer schId);
|
||||
|
||||
/** 指定主站下的启用院系子站(门户"专业院系"下拉数据源,《院系子站方案》) */
|
||||
List<CmsSite> findByParentSiteIdAndStatusOrderByIdAsc(Integer parentSiteId, Integer status);
|
||||
|
||||
/** 是否存在院系子站(站点改挂上级前的守卫) */
|
||||
boolean existsByParentSiteId(Integer parentSiteId);
|
||||
}
|
||||
Reference in New Issue
Block a user