|
@@ -0,0 +1,177 @@
|
|
|
+package com.persagy.adm.server.custom.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
+import com.persagy.adm.server.custom.common.AdmConst;
|
|
|
+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;
|
|
|
+import com.persagy.adm.server.custom.entity.db.AdmProblem;
|
|
|
+import com.persagy.adm.server.custom.entity.db.AdmQrCode;
|
|
|
+import com.persagy.adm.server.custom.interceptor.TokenInterceptor;
|
|
|
+import com.persagy.adm.server.custom.service.ServiceUtil;
|
|
|
+import com.persagy.adm.server.custom.service.impl.offline_data_download.CriteriaUtils;
|
|
|
+import com.persagy.adm.server.custom.service.impl.offline_data_download.DownLoadDataDeal;
|
|
|
+import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
+import com.persagy.dmp.common.model.response.CommonResult;
|
|
|
+import com.persagy.dmp.common.utils.ResultHelper;
|
|
|
+import com.persagy.dmp.digital.client.DigitalObjectClient;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * APP离线数据下载接口
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/app/download")
|
|
|
+public class AppDataDownloadController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AdmProblemMapper problemMapper;
|
|
|
+ @Autowired
|
|
|
+ AdmCadMapper admCadMapper;
|
|
|
+ @Autowired
|
|
|
+ AdmFileMapper fileMapper;
|
|
|
+ @Autowired
|
|
|
+ AdmQrCodeMapper qrCodeMapper;
|
|
|
+ @Autowired
|
|
|
+ ObjectMapper objectMapper;
|
|
|
+ @Autowired
|
|
|
+ DigitalObjectClient objectClient;
|
|
|
+ @Autowired
|
|
|
+ DownLoadDataDeal downLoadDataDeal;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载问题数据
|
|
|
+ */
|
|
|
+ @GetMapping("/problems")
|
|
|
+ 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)
|
|
|
+ .eq(AdmProblem::getBuildingId, buildingId)
|
|
|
+ .gt(ts != null && ts != 0,AdmProblem::getTs, ts)
|
|
|
+ .ne(ts != null && ts != 0,AdmProblem::getModifier,CriteriaUtils.getOperator(clientId,TokenInterceptor.bossAuthUserThreadLocal.get().getId()))
|
|
|
+ .orderByDesc(AdmProblem::getModifiedTime);
|
|
|
+ List<AdmProblem> problems = problemMapper.selectList(queryWrapper);
|
|
|
+ DownLoadData<List<AdmProblem>> downLoadData = new DownLoadData<>();
|
|
|
+ downLoadData.setData(problems);
|
|
|
+
|
|
|
+ if (!problems.isEmpty()){
|
|
|
+ Long modifiedTime = problems.get(0).getTs().getTime();
|
|
|
+ downLoadData.setTs(modifiedTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResultHelper.single(downLoadData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载图纸数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/cadFiles")
|
|
|
+ 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).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<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())).orderByDesc(AdmFile::getModifiedTime);
|
|
|
+ List<AdmFile> files = fileMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ 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<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())).orderByDesc(AdmQrCode::getModifiedTime);
|
|
|
+ List<AdmQrCode> qrCodes = qrCodeMapper.selectList(queryWrapper);
|
|
|
+ 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 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());
|
|
|
+ CriteriaUtils.buildDownloadQueryCriteria(criteria,operator,ts);
|
|
|
+
|
|
|
+ // 增量数据下载
|
|
|
+ if (ts != null && ts > 0){
|
|
|
+ criteria.getCriteria().putObject("ts").put("$gt", ts);
|
|
|
+ criteria.getCriteria().putObject("modifier").put("$ne", operator);
|
|
|
+ }
|
|
|
+ criteria.getCriteria().put("buildingId", buildingId);
|
|
|
+ List<ObjectNode> objs = ServiceUtil.queryAllPage(() -> objectClient.query(groupCode, projectId, AdmConst.APP_ID, TokenInterceptor.bossAuthUserThreadLocal.get().getId(), criteria), criteria, new Pagination(500));
|
|
|
+ if (objs == null)
|
|
|
+ objs = new ArrayList<>(0);
|
|
|
+
|
|
|
+ // 处理下载数据并压缩公共字段
|
|
|
+ downLoadDataDeal.packInfos(objs);
|
|
|
+ // 填充ts
|
|
|
+ downLoadDataDeal.test4Ts(objs);
|
|
|
+ DownLoadData<List<ObjectNode>> downLoadData = new DownLoadData<>();
|
|
|
+ downLoadData.setData(objs);
|
|
|
+ downLoadData.buildDownloadTs();
|
|
|
+ return ResultHelper.single(downLoadData);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|