package com.fzzy.gateway.controller;
|
|
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.data.BaseReqData;
|
import com.fzzy.gateway.data.BaseResp;
|
import com.fzzy.gateway.entity.GatewayDevice;
|
import lombok.extern.slf4j.Slf4j;
|
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;
|
|
|
/**
|
* 与网关相关的接口数据对接,由第三方对接
|
*/
|
@Slf4j
|
@Controller
|
@RequestMapping("/gateway/api/v1")
|
public class GatewayDataApi {
|
|
@Resource
|
private GatewayRemoteManager gatewayRemoteManager;
|
|
|
/**
|
* 粮情数据推送,第三方软件平台推送粮情数据到网关
|
*
|
* @param grainData
|
* @return
|
* @throws Exception
|
*/
|
@PostMapping("/push-grain")
|
public @ResponseBody
|
BaseResp pushGrain(@RequestBody Fz40Grain grainData) {
|
|
BaseResp resp = new BaseResp();
|
try {
|
|
log.info("----------主动推送粮情接口执行----{}",grainData);
|
|
//根据系统仓库编码获取配置设备信息
|
GatewayDevice device = GatewayUtils.getCacheByDepotSysId(grainData.getDepotId());
|
|
if (null == device) {
|
resp.setMsg("网关中没有获取到配置的终端设备信息,无法执行。仓库编码=" + grainData.getDepotId());
|
resp.setCode(BaseResp.CODE_500);
|
return resp;
|
}
|
|
//数据封装转换
|
GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(device.getPushProtocol());
|
if (null == reportService) {
|
log.error("------------粮情推送失败,系统不存在当前协议执行类----{}", device.getDeviceName());
|
resp.setMsg("粮情推送失败,系统不存在当前协议执行类,网关设备=" + device.getDeviceName());
|
resp.setCode(BaseResp.CODE_500);
|
return resp;
|
}
|
|
//数据封装
|
resp = reportService.grainData2GatewayApiInfo(grainData, device);
|
|
BaseReqData reqData = new BaseReqData();
|
reqData.setProductId(device.getProductId());
|
reqData.setDeviceName(device.getDeviceName());
|
reqData.setDeviceId(device.getDeviceId());
|
|
reqData.setDevice(device);
|
reqData.setData(resp.getData());
|
|
//手动推送到平台
|
resp = reportService.reportGrainDataByHand(reqData);
|
|
} catch (Exception e) {
|
log.error("-----------手动推送粮情数据执行异常---{}", e);
|
resp.setCode(BaseResp.CODE_500);
|
resp.setMsg("执行异常:" + e.getMessage());
|
}
|
return resp;
|
}
|
}
|