package com.malk.kabeiyi;

import com.malk.kabeiyi.service.KabeiyiService;
import com.malk.service.dingtalk.DDClient;
import com.malk.service.dingtalk.DDClient_Workflow;
import com.malk.utils.UtilDateTime;
import lombok.extern.slf4j.Slf4j;
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.time.LocalDateTime;
import java.util.*;

@Slf4j
@SpringBootTest
@RunWith(SpringRunner.class)
public class DdTest {


    @Autowired
    private DDClient ddClient;

    @Autowired
    private DDClient_Workflow ddClient_workflow;

    @Autowired
    private KabeiyiService kabeiyiService;


    @Test
    public void test(){
        LocalDateTime now=LocalDateTime.now();
        Map data=new HashMap();
        data.put("maxResults",10);
        data.put("nextToken",0);
        data.put("statuses", Arrays.asList("COMPLETED"));
        String processCode = "PROC-34A203FD-7EDC-45ED-B081-820250801B44";//1.1、工厂用章流程(除采购营销人事)
//        String processCode = "PROC-AD06D122-828A-40A5-8EDC-94BB246B59D2";

        Map rsp=ddClient_workflow.getInstanceIds(ddClient.getAccessToken(),processCode,
                UtilDateTime.getLocalDateTimeTimeStamp(now.minusDays(120)),UtilDateTime.getLocalDateTimeTimeStamp(now),data);
        List<String> list=(List)rsp.get("list");
        List result=new ArrayList();
        for(String id:list){
            result.add(ddClient_workflow.getProcessInstanceId(ddClient.getAccessToken(),id));
        }
        log.info("result:{}",result);
    }


    @Test
    public void test2(){
        Map map = new HashMap<>();
        map.put("procInstId","gl7nXvi4TLebPjFW2oqmrA05771720664838");
        kabeiyiService.pushProcInstToYD(map);

    }
}
