From 464ece7a27a45b1dbbb38261206f8db75916d62c Mon Sep 17 00:00:00 2001 From: wangfukang <15630117759@163.com> Date: Sun, 4 Aug 2024 15:16:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=97=E9=93=BA=E5=85=B3=E8=81=94=E5=88=86?= =?UTF-8?q?=E7=BB=84=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ShopRelationsController.java | 41 +++++++++ .../mapper/ShopRelationsMapper.java | 21 ++++- .../service/ShopRelationsService.java | 42 +++++++++ .../impl/ShopRelationsServiceImpl.java | 86 +++++++++++++++++-- .../resources/mapper/ShopRelationsMapper.xml | 8 ++ 5 files changed, 192 insertions(+), 6 deletions(-) diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/controller/ShopRelationsController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/controller/ShopRelationsController.java index 562694ec..f67d0022 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/controller/ShopRelationsController.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/controller/ShopRelationsController.java @@ -102,4 +102,45 @@ public class ShopRelationsController { return ResultUtil.error("获取店铺关联信息失败"); } } + + /** + * 根据店主id查询分组 + * + * @param shopOwnerId + * @return Result + * @author 王富康 + * @date 2024/8/4 + */ + @RequestMapping(value = "/getShopRelationsByShopOwnerId", method = RequestMethod.POST) + @ApiOperation("查询店主的分组") + public Result getShopRelationsByShopOwnerId(String shopOwnerId) { + + if (StringUtils.isEmpty(shopOwnerId)) { + return ResultUtil.error("店主id不能为空"); + } + try { + List shopRelationsVoList = shopRelationsService.getShopRelationsByShopOwnerId(shopOwnerId); + return new ResultUtil>().setData(shopRelationsVoList); + } catch (Exception e) { + log.error(e.getMessage(), e); + return ResultUtil.error("查询店主的分组失败"); + } + } + + // 修改分组店铺信息 + @RequestMapping(value = "/updateShopRelations", method = RequestMethod.POST) + @ApiOperation("修改分组店铺信息") + public Result updateShopRelations(@RequestBody ShopRelations shopRelations) { + + if (StringUtils.isEmpty(shopRelations.getId())) { + return ResultUtil.error("id不能为空"); + } + try { + shopRelationsService.updateShopRelations(shopRelations); + return ResultUtil.success("修改分组店铺信息成功"); + } catch (Exception e) { + log.error(e.getMessage(), e); + return ResultUtil.error("修改分组店铺信息失败"); + } + } } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/mapper/ShopRelationsMapper.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/mapper/ShopRelationsMapper.java index 7d8aa4e1..3c4e0eed 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/mapper/ShopRelationsMapper.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/mapper/ShopRelationsMapper.java @@ -7,5 +7,24 @@ import org.apache.ibatis.annotations.Param; import java.util.List; public interface ShopRelationsMapper extends BaseMapper { - List getShopRelations(@Param("shopId") String shopId); + + /** + * 根据店铺id获取关联的店铺信息 + * + * @param shopId + * @return List + * @author 王富康 + * @date 2024/8/4 + */ + List getShopRelations(@Param("shopId") String shopId); + + /** + * 根据店主id查询分组 + * + * @param shopOwnerId + * @return List + * @author 王富康 + * @date 2024/8/4 + */ + List getShopRelationsByShopOwnerId(@Param("shopOwnerId") String shopOwnerId); } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/ShopRelationsService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/ShopRelationsService.java index e70a337d..f75d8258 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/ShopRelationsService.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/ShopRelationsService.java @@ -6,9 +6,51 @@ import cc.hiver.mall.shoprelations.vo.ShopRelationsVo; import java.util.List; public interface ShopRelationsService { + + /** + * 新增店铺关联信息 + * + * @param shopRelations + * @author 王富康 + * @date 2024/8/4 + */ void addShopRelations(ShopRelations shopRelations); + /** + * 根据店铺id获取关联的店铺信息 + * + * @param shopId + * @return List + * @author 王富康 + * @date 2024/8/4 + */ List getShopRelations(String shopId); + /** + * 删除店铺关联信息 + * + * @param id + * @author 王富康 + * @date 2024/8/4 + */ void deleteShopRelations(String id); + + /** + * 根据店主id查询分组 + * + * @param shopOwnerId + * @return List + * @author 王富康 + * @date 2024/8/4 + */ + List getShopRelationsByShopOwnerId(String shopOwnerId); + + /** + * 修改分组店铺信息 + * + * @param shopRelations + * @author 王富康 + * @date 2024/8/4 + */ + void updateShopRelations(ShopRelations shopRelations); } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/impl/ShopRelationsServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/impl/ShopRelationsServiceImpl.java index 3cdeb7a8..213e0ade 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/impl/ShopRelationsServiceImpl.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/impl/ShopRelationsServiceImpl.java @@ -4,6 +4,7 @@ import cc.hiver.mall.shoprelations.entity.ShopRelations; import cc.hiver.mall.shoprelations.mapper.ShopRelationsMapper; import cc.hiver.mall.shoprelations.service.ShopRelationsService; import cc.hiver.mall.shoprelations.vo.ShopRelationsVo; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,26 +17,101 @@ public class ShopRelationsServiceImpl implements ShopRelationsService { @Autowired private ShopRelationsMapper shopRelationsMapper; + /** + * 新增店铺关联信息 + * + * @param shopRelations + * @author 王富康 + * @date 2024/8/4 + */ @Override public void addShopRelations(ShopRelations shopRelations) { shopRelationsMapper.insert(shopRelations); } + /** + * 根据店铺id获取关联的店铺信息 + * + * @param shopId + * @return List + * @author 王富康 + * @date 2024/8/4 + */ @Override public List getShopRelations(String shopId) { - List shopRelations = shopRelationsMapper.getShopRelations(shopId); - List shopRelationsVo = new ArrayList<>(); - if(shopRelations != null && !shopRelations.isEmpty()){ + // 查询出来包含当前店铺的分组信息 + final List shopRelations = shopRelationsMapper.getShopRelations(shopId); + // 需要返回的跟当前店铺有关联的店铺信息 + final List shopRelationsVo = new ArrayList<>(); + // 存放已经添加过的店铺id,用于去重 + final List shopIds = new ArrayList<>(); + if (shopRelations != null && !shopRelations.isEmpty()) { for (ShopRelations shopRelation : shopRelations) { - String groupShopId = shopRelation.getShopId(); - String shopName = shopRelation.getShopName(); + final String groupShopId = shopRelation.getShopId(); + final String shopName = shopRelation.getShopName(); + if (StringUtils.isEmpty(groupShopId)) { + // 根据都好分隔 + final String[] groupShopIdArray = groupShopId.split(","); + final String[] groupshopNameArray = shopName.split(","); + for (int i = 0; i < groupShopIdArray.length; i++) { + // 判断是否已经添加过 + if (!shopIds.contains(groupShopIdArray[i])) { + // 没有添加过,放进集合 + shopIds.add(groupShopIdArray[i]); + // 没有添加过,放回返回集合 + final ShopRelationsVo relationsVo = new ShopRelationsVo(); + relationsVo.setShopId(groupShopIdArray[i]); + relationsVo.setShopName(groupshopNameArray[i]); + shopRelationsVo.add(relationsVo); + } + } + } } } return shopRelationsVo; } + /** + * 删除店铺关联信息 + * + * @param id + * @author 王富康 + * @date 2024/8/4 + */ @Override public void deleteShopRelations(String id) { shopRelationsMapper.deleteById(id); } + + /** + * 根据店主id查询分组 + * + * @param shopOwnerId + * @return List + * @author 王富康 + * @date 2024/8/4 + */ + @Override + public List getShopRelationsByShopOwnerId(String shopOwnerId) { + return shopRelationsMapper.getShopRelationsByShopOwnerId(shopOwnerId); + } + + /** + * 修改分组店铺信息 + * + * @param shopRelations + * @author 王富康 + * @date 2024/8/4 + */ + @Override + public void updateShopRelations(ShopRelations shopRelations) { + // 只能修改分组名称及店铺信息,这里不要动其他数据 + // 获取到之前的数据 + final ShopRelations oldShopRelations = shopRelationsMapper.selectById(shopRelations.getId()); + oldShopRelations.setGroupName(shopRelations.getGroupName()); + oldShopRelations.setShopId(shopRelations.getShopId()); + oldShopRelations.setShopName(shopRelations.getShopName()); + // 更新 + shopRelationsMapper.updateById(oldShopRelations); + } } diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/ShopRelationsMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/ShopRelationsMapper.xml index 30a805bd..53930383 100644 --- a/hiver-modules/hiver-mall/src/main/resources/mapper/ShopRelationsMapper.xml +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/ShopRelationsMapper.xml @@ -35,4 +35,12 @@ from t_shop_relations where shop_id like concat('%',#{shopId},'%') + + + \ No newline at end of file