package cn.superdesk.uniorder.controller.operationCenter.order;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dto.param.accounting.statistics.ReceivableBalanceQueryParam;
import cn.superdesk.uniorder.dto.param.operationCenter.order.OperationCenterOrderParam;
import cn.superdesk.uniorder.dto.vo.operationCenter.order.OperationCenterOrderDetailsVo;
import cn.superdesk.uniorder.dto.vo.operationCenter.order.OperationCenterOrderFormVo;
import cn.superdesk.uniorder.dto.vo.operationCenter.order.OperationCenterOrderVo;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedOrderGoodsVo;
import cn.superdesk.uniorder.dubbo.consumer.operationCenter.order.OperationCenterOrderDubboService;
import com.alibaba.fastjson2.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : zx
 * @Create : 2023/3/24 11:26
 * Description : 运营中心1.0 数据同步 订单管理
 */

@Api(value = "运营中心-订单管理", tags = {"订单管理-订单"})
@Slf4j
@RestController
@RequestMapping("/operationCenter/order")
@RequiredArgsConstructor
public class OperationCenterOrderController extends BaseController {

    private final OperationCenterOrderDubboService operationCenterOrderDubboService;

    @ApiOperation(value = "运营中心-订单管理-列表", notes = "")
    @PostMapping("/list")
    @ResponseBody
    public R<OperationCenterOrderFormVo> list(@RequestBody @Validated OperationCenterOrderParam param) {
        log.info("运营中心-订单管理-列表,param:{}", JSON.toJSONString(param));

        R<OperationCenterOrderFormVo> result = new R<>();

        result=operationCenterOrderDubboService.list(param);

        return result;
    }

    @ApiOperation(value = "运营中心-订单管理-订单详情", notes = "")
    @PostMapping("/get/{id}")
    @ResponseBody
    public R<OperationCenterOrderDetailsVo> get(@PathVariable("id") Long id) {
        R<OperationCenterOrderDetailsVo> result = new R<>();
        if (null == id) {
            return result;
        }
        result = operationCenterOrderDubboService.getOperationCenterOrderDetails(id);
        return result;
    }

    /**
     * 导出订单列表
     * @param param
     * @return
     */

    @PostMapping("/export")
    public R<String> exportExcelOperationCenterOrder(@RequestBody OperationCenterOrderParam param) {
        log.info("导出运营中心订单-商品-报表, param : {}", param);
        return new R<>(operationCenterOrderDubboService.exportExcelOperationCenterOrder(param,getToken()));
    }

    /**
     * 导出订单详情
     * @param id
     * @return
     */
    @PostMapping("/export/{id}")
    public R<String> exportExcelOperationCenterOrder(@PathVariable("id") Long id) {
        log.info("导出运营中心订单-详情-商品-报表, param : {}", id);
        return new R<>(operationCenterOrderDubboService.exportExcelOperationCenterOrderId(id,getToken()));
    }

}
