package com.ruoyi.web.bst;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.reconciliationDate.constants.ReconciliationDateConstants;
import com.ruoyi.bst.reconciliationDate.domain.ReconciliationDateQuery;
import com.ruoyi.bst.reconciliationDate.domain.ReconciliationDateVO;
import com.ruoyi.bst.reconciliationDate.service.ReconciliationDateService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 渠道对账Controller
 *
 * @author ruoyi
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/bst/reconciliationDate")
public class ReconciliationDateController extends BaseController
{
    @Autowired
    private ReconciliationDateService reconciliationDateService;

    /**
     * 查询渠道对账列表
     */
    @PreAuthorize("@ss.hasPermi('bst:reconciliationDate:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReconciliationDateQuery query)
    {
        startPage();
        startOrderBy();
        List<ReconciliationDateVO> list = reconciliationDateService.selectReconciliationDateList(query);
        return getDataTable(list);
    }

    // 按日期分组
    @PreAuthorize("@ss.hasPermi('bst:reconciliationDate:list')")
    @GetMapping("/listGroupByDate")
    public TableDataInfo listGroupByDate(ReconciliationDateQuery query) {
        startPage();
        startOrderBy();
        List<ReconciliationDateVO> list = reconciliationDateService.selectReconciliationDateListGroupBy(query, ReconciliationDateConstants.GROUP_BY_DATE);
        return getDataTable(list);
    }

    // 按渠道分组
    @PreAuthorize("@ss.hasPermi('bst:reconciliationDate:list')")
    @GetMapping("/listGroupByChannel")
    public TableDataInfo getListGroupByChannel(ReconciliationDateQuery query) {
        startPage();
        startOrderBy();
        List<ReconciliationDateVO> list = reconciliationDateService.selectReconciliationDateListGroupBy(query, ReconciliationDateConstants.GROUP_BY_CHANNEL);
        return getDataTable(list);
    }

    // 按运营区分组
    @PreAuthorize("@ss.hasPermi('bst:reconciliationDate:list')")
    @GetMapping("/listGroupByArea")
    public TableDataInfo getListGroupByArea(ReconciliationDateQuery query) {
        startPage();
        startOrderBy();
        List<ReconciliationDateVO> list = reconciliationDateService.selectReconciliationDateListGroupBy(query, ReconciliationDateConstants.GROUP_BY_AREA);
        return getDataTable(list);
    }

    /**
     * 导出渠道对账列表
     */
    @PreAuthorize("@ss.hasPermi('bst:reconciliationDate:export')")
    @Log(title = "渠道对账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReconciliationDateQuery query)
    {
        List<ReconciliationDateVO> list = reconciliationDateService.selectReconciliationDateList(query);
        ExcelUtil<ReconciliationDateVO> util = new ExcelUtil<ReconciliationDateVO>(ReconciliationDateVO.class);
        util.exportExcel(response, list, "渠道对账数据");
    }

    /**
     * 获取渠道对账详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:reconciliationDate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(reconciliationDateService.selectReconciliationDateById(id));
    }
}
