package org.springnewfiber.dataadapter.xf.controller; import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Maps; import io.swagger.annotations.Api; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springnewfiber.dataadapter.config.R; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; import org.springnewfiber.dataadapter.xf.XfDataEnum; import org.springnewfiber.dataadapter.xf.entity.*; import java.util.Date; import java.util.Map; /** * @program: newfiber-data-adapter * @description: * @author: djt * @create: 2022-06-14 20:44 **/ @RestController @AllArgsConstructor //@PreAuth(AuthConstant.PERMISSION_ALL) @RequestMapping("/monitorData") @Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") @Slf4j public class MonitorDataController { @PostMapping("/xfInterface") public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); PtReceiveBaseModel model = new PtReceiveBaseModel(); try { if (xfDataEnum == XfDataEnum.ChnlData) { MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); model = RealTimeSerializer.xfObjectToRealMap(DTO); } else if (xfDataEnum == XfDataEnum.ForcastData) { MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); model = new PtReceiveBaseModel(); Map<String, MqNodeData> dataMap = Maps.newHashMap(); MqNodeData dataQ = new MqNodeData(); dataQ.setSn("q"); dataQ.setKey("q"); dataQ.setValue(DTO.getQ()); MqNodeData dataZ = new MqNodeData(); dataZ.setSn("z"); dataZ.setKey("z"); dataZ.setValue(DTO.getZ()); MqNodeData dataYbt = new MqNodeData(); dataYbt.setSn("ybt"); dataYbt.setKey("ybt"); dataYbt.setValue(DTO.getFocTime()); dataMap.put("q", dataQ); dataMap.put("z", dataZ); dataMap.put("ybt", dataYbt); model.setDataMap(dataMap); model.setSt(DTO.getStcd()); model.setTt(DTO.getPubTime()); model.setUt(new Date()); } else if (xfDataEnum == XfDataEnum.LakeData) { MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); model = RealTimeSerializer.xfObjectToRealMap(DTO); } else if (xfDataEnum == XfDataEnum.Meteorological) { MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); model = RealTimeSerializer.xfObjectToRealMap(DTO); } else if (xfDataEnum == XfDataEnum.PptnData) { MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); model = RealTimeSerializer.xfObjectToRealMap(DTO); } else if (xfDataEnum == XfDataEnum.PumpData) { MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); model = RealTimeSerializer.xfObjectToRealMap(DTO); } else if (xfDataEnum == XfDataEnum.RiverData) { MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); model = RealTimeSerializer.xfObjectToRealMap(DTO); } else if (xfDataEnum == XfDataEnum.SoilData) { MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); model = RealTimeSerializer.xfObjectToRealMap(DTO); } else if (xfDataEnum == XfDataEnum.WasData) { MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); model = RealTimeSerializer.xfObjectToRealMap(DTO); } else if (xfDataEnum == XfDataEnum.WetlogData) { MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); model = RealTimeSerializer.xfObjectToRealMap(DTO); } else { throw new RuntimeException("暂未开发"); } log.info("cover:{}", JSONObject.toJSONString(model)); return R.status(true); } catch (Exception e) { log.error("解析错误,:{}", e.getStackTrace()); throw new RuntimeException("类型转换错误"); } } }