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

帖子管理代码提交

上级 fab8a6ae
......@@ -87,11 +87,12 @@ public class PostController {
/**
* 删除
*/
@RequestMapping("/delete")
@RequestMapping("/changeStatus")
@RequiresPermissions("post:delete")
@ResponseBody
public R delete(@RequestBody String[] ids) {
postService.deleteBatch(ids);
public R changeStatus(@RequestParam("archived") Integer archived, @RequestBody String[] ids) {
postService.changeStatus(archived, ids);
return R.ok();
}
......@@ -107,4 +108,18 @@ public class PostController {
return R.ok().put("list", list);
}
/**
* 置顶 or 取消置顶
*/
@RequestMapping("/placedPostTop/{id}")
@ResponseBody
public R placedPostTop(@PathVariable("id") String id) {
postService.placedPostTop(id);
return R.ok();
}
}
package com.platform.dao;
import com.platform.entity.PostEntity;
import org.apache.ibatis.annotations.Param;
/**
* Dao
......@@ -10,5 +11,7 @@ import com.platform.entity.PostEntity;
*/
public interface PostDao extends BaseDao<PostEntity> {
int changePostStatus(String ids[]);
int changePostStatus(@Param("archived")Integer archived,@Param("ids") String ids[]);
int placedTop(Integer id, Integer isTop);
}
......@@ -2,6 +2,7 @@ package com.platform.service;
import com.platform.entity.PostEntity;
import com.platform.vo.PostVo;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.List;
import java.util.Map;
......@@ -68,5 +69,7 @@ public interface PostService {
* @param ids
* @return 删除条数
*/
int deleteBatch(String[] ids);
int changeStatus(Integer archived,String[] ids);
int placedPostTop(String id);
}
......@@ -122,17 +122,33 @@ public class PostServiceImpl implements PostService {
@Override
public int delete(String id) {
String[] ids = new String[]{id};
return postDao.changePostStatus(ids);
return postDao.changePostStatus(0, ids);
}
/**
* 逻辑删除
* 修改状态
*
* @param ids
* @return
*/
@Override
public int deleteBatch(String[] ids) {
return postDao.changePostStatus(ids);
public int changeStatus(Integer archived, String[] ids) {
return postDao.changePostStatus(archived, ids);
}
/**
* 置顶 or 取消置顶
* 1)如果已置顶,则取消置顶
*
* @param id
* @return int
*/
@Override
public int placedPostTop(String id) {
//根据ID查询帖子信息
PostEntity post = postDao.queryObject(id);
Integer isTop = post.getIsTop();
post.setIsTop(isTop == 0 ? 1 : 0);
return postDao.update(post);
}
}
......@@ -42,6 +42,10 @@
where id = #{id}
</select>
<update id="placedTop" parameterType="com.platform.entity.PostEntity">
update post set is_top=#{isTop} where id=#{id}
</update>
<select id="queryList" resultType="com.platform.vo.PostVo">
SELECT
p.*,
......@@ -72,7 +76,7 @@
order by ${sidx} ${order}
</when>
<otherwise>
order by createDate desc
order by is_top desc ,create_date desc
</otherwise>
</choose>
<if test="offset != null and limit != null">
......@@ -165,8 +169,8 @@
</delete>
<update id="changePostStatus">
update post set archived=0 where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
update post set archived=#{archived} where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</update>
......
......@@ -35,9 +35,9 @@ $(function () {
{label: '创建时间', name: 'createDate', index: 'create_date', width: 80},
{
label: '操作', index: 'operate', width: 80, formatter: function (value, grid, rows) {
return '<span class="label label-info pointer" onclick="vm.audit(' + rows.id + ')">审核</span>&nbsp;&nbsp;' +
'<span class="label label-warning pointer" onclick="vm.off(' + rows.id + ')" ">下线</span>&nbsp;&nbsp;' +
'<span class="label label-success pointer" onclick="vm.activate(' + rows.id + ')" ">激活</span>';
return '<span class="label label-info pointer" onclick="vm.audit(\'' + rows.id + '\')">审核</span>&nbsp;&nbsp;' +
'<span class="label label-warning pointer" onclick="vm.off(\'' + rows.id + '\')" ">下线</span>&nbsp;&nbsp;' +
'<span class="label label-success pointer" onclick="vm.activate(\'' + rows.id + '\')" ">激活</span>';
}
}]
});
......
......@@ -3,6 +3,7 @@ $(function () {
url: '../post/list',
colModel: [
{label: 'id', name: 'id', index: 'id', key: true, hidden: true},
{label: 'isTop', name: 'isTop', index: 'isTop', 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},
......@@ -20,7 +21,14 @@ $(function () {
{label: '作者', name: 'createdBy', index: 'created_by', width: 80},
{
label: '操作', index: 'operate', width: 80, formatter: function (value, grid, rows) {
return '<span class="label label-info pointer" onclick="vm.placedTop(' + rows.id + ')">置顶</span>';
if (rows.isTop === 1) {
return '<span class="label label-danger pointer" onclick="vm.placedTop(\'' + rows.id + '\')">置顶</span>&nbsp;&nbsp;' +
'<span class="label label-warning pointer" onclick="vm.off(\'' + rows.id + '\')" ">下线</span>&nbsp;&nbsp;' +
'<span class="label label-success pointer" onclick="vm.activate(\'' + rows.id + '\')" ">激活</span>';
}
return '<span class="label label-info pointer" onclick="vm.placedTop(\'' + rows.id + '\')">置顶</span>&nbsp;&nbsp;' +
'<span class="label label-warning pointer" onclick="vm.off(\'' + rows.id + '\')" ">下线</span>&nbsp;&nbsp;' +
'<span class="label label-success pointer" onclick="vm.activate(\'' + rows.id + '\')" ">激活</span>';
}
}
]
......@@ -61,6 +69,50 @@ let vm = new Vue({
}
},
methods: {
placedTop: function (id) {
let url = '../post/placedPostTop/' + id;
Ajax.request({
url: url,
type: "GET",
contentType: "application/json",
successCallback: function () {
alert('操作成功', function (index) {
vm.reload();
});
}
});
},
off: function (id) {
let ids = [id];
let url = '../post/changeStatus?archived=2';
Ajax.request({
url: url,
type: "POST",
params: JSON.stringify(ids),
contentType: "application/json",
successCallback: function () {
alert('操作成功', function (index) {
vm.reload();
});
}
});
},
activate: function (id) {
let ids = [id];
let url = '../post/changeStatus?archived=1';
Ajax.request({
url: url,
type: "POST",
params: JSON.stringify(ids),
contentType: "application/json",
successCallback: function () {
alert('操作成功', function (index) {
vm.reload();
});
}
});
},
changeType: function () {
let type = this.post.userType;
if (type === 0) {
......@@ -103,9 +155,7 @@ let vm = new Vue({
// 限制上传文件的宽高
// return this.checkImageWH(file,750,320);
},
placedTop: function () {
},
handleSuccess(response, file, fileList) {
// "http://diaosaas-prod.oss-cn-shenzhen.aliyuncs.com/education/155728894307110106.jpg"
vm.uploadList.push(response);
......@@ -190,7 +240,7 @@ let vm = new Vue({
confirm('确定要删除选中的记录?', function () {
Ajax.request({
url: "../post/delete",
url: "../post/changeStatus?archived=0",
params: JSON.stringify(ids),
type: "POST",
contentType: "application/json",
......@@ -204,15 +254,16 @@ let vm = new Vue({
}
,
getInfo: function (id) {
console.log(id);
Ajax.request({
url: "../post/info/" + id,
async: true,
successCallback: function (r) {
vm.disabled = true
// vm.disabled = true
vm.post = r.post;
vm.isShow = false;
vm.uploadList = [];
let status = vm.post.archived
let status = vm.post.archived;
//正常
if (status === 1) {
vm.isShow = true
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论