HotShopController.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package com.fdkankan.ucenter.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.fdkankan.common.exception.BusinessException;
  4. import com.fdkankan.ucenter.common.Result;
  5. import com.fdkankan.ucenter.constant.LoginConstant;
  6. import com.fdkankan.ucenter.entity.HotShop;
  7. import com.fdkankan.ucenter.service.IHotShopService;
  8. import com.fdkankan.ucenter.vo.RequestHotShop;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import java.util.Arrays;
  15. import java.util.List;
  16. /**
  17. * <p>
  18. * 热点与商品关联表 前端控制器
  19. * </p>
  20. *
  21. * @author
  22. * @since 2022-11-02
  23. */
  24. @RestController
  25. @RequestMapping("/ucenter/hot/shop")
  26. public class HotShopController {
  27. @Autowired
  28. IHotShopService hotShopService;
  29. /**
  30. * 热点id找小程序商品id
  31. */
  32. @RequestMapping(value = "/findGoodIdByHotId")
  33. public Result<List<HotShop>> findGoodIdByHotId(@RequestBody RequestHotShop param) throws Exception {
  34. if(StringUtils.isEmpty(param.getHotId()) || StringUtils.isEmpty(param.getOrigin())){
  35. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  36. }
  37. LambdaQueryWrapper<HotShop> wrapper = new LambdaQueryWrapper<>();
  38. wrapper.eq(HotShop::getHotId,param.getHotId());
  39. wrapper.eq(HotShop::getOrigin,param.getOrigin());
  40. if(StringUtils.isNotBlank(param.getPageSid())){
  41. wrapper.eq(HotShop::getPageSid,param.getPageSid());
  42. }
  43. return Result.success(hotShopService.list(wrapper));
  44. }
  45. /**
  46. * 热点id找小程序商品id
  47. */
  48. @RequestMapping(value = "/findGoodIdByHotIdList")
  49. public Result<List<HotShop>> findGoodIdByHotIdList(@RequestBody RequestHotShop param) throws Exception {
  50. if(StringUtils.isEmpty(param.getHotId()) || StringUtils.isEmpty(param.getOrigin())){
  51. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  52. }
  53. LambdaQueryWrapper<HotShop> wrapper = new LambdaQueryWrapper<>();
  54. wrapper.eq(HotShop::getHotId,param.getHotId());
  55. wrapper.eq(HotShop::getOrigin,param.getOrigin());
  56. return Result.success(hotShopService.list(wrapper));
  57. }
  58. /**
  59. * 保存热点与商品关联
  60. */
  61. @RequestMapping(value = "/saveHotShop")
  62. public Result saveHotShop(@RequestBody RequestHotShop param) throws Exception {
  63. if(StringUtils.isEmpty(param.getHotId()) && StringUtils.isEmpty(param.getOrigin())){
  64. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  65. }
  66. String[] pageSids = null;
  67. if(StringUtils.isNotEmpty(param.getPageSid())){
  68. pageSids = param.getPageSid().split(",");
  69. }
  70. HotShop hotShopEntity = null;
  71. //查看是否有已经关联的商品,有则删除
  72. LambdaQueryWrapper<HotShop> wrapper = new LambdaQueryWrapper<>();
  73. wrapper.eq(HotShop::getHotId,param.getHotId());
  74. wrapper.eq(HotShop::getOrigin,param.getOrigin());
  75. hotShopService.remove(wrapper);
  76. if(StringUtils.isNotEmpty(param.getGoodsIds())){
  77. String[] ids = param.getGoodsIds().split(",");
  78. for(int i = 0, len = ids.length; i < len; i ++){
  79. hotShopEntity = new HotShop();
  80. hotShopEntity.setHotId(param.getHotId());
  81. hotShopEntity.setSceneNum(param.getSceneNum());
  82. hotShopEntity.setPageSid("0");
  83. if(pageSids != null){
  84. hotShopEntity.setPageSid(pageSids[i]);
  85. }
  86. hotShopEntity.setGoodId(Long.valueOf(ids[i]));
  87. hotShopEntity.setOrigin(param.getOrigin());
  88. hotShopService.save(hotShopEntity);
  89. }
  90. }
  91. return Result.success();
  92. }
  93. /**
  94. * 删除热点商品关联
  95. */
  96. @RequestMapping(value = "/deleteGoodsHot")
  97. public Result deleteGoodsHot(@RequestBody RequestHotShop param) throws Exception {
  98. if(StringUtils.isEmpty(param.getHotId()) && StringUtils.isEmpty(param.getOrigin())){
  99. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  100. }
  101. LambdaQueryWrapper<HotShop> wrapper = new LambdaQueryWrapper<>();
  102. wrapper.eq(HotShop::getHotId,param.getHotId());
  103. wrapper.eq(HotShop::getOrigin,param.getOrigin());
  104. if(StringUtils.isNotBlank(param.getPageSid())){
  105. wrapper.eq(HotShop::getPageSid,param.getPageSid());
  106. }
  107. List<HotShop> list = hotShopService.list(wrapper);
  108. if(list != null && list.size() == 1){
  109. hotShopService.removeById(list.get(0).getId());
  110. }
  111. return Result.success();
  112. }
  113. }