liyanqi
2022-09-15 34de42f43fd75a31fe0c0d51adf30fb554ad5fa6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.ycl.service.platform.store.impl;
 
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.entity.platform.store.StoreScoreRule;
import com.ycl.exception.ApiException;
import com.ycl.mapper.platform.store.StoreScoreRuleMapper;
import com.ycl.service.platform.store.StoreScoreRuleService;
import com.ycl.vo.store.StoreScoreRuleVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
/**
 * <p>
 * 商铺积分规则管理 服务实现类
 * </p>
 *
 * @author lyq
 * @since 2022-09-14
 */
@Service
public class StoreScoreRuleServiceImpl extends ServiceImpl<StoreScoreRuleMapper, StoreScoreRule> implements StoreScoreRuleService {
 
    @Override
    public Page<StoreScoreRule> list(String keyword, Integer pageSize, Integer pageNum) {
        Page<StoreScoreRule> page = new Page<>(pageSize, pageNum);
        LambdaQueryWrapper<StoreScoreRule> wrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotEmpty(keyword)) {
            wrapper.like(StoreScoreRule::getCategory, keyword);
        }
        wrapper.orderByDesc(StoreScoreRule::getCategory);
        return page(page, wrapper);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(StoreScoreRuleVO.AddScoreVO addScoreVO) {
        StoreScoreRule build = StoreScoreRule.builder()
                .category(addScoreVO.getCategory())
                .deductionItem(addScoreVO.getDeductionItem())
                .markScore(addScoreVO.getMarkScore()).build();
        boolean save = save(build);
        if (!save) {
            throw new ApiException("添加失败");
        }
    }
}