ApiFootprintController.java 6.7 KB

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