ApiFootprintController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package com.kmall.api.api;
  2. import com.kmall.api.annotation.LoginUser;
  3. import com.kmall.api.entity.FootprintVo;
  4. import com.kmall.api.entity.UserVo;
  5. import com.kmall.api.service.ApiFootprintService;
  6. import com.kmall.api.util.ApiBaseAction;
  7. import com.kmall.api.util.ApiPageUtils;
  8. import com.kmall.common.utils.DateUtils;
  9. import com.kmall.common.utils.Query;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.*;
  12. import java.util.*;
  13. /**
  14. * 作者: @author Scott <br>
  15. * 时间: 2017-08-11 08:32<br>
  16. * 描述: ApiIndexController <br>
  17. */
  18. @RestController
  19. @RequestMapping("/api/footprint")
  20. public class ApiFootprintController extends ApiBaseAction {
  21. @Autowired
  22. private ApiFootprintService footprintService;
  23. /**
  24. */
  25. @PostMapping("delete")
  26. public Object delete(@LoginUser UserVo loginUser, Integer footprintId) {
  27. //删除当天的同一个商品的足迹
  28. FootprintVo footprintEntity = footprintService.queryObject(footprintId);
  29. //
  30. Map param = new HashMap();
  31. param.put("user_id", loginUser.getId());
  32. param.put("goods_id", footprintEntity.getGoods_id());
  33. footprintService.deleteByParam(param);
  34. //
  35. return toResponsMsgSuccess("删除成功");
  36. }
  37. /**
  38. */
  39. @GetMapping("list")
  40. public Object list(@LoginUser UserVo loginUser,
  41. @RequestParam(value = "page", defaultValue = "1") Integer page,
  42. @RequestParam(value = "size", defaultValue = "10") Integer size) {
  43. Map resultObj = new HashMap();
  44. Long storeId = getStoreId();
  45. //查询列表数据
  46. Map params = new HashMap();
  47. params.put("page", page);
  48. params.put("limit", size);
  49. params.put("sidx", "f.id");
  50. params.put("user_id", loginUser.getId());
  51. params.put("store_id", storeId);
  52. params.put("maxFoot", true);
  53. params.put("order", "desc");
  54. Query query = new Query(params);
  55. List<FootprintVo> footprintVos = footprintService.queryList(query);
  56. int total = footprintService.queryTotal(query);
  57. ApiPageUtils pageUtil = new ApiPageUtils(footprintVos, total, query.getLimit(), query.getPage());
  58. //
  59. Map<String, List<FootprintVo>> footPrintMap = new TreeMap<String, List<FootprintVo>>(new Comparator<String>() {
  60. /*
  61. * int compare(Object o1, Object o2) 返回一个基本类型的整型,
  62. * 返回负数表示:o1 小于o2,
  63. * 返回0 表示:o1和o2相等,
  64. * 返回正数表示:o1大于o2。
  65. */
  66. public int compare(String o1, String o2) {
  67. //指定排序器按照降序排列
  68. return o2.compareTo(o1);
  69. }
  70. });
  71. if (null != footprintVos && footprintVos.size() > 0) {
  72. for (FootprintVo footprintVo : footprintVos) {
  73. String addTime = DateUtils.timeToStr(footprintVo.getAdd_time(), DateUtils.DATE_PATTERN);
  74. List<FootprintVo> tmpList = footPrintMap.get(addTime);
  75. if (null == footPrintMap.get(addTime)) {
  76. tmpList = new ArrayList();
  77. }
  78. tmpList.add(footprintVo);
  79. footPrintMap.put(addTime, tmpList);
  80. }
  81. List<FootprintVo>[] footprintVoList = new List[footPrintMap.size()];
  82. int i = 0;
  83. for (Map.Entry<String, List<FootprintVo>> entry : footPrintMap.entrySet()) {
  84. footprintVoList[i] = entry.getValue();
  85. i++;
  86. }
  87. resultObj.put("count", pageUtil.getCount());
  88. resultObj.put("totalPages", pageUtil.getTotalPages());
  89. resultObj.put("numsPerPage", pageUtil.getNumsPerPage());
  90. resultObj.put("currentPage", pageUtil.getCurrentPage());
  91. resultObj.put("data", footprintVoList);
  92. }
  93. return this.toResponsSuccess(resultObj);
  94. }
  95. /**
  96. * 猜你喜欢
  97. */
  98. @GetMapping("glist")
  99. public Object glist(@LoginUser UserVo loginUser,String storeId) {
  100. Map resultObj = new HashMap();
  101. //查询列表数据
  102. Map params = new HashMap();
  103. params.put("sidx", "f.id");
  104. params.put("user_id", loginUser.getId());
  105. params.put("maxFoot", true);
  106. params.put("order", "desc");
  107. params.put("bizType", true);
  108. params.put("store_id", storeId);
  109. List<FootprintVo> footprintVos = footprintService.queryList(params);
  110. List<FootprintVo> list = new ArrayList();
  111. if (null != footprintVos) {
  112. for (FootprintVo vo : footprintVos) {
  113. boolean has = false;
  114. for (FootprintVo voInner : list) {
  115. if (vo.getGoods_id().equals(voInner.getGoods_id())) {
  116. has = true;
  117. break;
  118. }
  119. }
  120. if (!has) {
  121. list.add(vo);
  122. }
  123. if (list.size() > 10) {
  124. break;
  125. }
  126. }
  127. }
  128. resultObj.put("list", list);
  129. return this.toResponsSuccess(resultObj);
  130. }
  131. /**
  132. */
  133. @GetMapping("sharelist")
  134. public Object sharelist(@LoginUser UserVo loginUser,
  135. @RequestParam(value = "page", defaultValue = "1") Integer page,
  136. @RequestParam(value = "size", defaultValue = "10") Integer size) {
  137. Map resultObj = new HashMap();
  138. //查询列表数据
  139. Map params = new HashMap();
  140. params.put("sidx", "f.id");
  141. params.put("order", "desc");
  142. params.put("referrer", loginUser.getId());
  143. List<FootprintVo> footprintVos = footprintService.shareList(params);
  144. //
  145. resultObj.put("data", footprintVos);
  146. return this.toResponsSuccess(resultObj);
  147. }
  148. }