package com.keyware.shandan.basicdata.controller;

import com.keyware.shandan.bianmu.service.DirPermissionService;
import com.keyware.shandan.common.util.StringUtils;
import com.keyware.shandan.frame.config.security.SecurityUtil;
import com.keyware.shandan.system.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * 基础数据目录管理前端控制器
 *
 * @author GuoXin
 * @date 2022-10-31
 */
@Slf4j
@RestController
@RequestMapping("/basic-data")
public class BasicDataDirectoryController {

    @Autowired
    private DirPermissionService dirPermissionService;

    @GetMapping("/view/index")
    public ModelAndView index(ModelAndView mav, @RequestParam(required = false) String browser) {
        mav.setViewName("business/directory/directory-basicdata");
        dirPermissionService.refreshCache();
        SysUser user = SecurityUtil.getLoginSysUser();
        mav.addObject("readDirIds", dirPermissionService.getByReadPermis(user));
        mav.addObject("writeDirIds", dirPermissionService.getByWritePermis(user));
        mav.addObject("browser", StringUtils.hasText(browser));
        return mav;
    }
}
