Commit 2fbc7bd31da33fe2e3e392e603b9ef8676a5fc15

Authored by 黄 x
1 parent a3ac0ee6

fix: thingsModel page query bug

@@ -43,12 +43,17 @@ public class ThingsModelController extends BaseController { @@ -43,12 +43,17 @@ public class ThingsModelController extends BaseController {
43 params = {PAGE_SIZE, PAGE}) 43 params = {PAGE_SIZE, PAGE})
44 @ApiOperation(value = "分页") 44 @ApiOperation(value = "分页")
45 public YtPageData<ThingsModelDTO> page( 45 public YtPageData<ThingsModelDTO> page(
  46 + @RequestParam("deviceProfileId") String deviceProfileId,
46 @RequestParam(PAGE_SIZE) int pageSize, 47 @RequestParam(PAGE_SIZE) int pageSize,
47 @RequestParam(PAGE) int page, 48 @RequestParam(PAGE) int page,
48 @RequestParam(value = "nameOrIdentifier", required = false) String nameOrIdentifier, 49 @RequestParam(value = "nameOrIdentifier", required = false) String nameOrIdentifier,
  50 + @RequestParam(value = "functionType", required = false) FunctionTypeEnum functionType,
49 @RequestParam(value = ORDER_FILED, required = false) String orderBy, 51 @RequestParam(value = ORDER_FILED, required = false) String orderBy,
50 @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) 52 @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
51 throws ThingsboardException { 53 throws ThingsboardException {
  54 + if(StringUtils.isEmpty(deviceProfileId)){
  55 + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  56 + }
52 HashMap<String, Object> queryMap = new HashMap<>(); 57 HashMap<String, Object> queryMap = new HashMap<>();
53 queryMap.put("nameOrIdentifier", nameOrIdentifier); 58 queryMap.put("nameOrIdentifier", nameOrIdentifier);
54 queryMap.put(PAGE_SIZE, pageSize); 59 queryMap.put(PAGE_SIZE, pageSize);
@@ -57,7 +62,11 @@ public class ThingsModelController extends BaseController { @@ -57,7 +62,11 @@ public class ThingsModelController extends BaseController {
57 if (orderType != null) { 62 if (orderType != null) {
58 queryMap.put(ORDER_TYPE, orderType.name()); 63 queryMap.put(ORDER_TYPE, orderType.name());
59 } 64 }
60 - return thingsModelService.page(queryMap, getCurrentUser().getCurrentTenantId()); 65 + if (functionType != null) {
  66 + queryMap.put("functionType", functionType);
  67 + }
  68 + return thingsModelService.page(
  69 + queryMap, getCurrentUser().getCurrentTenantId(), deviceProfileId);
61 } 70 }
62 71
63 @PostMapping() 72 @PostMapping()
@@ -37,23 +37,28 @@ public class ThingsModelServiceImpl @@ -37,23 +37,28 @@ public class ThingsModelServiceImpl
37 private final YtDeviceProfileService ytDeviceProfileService; 37 private final YtDeviceProfileService ytDeviceProfileService;
38 38
39 @Override 39 @Override
40 - public YtPageData<ThingsModelDTO> page(Map<String, Object> queryMap, String tenantId) { 40 + public YtPageData<ThingsModelDTO> page(
  41 + Map<String, Object> queryMap, String tenantId, String deviceProfileId) {
41 String nameOrIdentifier = 42 String nameOrIdentifier =
42 null != queryMap.get("nameOrIdentifier") ? (String) queryMap.get("nameOrIdentifier") : null; 43 null != queryMap.get("nameOrIdentifier") ? (String) queryMap.get("nameOrIdentifier") : null;
  44 + String functionType =
  45 + null != queryMap.get("functionType") ? queryMap.get("functionType").toString() : null;
43 IPage<TkThingsModelEntity> iPage = 46 IPage<TkThingsModelEntity> iPage =
44 baseMapper.selectPage( 47 baseMapper.selectPage(
45 getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false), 48 getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false),
46 new LambdaQueryWrapper<TkThingsModelEntity>() 49 new LambdaQueryWrapper<TkThingsModelEntity>()
47 .eq(TkThingsModelEntity::getTenantId, tenantId) 50 .eq(TkThingsModelEntity::getTenantId, tenantId)
48 - .like(  
49 - StringUtils.isNotEmpty(nameOrIdentifier),  
50 - TkThingsModelEntity::getFunctionName,  
51 - nameOrIdentifier)  
52 - .or()  
53 - .like( 51 + .eq(TkThingsModelEntity::getDeviceProfileId, deviceProfileId)
  52 + .eq(
  53 + StringUtils.isNotEmpty(functionType),
  54 + TkThingsModelEntity::getFunctionType,
  55 + functionType)
  56 + .and(
54 StringUtils.isNotEmpty(nameOrIdentifier), 57 StringUtils.isNotEmpty(nameOrIdentifier),
55 - TkThingsModelEntity::getIdentifier,  
56 - nameOrIdentifier)); 58 + qr ->
  59 + qr.like(TkThingsModelEntity::getFunctionName, nameOrIdentifier)
  60 + .or()
  61 + .like(TkThingsModelEntity::getIdentifier, nameOrIdentifier)));
57 return getPageData(iPage, ThingsModelDTO.class); 62 return getPageData(iPage, ThingsModelDTO.class);
58 } 63 }
59 64
@@ -10,7 +10,8 @@ import java.util.List; @@ -10,7 +10,8 @@ import java.util.List;
10 import java.util.Map; 10 import java.util.Map;
11 11
12 public interface ThingsModelService { 12 public interface ThingsModelService {
13 - YtPageData<ThingsModelDTO> page(Map<String, Object> queryMap, String tenantId); 13 + YtPageData<ThingsModelDTO> page(
  14 + Map<String, Object> queryMap, String tenantId, String deviceProfileId);
14 15
15 ThingsModelDTO saveOrUpdate(ThingsModelDTO thingsModelDTO); 16 ThingsModelDTO saveOrUpdate(ThingsModelDTO thingsModelDTO);
16 17
@@ -25,5 +26,5 @@ public interface ThingsModelService { @@ -25,5 +26,5 @@ public interface ThingsModelService {
25 26
26 JsonNode getTingsModelTSL(FunctionTypeEnum typeEnum, String tenantId, String deviceProfileId); 27 JsonNode getTingsModelTSL(FunctionTypeEnum typeEnum, String tenantId, String deviceProfileId);
27 28
28 - boolean changeTSLStatus(String deviceProfileId,String tenantId,Integer status); 29 + boolean changeTSLStatus(String deviceProfileId, String tenantId, Integer status);
29 } 30 }