From 2c5a0e133b64bb0a46b1419c48e9b62a4779e268 Mon Sep 17 00:00:00 2001 From: cloudroam <cloudroam> Date: 星期一, 09 十二月 2024 16:13:17 +0800 Subject: [PATCH] add: 供应商子账号 --- src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java b/src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java index 14dab63..e4b4d21 100644 --- a/src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java +++ b/src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java @@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.mzl.flower.base.cache.StringCacheClient; import com.mzl.flower.config.exception.ValidationException; import com.mzl.flower.config.security.SecurityUtils; import com.mzl.flower.constant.Constants; @@ -12,10 +13,10 @@ import com.mzl.flower.dto.response.supplier.SupplierSubVO; import com.mzl.flower.entity.supplier.SupplierSub; import com.mzl.flower.entity.system.User; +import com.mzl.flower.mapper.supplier.SupplierMapper; import com.mzl.flower.mapper.supplier.SupplierSubMapper; import com.mzl.flower.mapper.system.UserMapper; import com.mzl.flower.service.BaseService; -import com.mzl.flower.utils.DateUtils; import com.mzl.flower.utils.UUIDGenerator; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; @@ -38,19 +39,39 @@ private final UserMapper userMapper; private final BaseService baseService; + private final StringCacheClient stringCacheClient; + + public static final String SMS_CODE_KEY = "SMS-CODE-KEY"; + + public static final String TOKEN_KEY = "TOKEN-KEY"; + + public static final String SEPARATOR = ":"; + + private final SupplierMapper supplierMapper; + public void addOrUpdateSupplier(SupplierSubDTO dto) { - + if (StringUtils.isEmpty(dto.getType())) { + if (StringUtils.isEmpty(dto.getSmsCode())) { + throw new ValidationException("手机验证码为空"); + } + String smsCode = dto.getSmsCode(); + //从缓存中获取验证码 + String smsCacheCode = stringCacheClient.get(SMS_CODE_KEY + SEPARATOR + Constants.USER_TYPE.supplier.name() + SEPARATOR + dto.getPhone()); + if (!org.apache.commons.lang3.StringUtils.equals(smsCode, smsCacheCode)) { + throw new ValidationException("手机验证码不正确"); + } + } SupplierSub supplierSub; if (dto.getId() == null) { - if (StringUtils.isEmpty(dto.getSupplierId())) { - throw new ValidationException("供应商主账号ID不能为空"); + SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId()); + if(ObjectUtils.isEmpty(supplierDTO)){ + throw new ValidationException("供应商信息不存在"); } - //检查该供应商下是否有名称一样的子账号 - if (checkExistName(dto.getName(), dto.getSupplierId())) { + if (checkExistName(dto.getName(), supplierDTO.getId())) { throw new ValidationException("子账号名称已存在"); } @@ -62,6 +83,7 @@ supplierSub = new SupplierSub(); BeanUtils.copyProperties(dto, supplierSub, "id"); + supplierSub.setSupplierId(supplierDTO.getId()); supplierSub.create(SecurityUtils.getUserId()); supplierSub.setIsEnabled(true); @@ -143,7 +165,7 @@ } - public Page<SupplierDTO> querySupplier(QuerySupplierSubDTO dto, Page page) { + public Page<SupplierSubVO> querySupplier(QuerySupplierSubDTO dto, Page page) { List<SupplierSubVO> list = supplierSubMapper.querySupplierSub(dto, page); page.setRecords(list); return page; @@ -200,4 +222,16 @@ supplierSubMapper.deleteById(id); } } + + public List<SupplierSub> getSubSupplier() { + SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId()); + if(ObjectUtils.isEmpty(supplierDTO)){ + throw new ValidationException("供应商信息不存在"); + } + return supplierSubMapper.getSubSupplier(String.valueOf(supplierDTO.getId())); + } + + public SupplierSub getById(Long id) { + return supplierSubMapper.selectById(id); + } } -- Gitblit v1.9.3