diff --git a/src/main/java/com/hisense/monitormanage/controller/ShangTangController.java b/src/main/java/com/hisense/monitormanage/controller/ShangTangController.java index c94f719..2cbf02c 100644 --- a/src/main/java/com/hisense/monitormanage/controller/ShangTangController.java +++ b/src/main/java/com/hisense/monitormanage/controller/ShangTangController.java @@ -2,11 +2,16 @@ package com.hisense.monitormanage.controller; import cn.hutool.http.HttpRequest; import com.alibaba.fastjson.JSONObject; +import com.hisense.monitormanage.entity.CameraChannel; +import com.hisense.monitormanage.entity.Event; import com.hisense.monitormanage.entity.Result; +import com.hisense.monitormanage.mapper.EventMapper; import com.hisense.monitormanage.service.ShangTangService; import io.swagger.annotations.ApiOperation; import org.omg.CORBA.Request; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -14,6 +19,8 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,6 +32,9 @@ public class ShangTangController { @Autowired private ShangTangService shangTangService; + @Autowired + private EventMapper eventMapper; + /** * 订阅任务下发接口 * @return @@ -52,6 +62,68 @@ public class ShangTangController { } String strcont = content.toString();// 内容 + JSONObject jsonObject = JSONObject.parseObject(strcont); + Event event = new Event(); + event.setEventCnName(jsonObject.getString("eventAlias")); + event.setEventSerial(jsonObject.getString("eventSerial")); + JSONObject attributes = jsonObject.getJSONObject("attributes"); + if (attributes==null){ + }else { + JSONObject text = attributes.getJSONObject("text"); + if (text == null){ + }else { + event.setVehicle(text.getString("valueDescription")); + } + JSONObject color = attributes.getJSONObject("color"); + if (color == null) { + } else { + event.setColor(color.getString("valueDescription")); + } + JSONObject largeVehicle = attributes.getJSONObject("large_vehicle"); + if (largeVehicle == null) { + } else { + event.setVehicle(largeVehicle.getString("valueDescription")); + } + JSONObject trainingVehicle = attributes.getJSONObject("training_vehicle"); + if (trainingVehicle == null) { + } else { + event.setVehicle(trainingVehicle.getString("valueDescription")); + } + JSONObject smallVehicle = attributes.getJSONObject("small_vehicle"); + if (smallVehicle == null) { + } else { + event.setVehicle(smallVehicle.getString("valueDescription")); + } + JSONObject aClass = attributes.getJSONObject("class"); + if (aClass == null) { + } else { + event.setClasses(aClass.getString("valueDescription")); + } + } + JSONObject camera = jsonObject.getJSONObject("camera"); + if (camera == null){ + }else { + event.setCameraName(camera.getString("cameraName")); + event.setDistrict(camera.getString("district")); + event.setLatitude(camera.getBigDecimal("latitude")); + event.setLongitude(camera.getBigDecimal("longitude")); + } + JSONObject image = jsonObject.getJSONObject("image"); + if (image == null){ + + }else { + event.setImageUrl(image.getString("imageUrl")); + } + event.setTaskId(jsonObject.getString("taskId")); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//要转换的时间格式 + Date date; + try { + date = sdf.parse(sdf.format(jsonObject.get("captureTime"))); + event.setCaptureTime(sdf.format(date)); + }catch (Exception e){ + e.printStackTrace(); + } + eventMapper.insert(event); System.out.println(strcont); return Result.success(strcont); } @@ -68,4 +140,13 @@ public class ShangTangController { } + @GetMapping("selectEvent") + public Result selectEvent(){ + List events = eventMapper.selectEvent(); + + Result success = Result.success(events); + + return success; + } + } diff --git a/src/main/java/com/hisense/monitormanage/entity/Event.java b/src/main/java/com/hisense/monitormanage/entity/Event.java new file mode 100644 index 0000000..d8861c5 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/entity/Event.java @@ -0,0 +1,27 @@ +package com.hisense.monitormanage.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +@Data +@TableName("t_event") +public class Event { + @TableId + private String id; + private String eventCnName; + private String eventSerial; + private String color; + private String vehicle; + private String classes; + private String cameraName; + private String district; + private BigDecimal latitude; + private BigDecimal longitude; + private String imageUrl; + private String taskId; + private String captureTime; +} diff --git a/src/main/java/com/hisense/monitormanage/mapper/EventMapper.java b/src/main/java/com/hisense/monitormanage/mapper/EventMapper.java new file mode 100644 index 0000000..cdd1e5f --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/mapper/EventMapper.java @@ -0,0 +1,12 @@ +package com.hisense.monitormanage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hisense.monitormanage.entity.Event; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +public interface EventMapper extends BaseMapper { + @Select("SELECT * FROM t_event") + List selectEvent(); +} diff --git a/src/main/resources/mapper/EventMapper.xml b/src/main/resources/mapper/EventMapper.xml new file mode 100644 index 0000000..4ad23b8 --- /dev/null +++ b/src/main/resources/mapper/EventMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file