|
@@ -36,20 +36,21 @@ public class IdeaServiceImpl extends ServiceImpl<IdeaMapper, Idea> implements Id
|
|
|
@Override
|
|
|
public HttpRespMsg add(Idea idea) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
- if(null == idea.getId()){
|
|
|
- if(1==idea.getIsDraft()){
|
|
|
+ if (null == idea.getId()) {
|
|
|
+ if (1 == idea.getIsDraft()) {
|
|
|
//只能保留一条草稿
|
|
|
Idea oldIdea = ideaMapper.selectOne(new QueryWrapper<Idea>().eq("uid", idea.getUid()).eq("is_draft", 1).last("limit 1"));
|
|
|
- if(oldIdea!=null){
|
|
|
-
|
|
|
+ if (oldIdea == null) {
|
|
|
+ ideaMapper.insert(idea);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ ideaMapper.insert(idea);
|
|
|
}
|
|
|
- ideaMapper.insert(idea);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
Idea oldIdea = ideaMapper.selectById(idea.getId());
|
|
|
- if(oldIdea.getScore()==0.0){
|
|
|
+ if (oldIdea.getScore() == 0.0) {
|
|
|
ideaMapper.updateById(idea);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
msg.setError("当前建议已被评分,不可进行修改");
|
|
|
}
|
|
|
}
|
|
@@ -60,11 +61,11 @@ public class IdeaServiceImpl extends ServiceImpl<IdeaMapper, Idea> implements Id
|
|
|
public HttpRespMsg del(Idea idea) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
Idea oldIdea = ideaMapper.selectById(idea.getId());
|
|
|
- if(null == oldIdea.getScore()){
|
|
|
+ if (null == oldIdea.getScore()) {
|
|
|
ideaMapper.deleteById(idea.getId());
|
|
|
//删除该建议的评论
|
|
|
- ideaCommentMapper.delete(new QueryWrapper<IdeaComment>().eq("idea_id",idea.getId()));
|
|
|
- }else{
|
|
|
+ ideaCommentMapper.delete(new QueryWrapper<IdeaComment>().eq("idea_id", idea.getId()));
|
|
|
+ } else {
|
|
|
msg.setError("当前建议已被评分,不可进行删除");
|
|
|
}
|
|
|
return msg;
|
|
@@ -73,24 +74,24 @@ public class IdeaServiceImpl extends ServiceImpl<IdeaMapper, Idea> implements Id
|
|
|
@Override
|
|
|
public HttpRespMsg ideaList(Idea idea, PageUtil page) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
- PageHelper.startPage(page.getPageNum(),page.getPageSize());
|
|
|
- List<IdeaVO> list = ideaMapper.getIdeaListByUid(idea,null);
|
|
|
+ PageHelper.startPage(page.getPageNum(), page.getPageSize());
|
|
|
+ List<IdeaVO> list = ideaMapper.getIdeaListByUid(idea, null);
|
|
|
PageInfo<IdeaVO> info = new PageInfo<>(list);
|
|
|
msg.data = info;
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg ideaListByTime(Idea idea, String time,String scoreId) {
|
|
|
+ public HttpRespMsg ideaListByTime(Idea idea, String time, String scoreId) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
- List<IdeaVO> list = ideaMapper.getIdeaListByUid(idea,time);
|
|
|
- Score score = scoreMapper.selectOne(new QueryWrapper<Score>().eq("score_id",scoreId));
|
|
|
+ List<IdeaVO> list = ideaMapper.getIdeaListByUid(idea, time);
|
|
|
+ Score score = scoreMapper.selectOne(new QueryWrapper<Score>().eq("score_id", scoreId));
|
|
|
double sum = 0.0;
|
|
|
- if(list.size()>0){
|
|
|
+ if (list.size() > 0) {
|
|
|
sum = list.stream().mapToDouble(IdeaVO::getScore).sum();
|
|
|
}
|
|
|
- score.setTotal(score.getPersonalScore()+sum);
|
|
|
- scoreMapper.update(score,new QueryWrapper<Score>().eq("score_id",scoreId));
|
|
|
+ score.setTotal(score.getPersonalScore() + sum);
|
|
|
+ scoreMapper.update(score, new QueryWrapper<Score>().eq("score_id", scoreId));
|
|
|
msg.data = list;
|
|
|
return msg;
|
|
|
}
|
|
@@ -100,8 +101,8 @@ public class IdeaServiceImpl extends ServiceImpl<IdeaMapper, Idea> implements Id
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
List<Idea> list = ideaMapper.getIdeaScoreLists(ideaVO);
|
|
|
double sum = 0.0;
|
|
|
- if(list.size()>0){
|
|
|
- sum = list.stream().mapToDouble(Idea::getScore).sum();
|
|
|
+ if (list.size() > 0) {
|
|
|
+ sum = list.stream().mapToDouble(Idea::getScore).sum();
|
|
|
}
|
|
|
msg.data = sum;
|
|
|
return msg;
|
|
@@ -111,9 +112,9 @@ public class IdeaServiceImpl extends ServiceImpl<IdeaMapper, Idea> implements Id
|
|
|
public HttpRespMsg getDraft(Idea idea) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
Idea draftidea = ideaMapper.selectOne(new QueryWrapper<Idea>().eq("uid", idea.getUid()).eq("is_draft", 1).last("limit 1"));
|
|
|
- if(draftidea != null){
|
|
|
+ if (draftidea != null) {
|
|
|
msg.data = draftidea;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
msg.data = idea;
|
|
|
}
|
|
|
return msg;
|