RoleController.java 2.06 KB
package com.bsth.controller.sys;

import com.bsth.controller.BaseController;
import com.bsth.entity.sys.Role;
import com.bsth.service.sys.RoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;

@RestController
@RequestMapping("role")
public class RoleController extends BaseController<Role, Integer> {

    static Logger logger = LoggerFactory.getLogger(RoleController.class);

    @Autowired
    RoleService roleService;

    /**
     * menu 菜单json
     */
    private static String authJson;

    static {
        loadAuthStrByFile();
    }

    private static void loadAuthStrByFile() {
        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(RoleController.class.getClassLoader().getResourceAsStream("auths.json")));

            StringBuilder sb = new StringBuilder();

            String lineStr;

            while ((lineStr = br.readLine()) != null) {
                sb.append(lineStr);
            }

            authJson = sb.toString();

        } catch (Exception e) {
            logger.error("", e);
        }
    }


    @RequestMapping("auth_json")
    public String authJsonStr() {
        return authJson;
    }

    @RequestMapping("re_load")
    public int reLoadByFile() {
        loadAuthStrByFile();
        return 1;
    }

    @RequestMapping(value = "saveAuthStr", method = RequestMethod.POST)
    public Map<String, Object> saveAuthStr(@RequestParam String authStr, @RequestParam int id){
        return roleService.saveAuthStr(authStr, id);
    }

    @RequestMapping(value = "add", method = RequestMethod.POST)
    public Map<String, Object> add(@RequestParam String roleName){
        return roleService.add(roleName);
    }
}