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

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

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.SysUserFuncEntity;
import com.mx.cneeds.server.user.service.SysUserFuncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 功能与角色映射表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-03-16 11:22:10
 */
@RestController
@RequestMapping("sys/userfunc")
public class SysUserFuncController {
    @Autowired
    private SysUserFuncService sysUserFuncService;

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

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


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        SysUserFuncEntity sysUserFunc = sysUserFuncService.getById(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SysUserFuncEntity sysUserFunc){
        sysUserFuncService.save(sysUserFunc);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SysUserFuncEntity sysUserFunc){
        ValidatorUtils.validateEntity(sysUserFunc);
        sysUserFuncService.updateById(sysUserFunc);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        sysUserFuncService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
