Browse Source

APP数据下载接口拆分

yanguofeng 2 years ago
parent
commit
a099b3cac8

+ 48 - 14
adm-business/adm-server/src/main/java/com/persagy/adm/server/custom/controller/AppDataDownloadController.java

@@ -9,6 +9,7 @@ import com.persagy.adm.server.custom.dao.AdmCadMapper;
 import com.persagy.adm.server.custom.dao.AdmFileMapper;
 import com.persagy.adm.server.custom.dao.AdmProblemMapper;
 import com.persagy.adm.server.custom.dao.AdmQrCodeMapper;
+import com.persagy.adm.server.custom.dto.DownLoadData;
 import com.persagy.adm.server.custom.entity.Pagination;
 import com.persagy.adm.server.custom.entity.db.AdmCad;
 import com.persagy.adm.server.custom.entity.db.AdmFile;
@@ -57,7 +58,7 @@ public class AppDataDownloadController {
      * 下载问题数据
      */
     @GetMapping("/problems")
-    public CommonResult<List<AdmProblem>> problems(@RequestParam String groupCode,@RequestParam String projectId,@RequestParam String buildingId, @RequestParam(required = false) Long ts, @RequestParam String clientId){
+    public CommonResult<DownLoadData<List<AdmProblem>>> problems(@RequestParam String groupCode,@RequestParam String projectId,@RequestParam String buildingId, @RequestParam(required = false) Long ts, @RequestParam String clientId){
         LambdaQueryWrapper<AdmProblem> queryWrapper = new LambdaQueryWrapper<AdmProblem>()
                 .eq(AdmProblem::getGroupCode, groupCode)
                 .eq(AdmProblem::getProjectId, projectId)
@@ -66,58 +67,88 @@ public class AppDataDownloadController {
                 .ne(ts != null && ts != 0,AdmProblem::getModifier,CriteriaUtils.getOperator(clientId,TokenInterceptor.bossAuthUserThreadLocal.get().getId()))
                 .orderByDesc(AdmProblem::getModifiedTime);
         List<AdmProblem> problems = problemMapper.selectList(queryWrapper);
-        Long modifiedTime = problems.get(0).getTs().getTime();
+        DownLoadData<List<AdmProblem>> downLoadData = new DownLoadData<>();
+        downLoadData.setData(problems);
 
-        return ResultHelper.multi(problems);
+        if (!problems.isEmpty()){
+            Long modifiedTime = problems.get(0).getTs().getTime();
+            downLoadData.setTs(modifiedTime);
+        }
+
+        return ResultHelper.single(downLoadData);
     }
 
     /**
      * 下载图纸数据
+     * @return
      */
     @GetMapping("/cadFiles")
-    public CommonResult<List<AdmCad>> cadFiles(@RequestParam String groupCode,@RequestParam String projectId,@RequestParam String buildingId,@RequestParam(required = false) Long ts){
+    public CommonResult<DownLoadData<List<AdmCad>>> cadFiles(@RequestParam String groupCode, @RequestParam String projectId, @RequestParam String buildingId, @RequestParam(required = false) Long ts){
         List<AdmCad> admCads = admCadMapper.selectList(new LambdaQueryWrapper<AdmCad>()
                 .eq(AdmCad::getGroupCode,groupCode)
                 .eq(AdmCad::getProjectId,projectId)
                 .eq(AdmCad::getBuildingId,buildingId)
-                .gt(ts != null && ts != 0,AdmCad::getTs,ts));
-        return ResultHelper.multi(admCads);
+                .gt(ts != null && ts != 0,AdmCad::getTs,ts).orderByDesc(AdmCad::getModifiedTime));
+        DownLoadData<List<AdmCad>> downLoadData = new DownLoadData<>();
+        downLoadData.setData(admCads);
+        if (!admCads.isEmpty()){
+            Long modifiedTime = admCads.get(0).getTs().getTime();
+            downLoadData.setTs(modifiedTime);
+        }
+        return ResultHelper.single(downLoadData);
     }
     /**
      * 下载附件现场照片数据
+     * @return
      */
     @GetMapping("/files")
-    public CommonResult<List<AdmFile>> attachmentsFiles(@RequestParam String groupCode,@RequestParam String projectId,@RequestParam String buildingId, @RequestParam(required = false) Long ts, @RequestParam String clientId){
+    public CommonResult<DownLoadData<List<AdmFile>>> attachmentsFiles(@RequestParam String groupCode, @RequestParam String projectId, @RequestParam String buildingId, @RequestParam(required = false) Long ts, @RequestParam String clientId){
         LambdaQueryWrapper<AdmFile> queryWrapper = Wrappers.lambdaQuery(AdmFile.class)
                 .eq(AdmFile::getGroupCode,groupCode)
                 .eq(AdmFile::getProjectId,projectId)
                 .eq(AdmFile::getBuildingId,buildingId)
                 .gt(ts != null && ts != 0 ,AdmFile::getTs,ts)
-                .ne(ts != null && ts != 0 ,AdmFile::getModifier, CriteriaUtils.getOperator(clientId,TokenInterceptor.bossAuthUserThreadLocal.get().getId()));
+                .ne(ts != null && ts != 0 ,AdmFile::getModifier, CriteriaUtils.getOperator(clientId,TokenInterceptor.bossAuthUserThreadLocal.get().getId())).orderByDesc(AdmFile::getModifiedTime);
         List<AdmFile> files = fileMapper.selectList(queryWrapper);
-        return ResultHelper.multi(files);
+
+        DownLoadData<List<AdmFile>> downLoadData = new DownLoadData<>();
+        downLoadData.setData(files);
+        if (!files.isEmpty()){
+            Long modifiedTime = files.get(0).getTs().getTime();
+            downLoadData.setTs(modifiedTime);
+        }
+        return ResultHelper.single(downLoadData);
+
     }
     /**
      * 二维码数据
+     * @return
      */
     @GetMapping("/qrCodes")
-    public CommonResult<List<AdmQrCode>> qrCodes(@RequestParam String groupCode,@RequestParam String projectId,@RequestParam String buildingId, @RequestParam(required = false) Long ts, @RequestParam String clientId){
+    public CommonResult<DownLoadData<List<AdmQrCode>>> qrCodes(@RequestParam String groupCode, @RequestParam String projectId, @RequestParam String buildingId, @RequestParam(required = false) Long ts, @RequestParam String clientId){
         LambdaQueryWrapper<AdmQrCode> queryWrapper = Wrappers.lambdaQuery(AdmQrCode.class)
                 .eq(AdmQrCode::getGroupCode,groupCode)
                 .eq(AdmQrCode::getProjectId,projectId)
                 .eq(AdmQrCode::getBuildingId,buildingId)
                 .gt(ts != null && ts != 0 ,AdmQrCode::getTs,ts)
-                .ne(ts != null && ts != 0 ,AdmQrCode::getModifier,CriteriaUtils.getOperator(clientId,TokenInterceptor.bossAuthUserThreadLocal.get().getId()));
+                .ne(ts != null && ts != 0 ,AdmQrCode::getModifier,CriteriaUtils.getOperator(clientId,TokenInterceptor.bossAuthUserThreadLocal.get().getId())).orderByDesc(AdmQrCode::getModifiedTime);
         List<AdmQrCode> qrCodes = qrCodeMapper.selectList(queryWrapper);
-        return ResultHelper.multi(qrCodes);
+        DownLoadData<List<AdmQrCode>> downLoadData = new DownLoadData<>();
+        downLoadData.setData(qrCodes);
+        if (!qrCodes.isEmpty()){
+            Long modifiedTime = qrCodes.get(0).getTs().getTime();
+            downLoadData.setTs(modifiedTime);
+        }
+        return ResultHelper.single(downLoadData);
     }
 
 
     /**
      * 对象数据
+     * @return
      */
     @GetMapping("/objects")
-    public Object objects(@RequestParam String groupCode,@RequestParam String projectId,@RequestParam String buildingId, @RequestParam(required = false) Long ts, @RequestParam String clientId){
+    public CommonResult<DownLoadData<List<ObjectNode>>> objects(@RequestParam String groupCode, @RequestParam String projectId, @RequestParam String buildingId, @RequestParam(required = false) Long ts, @RequestParam String clientId){
         //从bdtp下载对象(空间、竖井、系统、设备、元空间)
         QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, AdmConst.OBJ_TYPE_SPACE, AdmConst.OBJ_TYPE_SHAFT, AdmConst.OBJ_TYPE_SYSTEM, AdmConst.OBJ_TYPE_EQUIPMENT, AdmConst.OBJ_TYPE_ISPACE);
         String operator = CriteriaUtils.getOperator(clientId, TokenInterceptor.bossAuthUserThreadLocal.get().getId());
@@ -137,7 +168,10 @@ public class AppDataDownloadController {
         downLoadDataDeal.packInfos(objs);
         // 填充ts
         downLoadDataDeal.test4Ts(objs);
-        return ResultHelper.multi(objs);
+        DownLoadData<List<ObjectNode>> downLoadData = new DownLoadData<>();
+        downLoadData.setData(objs);
+        downLoadData.buildDownloadTs();
+        return ResultHelper.single(downLoadData);
     }
 
 }

+ 62 - 0
adm-business/adm-server/src/main/java/com/persagy/adm/server/custom/dto/DownLoadData.java

@@ -0,0 +1,62 @@
+package com.persagy.adm.server.custom.dto;
+
+import cn.hutool.core.collection.CollUtil;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.adm.server.custom.entity.db.BaseAdmDataEntity;
+import com.persagy.dmp.common.model.entity.AuditableEntity;
+import com.persagy.dmp.common.model.entity.BaseEntity;
+import com.persagy.dmp.digital.entity.ObjectRelation;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class DownLoadData<T> {
+
+    private Long ts;
+    private T data;
+
+    public void buildDownloadTs() {
+        long ts = getMaxTs();
+        if(ts > 0)
+            this.ts = ts;
+    }
+
+    protected long getMaxTs() {
+        if(data instanceof List){
+            List<?> list = (List<?>) data;
+            long maxTs = -1;
+            maxTs = max(list, maxTs);
+            return maxTs;
+        }
+        return 0;
+    }
+
+
+    private long max(List<?> list, long maxTs) {
+        if(CollUtil.isNotEmpty(list)) {
+            for (Object data : list) {
+                long ts = -1;
+                if(data instanceof BaseAdmDataEntity) {
+                    if(((BaseAdmDataEntity) data).getTs() != null )
+                        ts = ((BaseAdmDataEntity) data).getTs().getTime();
+                } else if(data instanceof ObjectNode){
+                    if(((ObjectNode) data).get("ts") != null)
+                        ts = ((ObjectNode) data).get("ts").asLong();
+                } else if (data instanceof AuditableEntity){
+                    Date ts1 = ((AuditableEntity) data).getTs();
+                    if (ts1 != null){
+                        ts = ts1.getTime();
+                    }
+                } else if(data instanceof BaseEntity) {
+                    if(((ObjectRelation) data).getTs() != null)
+                        ts = ((ObjectRelation) data).getTs().getTime();
+                }
+                if(ts > maxTs)
+                    maxTs = ts;
+            }
+        }
+        return maxTs;
+    }
+}

+ 2 - 1
adm-business/adm-server/src/main/resources/db/init/schema.sql

@@ -220,7 +220,8 @@ CREATE TABLE IF NOT EXISTS `adm_problem`  (
   `type_code` varchar(20) NOT NULL COMMENT '问题类型编码',
   `type_name` varchar(40) NOT NULL COMMENT '问题类型名称',
   `info` json NULL COMMENT '问题描述',
-  `state` tinyint(0) NOT NULL COMMENT '建筑结构核查任务状态(1:有效;2:已解决)',
+  `status` tinyint(0) NOT NULL COMMENT '建筑结构核查任务状态(1:有效;2:已解决)',
+  `remark` varchar(255) DEFAULT NULL COMMENT '备注',
   `creator` varchar(32) NULL DEFAULT NULL COMMENT '创建人',
   `creation_time` char(14) NULL DEFAULT NULL COMMENT '创建时间',
   `modifier` varchar(32) NULL DEFAULT NULL COMMENT '最后修改人',