package com.malk.mc;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.malk.mc.entity.PocTbUser;
import com.malk.mc.mapper.PocTbUserMapper;
import com.malk.mc.service.McPocTbService;
import com.malk.service.dingtalk.DDClient;
import com.malk.service.dingtalk.DDClient_Notice;
import com.malk.service.dingtalk.DDClient_Workflow;
import com.malk.service.teambition.TBClient;
import com.malk.utils.UtilMap;
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.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.util.*;

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

    @Autowired
    private McPocTbService mcPocTbService;
    @Autowired
    private TBClient tbClient;

    @Autowired
    private PocTbUserMapper pocTbUserMapper;
    @Autowired
    private DDClient_Workflow ddClient_workflow;
    @Autowired
    private DDClient ddClient;

    @Test
    public void test() {
        String url="https%3A%2F%2Foapi.dingtalk.com%2Fconnect%2Foauth2%2Fsns_authorize%3Fappid%3Ddingclamhu8t5rm8nvbe%26response_type%3Dcode%26scope%3Dsnsapi_auth%26redirect_uri%3Dhttps%3A%2F%2Ftyeeli.test.isrm.going-link.com%2Foauth%2Flogin%2Fbykey%2F__unilink%2F76fzZhsvEibt6AusJiaLPoFc0F7Hs3V3DnUJNRJOuS2c7glLug7wEumwptkIgK3QMwpuLbUro6gSnWJGMIabbJbDkDAOHB6d1DWBiaCU64jwDpmRyIUCuzicg4JhW9YH9fevXP1waCmbyzccTVwnx0MnDQ";
//        mcPocTbService.saveWorkTimes("665ee80a57df029b4375c6de","616fb6f78ad4104a10515809", Arrays.asList("6671330b546ad300120e4c5c"));
        ddClient_workflow.createTBTask(ddClient.getAccessToken(),"153620324221442254","测试","测试",0,
                Arrays.asList("153620324221442254"),Arrays.asList(),UtilMap.map("pcUrl, appUrl",url,url),true,10,null);
    }

    @Test
    public void test2() {
        Map content = new HashMap<>();
        content.put("attachments",new Array[]{});
        content.put("text","已经完成，在协助客户测试，解决客>户提出的问题");
        mcPocTbService.saveWeekly("667a8acecb1f84f76e4e1b4e",content,"61e6614bd80be3b12f0ba72d","665c9db8ae4a37f6c0fc5be4","2024-06-25T09:15:58.230Z","2024-06-25T09:15:58.230Z" );
    }

    @Test
    public void tt(){
        String userId="{\"created\":\"2024-10-18T03:08:18.523Z\",\"dates\":[\"2024-10-18T00:00:00.000Z\"],\"executorId\":\"61b0993141573193a85b0074\",\"id\":\"6711d12248fdd60012792eb0\",\"organizationId\":\"6034c885e71842e1e5bb5218\"" +
                ",\"taskId\":\"66ebe2e3e5e72e2d893490f8\",\"updated\":\"2024-10-18T03:08:18.523Z\",\"workTime\":3600000,\"workTimeIds\":[\"6711d12248fdd60012792eb0\"]}";
        JSONObject data=JSONObject.parseObject(userId);
        mcPocTbService.saveWorkTimes(data.getString("taskId"),data.getString("executorId"), UtilMap.getList(data,"workTimeIds"));
    }
}
