package com.its.app.process;

import com.its.app.config.AppUtils;
import com.its.app.mapper.CctvMapper;
import com.its.app.mapper.WcamMapper;
import com.its.app.vo.voIcmpCtlrStts;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service("dbmsJobProcess")
public class DbmsJobProcess extends AbstractDbmsJobProcess {

    private WcamMapper wcamMapper;
    private CctvMapper cctvMapper;

    @Override
    protected void postConstruct() {
        this.wcamMapper = (WcamMapper) AppUtils.getBean(WcamMapper.class);
        this.cctvMapper = (CctvMapper) AppUtils.getBean(CctvMapper.class);
    }

    @Override
    public void process(DbmsJobData data) {

        try {
            int type = data.getType();
            switch(type) {
                case DbmsJobType.DATA_TYPE_WCAM_STTS:
                    voIcmpCtlrStts wcamStts = (voIcmpCtlrStts)data.getData();
                    this.wcamMapper.updateStts(wcamStts);
                    if (data.isHistory()) {
                        this.wcamMapper.insertSttsHs(wcamStts);
                    }
                    break;
                case DbmsJobType.DATA_TYPE_CCTV_STTS:
                    voIcmpCtlrStts cctvStts = (voIcmpCtlrStts)data.getData();
                    this.cctvMapper.updateStts(cctvStts);
                    break;
            }
        } catch (Exception e) {
            log.error("DbmsJobProcess.process: Exception: {}", e.toString());
        }
    }

}
