package cn.stylefeng.guns.plcserver.callback;
|
|
|
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.bs.locationInfo.model.params.LocationInfoParam;
|
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
|
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
|
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.dq.materialTraceability.model.params.MaterialTraceabilityParam;
|
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
|
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.modular.gm.greaseManage.model.params.GreaseManageParam;
|
import cn.stylefeng.guns.modular.gm.greaseManage.model.result.GreaseManageResult;
|
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
|
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
|
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
|
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
|
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
|
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
|
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
|
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
|
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
|
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
|
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
|
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
|
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
|
import cn.stylefeng.guns.plcserver.opc.OPCElement;
|
import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
|
import cn.stylefeng.guns.plcserver.tool.DateTool;
|
import cn.stylefeng.guns.plcserver.tool.LogUtil;
|
import com.kangaroohy.milo.model.ReadWriteEntity;
|
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
|
import com.kangaroohy.milo.service.MiloService;
|
import org.apache.log4j.Logger;
|
import org.openscada.opc.lib.da.Item;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDate;
|
import java.time.format.DateTimeFormatter;
|
import java.time.temporal.ChronoUnit;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Random;
|
|
@Component
|
public class StateCallback implements SubscriptionCallback {
|
|
public MiloService miloService;
|
|
@Autowired
|
public ProductionOrdeInfoService productionOrdeInfoService;
|
@Autowired
|
public PassingStationCollectionService passingStationCollectionService;
|
@Autowired
|
public ParamCollectionService paramCollectionService;
|
@Autowired
|
public CollectionParamConfService collectionParamConfService;
|
@Autowired
|
public SerialNumbersConfService serialNumbersConfService;
|
@Autowired
|
private EquipmentStatusService equipmentStatusService;
|
|
@Autowired
|
private EquipmentAlarmService equipmentAlarmService;
|
@Autowired
|
private MaterialTraceabilityService materialTraceabilityService;
|
@Autowired
|
private EquipmentInfoService equipmentInfoService;
|
@Autowired
|
private RepairManageInfoService repairManageInfoService;
|
|
@Autowired
|
private LocationInfoService locationInfoService;
|
|
@Autowired
|
private GreaseManageService greaseManageService;
|
|
@Autowired
|
private ProductionOrderRecordsService productionOrderRecordsService;
|
|
@Autowired
|
private ProductionOrderBatchInfoService productionOrderBatchInfoService;
|
|
private static Logger logger;
|
LogUtil logUtil = new LogUtil();
|
static {
|
logger = Logger.getLogger(StateCallback.class);
|
}
|
private static Date IN_TIME = null;
|
private static String S_ORDER_CODE = "";//工单编号
|
private static String S_PRODUCT_CODE = "";//产品编号
|
private static String S_PRODUCT_TYPE= "";//产品类型
|
private static String S_SFC_CODE = "";//总成编码
|
private static String PRODUCTION_LINE = "BOP";//产线号
|
private static String LOCATION_CODE = "BOP010";//工位号
|
private static List list = null;
|
|
public StateCallback(MiloService miloService,
|
ProductionOrdeInfoService productionOrdeInfoService,
|
PassingStationCollectionService passingStationCollectionService,
|
ParamCollectionService paramCollectionService,
|
CollectionParamConfService collectionParamConfService,
|
SerialNumbersConfService serialNumbersConfService,
|
EquipmentStatusService equipmentStatusService,
|
EquipmentAlarmService equipmentAlarmService,
|
MaterialTraceabilityService materialTraceabilityService,
|
EquipmentInfoService equipmentInfoService,
|
RepairManageInfoService repairManageInfoService,
|
LocationInfoService locationInfoService,
|
GreaseManageService greaseManageService,
|
ProductionOrderRecordsService productionOrderRecordsService,
|
ProductionOrderBatchInfoService productionOrderBatchInfoService) {
|
this.miloService = miloService;
|
this.productionOrdeInfoService = productionOrdeInfoService;
|
this.passingStationCollectionService = passingStationCollectionService;
|
this.paramCollectionService = paramCollectionService;
|
this.collectionParamConfService = collectionParamConfService;
|
this.serialNumbersConfService = serialNumbersConfService;
|
this.equipmentStatusService = equipmentStatusService;
|
this.equipmentAlarmService = equipmentAlarmService;
|
this.materialTraceabilityService = materialTraceabilityService;
|
this.equipmentInfoService = equipmentInfoService;
|
this.repairManageInfoService = repairManageInfoService;
|
this.locationInfoService = locationInfoService;
|
this.greaseManageService = greaseManageService;
|
this.productionOrderRecordsService = productionOrderRecordsService;
|
this.productionOrderBatchInfoService = productionOrderBatchInfoService;
|
}
|
@Override
|
public void onSubscribe(String identifier, Object value) {
|
String ecpStr = "";//异常记录标记
|
try {
|
handleInfo();
|
} catch (Exception e) {
|
ecpStr ="出现异常:" + logUtil.getTrace(e);
|
}finally {
|
if(!"".equals(ecpStr)){
|
logger.info(ecpStr+"\r\n");
|
}
|
}
|
}
|
public void handleInfo() throws Exception {
|
logger.info("OP100工位,handleInfo START!");
|
|
if(null == list ){
|
EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam();
|
list = equipmentInfoService.findListBySpec(equipmentInfoParam);
|
}
|
if(null != list && list.size()>0) {
|
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.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.add(equipmentAlarmParam);
|
}
|
}
|
|
}
|
}
|
|
|
Thread.sleep(60*1000);
|
}
|
|
public void handleOilStateDOP020(String LOCATION_CODE) throws Exception {
|
GreaseManageParam param = new GreaseManageParam();
|
param.setLocationCode(LOCATION_CODE);
|
List<GreaseManageResult> list = greaseManageService.findListBySpec(param);
|
if(!list.isEmpty()) {
|
String duaDate = list.get(0).getDuaDate();
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
|
String currentDate = format.format(new Date());
|
long daysBetween = getRemainder(currentDate,duaDate);
|
if(daysBetween>0){
|
ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_OIL_STATE,false);
|
miloService.writeToOpcUa(entity);//写PC完成
|
}else{
|
ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_OIL_STATE,true);
|
miloService.writeToOpcUa(entity);//写PC完成
|
}
|
}
|
}
|
|
public void handleOilStateOP050(String LOCATION_CODE) throws Exception {
|
GreaseManageParam param = new GreaseManageParam();
|
param.setLocationCode(LOCATION_CODE);
|
List<GreaseManageResult> list = greaseManageService.findListBySpec(param);
|
if(!list.isEmpty()) {
|
String duaDate = list.get(0).getDuaDate();
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
|
String currentDate = format.format(new Date());
|
long daysBetween = getRemainder(currentDate,duaDate);
|
if(daysBetween>0){
|
ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_OIL_STATE,false);
|
miloService.writeToOpcUa(entity);//写PC完成
|
}else{
|
ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_OIL_STATE,true);
|
miloService.writeToOpcUa(entity);//写PC完成
|
}
|
}
|
}
|
|
public void handleOilStateBOP030(String LOCATION_CODE) throws Exception {
|
GreaseManageParam param = new GreaseManageParam();
|
param.setLocationCode(LOCATION_CODE);
|
List<GreaseManageResult> list = greaseManageService.findListBySpec(param);
|
if(!list.isEmpty()) {
|
String duaDate = list.get(0).getDuaDate();
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
|
String currentDate = format.format(new Date());
|
long daysBetween = getRemainder(currentDate,duaDate);
|
if(daysBetween>0){
|
ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_OIL_STATE,false);
|
miloService.writeToOpcUa(entity);//写PC完成
|
}else{
|
ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_OIL_STATE,true);
|
miloService.writeToOpcUa(entity);//写PC完成
|
}
|
}
|
}
|
|
public static long getRemainder(String currentDate,String tableDate){
|
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
LocalDate localDate1 = LocalDate.parse(currentDate, dateFormatter);
|
LocalDate localDate2 = LocalDate.parse(tableDate, dateFormatter);
|
long days = ChronoUnit.DAYS.between(localDate1, localDate2);
|
return days;
|
}
|
}
|