提交 | 用户 | 时间
|
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.video.controller.admin.nvr.vo.NvrPageReqVO; |
|
12 |
import com.iailab.module.data.video.controller.admin.nvr.vo.NvrSaveReqVO; |
|
13 |
import com.iailab.module.data.video.dahua.DHClientFactory; |
|
14 |
import com.iailab.module.data.video.dao.NvrDao; |
|
15 |
import com.iailab.module.data.video.dto.NvrDTO; |
|
16 |
import com.iailab.module.data.video.entity.NvrEntity; |
|
17 |
import com.iailab.module.data.video.service.NvrService; |
|
18 |
import org.apache.commons.lang3.StringUtils; |
|
19 |
import org.springframework.stereotype.Service; |
|
20 |
import org.springframework.transaction.annotation.Transactional; |
|
21 |
|
|
22 |
import javax.annotation.Resource; |
|
23 |
import java.util.Date; |
|
24 |
import java.util.List; |
|
25 |
import java.util.Map; |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* @author PanZhibao |
|
30 |
* @Description |
|
31 |
* @createTime 2024年03月07日 |
|
32 |
*/ |
|
33 |
@Service |
|
34 |
public class NvrServiceImpl extends BaseServiceImpl<NvrDao, NvrEntity> implements NvrService { |
|
35 |
|
|
36 |
@Resource |
|
37 |
private NvrDao nvrDao; |
|
38 |
|
|
39 |
@Resource |
|
40 |
private DHClientFactory dhClientFactory; |
|
41 |
|
|
42 |
@Override |
|
43 |
public PageResult<NvrDTO> getPage(NvrPageReqVO pageReqVO) { |
|
44 |
PageResult<NvrEntity> pageResult = nvrDao.selectPage(pageReqVO); |
|
45 |
// List<DevNvrEntity> list = pageResult.getList(); |
|
46 |
// dhClientFactory.getNvrOnlineStatus(list); |
|
47 |
return BeanUtils.toBean(pageResult, NvrDTO.class); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public List<NvrDTO> list(Map<String, Object> params) { |
|
52 |
QueryWrapper<NvrEntity> queryWrapper = getWrapper(params); |
|
53 |
queryWrapper.orderByDesc(Constant.CREATE_DATE); |
|
54 |
List<NvrEntity> list = baseDao.selectList(queryWrapper); |
|
55 |
return ConvertUtils.sourceToTarget(list, NvrDTO.class); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public NvrDTO get(String id) { |
|
60 |
NvrEntity entity = baseDao.selectById(id); |
|
61 |
|
|
62 |
return ConvertUtils.sourceToTarget(entity, NvrDTO.class); |
|
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
public NvrDTO getByIp(String ip) { |
|
67 |
QueryWrapper<NvrEntity> wrapper = new QueryWrapper<>(); |
|
68 |
wrapper.eq("ip", ip); |
|
69 |
NvrEntity entity = baseDao.selectOne(wrapper); |
|
70 |
|
|
71 |
return ConvertUtils.sourceToTarget(entity, NvrDTO.class); |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public NvrDTO getByCode(String code) { |
|
76 |
QueryWrapper<NvrEntity> wrapper = new QueryWrapper<>(); |
|
77 |
wrapper.eq("code", code); |
|
78 |
NvrEntity entity = baseDao.selectOne(wrapper); |
|
79 |
|
|
80 |
return ConvertUtils.sourceToTarget(entity, NvrDTO.class); |
|
81 |
} |
|
82 |
|
|
83 |
private QueryWrapper<NvrEntity> getWrapper(Map<String, Object> params) { |
|
84 |
String code = (String) params.get("code"); |
|
85 |
String location = (String) params.get("location"); |
|
86 |
String nvrId = (String) params.get("nvrId"); |
|
87 |
Integer status = params.get("status") == null ? null : Integer.parseInt(params.get("status").toString()); |
|
88 |
|
|
89 |
QueryWrapper<NvrEntity> wrapper = new QueryWrapper<>(); |
|
90 |
wrapper.like(StringUtils.isNotBlank(code), "code", code) |
|
91 |
.like(StringUtils.isNotBlank(location), "location", location) |
|
92 |
.eq(StringUtils.isNotBlank(nvrId), "nvr_id", nvrId) |
|
93 |
.eq(status != null, "status", status); |
|
94 |
|
|
95 |
return wrapper; |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public String save(NvrSaveReqVO saveReqVO) { |
|
100 |
NvrEntity entity = BeanUtils.toBean(saveReqVO, NvrEntity.class); |
|
101 |
entity.setCreateDate(new Date()); |
|
102 |
entity.setUpdater(WebFrameworkUtils.getLoginUserId()); |
|
103 |
insert(entity); |
|
104 |
return entity.getId(); |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public String update(NvrSaveReqVO saveReqVO) { |
|
109 |
NvrEntity entity = BeanUtils.toBean(saveReqVO, NvrEntity.class); |
|
110 |
entity.setUpdateDate(new Date()); |
|
111 |
entity.setUpdater(WebFrameworkUtils.getLoginUserId()); |
|
112 |
updateById(entity); |
|
113 |
return entity.getId(); |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
@DSTransactional(rollbackFor = Exception.class) |
08b6a5
|
118 |
public void delete(String id) { |
149dd0
|
119 |
nvrDao.deleteById(id); |
H |
120 |
} |
|
121 |
|
|
122 |
// @Override |
|
123 |
// public Long cheack(DevNvrDTO dto) { |
|
124 |
// Long id = dto.getId(); |
|
125 |
// String code = dto.getCode(); |
|
126 |
// String name = dto.getName(); |
|
127 |
// QueryWrapper<DevNvrEntity> queryWrapper = new QueryWrapper<>(); |
|
128 |
// queryWrapper.ne(StringUtils.isNotBlank(id.toString()), "id", id); |
|
129 |
// queryWrapper.and(wrapper -> wrapper.eq("code", code).or(). |
|
130 |
// eq(StringUtils.isNotBlank(name), "name", name)); |
|
131 |
// return baseDao.selectCount(queryWrapper); |
|
132 |
// } |
|
133 |
|
|
134 |
@Override |
|
135 |
public void setStatus(String ip, Integer status) { |
|
136 |
QueryWrapper<NvrEntity> wrapper = new QueryWrapper<>(); |
|
137 |
wrapper.eq("ip", ip); |
|
138 |
NvrEntity entity = new NvrEntity(); |
|
139 |
entity.setIp(ip); |
|
140 |
entity.setStatus(status); |
|
141 |
baseDao.update(entity, wrapper); |
|
142 |
} |
|
143 |
} |