import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.haoban.manage.api.service.QywxTagApiService;
import com.gic.haoban.manage.service.pojo.QywxSyncTagFormatPojo;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 标签同步
 */

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class TagSyncTest {

    public static void main(String[] args) {
        JSONObject json = JSONObject.parseObject(getText()) ;
        JSONArray list = json.getJSONObject("result").getJSONArray("tag_group") ;
        System.out.println(JSONArray.toJSONString(list,true));
    }

    @Autowired
    private QywxTagApiService qywxTagApiService ;

    // com.gic.haoban.manage.service.service.out.impl.QywxTagApiServiceImpl.syncQywxTagToGicByExternalUserId
    @Test
    public void test1() {
         String wxEnterpriseId = "ca66a01b79474c40b3e7c7f93daf1a3b" ;
         String externalUserId = "wm59NLDQAAdcT6u5mqXz_jeMN9CpgXuw"  ;
         String wxUserId = "wo59NLDQAACLAXbOdqrz-70qpl72cWcA" ;
         this.qywxTagApiService.syncQywxTagToGicByExternalUserId(wxEnterpriseId,externalUserId,wxUserId,null) ;

    }

    public static QywxSyncTagFormatPojo get() {
        QywxSyncTagFormatPojo pojo = new QywxSyncTagFormatPojo() ;

        Map<String, String> qywxToGicTagItemIdMap = new HashMap<>();
        qywxToGicTagItemIdMap.put("et59NLDQAArYF4RnhIExLDXOuV7ncSCA","beb3634744fa40249980100d7bf1f6f1") ;
        qywxToGicTagItemIdMap.put("et59NLDQAAOe2bxm8ylLMxG_dfXlTGCg","3f8e9920614d4008a1cb511f15ea759e") ;
        qywxToGicTagItemIdMap.put("et59NLDQAAXBDE5t_33GtCHWVEre4sfQ","e48e0d8e1a7f4ca58f5bbdcd5009cc90") ;
        /**
         * gic标签值ID -> 企业微信标签值ID
         */
        Map<String, String> gicToQywxTagItemIdMap= new HashMap<>();
        gicToQywxTagItemIdMap.put("beb3634744fa40249980100d7bf1f6f1","et59NLDQAArYF4RnhIExLDXOuV7ncSCA") ;
        gicToQywxTagItemIdMap.put("3f8e9920614d4008a1cb511f15ea759e","et59NLDQAAOe2bxm8ylLMxG_dfXlTGCg") ;
        gicToQywxTagItemIdMap.put("e48e0d8e1a7f4ca58f5bbdcd5009cc90","et59NLDQAAXBDE5t_33GtCHWVEre4sfQ") ;
        /**
         * gic企业ID ->  企业微信标签值ID LIST
         */
        Map<String, Set<String>> entQywxTagKeysMap = new HashMap<>();
        entQywxTagKeysMap.put("ff8080815dacd3a2015dacd3ef5c0000",Arrays.asList("et59NLDQAArYF4RnhIExLDXOuV7ncSCA","et59NLDQAAOe2bxm8ylLMxG_dfXlTGCg","et59NLDQAAXBDE5t_33GtCHWVEre4sfQ").stream().collect(Collectors.toSet())) ;
        /**
         * gic企业ID -> gic标签值ID LIST
         */
        Map<String, Set<String>> entGicTagItemIdMap = new HashMap<>();
        entGicTagItemIdMap.put("ff8080815dacd3a2015dacd3ef5c0000",Arrays.asList("beb3634744fa40249980100d7bf1f6f1","3f8e9920614d4008a1cb511f15ea759e","e48e0d8e1a7f4ca58f5bbdcd5009cc90").stream().collect(Collectors.toSet())) ;

        pojo.setQywxToGicTagItemIdMap(qywxToGicTagItemIdMap);
        pojo.setGicToQywxTagItemIdMap(gicToQywxTagItemIdMap);

        pojo.setEntGicTagItemIdMap(entGicTagItemIdMap);
        pojo.setEntQywxTagKeysMap(entQywxTagKeysMap);

        return pojo ;

    }


    // com.gic.haoban.manage.service.service.out.impl.QywxTagApiServiceImpl.syncQywxTagToGicByExternalUserId

    public  static String getText(){
        try {
            BufferedReader bw = new BufferedReader(new FileReader(new File("d:\\bq.txt"))) ;
            StringBuilder sb = new StringBuilder() ;
            while(true) {
                String s =  bw.readLine() ;
                if(StringUtils.isBlank(s)) {
                    break ;
                }else {
                    String ss = new String(s.getBytes(),"UTF-8") ;
                    sb.append(ss) ;
                }
            }
            bw.close();
            return sb.toString() ;
        }catch(Exception e) {
        }
        return null ;
    }

}
