| | |
| | | package com.fzzy.gateway.controller; |
| | | |
| | | import com.fzzy.api.data.GatewayDeviceProtocol; |
| | | import com.fzzy.api.data.GatewayDeviceType; |
| | | import com.fzzy.async.fzzy40.entity.Fz40Grain; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.api.GatewayDeviceReportService; |
| | | import com.fzzy.gateway.api.GatewayRemoteManager; |
| | | import com.fzzy.gateway.api.GatewaySyncLprService; |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | | import com.fzzy.gateway.entity.GateWayParam; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.service.GatewayDeviceService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | /** |
| | |
| | | public class GatewayDataApi { |
| | | |
| | | @Resource |
| | | private GatewayDeviceService gatewayDeviceService; |
| | | |
| | | @Resource |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | |
| | | |
| | | /** |
| | | * 测试入口 |
| | | * 粮情数据推送,第三方软件平台推送粮情数据到网关 |
| | | * |
| | | * @param param |
| | | * @param grainData |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @PostMapping("/test/deviceTest") |
| | | public @ResponseBody |
| | | String deviceTest(@RequestBody GateWayParam param) throws Exception { |
| | | @PostMapping("/push-grain") |
| | | public @ResponseBody BaseResp pushGrain(@RequestBody Fz40Grain grainData) throws Exception { |
| | | |
| | | if (StringUtils.isEmpty(param.getBizType())) { |
| | | return "ERROR:没有获取到业务类型,执行失败"; |
| | | BaseResp resp = new BaseResp(); |
| | | |
| | | //根据系统仓库编码获取配置设备信息 |
| | | GatewayDevice device = GatewayUtils.getCacheByDepotSysId(grainData.getDepotId()); |
| | | |
| | | if (null == device) { |
| | | resp.setMsg("网关中没有获取到配置的终端设备信息,无法执行。仓库编码=" + grainData.getDepotId()); |
| | | resp.setCode(BaseResp.CODE_500); |
| | | return resp; |
| | | } |
| | | |
| | | if ("testGrain".equals(param.getBizType())) { |
| | | return testGrain(param); |
| | | //数据封装转换 |
| | | GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()); |
| | | if (null == reportService) { |
| | | log.error("------------粮情推送失败,系统不存在当前协议执行类----{}", device.getDeviceName()); |
| | | resp.setMsg("粮情推送失败,系统不存在当前协议执行类,网关设备=" + device.getDeviceName()); |
| | | resp.setCode(BaseResp.CODE_500); |
| | | return resp; |
| | | } |
| | | |
| | | if ("ajaxTestKafkaGrain".equals(param.getBizType())) { |
| | | return ajaxTestKafkaGrain(param); |
| | | } |
| | | |
| | | if ("ajaxTestWeight".equals(param.getBizType())) { |
| | | return ajaxTestWeight(param); |
| | | } |
| | | |
| | | if ("ajaxTestLpr".equals(param.getBizType())) { |
| | | return ajaxTestLpr(param); |
| | | } |
| | | |
| | | return "SUCCESS"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 下行分机测试入口 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @PostMapping("/test/IDE") |
| | | public @ResponseBody |
| | | String testIDE(@RequestBody GateWayParam param) throws Exception { |
| | | |
| | | if (StringUtils.isEmpty(param.getBizType())) { |
| | | return "ERROR:没有获取到业务类型,执行失败"; |
| | | } |
| | | |
| | | //获取分机配置 |
| | | if ("syncConf".equals(param.getBizType())) { |
| | | return syncConf(param); |
| | | } |
| | | |
| | | if ("writeConf".equals(param.getBizType())) { |
| | | return writeConf(param); |
| | | } |
| | | |
| | | if ("initParam".equals(param.getBizType())) { |
| | | return initCable(param); |
| | | } |
| | | |
| | | if ("disconnect".equals(param.getBizType())) { |
| | | return disconnect(param); |
| | | } |
| | | |
| | | if ("transparent".equals(param.getBizType())) { |
| | | return transparent(param); |
| | | } |
| | | |
| | | return "SUCCESS"; |
| | | } |
| | | |
| | | |
| | | private String transparent(GateWayParam param) { |
| | | |
| | | String deviceId = param.getDeviceId(); |
| | | |
| | | GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId); |
| | | //数据封装 |
| | | resp = reportService.grainData2GatewayApiInfo(grainData, device); |
| | | |
| | | BaseReqData reqData = new BaseReqData(); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDevice(device); |
| | | reqData.setAutoReplay(false); |
| | | |
| | | BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).transparent(reqData); |
| | | if (BaseResp.CODE_200 != resp.getCode()) { |
| | | return "ERROR:" + resp.getMsg(); |
| | | } |
| | | return "SUCCESS"; |
| | | } |
| | | |
| | | private String disconnect(GateWayParam param) { |
| | | String deviceId = param.getDeviceId(); |
| | | |
| | | GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId); |
| | | |
| | | BaseReqData reqData = new BaseReqData(); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | |
| | | reqData.setDevice(device); |
| | | reqData.setAutoReplay(false); |
| | | |
| | | BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).disconnect(reqData); |
| | | if (BaseResp.CODE_200 != resp.getCode()) { |
| | | return "ERROR:" + resp.getMsg(); |
| | | } |
| | | return "SUCCESS"; |
| | | //手动推送到平台 |
| | | resp = reportService.reportGrainDataByHand(reqData); |
| | | |
| | | |
| | | return resp; |
| | | } |
| | | |
| | | private String initCable(GateWayParam param) { |
| | | String deviceId = param.getDeviceId(); |
| | | |
| | | GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId); |
| | | |
| | | BaseReqData reqData = new BaseReqData(); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDevice(device); |
| | | reqData.setAutoReplay(false); |
| | | |
| | | BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).initCable(reqData); |
| | | if (BaseResp.CODE_200 != resp.getCode()) { |
| | | return "ERROR:" + resp.getMsg(); |
| | | } |
| | | return "SUCCESS"; |
| | | } |
| | | |
| | | private String syncConf(GateWayParam param) { |
| | | |
| | | String deviceId = param.getDeviceId(); |
| | | |
| | | GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId); |
| | | |
| | | BaseReqData reqData = new BaseReqData(); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDevice(device); |
| | | reqData.setAutoReplay(false); |
| | | |
| | | BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncConf(reqData); |
| | | if (BaseResp.CODE_200 != resp.getCode()) { |
| | | return "ERROR:" + resp.getMsg(); |
| | | } |
| | | return "SUCCESS"; |
| | | } |
| | | |
| | | private String writeConf(GateWayParam param) { |
| | | String deviceId = param.getDeviceId(); |
| | | |
| | | GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId); |
| | | |
| | | BaseReqData reqData = new BaseReqData(); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDevice(device); |
| | | reqData.setAutoReplay(false); |
| | | |
| | | BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).writeConf(reqData); |
| | | if (BaseResp.CODE_200 != resp.getCode()) { |
| | | return "ERROR:" + resp.getMsg(); |
| | | } |
| | | return "SUCCESS"; |
| | | } |
| | | |
| | | /** |
| | | * 初始化车牌识别 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @PostMapping("/control/init-lpr") |
| | | public @ResponseBody |
| | | String initLpr(@RequestBody GateWayParam param) throws Exception { |
| | | |
| | | List<GatewayDevice> list = gatewayDeviceService.listAll(); |
| | | |
| | | if (null == list || list.isEmpty()) { |
| | | return "ERROR:没有获取到设备信息"; |
| | | } |
| | | |
| | | BaseReqData reqData; |
| | | int i = 0; |
| | | GatewaySyncLprService syncLprService; |
| | | for (GatewayDevice device : list) { |
| | | |
| | | if (!GatewayDeviceType.TYPE_02.getCode().equals(device.getType())) { |
| | | continue; |
| | | } |
| | | reqData = new BaseReqData(device); |
| | | reqData.setIndex(i); |
| | | syncLprService = gatewayRemoteManager.getSyncLprService(device.getSyncProtocol()); |
| | | if (null == syncLprService) continue; |
| | | syncLprService.initLpr(reqData); |
| | | i++; |
| | | } |
| | | |
| | | return "SUCCESS"; |
| | | } |
| | | |
| | | private String testGrain(GateWayParam param) { |
| | | String deviceId = param.getDeviceId(); |
| | | |
| | | GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId); |
| | | |
| | | BaseReqData reqData = new BaseReqData(); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDevice(device); |
| | | reqData.setAutoReplay(true); |
| | | |
| | | if (!GatewayDeviceType.TYPE_07.getCode().equals(device.getType())) { |
| | | return "ERROR:当前设备非粮情设备不支持当前操作"; |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(device.getCableRule())) { |
| | | return "ERROR:当前设备没有配置布线规则,无法执行"; |
| | | } |
| | | |
| | | BaseResp resp; |
| | | if (GatewayDeviceProtocol.DEVICE_TEST.getCode().equals(device.getSyncProtocol())) { |
| | | resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrain(reqData); |
| | | } else { |
| | | reqData.setAutoReplay(false); |
| | | resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain(reqData); |
| | | } |
| | | |
| | | //自动推送 |
| | | if (BaseResp.CODE_200 == resp.getCode() && reqData.isAutoReplay()) { |
| | | reqData.setData(resp.getData()); |
| | | gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainData(reqData); |
| | | } |
| | | |
| | | return "SUCCESS"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 粮情推送测试KAFKA方式 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | public String ajaxTestKafkaGrain(GateWayParam param) throws Exception { |
| | | List<GatewayDevice> list = gatewayDeviceService.listAll(); |
| | | if (null == list || list.isEmpty()) { |
| | | return "ERROR:为获取到系统中设备配置,取消执行"; |
| | | } |
| | | |
| | | BaseReqData reqData; |
| | | BaseResp resp; |
| | | for (GatewayDevice device : list) { |
| | | reqData = new BaseReqData(); |
| | | reqData.setDeviceId(param.getDeviceId()); |
| | | reqData.setDayTime(param.getDayTime()); |
| | | reqData.setDevice(device); |
| | | |
| | | resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrainKafka(reqData); |
| | | |
| | | //自动推送 |
| | | if (BaseResp.CODE_200 == resp.getCode()) { |
| | | reqData.setData(resp.getData()); |
| | | gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainDataByKafka(reqData); |
| | | } |
| | | } |
| | | |
| | | return "SUCCESS"; |
| | | } |
| | | |
| | | /** |
| | | * 地磅推送测试 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | public String ajaxTestWeight(GateWayParam param) throws Exception { |
| | | |
| | | double weight = param.getWeight(); |
| | | |
| | | List<GatewayDevice> list = gatewayDeviceService.listAll(); |
| | | if (list == null || list.size() <= 0) { |
| | | return "ERROR:没有配置设备信息,执行失败"; |
| | | } |
| | | |
| | | List<GatewayDevice> weights = list.stream().filter(s -> (GatewayDeviceType.TYPE_01.getCode().equals(s.getType()))).collect(Collectors.toList()); |
| | | if (weights == null || weights.size() <= 0) { |
| | | return "ERROR:ERROR:没有配置设备信息,执行失败"; |
| | | } |
| | | |
| | | BaseReqData reqData; |
| | | BaseResp resp; |
| | | for (GatewayDevice device : weights) { |
| | | reqData = new BaseReqData(); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDevice(device); |
| | | reqData.setAutoReplay(true); |
| | | reqData.setWeight(weight); |
| | | resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testWeight(reqData); |
| | | |
| | | //自动推送 |
| | | if (BaseResp.CODE_200 == resp.getCode() && reqData.isAutoReplay()) { |
| | | reqData.setData(resp.getData()); |
| | | gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportWeightData(reqData); |
| | | } |
| | | } |
| | | return "SUCCESS"; |
| | | } |
| | | |
| | | /** |
| | | * 地磅推送测试 |
| | | * |
| | | * @return |
| | | */ |
| | | public String ajaxTestLpr(GateWayParam param) throws Exception { |
| | | |
| | | String carNumber = param.getCarNumber(); |
| | | |
| | | List<GatewayDevice> list = gatewayDeviceService.listAll(); |
| | | if (list == null || list.size() <= 0) { |
| | | log.error("ERROR:没有配置设备信息,执行失败"); |
| | | return "ERROR:没有配置设备信息,执行失败"; |
| | | } |
| | | List<GatewayDevice> weights = list.stream().filter(s -> (GatewayDeviceType.TYPE_02.getCode().equals(s.getType()))).collect(Collectors.toList()); |
| | | if (weights == null || weights.size() <= 0) { |
| | | log.error("ERROR:没有配置设备信息,执行失败"); |
| | | return "ERROR:没有配置设备信息,执行失败"; |
| | | } |
| | | |
| | | BaseReqData reqData; |
| | | BaseResp resp; |
| | | for (GatewayDevice device : weights) { |
| | | reqData = new BaseReqData(); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDevice(device); |
| | | reqData.setAutoReplay(true); |
| | | reqData.setCarNumber(carNumber); |
| | | resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testLpr(reqData); |
| | | |
| | | //自动推送 |
| | | if (BaseResp.CODE_200 == resp.getCode() && reqData.isAutoReplay()) { |
| | | reqData.setData(resp.getData()); |
| | | gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportLprData(reqData); |
| | | } |
| | | } |
| | | return "SUCCESS"; |
| | | } |
| | | } |