package com.trade.client.trade.salesorder.controller;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

import com.trade.client.security.utils.UserUtils;
import com.trade.client.trade.exportrebate.service.ExportTaxRebateService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.trade.common.core.domain.ResponseResult;
import com.trade.service.trade.salesorder.service.ICustomsDeclarationService;
import com.trade.service.trade.salesorder.vo.CustomsDeclarationSearch;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 报关单信息 前端控制器
 * </p>
 *
 * @author zhangchenm
 * @since 2024-09-19
 */
@RestController
@RequestMapping("/customsDeclaration")
public class CustomsDeclarationController {

    @Resource
    private ICustomsDeclarationService customsDeclarationService;
    @Resource
    private ExportTaxRebateService exportTaxRebateService;

    /**
     * 获取报关单列表
     */
    @RequestMapping("/queryList")
    public Object queryList(CustomsDeclarationSearch search) {
        search.setCustomerUserId(UserUtils.getCustomerUserId());
        return ResponseResult.success(customsDeclarationService.queryListBySearch(search));
    }

    /**
     * 根据订单id获取报关单详情
     */
    @RequestMapping("/getDetailById")
    public Object getDetailById(@NotNull(message = "ID不能为空") Long id) {
        return ResponseResult.success(customsDeclarationService.getDetailById(id));
    }

    /**
     * 重定向小图进行报关单下载
     */
    @GetMapping("/download")
    public ResponseResult<String> getDownloadCustomsDeclarationUrl() {
        String url = exportTaxRebateService.getDownloadCustomsDeclarationUrl();
        return ResponseResult.success(url);
    }
}
