package org.jeecg.modules.wps.util;

import org.jeecg.modules.wps.util.file.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class WpsUtil {
    @Value("wps.domain")
    private String domain;
    @Value("wps.appid")
    private String appid;
    @Value("wps.appsecret")
    private String appsecret;
    @Value("wps.download_host")
    private String downloadHost;
    @Value("wps.local_Dir")
    private String localDir;
    public String getWpsUrl(Map<String,String> values,String fileType,String fileId){
        String keyValueStr = SignatureUtil.getKeyValueStr(values);
        String signature = SignatureUtil.getSignature(values, appsecret);
        String fileTypeCode = FileUtil.getFileTypeCode(fileType);

        return domain + fileTypeCode + "/" + fileId + "?"
                + keyValueStr + "_w_signature=" + signature;
    }

    public String getTemplateWpsUrl(String fileType,String userId){
        Map<String,String> values = new HashMap<>();
        values.put("_w_appid", appid);
        values.put("_w_userid", userId);
        String keyValueStr = SignatureUtil.getKeyValueStr(values);
        String signature = SignatureUtil.getSignature(values, appsecret);
        String fileTypeCode = FileUtil.getTypeCode(fileType);

        return domain + fileTypeCode + "/new/0" + "?"
                + keyValueStr + "_w_signature=" + signature;
    }

}
