package cn.stylefeng.guns.plcserver.server.state.impl;
|
|
|
import cn.stylefeng.guns.modular.bs.collectionParamConf.model.params.CollectionParamConfParam;
|
import cn.stylefeng.guns.modular.bs.collectionParamConf.model.result.CollectionParamConfResult;
|
import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService;
|
import cn.stylefeng.guns.modular.bs.equipmentInfo.model.params.EquipmentInfoParam;
|
import cn.stylefeng.guns.modular.bs.equipmentInfo.model.result.EquipmentInfoResult;
|
import cn.stylefeng.guns.modular.bs.equipmentInfo.service.EquipmentInfoService;
|
import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
|
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
|
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
|
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
|
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.opc.unit.OPCUnit;
|
import cn.stylefeng.guns.plcserver.server.OP100.OP100ServerInterface;
|
import cn.stylefeng.guns.plcserver.server.state.StateServerInterface;
|
import cn.stylefeng.guns.plcserver.tool.DateTool;
|
import cn.stylefeng.guns.plcserver.tool.LogUtil;
|
import org.apache.log4j.Logger;
|
import org.openscada.opc.lib.da.Group;
|
import org.openscada.opc.lib.da.Item;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
|
public class StateServerInterfaceImpl implements StateServerInterface {
|
|
private static Logger logger;
|
LogUtil logUtil = new LogUtil();
|
static {
|
logger = Logger.getLogger(StateServerInterfaceImpl.class);
|
}
|
|
private OPCComm opc = OPCComm.getInstance();
|
|
private static String GROUP_NAME = "STATE_GROUP";//组
|
private static List list = null;
|
private static Group group = null;
|
|
@Override
|
public void monitor() {
|
String ecpStr = "";//异常记录标记
|
try{
|
handleInfo();
|
|
}catch (Exception e) {
|
ecpStr ="出现异常:" + logUtil.getTrace(e);
|
}finally {
|
if(!"".equals(ecpStr)){
|
logger.info(ecpStr+"\r\n");
|
}
|
}
|
}
|
|
|
//PC读参数信息
|
public void handleInfo() throws Exception {
|
logger.info("OP100工位,handleInfo START!");
|
|
if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
|
if(group != null){
|
opc.getServer().removeGroup(group,true);
|
}
|
group = opc.getServer().addGroup(GROUP_NAME);
|
|
EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam();
|
EquipmentInfoService equipmentInfoService = opc.equipmentInfoService;
|
list = equipmentInfoService.findListBySpec(equipmentInfoParam);
|
|
for(int i=0;i<list.size();i++){
|
EquipmentInfoResult result = (EquipmentInfoResult) list.get(i);
|
Item item = group.addItem(result.getSpareField1());
|
result.setItem(item);
|
list.set(i,result);
|
}
|
}
|
if(null != list && list.size()>0) {
|
EquipmentStatusService equipmentStatusService = opc.equipmentStatusService;
|
|
for (int i = 0; i < list.size(); i++) {
|
EquipmentInfoResult result = (EquipmentInfoResult) list.get(i);
|
Item item = result.getItem();
|
String value = OPCUnit.read(item);//读参数值 设备状态
|
String equipmentNo = result.getEquipmentNo();
|
|
EquipmentStatusParam equipmentStatusParam = new EquipmentStatusParam();
|
equipmentStatusParam.setEquipmentNo(equipmentNo);
|
List statuslist = equipmentStatusService.findListBySpec(equipmentStatusParam);
|
if(statuslist.size()>0){
|
EquipmentStatusResult equipmentStatusResult = (EquipmentStatusResult) statuslist.get(0);
|
if(!value.equals(equipmentStatusResult.getStatus())){
|
equipmentStatusParam.setId(equipmentStatusResult.getId());
|
equipmentStatusParam.setStatus(value);
|
equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate());
|
equipmentStatusService.update(equipmentStatusParam);//更新设备状态
|
|
//添加设备报警
|
if("3".equals(value)){
|
EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam();
|
equipmentAlarmParam.setEquipmentNo(equipmentNo);
|
equipmentAlarmParam.setEquipmentName(result.getEquipmentName());
|
equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode());
|
equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode());
|
equipmentAlarmParam.setLocationCode(result.getLocationCode());
|
equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"报警!");
|
equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate());
|
EquipmentAlarmService equipmentAlarmService = opc.equipmentAlarmService;
|
equipmentAlarmService.add(equipmentAlarmParam);
|
}
|
}
|
|
}else{
|
equipmentStatusParam.setEquipmentName(result.getEquipmentName());
|
equipmentStatusParam.setWorkshopCode(result.getWorkshopCode());
|
equipmentStatusParam.setProductionLineCode(result.getProductionLineCode());
|
equipmentStatusParam.setLocationCode(result.getLocationCode());
|
equipmentStatusParam.setStatus(value);
|
equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate());
|
equipmentStatusService.add(equipmentStatusParam);
|
|
//添加设备报警
|
if("3".equals(value)){
|
EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam();
|
equipmentAlarmParam.setEquipmentNo(equipmentNo);
|
equipmentAlarmParam.setEquipmentName(result.getEquipmentName());
|
equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode());
|
equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode());
|
equipmentAlarmParam.setLocationCode(result.getLocationCode());
|
equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"报警!");
|
equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate());
|
EquipmentAlarmService equipmentAlarmService = opc.equipmentAlarmService;
|
equipmentAlarmService.add(equipmentAlarmParam);
|
}
|
}
|
|
}
|
}
|
|
}
|
|
|
}
|