package vip.xiaonuo.money.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.money.entity.MoneyBorrowWarning;
import vip.xiaonuo.money.entity.MoneyOverdue;
import vip.xiaonuo.money.entity.MoneyWriteOverdue;
import vip.xiaonuo.money.entity.vo.MoneyBorrowUserVo;
import vip.xiaonuo.money.param.MoneyInOutParam;
import vip.xiaonuo.money.param.MoneyOverdueDetailPageParam;
import vip.xiaonuo.money.param.MoneyOverduePageParam;
import vip.xiaonuo.money.param.MoneyOverdueParam;
import vip.xiaonuo.money.service.IMoneyOverdueService;

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

/**
 * <p>
 * 财务应收逾期表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-21
 */

@Api(tags = "应收逾期分析控制器")
@ApiSupport(author = "wang", order = 1)
@RestController
@Validated
public class MoneyOverdueController {

    @Autowired
    private IMoneyOverdueService overdueService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("逾期一个月以上总金额")
    @PostMapping("/money-overdue/getOverdueCount")
    public CommonResult<JSONObject> getOverdueCount(@RequestBody MoneyOverdueParam overdueParam) {
        return CommonResult.data(overdueService.getOverdueCount(overdueParam));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("逾期占比")
    @PostMapping("/money-overdue/overdueRank")
    public CommonResult<JSONObject> overdueRank(@RequestBody MoneyOverdueParam overdueParam) {
        return CommonResult.data(overdueService.overdueRank(overdueParam));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("客户应收/逾期分析--客户逾期金额共用")
    @PostMapping("/money-overdue/userRank")
    public CommonResult<List<MoneyBorrowUserVo>> userRank(@RequestBody MoneyOverdueParam overdueParam) {
        return CommonResult.data(overdueService.userRank(overdueParam));
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("逾期明细表")
    @PostMapping("/money-overdue/overdueDetail")
    public CommonResult<Page<MoneyWriteOverdue>> overdueDetail(@RequestBody MoneyOverdueDetailPageParam overduePageParam) {
        return CommonResult.data(overdueService.overdueDetail(overduePageParam));
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("客户列表")
    @PostMapping("/money-overdue/listUserName")
    public CommonResult<List<MoneyOverdue>> listUserName(@RequestBody Map<String,String> paramsMap) {
        return CommonResult.data(overdueService.listUserName(paramsMap));
    }
    @ApiOperationSupport(order = 4)
    @ApiOperation("逾期明细表添加")
    @PostMapping("/money-overdue/overdueAdd")
    public CommonResult<String> overdueAdd(@RequestBody MoneyOverdue moneyOverdue) {
        String orgId = moneyOverdue.getOrgId();
        if (StringUtils.isBlank(orgId)){
            throw new CommonException("请选择公司");
        }
        overdueService.save(moneyOverdue);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("客户筛选")
    @PostMapping("/money-overdue/keHu")
    public CommonResult< List<MoneyOverdue>> keHu(@RequestBody MoneyOverdue moneyOverdue) {

        return CommonResult.data(  overdueService.keHu(moneyOverdue));
    }


}
