package com.ruoyi.ibs.dashboard.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.R;
import com.ruoyi.common.core.page.TableDataPageInfo;
import com.ruoyi.common.utils.OssUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ibs.dashboard.domain.entity.LoadIndDmPaItemHome;
import com.ruoyi.ibs.dashboard.domain.vo.CampaignVO;
import com.ruoyi.ibs.dashboard.domain.vo.CommonRespVO;
import com.ruoyi.ibs.dashboard.domain.vo.LoanContractDueWarnVO;
import com.ruoyi.ibs.dashboard.domain.vo.WarnInfoVO;
import com.ruoyi.ibs.dashboard.service.DashboardCampaignService;
import com.ruoyi.ibs.dashboard.service.DashboardService;
import com.ruoyi.system.service.ISysNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Author 吴凯程
 * @Date 2025/3/3
 **/
@Api(tags = "首页数据接口")
@RestController
@RequestMapping("/dashboard")
public class DashboardController extends BaseController {

    @Resource
    private DashboardService dashboardService;

    @Resource
    private DashboardCampaignService dashboardCampaignService;

    @Autowired
    private ISysNoticeService noticeService;


    @Autowired
    private OssUtils ossUtils;

    @ApiOperation("获取贷款预警信息列表")
    @Log(title = "获取贷款预警信息列表")
    @GetMapping("/loan/warn/list")
    public TableDataPageInfo<LoanContractDueWarnVO> getWarnList(@RequestParam String custIdName,@RequestParam(required = true) String custType) {
        if(SecurityUtils.isAdmin(getUserId())){
            return null;
        }
        Page<Object> page = startPage();
        List<LoanContractDueWarnVO> warnList = dashboardService.getLoanWarnList(custIdName,custType);
        return getDataTable(warnList, page);
    }

    @ApiOperation("获取预警信息列表")
    @Log(title = "获取预警信息列表")
    @GetMapping("/warn/list")
    public R<List<WarnInfoVO>> getWarnInfoList() {
        if(SecurityUtils.isAdmin(getUserId())){
            return null;
        }
        return R.ok(dashboardService.getWarnInfoList());
    }

    /**
     * 测试用接口
     * @return
     */
    @ApiOperation("测试获取预警信息列表")
    @Log(title = "测试获取预警信息列表")
    @GetMapping("/warn/test")
    public R<List<WarnInfoVO>> getWarnInfoTest() {
        if(SecurityUtils.isAdmin(getUserId())){
            return null;
        }
        List<WarnInfoVO> warnInfoVOList = new ArrayList<>(Arrays.asList(
                new WarnInfoVO("贷款到期提醒", null),
                new WarnInfoVO("提前还贷预警", null),
                new WarnInfoVO("存款指标提醒", null),
                new WarnInfoVO("贷款指标提醒", null),
                new WarnInfoVO("定期到期提醒", null),
                new WarnInfoVO("扣息不足提醒", null),
                new WarnInfoVO("大额动账提醒", null),
                new WarnInfoVO("不良动账提醒", null)
        ));
        return R.ok(warnInfoVOList);
    }

    /**
     * 测试获取token
     * @return
     */
    @ApiOperation("测试获取预警信息列表")
    @Log(title = "测试获取预警信息列表")
    @PostMapping("/token")
    public String getToken() {
        return "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjBhMjE4MzBjLWUxYjEtNDlmYi1hODU1LTE3OTk0YmZkNTM4ZiJ9.PxLmxHytRSjUS24aq_CDWrCgLxFmEP1qVlVXnIX";
    }

    /**
     * 获取预警信息列表--青田
     *
     * @return
     */
    @ApiOperation("获取预警信息列表")
    @Log(title = "获取预警信息列表")
    @GetMapping("/warnResp/list")
    public TableDataPageInfo<Map<String, Object>> getWarnRespList(String type, Long pageNum, Long pageSize){
        if(SecurityUtils.isAdmin(getUserId())){
            return null;
        }
        CommonRespVO commonRespVO = dashboardService.getWarnRespList(type, pageNum, pageSize);
        return getDataTableByQt(commonRespVO.getData(), commonRespVO.getTotal());
    }

    //测试数据
    @ApiOperation("预警测试数据")
    @Log(title = "预警测试数据")
    @GetMapping("/warnResp/list/test")
    public TableDataPageInfo<Map<String, Object>> getListTest(String type, Long pageNum, Long pageSize){
        if(SecurityUtils.isAdmin(getUserId())){
            return null;
        }
        List<Map<String, Object>> dataList = new ArrayList<>();
        // 第一条数据
        Map<String, Object> data1 = new HashMap<>();
        data1.put("管贷责任人", "9320370");
        data1.put("客户名称", "张旭君");
        data1.put("客户内码", "81010941565");
        data1.put("币种", "CNY");
        data1.put("动账金额", "2000.0");
        data1.put("联系电话", "18157877152");
        data1.put("管贷责任人姓名", "章丽丽");
        data1.put("证件号码", "101332522199512198597");
        data1.put("交易产品", "活期");
        data1.put("交易类型", "存入");
        dataList.add(data1);
        return getDataTableByQt(dataList, dataList.size());
    }



    @ApiOperation("支行管理员获取任务清单")
    @Log(title = "支行管理员获取任务清单")
    @GetMapping("/campaign/branch")
    public TableDataPageInfo<CampaignVO> getListByBranchAdmin(@RequestParam Boolean isFinish) {
        Page<Object> page = startPage();
        List<CampaignVO> listByBranchAdmin = dashboardCampaignService.getListByBranchAdmin(isFinish);
        return getDataTable(listByBranchAdmin, page);
    }

    @ApiOperation("总行获取代办")
    @Log(title = "总行获取代办")
    @GetMapping("/campaign/head")
    public TableDataPageInfo<CampaignVO> getListByheadAdmin(@RequestParam Boolean isFinish) {
        Page<Object> page = startPage();
        List<CampaignVO> listByBranchAdmin = dashboardCampaignService.getListByHeadAdmin(isFinish);
        return getDataTable(listByBranchAdmin, page);
    }

    @ApiOperation("客户经理获取任务清单")
    @Log(title = "客户经理获取任务清单")
    @GetMapping("/campaign/manager")
    public TableDataPageInfo<CampaignVO> getListByManager() {
        Page<Object> page = startPage();
        List<CampaignVO> listByManager = dashboardCampaignService.getListByManager();
        return getDataTable(listByManager, page);
    }

    @ApiOperation("获取指标数据")
    @Log(title = "获取指标数据")
    @GetMapping("/index")
    public R<List<LoadIndDmPaItemHome>> getIndDmPaItemHomeList() {
        if(SecurityUtils.isAdmin(getUserId())){
            return null;
        }
        return R.ok(dashboardService.getIndDmPaItemHomeList());
    }


}
