Commit 9c4e09c6 by gdj

增加aiInfo的新增接口。

parent c3be5a33
...@@ -18,6 +18,12 @@ import org.springframework.web.bind.annotation.*; ...@@ -18,6 +18,12 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import com.dji.sample.ai.model.dto.TopicAiInfoDTO;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM; import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM;
...@@ -35,6 +41,9 @@ public class AiInfoController { ...@@ -35,6 +41,9 @@ public class AiInfoController {
@Autowired @Autowired
private IAiInfoService aiInfoService; private IAiInfoService aiInfoService;
@Autowired
private ObjectMapper objectMapper;
/** /**
* Paging to query all users in a workspace. * Paging to query all users in a workspace.
* @param param param * @param param param
...@@ -56,6 +65,31 @@ public class AiInfoController { ...@@ -56,6 +65,31 @@ public class AiInfoController {
return HttpResultResponse.success(dto); return HttpResultResponse.success(dto);
} }
@PostMapping("/addFromTopic")
public HttpResultResponse<AiInfoDTO> addAiInfoFromTopic(@RequestBody TopicAiInfoDTO topicDto) throws Exception {
AiInfoDTO dto = new AiInfoDTO();
dto.setDeviceSn(topicDto.getDeviceSn());
dto.setPayloadSn(topicDto.getPayloadSn());
dto.setWarnType(topicDto.getWarnType());
dto.setWarnEvent(topicDto.getWarnEvent());
dto.setImageUrl(topicDto.getImageUrl());
dto.setWarnLocation(topicDto.getWarnLocation());
dto.setAlgorithmType(topicDto.getAlgorithmType());
if (topicDto.getWarnTime() != null) {
dto.setWarnTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(topicDto.getWarnTime()), ZoneId.systemDefault()));
}
dto.setCreateTime(LocalDateTime.now());
if (topicDto.getObj() != null) {
dto.setJson(objectMapper.writeValueAsString(topicDto.getObj()));
}
AiInfoDTO result = aiInfoService.createAiInfo(dto);
return HttpResultResponse.success(result);
}
@GetMapping("/get") @GetMapping("/get")
public HttpResultResponse<AiInfoDTO> getAiInfo(@RequestParam Long id) { public HttpResultResponse<AiInfoDTO> getAiInfo(@RequestParam Long id) {
AiInfoDTO dto = aiInfoService.getAiInfoById(id); AiInfoDTO dto = aiInfoService.getAiInfoById(id);
......
package com.dji.sample.ai.model.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @author guan
*/
@Data
public class TopicAiInfoDTO implements Serializable {
@JsonProperty("device_sn")
private String deviceSn;
@JsonProperty("payload_sn")
private String payloadSn;
@JsonProperty("warn_type")
private String warnType;
@JsonProperty("warn_event")
private String warnEvent;
/** epoch milli */
@JsonProperty("warn_time")
private Long warnTime;
@JsonProperty("image_url")
private String imageUrl;
@JsonProperty("warn_location")
private String warnLocation;
@JsonProperty("algorithm_type")
private String algorithmType;
/** Raw object payload (may be JSON object) */
@JsonProperty("obj")
private Object obj;
}
...@@ -46,6 +46,7 @@ public class GlobalMVCConfigurer implements WebMvcConfigurer { ...@@ -46,6 +46,7 @@ public class GlobalMVCConfigurer implements WebMvcConfigurer {
// 放行 aiInfo 新增与修改接口 // 放行 aiInfo 新增与修改接口
excludePaths.add("/" + managePrefix + manageVersion + "/aiInfo/add"); excludePaths.add("/" + managePrefix + manageVersion + "/aiInfo/add");
excludePaths.add("/" + managePrefix + manageVersion + "/aiInfo/update"); excludePaths.add("/" + managePrefix + manageVersion + "/aiInfo/update");
excludePaths.add("/" + managePrefix + manageVersion + "/aiInfo/addFromTopic");
// Intercept for all request interfaces. // Intercept for all request interfaces.
registry.addInterceptor(authInterceptor).addPathPatterns("/**").excludePathPatterns(excludePaths); registry.addInterceptor(authInterceptor).addPathPatterns("/**").excludePathPatterns(excludePaths);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment