package com.mortals.xhx.module.print.service.PrintComponent;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.mortals.xhx.common.code.PrintTypeEnum;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UrlPrintComponent extends BasePrintComponent {

    public UrlPrintComponent(String type) {
        super(type);
    }

    @Override
    public void print(ComponentCons cons) {
        //通过网络下载附件地址
        byte[] fileBytes = HttpUtil.downloadBytes(cons.getUrl());
        //获取文件后缀
        String suffixName = FileUtil.getSuffix(cons.getUrl());
        log.info("file lens:{}", fileBytes.length);
        log.info("file suffixName:{}", suffixName);
    }


    @Override
    public String getType() {
        return PrintTypeEnum.PRINT_URL.getValue();
    }
}
