package com.leromro.core.controller;

import com.leromro.common.annotation.Log;
import com.leromro.common.core.controller.BaseController;
import com.leromro.common.core.domain.R;
import com.leromro.common.core.page.TableDataInfo;
import com.leromro.common.enums.BusinessType;
import com.leromro.common.utils.poi.ExcelUtil;
import com.leromro.core.domain.dto.OrderSettlementApplicationListDTO;
import com.leromro.core.domain.dto.SettlementOrderApplyDTO;
import com.leromro.core.domain.dto.SettlementOrderAuditorDTO;
import com.leromro.core.domain.vo.OrderSettlementApplicationDetailVO;
import com.leromro.core.domain.vo.OrderSettlementApplicationListVO;
import com.leromro.core.service.IOrderSettlementApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 订单费用结算申请Controller
 * 
 * @author lsd
 * @date 2025-05-13
 */
@RestController
@Api(tags = "订单费用结算申请")
@RequestMapping("/core/orderSettlementApplication")
public class OrderSettlementApplicationController extends BaseController
{
    @Autowired
    private IOrderSettlementApplicationService orderSettlementApplicationService;

    /**
     * 查询订单费用结算申请列表
     */
    @ApiOperation("查询订单费用结算申请列表")
    @GetMapping("/list")
    public TableDataInfo<OrderSettlementApplicationListVO> list(OrderSettlementApplicationListDTO orderSettlementApplicationListDTO)
    {
        List<OrderSettlementApplicationListVO> list = orderSettlementApplicationService.selectOrderSettlementApplicationList(orderSettlementApplicationListDTO);
        return getDataTable(list);
    }

    /**
     * 导出订单费用结算申请列表
     */
    @ApiOperation("导出订单费用结算申请列表")
    @Log(title = "订单费用结算申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderSettlementApplicationListDTO orderSettlementApplicationListDTO)
    {
        List<OrderSettlementApplicationListVO> list = orderSettlementApplicationService.selectOrderSettlementApplicationList(orderSettlementApplicationListDTO);
        ExcelUtil<OrderSettlementApplicationListVO> util = new ExcelUtil<OrderSettlementApplicationListVO>(OrderSettlementApplicationListVO.class);
        util.exportExcel(response, list, "订单费用结算申请数据");
    }

    /**
     * 获取订单费用结算申请详细信息
     */
    @ApiOperation("获取订单费用结算申请详细信息")
    @GetMapping(value = "/{id}")
    public R<OrderSettlementApplicationDetailVO> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(orderSettlementApplicationService.selectOrderSettlementApplicationById(id));
    }

    /**
     * 区域公司/服务中心订单结算申请
     */
    @ApiOperation("区域公司/服务中心订单结算申请")
    @PostMapping("/web/applyOrderSettlement")
    public R applyOrderSettlement(@RequestBody @Validated SettlementOrderApplyDTO settlementOrderApplyDTO) {
        orderSettlementApplicationService.applyOrderSettlement(settlementOrderApplyDTO);
        return R.ok();
    }

    /**
     * 区域公司/服务中心订单结算审核
     */
    @ApiOperation("区域公司/服务中心订单结算审核")
    @PostMapping("/web/auditorOrderSettlement")
    public R auditorOrderSettlement(@RequestBody @Validated SettlementOrderAuditorDTO settlementOrderAuditorDTO) {
        orderSettlementApplicationService.auditorOrderSettlement(settlementOrderAuditorDTO);
        return R.ok();
    }
}
