陶杰
2025-01-08 ae1471f378f399f76518539ec8992e64a3673436
src/main/java/com/mzl/flower/web/login/SupplierLoginController.java
@@ -5,6 +5,7 @@
import com.mzl.flower.base.R;
import com.mzl.flower.base.ReturnDataDTO;
import com.mzl.flower.base.cache.StringCacheClient;
import com.mzl.flower.config.GlobalSupplierVariables;
import com.mzl.flower.config.exception.BaseException;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.config.security.token.PhoneAuthenticationToken;
@@ -12,8 +13,10 @@
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.UserLoginDTO;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
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.service.login.LoginService;
import com.mzl.flower.service.system.UserService;
import io.swagger.annotations.Api;
@@ -65,6 +68,14 @@
    @Autowired
    private SupplierMapper supplierMapper;
    @Autowired
    private SupplierSubMapper supplierSubMapper;
    @Autowired
    private GlobalSupplierVariables globalSupplierVariables;
    public static final String SMS_CODE_KEY = "SMS-CODE-KEY";
    public static final String TOKEN_KEY = "TOKEN-KEY";
@@ -87,12 +98,30 @@
        if(user == null){
            throw new ValidationException("用户不存在");
        }
        SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(user.getId());
        if (ObjectUtils.isEmpty(supplierDTO)) {
            throw new ValidationException("用户不存在");
        }
        if (supplierDTO.getIsEnabled() == false) {
            throw new ValidationException("用户已禁用,请联系管理员");
        // 子账号校验:1.不存在->放行。
        // 2.存在->校验是否已经禁用。
        // 3.存在且未禁用->校验父级账号是否禁用。
        // 4.父级禁用->提示
        // 5.父级未禁用->保存子账号token并返回
        SupplierSub supplierSub = supplierSubMapper.getCurrentSupplier(user.getId());
        if (supplierSub != null) {
            if (supplierSub.getIsEnabled() == false) {
                throw new ValidationException("子账号已禁用");
            }else{
                //这里拿父级供应商ID查询用户ID再校验
                SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(String.valueOf( supplierSub.getSupplierId()));
                if (supplierDTO != null && supplierDTO.getIsEnabled() == false) {
                    throw new ValidationException("账号用户已禁用,请联系管理员");
                }
            }
        }else {
            SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(user.getId());
            if (!ObjectUtils.isEmpty(supplierDTO)) {
                globalSupplierVariables.removeSupplier(String.valueOf(supplierDTO.getId()));
            }
            if (supplierDTO != null && supplierDTO.getIsEnabled() == false) {
                throw new ValidationException("用户已禁用,请联系管理员");
            }
        }
        String tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + user.getId());
        if (StringUtils.isNotBlank(tokenCache))  {
@@ -137,6 +166,28 @@
        if(user == null){
            throw new ValidationException("用户不存在");
        }
        // 子账号校验:1.不存在->放行。
        // 2.存在->校验是否已经禁用。
        // 3.存在且未禁用->校验父级账号是否禁用。
        // 4.父级禁用->提示
        // 5.父级未禁用->保存子账号token并返回
        SupplierSub supplierSub = supplierSubMapper.getCurrentSupplier(user.getId());
        if (supplierSub != null) {
            if (supplierSub.getIsEnabled() == false) {
                throw new ValidationException("子账号已禁用,请联系父级账号");
            } else {
                //这里拿父级供应商ID查询用户ID再校验
                SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(String.valueOf(supplierSub.getSupplierId()));
                if (supplierDTO != null && supplierDTO.getIsEnabled() == false) {
                    throw new ValidationException("父级账号用户已禁用,请联系管理员");
                }
            }
        } else {
            SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(user.getId());
            if (supplierDTO != null && supplierDTO.getIsEnabled() == false) {
                throw new ValidationException("用户已禁用,请联系管理员");
            }
        }
        String tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + user.getId());
        if (StringUtils.isNotBlank(tokenCache))  {
            //强制删除token,下线