Browse Source

添加万达关系映射接口

fengyanjie 3 years ago
parent
commit
b21ef176f8

+ 2 - 2
dmp-rwd/src/main/java/com/persagy/dmp/rwd/controller/ClassDefWdController.java

@@ -4,7 +4,7 @@ import com.persagy.common.criteria.JacksonCriteria;
 import com.persagy.common.json.JacksonMapper;
 import com.persagy.common.web.PagedResponse;
 import com.persagy.dmp.rwd.model.ClassDefWdModel;
-import com.persagy.dmp.rwd.service.ClassDefService;
+import com.persagy.dmp.rwd.service.ClassDefWdService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/rwd/def/class/wd")
 public class ClassDefWdController {
     @Autowired
-    private ClassDefService service;
+    private ClassDefWdService service;
 
 //	@PostMapping("")
 //	public ListResponse<ClassDefModel> queryClass(@RequestParam(name = "groupCode", required = false) String groupCode,

+ 30 - 34
dmp-rwd/src/main/java/com/persagy/dmp/rwd/service/ClassDefService.java

@@ -11,9 +11,8 @@ import com.persagy.common.web.PagedResponse;
 import com.persagy.dmp.rwd.entity.*;
 import com.persagy.dmp.rwd.enums.FuncidDataType;
 import com.persagy.dmp.rwd.enums.ObjType;
-import com.persagy.dmp.rwd.model.ClassDefWdModel;
+import com.persagy.dmp.rwd.model.ClassDefModel;
 import com.persagy.dmp.rwd.model.FuncidDefModel;
-import com.persagy.dmp.rwd.repository.ClassDefWdRepository;
 import com.persagy.dmp.rwd.util.ClassCodeUtils;
 import com.querydsl.core.types.dsl.BooleanExpression;
 import lombok.extern.slf4j.Slf4j;
@@ -30,9 +29,6 @@ import java.util.stream.Collectors;
 public class ClassDefService extends BaseService {
 
     @Autowired
-    private ClassDefWdRepository classDefWdRepository;
-
-    @Autowired
     private FuncidDefService funcidDefService;
 
     @Autowired
@@ -41,8 +37,8 @@ public class ClassDefService extends BaseService {
     @Autowired
     private ClassCodeUtils classCodeUtils;
 
-    public ListResponse<ClassDefWdModel> queryClass(String groupCode, String schemaId, String projectId, String appId, Boolean subFlag, JacksonCriteria criteria) {
-        ListResponse<ClassDefWdModel> resp = new ListResponse<>();
+    public ListResponse<ClassDefModel> queryClass(String groupCode, String schemaId, String projectId, String appId, Boolean subFlag, JacksonCriteria criteria) {
+        ListResponse<ClassDefModel> resp = new ListResponse<>();
         OrgParam orgParam = prepareParam(resp);
         if (!resp.success()) {
             return resp;
@@ -70,7 +66,7 @@ public class ClassDefService extends BaseService {
             }
         }
 
-        Map<String, ClassDefWdModel> map = new HashMap<>();
+        Map<String, ClassDefModel> map = new HashMap<>();
         // 查询平台级
         JacksonCriteria jacksonCriteria = JacksonCriteria.newInstance();
         jacksonCriteria.getCriteria().setAll(criteria.getCriteria());
@@ -78,8 +74,8 @@ public class ClassDefService extends BaseService {
         jacksonCriteria.add("groupCode", "0");
         jacksonCriteria.setWithoutCount(true);
         setSharding("0", "0"); // sharding
-        PagedResponse<ClassDefWdModel> queryResponse = query(jacksonCriteria);
-        for (ClassDefWdModel model : queryResponse.getData()) {
+        PagedResponse<ClassDefModel> queryResponse = query(jacksonCriteria);
+        for (ClassDefModel model : queryResponse.getData()) {
             map.put(model.getCode(), model);
         }
 
@@ -92,7 +88,7 @@ public class ClassDefService extends BaseService {
             jacksonCriteria.setWithoutCount(true);
             setSharding(orgParam.groupCode, "0"); // sharding
             queryResponse = query(groupCriteria);
-            for (ClassDefWdModel model : queryResponse.getData()) {
+            for (ClassDefModel model : queryResponse.getData()) {
                 map.put(model.getCode(), model);
             }
         }
@@ -107,7 +103,7 @@ public class ClassDefService extends BaseService {
             jacksonCriteria.setWithoutCount(true);
             setSharding(orgParam.groupCode, orgParam.projectId); // sharding
             queryResponse = query(jacksonCriteria);
-            for (ClassDefWdModel model : queryResponse.getData()) {
+            for (ClassDefModel model : queryResponse.getData()) {
                 map.put(model.getCode(), model);
             }
         }
@@ -124,9 +120,9 @@ public class ClassDefService extends BaseService {
 
             if (classCodes.size() > 0) {
                 // 方案有订阅, 去除未订阅的内容
-                Iterator<Map.Entry<String, ClassDefWdModel>> iterator = map.entrySet().iterator();
+                Iterator<Map.Entry<String, ClassDefModel>> iterator = map.entrySet().iterator();
                 while (iterator.hasNext()) {
-                    Map.Entry<String, ClassDefWdModel> next = iterator.next();
+                    Map.Entry<String, ClassDefModel> next = iterator.next();
                     if (!classCodes.contains(next.getKey())) {
                         iterator.remove();
                     }
@@ -146,9 +142,9 @@ public class ClassDefService extends BaseService {
 
             if (classCodes.size() > 0) {
                 // 方案有订阅, 去除未订阅的内容
-                Iterator<Map.Entry<String, ClassDefWdModel>> iterator = map.entrySet().iterator();
+                Iterator<Map.Entry<String, ClassDefModel>> iterator = map.entrySet().iterator();
                 while (iterator.hasNext()) {
-                    Map.Entry<String, ClassDefWdModel> next = iterator.next();
+                    Map.Entry<String, ClassDefModel> next = iterator.next();
                     if (!classCodes.contains(next.getKey())) {
                         iterator.remove();
                     }
@@ -160,7 +156,7 @@ public class ClassDefService extends BaseService {
         if (subFlag && map.size() > 0) {
 
             //List<FuncidDataType> enumTypeList = Arrays.asList(FuncidDataType.ENUM);
-            List<String> classCodeList = map.values().stream().map(ClassDefWdModel::getCode).collect(Collectors.toList());
+            List<String> classCodeList = map.values().stream().map(ClassDefModel::getCode).collect(Collectors.toList());
             JacksonCriteria funcidCriteria = JacksonCriteria.newInstance();
             funcidCriteria.add("classCode").in(classCodeList);
             funcidCriteria.add("dataType", FuncidDataType.ENUM);
@@ -174,7 +170,7 @@ public class ClassDefService extends BaseService {
                 }
 
                 String classCode = funcid.getClassCode();
-                ClassDefWdModel classDefModel = map.get(classCode);
+                ClassDefModel classDefModel = map.get(classCode);
                 if (classDefModel == null) {
                     continue;
                 }
@@ -185,7 +181,7 @@ public class ClassDefService extends BaseService {
 
                 for (JsonNode jsonNode : dataSource) {
                     ObjectNode item = (ObjectNode) jsonNode;
-                    ClassDefWdModel model = new ClassDefWdModel();
+                    ClassDefModel model = new ClassDefModel();
                     BeanUtils.copyProperties(classDefModel, model);
                     model.setCode(classDefModel.getCode() + "&" + funcid.getCode() + "=" + item.get("code").asText());
                     model.setName(classDefModel.getName() + "-" + item.get("name").asText());
@@ -198,7 +194,7 @@ public class ClassDefService extends BaseService {
         }
 
         //
-        List<ClassDefWdModel> data = new ArrayList<>(map.size());
+        List<ClassDefModel> data = new ArrayList<>(map.size());
         data.addAll(map.values());
         resp.setData(data);
         return resp;
@@ -208,19 +204,19 @@ public class ClassDefService extends BaseService {
     private List<BooleanExpression> parse(ObjectNode object) {
         // TODO
         List<BooleanExpression> list = new LinkedList<>();
-        QClassDefWd qt = QClassDefWd.classDefWd;
+        QClassDef qt = QClassDef.classDef;
         list.addAll(CriteriaUtils.parse(qt.objType, object.get("objType"), ObjType.class));
         return list;
     }
 
-    public PagedResponse<ClassDefWdModel> query(JacksonCriteria criteria) {
-        PagedResponse<ClassDefWd> resp = criteriaUtils.query(QClassDefWd.classDefWd, this::parse, criteria);
-        PagedResponse<ClassDefWdModel> result = new PagedResponse<>();
+    public PagedResponse<ClassDefModel> query(JacksonCriteria criteria) {
+        PagedResponse<ClassDef> resp = criteriaUtils.query(QClassDef.classDef, this::parse, criteria);
+        PagedResponse<ClassDefModel> result = new PagedResponse<>();
         result.setCount(resp.getCount());
-        List<ClassDefWd> dataList = resp.getData();
+        List<ClassDef> dataList = resp.getData();
         if (dataList != null && dataList.size() > 0) {
-            List<ClassDefWdModel> collect = dataList.stream().map(entity -> {
-                ClassDefWdModel model = entity.toModel();
+            List<ClassDefModel> collect = dataList.stream().map(entity -> {
+                ClassDefModel model = entity.toModel();
                 return model;
             }).collect(Collectors.toList());
             result.setData(collect);
@@ -229,25 +225,25 @@ public class ClassDefService extends BaseService {
     }
 
     @Transactional
-    public MapResponse create(ClassDefWdModel param) {
+    public MapResponse create(ClassDefModel param) {
         MapResponse response = new MapResponse();
         // TODO
-        ClassDefWd entity = ClassDefWd.fromModel(param);
-        classDefWdRepository.save(entity);
+        ClassDef entity = ClassDef.fromModel(param);
+        classDefRepository.save(entity);
         return response;
     }
 
     @Transactional
-    public MapResponse update(ClassDefWdModel param) {
+    public MapResponse update(ClassDefModel param) {
         MapResponse response = new MapResponse();
         // TODO
-        ClassDefWd entity = ClassDefWd.fromModel(param);
-        classDefWdRepository.save(entity);
+        ClassDef entity = ClassDef.fromModel(param);
+        classDefRepository.save(entity);
         return response;
     }
 
     @Transactional
-    public MapResponse delete(ClassDefWdModel param) {
+    public MapResponse delete(ClassDefModel param) {
         MapResponse response = new MapResponse();
         // TODO
         return response;

+ 40 - 236
dmp-rwd/src/main/java/com/persagy/dmp/rwd/service/ClassDefWdService.java

@@ -1,258 +1,62 @@
 package com.persagy.dmp.rwd.service;
 
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.common.criteria.CriteriaUtils;
 import com.persagy.common.criteria.JacksonCriteria;
-import com.persagy.common.web.ListResponse;
-import com.persagy.common.web.MapResponse;
 import com.persagy.common.web.PagedResponse;
-import com.persagy.dmp.rwd.entity.*;
-import com.persagy.dmp.rwd.enums.FuncidDataType;
+import com.persagy.dmp.rwd.entity.ClassDefWd;
+import com.persagy.dmp.rwd.entity.QClassDefWd;
 import com.persagy.dmp.rwd.enums.ObjType;
-import com.persagy.dmp.rwd.model.ClassDefModel;
-import com.persagy.dmp.rwd.model.FuncidDefModel;
-import com.persagy.dmp.rwd.repository.ClassDefRepository;
+import com.persagy.dmp.rwd.model.ClassDefWdModel;
+import com.persagy.dmp.rwd.repository.ClassDefWdRepository;
 import com.persagy.dmp.rwd.util.ClassCodeUtils;
 import com.querydsl.core.types.dsl.BooleanExpression;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import javax.transaction.Transactional;
-import java.util.*;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.stream.Collectors;
 
 @Slf4j
 @Service
 public class ClassDefWdService extends BaseService {
 
-	@Autowired
-	private ClassDefRepository classDefRepository;
-
-	@Autowired
-	private FuncidDefService funcidDefService;
-
-	@Autowired
-	private CriteriaUtils criteriaUtils;
-
-	@Autowired
-	private ClassCodeUtils classCodeUtils;
-
-	public ListResponse<ClassDefModel> queryClass(String groupCode, String schemaId, String projectId, String appId, Boolean subFlag, JacksonCriteria criteria) {
-		ListResponse<ClassDefModel> resp = new ListResponse<>();
-		OrgParam orgParam = prepareParam(resp);
-		if (!resp.success()) {
-			return resp;
-		}
-		//
-		classCodeUtils.prepareCriteriaForFuncid(criteria, "code");
-
-		if (orgParam.appId != null && (orgParam.projectId == null || "0".equalsIgnoreCase(orgParam.projectId))) {
-			resp.setFail("传入appId时必须同时传入projectId");
-			return resp;
-		}
-
-		if (orgParam.projectId != null && !"0".equalsIgnoreCase(orgParam.projectId)) {
-			if (orgParam.groupCode == null || "0".equals(orgParam.groupCode)) {
-				resp.setFail("传入porjectId时必须同时传入groupCode");
-				return resp;
-			}
-			QSchemaProject pqt = QSchemaProject.schemaProject;
-			Optional<SchemaProject> one = schemaProjectRepository.findOne(pqt.projectId.eq(orgParam.projectId).and(pqt.groupCode.eq(orgParam.groupCode)));
-			if (one.isPresent()) {
-				orgParam.schemaId = one.get().getSchemaId();
-			} else {
-				resp.setFail("当前项目未配置集团方案");
-				return resp;
-			}
-		}
-
-		Map<String, ClassDefModel> map = new HashMap<>();
-		// 查询平台级
-		JacksonCriteria jacksonCriteria = JacksonCriteria.newInstance();
-		jacksonCriteria.getCriteria().setAll(criteria.getCriteria());
-		jacksonCriteria.add("type", "common");
-		jacksonCriteria.add("groupCode", "0");
-		jacksonCriteria.setWithoutCount(true);
-		setSharding("0", "0"); // sharding
-		PagedResponse<ClassDefModel> queryResponse = query(jacksonCriteria);
-		for (ClassDefModel model : queryResponse.getData()) {
-			map.put(model.getCode(), model);
-		}
-
-		// 查询集团级
-		if (orgParam.groupCode != null && !"0".equalsIgnoreCase(orgParam.groupCode)) {
-			JacksonCriteria groupCriteria = JacksonCriteria.newInstance();
-			groupCriteria.getCriteria().setAll(criteria.getCriteria());
-			groupCriteria.add("type", "group");
-			groupCriteria.add("groupCode", orgParam.groupCode);
-			jacksonCriteria.setWithoutCount(true);
-			setSharding(orgParam.groupCode, "0"); // sharding
-			queryResponse = query(groupCriteria);
-			for (ClassDefModel model : queryResponse.getData()) {
-				map.put(model.getCode(), model);
-			}
-		}
-
-		// 查询项目级
-		if (orgParam.projectId != null && !"0".equalsIgnoreCase(orgParam.projectId)) {
-			jacksonCriteria = JacksonCriteria.newInstance();
-			jacksonCriteria.getCriteria().setAll(criteria.getCriteria());
-			jacksonCriteria.add("type", "project");
-			jacksonCriteria.add("groupCode", orgParam.groupCode);
-			jacksonCriteria.add("projectId", orgParam.projectId);
-			jacksonCriteria.setWithoutCount(true);
-			setSharding(orgParam.groupCode, orgParam.projectId); // sharding
-			queryResponse = query(jacksonCriteria);
-			for (ClassDefModel model : queryResponse.getData()) {
-				map.put(model.getCode(), model);
-			}
-		}
-
-		// 筛选方案订阅
-		if (orgParam.schemaId != null && !"0".equalsIgnoreCase(orgParam.schemaId)) {
-			QSchemaClass qsc = QSchemaClass.schemaClass;
-			setSharding(orgParam.groupCode, orgParam.projectId); // sharding
-			Iterable<SchemaClass> all = schemaClassRepository.findAll(qsc.schemaId.eq(orgParam.schemaId).and(qsc.groupCode.eq(orgParam.groupCode)));
-			Set<String> classCodes = new HashSet<>();
-			for (SchemaClass item : all) {
-				classCodes.add(item.getClassCode());
-			}
-
-			if (classCodes.size() > 0) {
-				// 方案有订阅, 去除未订阅的内容
-				Iterator<Map.Entry<String, ClassDefModel>> iterator = map.entrySet().iterator();
-				while (iterator.hasNext()) {
-					Map.Entry<String, ClassDefModel> next = iterator.next();
-					if (!classCodes.contains(next.getKey())) {
-						iterator.remove();
-					}
-				}
-			}
-		}
-
-		// 筛选应用订阅部分
-		if (orgParam.appId != null && !"0".equalsIgnoreCase(orgParam.appId)) {
-			QAppClass qac = QAppClass.appClass;
-			setSharding(orgParam.groupCode, orgParam.projectId); // sharding
-			Iterable<AppClass> all = appClassRepository.findAll(qac.appId.eq(appId).and(qac.groupCode.eq(orgParam.groupCode).and(qac.projectId.eq(orgParam.projectId))));
-			Set<String> classCodes = new HashSet<>();
-			for (AppClass item : all) {
-				classCodes.add(item.getClassCode());
-			}
-
-			if (classCodes.size() > 0) {
-				// 方案有订阅, 去除未订阅的内容
-				Iterator<Map.Entry<String, ClassDefModel>> iterator = map.entrySet().iterator();
-				while (iterator.hasNext()) {
-					Map.Entry<String, ClassDefModel> next = iterator.next();
-					if (!classCodes.contains(next.getKey())) {
-						iterator.remove();
-					}
-				}
-			}
-		}
-		// 处理子分类
-		// TODO
-		if (subFlag && map.size() > 0) {
-
-			//List<FuncidDataType> enumTypeList = Arrays.asList(FuncidDataType.ENUM);
-			List<String> classCodeList = map.values().stream().map(ClassDefModel::getCode).collect(Collectors.toList());
-			JacksonCriteria funcidCriteria = JacksonCriteria.newInstance();
-			funcidCriteria.add("classCode").in(classCodeList);
-			funcidCriteria.add("dataType", FuncidDataType.ENUM);
-			funcidCriteria.setWithoutCount(true);
-			ListResponse<FuncidDefModel> funcidDefModelListResponse = funcidDefService.queryFuncid(groupCode, schemaId, projectId, appId, funcidCriteria);
-			List<FuncidDefModel> funcidList = funcidDefModelListResponse.getData() != null ? funcidDefModelListResponse.getData() : Collections.emptyList();
-
-			for (FuncidDefModel funcid : funcidList) {
-				if (!funcid.getSubFlag()) {
-					continue;
-				}
-
-				String classCode = funcid.getClassCode();
-				ClassDefModel classDefModel = map.get(classCode);
-				if (classDefModel == null) {
-					continue;
-				}
-				ArrayNode dataSource = funcid.getDataSource();
-				if (dataSource.size() == 0) {
-					continue;
-				}
-
-				for (JsonNode jsonNode : dataSource) {
-					ObjectNode item = (ObjectNode) jsonNode;
-					ClassDefModel model = new ClassDefModel();
-					BeanUtils.copyProperties(classDefModel, model);
-					model.setCode(classDefModel.getCode() + "&" + funcid.getCode() + "=" + item.get("code").asText());
-					model.setName(classDefModel.getName() + "-" + item.get("name").asText());
-					model.setAliasCode(classDefModel.getAliasCode() + "-" + item.get("code").asText());
-					model.setAliasName(classDefModel.getAliasName() + "-" + item.get("name").asText());
-					map.put(model.getCode(), model);
-				}
-				map.remove(classCode);
-			}
-		}
-
-		//
-		List<ClassDefModel> data = new ArrayList<>(map.size());
-		data.addAll(map.values());
-		resp.setData(data);
-		return resp;
-	}
-
-
-	private List<BooleanExpression> parse(ObjectNode object) {
-		// TODO
-		List<BooleanExpression> list = new LinkedList<>();
-		QClassDef qt = QClassDef.classDef;
-		list.addAll(CriteriaUtils.parse(qt.objType, object.get("objType"), ObjType.class));
-		return list;
-	}
-
-	public PagedResponse<ClassDefModel> query(JacksonCriteria criteria) {
-		PagedResponse<ClassDef> resp = criteriaUtils.query(QClassDef.classDef, this::parse, criteria);
-		PagedResponse<ClassDefModel> result = new PagedResponse<>();
-		result.setCount(resp.getCount());
-		List<ClassDef> dataList = resp.getData();
-		if (dataList != null && dataList.size() > 0) {
-			List<ClassDefModel> collect = dataList.stream().map(entity -> {
-				ClassDefModel model = entity.toModel();
-				return model;
-			}).collect(Collectors.toList());
-			result.setData(collect);
-		}
-		return result;
-	}
-
-	@Transactional
-	public MapResponse create(ClassDefModel param) {
-		MapResponse response = new MapResponse();
-		// TODO
-		ClassDef entity = ClassDef.fromModel(param);
-		classDefRepository.save(entity);
-		return response;
-	}
-
-	@Transactional
-	public MapResponse update(ClassDefModel param) {
-		MapResponse response = new MapResponse();
-		// TODO
-		ClassDef entity = ClassDef.fromModel(param);
-		classDefRepository.save(entity);
-		return response;
-	}
-
-	@Transactional
-	public MapResponse delete(ClassDefModel param) {
-		MapResponse response = new MapResponse();
-		// TODO
-		return response;
-	}
-
+    @Autowired
+    private ClassDefWdRepository classDefWdRepository;
+
+    @Autowired
+    private FuncidDefService funcidDefService;
+
+    @Autowired
+    private CriteriaUtils criteriaUtils;
+
+    @Autowired
+    private ClassCodeUtils classCodeUtils;
+
+    private List<BooleanExpression> parse(ObjectNode object) {
+        // TODO
+        List<BooleanExpression> list = new LinkedList<>();
+        QClassDefWd qt = QClassDefWd.classDefWd;
+        list.addAll(CriteriaUtils.parse(qt.objType, object.get("objType"), ObjType.class));
+        return list;
+    }
+
+    public PagedResponse<ClassDefWdModel> query(JacksonCriteria criteria) {
+        PagedResponse<ClassDefWd> resp = criteriaUtils.query(QClassDefWd.classDefWd, this::parse, criteria);
+        PagedResponse<ClassDefWdModel> result = new PagedResponse<>();
+        result.setCount(resp.getCount());
+        List<ClassDefWd> dataList = resp.getData();
+        if (dataList != null && dataList.size() > 0) {
+            List<ClassDefWdModel> collect = dataList.stream().map(entity -> {
+                ClassDefWdModel model = entity.toModel();
+                return model;
+            }).collect(Collectors.toList());
+            result.setData(collect);
+        }
+        return result;
+    }
 
 }