package com.ruoyi.web.controller.dragForm;

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

import com.ruoyi.system.entity.CommonEntity;
import com.ruoyi.system.entity.DragTableStatistic;
import com.ruoyi.system.entity.vo.DragTableVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IDragTableStatisticService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 动态表格统计Controller
 *
 * @author ruoyi
 * @date 2023-10-27
 */
@RestController
@RequestMapping("/system/statistic")
@Api(value = "/system/statistic", description = "动态表格统计-接口")
public class DragTableStatisticController extends BaseController
{
    @Autowired
    private IDragTableStatisticService dragTableStatisticService;

/**
 * 查询动态表格统计列表
 */
@PreAuthorize("@ss.hasPermi('system:statistic:list')")
@GetMapping("/list")
@ApiOperation(value = "查询动态表格统计列表")
    public TableDataInfo list(DragTableStatistic dragTableStatistic)
    {
        startPage();
        List<DragTableStatistic> list = dragTableStatisticService.selectDragTableStatisticList(dragTableStatistic);
        return getDataTable(list);
    }

    /**
     * 导出动态表格统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:statistic:export')")
    @Log(title = "动态表格统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出动态表格统计列表")
    public void export(HttpServletResponse response, DragTableStatistic dragTableStatistic)
    {
        List<DragTableStatistic> list = dragTableStatisticService.selectDragTableStatisticList(dragTableStatistic);
        ExcelUtil<DragTableStatistic> util = new ExcelUtil<DragTableStatistic>(DragTableStatistic.class);
        util.exportExcel(response, list, "动态表格统计数据");
    }

    /**
     * 获取动态表格统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:statistic:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取动态表格统计详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dragTableStatisticService.selectDragTableStatisticById(id));
    }

    /**
     * 新增动态表格统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistic:add')")
    @Log(title = "动态表格统计", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增动态表格统计")
    public AjaxResult add(@RequestBody DragTableVo vo)
    {
        if(vo.getDragTableStatisticList()==null||vo.getDragTableStatisticList().size()<0){
            return  AjaxResult.success("未填写统计信息1");
        }
        if(vo.getTableSqlList()==null||vo.getTableSqlList().size()<0){
            return  AjaxResult.success("未填写统计信息2");
        }
        return toAjax(dragTableStatisticService.batchInsertDragTableStatistic(vo));
    }

    /**
     * 新增动态表格组统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistic:add')")
    @Log(title = "动态表格统计", businessType = BusinessType.INSERT)
    @PostMapping("/addGroupTableStatistic")
    @ApiOperation(value = "新增动态表格统计")
    public AjaxResult addGroupTableStatistic(@RequestBody DragTableVo vo)
    {
        if(vo.getDragTableStatisticList()==null||vo.getDragTableStatisticList().size()<0){
            return  AjaxResult.success("未填写统计信息1");
        }
        if(vo.getTableSqlList()==null||vo.getTableSqlList().size()<0){
            return  AjaxResult.success("未填写统计信息2");
        }
        return toAjax(dragTableStatisticService.batchInsertGroupDragTableStatistic(vo));
    }

    /**
     * 修改动态表格统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistic:edit')")
    @Log(title = "动态表格统计", businessType = BusinessType.UPDATE)
    @PutMapping("/updateGroupTableStatistic")
    @ApiOperation(value = "修改动态表格统计")
    public AjaxResult updateGroupTableStatistic(@RequestBody DragTableVo vo)
    {
        dragTableStatisticService.updateGroupDragTableStatistic(vo);
        return AjaxResult.success();
    }



    /**
     * 修改动态表格统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistic:edit')")
    @Log(title = "动态表格统计", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改动态表格统计")
    public AjaxResult edit(@RequestBody DragTableVo vo)
    {
        dragTableStatisticService.updateDragTableStatistic(vo);
        return AjaxResult.success();
    }

    /**
     * 删除动态表格统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistic:remove')")
    @Log(title = "动态表格统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tableKey}")
    @ApiOperation(value = "删除动态表格统计")
    public AjaxResult remove(@PathVariable String tableKey)
    {
        return toAjax(dragTableStatisticService.deleteDragTableStatisticByTableKey(tableKey));
    }

    /**
     * 获取动态表格统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:statistic:query')")
    @GetMapping("/getInfoBySqlKey")
    @ApiOperation(value = "获取动态表格统计详细信息")
    public AjaxResult getInfoBySqlKey(@RequestParam("sqlKey") String sqlKey)
    {
        return success(dragTableStatisticService.getInfoBySqlKey(sqlKey));
    }

    /**
     * 获取列表统计信息
     */
    @GetMapping("/getStatisticList")
    public AjaxResult getStatisticList(CommonEntity commonEntity){
        return AjaxResult.success(dragTableStatisticService.getStatisticList(commonEntity));
    }


}
