Commit 68a844f97a0ee0bd6d793d242edc6f24330f012c
Merge branch '2023-12-27' into 'master_dev'
fix:报表导出列表查询增加根据客户分配设备过滤 See merge request yunteng/thingskit!300
Showing
2 changed files
with
23 additions
and
5 deletions
... | ... | @@ -68,6 +68,9 @@ public class TkReportGenerateRecordController extends BaseController { |
68 | 68 | queryMap.put(ORDER_TYPE, orderType.name()); |
69 | 69 | } |
70 | 70 | queryMap.put("userId", getCurrentUser().getCurrentUserId()); |
71 | + if(getCurrentUser().isCustomerUser()){ | |
72 | + queryMap.put("customerId", getCurrentUser().getCustomerId().toString()); | |
73 | + } | |
71 | 74 | return reportFormGenerateRecordService.page(queryMap, getCurrentUser().isTenantAdmin()); |
72 | 75 | } |
73 | 76 | ... | ... |
... | ... | @@ -3,6 +3,7 @@ package org.thingsboard.server.dao.yunteng.impl; |
3 | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | 5 | import com.fasterxml.jackson.databind.JsonNode; |
6 | +import com.fasterxml.jackson.databind.node.ArrayNode; | |
6 | 7 | import com.fasterxml.jackson.databind.node.ObjectNode; |
7 | 8 | import com.google.common.util.concurrent.FutureCallback; |
8 | 9 | import com.google.common.util.concurrent.Futures; |
... | ... | @@ -34,11 +35,9 @@ import org.thingsboard.server.common.data.yunteng.utils.ExcelUtil; |
34 | 35 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
35 | 36 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
36 | 37 | import org.thingsboard.server.dao.yunteng.entities.TkReportGenerateRecordEntity; |
38 | +import org.thingsboard.server.dao.yunteng.mapper.DeviceMapper; | |
37 | 39 | import org.thingsboard.server.dao.yunteng.mapper.ReportGenerateRecordMapper; |
38 | -import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
39 | -import org.thingsboard.server.dao.yunteng.service.UserOrganizationMappingService; | |
40 | -import org.thingsboard.server.dao.yunteng.service.TkOrganizationService; | |
41 | -import org.thingsboard.server.dao.yunteng.service.TkReportGenerateRecordService; | |
40 | +import org.thingsboard.server.dao.yunteng.service.*; | |
42 | 41 | |
43 | 42 | import java.io.ByteArrayInputStream; |
44 | 43 | import java.io.ByteArrayOutputStream; |
... | ... | @@ -64,6 +63,7 @@ public class TkReportGenerateRecordServiceImpl |
64 | 63 | private final TimeseriesService tsService; |
65 | 64 | private final FileStorageService fileStorageService; |
66 | 65 | private final UserOrganizationMappingService userOrganizationMappingService; |
66 | + private final DeviceMapper deviceMapper; | |
67 | 67 | private volatile HashMap<String,List<CustomDataForExcelDTO>> excelReportMap = new HashMap<>(); |
68 | 68 | |
69 | 69 | @Override |
... | ... | @@ -80,7 +80,8 @@ public class TkReportGenerateRecordServiceImpl |
80 | 80 | .map(obj -> Integer.valueOf(obj.toString())) |
81 | 81 | .orElse(null); |
82 | 82 | List<String> organizationIds = null; |
83 | - if (!tenantAdmin && null != queryMap.get("userId")) { | |
83 | + boolean isCustomer =!tenantAdmin && null != queryMap.get("userId"); | |
84 | + if (isCustomer) { | |
84 | 85 | organizationIds = |
85 | 86 | userOrganizationMappingService.getOrganizationIdsByUserId( |
86 | 87 | queryMap.get("userId").toString()); |
... | ... | @@ -107,6 +108,20 @@ public class TkReportGenerateRecordServiceImpl |
107 | 108 | organizationIds != null && organizationIds.size() > 0, |
108 | 109 | TkReportGenerateRecordEntity::getOrganizationId, |
109 | 110 | organizationIds)); |
111 | + | |
112 | + if (isCustomer) { | |
113 | + List<TkReportGenerateRecordEntity> list = iPage.getRecords(); | |
114 | + List<String> deviceIds = deviceMapper.findDeviceIdsByCustomerId(queryMap.get("customerId").toString()); | |
115 | + list.forEach(entity -> { | |
116 | + ArrayNode exes = (ArrayNode) entity.getExecuteCondition().path("executeAttributes"); | |
117 | + for (int i = 0; i < exes.size(); i++) { | |
118 | + if(!deviceIds.contains(exes.get(i).get("device").asText())){ | |
119 | + exes.remove(i); | |
120 | + i--; | |
121 | + } | |
122 | + } | |
123 | + }); | |
124 | + } | |
110 | 125 | return getPageData(iPage, ReportGenerateRecordDTO.class); |
111 | 126 | } |
112 | 127 | ... | ... |