视图修改、接口修改

This commit is contained in:
2025-10-28 19:04:35 +08:00
parent 98c73632bd
commit c5c134fbb3
96 changed files with 7122 additions and 4194 deletions

View File

@@ -6,7 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xyzh.api.news.banner.BannerService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.core.page.PageRequest;
import org.xyzh.common.dto.resource.TbBanner;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @description 横幅控制器
@@ -27,16 +31,16 @@ public class BannerController {
* 获取横幅列表
*/
@GetMapping("/list")
public ResultDomain<TbBanner> getBannerList() {
return bannerService.getBannerList(null);
public ResultDomain<TbBanner> getBannerList(TbBanner filter) {
return bannerService.getBannerList(filter);
}
/**
* 根据ID获取横幅详情
*/
@GetMapping("/banner/{bannerID}")
public ResultDomain<TbBanner> getBannerById(@PathVariable String bannerID) {
return bannerService.getBannerById(bannerID);
@PostMapping("/banner/page")
public ResultDomain<TbBanner> getBannerPage(@RequestBody PageRequest<TbBanner> pageRequest) {
return bannerService.getBannerPage(pageRequest.getPageParam(), pageRequest.getFilter());
}
/**
@@ -58,36 +62,27 @@ public class BannerController {
/**
* 删除横幅
*/
@DeleteMapping("/banner/{bannerID}")
public ResultDomain<Boolean> deleteBanner(@PathVariable String bannerID) {
return bannerService.deleteBanner(bannerID);
@DeleteMapping("/banner")
public ResultDomain<Boolean> deleteBanner(@RequestBody TbBanner banner) {
return bannerService.deleteBanner(banner.getBannerID());
}
/**
* 更新横幅状态
*/
@PutMapping("/banner/{bannerID}/status")
public ResultDomain<TbBanner> updateBannerStatus(
@PathVariable String bannerID,
@RequestParam Integer status) {
return bannerService.updateBannerStatus(bannerID, status);
@PutMapping("/banner/status")
public ResultDomain<TbBanner> updateBannerStatus(@RequestBody TbBanner banner) {
return bannerService.updateBannerStatus(banner.getBannerID(), banner.getStatus());
}
/**
* 更新横幅排序
* 获取首页横幅列表
*/
@PutMapping("/banner/{bannerID}/order")
public ResultDomain<TbBanner> updateBannerOrder(
@PathVariable String bannerID,
@RequestParam Integer orderNum) {
return bannerService.updateBannerOrder(bannerID, orderNum);
@GetMapping("/home")
public ResultDomain<TbBanner> getHomeBannerList() {
return bannerService.selectHomeBanners();
}
/**
* 获取活跃横幅
*/
@GetMapping("/active")
public ResultDomain<TbBanner> getActiveBanners(@RequestParam(required = false) Integer limit) {
return bannerService.getActiveBanners(limit);
}
}

View File

@@ -27,6 +27,19 @@ public interface BannerMapper extends BaseMapper<TbBanner> {
*/
List<TbBanner> selectBanners(TbBanner filter);
List<TbBanner> selectBannersLimit(@Param("filter") TbBanner filter, @Param("limit") Integer limit);
/**
* @description 分页查询Banner
* @param filter 过滤条件
* @param pageParam 分页参数
* @return List<TbBanner> Banner列表
* @author yslg
* @since 2025-10-15
*/
List<TbBanner> selectBannersPage(@Param("filter") TbBanner filter, @Param("pageParam") PageParam pageParam);
/**
* @description 根据Banner ID查询Banner信息
* @param bannerId Banner ID
@@ -117,16 +130,6 @@ public interface BannerMapper extends BaseMapper<TbBanner> {
*/
int batchDeleteBanners(@Param("ids") List<String> ids);
/**
* @description 分页查询Banner
* @param filter 过滤条件
* @param pageParam 分页参数
* @return List<TbBanner> Banner列表
* @author yslg
* @since 2025-10-15
*/
List<TbBanner> selectBannersPage(@Param("filter") TbBanner filter, @Param("pageParam") PageParam pageParam);
/**
* @description 统计Banner总数
* @param filter 过滤条件

View File

@@ -11,6 +11,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.core.page.PageDomain;
import org.xyzh.common.core.page.PageParam;
import org.xyzh.common.dto.resource.TbBanner;
import org.xyzh.common.utils.IDUtils;
import org.xyzh.news.mapper.BannerMapper;
@@ -32,49 +34,27 @@ public class NCBannerServiceImpl implements BannerService {
private BannerMapper bannerMapper;
@Override
public ResultDomain<TbBanner> getBannerList(Integer status) {
public ResultDomain<TbBanner> getBannerList(TbBanner filter) {
ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
try {
List<TbBanner> list;
if (status != null) {
list = bannerMapper.selectByStatus(status);
} else {
TbBanner filter = new TbBanner();
list = bannerMapper.selectBanners(filter);
}
resultDomain.success("获取横幅列表成功", list);
return resultDomain;
} catch (Exception e) {
logger.error("获取横幅列表异常: {}", e.getMessage(), e);
resultDomain.fail("获取横幅列表失败: " + e.getMessage());
return resultDomain;
}
List<TbBanner> list = bannerMapper.selectBanners(filter);
resultDomain.success("获取横幅列表成功", list);
return resultDomain;
}
@Override
public ResultDomain<TbBanner> getBannerById(String bannerID) {
public ResultDomain<TbBanner> getBannerPage(PageParam pageParam,TbBanner filter) {
ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
try {
// 参数验证
if (!StringUtils.hasText(bannerID)) {
resultDomain.fail("横幅ID不能为空");
return resultDomain;
}
List<TbBanner> list = bannerMapper.selectBannersPage(filter, pageParam);
PageDomain<TbBanner> pageDomain = new PageDomain<>();
int total = (int)bannerMapper.countBanners(filter);
pageParam.setTotalElements(total);
pageParam.setTotalPages( (int)Math.ceil((double)total / pageParam.getPageSize()));
pageDomain.setDataList(list);
pageDomain.setPageParam(pageParam);
// 查询横幅
TbBanner banner = bannerMapper.selectByBannerId(bannerID);
if (banner == null || banner.getDeleted()) {
resultDomain.fail("横幅不存在");
return resultDomain;
}
resultDomain.success("获取横幅详情成功", banner);
return resultDomain;
} catch (Exception e) {
logger.error("获取横幅详情异常: {}", e.getMessage(), e);
resultDomain.fail("获取横幅详情失败: " + e.getMessage());
return resultDomain;
}
resultDomain.success("获取横幅列表成功", pageDomain);
return resultDomain;
}
@Override
@@ -103,7 +83,7 @@ public class NCBannerServiceImpl implements BannerService {
if (banner.getID() == null) {
banner.setID(IDUtils.generateID());
}
banner.setBannerID(IDUtils.generateID());
banner.setCreateTime(new Date());
banner.setUpdateTime(new Date());
banner.setDeleted(false);
@@ -139,13 +119,13 @@ public class NCBannerServiceImpl implements BannerService {
ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
try {
// 参数验证
if (banner == null || !StringUtils.hasText(banner.getID())) {
if (banner == null || !StringUtils.hasText(banner.getBannerID())) {
resultDomain.fail("横幅ID不能为空");
return resultDomain;
}
// 检查横幅是否存在
TbBanner existing = bannerMapper.selectById(banner.getID());
TbBanner existing = bannerMapper.selectByBannerId(banner.getBannerID());
if (existing == null || existing.getDeleted()) {
resultDomain.fail("横幅不存在");
return resultDomain;
@@ -153,7 +133,7 @@ public class NCBannerServiceImpl implements BannerService {
// 如果修改了标题,检查标题是否已被使用
if (StringUtils.hasText(banner.getTitle()) && !banner.getTitle().equals(existing.getTitle())) {
int count = bannerMapper.countByTitle(banner.getTitle(), banner.getID());
int count = bannerMapper.countByTitle(banner.getTitle(), banner.getBannerID());
if (count > 0) {
resultDomain.fail("横幅标题已存在");
return resultDomain;
@@ -166,9 +146,9 @@ public class NCBannerServiceImpl implements BannerService {
// 更新数据库
int result = bannerMapper.updateBanner(banner);
if (result > 0) {
logger.info("更新横幅成功: {}", banner.getID());
logger.info("更新横幅成功: {}", banner.getBannerID());
// 重新查询返回完整数据
TbBanner updated = bannerMapper.selectById(banner.getID());
TbBanner updated = bannerMapper.selectByBannerId(banner.getBannerID());
resultDomain.success("更新横幅成功", updated);
return resultDomain;
} else {
@@ -247,7 +227,7 @@ public class NCBannerServiceImpl implements BannerService {
if (result > 0) {
logger.info("更新横幅状态成功: {}", bannerID);
// 重新查询返回完整数据
TbBanner updated = bannerMapper.selectById(banner.getID());
TbBanner updated = bannerMapper.selectByBannerId(banner.getBannerID());
resultDomain.success("更新横幅状态成功", updated);
return resultDomain;
} else {
@@ -291,7 +271,7 @@ public class NCBannerServiceImpl implements BannerService {
if (result > 0) {
logger.info("更新横幅排序成功: {}", bannerID);
// 重新查询返回完整数据
TbBanner updated = bannerMapper.selectById(banner.getID());
TbBanner updated = bannerMapper.selectByBannerId(banner.getBannerID());
resultDomain.success("更新横幅排序成功", updated);
return resultDomain;
} else {
@@ -377,4 +357,15 @@ public class NCBannerServiceImpl implements BannerService {
return resultDomain;
}
}
@Override
public ResultDomain<TbBanner> selectHomeBanners() {
ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
TbBanner filter = new TbBanner();
filter.setStatus(1);
List<TbBanner> list = bannerMapper.selectBannersLimit(filter, 5);
resultDomain.success("获取首页横幅列表成功", list);
return resultDomain;
}
}

View File

@@ -13,9 +13,11 @@ import org.springframework.util.StringUtils;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.dto.resource.TbResourceTag;
import org.xyzh.common.dto.resource.TbTag;
import org.xyzh.common.dto.user.TbSysUser;
import org.xyzh.common.utils.IDUtils;
import org.xyzh.news.mapper.ResourceTagMapper;
import org.xyzh.news.mapper.TagMapper;
import org.xyzh.system.utils.LoginUtil;
import org.xyzh.api.news.tag.TagService;
/**
@@ -89,39 +91,27 @@ public class NCTagServiceImpl implements TagService {
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbTag> updateTag(TbTag tag) {
ResultDomain<TbTag> resultDomain = new ResultDomain<>();
TbSysUser user = LoginUtil.getCurrentUser();
if (user == null) {
resultDomain.fail("用户未登录");
return resultDomain;
}
try {
// 参数验证
if (tag == null || !StringUtils.hasText(tag.getID())) {
if (tag == null || !StringUtils.hasText(tag.getTagID())) {
resultDomain.fail("标签ID不能为空");
return resultDomain;
}
// 检查标签是否存在
TbTag existingTag = tagMapper.selectById(tag.getID());
if (existingTag == null || existingTag.getDeleted()) {
resultDomain.fail("标签不存在");
return resultDomain;
}
// 检查标签名称是否重复(排除自身,同类型下)
if (StringUtils.hasText(tag.getName())) {
Integer tagType = tag.getTagType() != null ? tag.getTagType() : existingTag.getTagType();
int count = tagMapper.countByNameAndType(tag.getName(), tagType, tag.getID());
if (count > 0) {
resultDomain.fail("该类型下标签名称已存在");
return resultDomain;
}
}
// 更新时间
tag.setUpdater(user.getID());
tag.setUpdateTime(new Date());
// 更新数据库
int result = tagMapper.updateTag(tag);
if (result > 0) {
logger.info("更新标签成功: {}", tag.getID());
logger.info("更新标签成功: {}", tag.getTagID());
// 重新查询返回完整数据
TbTag updated = tagMapper.selectById(tag.getID());
TbTag updated = tagMapper.selectByTagId(tag.getTagID());
resultDomain.success("更新标签成功", updated);
return resultDomain;
} else {

View File

@@ -5,6 +5,7 @@
<!-- 基础结果映射 -->
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.resource.TbBanner">
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="banner_id" property="bannerID" jdbcType="VARCHAR"/>
<result column="title" property="title" jdbcType="VARCHAR"/>
<result column="image_url" property="imageUrl" jdbcType="VARCHAR"/>
<result column="link_type" property="linkType" jdbcType="INTEGER"/>
@@ -22,7 +23,7 @@
<!-- 基础字段 -->
<sql id="Base_Column_List">
id, title, image_url, link_type, link_id, link_url, order_num, status,
id, banner_id, title, image_url, link_type, link_id, link_url, order_num, status,
creator, updater, create_time, update_time, delete_time, deleted
</sql>
@@ -30,6 +31,9 @@
<sql id="Where_Clause">
<where>
deleted = 0
<if test="bannerID != null and bannerID != ''">
AND banner_id = #{bannerID}
</if>
<if test="title != null and title != ''">
AND title LIKE CONCAT('%', #{title}, '%')
</if>
@@ -44,6 +48,26 @@
</if>
</where>
</sql>
<sql id="Filter_Clause">
<where>
deleted = 0
<if test="filter.bannerID != null and filter.bannerID != ''">
AND banner_id = #{filter.bannerID}
</if>
<if test="filter.title != null and filter.title != ''">
AND title LIKE CONCAT('%', #{filter.title}, '%')
</if>
<if test="filter.linkType != null">
AND link_type = #{filter.linkType}
</if>
<if test="filter.linkID != null and filter.linkID != ''">
AND link_id = #{filter.linkID}
</if>
<if test="filter.status != null">
AND status = #{filter.status}
</if>
</where>
</sql>
<!-- selectBanners -->
<select id="selectBanners" resultMap="BaseResultMap">
@@ -54,12 +78,21 @@
ORDER BY order_num ASC, create_time DESC
</select>
<select id="selectBannersLimit" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM tb_banner
<include refid="Filter_Clause"/>
ORDER BY order_num ASC, create_time DESC
LIMIT #{limit}
</select>
<!-- 根据Banner ID查询Banner信息 -->
<select id="selectByBannerId" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_banner
WHERE id = #{bannerId} AND deleted = 0
WHERE banner_id = #{bannerID} AND deleted = 0
</select>
<!-- 根据状态查询Banner列表 -->
@@ -95,18 +128,18 @@
FROM tb_banner
WHERE title = #{title} AND deleted = 0
<if test="excludeId != null and excludeId != ''">
AND id != #{excludeId}
AND banner_id != #{excludeId}
</if>
</select>
<!-- 插入Banner -->
<insert id="insertBanner" parameterType="org.xyzh.common.dto.resource.TbBanner">
INSERT INTO tb_banner (
id, title, image_url, link_type, link_id, link_url, order_num, status,
creator, updater, create_time, update_time, delete_time, deleted
id, banner_id, title, image_url, link_type, link_id, link_url, order_num, status,
creator, create_time
) VALUES (
#{id}, #{title}, #{imageUrl}, #{linkType}, #{linkID}, #{linkUrl}, #{orderNum}, #{status},
#{creator}, #{updater}, #{createTime}, #{updateTime}, #{deleteTime}, #{deleted}
#{id}, #{bannerID}, #{title}, #{imageUrl}, #{linkType}, #{linkID}, #{linkUrl}, #{orderNum}, #{status},
#{creator}, #{createTime}
)
</insert>
@@ -114,6 +147,9 @@
<update id="updateBanner" parameterType="org.xyzh.common.dto.resource.TbBanner">
UPDATE tb_banner
<set>
<if test="bannerID != null and bannerID != ''">
banner_id = #{bannerID},
</if>
<if test="title != null and title != ''">
title = #{title},
</if>
@@ -148,24 +184,24 @@
deleted = #{deleted},
</if>
</set>
WHERE id = #{id}
WHERE banner_id = #{bannerID}
</update>
<!-- 删除Banner -->
<delete id="deleteBanner" parameterType="org.xyzh.common.dto.resource.TbBanner">
DELETE FROM tb_banner
WHERE id = #{id}
WHERE banner_id = #{bannerID}
</delete>
<!-- 批量插入Banner -->
<insert id="batchInsertBanners" parameterType="java.util.List">
INSERT INTO tb_banner (
id, title, image_url, link_type, link_id, link_url, order_num, status,
id, banner_id, title, image_url, link_type, link_id, link_url, order_num, status,
creator, updater, create_time, update_time, delete_time, deleted
) VALUES
<foreach collection="bannerList" item="item" separator=",">
(
#{item.id}, #{item.title}, #{item.imageUrl}, #{item.linkType}, #{item.linkID},
#{item.id}, #{item.bannerID}, #{item.title}, #{item.imageUrl}, #{item.linkType}, #{item.linkID},
#{item.linkUrl}, #{item.orderNum}, #{item.status}, #{item.creator}, #{item.updater},
#{item.createTime}, #{item.updateTime}, #{item.deleteTime}, #{item.deleted}
)
@@ -175,9 +211,9 @@
<!-- 批量删除Banner -->
<delete id="batchDeleteBanners">
DELETE FROM tb_banner
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
WHERE banner_id IN
<foreach collection="ids" item="bannerID" open="(" separator="," close=")">
#{bannerID}
</foreach>
</delete>
@@ -186,7 +222,7 @@
SELECT
<include refid="Base_Column_List" />
FROM tb_banner
<include refid="Where_Clause" />
<include refid="Filter_Clause" />
ORDER BY order_num ASC, create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select>
@@ -195,7 +231,7 @@
<select id="countBanners" resultType="long">
SELECT COUNT(1)
FROM tb_banner
<include refid="Where_Clause" />
<include refid="Filter_Clause" />
</select>
</mapper>