定时任务修正

This commit is contained in:
2025-11-17 15:16:11 +08:00
parent 4b167058b6
commit 6e9057f6ee
16 changed files with 444 additions and 496 deletions

View File

@@ -52,10 +52,10 @@ public class ResourceController {
}
/**
* 获取资源分页(按浏览次数排序)
* 获取资源分页(按浏览次数排序,包含推荐信息
*/
@PostMapping("/page/view-count")
public ResultDomain<TbResource> getResourcePageOrderByViewCount(@RequestBody PageRequest<TbResource> request) {
public ResultDomain<ResourceVO> getResourcePageOrderByViewCount(@RequestBody PageRequest<TbResource> request) {
TbResource filter = request.getFilter();
PageParam pageParam = request.getPageParam();
return resourceService.getResourcePageOrderByViewCount(filter, pageParam);

View File

@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.xyzh.common.core.page.PageParam;
import org.xyzh.common.dto.resource.TbResource;
import org.xyzh.common.vo.ResourceVO;
import org.xyzh.common.vo.UserDeptRoleVO;
import java.util.List;
@@ -166,16 +167,15 @@ public interface ResourceMapper extends BaseMapper<TbResource> {
List<TbResource> selectResourcesPage(@Param("filter") TbResource filter, @Param("pageParam") PageParam pageParam, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
/**
* @description 分页查询资源
* @description 获取资源分页(按浏览次数排序,包含推荐信息)
* @param filter 过滤条件
* @param pageParam 分页参数
* @param userDeptRoles 用户部门角色列表
* @return List<TbResource> 资源列表
* @return List<ResourceVO> 资源VO列表包含推荐信息
* @author yslg
* @since 2025-10-15
*/
List<TbResource> selectResourcesPageOrderByViewCount(@Param("filter") TbResource filter, @Param("pageParam") PageParam pageParam, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
List<ResourceVO> selectResourcesPageOrderByViewCount(@Param("filter") TbResource filter, @Param("pageParam") PageParam pageParam, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
/**
* @description 统计资源总数

View File

@@ -96,19 +96,21 @@ public class NCResourceServiceImpl implements ResourceService {
}
@Override
public ResultDomain<TbResource> getResourcePageOrderByViewCount(TbResource filter, PageParam pageParam) {
ResultDomain<TbResource> resultDomain = new ResultDomain<>();
public ResultDomain<ResourceVO> getResourcePageOrderByViewCount(TbResource filter, PageParam pageParam) {
ResultDomain<ResourceVO> resultDomain = new ResultDomain<>();
try {
if (filter == null) {
filter = new TbResource();
}
// 获取当前用户的部门角色
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
List<TbResource> list = resourceMapper.selectResourcesPageOrderByViewCount(filter, pageParam, userDeptRoles);
// 直接查询ResourceVO列表SQL已经LEFT JOIN了recommend表
List<ResourceVO> resourceVOList = resourceMapper.selectResourcesPageOrderByViewCount(filter, pageParam, userDeptRoles);
long total = resourceMapper.countResources(filter, userDeptRoles);
pageParam.setTotalElements(total);
pageParam.setTotalPages((int) Math.ceil((double) total / pageParam.getPageSize()));
resultDomain.success("获取资源分页(按浏览次数排序)成功", new PageDomain<TbResource>(pageParam, list));
resultDomain.success("获取资源分页(按浏览次数排序)成功", new PageDomain<ResourceVO>(pageParam, resourceVOList));
return resultDomain;
}
catch (Exception e) {

View File

@@ -336,9 +336,44 @@
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select>
<select id="selectResourcesPageOrderByViewCount" resultMap="BaseResultMap">
SELECT DISTINCT r.*
<!-- ResourceVO结果映射包含推荐信息 -->
<resultMap id="ResourceVOResultMap" type="org.xyzh.common.vo.ResourceVO">
<result column="is_top_recommend" property="isTopRecommend" jdbcType="BOOLEAN"/>
<result column="is_ideological_recommend" property="isIdeologicalRecommend" jdbcType="BOOLEAN"/>
<association property="resource" javaType="org.xyzh.common.dto.resource.TbResource">
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="resource_id" property="resourceID" jdbcType="VARCHAR"/>
<result column="title" property="title" jdbcType="VARCHAR"/>
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
<result column="summary" property="summary" jdbcType="VARCHAR"/>
<result column="cover_image" property="coverImage" jdbcType="VARCHAR"/>
<result column="tag_id" property="tagID" jdbcType="VARCHAR"/>
<result column="author" property="author" jdbcType="VARCHAR"/>
<result column="source" property="source" jdbcType="VARCHAR"/>
<result column="source_url" property="sourceUrl" jdbcType="VARCHAR"/>
<result column="view_count" property="viewCount" jdbcType="INTEGER"/>
<result column="like_count" property="likeCount" jdbcType="INTEGER"/>
<result column="collect_count" property="collectCount" jdbcType="INTEGER"/>
<result column="status" property="status" jdbcType="INTEGER"/>
<result column="is_recommend" property="isRecommend" jdbcType="BOOLEAN"/>
<result column="is_banner" property="isBanner" jdbcType="BOOLEAN"/>
<result column="publish_time" property="publishTime" jdbcType="TIMESTAMP"/>
<result column="creator" property="creator" jdbcType="VARCHAR"/>
<result column="updater" property="updater" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
</association>
</resultMap>
<select id="selectResourcesPageOrderByViewCount" resultMap="ResourceVOResultMap">
SELECT
r.*,
MAX(CASE WHEN rec.recommend_type = 1 THEN 1 ELSE 0 END) AS is_top_recommend,
MAX(CASE WHEN rec.recommend_type = 2 THEN 1 ELSE 0 END) AS is_ideological_recommend
FROM tb_resource r
LEFT JOIN tb_resource_recommend rec ON r.resource_id = rec.resource_id AND rec.deleted = 0
<include refid="Permission_Filter"/>
WHERE r.deleted = 0
<if test="filter.title != null and filter.title != ''">
@@ -359,6 +394,10 @@
<if test="filter.isBanner != null">
AND r.is_banner = #{filter.isBanner}
</if>
GROUP BY r.id, r.resource_id, r.title, r.content, r.summary, r.cover_image, r.tag_id,
r.author, r.source, r.source_url, r.view_count, r.like_count, r.collect_count,
r.status, r.is_recommend, r.is_banner, r.publish_time, r.creator, r.updater,
r.create_time, r.update_time, r.delete_time, r.deleted
ORDER BY r.view_count DESC, r.publish_time DESC, r.create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select>