package com.fzzy.igds.api.v1.service; import com.alibaba.fastjson.JSONObject; import com.fzzy.igds.api.v1.data.ApiV1Req; import com.fzzy.igds.api.v1.data.ApiV1Resp; import com.fzzy.igds.api.v1.data.Param3031; import com.fzzy.igds.constant.Constant; import com.fzzy.igds.constant.MonitorPointType; import com.fzzy.igds.data.BaseResp; import com.fzzy.igds.domain.Camera; import com.fzzy.igds.domain.EventInfo; import com.fzzy.igds.domain.GatewaySer; import com.fzzy.igds.domain.SnapReply; import com.fzzy.igds.service.EventInfoService; import com.fzzy.igds.service.FileService; import com.fzzy.igds.service.SecCameraService; import com.fzzy.igds.service.SnapReplyService; import com.fzzy.igds.utils.ContextUtil; import com.ruoyi.common.config.FrameworkConfig; import com.ruoyi.common.utils.StringUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.time.DateUtils; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import javax.annotation.Resource; /** * @Description AI事件解析 * @Author CZT * @Date 2026/1/7 11:09 */ @Slf4j @Component public class ApiV1Service3031 { @Resource private EventInfoService eventInfoService; @Resource private FileService fileService; @Resource private SecCameraService cameraService; @Resource private SnapReplyService snapReplyService; /** * @param req * @param gatewaySer * @return */ public ApiV1Resp analysis(ApiV1Req req, GatewaySer gatewaySer) throws Exception { //转化为对象 Param3031 param = JSONObject.parseObject(JSONObject.toJSONString(req.getData()), Param3031.class); if (null == param) { return ApiV1Resp.error("抓拍信息为空,不解析!", req); } step1(param, gatewaySer); return ApiV1Resp.success(null, req); } /** * 异步解析 * * @param param */ @Async public void step1(Param3031 param, GatewaySer gatewaySer) throws Exception { EventInfo info = new EventInfo(); info.setId(ContextUtil.generateId()); info.setCompanyId(gatewaySer.getCompanyId()); info.setDeptId(gatewaySer.getDeptId()); info.setSerId(param.getCameraId()); info.setName(param.getName()); info.setBizType(param.getBizType()); info.setType(param.getType()); info.setLevel(param.getLevel()); info.setInfo(param.getInfo()); info.setTime(DateUtils.parseDate(param.getTime(), "yyyy-MM-dd HH:mm:ss")); info.setTags(param.getTags()); //base64转化为图片保存 String savePath = fileService.getFileSavePath("EVENT"); String fileName = ContextUtil.UUID() + ".jpg"; String filePath = savePath + fileName; fileService.baseImg2Disk(filePath, param.getImgBase64()); //设置保存图片路径 info.setImgName(filePath.replace(FrameworkConfig.getProfile(), "/profile/")); eventInfoService.addData(info); //地磅抓拍判断是否生成批复告警 Camera cameraById = cameraService.getCameraById(gatewaySer.getCompanyId(), param.getCameraId()); //判断当前抓拍图的触发设备是否是地磅监控设备 if(null != cameraById && MonitorPointType.WEIGHBRIDGE_ROOM.getCode().equals(cameraById.getSpdwlx())){ String isGenerateAReply = param.getIsGenerateAReply(); //判断当前AI事件抓拍,是否触发生成批复告警 if(StringUtils.isNotBlank(isGenerateAReply) && Constant.YN_Y.equals(isGenerateAReply)){ SnapReply snapReply = new SnapReply(); snapReply.setDeptId(gatewaySer.getDeptId()); String content = "检测到库区有疑似出入库行为,请核对处理。"; snapReply.setContent(content); BaseResp baseResp = snapReplyService.addData(snapReply); if(BaseResp.isSuccess(baseResp)){ log.info("生成回复告警成功!"); // todo 推送公众号信息 } } } log.info("质押监管接口V1,3031接口解析完成"); } }