ApiCommentService.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.kmall.api.service;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.kmall.api.dao.ApiCommentMapper;
  5. import com.kmall.api.dao.ApiCommentPictureMapper;
  6. import com.kmall.api.dao.ApiOrderMapper;
  7. import com.kmall.api.entity.CommentPictureVo;
  8. import com.kmall.api.entity.CommentVo;
  9. import com.kmall.api.entity.OrderVo;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import java.util.List;
  14. import java.util.Map;
  15. @Service
  16. public class ApiCommentService {
  17. @Autowired
  18. private ApiCommentMapper commentDao;
  19. @Autowired
  20. private ApiCommentPictureMapper commentPictureDao;
  21. @Autowired
  22. private ApiOrderMapper apiOrderMapper;
  23. public CommentVo queryObject(Integer id) {
  24. return commentDao.queryObject(id);
  25. }
  26. public List<CommentVo> queryList(Map<String, Object> map) {
  27. return commentDao.queryList(map);
  28. }
  29. public int queryTotal(Map<String, Object> map) {
  30. return commentDao.queryTotal(map);
  31. }
  32. public int queryhasPicTotal(Map<String, Object> map) {
  33. return commentDao.queryhasPicTotal(map);
  34. }
  35. @Transactional
  36. public int save(CommentVo comment) {
  37. return commentDao.save(comment);
  38. }
  39. @Transactional
  40. public Long save(JSONObject jsonParam, Long userId) {
  41. Integer typeId = jsonParam.getInteger("typeId");
  42. Integer mannerScore = jsonParam.getInteger("mannerScore");
  43. Integer speedScore = jsonParam.getInteger("speedScore");
  44. Long orderId = jsonParam.getLong("orderId");
  45. JSONArray goodsList = jsonParam.getJSONArray("goodsList");
  46. if (goodsList.size() > 0) {
  47. for (int i = 0; i < goodsList.size(); i++) {
  48. JSONObject goodsObj = goodsList.getJSONObject(i); // 遍历 jsonarray 数组,把每一个对象转成 json 对象
  49. String comment = goodsObj.getString("comment");
  50. String goods_name = goodsObj.getString("goods_name");
  51. String goods_specification_name_value = goodsObj.getString("goods_specification_name_value");
  52. JSONArray pics = goodsObj.getJSONArray("pics");
  53. Long goods_id = goodsObj.getLong("goods_id");
  54. Long product_id = goodsObj.getLong("product_id");
  55. Integer score = goodsObj.getInteger("score");
  56. //
  57. CommentVo commentEntity = new CommentVo();
  58. commentEntity.setTypeId(typeId);
  59. commentEntity.setValueId(goods_id);
  60. commentEntity.setContent(comment);
  61. commentEntity.setStatus(0);
  62. commentEntity.setDeliveryLevel(speedScore);
  63. commentEntity.setEvalLevel(mannerScore);
  64. commentEntity.setGoodsSpecifitionNameValue(goods_specification_name_value);
  65. commentEntity.setGoodsLevel(score);
  66. commentEntity.setUserId(userId);
  67. commentEntity.setAddTime(System.currentTimeMillis() / 1000);
  68. commentEntity.setProductId(product_id);
  69. commentEntity.setOrderId(orderId);
  70. commentEntity.setValueName(goods_name);
  71. commentDao.save(commentEntity);
  72. // pics
  73. if (null == pics || pics.size() < 1) {
  74. continue;
  75. }
  76. for (int index = 0; index < pics.size(); index++) {
  77. CommentPictureVo pictureVo = new CommentPictureVo();
  78. pictureVo.setComment_id(commentEntity.getId());
  79. pictureVo.setPic_url(pics.getString(index));
  80. pictureVo.setSort_order(index + 1);
  81. commentPictureDao.save(pictureVo);
  82. }
  83. }
  84. }
  85. // 更新订单评价
  86. OrderVo orderVo = apiOrderMapper.queryObject(orderId);
  87. orderVo.setComment_count(orderVo.getComment_count() + 1);
  88. apiOrderMapper.update(orderVo);
  89. return orderId;
  90. }
  91. public void update(CommentVo comment) {
  92. commentDao.update(comment);
  93. }
  94. public void delete(Integer id) {
  95. commentDao.delete(id);
  96. }
  97. public void deleteBatch(Integer[] ids) {
  98. commentDao.deleteBatch(ids);
  99. }
  100. public List<Map> queryOrderTotal(Map<String, Object> map) {
  101. return commentDao.queryOrderTotal(map);
  102. }
  103. }