陶杰
2024-08-29 b2b82c1308fd2cf71e118ab8df8258f8160f010a
src/main/java/com/mzl/flower/service/point/PointGoodsService.java
对比新文件
@@ -0,0 +1,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);
    }
}