Cui Zhi Feng
2024-08-29 9f1412bc3afa8f16d13d9948b547c8748e02869a
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.mzl.flower.service.point.impl;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.dto.request.point.CustomerPointDetailDTO;
import com.mzl.flower.dto.request.point.CustomerPointDetailQueryDTO;
import com.mzl.flower.dto.response.point.CustomerPointDetailVO;
import com.mzl.flower.entity.point.CustomerPointDetail;
import com.mzl.flower.mapper.point.CustomerPointDetailMapper;
import com.mzl.flower.service.point.CustomerPointDetailService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * @author fanghaowei
 * @version version2.0
 * @className MemberServiceImpl
 * @date 2024/8/26
 * @description 积分记录
 */
@Service
@Transactional
@RequiredArgsConstructor
public class CustomerPointDetailServiceImpl extends ServiceImpl<CustomerPointDetailMapper, CustomerPointDetail> implements CustomerPointDetailService {
 
    private final CustomerPointDetailMapper customerPointDetailMapper;
 
    @Override
    public void save(CustomerPointDetailDTO customerPointDetailDTO) {
        if (customerPointDetailDTO.getId() != null) {
            throw new ValidationException("id必须为空");
        }
        CustomerPointDetail customerPointDetail = new CustomerPointDetail();
        BeanUtils.copyProperties(customerPointDetailDTO, customerPointDetail);
        customerPointDetail.create(SecurityUtils.getUserId());
        customerPointDetailMapper.insert(customerPointDetail);
    }
 
    @Override
    public void update(CustomerPointDetailDTO customerPointDetailDTO) {
        if (customerPointDetailDTO.getId() == null || customerPointDetailDTO.getId() == 0) {
            throw new ValidationException("id不能为空");
        }
        CustomerPointDetail customerPointDetail = customerPointDetailMapper.selectById(customerPointDetailDTO.getId());
        if (customerPointDetail == null) {
            throw new ValidationException("找不到id为" + customerPointDetail.getId() + "的积分记录");
        }
        BeanUtils.copyProperties(customerPointDetailDTO, customerPointDetail, "id", "createTime", "createBy", "deleted", "status");
        customerPointDetail.update(SecurityUtils.getUserId());
        customerPointDetailMapper.updateById(customerPointDetail);
    }
 
 
    @Override
    public void delete(Long id) {
        CustomerPointDetail customerPointDetail = customerPointDetailMapper.selectById(id);
        if (customerPointDetail == null) {
            throw new ValidationException("找不到id为" + id + "的积分记录");
        }
        customerPointDetailMapper.deleteById(id);
 
    }
 
    @Override
    public Page<CustomerPointDetailVO> queryPage(CustomerPointDetailQueryDTO customerPointDetailQueryDTO, Page page) {
        List<CustomerPointDetailVO> list = customerPointDetailMapper.queryPage(customerPointDetailQueryDTO, page);
        page.setRecords(list);
        return page;
    }
}