文章、课程标签的默认封面
This commit is contained in:
@@ -5,9 +5,11 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.xyzh.api.news.tag.TagService;
|
||||
import org.xyzh.api.news.tag.TagDefaultCoverService;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.resource.TbTag;
|
||||
import org.xyzh.common.dto.resource.TbResourceTag;
|
||||
import org.xyzh.common.dto.resource.TbTagDefaultCover;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -25,6 +27,9 @@ public class TagController {
|
||||
|
||||
@Autowired
|
||||
private TagService tagService;
|
||||
|
||||
@Autowired
|
||||
private TagDefaultCoverService tagDefaultCoverService;
|
||||
|
||||
/**
|
||||
* 获取标签列表
|
||||
@@ -138,4 +143,62 @@ public class TagController {
|
||||
public ResultDomain<String> getResourcesByTag(@PathVariable("tagID") String tagID) {
|
||||
return tagService.getResourcesByTag(tagID);
|
||||
}
|
||||
|
||||
// ----------------标签默认封面相关--------------------------------
|
||||
|
||||
/**
|
||||
* 获取标签的启用默认封面列表
|
||||
*/
|
||||
@GetMapping("/tag/{tagID}/default-covers")
|
||||
public ResultDomain<TbTagDefaultCover> getDefaultCovers(@PathVariable("tagID") String tagID) {
|
||||
return tagDefaultCoverService.getDefaultCovers(tagID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取标签的所有默认封面列表(管理端使用)
|
||||
*/
|
||||
@GetMapping("/tag/{tagID}/all-default-covers")
|
||||
public ResultDomain<TbTagDefaultCover> getAllDefaultCovers(@PathVariable("tagID") String tagID) {
|
||||
return tagDefaultCoverService.getAllDefaultCovers(tagID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加默认封面
|
||||
*/
|
||||
@PostMapping("/default-cover")
|
||||
public ResultDomain<String> addDefaultCover(@RequestBody TbTagDefaultCover cover) {
|
||||
return tagDefaultCoverService.addDefaultCover(cover);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新默认封面
|
||||
*/
|
||||
@PutMapping("/default-cover")
|
||||
public ResultDomain<String> updateDefaultCover(@RequestBody TbTagDefaultCover cover) {
|
||||
return tagDefaultCoverService.updateDefaultCover(cover);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除默认封面
|
||||
*/
|
||||
@DeleteMapping("/default-cover/{id}")
|
||||
public ResultDomain<String> deleteDefaultCover(@PathVariable("id") String id) {
|
||||
return tagDefaultCoverService.deleteDefaultCover(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加默认封面
|
||||
*/
|
||||
@PostMapping("/default-covers/batch")
|
||||
public ResultDomain<String> batchAddDefaultCovers(@RequestBody List<TbTagDefaultCover> covers) {
|
||||
return tagDefaultCoverService.batchAddDefaultCovers(covers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标签ID删除所有默认封面
|
||||
*/
|
||||
@DeleteMapping("/tag/{tagID}/default-covers")
|
||||
public ResultDomain<String> deleteDefaultCoversByTagId(@PathVariable("tagID") String tagID) {
|
||||
return tagDefaultCoverService.deleteDefaultCoversByTagId(tagID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.xyzh.news.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.dto.resource.TbTagDefaultCover;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description 标签默认封面Mapper接口
|
||||
* @author system
|
||||
* @since 2025-12-24
|
||||
*/
|
||||
@Mapper
|
||||
public interface TagDefaultCoverMapper {
|
||||
|
||||
/**
|
||||
* @description 根据标签ID查询默认封面列表
|
||||
* @param tagId 标签ID
|
||||
* @return List<TbTagDefaultCover> 默认封面列表
|
||||
* @author system
|
||||
* @since 2025-12-24
|
||||
*/
|
||||
List<TbTagDefaultCover> selectDefaultCoversByTagId(@Param("tagId") String tagId);
|
||||
|
||||
/**
|
||||
* @description 根据标签ID查询启用的默认封面列表
|
||||
* @param tagId 标签ID
|
||||
* @return List<TbTagDefaultCover> 启用的默认封面列表
|
||||
* @author system
|
||||
* @since 2025-12-24
|
||||
*/
|
||||
List<TbTagDefaultCover> selectActiveDefaultCoversByTagId(@Param("tagId") String tagId);
|
||||
|
||||
/**
|
||||
* @description 插入默认封面
|
||||
* @param cover 默认封面对象
|
||||
* @return int 影响行数
|
||||
* @author system
|
||||
* @since 2025-12-24
|
||||
*/
|
||||
int insertDefaultCover(TbTagDefaultCover cover);
|
||||
|
||||
/**
|
||||
* @description 更新默认封面
|
||||
* @param cover 默认封面对象
|
||||
* @return int 影响行数
|
||||
* @author system
|
||||
* @since 2025-12-24
|
||||
*/
|
||||
int updateDefaultCover(TbTagDefaultCover cover);
|
||||
|
||||
/**
|
||||
* @description 删除默认封面
|
||||
* @param id 主键ID
|
||||
* @return int 影响行数
|
||||
* @author system
|
||||
* @since 2025-12-24
|
||||
*/
|
||||
int deleteDefaultCover(@Param("id") String id);
|
||||
|
||||
/**
|
||||
* @description 根据标签ID删除所有默认封面
|
||||
* @param tagId 标签ID
|
||||
* @return int 影响行数
|
||||
* @author system
|
||||
* @since 2025-12-24
|
||||
*/
|
||||
int deleteDefaultCoversByTagId(@Param("tagId") String tagId);
|
||||
|
||||
/**
|
||||
* @description 根据ID查询默认封面
|
||||
* @param id 主键ID
|
||||
* @return TbTagDefaultCover 默认封面对象
|
||||
* @author system
|
||||
* @since 2025-12-24
|
||||
*/
|
||||
TbTagDefaultCover selectDefaultCoverById(@Param("id") String id);
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
package org.xyzh.news.service.impl;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.xyzh.api.news.tag.TagDefaultCoverService;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.resource.TbTagDefaultCover;
|
||||
import org.xyzh.news.mapper.TagDefaultCoverMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @description 标签默认封面服务实现
|
||||
* @author system
|
||||
* @since 2025-12-24
|
||||
*/
|
||||
@Service
|
||||
public class NCTagDefaultCoverServiceImpl implements TagDefaultCoverService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NCTagDefaultCoverServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private TagDefaultCoverMapper tagDefaultCoverMapper;
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbTagDefaultCover> getDefaultCovers(String tagID) {
|
||||
ResultDomain<TbTagDefaultCover> result = new ResultDomain<>();
|
||||
try {
|
||||
if (tagID == null || tagID.trim().isEmpty()) {
|
||||
result.fail("标签ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<TbTagDefaultCover> covers = tagDefaultCoverMapper.selectActiveDefaultCoversByTagId(tagID);
|
||||
logger.info("获取标签[{}]的默认封面列表,数量:{}", tagID, covers.size());
|
||||
|
||||
result.success("获取成功", covers);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
logger.error("获取标签默认封面列表失败", e);
|
||||
result.fail("获取默认封面列表失败:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbTagDefaultCover> getAllDefaultCovers(String tagID) {
|
||||
ResultDomain<TbTagDefaultCover> result = new ResultDomain<>();
|
||||
try {
|
||||
if (tagID == null || tagID.trim().isEmpty()) {
|
||||
result.fail("标签ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<TbTagDefaultCover> covers = tagDefaultCoverMapper.selectDefaultCoversByTagId(tagID);
|
||||
logger.info("获取标签[{}]的所有默认封面列表,数量:{}", tagID, covers.size());
|
||||
|
||||
result.success("获取成功", covers);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
logger.error("获取标签所有默认封面列表失败", e);
|
||||
result.fail("获取默认封面列表失败:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResultDomain<String> addDefaultCover(TbTagDefaultCover cover) {
|
||||
ResultDomain<String> result = new ResultDomain<>();
|
||||
try {
|
||||
if (cover.getTagID() == null || cover.getTagID().trim().isEmpty()) {
|
||||
result.fail("标签ID不能为空");
|
||||
return result;
|
||||
}
|
||||
if (cover.getCoverImage() == null || cover.getCoverImage().trim().isEmpty()) {
|
||||
result.fail("封面图片不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
cover.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||
if (cover.getIsActive() == null) {
|
||||
cover.setIsActive(1);
|
||||
}
|
||||
if (cover.getOrderNum() == null) {
|
||||
cover.setOrderNum(0);
|
||||
}
|
||||
|
||||
int rows = tagDefaultCoverMapper.insertDefaultCover(cover);
|
||||
if (rows > 0) {
|
||||
logger.info("添加标签默认封面成功,ID:{}", cover.getId());
|
||||
result.success("添加成功", cover.getId());
|
||||
return result;
|
||||
} else {
|
||||
result.fail("添加失败");
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("添加标签默认封面失败", e);
|
||||
result.fail("添加失败:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResultDomain<String> updateDefaultCover(TbTagDefaultCover cover) {
|
||||
ResultDomain<String> result = new ResultDomain<>();
|
||||
try {
|
||||
if (cover.getId() == null || cover.getId().trim().isEmpty()) {
|
||||
result.fail("ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
int rows = tagDefaultCoverMapper.updateDefaultCover(cover);
|
||||
if (rows > 0) {
|
||||
logger.info("更新标签默认封面成功,ID:{}", cover.getId());
|
||||
result.success("更新成功", cover.getId());
|
||||
return result;
|
||||
} else {
|
||||
result.fail("更新失败,记录不存在");
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("更新标签默认封面失败", e);
|
||||
result.fail("更新失败:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResultDomain<String> deleteDefaultCover(String id) {
|
||||
ResultDomain<String> result = new ResultDomain<>();
|
||||
try {
|
||||
if (id == null || id.trim().isEmpty()) {
|
||||
result.fail("ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
int rows = tagDefaultCoverMapper.deleteDefaultCover(id);
|
||||
if (rows > 0) {
|
||||
logger.info("删除标签默认封面成功,ID:{}", id);
|
||||
result.success("删除成功", id);
|
||||
return result;
|
||||
} else {
|
||||
result.fail("删除失败,记录不存在");
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("删除标签默认封面失败", e);
|
||||
result.fail("删除失败:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResultDomain<String> batchAddDefaultCovers(List<TbTagDefaultCover> covers) {
|
||||
ResultDomain<String> result = new ResultDomain<>();
|
||||
try {
|
||||
if (covers == null || covers.isEmpty()) {
|
||||
result.fail("封面列表不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
int successCount = 0;
|
||||
for (TbTagDefaultCover cover : covers) {
|
||||
cover.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||
if (cover.getIsActive() == null) {
|
||||
cover.setIsActive(1);
|
||||
}
|
||||
if (cover.getOrderNum() == null) {
|
||||
cover.setOrderNum(0);
|
||||
}
|
||||
|
||||
int rows = tagDefaultCoverMapper.insertDefaultCover(cover);
|
||||
if (rows > 0) {
|
||||
successCount++;
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("批量添加标签默认封面完成,成功:{}/总数:{}", successCount, covers.size());
|
||||
result.success("批量添加成功,成功数量:" + successCount, String.valueOf(successCount));
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
logger.error("批量添加标签默认封面失败", e);
|
||||
result.fail("批量添加失败:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResultDomain<String> deleteDefaultCoversByTagId(String tagID) {
|
||||
ResultDomain<String> result = new ResultDomain<>();
|
||||
try {
|
||||
if (tagID == null || tagID.trim().isEmpty()) {
|
||||
result.fail("标签ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
int rows = tagDefaultCoverMapper.deleteDefaultCoversByTagId(tagID);
|
||||
logger.info("删除标签[{}]的所有默认封面成功,删除数量:{}", tagID, rows);
|
||||
result.success("删除成功", String.valueOf(rows));
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
logger.error("删除标签默认封面失败", e);
|
||||
result.fail("删除失败:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.xyzh.news.mapper.TagDefaultCoverMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.resource.TbTagDefaultCover">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="tag_id" property="tagID" jdbcType="VARCHAR"/>
|
||||
<result column="cover_image" property="coverImage" jdbcType="VARCHAR"/>
|
||||
<result column="order_num" property="orderNum" jdbcType="INTEGER"/>
|
||||
<result column="is_active" property="isActive" jdbcType="TINYINT"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, tag_id, cover_image, order_num, is_active, creator, create_time, updater, update_time
|
||||
</sql>
|
||||
|
||||
<!-- 根据标签ID查询默认封面列表 -->
|
||||
<select id="selectDefaultCoversByTagId" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM tb_tag_default_cover
|
||||
WHERE tag_id = #{tagId}
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据标签ID查询启用的默认封面列表 -->
|
||||
<select id="selectActiveDefaultCoversByTagId" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM tb_tag_default_cover
|
||||
WHERE tag_id = #{tagId} AND is_active = 1
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据ID查询默认封面 -->
|
||||
<select id="selectDefaultCoverById" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM tb_tag_default_cover
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<!-- 插入默认封面 -->
|
||||
<insert id="insertDefaultCover">
|
||||
INSERT INTO tb_tag_default_cover
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="tagID != null">tag_id,</if>
|
||||
<if test="coverImage != null">cover_image,</if>
|
||||
<if test="orderNum != null">order_num,</if>
|
||||
<if test="isActive != null">is_active,</if>
|
||||
<if test="creator != null">creator,</if>
|
||||
create_time,
|
||||
</trim>
|
||||
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="tagID != null">#{tagID},</if>
|
||||
<if test="coverImage != null">#{coverImage},</if>
|
||||
<if test="orderNum != null">#{orderNum},</if>
|
||||
<if test="isActive != null">#{isActive},</if>
|
||||
<if test="creator != null">#{creator},</if>
|
||||
NOW(),
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<!-- 更新默认封面 -->
|
||||
<update id="updateDefaultCover">
|
||||
UPDATE tb_tag_default_cover
|
||||
<set>
|
||||
<if test="coverImage != null">cover_image = #{coverImage},</if>
|
||||
<if test="orderNum != null">order_num = #{orderNum},</if>
|
||||
<if test="isActive != null">is_active = #{isActive},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 删除默认封面 -->
|
||||
<delete id="deleteDefaultCover">
|
||||
DELETE FROM tb_tag_default_cover WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- 根据标签ID删除所有默认封面 -->
|
||||
<delete id="deleteDefaultCoversByTagId">
|
||||
DELETE FROM tb_tag_default_cover WHERE tag_id = #{tagId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user