init
This commit is contained in:
@@ -0,0 +1,290 @@
|
||||
package com.ruoyi.cms.blog.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.cms.fileInfo.service.ISysFileInfoService;
|
||||
import com.ruoyi.cms.tag.domain.CmsTag;
|
||||
import com.ruoyi.cms.tag.service.ICmsTagService;
|
||||
import com.ruoyi.cms.type.domain.CmsType;
|
||||
import com.ruoyi.cms.type.service.ICmsTypeService;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.cms.blog.domain.CmsBlog;
|
||||
import com.ruoyi.cms.blog.service.ICmsBlogService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
|
||||
/**
|
||||
* 文章管理Controller
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-01
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/cms/blog")
|
||||
public class CmsBlogController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ICmsBlogService cmsBlogService;
|
||||
|
||||
@Autowired
|
||||
private ICmsTypeService cmsTypeService;
|
||||
|
||||
@Autowired
|
||||
private ICmsTagService cmsTagService;
|
||||
|
||||
@Autowired
|
||||
private SysPermissionService permissionService;
|
||||
|
||||
@Autowired
|
||||
private ISysFileInfoService sysFileInfoService;
|
||||
|
||||
/**
|
||||
* 首页查询文章列表
|
||||
*/
|
||||
@GetMapping("/cms/cmsList")
|
||||
public TableDataInfo cmsList(CmsBlog cmsBlog)
|
||||
{
|
||||
startPage();
|
||||
//状态为发布
|
||||
cmsBlog.setStatus("1");
|
||||
List<CmsBlog> list = cmsBlogService.selectCmsBlogList(cmsBlog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页获取文章详细信息
|
||||
*/
|
||||
@GetMapping(value = { "/cms/detail/", "/cms/detail/{id}" })
|
||||
public AjaxResult getInfoDetail(@PathVariable(value = "id", required = false) Long id)
|
||||
{
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
CmsType cmsType = new CmsType();
|
||||
CmsTag cmsTag = new CmsTag();
|
||||
ajax.put("types", cmsTypeService.selectCmsTypeList(cmsType));
|
||||
ajax.put("tags", cmsTagService.selectCmsTagList(cmsTag));
|
||||
if (StringUtils.isNotNull(id))
|
||||
{
|
||||
ajax.put(AjaxResult.DATA_TAG, cmsBlogService.selectCmsBlogById(id));
|
||||
}
|
||||
return ajax;
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页按分类查询文章列表
|
||||
*/
|
||||
@GetMapping("/cms/cmsListByType/{id}")
|
||||
public TableDataInfo cmsListByTypeId(@PathVariable(value = "id", required = false) Long id)
|
||||
{
|
||||
startPage();
|
||||
List<CmsBlog> list = cmsBlogService.selectCmsBlogListByTypeId(id);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页按标签查询文章列表
|
||||
*/
|
||||
@GetMapping("/cms/cmsListByTag/{id}")
|
||||
public TableDataInfo cmsListByTagId(@PathVariable(value = "id", required = false) Long id)
|
||||
{
|
||||
startPage();
|
||||
List<CmsBlog> list = cmsBlogService.selectCmsBlogListByTagId(id);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页查询推荐文章列表
|
||||
*/
|
||||
@GetMapping("/cms/cmsListRecommend")
|
||||
public TableDataInfo cmsListRecommend(CmsBlog cmsBlog)
|
||||
{
|
||||
startPage();
|
||||
//状态为发布
|
||||
cmsBlog.setStatus("1");
|
||||
List<CmsBlog> list = cmsBlogService.selectCmsBlogListRecommend(cmsBlog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页增加阅读量
|
||||
*/
|
||||
@GetMapping("/cms/addBlogViews/{id}")
|
||||
public AjaxResult addBlogViews(@PathVariable(value = "id", required = false) Long id)
|
||||
{
|
||||
CmsBlog cmsBlog = cmsBlogService.selectCmsBlogById(id);
|
||||
Long views = cmsBlog.getViews();
|
||||
views+=Long.parseLong("1");
|
||||
cmsBlog.setViews(views);
|
||||
cmsBlogService.updateCmsBlog(cmsBlog);
|
||||
return AjaxResult.success(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 随笔页查询文章列表
|
||||
*/
|
||||
@GetMapping("/cms/cmsEssayList")
|
||||
public TableDataInfo cmsEssayList(CmsBlog cmsBlog)
|
||||
{
|
||||
startPage();
|
||||
//状态为发布
|
||||
cmsBlog.setStatus("1");
|
||||
List<CmsBlog> list = cmsBlogService.selectCmsBlogList(cmsBlog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文章管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:blog:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(CmsBlog cmsBlog)
|
||||
{
|
||||
startPage();
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (!SecurityUtils.isAdmin(getUserId())&&!roles.contains("admin")&&!roles.contains("cms")){
|
||||
cmsBlog.setCreateBy(getUsername());
|
||||
}
|
||||
List<CmsBlog> list = cmsBlogService.selectCmsBlogList(cmsBlog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出文章管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:blog:export')")
|
||||
@Log(title = "文章管理", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, CmsBlog cmsBlog)
|
||||
{
|
||||
List<CmsBlog> list = cmsBlogService.selectCmsBlogList(cmsBlog);
|
||||
ExcelUtil<CmsBlog> util = new ExcelUtil<CmsBlog>(CmsBlog.class);
|
||||
util.exportExcel(response, list, "文章管理数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文章管理详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:blog:query')")
|
||||
@GetMapping(value = { "/", "/{id}" })
|
||||
public AjaxResult getInfo(@PathVariable(value = "id", required = false) Long id)
|
||||
{
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
CmsType cmsType = new CmsType();
|
||||
CmsTag cmsTag = new CmsTag();
|
||||
ajax.put("types", cmsTypeService.selectCmsTypeList(cmsType));
|
||||
ajax.put("tags", cmsTagService.selectCmsTagList(cmsTag));
|
||||
if (StringUtils.isNotNull(id))
|
||||
{
|
||||
ajax.put(AjaxResult.DATA_TAG, cmsBlogService.selectCmsBlogById(id));
|
||||
}
|
||||
return ajax;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增文章管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:blog:add')")
|
||||
@Log(title = "文章管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody CmsBlog cmsBlog)
|
||||
{
|
||||
cmsBlog.setCreateBy(getUsername());
|
||||
Long blogId = cmsBlogService.insertCmsBlog(cmsBlog);
|
||||
if (blogId==null){
|
||||
return AjaxResult.error();
|
||||
}
|
||||
return AjaxResult.success(blogId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文章管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:blog:edit')")
|
||||
@Log(title = "文章管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody CmsBlog cmsBlog)
|
||||
{
|
||||
cmsBlog.setUpdateBy(getUsername());
|
||||
//删除原首图
|
||||
CmsBlog oldBlog = cmsBlogService.selectCmsBlogById(cmsBlog.getId());
|
||||
if (cmsBlog.getBlogPic().isEmpty()||!cmsBlog.getBlogPic().equals(oldBlog.getBlogPic())){
|
||||
if(!oldBlog.getBlogPic().isEmpty()){
|
||||
String blogPic = oldBlog.getBlogPic();
|
||||
if (blogPic!=null&&!"".equals(blogPic)){
|
||||
int newFileNameSeparatorIndex = blogPic.lastIndexOf("/");
|
||||
String FileName = blogPic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
|
||||
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return toAjax(cmsBlogService.updateCmsBlog(cmsBlog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:blog:remove')")
|
||||
@Log(title = "文章管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
//删除原首图
|
||||
for (Long id : ids) {
|
||||
CmsBlog oldBlog = cmsBlogService.selectCmsBlogById(id);
|
||||
if(!oldBlog.getBlogPic().isEmpty()){
|
||||
String blogPic = oldBlog.getBlogPic();
|
||||
if (blogPic!=null&&!"".equals(blogPic)){
|
||||
int newFileNameSeparatorIndex = blogPic.lastIndexOf("/");
|
||||
String FileName = blogPic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
|
||||
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return toAjax(cmsBlogService.deleteCmsBlogByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消按钮-删除首图
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:blog:edit')")
|
||||
@PostMapping("/cancel")
|
||||
public AjaxResult cancel(@RequestBody CmsBlog cmsBlog)
|
||||
{
|
||||
String blogPic = cmsBlog.getBlogPic();
|
||||
if (blogPic!=null&&!"".equals(blogPic)){
|
||||
Long blogId = cmsBlog.getId();
|
||||
if (blogId==null){
|
||||
int newFileNameSeparatorIndex = blogPic.lastIndexOf("/");
|
||||
String FileName = blogPic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
|
||||
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
|
||||
}else {
|
||||
String Pic = cmsBlogService.selectCmsBlogById(blogId).getBlogPic();
|
||||
if (!blogPic.equals(Pic)){
|
||||
int newFileNameSeparatorIndex = blogPic.lastIndexOf("/");
|
||||
String FileName = blogPic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
|
||||
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return toAjax(1);
|
||||
}
|
||||
}
|
||||
282
ruoyi-cms/src/main/java/com/ruoyi/cms/blog/domain/CmsBlog.java
Normal file
282
ruoyi-cms/src/main/java/com/ruoyi/cms/blog/domain/CmsBlog.java
Normal file
@@ -0,0 +1,282 @@
|
||||
package com.ruoyi.cms.blog.domain;
|
||||
|
||||
import com.ruoyi.cms.tag.domain.CmsTag;
|
||||
import com.ruoyi.cms.type.domain.CmsType;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文章管理对象 cms_blog
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-01
|
||||
*/
|
||||
public class CmsBlog extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
@Excel(name = "标题")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 类型 1文章 2随笔
|
||||
*/
|
||||
@Excel(name = "类型")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
@Excel(name = "内容")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 文本编辑器类型 1 Quill富文本编辑器 2 CherryMarkdown
|
||||
*/
|
||||
@Excel(name = "文本编辑器类型")
|
||||
private String contentType;
|
||||
|
||||
/**
|
||||
* Markdown格式内容
|
||||
*/
|
||||
@Excel(name = "Markdown格式内容")
|
||||
private String contentMarkdown;
|
||||
|
||||
/**
|
||||
* 置顶(0否 1是)
|
||||
*/
|
||||
@Excel(name = "置顶", readConverterExp = "0=否,1=是")
|
||||
private String top;
|
||||
|
||||
/**
|
||||
* 阅读
|
||||
*/
|
||||
@Excel(name = "阅读")
|
||||
private Long views;
|
||||
|
||||
/**
|
||||
* 状态(0暂存 1发布)
|
||||
*/
|
||||
@Excel(name = "状态", readConverterExp = "0=暂存,1=发布")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 首页图片类型(0地址 1上传)
|
||||
*/
|
||||
@Excel(name = "首页图片类型", readConverterExp = "0=地址,1=上传")
|
||||
private String blogPicType;
|
||||
|
||||
/** 首页图片( 1上传) */
|
||||
@Excel(name = "首页图片( 1上传)")
|
||||
private String blogPic;
|
||||
|
||||
/** 首页图片( 0地址) */
|
||||
@Excel(name = "首页图片( 0地址)")
|
||||
private String blogPicLink;
|
||||
|
||||
/** 简介 */
|
||||
@Excel(name = "简介")
|
||||
private String blogDesc;
|
||||
|
||||
/** 附件列表 */
|
||||
private String blogFiles;
|
||||
|
||||
/**
|
||||
* 分类
|
||||
*/
|
||||
private Long[] typeIds;
|
||||
|
||||
/**
|
||||
* 分类
|
||||
*/
|
||||
private Long[] tagIds;
|
||||
|
||||
/** 角色对象 */
|
||||
private List<CmsTag> tags;
|
||||
|
||||
/** 角色对象 */
|
||||
private List<CmsType> types;
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setTop(String top) {
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
public String getTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
public void setViews(Long views) {
|
||||
this.views = views;
|
||||
}
|
||||
|
||||
public Long getViews() {
|
||||
return views;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public Long[] getTypeIds() {
|
||||
return typeIds;
|
||||
}
|
||||
|
||||
public void setTypeIds(Long[] typeIds) {
|
||||
this.typeIds = typeIds;
|
||||
}
|
||||
|
||||
public Long[] getTagIds() {
|
||||
return tagIds;
|
||||
}
|
||||
|
||||
public void setTagIds(Long[] tagIds) {
|
||||
this.tagIds = tagIds;
|
||||
}
|
||||
|
||||
public List<CmsTag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<CmsTag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public List<CmsType> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(List<CmsType> types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public String getBlogPic() {
|
||||
return blogPic;
|
||||
}
|
||||
|
||||
public void setBlogPic(String blogPic) {
|
||||
this.blogPic = blogPic;
|
||||
}
|
||||
|
||||
public String getBlogDesc() {
|
||||
return blogDesc;
|
||||
}
|
||||
|
||||
public void setBlogDesc(String blogDesc) {
|
||||
this.blogDesc = blogDesc;
|
||||
}
|
||||
|
||||
public String getBlogFiles() {
|
||||
return blogFiles;
|
||||
}
|
||||
|
||||
public void setBlogFiles(String blogFiles) {
|
||||
this.blogFiles = blogFiles;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getContentMarkdown() {
|
||||
return contentMarkdown;
|
||||
}
|
||||
|
||||
public void setContentMarkdown(String contentMarkdown) {
|
||||
this.contentMarkdown = contentMarkdown;
|
||||
}
|
||||
|
||||
public String getBlogPicType() {
|
||||
return blogPicType;
|
||||
}
|
||||
|
||||
public void setBlogPicType(String blogPicType) {
|
||||
this.blogPicType = blogPicType;
|
||||
}
|
||||
|
||||
public String getBlogPicLink() {
|
||||
return blogPicLink;
|
||||
}
|
||||
|
||||
public void setBlogPicLink(String blogPicLink) {
|
||||
this.blogPicLink = blogPicLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("title", getTitle())
|
||||
.append("type", getType())
|
||||
.append("content", getContent())
|
||||
.append("contentType", getContentType())
|
||||
.append("contentMarkdown", getContentMarkdown())
|
||||
.append("top", getTop())
|
||||
.append("views", getViews())
|
||||
.append("status", getStatus())
|
||||
.append("typeIds", getTypeIds())
|
||||
.append("tagIds", getTagIds())
|
||||
.append("tags", getTags())
|
||||
.append("types", getTypes())
|
||||
.append("blogPicType", getBlogPicType())
|
||||
.append("blogPic", getBlogPic())
|
||||
.append("blogPicLink", getBlogPicLink())
|
||||
.append("blogDesc", getBlogDesc())
|
||||
.append("blogFiles", getBlogFiles())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.ruoyi.cms.blog.domain;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈blog标签关联表 cms_blog_tag〉
|
||||
* @Date: 2022/1/2 22:54
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈blog标签关联表 cms_blog_tag〉
|
||||
* @Date: 2022/1/2 22:54
|
||||
**/
|
||||
public class CmsBlogTag {
|
||||
private Long tagId;
|
||||
private Long blogId;
|
||||
private Long[] tagIds;
|
||||
|
||||
public Long getTagId() {
|
||||
return tagId;
|
||||
}
|
||||
|
||||
public void setTagId(Long tagId) {
|
||||
this.tagId = tagId;
|
||||
}
|
||||
|
||||
public Long getBlogId() {
|
||||
return blogId;
|
||||
}
|
||||
|
||||
public void setBlogId(Long blogId) {
|
||||
this.blogId = blogId;
|
||||
}
|
||||
|
||||
public Long[] getTagIds() {
|
||||
return tagIds;
|
||||
}
|
||||
|
||||
public void setTagIds(Long[] tagIds) {
|
||||
this.tagIds = tagIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("tagId", getTagId())
|
||||
.append("blogId", getBlogId())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.ruoyi.cms.blog.domain;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈blog类型关联表 cms_blog_type〉
|
||||
* @Date: 2022/1/2 23:34
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈blog分类关联表 cms_blog_type〉
|
||||
* @Date: 2022/1/2 23:34
|
||||
**/
|
||||
public class CmsBlogType {
|
||||
private Long typeId;
|
||||
private Long blogId;
|
||||
private Long[] typeIds;
|
||||
|
||||
public Long getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public void setTypeId(Long typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public Long getBlogId() {
|
||||
return blogId;
|
||||
}
|
||||
|
||||
public void setBlogId(Long blogId) {
|
||||
this.blogId = blogId;
|
||||
}
|
||||
|
||||
public Long[] getTypeIds() {
|
||||
return typeIds;
|
||||
}
|
||||
|
||||
public void setTypeIds(Long[] typeIds) {
|
||||
this.typeIds = typeIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("typeId", getTypeId())
|
||||
.append("blogId", getBlogId())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.ruoyi.cms.blog.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.blog.domain.CmsBlog;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 文章管理Mapper接口
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-01
|
||||
*/
|
||||
public interface CmsBlogMapper
|
||||
{
|
||||
/**
|
||||
* 查询文章管理
|
||||
*
|
||||
* @param id 文章管理主键
|
||||
* @return 文章管理
|
||||
*/
|
||||
public CmsBlog selectCmsBlogById(Long id);
|
||||
|
||||
/**
|
||||
* 查询文章管理列表
|
||||
*
|
||||
* @param cmsBlog 文章管理
|
||||
* @return 文章管理集合
|
||||
*/
|
||||
public List<CmsBlog> selectCmsBlogList(CmsBlog cmsBlog);
|
||||
|
||||
public List<CmsBlog> selectCmsBlogListBetweenCreateTime(@Param("title") String title,@Param("type") String type,@Param("top") String top,@Param("status") String status,@Param("createTimeBegin") String createTimeBegin,@Param("createTimeEnd") String createTimeEnd,@Param("createBy") String createBy);
|
||||
|
||||
/**
|
||||
* 查询推荐文章列表
|
||||
*/
|
||||
public List<CmsBlog> selectCmsBlogListRecommend(CmsBlog cmsBlog);
|
||||
|
||||
/**
|
||||
* 按分类查询文章管理列表
|
||||
*/
|
||||
public List<CmsBlog> selectCmsBlogListByTypeId(Long id);
|
||||
|
||||
/**
|
||||
* 按标签查询文章管理列表
|
||||
*/
|
||||
public List<CmsBlog> selectCmsBlogListByTagId(Long id);
|
||||
|
||||
/**
|
||||
* 新增文章管理
|
||||
*
|
||||
* @param cmsBlog 文章管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCmsBlog(CmsBlog cmsBlog);
|
||||
|
||||
/**
|
||||
* 修改文章管理
|
||||
*
|
||||
* @param cmsBlog 文章管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsBlog(CmsBlog cmsBlog);
|
||||
|
||||
/**
|
||||
* 删除文章管理
|
||||
*
|
||||
* @param id 文章管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsBlogById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除文章管理
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsBlogByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 统计博客数量
|
||||
*
|
||||
* @param cmsBlog 查询条件
|
||||
* @return 博客数量
|
||||
*/
|
||||
public int countCmsBlog(CmsBlog cmsBlog);
|
||||
|
||||
/**
|
||||
* 统计总阅读量
|
||||
*
|
||||
* @param cmsBlog 查询条件
|
||||
* @return 总阅读量
|
||||
*/
|
||||
public Long sumViews(CmsBlog cmsBlog);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ruoyi.cms.blog.mapper;
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlogTag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈blog标签关联 数据层〉
|
||||
* @Date: 2022/1/2 23:12
|
||||
*/
|
||||
public interface CmsBlogTagMapper {
|
||||
/**
|
||||
* 批量新增
|
||||
*/
|
||||
public int batchBlogTag(List<CmsBlogTag> blogTagList);
|
||||
/**
|
||||
* 通过blogID删除blog文件关联
|
||||
*/
|
||||
public int deleteBlogTagByBlogId(Long blogId);
|
||||
/**
|
||||
* 批量删除blog文件关联
|
||||
*/
|
||||
public int deleteBlogTag(Long[] ids);
|
||||
/**
|
||||
* 查询文件列表
|
||||
*/
|
||||
public List<CmsBlogTag> selectBlogTagList(Long blogId);
|
||||
/**
|
||||
* 通过tagId删除blog文件关联
|
||||
*/
|
||||
public int deleteBlogTagByTagId(Long tagId);
|
||||
/**
|
||||
* 通过tagId统计blog数量
|
||||
*/
|
||||
public int countBlogByTagId(Long tagId);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ruoyi.cms.blog.mapper;
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlogType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈blog分类关联 数据层〉
|
||||
* @Date: 2022/1/2 23:37
|
||||
*/
|
||||
public interface CmsBlogTypeMapper {
|
||||
/**
|
||||
* 批量新增
|
||||
*/
|
||||
public int batchBlogType(List<CmsBlogType> blogTypeList);
|
||||
/**
|
||||
* 通过blogID删除blog文件关联
|
||||
*/
|
||||
public int deleteBlogTypeByBlogId(Long blogId);
|
||||
/**
|
||||
* 批量删除blog文件关联
|
||||
*/
|
||||
public int deleteBlogType(Long[] ids);
|
||||
/**
|
||||
* 查询博客列表
|
||||
*/
|
||||
public List<CmsBlogType> selectBlogTypeList(Long blogId);
|
||||
/**
|
||||
* 通过typeId删除blog文件关联
|
||||
*/
|
||||
public int deleteBlogTypeByTypeId(Long typeId);
|
||||
/**
|
||||
* 通过typeId统计blog数量
|
||||
*/
|
||||
public int countBlogByTypeId(Long typeId);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.ruoyi.cms.blog.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.blog.domain.CmsBlog;
|
||||
|
||||
/**
|
||||
* 文章管理Service接口
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-01
|
||||
*/
|
||||
public interface ICmsBlogService
|
||||
{
|
||||
/**
|
||||
* 查询文章管理
|
||||
*
|
||||
* @param id 文章管理主键
|
||||
* @return 文章管理
|
||||
*/
|
||||
public CmsBlog selectCmsBlogById(Long id);
|
||||
|
||||
/**
|
||||
* 查询文章管理列表
|
||||
*
|
||||
* @param cmsBlog 文章管理
|
||||
* @return 文章管理集合
|
||||
*/
|
||||
public List<CmsBlog> selectCmsBlogList(CmsBlog cmsBlog);
|
||||
|
||||
/**
|
||||
* 查询推荐文章列表
|
||||
*/
|
||||
public List<CmsBlog> selectCmsBlogListRecommend(CmsBlog cmsBlog);
|
||||
|
||||
/**
|
||||
* 按分类查询文章列表
|
||||
*/
|
||||
public List<CmsBlog> selectCmsBlogListByTypeId(Long id);
|
||||
|
||||
/**
|
||||
* 按标签查询文章列表
|
||||
*/
|
||||
public List<CmsBlog> selectCmsBlogListByTagId(Long id);
|
||||
|
||||
/**
|
||||
* 新增文章管理
|
||||
*
|
||||
* @param cmsBlog 文章管理
|
||||
* @return 结果
|
||||
*/
|
||||
public Long insertCmsBlog(CmsBlog cmsBlog);
|
||||
|
||||
/**
|
||||
* 修改文章管理
|
||||
*
|
||||
* @param cmsBlog 文章管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsBlog(CmsBlog cmsBlog);
|
||||
|
||||
/**
|
||||
* 批量删除文章管理
|
||||
*
|
||||
* @param ids 需要删除的文章管理主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsBlogByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除文章管理信息
|
||||
*
|
||||
* @param id 文章管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsBlogById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.cms.blog.service;
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlogTag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈${DESCRIPTION}〉
|
||||
* @Date: 2022/1/2 23:22
|
||||
*/
|
||||
public interface ICmsBlogTagService {
|
||||
/**
|
||||
* 批量新增
|
||||
*/
|
||||
public int batchBlogTag(List<CmsBlogTag> blogTagList);
|
||||
/**
|
||||
* 通过blogID删除blog标签关联
|
||||
*/
|
||||
public int deleteBlogTagByBlogId(Long blogId);
|
||||
/**
|
||||
* 批量删除blog标签关联
|
||||
*/
|
||||
public int deleteBlogTag(Long[] ids);
|
||||
/**
|
||||
* 查询标签列表
|
||||
*/
|
||||
public List<CmsBlogTag> selectBlogTagList(Long blogId);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.cms.blog.service;
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlogType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈${DESCRIPTION}〉
|
||||
* @Date: 2022/1/2 23:42
|
||||
*/
|
||||
public interface ICmsBlogTypeService {
|
||||
/**
|
||||
* 批量新增
|
||||
*/
|
||||
public int batchBlogType(List<CmsBlogType> blogTypeList);
|
||||
/**
|
||||
* 通过blogID删除blog分类关联
|
||||
*/
|
||||
public int deleteBlogTypeByBlogId(Long blogId);
|
||||
/**
|
||||
* 批量删除blog分类关联
|
||||
*/
|
||||
public int deleteBlogType(Long[] ids);
|
||||
/**
|
||||
* 查询分类列表
|
||||
*/
|
||||
public List<CmsBlogType> selectBlogTypeList(Long blogId);
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
package com.ruoyi.cms.blog.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlogTag;
|
||||
import com.ruoyi.cms.blog.domain.CmsBlogType;
|
||||
import com.ruoyi.cms.blog.mapper.CmsBlogTagMapper;
|
||||
import com.ruoyi.cms.blog.mapper.CmsBlogTypeMapper;
|
||||
import com.ruoyi.cms.tag.domain.CmsTag;
|
||||
import com.ruoyi.cms.tag.mapper.CmsTagMapper;
|
||||
import com.ruoyi.cms.type.domain.CmsType;
|
||||
import com.ruoyi.cms.type.mapper.CmsTypeMapper;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.cms.blog.mapper.CmsBlogMapper;
|
||||
import com.ruoyi.cms.blog.domain.CmsBlog;
|
||||
import com.ruoyi.cms.blog.service.ICmsBlogService;
|
||||
|
||||
/**
|
||||
* 文章管理Service业务层处理
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-01
|
||||
*/
|
||||
@Service
|
||||
public class CmsBlogServiceImpl implements ICmsBlogService
|
||||
{
|
||||
@Autowired
|
||||
private CmsBlogMapper cmsBlogMapper;
|
||||
|
||||
@Autowired
|
||||
private CmsBlogTagMapper cmsBlogTagMapper;
|
||||
|
||||
@Autowired
|
||||
private CmsTagMapper cmsTagMapper;
|
||||
|
||||
@Autowired
|
||||
private CmsBlogTypeMapper cmsBlogTypeMapper;
|
||||
|
||||
@Autowired
|
||||
private CmsTypeMapper cmsTypeMapper;
|
||||
|
||||
/**
|
||||
* 查询文章管理
|
||||
*
|
||||
* @param id 文章管理主键
|
||||
* @return 文章管理
|
||||
*/
|
||||
@Override
|
||||
public CmsBlog selectCmsBlogById(Long id)
|
||||
{
|
||||
CmsBlog blog = cmsBlogMapper.selectCmsBlogById(id);
|
||||
//查询标签列表
|
||||
List<CmsBlogTag> blogTagList = cmsBlogTagMapper.selectBlogTagList(id);
|
||||
Long[] tagIds = new Long[blogTagList.size()];
|
||||
List<CmsTag> tags = new ArrayList<>();
|
||||
List<CmsType> types = new ArrayList<>();
|
||||
for (int i = 0; i<blogTagList.size();i++){
|
||||
CmsBlogTag cmsBlogTag = blogTagList.get(i);
|
||||
Long tagId = cmsBlogTag.getTagId();
|
||||
tagIds[i] = tagId;
|
||||
CmsTag cmsTag = cmsTagMapper.selectCmsTagByTagId(tagId);
|
||||
tags.add(cmsTag);
|
||||
}
|
||||
blog.setTagIds(tagIds);
|
||||
blog.setTags(tags);
|
||||
//查询分类列表
|
||||
List<CmsBlogType> blogTypeList = cmsBlogTypeMapper.selectBlogTypeList(id);
|
||||
Long[] typeIds = new Long[blogTypeList.size()];
|
||||
for (int i = 0; i<blogTypeList.size();i++){
|
||||
CmsBlogType cmsBlogType = blogTypeList.get(i);
|
||||
Long typeId = cmsBlogType.getTypeId();
|
||||
typeIds[i] = typeId;
|
||||
CmsType cmsType = cmsTypeMapper.selectCmsTypeByTypeId(typeId);
|
||||
types.add(cmsType);
|
||||
}
|
||||
blog.setTypeIds(typeIds);
|
||||
blog.setTypes(types);
|
||||
return blog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文章管理列表
|
||||
*
|
||||
* @param cmsBlog 文章管理
|
||||
* @return 文章管理
|
||||
*/
|
||||
@Override
|
||||
public List<CmsBlog> selectCmsBlogList(CmsBlog cmsBlog)
|
||||
{
|
||||
List<CmsBlog> cmsBlogList = cmsBlogMapper.selectCmsBlogList(cmsBlog);
|
||||
|
||||
// 为每个博客设置首页图片(如果为空,则从content中提取)
|
||||
for (CmsBlog blog : cmsBlogList) {
|
||||
setDefaultBlogPicFromContent(blog);
|
||||
}
|
||||
|
||||
List<CmsBlog> blogList = BlogListAddTypeAndTag(cmsBlogList);
|
||||
return blogList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询推荐文章列表
|
||||
*/
|
||||
@Override
|
||||
public List<CmsBlog> selectCmsBlogListRecommend(CmsBlog cmsBlog) {
|
||||
List<CmsBlog> cmsBlogList = cmsBlogMapper.selectCmsBlogListRecommend(cmsBlog);
|
||||
// 为每个博客设置首页图片(如果为空,则从content中提取)
|
||||
for (CmsBlog blog : cmsBlogList) {
|
||||
setDefaultBlogPicFromContent(blog);
|
||||
}
|
||||
List<CmsBlog> blogList = BlogListAddTypeAndTag(cmsBlogList);
|
||||
return blogList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按分类查询文章列表
|
||||
*/
|
||||
@Override
|
||||
public List<CmsBlog> selectCmsBlogListByTypeId(Long id) {
|
||||
List<CmsBlog> cmsBlogList = cmsBlogMapper.selectCmsBlogListByTypeId(id);
|
||||
// 为每个博客设置首页图片(如果为空,则从content中提取)
|
||||
for (CmsBlog blog : cmsBlogList) {
|
||||
setDefaultBlogPicFromContent(blog);
|
||||
}
|
||||
List<CmsBlog> blogList = BlogListAddTypeAndTag(cmsBlogList);
|
||||
return blogList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按标签查询文章列表
|
||||
*/
|
||||
@Override
|
||||
public List<CmsBlog> selectCmsBlogListByTagId(Long id) {
|
||||
List<CmsBlog> cmsBlogList = cmsBlogMapper.selectCmsBlogListByTagId(id);
|
||||
// 为每个博客设置首页图片(如果为空,则从content中提取)
|
||||
for (CmsBlog blog : cmsBlogList) {
|
||||
setDefaultBlogPicFromContent(blog);
|
||||
}
|
||||
List<CmsBlog> blogList = BlogListAddTypeAndTag(cmsBlogList);
|
||||
return blogList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增文章管理
|
||||
*
|
||||
* @param cmsBlog 文章管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public Long insertCmsBlog(CmsBlog cmsBlog)
|
||||
{
|
||||
cmsBlog.setCreateTime(DateUtils.getNowDate());
|
||||
cmsBlogMapper.insertCmsBlog(cmsBlog);
|
||||
Long blogId = cmsBlog.getId();
|
||||
//新增文章标签
|
||||
Long[] tagIds = cmsBlog.getTagIds();
|
||||
if (tagIds!=null&&tagIds.length>0){
|
||||
List<CmsBlogTag> blogTagList = new ArrayList<>();
|
||||
for (Long tagId : tagIds) {
|
||||
CmsBlogTag cmsBlogTag = new CmsBlogTag();
|
||||
cmsBlogTag.setBlogId(blogId);
|
||||
cmsBlogTag.setTagId(tagId);
|
||||
blogTagList.add(cmsBlogTag);
|
||||
}
|
||||
cmsBlogTagMapper.batchBlogTag(blogTagList);
|
||||
}
|
||||
//新增文章分类
|
||||
Long[] typeIds = cmsBlog.getTypeIds();
|
||||
if (typeIds!=null&&typeIds.length>0){
|
||||
List<CmsBlogType> blogTypeList = new ArrayList<>();
|
||||
for (Long typeId : typeIds) {
|
||||
CmsBlogType cmsBlogType = new CmsBlogType();
|
||||
cmsBlogType.setBlogId(blogId);
|
||||
cmsBlogType.setTypeId(typeId);
|
||||
blogTypeList.add(cmsBlogType);
|
||||
}
|
||||
cmsBlogTypeMapper.batchBlogType(blogTypeList);
|
||||
}
|
||||
return blogId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文章管理
|
||||
*
|
||||
* @param cmsBlog 文章管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateCmsBlog(CmsBlog cmsBlog)
|
||||
{
|
||||
cmsBlog.setUpdateTime(DateUtils.getNowDate());
|
||||
Long blogId = cmsBlog.getId();
|
||||
//清空文章分类关联
|
||||
cmsBlogTypeMapper.deleteBlogTypeByBlogId(blogId);
|
||||
//清空文章标签关联
|
||||
cmsBlogTagMapper.deleteBlogTagByBlogId(blogId);
|
||||
//新增文章标签
|
||||
Long[] tagIds = cmsBlog.getTagIds();
|
||||
if (tagIds!=null&&tagIds.length>0){
|
||||
List<CmsBlogTag> blogTagList = new ArrayList<>();
|
||||
for (Long tagId : tagIds) {
|
||||
CmsBlogTag cmsBlogTag = new CmsBlogTag();
|
||||
cmsBlogTag.setBlogId(blogId);
|
||||
cmsBlogTag.setTagId(tagId);
|
||||
blogTagList.add(cmsBlogTag);
|
||||
}
|
||||
cmsBlogTagMapper.batchBlogTag(blogTagList);
|
||||
}
|
||||
//新增文章分类
|
||||
Long[] typeIds = cmsBlog.getTypeIds();
|
||||
if (typeIds!=null&&typeIds.length>0){
|
||||
List<CmsBlogType> blogTypeList = new ArrayList<>();
|
||||
for (Long typeId : typeIds) {
|
||||
CmsBlogType cmsBlogType = new CmsBlogType();
|
||||
cmsBlogType.setBlogId(blogId);
|
||||
cmsBlogType.setTypeId(typeId);
|
||||
blogTypeList.add(cmsBlogType);
|
||||
}
|
||||
cmsBlogTypeMapper.batchBlogType(blogTypeList);
|
||||
}
|
||||
return cmsBlogMapper.updateCmsBlog(cmsBlog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除文章管理
|
||||
*
|
||||
* @param ids 需要删除的文章管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCmsBlogByIds(Long[] ids)
|
||||
{
|
||||
for (Long id : ids) {
|
||||
//清空文章分类关联
|
||||
cmsBlogTypeMapper.deleteBlogTypeByBlogId(id);
|
||||
//清空文章标签关联
|
||||
cmsBlogTagMapper.deleteBlogTagByBlogId(id);
|
||||
}
|
||||
return cmsBlogMapper.deleteCmsBlogByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章管理信息
|
||||
*
|
||||
* @param id 文章管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCmsBlogById(Long id)
|
||||
{
|
||||
//清空文章分类关联
|
||||
cmsBlogTypeMapper.deleteBlogTypeByBlogId(id);
|
||||
//清空文章标签关联
|
||||
cmsBlogTagMapper.deleteBlogTagByBlogId(id);
|
||||
return cmsBlogMapper.deleteCmsBlogById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果首页图片为空,从content中提取第一个图片作为首页图片
|
||||
*
|
||||
* @param blog 博客对象
|
||||
*/
|
||||
private void setDefaultBlogPicFromContent(CmsBlog blog) {
|
||||
// 检查首页图片是否为空
|
||||
boolean hasBlogPic = (blog.getBlogPic() != null && !blog.getBlogPic().trim().isEmpty()) ||
|
||||
(blog.getBlogPicLink() != null && !blog.getBlogPicLink().trim().isEmpty());
|
||||
|
||||
if (!hasBlogPic && blog.getContent() != null && !blog.getContent().trim().isEmpty()) {
|
||||
String firstImageUrl = extractFirstImageFromContent(blog.getContent());
|
||||
if (firstImageUrl != null && !firstImageUrl.trim().isEmpty()) {
|
||||
// 设置为地址类型的首页图片
|
||||
blog.setBlogPicType("0");
|
||||
blog.setBlogPicLink(firstImageUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从内容中提取第一个图片的URL
|
||||
* 支持Markdown格式: 和 HTML格式:<img src="url">
|
||||
*
|
||||
* @param content 内容(支持Markdown和HTML)
|
||||
* @return 第一个图片的URL,如果没有找到则返回null
|
||||
*/
|
||||
private String extractFirstImageFromContent(String content) {
|
||||
// 首先尝试匹配Markdown格式的图片:
|
||||
Pattern markdownPattern = Pattern.compile("!\\[.*?\\]\\(([^)]+)\\)");
|
||||
Matcher markdownMatcher = markdownPattern.matcher(content);
|
||||
|
||||
if (markdownMatcher.find()) {
|
||||
return markdownMatcher.group(1);
|
||||
}
|
||||
|
||||
// 如果没有找到Markdown格式,再尝试匹配HTML格式的img标签
|
||||
Pattern htmlPattern = Pattern.compile("<img[^>]+src\\s*=\\s*[\"']([^\"']+)[\"'][^>]*>", Pattern.CASE_INSENSITIVE);
|
||||
Matcher htmlMatcher = htmlPattern.matcher(content);
|
||||
|
||||
if (htmlMatcher.find()) {
|
||||
return htmlMatcher.group(1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<CmsBlog> BlogListAddTypeAndTag(List<CmsBlog> cmsBlogList){
|
||||
if (cmsBlogList==null||cmsBlogList.size()<0){
|
||||
return cmsBlogList;
|
||||
}
|
||||
for (CmsBlog blog : cmsBlogList) {
|
||||
Long blogId = blog.getId();
|
||||
//查询标签列表
|
||||
List<CmsBlogTag> blogTagList = cmsBlogTagMapper.selectBlogTagList(blogId);
|
||||
List<CmsTag> cmsTagList = new ArrayList<>();
|
||||
blogTagList.forEach((CmsBlogTag cmsBlogTag)->{
|
||||
Long tagId = cmsBlogTag.getTagId();
|
||||
CmsTag cmsTag = cmsTagMapper.selectCmsTagByTagId(tagId);
|
||||
cmsTagList.add(cmsTag);
|
||||
});
|
||||
blog.setTags(cmsTagList);
|
||||
//查询分类列表
|
||||
List<CmsBlogType> blogTypeList = cmsBlogTypeMapper.selectBlogTypeList(blogId);
|
||||
List<CmsType> cmsTypeList = new ArrayList<>();
|
||||
blogTypeList.forEach((CmsBlogType cmsBlogType)->{
|
||||
Long typeId = cmsBlogType.getTypeId();
|
||||
CmsType cmsType = cmsTypeMapper.selectCmsTypeByTypeId(typeId);
|
||||
cmsTypeList.add(cmsType);
|
||||
});
|
||||
blog.setTypes(cmsTypeList);
|
||||
}
|
||||
return cmsBlogList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.ruoyi.cms.blog.service.impl;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈〉
|
||||
* @Date: 2022/1/2 23:24
|
||||
*/
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlogTag;
|
||||
import com.ruoyi.cms.blog.mapper.CmsBlogTagMapper;
|
||||
import com.ruoyi.cms.blog.service.ICmsBlogTagService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈〉
|
||||
* @Date: 2022/1/2 23:24
|
||||
**/
|
||||
@Service
|
||||
public class CmsBlogTagServiceImpl implements ICmsBlogTagService {
|
||||
|
||||
@Autowired
|
||||
CmsBlogTagMapper cmsBlogTagMapper;
|
||||
|
||||
@Override
|
||||
public int batchBlogTag(List<CmsBlogTag> blogTagList) {
|
||||
return cmsBlogTagMapper.batchBlogTag(blogTagList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteBlogTagByBlogId(Long blogId) {
|
||||
return cmsBlogTagMapper.deleteBlogTagByBlogId(blogId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteBlogTag(Long[] ids) {
|
||||
return cmsBlogTagMapper.deleteBlogTag(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsBlogTag> selectBlogTagList(Long blogId) {
|
||||
return cmsBlogTagMapper.selectBlogTagList(blogId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.ruoyi.cms.blog.service.impl;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈〉
|
||||
* @Date: 2022/1/2 23:44
|
||||
*/
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlogType;
|
||||
import com.ruoyi.cms.blog.mapper.CmsBlogTypeMapper;
|
||||
import com.ruoyi.cms.blog.service.ICmsBlogTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈〉
|
||||
* @Date: 2022/1/2 23:44
|
||||
**/
|
||||
@Service
|
||||
public class CmsBlogTypeServiceImpl implements ICmsBlogTypeService {
|
||||
|
||||
@Autowired
|
||||
CmsBlogTypeMapper cmsBlogTypeMapper;
|
||||
|
||||
@Override
|
||||
public int batchBlogType(List<CmsBlogType> blogTypeList) {
|
||||
return cmsBlogTypeMapper.batchBlogType(blogTypeList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteBlogTypeByBlogId(Long blogId) {
|
||||
return cmsBlogTypeMapper.deleteBlogTypeByBlogId(blogId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteBlogType(Long[] ids) {
|
||||
return cmsBlogTypeMapper.deleteBlogType(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsBlogType> selectBlogTypeList(Long blogId) {
|
||||
return cmsBlogTypeMapper.selectBlogTypeList(blogId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
package com.ruoyi.cms.charts.controller;
|
||||
/**
|
||||
* @program: ruo-yi-vue-blog
|
||||
* @Author: WangNing
|
||||
* @Description: 〈图表后台接口〉
|
||||
* @Date: 2022/4/25 10:37
|
||||
*/
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlog;
|
||||
import com.ruoyi.cms.charts.service.IChartService;
|
||||
import com.ruoyi.cms.comment.domain.CmsComment;
|
||||
import com.ruoyi.cms.comment.service.ICmsCommentService;
|
||||
import com.ruoyi.cms.message.domain.CmsMessage;
|
||||
import com.ruoyi.cms.message.service.ICmsMessageService;
|
||||
import com.ruoyi.cms.tag.domain.CmsTag;
|
||||
import com.ruoyi.cms.tag.service.ICmsTagService;
|
||||
import com.ruoyi.cms.type.domain.CmsType;
|
||||
import com.ruoyi.cms.type.service.ICmsTypeService;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈图表后台接口〉
|
||||
* @Date: 2022/4/25 10:37
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/cms/chart")
|
||||
public class ChartController extends BaseController {
|
||||
@Autowired
|
||||
private IChartService chartService;
|
||||
|
||||
@Autowired
|
||||
private ICmsTypeService cmsTypeService;
|
||||
|
||||
@Autowired
|
||||
private ICmsTagService cmsTagService;
|
||||
|
||||
@Autowired
|
||||
private ICmsCommentService cmsCommentService;
|
||||
|
||||
@Autowired
|
||||
private ICmsMessageService cmsMessageService;
|
||||
|
||||
@Autowired
|
||||
private SysPermissionService permissionService;
|
||||
|
||||
/**
|
||||
* 查询总阅读量/文章总数/评论总数/留言总数
|
||||
*/
|
||||
@GetMapping("/total")
|
||||
public Map total() {
|
||||
Map total = new HashMap();
|
||||
CmsBlog cmsBlog = new CmsBlog();
|
||||
CmsComment cmsComment = new CmsComment();
|
||||
CmsMessage cmsMessage = new CmsMessage();
|
||||
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (!SecurityUtils.isAdmin(getUserId()) && !roles.contains("admin") && !roles.contains("cms")) {
|
||||
cmsBlog.setCreateBy(getUsername());
|
||||
}
|
||||
cmsBlog.setType("1");
|
||||
|
||||
// 使用优化的统计方法,直接在数据库层面计算
|
||||
Long views = chartService.sumViews(cmsBlog);
|
||||
int blogCount = chartService.countBlog(cmsBlog);
|
||||
|
||||
cmsComment.setDelFlag("0");
|
||||
int commentCount = chartService.countComment(cmsComment);
|
||||
|
||||
cmsMessage.setDelFlag("0");
|
||||
int messageCount = chartService.countMessage(cmsMessage);
|
||||
|
||||
total.put("views", views);
|
||||
total.put("blog", blogCount);
|
||||
total.put("comment", commentCount);
|
||||
total.put("message", messageCount);
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询平滑折线图数据
|
||||
*/
|
||||
@GetMapping("/lineChart")
|
||||
public Map lineChart() {
|
||||
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
|
||||
Map lineChart = new HashMap();
|
||||
List datex = new ArrayList();
|
||||
List commentData = new ArrayList();
|
||||
List blogData = new ArrayList();
|
||||
List messageData = new ArrayList();
|
||||
CmsBlog cmsBlog = new CmsBlog();
|
||||
CmsComment cmsComment = new CmsComment();
|
||||
CmsMessage cmsMessage = new CmsMessage();
|
||||
Date date = new Date();
|
||||
//Mon
|
||||
Date MonBegin = getFrontDayBegin(date, 6);
|
||||
Date MonEnd = getFrontDayEnd(date, 6);
|
||||
datex.add(sd.format(MonBegin));
|
||||
//Tue
|
||||
Date TueBegin = getFrontDayBegin(date, 5);
|
||||
Date TueEnd = getFrontDayEnd(date, 5);
|
||||
datex.add(sd.format(TueBegin));
|
||||
//Wed
|
||||
Date WedBegin = getFrontDayBegin(date, 4);
|
||||
Date WedEnd = getFrontDayEnd(date, 4);
|
||||
datex.add(sd.format(WedBegin));
|
||||
//Thu
|
||||
Date ThuBegin = getFrontDayBegin(date, 3);
|
||||
Date ThuEnd = getFrontDayEnd(date, 3);
|
||||
datex.add(sd.format(ThuBegin));
|
||||
//Fri
|
||||
Date FriBegin = getFrontDayBegin(date, 2);
|
||||
Date FriEnd = getFrontDayEnd(date, 2);
|
||||
datex.add(sd.format(FriBegin));
|
||||
//Sat
|
||||
Date SatBegin = getFrontDayBegin(date, 1);
|
||||
Date SatEnd = getFrontDayEnd(date, 1);
|
||||
datex.add(sd.format(SatBegin));
|
||||
//Sun
|
||||
Date SunBegin = getFrontDayBegin(date, 0);
|
||||
Date SunEnd = getFrontDayEnd(date, 0);
|
||||
datex.add(sd.format(SunBegin));
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (!SecurityUtils.isAdmin(getUserId()) && !roles.contains("admin") && !roles.contains("cms")) {
|
||||
cmsBlog.setCreateBy(getUsername());
|
||||
}
|
||||
cmsBlog.setType("1");
|
||||
blogData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(MonBegin),sf.format(MonEnd)).size());
|
||||
blogData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(TueBegin),sf.format(TueEnd)).size());
|
||||
blogData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(WedBegin),sf.format(WedEnd)).size());
|
||||
blogData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(ThuBegin),sf.format(ThuEnd)).size());
|
||||
blogData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(FriBegin),sf.format(FriEnd)).size());
|
||||
blogData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(SatBegin),sf.format(SatEnd)).size());
|
||||
blogData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(SunBegin),sf.format(SunEnd)).size());
|
||||
cmsComment.setDelFlag("0");
|
||||
commentData.add(chartService.selectCmsCommentListBetweenCreateTime(cmsComment,sf.format(MonBegin),sf.format(MonEnd)).size());
|
||||
commentData.add(chartService.selectCmsCommentListBetweenCreateTime(cmsComment,sf.format(TueBegin),sf.format(TueEnd)).size());
|
||||
commentData.add(chartService.selectCmsCommentListBetweenCreateTime(cmsComment,sf.format(WedBegin),sf.format(WedEnd)).size());
|
||||
commentData.add(chartService.selectCmsCommentListBetweenCreateTime(cmsComment,sf.format(ThuBegin),sf.format(ThuEnd)).size());
|
||||
commentData.add(chartService.selectCmsCommentListBetweenCreateTime(cmsComment,sf.format(FriBegin),sf.format(FriEnd)).size());
|
||||
commentData.add(chartService.selectCmsCommentListBetweenCreateTime(cmsComment,sf.format(SatBegin),sf.format(SatEnd)).size());
|
||||
commentData.add(chartService.selectCmsCommentListBetweenCreateTime(cmsComment,sf.format(SunBegin),sf.format(SunEnd)).size());
|
||||
cmsMessage.setDelFlag("0");
|
||||
messageData.add(chartService.selectCmsMessageListBetweenCreateTime(cmsMessage,sf.format(MonBegin),sf.format(MonEnd)).size());
|
||||
messageData.add(chartService.selectCmsMessageListBetweenCreateTime(cmsMessage,sf.format(TueBegin),sf.format(TueEnd)).size());
|
||||
messageData.add(chartService.selectCmsMessageListBetweenCreateTime(cmsMessage,sf.format(WedBegin),sf.format(WedEnd)).size());
|
||||
messageData.add(chartService.selectCmsMessageListBetweenCreateTime(cmsMessage,sf.format(ThuBegin),sf.format(ThuEnd)).size());
|
||||
messageData.add(chartService.selectCmsMessageListBetweenCreateTime(cmsMessage,sf.format(FriBegin),sf.format(FriEnd)).size());
|
||||
messageData.add(chartService.selectCmsMessageListBetweenCreateTime(cmsMessage,sf.format(SatBegin),sf.format(SatEnd)).size());
|
||||
messageData.add(chartService.selectCmsMessageListBetweenCreateTime(cmsMessage,sf.format(SunBegin),sf.format(SunEnd)).size());
|
||||
lineChart.put("datex", datex);
|
||||
lineChart.put("blogData", blogData);
|
||||
lineChart.put("commentData", commentData);
|
||||
lineChart.put("messageData", messageData);
|
||||
return lineChart;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分类饼图数据
|
||||
*/
|
||||
@GetMapping("/pieChart")
|
||||
public Map pieChart() {
|
||||
Map pieChart = new HashMap();
|
||||
CmsType cmsType = new CmsType();
|
||||
List type = new ArrayList();
|
||||
List data = new ArrayList();
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (!SecurityUtils.isAdmin(getUserId()) && !roles.contains("admin") && !roles.contains("cms")) {
|
||||
cmsType.setCreateBy(getUsername());
|
||||
}
|
||||
List<CmsType> list = cmsTypeService.selectCmsTypeList(cmsType);
|
||||
for (CmsType cType : list) {
|
||||
Map typeMap = new HashMap();
|
||||
type.add(cType.getTypeName());
|
||||
typeMap.put("name",cType.getTypeName());
|
||||
typeMap.put("value",cType.getBlogNum());
|
||||
data.add(typeMap);
|
||||
}
|
||||
pieChart.put("type", type);
|
||||
pieChart.put("data", data);
|
||||
return pieChart;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询标签球数据
|
||||
*/
|
||||
@GetMapping("/tagChart")
|
||||
public Map tagChart() {
|
||||
Map tagChart = new HashMap();
|
||||
CmsTag cmsTag = new CmsTag();
|
||||
List tag = new ArrayList();
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (!SecurityUtils.isAdmin(getUserId()) && !roles.contains("admin") && !roles.contains("cms")) {
|
||||
cmsTag.setCreateBy(getUsername());
|
||||
}
|
||||
List<CmsTag> list = cmsTagService.selectCmsTagList(cmsTag);
|
||||
for (CmsTag cTag : list) {
|
||||
tag.add(cTag.getTagName()+" "+String.valueOf(cTag.getBlogNum()));
|
||||
}
|
||||
tagChart.put("tag", tag);
|
||||
return tagChart;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询柱状图数据
|
||||
*/
|
||||
@GetMapping("/essayChart")
|
||||
public Map essayChart() {
|
||||
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
|
||||
Map essayChart = new HashMap();
|
||||
List datex = new ArrayList();
|
||||
List essayData = new ArrayList();
|
||||
CmsBlog cmsBlog = new CmsBlog();
|
||||
Date date = new Date();
|
||||
//Mon
|
||||
Date MonBegin = getFrontDayBegin(date, 6);
|
||||
Date MonEnd = getFrontDayEnd(date, 6);
|
||||
datex.add(sd.format(MonBegin));
|
||||
//Tue
|
||||
Date TueBegin = getFrontDayBegin(date, 5);
|
||||
Date TueEnd = getFrontDayEnd(date, 5);
|
||||
datex.add(sd.format(TueBegin));
|
||||
//Wed
|
||||
Date WedBegin = getFrontDayBegin(date, 4);
|
||||
Date WedEnd = getFrontDayEnd(date, 4);
|
||||
datex.add(sd.format(WedBegin));
|
||||
//Thu
|
||||
Date ThuBegin = getFrontDayBegin(date, 3);
|
||||
Date ThuEnd = getFrontDayEnd(date, 3);
|
||||
datex.add(sd.format(ThuBegin));
|
||||
//Fri
|
||||
Date FriBegin = getFrontDayBegin(date, 2);
|
||||
Date FriEnd = getFrontDayEnd(date, 2);
|
||||
datex.add(sd.format(FriBegin));
|
||||
//Sat
|
||||
Date SatBegin = getFrontDayBegin(date, 1);
|
||||
Date SatEnd = getFrontDayEnd(date, 1);
|
||||
datex.add(sd.format(SatBegin));
|
||||
//Sun
|
||||
Date SunBegin = getFrontDayBegin(date, 0);
|
||||
Date SunEnd = getFrontDayEnd(date, 0);
|
||||
datex.add(sd.format(SunBegin));
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (!SecurityUtils.isAdmin(getUserId()) && !roles.contains("admin") && !roles.contains("cms")) {
|
||||
cmsBlog.setCreateBy(getUsername());
|
||||
}
|
||||
cmsBlog.setType("2");
|
||||
List<CmsBlog> blogList = chartService.selectList(cmsBlog);
|
||||
essayData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(MonBegin),sf.format(MonEnd)).size());
|
||||
essayData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(TueBegin),sf.format(TueEnd)).size());
|
||||
essayData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(WedBegin),sf.format(WedEnd)).size());
|
||||
essayData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(ThuBegin),sf.format(ThuEnd)).size());
|
||||
essayData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(FriBegin),sf.format(FriEnd)).size());
|
||||
essayData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(SatBegin),sf.format(SatEnd)).size());
|
||||
essayData.add(chartService.selectListBetweenCreateTime(cmsBlog,sf.format(SunBegin),sf.format(SunEnd)).size());
|
||||
essayChart.put("datex", datex);
|
||||
essayChart.put("essayData", essayData);
|
||||
essayChart.put("total", blogList.size());
|
||||
return essayChart;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回某个日期前几天的开始日期
|
||||
*/
|
||||
public static Date getFrontDayBegin(Date date, int i) {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(date);
|
||||
cal.set(Calendar.DATE, cal.get(Calendar.DATE) - i);
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回某个日期前几天的结束日期
|
||||
*/
|
||||
public static Date getFrontDayEnd(Date date, int i) {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(date);
|
||||
cal.set(Calendar.DATE, cal.get(Calendar.DATE) - i);
|
||||
cal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
cal.set(Calendar.MINUTE, 59);
|
||||
cal.set(Calendar.SECOND, 59);
|
||||
return cal.getTime();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.ruoyi.cms.charts.service;
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlog;
|
||||
import com.ruoyi.cms.comment.domain.CmsComment;
|
||||
import com.ruoyi.cms.message.domain.CmsMessage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: ruo-yi-vue-blog
|
||||
* @Author: WangNing
|
||||
* @Description: 〈${DESCRIPTION}〉
|
||||
* @Date: 2022/4/27 10:17
|
||||
*/
|
||||
public interface IChartService {
|
||||
public List<CmsBlog> selectList(CmsBlog cmsBlog);
|
||||
public List<CmsBlog> selectListBetweenCreateTime(CmsBlog cmsBlog,String createTimeBegin,String createTimeEnd);
|
||||
public List<CmsComment> selectCmsCommentListBetweenCreateTime(CmsComment cmsComment,String createTimeBegin,String createTimeEnd);
|
||||
public List<CmsMessage> selectCmsMessageListBetweenCreateTime(CmsMessage cmsMessage,String createTimeBegin,String createTimeEnd);
|
||||
|
||||
/**
|
||||
* 统计博客数量
|
||||
*
|
||||
* @param cmsBlog 查询条件
|
||||
* @return 博客数量
|
||||
*/
|
||||
public int countBlog(CmsBlog cmsBlog);
|
||||
|
||||
/**
|
||||
* 统计总阅读量
|
||||
*
|
||||
* @param cmsBlog 查询条件
|
||||
* @return 总阅读量
|
||||
*/
|
||||
public Long sumViews(CmsBlog cmsBlog);
|
||||
|
||||
/**
|
||||
* 统计评论数量
|
||||
*
|
||||
* @param cmsComment 查询条件
|
||||
* @return 评论数量
|
||||
*/
|
||||
public int countComment(CmsComment cmsComment);
|
||||
|
||||
/**
|
||||
* 统计留言数量
|
||||
*
|
||||
* @param cmsMessage 查询条件
|
||||
* @return 留言数量
|
||||
*/
|
||||
public int countMessage(CmsMessage cmsMessage);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.ruoyi.cms.charts.service.impl;
|
||||
/**
|
||||
* @program: ruo-yi-vue-blog
|
||||
* @Author: WangNing
|
||||
* @Description: 〈〉
|
||||
* @Date: 2022/4/27 10:18
|
||||
*/
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlog;
|
||||
import com.ruoyi.cms.blog.mapper.CmsBlogMapper;
|
||||
import com.ruoyi.cms.charts.service.IChartService;
|
||||
import com.ruoyi.cms.comment.domain.CmsComment;
|
||||
import com.ruoyi.cms.comment.mapper.CmsCommentMapper;
|
||||
import com.ruoyi.cms.message.domain.CmsMessage;
|
||||
import com.ruoyi.cms.message.mapper.CmsMessageMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈〉
|
||||
* @Date: 2022/4/27 10:18
|
||||
**/
|
||||
@Service
|
||||
public class ChartServiceImpl implements IChartService {
|
||||
|
||||
@Autowired
|
||||
private CmsBlogMapper cmsBlogMapper;
|
||||
|
||||
@Autowired
|
||||
private CmsCommentMapper cmsCommentMapper;
|
||||
|
||||
@Autowired
|
||||
private CmsMessageMapper cmsMessageMapper;
|
||||
|
||||
@Override
|
||||
public List<CmsBlog> selectList(CmsBlog cmsBlog) {
|
||||
return cmsBlogMapper.selectCmsBlogList(cmsBlog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsBlog> selectListBetweenCreateTime(CmsBlog cmsBlog,String createTimeBegin,String createTimeEnd) {
|
||||
return cmsBlogMapper.selectCmsBlogListBetweenCreateTime(cmsBlog.getTitle(),cmsBlog.getType(),cmsBlog.getTop(),cmsBlog.getStatus(),createTimeBegin,createTimeEnd,cmsBlog.getCreateBy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsComment> selectCmsCommentListBetweenCreateTime(CmsComment cmsComment,String createTimeBegin,String createTimeEnd) {
|
||||
return cmsCommentMapper.selectCmsCommentListBetweenCreateTime(cmsComment.getType(),cmsComment.getDelFlag(),createTimeBegin,createTimeEnd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsMessage> selectCmsMessageListBetweenCreateTime(CmsMessage cmsMessage, String createTimeBegin, String createTimeEnd) {
|
||||
return cmsMessageMapper.selectCmsMessageListBetweenCreateTime(cmsMessage.getType(),cmsMessage.getDelFlag(),createTimeBegin,createTimeEnd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countBlog(CmsBlog cmsBlog) {
|
||||
return cmsBlogMapper.countCmsBlog(cmsBlog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sumViews(CmsBlog cmsBlog) {
|
||||
return cmsBlogMapper.sumViews(cmsBlog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countComment(CmsComment cmsComment) {
|
||||
return cmsCommentMapper.countCmsComment(cmsComment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countMessage(CmsMessage cmsMessage) {
|
||||
return cmsMessageMapper.countCmsMessage(cmsMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.ruoyi.cms.comment.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.cms.comment.domain.CmsCommentLike;
|
||||
import com.ruoyi.cms.message.domain.CmsMessage;
|
||||
import com.ruoyi.cms.message.domain.CmsMessageLike;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.cms.comment.domain.CmsComment;
|
||||
import com.ruoyi.cms.comment.service.ICmsCommentService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 评论管理Controller
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-21
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/cms/comment")
|
||||
public class CmsCommentController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ICmsCommentService cmsCommentService;
|
||||
|
||||
@Autowired
|
||||
private SysPermissionService permissionService;
|
||||
|
||||
|
||||
/**
|
||||
* 首页查询评论列表
|
||||
*/
|
||||
@GetMapping("/cms/list")
|
||||
public TableDataInfo cmsList(CmsComment cmsComment)
|
||||
{
|
||||
startPage();
|
||||
List<CmsComment> list = cmsCommentService.selectCommentList(cmsComment);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页新增评论
|
||||
*/
|
||||
@PostMapping("/cms/addComment")
|
||||
public AjaxResult addComment(@RequestBody CmsComment cmsComment)
|
||||
{
|
||||
Long parentId = cmsComment.getParentId();
|
||||
if (parentId!=null){
|
||||
CmsComment comment = cmsCommentService.selectCmsCommentById(parentId);
|
||||
if (comment.getMainId()!=null){
|
||||
cmsComment.setMainId(comment.getMainId());
|
||||
}else {
|
||||
cmsComment.setMainId(parentId);
|
||||
}
|
||||
}
|
||||
return toAjax(cmsCommentService.insertCmsComment(cmsComment));
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页新增点赞
|
||||
*/
|
||||
@PostMapping("/cms/addCmsCommentLike")
|
||||
public AjaxResult addCmsCommentLike(@RequestBody CmsCommentLike cmsCommentLike)
|
||||
{
|
||||
return toAjax(cmsCommentService.addCmsCommentLike(cmsCommentLike));
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页删除点赞
|
||||
*/
|
||||
@Log(title = "删除评论点赞", businessType = BusinessType.DELETE)
|
||||
@PostMapping("/cms/delCmsCommentLike")
|
||||
public AjaxResult delCmsCommentLike(@RequestBody CmsCommentLike cmsCommentLike)
|
||||
{
|
||||
return toAjax(cmsCommentService.delCmsCommentLike(cmsCommentLike));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询评论管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:comment:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(CmsComment cmsComment)
|
||||
{
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (!SecurityUtils.isAdmin(getUserId())&&!roles.contains("admin")&&!roles.contains("cms")){
|
||||
cmsComment.setCreateBy(getUsername());
|
||||
}
|
||||
cmsComment.setDelFlag("0");
|
||||
startPage();
|
||||
List<CmsComment> list = cmsCommentService.selectCmsCommentList(cmsComment);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出评论管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:comment:export')")
|
||||
@Log(title = "评论管理", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, CmsComment cmsComment)
|
||||
{
|
||||
List<CmsComment> list = cmsCommentService.selectCmsCommentList(cmsComment);
|
||||
ExcelUtil<CmsComment> util = new ExcelUtil<CmsComment>(CmsComment.class);
|
||||
util.exportExcel(response, list, "评论管理数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论管理详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:comment:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return AjaxResult.success(cmsCommentService.selectCmsCommentById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增评论管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:comment:add')")
|
||||
@Log(title = "评论管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody CmsComment cmsComment)
|
||||
{
|
||||
return toAjax(cmsCommentService.insertCmsComment(cmsComment));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改评论管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:comment:edit')")
|
||||
@Log(title = "评论管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody CmsComment cmsComment)
|
||||
{
|
||||
return toAjax(cmsCommentService.updateCmsComment(cmsComment));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除评论管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:comment:remove')")
|
||||
@Log(title = "评论管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(cmsCommentService.deleteCmsCommentByIds(ids));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
package com.ruoyi.cms.comment.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 评论管理对象 cms_comment
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-21
|
||||
*/
|
||||
public class CmsComment extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
private Long id;
|
||||
|
||||
/** 父评论id */
|
||||
@Excel(name = "父评论id")
|
||||
private Long parentId;
|
||||
|
||||
/** 主评论id(第一级评论) */
|
||||
@Excel(name = "主评论id(第一级评论)")
|
||||
private Long mainId;
|
||||
|
||||
/** 点赞数量 */
|
||||
@Excel(name = "点赞数量")
|
||||
private Long likeNum;
|
||||
|
||||
/** 内容 */
|
||||
@Excel(name = "内容")
|
||||
private String content;
|
||||
|
||||
/** 评论类型:对人评论,对项目评论,对资源评论 */
|
||||
@Excel(name = "评论类型:对人评论,对项目评论,对资源评论")
|
||||
private String type;
|
||||
|
||||
/** 被评论者id,可以是人、项目、资源 */
|
||||
@Excel(name = "被评论者id,可以是人、项目、资源")
|
||||
private Long blogId;
|
||||
|
||||
/** 文章标题 */
|
||||
private String blogTitle;
|
||||
|
||||
/** 删除标志(0代表存在 1代表删除) */
|
||||
private String delFlag;
|
||||
|
||||
/** 评论者id */
|
||||
@Excel(name = "评论者id")
|
||||
private Long userId;
|
||||
|
||||
/** 头像 */
|
||||
private String avatar;
|
||||
|
||||
/** 回复 */
|
||||
private List<CmsComment> children;
|
||||
|
||||
/** 父留言者 */
|
||||
private String pCreateBy;
|
||||
|
||||
/** 点赞 */
|
||||
private boolean isLike;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
public void setParentId(Long parentId)
|
||||
{
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public Long getParentId()
|
||||
{
|
||||
return parentId;
|
||||
}
|
||||
public void setMainId(Long mainId)
|
||||
{
|
||||
this.mainId = mainId;
|
||||
}
|
||||
|
||||
public Long getMainId()
|
||||
{
|
||||
return mainId;
|
||||
}
|
||||
public void setLikeNum(Long likeNum)
|
||||
{
|
||||
this.likeNum = likeNum;
|
||||
}
|
||||
|
||||
public Long getLikeNum()
|
||||
{
|
||||
return likeNum;
|
||||
}
|
||||
public void setContent(String content)
|
||||
{
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContent()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
public void setBlogId(Long blogId)
|
||||
{
|
||||
this.blogId = blogId;
|
||||
}
|
||||
|
||||
public Long getBlogId()
|
||||
{
|
||||
return blogId;
|
||||
}
|
||||
public void setDelFlag(String delFlag)
|
||||
{
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
|
||||
public String getDelFlag()
|
||||
{
|
||||
return delFlag;
|
||||
}
|
||||
public void setUserId(Long userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public List<CmsComment> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<CmsComment> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public String getPCreateBy() {
|
||||
return pCreateBy;
|
||||
}
|
||||
|
||||
public void setPCreateBy(String pCreateBy) {
|
||||
this.pCreateBy = pCreateBy;
|
||||
}
|
||||
|
||||
public boolean getIsLike() {
|
||||
return isLike;
|
||||
}
|
||||
|
||||
public String getBlogTitle() {
|
||||
return blogTitle;
|
||||
}
|
||||
|
||||
public void setBlogTitle(String blogTitle) {
|
||||
this.blogTitle = blogTitle;
|
||||
}
|
||||
|
||||
public void setIsLike(boolean like) {
|
||||
isLike = like;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("parentId", getParentId())
|
||||
.append("mainId", getMainId())
|
||||
.append("likeNum", getLikeNum())
|
||||
.append("content", getContent())
|
||||
.append("type", getType())
|
||||
.append("blogId", getBlogId())
|
||||
.append("blogTitle", getBlogTitle())
|
||||
.append("delFlag", getDelFlag())
|
||||
.append("userId", getUserId())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("avatar", getAvatar())
|
||||
.append("children", getChildren())
|
||||
.append("pCreateBy", getPCreateBy())
|
||||
.append("isLike", getIsLike())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.ruoyi.cms.comment.domain;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈評論點贊实体类〉
|
||||
* @Date: 2022/1/22 17:48
|
||||
*/
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈評論點贊实体类〉
|
||||
* @Date: 2022/1/22 17:48
|
||||
**/
|
||||
public class CmsCommentLike extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long commentId;
|
||||
private Long userId;
|
||||
|
||||
/** 点赞数量 */
|
||||
private Long likeNum;
|
||||
|
||||
public Long getCommentId() {
|
||||
return commentId;
|
||||
}
|
||||
|
||||
public void setCommentId(Long commentId) {
|
||||
this.commentId = commentId;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getLikeNum() {
|
||||
return likeNum;
|
||||
}
|
||||
|
||||
public void setLikeNum(Long likeNum) {
|
||||
this.likeNum = likeNum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("commentId", getCommentId())
|
||||
.append("userId", getUserId())
|
||||
.append("likeNum", getLikeNum())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.ruoyi.cms.comment.mapper;
|
||||
|
||||
import com.ruoyi.cms.comment.domain.CmsCommentLike;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈${DESCRIPTION}〉
|
||||
* @Date: 2022/1/22 20:08
|
||||
*/
|
||||
public interface CmsCommentLikeMapper {
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
public List<CmsCommentLike> selectCmsCommentLikeList(CmsCommentLike cmsCommentLike);
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public int addCmsCommentLike(CmsCommentLike cmsCommentLike);
|
||||
/**
|
||||
* 删除关联
|
||||
*/
|
||||
public int deleteCmsCommentLike(CmsCommentLike cmsCommentLike);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.ruoyi.cms.comment.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.comment.domain.CmsComment;
|
||||
import com.ruoyi.cms.message.domain.CmsMessage;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 评论管理Mapper接口
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-21
|
||||
*/
|
||||
public interface CmsCommentMapper
|
||||
{
|
||||
/**
|
||||
* 查询评论管理
|
||||
*
|
||||
* @param id 评论管理主键
|
||||
* @return 评论管理
|
||||
*/
|
||||
public CmsComment selectCmsCommentById(Long id);
|
||||
|
||||
/**
|
||||
* 查询评论管理列表
|
||||
*
|
||||
* @param cmsComment 评论管理
|
||||
* @return 评论管理集合
|
||||
*/
|
||||
public List<CmsComment> selectCmsCommentList(CmsComment cmsComment);
|
||||
|
||||
public List<CmsComment> selectCmsCommentListBetweenCreateTime(@Param("type") String type, @Param("delFlag") String delFlag, @Param("createTimeBegin") String createTimeBegin, @Param("createTimeEnd") String createTimeEnd);
|
||||
|
||||
/**
|
||||
* 查询子留言列表
|
||||
*/
|
||||
public List<CmsComment> selectChildCommentList(CmsComment cmsComment);
|
||||
|
||||
/**
|
||||
* 新增评论管理
|
||||
*
|
||||
* @param cmsComment 评论管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCmsComment(CmsComment cmsComment);
|
||||
|
||||
/**
|
||||
* 修改评论管理
|
||||
*
|
||||
* @param cmsComment 评论管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsComment(CmsComment cmsComment);
|
||||
|
||||
/**
|
||||
* 删除评论管理
|
||||
*
|
||||
* @param id 评论管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsCommentById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除评论管理
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsCommentByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除评论管理
|
||||
*
|
||||
* @param id 评论管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDelFlagById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除评论管理
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDelFlagByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 统计评论数量
|
||||
*
|
||||
* @param cmsComment 查询条件
|
||||
* @return 评论数量
|
||||
*/
|
||||
public int countCmsComment(CmsComment cmsComment);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.ruoyi.cms.comment.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.comment.domain.CmsComment;
|
||||
import com.ruoyi.cms.comment.domain.CmsCommentLike;
|
||||
import com.ruoyi.cms.message.domain.CmsMessage;
|
||||
import com.ruoyi.cms.message.domain.CmsMessageLike;
|
||||
|
||||
/**
|
||||
* 评论管理Service接口
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-21
|
||||
*/
|
||||
public interface ICmsCommentService
|
||||
{
|
||||
/**
|
||||
* 首页查询留言列表
|
||||
*/
|
||||
public List<CmsComment> selectCommentList(CmsComment cmsComment);
|
||||
|
||||
/**
|
||||
* 首页新增点赞
|
||||
*/
|
||||
public int addCmsCommentLike(CmsCommentLike cmsCommentLike);
|
||||
|
||||
/**
|
||||
* 首页删除点赞
|
||||
*/
|
||||
public int delCmsCommentLike(CmsCommentLike cmsCommentLike);
|
||||
|
||||
/**
|
||||
* 查询评论管理
|
||||
*
|
||||
* @param id 评论管理主键
|
||||
* @return 评论管理
|
||||
*/
|
||||
public CmsComment selectCmsCommentById(Long id);
|
||||
|
||||
/**
|
||||
* 查询评论管理列表
|
||||
*
|
||||
* @param cmsComment 评论管理
|
||||
* @return 评论管理集合
|
||||
*/
|
||||
public List<CmsComment> selectCmsCommentList(CmsComment cmsComment);
|
||||
|
||||
/**
|
||||
* 新增评论管理
|
||||
*
|
||||
* @param cmsComment 评论管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCmsComment(CmsComment cmsComment);
|
||||
|
||||
/**
|
||||
* 修改评论管理
|
||||
*
|
||||
* @param cmsComment 评论管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsComment(CmsComment cmsComment);
|
||||
|
||||
/**
|
||||
* 批量删除评论管理
|
||||
*
|
||||
* @param ids 需要删除的评论管理主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsCommentByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除评论管理信息
|
||||
*
|
||||
* @param id 评论管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsCommentById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
package com.ruoyi.cms.comment.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.cms.blog.domain.CmsBlog;
|
||||
import com.ruoyi.cms.blog.mapper.CmsBlogMapper;
|
||||
import com.ruoyi.cms.comment.domain.CmsCommentLike;
|
||||
import com.ruoyi.cms.comment.mapper.CmsCommentLikeMapper;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.cms.comment.mapper.CmsCommentMapper;
|
||||
import com.ruoyi.cms.comment.domain.CmsComment;
|
||||
import com.ruoyi.cms.comment.service.ICmsCommentService;
|
||||
|
||||
/**
|
||||
* 评论管理Service业务层处理
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-21
|
||||
*/
|
||||
@Service
|
||||
public class CmsCommentServiceImpl implements ICmsCommentService
|
||||
{
|
||||
@Autowired
|
||||
private CmsCommentMapper cmsCommentMapper;
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
@Autowired
|
||||
private CmsCommentLikeMapper cmsCommentLikeMapper;
|
||||
|
||||
@Autowired
|
||||
private CmsBlogMapper cmsBlogMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 首页查询评论列表
|
||||
*/
|
||||
@Override
|
||||
public List<CmsComment> selectCommentList(CmsComment cmsComment) {
|
||||
//判断是否登录
|
||||
Long logUserUserId = null;
|
||||
String createBy = cmsComment.getCreateBy();
|
||||
if (createBy!=null&&!"".equals(createBy)){
|
||||
SysUser logUser = sysUserMapper.selectUserByUserName(createBy);
|
||||
logUserUserId = logUser.getUserId();
|
||||
}
|
||||
cmsComment.setCreateBy(null);
|
||||
cmsComment.setType("0");
|
||||
cmsComment.setDelFlag("0");
|
||||
List<CmsComment> cmsCommentList = cmsCommentMapper.selectCmsCommentList(cmsComment);
|
||||
for (CmsComment comment : cmsCommentList) {
|
||||
//添加头像
|
||||
Long userId = comment.getUserId();
|
||||
if (userId!=null){
|
||||
SysUser user = sysUserMapper.selectUserById(userId);
|
||||
comment.setAvatar(user.getAvatar());
|
||||
}
|
||||
//添加是否被点赞
|
||||
if (logUserUserId!=null){
|
||||
CmsCommentLike commentLike = new CmsCommentLike();
|
||||
commentLike.setCommentId(comment.getId());
|
||||
commentLike.setUserId(logUserUserId);
|
||||
List<CmsCommentLike> likeList = cmsCommentLikeMapper.selectCmsCommentLikeList(commentLike);
|
||||
if (likeList.size()>0){
|
||||
comment.setIsLike(true);
|
||||
}else {
|
||||
comment.setIsLike(false);
|
||||
}
|
||||
}
|
||||
//添加子评论(回复)
|
||||
CmsComment childComment = new CmsComment();
|
||||
childComment.setType("1");
|
||||
childComment.setMainId(comment.getId());
|
||||
List<CmsComment> childCommentList = cmsCommentMapper.selectChildCommentList(childComment);
|
||||
if (childCommentList.size()>0){
|
||||
for (CmsComment childListComment : childCommentList) {
|
||||
//添加头像
|
||||
Long childUserId = childListComment.getUserId();
|
||||
if (childUserId!=null){
|
||||
SysUser user = sysUserMapper.selectUserById(childUserId);
|
||||
childListComment.setAvatar(user.getAvatar());
|
||||
}
|
||||
//添加是否被点赞
|
||||
if (logUserUserId!=null){
|
||||
CmsCommentLike commentLike = new CmsCommentLike();
|
||||
commentLike.setCommentId(comment.getId());
|
||||
commentLike.setUserId(logUserUserId);
|
||||
List<CmsCommentLike> likeList = cmsCommentLikeMapper.selectCmsCommentLikeList(commentLike);
|
||||
if (likeList.size()>0){
|
||||
comment.setIsLike(true);
|
||||
}else {
|
||||
comment.setIsLike(false);
|
||||
}
|
||||
}
|
||||
//添加父评论信息
|
||||
CmsComment byId = cmsCommentMapper.selectCmsCommentById(childListComment.getParentId());
|
||||
childListComment.setPCreateBy(byId.getCreateBy());
|
||||
}
|
||||
comment.setChildren(childCommentList);
|
||||
}
|
||||
}
|
||||
return cmsCommentList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addCmsCommentLike(CmsCommentLike cmsCommentLike) {
|
||||
int result = -1;
|
||||
String createBy = cmsCommentLike.getCreateBy();
|
||||
if (!"".equals(createBy)&&createBy!=null){
|
||||
SysUser user = sysUserMapper.selectUserByUserName(createBy);
|
||||
if (user!=null){
|
||||
cmsCommentLike.setUserId(user.getUserId());
|
||||
cmsCommentLikeMapper.addCmsCommentLike(cmsCommentLike);
|
||||
}
|
||||
}
|
||||
//修改点赞数量
|
||||
CmsComment cmsComment = new CmsComment();
|
||||
cmsComment.setId(cmsCommentLike.getCommentId());
|
||||
cmsComment.setLikeNum(cmsCommentLike.getLikeNum());
|
||||
result = cmsCommentMapper.updateCmsComment(cmsComment);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delCmsCommentLike(CmsCommentLike cmsCommentLike) {
|
||||
int result = -1;
|
||||
String createBy = cmsCommentLike.getCreateBy();
|
||||
if (!"".equals(createBy)&&createBy!=null){
|
||||
SysUser user = sysUserMapper.selectUserByUserName(createBy);
|
||||
if (user!=null){
|
||||
cmsCommentLike.setUserId(user.getUserId());
|
||||
cmsCommentLikeMapper.deleteCmsCommentLike(cmsCommentLike);
|
||||
}
|
||||
}
|
||||
//修改点赞数量
|
||||
CmsComment cmsComment = new CmsComment();
|
||||
cmsComment.setId(cmsCommentLike.getCommentId());
|
||||
cmsComment.setLikeNum(cmsCommentLike.getLikeNum());
|
||||
result = cmsCommentMapper.updateCmsComment(cmsComment);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询评论管理
|
||||
*
|
||||
* @param id 评论管理主键
|
||||
* @return 评论管理
|
||||
*/
|
||||
@Override
|
||||
public CmsComment selectCmsCommentById(Long id)
|
||||
{
|
||||
return cmsCommentMapper.selectCmsCommentById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询评论管理列表
|
||||
*
|
||||
* @param cmsComment 评论管理
|
||||
* @return 评论管理
|
||||
*/
|
||||
@Override
|
||||
public List<CmsComment> selectCmsCommentList(CmsComment cmsComment)
|
||||
{
|
||||
List<CmsComment> cmsCommentList = new ArrayList<>();
|
||||
//判断用户权限
|
||||
String createBy = cmsComment.getCreateBy();
|
||||
if (createBy!=null&&!"".equals(createBy)){
|
||||
SysUser user = sysUserMapper.selectUserByUserName(createBy);
|
||||
if (user!=null){
|
||||
List<CmsComment> CommentList = cmsCommentMapper.selectCmsCommentList(cmsComment);
|
||||
for (CmsComment comment : CommentList) {
|
||||
//查询子评论(回复)
|
||||
CmsComment childComment = new CmsComment();
|
||||
childComment.setType("1");
|
||||
childComment.setParentId(comment.getId());
|
||||
List<CmsComment> childCommentList = cmsCommentMapper.selectCmsCommentList(childComment);
|
||||
if (childCommentList.size()>0){
|
||||
cmsCommentList.addAll(childCommentList);
|
||||
}
|
||||
}
|
||||
cmsCommentList.addAll(CommentList);
|
||||
}
|
||||
}else {
|
||||
cmsCommentList = cmsCommentMapper.selectCmsCommentList(cmsComment);
|
||||
}
|
||||
for (CmsComment comment : cmsCommentList) {
|
||||
//添加头像
|
||||
Long userId = comment.getUserId();
|
||||
if (userId!=null){
|
||||
SysUser user = sysUserMapper.selectUserById(userId);
|
||||
comment.setAvatar(user.getAvatar());
|
||||
}
|
||||
//添加父评论信息
|
||||
Long parentId = comment.getParentId();
|
||||
if (parentId!=null){
|
||||
CmsComment parentComment = cmsCommentMapper.selectCmsCommentById(parentId);
|
||||
comment.setPCreateBy(parentComment.getCreateBy());
|
||||
}
|
||||
//添加博客信息
|
||||
Long blogId = comment.getBlogId();
|
||||
if (blogId!=null){
|
||||
CmsBlog blog = cmsBlogMapper.selectCmsBlogById(blogId);
|
||||
comment.setBlogTitle(blog.getTitle());
|
||||
}
|
||||
}
|
||||
//排序
|
||||
// String[] sortNameArr1 = {"createTime"};
|
||||
// //true升序,false降序
|
||||
// boolean[] isAscArr1 = {false};
|
||||
// ListSortUtils.sort(cmsMessageList, sortNameArr1, isAscArr1);
|
||||
// cmsMessageList.sort((a,b)->a.getCreateBy().compareTo(b.getCreateBy()));
|
||||
// Collections.sort(cmsMessageList, new Comparator<CmsMessage>() {
|
||||
// @Override
|
||||
// public int compare(CmsMessage o1, CmsMessage o2) {
|
||||
// //升序
|
||||
// //return o1.getCreateBy().compareTo(o2.getCreateBy());
|
||||
// //降序
|
||||
// return o2.getCreateBy().compareTo(o1.getCreateBy());
|
||||
// }
|
||||
// });
|
||||
return cmsCommentList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增评论管理
|
||||
*
|
||||
* @param cmsComment 评论管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertCmsComment(CmsComment cmsComment)
|
||||
{
|
||||
String createBy = cmsComment.getCreateBy();
|
||||
if (createBy!=null&&!"".equals(createBy)){
|
||||
SysUser user = sysUserMapper.selectUserByUserName(createBy);
|
||||
if (user!=null){
|
||||
cmsComment.setUserId(user.getUserId());
|
||||
}
|
||||
}
|
||||
cmsComment.setCreateTime(DateUtils.getNowDate());
|
||||
return cmsCommentMapper.insertCmsComment(cmsComment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改评论管理
|
||||
*
|
||||
* @param cmsComment 评论管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateCmsComment(CmsComment cmsComment)
|
||||
{
|
||||
cmsComment.setUpdateTime(DateUtils.getNowDate());
|
||||
return cmsCommentMapper.updateCmsComment(cmsComment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除评论管理
|
||||
*
|
||||
* @param ids 需要删除的评论管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCmsCommentByIds(Long[] ids)
|
||||
{
|
||||
return cmsCommentMapper.updateDelFlagByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除评论管理信息
|
||||
*
|
||||
* @param id 评论管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCmsCommentById(Long id)
|
||||
{
|
||||
return cmsCommentMapper.updateDelFlagById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.ruoyi.cms.fileInfo.controller;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈〉
|
||||
* @Date: 2022/1/2 1:05
|
||||
*/
|
||||
|
||||
import com.ruoyi.cms.fileInfo.domain.FileBlogInfo;
|
||||
import com.ruoyi.cms.fileInfo.domain.SysFileInfo;
|
||||
import com.ruoyi.cms.fileInfo.service.IFileBlogInfoService;
|
||||
import com.ruoyi.cms.fileInfo.service.ISysFileInfoService;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈〉
|
||||
* @Date: 2022/1/2 1:05
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/fileBlogInfo")
|
||||
public class FileBlogInfoController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IFileBlogInfoService fileBlogInfoService;
|
||||
|
||||
@Autowired
|
||||
private ISysFileInfoService fileInfoService;
|
||||
|
||||
/**
|
||||
* 新增blog文件关联
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:blog:add')")
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody FileBlogInfo fileBlogInfo)
|
||||
{
|
||||
List<FileBlogInfo> fileBlogList = new ArrayList<>();
|
||||
Long blogId = fileBlogInfo.getBlogId();
|
||||
Long[] fileIds = fileBlogInfo.getFileIds();
|
||||
for (Long fileId : fileIds) {
|
||||
FileBlogInfo info = new FileBlogInfo();
|
||||
info.setFileId(fileId);
|
||||
info.setBlogId(blogId);
|
||||
fileBlogList.add(info);
|
||||
}
|
||||
fileBlogInfoService.batchFileBlog(fileBlogList);
|
||||
return toAjax(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除blog文件关联
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:blog:remove')")
|
||||
@DeleteMapping("/{blogIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] blogIds)
|
||||
{
|
||||
for (Long id : blogIds) {
|
||||
List<FileBlogInfo> fileBlogInfos = fileBlogInfoService.selectFileBlogList(id);
|
||||
fileBlogInfos.forEach((FileBlogInfo fileBlogInfo)->{
|
||||
Long fileId = fileBlogInfo.getFileId();
|
||||
fileInfoService.deleteSysFileInfoByFileId(fileId);
|
||||
});
|
||||
}
|
||||
fileBlogInfoService.deleteFileBlog(blogIds);
|
||||
return toAjax(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据blogId获取文件列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:blog:query')")
|
||||
@GetMapping(value = "/{blogId}")
|
||||
public AjaxResult getInfo(@PathVariable Long blogId)
|
||||
{
|
||||
List<SysFileInfo> sysFileInfoList = new ArrayList<>();
|
||||
List<FileBlogInfo> fileBlogInfos = fileBlogInfoService.selectFileBlogList(blogId);
|
||||
fileBlogInfos.forEach((FileBlogInfo fileBlogInfo)->{
|
||||
Long fileId = fileBlogInfo.getFileId();
|
||||
SysFileInfo sysFileInfo = fileInfoService.selectSysFileInfoByFileId(fileId);
|
||||
if (sysFileInfo!=null){
|
||||
sysFileInfoList.add(sysFileInfo);
|
||||
}
|
||||
});
|
||||
return AjaxResult.success(sysFileInfoList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.ruoyi.cms.fileInfo.controller;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈〉
|
||||
* @Date: 2022/1/1 0:36
|
||||
*/
|
||||
|
||||
import com.ruoyi.cms.fileInfo.domain.FileNoticeInfo;
|
||||
import com.ruoyi.cms.fileInfo.domain.SysFileInfo;
|
||||
import com.ruoyi.cms.fileInfo.service.IFileNoticeInfoService;
|
||||
import com.ruoyi.cms.fileInfo.service.ISysFileInfoService;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈〉
|
||||
* @Date: 2022/1/1 0:36
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/fileNoticeInfo")
|
||||
public class FileNoticeInfoController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IFileNoticeInfoService fileNoticeInfoService;
|
||||
|
||||
@Autowired
|
||||
private ISysFileInfoService fileInfoService;
|
||||
|
||||
/**
|
||||
* 新增通知公告文件
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:notice:add')")
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody FileNoticeInfo fileNoticeInfo)
|
||||
{
|
||||
List<FileNoticeInfo> fileNoticeList = new ArrayList<>();
|
||||
Long noticeId = fileNoticeInfo.getNoticeId();
|
||||
Long[] fileIds = fileNoticeInfo.getFileIds();
|
||||
for (Long fileId : fileIds) {
|
||||
FileNoticeInfo info = new FileNoticeInfo();
|
||||
info.setFileId(fileId);
|
||||
info.setNoticeId(noticeId);
|
||||
fileNoticeList.add(info);
|
||||
}
|
||||
fileNoticeInfoService.batchFileNotice(fileNoticeList);
|
||||
return toAjax(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除通知公告文件
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:notice:remove')")
|
||||
@DeleteMapping("/{noticeIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] noticeIds)
|
||||
{
|
||||
for (Long id : noticeIds) {
|
||||
List<FileNoticeInfo> fileNoticeInfos = fileNoticeInfoService.selectFileNoticeList(id);
|
||||
fileNoticeInfos.forEach((FileNoticeInfo fileNoticeInfo)->{
|
||||
Long fileId = fileNoticeInfo.getFileId();
|
||||
fileInfoService.deleteSysFileInfoByFileId(fileId);
|
||||
});
|
||||
}
|
||||
fileNoticeInfoService.deleteFileNotice(noticeIds);
|
||||
return toAjax(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据通知公告编号获取文件列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:notice:query')")
|
||||
@GetMapping(value = "/{noticeId}")
|
||||
public AjaxResult getInfo(@PathVariable Long noticeId)
|
||||
{
|
||||
List<SysFileInfo> sysFileInfoList = new ArrayList<>();
|
||||
List<FileNoticeInfo> fileNoticeInfos = fileNoticeInfoService.selectFileNoticeList(noticeId);
|
||||
fileNoticeInfos.forEach((FileNoticeInfo fileNoticeInfo)->{
|
||||
Long fileId = fileNoticeInfo.getFileId();
|
||||
SysFileInfo sysFileInfo = fileInfoService.selectSysFileInfoByFileId(fileId);
|
||||
if (sysFileInfo!=null){
|
||||
sysFileInfoList.add(sysFileInfo);
|
||||
}
|
||||
});
|
||||
return AjaxResult.success(sysFileInfoList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.ruoyi.cms.fileInfo.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.cms.fileInfo.domain.SysFileInfo;
|
||||
import com.ruoyi.cms.fileInfo.service.ISysFileInfoService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 文件管理Controller
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2021-12-29
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/fileInfo")
|
||||
public class SysFileInfoController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ISysFileInfoService sysFileInfoService;
|
||||
|
||||
@Autowired
|
||||
private SysPermissionService permissionService;
|
||||
|
||||
/**
|
||||
* 查询文件管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:fileInfo:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SysFileInfo sysFileInfo)
|
||||
{
|
||||
startPage();
|
||||
//判断用户权限
|
||||
String createBy = sysFileInfo.getCreateBy();
|
||||
if (createBy==null&&"".equals(createBy)){
|
||||
throw new ServiceException("获取列表createBy参数为空");
|
||||
}
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (SecurityUtils.isAdmin(getUserId())||roles.contains("admin")||roles.contains("cms")){
|
||||
sysFileInfo.setCreateBy("");
|
||||
}
|
||||
List<SysFileInfo> list = sysFileInfoService.selectSysFileInfoList(sysFileInfo);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出文件管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:fileInfo:export')")
|
||||
@Log(title = "文件管理", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SysFileInfo sysFileInfo)
|
||||
{
|
||||
List<SysFileInfo> list = sysFileInfoService.selectSysFileInfoList(sysFileInfo);
|
||||
ExcelUtil<SysFileInfo> util = new ExcelUtil<SysFileInfo>(SysFileInfo.class);
|
||||
util.exportExcel(response, list, "文件管理数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件管理详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:fileInfo:query')")
|
||||
@GetMapping(value = "/{fileId}")
|
||||
public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
|
||||
{
|
||||
return AjaxResult.success(sysFileInfoService.selectSysFileInfoByFileId(fileId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增文件管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:fileInfo:add')")
|
||||
@Log(title = "文件管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody SysFileInfo sysFileInfo)
|
||||
{
|
||||
return toAjax(sysFileInfoService.insertSysFileInfo(sysFileInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:fileInfo:edit')")
|
||||
@Log(title = "文件管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody SysFileInfo sysFileInfo)
|
||||
{
|
||||
return toAjax(sysFileInfoService.updateSysFileInfo(sysFileInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:fileInfo:remove')")
|
||||
@Log(title = "文件管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{fileIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] fileIds)
|
||||
{
|
||||
return toAjax(sysFileInfoService.deleteSysFileInfoByFileIds(fileIds));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.ruoyi.cms.fileInfo.domain;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈blog文件关联 cms_blog_file〉
|
||||
* @Date: 2022/1/2 0:41
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈blog文件关联 cms_blog_file〉
|
||||
* @Date: 2022/1/2 0:41
|
||||
**/
|
||||
public class FileBlogInfo {
|
||||
private Long fileId;
|
||||
private Long blogId;
|
||||
private Long[] fileIds;
|
||||
|
||||
public Long getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
public void setFileId(Long fileId) {
|
||||
this.fileId = fileId;
|
||||
}
|
||||
|
||||
public Long getBlogId() {
|
||||
return blogId;
|
||||
}
|
||||
|
||||
public void setBlogId(Long blogId) {
|
||||
this.blogId = blogId;
|
||||
}
|
||||
|
||||
public Long[] getFileIds() {
|
||||
return fileIds;
|
||||
}
|
||||
|
||||
public void setFileIds(Long[] fileIds) {
|
||||
this.fileIds = fileIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("fileId", getFileId())
|
||||
.append("blogId", getBlogId())
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.ruoyi.cms.fileInfo.domain;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈通知公告和文件关联 sys_notice_file〉
|
||||
* @Date: 2021/12/31 21:49
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈通知公告和文件关联 sys_notice_file〉
|
||||
* @Date: 2021/12/31 21:49
|
||||
**/
|
||||
public class FileNoticeInfo {
|
||||
private Long fileId;
|
||||
private Long noticeId;
|
||||
private Long[] fileIds;
|
||||
|
||||
public Long getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
public void setFileId(Long fileId) {
|
||||
this.fileId = fileId;
|
||||
}
|
||||
|
||||
public Long getNoticeId() {
|
||||
return noticeId;
|
||||
}
|
||||
|
||||
public void setNoticeId(Long noticeId) {
|
||||
this.noticeId = noticeId;
|
||||
}
|
||||
|
||||
public Long[] getFileIds() {
|
||||
return fileIds;
|
||||
}
|
||||
|
||||
public void setFileIds(Long[] fileIds) {
|
||||
this.fileIds = fileIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("fileId", getFileId())
|
||||
.append("roleId", getNoticeId())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.ruoyi.cms.fileInfo.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 文件管理对象 sys_file_info
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2021-12-29
|
||||
*/
|
||||
public class SysFileInfo extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 文件主键id */
|
||||
private Long fileId;
|
||||
|
||||
/** 文件名称 */
|
||||
@Excel(name = "文件名称")
|
||||
private String fileOriginName;
|
||||
|
||||
/** 文件类型,例如txt */
|
||||
@Excel(name = "文件类型,例如txt")
|
||||
private String fileSuffix;
|
||||
|
||||
/** 文件大小 */
|
||||
@Excel(name = "文件大小")
|
||||
private String fileSizeInfo;
|
||||
|
||||
/** 存储文件名称 */
|
||||
@Excel(name = "存储文件名称")
|
||||
private String fileObjectName;
|
||||
|
||||
/** 存储路径 */
|
||||
@Excel(name = "存储路径")
|
||||
private String filePath;
|
||||
|
||||
/** 是否删除:Y-被删除,N-未删除 */
|
||||
private String delFlag;
|
||||
|
||||
public void setFileId(Long fileId)
|
||||
{
|
||||
this.fileId = fileId;
|
||||
}
|
||||
|
||||
public Long getFileId()
|
||||
{
|
||||
return fileId;
|
||||
}
|
||||
public void setFileOriginName(String fileOriginName)
|
||||
{
|
||||
this.fileOriginName = fileOriginName;
|
||||
}
|
||||
|
||||
public String getFileOriginName()
|
||||
{
|
||||
return fileOriginName;
|
||||
}
|
||||
public void setFileSuffix(String fileSuffix)
|
||||
{
|
||||
this.fileSuffix = fileSuffix;
|
||||
}
|
||||
|
||||
public String getFileSuffix()
|
||||
{
|
||||
return fileSuffix;
|
||||
}
|
||||
public void setFileSizeInfo(String fileSizeInfo)
|
||||
{
|
||||
this.fileSizeInfo = fileSizeInfo;
|
||||
}
|
||||
|
||||
public String getFileSizeInfo()
|
||||
{
|
||||
return fileSizeInfo;
|
||||
}
|
||||
public void setFileObjectName(String fileObjectName)
|
||||
{
|
||||
this.fileObjectName = fileObjectName;
|
||||
}
|
||||
|
||||
public String getFileObjectName()
|
||||
{
|
||||
return fileObjectName;
|
||||
}
|
||||
public void setFilePath(String filePath)
|
||||
{
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getFilePath()
|
||||
{
|
||||
return filePath;
|
||||
}
|
||||
public void setDelFlag(String delFlag)
|
||||
{
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
|
||||
public String getDelFlag()
|
||||
{
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("fileId", getFileId())
|
||||
.append("fileOriginName", getFileOriginName())
|
||||
.append("fileSuffix", getFileSuffix())
|
||||
.append("fileSizeInfo", getFileSizeInfo())
|
||||
.append("fileObjectName", getFileObjectName())
|
||||
.append("filePath", getFilePath())
|
||||
.append("delFlag", getDelFlag())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.cms.fileInfo.mapper;
|
||||
|
||||
import com.ruoyi.cms.fileInfo.domain.FileBlogInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈blog文件关联 数据层〉
|
||||
* @Date: 2022/1/2 0:48
|
||||
*/
|
||||
public interface FileBlogInfoMapper {
|
||||
/**
|
||||
* 批量新增
|
||||
*/
|
||||
public int batchFileBlog(List<FileBlogInfo> fileBlogList);
|
||||
/**
|
||||
* 通过blogID删除blog文件关联
|
||||
*/
|
||||
public int deleteFileBlogByBlogId(Long blogId);
|
||||
/**
|
||||
* 批量删除blog文件关联
|
||||
*/
|
||||
public int deleteFileBlog(Long[] ids);
|
||||
/**
|
||||
* 查询文件列表
|
||||
*/
|
||||
public List<FileBlogInfo> selectFileBlogList(Long blogId);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.cms.fileInfo.mapper;
|
||||
|
||||
import com.ruoyi.cms.fileInfo.domain.FileNoticeInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈通知公告和文件关联 数据层〉
|
||||
* @Date: 2021/12/31 22:24
|
||||
*/
|
||||
public interface FileNoticeInfoMapper {
|
||||
/**
|
||||
* 批量新增
|
||||
*/
|
||||
public int batchFileNotice(List<FileNoticeInfo> userRoleList);
|
||||
/**
|
||||
* 通过通知公告ID删除通知公告和文件关联
|
||||
*/
|
||||
public int deleteFileNoticeByNoticeId(Long noticeId);
|
||||
/**
|
||||
* 批量删除通知公告和文件关联
|
||||
*/
|
||||
public int deleteFileNotice(Long[] ids);
|
||||
/**
|
||||
* 查询文件列表
|
||||
*/
|
||||
public List<FileNoticeInfo> selectFileNoticeList(Long noticeId);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.ruoyi.cms.fileInfo.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.fileInfo.domain.SysFileInfo;
|
||||
|
||||
/**
|
||||
* 文件管理Mapper接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2021-12-29
|
||||
*/
|
||||
public interface SysFileInfoMapper
|
||||
{
|
||||
/**
|
||||
* 查询文件管理
|
||||
*
|
||||
* @param fileObjectName
|
||||
* @return 文件管理
|
||||
*/
|
||||
public SysFileInfo selectSysFileInfoByFileObjectName(String fileObjectName);
|
||||
|
||||
/**
|
||||
* 查询文件管理
|
||||
*
|
||||
* @param fileId 文件管理主键
|
||||
* @return 文件管理
|
||||
*/
|
||||
public SysFileInfo selectSysFileInfoByFileId(Long fileId);
|
||||
|
||||
/**
|
||||
* 查询文件管理列表
|
||||
*
|
||||
* @param sysFileInfo 文件管理
|
||||
* @return 文件管理集合
|
||||
*/
|
||||
public List<SysFileInfo> selectSysFileInfoList(SysFileInfo sysFileInfo);
|
||||
|
||||
/**
|
||||
* 新增文件管理
|
||||
*
|
||||
* @param sysFileInfo 文件管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertSysFileInfo(SysFileInfo sysFileInfo);
|
||||
|
||||
/**
|
||||
* 修改文件管理
|
||||
*
|
||||
* @param sysFileInfo 文件管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateSysFileInfo(SysFileInfo sysFileInfo);
|
||||
|
||||
/**
|
||||
* 删除文件管理
|
||||
*
|
||||
* @param fileId 文件管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysFileInfoByFileId(Long fileId);
|
||||
|
||||
/**
|
||||
* 批量删除文件管理
|
||||
*
|
||||
* @param fileIds 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysFileInfoByFileIds(Long[] fileIds);
|
||||
|
||||
/**
|
||||
* 删除文件管理信息
|
||||
*
|
||||
* @param fileObjectName
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysFileInfoByFileObjectName(String fileObjectName);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.cms.fileInfo.service;
|
||||
|
||||
import com.ruoyi.cms.fileInfo.domain.FileBlogInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈${DESCRIPTION}〉
|
||||
* @Date: 2022/1/2 0:58
|
||||
*/
|
||||
public interface IFileBlogInfoService {
|
||||
/**
|
||||
* 批量新增
|
||||
*/
|
||||
public int batchFileBlog(List<FileBlogInfo> fileBlogList);
|
||||
/**
|
||||
* 通过通知公告ID删除通知公告和文件关联
|
||||
*/
|
||||
public int deleteFileBlogByBlogId(Long blogId);
|
||||
/**
|
||||
* 批量删除通知公告和文件关联
|
||||
*/
|
||||
public int deleteFileBlog(Long[] ids);
|
||||
/**
|
||||
* 查询文件列表
|
||||
*/
|
||||
public List<FileBlogInfo> selectFileBlogList(Long blogId);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.cms.fileInfo.service;
|
||||
|
||||
import com.ruoyi.cms.fileInfo.domain.FileNoticeInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈Service接口〉
|
||||
* @Date: 2021/12/31 23:24
|
||||
*/
|
||||
public interface IFileNoticeInfoService {
|
||||
/**
|
||||
* 批量新增
|
||||
*/
|
||||
public int batchFileNotice(List<FileNoticeInfo> fileNoticeList);
|
||||
/**
|
||||
* 通过通知公告ID删除通知公告和文件关联
|
||||
*/
|
||||
public int deleteFileNoticeByNoticeId(Long noticeId);
|
||||
/**
|
||||
* 批量删除通知公告和文件关联
|
||||
*/
|
||||
public int deleteFileNotice(Long[] ids);
|
||||
/**
|
||||
* 查询文件列表
|
||||
*/
|
||||
public List<FileNoticeInfo> selectFileNoticeList(Long noticeId);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.ruoyi.cms.fileInfo.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.fileInfo.domain.SysFileInfo;
|
||||
|
||||
/**
|
||||
* 文件管理Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2021-12-29
|
||||
*/
|
||||
public interface ISysFileInfoService
|
||||
{
|
||||
/**
|
||||
* 查询文件管理
|
||||
*
|
||||
* @param fileObjectName
|
||||
* @return 文件管理
|
||||
*/
|
||||
public SysFileInfo selectSysFileInfoByFileObjectName(String fileObjectName);
|
||||
/**
|
||||
* 查询文件管理
|
||||
*
|
||||
* @param fileId 文件管理主键
|
||||
* @return 文件管理
|
||||
*/
|
||||
public SysFileInfo selectSysFileInfoByFileId(Long fileId);
|
||||
|
||||
/**
|
||||
* 查询文件管理列表
|
||||
*
|
||||
* @param sysFileInfo 文件管理
|
||||
* @return 文件管理集合
|
||||
*/
|
||||
public List<SysFileInfo> selectSysFileInfoList(SysFileInfo sysFileInfo);
|
||||
|
||||
/**
|
||||
* 新增文件管理
|
||||
*
|
||||
* @param sysFileInfo 文件管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertSysFileInfo(SysFileInfo sysFileInfo);
|
||||
|
||||
/**
|
||||
* 修改文件管理
|
||||
*
|
||||
* @param sysFileInfo 文件管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateSysFileInfo(SysFileInfo sysFileInfo);
|
||||
|
||||
/**
|
||||
* 批量删除文件管理
|
||||
*
|
||||
* @param fileIds 需要删除的文件管理主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysFileInfoByFileIds(Long[] fileIds);
|
||||
|
||||
/**
|
||||
* 删除文件管理信息
|
||||
*
|
||||
* @param fileId 文件管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysFileInfoByFileId(Long fileId);
|
||||
|
||||
/**
|
||||
* 删除文件管理信息
|
||||
*
|
||||
* @param fileObjectName
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysFileInfoByFileObjectName(String fileObjectName);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.ruoyi.cms.fileInfo.service.impl;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈〉
|
||||
* @Date: 2022/1/2 1:00
|
||||
*/
|
||||
|
||||
import com.ruoyi.cms.fileInfo.domain.FileBlogInfo;
|
||||
import com.ruoyi.cms.fileInfo.mapper.FileBlogInfoMapper;
|
||||
import com.ruoyi.cms.fileInfo.service.IFileBlogInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈〉
|
||||
* @Date: 2022/1/2 1:00
|
||||
**/
|
||||
@Service
|
||||
public class FileBlogInfoServiceImpl implements IFileBlogInfoService {
|
||||
|
||||
@Autowired
|
||||
private FileBlogInfoMapper fileBlogInfoMapper;
|
||||
|
||||
@Override
|
||||
public int batchFileBlog(List<FileBlogInfo> fileBlogList) {
|
||||
return fileBlogInfoMapper.batchFileBlog(fileBlogList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteFileBlogByBlogId(Long blogId) {
|
||||
return fileBlogInfoMapper.deleteFileBlogByBlogId(blogId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteFileBlog(Long[] ids) {
|
||||
return fileBlogInfoMapper.deleteFileBlog(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileBlogInfo> selectFileBlogList(Long blogId) {
|
||||
return fileBlogInfoMapper.selectFileBlogList(blogId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.ruoyi.cms.fileInfo.service.impl;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈〉
|
||||
* @Date: 2021/12/31 23:33
|
||||
*/
|
||||
|
||||
import com.ruoyi.cms.fileInfo.domain.FileNoticeInfo;
|
||||
import com.ruoyi.cms.fileInfo.domain.SysFileInfo;
|
||||
import com.ruoyi.cms.fileInfo.mapper.FileNoticeInfoMapper;
|
||||
import com.ruoyi.cms.fileInfo.mapper.SysFileInfoMapper;
|
||||
import com.ruoyi.cms.fileInfo.service.IFileNoticeInfoService;
|
||||
import com.ruoyi.common.config.RuoYiConfig;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.file.FileUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈〉
|
||||
* @Date: 2021/12/31 23:33
|
||||
**/
|
||||
@Service
|
||||
public class FileNoticeInfoServiceImpl implements IFileNoticeInfoService {
|
||||
|
||||
@Autowired
|
||||
private FileNoticeInfoMapper fileNoticeInfoMapper;
|
||||
|
||||
@Override
|
||||
public int batchFileNotice(List<FileNoticeInfo> fileNoticeList) {
|
||||
return fileNoticeInfoMapper.batchFileNotice(fileNoticeList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteFileNoticeByNoticeId(Long noticeId) {
|
||||
return fileNoticeInfoMapper.deleteFileNoticeByNoticeId(noticeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteFileNotice(Long[] ids) {
|
||||
return fileNoticeInfoMapper.deleteFileNotice(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileNoticeInfo> selectFileNoticeList(Long noticeId) {
|
||||
return fileNoticeInfoMapper.selectFileNoticeList(noticeId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.ruoyi.cms.fileInfo.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.config.RuoYiConfig;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.file.FileUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.cms.fileInfo.mapper.SysFileInfoMapper;
|
||||
import com.ruoyi.cms.fileInfo.domain.SysFileInfo;
|
||||
import com.ruoyi.cms.fileInfo.service.ISysFileInfoService;
|
||||
|
||||
/**
|
||||
* 文件管理Service业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2021-12-29
|
||||
*/
|
||||
@Service
|
||||
public class SysFileInfoServiceImpl implements ISysFileInfoService
|
||||
{
|
||||
@Autowired
|
||||
private SysFileInfoMapper sysFileInfoMapper;
|
||||
|
||||
@Override
|
||||
public SysFileInfo selectSysFileInfoByFileObjectName(String fileObjectName) {
|
||||
return sysFileInfoMapper.selectSysFileInfoByFileObjectName(fileObjectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文件管理
|
||||
*
|
||||
* @param fileId 文件管理主键
|
||||
* @return 文件管理
|
||||
*/
|
||||
@Override
|
||||
public SysFileInfo selectSysFileInfoByFileId(Long fileId)
|
||||
{
|
||||
return sysFileInfoMapper.selectSysFileInfoByFileId(fileId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文件管理列表
|
||||
*
|
||||
* @param sysFileInfo 文件管理
|
||||
* @return 文件管理
|
||||
*/
|
||||
@Override
|
||||
public List<SysFileInfo> selectSysFileInfoList(SysFileInfo sysFileInfo)
|
||||
{
|
||||
return sysFileInfoMapper.selectSysFileInfoList(sysFileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增文件管理
|
||||
*
|
||||
* @param sysFileInfo 文件管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertSysFileInfo(SysFileInfo sysFileInfo)
|
||||
{
|
||||
sysFileInfo.setCreateTime(DateUtils.getNowDate());
|
||||
return sysFileInfoMapper.insertSysFileInfo(sysFileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件管理
|
||||
*
|
||||
* @param sysFileInfo 文件管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateSysFileInfo(SysFileInfo sysFileInfo)
|
||||
{
|
||||
sysFileInfo.setUpdateTime(DateUtils.getNowDate());
|
||||
return sysFileInfoMapper.updateSysFileInfo(sysFileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除文件管理
|
||||
*
|
||||
* @param fileIds 需要删除的文件管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSysFileInfoByFileIds(Long[] fileIds)
|
||||
{
|
||||
for (int i = 0; i<fileIds.length; i++){
|
||||
Long fileId = fileIds[i];
|
||||
SysFileInfo sysFileInfo = sysFileInfoMapper.selectSysFileInfoByFileId(fileId);
|
||||
String filePath = RuoYiConfig.getProfile() + StringUtils.substringAfter(sysFileInfo.getFilePath(), Constants.RESOURCE_PREFIX);
|
||||
FileUtils.deleteFile(filePath);
|
||||
}
|
||||
return sysFileInfoMapper.deleteSysFileInfoByFileIds(fileIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件管理信息
|
||||
*
|
||||
* @param fileId 文件管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSysFileInfoByFileId(Long fileId)
|
||||
{
|
||||
SysFileInfo sysFileInfo = sysFileInfoMapper.selectSysFileInfoByFileId(fileId);
|
||||
String filePath = RuoYiConfig.getProfile() + StringUtils.substringAfter(sysFileInfo.getFilePath(), Constants.RESOURCE_PREFIX);
|
||||
FileUtils.deleteFile(filePath);
|
||||
return sysFileInfoMapper.deleteSysFileInfoByFileId(fileId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteSysFileInfoByFileObjectName(String fileObjectName) {
|
||||
SysFileInfo sysFileInfo = sysFileInfoMapper.selectSysFileInfoByFileObjectName(fileObjectName);
|
||||
String filePath = RuoYiConfig.getProfile() + StringUtils.substringAfter(sysFileInfo.getFilePath(), Constants.RESOURCE_PREFIX);
|
||||
FileUtils.deleteFile(filePath);
|
||||
return sysFileInfoMapper.deleteSysFileInfoByFileObjectName(fileObjectName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.ruoyi.cms.message.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.cms.message.domain.CmsMessageLike;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.cms.message.domain.CmsMessage;
|
||||
import com.ruoyi.cms.message.service.ICmsMessageService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 留言管理Controller
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-15
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/cms/message")
|
||||
public class CmsMessageController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ICmsMessageService cmsMessageService;
|
||||
|
||||
@Autowired
|
||||
private SysPermissionService permissionService;
|
||||
|
||||
/**
|
||||
* 首页查询留言列表
|
||||
*/
|
||||
@GetMapping("/cms/list")
|
||||
public TableDataInfo cmsList(CmsMessage cmsMessage)
|
||||
{
|
||||
startPage();
|
||||
List<CmsMessage> list = cmsMessageService.selectMessageList(cmsMessage);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页新增留言
|
||||
*/
|
||||
@PostMapping("/cms/addMessage")
|
||||
public AjaxResult addMessage(@RequestBody CmsMessage cmsMessage)
|
||||
{
|
||||
Long parentId = cmsMessage.getParentId();
|
||||
if (parentId!=null){
|
||||
CmsMessage message = cmsMessageService.selectCmsMessageById(parentId);
|
||||
if (message.getMainId()!=null){
|
||||
cmsMessage.setMainId(message.getMainId());
|
||||
}else {
|
||||
cmsMessage.setMainId(parentId);
|
||||
}
|
||||
}
|
||||
return toAjax(cmsMessageService.insertCmsMessage(cmsMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页新增点赞
|
||||
*/
|
||||
@PostMapping("/cms/addCmsMessageLike")
|
||||
public AjaxResult addCmsMessageLike(@RequestBody CmsMessageLike cmsMessageLike)
|
||||
{
|
||||
return toAjax(cmsMessageService.addCmsMessageLike(cmsMessageLike));
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页删除点赞
|
||||
*/
|
||||
@Log(title = "删除留言点赞", businessType = BusinessType.DELETE)
|
||||
@PostMapping("/cms/delCmsMessageLike")
|
||||
public AjaxResult delCmsMessageLike(@RequestBody CmsMessageLike cmsMessageLike)
|
||||
{
|
||||
return toAjax(cmsMessageService.delCmsMessageLike(cmsMessageLike));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询留言管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:message:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(CmsMessage cmsMessage)
|
||||
{
|
||||
startPage();
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (!SecurityUtils.isAdmin(getUserId())&&!roles.contains("admin")&&!roles.contains("cms")){
|
||||
cmsMessage.setCreateBy(getUsername());
|
||||
}
|
||||
cmsMessage.setDelFlag("0");
|
||||
List<CmsMessage> list = cmsMessageService.selectCmsMessageList(cmsMessage);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出留言管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:message:export')")
|
||||
@Log(title = "留言管理", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, CmsMessage cmsMessage)
|
||||
{
|
||||
List<CmsMessage> list = cmsMessageService.selectCmsMessageList(cmsMessage);
|
||||
ExcelUtil<CmsMessage> util = new ExcelUtil<CmsMessage>(CmsMessage.class);
|
||||
util.exportExcel(response, list, "留言管理数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取留言管理详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:message:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return AjaxResult.success(cmsMessageService.selectCmsMessageById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增留言管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:message:add')")
|
||||
@Log(title = "留言管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody CmsMessage cmsMessage)
|
||||
{
|
||||
return toAjax(cmsMessageService.insertCmsMessage(cmsMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改留言管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:message:edit')")
|
||||
@Log(title = "留言管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody CmsMessage cmsMessage)
|
||||
{
|
||||
return toAjax(cmsMessageService.updateCmsMessage(cmsMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除留言管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:message:remove')")
|
||||
@Log(title = "留言管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(cmsMessageService.deleteCmsMessageByIds(ids));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
package com.ruoyi.cms.message.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 留言管理对象 cms_message
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-15
|
||||
*/
|
||||
public class CmsMessage extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
private Long id;
|
||||
|
||||
/** 父留言id */
|
||||
@Excel(name = "父留言id")
|
||||
private Long parentId;
|
||||
|
||||
/** 主留言id(第一级留言) */
|
||||
@Excel(name = "主留言id(第一级留言)")
|
||||
private Long mainId;
|
||||
|
||||
/** 点赞数量 */
|
||||
@Excel(name = "点赞数量")
|
||||
private Long likeNum;
|
||||
|
||||
/** 内容 */
|
||||
@Excel(name = "内容")
|
||||
private String content;
|
||||
|
||||
/** 留言类型:(0代表留言 1代表回复) */
|
||||
@Excel(name = "留言类型:(0代表留言 1代表回复)")
|
||||
private String type;
|
||||
|
||||
/** 被留言者id,可以是人、项目、资源 */
|
||||
@Excel(name = "被留言者id,可以是人、项目、资源")
|
||||
private Long blogId;
|
||||
|
||||
/** 留言者id */
|
||||
@Excel(name = "留言者id")
|
||||
private Long userId;
|
||||
|
||||
/** 删除标志(0代表存在 1代表删除) */
|
||||
@Excel(name = "删除标志(0代表存在 1代表删除)")
|
||||
private String delFlag;
|
||||
|
||||
/** 头像 */
|
||||
private String avatar;
|
||||
|
||||
/** 回复 */
|
||||
private List<CmsMessage> children;
|
||||
|
||||
/** 父留言者 */
|
||||
private String pCreateBy;
|
||||
|
||||
/** 点赞 */
|
||||
private boolean isLike;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
public void setParentId(Long parentId)
|
||||
{
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public Long getParentId()
|
||||
{
|
||||
return parentId;
|
||||
}
|
||||
public void setLikeNum(Long likeNum)
|
||||
{
|
||||
this.likeNum = likeNum;
|
||||
}
|
||||
|
||||
public Long getMainId() {
|
||||
return mainId;
|
||||
}
|
||||
|
||||
public void setMainId(Long mainId) {
|
||||
this.mainId = mainId;
|
||||
}
|
||||
|
||||
public Long getLikeNum()
|
||||
{
|
||||
return likeNum;
|
||||
}
|
||||
public void setContent(String content)
|
||||
{
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContent()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
public void setBlogId(Long blogId)
|
||||
{
|
||||
this.blogId = blogId;
|
||||
}
|
||||
|
||||
public Long getBlogId()
|
||||
{
|
||||
return blogId;
|
||||
}
|
||||
public void setUserId(Long userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
|
||||
public String getDelFlag() {
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
public void setDelFlag(String delFlag) {
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public List<CmsMessage> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<CmsMessage> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public String getPCreateBy() {
|
||||
return pCreateBy;
|
||||
}
|
||||
|
||||
public void setPCreateBy(String pCreateBy) {
|
||||
this.pCreateBy = pCreateBy;
|
||||
}
|
||||
|
||||
public boolean getIsLike() {
|
||||
return isLike;
|
||||
}
|
||||
|
||||
public void setIsLike(boolean isLike) {
|
||||
this.isLike = isLike;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("parentId", getParentId())
|
||||
.append("mainId", getMainId())
|
||||
.append("likeNum", getLikeNum())
|
||||
.append("content", getContent())
|
||||
.append("type", getType())
|
||||
.append("blogId", getBlogId())
|
||||
.append("userId", getUserId())
|
||||
.append("delFlag", getDelFlag())
|
||||
.append("avatar",getAvatar())
|
||||
.append("children",getChildren())
|
||||
.append("pCreateBy",getPCreateBy())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("isLike", getIsLike())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.ruoyi.cms.message.domain;
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈留言点赞实体类〉
|
||||
* @Date: 2022/1/19 8:38
|
||||
*/
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* @Author: WangNing
|
||||
* @Description:〈留言点赞实体类〉
|
||||
* @Date: 2022/1/19 8:38
|
||||
**/
|
||||
public class CmsMessageLike extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long messageId;
|
||||
private Long userId;
|
||||
|
||||
/** 点赞数量 */
|
||||
private Long likeNum;
|
||||
|
||||
public Long getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(Long messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getLikeNum() {
|
||||
return likeNum;
|
||||
}
|
||||
|
||||
public void setLikeNum(Long likeNum) {
|
||||
this.likeNum = likeNum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("messageId", getMessageId())
|
||||
.append("userId", getUserId())
|
||||
.append("likeNum", getLikeNum())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.ruoyi.cms.message.mapper;
|
||||
|
||||
import com.ruoyi.cms.message.domain.CmsMessageLike;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈数据层〉
|
||||
* @Date: 2022/1/19 8:42
|
||||
*/
|
||||
public interface CmsMessageLikeMapper {
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
public List<CmsMessageLike> selectCmsMessageLikeList(CmsMessageLike cmsMessageLike);
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public int addCmsMessageLike(CmsMessageLike cmsMessageLike);
|
||||
/**
|
||||
* 删除关联
|
||||
*/
|
||||
public int deleteCmsMessageLike(CmsMessageLike cmsMessageLike);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.ruoyi.cms.message.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.message.domain.CmsMessage;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 留言管理Mapper接口
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-15
|
||||
*/
|
||||
public interface CmsMessageMapper
|
||||
{
|
||||
/**
|
||||
* 查询留言管理
|
||||
*
|
||||
* @param id 留言管理主键
|
||||
* @return 留言管理
|
||||
*/
|
||||
public CmsMessage selectCmsMessageById(Long id);
|
||||
|
||||
/**
|
||||
* 查询留言管理列表
|
||||
*
|
||||
* @param cmsMessage 留言管理
|
||||
* @return 留言管理集合
|
||||
*/
|
||||
public List<CmsMessage> selectCmsMessageList(CmsMessage cmsMessage);
|
||||
|
||||
public List<CmsMessage> selectCmsMessageListBetweenCreateTime(@Param("type") String type, @Param("delFlag") String delFlag, @Param("createTimeBegin") String createTimeBegin, @Param("createTimeEnd") String createTimeEnd);
|
||||
|
||||
/**
|
||||
* 查询子留言列表
|
||||
*/
|
||||
public List<CmsMessage> selectChildMessageList(CmsMessage cmsMessage);
|
||||
|
||||
/**
|
||||
* 新增留言管理
|
||||
*
|
||||
* @param cmsMessage 留言管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCmsMessage(CmsMessage cmsMessage);
|
||||
|
||||
/**
|
||||
* 修改留言管理
|
||||
*
|
||||
* @param cmsMessage 留言管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsMessage(CmsMessage cmsMessage);
|
||||
|
||||
/**
|
||||
* 删除留言管理
|
||||
*
|
||||
* @param id 留言管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsMessageById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除留言管理
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsMessageByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除留言管理
|
||||
*
|
||||
* @param id 留言管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDelFlagById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除留言管理
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDelFlagByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 统计留言数量
|
||||
*
|
||||
* @param cmsMessage 查询条件
|
||||
* @return 留言数量
|
||||
*/
|
||||
public int countCmsMessage(CmsMessage cmsMessage);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.ruoyi.cms.message.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.message.domain.CmsMessage;
|
||||
import com.ruoyi.cms.message.domain.CmsMessageLike;
|
||||
|
||||
/**
|
||||
* 留言管理Service接口
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-15
|
||||
*/
|
||||
public interface ICmsMessageService
|
||||
{
|
||||
/**
|
||||
* 首页查询留言列表
|
||||
*/
|
||||
public List<CmsMessage> selectMessageList(CmsMessage cmsMessage);
|
||||
|
||||
/**
|
||||
* 首页新增点赞
|
||||
*/
|
||||
public int addCmsMessageLike(CmsMessageLike cmsMessageLike);
|
||||
|
||||
/**
|
||||
* 首页删除点赞
|
||||
*/
|
||||
public int delCmsMessageLike(CmsMessageLike cmsMessageLike);
|
||||
|
||||
/**
|
||||
* 查询留言管理
|
||||
*
|
||||
* @param id 留言管理主键
|
||||
* @return 留言管理
|
||||
*/
|
||||
public CmsMessage selectCmsMessageById(Long id);
|
||||
|
||||
/**
|
||||
* 查询留言管理列表
|
||||
*
|
||||
* @param cmsMessage 留言管理
|
||||
* @return 留言管理集合
|
||||
*/
|
||||
public List<CmsMessage> selectCmsMessageList(CmsMessage cmsMessage);
|
||||
|
||||
/**
|
||||
* 新增留言管理
|
||||
*
|
||||
* @param cmsMessage 留言管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCmsMessage(CmsMessage cmsMessage);
|
||||
|
||||
/**
|
||||
* 修改留言管理
|
||||
*
|
||||
* @param cmsMessage 留言管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsMessage(CmsMessage cmsMessage);
|
||||
|
||||
/**
|
||||
* 批量删除留言管理
|
||||
*
|
||||
* @param ids 需要删除的留言管理主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsMessageByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除留言管理信息
|
||||
*
|
||||
* @param id 留言管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsMessageById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
package com.ruoyi.cms.message.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.cms.message.domain.CmsMessageLike;
|
||||
import com.ruoyi.cms.message.mapper.CmsMessageLikeMapper;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.cms.message.mapper.CmsMessageMapper;
|
||||
import com.ruoyi.cms.message.domain.CmsMessage;
|
||||
import com.ruoyi.cms.message.service.ICmsMessageService;
|
||||
|
||||
/**
|
||||
* 留言管理Service业务层处理
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-15
|
||||
*/
|
||||
@Service
|
||||
public class CmsMessageServiceImpl implements ICmsMessageService
|
||||
{
|
||||
@Autowired
|
||||
private CmsMessageMapper cmsMessageMapper;
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
@Autowired
|
||||
private CmsMessageLikeMapper cmsMessageLikeMapper;
|
||||
|
||||
/**
|
||||
* 首页查询留言列表
|
||||
*/
|
||||
@Override
|
||||
public List<CmsMessage> selectMessageList(CmsMessage cmsMessage) {
|
||||
//判断是否登录
|
||||
Long logUserUserId = null;
|
||||
String createBy = cmsMessage.getCreateBy();
|
||||
if (createBy!=null&&!"".equals(createBy)){
|
||||
SysUser logUser = sysUserMapper.selectUserByUserName(createBy);
|
||||
logUserUserId = logUser.getUserId();
|
||||
}
|
||||
cmsMessage.setCreateBy(null);
|
||||
cmsMessage.setType("0");
|
||||
cmsMessage.setDelFlag("0");
|
||||
List<CmsMessage> cmsMessageList = cmsMessageMapper.selectCmsMessageList(cmsMessage);
|
||||
for (CmsMessage message : cmsMessageList) {
|
||||
//添加头像
|
||||
Long userId = message.getUserId();
|
||||
if (userId!=null){
|
||||
SysUser user = sysUserMapper.selectUserById(userId);
|
||||
message.setAvatar(user.getAvatar());
|
||||
}
|
||||
//添加是否被点赞
|
||||
if (logUserUserId!=null){
|
||||
CmsMessageLike messageLike = new CmsMessageLike();
|
||||
messageLike.setMessageId(message.getId());
|
||||
messageLike.setUserId(logUserUserId);
|
||||
List<CmsMessageLike> likeList = cmsMessageLikeMapper.selectCmsMessageLikeList(messageLike);
|
||||
if (likeList.size()>0){
|
||||
message.setIsLike(true);
|
||||
}else {
|
||||
message.setIsLike(false);
|
||||
}
|
||||
}
|
||||
//添加子评论(回复)
|
||||
CmsMessage childMessage = new CmsMessage();
|
||||
childMessage.setType("1");
|
||||
childMessage.setMainId(message.getId());
|
||||
List<CmsMessage> childMessageList = cmsMessageMapper.selectChildMessageList(childMessage);
|
||||
if (childMessageList.size()>0){
|
||||
for (CmsMessage childListMessage : childMessageList) {
|
||||
//添加头像
|
||||
Long childUserId = childListMessage.getUserId();
|
||||
if (childUserId!=null){
|
||||
SysUser user = sysUserMapper.selectUserById(childUserId);
|
||||
childListMessage.setAvatar(user.getAvatar());
|
||||
}
|
||||
//添加是否被点赞
|
||||
if (logUserUserId!=null){
|
||||
CmsMessageLike messageLike = new CmsMessageLike();
|
||||
messageLike.setMessageId(message.getId());
|
||||
messageLike.setUserId(logUserUserId);
|
||||
List<CmsMessageLike> likeList = cmsMessageLikeMapper.selectCmsMessageLikeList(messageLike);
|
||||
if (likeList.size()>0){
|
||||
message.setIsLike(true);
|
||||
}else {
|
||||
message.setIsLike(false);
|
||||
}
|
||||
}
|
||||
//添加父留言信息
|
||||
CmsMessage byId = cmsMessageMapper.selectCmsMessageById(childListMessage.getParentId());
|
||||
childListMessage.setPCreateBy(byId.getCreateBy());
|
||||
}
|
||||
message.setChildren(childMessageList);
|
||||
}
|
||||
}
|
||||
return cmsMessageList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addCmsMessageLike(CmsMessageLike cmsMessageLike) {
|
||||
int result = -1;
|
||||
String createBy = cmsMessageLike.getCreateBy();
|
||||
if (!"".equals(createBy)&&createBy!=null){
|
||||
SysUser user = sysUserMapper.selectUserByUserName(createBy);
|
||||
if (user!=null){
|
||||
cmsMessageLike.setUserId(user.getUserId());
|
||||
cmsMessageLikeMapper.addCmsMessageLike(cmsMessageLike);
|
||||
}
|
||||
}
|
||||
//修改点赞数量
|
||||
CmsMessage cmsMessage = new CmsMessage();
|
||||
cmsMessage.setId(cmsMessageLike.getMessageId());
|
||||
cmsMessage.setLikeNum(cmsMessageLike.getLikeNum());
|
||||
result = cmsMessageMapper.updateCmsMessage(cmsMessage);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delCmsMessageLike(CmsMessageLike cmsMessageLike) {
|
||||
int result = -1;
|
||||
String createBy = cmsMessageLike.getCreateBy();
|
||||
if (!"".equals(createBy)&&createBy!=null){
|
||||
SysUser user = sysUserMapper.selectUserByUserName(createBy);
|
||||
if (user!=null){
|
||||
cmsMessageLike.setUserId(user.getUserId());
|
||||
cmsMessageLikeMapper.deleteCmsMessageLike(cmsMessageLike);
|
||||
}
|
||||
}
|
||||
//修改点赞数量
|
||||
CmsMessage cmsMessage = new CmsMessage();
|
||||
cmsMessage.setId(cmsMessageLike.getMessageId());
|
||||
cmsMessage.setLikeNum(cmsMessageLike.getLikeNum());
|
||||
result = cmsMessageMapper.updateCmsMessage(cmsMessage);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询留言管理
|
||||
*
|
||||
* @param id 留言管理主键
|
||||
* @return 留言管理
|
||||
*/
|
||||
@Override
|
||||
public CmsMessage selectCmsMessageById(Long id)
|
||||
{
|
||||
return cmsMessageMapper.selectCmsMessageById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询留言管理列表
|
||||
*
|
||||
* @param cmsMessage 留言管理
|
||||
* @return 留言管理
|
||||
*/
|
||||
@Override
|
||||
public List<CmsMessage> selectCmsMessageList(CmsMessage cmsMessage)
|
||||
{
|
||||
List<CmsMessage> cmsMessageList = new ArrayList<>();
|
||||
//判断用户权限
|
||||
String createBy = cmsMessage.getCreateBy();
|
||||
if (createBy!=null&&!"".equals(createBy)){
|
||||
SysUser user = sysUserMapper.selectUserByUserName(createBy);
|
||||
if (user!=null){
|
||||
List<CmsMessage> MessageList = cmsMessageMapper.selectCmsMessageList(cmsMessage);
|
||||
for (CmsMessage message : MessageList) {
|
||||
//查询子评论(回复)
|
||||
CmsMessage childMessage = new CmsMessage();
|
||||
childMessage.setType("1");
|
||||
childMessage.setParentId(message.getId());
|
||||
List<CmsMessage> childMessageList = cmsMessageMapper.selectCmsMessageList(childMessage);
|
||||
if (childMessageList.size()>0){
|
||||
cmsMessageList.addAll(childMessageList);
|
||||
}
|
||||
}
|
||||
cmsMessageList.addAll(MessageList);
|
||||
}
|
||||
}else {
|
||||
cmsMessageList = cmsMessageMapper.selectCmsMessageList(cmsMessage);
|
||||
}
|
||||
for (CmsMessage message : cmsMessageList) {
|
||||
//添加头像
|
||||
Long userId = message.getUserId();
|
||||
if (userId!=null){
|
||||
SysUser user = sysUserMapper.selectUserById(userId);
|
||||
message.setAvatar(user.getAvatar());
|
||||
}
|
||||
//添加父留言信息
|
||||
Long parentId = message.getParentId();
|
||||
if (parentId!=null){
|
||||
CmsMessage parentMessage = cmsMessageMapper.selectCmsMessageById(parentId);
|
||||
message.setPCreateBy(parentMessage.getCreateBy());
|
||||
}
|
||||
}
|
||||
//排序
|
||||
// String[] sortNameArr1 = {"createTime"};
|
||||
// //true升序,false降序
|
||||
// boolean[] isAscArr1 = {false};
|
||||
// ListSortUtils.sort(cmsMessageList, sortNameArr1, isAscArr1);
|
||||
// cmsMessageList.sort((a,b)->a.getCreateBy().compareTo(b.getCreateBy()));
|
||||
// Collections.sort(cmsMessageList, new Comparator<CmsMessage>() {
|
||||
// @Override
|
||||
// public int compare(CmsMessage o1, CmsMessage o2) {
|
||||
// //升序
|
||||
// //return o1.getCreateBy().compareTo(o2.getCreateBy());
|
||||
// //降序
|
||||
// return o2.getCreateBy().compareTo(o1.getCreateBy());
|
||||
// }
|
||||
// });
|
||||
return cmsMessageList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增留言管理
|
||||
*
|
||||
* @param cmsMessage 留言管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertCmsMessage(CmsMessage cmsMessage)
|
||||
{
|
||||
String createBy = cmsMessage.getCreateBy();
|
||||
if (createBy!=null&&!"".equals(createBy)){
|
||||
SysUser user = sysUserMapper.selectUserByUserName(createBy);
|
||||
if (user!=null){
|
||||
cmsMessage.setUserId(user.getUserId());
|
||||
}
|
||||
}
|
||||
cmsMessage.setCreateTime(DateUtils.getNowDate());
|
||||
return cmsMessageMapper.insertCmsMessage(cmsMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改留言管理
|
||||
*
|
||||
* @param cmsMessage 留言管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateCmsMessage(CmsMessage cmsMessage)
|
||||
{
|
||||
cmsMessage.setUpdateTime(DateUtils.getNowDate());
|
||||
return cmsMessageMapper.updateCmsMessage(cmsMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除留言管理
|
||||
*
|
||||
* @param ids 需要删除的留言管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCmsMessageByIds(Long[] ids)
|
||||
{
|
||||
return cmsMessageMapper.updateDelFlagByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除留言管理信息
|
||||
*
|
||||
* @param id 留言管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCmsMessageById(Long id)
|
||||
{
|
||||
return cmsMessageMapper.updateDelFlagById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.ruoyi.cms.tag.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.cms.tag.domain.CmsTag;
|
||||
import com.ruoyi.cms.tag.service.ICmsTagService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 标签管理Controller
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-02
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/cms/tag")
|
||||
public class CmsTagController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ICmsTagService cmsTagService;
|
||||
|
||||
@Autowired
|
||||
private SysPermissionService permissionService;
|
||||
|
||||
/**
|
||||
* 查询标签管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:tag:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(CmsTag cmsTag)
|
||||
{
|
||||
startPage();
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (!SecurityUtils.isAdmin(getUserId())&&!roles.contains("admin")&&!roles.contains("cms")){
|
||||
cmsTag.setCreateBy(getUsername());
|
||||
}
|
||||
List<CmsTag> list = cmsTagService.selectCmsTagList(cmsTag);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出标签管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:tag:export')")
|
||||
@Log(title = "标签管理", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, CmsTag cmsTag)
|
||||
{
|
||||
List<CmsTag> list = cmsTagService.selectCmsTagList(cmsTag);
|
||||
ExcelUtil<CmsTag> util = new ExcelUtil<CmsTag>(CmsTag.class);
|
||||
util.exportExcel(response, list, "标签管理数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取标签管理详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:tag:query')")
|
||||
@GetMapping(value = "/{tagId}")
|
||||
public AjaxResult getInfo(@PathVariable("tagId") Long tagId)
|
||||
{
|
||||
return AjaxResult.success(cmsTagService.selectCmsTagByTagId(tagId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增标签管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:tag:add')")
|
||||
@Log(title = "标签管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody CmsTag cmsTag)
|
||||
{
|
||||
cmsTag.setCreateBy(getUsername());
|
||||
return toAjax(cmsTagService.insertCmsTag(cmsTag));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改标签管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:tag:edit')")
|
||||
@Log(title = "标签管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody CmsTag cmsTag)
|
||||
{
|
||||
cmsTag.setUpdateBy(getUsername());
|
||||
return toAjax(cmsTagService.updateCmsTag(cmsTag));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除标签管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:tag:remove')")
|
||||
@Log(title = "标签管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{tagIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] tagIds)
|
||||
{
|
||||
return toAjax(cmsTagService.deleteCmsTagByTagIds(tagIds));
|
||||
}
|
||||
}
|
||||
67
ruoyi-cms/src/main/java/com/ruoyi/cms/tag/domain/CmsTag.java
Normal file
67
ruoyi-cms/src/main/java/com/ruoyi/cms/tag/domain/CmsTag.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.ruoyi.cms.tag.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 标签管理对象 cms_tag
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-02
|
||||
*/
|
||||
public class CmsTag extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 标签ID */
|
||||
private Long tagId;
|
||||
|
||||
/** 标签名称 */
|
||||
@Excel(name = "标签名称")
|
||||
private String tagName;
|
||||
|
||||
/** 博客数量 */
|
||||
private int blogNum;
|
||||
|
||||
public void setTagId(Long tagId)
|
||||
{
|
||||
this.tagId = tagId;
|
||||
}
|
||||
|
||||
public Long getTagId()
|
||||
{
|
||||
return tagId;
|
||||
}
|
||||
public void setTagName(String tagName)
|
||||
{
|
||||
this.tagName = tagName;
|
||||
}
|
||||
|
||||
public String getTagName()
|
||||
{
|
||||
return tagName;
|
||||
}
|
||||
|
||||
public int getBlogNum() {
|
||||
return blogNum;
|
||||
}
|
||||
|
||||
public void setBlogNum(int blogNum) {
|
||||
this.blogNum = blogNum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("tagId", getTagId())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("tagName", getTagName())
|
||||
.append("blogNum", getBlogNum())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.ruoyi.cms.tag.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.tag.domain.CmsTag;
|
||||
|
||||
/**
|
||||
* 标签管理Mapper接口
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-02
|
||||
*/
|
||||
public interface CmsTagMapper
|
||||
{
|
||||
/**
|
||||
* 查询标签管理
|
||||
*
|
||||
* @param tagId 标签管理主键
|
||||
* @return 标签管理
|
||||
*/
|
||||
public CmsTag selectCmsTagByTagId(Long tagId);
|
||||
|
||||
/**
|
||||
* 查询标签管理列表
|
||||
*
|
||||
* @param cmsTag 标签管理
|
||||
* @return 标签管理集合
|
||||
*/
|
||||
public List<CmsTag> selectCmsTagList(CmsTag cmsTag);
|
||||
|
||||
/**
|
||||
* 通过tagName查询标签管理列表
|
||||
*
|
||||
* @param tagName
|
||||
* @return 标签管理集合
|
||||
*/
|
||||
public List<CmsTag> selectCmsTagListByTagName(String tagName);
|
||||
|
||||
/**
|
||||
* 新增标签管理
|
||||
*
|
||||
* @param cmsTag 标签管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCmsTag(CmsTag cmsTag);
|
||||
|
||||
/**
|
||||
* 修改标签管理
|
||||
*
|
||||
* @param cmsTag 标签管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsTag(CmsTag cmsTag);
|
||||
|
||||
/**
|
||||
* 删除标签管理
|
||||
*
|
||||
* @param tagId 标签管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsTagByTagId(Long tagId);
|
||||
|
||||
/**
|
||||
* 批量删除标签管理
|
||||
*
|
||||
* @param tagIds 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsTagByTagIds(Long[] tagIds);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.cms.tag.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.tag.domain.CmsTag;
|
||||
|
||||
/**
|
||||
* 标签管理Service接口
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-02
|
||||
*/
|
||||
public interface ICmsTagService
|
||||
{
|
||||
/**
|
||||
* 查询标签管理
|
||||
*
|
||||
* @param tagId 标签管理主键
|
||||
* @return 标签管理
|
||||
*/
|
||||
public CmsTag selectCmsTagByTagId(Long tagId);
|
||||
|
||||
/**
|
||||
* 查询标签管理列表
|
||||
*
|
||||
* @param cmsTag 标签管理
|
||||
* @return 标签管理集合
|
||||
*/
|
||||
public List<CmsTag> selectCmsTagList(CmsTag cmsTag);
|
||||
|
||||
/**
|
||||
* 新增标签管理
|
||||
*
|
||||
* @param cmsTag 标签管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCmsTag(CmsTag cmsTag);
|
||||
|
||||
/**
|
||||
* 修改标签管理
|
||||
*
|
||||
* @param cmsTag 标签管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsTag(CmsTag cmsTag);
|
||||
|
||||
/**
|
||||
* 批量删除标签管理
|
||||
*
|
||||
* @param tagIds 需要删除的标签管理主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsTagByTagIds(Long[] tagIds);
|
||||
|
||||
/**
|
||||
* 删除标签管理信息
|
||||
*
|
||||
* @param tagId 标签管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsTagByTagId(Long tagId);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.ruoyi.cms.tag.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.cms.blog.mapper.CmsBlogTagMapper;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.cms.tag.mapper.CmsTagMapper;
|
||||
import com.ruoyi.cms.tag.domain.CmsTag;
|
||||
import com.ruoyi.cms.tag.service.ICmsTagService;
|
||||
|
||||
/**
|
||||
* 标签管理Service业务层处理
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-02
|
||||
*/
|
||||
@Service
|
||||
public class CmsTagServiceImpl implements ICmsTagService
|
||||
{
|
||||
@Autowired
|
||||
private CmsTagMapper cmsTagMapper;
|
||||
|
||||
@Autowired
|
||||
private CmsBlogTagMapper cmsBlogTagMapper;
|
||||
|
||||
/**
|
||||
* 查询标签管理
|
||||
*
|
||||
* @param tagId 标签管理主键
|
||||
* @return 标签管理
|
||||
*/
|
||||
@Override
|
||||
public CmsTag selectCmsTagByTagId(Long tagId)
|
||||
{
|
||||
return cmsTagMapper.selectCmsTagByTagId(tagId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询标签管理列表
|
||||
*
|
||||
* @param cmsTag 标签管理
|
||||
* @return 标签管理
|
||||
*/
|
||||
@Override
|
||||
public List<CmsTag> selectCmsTagList(CmsTag cmsTag)
|
||||
{
|
||||
List<CmsTag> cmsTagList = cmsTagMapper.selectCmsTagList(cmsTag);
|
||||
for (CmsTag tag : cmsTagList) {
|
||||
int blogNum = cmsBlogTagMapper.countBlogByTagId(tag.getTagId());
|
||||
tag.setBlogNum(blogNum);
|
||||
}
|
||||
return cmsTagList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增标签管理
|
||||
*
|
||||
* @param cmsTag 标签管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertCmsTag(CmsTag cmsTag)
|
||||
{
|
||||
List<CmsTag> cmsTagList = cmsTagMapper.selectCmsTagListByTagName(cmsTag.getTagName());
|
||||
if (cmsTagList.size()>0){
|
||||
throw new ServiceException("标签名称已存在");
|
||||
}
|
||||
cmsTag.setCreateTime(DateUtils.getNowDate());
|
||||
return cmsTagMapper.insertCmsTag(cmsTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改标签管理
|
||||
*
|
||||
* @param cmsTag 标签管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateCmsTag(CmsTag cmsTag)
|
||||
{
|
||||
List<CmsTag> cmsTagList = cmsTagMapper.selectCmsTagListByTagName(cmsTag.getTagName());
|
||||
if (cmsTagList.size()>0){
|
||||
for (CmsTag tag : cmsTagList) {
|
||||
if (!cmsTag.getTagId().equals(tag.getTagId())){
|
||||
throw new ServiceException("标签名称已存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
cmsTag.setUpdateTime(DateUtils.getNowDate());
|
||||
return cmsTagMapper.updateCmsTag(cmsTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除标签管理
|
||||
*
|
||||
* @param tagIds 需要删除的标签管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCmsTagByTagIds(Long[] tagIds)
|
||||
{
|
||||
for (Long tagId : tagIds) {
|
||||
//删除标签文章关联表信息
|
||||
cmsBlogTagMapper.deleteBlogTagByTagId(tagId);
|
||||
}
|
||||
return cmsTagMapper.deleteCmsTagByTagIds(tagIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除标签管理信息
|
||||
*
|
||||
* @param tagId 标签管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCmsTagByTagId(Long tagId)
|
||||
{
|
||||
//删除标签文章关联表信息
|
||||
cmsBlogTagMapper.deleteBlogTagByTagId(tagId);
|
||||
return cmsTagMapper.deleteCmsTagByTagId(tagId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.ruoyi.cms.type.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.cms.type.domain.CmsType;
|
||||
import com.ruoyi.cms.type.service.ICmsTypeService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 分类管理Controller
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-02
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/cms/type")
|
||||
public class CmsTypeController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ICmsTypeService cmsTypeService;
|
||||
|
||||
@Autowired
|
||||
private SysPermissionService permissionService;
|
||||
|
||||
/**
|
||||
* 查询分类管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:type:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(CmsType cmsType)
|
||||
{
|
||||
startPage();
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
|
||||
if (!SecurityUtils.isAdmin(getUserId())&&!roles.contains("admin")&&!roles.contains("cms")){
|
||||
cmsType.setCreateBy(getUsername());
|
||||
}
|
||||
List<CmsType> list = cmsTypeService.selectCmsTypeList(cmsType);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出分类管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:type:export')")
|
||||
@Log(title = "分类管理", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, CmsType cmsType)
|
||||
{
|
||||
List<CmsType> list = cmsTypeService.selectCmsTypeList(cmsType);
|
||||
ExcelUtil<CmsType> util = new ExcelUtil<CmsType>(CmsType.class);
|
||||
util.exportExcel(response, list, "分类管理数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类管理详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:type:query')")
|
||||
@GetMapping(value = "/{typeId}")
|
||||
public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
|
||||
{
|
||||
return AjaxResult.success(cmsTypeService.selectCmsTypeByTypeId(typeId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增分类管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:type:add')")
|
||||
@Log(title = "分类管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody CmsType cmsType)
|
||||
{
|
||||
cmsType.setCreateBy(getUsername());
|
||||
return toAjax(cmsTypeService.insertCmsType(cmsType));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分类管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:type:edit')")
|
||||
@Log(title = "分类管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody CmsType cmsType)
|
||||
{
|
||||
cmsType.setUpdateBy(getUsername());
|
||||
return toAjax(cmsTypeService.updateCmsType(cmsType));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:type:remove')")
|
||||
@Log(title = "分类管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{typeIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] typeIds)
|
||||
{
|
||||
return toAjax(cmsTypeService.deleteCmsTypeByTypeIds(typeIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消按钮-删除分类图片
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('cms:type:edit')")
|
||||
@PostMapping("/cancel")
|
||||
public AjaxResult cancel(@RequestBody CmsType cmsType)
|
||||
{
|
||||
return toAjax(cmsTypeService.cancel(cmsType));
|
||||
}
|
||||
|
||||
}
|
||||
109
ruoyi-cms/src/main/java/com/ruoyi/cms/type/domain/CmsType.java
Normal file
109
ruoyi-cms/src/main/java/com/ruoyi/cms/type/domain/CmsType.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package com.ruoyi.cms.type.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 分类管理对象 cms_type
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-02
|
||||
*/
|
||||
public class CmsType extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 分类ID */
|
||||
private Long typeId;
|
||||
|
||||
/** 分类名称 */
|
||||
@Excel(name = "分类名称")
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 分类图像类型(0地址 1上传)
|
||||
*/
|
||||
@Excel(name = "分类图像类型(0地址 1上传)", readConverterExp = "0=地址,1=上传")
|
||||
private String typePicType;
|
||||
|
||||
/** 分类图像( 1上传) */
|
||||
@Excel(name = "分类图像( 1上传)")
|
||||
private String typePic;
|
||||
|
||||
/** 分类图像( 0地址) */
|
||||
@Excel(name = "分类图像( 0地址)")
|
||||
private String typePicLink;
|
||||
|
||||
/** 博客数量 */
|
||||
private int blogNum;
|
||||
|
||||
public void setTypeId(Long typeId)
|
||||
{
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public Long getTypeId()
|
||||
{
|
||||
return typeId;
|
||||
}
|
||||
public void setTypeName(String typeName)
|
||||
{
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
public String getTypeName()
|
||||
{
|
||||
return typeName;
|
||||
}
|
||||
public void setTypePic(String typePic)
|
||||
{
|
||||
this.typePic = typePic;
|
||||
}
|
||||
|
||||
public String getTypePic()
|
||||
{
|
||||
return typePic;
|
||||
}
|
||||
|
||||
public int getBlogNum() {
|
||||
return blogNum;
|
||||
}
|
||||
|
||||
public void setBlogNum(int blogNum) {
|
||||
this.blogNum = blogNum;
|
||||
}
|
||||
|
||||
public String getTypePicType() {
|
||||
return typePicType;
|
||||
}
|
||||
|
||||
public void setTypePicType(String typePicType) {
|
||||
this.typePicType = typePicType;
|
||||
}
|
||||
|
||||
public String getTypePicLink() {
|
||||
return typePicLink;
|
||||
}
|
||||
|
||||
public void setTypePicLink(String typePicLink) {
|
||||
this.typePicLink = typePicLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("typeId", getTypeId())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("typeName", getTypeName())
|
||||
.append("typePic", getTypePic())
|
||||
.append("typePicType", getTypePicType())
|
||||
.append("typePicLink", getTypePicLink())
|
||||
.append("blogNum", getBlogNum())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.ruoyi.cms.type.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.cms.tag.domain.CmsTag;
|
||||
import com.ruoyi.cms.type.domain.CmsType;
|
||||
|
||||
/**
|
||||
* 分类管理Mapper接口
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-02
|
||||
*/
|
||||
public interface CmsTypeMapper
|
||||
{
|
||||
/**
|
||||
* 查询分类管理
|
||||
*
|
||||
* @param typeId 分类管理主键
|
||||
* @return 分类管理
|
||||
*/
|
||||
public CmsType selectCmsTypeByTypeId(Long typeId);
|
||||
|
||||
/**
|
||||
* 查询分类管理列表
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 分类管理集合
|
||||
*/
|
||||
public List<CmsType> selectCmsTypeList(CmsType cmsType);
|
||||
|
||||
/**
|
||||
* 通过typeName查询标签管理列表
|
||||
*
|
||||
* @param typeName
|
||||
* @return 标签管理集合
|
||||
*/
|
||||
public List<CmsType> selectCmsTypeListByTypeName(String typeName);
|
||||
|
||||
/**
|
||||
* 新增分类管理
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCmsType(CmsType cmsType);
|
||||
|
||||
/**
|
||||
* 修改分类管理
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsType(CmsType cmsType);
|
||||
|
||||
/**
|
||||
* 删除分类管理
|
||||
*
|
||||
* @param typeId 分类管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsTypeByTypeId(Long typeId);
|
||||
|
||||
/**
|
||||
* 批量删除分类管理
|
||||
*
|
||||
* @param typeIds 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsTypeByTypeIds(Long[] typeIds);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.ruoyi.cms.type.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.cms.type.domain.CmsType;
|
||||
|
||||
/**
|
||||
* 分类管理Service接口
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-02
|
||||
*/
|
||||
public interface ICmsTypeService
|
||||
{
|
||||
/**
|
||||
* 查询分类管理
|
||||
*
|
||||
* @param typeId 分类管理主键
|
||||
* @return 分类管理
|
||||
*/
|
||||
public CmsType selectCmsTypeByTypeId(Long typeId);
|
||||
|
||||
/**
|
||||
* 查询分类管理列表
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 分类管理集合
|
||||
*/
|
||||
public List<CmsType> selectCmsTypeList(CmsType cmsType);
|
||||
|
||||
/**
|
||||
* 新增分类管理
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCmsType(CmsType cmsType);
|
||||
|
||||
/**
|
||||
* 修改分类管理
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsType(CmsType cmsType);
|
||||
|
||||
/**
|
||||
* 批量删除分类管理
|
||||
*
|
||||
* @param typeIds 需要删除的分类管理主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsTypeByTypeIds(Long[] typeIds);
|
||||
|
||||
/**
|
||||
* 删除分类管理信息
|
||||
*
|
||||
* @param typeId 分类管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsTypeByTypeId(Long typeId);
|
||||
|
||||
/**
|
||||
* 取消按钮-删除分类图片
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int cancel(CmsType cmsType);
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package com.ruoyi.cms.type.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.cms.blog.mapper.CmsBlogTypeMapper;
|
||||
import com.ruoyi.cms.fileInfo.service.ISysFileInfoService;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.cms.type.mapper.CmsTypeMapper;
|
||||
import com.ruoyi.cms.type.domain.CmsType;
|
||||
import com.ruoyi.cms.type.service.ICmsTypeService;
|
||||
|
||||
/**
|
||||
* 分类管理Service业务层处理
|
||||
*
|
||||
* @author ning
|
||||
* @date 2022-01-02
|
||||
*/
|
||||
@Service
|
||||
public class CmsTypeServiceImpl implements ICmsTypeService
|
||||
{
|
||||
@Autowired
|
||||
private CmsTypeMapper cmsTypeMapper;
|
||||
|
||||
@Autowired
|
||||
private ISysFileInfoService sysFileInfoService;
|
||||
|
||||
@Autowired
|
||||
private CmsBlogTypeMapper cmsBlogTypeMapper;
|
||||
|
||||
/**
|
||||
* 查询分类管理
|
||||
*
|
||||
* @param typeId 分类管理主键
|
||||
* @return 分类管理
|
||||
*/
|
||||
@Override
|
||||
public CmsType selectCmsTypeByTypeId(Long typeId)
|
||||
{
|
||||
return cmsTypeMapper.selectCmsTypeByTypeId(typeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分类管理列表
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 分类管理
|
||||
*/
|
||||
@Override
|
||||
public List<CmsType> selectCmsTypeList(CmsType cmsType)
|
||||
{
|
||||
List<CmsType> cmsTypeList = cmsTypeMapper.selectCmsTypeList(cmsType);
|
||||
for (CmsType type : cmsTypeList) {
|
||||
int blogNum = cmsBlogTypeMapper.countBlogByTypeId(type.getTypeId());
|
||||
type.setBlogNum(blogNum);
|
||||
}
|
||||
return cmsTypeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增分类管理
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertCmsType(CmsType cmsType)
|
||||
{
|
||||
List<CmsType> cmsTypeList = cmsTypeMapper.selectCmsTypeListByTypeName(cmsType.getTypeName());
|
||||
if (cmsTypeList.size()>0){
|
||||
throw new ServiceException("分类名称已存在");
|
||||
}
|
||||
cmsType.setCreateTime(DateUtils.getNowDate());
|
||||
return cmsTypeMapper.insertCmsType(cmsType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分类管理
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateCmsType(CmsType cmsType)
|
||||
{
|
||||
List<CmsType> cmsTypeList = cmsTypeMapper.selectCmsTypeListByTypeName(cmsType.getTypeName());
|
||||
if (cmsTypeList.size()>0){
|
||||
for (CmsType type : cmsTypeList) {
|
||||
if (!type.getTypeId().equals(cmsType.getTypeId())){
|
||||
throw new ServiceException("分类名称已存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
String typePic = cmsTypeMapper.selectCmsTypeByTypeId(cmsType.getTypeId()).getTypePic();
|
||||
if (typePic!=null&&!"".equals(typePic)&&!typePic.equals(cmsType.getTypePic())){
|
||||
int newFileNameSeparatorIndex = typePic.lastIndexOf("/");
|
||||
String FileName = typePic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
|
||||
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
|
||||
}
|
||||
cmsType.setUpdateTime(DateUtils.getNowDate());
|
||||
return cmsTypeMapper.updateCmsType(cmsType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除分类管理
|
||||
*
|
||||
* @param typeIds 需要删除的分类管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCmsTypeByTypeIds(Long[] typeIds)
|
||||
{
|
||||
for (Long typeId : typeIds) {
|
||||
String typePic = cmsTypeMapper.selectCmsTypeByTypeId(typeId).getTypePic();
|
||||
if (typePic!=null&&!"".equals(typePic)){
|
||||
int newFileNameSeparatorIndex = typePic.lastIndexOf("/");
|
||||
String FileName = typePic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
|
||||
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
|
||||
}
|
||||
//删除分类文章关联表信息
|
||||
cmsBlogTypeMapper.deleteBlogTypeByTypeId(typeId);
|
||||
}
|
||||
return cmsTypeMapper.deleteCmsTypeByTypeIds(typeIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类管理信息
|
||||
*
|
||||
* @param typeId 分类管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCmsTypeByTypeId(Long typeId)
|
||||
{
|
||||
String typePic = cmsTypeMapper.selectCmsTypeByTypeId(typeId).getTypePic();
|
||||
if (typePic!=null&&!"".equals(typePic)){
|
||||
int newFileNameSeparatorIndex = typePic.lastIndexOf("/");
|
||||
String FileName = typePic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
|
||||
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
|
||||
}
|
||||
//删除分类文章关联表信息
|
||||
cmsBlogTypeMapper.deleteBlogTypeByTypeId(typeId);
|
||||
return cmsTypeMapper.deleteCmsTypeByTypeId(typeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消按钮-删除分类图片
|
||||
*
|
||||
* @param cmsType 分类管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int cancel(CmsType cmsType) {
|
||||
String typePic = cmsType.getTypePic();
|
||||
if (typePic!=null&&!"".equals(typePic)){
|
||||
Long typeId = cmsType.getTypeId();
|
||||
if (typeId==null){
|
||||
int newFileNameSeparatorIndex = typePic.lastIndexOf("/");
|
||||
String FileName = typePic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
|
||||
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
|
||||
}else {
|
||||
String Pic = cmsTypeMapper.selectCmsTypeByTypeId(typeId).getTypePic();
|
||||
if (!typePic.equals(Pic)){
|
||||
int newFileNameSeparatorIndex = typePic.lastIndexOf("/");
|
||||
String FileName = typePic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
|
||||
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
163
ruoyi-cms/src/main/java/com/ruoyi/cms/utils/ListSortUtils.java
Normal file
163
ruoyi-cms/src/main/java/com/ruoyi/cms/utils/ListSortUtils.java
Normal file
@@ -0,0 +1,163 @@
|
||||
package com.ruoyi.cms.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @program: RuoYi-Vue
|
||||
* @Author: WangNing
|
||||
* @Description: 〈list多属性排序〉
|
||||
* @Date: 2022/1/20 10:25
|
||||
*/
|
||||
public class ListSortUtils {
|
||||
/**
|
||||
* 对list的元素按照多个属性名称排序,
|
||||
* list元素的属性可以是数字(byte、short、int、long、float、double等,支持正数、负数、0)、char、String、java.util.Date
|
||||
*
|
||||
*
|
||||
* list元素的属性名称
|
||||
* @param isAsc
|
||||
* true升序,false降序
|
||||
*/
|
||||
public static <E> void sort(List<E> list, final boolean isAsc, final String... sortnameArr) {
|
||||
Collections.sort(list, new Comparator<E>() {
|
||||
|
||||
@Override
|
||||
public int compare(E a, E b) {
|
||||
|
||||
int ret = 0;
|
||||
try {
|
||||
for (int i = 0; i < sortnameArr.length; i++) {
|
||||
ret = ListSortUtils.compareObject(sortnameArr[i], isAsc, a, b);
|
||||
if (0 != ret) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 给list的每个属性都指定是升序还是降序
|
||||
*
|
||||
* @param list
|
||||
* @param sortnameArr 参数数组
|
||||
* @param typeArr 每个属性对应的升降序数组, true升序,false降序
|
||||
*/
|
||||
|
||||
public static <E> void sort(List<E> list, final String[] sortnameArr, final boolean[] typeArr) {
|
||||
if (sortnameArr.length != typeArr.length) {
|
||||
throw new RuntimeException("属性数组元素个数和升降序数组元素个数不相等");
|
||||
}
|
||||
Collections.sort(list, new Comparator<E>() {
|
||||
@Override
|
||||
public int compare(E a, E b) {
|
||||
int ret = 0;
|
||||
try {
|
||||
for (int i = 0; i < sortnameArr.length; i++) {
|
||||
ret = ListSortUtils.compareObject(sortnameArr[i], typeArr[i], a, b);
|
||||
if (0 != ret) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 对2个对象按照指定属性名称进行排序
|
||||
*
|
||||
* @param sortname
|
||||
* 属性名称
|
||||
* @param isAsc
|
||||
* true升序,false降序
|
||||
* @param a
|
||||
* @param b
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static <E> int compareObject(final String sortname, final boolean isAsc, E a, E b) throws Exception {
|
||||
int ret;
|
||||
Object value1 = ListSortUtils.forceGetFieldValue(a, sortname);
|
||||
Object value2 = ListSortUtils.forceGetFieldValue(b, sortname);
|
||||
String str1 = value1.toString();
|
||||
String str2 = value2.toString();
|
||||
if (value1 instanceof Number && value2 instanceof Number) {
|
||||
int maxlen = Math.max(str1.length(), str2.length());
|
||||
str1 = ListSortUtils.addZero2Str((Number) value1, maxlen);
|
||||
str2 = ListSortUtils.addZero2Str((Number) value2, maxlen);
|
||||
} else if (value1 instanceof Date && value2 instanceof Date) {
|
||||
long time1 = ((Date) value1).getTime();
|
||||
long time2 = ((Date) value2).getTime();
|
||||
int maxlen = Long.toString(Math.max(time1, time2)).length();
|
||||
str1 = ListSortUtils.addZero2Str(time1, maxlen);
|
||||
str2 = ListSortUtils.addZero2Str(time2, maxlen);
|
||||
}
|
||||
if (isAsc) {
|
||||
ret = str1.compareTo(str2);
|
||||
} else {
|
||||
ret = str2.compareTo(str1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给数字对象按照指定长度在左侧补0.
|
||||
*
|
||||
* 使用案例: addZero2Str(11,4) 返回 "0011", addZero2Str(-18,6)返回 "-000018"
|
||||
*
|
||||
* @param numObj
|
||||
* 数字对象
|
||||
* @param length
|
||||
* 指定的长度
|
||||
* @return
|
||||
*/
|
||||
public static String addZero2Str(Number numObj, int length) {
|
||||
NumberFormat nf = NumberFormat.getInstance();
|
||||
// 设置是否使用分组
|
||||
nf.setGroupingUsed(false);
|
||||
// 设置最大整数位数
|
||||
nf.setMaximumIntegerDigits(length);
|
||||
// 设置最小整数位数
|
||||
nf.setMinimumIntegerDigits(length);
|
||||
return nf.format(numObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定对象的指定属性值(去除private,protected的限制)
|
||||
*
|
||||
* @param obj
|
||||
* 属性名称所在的对象
|
||||
* @param fieldName
|
||||
* 属性名称
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Object forceGetFieldValue(Object obj, String fieldName) throws Exception {
|
||||
Field field = obj.getClass().getField(fieldName);
|
||||
Object object = null;
|
||||
boolean accessible = field.isAccessible();
|
||||
if (!accessible) {
|
||||
// 如果是private,protected修饰的属性,需要修改为可以访问的
|
||||
field.setAccessible(true);
|
||||
object = field.get(obj);
|
||||
// 还原private,protected属性的访问性质
|
||||
field.setAccessible(accessible);
|
||||
return object;
|
||||
}
|
||||
object = field.get(obj);
|
||||
return object;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user