Commit ff3e0f705d809ca2bfd466a9ba0c133216303200

Authored by 黄 x
1 parent c848b7d5

fix: [DEFECT-817] add device script query params name and creatTime

... ... @@ -44,6 +44,7 @@ import org.thingsboard.server.controller.BaseController;
44 44 import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService;
45 45 import org.thingsboard.server.dao.yunteng.service.TkDeviceScriptService;
46 46
  47 +import java.sql.Timestamp;
47 48 import java.time.LocalDateTime;
48 49 import java.time.ZoneOffset;
49 50 import java.util.*;
... ... @@ -156,7 +157,10 @@ public class TkDeviceScriptController extends BaseController {
156 157 @RequestParam(PAGE_SIZE) int pageSize,
157 158 @RequestParam(PAGE) int page,
158 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 164 throws ThingsboardException {
161 165 Map<String, Object> queryMap = new HashMap<>();
162 166 queryMap.put(PAGE_SIZE, pageSize);
... ... @@ -165,6 +169,19 @@ public class TkDeviceScriptController extends BaseController {
165 169 queryMap.put(ORDER_TYPE, orderType);
166 170 queryMap.put(CUSTOMER_ID, getCurrentUser().getCustomerId().toString());
167 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 185 return scriptService.page(queryMap, getCurrentUser().isTenantAdmin());
169 186 }
170 187
... ...
... ... @@ -24,6 +24,7 @@ import org.thingsboard.server.dao.yunteng.mapper.TkDeviceProfileMapper;
24 24 import org.thingsboard.server.dao.yunteng.mapper.TkDeviceScriptMapper;
25 25 import org.thingsboard.server.dao.yunteng.service.*;
26 26
  27 +import java.time.LocalDateTime;
27 28 import java.util.*;
28 29 import java.util.stream.Collectors;
29 30
... ... @@ -125,7 +126,7 @@ public class TkDeviceScriptServiceImpl
125 126 .lambda()
126 127 .in(TkDeviceProfileEntity::getScriptId, ids));
127 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 130 throw new YtDataValidationException(
130 131 String.format(ErrorMessage.PROJECT_USED_SCRIPT.getMessage(), names));
131 132 }
... ... @@ -186,10 +187,7 @@ public class TkDeviceScriptServiceImpl
186 187 TkDeviceScriptEntity profile = baseMapper.selectOne(queryWrapper);
187 188 return Optional.ofNullable(profile)
188 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 193 @Override
... ... @@ -205,6 +203,11 @@ public class TkDeviceScriptServiceImpl
205 203 Optional.ofNullable(queryMap.get(QueryConstant.CUSTOMER_ID))
206 204 .map(Object::toString)
207 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 211 Set<String> scriptIds = null;
209 212 if (!isTenantAdmin && StringUtils.isNotEmpty(customerId)) {
210 213 scriptIds = getCustomerScripts(customerId, tenantId);
... ... @@ -216,6 +219,12 @@ public class TkDeviceScriptServiceImpl
216 219 new QueryWrapper<TkDeviceScriptEntity>()
217 220 .lambda()
218 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 228 .in(!isTenantAdmin, TkDeviceScriptEntity::getId, scriptIds);
220 229
221 230 IPage<TkDeviceScriptEntity> scripts = baseMapper.selectPage(currentPage, queryWrapper);
... ... @@ -232,11 +241,9 @@ public class TkDeviceScriptServiceImpl
232 241 new QueryWrapper<TkDeviceScriptEntity>()
233 242 .lambda()
234 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 249 private Set<String> getCustomerScripts(String customerId, String tenantId) {
... ... @@ -244,9 +251,9 @@ public class TkDeviceScriptServiceImpl
244 251 List<TkCustomerDeviceDTO> list = tkCustomerDevice.getMappingByCustomerId(customerId);
245 252 if (null != list && !list.isEmpty()) {
246 253 Set<String> deviceIds =
247   - list.stream().map(obj -> obj.getDeviceId()).collect(Collectors.toSet());
  254 + list.stream().map(TkCustomerDeviceDTO::getDeviceId).collect(Collectors.toSet());
248 255 scriptIds =
249   - Optional.ofNullable(deviceIds)
  256 + Optional.of(deviceIds)
250 257 .map(
251 258 ids -> {
252 259 List<DeviceDTO> deviceDTOS =
... ... @@ -254,7 +261,7 @@ public class TkDeviceScriptServiceImpl
254 261 if (null != deviceDTOS && !deviceDTOS.isEmpty()) {
255 262 List<String> deviceProfiles =
256 263 deviceDTOS.stream()
257   - .map(obj -> obj.getDeviceProfileId())
  264 + .map(DeviceDTO::getDeviceProfileId)
258 265 .collect(Collectors.toList());
259 266 List<DeviceProfileDTO> deviceProfileDTOList =
260 267 tkDeviceProfileService.findDeviceProfileByIds(tenantId, deviceProfiles);
... ... @@ -262,7 +269,7 @@ public class TkDeviceScriptServiceImpl
262 269 .map(
263 270 deviceProfileDTOS ->
264 271 deviceProfileDTOS.stream()
265   - .map(obj -> obj.getScriptId())
  272 + .map(DeviceProfileDTO::getScriptId)
266 273 .collect(Collectors.toSet()))
267 274 .orElse(null);
268 275 }
... ...