cloudroam
2024-12-10 6ee2a947a786edad9eb19a5401de7fcc456b90a6
add: 供应商子账号4
已修改2个文件
已添加1个文件
83 ■■■■■ 文件已修改
src/main/java/com/mzl/flower/config/GlobalSupplierVariables.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/system/UserService.java 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/config/GlobalSupplierVariables.java
对比新文件
@@ -0,0 +1,39 @@
package com.mzl.flower.config;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.HashMap;
import java.util.Map;
@Component
public class GlobalSupplierVariables {
    private final Map<String, String> supplierMap = new HashMap<>();
    @PostConstruct
    public void init() {
        // 初始化操作,如果需要的话
        System.out.println("Application started, initializing supplier map...");
    }
    @PreDestroy
    public void cleanup() {
        // 清理操作
        supplierMap.clear();
        System.out.println("Application shutting down, clearing supplier map...");
    }
    public String getSupplier(String supplierId) {
        return supplierMap.get(supplierId);
    }
    public void setSupplier(String supplierId, String userId) {
        supplierMap.put(supplierId, userId);
    }
    public void removeSupplier(String supplierId) {
        supplierMap.remove(supplierId);
    }
}
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;
@@ -71,6 +72,8 @@
    private final PartnerService partnerService;
    private final StationService stationService;
    private final UserWechatMapper wechatMapper;
    private final GlobalSupplierVariables globalSupplierVariables;
@@ -274,10 +277,22 @@
        String userId = "";
        if (type == 1) {
            userId = SecurityUtils.getUserId();
        }else {
            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();
src/main/java/com/mzl/flower/service/system/UserService.java
@@ -3,12 +3,14 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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;
import com.mzl.flower.dto.request.BindWechatDTO;
import com.mzl.flower.dto.request.system.*;
import com.mzl.flower.dto.response.current.CurrentUserDTO;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
import com.mzl.flower.dto.response.system.EmployeeDTO;
import com.mzl.flower.dto.response.system.MenuTreeDTO;
import com.mzl.flower.dto.response.system.UserDetailsDTO;
@@ -18,6 +20,7 @@
import com.mzl.flower.entity.system.*;
import com.mzl.flower.enums.TrueOrFalseEnum;
import com.mzl.flower.mapper.point.CustomerPointMapper;
import com.mzl.flower.mapper.supplier.SupplierMapper;
import com.mzl.flower.mapper.supplier.SupplierSubMapper;
import com.mzl.flower.mapper.system.*;
import com.mzl.flower.service.customer.CustomerService;
@@ -89,6 +92,12 @@
    @Autowired
    private SupplierSubMapper supplierSubMapper;
    @Autowired
    private SupplierMapper supplierMapper;
    @Autowired
    private  GlobalSupplierVariables globalSupplierVariables;
    public User findUserByOpenId(String openId, String sessionKey, String unionId
            , String imgUrl, String nickname,String userType){
@@ -148,6 +157,7 @@
    }
    public CurrentUserDTO getCurrentUser() {
        String userId = SecurityUtils.getUserId();
        CurrentUserDTO result = new CurrentUserDTO();
@@ -216,16 +226,23 @@
        }else if(Constants.USER_TYPE.supplier.name().equals(user.getType())){
            result.setSupplierDTO(supplierService.getCurrentSupplier());
            SupplierSub sub = supplierSubMapper.getCurrentSupplier(SecurityUtils.getUserId());
            SupplierDTO dto = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId());
            String tempUserId = globalSupplierVariables.getSupplier(String.valueOf(dto.getId()));
            if (!ObjectUtils.isEmpty(sub)) {
                result.setIsSubSupplier(true);
                result.setSupplierSub(sub);
                //可切换
                result.setSwitchFlag(false);
            } else {
                result.setIsSubSupplier(false);
                result.setSupplierSub(null);
                //不可切换
                result.setSwitchFlag(true);
                if (!StringUtils.isBlank(tempUserId)) {
                    SupplierSub temSub = supplierSubMapper.getCurrentSupplier(tempUserId);
                    result.setIsSubSupplier(true);
                    result.setSupplierSub(temSub);
                    result.setSwitchFlag(true);
                } else {
                    result.setIsSubSupplier(false);
                    result.setSupplierSub(null);
                    result.setSwitchFlag(true);
                }
            }
        }else if(Constants.USER_TYPE.partner.name().equals(user.getType())){
            result.setPartnerDTO(partnerService.getCurrentPartner());