feat(新增): 新增活动规则,根据关键字获取sku列表,活动使用
This commit is contained in:
parent
eb22d344b3
commit
a6db5a7600
|
@ -24,4 +24,8 @@ public interface ProductFeignClient {
|
||||||
// 根据skuId得到sku信息列表
|
// 根据skuId得到sku信息列表
|
||||||
@PostMapping("inner/findSkuInfoList")
|
@PostMapping("inner/findSkuInfoList")
|
||||||
Result<List<SkuInfo>> findSkuInfoList(@RequestBody List<Long> skuIdList);
|
Result<List<SkuInfo>> findSkuInfoList(@RequestBody List<Long> skuIdList);
|
||||||
|
|
||||||
|
// 根据关键字获取sku列表
|
||||||
|
@GetMapping("inner/findSkuInfoByKeyword/{keyword}")
|
||||||
|
Result<List<SkuInfo>> findSkuInfoByKeyword(@PathVariable("keyword") String keyword);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.atguigu.ssyx.model.activity.ActivityInfo;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 活动表 Mapper 接口
|
* 活动表 Mapper 接口
|
||||||
|
@ -15,4 +17,11 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ActivityInfoMapper extends BaseMapper<ActivityInfo> {
|
public interface ActivityInfoMapper extends BaseMapper<ActivityInfo> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断添加商品之前是否参加过活动
|
||||||
|
*
|
||||||
|
* @param skuIdList skuId
|
||||||
|
* @return List<Long>
|
||||||
|
*/
|
||||||
|
List<Long> selectSkuIdListExist(List<Long> skuIdList);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ 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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,6 +24,7 @@ import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, ActivityInfo> implements ActivityInfoService {
|
public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, ActivityInfo> implements ActivityInfoService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProductFeignClient productFeignClient;
|
private ProductFeignClient productFeignClient;
|
||||||
|
@ -57,10 +59,17 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> findActivityRuleList(Long id) {
|
public Map<String, Object> findActivityRuleList(Long id) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
List<ActivityRule> activityInfoList = activityRuleMapper.selectList(Wrappers.<ActivityRule>lambdaQuery().eq(ActivityRule::getActivityId, id));
|
|
||||||
|
// 活动信息列表
|
||||||
|
List<ActivityRule> activityInfoList = activityRuleMapper.selectList(
|
||||||
|
Wrappers.<ActivityRule>lambdaQuery().eq(ActivityRule::getActivityId, id)
|
||||||
|
);
|
||||||
result.put("activityRuleList", activityInfoList);
|
result.put("activityRuleList", activityInfoList);
|
||||||
|
|
||||||
List<ActivitySku> activitySkuList = activitySkuMapper.selectList(Wrappers.<ActivitySku>lambdaQuery().eq(ActivitySku::getActivityId, id));
|
// 查询活动列表
|
||||||
|
List<ActivitySku> activitySkuList = activitySkuMapper.selectList(
|
||||||
|
Wrappers.<ActivitySku>lambdaQuery().eq(ActivitySku::getActivityId, id)
|
||||||
|
);
|
||||||
List<Long> skuIdList = activitySkuList.stream().map(ActivitySku::getSkuId).collect(Collectors.toList());
|
List<Long> skuIdList = activitySkuList.stream().map(ActivitySku::getSkuId).collect(Collectors.toList());
|
||||||
|
|
||||||
// 通过远程调用根据skuId得到商品信息
|
// 通过远程调用根据skuId得到商品信息
|
||||||
|
@ -72,11 +81,33 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
|
||||||
/**
|
/**
|
||||||
* 新增活动规则
|
* 新增活动规则
|
||||||
*
|
*
|
||||||
* @param activityRuleVo 活动规则
|
* @param vo 活动规则
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void saveActivityRule(ActivityRuleVo activityRuleVo) {
|
public void saveActivityRule(ActivityRuleVo vo) {
|
||||||
|
Long activityId = vo.getActivityId();
|
||||||
|
List<ActivityRule> activityRuleList = vo.getActivityRuleList();
|
||||||
|
List<ActivitySku> activitySkuList = vo.getActivitySkuList();
|
||||||
|
|
||||||
|
// 根据id查询活动信息
|
||||||
|
ActivityInfo activityInfo = getById(activityId);
|
||||||
|
|
||||||
|
// 删除之前规则数据
|
||||||
|
activityRuleMapper.delete(Wrappers.<ActivityRule>lambdaQuery().eq(ActivityRule::getActivityId, activityId));
|
||||||
|
activitySkuMapper.delete(Wrappers.<ActivitySku>lambdaQuery().eq(ActivitySku::getActivityId, activityId));
|
||||||
|
|
||||||
|
// 获取规则列表数据
|
||||||
|
activityRuleList.forEach(activityRule -> {
|
||||||
|
activityRule.setActivityId(activityId);
|
||||||
|
activityRule.setActivityType(activityInfo.getActivityType());
|
||||||
|
activityRuleMapper.insert(activityRule);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取规则范围数据
|
||||||
|
activitySkuList.forEach(activitySku -> {
|
||||||
|
activitySku.setActivityId(activityId);
|
||||||
|
activitySkuMapper.insert(activitySku);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,6 +118,16 @@ public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, Act
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SkuInfo> findSkuInfoByKeyword(String keyword) {
|
public List<SkuInfo> findSkuInfoByKeyword(String keyword) {
|
||||||
return null;
|
// 根据关键字查询sku匹配内容
|
||||||
|
List<SkuInfo> skuInfoList = productFeignClient.findSkuInfoByKeyword(keyword).getData();
|
||||||
|
List<Long> skuIdList = skuInfoList.stream().map(SkuInfo::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 判断添加商品之前是否参加过活动
|
||||||
|
List<Long> existSkuIdList = baseMapper.selectSkuIdListExist(skuIdList);
|
||||||
|
// 如果参加的话就剔除
|
||||||
|
skuInfoList.removeIf(skuInfo -> existSkuIdList.contains(skuInfo.getId()));
|
||||||
|
|
||||||
|
// 返回结果
|
||||||
|
return skuInfoList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,17 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!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.ActivityInfoMapper">
|
<mapper namespace="com.atguigu.ssyx.activity.mapper.ActivityInfoMapper">
|
||||||
|
<!-- 判断添加商品之前是否参加过活动 -->
|
||||||
|
<select id="selectSkuIdListExist" resultType="java.lang.Long">
|
||||||
|
select *
|
||||||
|
from activity_info info
|
||||||
|
inner join activity_sku sku on info.id = sku.activity_id
|
||||||
|
<if test="skuIdList != null">
|
||||||
|
where sku.sku_id in
|
||||||
|
<foreach collection="skuIdList" item="skuId" open="(" close=")" separator=",">
|
||||||
|
#{skuId}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
and now() between info.start_time and info.end_time
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -41,4 +41,11 @@ public class ProductInnerController {
|
||||||
List<SkuInfo> skuInfoList = skuInfoService.findSkuInfoList(skuIdList);
|
List<SkuInfo> skuInfoList = skuInfoService.findSkuInfoList(skuIdList);
|
||||||
return Result.success(skuInfoList);
|
return Result.success(skuInfoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "根据关键字获取sku列表")
|
||||||
|
@GetMapping("inner/findSkuInfoByKeyword/{keyword}")
|
||||||
|
public Result<List<SkuInfo>> findSkuInfoByKeyword(@PathVariable("keyword") String keyword) {
|
||||||
|
List<SkuInfo> skuInfoList = skuInfoService.findSkuInfoByKeyword(keyword);
|
||||||
|
return Result.success(skuInfoList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,4 +81,12 @@ public interface SkuInfoService extends IService<SkuInfo> {
|
||||||
* @return List<SkuInfo>
|
* @return List<SkuInfo>
|
||||||
*/
|
*/
|
||||||
List<SkuInfo> findSkuInfoList(List<Long> skuIdList);
|
List<SkuInfo> findSkuInfoList(List<Long> skuIdList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据关键字获取sku列表
|
||||||
|
*
|
||||||
|
* @param keyword 关键字
|
||||||
|
* @return List<SkuInfo>
|
||||||
|
*/
|
||||||
|
List<SkuInfo> findSkuInfoByKeyword(String keyword);
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,4 +234,15 @@ public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoMapper, SkuInfo> impl
|
||||||
public List<SkuInfo> findSkuInfoList(List<Long> skuIdList) {
|
public List<SkuInfo> findSkuInfoList(List<Long> skuIdList) {
|
||||||
return baseMapper.selectBatchIds(skuIdList);
|
return baseMapper.selectBatchIds(skuIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据关键字获取sku列表
|
||||||
|
*
|
||||||
|
* @param keyword 关键字
|
||||||
|
* @return List<SkuInfo>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SkuInfo> findSkuInfoByKeyword(String keyword) {
|
||||||
|
return list(Wrappers.<SkuInfo>lambdaQuery().like(SkuInfo::getSkuName, keyword));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue