|
@@ -2,30 +2,102 @@ package org.jetlinks.community.device.web;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import jdk.nashorn.internal.ir.Block;
|
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
|
|
|
import org.hswebframework.web.api.crud.entity.TreeSupportEntity;
|
|
import org.hswebframework.web.api.crud.entity.TreeSupportEntity;
|
|
|
|
|
+import org.hswebframework.web.authorization.Authentication;
|
|
|
|
|
+import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
|
|
|
|
|
+import org.hswebframework.web.exception.BusinessException;
|
|
|
import org.jetlinks.community.device.entity.DeviceCategory;
|
|
import org.jetlinks.community.device.entity.DeviceCategory;
|
|
|
|
|
+import org.jetlinks.community.device.entity.DeviceInstanceEntity;
|
|
|
|
|
+import org.jetlinks.community.device.service.DeviceCategoryService;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.util.StreamUtils;
|
|
import org.springframework.util.StreamUtils;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+import reactor.core.Disposable;
|
|
|
import reactor.core.publisher.Flux;
|
|
import reactor.core.publisher.Flux;
|
|
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/device/category")
|
|
@RequestMapping("/device/category")
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
|
|
+@AllArgsConstructor
|
|
|
@Tag(name = "设备分类目录")
|
|
@Tag(name = "设备分类目录")
|
|
|
-public class DeviceCategoryController {
|
|
|
|
|
|
|
+public class DeviceCategoryController{
|
|
|
|
|
|
|
|
|
|
|
|
|
- static List<DeviceCategory> statics;
|
|
|
|
|
|
|
+ private final DeviceCategoryService service;
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/add")
|
|
|
|
|
+ @Operation(summary = "添加目录")
|
|
|
|
|
+ public Mono<?> add(@RequestBody Mono<DeviceCategory> payload){
|
|
|
|
|
+ return this.service.insert(payload)
|
|
|
|
|
+ .thenReturn(payload)
|
|
|
|
|
+ .onErrorMap(e->new BusinessException("服务器繁忙,请稍后重试",e));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @DeleteMapping("/{id}")
|
|
|
|
|
+ @Operation(summary = "删除目录")
|
|
|
|
|
+ public Mono<?> remove(@PathVariable @Parameter(description = "设备ID") String id){
|
|
|
|
|
+ return this.service.createDelete()
|
|
|
|
|
+ .where(DeviceCategory::getId,id)
|
|
|
|
|
+ .execute()
|
|
|
|
|
+ .then();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping
|
|
|
|
|
+ @Operation(summary = "更新目录")
|
|
|
|
|
+ public Mono<?> updata(@RequestBody Mono<DeviceCategory> payload){
|
|
|
|
|
+ return payload.flatMap(data->
|
|
|
|
|
+ this.service.createUpdate()
|
|
|
|
|
+ .set(data)
|
|
|
|
|
+ .where(DeviceCategory::getId,data.getId())
|
|
|
|
|
+ .execute()
|
|
|
|
|
+ .then()
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/{id}/detail")
|
|
|
|
|
+ @Operation(summary = "目录详情")
|
|
|
|
|
+ public Mono<?> detail(@PathVariable @Parameter(description = "设备ID") String id){
|
|
|
|
|
+ return this.service.createQuery()
|
|
|
|
|
+ .where(DeviceCategory::getId,id)
|
|
|
|
|
+ .fetchOne();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping
|
|
|
|
|
+ @Operation(summary = "获取全部分类目录")
|
|
|
|
|
+ public Flux<DeviceCategory> getAllCategory() {
|
|
|
|
|
+ return this.service.createQuery()
|
|
|
|
|
+ .fetch();
|
|
|
|
|
+ // return Flux.fromIterable(statics);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/_tree")
|
|
|
|
|
+ @Operation(summary = "获取全部分类目录(树结构)")
|
|
|
|
|
+ public Flux<DeviceCategory> getAllCategoryTree() {
|
|
|
|
|
+ return this.service
|
|
|
|
|
+ .createQuery()
|
|
|
|
|
+ .fetch()
|
|
|
|
|
+ .collectList()
|
|
|
|
|
+ .flatMapMany(data->{
|
|
|
|
|
+ return Flux.fromIterable(TreeSupportEntity.list2tree(data, DeviceCategory::setChildren));
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ static List<DeviceCategory> statics;
|
|
|
|
|
|
|
|
static void rebuild(String parentId, List<DeviceCategory> children) {
|
|
static void rebuild(String parentId, List<DeviceCategory> children) {
|
|
|
if (children == null) {
|
|
if (children == null) {
|
|
@@ -63,16 +135,5 @@ public class DeviceCategoryController {
|
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- @GetMapping
|
|
|
|
|
- @Operation(summary = "获取全部分类目录")
|
|
|
|
|
- public Flux<DeviceCategory> getAllCategory() {
|
|
|
|
|
- return Flux.fromIterable(statics);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @GetMapping("/_tree")
|
|
|
|
|
- @Operation(summary = "获取全部分类目录(树结构)")
|
|
|
|
|
- public Flux<DeviceCategory> getAllCategoryTree() {
|
|
|
|
|
- return Flux.fromIterable(TreeSupportEntity.list2tree(statics, DeviceCategory::setChildren));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ */
|
|
|
}
|
|
}
|