package com.microservices.dms.achievementLibrary.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.page.TableDataInfo;
import com.microservices.dms.achievementLibrary.domain.BlockchainListQueryVo;
import com.microservices.dms.achievementLibrary.domain.TokenListVo;
import com.microservices.dms.achievementLibrary.domain.blockchain.InBlockchainData;
import com.microservices.dms.achievementLibrary.domain.blockchain.InLinkProjectVo;
import com.microservices.dms.achievementLibrary.domain.blockchain.UserVo;
import com.microservices.dms.achievementLibrary.service.BlockChainService;
import com.microservices.dms.achievementLibrary.service.InBlockchainDataServiceImpl;
import com.microservices.dms.common.vo.UserCreateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/blockChain")
@Api(tags = "数据管理体系-数据产权子系统")
public class BlockChainController extends BaseController {

    @Autowired
    private BlockChainService blockChainService;

    @Autowired
    private InBlockchainDataServiceImpl inBlockchainDataService;

    @GetMapping("/projectTokenList")
    @ApiOperation(value = "项目token列表")
    public TableDataInfo projectTokenList(String projectName) {
        startPage();
        List<TokenListVo> list = blockChainService.projectTokenList(projectName);
        return getDataTable(list);
    }

    @GetMapping("/projectTokenDistribute")
    @ApiOperation(value = "项目token分配、点击token分配按钮，弹出框展示相关数据（项目名称、分配token、被分配人）")
    public AjaxResult projectTokenDistribute(InLinkProjectVo projectVo) {
        return blockChainService.projectTokenDistribute(projectVo);
    }

    @GetMapping("/issueDataList")
    @ApiOperation(value = "入链issue列表")
    public TableDataInfo issueDataList(BlockchainListQueryVo queryVo) {
        startPage();
        List<Map<String, Object>> list = blockChainService.issueDataList(queryVo);
        return getDataTable(list);
    }


    @GetMapping("/commitDataList")
    @ApiOperation(value = "入链commit列表")
    public TableDataInfo commitDataList(BlockchainListQueryVo queryVo) {
        startPage();
        List<Map<String, Object>> list = blockChainService.commitDataList(queryVo);
        return getDataTable(list);
    }

    @GetMapping("/prDataList")
    @ApiOperation(value = "入链PR列表")
    public TableDataInfo prDataList(BlockchainListQueryVo queryVo) {
        startPage();
        List<Map<String, Object>> list = blockChainService.prDataList(queryVo);
        return getDataTable(list);
    }

    @GetMapping("/userDataList")
    @ApiOperation(value = "入链user列表")
    public TableDataInfo userDataList(BlockchainListQueryVo queryVo) {
        List<Map> list = blockChainService.userDataList(queryVo);
        return getDataTable(list);
    }


    @GetMapping("/userList")
    @ApiOperation(value = "用户列表列表")
    public TableDataInfo userList(UserVo userVo) {
        startPage();
        List<UserVo> list = blockChainService.userList(userVo);
        return getDataTable(list);
    }


    @GetMapping("/InBlockchainDataList")
    @ApiOperation(value = "查询区块链数据入链列表")
    public TableDataInfo list(InBlockchainData inBlockchainData) {
        startPage();
        List<InBlockchainData> list = inBlockchainDataService.selectInBlockchainDataList(inBlockchainData);
        return getDataTable(list);
    }

    @ApiOperation("提供入链项目信息查询")
    @GetMapping("/queryBlockInfo")
    public AjaxResult queryBlockInfo (String type,String typeId) {
        return blockChainService.queryBlockInfo(type,typeId);
    }

    @ApiOperation("根据项目id获取用户对应的token")
    @GetMapping("/getUserTokenByProjectId")
    public AjaxResult getUserTokenByProjectId (String type,String userName,String tokenName) {
        return blockChainService.getUserTokenByProjectId(type,userName,tokenName);
    }

    @ApiOperation("获取用户对应的所有项目token")
    @GetMapping("/getUserAllProjectToken")
    public AjaxResult getUserAllProjectToken (String userName) {
        return blockChainService.getUserAllProjectToken(userName);
    }

}