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

帖子管理代码提交

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