package com.ruoyi.ibs.cmpm.controller;

import com.github.pagehelper.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataPageInfo;
import com.ruoyi.ibs.cmpm.domain.dto.*;
import com.ruoyi.ibs.cmpm.domain.vo.GridCmpmClaimVO;
import com.ruoyi.ibs.cmpm.domain.vo.GridCmpmTransferVO;
import com.ruoyi.ibs.cmpm.service.GridCmpmTransferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 吴凯程
 * @Date 2025/10/20
 **/
@Api(tags = "绩效网格移交")
@RestController
@RequestMapping("/grid/cmpm/transfer")
public class GridCmpmTransferController extends BaseController {

    @Resource
    private GridCmpmTransferService gridCmpmTransferService;


    @PostMapping("/create")
    @Log(title = "绩效网格-创建关系移交审批")
    @ApiOperation("创建关系移交审批")
    public AjaxResult create(@RequestBody GridCmpmTransferDTO gridCmpmTransferDTO) {
        return success(gridCmpmTransferService.createGridCmpmTransfer(gridCmpmTransferDTO));
    }

    @PostMapping("/create/claim")
    @Log(title = "绩效网格-创建客户经理认领审批")
    @ApiOperation("创建客户经理认领审批")
    public AjaxResult createClaim(@RequestBody GridCmpmClaimDTO gridCmpmClaimDTO) {
        return success(gridCmpmTransferService.createClaim(gridCmpmClaimDTO));
    }

    @PostMapping("/create/common/claim")
    @Log(title = "绩效网格-创建公共池认领审批")
    @ApiOperation("创建公共池认领审批")
    public AjaxResult createCommonClaim(@RequestBody GridCmpmClaimDTO gridCmpmClaimDTO) {
        return success(gridCmpmTransferService.createCommonClaim(gridCmpmClaimDTO));
    }

    @PostMapping("/approve")
    @Log(title = "绩效网格-审批关系移交审批")
    @ApiOperation("审批关系移交审批")
    public AjaxResult approve(@RequestBody GridCmpmApproveDTO gridCmpmApproveDTO) {
        return success(gridCmpmTransferService.approveTransfer(gridCmpmApproveDTO));
    }

    @GetMapping("/list/approve")
    @ApiOperation("绩效网格-查询关系移交审批列表")
    @Log(title = "查询关系移交审批列表")
    public TableDataPageInfo list(GridCmpmTransferListDTO gridCmpmRetailListDTO) {
        Page<Object> page = startPage();
        List<GridCmpmTransferVO> gridCmpmTransferList = gridCmpmTransferService.getGridCmpmTransferList(gridCmpmRetailListDTO);
        return getDataTable(gridCmpmTransferList, page);
    }

    @GetMapping("/list/history")
    @ApiOperation("绩效网格-查询关系移交审批历史列表")
    @Log(title = "查询关系移交审批历史列表")
    public TableDataPageInfo historyList(GridCmpmTransferListDTO gridCmpmRetailListDTO) {
        Page<Object> page = startPage();
        List<GridCmpmTransferVO> gridCmpmTransferList = gridCmpmTransferService.getGridCmpmTransferHistoryList(gridCmpmRetailListDTO);
        return getDataTable(gridCmpmTransferList, page);
    }

    @PostMapping("/adjust")
    @ApiOperation("绩效网格-总行支行管理员调整关系")
    @Log(title = "总行支行管理员调整关系")
    public AjaxResult adjust(@RequestBody GridCmpmAdjustDTO gridCmpmAdjustDTO) {
        return success(gridCmpmTransferService.adjustGridCmpm(gridCmpmAdjustDTO));
    }

    @GetMapping("/claim/list")
    @ApiOperation("绩效网格-查询认领客户列表")
    @Log(title = "查询认领客户列表")
    public TableDataPageInfo claimList(String custKey, String gridType) {
        Page<Object> page = startPage();
        List<GridCmpmClaimVO> gridCmpmClaimList = gridCmpmTransferService.queryClaimList(custKey, gridType);
        return getDataTable(gridCmpmClaimList, page);
    }




}
