package com.clx.performance.controller.temp;

import com.clx.performance.service.TempService;
import com.clx.performance.vo.pc.child.OrderChildLineStatisticsVO;
import com.msl.common.result.Result;
import com.nbcb.sdk.OpenSDK;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.init.ResourceReader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;


/**
 * @Author: aiqingguo
 * @Description: 临时接口
 * @Date: 2023-8-21 12:10:16
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping(value="/temp/bank")
public class TempBankController {

    @Autowired
    private TempService tempService;

    @ApiOperation(value = "test", notes = "<br>By:艾庆国")
    @RequestMapping(value = "/test", method = RequestMethod.POST)
    public Result<OrderChildLineStatisticsVO> test() throws Exception {

        bankTest();


        return Result.ok();
    }

    private void bankTest() throws Exception {
        String priKey = "MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgTt6OadouxxxSDg/0SZdOIBqtnFGKrpwmL+quEUf+hfSgCgYIKoEcz1UBgi2hRANCAAQGHNN2NO7btp+w1248yk98E0asGC8sG0bmIzdom4M0xp3vc4IfXjmZ8omUz4oVcjzAuyMSSpJM6uPLcU1SH4HZ";

        InputStream inputStream = TempBankController.class.getClassLoader().getResourceAsStream("config.properties");
        if (inputStream != null) {
            log.info("存在2");

            OpenSDK.init(inputStream, priKey);

            try (FileOutputStream fos = new FileOutputStream("/app/a.txt")) {

                fos.write("123 测试".getBytes());
                String res1 = OpenSDK.sendFile("", "open-filegateway","/app/a.txt");

                log.info("url:{}", res1);

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        else{
            log.info("文件不存在");
        }

    }



    public static void main(String[] args) {

        try {
            callBySepJson();
            //demo.callByBean();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @throws Exception
     */
    public static void callBySepJson() throws Exception {
        String priKey = "MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgTt6OadouxxxSDg/0SZdOIBqtnFGKrpwmL+quEUf+hfSgCgYIKoEcz1UBgi2hRANCAAQGHNN2NO7btp+w1248yk98E0asGC8sG0bmIzdom4M0xp3vc4IfXjmZ8omUz4oVcjzAuyMSSpJM6uPLcU1SH4HZ";

        System.out.println(TempBankController.class.getClassLoader().getResource("").getPath());

        OpenSDK.init(TempBankController.class.getClassLoader().getResource("config.properties").getPath(), priKey);


        /*
         * dataJson 是放置具体交易请求业务报文,dataJson报文结构如下： {"Data":{"app_name":"1"}}
         */
//        String dataJson="";
//        // 发送请求并获取响应(第一个填入productId,第二个填入serviceId)
//        String res = OpenSDK.send("", "", dataJson);
//        if (log.isDebugEnabled()) {
//            log.debug("res: " + res);
//        }

        //上传文件
        String res1 = OpenSDK.sendFile("", "open-filegateway",TempBankController.class.getClassLoader().getResource("bank.txt").getPath());

        System.out.println(res1);
        //下载文件
//		String res = OpenSDK.sendFileDownload( "productId","fcd47917-bc9c-4c11-b217-f7095f5384fe","D:\\ab\\test");
    }

    /**
     * JavaBean方式（通过产品SDK提供的JavaBean）
     *
     * @throws Exception
     */
    public void callByBean() throws Exception {

    }

}
