| | |
| | | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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.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("子账号名称已存在"); |
| | | } |
| | | |