package com.chinaweal.aiccs.aiccs.blacklist;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaweal.aiccs.aiccs.abnormal.service.EBaseinfoService;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.youfool.framework.springboot.exception.custom.BusinessException;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.rest.ResultCode;
import com.chinaweal.youfool.framework.springboot.util.AssertUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Author Lee
 * @Since 2021/4/21 13:35
 */
@Api(tags = "黑名单相关接口")
@RestController
@RequestMapping("/entBlacklist")
public class EntBlacklistController {

    @Autowired
    private EBaseinfoService eBaseinfoService;


    @ApiOperation(value = "失信异常名单-企业查询")
    @GetMapping("getBlackForEnt")
    public RestResult<IPage<Map<String, String>>> getBlackForEnt(@ApiParam("统一码") String uscc,
                                                                 @ApiParam("企业名称") String entName,
                                                                 @RequestParam long curPage,
                                                                 @RequestParam long pageSize) {
        if (StringUtils.isBlank(uscc) && StringUtils.isBlank(entName)) {
            throw new BusinessException(ResultCode.PARAM_IS_BLANK);
        }

        return RestResult.ok(eBaseinfoService.selectBlackForEnt(new Page<>(curPage, pageSize), uscc, entName));
    }

    @ApiOperation(value = "失信异常名单-自然人查询")
    @GetMapping("getBlackForPerson")
    public RestResult<IPage<Map<String, String>>> getBlackForPerson(@ApiParam("证件号码") String cerNo,
                                                                    @ApiParam("姓名") String name,
                                                                    @RequestParam long curPage,
                                                                    @RequestParam long pageSize) {
        if (StringUtils.isBlank(cerNo) && StringUtils.isBlank(name)) {
            throw new BusinessException(ResultCode.PARAM_IS_BLANK);
        }

        return RestResult.ok(eBaseinfoService.selectBlackForPerson(new Page<>(curPage, pageSize), cerNo, name));
    }

    @ApiOperation(value = "失信异常企业名单-根据自然人查询")
    @GetMapping("getEntBlackForPerson")
    public RestResult<IPage<Map<String, String>>> getEntBlackForPerson(@ApiParam("证件号码") String cerNo,
                                                                    @RequestParam long curPage,
                                                                    @RequestParam long pageSize) {
        AssertUtils.isNotBlank(cerNo);

        return RestResult.ok(eBaseinfoService.getEntBlackForPerson(new Page<>(curPage, pageSize), cerNo));
    }

    @ApiOperation(value = "统计")
    @GetMapping("statistics")
    public RestResult<List<Map<String, String>>> statistics(@RequestParam @ApiParam("开始统计时间") String startDate,
                                                            @RequestParam @ApiParam("结束统计时间") String endDate) {
        AssertUtils.isNotBlank(startDate, endDate);

//        List<Map<String, String>> list = new ArrayList<>();
//        Map<String, String> resultMap = new HashMap<>();
//        resultMap.put("单位名称", "广州市市场监督管理局");
//        resultMap.put("经营异常列入数量-分组(农专、个体户、企业)", "2,971,23474");
//        resultMap.put("经营异常-移出数量", "13384");
//        resultMap.put("经营异常-同比增长率", "33.5154%");
//        resultMap.put("经营异常-环比增长率", "75.3425%");
//        resultMap.put("严重违法列入数量-分组(农专、个体户、企业)", "0,0,692");
//        resultMap.put("严重违法-移出数量", "262");
//        resultMap.put("严重违法-同比增长率", "40.8081%");
//        resultMap.put("严重违法-环比增长率", "-76.7589%");
//        resultMap.put("批量吊销-列入数量", "0");
//        resultMap.put("批量吊销-同比增长率", "0%");
//        resultMap.put("批量吊销-环比增长率", "0%");
//        list.add(resultMap);
//        return RestResult.ok(list);
        return RestResult.ok(eBaseinfoService.statistics(startDate, endDate));
    }

}
