| | |
| | | package com.mzl.flower.service.menber.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.constant.Constants; |
| | | import com.mzl.flower.dto.request.menber.MemberDTO; |
| | | import com.mzl.flower.dto.request.menber.MemberQueryDTO; |
| | | import com.mzl.flower.dto.response.member.MemberVO; |
| | | import com.mzl.flower.entity.menber.Member; |
| | | import com.mzl.flower.mapper.member.MemberMapper; |
| | | import com.mzl.flower.service.menber.MemberService; |
| | | 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.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author fanghaowei |
| | |
| | | * @description 会员管理功能逻辑层 |
| | | */ |
| | | @Service |
| | | @Transactional |
| | | @RequiredArgsConstructor |
| | | public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService { |
| | | |
| | |
| | | if (StringUtils.isEmpty(member.getName())) { |
| | | throw new ValidationException("会员等级名称不能为空"); |
| | | } |
| | | |
| | | if (member.getStartPoint() > member.getEndPoint()) { |
| | | throw new ValidationException("成长点开始不能大于结束"); |
| | | } |
| | | if (!StringUtils.isEmpty(member.getDiscountRatio())) { |
| | | int discountRatio1 = member.getDiscountRatio().compareTo(BigDecimal.ZERO); |
| | | if (discountRatio1 == -1) { |
| | | throw new ValidationException("会员折扣百分比不能小于0"); |
| | | } |
| | | int discountRatio2 = member.getDiscountRatio().compareTo(new BigDecimal(100)); |
| | | if (discountRatio2 == 1) { |
| | | throw new ValidationException("会员折扣百分比不能大于100"); |
| | | } |
| | | } |
| | | if (!StringUtils.isEmpty(member.getDiscountAmount())) { |
| | | int discountAmount = member.getDiscountAmount().compareTo(BigDecimal.ZERO); |
| | | if (discountAmount == -1) { |
| | | throw new ValidationException("会员折扣固定金额不能小于0"); |
| | | } |
| | | } |
| | | |
| | | //保存时判断是否有重复的名称 |
| | | Member memberByName = memberMapper.getMemberByName(member.getName()); |
| | | if (!ObjectUtils.isEmpty(memberByName)) { |
| | |
| | | if (memberInfo == null) { |
| | | throw new ValidationException("会员等级信息不存在"); |
| | | } |
| | | if (!memberInfo.getCreateBy().equals(SecurityUtils.getUserId())) { |
| | | throw new ValidationException("无权限修改"); |
| | | } |
| | | // if (!memberInfo.getCreateBy().equals(SecurityUtils.getUserId())) { |
| | | // throw new ValidationException("无权限修改"); |
| | | // } |
| | | Member memberTemp = memberMapper.getMemberByName(memberDTO.getName()); |
| | | //判断如果按照会员等级查询到得名称和当前得Id不一致,不能修改。 |
| | | if (!ObjectUtils.isEmpty(memberTemp)) { |
| | |
| | | |
| | | @Override |
| | | public void deleteMember(String id) { |
| | | if(id.equals(Constants.DEFAULT_MEMBER_ID)){ |
| | | throw new ValidationException("默认普通会员只能编辑,不能删除"); |
| | | } |
| | | Member member = memberMapper.selectById(id); |
| | | if (member == null) { |
| | | throw new ValidationException("会员等级信息不存在"); |
| | |
| | | // TODO: 2024/8/26 如果当前会员绑定了优惠券,不能删除,等优惠券逻辑完成。 |
| | | memberMapper.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | | public Page<MemberVO> queryPage(MemberQueryDTO memberQueryDTO, Page page) { |
| | | List<MemberVO> list = memberMapper.queryPage(memberQueryDTO, page); |
| | | page.setRecords(list); |
| | | return page; |
| | | } |
| | | } |