feat(新增): 优惠卷相关接口
This commit is contained in:
parent
afc144c350
commit
cd90d93f3e
|
@ -23,6 +23,11 @@
|
||||||
<artifactId>common-util</artifactId>
|
<artifactId>common-util</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atguigu</groupId>
|
||||||
|
<artifactId>rabbit-util</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.atguigu</groupId>
|
<groupId>com.atguigu</groupId>
|
||||||
<artifactId>model</artifactId>
|
<artifactId>model</artifactId>
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.atguigu.ssyx.common.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.Message;
|
||||||
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class MQProducerAckConfig implements RabbitTemplate.ReturnCallback, RabbitTemplate.ConfirmCallback {
|
||||||
|
|
||||||
|
// 我们发送消息使用的是 private RabbitTemplate rabbitTemplate; 对象
|
||||||
|
// 如果不做设置的话 当前的rabbitTemplate 与当前的配置类没有任何关系!
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
// 设置 表示修饰一个非静态的void方法,在服务器加载Servlet的时候运行。并且只执行一次!
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
rabbitTemplate.setReturnCallback(this);
|
||||||
|
rabbitTemplate.setConfirmCallback(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表示消息是否正确发送到了交换机上
|
||||||
|
*
|
||||||
|
* @param correlationData 消息的载体
|
||||||
|
* @param ack 判断是否发送到交换机上
|
||||||
|
* @param cause 原因
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||||
|
if (ack) {
|
||||||
|
System.out.println("消息发送成功!");
|
||||||
|
} else {
|
||||||
|
System.out.println("消息发送失败!" + cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息如果没有正确发送到队列中,则会走这个方法!如果消息被正常处理,则这个方法不会走!
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
|
||||||
|
System.out.println("消息主体: " + new String(message.getBody()));
|
||||||
|
System.out.println("应答码: " + replyCode);
|
||||||
|
System.out.println("描述:" + replyText);
|
||||||
|
System.out.println("消息使用的交换器 exchange : " + exchange);
|
||||||
|
System.out.println("消息使用的路由键 routing : " + routingKey);
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,4 +28,8 @@ public interface ProductFeignClient {
|
||||||
// 根据关键字获取sku列表
|
// 根据关键字获取sku列表
|
||||||
@GetMapping("inner/findSkuInfoByKeyword/{keyword}")
|
@GetMapping("inner/findSkuInfoByKeyword/{keyword}")
|
||||||
Result<List<SkuInfo>> findSkuInfoByKeyword(@PathVariable("keyword") String keyword);
|
Result<List<SkuInfo>> findSkuInfoByKeyword(@PathVariable("keyword") String keyword);
|
||||||
|
|
||||||
|
// 批量获取分类信息
|
||||||
|
@PostMapping("inner/findCategoryList")
|
||||||
|
List<Category> findCategoryList(@RequestBody List<Long> rangeIdList);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,94 @@
|
||||||
package com.atguigu.ssyx.activity.controller;
|
package com.atguigu.ssyx.activity.controller;
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
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 com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
@Api(tags = "优惠卷相关接口")
|
||||||
* <p>
|
|
||||||
* 优惠券信息 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author bunny
|
|
||||||
* @since 2024-04-04
|
|
||||||
*/
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/activity/coupon-info")
|
@RequestMapping("/admin/activity/couponInfo")
|
||||||
public class CouponInfoController {
|
public class CouponInfoController {
|
||||||
|
|
||||||
}
|
@Autowired
|
||||||
|
private CouponInfoService couponInfoService;
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取分页列表")
|
||||||
|
@GetMapping("{page}/{limit}")
|
||||||
|
public Result<IPage<CouponInfo>> index(
|
||||||
|
@ApiParam(name = "page", value = "当前页码", required = true)
|
||||||
|
@PathVariable Long page,
|
||||||
|
@ApiParam(name = "limit", value = "每页记录数", required = true)
|
||||||
|
@PathVariable Long limit
|
||||||
|
) {
|
||||||
|
Page<CouponInfo> pageParam = new Page<>(page, limit);
|
||||||
|
IPage<CouponInfo> pageModel = couponInfoService.selectPage(pageParam);
|
||||||
|
return Result.success(pageModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取优惠券")
|
||||||
|
@GetMapping("get/{id}")
|
||||||
|
public Result<CouponInfo> get(@PathVariable Long id) {
|
||||||
|
CouponInfo couponInfo = couponInfoService.getCouponInfo(id);
|
||||||
|
return Result.success(couponInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "新增优惠券")
|
||||||
|
@PostMapping("save")
|
||||||
|
public Result<CouponInfo> save(@RequestBody CouponInfo couponInfo) {
|
||||||
|
couponInfoService.save(couponInfo);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "修改优惠券")
|
||||||
|
@PutMapping("update")
|
||||||
|
public Result<CouponInfo> update(@RequestBody CouponInfo couponInfo) {
|
||||||
|
couponInfoService.save(couponInfo);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "删除优惠券")
|
||||||
|
@DeleteMapping("remove/{id}")
|
||||||
|
public Result<CouponInfo> remove(@PathVariable Long id) {
|
||||||
|
couponInfoService.removeById(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "根据id列表删除优惠券")
|
||||||
|
@DeleteMapping("batchRemove")
|
||||||
|
public Result<CouponInfo> batchRemove(@RequestBody List<Long> ids) {
|
||||||
|
couponInfoService.removeByIds(ids);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取优惠券信息")
|
||||||
|
@GetMapping("findCouponRuleList/{id}")
|
||||||
|
public Result<Map<String, Object>> findCouponRuleList(@PathVariable Long id) {
|
||||||
|
Map<String, Object> map = couponInfoService.findCouponRuleList(id);
|
||||||
|
return Result.success(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "新增活动")
|
||||||
|
@PostMapping("saveCouponRule")
|
||||||
|
public Result<CouponRuleVo> saveCouponRule(@RequestBody CouponRuleVo couponRuleVo) {
|
||||||
|
couponInfoService.saveCouponRule(couponRuleVo);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "根据关键字获取sku列表,活动使用")
|
||||||
|
@GetMapping("findCouponByKeyword/{keyword}")
|
||||||
|
public Result<List<CouponInfo>> findCouponByKeyword(@PathVariable("keyword") String keyword) {
|
||||||
|
return Result.success(couponInfoService.findCouponByKeyword(keyword));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CouponRangeMapper extends BaseMapper<CouponRange> {
|
||||||
|
}
|
|
@ -1,8 +1,14 @@
|
||||||
package com.atguigu.ssyx.activity.service;
|
package com.atguigu.ssyx.activity.service;
|
||||||
|
|
||||||
import com.atguigu.ssyx.model.activity.CouponInfo;
|
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.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 优惠券信息 服务类
|
* 优惠券信息 服务类
|
||||||
|
@ -13,4 +19,42 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
*/
|
*/
|
||||||
public interface CouponInfoService extends IService<CouponInfo> {
|
public interface CouponInfoService extends IService<CouponInfo> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 获取分页列表
|
||||||
|
*
|
||||||
|
* @param pageParam 查询分页条件
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
IPage<CouponInfo> selectPage(Page<CouponInfo> pageParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取优惠券
|
||||||
|
*
|
||||||
|
* @param id 优惠卷Id
|
||||||
|
* @return 优惠卷
|
||||||
|
*/
|
||||||
|
CouponInfo getCouponInfo(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取优惠券信息
|
||||||
|
*
|
||||||
|
* @param id 优惠卷Id
|
||||||
|
* @return Map<String, Object>
|
||||||
|
*/
|
||||||
|
Map<String, Object> findCouponRuleList(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 新增活动
|
||||||
|
*
|
||||||
|
* @param couponRuleVo 新的活动
|
||||||
|
*/
|
||||||
|
void saveCouponRule(CouponRuleVo couponRuleVo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据关键字获取sku列表,活动使用
|
||||||
|
*
|
||||||
|
* @param keyword 关键字
|
||||||
|
* @return 根据关键字获取sku列表,活动使用
|
||||||
|
*/
|
||||||
|
List<CouponInfo> findCouponByKeyword(String keyword);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,136 @@
|
||||||
package com.atguigu.ssyx.activity.service.impl;
|
package com.atguigu.ssyx.activity.service.impl;
|
||||||
|
|
||||||
import com.atguigu.ssyx.activity.mapper.CouponInfoMapper;
|
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.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.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.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
import java.util.HashMap;
|
||||||
* <p>
|
import java.util.List;
|
||||||
* 优惠券信息 服务实现类
|
import java.util.Map;
|
||||||
* </p>
|
import java.util.stream.Collectors;
|
||||||
*
|
|
||||||
* @author bunny
|
|
||||||
* @since 2024-04-04
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
public class CouponInfoServiceImpl extends ServiceImpl<CouponInfoMapper, CouponInfo> implements CouponInfoService {
|
public class CouponInfoServiceImpl extends ServiceImpl<CouponInfoMapper, CouponInfo> implements CouponInfoService {
|
||||||
|
@Autowired
|
||||||
|
private CouponRangeMapper couponRangeMapper;
|
||||||
|
@Autowired
|
||||||
|
private ProductFeignClient productFeignClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 获取分页列表
|
||||||
|
*
|
||||||
|
* @param pageParam 查询分页条件
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public IPage<CouponInfo> selectPage(Page<CouponInfo> pageParam) {
|
||||||
|
Page<CouponInfo> page = page(pageParam);
|
||||||
|
List<CouponInfo> pageRecords = page.getRecords();
|
||||||
|
|
||||||
|
pageRecords.forEach(record -> {
|
||||||
|
record.setCouponTypeString(record.getCouponType().getComment());
|
||||||
|
CouponRangeType rangeType = record.getRangeType();
|
||||||
|
if (rangeType != null) {
|
||||||
|
record.setRangeTypeString(rangeType.getComment());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取优惠券
|
||||||
|
*
|
||||||
|
* @param id 优惠卷Id
|
||||||
|
* @return 优惠卷
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public CouponInfo getCouponInfo(Long id) {
|
||||||
|
CouponInfo couponInfo = getById(id);
|
||||||
|
couponInfo.setCouponTypeString(couponInfo.getCouponType().getComment());
|
||||||
|
|
||||||
|
// 使用范围
|
||||||
|
if (couponInfo.getRangeType() != null) {
|
||||||
|
couponInfo.setRangeTypeString(couponInfo.getRangeType().getComment());
|
||||||
|
}
|
||||||
|
return couponInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取优惠券信息
|
||||||
|
*
|
||||||
|
* @param id 优惠卷Id
|
||||||
|
* @return Map<String, Object>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> findCouponRuleList(Long id) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
CouponInfo couponInfo = getById(id);
|
||||||
|
// 根据Id查询 couponRange 列表
|
||||||
|
List<CouponRange> couponRangeList = couponRangeMapper.selectList(Wrappers.<CouponRange>lambdaQuery().eq(CouponRange::getCouponId, id));
|
||||||
|
List<Long> rangeIdList = couponRangeList.stream().map(CouponRange::getRangeId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 分别判断封装不同数据
|
||||||
|
if (!CollectionUtils.isEmpty(rangeIdList)) {
|
||||||
|
if (couponInfo.getRangeType() == CouponRangeType.SKU) {
|
||||||
|
List<SkuInfo> skuInfoList = productFeignClient.findSkuInfoList(rangeIdList).getData();
|
||||||
|
result.put("skuInfoList", skuInfoList);
|
||||||
|
}
|
||||||
|
if (couponInfo.getRangeType() == CouponRangeType.CATEGORY) {
|
||||||
|
List<Category> categoryList = productFeignClient.findCategoryList(rangeIdList);
|
||||||
|
result.put("categoryList", categoryList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 新增活动
|
||||||
|
*
|
||||||
|
* @param vo 新的活动
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void saveCouponRule(CouponRuleVo vo) {
|
||||||
|
// 删除之前的内容
|
||||||
|
couponRangeMapper.delete(Wrappers.<CouponRange>lambdaQuery().eq(CouponRange::getCouponId, vo.getCouponId()));
|
||||||
|
// 查询优惠卷基本信息
|
||||||
|
CouponInfo couponInfo = getById(vo.getCouponId());
|
||||||
|
couponInfo.setRangeType(vo.getRangeType());
|
||||||
|
couponInfo.setConditionAmount(vo.getConditionAmount());
|
||||||
|
couponInfo.setAmount(vo.getAmount());
|
||||||
|
couponInfo.setConditionAmount(vo.getConditionAmount());
|
||||||
|
couponInfo.setRangeDesc(vo.getRangeDesc());
|
||||||
|
// 添加优惠卷信息
|
||||||
|
updateById(couponInfo);
|
||||||
|
|
||||||
|
// 添加优惠卷新的规则数据
|
||||||
|
List<CouponRange> couponRangeList = vo.getCouponRangeList();
|
||||||
|
couponRangeList.forEach(couponRange -> {
|
||||||
|
couponRange.setCouponId(vo.getCouponId());
|
||||||
|
couponRangeMapper.insert(couponRange);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CouponInfo> findCouponByKeyword(String keyword) {
|
||||||
|
// 模糊查询
|
||||||
|
QueryWrapper<CouponInfo> couponInfoQueryWrapper = new QueryWrapper<>();
|
||||||
|
couponInfoQueryWrapper.like("coupon_name", keyword);
|
||||||
|
return list(couponInfoQueryWrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,4 +48,10 @@ public class ProductInnerController {
|
||||||
List<SkuInfo> skuInfoList = skuInfoService.findSkuInfoByKeyword(keyword);
|
List<SkuInfo> skuInfoList = skuInfoService.findSkuInfoByKeyword(keyword);
|
||||||
return Result.success(skuInfoList);
|
return Result.success(skuInfoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "批量获取分类信息")
|
||||||
|
@PostMapping("inner/findCategoryList")
|
||||||
|
public List<Category> findCategoryList(@RequestBody List<Long> rangeIdList) {
|
||||||
|
return categoryService.listByIds(rangeIdList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue