package com.sckw.report.controller.operator;

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.model.vo.OperatorTOrderContractParam;
import com.sckw.report.model.vo.OperatorTOrderExportQueryVO;
import com.sckw.report.model.vo.OperatorTOrderListQueryVO;
import com.sckw.report.model.vo.OperatorTOrderStsQueryVO;
import com.sckw.report.service.operator.TradeOrderManageService;
import com.sckw.report.service.param.TradeOrderListExport;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @desc: 运营端贸易订单管理相关接口
 * @author: yzc
 * @date: 2023-09-14 11:21
 */
@AllArgsConstructor
@RestController
@RequestMapping("/kwOrderManage")
public class TradeOrderManageController {

    private final TradeOrderManageService tradeOrderManageService;


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

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

    /**
     * @desc: 贸易订单列表导出
     * @author: yzc
     * @date: 2023-09-14 14:40
     * @Param params:
     * @Param response:
     * @return: void
     */
    @PostMapping(value = "/listExport", produces = MediaType.APPLICATION_JSON_VALUE)
    public void listExport(@RequestBody @Validated OperatorTOrderExportQueryVO params, HttpServletResponse response) {
        List<TradeOrderListExport> list = tradeOrderManageService.export(params);
        if (CollectionUtils.isEmpty(list)) {
            throw new CustomPromptException(HttpStatus.SUCCESS_CODE, "暂无数据，请确认");
        }
        ExcelUtil.downData(response, TradeOrderListExport.class, list);
    }

    /**
     * @desc: 合同关联订单列表
     * @author: yzc
     * @date: 2023-09-14 14:51
     * @Param params:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/contractAssociationList", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult contractAssociationList(@RequestBody @Validated OperatorTOrderContractParam params) {
        return HttpResult.ok(tradeOrderManageService.contractAssociationList(params));
    }

}
