陶杰
2025-01-08 ae1471f378f399f76518539ec8992e64a3673436
src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java
@@ -3,6 +3,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.GlobalSupplierVariables;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.constant.Constants;
@@ -36,6 +37,7 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -70,6 +72,8 @@
    private final PartnerService partnerService;
    private final StationService stationService;
    private final UserWechatMapper wechatMapper;
    private final GlobalSupplierVariables globalSupplierVariables;
@@ -248,20 +252,48 @@
    }
    public List<SupplierSub> getSubSupplier() {
        List<SupplierSub> supplierSubs = new ArrayList<>();
        SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId());
        if(ObjectUtils.isEmpty(supplierDTO)){
        if (ObjectUtils.isEmpty(supplierDTO)) {
            throw new ValidationException("供应商信息不存在");
        }
        return supplierSubMapper.getSubSupplier(String.valueOf(supplierDTO.getId()));
        List<SupplierSub> subSupplier = supplierSubMapper.getSubSupplier(String.valueOf(supplierDTO.getId()));
        if (!CollectionUtils.isEmpty(subSupplier)) {
            subSupplier.forEach(s -> {
                s.setIsSub(true);
                s.setType(0);
            });
            supplierSubs.addAll(subSupplier);
        }
        return supplierSubs;
    }
    public SupplierSub getById(Long id) {
        return supplierSubMapper.selectById(id);
    }
    public CurrentUserDTO getSwitchById(Long id) {
        SupplierSub supplierSub = supplierSubMapper.selectById(id);
        String userId = supplierSub.getUserId();
    public CurrentUserDTO getSwitchById(Long id, int type) {
        String userId = "";
        if (type == 1) {
            userId = SecurityUtils.getUserId();
            SupplierDTO currentSupplier = supplierMapper.getCurrentSupplier(userId);
            //切换主账号
            String supplier = globalSupplierVariables.getSupplier(String.valueOf(currentSupplier.getId()));
            if (!StringUtils.isEmpty(supplier)) {
                globalSupplierVariables.removeSupplier(String.valueOf(currentSupplier.getId()));
            }
        } else {
            SupplierSub supplierSub = supplierSubMapper.selectById(id);
            supplierSub.setType(0);
            userId = supplierSub.getUserId();
            //切换子账号
            String supplier = globalSupplierVariables.getSupplier(String.valueOf(supplierSub.getSupplierId()));
            if (!StringUtils.isEmpty(supplier)) {
                globalSupplierVariables.removeSupplier(String.valueOf(supplierSub.getSupplierId()));
            }
            globalSupplierVariables.setSupplier(String.valueOf(supplierSub.getSupplierId()), userId);
        }
        CurrentUserDTO result = new CurrentUserDTO();
@@ -319,8 +351,9 @@
            }
        }else if(Constants.USER_TYPE.supplier.name().equals(user.getType())){
            result.setSupplierDTO(supplierService.getCurrentSupplier());
            SupplierSub sub = supplierSubMapper.getCurrentSupplier(SecurityUtils.getUserId());
            SupplierSub sub = supplierSubMapper.getCurrentSupplier(userId);
            if (!ObjectUtils.isEmpty(sub)) {
                sub.setType(0);
                result.setIsSubSupplier(true);
                result.setSupplierSub(sub);
                result.setSwitchFlag(true);
@@ -344,4 +377,31 @@
    public User getUserById(String id){
        return userMapper.selectById(id);
    }
    public List<SupplierSub> getAllSupplier() {
        List<SupplierSub> supplierSubs = new ArrayList<>();
        SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId());
        if (!ObjectUtils.isEmpty(supplierDTO)) {
            SupplierSub subParent = new SupplierSub();
            subParent.setId((long) -1);
            subParent.setUserId(supplierDTO.getUserId());
            subParent.setSupplierId(supplierDTO.getId());
            subParent.setName(supplierDTO.getName());
            subParent.setContact(supplierDTO.getContactName());
            subParent.setPhone(supplierDTO.getContactTel());
            subParent.setIsEnabled(supplierDTO.getIsEnabled());
            subParent.setIsSub(false);
            subParent.setType(1);
            supplierSubs.add(subParent);
        }
        List<SupplierSub> subSupplier = supplierSubMapper.getSubSupplier(String.valueOf(supplierDTO.getId()));
        if (!CollectionUtils.isEmpty(subSupplier)) {
            subSupplier.forEach(s->{
                s.setIsSub(true);
                s.setType(0);
            });
            supplierSubs.addAll(subSupplier);
        }
        return supplierSubs;
    }
}