diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/camera/CameraController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/camera/CameraController.java index f394a9577..58dd9198d 100644 --- a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/camera/CameraController.java +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/camera/CameraController.java @@ -7,11 +7,15 @@ import com.jsowell.common.core.controller.BaseController; import com.jsowell.pile.dto.camera.CameraHeartBeatDTO; import com.jsowell.pile.dto.camera.CameraIdentifyResultsDTO; import com.jsowell.thirdparty.camera.common.CameraCommonResult; +import com.jsowell.thirdparty.camera.service.CameraService; +import org.springframework.beans.factory.annotation.Autowired; 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.RestController; +import java.util.List; + /** * 充电相机 controller * @@ -22,6 +26,8 @@ import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/camera") public class CameraController extends BaseController { + @Autowired + private CameraService cameraService; /** * 心跳 @@ -40,8 +46,11 @@ public class CameraController extends BaseController { * @param jsonObject */ @PostMapping("/v1/receiveIdentifyResults") - public void receiveIdentifyResults(@RequestBody JSONObject jsonObject) { + public CameraCommonResult receiveIdentifyResults(@RequestBody JSONObject jsonObject) { logger.info("相机系统接收识别结果 params:{}", jsonObject); - + CameraCommonResult result = new CameraCommonResult(); + // 调用service方法处理 + cameraService.receiveIdentifyResults(jsonObject); + return result.successResponse(); } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/camera/service/CameraService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/camera/service/CameraService.java index b30f5467b..968bfe2d5 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/camera/service/CameraService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/camera/service/CameraService.java @@ -1,11 +1,45 @@ package com.jsowell.thirdparty.camera.service; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.pile.dto.camera.CameraIdentifyResultsDTO; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + /** - * TODO + * 相机管理系统 Service * * @author Lemon * @Date 2023/12/5 11:11:32 */ +@Service public class CameraService { + @Autowired + private RedisCache redisCache; + + + public void receiveIdentifyResults(JSONObject jsonObject) { + + // 获取背景图片 + JSONArray bgImgs = jsonObject.getJSONArray("bg_img"); + List bgImgList = bgImgs.toList(CameraIdentifyResultsDTO.BgImg.class); + if (CollectionUtils.isEmpty(bgImgList)) { + return; + } + for (CameraIdentifyResultsDTO.BgImg bgImg : bgImgList) { + String image = bgImg.getImage(); // 图片的 base64 编码 + String key = bgImg.getKey(); // 索引id + String redisKey = "receiveCameraImageByKey_" + key; + // 根据索引id存入缓存 + redisCache.setCacheObject(redisKey, image, 10, TimeUnit.HOURS); + } + + } }