package edu.neusoft.project.util.Thread;

import edu.neusoft.project.model.service.PersonService;
import edu.neusoft.project.util.OSSCtrl.OssPostObject;

import java.util.Date;
import java.util.concurrent.Callable;

public class OssBasicUploadThread implements Callable<Integer> {
    private String postFileName ;  // 确保运行代码的路径中有该文件
    private String objectName ;  // 你上传文件之后的object名称
    private String bucket ;  // 你之前创建的bucket，确保这个bucket已经创建
    private PersonService service = new PersonService();


    public OssBasicUploadThread(String postFileName, String objectName, String bucket) {
        this.postFileName = postFileName;
        this.objectName = objectName;
        this.bucket = bucket;
    }


    @Override
    public Integer call() throws Exception {
        OssPostObject oss=new OssPostObject(postFileName,"personPict/"+objectName,bucket);
        System.out.println(new Date()+Thread.currentThread().getName()+"OSSBasicUpload-----ON");
        oss.PostObject();
        int ret =service.updPersonPict("personPict/"+objectName,objectName);
        System.out.println(new Date()+Thread.currentThread().getName()+"OSSBasicUpload-----OFF");
        if (ret == 1 ){
            return 1;
        }
        return 0;
    }
}
