zhaoyk 3 年之前
父節點
當前提交
d78886f245

+ 2 - 0
src/main/java/com/persagy/bdtp/adm/controller/ManageController.java

@@ -4,12 +4,14 @@ import com.persagy.bdtp.adm.common.AdmRequest;
 import com.persagy.bdtp.adm.common.AdmResult;
 import com.persagy.bdtp.adm.service.ISyncOldAdm;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.Map;
 
+@CrossOrigin
 @RestController
 @RequestMapping("/manage")
 public class ManageController {

+ 2 - 0
src/main/java/com/persagy/bdtp/adm/entity/AdmInfosConfig.java

@@ -35,6 +35,8 @@ public class AdmInfosConfig implements IAdmEntity {
     )
     private List<Object> infos;
 
+    private String flag;
+
     private String strInfos;
 
     @Override

+ 2 - 0
src/main/java/com/persagy/bdtp/adm/entity/AdmPipeConfig.java

@@ -23,6 +23,8 @@ public class AdmPipeConfig implements IAdmEntity {
 
     private String classCodeTo;
 
+    private String flag;
+
     @Override
     public void serializeJsonProp() {
 

+ 2 - 0
src/main/java/com/persagy/bdtp/adm/entity/AdmRelsConfig.java

@@ -27,6 +27,8 @@ public class AdmRelsConfig implements IAdmEntity {
 
     private String classCodeTo;
 
+    private String flag;
+
     @Override
     public void serializeJsonProp() {
 

+ 8 - 1
src/main/java/com/persagy/bdtp/adm/service/ServiceUtil.java

@@ -15,9 +15,16 @@ public class ServiceUtil {
 	private static final String SUCCESS = "success";
 
 	public static <T> T call(Supplier<CommonResult<T>> action) {
+		return call(action, null);
+	}
+
+	public static <T> T call(Supplier<CommonResult<T>> action, Pagination pagination) {
 		CommonResult<T> result = action.get();
-		if(SUCCESS.equals(result.getResult()))
+		if(SUCCESS.equals(result.getResult())) {
+			if(pagination != null)
+				pagination.setTotal(result.getCount().intValue());
 			return result.getData();
+		}
 		throw new CallException(new AdmResult<>(result.getResult(), result.getMessage()));
 	}
 

+ 6 - 4
src/main/java/com/persagy/bdtp/adm/service/impl/QueryFromOldAdmImpl.java

@@ -97,11 +97,13 @@ public class QueryFromOldAdmImpl implements IQueryFromOldAdm {
 		for (AdmM2dEquip equip : equips) {
 			classCodeList.add(equip.getClassCode());
 		}
-		try {
-			String filter = "classCode in " + objectMapper.writeValueAsString(classCodeList);
-			params.put("filters", filter);
-		} catch (IOException e) {
+		if (classCodeList.size() > 0) {
+			try {
+				String filter = "classCode in " + objectMapper.writeValueAsString(classCodeList);
+				params.put("filters", filter);
+			} catch (IOException e) {
 
+			}
 		}
 
 		return queryAllPage(() -> admClient.queryEquip(groupCode, projectId, appId, user, token, params), params, pagination);

+ 18 - 1
src/main/java/com/persagy/bdtp/adm/service/impl/SyncAppImpl.java

@@ -15,18 +15,21 @@ 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.oldadm.OldAdmResult;
 import com.persagy.bdtp.adm.service.*;
 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.lang.PsDateTime;
+import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.define.entity.RelationDefine;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.function.Supplier;
 
 @Service
 public class SyncAppImpl implements ISyncApp {
@@ -109,7 +112,7 @@ public class SyncAppImpl implements ISyncApp {
 		//查询系统和设备定义
 		QueryCriteria criteria = ServiceUtil.getQueryCriteria(null, objectMapper);
 		criteria.getCriteria().putArray("objType").add("system").add("equipment");
-		List<TypeDef> typeList = ServiceUtil.call(() -> rwdClient.queryObjectType(groupCode, projectId, AdmConst.APP_ID, userId, criteria));
+		List<TypeDef> typeList = queryAllPage(() -> rwdClient.queryObjectType(groupCode, projectId, AdmConst.APP_ID, userId, criteria), criteria, new Pagination(500));
 
 		//查询关系定义
 		List<RelationDefine> relList = ServiceUtil.call(() -> rwdClient.queryRelDef(groupCode, projectId, AdmConst.APP_ID, userId, new QueryCriteria()));
@@ -155,6 +158,20 @@ public class SyncAppImpl implements ISyncApp {
 		return data;
 	}
 
+	private <T> List<T> queryAllPage(Supplier<CommonResult<List<T>>> action, QueryCriteria criteria, Pagination pagination){
+		List<T> list = null;
+		while (pagination.isHasNext()){
+			criteria.setPage((long)pagination.getPageNum());
+			criteria.setSize((long)pagination.getPageSize());
+			if(list == null)
+				list = ServiceUtil.call(action, pagination);
+			else
+				list.addAll(ServiceUtil.call(action, pagination));
+			pagination.next();
+		}
+		return list;
+	}
+
 	@Override
 	public Map<String, Object> downloadFrameData(String groupCode, String projectId, String userId) {
 		List<OProject> prjList = null;

+ 1 - 1
src/main/resources/bootstrap.yml

@@ -1,5 +1,5 @@
 server:
-  port: 8877
+  port: 8876
 spring:
   application:
     # 应用名称

+ 48 - 54
src/test/java/com/persagy/bdtp/adm/test/AdmApplicationTests.java

@@ -59,20 +59,29 @@ public class AdmApplicationTests {
 	//@Transactional
 	public void testInfosCfg(){
 		String type = "se";
-		String major = type.toUpperCase();
 
-		List<AdmInfosConfig> dbList = infosConfigMapper.selectList(new QueryWrapper<AdmInfosConfig>().eq("major_code", major));
-		HashMap<String, AdmInfosConfig> dbMap = new HashMap<>();
-		dbList.stream().forEach(cfg -> dbMap.put(cfg.getClassCode(), cfg));
+		List<AdmComponent> compList = componentMapper.selectList(null);
+		HashMap<String, List<AdmComponent>> compMap = new HashMap<>();
+		compList.stream().forEach(comp -> {
+			List<AdmComponent> list = compMap.get(comp.getClassCode());
+			if(list == null){
+				list = new ArrayList<>();
+				compMap.put(comp.getClassCode(), list);
+			}
+			list.add(comp);
+		});
+
+		infosConfigMapper.delete(new QueryWrapper<AdmInfosConfig>().eq("flag", type));
+
 		List<AdmInfosConfig> list = new InfosCfgs().read(type);
 		for(AdmInfosConfig item : list) {
-			AdmInfosConfig dbItem = dbMap.get(item.getClassCode());
-			if(dbItem == null)
-				infosConfigMapper.insert(item);
-			else {
-				item.setId(dbItem.getId());
-				infosConfigMapper.updateById(item);
-			}
+			item.setFlag(type);
+
+			List<AdmComponent> comps = compMap.get(item.getClassCode());
+			if(comps != null)
+				setCompsToInfo(item.getInfos(), null, comps);
+
+			infosConfigMapper.insert(item);
 		}
 	}
 
@@ -81,19 +90,24 @@ public class AdmApplicationTests {
 	@Test
 	public void testRelsCfg(){
 		String type = "se";
-
-		List<AdmRelsConfig> dbList = relsConfigMapper.selectList(null);
-		HashMap<String, AdmRelsConfig> dbMap = new HashMap<>();
-		dbList.stream().forEach(cfg -> dbMap.put(cfg.getClassCodeFrom(), cfg));
+		relsConfigMapper.delete(new QueryWrapper<AdmRelsConfig>().eq("flag", type));
 		List<AdmRelsConfig> list = new RelCfgs().read(type);
 		for(AdmRelsConfig item : list) {
-			AdmRelsConfig dbItem = dbMap.get(item.getClassCodeFrom());
-			if(dbItem == null)
-				relsConfigMapper.insert(item);
-			else {
-				item.setId(dbItem.getId());
-				relsConfigMapper.updateById(item);
-			}
+			item.setFlag(type);
+			relsConfigMapper.insert(item);
+		}
+	}
+
+	@Autowired
+	private AdmPipeConfigMapper pipeConfigMapper;
+	@Test
+	public void testPipeCfg(){
+		String type = "ff";
+		pipeConfigMapper.delete(new QueryWrapper<AdmPipeConfig>().eq("flag", type));
+		List<AdmPipeConfig> list = new PipeCfgs().read(type);
+		for(AdmPipeConfig item : list) {
+			item.setFlag(type);
+			pipeConfigMapper.insert(item);
 		}
 	}
 
@@ -121,17 +135,18 @@ public class AdmApplicationTests {
 			List<AdmComponent> comps = entry.getValue();
 			AdmInfosConfig cfg = cfgMap.get(classCode);
 			if(cfg != null){
-				List<Map> infos = (List)cfg.getInfos();
-				Map info = null;
-				for(Map m : infos) {
-					if("comp_type".equals(m.get("code"))){
-						info = m;
-						break;
-					}
-				}
-				setCompsToInfo(infos, info, comps);
-
-				infosConfigMapper.updateById(cfg);
+				//不需要更新操作
+//				List<Map> infos = (List)cfg.getInfos();
+//				Map info = null;
+//				for(Map m : infos) {
+//					if("comp_type".equals(m.get("code"))){
+//						info = m;
+//						break;
+//					}
+//				}
+//				setCompsToInfo(infos, info, comps);
+//
+//				infosConfigMapper.updateById(cfg);
 			} else {
 				cfg = new AdmInfosConfig();
 				cfg.setId(IdUtil.simpleUUID());
@@ -168,25 +183,4 @@ public class AdmApplicationTests {
 		info.put("options", ops);
 	}
 
-	@Autowired
-	private AdmPipeConfigMapper pipeConfigMapper;
-	@Test
-	public void testPipeCfg(){
-		String type = "ff";
-
-		List<AdmPipeConfig> dbList = pipeConfigMapper.selectList(null);
-		HashMap<String, AdmPipeConfig> dbMap = new HashMap<>();
-		dbList.stream().forEach(cfg -> dbMap.put(cfg.getClassCodeFrom(), cfg));
-		List<AdmPipeConfig> list = new PipeCfgs().read(type);
-		for(AdmPipeConfig item : list) {
-			AdmPipeConfig dbItem = dbMap.get(item.getClassCodeFrom());
-			if(dbItem == null)
-				pipeConfigMapper.insert(item);
-			else {
-				item.setId(dbItem.getId());
-				pipeConfigMapper.updateById(item);
-			}
-		}
-	}
-
 }