|
@@ -6,26 +6,23 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
-import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
-import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.bdtp.adm.client.DicClient;
|
|
|
import com.persagy.bdtp.adm.client.RwdClient;
|
|
|
import com.persagy.bdtp.adm.common.AdmConst;
|
|
|
-import com.persagy.bdtp.adm.common.AdmResult;
|
|
|
import com.persagy.bdtp.adm.dao.*;
|
|
|
import com.persagy.bdtp.adm.entity.*;
|
|
|
-import com.persagy.bdtp.adm.entity.oldadm.OProject;
|
|
|
+import com.persagy.bdtp.adm.entity.db.*;
|
|
|
import com.persagy.bdtp.adm.service.*;
|
|
|
+import com.persagy.bdtp.adm.util.DataExtrasUtil;
|
|
|
import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
-import com.persagy.dmp.common.constant.ResponseCode;
|
|
|
import com.persagy.dmp.common.constant.ValidEnum;
|
|
|
-import com.persagy.dmp.common.helper.SpringHelper;
|
|
|
import com.persagy.dmp.common.model.response.CommonResult;
|
|
|
-import com.persagy.dmp.define.entity.ObjectInfoDefine;
|
|
|
import com.persagy.dmp.define.entity.RelationDefine;
|
|
|
+import com.persagy.dmp.digital.client.DigitalObjectClient;
|
|
|
+import com.persagy.dmp.digital.client.DigitalRelationClient;
|
|
|
+import com.persagy.dmp.digital.entity.ObjectRelation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -37,26 +34,22 @@ import java.util.function.Supplier;
|
|
|
public class SyncAppImpl implements ISyncApp {
|
|
|
|
|
|
@Autowired
|
|
|
- private IAdmObjectService objectService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IQueryFromOldAdm queryOldAdm;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private RwdClient rwdClient;
|
|
|
|
|
|
@Autowired
|
|
|
private DicClient dicClient;
|
|
|
|
|
|
@Autowired
|
|
|
- private IConfigService configService;
|
|
|
+ private DigitalObjectClient objectClient;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DigitalRelationClient relationClient;
|
|
|
|
|
|
@Autowired
|
|
|
- private AdmObjectMapper admObjMapper;
|
|
|
+ private AdmClientFlagMapper clientFlagMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private AdmRelationMapper relationMapper;
|
|
|
+ private IConfigService configService;
|
|
|
|
|
|
@Autowired
|
|
|
private AdmPipeMapper pipeMapper;
|
|
@@ -88,108 +81,48 @@ public class SyncAppImpl implements ISyncApp {
|
|
|
@Autowired
|
|
|
private IAdmLogService logService;
|
|
|
|
|
|
-// @Autowired
|
|
|
-// ResourceLoader resourceLoader;
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
- public Map<String, Object> downloadDict(String groupCode, String projectId, String userId) {
|
|
|
+ public Dict downloadDict(String groupCode, String projectId, String userId) {
|
|
|
return queryDict(groupCode, projectId, userId, true, true);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> downloadConfig(String groupCode, String projectId, String userId) {
|
|
|
- //配置数据查询
|
|
|
- List<AdmM2dEquip> m2dTypes = configService.queryM2dEquip(projectId);
|
|
|
- List<AdmInfosConfig> infosConfig = configService.queryInfosConfig(projectId);
|
|
|
- List<AdmRelsConfig> relConfig = configService.queryRelsConfig(projectId);
|
|
|
- List<AdmPipeConfig> pipeConfig = configService.queryPipeConfig(projectId);
|
|
|
- List<AdmConfig> config = configService.queryCommonConfig(projectId);
|
|
|
- List<AdmComponent> component = configService.queryComponent(projectId);
|
|
|
- List<AdmContainerConfig> containerConfig = configService.queryContainerConfig(projectId);
|
|
|
-
|
|
|
- HashMap<String, Object> data = new HashMap<>();
|
|
|
- data.put("m2dTypes", m2dTypes);
|
|
|
- data.put("infosConfig", serializeJsonProp(infosConfig));
|
|
|
- data.put("relConfig", relConfig);
|
|
|
- data.put("pipeConfig", pipeConfig);
|
|
|
- data.put("config", serializeJsonProp(config));
|
|
|
- data.put("component", component);
|
|
|
- data.put("containerConfig", containerConfig);
|
|
|
-
|
|
|
- return data;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<String, Object> queryDict(String groupCode, String projectId, String userId, boolean includeRel, boolean includeInfos){
|
|
|
- boolean newDict = "JD".equalsIgnoreCase(groupCode);
|
|
|
-
|
|
|
+ public Dict queryDict(String groupCode, String projectId, String userId, boolean includeRel, boolean includeInfos){
|
|
|
//从知识库服务获取专业分类
|
|
|
- QueryCriteria majorCriteria = ServiceUtil.getQueryCriteria(null, objectMapper);
|
|
|
+ QueryCriteria majorCriteria = ServiceUtil.getQueryCriteria(objectMapper);
|
|
|
majorCriteria.getCriteria().put("type", "major");
|
|
|
List<Map<String, Object>> majorList = ServiceUtil.call (() -> dicClient.dataQuery(groupCode, projectId, AdmConst.APP_ID, userId, majorCriteria));
|
|
|
|
|
|
//查询系统和设备定义
|
|
|
- QueryCriteria criteria = ServiceUtil.getQueryCriteria(null, objectMapper);
|
|
|
- criteria.getCriteria().putArray("objType").add("system").add("equipment");
|
|
|
+ QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, AdmConst.OBJ_TYPE_SYSTEM, AdmConst.OBJ_TYPE_EQUIPMENT);
|
|
|
List<TypeDef> typeList = queryAllPage(() -> rwdClient.queryObjectType(groupCode, projectId, AdmConst.APP_ID, userId, criteria), criteria, new Pagination(500));
|
|
|
|
|
|
- //查询重命名设备类型
|
|
|
- ObjectNode renameNode = !newDict ? configService.queryRenameEquipTypes(projectId) : null;
|
|
|
-
|
|
|
LinkedList<TypeDef> sysList = new LinkedList<>();
|
|
|
LinkedList<TypeDef> equipList = new LinkedList<>();
|
|
|
for(TypeDef def : typeList){
|
|
|
- if(def.getObjType().equals("system"))
|
|
|
+ if(def.getObjType().equals(AdmConst.OBJ_TYPE_SYSTEM))
|
|
|
sysList.add(def);
|
|
|
- else if(def.getObjType().equals("equipment")) {
|
|
|
- if(!newDict) {
|
|
|
- if (renameNode != null) { //设备类型重命名
|
|
|
- JsonNode n = renameNode.get(def.getCode());
|
|
|
- if(n != null)
|
|
|
- def.setName(n.asText());
|
|
|
- }
|
|
|
- }
|
|
|
+ else if(def.getObjType().equals(AdmConst.OBJ_TYPE_EQUIPMENT))
|
|
|
equipList.add(def);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //加载新增的自定义设备类
|
|
|
-// try{
|
|
|
-// Resource resource = resourceLoader.getResource("classpath:equip.json");
|
|
|
-// List<TypeDef> types = objectMapper.readValue(resource.getInputStream(), new TypeReference<List<TypeDef>>(){});
|
|
|
-// equipList.addAll(types);
|
|
|
-// }catch (Exception e) {
|
|
|
-//
|
|
|
-// }
|
|
|
- if(!newDict) {
|
|
|
- ArrayNode arr = configService.queryNewEquipTypes(projectId);
|
|
|
- if(arr != null) {
|
|
|
- try{
|
|
|
- List<TypeDef> types = objectMapper.readValue(objectMapper.writeValueAsString(arr), new TypeReference<List<TypeDef>>(){});
|
|
|
- equipList.addAll(types);
|
|
|
- }catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- HashMap<String, Object> data = new HashMap<>();
|
|
|
- data.put("major", majorList);
|
|
|
- data.put("system", sysList);
|
|
|
- data.put("equipment", equipList);
|
|
|
+ Dict data = new Dict();
|
|
|
+ data.setMajor(majorList);
|
|
|
+ data.setSystem(sysList);
|
|
|
+ data.setEquipment(equipList);
|
|
|
|
|
|
//查询关系定义
|
|
|
if(includeRel) {
|
|
|
List<RelationDefine> relList = ServiceUtil.call(() -> rwdClient.queryRelDef(groupCode, projectId, AdmConst.APP_ID, userId, new QueryCriteria()));
|
|
|
- data.put("relation", relList);
|
|
|
+ data.setRelation(relList);
|
|
|
}
|
|
|
+
|
|
|
//查询信息点定义
|
|
|
if(includeInfos) {
|
|
|
QueryCriteria qc = new QueryCriteria();
|
|
|
qc.setCriteria(objectMapper.createObjectNode());
|
|
|
List<InfoDef> funcList = ServiceUtil.call(() -> rwdClient.queryFunc(groupCode, projectId, AdmConst.APP_ID, userId, qc));
|
|
|
- data.put("infos", funcList);
|
|
|
+ data.setInfos(funcList);
|
|
|
}
|
|
|
|
|
|
return data;
|
|
@@ -210,211 +143,347 @@ public class SyncAppImpl implements ISyncApp {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Map<String, Object> downloadConfig(String groupCode, String projectId, String userId) {
|
|
|
+ //配置数据查询
|
|
|
+ List<AdmM2dEquip> m2dTypes = configService.queryM2dEquip(projectId);
|
|
|
+ List<AdmInfosConfig> infosConfig = configService.queryInfosConfig(projectId);
|
|
|
+ List<AdmRelsConfig> relConfig = configService.queryRelsConfig(projectId);
|
|
|
+ List<AdmPipeConfig> pipeConfig = configService.queryPipeConfig(projectId);
|
|
|
+ List<AdmConfig> config = configService.queryCommonConfig(projectId);
|
|
|
+ List<AdmComponent> component = configService.queryComponent(projectId);
|
|
|
+ List<AdmContainerConfig> containerConfig = configService.queryContainerConfig(projectId);
|
|
|
+
|
|
|
+ HashMap<String, Object> data = new HashMap<>();
|
|
|
+ data.put("m2dTypes", m2dTypes);
|
|
|
+ data.put("infosConfig", infosConfig);
|
|
|
+ data.put("relConfig", relConfig);
|
|
|
+ data.put("pipeConfig", pipeConfig);
|
|
|
+ data.put("config", config);
|
|
|
+ data.put("component", component);
|
|
|
+ data.put("containerConfig", containerConfig);
|
|
|
+
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Map<String, Object> downloadFrameData(String groupCode, String projectId, String userId) {
|
|
|
- List<OProject> prjList = null;
|
|
|
- String token = queryOldAdm.login();
|
|
|
- if(StrUtil.isNotBlank(token))
|
|
|
- prjList = queryOldAdm.queryProject(token, groupCode, projectId);
|
|
|
- else
|
|
|
- throw new CallException(new AdmResult(ResponseCode.A0220.getCode(), "ADM platform: " + ResponseCode.A0220.getDesc()));
|
|
|
-
|
|
|
- String[] prjIds = new String[prjList.size()];
|
|
|
- for (int i = 0; i < prjIds.length; i++) {
|
|
|
- prjIds[i] = prjList.get(i).getId();
|
|
|
- }
|
|
|
- List<AdmObject> bdAndFl = objectService.queryBdAndFl(prjIds);
|
|
|
+ //TODO 项目修改为从运维平台查询
|
|
|
+ QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, AdmConst.OBJ_TYPE_PROJECT);
|
|
|
+ List<ObjectNode> prjList = ServiceUtil.call(() -> objectClient.query(groupCode, null, AdmConst.APP_ID, userId, criteria));
|
|
|
+ packInfos(prjList);
|
|
|
+
|
|
|
+ QueryCriteria criteria2 = ServiceUtil.getQueryCriteria(objectMapper, AdmConst.OBJ_TYPE_BUILDING, AdmConst.OBJ_TYPE_FLOOR);
|
|
|
+ List<ObjectNode> bdAndFl = ServiceUtil.call(() -> objectClient.query(groupCode, projectId, AdmConst.APP_ID, userId, criteria2));
|
|
|
+ packInfos(bdAndFl);
|
|
|
|
|
|
HashMap<String, Object> data = new HashMap<>();
|
|
|
data.put("projects", prjList);
|
|
|
- data.put("buildingsAndFloors", serializeJsonProp(bdAndFl));
|
|
|
+ data.put("buildingsAndFloors", bdAndFl);
|
|
|
+
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
+ private void packInfos(List<ObjectNode> dataList){
|
|
|
+ for(ObjectNode node : dataList) {
|
|
|
+ DataExtrasUtil.packObjExtras(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
- public SyncData downloadBuildingData(String projectId, String buildingId, String uploadFlag, String lastDownloadTime) {
|
|
|
- List<AdmObject> bdData = admObjMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmObject>(), projectId, buildingId, uploadFlag, lastDownloadTime));
|
|
|
- List<AdmRelation> bdRel = relationMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmRelation>(), projectId, buildingId, uploadFlag, lastDownloadTime));
|
|
|
- List<AdmPipe> pipes = pipeMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmPipe>(), projectId, buildingId, uploadFlag, lastDownloadTime));
|
|
|
+ public BuildingData downloadBuildingData(String projectId, String buildingId, String uploadFlag, String lastDownloadTime) {
|
|
|
+ throw new RuntimeException("not supported");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BuildingData downloadBuildingData(String groupCode, String projectId, String userId, String uploadFlag, String buildingId, Long bdtpDownloadTs, Long admDownloadTs) {
|
|
|
+ String operator = getOperator(uploadFlag, userId);
|
|
|
+
|
|
|
+ //从bdtp下载对象(空间、竖井、设备)
|
|
|
+ QueryCriteria objCriteria = ServiceUtil.getQueryCriteria(objectMapper,
|
|
|
+ AdmConst.OBJ_TYPE_SPACE, AdmConst.OBJ_TYPE_SHAFT, AdmConst.OBJ_TYPE_SYSTEM, AdmConst.OBJ_TYPE_EQUIPMENT);
|
|
|
+ buildDownloadQueryCriteria(objCriteria, buildingId, operator, bdtpDownloadTs);
|
|
|
+ List<ObjectNode> objs = queryAllPage(() -> objectClient.query(groupCode, projectId, AdmConst.APP_ID, userId, objCriteria), objCriteria, new Pagination(500));
|
|
|
+ packInfos(objs);
|
|
|
+ test4Ts(objs);
|
|
|
+
|
|
|
+ //关系数据按项目下载,不在建筑数据中处理
|
|
|
+
|
|
|
+ //管道数据,实验方案
|
|
|
+ List<AdmPipe> pipes = pipeMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmPipe>(), projectId, buildingId, operator, admDownloadTs));
|
|
|
|
|
|
//任务相关数据查询
|
|
|
- List<AdmJobSpace> jobSpace = jobSpaceMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmJobSpace>(), projectId, buildingId, uploadFlag, lastDownloadTime));
|
|
|
- List<AdmProblemArch> problemArch = problemArchMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmProblemArch>(), projectId, buildingId, uploadFlag, lastDownloadTime));
|
|
|
- List<AdmProblemEquip> problemEquip = problemEquipMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmProblemEquip>(), projectId, buildingId, uploadFlag, lastDownloadTime));
|
|
|
- List<AdmFile> file = fileMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmFile>(), projectId, buildingId, uploadFlag, lastDownloadTime));
|
|
|
- List<AdmQrCode> qrCode = qrCodeMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmQrCode>(), projectId, buildingId, uploadFlag, lastDownloadTime));
|
|
|
- List<AdmServeArea> serveArea = serveAreaMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmServeArea>(), projectId, buildingId, uploadFlag, lastDownloadTime));
|
|
|
-
|
|
|
- SyncData data = new SyncData();
|
|
|
+ List<AdmJobSpace> jobSpace = jobSpaceMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmJobSpace>(), projectId, buildingId, operator, admDownloadTs));
|
|
|
+ List<AdmProblemArch> problemArch = problemArchMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmProblemArch>(), projectId, buildingId, operator, admDownloadTs));
|
|
|
+ List<AdmProblemEquip> problemEquip = problemEquipMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmProblemEquip>(), projectId, buildingId, operator, admDownloadTs));
|
|
|
+ List<AdmFile> file = fileMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmFile>(), projectId, buildingId, operator, admDownloadTs));
|
|
|
+ List<AdmQrCode> qrCode = qrCodeMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmQrCode>(), projectId, buildingId, operator, admDownloadTs));
|
|
|
+ List<AdmServeArea> serveArea = serveAreaMapper.selectList(buildDownloadQueryWrapper(new QueryWrapper<AdmServeArea>(), projectId, buildingId, operator, admDownloadTs));
|
|
|
+
|
|
|
+ BuildingData data = new BuildingData();
|
|
|
data.setBuildingId(buildingId);
|
|
|
|
|
|
- data.setObjects(serializeJsonProp(bdData));
|
|
|
- data.setRelations(bdRel);
|
|
|
- data.setPipes(serializeJsonProp(pipes));
|
|
|
+ data.setObjects(objs);
|
|
|
+
|
|
|
+ data.setPipes(pipes);
|
|
|
|
|
|
- data.setJobSpace(serializeJsonProp(jobSpace));
|
|
|
- data.setProblemArch(serializeJsonProp(problemArch));
|
|
|
+ data.setJobSpace(jobSpace);
|
|
|
+ data.setProblemArch(problemArch);
|
|
|
data.setProblemEquip(problemEquip);
|
|
|
data.setFile(file);
|
|
|
- data.setQrCode(serializeJsonProp(qrCode));
|
|
|
+ data.setQrCode(qrCode);
|
|
|
data.setServeArea(serveArea);
|
|
|
- data.setTimestamp(DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
|
|
|
|
|
|
+ data.buildDownloadTs();
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
- private <T> QueryWrapper<T> buildDownloadQueryWrapper(QueryWrapper<T> wrapper, String projectId, String buildingId, String uploadFlag, String lastDownloadTime){
|
|
|
- wrapper.eq("project_id", projectId).eq("building_id", buildingId);
|
|
|
- applyUploadFlag(wrapper, uploadFlag,lastDownloadTime);
|
|
|
- return wrapper;
|
|
|
+ private String getOperator(String uploadFlag, String userId){
|
|
|
+ AdmClientFlag clientFlag = clientFlagMapper.selectOne(new QueryWrapper<AdmClientFlag>().eq("client_flag", uploadFlag));
|
|
|
+ if(clientFlag == null) {
|
|
|
+ clientFlag = new AdmClientFlag();
|
|
|
+ clientFlag.setClientFlag(uploadFlag);
|
|
|
+ clientFlag.setUserId(userId);
|
|
|
+ clientFlagMapper.insert(clientFlag);
|
|
|
+ }
|
|
|
+ return userId + ':' + clientFlag.getId();
|
|
|
}
|
|
|
|
|
|
- private void applyUploadFlag(QueryWrapper<?> wrapper, String uploadFlag, String lastDownloadTime){
|
|
|
- if (StrUtil.isNotBlank(lastDownloadTime)) { //非初始化下载
|
|
|
- if (StrUtil.isNotBlank(uploadFlag))
|
|
|
- wrapper.and(w -> w.isNull("upload_flag").or().ne("upload_flag", uploadFlag));
|
|
|
+ private <T> QueryWrapper<T> buildDownloadQueryWrapper(QueryWrapper<T> wrapper, String projectId, String buildingId, String operator, Long lastDownloadTime){
|
|
|
+ wrapper.eq("project_id", projectId).eq("building_id", buildingId);
|
|
|
+
|
|
|
+ if (lastDownloadTime != null && lastDownloadTime > 0) { //非初始化下载
|
|
|
+ wrapper.gt("ts", lastDownloadTime);
|
|
|
|
|
|
wrapper.and(
|
|
|
- w -> w.isNotNull("modified_time").gt("modified_time", lastDownloadTime)
|
|
|
+ w -> w.isNotNull("modifier").ne("modifier", operator)
|
|
|
.or()
|
|
|
- .isNull("modified_time").gt("creation_time", lastDownloadTime)
|
|
|
+ .isNull("modifier").ne("creator", operator)
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ return wrapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void buildDownloadQueryCriteria(QueryCriteria criteria, String buildingId, String operator, Long lastDownloadTime){
|
|
|
+ if(StrUtil.isNotBlank(buildingId)) {
|
|
|
+ //TODO 关联buildingId查询
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lastDownloadTime != null && lastDownloadTime > 0) {
|
|
|
+ criteria.getCriteria().putObject("ts").put("$gt", lastDownloadTime);
|
|
|
+ criteria.getCriteria().putObject("modifier").put("$ne", operator); //TODO 暂时只能处理modifier
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO debug 接口未返回ts时,添加一个
|
|
|
+ private void test4Ts(List<?> dataList){
|
|
|
+ for(Object data : dataList) {
|
|
|
+ if(data instanceof ObjectNode) {
|
|
|
+ if (((ObjectNode) data).get("ts") == null)
|
|
|
+ ((ObjectNode) data).put("ts", System.currentTimeMillis());
|
|
|
+ } else if(data instanceof ObjectRelation){
|
|
|
+ if(((ObjectRelation) data).getTs() == null)
|
|
|
+ ((ObjectRelation) data).setTs(new Date());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public UploadRtn uploadData(SyncData uploadData, String projectId, String uploadFlag) {
|
|
|
- UploadRtn rtn = new UploadRtn();
|
|
|
+ public ProjectData downloadProjectData(String groupCode, String projectId, String userId, String uploadFlag, Long bdtpDownloadTs, Long admDownloadTs) {
|
|
|
+ String operator = getOperator(uploadFlag, userId);
|
|
|
+
|
|
|
+ QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper);
|
|
|
+ buildDownloadQueryCriteria(criteria, null, operator, bdtpDownloadTs);
|
|
|
+
|
|
|
+ List<ObjectRelation> rels = queryAllPage(() -> relationClient.query(groupCode, projectId, AdmConst.APP_ID, userId, criteria), criteria, new Pagination(500));
|
|
|
+ test4Ts(rels);
|
|
|
+
|
|
|
+ ProjectData data = new ProjectData();
|
|
|
+ data.setRelations(rels);
|
|
|
+
|
|
|
+ data.buildDownloadTs();
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UploadRtn uploadData(UploadData uploadData, String groupCode, String projectId, String userId, String uploadFlag) {
|
|
|
+ if(!uploadData.notEmpty())
|
|
|
+ return new UploadRtn();
|
|
|
+
|
|
|
+ String operator = getOperator(uploadFlag, userId);
|
|
|
String timestamp = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
|
|
|
|
|
|
+ UploadRtn rtn = new UploadRtn();
|
|
|
+ List<AdmUploadLog> logs = new ArrayList<>();
|
|
|
+
|
|
|
+ //上传bdtp数据
|
|
|
if (CollUtil.isNotEmpty(uploadData.getObjects())) {
|
|
|
- List<AdmObject> dbObjs = admObjMapper.selectList(new QueryWrapper<AdmObject>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
|
|
|
- List<AdmObject> expired = uploadAdmData(deserializeJsonProp(uploadData.getObjects()), dbObjs, uploadFlag, timestamp, admObjMapper, "object");
|
|
|
- rtn.setExpiredObjectIds(buildExpiredIds(expired));
|
|
|
+ List<ObjectNode>[] objData = prepareBdtpData(uploadData.getObjects(), operator, timestamp, uploadData.getUploadJobId(), logs);
|
|
|
+ uploadObjs(groupCode, projectId, userId, objData);
|
|
|
}
|
|
|
if (CollUtil.isNotEmpty(uploadData.getRelations())) {
|
|
|
- List<AdmRelation> dbObjs = relationMapper.selectList(new QueryWrapper<AdmRelation>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
|
|
|
- List<AdmRelation> expired = uploadAdmData(uploadData.getRelations(), dbObjs, uploadFlag, timestamp, relationMapper, "relation");
|
|
|
- rtn.setExpiredRelationIds(buildExpiredIds(expired));
|
|
|
+ List<ObjectNode>[] relData = prepareBdtpData(uploadData.getRelations(), operator, timestamp, uploadData.getUploadJobId(), logs);
|
|
|
+ uploadRels(groupCode, projectId, userId, relData);
|
|
|
+ }
|
|
|
+
|
|
|
+ //上传adm数据
|
|
|
+ uploadAdmData(uploadData, operator, timestamp, logs);
|
|
|
+
|
|
|
+ //记录日志
|
|
|
+ logService.saveUploadLog(logs);
|
|
|
+
|
|
|
+ //TODO m2d, message & state
|
|
|
+
|
|
|
+ rtn.setTimestamp(timestamp);
|
|
|
+ return rtn;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void uploadObjs(String groupCode, String projectId, String userId, List<ObjectNode>[] data) {
|
|
|
+ if(data[0].size() > 0)
|
|
|
+ ServiceUtil.call(() -> objectClient.create(groupCode, projectId, AdmConst.APP_ID, userId, data[0]));
|
|
|
+ if (data[1].size() > 0)
|
|
|
+ ServiceUtil.call(() -> objectClient.update(groupCode, projectId, AdmConst.APP_ID, userId, data[1]));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void uploadRels(String groupCode, String projectId, String userId, List<ObjectNode>[] data) {
|
|
|
+ if(data[0].size() > 0)
|
|
|
+ ServiceUtil.call(() -> relationClient.create(groupCode, projectId, AdmConst.APP_ID, userId, data[0]));
|
|
|
+ if (data[1].size() > 0)
|
|
|
+ ServiceUtil.call(() -> relationClient.update(groupCode, projectId, AdmConst.APP_ID, userId, data[1]));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ObjectNode>[] prepareBdtpData(List<ObjectNode> list, String operator, String time, String jobId, List<AdmUploadLog> logs){
|
|
|
+ List<ObjectNode> updateList = new ArrayList<>();
|
|
|
+ Iterator<ObjectNode> iter = list.iterator();
|
|
|
+ while (iter.hasNext()) {
|
|
|
+ ObjectNode entity = iter.next();
|
|
|
+ DataExtrasUtil.unpackObjExtras(entity);
|
|
|
+
|
|
|
+ AdmUploadLog log;
|
|
|
+ if (entity.get("state").asInt() == 1) {
|
|
|
+ updateList.add(entity);
|
|
|
+ iter.remove();
|
|
|
+
|
|
|
+ boolean remove = entity.get("valid").asInt() == ValidEnum.FALSE.getType();
|
|
|
+ log = new AdmUploadLog(jobId, operator, remove ? AdmUploadLog.REMOVE : AdmUploadLog.MODIFY);
|
|
|
+ log.setData(entity, objectMapper);
|
|
|
+
|
|
|
+ entity.put("updateApp", AdmConst.CREATOR_APP);
|
|
|
+ entity.put("modifier", operator);
|
|
|
+ entity.put("modifiedTime", time);
|
|
|
+
|
|
|
+ //TODO 可能需要进行删除信息点操作
|
|
|
+
|
|
|
+ } else {
|
|
|
+ log = new AdmUploadLog(jobId, operator, AdmUploadLog.ADD);
|
|
|
+ log.setData(entity, objectMapper);
|
|
|
+
|
|
|
+ entity.put("createApp", AdmConst.CREATOR_APP);
|
|
|
+ entity.put("creator", operator);
|
|
|
+ entity.put("creationTime", time);
|
|
|
+ entity.put("modifiedTime", time); //TODO 临时处理,方便之后的增量查询
|
|
|
+ }
|
|
|
+ logs.add(log);
|
|
|
}
|
|
|
|
|
|
+ return new List[] {list, updateList};
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void uploadAdmData(UploadData uploadData, String operator, String time, List<AdmUploadLog> logs){
|
|
|
if (CollUtil.isNotEmpty(uploadData.getPipes())) {
|
|
|
- List<AdmPipe> dbObjs = pipeMapper.selectList(new QueryWrapper<AdmPipe>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
|
|
|
- List<AdmPipe> expired = uploadAdmData(deserializeJsonProp(uploadData.getPipes()), dbObjs, uploadFlag, timestamp, pipeMapper, "pipe");
|
|
|
- rtn.setExpiredPipeIds(buildExpiredIds(expired));
|
|
|
+ uploadAdmEntities(uploadData.getPipes(), operator, time, uploadData.getUploadJobId(), pipeMapper, logs, true);
|
|
|
}
|
|
|
|
|
|
if (CollUtil.isNotEmpty(uploadData.getJobSpace())) {
|
|
|
- List<AdmJobSpace> dbObjs = jobSpaceMapper.selectList(new QueryWrapper<AdmJobSpace>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
|
|
|
- List<AdmJobSpace> expired = uploadAdmData(deserializeJsonProp(uploadData.getJobSpace()), dbObjs, uploadFlag, timestamp, jobSpaceMapper, null);
|
|
|
- rtn.setExpiredJobSpaceIds(buildExpiredIds(expired));
|
|
|
+ uploadAdmEntities(uploadData.getJobSpace(), operator, time, uploadData.getUploadJobId(), jobSpaceMapper, logs, false);
|
|
|
}
|
|
|
if (CollUtil.isNotEmpty(uploadData.getProblemArch())) {
|
|
|
- List<AdmProblemArch> dbObjs = problemArchMapper.selectList(new QueryWrapper<AdmProblemArch>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
|
|
|
- List<AdmProblemArch> expired = uploadAdmData(deserializeJsonProp(uploadData.getProblemArch()), dbObjs, uploadFlag, timestamp, problemArchMapper, null);
|
|
|
- rtn.setExpiredProblemArchIds(buildExpiredIds(expired));
|
|
|
+ uploadAdmEntities(uploadData.getProblemArch(), operator, time, uploadData.getUploadJobId(), problemArchMapper, logs, false);
|
|
|
}
|
|
|
if (CollUtil.isNotEmpty(uploadData.getProblemEquip())) {
|
|
|
- List<AdmProblemEquip> dbObjs = problemEquipMapper.selectList(new QueryWrapper<AdmProblemEquip>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
|
|
|
- List<AdmProblemEquip> expired = uploadAdmData(uploadData.getProblemEquip(), dbObjs, uploadFlag, timestamp, problemEquipMapper, null);
|
|
|
- rtn.setExpiredProblemEquipIds(buildExpiredIds(expired));
|
|
|
+ uploadAdmEntities(uploadData.getProblemEquip(), operator, time, uploadData.getUploadJobId(), problemEquipMapper, logs, false);
|
|
|
}
|
|
|
if (CollUtil.isNotEmpty(uploadData.getFile())) {
|
|
|
- List<AdmFile> dbObjs = fileMapper.selectList(new QueryWrapper<AdmFile>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
|
|
|
- List<AdmFile> expired = uploadAdmData(uploadData.getFile(), dbObjs, uploadFlag, timestamp, fileMapper, null);
|
|
|
- rtn.setExpiredFileIds(buildExpiredIds(expired));
|
|
|
+ uploadAdmEntities(uploadData.getFile(), operator, time, uploadData.getUploadJobId(), fileMapper, logs, false);
|
|
|
}
|
|
|
if (CollUtil.isNotEmpty(uploadData.getQrCode())) {
|
|
|
- List<AdmQrCode> dbObjs = qrCodeMapper.selectList(new QueryWrapper<AdmQrCode>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
|
|
|
- List<AdmQrCode> expired = uploadAdmData(deserializeJsonProp(uploadData.getQrCode()), dbObjs, uploadFlag, timestamp, qrCodeMapper, null);
|
|
|
- rtn.setExpiredQrCodeIds(buildExpiredIds(expired));
|
|
|
+ uploadAdmEntities(uploadData.getQrCode(), operator, time, uploadData.getUploadJobId(), qrCodeMapper, logs, false);
|
|
|
}
|
|
|
if (CollUtil.isNotEmpty(uploadData.getServeArea())) {
|
|
|
- List<AdmServeArea> dbObjs = serveAreaMapper.selectList(new QueryWrapper<AdmServeArea>().eq("building_id", uploadData.getBuildingId()).eq("valid", ValidEnum.TRUE.getType()));
|
|
|
- List<AdmServeArea> expired = uploadAdmData(uploadData.getServeArea(), dbObjs, uploadFlag, timestamp, serveAreaMapper, null);
|
|
|
- rtn.setExpiredServeAreaIds(buildExpiredIds(expired));
|
|
|
+ uploadAdmEntities(uploadData.getServeArea(), operator, time, uploadData.getUploadJobId(), serveAreaMapper, logs, false);
|
|
|
}
|
|
|
-
|
|
|
- rtn.setTimestamp(timestamp);
|
|
|
- rtn.setBuildingId(uploadData.getBuildingId());
|
|
|
- return rtn;
|
|
|
}
|
|
|
|
|
|
- private <T extends BaseAdmDataEntity> List<T> uploadAdmData(List<T> objs, List<T> dbObjs, String uploadFlag, String timestamp, BaseMapper<T> mapper, String d2mType){
|
|
|
- List<T> expired = new ArrayList<>();
|
|
|
- HashMap<String, T> dbMap = new HashMap<>(dbObjs.size());
|
|
|
- for(T dbObj : dbObjs) {
|
|
|
- dbMap.put(dbObj.getId(), dbObj);
|
|
|
- }
|
|
|
-
|
|
|
- List<T> msgAdd = new ArrayList<>();
|
|
|
- List<T> msgModify = new ArrayList<>();
|
|
|
- List<T> msgRemove = new ArrayList<>();
|
|
|
- for (T obj : objs) {
|
|
|
- if(obj == null)
|
|
|
- continue;
|
|
|
+ private <T extends BaseAdmDataEntity> void uploadAdmEntities(List<T> list, String operator, String time, String jobId, BaseMapper<T> mapper, List<AdmUploadLog> logs, boolean merge) {
|
|
|
+ List<T> updateList = new ArrayList<>();
|
|
|
+ Iterator<T> iter = list.iterator();
|
|
|
+ while (iter.hasNext()) {
|
|
|
+ T entity = iter.next();
|
|
|
|
|
|
- logService.saveUploadLog(new AdmUploadLog(uploadFlag, timestamp, obj));
|
|
|
+ AdmUploadLog log;
|
|
|
+ if (entity.getState() == 1) {
|
|
|
+ updateList.add(entity);
|
|
|
+ iter.remove();;
|
|
|
|
|
|
- T dbObj = dbMap.get(obj.getId());
|
|
|
- if (dbObj == null) {
|
|
|
- if(obj.getValid().intValue() == ValidEnum.FALSE.getType())
|
|
|
- continue;
|
|
|
+ boolean remove = entity.getValid().intValue() == ValidEnum.FALSE.getType();
|
|
|
+ log = new AdmUploadLog(jobId, operator, remove ? AdmUploadLog.REMOVE : AdmUploadLog.MODIFY);
|
|
|
+ } else {
|
|
|
+ log = new AdmUploadLog(jobId, operator, AdmUploadLog.ADD);
|
|
|
+ }
|
|
|
+ log.setData(entity, objectMapper);
|
|
|
+ logs.add(log);
|
|
|
+ }
|
|
|
|
|
|
- obj.setCreationTime(timestamp);
|
|
|
- obj.setCreator(AdmConst.CREATOR_APP);
|
|
|
- obj.setUploadFlag(uploadFlag);
|
|
|
+ //insert
|
|
|
+ if(list.size() > 0) {
|
|
|
+ for(T entity : list) {
|
|
|
+ entity.setCreator(operator);
|
|
|
+ entity.setCreationTime(time);
|
|
|
+ mapper.insert(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if(d2mType != null)
|
|
|
- setDeliveryDataProps((BaseDeliveryEntity) obj, null);
|
|
|
+ //update
|
|
|
+ if (updateList.size() > 0) {
|
|
|
+ Map<String, T> dbObjsMap = null;
|
|
|
+ if(merge) {
|
|
|
+ ArrayList<String> updateIds = new ArrayList<>(updateList.size());
|
|
|
+ updateList.forEach(entity -> updateIds.add(entity.getId()));
|
|
|
+ List<T> dbList = mapper.selectBatchIds(updateIds);
|
|
|
+
|
|
|
+ dbObjsMap = new HashMap<>(dbList.size());
|
|
|
+ for(T dbObj : dbList) {
|
|
|
+ dbObjsMap.put(dbObj.getId(), dbObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- mapper.insert(obj);
|
|
|
+ for(T entity : updateList) {
|
|
|
+ if(merge)
|
|
|
+ entity = mergeEntity(entity, dbObjsMap.get(entity.getId()));
|
|
|
|
|
|
- if(d2mType != null)
|
|
|
- msgAdd.add(obj);
|
|
|
- } else {
|
|
|
-// String dbTs;
|
|
|
-// String ts;
|
|
|
-// if(dbObj.getModifiedTime() != null){
|
|
|
-// dbTs = dbObj.getModifiedTime();
|
|
|
-// ts = obj.getModifiedTime();
|
|
|
-// } else {
|
|
|
-// dbTs = dbObj.getCreationTime();
|
|
|
-// ts = obj.getCreationTime();
|
|
|
-// }
|
|
|
-// if (!dbTs.equals(ts)) {
|
|
|
-// //TODO 时间戳不一致,离线数据无效,暂时跳过处理
|
|
|
-// expired.add(obj);
|
|
|
-// } else {
|
|
|
- obj.setModifiedTime(timestamp);
|
|
|
- obj.setModifier(AdmConst.CREATOR_APP);
|
|
|
- obj.setUploadFlag(uploadFlag);
|
|
|
-
|
|
|
- if(d2mType != null)
|
|
|
- setDeliveryDataProps((BaseDeliveryEntity) obj, null);
|
|
|
-
|
|
|
- //合并信息点
|
|
|
- if(dbObj instanceof AdmObject && obj instanceof AdmObject)
|
|
|
- ((AdmObject) obj).setInfos(mergeInfos(((AdmObject) obj).getInfos(), ((AdmObject) dbObj).getInfos()));
|
|
|
- else if(dbObj instanceof AdmPipe && obj instanceof AdmPipe)
|
|
|
- ((AdmPipe) obj).setInfos(mergeInfos(((AdmPipe) obj).getInfos(), ((AdmPipe) dbObj).getInfos()));
|
|
|
-
|
|
|
- mapper.updateById(obj);
|
|
|
-
|
|
|
- if(d2mType != null) {
|
|
|
- if(obj.getValid().intValue() == ValidEnum.FALSE.getType())
|
|
|
- msgRemove.add(obj);
|
|
|
- else
|
|
|
- msgModify.add(obj);
|
|
|
- }
|
|
|
-// }
|
|
|
+ entity.setModifier(operator);
|
|
|
+ entity.setModifiedTime(time);
|
|
|
+ mapper.updateById(entity);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if(d2mType != null)
|
|
|
- sendD2mMessage(d2mType, msgAdd, msgModify, msgRemove);
|
|
|
+ private <T extends BaseAdmDataEntity> T mergeEntity(T obj, T dbObj) {
|
|
|
+ if (dbObj != null) {
|
|
|
+ if(dbObj instanceof AdmPipe)
|
|
|
+ ((AdmPipe)obj).setInfos(mergeInfos(((AdmPipe) obj).getInfos(), ((AdmPipe) dbObj).getInfos()));
|
|
|
+ }
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
|
|
|
- return expired;
|
|
|
+ private ObjectNode mergeInfos(ObjectNode infos, ObjectNode dbInfos){
|
|
|
+ if (dbInfos != null) {
|
|
|
+ if(infos != null)
|
|
|
+ dbInfos.setAll(infos);
|
|
|
+ return dbInfos;
|
|
|
+ } else
|
|
|
+ return infos;
|
|
|
}
|
|
|
|
|
|
private void setDeliveryDataProps(BaseDeliveryEntity obj, BaseDeliveryEntity dbObj){
|
|
@@ -427,15 +496,6 @@ public class SyncAppImpl implements ISyncApp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private ObjectNode mergeInfos(ObjectNode infos, ObjectNode dbInfos){
|
|
|
- if(dbInfos != null) {
|
|
|
- if(infos != null)
|
|
|
- dbInfos.setAll(infos);
|
|
|
- return dbInfos;
|
|
|
- } else
|
|
|
- return infos;
|
|
|
- }
|
|
|
-
|
|
|
private void sendD2mMessage(String objectType, List<?> msgAdd, List<?> msgModify, List<?> msgRemove){
|
|
|
D2mMessage message = new D2mMessage();
|
|
|
message.setItemType(objectType);
|
|
@@ -458,19 +518,4 @@ public class SyncAppImpl implements ISyncApp {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private <T extends BaseAdmEntity> List<T> serializeJsonProp(List<T> list){
|
|
|
- //app端完善,不需要做tostr处理了
|
|
|
-// for(BaseAdmEntity entity : list) {
|
|
|
-// entity.serializeJsonProp();
|
|
|
-// }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
- private <T extends BaseAdmEntity> List<T> deserializeJsonProp(List<T> list){
|
|
|
- for(BaseAdmEntity entity : list) {
|
|
|
- entity.deserializeJsonProp();
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
}
|