| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.fzzy.api.data.GatewayDeviceProtocol; |
| | | import com.fzzy.api.data.GatewayDeviceType; |
| | | import com.fzzy.api.utils.DateUtil; |
| | | import com.fzzy.data.ConfigData; |
| | | import com.fzzy.gateway.api.GatewayRemoteManager; |
| | | import com.fzzy.gateway.api.GatewayRemoteService; |
| | | import com.fzzy.gateway.api.GatewaySyncGranService; |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | | import com.fzzy.gateway.data.WeatherWebDto; |
| | | import com.fzzy.gateway.entity.GatewayConf; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.service.GatewayConfService; |
| | | import com.fzzy.gateway.service.GatewayDeviceTestPR; |
| | | import com.fzzy.gateway.util.GatewayHttpUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Collection; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 网关相关的定时器 |
| | |
| | | @Resource |
| | | private ConfigData configData; |
| | | |
| | | @Resource |
| | | private GatewayDeviceTestPR gatewayDeviceTestPR; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | doHeartbeat(); |
| | | |
| | | } |
| | | /** |
| | | * <p> |
| | | * 粮情每天11点穿上区 |
| | | */ |
| | | // @Scheduled(cron = "0 0 11 * * ?") |
| | | public void scheduledGrain() { |
| | | //获取设备配置,只针对粮情设备进行执行 |
| | | log.info("定时kafka粮情推送"); |
| | | List<GatewayDevice> list = gatewayDeviceTestPR.listAll(); |
| | | |
| | | if (null == list || list.isEmpty()) { |
| | | log.error("为获取到系统中设备配置,取消执行\""); |
| | | return ; |
| | | } |
| | | BaseReqData reqData; |
| | | BaseResp resp; |
| | | for (GatewayDevice device : list) { |
| | | |
| | | //如果不是粮情分机跳过 |
| | | if (!GatewayDeviceType.TYPE_07.getCode().equals(device.getType())) { |
| | | continue; |
| | | } |
| | | reqData = new BaseReqData(); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | reqData.setDayTime(new Date()); |
| | | reqData.setDevice(device); |
| | | |
| | | //获取到 |
| | | resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrainKafka(reqData); |
| | | log.info("resp = "+resp.toString()); |
| | | //自动推送 |
| | | if (BaseResp.CODE_200 == resp.getCode()) { |
| | | reqData.setData(resp.getData()); |
| | | gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainDataByHand(reqData); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * <p> |
| | | * 粮情每天8点采集粮情 |
| | | * |
| | | */ |
| | | // @Scheduled(cron = "0 30 5 ? * *") |
| | | // @Scheduled(cron = "0 32 11 ? * 1,4") |
| | | @Scheduled(cron = "0 32 5 ? * *") |
| | | public void scheduledGrain2() { |
| | | //获取设备配置,只针对粮情设备进行执行 |
| | | log.info("定时粮情采集kafka推送"); |
| | | List<GatewayDevice> list = gatewayDeviceTestPR.listAll(); |
| | | |
| | | if (null == list || list.isEmpty()) { |
| | | log.error("为获取到系统中设备配置,取消执行\""); |
| | | return ; |
| | | } |
| | | BaseReqData reqData ; |
| | | BaseResp resp; |
| | | |
| | | for (int i = 0 ;i<3;i++){ |
| | | for (GatewayDevice device : list) { |
| | | try{ |
| | | //如果不是粮情分机跳过 |
| | | if (!GatewayDeviceType.TYPE_07.getCode().equals(device.getType())) { |
| | | continue; |
| | | } |
| | | if( i>0 && !(device.getDeviceId().startsWith("91510704731594658J001") ||device.getDeviceId().startsWith("91510704731594658J002") || device.getDeviceId().startsWith("91510700205404914T001"))){ |
| | | continue; |
| | | } |
| | | reqData = new BaseReqData(); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDevice(device); |
| | | reqData.setAutoReplay(true); |
| | | GatewaySyncGranService syncGrainService = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()); |
| | | resp = syncGrainService.syncGrain(reqData); |
| | | log.info("命令发送结果:"+resp.toString()); |
| | | Thread.sleep(120000); |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage(),e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | @Scheduled(cron = "0/3 * * * * ?") |
| | | public void scheduled3() { |
| | | try{ |
| | | //执行HTTP地磅请求 |
| | | exeHttpWeightReq(); |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage(),e); |
| | | } |
| | | |
| | | //执行HTTP地磅请求 |
| | | exeHttpWeightReq(); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | BaseReqData reqData; |
| | | for (GatewayDevice device : list) { |
| | | |
| | | if (!GatewayDeviceProtocol.DEVICE_WEIGHT_HTTP.getCode().equals(device.getSyncProtocol())) { |
| | | continue; |
| | | } |
| | | |
| | | reqData = new BaseReqData(); |
| | | reqData.setDevice(device); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | |
| | | gatewayRemoteManager.getSyncWeightService(device.getSyncProtocol()).syncWeightInfo(reqData); |
| | | } |
| | | } |