
package com.tmerclub.cloud.search.controller.supplier;

import com.tmerclub.cloud.api.product.feign.CategoryShopFeignClient;
import com.tmerclub.cloud.api.product.feign.SkuFeignClient;
import com.tmerclub.cloud.api.product.feign.SpuFeignClient;
import com.tmerclub.cloud.api.supplier.feign.SupplierDetailFeignClient;
import com.tmerclub.cloud.common.order.dto.OrderSearchDTO;
import com.tmerclub.cloud.common.order.vo.OrderExcelVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.common.util.ExcelUtil;
import com.tmerclub.cloud.search.manager.OrderSearchManager;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 订单搜索
 *
 * @author YXF
 * @date 2023/08/10
 */
@RestController("supplierOrderSearchController")
@RequestMapping("/s/order/search")
@Tag(name = "admin-order管理列表接口")
public class OrderSearchController {
    private static final Logger LOGGER = LoggerFactory.getLogger(OrderSearchController.class);

    @Autowired
    private OrderSearchManager orderSearchManager;
    @Autowired
    private SkuFeignClient skuFeignClient;
    @Autowired
    private CategoryShopFeignClient categoryShopFeignClient;
    @Autowired
    private SpuFeignClient spuFeignClient;
    @Autowired
    private SupplierDetailFeignClient supplierDetailFeignClient;


    @GetMapping("/soldExcel")
    @Operation(summary = "导出excel", description = "导出订单excel")
    public ServerResponseEntity<Void> orderSoldExcel(HttpServletResponse response, OrderSearchDTO orderSearchDTO) {
        orderSearchDTO.setSupplierId(AuthUserContext.get().getTenantId());
        orderSearchDTO.setIsPayed(1);
        // 查询订单列表
        List<OrderExcelVO> orderExcelList = orderSearchManager.orderExcelScrollSearch(orderSearchDTO);
        // 生成excel
        ExcelUtil.soleExcel(response, orderExcelList, OrderExcelVO.EXCEL_NAME, OrderExcelVO.MERGE_ROW_INDEX, OrderExcelVO.MERGE_COLUMN_INDEX, OrderExcelVO.class);
        return ServerResponseEntity.success();
    }
}
