123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package com.fdkankan.ucenter.controller;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.ucenter.common.Result;
- import com.fdkankan.ucenter.constant.LoginConstant;
- import com.fdkankan.ucenter.entity.HotShop;
- import com.fdkankan.ucenter.service.IHotShopService;
- import com.fdkankan.ucenter.vo.RequestHotShop;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.Arrays;
- import java.util.List;
- /**
- * <p>
- * 热点与商品关联表 前端控制器
- * </p>
- *
- * @author
- * @since 2022-11-02
- */
- @RestController
- @RequestMapping("/ucenter/hot/shop")
- public class HotShopController {
- @Autowired
- IHotShopService hotShopService;
- /**
- * 热点id找小程序商品id
- */
- @RequestMapping(value = "/findGoodIdByHotId")
- public Result<List<HotShop>> findGoodIdByHotId(@RequestBody RequestHotShop param) throws Exception {
- if(StringUtils.isEmpty(param.getHotId()) || StringUtils.isEmpty(param.getOrigin())){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- LambdaQueryWrapper<HotShop> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(HotShop::getHotId,param.getHotId());
- wrapper.eq(HotShop::getOrigin,param.getOrigin());
- if(StringUtils.isNotBlank(param.getPageSid())){
- wrapper.eq(HotShop::getPageSid,param.getPageSid());
- }
- return Result.success(hotShopService.list(wrapper));
- }
- /**
- * 热点id找小程序商品id
- */
- @RequestMapping(value = "/findGoodIdByHotIdList")
- public Result<List<HotShop>> findGoodIdByHotIdList(@RequestBody RequestHotShop param) throws Exception {
- if(StringUtils.isEmpty(param.getHotId()) || StringUtils.isEmpty(param.getOrigin())){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- LambdaQueryWrapper<HotShop> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(HotShop::getHotId,param.getHotId());
- wrapper.eq(HotShop::getOrigin,param.getOrigin());
- return Result.success(hotShopService.list(wrapper));
- }
- /**
- * 保存热点与商品关联
- */
- @RequestMapping(value = "/saveHotShop")
- public Result saveHotShop(@RequestBody RequestHotShop param) throws Exception {
- if(StringUtils.isEmpty(param.getHotId()) && StringUtils.isEmpty(param.getOrigin())){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- String[] pageSids = null;
- if(StringUtils.isNotEmpty(param.getPageSid())){
- pageSids = param.getPageSid().split(",");
- }
- HotShop hotShopEntity = null;
- //查看是否有已经关联的商品,有则删除
- LambdaQueryWrapper<HotShop> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(HotShop::getHotId,param.getHotId());
- wrapper.eq(HotShop::getOrigin,param.getOrigin());
- hotShopService.remove(wrapper);
- if(StringUtils.isNotEmpty(param.getGoodsIds())){
- String[] ids = param.getGoodsIds().split(",");
- for(int i = 0, len = ids.length; i < len; i ++){
- hotShopEntity = new HotShop();
- hotShopEntity.setHotId(param.getHotId());
- hotShopEntity.setSceneNum(param.getSceneNum());
- hotShopEntity.setPageSid("0");
- if(pageSids != null){
- hotShopEntity.setPageSid(pageSids[i]);
- }
- hotShopEntity.setGoodId(Long.valueOf(ids[i]));
- hotShopEntity.setOrigin(param.getOrigin());
- hotShopService.save(hotShopEntity);
- }
- }
- return Result.success();
- }
- /**
- * 删除热点商品关联
- */
- @RequestMapping(value = "/deleteGoodsHot")
- public Result deleteGoodsHot(@RequestBody RequestHotShop param) throws Exception {
- if(StringUtils.isEmpty(param.getHotId()) && StringUtils.isEmpty(param.getOrigin())){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- LambdaQueryWrapper<HotShop> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(HotShop::getHotId,param.getHotId());
- wrapper.eq(HotShop::getOrigin,param.getOrigin());
- if(StringUtils.isNotBlank(param.getPageSid())){
- wrapper.eq(HotShop::getPageSid,param.getPageSid());
- }
- List<HotShop> list = hotShopService.list(wrapper);
- if(list != null && list.size() == 1){
- hotShopService.removeById(list.get(0).getId());
- }
- return Result.success();
- }
- }
|