package org.ts.ddcs.DataSaveProcesser;

import org.ts.ddcs.DataItemTemplate.DataItemTemplateInterface;
import org.ts.ddcs.DataTemplate.DataTemplateInterface;
import org.ts.ddcs.Log.LogHelper;
import org.ts.ddcs.Service.SwService;
import org.ts.ddcs.Tool.BytesHelp;
import org.ts.ddcs.Worker.DataProcessHolder;
import org.ts.ddcs.utils.GBConstants;

import java.util.LinkedList;

@SuppressWarnings("all")
public class DataSaveProcesserC31 extends DataSaveProcesser {
    @Override
    public void Save(DataTemplateInterface dataTemplateInterface) {
        super.Save(dataTemplateInterface);
        try {
            String rtuCode = BytesHelp.byte2HexStr(dataTemplateInterface.RtuCode());
            LogHelper.info("SAVE:" + dataTemplateInterface.GetFeture() + " " + BytesHelp.byte2HexStr(dataTemplateInterface.RtuCode()));
            SwService swService = DataProcessHolder.newInstance().dataProcess.swService;
            //均匀时间，只处理5分钟
            LinkedList<DataItemTemplateInterface> dataItem = dataTemplateInterface.MacthDataItem(GBConstants.TABLE_DRXNN);
            if (dataItem.size() > 0) {
//                PptnEntity pptnEntity = new PptnEntity();
//                StringBuffer dataStr = new StringBuffer(BytesHelp.byte2HexStr(dataTemplateInterface.CollectTime()));
//                String tm = "20" + dataStr.toString() + "00";
//                dataStr = new StringBuffer(BytesHelp.byte2HexStr(dataTemplateInterface.SendPacketTime()));
//                String dt = "20" + dataStr.toString();
//                SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
//                pptnEntity.setTM(new Timestamp(timeFormat.parse(tm).getTime()));
//                pptnEntity.setDT(new Timestamp(timeFormat.parse(dt).getTime()));
//                pptnEntity.setTS(new Timestamp(new Date().getTime()));
//                String stcd = BytesHelp.byte2HexStr(dataTemplateInterface.RtuCode());
//                pptnEntity.setSTCD(stcd);
//                for (DataItemTemplateInterface item : dataItem) {
//                    item.SetEntity(pptnEntity);
//                }
//                swService.SaveSwPPTN_5Min_Data(pptnEntity);
//                swService.SaveSwPPTN_5Min_to_hour_Data(pptnEntity);
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }
}
