Commit e676925691ad01fd84405e878e993d72b4d9bff3

Authored by 云中非
2 parents 1289569c 2ef7cd76

Merge branch 'master' into 20221129

... ... @@ -6,6 +6,7 @@ import io.swagger.annotations.ApiOperation;
6 6 import lombok.RequiredArgsConstructor;
7 7 import org.apache.commons.lang3.StringUtils;
8 8 import org.springframework.http.ResponseEntity;
  9 +import org.springframework.security.access.prepost.PreAuthorize;
9 10 import org.springframework.validation.annotation.Validated;
10 11 import org.springframework.web.bind.annotation.*;
11 12 import org.thingsboard.server.common.data.exception.ThingsboardException;
... ... @@ -72,7 +73,7 @@ public class ThingsModelController extends BaseController {
72 73
73 74 @PostMapping()
74 75 @ApiOperation("保存物模型")
75   - // @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:things_model:post'})")
  76 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:things_model:post'})")
76 77 public ResponseEntity<ThingsModelDTO> save(
77 78 @Validated(AddGroup.class) @RequestBody ThingsModelDTO thingsModelDTO)
78 79 throws ThingsboardException {
... ... @@ -81,7 +82,7 @@ public class ThingsModelController extends BaseController {
81 82
82 83 @PutMapping()
83 84 @ApiOperation("修改物模型")
84   - // @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:things_model:put'})")
  85 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:things_model:put'})")
85 86 public ResponseEntity<ThingsModelDTO> update(
86 87 @Validated(UpdateGroup.class) @RequestBody ThingsModelDTO thingsModelDTO)
87 88 throws ThingsboardException {
... ... @@ -90,7 +91,7 @@ public class ThingsModelController extends BaseController {
90 91
91 92 @DeleteMapping
92 93 @ApiOperation("删除")
93   - // @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:things_model:delete'})")
  94 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:things_model:delete'})")
94 95 public boolean delete(@Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO)
95 96 throws ThingsboardException {
96 97 deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId());
... ... @@ -99,7 +100,6 @@ public class ThingsModelController extends BaseController {
99 100
100 101 @GetMapping("/{functionType}/{deviceProfileId}")
101 102 @ApiOperation("获取物模型TSL")
102   - // @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:things_model:json:view'})")
103 103 public ResponseEntity<JsonNode> getTSL(
104 104 @PathVariable("functionType") FunctionTypeEnum functionType,
105 105 @PathVariable("deviceProfileId") String deviceProfileId)
... ... @@ -110,7 +110,7 @@ public class ThingsModelController extends BaseController {
110 110 }
111 111
112 112 @PutMapping("/{deviceProfileId}")
113   - // @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:things_model:release'})")
  113 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:things_model:release'})")
114 114 @ApiOperation("物模型发布")
115 115 public ResponseEntity<Boolean> releaseTSL(@PathVariable("deviceProfileId") String deviceProfileId)
116 116 throws ThingsboardException {
... ...
... ... @@ -37,9 +37,7 @@ import org.thingsboard.server.service.security.permission.Operation;
37 37
38 38 import java.time.LocalDateTime;
39 39 import java.time.ZoneOffset;
40   -import java.util.List;
41   -import java.util.Objects;
42   -import java.util.UUID;
  40 +import java.util.*;
43 41
44 42 import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*;
45 43
... ... @@ -126,16 +124,17 @@ public class TkDeviceProfileController extends BaseController {
126 124
127 125 @GetMapping("{id}")
128 126 @ApiOperation("详情")
129   - @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:get'})")
  127 + @PreAuthorize(
  128 + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:deviceProfile:get'})")
130 129 public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id)
131 130 throws ThingsboardException {
132 131 return ResponseEntity.of(
133 132 ytDeviceProfileService.getDeviceProfile(getCurrentUser().getCurrentTenantId(), id));
134 133 }
135 134
136   - @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
137 135 @GetMapping(params = {PAGE_SIZE, PAGE})
138 136 @ApiOperation("查询")
  137 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})")
139 138 public YtPageData<DeviceProfileDTO> pageDeviceProfile(
140 139 @RequestParam(PAGE_SIZE) int pageSize,
141 140 @RequestParam(PAGE) int page,
... ... @@ -144,21 +143,32 @@ public class TkDeviceProfileController extends BaseController {
144 143 @RequestParam(value = ORDER_FILED, required = false) String orderBy,
145 144 @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
146 145 throws ThingsboardException {
147   - return ytDeviceProfileService.page(
148   - page,
149   - pageSize,
150   - orderBy,
151   - orderType,
152   - getCurrentUser().getCurrentTenantId(),
153   - name,
154   - transportType);
  146 + Map<String, Object> queryMap = new HashMap<>();
  147 + queryMap.put(PAGE, page);
  148 + queryMap.put(PAGE_SIZE, pageSize);
  149 + queryMap.put(ORDER_FILED, orderBy);
  150 + queryMap.put(ORDER_TYPE, orderType);
  151 + queryMap.put("name", name);
  152 + queryMap.put("transportType", transportType);
  153 + queryMap.put(TENANT_ID, getCurrentUser().getCurrentTenantId());
  154 + queryMap.put(CUSTOMER_ID, getCurrentUser().getCustomerId().toString());
  155 + return ytDeviceProfileService.page(queryMap, getCurrentUser().isTenantAdmin());
155 156 }
156 157
157 158 @GetMapping("/me/list")
158 159 @ApiOperation("选项列表")
  160 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})")
159 161 public ResponseEntity listDeviceProfile() throws ThingsboardException {
160   - List<DeviceProfileDTO> results =
161   - ytDeviceProfileService.findDeviceProfile(getCurrentUser().getCurrentTenantId(), null);
  162 + List<DeviceProfileDTO> results;
  163 + String tenantId = getCurrentUser().getCurrentTenantId();
  164 + if (getCurrentUser().isTenantAdmin()) {
  165 + results = ytDeviceProfileService.findDeviceProfile(tenantId, null);
  166 + } else {
  167 + results =
  168 + ytDeviceProfileService.findCustomerDeviceProfiles(
  169 + tenantId, getCurrentUser().getCustomerId());
  170 + }
  171 +
162 172 return ResponseEntity.ok(results);
163 173 }
164 174
... ... @@ -177,18 +187,20 @@ public class TkDeviceProfileController extends BaseController {
177 187 }
178 188
179 189 private void deleteTbDeviceProfile(String profileId) throws ThingsboardException {
180   - DeviceProfileDTO dto = ytDeviceProfileService.findDeviceProfileById(getCurrentUser().getCurrentTenantId(), profileId);
181   - if(null != dto){
  190 + DeviceProfileDTO dto =
  191 + ytDeviceProfileService.findDeviceProfileById(
  192 + getCurrentUser().getCurrentTenantId(), profileId);
  193 + if (null != dto) {
182 194 DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(dto.getTbProfileId()));
183 195 DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.DELETE);
184 196 deviceProfileService.deleteDeviceProfile(getTenantId(), deviceProfileId);
185 197
186 198 tbClusterService.onDeviceProfileDelete(deviceProfile, null);
187 199 tbClusterService.broadcastEntityStateChangeEvent(
188   - deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED);
  200 + deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED);
189 201
190 202 logEntityAction(
191   - deviceProfileId, deviceProfile, null, ActionType.DELETED, null, deviceProfileId);
  203 + deviceProfileId, deviceProfile, null, ActionType.DELETED, null, deviceProfileId);
192 204
193 205 sendEntityNotificationMsg(getTenantId(), deviceProfile.getId(), EdgeEventActionType.DELETED);
194 206 }
... ...
... ... @@ -46,9 +46,7 @@ import org.thingsboard.server.dao.yunteng.service.TkDeviceScriptService;
46 46
47 47 import java.time.LocalDateTime;
48 48 import java.time.ZoneOffset;
49   -import java.util.List;
50   -import java.util.Objects;
51   -import java.util.UUID;
  49 +import java.util.*;
52 50 import java.util.concurrent.TimeUnit;
53 51
54 52 import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*;
... ... @@ -133,33 +131,37 @@ public class TkDeviceScriptController extends BaseController {
133 131
134 132 @GetMapping("{id}")
135 133 @ApiOperation("详情")
136   - // @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:get'})")
  134 + @PreAuthorize(
  135 + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:js:get'})")
137 136 public ResponseEntity<TkDeviceScriptDTO> getDevice(@PathVariable("id") String id)
138 137 throws ThingsboardException {
139 138 return ResponseEntity.of(
140 139 scriptService.getDeviceScript(getCurrentUser().getCurrentTenantId(), id));
141 140 }
142 141
143   - @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
144 142 @GetMapping(params = {PAGE_SIZE, PAGE})
145 143 @ApiOperation("分页查询")
146   - public YtPageData<TkDeviceScriptDTO> pageDeviceProfile(
  144 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})")
  145 + public YtPageData<TkDeviceScriptDTO> pageDeviceScript(
147 146 @RequestParam(PAGE_SIZE) int pageSize,
148 147 @RequestParam(PAGE) int page,
149   - @RequestParam(value = "name", required = false) String name,
150   - @RequestParam(value = "transportType", required = false) String transportType,
151 148 @RequestParam(value = ORDER_FILED, required = false) String orderFiled,
152 149 @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
153 150 throws ThingsboardException {
154   -
155   - return scriptService.page(
156   - page, pageSize, orderFiled, orderType, getCurrentUser().getCurrentTenantId());
  151 + Map<String, Object> queryMap = new HashMap<>();
  152 + queryMap.put(PAGE_SIZE, pageSize);
  153 + queryMap.put(PAGE, page);
  154 + queryMap.put(ORDER_FILED, orderFiled);
  155 + queryMap.put(ORDER_TYPE, orderType);
  156 + queryMap.put(CUSTOMER_ID, getCurrentUser().getCustomerId().toString());
  157 + queryMap.put(TENANT_ID, getCurrentUser().getCurrentTenantId());
  158 + return scriptService.page(queryMap, getCurrentUser().isTenantAdmin());
157 159 }
158 160
159 161 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
160 162 @GetMapping("/me/list")
161 163 @ApiOperation("选项列表")
162   - public ResponseEntity listDeviceProfile() throws ThingsboardException {
  164 + public ResponseEntity listDeviceScript() throws ThingsboardException {
163 165 List<TkDeviceScriptDTO> results =
164 166 scriptService.findDeviceScript(getCurrentUser().getCurrentTenantId());
165 167 return ResponseEntity.ok(results);
... ... @@ -167,7 +169,7 @@ public class TkDeviceScriptController extends BaseController {
167 169
168 170 @DeleteMapping
169 171 @ApiOperation("删除")
170   - @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:delete'})")
  172 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:js:delete'})")
171 173 public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO)
172 174 throws ThingsboardException {
173 175 scriptService.deleteScriptes(getCurrentUser().getCurrentTenantId(), deleteDTO.getIds());
... ...
... ... @@ -7,4 +7,5 @@ public class QueryConstant {
7 7 public static final String ORDER_TYPE = "orderType";
8 8 public static final String CREATE_TIME="createTime";
9 9 public static final String TENANT_ID = "tenantId";
  10 + public static final String CUSTOMER_ID = "customerId";
10 11 }
... ...
... ... @@ -3,18 +3,21 @@ package org.thingsboard.server.dao.yunteng.impl;
3 3 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 4 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 5 import com.baomidou.mybatisplus.core.metadata.IPage;
  6 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 7 import lombok.RequiredArgsConstructor;
7 8 import lombok.extern.slf4j.Slf4j;
8 9 import org.apache.commons.lang3.StringUtils;
9 10 import org.springframework.stereotype.Service;
10 11 import org.springframework.transaction.annotation.Transactional;
11 12 import org.thingsboard.server.common.data.DeviceProfile;
  13 +import org.thingsboard.server.common.data.id.CustomerId;
12 14 import org.thingsboard.server.common.data.id.TenantId;
  15 +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
13 16 import org.thingsboard.server.common.data.yunteng.constant.ModelConstants;
  17 +import org.thingsboard.server.common.data.yunteng.constant.QueryConstant;
14 18 import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException;
15 19 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
16 20 import org.thingsboard.server.common.data.yunteng.dto.*;
17   -import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum;
18 21 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
19 22 import org.thingsboard.server.dao.yunteng.entities.*;
20 23 import org.thingsboard.server.dao.yunteng.jpa.dao.YtJpaDeviceProfileDao;
... ... @@ -24,6 +27,7 @@ import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
24 27 import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService;
25 28
26 29 import java.util.*;
  30 +import java.util.stream.Collectors;
27 31
28 32 @Service
29 33 @RequiredArgsConstructor
... ... @@ -152,26 +156,94 @@ public class TkDeviceProfileServiceImpl
152 156 }
153 157
154 158 @Override
155   - public YtPageData<DeviceProfileDTO> page(
156   - Integer page,
157   - Integer pageSize,
158   - String orderField,
159   - OrderTypeEnum orderType,
160   - String tenantIdStr,
161   - String profileName,
162   - String transportType) {
163   -
  159 + public YtPageData<DeviceProfileDTO> page(Map<String, Object> queryMap, boolean isTenantAdmin) {
  160 + String tenantIdStr =
  161 + Optional.ofNullable(queryMap.get(QueryConstant.TENANT_ID))
  162 + .map(Object::toString)
  163 + .orElse(null);
  164 + String profileName =
  165 + Optional.ofNullable(queryMap.get("name")).map(Object::toString).orElse(null);
  166 + String transportType =
  167 + Optional.ofNullable(queryMap.get("transportType")).map(Object::toString).orElse(null);
  168 + String customerId =
  169 + Optional.ofNullable(queryMap.get("customerId"))
  170 + .map(
  171 + obj -> {
  172 + if (isTenantAdmin) {
  173 + return null;
  174 + }
  175 + return obj.toString();
  176 + })
  177 + .orElse(null);
  178 + List<String> deviceProfileIds = null;
  179 + IPage<DeviceProfileDTO> result = new Page<>();
  180 + if (!isTenantAdmin) {
  181 + List<DeviceDTO> deviceDTOS = deviceMapper.findDeviceInfoByCustomerId(tenantIdStr, customerId);
  182 + if (null == deviceDTOS || deviceDTOS.isEmpty()) {
  183 + return getPageData(result, DeviceProfileDTO.class);
  184 + }
  185 + deviceProfileIds =
  186 + Optional.of(deviceDTOS)
  187 + .map(
  188 + devices ->
  189 + devices.stream().map(DeviceDTO::getDeviceProfileId).collect(Collectors.toList()))
  190 + .orElse(null);
  191 + }
164 192 IPage<TkDeviceProfileEntity> currentPage =
165   - getCurrentPage(page, pageSize, orderField, orderType);
166   - IPage<DeviceProfileDTO> result =
167   - baseMapper.getProfilePage(currentPage, tenantIdStr, profileName, transportType);
168   -
  193 + getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false);
  194 + result =
  195 + baseMapper.getProfilePage(
  196 + currentPage, tenantIdStr, profileName, transportType, deviceProfileIds);
169 197 return getPageData(result, DeviceProfileDTO.class);
170 198 }
171 199
172 200 @Override
173 201 public List<DeviceProfileDTO> findDeviceProfile(String tenantId, String scriptId) {
174   - List<DeviceProfileDTO> results = baseMapper.profileByScriptId(tenantId, scriptId);
175   - return results;
  202 + return baseMapper.profileByScriptId(tenantId, scriptId);
  203 + }
  204 +
  205 + @Override
  206 + public List<DeviceProfileDTO> findCustomerDeviceProfiles(String tenantId, CustomerId customerId) {
  207 + List<DeviceDTO> deviceDTOS =
  208 + deviceMapper.findDeviceInfoByCustomerId(tenantId, customerId.toString());
  209 + List<String> deviceProfileIds =
  210 + Optional.ofNullable(deviceDTOS)
  211 + .map(
  212 + devices ->
  213 + devices.stream().map(DeviceDTO::getDeviceProfileId).collect(Collectors.toList()))
  214 + .orElse(null);
  215 + if (null == deviceProfileIds || deviceProfileIds.isEmpty()) {
  216 + return null;
  217 + }
  218 + List<TkDeviceProfileEntity> entities =
  219 + baseMapper.selectList(
  220 + new LambdaQueryWrapper<TkDeviceProfileEntity>()
  221 + .eq(TkDeviceProfileEntity::getTenantId, tenantId)
  222 + .in(TkDeviceProfileEntity::getId, deviceProfileIds));
  223 + if (null != entities && !entities.isEmpty()) {
  224 + return entities.stream()
  225 + .map(obj -> obj.getDTO(DeviceProfileDTO.class))
  226 + .collect(Collectors.toList());
  227 + }
  228 + return null;
  229 + }
  230 +
  231 + @Override
  232 + public List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId, List<String> ids) {
  233 + if (StringUtils.isEmpty(tenantId) || null == ids) {
  234 + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  235 + }
  236 + List<TkDeviceProfileEntity> entities =
  237 + baseMapper.selectList(
  238 + new LambdaQueryWrapper<TkDeviceProfileEntity>()
  239 + .eq(TkDeviceProfileEntity::getTenantId, tenantId)
  240 + .in(TkDeviceProfileEntity::getId, ids));
  241 +
  242 + if (null == entities || entities.isEmpty()) {
  243 + return null;
  244 + }
  245 + return entities.stream()
  246 + .map(obj -> obj.getDTO(DeviceProfileDTO.class))
  247 + .collect(Collectors.toList());
176 248 }
177 249 }
... ...
... ... @@ -8,33 +8,36 @@ import lombok.extern.slf4j.Slf4j;
8 8 import org.apache.commons.lang3.StringUtils;
9 9 import org.springframework.stereotype.Service;
10 10 import org.springframework.transaction.annotation.Transactional;
  11 +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
11 12 import org.thingsboard.server.common.data.yunteng.constant.ModelConstants;
  13 +import org.thingsboard.server.common.data.yunteng.constant.QueryConstant;
12 14 import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException;
13 15 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
  16 +import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO;
  17 +import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO;
  18 +import org.thingsboard.server.common.data.yunteng.dto.TkCustomerDeviceDTO;
14 19 import org.thingsboard.server.common.data.yunteng.dto.TkDeviceScriptDTO;
15   -import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum;
16 20 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
17 21 import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity;
18 22 import org.thingsboard.server.dao.yunteng.entities.TkDeviceScriptEntity;
19 23 import org.thingsboard.server.dao.yunteng.mapper.TkDeviceProfileMapper;
20 24 import org.thingsboard.server.dao.yunteng.mapper.TkDeviceScriptMapper;
21   -import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
22   -import org.thingsboard.server.dao.yunteng.service.TkDeviceScriptService;
  25 +import org.thingsboard.server.dao.yunteng.service.*;
23 26
24   -import java.util.List;
25   -import java.util.Optional;
26   -import java.util.Set;
  27 +import java.util.*;
27 28 import java.util.stream.Collectors;
28 29
29 30 @Service
30 31 @RequiredArgsConstructor
31 32 @Slf4j
32   -public class TkDeviceScriptServiceImpl extends AbstractBaseService<TkDeviceScriptMapper, TkDeviceScriptEntity>
33   - implements TkDeviceScriptService {
34   -
  33 +public class TkDeviceScriptServiceImpl
  34 + extends AbstractBaseService<TkDeviceScriptMapper, TkDeviceScriptEntity>
  35 + implements TkDeviceScriptService {
35 36
36 37 private final TkDeviceProfileMapper profileMapper;
37   -
  38 + private final TkCustomerDevice tkCustomerDevice;
  39 + private final TkDeviceProfileService tkDeviceProfileService;
  40 + private final TkDeviceService tkDeviceService;
38 41
39 42 @Override
40 43 public boolean validateFormdata(TkDeviceScriptDTO scriptDTO, boolean created) {
... ... @@ -42,32 +45,32 @@ public class TkDeviceScriptServiceImpl extends AbstractBaseService<TkDeviceScrip
42 45 if (created) {
43 46 // 判断数据库是否已存在名字相同的设备配置
44 47 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
45   - new QueryWrapper<TkDeviceScriptEntity>()
46   - .lambda()
47   - .eq(TkDeviceScriptEntity::getTenantId, tenantId)
48   - .eq(TkDeviceScriptEntity::getName, scriptDTO.getName());
  48 + new QueryWrapper<TkDeviceScriptEntity>()
  49 + .lambda()
  50 + .eq(TkDeviceScriptEntity::getTenantId, tenantId)
  51 + .eq(TkDeviceScriptEntity::getName, scriptDTO.getName());
49 52 int results = baseMapper.selectCount(queryWrapper);
50 53 if (results > 0) {
51 54 throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage());
52 55 }
53 56 } else {
54 57 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
55   - new QueryWrapper<TkDeviceScriptEntity>()
56   - .lambda()
57   - .eq(TkDeviceScriptEntity::getTenantId, tenantId)
58   - .and(
59   - second ->
60   - second
61   - .eq(TkDeviceScriptEntity::getId, scriptDTO.getId())
62   - .or(f -> f.eq(TkDeviceScriptEntity::getName, scriptDTO.getName())));
63   -
  58 + new QueryWrapper<TkDeviceScriptEntity>()
  59 + .lambda()
  60 + .eq(TkDeviceScriptEntity::getTenantId, tenantId)
  61 + .and(
  62 + second ->
  63 + second
  64 + .eq(TkDeviceScriptEntity::getId, scriptDTO.getId())
  65 + .or(f -> f.eq(TkDeviceScriptEntity::getName, scriptDTO.getName())));
64 66
65 67 List<TkDeviceScriptEntity> results = baseMapper.selectList(queryWrapper);
66   - for(TkDeviceScriptEntity item:results){
67   - if(item.getId().equals(scriptDTO.getId()) && !item.getTenantId().equals(scriptDTO.getTenantId())){
  68 + for (TkDeviceScriptEntity item : results) {
  69 + if (item.getId().equals(scriptDTO.getId())
  70 + && !item.getTenantId().equals(scriptDTO.getTenantId())) {
68 71 throw new YtDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
69 72 }
70   - if(!item.getId().equals(scriptDTO.getId()) && item.getName().equals(scriptDTO.getName())){
  73 + if (!item.getId().equals(scriptDTO.getId()) && item.getName().equals(scriptDTO.getName())) {
71 74 throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage());
72 75 }
73 76 }
... ... @@ -79,12 +82,12 @@ public class TkDeviceScriptServiceImpl extends AbstractBaseService<TkDeviceScrip
79 82 @Override
80 83 public String getScriptText(String tenantId, String scriptId) {
81 84 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
82   - new QueryWrapper<TkDeviceScriptEntity>()
83   - .lambda()
84   - .eq(TkDeviceScriptEntity::getTenantId, tenantId)
85   - .eq(TkDeviceScriptEntity::getId, scriptId);
  85 + new QueryWrapper<TkDeviceScriptEntity>()
  86 + .lambda()
  87 + .eq(TkDeviceScriptEntity::getTenantId, tenantId)
  88 + .eq(TkDeviceScriptEntity::getId, scriptId);
86 89 TkDeviceScriptEntity result = baseMapper.selectOne(queryWrapper);
87   - return result ==null? null : result.getConvertJs();
  90 + return result == null ? null : result.getConvertJs();
88 91 }
89 92
90 93 @Override
... ... @@ -100,39 +103,40 @@ public class TkDeviceScriptServiceImpl extends AbstractBaseService<TkDeviceScrip
100 103 public void checkDeviceScriptes(String tenantId, Set<String> ids) {
101 104 // check if ids bind to device
102 105 List<TkDeviceProfileEntity> usedList =
103   - profileMapper.selectList(
104   - new QueryWrapper<TkDeviceProfileEntity>().lambda().in(TkDeviceProfileEntity::getScriptId, ids));
105   - if (usedList !=null &&usedList.size() > 0) {
106   - List<String> names = usedList.stream()
107   - .map(i -> i.getName())
108   - .collect(Collectors.toList());
109   - throw new YtDataValidationException(String.format(ErrorMessage.PROJECT_USED_SCRIPT.getMessage(),names));
  106 + profileMapper.selectList(
  107 + new QueryWrapper<TkDeviceProfileEntity>()
  108 + .lambda()
  109 + .in(TkDeviceProfileEntity::getScriptId, ids));
  110 + if (usedList != null && usedList.size() > 0) {
  111 + List<String> names = usedList.stream().map(i -> i.getName()).collect(Collectors.toList());
  112 + throw new YtDataValidationException(
  113 + String.format(ErrorMessage.PROJECT_USED_SCRIPT.getMessage(), names));
110 114 }
111 115 }
  116 +
112 117 @Override
113 118 @Transactional
114 119 public void deleteScriptes(String tenantId, Set<String> ids) {
115 120 checkDeviceScriptes(tenantId, ids);
116 121 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
117   - new QueryWrapper<TkDeviceScriptEntity>()
118   - .lambda()
119   - .eq(TkDeviceScriptEntity::getTenantId, tenantId)
120   - .in(TkDeviceScriptEntity::getId, ids);
  122 + new QueryWrapper<TkDeviceScriptEntity>()
  123 + .lambda()
  124 + .eq(TkDeviceScriptEntity::getTenantId, tenantId)
  125 + .in(TkDeviceScriptEntity::getId, ids);
121 126
122 127 baseMapper.delete(queryWrapper);
123   -
124 128 }
125 129
126 130 private TkDeviceScriptDTO insert(TkDeviceScriptDTO deviceDTO) {
127 131
128 132 TkDeviceScriptEntity profile = new TkDeviceScriptEntity();
129 133 deviceDTO.copyToEntity(
130   - profile,
131   - ModelConstants.TablePropertyMapping.ACTIVE_TIME,
132   - ModelConstants.TablePropertyMapping.DEVICE_STATE,
133   - ModelConstants.TablePropertyMapping.UPDATER,
134   - ModelConstants.TablePropertyMapping.CREATE_TIME,
135   - ModelConstants.TablePropertyMapping.UPDATE_TIME);
  134 + profile,
  135 + ModelConstants.TablePropertyMapping.ACTIVE_TIME,
  136 + ModelConstants.TablePropertyMapping.DEVICE_STATE,
  137 + ModelConstants.TablePropertyMapping.UPDATER,
  138 + ModelConstants.TablePropertyMapping.CREATE_TIME,
  139 + ModelConstants.TablePropertyMapping.UPDATE_TIME);
136 140
137 141 baseMapper.insert(profile);
138 142 return profile.getDTO(TkDeviceScriptDTO.class);
... ... @@ -141,30 +145,27 @@ public class TkDeviceScriptServiceImpl extends AbstractBaseService<TkDeviceScrip
141 145 private TkDeviceScriptDTO update(TkDeviceScriptDTO deviceDTO) {
142 146 TkDeviceScriptEntity device = new TkDeviceScriptEntity();
143 147 deviceDTO.copyToEntity(
144   - device,
145   - ModelConstants.TablePropertyMapping.ACTIVE_TIME,
146   - ModelConstants.TablePropertyMapping.DEVICE_STATE,
147   - ModelConstants.TablePropertyMapping.TB_DEVICE_ID,
148   - ModelConstants.TablePropertyMapping.TENANT_CODE,
149   - ModelConstants.TablePropertyMapping.CREATOR,
150   - ModelConstants.TablePropertyMapping.UPDATER,
151   - ModelConstants.TablePropertyMapping.CREATE_TIME,
152   - ModelConstants.TablePropertyMapping.UPDATE,
153   - ModelConstants.TablePropertyMapping.UPDATE_TIME);
  148 + device,
  149 + ModelConstants.TablePropertyMapping.ACTIVE_TIME,
  150 + ModelConstants.TablePropertyMapping.DEVICE_STATE,
  151 + ModelConstants.TablePropertyMapping.TB_DEVICE_ID,
  152 + ModelConstants.TablePropertyMapping.TENANT_CODE,
  153 + ModelConstants.TablePropertyMapping.CREATOR,
  154 + ModelConstants.TablePropertyMapping.UPDATER,
  155 + ModelConstants.TablePropertyMapping.CREATE_TIME,
  156 + ModelConstants.TablePropertyMapping.UPDATE,
  157 + ModelConstants.TablePropertyMapping.UPDATE_TIME);
154 158 baseMapper.updateById(device);
155 159 return device.getDTO(TkDeviceScriptDTO.class);
156 160 }
157 161
158   -
159   -
160   -
161 162 @Override
162 163 public Optional<TkDeviceScriptDTO> getDeviceScript(String tenantId, String id) {
163 164 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
164   - new QueryWrapper<TkDeviceScriptEntity>()
165   - .lambda()
166   - .eq(TkDeviceScriptEntity::getTenantId, tenantId)
167   - .eq(TkDeviceScriptEntity::getId, id);
  165 + new QueryWrapper<TkDeviceScriptEntity>()
  166 + .lambda()
  167 + .eq(TkDeviceScriptEntity::getTenantId, tenantId)
  168 + .eq(TkDeviceScriptEntity::getId, id);
168 169 TkDeviceScriptEntity profile = baseMapper.selectOne(queryWrapper);
169 170 return Optional.ofNullable(profile)
170 171 .map(
... ... @@ -175,35 +176,83 @@ public class TkDeviceScriptServiceImpl extends AbstractBaseService<TkDeviceScrip
175 176 }
176 177
177 178 @Override
178   - public YtPageData<TkDeviceScriptDTO> page(Integer page, Integer pageSize, String orderField, OrderTypeEnum orderType, String tenantId) {
179   - IPage<TkDeviceScriptEntity> currentPage = getCurrentPage(page,pageSize,orderField,orderType);
180   -
  179 + public YtPageData<TkDeviceScriptDTO> page(Map<String, Object> queryMap, boolean isTenantAdmin) {
  180 +
  181 + String tenantId =
  182 + Optional.ofNullable(queryMap.get(QueryConstant.TENANT_ID))
  183 + .map(Object::toString)
  184 + .orElse(null);
  185 + IPage<TkDeviceScriptEntity> currentPage =
  186 + getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false);
  187 + String customerId =
  188 + Optional.ofNullable(queryMap.get(QueryConstant.CUSTOMER_ID))
  189 + .map(Object::toString)
  190 + .orElse(null);
  191 + Set<String> scriptIds = null;
  192 + if (!isTenantAdmin && StringUtils.isNotEmpty(customerId)) {
  193 + scriptIds = getCustomerScripts(customerId, tenantId);
  194 + }
  195 + if (!isTenantAdmin && (null == scriptIds || scriptIds.isEmpty())) {
  196 + return new YtPageData<>(new ArrayList<>(), 0);
  197 + }
181 198 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
182   - new QueryWrapper<TkDeviceScriptEntity>()
183   - .lambda()
184   - .eq(TkDeviceScriptEntity::getTenantId, tenantId);
185   -
186   -
187   -
188   -
189   - IPage<TkDeviceScriptEntity> scriptes = baseMapper.selectPage(currentPage, queryWrapper);
190   - List<TkDeviceScriptDTO> records = scriptes.getRecords().stream()
  199 + new QueryWrapper<TkDeviceScriptEntity>()
  200 + .lambda()
  201 + .eq(TkDeviceScriptEntity::getTenantId, tenantId)
  202 + .in(!isTenantAdmin, TkDeviceScriptEntity::getId, scriptIds);
  203 +
  204 + IPage<TkDeviceScriptEntity> scripts = baseMapper.selectPage(currentPage, queryWrapper);
  205 + List<TkDeviceScriptDTO> records =
  206 + scripts.getRecords().stream()
191 207 .map(entity -> entity.getDTO(TkDeviceScriptDTO.class))
192 208 .collect(Collectors.toList());
193   - return new YtPageData<>(records, scriptes.getTotal());
  209 + return new YtPageData<>(records, scripts.getTotal());
194 210 }
195 211
196 212 @Override
197 213 public List<TkDeviceScriptDTO> findDeviceScript(String tenantId) {
198 214 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
199   - new QueryWrapper<TkDeviceScriptEntity>()
200   - .lambda()
201   - .eq(TkDeviceScriptEntity::getTenantId, tenantId);
202   - List<TkDeviceScriptDTO> results = baseMapper.selectList(queryWrapper).stream()
  215 + new QueryWrapper<TkDeviceScriptEntity>()
  216 + .lambda()
  217 + .eq(TkDeviceScriptEntity::getTenantId, tenantId);
  218 + List<TkDeviceScriptDTO> results =
  219 + baseMapper.selectList(queryWrapper).stream()
203 220 .map(item -> item.getDTO(TkDeviceScriptDTO.class))
204 221 .collect(Collectors.toList());
205 222 return results;
206 223 }
207 224
208   -
  225 + private Set<String> getCustomerScripts(String customerId, String tenantId) {
  226 + Set<String> scriptIds = null;
  227 + List<TkCustomerDeviceDTO> list = tkCustomerDevice.getMappingByCustomerId(customerId);
  228 + if (null != list && !list.isEmpty()) {
  229 + Set<String> deviceIds =
  230 + list.stream().map(obj -> obj.getDeviceId()).collect(Collectors.toSet());
  231 + scriptIds =
  232 + Optional.ofNullable(deviceIds)
  233 + .map(
  234 + ids -> {
  235 + List<DeviceDTO> deviceDTOS =
  236 + tkDeviceService.findDevicesInfoByIds(tenantId, ids);
  237 + if (null != deviceDTOS && !deviceDTOS.isEmpty()) {
  238 + List<String> deviceProfiles =
  239 + deviceDTOS.stream()
  240 + .map(obj -> obj.getDeviceProfileId())
  241 + .collect(Collectors.toList());
  242 + List<DeviceProfileDTO> deviceProfileDTOList =
  243 + tkDeviceProfileService.findDeviceProfileByIds(tenantId, deviceProfiles);
  244 + return Optional.ofNullable(deviceProfileDTOList)
  245 + .map(
  246 + deviceProfileDTOS ->
  247 + deviceProfileDTOS.stream()
  248 + .map(obj -> obj.getScriptId())
  249 + .collect(Collectors.toSet()))
  250 + .orElse(null);
  251 + }
  252 + return null;
  253 + })
  254 + .orElse(null);
  255 + }
  256 + return scriptIds;
  257 + }
209 258 }
... ...
... ... @@ -128,7 +128,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
128 128 DeviceProfile deviceProfile =
129 129 deviceProfileDao.findById(id, UUID.fromString(deviceDTO.getProfileId()));
130 130 TkOrganizationEntity organization =
131   - tkOrganizationMapper.selectById(deviceDTO.getOrganizationId());
  131 + tkOrganizationMapper.selectById(deviceDTO.getOrganizationId());
132 132 if (null == deviceProfile || null == organization) {
133 133 throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
134 134 } else if (!organization.getTenantId().equals(deviceTenantId)) {
... ... @@ -347,7 +347,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
347 347 }
348 348 // 查询该组织的所有子类
349 349 List<OrganizationDTO> organizationDTOS =
350   - tkOrganizationMapper.findOrganizationTreeList(tenantId, organizationIds);
  350 + tkOrganizationMapper.findOrganizationTreeList(tenantId, organizationIds);
351 351 List<String> queryOrganizationIds = new ArrayList<>();
352 352 organizationDTOS.forEach(item -> queryOrganizationIds.add(item.getId()));
353 353 return queryOrganizationIds;
... ... @@ -516,8 +516,20 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
516 516 }
517 517
518 518 @Override
519   - public List<DeviceDTO> findNumberAttributeDevicesByIds(String tenantId, List<String> ids) {
520   - return null;
  519 + public List<DeviceDTO> findDevicesInfoByIds(String tenantId, Set<String> ids) {
  520 + if (StringUtils.isEmpty(tenantId) || null == ids) {
  521 + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  522 + }
  523 + List<TkDeviceEntity> entities =
  524 + baseMapper.selectList(
  525 + new LambdaQueryWrapper<TkDeviceEntity>()
  526 + .eq(TkDeviceEntity::getTenantId, tenantId)
  527 + .in(TkDeviceEntity::getTbDeviceId, ids));
  528 + return Optional.ofNullable(entities)
  529 + .map(
  530 + list ->
  531 + list.stream().map(obj -> obj.getDTO(DeviceDTO.class)).collect(Collectors.toList()))
  532 + .orElse(null);
521 533 }
522 534
523 535 @Override
... ... @@ -537,22 +549,22 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
537 549
538 550 @Override
539 551 public JsonNode getDeviceAttributes(
540   - String deviceProfileId,String tenantId, DataTypeEnum dataType) {
  552 + String deviceProfileId, String tenantId, DataTypeEnum dataType) {
541 553
542 554 JsonNode jsonNode = JacksonUtil.newObjectNode();
543 555 List<ThingsModelDTO> thingsModel =
544   - thingsModelService.selectByDeviceProfileId(
545   - FunctionTypeEnum.properties, tenantId, deviceProfileId);
  556 + thingsModelService.selectByDeviceProfileId(
  557 + FunctionTypeEnum.properties, tenantId, deviceProfileId);
546 558 if (null != thingsModel && !thingsModel.isEmpty()) {
547 559 List<Map<String, Object>> attributes = new ArrayList<>();
548 560 for (ThingsModelDTO dto : thingsModel) {
549 561 JsonNode functionJson = dto.getFunctionJson();
550 562 String dataTypeKey = "dataType";
551 563 if (null != functionJson
552   - && null != functionJson.get(dataTypeKey)
553   - && null != functionJson.get(dataTypeKey).get("type")) {
  564 + && null != functionJson.get(dataTypeKey)
  565 + && null != functionJson.get(dataTypeKey).get("type")) {
554 566 DataTypeEnum queryDataType =
555   - DataTypeEnum.valueOf(functionJson.get(dataTypeKey).get("type").asText());
  567 + DataTypeEnum.valueOf(functionJson.get(dataTypeKey).get("type").asText());
556 568 if (null == dataType || queryDataType.equals(dataType)) {
557 569 Map<String, Object> attribute = new HashMap<>();
558 570 attribute.put("name", dto.getFunctionName());
... ...
... ... @@ -64,6 +64,8 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> {
64 64 */
65 65 List<String> findDeviceIdsByCustomerId(@Param("customerId") String customerId);
66 66
  67 + List<DeviceDTO> findDeviceInfoByCustomerId(@Param("tenantId") String tenantId,@Param("customerId") String customerId);
  68 +
67 69 List<BaseHomePageTop> findDeviceMessageInfo(
68 70 @Param("todayTime") Long todayTime, @Param("customerId") String customerId);
69 71
... ...
... ... @@ -12,14 +12,20 @@ import java.util.List;
12 12 @Mapper
13 13 public interface TkDeviceProfileMapper extends BaseMapper<TkDeviceProfileEntity> {
14 14
15   - /**
16   - * 获取产品(设备配置)详情
17   - * @return
18   - */
19   - DeviceProfileDTO selectDetail( @Param("tenantId") String tenantId, @Param("id") String id);
  15 + /**
  16 + * 获取产品(设备配置)详情
  17 + *
  18 + * @return
  19 + */
  20 + DeviceProfileDTO selectDetail(@Param("tenantId") String tenantId, @Param("id") String id);
20 21
21   - IPage<DeviceProfileDTO> getProfilePage(IPage<?> page, @Param("tenantId") String tenantId, @Param("profileName") String profileName, @Param("transportType") String transportType);
  22 + IPage<DeviceProfileDTO> getProfilePage(
  23 + IPage<?> page,
  24 + @Param("tenantId") String tenantId,
  25 + @Param("profileName") String profileName,
  26 + @Param("transportType") String transportType,
  27 + @Param("deviceProfileIds") List<String> deviceProfileIds);
22 28
23   -
24   - List<DeviceProfileDTO> profileByScriptId( @Param("tenantId") String tenantId, @Param("scriptId") String scriptId);
  29 + List<DeviceProfileDTO> profileByScriptId(
  30 + @Param("tenantId") String tenantId, @Param("scriptId") String scriptId);
25 31 }
... ...
1 1 package org.thingsboard.server.dao.yunteng.service;
2 2
  3 +import org.thingsboard.server.common.data.id.CustomerId;
3 4 import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO;
4   -import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum;
5 5 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
6 6 import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity;
7 7
8 8 import java.util.List;
  9 +import java.util.Map;
9 10 import java.util.Optional;
10 11 import java.util.Set;
11 12
... ... @@ -19,11 +20,13 @@ public interface TkDeviceProfileService extends BaseService<TkDeviceProfileEntit
19 20
20 21 Optional<DeviceProfileDTO> getDeviceProfile(String tenantId, String id);
21 22
22   - YtPageData<DeviceProfileDTO> page(Integer page, Integer pageSize, String orderField, OrderTypeEnum orderType
23   - ,String tenantIdStr, String profileName, String transportType);
  23 + YtPageData<DeviceProfileDTO> page(Map<String,Object> queryMap,boolean isTenantAdmin);
24 24
25 25 List<DeviceProfileDTO> findDeviceProfile(String tenantId,String scriptId);
26 26
  27 + List<DeviceProfileDTO> findCustomerDeviceProfiles(String tenantId, CustomerId customerId);
  28 +
  29 + List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId,List<String> ids);
27 30
28 31 /**
29 32 * 验证表单数据有效性
... ...
... ... @@ -6,6 +6,7 @@ import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
6 6 import org.thingsboard.server.dao.yunteng.entities.TkDeviceScriptEntity;
7 7
8 8 import java.util.List;
  9 +import java.util.Map;
9 10 import java.util.Optional;
10 11 import java.util.Set;
11 12
... ... @@ -27,7 +28,7 @@ public interface TkDeviceScriptService extends BaseService<TkDeviceScriptEntity>
27 28
28 29 Optional<TkDeviceScriptDTO> getDeviceScript(String tenantId, String id);
29 30
30   - YtPageData<TkDeviceScriptDTO> page(Integer page, Integer pageSize, String orderField, OrderTypeEnum orderType, String tenantId);
  31 + YtPageData<TkDeviceScriptDTO> page(Map<String, Object> queryMap, boolean isTenantAdmin);
31 32
32 33 List<TkDeviceScriptDTO> findDeviceScript(String tenantId);
33 34
... ...
... ... @@ -36,7 +36,6 @@ public interface TkDeviceService extends BaseService<TkDeviceEntity> {
36 36 /**
37 37 * 查询所有的设备信息
38 38 *
39   - * @param deviceDTO 过滤参数
40 39 * @return List<DeviceDTO>
41 40 */
42 41 boolean deviceNameUsed(String tenantId, String deviceName, String deviceId);
... ... @@ -160,13 +159,13 @@ public interface TkDeviceService extends BaseService<TkDeviceEntity> {
160 159 boolean saveSlaveDevice(String slaveId, String slaveName, String gatewayId, Long createTime);
161 160
162 161 /**
163   - * 通过设备ids查询拥有数值型属性的设备
  162 + * 通过设备ids查询设备信息列表
164 163 *
165 164 * @param tenantId 租户ID
166   - * @param ids
167   - * @return 数值型设备列表
  165 + * @param ids 设备IDS
  166 + * @return 设备信息列表
168 167 */
169   - List<DeviceDTO> findNumberAttributeDevicesByIds(String tenantId, List<String> ids);
  168 + List<DeviceDTO> findDevicesInfoByIds(String tenantId, Set<String> ids);
170 169
171 170 /**
172 171 * 通过tb设备ID获取平台设备信息
... ...
... ... @@ -245,7 +245,12 @@
245 245 LEFT JOIN device d ON d.id::TEXT = idi.tb_device_id
246 246 WHERE customer_id::TEXT = #{customerId}
247 247 </select>
248   -
  248 + <select id="findDeviceInfoByCustomerId" resultMap="deviceMap">
  249 + SELECT <include refid="basicColumns"/>
  250 + FROM tk_device ifd
  251 + LEFT JOIN device d ON ifd.tb_device_id = d.id::TEXT
  252 + WHERE ifd.tenant_id = #{tenantId} AND d.customer_id::TEXT = #{customerId}
  253 + </select>
249 254 <select id="findDeviceMessageInfo" resultMap="baseHomePageTop">
250 255 SELECT COUNT(ts.ts) AS sum_count,
251 256 SUM(CASE WHEN ts.ts >= #{todayTime} THEN 1 ELSE 0 END) AS today_add
... ...
... ... @@ -37,14 +37,21 @@
37 37 LEFT JOIN tk_device_profile iot ON iot.tb_profile_id = base.id::TEXT
38 38 <where>
39 39 <if test="tenantId !=null and tenantId !=''">
40   - AND base.tenant_id::TEXT = #{tenantId}
  40 + AND iot.tenant_id = #{tenantId}
41 41 </if>
42 42 <if test="profileName !=null and profileName !=''">
43   - AND base.name = #{profileName}
  43 + AND base.name LIKE CONCAT('%',#{profileName},'%')
44 44 </if>
45 45 <if test="transportType !=null and transportType !=''">
46 46 AND base.transport_type = #{transportType}
47 47 </if>
  48 + <if test="deviceProfileIds != null">
  49 + AND base.id::TEXT IN
  50 + <foreach collection="deviceProfileIds" item="id" open="(" separator="," close=")">
  51 + #{id}
  52 + </foreach>
  53 + </if>
  54 +
48 55 </where>
49 56 </select>
50 57
... ...