|
@@ -1,10 +1,13 @@
|
|
|
package com.gis.cms.service.impl;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.gis.admin.entity.po.SysUserEntity;
|
|
|
import com.gis.cms.entity.dto.BbsDto;
|
|
|
+import com.gis.cms.entity.dto.BbsMessagePageDto;
|
|
|
import com.gis.cms.entity.dto.BbsPageDto;
|
|
|
import com.gis.cms.entity.dto.SortPageDto;
|
|
|
import com.gis.cms.entity.po.BbsEntity;
|
|
@@ -23,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -51,7 +55,8 @@ public class BbsServiceImpl extends ServiceImpl<BbsMapper, BbsEntity> implements
|
|
|
IPage<BbsEntity> page = new Page<>(param.getPageNum() , param.getPageSize());
|
|
|
|
|
|
StringBuffer sql = new StringBuffer();
|
|
|
- sql.append("SELECT a.*, COUNT(case when b.status=2 and b.is_delete=0 then 1 end) reply from tb_bbs a left join tb_bbs_message b on b.bbs_id=a.id where a.is_delete=0 ");
|
|
|
+// sql.append("SELECT a.*, COUNT(case when b.status=2 and b.is_delete=0 then 1 end) reply from tb_bbs a left join tb_bbs_message b on b.bbs_id=a.id where a.is_delete=0 ");
|
|
|
+ sql.append("SELECT a.*, COUNT(case when b.status=2 and b.is_delete=0 and b.bbs_type='reply' then 1 end) reply from tb_bbs a left join tb_bbs b on b.parent_id=a.id where a.is_delete=0 ");
|
|
|
Integer status = param.getStatus();
|
|
|
if (status!=null){
|
|
|
sql.append(" and a.status=").append(status);
|
|
@@ -67,6 +72,11 @@ public class BbsServiceImpl extends ServiceImpl<BbsMapper, BbsEntity> implements
|
|
|
sql.append(" and a.type='").append(type).append("'");
|
|
|
}
|
|
|
|
|
|
+ String bbsType = param.getBbsType();
|
|
|
+ if (StringUtils.isNotBlank(bbsType)){
|
|
|
+ sql.append(" and a.bbs_type='").append(bbsType).append("'");
|
|
|
+ }
|
|
|
+
|
|
|
String searchKey = param.getSearchKey();
|
|
|
if (StringUtils.isNotBlank(searchKey)){
|
|
|
searchKey = RegexUtil.sqlReplaceSpecialStr(searchKey);
|
|
@@ -74,12 +84,29 @@ public class BbsServiceImpl extends ServiceImpl<BbsMapper, BbsEntity> implements
|
|
|
}
|
|
|
|
|
|
sql.append(" GROUP BY a.id");
|
|
|
+
|
|
|
+ sql.append(" ORDER BY a.create_time desc");
|
|
|
log.info("sql: {}", sql.toString());
|
|
|
|
|
|
IPage<BbsEntity> result = getBaseMapper().pageSearchSql(sql.toString(), page);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result bbsMessageList(BbsMessagePageDto param) {
|
|
|
+ BaseUtil.startPage(param);
|
|
|
+ IPage<BbsEntity> page = new Page<>(param.getPageNum() , param.getPageSize());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<BbsEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(BbsEntity::getBbsType, "reply");
|
|
|
+ wrapper.eq(BbsEntity::getStatus, 2);
|
|
|
+ wrapper.eq(BbsEntity::getParentId, param.getParentId());
|
|
|
+
|
|
|
+ wrapper.orderByDesc(BbsEntity::getCreateTime);
|
|
|
+ IPage<BbsEntity> result = this.page(page, wrapper);
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -113,6 +140,19 @@ public class BbsServiceImpl extends ServiceImpl<BbsMapper, BbsEntity> implements
|
|
|
return Result.success(map);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result del(Long id) {
|
|
|
+ BbsEntity entity = this.getById(id);
|
|
|
+ // 删除所有回帖
|
|
|
+ if ("topic".equals(entity.getBbsType())){
|
|
|
+ getBaseMapper().delByParentId(id);
|
|
|
+ }
|
|
|
+ this.removeById(entity);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Result saveEntity(BbsDto param) {
|
|
@@ -122,6 +162,11 @@ public class BbsServiceImpl extends ServiceImpl<BbsMapper, BbsEntity> implements
|
|
|
if (StringUtils.isBlank(creatorName)){
|
|
|
entity.setCreatorName("匿名用户");
|
|
|
}
|
|
|
+
|
|
|
+ String bbsType = param.getBbsType();
|
|
|
+ if ("reply".equals(bbsType) && param.getParentId() == null){
|
|
|
+ return Result.failure("回帖时,父级id不能为空");
|
|
|
+ }
|
|
|
entity.setStatus(0);
|
|
|
this.saveOrUpdate(entity);
|
|
|
return Result.success();
|