提交 | 用户 | 时间
|
71e81e
|
1 |
package cn.stylefeng.guns.plcserver.server.OP010.callback; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.modular.em.equipmentAlarm.model.params.EquipmentAlarmParam; |
|
4 |
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService; |
|
5 |
import cn.stylefeng.guns.modular.em.equipmentStatus.model.params.EquipmentStatusParam; |
|
6 |
import cn.stylefeng.guns.modular.em.equipmentStatus.model.result.EquipmentStatusResult; |
|
7 |
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService; |
|
8 |
import cn.stylefeng.guns.plcserver.opc.GlobalVariable; |
|
9 |
import cn.stylefeng.guns.plcserver.opc.OPCComm; |
|
10 |
import cn.stylefeng.guns.plcserver.tool.DateTool; |
|
11 |
import org.jinterop.dcom.common.JIException; |
|
12 |
import org.jinterop.dcom.core.JIVariant; |
|
13 |
import org.openscada.opc.lib.da.DataCallback; |
|
14 |
import org.openscada.opc.lib.da.Item; |
|
15 |
import org.openscada.opc.lib.da.ItemState; |
|
16 |
|
|
17 |
import java.util.List; |
|
18 |
|
|
19 |
public class DataCallBack_OP010_E_STATE implements DataCallback { |
|
20 |
|
|
21 |
private OPCComm opc = OPCComm.getInstance(); |
|
22 |
|
|
23 |
@Override |
|
24 |
public void changed(Item item, ItemState itemState) { |
|
25 |
// 读取变量的值 |
|
26 |
try { |
|
27 |
if (itemState.getValue().getType() == JIVariant.VT_I2) { |
|
28 |
int value = itemState.getValue().getObjectAsShort(); |
|
29 |
if(value != GlobalVariable.OP010_E_STATE){ |
|
30 |
EquipmentStatusParam equipmentStatusParam = new EquipmentStatusParam(); |
|
31 |
equipmentStatusParam.setLocationCode("OP010"); |
|
32 |
|
|
33 |
EquipmentStatusService equipmentStatusService = opc.equipmentStatusService; |
|
34 |
List<EquipmentStatusResult> list = equipmentStatusService.findListBySpec(equipmentStatusParam); |
|
35 |
if(list.size()>0){ |
|
36 |
EquipmentStatusResult equipmentStatusResult = list.get(0); |
|
37 |
equipmentStatusParam.setId(equipmentStatusResult.getId()); |
|
38 |
equipmentStatusParam.setStatus(String.valueOf(value)); |
|
39 |
equipmentStatusService.update(equipmentStatusParam); |
|
40 |
GlobalVariable.OP010_E_STATE = value; |
|
41 |
} |
|
42 |
if(value == 3){ |
|
43 |
EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam(); |
|
44 |
equipmentAlarmParam.setLocationCode("OP010"); |
|
45 |
equipmentAlarmParam.setErrorDesc("设备告警"); |
|
46 |
equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate()); |
|
47 |
EquipmentAlarmService equipmentAlarmService = opc.equipmentAlarmService; |
|
48 |
equipmentAlarmService.add(equipmentAlarmParam); |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
} |
|
53 |
} catch (JIException e) { |
|
54 |
e.printStackTrace(); |
|
55 |
} |
|
56 |
} |
|
57 |
} |