long
2023-09-02 e379948bb83ebcc9ce0c467a7b970f74bc00e9a1
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.state.impl;
2
3
4 import cn.stylefeng.guns.modular.bs.collectionParamConf.model.params.CollectionParamConfParam;
5 import cn.stylefeng.guns.modular.bs.collectionParamConf.model.result.CollectionParamConfResult;
6 import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService;
7 import cn.stylefeng.guns.modular.bs.equipmentInfo.model.params.EquipmentInfoParam;
8 import cn.stylefeng.guns.modular.bs.equipmentInfo.model.result.EquipmentInfoResult;
9 import cn.stylefeng.guns.modular.bs.equipmentInfo.service.EquipmentInfoService;
10 import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
11 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
12 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
13 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
14 import cn.stylefeng.guns.modular.em.equipmentAlarm.model.params.EquipmentAlarmParam;
15 import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
16 import cn.stylefeng.guns.modular.em.equipmentStatus.model.params.EquipmentStatusParam;
17 import cn.stylefeng.guns.modular.em.equipmentStatus.model.result.EquipmentStatusResult;
18 import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
19 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
20 import cn.stylefeng.guns.plcserver.opc.OPCComm;
21 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
22 import cn.stylefeng.guns.plcserver.server.OP100.OP100ServerInterface;
23 import cn.stylefeng.guns.plcserver.server.state.StateServerInterface;
24 import cn.stylefeng.guns.plcserver.tool.DateTool;
25 import cn.stylefeng.guns.plcserver.tool.LogUtil;
26 import org.apache.log4j.Logger;
27 import org.openscada.opc.lib.da.Group;
28 import org.openscada.opc.lib.da.Item;
29
30 import java.util.Date;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35
36 public class StateServerInterfaceImpl implements StateServerInterface {
37
38     private static Logger logger;
39     LogUtil logUtil = new LogUtil();
40     static {
41         logger = Logger.getLogger(StateServerInterfaceImpl.class);
42     }
43
44     private OPCComm opc = OPCComm.getInstance();
45
46     private static String GROUP_NAME  = "STATE_GROUP";//组
47     private static List list = null;
48     private static Group group = null;
49
50     @Override
51     public void monitor() {
52         String ecpStr = "";//异常记录标记
53         try{
54             handleInfo();
55
56         }catch (Exception e) {
57             ecpStr ="出现异常:" + logUtil.getTrace(e);
58         }finally {
59             if(!"".equals(ecpStr)){
60                 logger.info(ecpStr+"\r\n");
61             }
62         }
63     }
64
65
66     //PC读参数信息
67     public void handleInfo() throws Exception {
68         logger.info("OP100工位,handleInfo START!");
69
70         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
71             if(group != null){
72                 opc.getServer().removeGroup(group,true);
73             }
74             group = opc.getServer().addGroup(GROUP_NAME);
75
76             EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam();
77             EquipmentInfoService equipmentInfoService = opc.equipmentInfoService;
78             list = equipmentInfoService.findListBySpec(equipmentInfoParam);
79
80             for(int i=0;i<list.size();i++){
81                 EquipmentInfoResult result = (EquipmentInfoResult) list.get(i);
82                 Item item = group.addItem(result.getSpareField1());
83                 result.setItem(item);
84                 list.set(i,result);
85             }
86         }
87         if(null != list && list.size()>0) {
88             EquipmentStatusService equipmentStatusService = opc.equipmentStatusService;
89
90             for (int i = 0; i < list.size(); i++) {
91                 EquipmentInfoResult result = (EquipmentInfoResult) list.get(i);
92                 Item item = result.getItem();
93                 String value = OPCUnit.read(item);//读参数值  设备状态
94                 String equipmentNo = result.getEquipmentNo();
95
96                 EquipmentStatusParam equipmentStatusParam = new EquipmentStatusParam();
97                 equipmentStatusParam.setEquipmentNo(equipmentNo);
98                 List statuslist = equipmentStatusService.findListBySpec(equipmentStatusParam);
99                 if(statuslist.size()>0){
100                     EquipmentStatusResult equipmentStatusResult = (EquipmentStatusResult) statuslist.get(0);
101                     if(!value.equals(equipmentStatusResult.getStatus())){
102                         equipmentStatusParam.setId(equipmentStatusResult.getId());
103                         equipmentStatusParam.setStatus(value);
104                         equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate());
105                         equipmentStatusService.update(equipmentStatusParam);//更新设备状态
106
107                         //添加设备报警
108                         if("3".equals(value)){
109                             EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam();
110                             equipmentAlarmParam.setEquipmentNo(equipmentNo);
111                             equipmentAlarmParam.setEquipmentName(result.getEquipmentName());
112                             equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode());
113                             equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode());
114                             equipmentAlarmParam.setLocationCode(result.getLocationCode());
115                             equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"报警!");
116                             equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate());
117                             EquipmentAlarmService equipmentAlarmService = opc.equipmentAlarmService;
118                             equipmentAlarmService.add(equipmentAlarmParam);
119                         }
120                     }
121
122                 }else{
123                     equipmentStatusParam.setEquipmentName(result.getEquipmentName());
124                     equipmentStatusParam.setWorkshopCode(result.getWorkshopCode());
125                     equipmentStatusParam.setProductionLineCode(result.getProductionLineCode());
126                     equipmentStatusParam.setLocationCode(result.getLocationCode());
127                     equipmentStatusParam.setStatus(value);
128                     equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate());
129                     equipmentStatusService.add(equipmentStatusParam);
130
131                     //添加设备报警
132                     if("3".equals(value)){
133                         EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam();
134                         equipmentAlarmParam.setEquipmentNo(equipmentNo);
135                         equipmentAlarmParam.setEquipmentName(result.getEquipmentName());
136                         equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode());
137                         equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode());
138                         equipmentAlarmParam.setLocationCode(result.getLocationCode());
139                         equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"报警!");
140                         equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate());
141                         EquipmentAlarmService equipmentAlarmService = opc.equipmentAlarmService;
142                         equipmentAlarmService.add(equipmentAlarmParam);
143                     }
144                 }
145
146             }
147         }
148
149     }
150
151
152 }