潘志宝
2024-11-14 afa8fc57084c423218c6816b710dfb2f0b87ea89
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/video/service/impl/CameraServiceImpl.java
@@ -10,7 +10,7 @@
import com.iailab.framework.web.core.util.WebFrameworkUtils;
import com.iailab.module.data.mq.consumer.ImageMessage;
import com.iailab.module.data.video.controller.admin.camera.vo.CameraPageReqVO;
import com.iailab.module.data.video.dahua.DHSavePath;
import com.iailab.module.data.video.config.VideoConfiguration;
import com.iailab.module.data.video.dao.CameraDao;
import com.iailab.module.data.video.dao.ImageDao;
import com.iailab.module.data.video.dto.CameraDTO;
@@ -20,6 +20,7 @@
import com.iailab.module.data.video.service.CameraService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -35,6 +36,9 @@
 */
@Service
public class CameraServiceImpl extends BaseServiceImpl<CameraDao, CameraEntity> implements CameraService {
    @Value("${video.capture-dir}")
    public String captureDir;
    @Resource
    private CameraDao cameraDao;
@@ -93,26 +97,40 @@
    public void dealCapture(Map<String, String> params) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, 0);
        Date captureDate = calendar.getTime();
        CameraDTO devCamera = getByCode(params.get("cmdSerial"));
        String strFileName = params.get("strFileName");
        String brand = params.get("brand");
        String capturePath = "";
        String routingKey = "";
        switch (brand) {
            case "DH":
                capturePath = VideoConfiguration.staticDhCapturePath;
                routingKey = ImageMessage.DAHUA_ROUTING_KEY;
                break;
            case "HK":
                capturePath = VideoConfiguration.staticHkCapturePath;
                routingKey = ImageMessage.HIKVISION_ROUTING_KEY;
                break;
        }
        String imagePath = strFileName.replace("\\", "/");
        String imageUrl = imagePath.replace(DHSavePath.capturePath, "");
        String imageUrl = imagePath.replace(capturePath, "");
        ImageEntity image = new ImageEntity();
        image.setCameraId(devCamera.getId());
        image.setImagePath(imagePath);
        image.setImageUrl("/Capture/" + imageUrl);
        image.setImageUrl(capturePath.replace(captureDir, "") + imageUrl);
        image.setCreateDate(captureDate);
        imageDao.insert(image);
        //存入rabbitmq消息队列,等待模型处理
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        ImageMessage imageMessage = new ImageMessage();
        imageMessage.setMessageId(image.getId());
        imageMessage.setCreateTime(createTime);
        imageMessage.setImageDTO(BeanUtils.toBean(image, ImageDTO.class));
        rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, ImageMessage.ROUTING_KEY, imageMessage);
//        rabbitTemplate.convertAndSend("topic.image", imageMap);
        sendRabbitMQMessage(image, routingKey);
    }
    @Override
    public void setStatus(String id, Integer status) {
        CameraEntity cameraEntity = new CameraEntity();
        cameraEntity.setId(id);
        cameraEntity.setStatus(status);
        baseDao.updateById(cameraEntity);
    }
    private QueryWrapper<CameraEntity> getWrapper(CameraPageReqVO cameraPageReqVO){
@@ -141,8 +159,8 @@
    @Override
    @DSTransactional(rollbackFor = Exception.class)
    public void delete(String[] ids) {
        baseDao.deleteBatchIds(Arrays.asList(ids));
    public void delete(String id) {
        baseDao.deleteById(id);
    }
    @Override
@@ -155,4 +173,14 @@
        return baseDao.selectCount(queryWrapper);
    }
    // 发送rabbitMQ消息
    private void sendRabbitMQMessage(ImageEntity image, String routingKey) {
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        ImageMessage imageMessage = new ImageMessage();
        imageMessage.setMessageId(image.getId());
        imageMessage.setCreateTime(createTime);
        imageMessage.setImageDTO(BeanUtils.toBean(image, ImageDTO.class));
        rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, routingKey, imageMessage);
    }
}