| | |
| | | package com.mzl.flower.service; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.mzl.flower.base.cache.MarkupCacheClient; |
| | | 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.entity.payment.OrderItemSales; |
| | | import com.mzl.flower.entity.payment.OrderSalesItem; |
| | | import com.mzl.flower.entity.supplier.Supplier; |
| | | import com.mzl.flower.entity.supplier.SupplierSub; |
| | | import com.mzl.flower.mapper.customer.CustomerMapper; |
| | | import com.mzl.flower.mapper.flower.FlowerCategoryMapper; |
| | | import com.mzl.flower.mapper.member.MemberMapper; |
| | | import com.mzl.flower.mapper.partner.PartnerMapper; |
| | | import com.mzl.flower.mapper.supplier.SupplierMapper; |
| | | import com.mzl.flower.mapper.supplier.SupplierSubMapper; |
| | | import com.mzl.flower.mapper.system.UserMapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.security.oauth2.common.OAuth2AccessToken; |
| | | import org.springframework.security.oauth2.common.OAuth2RefreshToken; |
| | | import org.springframework.security.oauth2.provider.token.TokenStore; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import static java.time.format.DateTimeFormatter.BASIC_ISO_DATE; |
| | | |
| | | @Service |
| | | public class BaseService { |
| | | |
| | | @Autowired |
| | |
| | | |
| | | @Autowired |
| | | protected SupplierMapper supplierMapper; |
| | | |
| | | @Autowired |
| | | protected SupplierSubMapper supplierSubMapper; |
| | | |
| | | @Autowired |
| | | protected PartnerMapper partnerMapper; |
| | |
| | | protected Member getMember(Long levelId){ |
| | | return memberMapper.selectById(levelId); |
| | | } |
| | | |
| | | @Autowired |
| | | private StringCacheClient stringCacheClient; |
| | | |
| | | @Autowired |
| | | private TokenStore tokenStore; |
| | | |
| | | public static final String TOKEN_KEY = "TOKEN-KEY"; |
| | | |
| | | public static final String SEPARATOR = ":"; |
| | | |
| | | protected double getServiceFeeRate(List<FeeService> fees, Integer saleCount){ |
| | | int sc = saleCount == null ? 0 : saleCount; |
| | |
| | | BigDecimal feePlatformPack = getAmount(s.getFeePlatformPack()); |
| | | BigDecimal feePlatformCheck = getAmount(s.getFeePlatformCheck()); |
| | | BigDecimal feePlatformTransport = getAmount(s.getFeePlatformTransport()); |
| | | BigDecimal feePackingTransport = getAmount(s.getFeePackingTransport()); |
| | | |
| | | BigDecimal b = platformSalesMap.get(orderItemId); |
| | | if (b == null) { |
| | | b = new BigDecimal(0); |
| | | } |
| | | b = b.add(feePlatform).add(feePlatformPack).add(feePlatformCheck).add(feePlatformTransport); |
| | | b = b.add(feePlatform).add(feePlatformPack).add(feePlatformCheck) |
| | | .add(feePlatformTransport).add(feePackingTransport); |
| | | platformSalesMap.put(orderItemId, b); |
| | | } |
| | | } |
| | |
| | | return p; |
| | | } |
| | | |
| | | public Supplier getCurrentSupplier(){ |
| | | public Supplier getCurrentSupplier() { |
| | | String userId = SecurityUtils.getUserId(); |
| | | Supplier s = supplierMapper.selectOne(new QueryWrapper<Supplier>() |
| | | .eq("user_id", userId)); |
| | | if(s == null){ |
| | | throw new ValidationException("供应商信息未认证,请到个人中心进行认证"); |
| | | if (s == null) { |
| | | SupplierSub sub = supplierSubMapper.getCurrentSupplier(SecurityUtils.getUserId()); |
| | | if (!ObjectUtils.isEmpty(sub)) { |
| | | s = supplierMapper.selectById(sub.getSupplierId()); |
| | | return s; |
| | | } else { |
| | | throw new ValidationException("供应商信息未认证,请到个人中心进行认证"); |
| | | } |
| | | } |
| | | |
| | | return s; |
| | | } |
| | | |
| | |
| | | return null; |
| | | } |
| | | |
| | | public void removeToken(String userId) { |
| | | String tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + userId); |
| | | if (StringUtils.isNotBlank(tokenCache)) { |
| | | //强制删除token,下线 |
| | | if (StringUtils.isNotBlank(tokenCache) && StringUtils.isNotBlank(userId)) { |
| | | stringCacheClient.delete(TOKEN_KEY + SEPARATOR + userId); |
| | | String tokenValue = tokenCache.replace(OAuth2AccessToken.BEARER_TYPE, StrUtil.EMPTY).trim(); |
| | | OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue); |
| | | if (accessToken != null && StringUtils.isNotBlank(accessToken.getValue())) { |
| | | tokenStore.removeAccessToken(accessToken); |
| | | OAuth2RefreshToken refreshToken = accessToken.getRefreshToken(); |
| | | tokenStore.removeRefreshToken(refreshToken); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |