import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.haoban.manage.api.service.OpenStaffApiService;
import com.gic.member.api.dto.es.MemberDataDTO;
import com.gic.member.api.service.MemberApiService;
import com.gic.search.engine.api.constant.OperateEnum;
import com.gic.search.engine.api.dto.ESResponseQueryBatch;
import com.gic.search.engine.api.dto.dynamic.DynamicSearchDTO;
import com.gic.search.engine.api.filter.NewNodeAddUtil;
import com.gic.search.engine.api.service.dynamic.ESDataDynamicOperationApiService;
import org.apache.commons.collections.CollectionUtils;
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.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

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


    @Autowired
    private ESDataDynamicOperationApiService esDataDynamicOperationApiService ;

    String eid = "ff8080816deed97e016df22b567a1e2b";

    @Test
    public void tt()  {
        List<String> list = FileUtils3.getText();
        this.getMemberMap(eid,list) ;
    }


    public void getMemberMap(String enterpriseId, List<String> memberIdList) {
        String returnFields = "memberId,mainStoreId,mainClerkId,openStoreId,openClerkId,name,nickName,phoneNumber,photoUrl,cardNo";
        List<JSONObject> esList = this.queryDataBatch(enterpriseId, memberIdList, returnFields);
        List<MemberDataDTO> list = JSONArray.parseArray(JSONArray.toJSONString(esList),MemberDataDTO.class);
        for(MemberDataDTO m : list) {
            System.out.println(m.getMemberId()+","+m.getCardNo());
        }
    }

    public List<JSONObject> queryDataBatch(String enterpriseId, List<String> memberIdList, String returnFields) {
        DynamicSearchDTO search = new DynamicSearchDTO();
        search.setEnterpriseId(enterpriseId);
        search.setColumnCategoryCode("member");
        String memberIds = String.join(" ", memberIdList);
        JSONObject searchObj = new JSONObject();
        searchObj = NewNodeAddUtil.addNewNodeForAnd("memberId", OperateEnum.OPERATE_CONTAIN.getValue(), memberIds,
                searchObj);
        search.setSearchJson(searchObj);
        search.setReturnFileds(returnFields);
        search.setSortJson(NewNodeAddUtil.createSortNode("memberId", NewNodeAddUtil.SORT_RULE_ASC));
        search.setBegin(0);
        search.setRecordNumber(memberIdList.size());
        ESResponseQueryBatch response = this.esDataDynamicOperationApiService.queryDataBatch(search, Boolean.FALSE,
                null);
        return response.getRes();
    }

}
