package com.jsowell.web.controller.pile;

import com.jsowell.common.annotation.Log;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.core.page.TableDataInfo;
import com.jsowell.common.enums.BusinessType;
import com.jsowell.common.util.poi.ExcelUtil;
import com.jsowell.pile.domain.SettleOrderReport;
import com.jsowell.pile.dto.MerchantOrderReportDTO;
import com.jsowell.pile.service.ISettleOrderReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 结算订单报Controller
 *
 * @author jsowell
 * @date 2023-06-06
 */
@RestController
@RequestMapping("/pile/report")
public class SettleOrderReportController extends BaseController {
    @Autowired
    private ISettleOrderReportService settleOrderReportService;

    /**
     * 查询结算订单报列表
     */
    @PreAuthorize("@ss.hasPermi('pile:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(SettleOrderReport settleOrderReport) {
        startPage();
        List<SettleOrderReport> list = settleOrderReportService.selectSettleOrderReportList(settleOrderReport);
        return getDataTable(list);
    }

    /**
     * 导出结算订单报列表
     */
    @PreAuthorize("@ss.hasPermi('pile:report:export')")
    @Log(title = "结算订单报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SettleOrderReport settleOrderReport) {
        List<SettleOrderReport> list = settleOrderReportService.selectSettleOrderReportList(settleOrderReport);
        ExcelUtil<SettleOrderReport> util = new ExcelUtil<SettleOrderReport>(SettleOrderReport.class);
        util.exportExcel(response, list, "结算订单报数据");
    }

    /**
     * 获取结算订单报详细信息
     */
    @PreAuthorize("@ss.hasPermi('pile:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(settleOrderReportService.selectSettleOrderReportById(id));
    }

    /**
     * 新增结算订单报
     */
    @PreAuthorize("@ss.hasPermi('pile:report:add')")
    @Log(title = "结算订单报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SettleOrderReport settleOrderReport) {
        return toAjax(settleOrderReportService.insertSettleOrderReport(settleOrderReport));
    }

    /**
     * 修改结算订单报
     */
    @PreAuthorize("@ss.hasPermi('pile:report:edit')")
    @Log(title = "结算订单报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SettleOrderReport settleOrderReport) {
        return toAjax(settleOrderReportService.updateSettleOrderReport(settleOrderReport));
    }

    /**
     * 删除结算订单报
     */
    @PreAuthorize("@ss.hasPermi('pile:report:remove')")
    @Log(title = "结算订单报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(settleOrderReportService.deleteSettleOrderReportByIds(ids));
    }

    /**
     * 查询运营商订单报表
     * @param dto
     * @return
     */
    @PreAuthorize("@ss.hasPermi('pile:merchant:query')")
    @PostMapping("/getMerchantOrderReport")
    public AjaxResult getMerchantOrderReport(@RequestBody MerchantOrderReportDTO dto) {
        return AjaxResult.success(settleOrderReportService.getMerchantOrderReport(dto));
    }
}
