package com.xy.service;

import com.xy.annotate.RestMappingController;
import com.xy.dto.DeviceInfoDto;
import com.xy.utils.R;
import com.xy.utils.TyImgUrlConvert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;
import java.io.IOException;

/***
 * 异步导出处理
 * @author 谭斌
 * @date 2023/3/4 10:44
 */
@Service
@RequiredArgsConstructor
@Api(tags = "文件导出-异步")
@RestMappingController("export/async")
public class ExportAsyncService {

    private final DeviceInfoServiceImpl deviceInfoService;

    @ApiOperation("导出设备信息")
    @PostMapping("deviceInfo")
    public R exportDeviceInfo(@RequestBody @Valid DeviceInfoDto.Page page) {
        deviceInfoService.exportDevicesAsync(page);
        return R.ok();
    }

    @ApiOperation("拓元商品上传")
    @PostMapping("tyGoodsImgUpload")
    public R tyGoodsImgUpload() {
        try {
            TyImgUrlConvert.upload();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return R.ok();
    }

}
