提交 | 用户 | 时间
|
149dd0
|
1 |
package com.iailab.module.data.video.service.impl; |
H |
2 |
|
|
3 |
import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
|
4 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
5 |
import com.iailab.framework.common.constant.Constant; |
|
6 |
import com.iailab.framework.common.pojo.PageResult; |
|
7 |
import com.iailab.framework.common.service.impl.BaseServiceImpl; |
|
8 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
9 |
import com.iailab.framework.common.util.object.ConvertUtils; |
|
10 |
import com.iailab.framework.web.core.util.WebFrameworkUtils; |
|
11 |
import com.iailab.module.data.mq.consumer.ImageMessage; |
|
12 |
import com.iailab.module.data.video.controller.admin.camera.vo.CameraPageReqVO; |
21dc7e
|
13 |
import com.iailab.module.data.video.dahua.DHConfiguration; |
149dd0
|
14 |
import com.iailab.module.data.video.dahua.DHSavePath; |
H |
15 |
import com.iailab.module.data.video.dao.CameraDao; |
|
16 |
import com.iailab.module.data.video.dao.ImageDao; |
|
17 |
import com.iailab.module.data.video.dto.CameraDTO; |
|
18 |
import com.iailab.module.data.video.dto.ImageDTO; |
|
19 |
import com.iailab.module.data.video.entity.CameraEntity; |
|
20 |
import com.iailab.module.data.video.entity.ImageEntity; |
|
21 |
import com.iailab.module.data.video.service.CameraService; |
|
22 |
import org.apache.commons.lang3.StringUtils; |
|
23 |
import org.springframework.amqp.rabbit.core.RabbitTemplate; |
|
24 |
import org.springframework.stereotype.Service; |
|
25 |
|
|
26 |
import javax.annotation.Resource; |
|
27 |
import javax.validation.Valid; |
|
28 |
import java.time.LocalDateTime; |
|
29 |
import java.time.format.DateTimeFormatter; |
|
30 |
import java.util.*; |
|
31 |
|
|
32 |
/** |
|
33 |
* @author PanZhibao |
|
34 |
* @Description |
|
35 |
* @createTime 2024年02月27日 |
|
36 |
*/ |
|
37 |
@Service |
|
38 |
public class CameraServiceImpl extends BaseServiceImpl<CameraDao, CameraEntity> implements CameraService { |
|
39 |
|
|
40 |
@Resource |
|
41 |
private CameraDao cameraDao; |
|
42 |
|
|
43 |
@Resource |
|
44 |
private ImageDao imageDao; |
|
45 |
|
|
46 |
@Resource |
|
47 |
private RabbitTemplate rabbitTemplate; |
|
48 |
|
|
49 |
@Override |
|
50 |
public PageResult<CameraDTO> getPage(CameraPageReqVO cameraPageReqVO) { |
|
51 |
PageResult<CameraEntity> pageResult = cameraDao.selectPage(cameraPageReqVO); |
|
52 |
return BeanUtils.toBean(pageResult, CameraDTO.class); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public List<CameraDTO> list(@Valid CameraPageReqVO cameraPageReqVO) { |
|
57 |
QueryWrapper<CameraEntity> queryWrapper = getWrapper(cameraPageReqVO); |
|
58 |
queryWrapper.orderByDesc(Constant.CREATE_DATE); |
|
59 |
List<CameraEntity> list = baseDao.selectList(queryWrapper); |
|
60 |
return ConvertUtils.sourceToTarget(list, CameraDTO.class); |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public List<CameraDTO> apiCameraList(Map<String, Object> params) { |
|
65 |
return baseDao.apiCameraList(); |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public List<CameraDTO> getByNVRId(String nvrId) { |
|
70 |
QueryWrapper<CameraEntity> queryWrapper = new QueryWrapper<>(); |
|
71 |
queryWrapper.eq("nvr_id", nvrId).orderByAsc("channel"); |
|
72 |
List<CameraEntity> list = baseDao.selectList(queryWrapper); |
|
73 |
return ConvertUtils.sourceToTarget(list, CameraDTO.class); |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public CameraDTO get(String id) { |
|
78 |
CameraEntity entity = baseDao.selectById(id); |
|
79 |
|
|
80 |
return ConvertUtils.sourceToTarget(entity, CameraDTO.class); |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public CameraDTO getByCode(String code) { |
|
85 |
QueryWrapper<CameraEntity> wrapper = new QueryWrapper<>(); |
|
86 |
wrapper.eq("code", code); |
|
87 |
CameraEntity entity = baseDao.selectOne(wrapper); |
|
88 |
|
|
89 |
return ConvertUtils.sourceToTarget(entity, CameraDTO.class); |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
@DSTransactional(rollbackFor = Exception.class) |
|
94 |
public void dealCapture(Map<String, String> params) { |
|
95 |
Calendar calendar = Calendar.getInstance(); |
|
96 |
calendar.set(Calendar.MILLISECOND, 0); |
|
97 |
calendar.set(Calendar.SECOND, 0); |
|
98 |
Date captureDate = calendar.getTime(); |
|
99 |
CameraDTO devCamera = getByCode(params.get("cmdSerial")); |
|
100 |
String strFileName = params.get("strFileName"); |
|
101 |
String imagePath = strFileName.replace("\\", "/"); |
21dc7e
|
102 |
String imageUrl = imagePath.replace(DHConfiguration.staticCapturePath, ""); |
149dd0
|
103 |
ImageEntity image = new ImageEntity(); |
H |
104 |
image.setCameraId(devCamera.getId()); |
|
105 |
image.setImagePath(imagePath); |
|
106 |
image.setImageUrl("/Capture/" + imageUrl); |
|
107 |
image.setCreateDate(captureDate); |
|
108 |
imageDao.insert(image); |
|
109 |
//存入rabbitmq消息队列,等待模型处理 |
191b3d
|
110 |
sendRabbitMQMessage(image); |
149dd0
|
111 |
} |
H |
112 |
|
|
113 |
private QueryWrapper<CameraEntity> getWrapper(CameraPageReqVO cameraPageReqVO){ |
|
114 |
String location = cameraPageReqVO.getLocation(); |
|
115 |
QueryWrapper<CameraEntity> wrapper = new QueryWrapper<>(); |
|
116 |
wrapper.eq("type", cameraPageReqVO.getType()); |
|
117 |
wrapper.like(StringUtils.isNotBlank(location), "location", location); |
|
118 |
return wrapper; |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public void save(CameraDTO dto) { |
|
123 |
CameraEntity entity = ConvertUtils.sourceToTarget(dto, CameraEntity.class); |
|
124 |
entity.setCreateDate(new Date()); |
|
125 |
entity.setCreator(WebFrameworkUtils.getLoginUserId()); |
|
126 |
insert(entity); |
|
127 |
} |
|
128 |
|
|
129 |
@Override |
|
130 |
public void update(CameraDTO dto) { |
|
131 |
CameraEntity entity = ConvertUtils.sourceToTarget(dto, CameraEntity.class); |
|
132 |
entity.setUpdateDate(new Date()); |
|
133 |
entity.setUpdater(WebFrameworkUtils.getLoginUserId()); |
|
134 |
updateById(entity); |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
@DSTransactional(rollbackFor = Exception.class) |
|
139 |
public void delete(String[] ids) { |
|
140 |
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
141 |
} |
|
142 |
|
|
143 |
@Override |
|
144 |
public Long cheack(CameraDTO dto) { |
|
145 |
String id = dto.getId(); |
|
146 |
String code = dto.getCode(); |
|
147 |
QueryWrapper<CameraEntity> queryWrapper = new QueryWrapper<>(); |
|
148 |
queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); |
|
149 |
queryWrapper.and(wrapper -> wrapper.eq("code", code)); |
|
150 |
return baseDao.selectCount(queryWrapper); |
|
151 |
} |
|
152 |
|
191b3d
|
153 |
// 发送rabbitMQ消息 |
H |
154 |
private void sendRabbitMQMessage(ImageEntity image) { |
|
155 |
String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|
156 |
ImageMessage imageMessage = new ImageMessage(); |
|
157 |
imageMessage.setMessageId(image.getId()); |
|
158 |
imageMessage.setCreateTime(createTime); |
|
159 |
imageMessage.setImageDTO(BeanUtils.toBean(image, ImageDTO.class)); |
|
160 |
rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, ImageMessage.DAHUA_ROUTING_KEY, imageMessage); |
21dc7e
|
161 |
rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, ImageMessage.HIKVISION_ROUTING_KEY, imageMessage); |
191b3d
|
162 |
} |
H |
163 |
|
149dd0
|
164 |
} |