package com.ms.biz;

import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.biz.common.R;
import com.ms.biz.common.Ret;
import com.ms.biz.common.SPIBaseService;
import com.ms.api.dto.ItemDTO;
import com.ms.biz.paas.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;


@ExtensionService("testTos")
@Slf4j
public class TestTosService extends SPIBaseService implements ExtensionServiceHandler<ItemDTO, String> {

    @Autowired
    StorageService storageService;

    @Override
    public BaseResponse<String> handle(BaseRequest<ItemDTO> req) {
        try{
            initHandle(req);

            Ret ret = storageService.uploadContent("test","这是测试数据");
            String url = (String)ret.getData().get("url");
            ret = storageService.getContent("test");
            String content = (String)ret.getData().get("data");
            String publicUrl = storageService.getPubOssUrlByOssPath("test");

            return R.ok("地址:" + url + "内容:" + content + "公网地址: " + publicUrl);
        }catch (Throwable e){
            e.printStackTrace();
            return R.ok(e.getMessage());
        }
    }
}
