cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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();
        }
    }
}