package com.trade.admin.trade.salesorder;

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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

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

    @Resource
    private ICustomsDeclarationService customsDeclarationService;

    /**
     * 获取报关单列表
     */
    @RequestMapping("/queryList")
    @PreAuthorize("@ss.hasPermi('trade:salesBgd:list')")
    public Object queryList(CustomsDeclarationSearch search) {
        return ResponseResult.success(customsDeclarationService.queryListBySearch(search));
    }

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

    /**
     * 重定向小图进行报关单下载
     */
    @GetMapping("/download")
    @PreAuthorize("@ss.hasRole('EXPORT_TAX_REFUNDER')")
    public ResponseResult<String> getDownloadCustomsDeclarationUrl(String xtUserId, String xtEid) {
        String taxRebateUrl = customsDeclarationService.getDownloadCustomsDeclarationUrl(xtUserId, xtEid);
        return ResponseResult.success(taxRebateUrl);
    }
}
