package com.trs.digital.module.manager.controller.admin.digsearch;

import com.trs.digital.framework.common.pojo.PageResult;
import com.trs.digital.module.manager.configure.HybaseFactory;
import com.trs.hybase.client.*;
import com.trs.hybase.client.params.ConnectParams;
import com.trs.hybase.client.params.OperationParams;
import com.trs.hybase.client.params.SearchParams;

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


public class Test {


    public static void main(String[] args) {
        String server = "http://trs.nmsuny.com:5555/";
        String user = "admin";
        String password = "TRSadmin123!@#";
        TRSConnection trsConnection = new TRSConnection(server, user, password, new ConnectParams());
        try {
            try {
                SearchParams sParams = new SearchParams();
                TRSResultSet resultSet = trsConnection.executeSelect("system.dig_ftp", "docid:2", 0, 1, sParams);
                resultSet.moveNext();
                TRSRecord re = resultSet.get();


                TRSInputRecord updated = new TRSInputRecord();
                updated.setUid(re.getUid());
                updated.addColumn("file_year", "2022");
                ArrayList<TRSInputRecord> updateList = new ArrayList<TRSInputRecord>(1);
                updateList.add(updated);
                OperationParams uParams = new OperationParams();
                uParams.setProperty("update.mode.replace", "false");
                trsConnection.executeUpdate("system.dig_ftp", updateList,uParams,new TRSReport());
            } catch (Exception e) {
                e.getMessage();
            } finally {
                HybaseFactory.clean();
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            trsConnection.close();
        }
    }





/*    public static void main(String[] args) {
        String server = "http://trs.nmsuny.com:5555/";
        String user = "admin";
        String password = "TRSadmin123!@#";
        TRSConnection trsConnection = new TRSConnection(server, user, password, new ConnectParams());

        PageResult<Map<String, Object>> pageResult = new PageResult<>();
        List<Map<String, Object>> list = new ArrayList<>();
        try {




            SearchParams param = new SearchParams();
            //param.setReadColumns("ID");
            param.setCutSize(200);
            try {
                TRSResultSet rs = trsConnection.executeSelect("system.dig_ftp","docid:2",0,10, param);
                for (int i = 0; i < rs.size(); i++) {
                    rs.moveNext();
                    TRSRecord trsRecord = rs.get();
                    Map<String, Object> map = new HashMap<>();
                    for (String column : trsRecord.getColumnNames()) {
                        map.put(column, trsRecord.getString(column));
                    }
                    list.add(map);
                }
                System.out.println(list.size());
            } catch (Exception e) {
                e.getMessage();
            } finally {
                HybaseFactory.clean();
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            trsConnection.close();
        }
    }*/



/*    public static void main(String[] args) {
        String server = "http://trs.nmsuny.com:5555/";
        String user = "admin";
        String password = "TRSadmin123!@#";
        TRSConnection trsConnection = new TRSConnection(server, user, password, new ConnectParams());

        PageResult<Map<String, Object>> pageResult = new PageResult<>();
        List<Map<String, Object>> list = new ArrayList<>();
        try {
            SearchParams param = new SearchParams();
            //设置结果排序方式为创建时间排序
//        param.setSortMethod("-createTime");
            //设置返回结果字段
            param.setReadColumns("id;SynonymGroup;graphName");
            TRSResultSet rs = trsConnection.executeSelect("system.internal_system_log", null, 1, 2, param);
            pageResult.setTotal(rs.getNumFound());
            for (int i = 0; i < rs.size(); i++) {
                rs.moveNext();
                TRSRecord trsRecord = rs.get();
                Map<String, Object> map = new HashMap<>();
                for (String column : trsRecord.getColumnNames()) {
                    map.put(column, trsRecord.getString(column));
                }
                list.add(map);
            }
            pageResult.setList(list);
        } catch (TRSException e) {
            e.printStackTrace();
        } finally {
            trsConnection.close();
        }
    }*/
}
