diff --git a/src/main/java/com/peanut/modules/book/controller/ShopStoreController.java b/src/main/java/com/peanut/modules/book/controller/ShopStoreController.java deleted file mode 100644 index aa39ced6..00000000 --- a/src/main/java/com/peanut/modules/book/controller/ShopStoreController.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.peanut.modules.book.controller; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.github.yulichang.wrapper.MPJLambdaWrapper; -import com.peanut.common.utils.R; -import com.peanut.modules.book.entity.ShopStore; -import com.peanut.modules.book.service.ShopStoreService; -import lombok.extern.slf4j.Slf4j; -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.Map; - -@Slf4j -@RestController -@RequestMapping("book/shopStore") -public class ShopStoreController { - - @Autowired - private ShopStoreService shopStoreService; - - /** - * 获取小店列表 - */ - @RequestMapping("/getStoreList") - public R getStoreList(@RequestBody Map params){ - MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); - if (params.containsKey("name")&&!"".equals(params.get("name").toString())){ - wrapper.like(ShopStore::getName,params.get("name").toString()); - } - Page page = shopStoreService.page(new Page<>( - Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper); - return R.ok().put("result", page); - } - - @RequestMapping(path = "/getStoreById") - public R getStoreById(String id) { - return R.ok().put("result",shopStoreService.getById(id)); - } - - @RequestMapping(path = "/saveOrUpdateStore") - public R saveOrUpdateStore(@RequestBody ShopStore store) { - shopStoreService.saveOrUpdate(store); - return R.ok(); - } - - @RequestMapping(path = "/delStore") - public R delStore(String id) { - shopStoreService.removeById(id); - return R.ok(); - } - -} diff --git a/src/main/java/com/peanut/modules/book/service/ShopStoreService.java b/src/main/java/com/peanut/modules/book/service/ShopStoreService.java index 96425ed7..cc7a5864 100644 --- a/src/main/java/com/peanut/modules/book/service/ShopStoreService.java +++ b/src/main/java/com/peanut/modules/book/service/ShopStoreService.java @@ -1,7 +1,7 @@ package com.peanut.modules.book.service; import com.baomidou.mybatisplus.extension.service.IService; -import com.peanut.modules.book.entity.ShopStore; +import com.peanut.modules.common.entity.ShopStore; public interface ShopStoreService extends IService { } diff --git a/src/main/java/com/peanut/modules/common/dao/ShopStoreDao.java b/src/main/java/com/peanut/modules/common/dao/ShopStoreDao.java index 9b1f228e..84b386f7 100644 --- a/src/main/java/com/peanut/modules/common/dao/ShopStoreDao.java +++ b/src/main/java/com/peanut/modules/common/dao/ShopStoreDao.java @@ -1,7 +1,7 @@ -package com.peanut.modules.book.dao; +package com.peanut.modules.common.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.peanut.modules.book.entity.ShopStore; +import com.peanut.modules.common.entity.ShopStore; import org.apache.ibatis.annotations.Mapper; @Mapper diff --git a/src/main/java/com/peanut/modules/common/dao/ShopStoreToProductDao.java b/src/main/java/com/peanut/modules/common/dao/ShopStoreToProductDao.java new file mode 100644 index 00000000..bd3f2c83 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/dao/ShopStoreToProductDao.java @@ -0,0 +1,9 @@ +package com.peanut.modules.common.dao; + +import com.github.yulichang.base.MPJBaseMapper; +import com.peanut.modules.common.entity.ShopStoreToProductEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ShopStoreToProductDao extends MPJBaseMapper { +} diff --git a/src/main/java/com/peanut/modules/common/entity/ShopStore.java b/src/main/java/com/peanut/modules/common/entity/ShopStore.java index 46db3761..52df04f2 100644 --- a/src/main/java/com/peanut/modules/common/entity/ShopStore.java +++ b/src/main/java/com/peanut/modules/common/entity/ShopStore.java @@ -1,4 +1,4 @@ -package com.peanut.modules.book.entity; +package com.peanut.modules.common.entity; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableLogic; @@ -28,6 +28,8 @@ public class ShopStore implements Serializable { */ private Date createTime; + private Integer sort; + @TableLogic private Integer delFlag; diff --git a/src/main/java/com/peanut/modules/common/entity/ShopStoreToProductEntity.java b/src/main/java/com/peanut/modules/common/entity/ShopStoreToProductEntity.java new file mode 100644 index 00000000..f17ad6b6 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/entity/ShopStoreToProductEntity.java @@ -0,0 +1,34 @@ +package com.peanut.modules.common.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("shop_store_to_product") +public class ShopStoreToProductEntity { + + @TableId + private Integer id; + + private Integer storeId; + + private Integer productId; + + private Integer sort; + + private Date createTime; + + @TableLogic + private Integer delFlag; + + @TableField(exist = false) + private ShopStore shopStore; + + @TableField(exist = false) + private ShopProduct shopProduct; +} diff --git a/src/main/java/com/peanut/modules/master/controller/PayPaymentOrderController.java b/src/main/java/com/peanut/modules/master/controller/PayPaymentOrderController.java index 92878193..0e01938b 100644 --- a/src/main/java/com/peanut/modules/master/controller/PayPaymentOrderController.java +++ b/src/main/java/com/peanut/modules/master/controller/PayPaymentOrderController.java @@ -1,8 +1,12 @@ package com.peanut.modules.master.controller; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.R; +import com.peanut.modules.book.service.ShopStoreService; import com.peanut.modules.common.entity.PayPaymentOrderEntity; +import com.peanut.modules.common.entity.ShopStore; import com.peanut.modules.master.service.PayPaymentOrderService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/com/peanut/modules/master/controller/ShopStoreController.java b/src/main/java/com/peanut/modules/master/controller/ShopStoreController.java new file mode 100644 index 00000000..83fa860d --- /dev/null +++ b/src/main/java/com/peanut/modules/master/controller/ShopStoreController.java @@ -0,0 +1,91 @@ +package com.peanut.modules.master.controller; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.peanut.common.utils.R; +import com.peanut.modules.common.entity.ShopStoreToProductEntity; +import com.peanut.modules.common.to.ParamTo; +import com.peanut.modules.master.service.ShopStoreService; +import com.peanut.modules.common.entity.ShopStore; +import com.peanut.modules.master.service.ShopStoreToProductService; +import lombok.extern.slf4j.Slf4j; +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.List; +import java.util.Map; + +@Slf4j +@RestController("masterShopStore") +@RequestMapping("master/shopStore") +public class ShopStoreController { + + @Autowired + private ShopStoreService shopStoreService; + + @Autowired + private ShopStoreToProductService shopStoreToProductService; + + /** + * 获取小店列表 + */ + @RequestMapping("/getStoreList") + public R getStoreList(@RequestBody Map params){ + MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); + if (params.containsKey("name")&&!"".equals(params.get("name").toString())){ + wrapper.like(ShopStore::getName,params.get("name").toString()); + } + Page page = shopStoreService.page(new Page<>( + Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper); + return R.ok().put("result", page); + } + + @RequestMapping(path = "/getStoreById") + public R getStoreById(@RequestBody Map map) { + int id = map.get("id"); + return R.ok().put("result",shopStoreService.getById(id)); + } + + @RequestMapping(path = "/saveOrUpdateStore") + public R saveOrUpdateStore(@RequestBody ShopStore store) { + shopStoreService.saveOrUpdate(store); + return R.ok(); + } + + @RequestMapping(path = "/delStore") + public R delStore(@RequestBody Map map) { + int id = map.get("id"); + return shopStoreService.delStore(id); + } + + @RequestMapping("/getStoreProductList") + public R getStoreProductList(@RequestBody Map map){ + List storeId = shopStoreToProductService.getStoreProductList(map.get("storeId")); + return R.ok().put("list",storeId); + } + + @RequestMapping("/getCanBindProductList") + public R getCanBindProductList(@RequestBody ParamTo param){ + Page canBindProductList = shopStoreToProductService.getCanBindProductList(param); + return R.ok().put("page",canBindProductList); + } + + @RequestMapping("/bindStoreAndProduct") + public R bindStoreAndProduct(@RequestBody Map map){ + return shopStoreToProductService.bindStoreAndProduct(map.get("storeId"),map.get("productId")); + } + + @RequestMapping("/unbindStoreAndProduct") + public R unbindStoreAndProduct(@RequestBody Map map){ + shopStoreToProductService.getBaseMapper().deleteById(map.get("id")); + return R.ok(); + } + + @RequestMapping("/editStoreProductSort") + public R editStoreProductSort(@RequestBody Map map){ + return shopStoreToProductService.editStoreProductSort(map); + } + +} diff --git a/src/main/java/com/peanut/modules/master/service/ShopStoreService.java b/src/main/java/com/peanut/modules/master/service/ShopStoreService.java new file mode 100644 index 00000000..a5f5955a --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/ShopStoreService.java @@ -0,0 +1,9 @@ +package com.peanut.modules.master.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.peanut.common.utils.R; +import com.peanut.modules.common.entity.ShopStore; + +public interface ShopStoreService extends IService { + R delStore(int id); +} diff --git a/src/main/java/com/peanut/modules/master/service/ShopStoreToProductService.java b/src/main/java/com/peanut/modules/master/service/ShopStoreToProductService.java new file mode 100644 index 00000000..9e592b4e --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/ShopStoreToProductService.java @@ -0,0 +1,21 @@ +package com.peanut.modules.master.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.peanut.common.utils.R; +import com.peanut.modules.common.entity.ShopStoreToProductEntity; +import com.peanut.modules.common.to.ParamTo; + +import java.util.List; +import java.util.Map; + +public interface ShopStoreToProductService extends IService { + + List getStoreProductList(int id); + + Page getCanBindProductList(ParamTo param); + + R bindStoreAndProduct(int storeId,int productId); + + R editStoreProductSort(Map map); +} diff --git a/src/main/java/com/peanut/modules/master/service/impl/ShopStoreServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/ShopStoreServiceImpl.java new file mode 100644 index 00000000..84be8866 --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/impl/ShopStoreServiceImpl.java @@ -0,0 +1,30 @@ +package com.peanut.modules.master.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.peanut.common.utils.R; +import com.peanut.modules.common.dao.ShopStoreDao; +import com.peanut.modules.common.dao.ShopStoreToProductDao; +import com.peanut.modules.common.entity.ShopStore; +import com.peanut.modules.common.entity.ShopStoreToProductEntity; +import com.peanut.modules.master.service.ShopStoreService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Slf4j +@Service("shopStore") +public class ShopStoreServiceImpl extends ServiceImpl implements ShopStoreService { + @Autowired + private ShopStoreToProductDao shopStoreToProductDao; + + @Override + public R delStore(int id) { + Integer integer = shopStoreToProductDao.selectCount(new LambdaQueryWrapper().eq(ShopStoreToProductEntity::getStoreId, id)); + if(integer>0){ + return R.error("请先清空后,再操作"); + } + this.removeById(id); + return R.ok(); + } +} diff --git a/src/main/java/com/peanut/modules/master/service/impl/ShopStoreToProductServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/ShopStoreToProductServiceImpl.java new file mode 100644 index 00000000..6825351e --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/impl/ShopStoreToProductServiceImpl.java @@ -0,0 +1,76 @@ +package com.peanut.modules.master.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.peanut.common.utils.R; +import com.peanut.modules.common.dao.ShopProductDao; +import com.peanut.modules.common.dao.ShopStoreDao; +import com.peanut.modules.common.dao.ShopStoreToProductDao; +import com.peanut.modules.common.entity.ShopProduct; +import com.peanut.modules.common.entity.ShopStoreToProductEntity; +import com.peanut.modules.common.to.ParamTo; +import com.peanut.modules.master.service.ShopStoreToProductService; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service("masterShopStoreToProductService") +public class ShopStoreToProductServiceImpl extends ServiceImpl implements ShopStoreToProductService { + @Autowired + private ShopStoreDao shopStoreDao; + @Autowired + private ShopProductDao shopProductDao; + + @Override + public List getStoreProductList(int id) { + List shopStoreToProductEntities = this.getBaseMapper().selectList(new LambdaQueryWrapper() + .eq(ShopStoreToProductEntity::getStoreId, id).orderByAsc(ShopStoreToProductEntity::getSort)); + for (ShopStoreToProductEntity s : shopStoreToProductEntities){ + s.setShopStore(shopStoreDao.selectById(s.getStoreId())); + s.setShopProduct(shopProductDao.selectById(s.getProductId())); + } + return shopStoreToProductEntities; + } + + @Override + public Page getCanBindProductList(ParamTo param) { + List collect = this.getBaseMapper().selectList(new LambdaQueryWrapper() + .eq(ShopStoreToProductEntity::getStoreId, param.getId())) + .stream().map(ShopStoreToProductEntity::getProductId).collect(Collectors.toList()); + LambdaQueryWrapper shopProductLambdaQueryWrapper = new LambdaQueryWrapper<>(); + shopProductLambdaQueryWrapper.like(StringUtils.isNotBlank(param.getKeywords()),ShopProduct::getProductName,param.getKeywords()); + shopProductLambdaQueryWrapper.notIn(ShopProduct::getProductId,collect); + Page shopProductPage = shopProductDao.selectPage(new Page<>(param.getPage(), param.getLimit()), shopProductLambdaQueryWrapper); + return shopProductPage; + } + + @Override + public R bindStoreAndProduct(int storeId, int productId) { + //check + ShopStoreToProductEntity one = this.getOne(new LambdaQueryWrapper() + .eq(ShopStoreToProductEntity::getStoreId, storeId) + .eq(ShopStoreToProductEntity::getProductId, productId)); + if (one!=null){ + return R.error("重复绑定"); + } + ShopStoreToProductEntity shopStoreToProductEntity = new ShopStoreToProductEntity(); + shopStoreToProductEntity.setStoreId(storeId); + shopStoreToProductEntity.setProductId(productId); + this.save(shopStoreToProductEntity); + return R.ok().put("result",shopStoreToProductEntity); + } + + + @Override + public R editStoreProductSort(Map map) { + ShopStoreToProductEntity info = this.getById(map.get("id")); + info.setSort(map.get("sort")); + this.updateById(info); + return R.ok().put("result",info); + } +}