添加博客标签相关功能

This commit is contained in:
huangge1199 2024-08-27 10:39:40 +08:00
parent 5afe4ba819
commit db8a2e9cf9
8 changed files with 471 additions and 0 deletions

View File

@ -0,0 +1,116 @@
package com.ruoyi.blog.controller;
import java.util.List;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.web.annotation.RepeatSubmit;
import com.ruoyi.common.web.core.BaseController;
import jakarta.annotation.Resource;
import com.ruoyi.blog.domain.vo.BlogTagsVo;
import com.ruoyi.blog.domain.bo.BlogTagsBo;
import com.ruoyi.blog.service.IBlogTagsService;
import com.ruoyi.common.orm.core.page.TableDataInfo;
/**
* 博客标签Controller
*
* @author huangge1199
* 2024-08-27
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/blog/tags")
public class BlogTagsController extends BaseController
{
@Resource
private IBlogTagsService blogTagsService;
/**
* 查询博客标签列表
*/
@SaCheckPermission("blog:tags:list")
@GetMapping("/list")
public TableDataInfo<BlogTagsVo> list(BlogTagsBo blogTagsBo)
{
return blogTagsService.selectPage(blogTagsBo);
}
/**
* 导出博客标签列表
*/
@SaCheckPermission("blog:tags:export")
@Log(title = "博客标签", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, BlogTagsBo blogTagsBo)
{
List<BlogTagsVo> list = blogTagsService.selectList(blogTagsBo);
ExcelUtil.exportExcel(list, "博客标签", BlogTagsVo.class, response);
}
/**
* 获取博客标签详细信息
*/
@SaCheckPermission("blog:tags:query")
@GetMapping(value = "/{id}")
public R<BlogTagsVo> getInfo(@PathVariable Long id)
{
return R.ok(blogTagsService.selectById(id));
}
/**
* 新增博客标签
*/
@SaCheckPermission("blog:tags:add")
@Log(title = "博客标签", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping
public R<Void> add(@Validated @RequestBody BlogTagsBo blogTagsBo)
{
boolean inserted = blogTagsService.insert(blogTagsBo);
if (!inserted) {
return R.fail("新增博客标签记录失败!");
}
return R.ok();
}
/**
* 修改博客标签
*/
@SaCheckPermission("blog:tags:edit")
@Log(title = "博客标签", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping
public R<Void> edit(@Validated @RequestBody BlogTagsBo blogTagsBo)
{
Boolean updated = blogTagsService.update(blogTagsBo);
if (!updated) {
R.fail("修改博客标签记录失败!");
}
return R.ok();
}
/**
* 删除博客标签
*/
@SaCheckPermission("blog:tags:remove")
@Log(title = "博客标签", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@PathVariable Long[] ids)
{
boolean deleted = blogTagsService.deleteByIds(ids);
if (!deleted) {
R.fail("删除博客标签记录失败!");
}
return R.ok();
}
}

View File

@ -0,0 +1,34 @@
package com.ruoyi.blog.domain;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 博客标签对象 blog_tags
*
* @author huangge1199
* 2024-08-27
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Table(value = "blog_tags")
public class BlogTags extends BaseEntity
{
/** */
@Id
private Long id;
/** 颜色 */
private String color;
/** 名称 */
private String name;
/** 固定链接地址 */
private String slug;
}

View File

@ -0,0 +1,46 @@
package com.ruoyi.blog.domain.bo;
import com.ruoyi.blog.domain.BlogTags;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 博客标签业务对象 blog_tags
*
* @author huangge1199
* @date 2024-08-27
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = BlogTags.class, reverseConvertGenerate = false)
public class BlogTagsBo extends BaseEntity
{
/**
*
*/
@NotNull(message = "不能为空")
private Long id;
/**
* 颜色
*/
private String color;
/**
* 名称
*/
@NotBlank(message = "名称不能为空")
private String name;
/**
* 固定链接地址
*/
@NotBlank(message = "固定链接地址不能为空")
private String slug;
}

View File

@ -0,0 +1,50 @@
package com.ruoyi.blog.domain.vo;
import com.ruoyi.blog.domain.BlogTags;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.ruoyi.common.excel.annotation.ExcelDictFormat;
import com.ruoyi.common.excel.convert.ExcelDictConvert;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 博客标签视图对象 blog_tags
*
* @author huangge1199
* @date 2024-08-27
*/
@Data
@ExcelIgnoreUnannotated
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = BlogTags.class)
public class BlogTagsVo extends BaseEntity implements Serializable
{
@Serial
private static final long serialVersionUID = 1L;
/** */
@ExcelProperty(value = "")
private Long id;
/** 颜色 */
@ExcelProperty(value = "颜色")
private String color;
/** 名称 */
@ExcelProperty(value = "名称")
private String name;
/** 固定链接地址 */
@ExcelProperty(value = "固定链接地址")
private String slug;
}

View File

@ -0,0 +1,17 @@
package com.ruoyi.blog.mapper;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.ruoyi.blog.domain.BlogTags;
/**
* 博客标签Mapper接口
*
* @author huangge1199
* 2024-08-27
*/
@Mapper
public interface BlogTagsMapper extends BaseMapper<BlogTags>
{
}

View File

@ -0,0 +1,66 @@
package com.ruoyi.blog.service;
import java.util.List;
import com.ruoyi.blog.domain.BlogTags;
import com.ruoyi.blog.domain.vo.BlogTagsVo;
import com.ruoyi.blog.domain.bo.BlogTagsBo;
import com.ruoyi.common.orm.core.service.IBaseService;
import com.ruoyi.common.orm.core.page.TableDataInfo;
/**
* 博客标签Service接口
*
* @author huangge1199
* 2024-08-27
*/
public interface IBlogTagsService extends IBaseService<BlogTags>
{
/**
* 查询博客标签
*
* @param id 博客标签主键
* @return 博客标签
*/
BlogTagsVo selectById(Long id);
/**
* 查询博客标签列表
*
* @param blogTagsBo 博客标签Bo
* @return 博客标签集合
*/
List<BlogTagsVo> selectList(BlogTagsBo blogTagsBo);
/**
* 分页查询博客标签列表
*
* @param blogTagsBo 博客标签Bo
* @return 分页博客标签集合
*/
TableDataInfo<BlogTagsVo> selectPage(BlogTagsBo blogTagsBo);
/**
* 新增博客标签
*
* @param blogTagsBo 博客标签Bo
* @return 结果:true 操作成功false 操作失败
*/
boolean insert(BlogTagsBo blogTagsBo);
/**
* 修改博客标签
*
* @param blogTagsBo 博客标签Bo
* @return 结果:true 更新成功false 更新失败
*/
boolean update(BlogTagsBo blogTagsBo);
/**
* 批量删除博客标签
*
* @param ids 需要删除的博客标签主键集合
* @return 结果:true 删除成功false 删除失败
*/
boolean deleteByIds(Long[] ids);
}

View File

@ -0,0 +1,135 @@
package com.ruoyi.blog.service.impl;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import cn.hutool.core.util.ObjectUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.orm.core.page.PageQuery;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
import com.ruoyi.common.core.utils.DateUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.blog.mapper.BlogTagsMapper;
import com.ruoyi.blog.domain.BlogTags;
import com.ruoyi.blog.domain.bo.BlogTagsBo;
import com.ruoyi.blog.domain.vo.BlogTagsVo;
import com.ruoyi.blog.service.IBlogTagsService;
import static com.ruoyi.blog.domain.table.BlogTagsTableDef.BLOG_TAGS;
/**
* 博客标签Service业务层处理
*
* @author huangge1199
* 2024-08-27
*/
@Service
public class BlogTagsServiceImpl extends BaseServiceImpl<BlogTagsMapper, BlogTags> implements IBlogTagsService
{
@Resource
private BlogTagsMapper blogTagsMapper;
@Override
public QueryWrapper query() {
return super.query().from(BLOG_TAGS);
}
private QueryWrapper buildQueryWrapper(BlogTagsBo blogTagsBo) {
QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
if (StringUtils.isNotBlank(blogTagsBo.getName())) {
queryWrapper.and(BLOG_TAGS.NAME.like(blogTagsBo.getName()));
}
return queryWrapper;
}
/**
* 查询博客标签
*
* @param id 博客标签主键
* @return 博客标签
*/
@Override
public BlogTagsVo selectById(Long id)
{
return this.getOneAs(query().where(BLOG_TAGS.ID.eq(id)), BlogTagsVo.class);
}
/**
* 查询博客标签列表
*
* @param blogTagsBo 博客标签Bo
* @return 博客标签集合
*/
@Override
public List<BlogTagsVo> selectList(BlogTagsBo blogTagsBo)
{
QueryWrapper queryWrapper = buildQueryWrapper(blogTagsBo);
return this.listAs(queryWrapper, BlogTagsVo.class);
}
/**
* 分页查询博客标签列表
*
* @param blogTagsBo 博客标签Bo
* @return 分页博客标签集合
*/
@Override
public TableDataInfo<BlogTagsVo> selectPage(BlogTagsBo blogTagsBo)
{
QueryWrapper queryWrapper = buildQueryWrapper(blogTagsBo);
Page<BlogTagsVo> page = this.pageAs(PageQuery.build(), queryWrapper, BlogTagsVo.class);
return TableDataInfo.build(page);
}
/**
* 新增博客标签
*
* @param blogTagsBo 博客标签Bo
* @return 结果:true 操作成功false 操作失败
*/
@Override
public boolean insert(BlogTagsBo blogTagsBo)
{
BlogTags blogTags = MapstructUtils.convert(blogTagsBo, BlogTags.class);
return this.save(blogTags);//使用全局配置的雪花算法主键生成器生成ID值
}
/**
* 修改博客标签
*
* @param blogTagsBo 博客标签Bo
* @return 结果:true 更新成功false 更新失败
*/
@Override
public boolean update(BlogTagsBo blogTagsBo)
{
BlogTags blogTags = MapstructUtils.convert(blogTagsBo, BlogTags.class);
if(ObjectUtil.isNotNull(blogTags) && ObjectUtil.isNotNull(blogTags.getId())) {
boolean updated = this.updateById(blogTags);
}
return false;
}
/**
* 批量删除博客标签
*
* @param ids 需要删除的博客标签主键集合
* @return 结果:true 删除成功false 删除失败
*/
@Transactional
@Override
public boolean deleteByIds(Long[] ids)
{
return this.removeByIds(Arrays.asList(ids));
}
}

View File

@ -0,0 +1,7 @@
<?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="com.ruoyi.blog.mapper.BlogTagsMapper">
</mapper>