package com.usky.rule.service.impl;

import com.usky.rule.domain.RuleEngineDevice;
import com.usky.rule.service.RuleEngineDeviceService;
import com.usky.rule.vo.RuleEngineDeviceVO;
import org.springframework.stereotype.Service;


@Service
public class RuleEngineDeviceServiceImpl implements RuleEngineDeviceService {

    private RuleEngineDeviceVO toVO(RuleEngineDevice e) {
        RuleEngineDeviceVO vo = new RuleEngineDeviceVO();
        vo.setId(e.getId());
        vo.setDeviceId(e.getDeviceId());
        vo.setDeviceUuid(e.getDeviceUuid());
        vo.setIdentifier(e.getIdentifier());
        vo.setRuleEngineId(e.getRuleEngineId());
        vo.setProductId(e.getProductId() != null ? e.getProductId() : null);
        try {
            vo.setUpdatedBy(e.getUpdatedBy() != null && !e.getUpdatedBy().isEmpty() ? Long.parseLong(e.getUpdatedBy()) : null);
        } catch (NumberFormatException ignored) {
            vo.setUpdatedBy(null);
        }
        try {
            vo.setCreatedBy(e.getCreatedBy() != null && !e.getCreatedBy().isEmpty() ? Long.parseLong(e.getCreatedBy()) : null);
        } catch (NumberFormatException ignored) {
            vo.setCreatedBy(null);
        }
        if (e.getUpdateTime() != null) {
            vo.setUpdateTime(e.getUpdateTime().toString());
        }
        if (e.getCreateTime() != null) {
            vo.setCreateTime(e.getCreateTime().toString());
        }
        return vo;
    }
}
