package com.sckw.report.controller;

import com.sckw.core.exception.CustomPromptException;
import com.sckw.core.utils.CollectionUtils;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.excel.utils.ExcelUtil;
import com.sckw.report.service.KwOrderService;
import com.sckw.report.service.param.*;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zk
 * @desc 订单服务
 * @date 2023/7/10 0010
 */
@AllArgsConstructor
@RestController
@RequestMapping("/kwOrder")
public class KwOrderController {

    private final KwOrderService orderService;

    /**
     * @desc: 贸易订单详情
     * @author: yzc
     * @date: 2023-07-17 10:29
     * @Param id:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GetMapping("/tradeOrderDetail")
    public HttpResult detail(@RequestParam Long id) {
        return HttpResult.ok(orderService.tradeOrderDetail(id));
    }

    /**
     * @desc: 贸易订单列表分页查询
     * @author: yzc
     * @date: 2023-07-17 10:29
     * @Param params:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/tradeOrderSelect", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult select(@RequestBody @Validated TradeOrderListSelectParam params) {
        return HttpResult.ok(orderService.tradeOrderSelect(params));
    }

    /**
     * @desc: 贸易订单列表统计查询
     * @author: yzc
     * @date: 2023-07-17 10:29
     * @Param params:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/tradeOrderStatistic", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult statistic(@RequestBody @Validated TradeOrderListStatisticParam params) {
        return HttpResult.ok(orderService.tradeOrderStatistic(params));
    }

    /**
     * @desc: app主界面贸易订单统计
     * @author: yzc
     * @date: 2023-08-21 17:38
     * @Param params:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/tradeOrderAppStatistic", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult appStatistic(@RequestBody @Validated TradeOrderAppStatisticParam params) {
        return HttpResult.ok(orderService.appStatistic(params));
    }

    /**
     * @desc: 贸易订单列表导出
     * @author: yzc
     * @date: 2023-07-17 10:29
     * @Param params:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/tradeOrderExport", produces = MediaType.APPLICATION_JSON_VALUE)
    public void export(@RequestBody @Validated TradeOrderListExportParam params, HttpServletResponse response) {
        List<TradeOrderListExport> list = orderService.export(params);
        if (CollectionUtils.isEmpty(list)) {
            throw new CustomPromptException(HttpStatus.SUCCESS_CODE, "暂无数据，请确认");
        }
        ExcelUtil.downData(response, TradeOrderListExport.class, list);
    }

    /**
     * @desc: 贸易订单对账单分页列表查询
     * @author: yzc
     * @date: 2023-07-20 15:03
     * @Param params:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/tradeOrderStatementList", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult tradeOrderStatementList(@RequestBody @Validated TradeOrderStatementList params) {
        return HttpResult.ok(orderService.tradeOrderStatementList(params));
    }

    /**
     * @desc: 合同关联订单列表
     * @author: yzc
     * @date: 2023-07-27 16:48
     * @Param params:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/tradeOrderContractList", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult tradeOrderContractList(@RequestBody @Validated TradeOrderContractParam params) {
        return HttpResult.ok(orderService.tradeOrderContractList(params));
    }
}
