package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.ss.reconciliation.domain.Reconciliation;
import com.ruoyi.ss.reconciliation.domain.ReconciliationVO;
import com.ruoyi.ss.reconciliation.domain.ReconciliationQuery;
import com.ruoyi.ss.reconciliation.service.IReconciliationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台对账Controller
 *
 * @author qzz
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/system/reconciliation")
public class ReconciliationController extends BaseController
{
    @Autowired
    private IReconciliationService reconciliationService;

    /**
     * 查询平台对账列表
     */
    @PreAuthorize("@ss.hasPermi('system:reconciliation:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReconciliationQuery query)
    {
        startPage();
        startOrderBy();
        List<ReconciliationVO> list = reconciliationService.selectSsReconciliationList(query);
        return getDataTable(list);
    }

    /**
     * 导出平台对账列表
     */
    @PreAuthorize("@ss.hasPermi('system:reconciliation:export')")
    @Log(title = "平台对账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReconciliationQuery query)
    {
        List<ReconciliationVO> list = reconciliationService.selectSsReconciliationList(query);
        ExcelUtil<ReconciliationVO> util = new ExcelUtil<ReconciliationVO>(ReconciliationVO.class);
        util.exportExcel(response, list, "平台对账数据");
    }

    /**
     * 获取平台对账详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:reconciliation:query')")
    @GetMapping(value = "/{reconciliationId}")
    public AjaxResult getInfo(@PathVariable("reconciliationId") Long reconciliationId)
    {
        return success(reconciliationService.selectSsReconciliationByReconciliationId(reconciliationId));
    }

    /**
     * 新增平台对账
     */
    @PreAuthorize("@ss.hasPermi('system:reconciliation:add')")
    @Log(title = "平台对账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Reconciliation ssReconciliation)
    {
        return toAjax(reconciliationService.insertSsReconciliation(ssReconciliation));
    }

    /**
     * 修改平台对账
     */
    @PreAuthorize("@ss.hasPermi('system:reconciliation:edit')")
    @Log(title = "平台对账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reconciliation ssReconciliation)
    {
        return toAjax(reconciliationService.updateSsReconciliation(ssReconciliation));
    }

    /**
     * 删除平台对账
     */
    @PreAuthorize("@ss.hasPermi('system:reconciliation:remove')")
    @Log(title = "平台对账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reconciliationIds}")
    public AjaxResult remove(@PathVariable Long[] reconciliationIds)
    {
        return toAjax(reconciliationService.deleteSsReconciliationByReconciliationIds(reconciliationIds));
    }
}
