package cn.stylefeng.guns.plcserver.server.OP010.callback;
|
|
import cn.stylefeng.guns.modular.em.equipmentAlarm.model.params.EquipmentAlarmParam;
|
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
|
import cn.stylefeng.guns.modular.em.equipmentStatus.model.params.EquipmentStatusParam;
|
import cn.stylefeng.guns.modular.em.equipmentStatus.model.result.EquipmentStatusResult;
|
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
|
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
|
import cn.stylefeng.guns.plcserver.opc.OPCComm;
|
import cn.stylefeng.guns.plcserver.tool.DateTool;
|
import org.jinterop.dcom.common.JIException;
|
import org.jinterop.dcom.core.JIVariant;
|
import org.openscada.opc.lib.da.DataCallback;
|
import org.openscada.opc.lib.da.Item;
|
import org.openscada.opc.lib.da.ItemState;
|
|
import java.util.List;
|
|
public class DataCallBack_OP010_E_STATE implements DataCallback {
|
|
private OPCComm opc = OPCComm.getInstance();
|
|
@Override
|
public void changed(Item item, ItemState itemState) {
|
// 读取变量的值
|
try {
|
if (itemState.getValue().getType() == JIVariant.VT_I2) {
|
int value = itemState.getValue().getObjectAsShort();
|
if(value != GlobalVariable.OP010_E_STATE){
|
EquipmentStatusParam equipmentStatusParam = new EquipmentStatusParam();
|
equipmentStatusParam.setLocationCode("OP010");
|
|
EquipmentStatusService equipmentStatusService = opc.equipmentStatusService;
|
List<EquipmentStatusResult> list = equipmentStatusService.findListBySpec(equipmentStatusParam);
|
if(list.size()>0){
|
EquipmentStatusResult equipmentStatusResult = list.get(0);
|
equipmentStatusParam.setId(equipmentStatusResult.getId());
|
equipmentStatusParam.setStatus(String.valueOf(value));
|
equipmentStatusService.update(equipmentStatusParam);
|
GlobalVariable.OP010_E_STATE = value;
|
}
|
if(value == 3){
|
EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam();
|
equipmentAlarmParam.setLocationCode("OP010");
|
equipmentAlarmParam.setErrorDesc("设备告警");
|
equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate());
|
EquipmentAlarmService equipmentAlarmService = opc.equipmentAlarmService;
|
equipmentAlarmService.add(equipmentAlarmParam);
|
}
|
}
|
|
}
|
} catch (JIException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|