package com.mzl.flower.service.point.impl;
|
|
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.mzl.flower.config.exception.ValidationException;
|
import com.mzl.flower.config.security.SecurityUtils;
|
import com.mzl.flower.constant.Constants;
|
import com.mzl.flower.dto.BatchDTO;
|
import com.mzl.flower.dto.request.menber.MemberDTO;
|
import com.mzl.flower.dto.request.point.PointGoodDTO;
|
import com.mzl.flower.dto.request.point.PointGoodQueryDTO;
|
import com.mzl.flower.dto.response.content.AnnouncementDTO;
|
import com.mzl.flower.dto.response.point.PointGoodVO;
|
import com.mzl.flower.entity.content.Announcement;
|
import com.mzl.flower.entity.menber.Member;
|
import com.mzl.flower.entity.point.PointGood;
|
import com.mzl.flower.mapper.member.MemberMapper;
|
import com.mzl.flower.mapper.point.PointGoodMapper;
|
import com.mzl.flower.service.menber.MemberService;
|
import com.mzl.flower.service.point.PointGoodService;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.StringUtils;
|
|
import java.time.LocalDate;
|
import java.util.List;
|
|
/**
|
* @author fanghaowei
|
* @version version2.0
|
* @className MemberServiceImpl
|
* @date 2024/8/26
|
* @description 会员管理功能逻辑层
|
*/
|
@Service
|
@Transactional
|
@RequiredArgsConstructor
|
public class PointGoodServiceImpl extends ServiceImpl<PointGoodMapper, PointGood> implements PointGoodService {
|
|
private final PointGoodMapper pointGoodMapper;
|
|
@Override
|
public void save(PointGoodDTO pointGoodDTO) {
|
if (pointGoodDTO.getId() != null) {
|
throw new ValidationException("id必须为空");
|
}
|
if (pointGoodDTO.getStock() < 0) {
|
throw new ValidationException("库存不能小于0");
|
}
|
if (pointGoodDTO.getPoint() < 0) {
|
throw new ValidationException("积分不能小于0");
|
}
|
PointGood pointGood = new PointGood();
|
BeanUtils.copyProperties(pointGoodDTO, pointGood);
|
pointGood.setStatus(Constants.POINT_GOOD_STATUS.off.name());
|
pointGood.create(SecurityUtils.getUserId());
|
pointGoodMapper.insert(pointGood);
|
}
|
|
@Override
|
public void update(PointGoodDTO pointGoodDTO) {
|
if (pointGoodDTO.getId() == null || pointGoodDTO.getId() == 0) {
|
throw new ValidationException("id不能为空");
|
}
|
if (pointGoodDTO.getStock() < 0) {
|
throw new ValidationException("库存不能小于0");
|
}
|
if (pointGoodDTO.getPoint() < 0) {
|
throw new ValidationException("积分不能小于0");
|
}
|
PointGood pointGood = pointGoodMapper.selectById(pointGoodDTO.getId());
|
if (pointGood == null) {
|
throw new ValidationException("找不到id为" + pointGood.getId() + "的商品");
|
}
|
BeanUtils.copyProperties(pointGoodDTO, pointGood, "id", "createTime", "createBy", "deleted", "status");
|
pointGood.update(SecurityUtils.getUserId());
|
pointGoodMapper.updateById(pointGood);
|
}
|
|
@Override
|
public void batchDelete(BatchDTO batchDTO) {
|
pointGoodMapper.deleteBatchIds(batchDTO.getIds());
|
}
|
|
@Override
|
public void batchPublish(BatchDTO batchDTO) {
|
List<PointGood> list = pointGoodMapper.selectList(new LambdaQueryWrapper<PointGood>().in(PointGood::getId, batchDTO.getIds()));
|
for (PointGood pointGood : list) {
|
pointGood.setStatus(Constants.POINT_GOOD_STATUS.up.name());
|
pointGoodMapper.updateById(pointGood);
|
}
|
}
|
|
@Override
|
public void batchOff(BatchDTO batchDTO) {
|
List<PointGood> list = pointGoodMapper.selectList(new LambdaQueryWrapper<PointGood>().in(PointGood::getId, batchDTO.getIds()));
|
for (PointGood pointGood : list) {
|
pointGood.setStatus(Constants.POINT_GOOD_STATUS.off.name());
|
pointGoodMapper.updateById(pointGood);
|
}
|
}
|
|
@Override
|
public void delete(Long id) {
|
PointGood pointGood = pointGoodMapper.selectById(id);
|
if (pointGood == null) {
|
throw new ValidationException("找不到id为" + id + "的商品");
|
}
|
pointGoodMapper.deleteById(id);
|
|
}
|
|
@Override
|
public void copy(Long id) {
|
PointGood pointGoodTmp = pointGoodMapper.selectById(id);
|
if (pointGoodTmp == null) {
|
throw new ValidationException("找不到id为" + id + "的商品");
|
}
|
PointGood pointGood = new PointGood();
|
BeanUtils.copyProperties(pointGoodTmp, pointGood,"id","createTime", "createBy", "deleted", "status");
|
pointGood.setStatus(Constants.POINT_GOOD_STATUS.off.name());
|
pointGood.create(SecurityUtils.getUserId());
|
pointGoodMapper.deleteById(id);
|
|
}
|
|
@Override
|
public void changeStatus(Long id) {
|
PointGood pointGood = pointGoodMapper.selectById(id);
|
if (pointGood == null) {
|
throw new ValidationException("找不到id为" + id + "的商品");
|
}
|
if (Constants.COMMON_PUBLISH_STATUS.published.name().equals(pointGood.getStatus())) {
|
pointGood.setStatus(Constants.COMMON_PUBLISH_STATUS.unpublished.name());
|
} else {
|
pointGood.setStatus(Constants.COMMON_PUBLISH_STATUS.published.name());
|
}
|
pointGoodMapper.updateById(pointGood);
|
|
}
|
|
@Override
|
public PointGoodVO detail(Long id) {
|
PointGood pointGood = pointGoodMapper.selectById(id);
|
if (pointGood == null) {
|
return null;
|
}
|
PointGoodVO vo = new PointGoodVO();
|
BeanUtils.copyProperties(pointGood, vo);
|
return vo;
|
}
|
|
@Override
|
public Page<PointGoodVO> queryPage(PointGoodQueryDTO pointGoodQueryDTO, Page page) {
|
List<PointGoodVO> list = pointGoodMapper.queryPage(pointGoodQueryDTO, page);
|
page.setRecords(list);
|
return page;
|
}
|
}
|