1
0

CommentServiceImpl.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.kmall.admin.service.impl;
  2. import com.kmall.admin.dao.CommentDao;
  3. import com.kmall.admin.dao.CommentPictureDao;
  4. import com.kmall.admin.entity.CommentEntity;
  5. import com.kmall.admin.service.CommentService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.transaction.annotation.Transactional;
  9. import java.util.List;
  10. import java.util.Map;
  11. /**
  12. * 用户评价Service实现类
  13. *
  14. * @author Scott
  15. * @email
  16. * @date 2017-08-28 17:03:40
  17. */
  18. @Service("commentService")
  19. public class CommentServiceImpl implements CommentService {
  20. @Autowired
  21. private CommentDao commentDao;
  22. @Autowired
  23. private CommentPictureDao commentPictureDao;
  24. @Override
  25. public CommentEntity queryObject(Integer id) {
  26. return commentDao.queryObject(id);
  27. }
  28. @Override
  29. public List<CommentEntity> queryList(Map<String, Object> map) {
  30. List<CommentEntity> commentEntities = commentDao.queryList(map);
  31. // if (null != commentEntities && commentEntities.size() > 0) {
  32. // for (CommentEntity commentEntity : commentEntities) {
  33. // commentEntity.setContent(BaseStr64.decode(commentEntity.getContent()));
  34. // }
  35. // }
  36. return commentEntities;
  37. }
  38. @Override
  39. public int queryTotal(Map<String, Object> map) {
  40. return commentDao.queryTotal(map);
  41. }
  42. @Override
  43. public int save(CommentEntity comment) {
  44. return commentDao.save(comment);
  45. }
  46. @Override
  47. public int update(CommentEntity comment) {
  48. return commentDao.update(comment);
  49. }
  50. @Override
  51. @Transactional
  52. public int delete(Integer id) {
  53. //删除评论同时删除评论的图片
  54. commentPictureDao.deleteByCommentId(id);
  55. return commentDao.delete(id);
  56. }
  57. @Override
  58. public int deleteBatch(Integer[] ids) {
  59. return commentDao.deleteBatch(ids);
  60. }
  61. @Override
  62. public int toggleStatus(CommentEntity comment) {
  63. CommentEntity commentEntity = queryObject(comment.getId());
  64. if (commentEntity.getStatus() == 1) {
  65. commentEntity.setStatus(0);
  66. } else if (commentEntity.getStatus() == 0) {
  67. commentEntity.setStatus(1);
  68. }
  69. return commentDao.update(commentEntity);
  70. }
  71. @Override
  72. @Transactional
  73. public int toggleStatusBatch(Integer[] ids) {
  74. if (null == ids || ids.length < 1) {
  75. return 0;
  76. }
  77. for (Integer id : ids) {
  78. CommentEntity commentEntity = queryObject(id);
  79. if (commentEntity.getStatus() == 1) {
  80. commentEntity.setStatus(0);
  81. } else if (commentEntity.getStatus() == 0) {
  82. commentEntity.setStatus(1);
  83. }
  84. commentDao.update(commentEntity);
  85. }
  86. return 1;
  87. }
  88. }