categoryIdList);
}
diff --git a/guigu-ssyx-parent/service/service-acl/src/main/resources/application.yml b/guigu-ssyx-parent/service/service-acl/src/main/resources/application.yml
index 74dd1d2..e9aa979 100644
--- a/guigu-ssyx-parent/service/service-acl/src/main/resources/application.yml
+++ b/guigu-ssyx-parent/service/service-acl/src/main/resources/application.yml
@@ -6,6 +6,6 @@ spring:
cloud:
nacos:
discovery:
- server-addr: localhost:8848
- username: nacos
- password: nacos
+ server-addr: 82.157.68.223:8848
+ username: nacos
+ password: nacos
diff --git a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java
index a05ef13..2cf7c79 100644
--- a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java
+++ b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java
@@ -1,8 +1,17 @@
package com.atguigu.ssyx.activity.controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.atguigu.ssyx.activity.service.CouponInfoService;
+import com.atguigu.ssyx.common.result.Result;
+import com.atguigu.ssyx.model.activity.CouponInfo;
+import com.atguigu.ssyx.vo.activity.CouponRuleVo;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
/**
*
@@ -13,8 +22,79 @@ import org.springframework.web.bind.annotation.RestController;
* @since 2023-09-17
*/
@RestController
-@RequestMapping("/activity/coupon-info")
+@CrossOrigin
+@RequestMapping("/admin/activity/couponInfo")
public class CouponInfoController {
+ @Autowired
+ private CouponInfoService couponInfoService;
+
+ @ApiOperation(value = "获取分页列表")
+ @GetMapping("{page}/{limit}")
+ public Result index(
+ @ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Long page,
+ @ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Long limit) {
+ IPage pageModel = couponInfoService.selectPage(page, limit);
+ return Result.ok(pageModel);
+ }
+
+ @ApiOperation(value = "根据ID查询优惠券")
+ @GetMapping("get/{id}")
+ public Result get(@PathVariable Long id) {
+ CouponInfo couponInfo = couponInfoService.getCouponInfo(id);
+ return Result.ok(couponInfo);
+ }
+
+ @ApiOperation(value = "新增优惠券")
+ @PostMapping("save")
+ public Result save(@RequestBody CouponInfo couponInfo) {
+ couponInfoService.save(couponInfo);
+ return Result.ok(null);
+ }
+
+ @ApiOperation(value = "修改优惠券")
+ @PutMapping("update")
+ public Result updateById(@RequestBody CouponInfo couponInfo) {
+ couponInfoService.updateById(couponInfo);
+ return Result.ok(null);
+ }
+
+ @ApiOperation(value = "删除优惠券")
+ @DeleteMapping("remove/{id}")
+ public Result remove(@PathVariable String id) {
+ couponInfoService.removeById(id);
+ return Result.ok(null);
+ }
+
+ @ApiOperation(value = "根据id列表删除优惠券")
+ @DeleteMapping("batchRemove")
+ public Result batchRemove(@RequestBody List idList) {
+ couponInfoService.removeByIds(idList);
+ return Result.ok(null);
+ }
+
+ @ApiOperation(value = "获取优惠券信息")
+ @GetMapping("findCouponRuleList/{id}")
+ public Result findActivityRuleList(@PathVariable Long id) {
+ return Result.ok(couponInfoService.findCouponRuleList(id));
+ }
+
+ @ApiOperation(value = "新增优惠券")
+ @PostMapping("saveCouponRule")
+ public Result saveCouponRule(@RequestBody CouponRuleVo couponRuleVo) {
+ couponInfoService.saveCouponRule(couponRuleVo);
+ return Result.ok(null);
+ }
+
+ /**
+ * 根据关键字获取sku列表,活动使用
+ *
+ * @param keyword
+ * @return
+ */
+ @GetMapping("findCouponByKeyword/{keyword}")
+ public Result findCouponByKeyword(@PathVariable("keyword") String keyword) {
+ return Result.ok(couponInfoService.findCouponByKeyword(keyword));
+ }
}
diff --git a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/mapper/CouponRangeMapper.java b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/mapper/CouponRangeMapper.java
index d5424be..a639fcc 100644
--- a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/mapper/CouponRangeMapper.java
+++ b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/mapper/CouponRangeMapper.java
@@ -2,6 +2,7 @@ package com.atguigu.ssyx.activity.mapper;
import com.atguigu.ssyx.model.activity.CouponRange;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Repository;
/**
*
@@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @author atguigu
* @since 2023-09-17
*/
+@Repository
public interface CouponRangeMapper extends BaseMapper {
}
diff --git a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/CouponInfoService.java b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/CouponInfoService.java
index 2421889..e8c6e43 100644
--- a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/CouponInfoService.java
+++ b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/CouponInfoService.java
@@ -1,8 +1,13 @@
package com.atguigu.ssyx.activity.service;
import com.atguigu.ssyx.model.activity.CouponInfo;
+import com.atguigu.ssyx.vo.activity.CouponRuleVo;
+import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
+import java.util.List;
+import java.util.Map;
+
/**
*
* 优惠券信息 服务类
@@ -13,4 +18,44 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface CouponInfoService extends IService {
+
+ /**
+ * 获取分页列表
+ *
+ * @param page
+ * @param limit
+ * @return
+ */
+ IPage selectPage(Long page, Long limit);
+
+ /**
+ * 根据ID查询优惠券
+ *
+ * @param id
+ * @return
+ */
+ CouponInfo getCouponInfo(Long id);
+
+ /**
+ * 根据优惠卷id获取优惠券规则列表
+ *
+ * @param id
+ * @return
+ */
+ Map findCouponRuleList(Long id);
+
+ /**
+ * 新增优惠券规则
+ *
+ * @param couponRuleVo
+ */
+ void saveCouponRule(CouponRuleVo couponRuleVo);
+
+ /**
+ * 根据关键字获取sku列表,活动使用
+ *
+ * @param keyword
+ * @return
+ */
+ List findCouponByKeyword(String keyword);
}
diff --git a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/impl/CouponInfoServiceImpl.java b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/impl/CouponInfoServiceImpl.java
index 3e01101..c0b7810 100644
--- a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/impl/CouponInfoServiceImpl.java
+++ b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/impl/CouponInfoServiceImpl.java
@@ -1,10 +1,27 @@
package com.atguigu.ssyx.activity.service.impl;
import com.atguigu.ssyx.activity.mapper.CouponInfoMapper;
+import com.atguigu.ssyx.activity.mapper.CouponRangeMapper;
import com.atguigu.ssyx.activity.service.CouponInfoService;
+import com.atguigu.ssyx.client.product.ProductFeignClient;
+import com.atguigu.ssyx.enums.CouponRangeType;
import com.atguigu.ssyx.model.activity.CouponInfo;
+import com.atguigu.ssyx.model.activity.CouponRange;
+import com.atguigu.ssyx.model.product.Category;
+import com.atguigu.ssyx.model.product.SkuInfo;
+import com.atguigu.ssyx.vo.activity.CouponRuleVo;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
*
@@ -17,4 +34,119 @@ import org.springframework.stereotype.Service;
@Service
public class CouponInfoServiceImpl extends ServiceImpl implements CouponInfoService {
+
+ @Autowired
+ CouponRangeMapper couponRangeMapper;
+
+ @Autowired
+ ProductFeignClient productFeignClient;
+
+ /**
+ * 获取分页列表
+ *
+ * @param page
+ * @param limit
+ * @return
+ */
+ @Override
+ public IPage selectPage(Long page, Long limit) {
+ Page pageParam = new Page<>(page, limit);
+ Page couponInfoPage = baseMapper.selectPage(pageParam, null);
+ List couponInfoList = couponInfoPage.getRecords();
+ couponInfoList.forEach(item -> {
+ item.setCouponTypeString(item.getCouponType()
+ .getComment());
+ CouponRangeType rangeType = item.getRangeType();
+ if (rangeType != null) {
+ item.setRangeTypeString(rangeType.getComment());
+ }
+ });
+ return couponInfoPage;
+ }
+
+ /**
+ * 根据ID查询优惠券
+ *
+ * @param id
+ * @return
+ */
+ @Override
+ public CouponInfo getCouponInfo(Long id) {
+ CouponInfo couponInfo = baseMapper.selectById(id);
+ couponInfo.setCouponTypeString(couponInfo.getCouponType()
+ .getComment());
+ if (couponInfo.getRangeType() != null) {
+ couponInfo.setRangeTypeString(couponInfo.getRangeType()
+ .getComment());
+ }
+ return couponInfo;
+ }
+
+ /**
+ * 根据优惠卷id获取优惠券规则列表
+ *
+ * @param id
+ * @return
+ */
+ @Override
+ public Map findCouponRuleList(Long id) {
+ //第一步 根据优惠卷id查询优惠卷基本信息 coupon_info表
+ CouponInfo couponInfo = baseMapper.selectById(id);
+
+ //第二步 根据优惠卷id查询coupon_range 查询里面对应range_id
+ List couponRangeList = couponRangeMapper.selectList(new LambdaQueryWrapper().eq(CouponRange::getCouponId, id));
+ //couponRangeList获取所有range_id
+ //// 如果规则类型 SKU range_id就是skuId值
+ //// 如果规则类型 CATEGORY range_id就是分类Id值
+ List randIdList = couponRangeList.stream()
+ .map(CouponRange::getRangeId)
+ .collect(Collectors.toList());
+
+ Map result = new HashMap<>();
+ //第三步 分别判断封装不同数据
+ if (!CollectionUtils.isEmpty(randIdList)) {
+ if (couponInfo.getRangeType() == CouponRangeType.SKU) {
+ //// 如果规则类型是SKU ,得到skuId,
+ // 远程调用根据多个skuId值获取对应sku信息
+ List skuInfoList = productFeignClient.findSkuInfoList(randIdList);
+ result.put("skuInfoList", skuInfoList);
+
+ } else if (couponInfo.getRangeType() == CouponRangeType.CATEGORY) {
+ //// 如果规则类型是分类,得到分类Id,远程调用根据多个分类Id值获取对应分类信息
+ List categoryList = productFeignClient.findCategoryList(randIdList);
+ result.put("categoryList", categoryList);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public void saveCouponRule(CouponRuleVo couponRuleVo) {
+ //优惠券couponInfo 与 couponRange 要一起操作:先删除couponRange ,更新couponInfo ,再新增couponRange !
+
+ couponRangeMapper.delete(new LambdaQueryWrapper().eq(CouponRange::getCouponId, couponRuleVo.getCouponId()));
+
+ //更新优惠卷基本信息
+ CouponInfo couponInfo = baseMapper.selectById(couponRuleVo.getCouponId());
+ couponInfo.setRangeType(couponRuleVo.getRangeType());
+ couponInfo.setConditionAmount(couponRuleVo.getConditionAmount());
+ couponInfo.setAmount(couponRuleVo.getAmount());
+ couponInfo.setConditionAmount(couponRuleVo.getConditionAmount());
+ couponInfo.setRangeDesc(couponRuleVo.getRangeDesc());
+ baseMapper.updateById(couponInfo);
+
+ //添加优惠卷新规则数据
+ List couponRangeList = couponRuleVo.getCouponRangeList();
+ for (CouponRange couponRange : couponRangeList) {
+ //设置优惠卷id
+ couponRange.setCouponId(couponRuleVo.getCouponId());
+ //添加
+ couponRangeMapper.insert(couponRange);
+ }
+ }
+
+ @Override
+ public List findCouponByKeyword(String keyword) {
+ return baseMapper.selectList(new LambdaQueryWrapper().like(CouponInfo::getCouponName, keyword));
+ }
}
diff --git a/guigu-ssyx-parent/service/service-activity/src/main/resources/application.yml b/guigu-ssyx-parent/service/service-activity/src/main/resources/application.yml
index 299f6bb..fdddbd1 100644
--- a/guigu-ssyx-parent/service/service-activity/src/main/resources/application.yml
+++ b/guigu-ssyx-parent/service/service-activity/src/main/resources/application.yml
@@ -6,6 +6,6 @@ spring:
cloud:
nacos:
discovery:
- server-addr: localhost:8848
- username: nacos
- password: nacos
+ server-addr: 82.157.68.223:8848
+ username: nacos
+ password: nacos
diff --git a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/api/ProductInnnerController.java b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/api/ProductInnnerController.java
index 3f4a25a..23226ac 100644
--- a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/api/ProductInnnerController.java
+++ b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/api/ProductInnnerController.java
@@ -45,6 +45,12 @@ public class ProductInnnerController {
return skuInfoService.findSkuInfoList(skuIdList);
}
+ @ApiOperation(value = "批量获取分类信息")
+ @PostMapping("inner/findCategoryList")
+ public List findCategoryList(@RequestBody List categoryIdList) {
+ return categoryService.listByIds(categoryIdList);
+ }
+
@ApiOperation(value = "根据关键字获取sku列表")
@GetMapping("inner/findSkuInfoByKeyword/{keyword}")
public List findSkuInfoByKeyword(@PathVariable("keyword") String keyword) {
diff --git a/guigu-ssyx-parent/service/service-product/src/main/resources/application.yml b/guigu-ssyx-parent/service/service-product/src/main/resources/application.yml
index 15f2770..856ea6d 100644
--- a/guigu-ssyx-parent/service/service-product/src/main/resources/application.yml
+++ b/guigu-ssyx-parent/service/service-product/src/main/resources/application.yml
@@ -6,6 +6,4 @@ spring:
cloud:
nacos:
discovery:
- server-addr: localhost:8848
- username: nacos
- password: nacos
+ server-addr: 82.157.68.223:8848
diff --git a/guigu-ssyx-parent/service/service-search/src/main/resources/application.yml b/guigu-ssyx-parent/service/service-search/src/main/resources/application.yml
index e5f6453..3bec5db 100644
--- a/guigu-ssyx-parent/service/service-search/src/main/resources/application.yml
+++ b/guigu-ssyx-parent/service/service-search/src/main/resources/application.yml
@@ -6,6 +6,4 @@ spring:
cloud:
nacos:
discovery:
- server-addr: localhost:8848
- username: nacos
- password: nacos
+ server-addr: 82.157.68.223:8848
diff --git a/guigu-ssyx-parent/service/service-sys/src/main/resources/application.yml b/guigu-ssyx-parent/service/service-sys/src/main/resources/application.yml
index 980f10b..bbe8496 100644
--- a/guigu-ssyx-parent/service/service-sys/src/main/resources/application.yml
+++ b/guigu-ssyx-parent/service/service-sys/src/main/resources/application.yml
@@ -6,6 +6,4 @@ spring:
cloud:
nacos:
discovery:
- server-addr: localhost:8848
- username: nacos
- password: nacos
+ server-addr: 82.157.68.223:8848