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.SysUserDeptEntity;
import com.mx.cneeds.server.user.service.SysUserDeptService;
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/userdept")
public class SysUserDeptController {
    @Autowired
    private SysUserDeptService sysUserDeptService;

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

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


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        SysUserDeptEntity sysUserDept = sysUserDeptService.getById(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SysUserDeptEntity sysUserDept){
        sysUserDeptService.save(sysUserDept);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SysUserDeptEntity sysUserDept){
        ValidatorUtils.validateEntity(sysUserDept);
        sysUserDeptService.updateById(sysUserDept);
        
        return R.ok();
    }

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

        return R.ok();
    }

}
