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