前言

Github:https://github.com/HealerJean

博客:http://blog.healerjean.com

package com.duodian.youhui.admin.config;

import com.duodian.youhui.admin.constants.WeChatMessageParams;
import com.duodian.youhui.admin.constants.WechatMenuParams;
import com.duodian.youhui.dao.db.wechat.WeChatBusinessNoRepository;
import com.duodian.youhui.entity.db.wechat.WeChatBusinessNo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;

/**
 * @Desc:
 * @Author HealerJean
 * @Date 2018/8/17  下午5:18.
 */
@Component
public class PostConstructConfig {




    @Value("${docker_imagesDirectory}")
    private String docker_imagesDirectory ;

    @Value("${docker_erweimaEmptDirectory}")
    private String docker_erweimaEmptDirectory ;


    @Resource
    private WeChatBusinessNoRepository weChatBusinessNoRepository;


    @PostConstruct
    private void init()  throws Exception {


        //为docker容器中创建目录
        File imagesDirectory = new File(docker_imagesDirectory);
        File erweimaEmptDirectory = new File(docker_erweimaEmptDirectory);

        if(!imagesDirectory.exists()){
            imagesDirectory.mkdirs();
        }
        if(!erweimaEmptDirectory.exists()){
            erweimaEmptDirectory.mkdirs();
        }

        File shikeImage = new File(imagesDirectory,"shike.jpg");
        if(!shikeImage.exists()){
            FileOutputStream outputStreamShikeImage = new FileOutputStream(shikeImage);
            URL ushike = new URL("http://image.dangqugame.cn/admin/webproject/shike.jpg");
            BufferedImage imageShikeImage = ImageIO.read(ushike);
            ImageIO.write(imageShikeImage, "jpg", outputStreamShikeImage);

        }

        File contactmanager = new File(imagesDirectory, "contactmanager.jpg");
        if(!contactmanager.exists()) {
            FileOutputStream outputStreamContactmanager = new FileOutputStream(contactmanager);
            URL ucontactmanager = new URL("http://image.dangqugame.cn/admin/webproject/contactmanager.jpg");
            BufferedImage imageContactmanager = ImageIO.read(ucontactmanager);
            ImageIO.write(imageContactmanager, "jpg", outputStreamContactmanager);
        }
    }


}


ContactAuthor