package com.trade.admin.trade.purchaseorder.controller;

import com.trade.admin.enterprise.customer.dto.CustomerUserDto;
import com.trade.admin.enterprise.customer.service.CustomerUserService;
import com.trade.admin.job.PurchaseInvoiceSchedule;
import com.trade.common.core.domain.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @Author: wanglang
 * @Date: 2024/11/6 18:35
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api")
public class PurchaseInvoiceApiController {

    @Resource
    private PurchaseInvoiceSchedule purchaseInvoiceSchedule;
    @Resource
    private CustomerUserService customerUserService;

    @PostMapping("/pullInvoiceFile")
    public ResponseResult<Boolean> pullInvoiceFile(@RequestBody List<String> orderIds) {
        List<Long> ids = new ArrayList<>();
        for (String orderId : orderIds) {
            ids.add(Long.valueOf(orderId));
        }
        purchaseInvoiceSchedule.pullInvoiceDetail(ids);
        return ResponseResult.success(true);
    }

    @GetMapping("/getCustomerUser")
    public ResponseResult<CustomerUserDto> getCustomerUser(String userId) {
        return customerUserService.getCustomerUser(userId);
    }

    @GetMapping("/pullPurchaseInvoice")
    public ResponseResult<Boolean> pullPurchaseInvoice(String orderIds, Integer source) {
        List<Long> ids = new ArrayList<>();
        ids.add(Long.valueOf(orderIds));
        purchaseInvoiceSchedule.pullPurchaseInvoice(ids, source);
        return ResponseResult.success(true);
    }
}
