提交 | 用户 | 时间
|
ce910c
|
1 |
package com.iailab.module.data.dev.service.impl; |
H |
2 |
|
|
3 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
4 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
5 |
import com.iailab.framework.common.constant.Constant; |
|
6 |
import com.iailab.framework.common.page.PageData; |
|
7 |
import com.iailab.framework.common.pojo.PageResult; |
|
8 |
import com.iailab.framework.common.service.impl.BaseServiceImpl; |
|
9 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
10 |
import com.iailab.framework.common.util.object.ConvertUtils; |
1432cd
|
11 |
import com.iailab.framework.web.core.util.WebFrameworkUtils; |
ce910c
|
12 |
import com.iailab.module.data.dev.controller.admin.camera.vo.DevCameraPageReqVO; |
H |
13 |
import com.iailab.module.data.dev.dao.DevCameraDao; |
|
14 |
import com.iailab.module.data.dev.dto.DevCameraDTO; |
|
15 |
import com.iailab.module.data.dev.entity.DevCameraEntity; |
|
16 |
import com.iailab.module.data.dev.service.DevCameraService; |
|
17 |
import org.apache.commons.lang3.ObjectUtils; |
|
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 javax.validation.Valid; |
|
24 |
import java.util.*; |
|
25 |
|
|
26 |
/** |
|
27 |
* @author PanZhibao |
|
28 |
* @Description |
|
29 |
* @createTime 2024年02月27日 |
|
30 |
*/ |
|
31 |
@Service |
|
32 |
public class DevCameraServiceImpl extends BaseServiceImpl<DevCameraDao, DevCameraEntity> implements DevCameraService { |
|
33 |
|
|
34 |
@Resource |
|
35 |
private DevCameraDao devCameraDao; |
|
36 |
|
|
37 |
@Override |
|
38 |
public PageResult<DevCameraDTO> getPage(DevCameraPageReqVO cameraPageReqVO) { |
|
39 |
PageResult<DevCameraEntity> pageResult = devCameraDao.selectPage(cameraPageReqVO); |
|
40 |
return BeanUtils.toBean(pageResult, DevCameraDTO.class); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public List<DevCameraDTO> list(@Valid DevCameraPageReqVO cameraPageReqVO) { |
|
45 |
QueryWrapper<DevCameraEntity> queryWrapper = getWrapper(cameraPageReqVO); |
|
46 |
queryWrapper.orderByDesc(Constant.CREATE_DATE); |
|
47 |
List<DevCameraEntity> list = baseDao.selectList(queryWrapper); |
|
48 |
return ConvertUtils.sourceToTarget(list, DevCameraDTO.class); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public List<DevCameraDTO> apiCameraList(Map<String, Object> params) { |
|
53 |
return baseDao.apiCameraList(); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public List<DevCameraDTO> getByNVRId(String nvrId) { |
|
58 |
QueryWrapper<DevCameraEntity> queryWrapper = new QueryWrapper<>(); |
|
59 |
queryWrapper.eq("nvr_id", nvrId).orderByAsc("channel"); |
|
60 |
List<DevCameraEntity> list = baseDao.selectList(queryWrapper); |
|
61 |
return ConvertUtils.sourceToTarget(list, DevCameraDTO.class); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public DevCameraDTO get(String id) { |
|
66 |
DevCameraEntity entity = baseDao.selectById(id); |
|
67 |
|
|
68 |
return ConvertUtils.sourceToTarget(entity, DevCameraDTO.class); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public DevCameraDTO getByCode(Integer code) { |
|
73 |
QueryWrapper<DevCameraEntity> wrapper = new QueryWrapper<>(); |
|
74 |
wrapper.eq("code", code); |
|
75 |
DevCameraEntity entity = baseDao.selectOne(wrapper); |
|
76 |
|
|
77 |
return ConvertUtils.sourceToTarget(entity, DevCameraDTO.class); |
|
78 |
} |
|
79 |
|
|
80 |
private QueryWrapper<DevCameraEntity> getWrapper(DevCameraPageReqVO cameraPageReqVO){ |
|
81 |
String location = cameraPageReqVO.getLocation(); |
|
82 |
QueryWrapper<DevCameraEntity> wrapper = new QueryWrapper<>(); |
|
83 |
wrapper.like(StringUtils.isNotBlank(location), "location", location); |
|
84 |
return wrapper; |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public void save(DevCameraDTO dto) { |
|
89 |
DevCameraEntity entity = ConvertUtils.sourceToTarget(dto, DevCameraEntity.class); |
|
90 |
entity.setCreateDate(new Date()); |
1432cd
|
91 |
entity.setCreator(WebFrameworkUtils.getLoginUserId()); |
ce910c
|
92 |
insert(entity); |
H |
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
public void update(DevCameraDTO dto) { |
|
97 |
DevCameraEntity entity = ConvertUtils.sourceToTarget(dto, DevCameraEntity.class); |
|
98 |
entity.setUpdateDate(new Date()); |
1432cd
|
99 |
entity.setUpdater(WebFrameworkUtils.getLoginUserId()); |
ce910c
|
100 |
updateById(entity); |
H |
101 |
} |
|
102 |
|
|
103 |
@Override |
|
104 |
@Transactional(rollbackFor = Exception.class) |
|
105 |
public void delete(String[] ids) { |
|
106 |
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public Long cheack(DevCameraDTO dto) { |
|
111 |
String id = dto.getId(); |
|
112 |
Integer code = dto.getCode(); |
|
113 |
QueryWrapper<DevCameraEntity> queryWrapper = new QueryWrapper<>(); |
|
114 |
queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); |
|
115 |
queryWrapper.and(wrapper -> wrapper.eq("code", code)); |
|
116 |
return baseDao.selectCount(queryWrapper); |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public List<String> getLocation() { |
|
121 |
QueryWrapper<DevCameraEntity> wrapper = new QueryWrapper<>(); |
|
122 |
List<DevCameraEntity> devCameraEntities = baseDao.selectList(wrapper); |
|
123 |
List<String> locations = new ArrayList<>(); |
|
124 |
if(ObjectUtils.isNotEmpty(devCameraEntities)) { |
|
125 |
devCameraEntities.stream().forEach(cameraEntity -> { |
|
126 |
locations.add(cameraEntity.getLocation()); |
|
127 |
}); |
|
128 |
} |
|
129 |
return locations; |
|
130 |
} |
|
131 |
|
|
132 |
} |