| | |
| | | package com.fzzy.gateway.service; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.bstek.dorado.annotation.DataProvider; |
| | | import com.bstek.dorado.annotation.DataResolver; |
| | |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.hx2023.data.*; |
| | | import com.fzzy.gateway.hx2023.websocket.WebSocketDeviceReport; |
| | | import com.fzzy.gateway.service.repository.GatewayDeviceRep; |
| | | |
| | | import com.fzzy.mqtt.MqttPublishService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import org.apache.commons.lang.StringUtils; |
| | |
| | | @Resource |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | @Resource |
| | | private WebSocketDeviceReport webSocketDeviceReport; |
| | | private MqttPublishService mqttPublishService; |
| | | /** |
| | | * gatewayDeviceService#listAll |
| | | * |
| | |
| | | /** |
| | | * gatewayDeviceService#updateSave |
| | | * |
| | | * @param entity |
| | | * @param data |
| | | */ |
| | | @DataResolver |
| | | public void updateSave(GatewayDevice entity) { |
| | | GatewayDevice data = new GatewayDevice(); |
| | | BeanUtils.copyProperties(entity, data); |
| | | |
| | | if (null == data.getId()) { |
| | | data.setId(ContextUtil.getUUID()); |
| | | } |
| | | |
| | | |
| | | if (null == data.getDeviceSn()) { |
| | | if (null != entity.getIp()) { |
| | | data.setDeviceSn(entity.getIp()); |
| | | public void updateSave(GatewayDevice data) { |
| | | GatewayDevice data2 = new GatewayDevice(); |
| | | BeanUtils.copyProperties(data, data2); |
| | | |
| | | if (null == data2.getDeviceSn()) { |
| | | if (null != data2.getIp()) { |
| | | data.setDeviceSn(data2.getIp()); |
| | | } else { |
| | | data.setDeviceSn(data.getDeviceId()); |
| | | data.setDeviceSn(data2.getDeviceId()); |
| | | } |
| | | } |
| | | |
| | | gatewayDeviceRep.save(data); |
| | | |
| | | if (null == data2.getId()) { |
| | | data2.setId(ContextUtil.getUUID()); |
| | | gatewayDeviceRep.save(data2); |
| | | }else{ |
| | | gatewayDeviceRep.save(data2); |
| | | } |
| | | flushCache(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * gatewayDeviceService#flushCache |
| | | */ |
| | | @Expose |
| | | public void flushCache() { |
| | | List<GatewayDevice> list = listAll(); |
| | | if (null == list || list.isEmpty()) return; |
| | |
| | | * @return |
| | | */ |
| | | @Expose |
| | | public String ajaxTestWeight(Map<String, Object> parameter) { |
| | | double weigh = (double) parameter.get("weight"); |
| | | public String ajaxTestWeight() { |
| | | //double weigh = (double) parameter.get("weight"); |
| | | double weigh = Double.parseDouble("3500.0"); |
| | | List<GatewayDevice> devices = listAll(); |
| | | if(devices == null || devices.size()<= 0){ |
| | | return "没有设备"; |
| | |
| | | if(weights == null || weights.size()<= 0){ |
| | | return "没有获取到地磅设备"; |
| | | } |
| | | String topic = "/device/hx-weigh-big-01/91511424746940066Y001_91511424746940066Y0010000_002_004_002_001/message/property/report"; |
| | | |
| | | for (GatewayDevice device: weights) { |
| | | |
| | | WebSocketPacket packet = new WebSocketPacket(); |
| | |
| | | |
| | | packet.setTimestamp(System.currentTimeMillis()); |
| | | |
| | | |
| | | webSocketDeviceReport.sendByPacket(packet); |
| | | topic = "/device/hx-weigh-big-01/"+device.getDeviceId()+"/message/property/report"; |
| | | mqttPublishService.publishMsg(topic, JSON.toJSONString(packet)); |
| | | } |
| | | return "SUCCESS"; |
| | | } |