package com.trs.web2frame.tool.tyjyh.ggzyzheng;

import com.alibaba.fastjson.JSON;
import com.trs.cms.CMSConstants;
import com.trs.web2frame.WCMServiceCaller;
import com.trs.web2frame.dispatch.Dispatch;
import com.trs.web2frame.tool.tyjyh.ConfigConstant;
import com.trs.web2frame.tool.tyjyh.ConnectionUtil;
import com.trs.web2frame.util.Log_Exception;
import net.sf.json.JSONObject;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;

public class ServiceImplGgzy {
    private String sqlType = ConfigConstant.SQLTYPE;

    public List<Map<String,String>> getNmgGgzy(String channelName,String tableName){
        List<Map<String, String>> oldMaps = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            StringBuilder sb=new StringBuilder(
                    "select " +
                            "nmg.*, " +
                            "from '"+tableName+"' nmg" +
                            "where nmg.channle = '"+channelName+"' " +
                            " " +
                            "order by nmg.time asc"
            );
            System.out.println(sb);
            connection = ConnectionUtil.getConnectionBenji("mysql");
            statement = connection.createStatement();
            set = statement.executeQuery(sb.toString());
            while (set.next()){
                System.out.println(set);
                Map<String, String> map = new HashMap<>();
                map.put("id", set.getString("id"));
                map.put("title", set.getString("title"));
                map.put("url", set.getString("url"));
                map.put("time", set.getString("time"));
                map.put("content", set.getString("content"));
                map.put("image_ids", set.getString("image_ids"));
                map.put("file_ids", set.getString("file_ids"));
                map.put("channle", set.getString("channle"));
                oldMaps.add(map);
            }
            return oldMaps;
        } catch (Exception e) {
            Log_Exception.Error_txt("GetAllDocInfoFromOldDB() error"+e.getMessage());
            return null;
        } finally {
            ConnectionUtil.closeConnection(set, statement, connection);
        }
    }
}