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.SysUserRoleEntity;
import com.mx.cneeds.server.user.service.SysUserRoleService;
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/userrole")
public class SysUserRoleController {

    @Autowired
    private SysUserRoleService sysUserRoleService;

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

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


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("sys:sysuserrole:info")
    public R info(@PathVariable("id") Long id){
        SysUserRoleEntity sysUserRole = sysUserRoleService.getById(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sys:sysuserrole:save")
    public R save(@RequestBody SysUserRoleEntity sysUserRole){
        sysUserRoleService.save(sysUserRole);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("sys:sysuserrole:update")
    public R update(@RequestBody SysUserRoleEntity sysUserRole){
        ValidatorUtils.validateEntity(sysUserRole);
        sysUserRoleService.updateById(sysUserRole);
        
        return R.ok();
    }

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

        return R.ok();
    }

}
