提交 | 用户 | 时间
|
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; |
08b6a5
|
13 |
import com.iailab.module.data.video.config.VideoConfiguration; |
149dd0
|
14 |
import com.iailab.module.data.video.dao.CameraDao; |
H |
15 |
import com.iailab.module.data.video.dao.ImageDao; |
|
16 |
import com.iailab.module.data.video.dto.CameraDTO; |
|
17 |
import com.iailab.module.data.video.dto.ImageDTO; |
|
18 |
import com.iailab.module.data.video.entity.CameraEntity; |
|
19 |
import com.iailab.module.data.video.entity.ImageEntity; |
|
20 |
import com.iailab.module.data.video.service.CameraService; |
|
21 |
import org.apache.commons.lang3.StringUtils; |
|
22 |
import org.springframework.amqp.rabbit.core.RabbitTemplate; |
08b6a5
|
23 |
import org.springframework.beans.factory.annotation.Value; |
149dd0
|
24 |
import org.springframework.stereotype.Service; |
H |
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 { |
08b6a5
|
39 |
|
H |
40 |
@Value("${video.capture-dir}") |
|
41 |
public String captureDir; |
149dd0
|
42 |
|
H |
43 |
@Resource |
|
44 |
private CameraDao cameraDao; |
|
45 |
|
|
46 |
@Resource |
|
47 |
private ImageDao imageDao; |
|
48 |
|
|
49 |
@Resource |
|
50 |
private RabbitTemplate rabbitTemplate; |
|
51 |
|
|
52 |
@Override |
|
53 |
public PageResult<CameraDTO> getPage(CameraPageReqVO cameraPageReqVO) { |
|
54 |
PageResult<CameraEntity> pageResult = cameraDao.selectPage(cameraPageReqVO); |
|
55 |
return BeanUtils.toBean(pageResult, CameraDTO.class); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public List<CameraDTO> list(@Valid CameraPageReqVO cameraPageReqVO) { |
|
60 |
QueryWrapper<CameraEntity> queryWrapper = getWrapper(cameraPageReqVO); |
|
61 |
queryWrapper.orderByDesc(Constant.CREATE_DATE); |
|
62 |
List<CameraEntity> list = baseDao.selectList(queryWrapper); |
|
63 |
return ConvertUtils.sourceToTarget(list, CameraDTO.class); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public List<CameraDTO> apiCameraList(Map<String, Object> params) { |
|
68 |
return baseDao.apiCameraList(); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public List<CameraDTO> getByNVRId(String nvrId) { |
|
73 |
QueryWrapper<CameraEntity> queryWrapper = new QueryWrapper<>(); |
|
74 |
queryWrapper.eq("nvr_id", nvrId).orderByAsc("channel"); |
|
75 |
List<CameraEntity> list = baseDao.selectList(queryWrapper); |
|
76 |
return ConvertUtils.sourceToTarget(list, CameraDTO.class); |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public CameraDTO get(String id) { |
|
81 |
CameraEntity entity = baseDao.selectById(id); |
|
82 |
|
|
83 |
return ConvertUtils.sourceToTarget(entity, CameraDTO.class); |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public CameraDTO getByCode(String code) { |
|
88 |
QueryWrapper<CameraEntity> wrapper = new QueryWrapper<>(); |
|
89 |
wrapper.eq("code", code); |
|
90 |
CameraEntity entity = baseDao.selectOne(wrapper); |
|
91 |
|
|
92 |
return ConvertUtils.sourceToTarget(entity, CameraDTO.class); |
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
@DSTransactional(rollbackFor = Exception.class) |
|
97 |
public void dealCapture(Map<String, String> params) { |
|
98 |
Calendar calendar = Calendar.getInstance(); |
|
99 |
calendar.set(Calendar.MILLISECOND, 0); |
|
100 |
Date captureDate = calendar.getTime(); |
|
101 |
CameraDTO devCamera = getByCode(params.get("cmdSerial")); |
|
102 |
String strFileName = params.get("strFileName"); |
08b6a5
|
103 |
String brand = params.get("brand"); |
H |
104 |
String capturePath = ""; |
|
105 |
String routingKey = ""; |
|
106 |
switch (brand) { |
|
107 |
case "DH": |
|
108 |
capturePath = VideoConfiguration.staticDhCapturePath; |
|
109 |
routingKey = ImageMessage.DAHUA_ROUTING_KEY; |
|
110 |
break; |
|
111 |
case "HK": |
|
112 |
capturePath = VideoConfiguration.staticHkCapturePath; |
|
113 |
routingKey = ImageMessage.HIKVISION_ROUTING_KEY; |
|
114 |
break; |
|
115 |
} |
149dd0
|
116 |
String imagePath = strFileName.replace("\\", "/"); |
08b6a5
|
117 |
String imageUrl = imagePath.replace(capturePath, ""); |
149dd0
|
118 |
ImageEntity image = new ImageEntity(); |
H |
119 |
image.setCameraId(devCamera.getId()); |
|
120 |
image.setImagePath(imagePath); |
08b6a5
|
121 |
image.setImageUrl(capturePath.replace(captureDir, "") + imageUrl); |
149dd0
|
122 |
image.setCreateDate(captureDate); |
H |
123 |
imageDao.insert(image); |
|
124 |
//存入rabbitmq消息队列,等待模型处理 |
08b6a5
|
125 |
sendRabbitMQMessage(image, routingKey); |
H |
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public void setStatus(String id, Integer status) { |
|
130 |
CameraEntity cameraEntity = new CameraEntity(); |
|
131 |
cameraEntity.setId(id); |
|
132 |
cameraEntity.setStatus(status); |
|
133 |
baseDao.updateById(cameraEntity); |
149dd0
|
134 |
} |
H |
135 |
|
|
136 |
private QueryWrapper<CameraEntity> getWrapper(CameraPageReqVO cameraPageReqVO){ |
|
137 |
String location = cameraPageReqVO.getLocation(); |
|
138 |
QueryWrapper<CameraEntity> wrapper = new QueryWrapper<>(); |
|
139 |
wrapper.eq("type", cameraPageReqVO.getType()); |
|
140 |
wrapper.like(StringUtils.isNotBlank(location), "location", location); |
|
141 |
return wrapper; |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public void save(CameraDTO dto) { |
|
146 |
CameraEntity entity = ConvertUtils.sourceToTarget(dto, CameraEntity.class); |
|
147 |
entity.setCreateDate(new Date()); |
|
148 |
entity.setCreator(WebFrameworkUtils.getLoginUserId()); |
|
149 |
insert(entity); |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public void update(CameraDTO dto) { |
|
154 |
CameraEntity entity = ConvertUtils.sourceToTarget(dto, CameraEntity.class); |
|
155 |
entity.setUpdateDate(new Date()); |
|
156 |
entity.setUpdater(WebFrameworkUtils.getLoginUserId()); |
|
157 |
updateById(entity); |
|
158 |
} |
|
159 |
|
|
160 |
@Override |
|
161 |
@DSTransactional(rollbackFor = Exception.class) |
08b6a5
|
162 |
public void delete(String id) { |
H |
163 |
baseDao.deleteById(id); |
149dd0
|
164 |
} |
H |
165 |
|
|
166 |
@Override |
|
167 |
public Long cheack(CameraDTO dto) { |
|
168 |
String id = dto.getId(); |
|
169 |
String code = dto.getCode(); |
|
170 |
QueryWrapper<CameraEntity> queryWrapper = new QueryWrapper<>(); |
|
171 |
queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); |
|
172 |
queryWrapper.and(wrapper -> wrapper.eq("code", code)); |
|
173 |
return baseDao.selectCount(queryWrapper); |
|
174 |
} |
|
175 |
|
191b3d
|
176 |
// 发送rabbitMQ消息 |
08b6a5
|
177 |
private void sendRabbitMQMessage(ImageEntity image, String routingKey) { |
191b3d
|
178 |
String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
H |
179 |
ImageMessage imageMessage = new ImageMessage(); |
|
180 |
imageMessage.setMessageId(image.getId()); |
|
181 |
imageMessage.setCreateTime(createTime); |
|
182 |
imageMessage.setImageDTO(BeanUtils.toBean(image, ImageDTO.class)); |
08b6a5
|
183 |
rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, routingKey, imageMessage); |
191b3d
|
184 |
} |
H |
185 |
|
149dd0
|
186 |
} |