package com.ruoyi.ibs.grid.controller;

import com.github.pagehelper.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataPageInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ibs.grid.domain.entity.*;
import com.ruoyi.ibs.grid.service.GridCountService;
import com.ruoyi.ibs.grid.service.GridUnionCountService;
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.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "网格整体业绩汇总")
@RestController
@RequestMapping("/ibs/GridUnionCount/")
public class GridUnionCountController extends BaseController{


    @Autowired
    GridUnionCountService service;

    @Log(title = "网格整体业绩汇总-查询零售网格整体汇总列表")
    @ApiOperation(value = "查询零售汇总网格列表")
    @GetMapping("LsList")
    public TableDataPageInfo<GridUnionCmpmLingshou> selectLsCountList() {
        Page<Object> page = startPage();
        List<GridUnionCmpmLingshou> list = service.selectLsCountList();
        return getDataTable(list, page);
    }

    @Log(title = "网格整体业绩汇总-查询公司网格汇总列表")
    @ApiOperation(value = "查询公司汇总网格列表")
    @GetMapping("GsList")
    public TableDataPageInfo<GridUnionCmpmGongsi> selectGsCountList() {
        Page<Object> page = startPage();
        List<GridUnionCmpmGongsi> list = service.selectGsCountList();
        return getDataTable(list, page);
    }

    @Log(title = "网格整体业绩汇总-导出零售汇总网格")
    @ApiOperation(value = "导出零售汇总网格", produces = "application/octet-stream")
    @GetMapping("exportLs")
    public void exportLs(HttpServletResponse response) {
        try {
            ExcelUtil<GridUnionCmpmLingshou> util = new ExcelUtil<>(GridUnionCmpmLingshou.class);
            util.exportExcel(response, service.selectLsCountList(), "零售网格汇总");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Log(title = "网格整体业绩汇总-导出公司汇总网格")
    @ApiOperation(value = "导出公司汇总网格", produces = "application/octet-stream")
    @GetMapping("exportGs")
    public void exportGs(HttpServletResponse response) {
        try {
            ExcelUtil<GridUnionCmpmGongsi> util = new ExcelUtil<>(GridUnionCmpmGongsi.class);
            util.exportExcel(response, service.selectGsCountList(), "公司网格汇总");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Log(title = "网格整体业绩汇总-查询零售客户明细")
    @ApiOperation(value = "查询零售客户明细")
    @GetMapping("LsCustList")
    public TableDataPageInfo<GridUnionCustLingshou> selectLsCustList(String custName, String custIdc,String dt) {
        Page<Object> page = startPage();
        List<GridUnionCustLingshou> list = service.selectLsCustList(custName, custIdc,dt);
        return getDataTable(list, page);
    }

    @Log(title = "网格整体业绩汇总-查询公司客户明细")
    @ApiOperation(value = "查询公司客户明细")
    @GetMapping("GsCustList")
    public TableDataPageInfo<GridUnionCustGongsi> selectGsCustList( String custName, String socialCreditCode,String dt) {
        Page<Object> page = startPage();
        List<GridUnionCustGongsi> list = service.selectGsCustList( custName, socialCreditCode,dt);
        return getDataTable(list, page);
    }


    @Log(title = "网格整体业绩汇总-导出零售客户明细前1000条")
    @ApiOperation(value = "导出零售客户明细前1000条", produces = "application/octet-stream")
    @GetMapping("exportLsCustLimit")
    public void exportLsCustLimit(HttpServletResponse response, String custName, String custIdc,String dt) {
        try {
            ExcelUtil<GridUnionCustLingshou> util = new ExcelUtil<>(GridUnionCustLingshou.class);
            util.exportExcel(response, service.selectLsCustListLimit(custName, custIdc,dt), "网格客户明细");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Log(title = "网格整体业绩汇总-导出公司客户明细前1000条")
    @ApiOperation(value = "导出公司客户明细前1000条", produces = "application/octet-stream")
    @GetMapping("exportGsCustLimit")
    public void exportGsCustLimit(HttpServletResponse response, String custName, String socialCreditCode,String dt) {
        try {
            ExcelUtil<GridUnionCustGongsi> util = new ExcelUtil<>(GridUnionCustGongsi.class);
            util.exportExcel(response, service.selectGsCustListLimit(custName, socialCreditCode,dt), "网格客户明细");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Log(title = "网格整体业绩汇总-导出零售客户明细")
    @ApiOperation(value = "导出零售客户明细", produces = "application/octet-stream")
    @PostMapping("exportLsCust")
    public void exportLsCust(HttpServletResponse response, @RequestBody List<GridUnionCustLingshou> list) {
        try {
            ExcelUtil<GridUnionCustLingshou> util = new ExcelUtil<>(GridUnionCustLingshou.class);
            util.exportExcel(response, list, "网格客户明细");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Log(title = "网格整体业绩汇总-导出公司客户明细")
    @ApiOperation(value = "导出公司客户明细", produces = "application/octet-stream")
    @PostMapping("exportGsCust")
    public void exportGsCust(HttpServletResponse response, @RequestBody List<GridUnionCustGongsi> list) {
        try {
            ExcelUtil<GridUnionCustGongsi> util = new ExcelUtil<>(GridUnionCustGongsi.class);
            util.exportExcel(response, list, "网格客户明细");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

