¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.gateway.controller; |
| | | |
| | | import com.fzzy.api.data.GatewayDeviceProtocol; |
| | | import com.fzzy.api.data.GatewayDeviceType; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | 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.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | /** |
| | | * ä¸ç½å
³ç¸å
³çæ¥å£æ°æ®å¯¹æ¥ï¼ç±ç¬¬ä¸æ¹å¯¹æ¥ |
| | | */ |
| | | @Slf4j |
| | | @Controller |
| | | @RequestMapping("/gateway/api/v1") |
| | | public class GatewayDataApi { |
| | | |
| | | @Resource |
| | | private GatewayDeviceService gatewayDeviceService; |
| | | |
| | | @Resource |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | |
| | | |
| | | /** |
| | | * æµè¯å
¥å£ |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @PostMapping("/test/deviceTest") |
| | | public @ResponseBody |
| | | String deviceTest(@RequestBody GateWayParam param) throws Exception { |
| | | |
| | | if (StringUtils.isEmpty(param.getBizType())) { |
| | | return "ERROR:没æè·åå°ä¸å¡ç±»åï¼æ§è¡å¤±è´¥"; |
| | | } |
| | | |
| | | if ("testGrain".equals(param.getBizType())) { |
| | | return testGrain(param); |
| | | } |
| | | |
| | | 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); |
| | | |
| | | 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"; |
| | | } |
| | | |
| | | 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"; |
| | | } |
| | | } |