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

帖子管理代码提交

上级 2ad38adf
...@@ -5,6 +5,7 @@ import com.platform.service.PostService; ...@@ -5,6 +5,7 @@ import com.platform.service.PostService;
import com.platform.utils.PageUtils; import com.platform.utils.PageUtils;
import com.platform.utils.Query; import com.platform.utils.Query;
import com.platform.utils.R; import com.platform.utils.R;
import com.platform.vo.PostVo;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
...@@ -39,7 +40,7 @@ public class PostController { ...@@ -39,7 +40,7 @@ public class PostController {
//查询列表数据 //查询列表数据
Query query = new Query(params); Query query = new Query(params);
List<PostEntity> postList = postService.queryList(query); List<PostVo> postList = postService.queryList(query);
int total = postService.queryTotal(query); int total = postService.queryTotal(query);
PageUtils pageUtil = new PageUtils(postList, total, query.getLimit(), query.getPage()); PageUtils pageUtil = new PageUtils(postList, total, query.getLimit(), query.getPage());
...@@ -53,7 +54,7 @@ public class PostController { ...@@ -53,7 +54,7 @@ public class PostController {
@RequestMapping("/info/{id}") @RequestMapping("/info/{id}")
@RequiresPermissions("post:info") @RequiresPermissions("post:info")
@ResponseBody @ResponseBody
public R info(@PathVariable("id") Long id) { public R info(@PathVariable("id") String id) {
PostEntity post = postService.queryObject(id); PostEntity post = postService.queryObject(id);
return R.ok().put("post", post); return R.ok().put("post", post);
...@@ -89,7 +90,7 @@ public class PostController { ...@@ -89,7 +90,7 @@ public class PostController {
@RequestMapping("/delete") @RequestMapping("/delete")
@RequiresPermissions("post:delete") @RequiresPermissions("post:delete")
@ResponseBody @ResponseBody
public R delete(@RequestBody Long[] ids) { public R delete(@RequestBody String[] ids) {
postService.deleteBatch(ids); postService.deleteBatch(ids);
return R.ok(); return R.ok();
...@@ -102,7 +103,7 @@ public class PostController { ...@@ -102,7 +103,7 @@ public class PostController {
@ResponseBody @ResponseBody
public R queryAll(@RequestParam Map<String, Object> params) { public R queryAll(@RequestParam Map<String, Object> params) {
List<PostEntity> list = postService.queryList(params); List<PostVo> list = postService.queryList(params);
return R.ok().put("list", list); return R.ok().put("list", list);
} }
......
...@@ -10,4 +10,5 @@ import com.platform.entity.PostEntity; ...@@ -10,4 +10,5 @@ import com.platform.entity.PostEntity;
*/ */
public interface PostDao extends BaseDao<PostEntity> { public interface PostDao extends BaseDao<PostEntity> {
int changePostStatus(String ids[]);
} }
package com.platform.service; package com.platform.service;
import com.platform.entity.PostEntity; import com.platform.entity.PostEntity;
import com.platform.vo.PostVo;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -19,7 +20,7 @@ public interface PostService { ...@@ -19,7 +20,7 @@ public interface PostService {
* @param id 主键 * @param id 主键
* @return 实体 * @return 实体
*/ */
PostEntity queryObject(Long id); PostEntity queryObject(String id);
/** /**
* 分页查询 * 分页查询
...@@ -27,7 +28,7 @@ public interface PostService { ...@@ -27,7 +28,7 @@ public interface PostService {
* @param map 参数 * @param map 参数
* @return list * @return list
*/ */
List<PostEntity> queryList(Map<String, Object> map); List<PostVo> queryList(Map<String, Object> map);
/** /**
* 分页统计总数 * 分页统计总数
...@@ -59,7 +60,7 @@ public interface PostService { ...@@ -59,7 +60,7 @@ public interface PostService {
* @param id * @param id
* @return 删除条数 * @return 删除条数
*/ */
int delete(Long id); int delete(String id);
/** /**
* 根据主键批量删除 * 根据主键批量删除
...@@ -67,5 +68,5 @@ public interface PostService { ...@@ -67,5 +68,5 @@ public interface PostService {
* @param ids * @param ids
* @return 删除条数 * @return 删除条数
*/ */
int deleteBatch(Long[] ids); int deleteBatch(String[] ids);
} }
...@@ -9,6 +9,8 @@ import com.platform.entity.TbCfUserInfoEntity; ...@@ -9,6 +9,8 @@ import com.platform.entity.TbCfUserInfoEntity;
import com.platform.service.PostService; import com.platform.service.PostService;
import com.platform.utils.IdUtil; import com.platform.utils.IdUtil;
import com.platform.utils.ShiroUtils; import com.platform.utils.ShiroUtils;
import com.platform.vo.PostVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -27,6 +29,7 @@ import static com.platform.utils.ShiroUtils.getUserId; ...@@ -27,6 +29,7 @@ import static com.platform.utils.ShiroUtils.getUserId;
* @author lipengjun * @author lipengjun
* @date 2020-06-17 11:02:21 * @date 2020-06-17 11:02:21
*/ */
@Slf4j
@Service("postService") @Service("postService")
public class PostServiceImpl implements PostService { public class PostServiceImpl implements PostService {
@Autowired @Autowired
...@@ -39,25 +42,27 @@ public class PostServiceImpl implements PostService { ...@@ -39,25 +42,27 @@ public class PostServiceImpl implements PostService {
private SysUserDao sysUserDao; private SysUserDao sysUserDao;
@Override @Override
public PostEntity queryObject(Long id) { public PostEntity queryObject(String id) {
return postDao.queryObject(id); return postDao.queryObject(id);
} }
@Override @Override
public List<PostEntity> queryList(Map<String, Object> map) { public List<PostVo> queryList(Map<String, Object> map) {
List<PostEntity> list = new ArrayList<>(); List<PostVo> list = new ArrayList<>();
List<PostEntity> postList = postDao.queryList(map); List<PostEntity> postList = postDao.queryList(map);
postList.forEach(post -> { postList.forEach(post -> {
String userType = post.getUserType().toString(); String userType = post.getUserType().toString();
PostEntity postEntity = new PostEntity(); PostVo postEntity = new PostVo();
BeanUtils.copyProperties(post, postEntity); BeanUtils.copyProperties(post, postEntity);
//系统用户 //系统用户
if ("0".equals(userType)) { if ("0".equals(userType)) {
SysUserEntity user = sysUserDao.queryObject(post.getUserId()); SysUserEntity user = sysUserDao.queryObject(post.getUserId());
if (user != null)
postEntity.setCreatedBy(user.getUserName()); postEntity.setCreatedBy(user.getUserName());
//app用户 //app用户
} else if ("1".equals(userType)) { } else if ("1".equals(userType)) {
TbCfUserInfoEntity user = tbCfUserInfoDao.queryObject(post.getUserId()); TbCfUserInfoEntity user = tbCfUserInfoDao.queryObject(post.getUserId());
if (user != null)
postEntity.setCreatedBy(user.getNick()); postEntity.setCreatedBy(user.getNick());
} }
list.add(postEntity); list.add(postEntity);
...@@ -83,33 +88,51 @@ public class PostServiceImpl implements PostService { ...@@ -83,33 +88,51 @@ public class PostServiceImpl implements PostService {
String type = String.valueOf(post.getUserType()); String type = String.valueOf(post.getUserType());
if ("0".equals(type)) { if ("0".equals(type)) {
post.setUserId(getUserId()); post.setUserId(getUserId());
} } else if ("1".equals(type)) {
if ("1".equals(type)) {
String userId = tbCfUserInfoDao.queryById(post.getCreatedBy()); String userId = tbCfUserInfoDao.queryById(post.getCreatedBy());
post.setUserId(userId); post.setUserId(userId);
} }
post.setCategory(URLDecoder.decode(post.getCategory(), "utf-8")); post.setCategory(URLDecoder.decode(post.getCategory(), "utf-8"));
res = postDao.save(post); res = postDao.save(post);
} catch (Exception e) { } catch (Exception e) {
log.info(e.getMessage());
} }
return res; return res;
} }
@Override @Override
public int update(PostEntity post) { public int update(PostEntity post) {
int res = 0;
try {
String type = String.valueOf(post.getUserType());
if ("0".equals(type)) {
post.setUpdatedBy(ShiroUtils.getUserId());
}
post.setVersion(post.getVersion() + 1);
post.setUpdateDate(new Date()); post.setUpdateDate(new Date());
post.setUpdatedBy(ShiroUtils.getUserId()); post.setUpdatedBy(ShiroUtils.getUserId());
return postDao.update(post); post.setCategory(URLDecoder.decode(post.getCategory(), "utf-8"));
res = postDao.update(post);
} catch (Exception e) {
log.info(e.getMessage());
}
return res;
} }
@Override @Override
public int delete(Long id) { public int delete(String id) {
return postDao.delete(id); String[] ids = new String[]{id};
return postDao.changePostStatus(ids);
} }
/**
* 逻辑删除
*
* @param ids
* @return
*/
@Override @Override
public int deleteBatch(Long[] ids) { public int deleteBatch(String[] ids) {
return postDao.deleteBatch(ids); return postDao.changePostStatus(ids);
} }
} }
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
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 ) 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 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 WHERE 1=1
and p.archived!=0
<if test="name != null and name.trim() != ''"> <if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%') AND name LIKE concat('%',#{name},'%')
</if> </if>
...@@ -71,7 +72,7 @@ ...@@ -71,7 +72,7 @@
order by ${sidx} ${order} order by ${sidx} ${order}
</when> </when>
<otherwise> <otherwise>
order by create_time desc order by createDate desc
</otherwise> </otherwise>
</choose> </choose>
<if test="offset != null and limit != null"> <if test="offset != null and limit != null">
...@@ -163,4 +164,10 @@ ...@@ -163,4 +164,10 @@
</foreach> </foreach>
</delete> </delete>
<update id="changePostStatus">
update post set archived=0 where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -72,7 +72,7 @@ let vm = new Vue({ ...@@ -72,7 +72,7 @@ let vm = new Vue({
queryAccount: function () { queryAccount: function () {
let flag = vm.flag; let flag = vm.flag;
let url = '../tbcfuserinfo/queryByAccount?account=' + this.post.createdBy; let url = '../tbcfuserinfo/queryByAccount?account=' + this.post.createdBy;
console.log(123456,this.post.createBy) console.log(123456, this.post.createBy)
Ajax.request({ Ajax.request({
url: url, url: url,
type: "GET", type: "GET",
...@@ -139,6 +139,7 @@ let vm = new Vue({ ...@@ -139,6 +139,7 @@ let vm = new Vue({
vm.showList = false; vm.showList = false;
vm.title = "新增"; vm.title = "新增";
vm.post = {}; vm.post = {};
UE.getEditor('content').setContent('');
}, },
update: function (event) { update: function (event) {
let id = getSelectedRow("#jqGrid"); let id = getSelectedRow("#jqGrid");
...@@ -152,7 +153,7 @@ let vm = new Vue({ ...@@ -152,7 +153,7 @@ let vm = new Vue({
}, },
saveOrUpdate: function (event) { saveOrUpdate: function (event) {
let flag = vm.flag; let flag = vm.flag;
console.log(121323,vm.post.userType) console.log(121323, vm.post.userType)
if (vm.post.userType === 1 && vm.post.id == null) { if (vm.post.userType === 1 && vm.post.id == null) {
flag = this.queryAccount(); flag = this.queryAccount();
} }
...@@ -207,7 +208,28 @@ let vm = new Vue({ ...@@ -207,7 +208,28 @@ let vm = new Vue({
url: "../post/info/" + id, url: "../post/info/" + id,
async: true, async: true,
successCallback: function (r) { successCallback: function (r) {
vm.disabled = true
vm.post = r.post; vm.post = r.post;
vm.isShow = false;
vm.uploadList = [];
let status = vm.post.archived
//正常
if (status === 1) {
vm.isShow = true
} else if (status === 2) {
//下线
vm.isShow = false;
}
let content = vm.post.category;
let picture = vm.post.picture;
if (picture != null && picture != '') {
vm.uploadList = vm.post.picture.split(',');
}
if (content != null) {
UE.getEditor('content').setContent(content);
} else {
UE.getEditor('content').setContent('');
}
} }
}); });
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论