瀏覽代碼

机构类型

TRX 1 年之前
父節點
當前提交
18e04e8b8f

+ 8 - 0
src/main/java/com/zswl/dataservice/controller/user/ProjectInfoController.java

@@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 /**
  * 项目 服务
  *
@@ -61,4 +63,10 @@ public class ProjectInfoController {
     public ResultContent<ProjectInfoModel> getProjectInfo(String id) {
         return projectInfoService.getProjectInfo(id);
     }
+
+    @Operation(summary = "查询所有可用的项目列表")
+    @RequestMapping(value = "getAllProject", method = {RequestMethod.GET})
+    public ResultContent<List<ProjectInfoModel>> getAllProject() {
+        return projectInfoService.getAllProject();
+    }
 }

+ 3 - 0
src/main/java/com/zswl/dataservice/dao/mqtt/ProjectInfoDao.java

@@ -5,6 +5,7 @@ import com.zswl.dataservice.dao.mqtt.extend.DeviceInfoDaoExtend;
 import com.zswl.dataservice.dao.mqtt.extend.ProjectInfoDaoExtend;
 import com.zswl.dataservice.domain.mqtt.DeviceInfo;
 import com.zswl.dataservice.domain.mqtt.ProjectInfo;
+import com.zswl.dataservice.utils.mqtt.type.CommonState;
 
 import java.util.List;
 
@@ -19,4 +20,6 @@ public interface ProjectInfoDao extends MongoDao<ProjectInfo>, ProjectInfoDaoExt
     ProjectInfo findTopByCode(String code);
 
     List<ProjectInfo> findByIdIn(List<String> ids);
+
+    List<ProjectInfo> findByStateOrderByCreateTimeDesc(CommonState state);
 }

+ 6 - 0
src/main/java/com/zswl/dataservice/service/iot/IotServiceImpl.java

@@ -147,6 +147,12 @@ public class IotServiceImpl extends SuperService {
         return ResultContent.buildSuccess(toModel(entity));
     }
 
+    /**
+     * 分页查询 模版的Topic管理数据
+     * @param pageable
+     * @param param
+     * @return
+     */
     public ResultContent<Page<IotTopicModel>> pageIotTopic(Pageable pageable, IotTopicSearch param) {
         initSearchParam(param);
         Page<IotTopic> page = iotTopicDao.page(pageable, param);

+ 18 - 0
src/main/java/com/zswl/dataservice/service/mqtt/ProjectInfoService.java

@@ -16,6 +16,10 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * @author TRX
  * @date 2024/5/21
@@ -71,6 +75,20 @@ public class ProjectInfoService {
         return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
     }
 
+    /**
+     * 得到所有可用的项目
+     *
+     * @return
+     */
+    public ResultContent<List<ProjectInfoModel>> getAllProject() {
+        List<ProjectInfoModel> models = new ArrayList<>();
+        List<ProjectInfo> list = projectInfoDao.findByStateOrderByCreateTimeDesc(CommonState.Enable);
+        if (ObjectUtils.isNotEmpty(list)) {
+            models = list.stream().map(this::toModel).collect(Collectors.toList());
+        }
+        return ResultContent.buildSuccess(models);
+    }
+
     public ResultContent deleteProjectInfo(String id) {
         ProjectInfo projectInfo = projectInfoDao.findTopById(id);
         if (ObjectUtils.isEmpty(projectInfo)) {