Cui Zhi Feng
2024-08-29 74c467fe392a71755813283e322e0d8a083ef73e
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
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.mzl.flower.service.point;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.point.PointGoodsCreateDTO;
import com.mzl.flower.dto.request.point.PointGoodsQueryDTO;
import com.mzl.flower.dto.request.point.PointGoodsUpdateDTO;
import com.mzl.flower.dto.response.point.PointGoodsDTO;
import com.mzl.flower.dto.response.point.PointGoodsListDTO;
import com.mzl.flower.entity.point.PointGoods;
import com.mzl.flower.mapper.point.PointGoodsMapper;
import com.mzl.flower.service.BaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
@Service
@Transactional
public class PointGoodsService extends BaseService {
 
    @Autowired
    private PointGoodsMapper pointGoodsMapper;
 
    public Long addPointGoods(PointGoodsCreateDTO dto){
        PointGoods p = new PointGoods();
        BeanUtils.copyProperties(dto, p);
        p.setPictures(toJSONString(dto.getPictureList()));
        p.setStatus(Constants.POINT_GOODS_STATUS.I.name());
 
        p.create(SecurityUtils.getUserId());
        pointGoodsMapper.insert(p);
 
        return p.getId();
    }
 
    public Long updatePointGoods(PointGoodsUpdateDTO dto){
        PointGoods p = pointGoodsMapper.selectById(dto.getId());
        if(p == null){
            throw new ValidationException("商品未找到");
        }
 
        BeanUtils.copyProperties(dto, p);
        p.setPictures(toJSONString(dto.getPictureList()));
 
        p.update(SecurityUtils.getUserId());
        pointGoodsMapper.updateById(p);
 
        return p.getId();
    }
 
    public void deletePointGoods(Long id){
        pointGoodsMapper.deleteById(id);
    }
 
    public Page<PointGoodsListDTO> selectGoodsList(Page page, PointGoodsQueryDTO dto){
        List<PointGoodsListDTO> ls = pointGoodsMapper.selectGoodsList(page, dto);
 
        page.setRecords(ls);
        return page;
    }
 
    public PointGoodsDTO getGoodsInfo(Long id){
        PointGoods p = pointGoodsMapper.selectById(id);
        if(p == null){
            throw new ValidationException("商品未找到");
        }
        PointGoodsDTO dto = new PointGoodsDTO();
        BeanUtils.copyProperties(p, dto);
        dto.setPictureList(parseArray(p.getPictures(), String.class));
 
        return dto;
    }
 
    public void updateStatus(Long id, String status){
        PointGoods p = pointGoodsMapper.selectById(id);
        if(p == null){
            throw new ValidationException("商品未找到");
        }
 
        p.setStatus(status);
        p.update(SecurityUtils.getUserId());
        pointGoodsMapper.updateById(p);
    }
}