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

帖子管理代码提交

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