| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.druid.sql.visitor.functions.Substring; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.billion.main.api.domain.StationST180; |
| | | import com.billion.main.da.domain.DaCollectionParamConf; |
| | | import com.billion.main.da.domain.DaParamCollection; |
| | | import com.billion.main.da.domain.DaStationCollection; |
| | | import com.billion.main.da.domain.DaTightenCollection; |
| | | import com.billion.main.da.service.IDaCollectionParamConfService; |
| | | import com.billion.main.da.service.IDaParamCollectionService; |
| | | import com.billion.main.da.service.IDaStationCollectionService; |
| | | import com.billion.main.da.service.IDaTightenCollectionService; |
| | | import com.billion.main.plc.constant.Constants; |
| | | import com.billion.main.sc.domain.ScCollectionParamConf; |
| | | import com.billion.main.sc.service.IScCollectionParamConfService; |
| | |
| | | import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | @Slf4j |
| | | @Component |
| | | public class OPCUaSubscription implements SubscriptionCallback { |
| | | private static final Logger logger = LoggerFactory.getLogger("sys-user"); |
| | | |
| | | public static MiloService miloService; |
| | | public static IScCollectionParamConfService collectionParamConfService; |
| | | public static IDaParamCollectionService paramCollectionService; |
| | | public static IDaStationCollectionService stationCollectionService; |
| | | |
| | | public static IDaCollectionParamConfService daCollectionParamConfService; |
| | | public static IDaTightenCollectionService daTightenCollectionService; |
| | | public static SysNoticeServiceImpl sysNoticeService; |
| | | |
| | | public OPCUaSubscription(MiloService miloService, IScCollectionParamConfService collectionParamConfService |
| | | ,IDaParamCollectionService paramCollectionService,IDaStationCollectionService stationCollectionService,SysNoticeServiceImpl sysNoticeService) { |
| | | ,IDaParamCollectionService paramCollectionService,IDaStationCollectionService stationCollectionService,SysNoticeServiceImpl sysNoticeService |
| | | ,IDaCollectionParamConfService daCollectionParamConfService,IDaTightenCollectionService daTightenCollectionService) { |
| | | OPCUaSubscription.miloService = miloService; |
| | | OPCUaSubscription.collectionParamConfService = collectionParamConfService; |
| | | OPCUaSubscription.paramCollectionService = paramCollectionService; |
| | | OPCUaSubscription.stationCollectionService = stationCollectionService; |
| | | OPCUaSubscription.sysNoticeService = sysNoticeService; |
| | | |
| | | OPCUaSubscription.daCollectionParamConfService = daCollectionParamConfService; |
| | | OPCUaSubscription.daTightenCollectionService = daTightenCollectionService; |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (ObjUtil.isNotNull(SNCodeObject)){ |
| | | String SnCode = SNCodeObject.toString(); |
| | | if (StrUtil.isNotBlank(SnCode)){ |
| | | savePassingStation(thoroughfare,device,"snCode"); |
| | | saveParamCollection(device, "snCode", "stationStatus"); |
| | | savePassingStation(thoroughfare,device,SnCode); |
| | | saveParamCollection(device, SnCode, "stationStatus"); |
| | | } |
| | | } |
| | | Integer result = Constants.INTEGER_TWO_ONE; |
| | |
| | | private static void saveParamCollection(String device, String snCode, String stationStatus) { |
| | | try { |
| | | // 查询参数配置表 |
| | | List<ScCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<ScCollectionParamConf>() |
| | | .eq(ScCollectionParamConf::getLocationCode, device) |
| | | .eq(ScCollectionParamConf::getSubscribe, Constants.ONE) |
| | | .orderByDesc(ScCollectionParamConf::getOrderNum) |
| | | List<DaCollectionParamConf> list = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>() |
| | | .eq(DaCollectionParamConf::getProcessesCode, device) |
| | | .eq(DaCollectionParamConf::getRemarks, Constants.ONE) |
| | | .orderByAsc(DaCollectionParamConf::getGatherSequence) |
| | | ); |
| | | |
| | | if (CollUtil.isNotEmpty(list)) { |
| | | // 获取参数值 |
| | | List<String> collect = list.stream() |
| | | .map(ScCollectionParamConf::getNode) |
| | | .map(DaCollectionParamConf::getGatherAddress) |
| | | .map(String::trim) |
| | | .collect(Collectors.toList()); |
| | | List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(collect); |
| | | |
| | |
| | | * 保存采集数据 |
| | | */ |
| | | private static void saveCollectionData(String device, String snCode, |
| | | List<ScCollectionParamConf> list, List<ReadWriteEntity> readWriteEntityList) { |
| | | List<DaCollectionParamConf> list, List<ReadWriteEntity> readWriteEntityList) { |
| | | ArrayList<DaParamCollection> collectionList = new ArrayList<>(); |
| | | |
| | | if(Constants.TIGHTENCOLLECTION_LIST.contains(device)){ |
| | | //存拧紧数据 |
| | | try { |
| | | LinkedHashMap<String, Map<String, Object>> groupMap = new LinkedHashMap<>(); |
| | | for (int i = 0; i < list.size(); i += 3) { |
| | | try { |
| | | String groupKey = String.valueOf(i/3); |
| | | String paramSetName = list.get(i).getParameterSetName(); |
| | | int secondSlash = paramSetName.indexOf("/", paramSetName.indexOf("/") + 1); |
| | | paramSetName = secondSlash > 0 ? paramSetName.substring(0, secondSlash) : paramSetName; |
| | | |
| | | Map<String, Object> paramMap = new HashMap<>(); |
| | | |
| | | // 获取扭矩值 |
| | | Object torqueObj = readWriteEntityList.get(i).getValue(); |
| | | String torqueValue = torqueObj == null ? null : torqueObj.toString(); |
| | | if (torqueValue != null && !"0.0".equals(torqueValue)) { |
| | | paramMap.put("torque", Double.parseDouble(torqueValue)); |
| | | } |
| | | |
| | | // 获取角度值 |
| | | Object angleObj = readWriteEntityList.get(i + 1).getValue(); |
| | | String angleValue = angleObj == null ? null : angleObj.toString(); |
| | | if (angleValue != null && !"0.0".equals(angleValue)) { |
| | | paramMap.put("angle", Double.parseDouble(angleValue)); |
| | | } |
| | | |
| | | // 获取状态值 |
| | | Object statusObj = readWriteEntityList.get(i + 2).getValue(); |
| | | String statusValue = statusObj == null ? null : statusObj.toString(); |
| | | if (statusValue != null && !"0.0".equals(statusValue)) { |
| | | paramMap.put("angleStatus", statusValue); |
| | | paramMap.put("paramSetName", paramSetName); |
| | | groupMap.put(groupKey, paramMap); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("{}发动机拧紧数据第{}组处理失败: {}", snCode, i/3, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | List<DaTightenCollection> tightenList = new ArrayList<>(); |
| | | for (Map<String, Object> paramMap : groupMap.values()) { |
| | | try { |
| | | DaTightenCollection tighten = new DaTightenCollection(); |
| | | tighten.setSfcCode(snCode); |
| | | tighten.setLocationCode(device); |
| | | tighten.setParamSetName((String) paramMap.get("paramSetName")); |
| | | tighten.setTorque(paramMap.get("torque") != null ? paramMap.get("torque").toString() : null); |
| | | tighten.setAngle(paramMap.get("angle") != null ? paramMap.get("angle").toString() : null); |
| | | tighten.setAngleStatus((String) paramMap.get("angleStatus")); |
| | | tighten.setCollectTime(new Date()); |
| | | tightenList.add(tighten); |
| | | } catch (Exception e) { |
| | | logger.error("{}发动机拧紧数据对象转换失败: {}", snCode, e.getMessage()); |
| | | } |
| | | } |
| | | if(tightenList.size()>0){ |
| | | try { |
| | | daTightenCollectionService.saveBeachDaTightenCollection(tightenList); |
| | | logger.info("{}发动机存拧紧数据保存完成",snCode); |
| | | } catch (Exception e) { |
| | | logger.error("{}发动机拧紧数据批量保存失败: {}", snCode, e.getMessage()); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("{}发动机拧紧数据处理异常: {}", snCode, e.getMessage()); |
| | | } |
| | | }else { |
| | | for (int i = 0; i < readWriteEntityList.size(); i++) { |
| | | DaParamCollection daParamCollection = new DaParamCollection(); |
| | | daParamCollection.setSfcCode(snCode); |
| | | daParamCollection.setLocationCode(device); |
| | | daParamCollection.setParamCode(list.get(i).getParamCode()); |
| | | daParamCollection.setParamName(list.get(i).getParamName()); |
| | | daParamCollection.setParamCode(list.get(i).getParameterSetCode()); |
| | | daParamCollection.setParamName(list.get(i).getParameterSetName()); |
| | | daParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString()); |
| | | daParamCollection.setCollectTime(new Date()); |
| | | collectionList.add(daParamCollection); |
| | |
| | | paramCollectionService.insertBatch(collectionList); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 创建工位对象并赋值 |
| | | */ |