package com.kcim.web;

import com.kcim.common.util.Result;
import com.kcim.service.UserReportRightService;
import com.kcim.service.UserResponsibilityRightService;
import com.kcim.vo.UserReportRightVO;
import com.kcim.vo.UserResponsibilityRightVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户报表权限相关操作
 */
@RestController
@RequestMapping("/userReportRight")
@Api(tags = "用户报表权限相关操作")
public class UserReportRightController {
    @Autowired
    private UserReportRightService userReportRightService;
    @Autowired
    private UserResponsibilityRightService userResponsibilityRightService;


    @GetMapping("/getUserReports")
    @ApiOperation("查询用户有权限的损益报表")
    public Result getUserReports(){
        return Result.ok(userReportRightService.getUserReports());
    }

    @ApiOperation("获取用户列表")
    @GetMapping("/getUserList")
    public Result getUserList(@RequestParam(value = "current", defaultValue = "1") Integer current,
                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                              @RequestParam(value = "name", required = false) String userName) {
        return Result.ok(userReportRightService.getUserList(current,pageSize,userName));
    }

    @ApiOperation("获取用户损益报表权限列表")
    @GetMapping("/getUserReportRights")
    public Result getUserReportRights(@RequestParam(value = "userId") Long userId,
                                      @RequestParam(value = "reportName", required = false) String reportName,
                                      @RequestParam(value = "hideFlag", defaultValue = "0") Integer hideFlag) {
        return Result.ok(userReportRightService.getUserReportRights(userId,reportName,hideFlag));
    }

    @ApiOperation("修改用户损益报表权限")
    @PostMapping("/editUserReportRight")
    public Result editUserReportRight(@RequestBody UserReportRightVO userReportRightVO) {
        userReportRightService.editUserReportRight(userReportRightVO);
        return Result.ok();
    }

    /**
     * 获取用户责任中心权限列表
     * @param responsibilityName 责任呢中心代码/名称
     * @param hideFlag
     * @return
     */
    @ApiOperation("获取用户责任中心权限列表")
    @GetMapping("/getUserResponsibilityRights")
    public Result getUserResponsibilityRights(@RequestParam(value = "userId") Long userId,
                                              @RequestParam(value = "responsibilityName", required = false) String responsibilityName,
                                              @RequestParam(value = "hideFlag", defaultValue = "0") Integer hideFlag) {
        return Result.ok(userResponsibilityRightService.getUserResponsibilityRights(userId,responsibilityName,hideFlag));
    }

    @ApiOperation("修改用户损益报表权限")
    @PostMapping("/editUserResponsibilityRight")
    public Result editUserResponsibilityRight(@RequestBody UserResponsibilityRightVO uerResponsibilityRightVO) {
        userResponsibilityRightService.editUserResponsibilityRight(uerResponsibilityRightVO);
        return Result.ok();
    }

    @ApiOperation("修改用户的所有损益报表权限")
    @PostMapping("/editAllUserResponsibilityRight")
    public Result editAllUserResponsibilityRight(@RequestParam(value = "userId") Long userId,
                                                @RequestParam(value = "allRightFlag", defaultValue = "0") Integer allRightFlag) {
        userResponsibilityRightService.editAllUserResponsibilityRight(userId,allRightFlag);
        return Result.ok();
    }

}
