package com.usoftchina.bi.server.controller.user;

import com.usoftchina.bi.core.base.RepCode;
import com.usoftchina.bi.core.base.RepEntity;
import com.usoftchina.bi.server.model.pojo.annotation.CheckToken;
import com.usoftchina.bi.server.model.pojo.annotation.Log;
import com.usoftchina.bi.server.model.vo.configVo.BatchUserPowerInfo;
import com.usoftchina.bi.server.model.vo.configVo.UserPowerInfo;
import com.usoftchina.bi.server.service.user.UserPowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户权限设置
 * @Author chenwei
 * @Date 2019-05-13
 */
@RestController
@Api(description = "用户权限模块相关接口")
@RequestMapping("/user/power")
public class UserPowerController {

    @Autowired
    private UserPowerService userPowerService;

    /**
     * 新增用户(组)权限
     * @param userPowerInfo
     * @return
     */
    @PostMapping("/save")
    @CheckToken
    @ApiOperation(value = "新增用户(组)报表权限", notes = "新增用户(组)报表权限", response = RepEntity.class)
    public RepEntity save(@RequestHeader String token, @RequestBody UserPowerInfo userPowerInfo){
        userPowerService.save(userPowerInfo);
        return new RepEntity(RepCode.success);
    }

    @GetMapping("/read/{type}/{id}")
    @CheckToken
    @ApiOperation(value = "获取用户(组)报表权限", notes = "获取用户(组)报表权限", response = RepEntity.class)
    public RepEntity read(@RequestHeader String token, @PathVariable("type") int type, @PathVariable("id") int id) {
        return new RepEntity(RepCode.success, userPowerService.read(type, id));
    }

    @PostMapping("/delete")
    @CheckToken
    @ApiOperation(value = "删除用户(组)报表权限", notes = "删除用户(组)报表权限", response = RepEntity.class)
    public RepEntity delete(@RequestHeader String token, @RequestBody UserPowerInfo userPowerInfo){
        userPowerService.delete(userPowerInfo);
        return new RepEntity(RepCode.success);
    }

    @PostMapping("/batchAdd")
    @CheckToken
    @ApiOperation(value = "批量新增用户(组)报表权限", notes = "批量新增用户(组)报表权限", response = RepEntity.class)
    public RepEntity batchAdd(@RequestHeader String token, @RequestBody BatchUserPowerInfo batchUserPowerInfo){
        userPowerService.batchAdd(batchUserPowerInfo);
        return new RepEntity(RepCode.success);
    }

    @PostMapping("/batchDelete")
    @CheckToken
    @ApiOperation(value = "批量删除用户(组)报表权限", notes = "批量删除用户(组)报表权限", response = RepEntity.class)
    public RepEntity batchDelete(@RequestHeader String token, @RequestBody BatchUserPowerInfo batchUserPowerInfo){
        userPowerService.batchDelete(batchUserPowerInfo);
        return new RepEntity(RepCode.success);
    }

}
