package com.qmth.paper.library.common.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.qmth.boot.core.enums.Platform;
import com.qmth.boot.core.solar.model.AppInfo;
import com.qmth.boot.core.solar.model.OrgInfo;
import com.qmth.boot.core.solar.service.SolarService;
import com.qmth.paper.library.common.bean.auth.AuthBean;
import com.qmth.paper.library.common.bean.auth.ExpireTimeBean;
import com.qmth.paper.library.common.bean.dto.AuthOrgInfoDto;
import com.qmth.paper.library.common.bean.dto.MenuDto;
import com.qmth.paper.library.common.bean.dto.MenuPrivilegeDto;
import com.qmth.paper.library.common.bean.dto.OrgDto;
import com.qmth.paper.library.common.bean.dto.syssetting.SimpleObject;
import com.qmth.paper.library.common.bean.result.*;
import com.qmth.paper.library.common.contant.SysSettingConstant;
import com.qmth.paper.library.common.contant.SystemConstant;
import com.qmth.paper.library.common.entity.*;
import com.qmth.paper.library.common.enums.*;
import com.qmth.paper.library.common.service.*;
import com.qmth.paper.library.common.util.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: 公共服务service impl
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2021/3/26
 */
@Service
public class LibraryCommonServiceImpl implements LibraryCommonService {
    private final static Logger log = LoggerFactory.getLogger(LibraryCommonServiceImpl.class);

    @Resource
    CommonCacheService commonCacheService;

    @Resource
    BasicSchoolService basicSchoolService;

    @Resource
    SysUserRoleService sysUserRoleService;

    @Resource
    SysPrivilegeService sysPrivilegeService;

    @Resource
    SysRolePrivilegeService sysRolePrivilegeService;

    @Resource
    SysRoleService sysRoleService;

    @Resource
    TBSessionService tbSessionService;

    @Autowired
    private SysOrgService sysOrgService;

    @Resource
    LibraryCommonService commonService;

    @Resource
    FileStoreUtil fileStoreUtil;

    @Resource
    SysUserService sysUserService;

    @Resource
    SolarService solarService;

    /**
     * 获取用户菜单
     *
     * @param userId
     * @return
     */
    @Override
    public MenuResult getUserMenu(Long userId) {
        SysUser sysUser = sysUserService.getById(userId);
        List<SysUserRole> sysUserRoleList = getUserRolePrivilege(userId);
        List<SysRolePrivilege> sysRolePrivilegeList = new ArrayList<>();
        for (SysUserRole s : sysUserRoleList) {
            SysRole sysRole = sysRoleService.getById(s.getRoleId());
            if (Objects.nonNull(sysRole) && sysRole.getEnable()) {
                sysRolePrivilegeList.addAll(getRolePrivilege(s.getRoleId()));
            }
        }
        Set<Long> privilegeIds = sysRolePrivilegeList.stream().map(SysRolePrivilege::getPrivilegeId).collect(Collectors.toSet());
        QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
        sysPrivilegeQueryWrapper.lambda()
                .eq(SysPrivilege::getEnable, true).eq(SysPrivilege::getFrontDisplay, true)
                .orderByAsc(SysPrivilege::getSequence);

        if (!privilegeIds.isEmpty()) {
            sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds);
        }
        List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
        Gson gson = new Gson();
        List<MenuDto> menuDtoList = gson.fromJson(JacksonUtil.parseJson(sysPrivilegeList), new TypeToken<List<MenuDto>>() {
        }.getType());
        LinkedMultiValueMap<Long, MenuDto> linkedMultiValueMap = new LinkedMultiValueMap<>();
        List<MenuPrivilegeDto> menuPrivilegeDtoList = new ArrayList<>();
        for (MenuDto m : menuDtoList) {
            if (Objects.isNull(m.getParentId()) || m.getType() == PrivilegeEnum.MENU) {
                menuPrivilegeDtoList.add(gson.fromJson(gson.toJson(m), MenuPrivilegeDto.class));
            } else {
                if (!linkedMultiValueMap.containsKey(m.getParentId())) {
                    linkedMultiValueMap.add(m.getParentId(), m);
                } else {
                    List<MenuDto> menuDtos = linkedMultiValueMap.get(m.getParentId());
                    menuDtos.add(m);
                    linkedMultiValueMap.put(m.getParentId(), menuDtos);
                }
            }
        }
        for (MenuPrivilegeDto m : menuPrivilegeDtoList) {
            List<MenuDto> menuDtos = linkedMultiValueMap.get(m.getId());
            List<MenuDto> urls = null, buttons = null, links = null, lists = null, conditions = null;
            if (Objects.nonNull(menuDtos)) {
                for (MenuDto menuDto : menuDtos) {
                    if (menuDto.getType() == PrivilegeEnum.BUTTON) {
                        buttons = Objects.isNull(buttons) ? new ArrayList<>() : buttons;
                        buttons.add(gson.fromJson(gson.toJson(menuDto), MenuPrivilegeDto.class));
                        m.setButtons(buttons);
                    } else if (menuDto.getType() == PrivilegeEnum.LINK) {
                        links = Objects.isNull(links) ? new ArrayList<>() : links;
                        links.add(gson.fromJson(gson.toJson(menuDto), MenuPrivilegeDto.class));
                        m.setLinks(links);
                    } else if (menuDto.getType() == PrivilegeEnum.URL) {
                        urls = Objects.isNull(urls) ? new ArrayList<>() : urls;
                        urls.add(gson.fromJson(gson.toJson(menuDto), MenuPrivilegeDto.class));
                        m.setUrls(urls);
                    } else if (menuDto.getType() == PrivilegeEnum.LIST) {
                        lists = Objects.isNull(lists) ? new ArrayList<>() : lists;
                        lists.add(gson.fromJson(gson.toJson(menuDto), MenuPrivilegeDto.class));
                        m.setLists(lists);
                    } else if (menuDto.getType() == PrivilegeEnum.CONDITION) {
                        conditions = Objects.isNull(conditions) ? new ArrayList<>() : conditions;
                        conditions.add(gson.fromJson(gson.toJson(menuDto), MenuPrivilegeDto.class));
                        m.setConditions(conditions);
                    }
                }
            }
        }
        return new MenuResult(sysUser.getId(), menuPrivilegeDtoList);
    }

    /**
     * 新增用户权限
     *
     * @param sysUser
     * @param roleIds
     */
    @Override
    public void addUserRolePrivilege(SysUser sysUser, Long[] roleIds) {
        List<SysUserRole> sysUserRoleList = new ArrayList<>();
        for (int i = 0; i < roleIds.length; i++) {
            sysUserRoleList.add(new SysUserRole(sysUser.getId(), roleIds[i]));
        }
        sysUserRoleService.saveBatch(sysUserRoleList);
    }


    /**
     * 获取用户角色权限
     *
     * @param userId
     * @return
     */
    @Override
    public List<SysUserRole> getUserRolePrivilege(Long userId) {
        QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<>();
        sysUserRoleQueryWrapper.lambda().eq(SysUserRole::getUserId, userId)
                .eq(SysUserRole::getEnable, true);
        return sysUserRoleService.list(sysUserRoleQueryWrapper);
    }

    /**
     * 获取角色权限
     *
     * @param roleId
     * @return
     */
    @Override
    public List<SysRolePrivilege> getRolePrivilege(Long roleId) {
        QueryWrapper<SysRolePrivilege> sysRolePrivilegeQueryWrapper = new QueryWrapper<>();
        sysRolePrivilegeQueryWrapper.lambda().eq(SysRolePrivilege::getRoleId, roleId);
        return sysRolePrivilegeService.list(sysRolePrivilegeQueryWrapper);
    }

    /**
     * 获取用户权限
     *
     * @param userId
     * @return
     */
    @Override
    public AuthBean getUserAuth(Long userId) {
        AuthBean authBean = null;
        try {
            SysUser user = sysUserService.getById(userId);
            if (Objects.isNull(user)) {
                throw ExceptionResultEnum.USER_NO_DATA.exception();
            }
            //查询用户角色和权限
            List<SysUserRole> sysUserRoleList = getUserRolePrivilege(user.getId());
            if (Objects.nonNull(sysUserRoleList) && sysUserRoleList.size() > 0) {
                Set<Long> roleIds = sysUserRoleList.stream().map(s -> s.getRoleId()).collect(Collectors.toSet());
                List<SysRolePrivilege> sysRolePrivilegeList = new ArrayList<>();
                for (Long l : roleIds) {
                    sysRolePrivilegeList.addAll(getRolePrivilege(l));
                }
                Set<Long> privilegeIds = sysRolePrivilegeList.stream().map(s -> s.getPrivilegeId()).collect(Collectors.toSet());
                QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
                sysRoleQueryWrapper.lambda().in(SysRole::getId, roleIds)
                        .eq(SysRole::getEnable, true);
                List<SysRole> sysRoleList = sysRoleService.list(sysRoleQueryWrapper);
                int count = Objects.nonNull(sysRoleList) && sysRoleList.size() > 0 ? (int) sysRoleList.stream().filter(s -> Objects.equals(s.getName(), RoleTypeEnum.ADMIN.getDesc())).count() : 0;
                QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
                if (count > 0) {//超级系统管理员
//                    Long schoolId = Long.parseLong(ServletUtil.getRequestSchoolByNotVaild().toString());
                    sysPrivilegeQueryWrapper.lambda()
//                            .eq(SysPrivilege::getSchoolId, schoolId)
                            .eq(SysPrivilege::getType, PrivilegeEnum.URL)
                            .eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
                    List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
                    authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()));
                } else {
                    BasicSchool tbSchool = Objects.nonNull(user.getSchoolId()) ? basicSchoolService.getById(user.getSchoolId()) : null;
                    SysOrg org = Objects.nonNull(user.getOrgId()) ? sysOrgService.getById(user.getOrgId()) : null;
                    List<SysPrivilege> sysPrivilegeList = new ArrayList<>();
                    if (privilegeIds.size() > 0) {
                        sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds)
                                .eq(SysPrivilege::getType, PrivilegeEnum.URL)
                                .eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
                        sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
                    }
//                    if (Objects.isNull(tbSchool)) {
//                        sysPrivilegeQueryWrapper.lambda().isNull(SysPrivilege::getSchoolId);
//                    } else {
//                        sysPrivilegeQueryWrapper.lambda().eq(SysPrivilege::getSchoolId, user.getSchoolId());
//                    }
                    authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()), tbSchool, org);
                }
            }
        } catch (Exception e) {
            log.error(SystemConstant.LOG_ERROR, e);
            throw ExceptionResultEnum.ERROR.exception("添加用户鉴权缓存失败");
        }
        return authBean;
    }

    /**
     * 获取鉴权url
     *
     * @param privilegePropertyEnum
     * @param schoolId
     * @return
     */
    @Override
    public Set<String> getPrivilegeUrl(PrivilegePropertyEnum privilegePropertyEnum, Long schoolId) {
        QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
        sysPrivilegeQueryWrapper.lambda().eq(SysPrivilege::getType, PrivilegeEnum.URL)
                .eq(SysPrivilege::getProperty, privilegePropertyEnum)
                .eq(SysPrivilege::getEnable, true)
                .eq(SysPrivilege::getDefaultAuth, true);
//                .eq(SysPrivilege::getSchoolId, schoolId);
        List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
        return Objects.nonNull(sysPrivilegeList) && sysPrivilegeList.size() > 0 ? sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()) : null;
    }

    /**
     * 删除用户信息
     *
     * @param userId
     * @param all
     */
    @Override
    public void removeUserInfo(Long userId, boolean all) throws NoSuchAlgorithmException {
        AuthBean authBean = getUserAuth(userId);
        if (Objects.isNull(authBean)) {
            throw ExceptionResultEnum.NOT_LOGIN.exception();
        }
        if (all) {
            for (Platform p : Platform.values()) {
                Set<String> roleNamesSet = authBean.getRoleList().stream().map(s -> s.getName()).collect(Collectors.toSet());
                List<String> roleNames = new ArrayList<>();
                roleNames.addAll(roleNamesSet);
                Collections.sort(roleNames);
                String sessionId = SessionUtil.digest(userId, Math.abs(roleNames.toString().hashCode()), p.name());
                tbSessionService.removeById(sessionId);
            }
        } else {
            TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
            tbSessionService.removeById(tbSession.getId());
        }
    }

    /**
     * 批量删除用户信息
     *
     * @param userIds
     * @param all
     */
    @Override
    public void removeUserInfoBatch(List<Long> userIds, boolean all) {
        if (!CollectionUtils.isEmpty(userIds)) {
            new Thread(() -> {
                if (all) {
                    Set<String> sessionIdSet = new HashSet<>(Platform.values().length * userIds.size());
                    int min = 0;
                    int max = SystemConstant.IN_SIZE_MAX, size = userIds.size();
                    if (max >= size) {
                        max = size;
                    }
                    while (max <= size) {
                        List<UserRoleNameResult> userRoleNameResultList = sysUserService.selectRoleNames(userIds.subList(min, max));
                        for (UserRoleNameResult userRoleNameResult : userRoleNameResultList) {
                            List<String> roleNames = Arrays.asList(userRoleNameResult.getRoleNames().split(","));
                            Collections.sort(roleNames);
                            for (Platform p : Platform.values()) {
                                String sessionId = null;
                                try {
                                    sessionId = SessionUtil.digest(userRoleNameResult.getUserId(), Math.abs(roleNames.toString().hashCode()), p.name());
                                } catch (NoSuchAlgorithmException e) {
                                    e.printStackTrace();
                                }
                                sessionIdSet.add(sessionId);
                            }
                        }
                        if (max == size) {
                            break;
                        }
                        min = max;
                        max += SystemConstant.IN_SIZE_MAX;
                        if (max >= size) {
                            max = size;
                        }
                    }
                    tbSessionService.removeByIds(sessionIdSet);
                } else {
                    TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
                    tbSessionService.removeById(tbSession.getId());
                }
            }).start();
        }
    }

    /**
     * 文件预览
     *
     * @param path
     * @return
     */
    @Override
    public String filePreview(String path) {
        String url = null;
        JSONObject jsonObject = JSONObject.parseObject(path);
        String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
        String filePath = (String) jsonObject.get(SystemConstant.PATH);
        if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
            String hostUrl = commonCacheService.getSysSettingGlobal().get(SysSettingConstant.SYS_FILE_HOST_URL);
            filePath = SystemConstant.getLocalFilePath(hostUrl, filePath);
            if (filePath.startsWith("/")) {
                url = hostUrl + filePath;
            } else {
                url = hostUrl + File.separator + filePath;
            }
        } else {
            UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
            url = fileStoreUtil.getFileUrl(filePath);
        }
        url = url.replaceAll("\\\\", "/");
        return url;
    }

    public String preViewPath(String path, String uploadType, String type, Boolean isExpire) {
        if (StringUtils.isBlank(path)) {
            return null;
        }
        String pathUrl;
        // 本地文件
        if (Objects.equals(type, SystemConstant.LOCAL)) {
            String hostUrl = commonCacheService.getSysSettingGlobal().get(SysSettingConstant.SYS_FILE_HOST_URL);
            path = SystemConstant.getLocalFilePath(hostUrl, path);
            if (path.startsWith("/")) {
                pathUrl = hostUrl + path;
            } else {
                pathUrl = hostUrl + File.separator + path;
            }
        } else {
            if (isExpire) {
                pathUrl = fileStoreUtil.getFileUrl(path);
            } else {
                pathUrl = fileStoreUtil.getFileUrl(path);
            }
        }
        return pathUrl;
    }


    @Override
    public Set<Long> listSubOrgIds(Long id) {
        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
        Long orgId;
        if (id == null) {
            orgId = sysUser.getOrgId();
        } else {
            orgId = id;
        }
        if (orgId == null) {
            return null;
        }
        List<OrgDto> orgDtos = sysOrgService.listOrgTree();
        Set<Long> stringSet = new HashSet<>();
        stringSet.add(orgId);
        stringSet = getOrgIds(stringSet, orgDtos, orgId);
        return stringSet;
    }

    /**
     * 登录公用
     *
     * @param password
     * @param sysUser
     * @param appSource
     * @return
     * @throws NoSuchAlgorithmException
     */
    @Override
    public LoginResult login(String password, SysUser sysUser, AppSourceEnum appSource) throws NoSuchAlgorithmException {
        //停用
        if (!sysUser.getEnable()) {
            throw ExceptionResultEnum.USER_ENABLE.exception();
        }

        Platform platform = ServletUtil.getRequestPlatform();
        String deviceId = ServletUtil.getRequestDeviceId();
        AuthBean authBean = commonService.getUserAuth(sysUser.getId());
        //添加用户鉴权缓存
        if (Objects.isNull(authBean)) {
            throw ExceptionResultEnum.ROLE_ENABLE_AUTHORIZATION.exception();
        }
        //生成token
        String token = SystemConstant.getUuid();
        //添加用户会话缓存
        Set<String> roleNamesSet = new HashSet<>(), roleTypes = new HashSet<>();
        List<RoleResult> roleSource = new ArrayList<>();
        for (SysRole s : authBean.getRoleList()) {
            roleNamesSet.add(s.getName());
            if (Objects.isNull(s.getSource()) && Objects.nonNull(s.getType())) {
                roleTypes.add(s.getType().name());
            }
            roleSource.add(Objects.nonNull(s.getType()) ? new RoleResult(s.getId(), s.getName(), s.getType().name(), s.getSource()) : new RoleResult(s.getId(), s.getName(), s.getSource()));
        }
        List<String> roleNames = new ArrayList<>();
        roleNames.addAll(roleNamesSet);
        Collections.sort(roleNames);
        String sessionId = SessionUtil.digest(sysUser.getId(), Math.abs(roleNames.toString().hashCode()), platform.name());
        ExpireTimeBean expireTime = AuthUtil.getExpireTime(platform);
        TBSession tbSession = new TBSession(sysUser.getSchoolId(), sessionId, String.valueOf(sysUser.getId()), roleNames.toString(),
                platform.name(), platform.name(), deviceId, ServletUtil.getRequest().getLocalAddr(), token,
                expireTime.getDate().getTime(), appSource);
        tbSessionService.saveOrUpdate(tbSession);
        commonCacheService.saveTbSession(sessionId, tbSession);

        LoginResult loginResult = new LoginResult(sysUser, sessionId, token, Objects.nonNull(roleTypes) && roleTypes.size() > 0 ? roleTypes : roleNamesSet, appSource, roleSource);
        loginResult.setSchoolInfo(Objects.nonNull(authBean.getSchool()) ? loginResult.new SchoolNativeBean(authBean.getSchool()) : null);
        loginResult.setOrgInfo(Objects.nonNull(authBean.getOrg()) ? loginResult.new OrgNativeBean(authBean.getOrg()) : null);
        loginResult.setTime(System.currentTimeMillis());
        String mobileNumber = sysUser.getMobileNumber();
        int pwdCount = sysUser.getPwdCount();
        if (roleTypes.contains(RoleTypeEnum.ADMIN.name())) {
            mobileNumber = sysUser.getLoginName() + "（特殊权限）";
            pwdCount = 1;
        }
        loginResult.setUserLoginCheckResult(new UserLoginCheckResult(sysUser.getId(), mobileNumber, pwdCount));

        if(sysUser.getSchoolId() != null) {
            // 设置条码识别参数
            Map<String, SimpleObject> stringStringMap = commonCacheService.getSysSetting(sysUser.getSchoolId());
            loginResult.setOpenBarCode(!stringStringMap.containsKey(SysSettingConstant.RECOGNITION_TYPE) ? false : RecognitionTypeEnum.BAR_CODE.name().equals(stringStringMap.get(SysSettingConstant.RECOGNITION_TYPE).getValue()));
        } else {
            loginResult.setOpenBarCode(false);
        }
        return loginResult;
    }

    private Set<Long> getOrgIds(Set<Long> stringSet, List<OrgDto> orgDtos, Long parentId) {
        for (OrgDto orgDto : orgDtos) {
            Long tempParentId = orgDto.getParentId();
            if (parentId.equals(tempParentId) && stringSet.contains(parentId)) {
                stringSet.add(Long.valueOf(orgDto.getId()));
            }
            if (orgDto.getChildren().isEmpty()) {
                continue;
            }
            getOrgIds(stringSet, orgDto.getChildren(), Long.valueOf(orgDto.getId()));
        }
        return stringSet;
    }

    public static void outputFile(HttpServletResponse response, File file, String fileName) {
        try {

            if (!file.exists()) {
                response.sendError(404, "File not found!");
            }

            BufferedInputStream br = new BufferedInputStream(new FileInputStream(file));
            byte[] buf = new byte[1024];
            int len = 0;

            String fName = new String(fileName.getBytes(), "ISO-8859-1");

            response.reset();
            response.setContentType("application/x-msdownload");
            response.setHeader("Content-Disposition", "attachment; filename=" + fName);

            OutputStream outStream = response.getOutputStream();

            while ((len = br.read(buf)) > 0) {
                outStream.write(buf, 0, len);
            }

            br.close();
            outStream.close();
        } catch (FileNotFoundException e) {
            log.error(SystemConstant.LOG_ERROR, e);
        } catch (IOException e) {
            log.error(SystemConstant.LOG_ERROR, e);
        }
    }

    public AuthOrgInfoDto authInfoCache(String code) {
        AppInfo appInfo = solarService.getAppInfo();
        AuthOrgInfoDto authOrgInfoDto = null;
        if (Objects.nonNull(appInfo)) {
            List<OrgInfo> orgInfoList = solarService.getOrgList().stream().filter(s -> Objects.equals(s.getCode(), code)).collect(Collectors.toList());
            if (Objects.nonNull(orgInfoList) && orgInfoList.size() > 0) {
                authOrgInfoDto = new AuthOrgInfoDto(orgInfoList.get(0), appInfo.getControl());
            }
        }
        return authOrgInfoDto;
    }

    @Override
    public void flushCache(String type) {
        if (type.equals(FlushCacheTypeEnum.SYS_SETTING.name())) {
            Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
            commonCacheService.removeSysSetting(schoolId);
            commonCacheService.getSysSetting(schoolId);
        } else if (type.equals(FlushCacheTypeEnum.SYS_SETTING_GLOBAL.name())) {
            commonCacheService.removeSysSettingGlobal();
            commonCacheService.getSysSettingGlobal();
        } else {
            throw ExceptionResultEnum.ERROR.exception("请传入正确的缓存类型");
        }
    }
}
