Browse Source
# Conflicts: # hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopController.javamaster
19 changed files with 399 additions and 41 deletions
@ -0,0 +1,117 @@ |
|||||
|
/* |
||||
|
Copyright [2022] [https://hiver.cc]
|
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
*/ |
||||
|
package cc.hiver.mall.controller; |
||||
|
|
||||
|
import cc.hiver.core.common.constant.ShopConstant; |
||||
|
import cc.hiver.core.common.utils.ResultUtil; |
||||
|
import cc.hiver.core.common.utils.StringUtils; |
||||
|
import cc.hiver.core.common.vo.Result; |
||||
|
import cc.hiver.mall.entity.Comment; |
||||
|
import cc.hiver.mall.entity.ShopTakeaway; |
||||
|
import cc.hiver.mall.pojo.query.CommentQuery; |
||||
|
import cc.hiver.mall.pojo.query.ShopTakeawayQuery; |
||||
|
import cc.hiver.mall.pojo.vo.ProductPageVO; |
||||
|
import cc.hiver.mall.service.CommentService; |
||||
|
import cc.hiver.mall.service.ShopTakeawayService; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import io.swagger.annotations.ApiParam; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import java.time.LocalDateTime; |
||||
|
import java.time.format.DateTimeFormatter; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 店铺外卖业务配置控制器 |
||||
|
* |
||||
|
* @author cc |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@RestController |
||||
|
@Api(tags = "评论接口") |
||||
|
@RequestMapping("/hiver/app/comment") |
||||
|
public class CommentController { |
||||
|
|
||||
|
@Autowired |
||||
|
private CommentService commentService; |
||||
|
|
||||
|
@RequestMapping(value = "/save", method = RequestMethod.POST) |
||||
|
@ApiOperation("保存") |
||||
|
@ResponseBody |
||||
|
public Result<Comment> save(Comment comment) { |
||||
|
// 1. 获取当前时间
|
||||
|
final LocalDateTime now = LocalDateTime.now(); |
||||
|
|
||||
|
// 2. 定义格式化器 (例如:yyyy-MM-dd HH:mm:ss)
|
||||
|
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||
|
|
||||
|
// 3. 转换为字符串
|
||||
|
final String timeStr = now.format(formatter); |
||||
|
comment.setCreateByName(timeStr); |
||||
|
if(StringUtils.isEmpty(comment.getParentId())){ |
||||
|
comment.setLevel(ShopConstant.SHOP_STATUS_LOCK); |
||||
|
}else{ |
||||
|
comment.setLevel(ShopConstant.SHOP_STATUS_NORMAL); |
||||
|
} |
||||
|
final Integer result = commentService.insert(comment); |
||||
|
return new ResultUtil<Comment>().setData(comment); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/deleteById", method = RequestMethod.POST) |
||||
|
@ApiOperation("删除") |
||||
|
public Result<Object> deleteById( @RequestParam String id) { |
||||
|
commentService.deleteById(id); |
||||
|
return ResultUtil.success("删除成功"); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/deleteByOrderId", method = RequestMethod.POST) |
||||
|
@ApiOperation("删除") |
||||
|
public Result<Object> deleteByOrderId( @RequestParam String orderId) { |
||||
|
commentService.deleteByOrderId(orderId); |
||||
|
return ResultUtil.success("删除成功"); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/getCommentList", method = RequestMethod.POST) |
||||
|
@ApiOperation("获取店铺评论") |
||||
|
public Result<Page<Comment>> getCommentList( @RequestBody CommentQuery commentQuery) { |
||||
|
//评论分页
|
||||
|
final Page<Comment> commentsPage = commentService.getCommentList(commentQuery); |
||||
|
final List<String> parentIds = new ArrayList<>(); |
||||
|
commentsPage.getRecords().forEach(e -> { |
||||
|
parentIds.add(e.getId()); |
||||
|
}); |
||||
|
//封装子级评论
|
||||
|
if(parentIds.size() > 0){ |
||||
|
final List<Comment> comments = commentService.getCommentListByParentId(parentIds); |
||||
|
commentsPage.getRecords().forEach(e -> { |
||||
|
e.setComments(new ArrayList<>()); |
||||
|
if(comments.size() > 0){ |
||||
|
comments.forEach(comment -> { |
||||
|
if (e.getId().equals(comment.getParentId())) { |
||||
|
e.getComments().add(comment); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
return ResultUtil.data(commentsPage); |
||||
|
} |
||||
|
} |
||||
@ -1,9 +1,24 @@ |
|||||
package cc.hiver.mall.dao.mapper; |
package cc.hiver.mall.dao.mapper; |
||||
|
|
||||
import cc.hiver.mall.entity.Comment; |
import cc.hiver.mall.entity.Comment; |
||||
|
import cc.hiver.mall.pojo.query.CommentQuery; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
import org.springframework.stereotype.Repository; |
import org.springframework.stereotype.Repository; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
@Repository |
@Repository |
||||
public interface CommentMapper extends BaseMapper<Comment> { |
public interface CommentMapper extends BaseMapper<Comment> { |
||||
|
|
||||
|
Page<Comment> getCommentList(Page<Comment> page, @Param("comment") CommentQuery comment); |
||||
|
|
||||
|
void deleteByOrderId(String orderId); |
||||
|
|
||||
|
void deleteById(String id); |
||||
|
|
||||
|
int insert(Comment comment); |
||||
|
|
||||
|
List<Comment> getCommentListByParentId(@Param("parentIds")List<String> parentIds); |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,23 @@ |
|||||
|
package cc.hiver.mall.pojo.query; |
||||
|
|
||||
|
import cc.hiver.core.base.HiverBasePageQuery; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
@ApiModel("分享页查询对象") |
||||
|
@Data |
||||
|
public class CommentQuery extends HiverBasePageQuery { |
||||
|
|
||||
|
@ApiModelProperty("店铺id") |
||||
|
private String shopId; |
||||
|
|
||||
|
@ApiModelProperty("评论id") |
||||
|
private String orderId; |
||||
|
|
||||
|
@ApiModelProperty("评论id") |
||||
|
private Integer picture; |
||||
|
|
||||
|
@ApiModelProperty("评论id") |
||||
|
private Integer score; |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
package cc.hiver.mall.service; |
||||
|
|
||||
|
import cc.hiver.mall.entity.Comment; |
||||
|
import cc.hiver.mall.pojo.query.CommentQuery; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public interface CommentService extends IService<Comment> { |
||||
|
|
||||
|
Page<Comment> getCommentList(CommentQuery commentQuery); |
||||
|
|
||||
|
void deleteByOrderId(String orderId); |
||||
|
|
||||
|
void deleteById(String id); |
||||
|
|
||||
|
int insert(Comment comment); |
||||
|
|
||||
|
List<Comment> getCommentListByParentId(List<String> parentIds); |
||||
|
} |
||||
@ -0,0 +1,53 @@ |
|||||
|
package cc.hiver.mall.serviceimpl; |
||||
|
|
||||
|
import cc.hiver.mall.dao.mapper.CommentMapper; |
||||
|
import cc.hiver.mall.dao.mapper.ShopTakeawayMapper; |
||||
|
import cc.hiver.mall.entity.Comment; |
||||
|
import cc.hiver.mall.entity.ShopTakeaway; |
||||
|
import cc.hiver.mall.pojo.query.CommentQuery; |
||||
|
import cc.hiver.mall.service.CommentService; |
||||
|
import cc.hiver.mall.service.ShopTakeawayService; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import java.util.Collections; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@Transactional |
||||
|
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService { |
||||
|
|
||||
|
@Autowired |
||||
|
private CommentMapper commentMapper; |
||||
|
@Override |
||||
|
public Page<Comment> getCommentList(CommentQuery commentQuery) { |
||||
|
final Page<Comment> page = new Page<>(commentQuery.getPageNum(), commentQuery.getPageSize()); |
||||
|
final Page<Comment> salePage = commentMapper.getCommentList(page, commentQuery); |
||||
|
return salePage; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void deleteByOrderId(String orderId) { |
||||
|
commentMapper.deleteByOrderId(orderId); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void deleteById(String id) { |
||||
|
commentMapper.deleteById(id); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int insert(Comment comment) { |
||||
|
return commentMapper.insert(comment); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<Comment> getCommentListByParentId(List<String> parentIds) { |
||||
|
return commentMapper.getCommentListByParentId(parentIds); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue