提交 | 用户 | 时间
|
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.service.impl.BaseServiceImpl; |
|
8 |
import com.iailab.framework.common.util.object.ConvertUtils; |
|
9 |
import com.iailab.module.data.dev.dao.DevImageDao; |
|
10 |
import com.iailab.module.data.dev.dto.DevImageDTO; |
|
11 |
import com.iailab.module.data.dev.entity.DataEntity; |
|
12 |
import com.iailab.module.data.dev.entity.DevImageEntity; |
|
13 |
import com.iailab.module.data.dev.service.DevImageService; |
|
14 |
import org.apache.commons.lang3.ObjectUtils; |
|
15 |
import org.apache.commons.lang3.StringUtils; |
|
16 |
import org.springframework.stereotype.Service; |
|
17 |
import org.springframework.transaction.annotation.Transactional; |
|
18 |
import org.springframework.util.CollectionUtils; |
|
19 |
|
|
20 |
import java.util.*; |
|
21 |
|
|
22 |
/** |
|
23 |
* @author PanZhibao |
|
24 |
* @Description |
|
25 |
* @createTime 2024年02月27日 |
|
26 |
*/ |
|
27 |
@Service |
|
28 |
public class DevImageServiceImpl extends BaseServiceImpl<DevImageDao, DevImageEntity> implements DevImageService { |
|
29 |
|
|
30 |
@Override |
|
31 |
public PageData<DevImageDTO> page(Map<String, Object> params) { |
|
32 |
IPage<DevImageEntity> page = baseDao.selectPage( |
|
33 |
getPage(params, Constant.CREATE_DATE, false), |
|
34 |
getWrapper(params) |
|
35 |
); |
|
36 |
return getPageData(page, DevImageDTO.class); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public DevImageDTO get(String id) { |
|
41 |
DevImageEntity entity = baseDao.selectById(id); |
|
42 |
|
|
43 |
return ConvertUtils.sourceToTarget(entity, DevImageDTO.class); |
|
44 |
} |
|
45 |
|
|
46 |
private QueryWrapper<DevImageEntity> getWrapper(Map<String, Object> params){ |
|
47 |
String cameraId = (String)params.get("cameraId"); |
|
48 |
String startTime = (String)params.get("startTime"); |
|
49 |
String endTime = (String)params.get("endTime"); |
|
50 |
|
|
51 |
QueryWrapper<DevImageEntity> wrapper = new QueryWrapper<>(); |
|
52 |
wrapper.eq(StringUtils.isNotBlank(cameraId), "camera_id", cameraId) |
|
53 |
.ge(StringUtils.isNotBlank(startTime), "create_date", startTime) |
|
54 |
.le(StringUtils.isNotBlank(endTime), "create_date", endTime); |
|
55 |
|
|
56 |
return wrapper; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public List<DataEntity> getValueList(String cameraId, Date startTime, Date endTime) { |
|
61 |
QueryWrapper<DevImageEntity> wrapper = new QueryWrapper<>(); |
|
62 |
wrapper.eq( "camera_id", cameraId) |
|
63 |
.ge( "create_date", startTime) |
|
64 |
.le( "create_date", endTime) |
|
65 |
.orderByAsc("create_date"); |
|
66 |
List<DataEntity> result = new ArrayList<>(); |
|
67 |
List<DevImageEntity> list = baseDao.selectList(wrapper); |
|
68 |
if (CollectionUtils.isEmpty(list)) { |
|
69 |
return result; |
|
70 |
} |
|
71 |
list.forEach(item -> { |
|
72 |
DataEntity dataEntity = new DataEntity(); |
|
73 |
dataEntity.setDataValue(item.getImagePath()); |
|
74 |
dataEntity.setTimeStamp(item.getCreateDate()); |
|
75 |
result.add(dataEntity); |
|
76 |
}); |
|
77 |
return result; |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public String getUrl(String cameraId, String imagePath) { |
|
82 |
String result = ""; |
|
83 |
QueryWrapper<DevImageEntity> wrapper = new QueryWrapper<>(); |
|
84 |
wrapper.eq( "camera_id", cameraId) |
|
85 |
.eq( "image_path", imagePath) |
|
86 |
.orderByDesc("create_date"); |
|
87 |
List<DevImageEntity> devImageEntities = baseDao.selectList(wrapper); |
|
88 |
DevImageEntity entity = new DevImageEntity(); |
|
89 |
if (ObjectUtils.isNotEmpty(devImageEntities)) { |
|
90 |
entity = devImageEntities.get(0); |
|
91 |
} |
|
92 |
if (entity != null) { |
|
93 |
return entity.getImageUrl(); |
|
94 |
} |
|
95 |
return result; |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public void save(DevImageDTO dto) { |
|
100 |
DevImageEntity entity = ConvertUtils.sourceToTarget(dto, DevImageEntity.class); |
|
101 |
|
|
102 |
//保存菜单 |
|
103 |
insert(entity); |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public void update(DevImageDTO dto) { |
|
108 |
DevImageEntity entity = ConvertUtils.sourceToTarget(dto, DevImageEntity.class); |
|
109 |
|
|
110 |
//更新菜单 |
|
111 |
updateById(entity); |
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
@Transactional(rollbackFor = Exception.class) |
|
116 |
public void delete(String[] ids) { |
|
117 |
//删除菜单 |
|
118 |
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public DevImageDTO get(String cameraId, Date createDate) { |
|
123 |
QueryWrapper<DevImageEntity> wrapper = new QueryWrapper<>(); |
|
124 |
wrapper.eq( "camera_id", cameraId) |
|
125 |
.eq( "create_date", createDate); |
|
126 |
DevImageEntity entity = new DevImageEntity(); |
|
127 |
List<DevImageEntity> devImageEntities = baseDao.selectList(wrapper); |
|
128 |
if (ObjectUtils.isNotEmpty(devImageEntities)) { |
|
129 |
entity = devImageEntities.get(0); |
|
130 |
} |
|
131 |
return ConvertUtils.sourceToTarget(entity, DevImageDTO.class); |
|
132 |
} |
|
133 |
|
|
134 |
} |