Commit ff3e0f705d809ca2bfd466a9ba0c133216303200
1 parent
c848b7d5
fix: [DEFECT-817] add device script query params name and creatTime
Showing
2 changed files
with
39 additions
and
15 deletions
@@ -44,6 +44,7 @@ import org.thingsboard.server.controller.BaseController; | @@ -44,6 +44,7 @@ import org.thingsboard.server.controller.BaseController; | ||
44 | import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService; | 44 | import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService; |
45 | import org.thingsboard.server.dao.yunteng.service.TkDeviceScriptService; | 45 | import org.thingsboard.server.dao.yunteng.service.TkDeviceScriptService; |
46 | 46 | ||
47 | +import java.sql.Timestamp; | ||
47 | import java.time.LocalDateTime; | 48 | import java.time.LocalDateTime; |
48 | import java.time.ZoneOffset; | 49 | import java.time.ZoneOffset; |
49 | import java.util.*; | 50 | import java.util.*; |
@@ -156,7 +157,10 @@ public class TkDeviceScriptController extends BaseController { | @@ -156,7 +157,10 @@ public class TkDeviceScriptController extends BaseController { | ||
156 | @RequestParam(PAGE_SIZE) int pageSize, | 157 | @RequestParam(PAGE_SIZE) int pageSize, |
157 | @RequestParam(PAGE) int page, | 158 | @RequestParam(PAGE) int page, |
158 | @RequestParam(value = ORDER_FILED, required = false) String orderFiled, | 159 | @RequestParam(value = ORDER_FILED, required = false) String orderFiled, |
159 | - @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | 160 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType, |
161 | + @RequestParam(value = "name", required = false) String name, | ||
162 | + @RequestParam(value = "startTime", required = false) Long startTime, | ||
163 | + @RequestParam(value = "endTime", required = false) Long endTime) | ||
160 | throws ThingsboardException { | 164 | throws ThingsboardException { |
161 | Map<String, Object> queryMap = new HashMap<>(); | 165 | Map<String, Object> queryMap = new HashMap<>(); |
162 | queryMap.put(PAGE_SIZE, pageSize); | 166 | queryMap.put(PAGE_SIZE, pageSize); |
@@ -165,6 +169,19 @@ public class TkDeviceScriptController extends BaseController { | @@ -165,6 +169,19 @@ public class TkDeviceScriptController extends BaseController { | ||
165 | queryMap.put(ORDER_TYPE, orderType); | 169 | queryMap.put(ORDER_TYPE, orderType); |
166 | queryMap.put(CUSTOMER_ID, getCurrentUser().getCustomerId().toString()); | 170 | queryMap.put(CUSTOMER_ID, getCurrentUser().getCustomerId().toString()); |
167 | queryMap.put(TENANT_ID, getCurrentUser().getCurrentTenantId()); | 171 | queryMap.put(TENANT_ID, getCurrentUser().getCurrentTenantId()); |
172 | + | ||
173 | + if(!StringUtils.isEmpty(name)){ | ||
174 | + queryMap.put("name", name); | ||
175 | + } | ||
176 | + if(null != startTime && null!=endTime){ | ||
177 | + if (startTime > endTime) { | ||
178 | + throw new YtDataValidationException( | ||
179 | + ErrorMessage.START_TIME_NOT_MORE_THAN_END_TIME.getMessage()); | ||
180 | + } | ||
181 | + queryMap.put("startTime", new Timestamp(startTime).toLocalDateTime()); | ||
182 | + queryMap.put("endTime", new Timestamp(endTime).toLocalDateTime()); | ||
183 | + } | ||
184 | + | ||
168 | return scriptService.page(queryMap, getCurrentUser().isTenantAdmin()); | 185 | return scriptService.page(queryMap, getCurrentUser().isTenantAdmin()); |
169 | } | 186 | } |
170 | 187 |
@@ -24,6 +24,7 @@ import org.thingsboard.server.dao.yunteng.mapper.TkDeviceProfileMapper; | @@ -24,6 +24,7 @@ import org.thingsboard.server.dao.yunteng.mapper.TkDeviceProfileMapper; | ||
24 | import org.thingsboard.server.dao.yunteng.mapper.TkDeviceScriptMapper; | 24 | import org.thingsboard.server.dao.yunteng.mapper.TkDeviceScriptMapper; |
25 | import org.thingsboard.server.dao.yunteng.service.*; | 25 | import org.thingsboard.server.dao.yunteng.service.*; |
26 | 26 | ||
27 | +import java.time.LocalDateTime; | ||
27 | import java.util.*; | 28 | import java.util.*; |
28 | import java.util.stream.Collectors; | 29 | import java.util.stream.Collectors; |
29 | 30 | ||
@@ -125,7 +126,7 @@ public class TkDeviceScriptServiceImpl | @@ -125,7 +126,7 @@ public class TkDeviceScriptServiceImpl | ||
125 | .lambda() | 126 | .lambda() |
126 | .in(TkDeviceProfileEntity::getScriptId, ids)); | 127 | .in(TkDeviceProfileEntity::getScriptId, ids)); |
127 | if (usedList != null && usedList.size() > 0) { | 128 | if (usedList != null && usedList.size() > 0) { |
128 | - List<String> names = usedList.stream().map(i -> i.getName()).collect(Collectors.toList()); | 129 | + List<String> names = usedList.stream().map(TkDeviceProfileEntity::getName).collect(Collectors.toList()); |
129 | throw new YtDataValidationException( | 130 | throw new YtDataValidationException( |
130 | String.format(ErrorMessage.PROJECT_USED_SCRIPT.getMessage(), names)); | 131 | String.format(ErrorMessage.PROJECT_USED_SCRIPT.getMessage(), names)); |
131 | } | 132 | } |
@@ -186,10 +187,7 @@ public class TkDeviceScriptServiceImpl | @@ -186,10 +187,7 @@ public class TkDeviceScriptServiceImpl | ||
186 | TkDeviceScriptEntity profile = baseMapper.selectOne(queryWrapper); | 187 | TkDeviceScriptEntity profile = baseMapper.selectOne(queryWrapper); |
187 | return Optional.ofNullable(profile) | 188 | return Optional.ofNullable(profile) |
188 | .map( | 189 | .map( |
189 | - entity -> { | ||
190 | - TkDeviceScriptDTO result = entity.getDTO(TkDeviceScriptDTO.class); | ||
191 | - return result; | ||
192 | - }); | 190 | + entity -> entity.getDTO(TkDeviceScriptDTO.class)); |
193 | } | 191 | } |
194 | 192 | ||
195 | @Override | 193 | @Override |
@@ -205,6 +203,11 @@ public class TkDeviceScriptServiceImpl | @@ -205,6 +203,11 @@ public class TkDeviceScriptServiceImpl | ||
205 | Optional.ofNullable(queryMap.get(QueryConstant.CUSTOMER_ID)) | 203 | Optional.ofNullable(queryMap.get(QueryConstant.CUSTOMER_ID)) |
206 | .map(Object::toString) | 204 | .map(Object::toString) |
207 | .orElse(null); | 205 | .orElse(null); |
206 | + String name = Optional.ofNullable(queryMap.get("name")).map(Object::toString).orElse(null); | ||
207 | + LocalDateTime startTime = | ||
208 | + (LocalDateTime) Optional.ofNullable(queryMap.get("startTime")).orElse(null); | ||
209 | + LocalDateTime endTime = | ||
210 | + (LocalDateTime) Optional.ofNullable(queryMap.get("endTime")).orElse(null); | ||
208 | Set<String> scriptIds = null; | 211 | Set<String> scriptIds = null; |
209 | if (!isTenantAdmin && StringUtils.isNotEmpty(customerId)) { | 212 | if (!isTenantAdmin && StringUtils.isNotEmpty(customerId)) { |
210 | scriptIds = getCustomerScripts(customerId, tenantId); | 213 | scriptIds = getCustomerScripts(customerId, tenantId); |
@@ -216,6 +219,12 @@ public class TkDeviceScriptServiceImpl | @@ -216,6 +219,12 @@ public class TkDeviceScriptServiceImpl | ||
216 | new QueryWrapper<TkDeviceScriptEntity>() | 219 | new QueryWrapper<TkDeviceScriptEntity>() |
217 | .lambda() | 220 | .lambda() |
218 | .eq(TkDeviceScriptEntity::getTenantId, tenantId) | 221 | .eq(TkDeviceScriptEntity::getTenantId, tenantId) |
222 | + .like(StringUtils.isNotEmpty(name), TkDeviceScriptEntity::getName, name) | ||
223 | + .and( | ||
224 | + null != startTime && null != endTime, | ||
225 | + qr -> | ||
226 | + qr.ge(TkDeviceScriptEntity::getCreateTime, startTime) | ||
227 | + .le(TkDeviceScriptEntity::getCreateTime, endTime)) | ||
219 | .in(!isTenantAdmin, TkDeviceScriptEntity::getId, scriptIds); | 228 | .in(!isTenantAdmin, TkDeviceScriptEntity::getId, scriptIds); |
220 | 229 | ||
221 | IPage<TkDeviceScriptEntity> scripts = baseMapper.selectPage(currentPage, queryWrapper); | 230 | IPage<TkDeviceScriptEntity> scripts = baseMapper.selectPage(currentPage, queryWrapper); |
@@ -232,11 +241,9 @@ public class TkDeviceScriptServiceImpl | @@ -232,11 +241,9 @@ public class TkDeviceScriptServiceImpl | ||
232 | new QueryWrapper<TkDeviceScriptEntity>() | 241 | new QueryWrapper<TkDeviceScriptEntity>() |
233 | .lambda() | 242 | .lambda() |
234 | .eq(TkDeviceScriptEntity::getTenantId, tenantId); | 243 | .eq(TkDeviceScriptEntity::getTenantId, tenantId); |
235 | - List<TkDeviceScriptDTO> results = | ||
236 | - baseMapper.selectList(queryWrapper).stream() | ||
237 | - .map(item -> item.getDTO(TkDeviceScriptDTO.class)) | ||
238 | - .collect(Collectors.toList()); | ||
239 | - return results; | 244 | + return baseMapper.selectList(queryWrapper).stream() |
245 | + .map(item -> item.getDTO(TkDeviceScriptDTO.class)) | ||
246 | + .collect(Collectors.toList()); | ||
240 | } | 247 | } |
241 | 248 | ||
242 | private Set<String> getCustomerScripts(String customerId, String tenantId) { | 249 | private Set<String> getCustomerScripts(String customerId, String tenantId) { |
@@ -244,9 +251,9 @@ public class TkDeviceScriptServiceImpl | @@ -244,9 +251,9 @@ public class TkDeviceScriptServiceImpl | ||
244 | List<TkCustomerDeviceDTO> list = tkCustomerDevice.getMappingByCustomerId(customerId); | 251 | List<TkCustomerDeviceDTO> list = tkCustomerDevice.getMappingByCustomerId(customerId); |
245 | if (null != list && !list.isEmpty()) { | 252 | if (null != list && !list.isEmpty()) { |
246 | Set<String> deviceIds = | 253 | Set<String> deviceIds = |
247 | - list.stream().map(obj -> obj.getDeviceId()).collect(Collectors.toSet()); | 254 | + list.stream().map(TkCustomerDeviceDTO::getDeviceId).collect(Collectors.toSet()); |
248 | scriptIds = | 255 | scriptIds = |
249 | - Optional.ofNullable(deviceIds) | 256 | + Optional.of(deviceIds) |
250 | .map( | 257 | .map( |
251 | ids -> { | 258 | ids -> { |
252 | List<DeviceDTO> deviceDTOS = | 259 | List<DeviceDTO> deviceDTOS = |
@@ -254,7 +261,7 @@ public class TkDeviceScriptServiceImpl | @@ -254,7 +261,7 @@ public class TkDeviceScriptServiceImpl | ||
254 | if (null != deviceDTOS && !deviceDTOS.isEmpty()) { | 261 | if (null != deviceDTOS && !deviceDTOS.isEmpty()) { |
255 | List<String> deviceProfiles = | 262 | List<String> deviceProfiles = |
256 | deviceDTOS.stream() | 263 | deviceDTOS.stream() |
257 | - .map(obj -> obj.getDeviceProfileId()) | 264 | + .map(DeviceDTO::getDeviceProfileId) |
258 | .collect(Collectors.toList()); | 265 | .collect(Collectors.toList()); |
259 | List<DeviceProfileDTO> deviceProfileDTOList = | 266 | List<DeviceProfileDTO> deviceProfileDTOList = |
260 | tkDeviceProfileService.findDeviceProfileByIds(tenantId, deviceProfiles); | 267 | tkDeviceProfileService.findDeviceProfileByIds(tenantId, deviceProfiles); |
@@ -262,7 +269,7 @@ public class TkDeviceScriptServiceImpl | @@ -262,7 +269,7 @@ public class TkDeviceScriptServiceImpl | ||
262 | .map( | 269 | .map( |
263 | deviceProfileDTOS -> | 270 | deviceProfileDTOS -> |
264 | deviceProfileDTOS.stream() | 271 | deviceProfileDTOS.stream() |
265 | - .map(obj -> obj.getScriptId()) | 272 | + .map(DeviceProfileDTO::getScriptId) |
266 | .collect(Collectors.toSet())) | 273 | .collect(Collectors.toSet())) |
267 | .orElse(null); | 274 | .orElse(null); |
268 | } | 275 | } |