package com.mortals.xhx.thread;

import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.Rest;
import com.mortals.framework.service.ICacheService;
import com.mortals.xhx.protocol.complex.matter.model.req.FindHandlingReq;
import com.mortals.xhx.protocol.complex.matter.model.rsp.HandlingRspInfoList;
import com.mortals.xhx.protocol.complex.matter.service.IComplexMatterService;
import com.mortals.xhx.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;

import static com.mortals.xhx.common.key.Constant.REDIS_RESP_TIMEOUT;
import static com.mortals.xhx.common.key.RedisKey.KEY_EVENT_IMPLEMENTATION_RESP;

@Slf4j
public class DownloadFileFtpSendTask implements Runnable{

    private FindHandlingReq findHandlingReq;

    private String deviceLogo;

    private IComplexMatterService complexMatterService;

    private ICacheService cacheService;

    public DownloadFileFtpSendTask(String deviceLogo, FindHandlingReq findHandlingReq){
        this.findHandlingReq = findHandlingReq;
        this.deviceLogo = deviceLogo;
        complexMatterService = SpringUtils.getBean(IComplexMatterService.class);
        cacheService = SpringUtils.getBean(ICacheService.class);
    }
    @Override
    public void run() {

        try {
            log.info("DownloadFileFtpSendTask启动发送");
            Rest<Object> rest = complexMatterService.downloadFileFtp(deviceLogo, findHandlingReq);
            cacheService.lpushForTime(KEY_EVENT_IMPLEMENTATION_RESP + findHandlingReq.getNonce(), REDIS_RESP_TIMEOUT, JSONObject.toJSONString(rest));

        } catch (Exception e) {
            log.error("发送异常：" + e);
        }
    }
}
