package com.liangjian.dataplatform.member.service.impl;

import com.liangjian.dataplatform.member.entity.po.secondary.FiltersData;
import com.liangjian.dataplatform.member.jobUtil.EsUtils;
import com.liangjian.dataplatform.member.service.IMemberterminalService;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MemberterminalService implements IMemberterminalService {
    @Override
    public Map<String, Object> doclist(FiltersData data) {

        Map<String, Object> ret = new HashMap<>();
        int start = 0;
        Object query = null;
        String filter = null;

        String sql = "{\"size\":10,\"query\":{\"bool\":{\"must\":[{\"term\":{\"MemUsualPhone\":{\"value\":\"{@MemUsualPhone}\",\"boost\":1}}},{\"nested\":{\"query\":{\"match_all\":{\"boost\":1}},\"path\":\"Terminals\",\"ignore_unmapped\":false,\"score_mode\":\"none\",\"boost\":1,\"inner_hits\":{\"ignore_unmapped\":false,\"from\":{@from},\"size\":{@size},\"version\":false,\"seq_no_primary_term\":false,\"explain\":false,\"track_scores\":false,\"_source\":{\"includes\":[\"Terminals.*\"],\"excludes\":[]}}}}],\"adjust_pure_negative\":true,\"boost\":1}},\"_source\":false,\"stored_fields\":\"_none_\",\"docvalue_fields\":[{\"field\":\"MemUsualPhone\"}],\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}";

        sql = sql.replace("{@from}", "" + start).replace("{@size}", "" + data.getPageSize())
                .replace("{@MemUsualPhone}", "");

        String result = EsUtils.query(sql, "mem_memberbase_p/_search?format=json", false);

        JSONObject jsonObject = JSONObject.fromObject(result);
        List<Object> list = (List<Object>) jsonObject.getJSONObject("hits").get("hits");

        List<Object> objectList = new ArrayList<>();
        int totalCount = 0;
        if(list != null && list.size() > 0){


        }
        ret.put("items",objectList);
        ret.put("totalCount",totalCount);
        ret.put("success",true);
        return ret;
    }
}
