package com.ruoyi.ibs.grid.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.ibs.grid.domain.dto.GridShapeHeatMapDTO;
import com.ruoyi.ibs.grid.domain.entity.GridShapeCountLingshou;
import com.ruoyi.ibs.grid.domain.entity.GridShapeCustGongsi;
import com.ruoyi.ibs.grid.domain.entity.GridShapeCustLingshou;
import com.ruoyi.ibs.grid.domain.vo.GridShapeHeatMapVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ibs.grid.domain.entity.GridShapeCountGongsi;
import com.ruoyi.ibs.grid.service.IGridShapeCountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自定义地图网格汇总统计Controller
 * 
 * @author ruoyi
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/system/gridShapeCount")
@Api(tags = "自定义地图网格汇总统计")
public class GridShapeCountController extends BaseController
{
    @Autowired
    private IGridShapeCountService gridShapeCountService;

    /**
     * 查询自定义地图网格汇总统计_公司列表
     */
//    @PreAuthorize("@ss.hasPermi('system::list')")
    @ApiOperation(value = "查询gs汇总", notes = "查询gs汇总")
    @Log(title = "网格报表-查询自定义地图网格汇总统计_公司")
    @GetMapping("/gsList")
    public TableDataInfo gsList(String shapeType ,String shapeName, String gridName,String dt)
    {
        startPage();
        List<GridShapeCountGongsi> list = gridShapeCountService.selectGridShapeCountGongsiList(shapeType,shapeName, gridName,dt);
        return getDataTable(list);
    }

    /**
     * 查询自定义地图网格汇总统计_零售列表
     */
    @ApiOperation(value = "查询ls汇总", notes = "查询ls汇总")
    @Log(title = "网格报表-查询自定义地图网格汇总统计_零售")
    @GetMapping("/lsList")
    public TableDataInfo lsList(String shapeType ,String shapeName, String gridName,String dt)
    {
        startPage();
        List<GridShapeCountLingshou> list = gridShapeCountService.selectGridShapeCountLingshouList(shapeType,shapeName, gridName,dt);
        return getDataTable(list);
    }
    @ApiOperation(value = "查询gs客户明细", notes = "查询gs客户明细")
    @Log(title = "网格报表-查询自定义地图网格汇总统计_公司客户明细")
    @GetMapping("/gsCustList")
    public TableDataInfo gsCustList(String shapeId ,String custName, String custIdc,String dt)
    {
        startPage();
        List<GridShapeCustGongsi> list = gridShapeCountService.selectGridShapeCountgsCustList(shapeId, custName, custIdc,dt);
        return getDataTable(list);
    }
    @ApiOperation(value = "查询ls客户明细", notes = "查询ls客户明细")
    @Log(title = "网格报表-查询自定义地图网格汇总统计_零售客户明细")
    @GetMapping("/lsCustList")
    public TableDataInfo lsCustList(String shapeId ,String custName, String custIdc,String dt)
    {
        startPage();
        List<GridShapeCustLingshou> list = gridShapeCountService.selectGridShapeCountlsCustList(shapeId, custName, custIdc,dt);
        return getDataTable(list);
    }

    /**
     * 导出自定义地图网格汇总统计_公司列表
     */
//    @PreAuthorize("@ss.hasPermi('system::export')")
    @ApiOperation(value = "导出自定义地图网格汇总统计_公司", notes = "导出自定义地图网格汇总统计_公司")
    @Log(title = "网格报表-导出自定义地图网格汇总统计_公司", businessType = BusinessType.EXPORT)
    @PostMapping("/gsExport")
    public void gsExport(HttpServletResponse response, String shapeType ,String shapeName, String gridName,String dt)
    {
        List<GridShapeCountGongsi> list = gridShapeCountService.selectGridShapeCountGongsiList(shapeType,shapeName, gridName,dt);
        ExcelUtil<GridShapeCountGongsi> util = new ExcelUtil<GridShapeCountGongsi>(GridShapeCountGongsi.class);
        util.exportExcel(response, list, "自定义地图网格汇总统计_公司数据");
    }
    @ApiOperation(value = "导出自定义地图网格汇总统计_零售", notes = "导出自定义地图网格汇总统计_零售")
    @Log(title = "网格报表-导出自定义地图网格汇总统计_零售", businessType = BusinessType.EXPORT)
    @PostMapping("/lsExport")
    public void lsExport(HttpServletResponse response, String shapeType ,String shapeName, String gridName,String dt)
    {
        List<GridShapeCountLingshou> list = gridShapeCountService.selectGridShapeCountLingshouList(shapeType,shapeName, gridName,dt);
        ExcelUtil<GridShapeCountLingshou> util = new ExcelUtil<GridShapeCountLingshou>(GridShapeCountLingshou.class);
        util.exportExcel(response, list, "自定义地图网格汇总统计_公司数据");
    }

    @ApiOperation(value = "导出公司网格明细数据", notes = "导出公司网格明细数据")
    @Log(title = "网格报表-导出公司网格明细数据")
    @PostMapping("/gsmxExport")
    public void exportGsmx(HttpServletResponse response, String shapeId ,String custName, String custIdc,String dt) {
        try {
            ExcelUtil<GridShapeCustGongsi> util = new ExcelUtil<>(GridShapeCustGongsi.class);
            util.exportExcel(response, gridShapeCountService.selectGridShapeCountgsCustList(shapeId, custName, custIdc,dt), "公司网格客户明细汇总");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "导出零售网格明细数据-零售", notes = "导出零售网格明细数据")
    @Log(title = "网格报表-导出零售网格明细数据")
    @PostMapping("/lsmxExport")
    public void exportLsmx(HttpServletResponse response, String shapeId ,String custName, String custIdc,String dt) {
        try {
            ExcelUtil<GridShapeCustLingshou> util = new ExcelUtil<>(GridShapeCustLingshou.class);
            util.exportExcel(response, gridShapeCountService.selectGridShapeCountlsCustList(shapeId, custName, custIdc,dt), "零售网格客户明细汇总");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     *  自定义名单网格热力图
     *
     */
    @GetMapping("/heatMapLsList")
    @Log(title = "网格报表-自定义网格热力图查询零售")
    @ApiOperation(value = "自定义名单网格热力图-零售", notes = "自定义名单网格热力图")
    public R<List<GridShapeHeatMapVO>> heatMapLsList( GridShapeHeatMapDTO gridVirtualHeatMapDTO)
    {
        gridVirtualHeatMapDTO.setTabName("grid_shape_count_lingshou_detail");
        return R.ok(gridShapeCountService.heatMapList(gridVirtualHeatMapDTO));
    }

    @GetMapping("/heatMapGsList")
    @Log(title = "网格报表-自定义网格热力图查询-公司")
    @ApiOperation(value = "自定义名单网格热力图-公司", notes = "自定义名单网格热力图")
    public R<List<GridShapeHeatMapVO>> heatMapGsList( GridShapeHeatMapDTO gridVirtualHeatMapDTO)
    {
        gridVirtualHeatMapDTO.setTabName("grid_shape_count_gongsi_detail");
        return R.ok(gridShapeCountService.heatMapList(gridVirtualHeatMapDTO));
    }

    @GetMapping("/shapeNameGsList")
    @Log(title = "网格报表-自定义名单网格热力图")
    @ApiOperation(value = "自定义名单网格热力图-公司-区域名称查询", notes = "自定义名单网格热力图")
    public R<Map<String,String>> shapeNameGsList(@RequestParam(name ="shapeType", required = true) String shapeType)
    {
        return R.ok(gridShapeCountService.shapeNameList(shapeType,"grid_shape_count_gongsi_detail"));
    }


    @GetMapping("/shapeNameLsList")
    @Log(title = "网格报表-自定义名单网格热力图")
    @ApiOperation(value = "自定义名单网格热力图-零售-区域名称查询", notes = "自定义名单网格热力图")
    public R<Map<String,String>> shapeNameLsList(@RequestParam(name ="shapeType", required = true) String shapeType)
    {
        return R.ok(gridShapeCountService.shapeNameList(shapeType,"grid_shape_count_lingshou_detail"));
    }



    @GetMapping("/indexList")
    @Log(title = "网格报表-指標id查詢")
    @ApiOperation(value = "自定义名单网格热力图- 指標id查詢 gs/ls", notes = "自定义名单网格热力图")
    public R<Map<String,String>> indexList(@RequestParam(name ="type", required = true) String type)
    {
        return R.ok(gridShapeCountService.indexList(type));
    }

}
