商品详情展示
This commit is contained in:
@@ -4,10 +4,7 @@ import com.atguigu.ssyx.activity.service.ActivityInfoService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@@ -34,4 +31,10 @@ public class ActivityApiController {
|
||||
public Map<Long, List<String>> findActivity(@RequestBody List<Long> skuIdList) {
|
||||
return activityInfoService.findActivity(skuIdList);
|
||||
}
|
||||
|
||||
@ApiOperation("根据skuID获取营销数据和优惠卷")
|
||||
@GetMapping("inner/findActivityAndCoupon/{skuId}/{userId}")
|
||||
public Map<String, Object> findActivityAndCoupon(@PathVariable Long skuId, @PathVariable Long userId) {
|
||||
return activityInfoService.findActivityAndCoupon(skuId, userId);
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,9 @@ package com.atguigu.ssyx.activity.mapper;
|
||||
|
||||
import com.atguigu.ssyx.model.activity.CouponInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -13,4 +16,14 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
*/
|
||||
public interface CouponInfoMapper extends BaseMapper<CouponInfo> {
|
||||
|
||||
/**
|
||||
* 根据条件查询:skuId + 分类id + userId
|
||||
*
|
||||
* @param id
|
||||
* @param categoryId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<CouponInfo> selectCouponInfoList(
|
||||
@Param("skuId") Long id, @Param("categoryId") Long categoryId, @Param("userId") Long userId);
|
||||
}
|
||||
|
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.atguigu.ssyx.activity.mapper.CouponInfoMapper">
|
||||
|
||||
</mapper>
|
@@ -60,4 +60,13 @@ public interface ActivityInfoService extends IService<ActivityInfo> {
|
||||
* @return
|
||||
*/
|
||||
Map<Long, List<String>> findActivity(List<Long> skuIdList);
|
||||
|
||||
/**
|
||||
* 根据skuID获取营销数据和优惠卷
|
||||
*
|
||||
* @param skuId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> findActivityAndCoupon(Long skuId, Long userId);
|
||||
}
|
||||
|
@@ -58,4 +58,14 @@ public interface CouponInfoService extends IService<CouponInfo> {
|
||||
* @return
|
||||
*/
|
||||
List<CouponInfo> findCouponByKeyword(String keyword);
|
||||
|
||||
/**
|
||||
* 根据skuId+userId查询优惠卷信息
|
||||
*
|
||||
* @param skuId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
|
||||
List<CouponInfo> findCouponInfoList(Long skuId, Long userId);
|
||||
}
|
||||
|
@@ -4,11 +4,13 @@ import com.atguigu.ssyx.activity.mapper.ActivityInfoMapper;
|
||||
import com.atguigu.ssyx.activity.mapper.ActivityRuleMapper;
|
||||
import com.atguigu.ssyx.activity.mapper.ActivitySkuMapper;
|
||||
import com.atguigu.ssyx.activity.service.ActivityInfoService;
|
||||
import com.atguigu.ssyx.activity.service.CouponInfoService;
|
||||
import com.atguigu.ssyx.client.product.ProductFeignClient;
|
||||
import com.atguigu.ssyx.enums.ActivityType;
|
||||
import com.atguigu.ssyx.model.activity.ActivityInfo;
|
||||
import com.atguigu.ssyx.model.activity.ActivityRule;
|
||||
import com.atguigu.ssyx.model.activity.ActivitySku;
|
||||
import com.atguigu.ssyx.model.activity.CouponInfo;
|
||||
import com.atguigu.ssyx.model.product.SkuInfo;
|
||||
import com.atguigu.ssyx.vo.activity.ActivityRuleVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -51,6 +53,9 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
|
||||
@Autowired
|
||||
private ProductFeignClient productFeignClient;
|
||||
|
||||
@Autowired
|
||||
private CouponInfoService couponInfoService;
|
||||
|
||||
/**
|
||||
* 优惠活动列表方法
|
||||
*
|
||||
@@ -72,7 +77,7 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动规则列表方法
|
||||
* 根据活动Id查询活动规则列表方法
|
||||
*
|
||||
* @param activityId
|
||||
* @return
|
||||
@@ -172,6 +177,7 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
|
||||
return findSkuList;
|
||||
}
|
||||
|
||||
//拼接文字
|
||||
private String getRuleDesc(ActivityRule activityRule) {
|
||||
ActivityType activityType = activityRule.getActivityType();
|
||||
StringBuffer ruleDesc = new StringBuffer();
|
||||
@@ -216,4 +222,37 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据skuID获取营销数据和优惠卷
|
||||
*
|
||||
* @param skuId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> findActivityAndCoupon(Long skuId, Long userId) {
|
||||
//1 根据skuId获取sku营销活动,一个活动有多个规则
|
||||
List<ActivityRule> activityRuleList = this.findActivityRuleBySkuId(skuId);
|
||||
|
||||
//2 根据skuId+userId查询优惠卷信息
|
||||
List<CouponInfo> couponInfoList = couponInfoService.findCouponInfoList(skuId, userId);
|
||||
|
||||
//3 封装到map集合,返回
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("couponInfoList", couponInfoList);
|
||||
map.put("activityRuleList", activityRuleList);
|
||||
return map;
|
||||
}
|
||||
|
||||
//根据skuId获取活动规则数据
|
||||
public List<ActivityRule> findActivityRuleBySkuId(Long skuId) {
|
||||
List<ActivityRule> activityRuleList = baseMapper.findActivityRule(skuId);
|
||||
|
||||
for (ActivityRule activityRule : activityRuleList) {
|
||||
String ruleDesc = this.getRuleDesc(activityRule);
|
||||
activityRule.setRuleDesc(ruleDesc);
|
||||
}
|
||||
return activityRuleList;
|
||||
}
|
||||
}
|
||||
|
@@ -120,6 +120,11 @@ public class CouponInfoServiceImpl extends ServiceImpl<CouponInfoMapper, CouponI
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增优惠券规则
|
||||
*
|
||||
* @param couponRuleVo
|
||||
*/
|
||||
@Override
|
||||
public void saveCouponRule(CouponRuleVo couponRuleVo) {
|
||||
//优惠券couponInfo 与 couponRange 要一起操作:先删除couponRange ,更新couponInfo ,再新增couponRange !
|
||||
@@ -149,4 +154,22 @@ public class CouponInfoServiceImpl extends ServiceImpl<CouponInfoMapper, CouponI
|
||||
public List<CouponInfo> findCouponByKeyword(String keyword) {
|
||||
return baseMapper.selectList(new LambdaQueryWrapper<CouponInfo>().like(CouponInfo::getCouponName, keyword));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据skuId+userId查询优惠卷信息
|
||||
*
|
||||
* @param skuId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<CouponInfo> findCouponInfoList(Long skuId, Long userId) {
|
||||
//远程调用:根据skuId获取skuInfo
|
||||
SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
|
||||
|
||||
//根据条件查询:skuId + 分类id + userId
|
||||
List<CouponInfo> couponInfoList = baseMapper.selectCouponInfoList(skuInfo.getId(), skuInfo.getCategoryId(), userId);
|
||||
|
||||
return couponInfoList;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.atguigu.ssyx.activity.mapper.CouponInfoMapper">
|
||||
|
||||
<resultMap id="CouponInfoMap" type="com.atguigu.ssyx.model.activity.CouponInfo" autoMapping="true"></resultMap>
|
||||
|
||||
<!--//1 根据userId获取用户全部优惠卷-->
|
||||
<select id="selectCartCouponInfoList" resultMap="CouponInfoMap">
|
||||
select info.id,
|
||||
info.coupon_type,
|
||||
info.coupon_name,
|
||||
info.amount,
|
||||
info.condition_amount,
|
||||
info.start_time,
|
||||
info.end_time,
|
||||
info.range_type,
|
||||
info.range_desc,
|
||||
info.publish_count,
|
||||
info.per_limit,
|
||||
info.use_count,
|
||||
info.receive_count,
|
||||
info.expire_time,
|
||||
info.publish_status,
|
||||
info.create_time,
|
||||
info.update_time,
|
||||
info.is_deleted,
|
||||
cuse.coupon_status
|
||||
from coupon_use cuse
|
||||
inner join coupon_info info on cuse.coupon_id = info.id
|
||||
<where>
|
||||
and cuse.user_id = #{userId}
|
||||
and info.expire_time >= now()
|
||||
</where>
|
||||
order by info.amount desc
|
||||
</select>
|
||||
<!--//2 根据skuId+分类id+userId查询优惠卷信息-->
|
||||
<select id="selectCouponInfoList" resultMap="CouponInfoMap">
|
||||
select info.id,
|
||||
info.coupon_type,
|
||||
info.coupon_name,
|
||||
info.amount,
|
||||
info.condition_amount,
|
||||
info.start_time,
|
||||
info.end_time,
|
||||
info.range_type,
|
||||
info.range_desc,
|
||||
info.publish_count,
|
||||
info.per_limit,
|
||||
info.use_count,
|
||||
info.receive_count,
|
||||
info.expire_time,
|
||||
info.publish_status,
|
||||
info.create_time,
|
||||
info.update_time,
|
||||
info.is_deleted,
|
||||
cuse.coupon_status
|
||||
from coupon_info info
|
||||
left join coupon_range crange on info.id = crange.coupon_id
|
||||
left join coupon_use cuse on info.id = cuse.coupon_id and cuse.user_id = #{userId}
|
||||
where (info.range_type = 1 or (info.range_type = 2 and crange.range_id = #{skuId})
|
||||
or (info.range_type = 3 and crange.range_id = #{categoryId})
|
||||
)
|
||||
and info.is_deleted = 0
|
||||
and crange.is_deleted = 0
|
||||
and cuse.is_deleted = 0
|
||||
and now() between info.start_time and info.end_time
|
||||
order by info.amount desc
|
||||
</select>
|
||||
</mapper>
|
Reference in New Issue
Block a user