package com.szpg.plc.message.response.write;

import com.szpg.db.dao.PgDeviceDao;
import com.szpg.db.dao.PgJgDao;
import com.szpg.db.dao.impl.PgDeviceDaoImpl;
import com.szpg.db.dao.impl.PgJgDaoImpl;
import com.szpg.plc.message.response.WriteMemoryCommandResponse;
import org.apache.log4j.Logger;

public class SetJgLockBitCommandResponse extends WriteMemoryCommandResponse {

    private final Logger logger = Logger.getLogger(this.getClass().getName());

    private PgJgDao jgDao = new PgJgDaoImpl();
    private PgDeviceDao deviceDao = new PgDeviceDaoImpl();

    @Override
    public void afterAction() {
        if (this.isSuccess() == true) {
            // 更新设备状态 锁定
            int deviceId = deviceDao.findDeviceIdByCode(this.getDestinationId());
            if (deviceId > 0) {
                jgDao.updateDeviceStatus(deviceId, "0");
            }

            logger.info("[" + this.getAcucode() + "]锁定井盖成功");
        }
    }
}
