Showing
5 changed files
with
108 additions
and
10 deletions
@@ -28,10 +28,7 @@ import org.thingsboard.server.controller.BaseController; | @@ -28,10 +28,7 @@ import org.thingsboard.server.controller.BaseController; | ||
28 | import org.thingsboard.server.dao.yunteng.service.TkDataViewInterfaceService; | 28 | import org.thingsboard.server.dao.yunteng.service.TkDataViewInterfaceService; |
29 | import org.thingsboard.server.service.security.model.SecurityUser; | 29 | import org.thingsboard.server.service.security.model.SecurityUser; |
30 | 30 | ||
31 | -import java.util.ArrayList; | ||
32 | -import java.util.HashMap; | ||
33 | -import java.util.List; | ||
34 | -import java.util.Set; | 31 | +import java.util.*; |
35 | 32 | ||
36 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | 33 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
37 | 34 | ||
@@ -144,7 +141,7 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -144,7 +141,7 @@ public class TkDataViewInterfaceController extends BaseController { | ||
144 | @ApiOperation("根据接口类型过滤数据") | 141 | @ApiOperation("根据接口类型过滤数据") |
145 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 142 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
146 | public List<TkDataViewInterfaceDTO> filterByInterfaceType(@PathVariable("type") String type) throws ThingsboardException { | 143 | public List<TkDataViewInterfaceDTO> filterByInterfaceType(@PathVariable("type") String type) throws ThingsboardException { |
147 | - return tkDataViewInterfaceService.filterByInterfaceType(type,getCurrentUser().getCurrentTenantId()); | 144 | + return tkDataViewInterfaceService.filterByInterfaceType(type, getCurrentUser().getCurrentTenantId()); |
148 | } | 145 | } |
149 | 146 | ||
150 | 147 | ||
@@ -155,4 +152,42 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -155,4 +152,42 @@ public class TkDataViewInterfaceController extends BaseController { | ||
155 | return tkDataViewInterfaceService.findAll(getCurrentUser().getCurrentTenantId()); | 152 | return tkDataViewInterfaceService.findAll(getCurrentUser().getCurrentTenantId()); |
156 | } | 153 | } |
157 | 154 | ||
155 | + | ||
156 | + @ApiOperation("批量发布") | ||
157 | + @RequestMapping(value = "/batch_publish", params = {"ids"}, method = RequestMethod.PUT) | ||
158 | + @ResponseBody | ||
159 | + public ResponseEntity<Boolean> batchPublishInterface( | ||
160 | + @ApiParam(value = "A list of interface ids, separated by comma ','") | ||
161 | + @RequestParam("ids") String[] ids) throws ThingsboardException { | ||
162 | + | ||
163 | + List<String> idsList = new ArrayList<>(); | ||
164 | + for (String strId : ids) { | ||
165 | + idsList.add(strId); | ||
166 | + } | ||
167 | + return ResponseEntity.ok(tkDataViewInterfaceService.batchPublishInterface(idsList, getCurrentUser().getCurrentTenantId())); | ||
168 | + } | ||
169 | + | ||
170 | + @ApiOperation("批量取消发布") | ||
171 | + @RequestMapping(value = "/batch_cancel_publish", params = {"ids"}, method = RequestMethod.PUT) | ||
172 | + @ResponseBody | ||
173 | + public ResponseEntity<Boolean> batchCancelPublishInterface( | ||
174 | + @ApiParam(value = "A list of interface ids, separated by comma ','") | ||
175 | + @RequestParam("ids") String[] ids) throws ThingsboardException { | ||
176 | + | ||
177 | + List<String> idsList = new ArrayList<>(); | ||
178 | + for (String strId : ids) { | ||
179 | + idsList.add(strId); | ||
180 | + } | ||
181 | + return ResponseEntity.ok(tkDataViewInterfaceService.batchCancelPublishInterface(idsList, getCurrentUser().getCurrentTenantId())); | ||
182 | + } | ||
183 | + | ||
184 | + | ||
185 | +// @ApiOperation("SQL查询") | ||
186 | +// @RequestMapping(value = "/sql_select", params = {"sql"}, method = RequestMethod.POST) | ||
187 | +// @ResponseBody | ||
188 | +// public List<LinkedHashMap<String, Object>> sqlSelect( | ||
189 | +// @RequestParam("sql") String sql) throws ThingsboardException { | ||
190 | +// return tkDataViewInterfaceService.executeSql(sql); | ||
191 | +// } | ||
192 | + | ||
158 | } | 193 | } |
@@ -125,7 +125,7 @@ public class TkDataViewInterfaceServiceImpl | @@ -125,7 +125,7 @@ public class TkDataViewInterfaceServiceImpl | ||
125 | //Modify interface state is publish | 125 | //Modify interface state is publish |
126 | dataViewInterfaceEntity.setState(1); | 126 | dataViewInterfaceEntity.setState(1); |
127 | int resultInt = baseMapper.updateById(dataViewInterfaceEntity); | 127 | int resultInt = baseMapper.updateById(dataViewInterfaceEntity); |
128 | - return resultInt > 0 ? true : false; | 128 | + return resultInt > 0 ; |
129 | } | 129 | } |
130 | 130 | ||
131 | @Override | 131 | @Override |
@@ -137,7 +137,7 @@ public class TkDataViewInterfaceServiceImpl | @@ -137,7 +137,7 @@ public class TkDataViewInterfaceServiceImpl | ||
137 | //Modify interface state is cancelPublish | 137 | //Modify interface state is cancelPublish |
138 | dataViewInterfaceEntity.setState(0); | 138 | dataViewInterfaceEntity.setState(0); |
139 | int resultInt = baseMapper.updateById(dataViewInterfaceEntity); | 139 | int resultInt = baseMapper.updateById(dataViewInterfaceEntity); |
140 | - return resultInt > 0 ? true : false; | 140 | + return resultInt > 0 ; |
141 | } | 141 | } |
142 | 142 | ||
143 | @Override | 143 | @Override |
@@ -164,4 +164,50 @@ public class TkDataViewInterfaceServiceImpl | @@ -164,4 +164,50 @@ public class TkDataViewInterfaceServiceImpl | ||
164 | return lists; | 164 | return lists; |
165 | } | 165 | } |
166 | 166 | ||
167 | + | ||
168 | + @Override | ||
169 | + public boolean batchPublishInterface(List<String> ids, String tenantId) { | ||
170 | + List<TkDataViewInterfaceEntity> interfaceEntityList = | ||
171 | + baseMapper.selectList( | ||
172 | + new LambdaQueryWrapper<TkDataViewInterfaceEntity>() | ||
173 | + .in(TkDataViewInterfaceEntity::getId, ids)); | ||
174 | + for (TkDataViewInterfaceEntity center : interfaceEntityList) { | ||
175 | + if (!center.getTenantId().equals(tenantId)) { | ||
176 | + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage()); | ||
177 | + } | ||
178 | + } | ||
179 | + int resultInt = 0; | ||
180 | + for (TkDataViewInterfaceEntity interfaceEntity : interfaceEntityList) { | ||
181 | + interfaceEntity.setState(1); | ||
182 | + resultInt+=baseMapper.updateById(interfaceEntity); | ||
183 | + } | ||
184 | + return resultInt>0; | ||
185 | + } | ||
186 | + | ||
187 | + | ||
188 | + @Override | ||
189 | + public boolean batchCancelPublishInterface(List<String> ids, String tenantId) { | ||
190 | + List<TkDataViewInterfaceEntity> interfaceEntityList = | ||
191 | + baseMapper.selectList( | ||
192 | + new LambdaQueryWrapper<TkDataViewInterfaceEntity>() | ||
193 | + .in(TkDataViewInterfaceEntity::getId, ids)); | ||
194 | + for (TkDataViewInterfaceEntity center : interfaceEntityList) { | ||
195 | + if (!center.getTenantId().equals(tenantId)) { | ||
196 | + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage()); | ||
197 | + } | ||
198 | + } | ||
199 | + int resultInt = 0; | ||
200 | + for (TkDataViewInterfaceEntity interfaceEntity : interfaceEntityList) { | ||
201 | + interfaceEntity.setState(0); | ||
202 | + resultInt+=baseMapper.updateById(interfaceEntity); | ||
203 | + } | ||
204 | + return resultInt>0; | ||
205 | + } | ||
206 | + | ||
207 | + @Override | ||
208 | + public List<LinkedHashMap<String, Object>> executeSql(String sql){ | ||
209 | + List<LinkedHashMap<String, Object>> resultList = baseMapper.executeSql(sql); | ||
210 | + return resultList; | ||
211 | + } | ||
212 | + | ||
167 | } | 213 | } |
@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param; | @@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param; | ||
6 | import org.thingsboard.server.common.data.yunteng.dto.TkDataViewInterfaceDTO; | 6 | import org.thingsboard.server.common.data.yunteng.dto.TkDataViewInterfaceDTO; |
7 | import org.thingsboard.server.dao.yunteng.entities.TkDataViewInterfaceEntity; | 7 | import org.thingsboard.server.dao.yunteng.entities.TkDataViewInterfaceEntity; |
8 | 8 | ||
9 | +import java.util.LinkedHashMap; | ||
9 | import java.util.List; | 10 | import java.util.List; |
10 | 11 | ||
11 | /** | 12 | /** |
@@ -36,4 +37,11 @@ public interface TkDataViewInterfaceMapper extends BaseMapper<TkDataViewInterfac | @@ -36,4 +37,11 @@ public interface TkDataViewInterfaceMapper extends BaseMapper<TkDataViewInterfac | ||
36 | */ | 37 | */ |
37 | List<TkDataViewInterfaceDTO> findAll(@Param("tenantIds") List<String> tenantIds); | 38 | List<TkDataViewInterfaceDTO> findAll(@Param("tenantIds") List<String> tenantIds); |
38 | 39 | ||
40 | + /** | ||
41 | + * SQL 查询 | ||
42 | + * @param sqlStr | ||
43 | + * @return | ||
44 | + */ | ||
45 | + List<LinkedHashMap<String, Object>> executeSql(@Param("sqlStr") String sqlStr); | ||
46 | + | ||
39 | } | 47 | } |
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.yunteng.dto.DeleteDTO; | 3 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
4 | -import org.thingsboard.server.common.data.yunteng.dto.TkDataViewDTO; | ||
5 | import org.thingsboard.server.common.data.yunteng.dto.TkDataViewInterfaceDTO; | 4 | import org.thingsboard.server.common.data.yunteng.dto.TkDataViewInterfaceDTO; |
6 | -import org.thingsboard.server.common.data.yunteng.dto.request.TkDataViewContentInfoDTO; | ||
7 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 5 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
8 | - | 6 | +import java.util.LinkedHashMap; |
9 | import java.util.List; | 7 | import java.util.List; |
10 | import java.util.Map; | 8 | import java.util.Map; |
11 | 9 | ||
@@ -32,4 +30,10 @@ public interface TkDataViewInterfaceService { | @@ -32,4 +30,10 @@ public interface TkDataViewInterfaceService { | ||
32 | 30 | ||
33 | List<TkDataViewInterfaceDTO> findAll(String tenantId); | 31 | List<TkDataViewInterfaceDTO> findAll(String tenantId); |
34 | 32 | ||
33 | + boolean batchPublishInterface(List<String> ids, String tenantId); | ||
34 | + | ||
35 | + boolean batchCancelPublishInterface(List<String> ids, String tenantId); | ||
36 | + | ||
37 | + List<LinkedHashMap<String, Object>> executeSql(String sql); | ||
38 | + | ||
35 | } | 39 | } |