package com.foreverwin.mesnac.equip.consumer;


import com.foreverwin.mesnac.equip.service.EdcDataResourceService;
import com.foreverwin.mesnac.equip.service.ResourceFaultReceiveService;
import com.foreverwin.mesnac.equip.service.ResourceRunTimeService;
import com.foreverwin.mesnac.equip.service.ResourceStatusReceiveService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 设备接口业务处理
 *
 *
 * @author Leon
 * @date 2021-07-21
 */
@Component
public class ResourceMQProcess {

    private static Logger logger = LoggerFactory.getLogger(ResourceMQProcess.class);

    @Autowired
    private ResourceStatusReceiveService resourceStatusReceiveService;

    @Autowired
    private ResourceFaultReceiveService resourceFaultReceiveService;

    @Autowired
    private EdcDataResourceService edcDataResourceService;

    @Autowired
    private ResourceRunTimeService resourceRunTimeService;

    /**
     * 设备状态变更
     *
     * @param text
     * @return
     */
    public void resourceStatusProcess(String text) {
        try {
            resourceStatusReceiveService.updateResourceStatusByMq(text);
            logger.info("设备状态修改成功！");
        } catch (Exception e) {
            logger.error("设备状态修改失败：" + e.getMessage());
        }
    }

    /**
     * 设备故障信息记录
     * @param text
     * @return
     */
    public void resourceFaultProcess(String text){
        try {
            resourceFaultReceiveService.parseResourceFaultInfo(text);
            logger.info("设备故障信息记录成功！");
        } catch (Exception e) {
            logger.error("设备故障信息记录失败：" + e.getMessage());
        }
    }
    /**
     * 设备参数信息记录
     * @param text
     * @return
     */
    public void resourceParamProcess(String text){
        try {
            edcDataResourceService.saveResourceParamByMq(text);
            logger.info("设备参数信息记录成功");
        } catch (Exception e) {
            logger.error("设备参数信息记录失败："+e.getMessage());
        }
    }

    /**
     * 设备每日运行时长数据接收
     * @param text
     * @return
     */
    public void resourceRunTimeProcess(String text){
        try {
            resourceRunTimeService.saveResourceRunTimeByMq(text);
            logger.info("设备运行时长数据记录成功");
        } catch (Exception e) {
            logger.error("设备运行时长数据记录失败："+e.getMessage());
        }
    }

}
