package com.malk.ruisi;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.malk.ruisi.service.QysApiService;
import com.malk.ruisi.service.QysService;
import com.malk.ruisi.service.RsQysService;
import com.malk.server.aliwork.YDConf;
import com.malk.server.aliwork.YDParam;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest
@RunWith(SpringRunner.class)
public class test {

    @Autowired
    private QysApiService qysApiService;
    @Autowired
    private QysService qysService;
    @Autowired
    private RsQysService rsQysService;
//上传文件得到文档Id
    @Test
    public void test() throws Exception {
        Map data=new HashMap();
        data.put("file", FileUtil.file("/home/file/123.docx"));
        data.put("title","123");
        data.put("fileType","docx");
//        data.put("bizId",bizId);
//        data.put("title",FileUtil.mainName(file));
//        data.put("file", file);
//        data.put("fileSuffix", FileUtil.extName(file));
//        data.put("tenantName",tenantName);
//        qysApiService.sendPostFile(data,"/v2/document/createbyfile");
        qysService.createbyfile(data);
    }


//    @Test
//    public void test222(){
//        JSONObject obj=new JSONObject();
//        obj.put("formInstanceId","");
//        rsQysService.createbyfile("6552b416-09d0-4cd4-af9a-2b549144a508");
//    }


//    String bizId=param.getString("bizId");
//    String formInstanceId=param.getString("formInstanceId");
//    Map data = (Map) ydClient.queryData(YDParam.builder().formInstId(formInstanceId)
//            .appType(ydConf.getAppType()).systemToken(ydConf.getSystemToken())
//            .userId(ddConf.getOperator()).build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
//        log.info("data:{}",JSONObject.toJSONString(data));
//
//    JSONObject obj=new JSONObject();
//        obj.put("subject",data.get("textField_ltsbwef0"));
//        obj.put("sn",data.get("serialNumberField_ltsbweh2"));
//        obj.put("categoryName",data.get("textField_ltsbweif"));
//        obj.put("signatory",data.get("textField_ltwa0vk0"));
//        obj.put("send",false);// 是否发起合同；发起合同后不能再进行添加文档、指定签署位置等操作
//
//    JSONArray array=new JSONArray();
//    JSONObject signatory=new JSONObject();
////        signatory.put("tenantType",data.get("selectField_ltsbwei6"));
//        signatory.put("tenantType","COMPANY");
//        signatory.put("tenantName",data.get("selectField_ltsbwei5"));
//    // 假设 data 是一个 Map<String, String> 对象
////        String selectFieldValue = (String) data.get("selectField_lu69xx6q");
////        List<Integer> result;
////
////        if ("是".equals(selectFieldValue)) {
////            result = Arrays.asList(1, 2, 3);
////        } else {
////            result = Arrays.asList(1, 1, 1);
////        }
////
////        signatory.put("serialNo",result);
//        array.add(signatory);
////
//        obj.put("signatories",array);
//
//        log.info("obj:{}",obj);
//        try {
//        log.info("1. 创建合同草稿 {}",bizId);
//        JSONObject draft=qysService.createDraft(obj);
//        System.out.println(draft);
//    } catch (Exception e) {
//        e.printStackTrace();
//    }

    @Test
    public void qystest() throws Exception {
        Map map=new HashMap();
        map.put("sn","HT01-HTYY-202405200047");
        map.put("contractId","3230485872831869324");
        map.put("status","SIGNED");
        rsQysService.callback(map);
    }
}
