package com.winsun.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sun.org.apache.regexp.internal.RE;
import com.winsun.bean.Package;
import com.winsun.constant.FilePath;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpRequest;
import org.springframework.http.MediaType;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Author xuede
 * @Date 2020/3/6 16:44
 * @Version 1.0
 */
@Slf4j
@RestController
public class ImgController {

    //menuname = "图片路径"  只支持jpeg 和 png
    @RequestMapping( value = "/images/**",produces ={MediaType.IMAGE_JPEG_VALUE,MediaType.IMAGE_PNG_VALUE} )
    public byte[] getbackground(HttpServletRequest request) {
        byte[] bytes={};
        request.getServletPath();
        String  imgurl= FilePath.BACKGROUNDIMG.getValue()+"/"+request.getServletPath();
        imgurl = imgurl.replace("//", "/");
        File file = new File(imgurl);
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
        } catch (Exception e) {
            log.error("图片下载失败",e.getMessage());
        }
        bytes = new byte[0];
        try {
            bytes = new byte[inputStream.available()];
        } catch (Exception e) {
            log.error("图片下载失败",e.getMessage());
        }
        try {
            inputStream.read(bytes, 0, inputStream.available());
        } catch (Exception e) {
            log.error("图片下载失败",e.getMessage());
        }
        return bytes;
    }
}
