提交 cca4a58e authored 作者: lvwei's avatar lvwei

--no commit message

上级 47492dec
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/java/com/zrqx/fg/resource/controller/ResourceController.java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
......
......@@ -5,7 +5,6 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -19,6 +18,7 @@ import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.core.util.response.CallBack;
import com.zrqx.core.vo.resource.fg.comment.FgCommentVo;
import com.zrqx.core.vo.resource.fg.comment.FgUserCommentVo;
import com.zrqx.fg.resource.service.CommentService;
@RestController
......@@ -43,7 +43,7 @@ public class CommentController {
@ApiOperation("查看评论(根据当前登录用户会员id)")
@GetMapping(ResourceRequestPath.PAGE + ResourceRequestPath.COMMENT)
public CallBack<PageInfo<FgCommentVo>> pageComment(PageParam pageParam) {
public CallBack<PageInfo<FgUserCommentVo>> pageComment(PageParam pageParam) {
return CallBack.success(commentService.pageComment(pageParam));
}
......
......@@ -6,6 +6,7 @@ import com.zrqx.core.service.BaseService;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.core.vo.resource.fg.comment.FgCommentVo;
import com.zrqx.core.vo.resource.fg.comment.FgUserCommentVo;
public interface CommentService extends BaseService<Comment, Integer> {
......@@ -34,7 +35,7 @@ public interface CommentService extends BaseService<Comment, Integer> {
* @author lw
* @date: 2019年4月20日 上午10:41:30
*/
PageInfo<FgCommentVo> pageComment(PageParam pageParam);
PageInfo<FgUserCommentVo> pageComment(PageParam pageParam);
/**
* 删除评论
......
......@@ -4,12 +4,20 @@ import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zrqx.core.commons.redis.Redis;
import com.zrqx.core.enums.resource.comment.CommentStatusEnum;
import com.zrqx.core.exception.BusinessValidateException;
......@@ -18,13 +26,17 @@ import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.core.model.member.member.Member;
import com.zrqx.core.model.resource.comment.Comment;
import com.zrqx.core.model.resource.comment.Reply;
import com.zrqx.core.model.resource.goods.eleresource.EleResource;
import com.zrqx.core.model.resource.goods.phyresource.PhyResource;
import com.zrqx.core.service.BaseServiceImpl;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.core.vo.resource.fg.comment.FgCommentVo;
import com.zrqx.core.vo.resource.fg.goods.FgResourceVo;
import com.zrqx.core.vo.resource.fg.comment.FgUserCommentVo;
import com.zrqx.fg.resource.mapper.comment.CommentMapper;
import com.zrqx.fg.resource.mapper.comment.ReplyMapper;
import com.zrqx.fg.resource.mapper.goods.ele.EleResourceMapper;
import com.zrqx.fg.resource.mapper.goods.phy.PhyResourceMapper;
import com.zrqx.fg.resource.service.CommentService;
@Service
......@@ -37,6 +49,10 @@ public class CommentServiceImpl extends BaseServiceImpl<Comment, Integer> implem
@Autowired
ReplyMapper replyMapper;
@Autowired
EleResourceMapper eleResourceMapper;
@Autowired
PhyResourceMapper phyResourceMapper;
@Autowired
Redis redis;
@Override
......@@ -79,6 +95,7 @@ public class CommentServiceImpl extends BaseServiceImpl<Comment, Integer> implem
Comment comment = new Comment();
comment.setComment(form.getComment());
comment.setResourceId(form.getResourceId());
comment.setResourceType(form.getResourceType());
comment.setCreateTime(new Date());
comment.setCreater(String.valueOf(redis.getMember().getId()));
comment.setCreaterName(redis.getMember().getName());
......@@ -87,7 +104,7 @@ public class CommentServiceImpl extends BaseServiceImpl<Comment, Integer> implem
}
@Override
public PageInfo<FgCommentVo> pageComment(PageParam pageParam) {
public PageInfo<FgUserCommentVo> pageComment(PageParam pageParam) {
Member member = redis.getMember();
if(member == null || member.getId() == null) throw new BusinessValidateException("请重新登录");
if(pageParam == null) pageParam.setOrderBy(" createTime desc ");
......@@ -95,21 +112,34 @@ public class CommentServiceImpl extends BaseServiceImpl<Comment, Integer> implem
Comment commentRecord = new Comment();
commentRecord.setCreater(String.valueOf(member.getId()));
List<Comment> comments = commentMapper.select(commentRecord);
List<FgCommentVo> fgCommentVos = comments.stream().map(comment -> {
List<FgUserCommentVo> fgUserCommentVos = comments.stream().map(comment -> {
Reply replyRecord = new Reply();
replyRecord.setCommentId(comment.getId());
Reply reply = replyMapper.selectOne(replyRecord);
FgCommentVo fgCommentVo = new FgCommentVo();
FgUserCommentVo fgUserCommentVo = new FgUserCommentVo();
String resourceType = comment.getResourceType();
if(resourceType.contains("1-")){
PhyResource phyResource = phyResourceMapper.selectByPrimaryKey(comment.getResourceId());
fgUserCommentVo.setResourceCover(phyResource.getCover());
fgUserCommentVo.setResourceId(phyResource.getId());
fgUserCommentVo.setResourceName(phyResource.getName());
} else {
EleResource eleResource = eleResourceMapper.selectByPrimaryKey(comment.getResourceId());
fgUserCommentVo.setResourceCover(eleResource.getCover());
fgUserCommentVo.setResourceId(eleResource.getId());
fgUserCommentVo.setResourceName(eleResource.getName());
}
try {
BeanUtils.copyProperties(fgCommentVo, comment);
BeanUtils.copyProperties(fgCommentVo, reply);
BeanUtils.copyProperties(fgUserCommentVo, comment);
BeanUtils.copyProperties(fgUserCommentVo, reply);
} catch (Exception e) {
logger.error("评论:" + comment.getId() + "获取评论(根据用户)异常\n" + e.getMessage());
}
fgCommentVo.setStatusZh(CommentStatusEnum.getName(fgCommentVo.getStatus()));
return fgCommentVo;
fgUserCommentVo.setStatusZh(CommentStatusEnum.getName(fgUserCommentVo.getStatus()));
return fgUserCommentVo;
}).collect(Collectors.toList());
return new PageInfo<FgCommentVo>(fgCommentVos);
return new PageInfo<FgUserCommentVo>(fgUserCommentVos);
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论