From 7490c6ba0cafe9c668e9b26970c1dd4fb1be9e4c Mon Sep 17 00:00:00 2001 From: delicacylee Date: Sun, 30 Jul 2023 11:55:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=8E=A5=E5=8F=A3BUG?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E8=AF=81=E8=BF=90=E8=A1=8C=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GoodsAttributeController.java | 2 +- .../controller/GoodsCategoryController.java | 28 ++++++++++++++++--- .../hiver/shop/controller/MallController.java | 6 +++- .../shop/dao/GoodsAttributeValueDao.java | 2 +- .../cc/hiver/shop/dao/GoodsCategoryDao.java | 18 ++++++++++++ .../main/java/cc/hiver/shop/dao/MallDao.java | 3 -- .../cc/hiver/shop/dao/mapper/MallMapper.java | 19 +++++++++++++ .../shop/dto/CustomAddressQueryCriteria.java | 3 ++ .../service/GoodsAttributeValueService.java | 2 +- .../shop/service/GoodsCategoryService.java | 18 ++++++++++++ .../cc/hiver/shop/service/MallService.java | 3 -- .../shop/service/mybatis/IMallService.java | 17 +++++++++++ .../GoodsAttributeValueServiceImpl.java | 4 +-- .../serviceimpl/GoodsCategoryServiceImpl.java | 12 ++++++++ .../shop/serviceimpl/MallServiceImpl.java | 7 ----- .../serviceimpl/mybatis/IMallServiceImpl.java | 21 ++++++++++++++ .../src/main/resources/mapper/MallMapper.xml | 11 ++++++++ 17 files changed, 153 insertions(+), 23 deletions(-) create mode 100644 hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/mapper/MallMapper.java create mode 100644 hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/mybatis/IMallService.java create mode 100644 hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/mybatis/IMallServiceImpl.java create mode 100644 hiver-modules/hiver-shop/src/main/resources/mapper/MallMapper.xml diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/GoodsAttributeController.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/GoodsAttributeController.java index 785cb237..3b405920 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/GoodsAttributeController.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/GoodsAttributeController.java @@ -63,7 +63,7 @@ public class GoodsAttributeController { public Result edit(GoodsAttributeDto entity) { GoodsAttributeKey goodsAttributeKey = goodsAttributeKeyService.findById(entity.getId()); goodsAttributeKey.setAttributeKey(entity.getAttributeKey()); - List values = goodsAttributeValueService.findAllBykAndAttributeId(entity.getId()); + List values = goodsAttributeValueService.findAllByAttributeId(entity.getId()); goodsAttributeValueService.delete(values); for(String v : entity.getAttributeValues()) { GoodsAttributeValue goodsAttributeValue = new GoodsAttributeValue(); diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/GoodsCategoryController.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/GoodsCategoryController.java index ca2a69f6..2b52076f 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/GoodsCategoryController.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/GoodsCategoryController.java @@ -1,5 +1,6 @@ package cc.hiver.shop.controller; +import cc.hiver.core.common.constant.CommonConstant; import cc.hiver.core.common.utils.ResultUtil; import cc.hiver.core.common.vo.Result; import cc.hiver.shop.entity.GoodsCategory; @@ -9,10 +10,9 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; @Slf4j @RestController @@ -23,6 +23,14 @@ public class GoodsCategoryController { @Autowired private GoodsCategoryService goodsCategoryService; + @RequestMapping(value = "/getByParentId/{parentId}", method = RequestMethod.GET) + @ApiOperation(value = "通过parentId获取") + public Result> getByParentId(@PathVariable String parentId) { + List list = goodsCategoryService.findByParentIdOrderBySortOrder(parentId); + setInfo(list); + return new ResultUtil>().setData(list); + } + @RequestMapping(value = "/save", method = RequestMethod.POST) @ApiOperation(value = "保存数据") public Result save(GoodsCategory entity) { @@ -38,4 +46,16 @@ public class GoodsCategoryController { } return ResultUtil.success("批量通过id删除数据成功"); } + + public void setInfo(List list) { + // lambda表达式 + list.forEach(item -> { + if (!CommonConstant.PARENT_ID.equals(item.getParentId())) { + GoodsCategory parent = goodsCategoryService.get(item.getParentId()); + item.setParentTitle(parent.getCategoryName()); + } else { + item.setParentTitle("一级分类"); + } + }); + } } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/MallController.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/MallController.java index 7d1ac552..eee92f4a 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/MallController.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/controller/MallController.java @@ -6,6 +6,7 @@ import cc.hiver.shop.entity.Mall; import cc.hiver.shop.entity.UserMall; import cc.hiver.shop.service.MallService; import cc.hiver.shop.service.UserMallService; +import cc.hiver.shop.service.mybatis.IMallService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -27,6 +28,9 @@ public class MallController { @Autowired private UserMallService userMallService; + @Autowired + private IMallService iMallService; + @RequestMapping(value = "/get/{id}", method = RequestMethod.GET) @ApiOperation(value = "通过id获取") public Result get(@PathVariable String id) { @@ -73,7 +77,7 @@ public class MallController { @RequestMapping(value = "/getAll", method = RequestMethod.GET) @ApiOperation(value = "根据会员id获得商铺列表") public Result getAllByUserId(String userId) { - List list = mallService.findAllByUserId(userId); + List list = iMallService.findByUserId(userId); return ResultUtil.data(list); } } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/GoodsAttributeValueDao.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/GoodsAttributeValueDao.java index 6c29a398..c57f2058 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/GoodsAttributeValueDao.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/GoodsAttributeValueDao.java @@ -6,5 +6,5 @@ import cc.hiver.shop.entity.GoodsAttributeValue; import java.util.List; public interface GoodsAttributeValueDao extends HiverBaseDao { - List findAllBykAndAttributeId(String attributeId); + List findAllByAttributeId(String attributeId); } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/GoodsCategoryDao.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/GoodsCategoryDao.java index c59efe7d..b8ff35f7 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/GoodsCategoryDao.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/GoodsCategoryDao.java @@ -3,5 +3,23 @@ package cc.hiver.shop.dao; import cc.hiver.core.base.HiverBaseDao; import cc.hiver.shop.entity.GoodsCategory; +import java.util.List; + public interface GoodsCategoryDao extends HiverBaseDao { + /** + * 通过父id获取 升序 + * + * @param parentId + * @return + */ + List findByParentIdOrderBySortOrder(String parentId); + + /** + * 通过父id和状态获取 升序 + * + * @param parentId + * @param status + * @return + */ + List findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status); } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/MallDao.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/MallDao.java index 14c599fa..def15385 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/MallDao.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/MallDao.java @@ -3,8 +3,5 @@ package cc.hiver.shop.dao; import cc.hiver.core.base.HiverBaseDao; import cc.hiver.shop.entity.Mall; -import java.util.List; - public interface MallDao extends HiverBaseDao { - List findAllByUserId(String userId); } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/mapper/MallMapper.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/mapper/MallMapper.java new file mode 100644 index 00000000..a2bda514 --- /dev/null +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dao/mapper/MallMapper.java @@ -0,0 +1,19 @@ +package cc.hiver.shop.dao.mapper; + +import cc.hiver.shop.entity.Mall; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface MallMapper extends BaseMapper { + /** + * 通过用户id获取 + * + * @param userId + * @return + */ + List findByUserId(@Param("userId") String userId); +} diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dto/CustomAddressQueryCriteria.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dto/CustomAddressQueryCriteria.java index 6aad054e..b8b2bce3 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dto/CustomAddressQueryCriteria.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/dto/CustomAddressQueryCriteria.java @@ -7,6 +7,9 @@ import java.io.Serializable; @Data public class CustomAddressQueryCriteria implements Serializable { + @Query + private String id; + @Query private String userId; diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/GoodsAttributeValueService.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/GoodsAttributeValueService.java index fdf8b109..6fee0efe 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/GoodsAttributeValueService.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/GoodsAttributeValueService.java @@ -6,5 +6,5 @@ import cc.hiver.shop.entity.GoodsAttributeValue; import java.util.List; public interface GoodsAttributeValueService extends HiverBaseService { - List findAllBykAndAttributeId(String attributeId); + List findAllByAttributeId(String attributeId); } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/GoodsCategoryService.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/GoodsCategoryService.java index 2bf0b1bb..0f04a50a 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/GoodsCategoryService.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/GoodsCategoryService.java @@ -3,5 +3,23 @@ package cc.hiver.shop.service; import cc.hiver.core.base.HiverBaseService; import cc.hiver.shop.entity.GoodsCategory; +import java.util.List; + public interface GoodsCategoryService extends HiverBaseService { + /** + * 通过父id获取 升序 + * + * @param parentId + * @return + */ + List findByParentIdOrderBySortOrder(String parentId); + + /** + * 通过父id和状态获取 升序 + * + * @param parentId + * @param status + * @return + */ + List findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status); } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/MallService.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/MallService.java index b9725a96..8674785e 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/MallService.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/MallService.java @@ -3,8 +3,5 @@ package cc.hiver.shop.service; import cc.hiver.core.base.HiverBaseService; import cc.hiver.shop.entity.Mall; -import java.util.List; - public interface MallService extends HiverBaseService { - List findAllByUserId(String userId); } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/mybatis/IMallService.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/mybatis/IMallService.java new file mode 100644 index 00000000..e92804bf --- /dev/null +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/service/mybatis/IMallService.java @@ -0,0 +1,17 @@ +package cc.hiver.shop.service.mybatis; + +import cc.hiver.shop.entity.Mall; +import com.baomidou.mybatisplus.extension.service.IService; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface IMallService extends IService { + /** + * 通过用户id获取 + * + * @param userId + * @return + */ + List findByUserId(@Param("userId") String userId); +} diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/GoodsAttributeValueServiceImpl.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/GoodsAttributeValueServiceImpl.java index b146ffdf..53152870 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/GoodsAttributeValueServiceImpl.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/GoodsAttributeValueServiceImpl.java @@ -24,7 +24,7 @@ public class GoodsAttributeValueServiceImpl implements GoodsAttributeValueServic } @Override - public List findAllBykAndAttributeId(String attributeId) { - return goodsAttributeValueDao.findAllBykAndAttributeId(attributeId); + public List findAllByAttributeId(String attributeId) { + return goodsAttributeValueDao.findAllByAttributeId(attributeId); } } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/GoodsCategoryServiceImpl.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/GoodsCategoryServiceImpl.java index f4a3e29b..594930e6 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/GoodsCategoryServiceImpl.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/GoodsCategoryServiceImpl.java @@ -9,6 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Slf4j @Service @Transactional @@ -20,4 +22,14 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService { public HiverBaseDao getRepository() { return goodsCategoryDao; } + + @Override + public List findByParentIdOrderBySortOrder(String parentId) { + return goodsCategoryDao.findByParentIdOrderBySortOrder(parentId); + } + + @Override + public List findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status) { + return goodsCategoryDao.findByParentIdAndStatusOrderBySortOrder(parentId, status); + } } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/MallServiceImpl.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/MallServiceImpl.java index 77ebf95f..a0f4a901 100644 --- a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/MallServiceImpl.java +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/MallServiceImpl.java @@ -9,8 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - @Slf4j @Service @Transactional @@ -22,9 +20,4 @@ public class MallServiceImpl implements MallService { public HiverBaseDao getRepository() { return mallDao; } - - @Override - public List findAllByUserId(String userId) { - return mallDao.findAllByUserId(userId); - } } diff --git a/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/mybatis/IMallServiceImpl.java b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/mybatis/IMallServiceImpl.java new file mode 100644 index 00000000..386e73a7 --- /dev/null +++ b/hiver-modules/hiver-shop/src/main/java/cc/hiver/shop/serviceimpl/mybatis/IMallServiceImpl.java @@ -0,0 +1,21 @@ +package cc.hiver.shop.serviceimpl.mybatis; + +import cc.hiver.shop.dao.mapper.MallMapper; +import cc.hiver.shop.entity.Mall; +import cc.hiver.shop.service.mybatis.IMallService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class IMallServiceImpl extends ServiceImpl implements IMallService { + @Autowired + private MallMapper mallMapper; + + @Override + public List findByUserId(String userId) { + return mallMapper.findByUserId(userId); + } +} diff --git a/hiver-modules/hiver-shop/src/main/resources/mapper/MallMapper.xml b/hiver-modules/hiver-shop/src/main/resources/mapper/MallMapper.xml new file mode 100644 index 00000000..69f2fde7 --- /dev/null +++ b/hiver-modules/hiver-shop/src/main/resources/mapper/MallMapper.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file