package cn.teammodel.controller.admin.service.impl;

import cn.teammodel.common.ErrorCode;
import cn.teammodel.config.exception.ServiceException;
import cn.teammodel.controller.admin.service.BlobService;
import cn.teammodel.model.dto.admin.exam.BlobSasDto;
import cn.teammodel.utils.GroupUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.Map;

@Service
public class BlobServiceImpl implements BlobService {
    @Autowired
    private Environment env;
    @Override
    public Map<String, Object> getBlobSas(BlobSasDto blobSasDto, HttpServletRequest request) {

        Map<String, Object> sas;
        String url = env.getProperty("ies.server-url-blob-sas-rcwld");

        try {
            sas =  GroupUtil.getGroupId(blobSasDto,new GroupUtil(env), request,url);

        }catch (Exception e) {
            throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据转换错误");
        }
        return sas;
    }

    @Override
    public Map<String, Object> getSasR99(BlobSasDto blobSasDto, HttpServletRequest request) {

        Map<String, Object> sas;
        String url = env.getProperty("ies.server-url-blob-sas-r-99");

        try {
            sas =  GroupUtil.getGroupId(blobSasDto,new GroupUtil(env), request,url);

        }catch (Exception e) {
            throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据转换错误");
        }
        return sas;
    }
}
