package org.ts.ddcs.DataSaveProcesser.jtProcessor;


import org.ts.ddcs.DataItemTemplate.DataItemTemplateImg;
import org.ts.ddcs.DataItemTemplate.DataItemTemplateInterface;
import org.ts.ddcs.DataSaveProcesser.DataSaveProcesser;
import org.ts.ddcs.DataTemplate.DataTemplateInterface;
import org.ts.ddcs.Entity.RtuImageEntity;
import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.Service.JtService;
import org.ts.ddcs.Tool.BytesHelp;
import org.ts.ddcs.Worker.DataProcessHolder;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.domain.upload.FastImageFile;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;


/**
 * 0x30
 * 测试报
 */

public class DataProcessorJtMultimedia extends DataSaveProcesser {

    @Override
    public void Save(DataTemplateInterface dataTemplateInterface, Map<String, Object> param) {
        super.Save(dataTemplateInterface);
        try {

            LogHelper.info("SAVE:" + dataTemplateInterface.GetFeture() + " " + BytesHelp.byte2HexStr(dataTemplateInterface.RtuCode()));
            String rtuCode = BytesHelp.byte2HexStr(dataTemplateInterface.RtuCode()).substring(4, 20);

            JtService jtService = DataProcessHolder.newInstance().dataProcess.jtService;
            String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
            RtuImageEntity entity = new RtuImageEntity();
            entity.setGroupId(rtuCode);
            entity.setRtuCode(rtuCode);
            entity.setTm(new Timestamp(System.currentTimeMillis()));
            entity.setFileName((String) param.get("fileName"));
            entity.setFileType((String) param.get("fileType"));

            Map<String, Object> location = new HashMap<>(10);
            Map<String, DataItemTemplateInterface> dataItem = dataTemplateInterface.DataItem();
            DataItemTemplateInterface itemTemplateInterface = dataItem.get("location");
            if (null != itemTemplateInterface) {
                location = itemTemplateInterface.GetDatas();
            }
            jtService.saveSwImage(uuid, (String) param.get("photoUrlPath"), entity, location);
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }


}
