package com.malk.aiwei;

import com.alibaba.fastjson.JSONObject;
import com.malk.server.teambition.TBConf;
import com.malk.service.aliwork.YDClient;
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.util.ArrayList;
import java.util.Arrays;
import java.util.List;

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

    @Autowired
    private TBClient tbClient;
    @Autowired
    private TBConf tbConf;

    @Test
    public void test() {
        List<String> users = Arrays.asList("5f3a250040ce230ba377bf3c", "5e698cca21f5ad70dfba7d2b", "616fb6f78ad4104a10515809");
        String programId = "662a69aceda740b4e63d3976";
//        tbClient.createProgramMember(programId,tbConf.getOperatorId(),users);
        List addUsers = new ArrayList();
        for (String userId : users) {
            List resut = tbClient.queryProgramMember(programId, tbConf.getOperatorId(), UtilMap.map("userIds", userId));
            if (resut.size() < 1) addUsers.add(userId);
        }
        log.info("需要添加到项目集的userId:{}", tbClient);
        if (addUsers.size() > 0) tbClient.createProgramMember(programId, tbConf.getOperatorId(), addUsers);
    }

    @Autowired
    private YDClient ydClient;

    // this.initOptions("FORM-IQ8666B1PL275QG5BSSDG6ZD9X3Q29X881HCL4", JSON.stringify({'textField_ljsd7bjn':value}), //
    //    "8F966HB12J27MQJM6V4IQDYHYTPA2G4GTZGCLN1", "APP_QBWQITQBSPJNYTUTNPDK",
    //    'yida_pub_account', "selectField_lchafcgt", "selectField_lchafcgt", "selectField_lywdbrk1", 100);


    @Test
    public void adad() {
//        YDSearch ydSearch=new YDSearch("textField_lha7mqbs","G","物料子类", YDSearch.Type.TEXT_FIELD,YDSearch.Operator.EQ);
//        YDSearch ydSearch2=new YDSearch("textField_lha7mqbn","A2443","项目号", YDSearch.Type.TEXT_FIELD,YDSearch.Operator.EQ);
//        List<Map> list =(List<Map>) ydClient.queryData(YDParam.builder().formUuid("FORM-4W8667D17CAAGFXI9VO0J9J7RFNL2QDFL7AHLJ")
//                .appType("APP_QBWQITQBSPJNYTUTNPDK").systemToken("8F966HB12J27MQJM6V4IQDYHYTPA2G4GTZGCLN1")
//                .searchCondition(JSONObject.toJSONString(Arrays.asList(ydSearch,ydSearch2)))
//                .pageSize(100).build(), YDConf.FORM_QUERY.retrieve_list).getData();
//        List<Map> result=new ArrayList<>();
//        Map<String,String> keyMap=new HashMap<>();
//        for (Map map:list){
//            String data=UtilMap.getString(UtilMap.getMap(map,"formData"),("textField_lhsxurnt"));
//            if(!StringUtils.isBlank(data)&&!keyMap.containsKey(data)){
//                result.add(UtilMap.map("title",data));
//            }
//        }
//        print(result);
//        DDR_New ddr_new = ydClient.queryData(YDParam.builder()
//                .appType("APP_QBWQITQBSPJNYTUTNPDK").systemToken("8F966HB12J27MQJM6V4IQDYHYTPA2G4GTZGCLN1")
//                .pageSize(100)
//                .build(), YDConf.FORM_QUERY.retrieve_forms);
//        print(ddr_new);
    }

    private void print(Object o) {
        System.out.println(JSONObject.toJSONString(o));
    }

}
