package com.keyware.shandan.control.controller;

import com.keyware.shandan.bianmu.entity.DirectoryVo;
import com.keyware.shandan.bianmu.service.DirPermissionService;
import com.keyware.shandan.bianmu.service.DirectoryService;
import com.keyware.shandan.common.controller.BaseController;
import com.keyware.shandan.common.enums.SystemTypes;
import com.keyware.shandan.frame.config.security.SecurityUtil;
import com.keyware.shandan.system.entity.SysSetting;
import com.keyware.shandan.system.entity.SysUser;
import com.keyware.shandan.system.utils.SysSettingUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 目录表 前端控制器
 * </p>
 *
 * @author GuoXin
 * @since 2021-06-01
 */
@RestController
@RequestMapping("/business/directory")
public class DirectoryController extends BaseController<DirectoryService, DirectoryVo, String> {

    @Autowired
    private DirPermissionService dirPermissionService;

    @GetMapping("/")
    public ModelAndView index(ModelAndView modelAndView) {
        modelAndView.setViewName("directory/directory");

        dirPermissionService.refreshCache();
        SysUser user = SecurityUtil.getLoginSysUser();
        modelAndView.addObject("readDirIds", dirPermissionService.getByReadPermis(user));
        modelAndView.addObject("writeDirIds", dirPermissionService.getByWritePermis(user));

        SysSetting bianmuSetting = SysSettingUtil.getSysSetting(SystemTypes.BIANMU.name());
        modelAndView.addObject("bianmuAddress", bianmuSetting.getSysAddress());
        return modelAndView;
    }

}
