微信小程序分类查询(优惠券错误)完成
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.atguigu.ssyx.activity.api;
|
||||
|
||||
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 javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ClassName: ActivityInfoController
|
||||
* Package: com.atguigu.ssyx.activity.api
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/26 14:12
|
||||
*/
|
||||
@Api(tags = "促销与优惠券接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/activity")
|
||||
@Slf4j
|
||||
public class ActivityApiController {
|
||||
|
||||
@Resource
|
||||
private ActivityInfoService activityInfoService;
|
||||
|
||||
@ApiOperation(value = "根据skuId列表获取促销信息")
|
||||
@PostMapping("inner/findActivity")
|
||||
public Map<Long, List<String>> findActivity(@RequestBody List<Long> skuIdList) {
|
||||
return activityInfoService.findActivity(skuIdList);
|
||||
}
|
||||
}
|
@@ -19,7 +19,19 @@ import java.util.List;
|
||||
@Repository
|
||||
public interface ActivityInfoMapper extends BaseMapper<ActivityInfo> {
|
||||
|
||||
List<ActivityRule> selectActivityRuleList(Long skuId);
|
||||
|
||||
/**
|
||||
* 查询两张表判断 activity_info 和 activity_sku,编写SQL语句实现
|
||||
*
|
||||
* @param skuIdList
|
||||
* @return
|
||||
*/
|
||||
List<Long> selectSkuIdListExist(@Param("skuIdList") List<Long> skuIdList);
|
||||
|
||||
/**
|
||||
* 根据skuId进行查询,查询sku对应活动里面规则列表
|
||||
*
|
||||
* @param skuId
|
||||
* @return
|
||||
*/
|
||||
List<ActivityRule> findActivityRule(Long skuId);
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@ package com.atguigu.ssyx.activity.service;
|
||||
|
||||
|
||||
import com.atguigu.ssyx.model.activity.ActivityInfo;
|
||||
import com.atguigu.ssyx.model.activity.ActivityRule;
|
||||
import com.atguigu.ssyx.model.product.SkuInfo;
|
||||
import com.atguigu.ssyx.vo.activity.ActivityRuleVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -55,10 +54,10 @@ public interface ActivityInfoService extends IService<ActivityInfo> {
|
||||
List<SkuInfo> findSkuInfoByKeyword(String keyword);
|
||||
|
||||
/**
|
||||
* 根据skuId获取促销规则信息
|
||||
* 根据skuId列表获取促销信息
|
||||
*
|
||||
* @param skuId
|
||||
* @param skuIdList
|
||||
* @return
|
||||
*/
|
||||
List<ActivityRule> findActivityRule(Long skuId);
|
||||
Map<Long, List<String>> findActivity(List<Long> skuIdList);
|
||||
}
|
||||
|
@@ -172,23 +172,6 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
|
||||
return findSkuList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品获取规则数据
|
||||
*
|
||||
* @param skuId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ActivityRule> findActivityRule(Long skuId) {
|
||||
List<ActivityRule> activityRuleList = activityInfoMapper.selectActivityRuleList(skuId);
|
||||
if (!CollectionUtils.isEmpty(activityRuleList)) {
|
||||
for (ActivityRule activityRule : activityRuleList) {
|
||||
activityRule.setRuleDesc(this.getRuleDesc(activityRule));
|
||||
}
|
||||
}
|
||||
return activityRuleList;
|
||||
}
|
||||
|
||||
private String getRuleDesc(ActivityRule activityRule) {
|
||||
ActivityType activityType = activityRule.getActivityType();
|
||||
StringBuffer ruleDesc = new StringBuffer();
|
||||
@@ -207,4 +190,32 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
|
||||
}
|
||||
return ruleDesc.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据skuId列表获取促销信息
|
||||
*
|
||||
* @param skuIdList
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<Long, List<String>> findActivity(List<Long> skuIdList) {
|
||||
Map<Long, List<String>> result = new HashMap<>();
|
||||
//skuIdList遍历,得到每个skuId
|
||||
skuIdList.forEach(skuId -> {
|
||||
//根据skuId进行查询,查询sku对应活动里面规则列表
|
||||
List<ActivityRule> activityRuleList = baseMapper.findActivityRule(skuId);
|
||||
//数据封装,规则名称
|
||||
if (!CollectionUtils.isEmpty(activityRuleList)) {
|
||||
List<String> ruleList = new ArrayList<>();
|
||||
//把规则名称处理
|
||||
for (ActivityRule activityRule : activityRuleList) {
|
||||
ruleList.add(this.getRuleDesc(activityRule));
|
||||
}
|
||||
result.put(skuId, ruleList);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -58,13 +58,13 @@
|
||||
|
||||
<!--//根据skuId进行查询,查询sku对应活动里面规则列表-->
|
||||
<select id="findActivityRule" resultMap="ActivityRuleMap">
|
||||
select info.activity_type as activityType,
|
||||
rule.id,
|
||||
rule.activity_id,
|
||||
rule.condition_amount,
|
||||
rule.condition_num,
|
||||
rule.benefit_amount,
|
||||
rule.benefit_discount
|
||||
select DISTINCT rule.id,
|
||||
info.activity_type as activityType,
|
||||
rule.activity_id,
|
||||
rule.condition_amount,
|
||||
rule.condition_num,
|
||||
rule.benefit_amount,
|
||||
rule.benefit_discount
|
||||
from activity_info info
|
||||
inner join activity_sku sku on info.id = sku.activity_id
|
||||
inner join activity_rule rule on info.id = rule.activity_id
|
||||
@@ -89,6 +89,4 @@
|
||||
</where>
|
||||
and now() between info.start_time and info.end_time
|
||||
</select>
|
||||
<select id="selectActivityRuleList" resultType="com.atguigu.ssyx.model.activity.ActivityRule"></select>
|
||||
|
||||
</mapper>
|
||||
|
Reference in New Issue
Block a user