package com.skr.mdm.service.impl.reload;

import com.skr.mdm.annotation.CmdHandler;
import com.skr.mdm.bean.so.ReloadSO;
import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author nfq
 * @date 2020/11/4 9:25
 */
@Slf4j
@CmdHandler(cmdType = CmdTypeConstants.RELOAD)
public class ReloadServiceImpl implements CmdHandlerService {

    @Autowired
    private ReloadHandlerChain reloadHandlerChain;


    @Override
    public ResponseResult cmdHandler(Integer equipmentId, String data) {
        try {

            ReloadSO reloadSO = ReloadSO.builder().build();
            reloadHandlerChain.doReloadHandler(reloadSO, equipmentId);
            return ResponseResult.success(reloadSO);
        } catch (Exception e) {
            log.error("卸载重装拉取异常:" + equipmentId + data, e);
            return ResponseResult.failure();
        }
    }
}