package com.mx.cneeds.server.user.web;

import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.common.result.R;
import com.mx.cneeds.common.validator.ValidatorUtils;
import com.mx.cneeds.server.entity.SysRoleFuncEntity;
import com.mx.cneeds.server.user.service.SysRoleFuncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 功能与角色映射表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-01-09 15:09:01
 */
@RestController
@RequestMapping("sys/rolefunc")
public class SysRoleFuncController {
    @Autowired
    private SysRoleFuncService sysRoleFuncService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("sys:sysrolefunc:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysRoleFuncService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("sys:sysrolefunc:info")
    public R info(@PathVariable("id") Long id){
        SysRoleFuncEntity sysRoleFunc = sysRoleFuncService.getById(id);

        return R.ok().put("sysRoleFunc", sysRoleFunc);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sys:sysrolefunc:save")
    public R save(@RequestBody SysRoleFuncEntity sysRoleFunc){
        sysRoleFuncService.save(sysRoleFunc);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("sys:sysrolefunc:update")
    public R update(@RequestBody SysRoleFuncEntity sysRoleFunc){
        ValidatorUtils.validateEntity(sysRoleFunc);
        sysRoleFuncService.updateById(sysRoleFunc);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("sys:sysrolefunc:delete")
    public R delete(@RequestBody Long[] ids){
        sysRoleFuncService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
