提交 47438e6f authored 作者: 吴德鹏's avatar 吴德鹏

帖子管理

上级 3389af47
......@@ -47,6 +47,12 @@
<artifactId>kaptcha</artifactId>
<version>${kaptcha.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
......
package com.platform.controller;
import com.platform.entity.PostEntity;
import com.platform.service.PostService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* Controller
*
* @author lipengjun
* @date 2020-06-17 11:02:21
*/
@Controller
@RequestMapping("post")
public class PostController {
@Autowired
private PostService postService;
/**
* 查看列表
*/
@RequestMapping("/list")
@RequiresPermissions("post:list")
@ResponseBody
public R list(@RequestParam Map<String, Object> params) {
//查询列表数据
Query query = new Query(params);
List<PostEntity> postList = postService.queryList(query);
int total = postService.queryTotal(query);
PageUtils pageUtil = new PageUtils(postList, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
/**
* 查看信息
*/
@RequestMapping("/info/{id}")
@RequiresPermissions("post:info")
@ResponseBody
public R info(@PathVariable("id") Long id) {
PostEntity post = postService.queryObject(id);
return R.ok().put("post", post);
}
/**
* 保存
*/
@RequestMapping("/save")
@RequiresPermissions("post:save")
@ResponseBody
public R save(@RequestBody PostEntity post) {
postService.save(post);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("post:update")
@ResponseBody
public R update(@RequestBody PostEntity post) {
postService.update(post);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("post:delete")
@ResponseBody
public R delete(@RequestBody Long[] ids) {
postService.deleteBatch(ids);
return R.ok();
}
/**
* 查看所有列表
*/
@RequestMapping("/queryAll")
@ResponseBody
public R queryAll(@RequestParam Map<String, Object> params) {
List<PostEntity> list = postService.queryList(params);
return R.ok().put("list", list);
}
}
package com.platform.dao;
import com.platform.entity.PostEntity;
/**
* Dao
*
* @author lipengjun
* @date 2020-06-17 11:02:21
*/
public interface PostDao extends BaseDao<PostEntity> {
}
package com.platform.entity;
import java.io.Serializable;
import java.util.Date;
/**
* 实体
* 表名 post
*
* @author lipengjun
* @date 2020-06-17 11:02:21
*/
public class PostEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
private Long id;
/**
*
*/
private String archived;
/**
*
*/
private String archivedBy;
/**
*
*/
private Date archivedDate;
/**
*
*/
private Date createDate;
/**
*
*/
private String createdBy;
/**
*
*/
private Date updateDate;
/**
*
*/
private String updatedBy;
/**
*
*/
private Integer version;
/**
*
*/
private String caption;
/**
*
*/
private String category;
/**
*
*/
private String userId;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
* 设置:
*/
public void setArchived(String archived) {
this.archived = archived;
}
/**
* 获取:
*/
public String getArchived() {
return archived;
}
/**
* 设置:
*/
public void setArchivedBy(String archivedBy) {
this.archivedBy = archivedBy;
}
/**
* 获取:
*/
public String getArchivedBy() {
return archivedBy;
}
/**
* 设置:
*/
public void setArchivedDate(Date archivedDate) {
this.archivedDate = archivedDate;
}
/**
* 获取:
*/
public Date getArchivedDate() {
return archivedDate;
}
/**
* 设置:
*/
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
/**
* 获取:
*/
public Date getCreateDate() {
return createDate;
}
/**
* 设置:
*/
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
/**
* 获取:
*/
public String getCreatedBy() {
return createdBy;
}
/**
* 设置:
*/
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
/**
* 获取:
*/
public Date getUpdateDate() {
return updateDate;
}
/**
* 设置:
*/
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
/**
* 获取:
*/
public String getUpdatedBy() {
return updatedBy;
}
/**
* 设置:
*/
public void setVersion(Integer version) {
this.version = version;
}
/**
* 获取:
*/
public Integer getVersion() {
return version;
}
/**
* 设置:
*/
public void setCaption(String caption) {
this.caption = caption;
}
/**
* 获取:
*/
public String getCaption() {
return caption;
}
/**
* 设置:
*/
public void setCategory(String category) {
this.category = category;
}
/**
* 获取:
*/
public String getCategory() {
return category;
}
}
package com.platform.entity;
import java.io.Serializable;
import java.util.Date;
/**
* 实体
* 表名 post_hashtag
*
* @author lipengjun
* @date 2020-06-18 10:28:56
*/
public class PostHashtagEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 帖子标签ID
*/
private Long id;
/**
* 0:已删除 1:正常
*/
private String archived;
/**
* 删除人
*/
private String archivedBy;
/**
* 删除时间
*/
private Date archivedDate;
/**
* 创建时间
*/
private Date createDate;
/**
* 创建人
*/
private String createdBy;
/**
* 更新时间
*/
private Date updateDate;
/**
* 更新人
*/
private String updatedBy;
/**
* 版本
*/
private Integer version;
/**
* 标签ID
*/
private Long hashtagId;
/**
* 帖子ID
*/
private Long postId;
/**
* 设置:帖子标签ID
*/
public void setId(Long id) {
this.id = id;
}
/**
* 获取:帖子标签ID
*/
public Long getId() {
return id;
}
/**
* 设置:0:已删除 1:正常
*/
public void setArchived(String archived) {
this.archived = archived;
}
/**
* 获取:0:已删除 1:正常
*/
public String getArchived() {
return archived;
}
/**
* 设置:删除人
*/
public void setArchivedBy(String archivedBy) {
this.archivedBy = archivedBy;
}
/**
* 获取:删除人
*/
public String getArchivedBy() {
return archivedBy;
}
/**
* 设置:删除时间
*/
public void setArchivedDate(Date archivedDate) {
this.archivedDate = archivedDate;
}
/**
* 获取:删除时间
*/
public Date getArchivedDate() {
return archivedDate;
}
/**
* 设置:创建时间
*/
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
/**
* 获取:创建时间
*/
public Date getCreateDate() {
return createDate;
}
/**
* 设置:创建人
*/
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
/**
* 获取:创建人
*/
public String getCreatedBy() {
return createdBy;
}
/**
* 设置:更新时间
*/
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
/**
* 获取:更新时间
*/
public Date getUpdateDate() {
return updateDate;
}
/**
* 设置:更新人
*/
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
/**
* 获取:更新人
*/
public String getUpdatedBy() {
return updatedBy;
}
/**
* 设置:版本
*/
public void setVersion(Integer version) {
this.version = version;
}
/**
* 获取:版本
*/
public Integer getVersion() {
return version;
}
/**
* 设置:标签ID
*/
public void setHashtagId(Long hashtagId) {
this.hashtagId = hashtagId;
}
/**
* 获取:标签ID
*/
public Long getHashtagId() {
return hashtagId;
}
/**
* 设置:帖子ID
*/
public void setPostId(Long postId) {
this.postId = postId;
}
/**
* 获取:帖子ID
*/
public Long getPostId() {
return postId;
}
}
package com.platform.service;
import com.platform.entity.PostEntity;
import java.util.List;
import java.util.Map;
/**
* Service接口
*
* @author lipengjun
* @date 2020-06-17 11:02:21
*/
public interface PostService {
/**
* 根据主键查询实体
*
* @param id 主键
* @return 实体
*/
PostEntity queryObject(Long id);
/**
* 分页查询
*
* @param map 参数
* @return list
*/
List<PostEntity> queryList(Map<String, Object> map);
/**
* 分页统计总数
*
* @param map 参数
* @return 总数
*/
int queryTotal(Map<String, Object> map);
/**
* 保存实体
*
* @param post 实体
* @return 保存条数
*/
int save(PostEntity post);
/**
* 根据主键更新实体
*
* @param post 实体
* @return 更新条数
*/
int update(PostEntity post);
/**
* 根据主键删除
*
* @param id
* @return 删除条数
*/
int delete(Long id);
/**
* 根据主键批量删除
*
* @param ids
* @return 删除条数
*/
int deleteBatch(Long[] ids);
}
package com.platform.service.impl;
import com.platform.dao.PostDao;
import com.platform.entity.PostEntity;
import com.platform.service.PostService;
import com.platform.utils.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* Service实现类
*
* @author lipengjun
* @date 2020-06-17 11:02:21
*/
@Service("postService")
public class PostServiceImpl implements PostService {
@Autowired
private PostDao postDao;
@Override
public PostEntity queryObject(Long id) {
return postDao.queryObject(id);
}
@Override
public List<PostEntity> queryList(Map<String, Object> map) {
return postDao.queryList(map);
}
@Override
public int queryTotal(Map<String, Object> map) {
return postDao.queryTotal(map);
}
@Override
public int save(PostEntity post) {
post.setId(Long.parseLong(IdUtil.createIdbyUUID()));
return postDao.save(post);
}
@Override
public int update(PostEntity post) {
return postDao.update(post);
}
@Override
public int delete(Long id) {
return postDao.delete(id);
}
@Override
public int deleteBatch(Long[] ids) {
return postDao.deleteBatch(ids);
}
}
package com.platform.vo;
import com.platform.entity.PostEntity;
import lombok.Data;
/**
* @Auther: wudepeng
* @Date: 2020/06/17
* @Description:
*/
public class PostVo extends PostEntity {
private Integer count;
private Integer likes;
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public Integer getLikes() {
return likes;
}
public void setLikes(Integer likes) {
this.likes = likes;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.dao.PostDao">
<resultMap type="com.platform.entity.PostEntity" id="postMap">
<result property="id" column="id"/>
<result property="archived" column="archived"/>
<result property="archivedBy" column="archived_by"/>
<result property="archivedDate" column="archived_date"/>
<result property="createDate" column="create_date"/>
<result property="createdBy" column="created_by"/>
<result property="updateDate" column="update_date"/>
<result property="updatedBy" column="updated_by"/>
<result property="version" column="version"/>
<result property="caption" column="caption"/>
<result property="category" column="category"/>
<result property="userId" column="user_id"/>
</resultMap>
<select id="queryObject" resultType="com.platform.entity.PostEntity">
select
`id`,
`archived`,
`archived_by`,
`archived_date`,
`create_date`,
`created_by`,
`update_date`,
`updated_by`,
`version`,
`caption`,
`category`,
`user_id`
from post
where id = #{id}
</select>
<select id="queryList" resultType="com.platform.vo.PostVo">
SELECT
p.*,
IFNULL(c.count,0) count ,
IFNULL(l.likes,0) likes
FROM
post p
LEFT JOIN ( SELECT count( 1 ) count, post_id FROM `comment` GROUP BY post_id ) c ON p.id = c.post_id
LEFT JOIN ( SELECT count( 1 ) likes, post_id FROM post_like GROUP BY post_id ) l ON p.id = l.post_id
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<if test="title != null and title.trim() != ''">
AND caption LIKE concat('%',#{title},'%')
</if>
<if test="author != null and author.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<if test="topic != null and topic.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<choose>
<when test="sidx != null and sidx.trim() != ''">
order by ${sidx} ${order}
</when>
<otherwise>
order by id desc
</otherwise>
</choose>
<if test="offset != null and limit != null">
limit #{offset}, #{limit}
</if>
</select>
<select id="queryTotal" resultType="int">
select count(*) from post
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<if test="title != null and title.trim() != ''">
AND caption LIKE concat('%',#{title},'%')
</if>
<if test="author != null and author.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<if test="topic != null and topic.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
</select>
<insert id="save" parameterType="com.platform.entity.PostEntity" useGeneratedKeys="true" keyProperty="id">
insert into post(
`archived`,
`archived_by`,
`archived_date`,
`create_date`,
`created_by`,
`update_date`,
`updated_by`,
`version`,
`caption`,
`category`,
`user_id`)
values(
#{archived},
#{archivedBy},
#{archivedDate},
#{createDate},
#{createdBy},
#{updateDate},
#{updatedBy},
#{version},
#{caption},
#{category},
#{userId})
</insert>
<update id="update" parameterType="com.platform.entity.PostEntity">
update post
<set>
<if test="archived != null">`archived` = #{archived},</if>
<if test="archivedBy != null">`archived_by` = #{archivedBy},</if>
<if test="archivedDate != null">`archived_date` = #{archivedDate},</if>
<if test="createDate != null">`create_date` = #{createDate},</if>
<if test="createdBy != null">`created_by` = #{createdBy},</if>
<if test="updateDate != null">`update_date` = #{updateDate},</if>
<if test="updatedBy != null">`updated_by` = #{updatedBy},</if>
<if test="version != null">`version` = #{version},</if>
<if test="caption != null">`caption` = #{caption},</if>
<if test="category != null">`category` = #{category},</if>
<if test="userId != null">`user_id` = #{userId}</if>
</set>
where id = #{id}
</update>
<delete id="delete">
delete from post where id = #{value}
</delete>
<delete id="deleteBatch">
delete from post where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title></title>
#parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak style="height: calc(100% - 15px);">
<div v-show="showList" style="height: 100%;">
<Row :gutter="16">
<div class="search-group">
<span>
标题:
<i-input v-model="q.title" @on-enter="query" placeholder="标题" style="width:160px">
</i-input>
</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
<span>
作者:
<i-input v-model="q.author" @on-enter="query" placeholder="作者" style="width:160px">
</i-input>
</span> &nbsp;&nbsp;&nbsp;&nbsp;
<span>
话题:
<i-input v-model="q.topic" @on-enter="query" placeholder="话题" style="width:160px">
</i-input>
</span>
<i-button @click="query">查询</i-button>
<i-button @click="reloadSearch">重置</i-button>
</div>
<div class="buttons-group">
#if($shiro.hasPermission("post:save"))
<i-button type="info" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</i-button>
#end
#if($shiro.hasPermission("post:update"))
<i-button type="warning" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</i-button>
#end
#if($shiro.hasPermission("post:delete"))
<i-button type="error" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</i-button>
#end
</div>
</Row>
<table id="jqGrid"></table>
</div>
<Card v-show="!showList">
<p slot="title">{{title}}</p>
<i-form ref="formValidate" :model="post" :rules="ruleValidate" :label-width="80">
<Form-item label="0:已删除 1:正常" prop="archived">
<i-input v-model="post.archived" placeholder="0:已删除 1:正常"/>
</Form-item>
<Form-item label="删除人" prop="archivedBy">
<i-input v-model="post.archivedBy" placeholder="删除人"/>
</Form-item>
<Form-item label="删除时间" prop="archivedDate">
<i-input v-model="post.archivedDate" placeholder="删除时间"/>
</Form-item>
<Form-item label="创建时间" prop="createDate">
<i-input v-model="post.createDate" placeholder="创建时间"/>
</Form-item>
<Form-item label="创建人" prop="createdBy">
<i-input v-model="post.createdBy" placeholder="创建人"/>
</Form-item>
<Form-item label="更新时间" prop="updateDate">
<i-input v-model="post.updateDate" placeholder="更新时间"/>
</Form-item>
<Form-item label="更新人" prop="updatedBy">
<i-input v-model="post.updatedBy" placeholder="更新人"/>
</Form-item>
<Form-item label="版本" prop="version">
<i-input v-model="post.version" placeholder="版本"/>
</Form-item>
<Form-item label="标题" prop="caption">
<i-input v-model="post.caption" placeholder="标题"/>
</Form-item>
<Form-item label="文章内容" prop="category">
<i-input v-model="post.category" placeholder="文章内容"/>
</Form-item>
<Form-item label="用户ID" prop="userId">
<i-input v-model="post.userId" placeholder="用户ID"/>
</Form-item>
<Form-item>
<i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
<i-button type="warning" @click="reload" style="margin-left: 8px"/>
返回</i-button>
<i-button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
</Form-item>
</i-form>
</Card>
</div>
<script src="${rc.contextPath}/js/sys/post.js?_${date.systemTime}"></script>
</body>
</html>
\ No newline at end of file
$(function () {
$("#jqGrid").Grid({
url: '../post/list',
colModel: [
{label: 'id', name: 'id', index: 'id', key: true, hidden: true},
{label: '标题', name: 'caption', index: 'caption', width: 80},
{label: '用户ID', name: 'userId', index: 'user_id', width: 80},
{label: '评论数量', name: 'count', index: 'count', width: 80},
{label: '点赞数量', name: 'likes', index: 'likes', width: 80},
{label: '状态', name: 'archived', index: 'archived', width: 80},
{label: '创建时间', name: 'createDate', index: 'create_date', width: 80},
{label: '作者', name: 'createdBy', index: 'created_by', width: 80},
{
label: '操作', index: 'operate', width: 80, formatter: function (value, grid, rows) {
return '<i-button class=\"ivu-btn ivu-btn-info\" style=\'border-radius:25px;\' type=\"info\" @click="placedTop">置顶</i-button>';
}
}
]
});
});
let vm = new Vue({
el: '#rrapp',
data: {
showList: true,
title: null,
post: {},
ruleValidate: {
name: [
{required: true, message: '名称不能为空', trigger: 'blur'}
]
},
q: {
name: '',
title: '',
author: '',
topic: ''
}
},
methods: {
placedTop: function () {
},
query: function () {
vm.reload();
},
add: function () {
vm.showList = false;
vm.title = "新增";
vm.post = {};
},
update: function (event) {
let id = getSelectedRow("#jqGrid");
if (id == null) {
return;
}
vm.showList = false;
vm.title = "修改";
vm.getInfo(id);
},
saveOrUpdate: function (event) {
let url = vm.post.id == null ? "../post/save" : "../post/update";
Ajax.request({
url: url,
params: JSON.stringify(vm.post),
type: "POST",
contentType: "application/json",
successCallback: function (r) {
alert('操作成功', function (index) {
vm.reload();
});
}
});
},
del: function (event) {
let ids = getSelectedRows("#jqGrid");
if (ids == null) {
return;
}
confirm('确定要删除选中的记录?', function () {
Ajax.request({
url: "../post/delete",
params: JSON.stringify(ids),
type: "POST",
contentType: "application/json",
successCallback: function () {
alert('操作成功', function (index) {
vm.reload();
});
}
});
});
},
getInfo: function (id) {
Ajax.request({
url: "../post/info/" + id,
async: true,
successCallback: function (r) {
vm.post = r.post;
}
});
},
reload: function (event) {
vm.showList = true;
let page = $("#jqGrid").jqGrid('getGridParam', 'page');
$("#jqGrid").jqGrid('setGridParam', {
postData: {
'name': vm.q.name,
'title': vm.q.title,
'author': vm.q.author,
'topic': vm.q.topic
},
page: page
}).trigger("reloadGrid");
vm.handleReset('formValidate');
},
reloadSearch: function () {
vm.q = {
name: '',
title: '',
author: '',
topic: ''
};
vm.reload();
},
handleSubmit: function (name) {
handleSubmitValidate(this, name, function () {
vm.saveOrUpdate()
});
},
handleReset: function (name) {
handleResetForm(this, name);
}
}
});
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论