You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SRuml/CommentService.java

92 lines
2.2 KiB

package com.example.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.example.common.enums.ResultCodeEnum;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.entity.Comment;
import com.example.exception.CustomException;
import com.example.mapper.CommentMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 评论业务处理
**/
@Service
public class CommentService {
@Resource
private CommentMapper commentMapper;
/**
* 新增
*/
public void add(Comment comment) {
comment.setTime(DateUtil.now());
commentMapper.insert(comment);
}
/**
* 删除
*/
public void deleteById(Integer id) {
commentMapper.deleteById(id);
}
/**
* 批量删除
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
commentMapper.deleteById(id);
}
}
/**
* 修改
*/
public void updateById(Comment comment) {
commentMapper.updateById(comment);
}
/**
* 根据ID查询
*/
public Comment selectById(Integer id) {
return commentMapper.selectById(id);
}
/**
* 查询所有
*/
public List<Comment> selectAll(Comment comment) {
return commentMapper.selectAll(comment);
}
/**
* 分页查询
*/
public PageInfo<Comment> selectPage(Comment comment, Integer pageNum, Integer pageSize) {
Account currentUser = TokenUtils.getCurrentUser();
if (RoleEnum.USER.name().equals(currentUser.getRole())) {
comment.setUserId(currentUser.getId());
}
if (RoleEnum.BUSINESS.name().equals(currentUser.getRole())) {
comment.setBusinessId(currentUser.getId());
}
PageHelper.startPage(pageNum, pageSize);
List<Comment> list = commentMapper.selectAll(comment);
return PageInfo.of(list);
}
public List<Comment> selectByGoodsId(Integer id) {
return commentMapper.selectByGoodsId(id);
}
}