Sfoglia il codice sorgente

添加万达关系映射接口

fengyanjie 3 anni fa
parent
commit
2d6271649a

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

@@ -0,0 +1,52 @@
+package com.persagy.dmp.rwd.controller;
+
+import com.persagy.common.criteria.JacksonCriteria;
+import com.persagy.common.json.JacksonMapper;
+import com.persagy.common.web.ListResponse;
+import com.persagy.common.web.PagedResponse;
+import com.persagy.dmp.rwd.model.ClassDefModel;
+import com.persagy.dmp.rwd.service.ClassDefService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@Slf4j
+@RestController
+@RequestMapping("/rwd/def/class/wd")
+public class ClassDefWdController {
+	@Autowired
+	private ClassDefService service;
+
+//	@PostMapping("")
+//	public ListResponse<ClassDefModel> queryClass(@RequestParam(name = "groupCode", required = false) String groupCode,
+//												  @RequestParam(name = "schemaId", required = false) String schemaId,
+//												  @RequestParam(name = "projectId", required = false) String projectId,
+//												  @RequestParam(name = "appId", required = false) String appId,
+//												  @RequestParam(name = "subFlag", required = false, defaultValue = "false") Boolean subFlag,
+//												  @RequestBody JacksonCriteria criteria) {
+//		log.info("/class/query: {}", JacksonMapper.toSimpleJson(criteria));
+//		return service.queryClass(groupCode, schemaId, projectId, appId, subFlag, criteria);
+//	}
+
+	@PostMapping("/query")
+	public PagedResponse<ClassDefModel> query(@RequestBody JacksonCriteria criteria) {
+		log.info("================================= /class/query: {}", JacksonMapper.toSimpleJson(criteria));
+		return service.query(criteria);
+	}
+
+//	@PostMapping("/create")
+//	public MapResponse create(@RequestBody ClassDefModel param){
+//		return service.create(param);
+//	}
+//
+//	@PostMapping("/update")
+//	public MapResponse update(@RequestBody ClassDefModel param){
+//		return service.update(param);
+//	}
+//
+//	@PostMapping("/delete")
+//	public MapResponse delete(@RequestBody ClassDefModel param){
+//		return service.delete(param);
+//	}
+
+}

+ 70 - 0
dmp-rwd/src/main/java/com/persagy/dmp/rwd/entity/ClassDefWd.java

@@ -0,0 +1,70 @@
+package com.persagy.dmp.rwd.entity;
+
+import com.persagy.dmp.rwd.enums.ObjType;
+import com.persagy.dmp.rwd.model.ClassDefModel;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.persistence.*;
+
+@Setter
+@Getter
+@Entity
+@Table(name = "rwd_def_class_custom")
+@IdClass(GroupPK.class)
+public class ClassDefWd {
+
+	@Id
+	private String id;
+	@Id
+	private String groupCode;
+	private String code;
+	@Enumerated(value = EnumType.STRING)
+	private ObjType objType;
+	private String name;
+	private String aliasCode;
+	private String aliasName;
+	private String type;
+	private String projectId;
+	private String majorCode;
+	private String systemCode;
+	private String equipmentCode;
+	private String parentCode;
+
+	public static ClassDefWd fromModel(ClassDefModel model) {
+		ClassDefWd entity = new ClassDefWd();
+		entity.setId(model.getId());
+		entity.setCode(model.getCode());
+		entity.setObjType(model.getObjType());
+		entity.setName(model.getName());
+		entity.setAliasCode(model.getAliasCode());
+		entity.setAliasName(model.getAliasName());
+		entity.setType(model.getType());
+		entity.setGroupCode(model.getGroupCode());
+		entity.setProjectId(model.getProjectId());
+		entity.setMajorCode(model.getMajorCode());
+		entity.setSystemCode(model.getSystemCode());
+		entity.setEquipmentCode(model.getEquipmentCode());
+		entity.setParentCode(model.getParentCode());
+		return entity;
+	}
+
+	public ClassDefModel toModel() {
+		ClassDefModel model = new ClassDefModel();
+		model.setId(this.getId());
+		model.setCode(this.getCode());
+		model.setObjType(this.getObjType());
+		model.setName(this.getName());
+		model.setAliasCode(this.getAliasCode());
+		model.setAliasName(this.getAliasName());
+		model.setType(this.getType());
+		model.setGroupCode(this.getGroupCode());
+		model.setProjectId(this.getProjectId());
+		model.setMajorCode(this.getMajorCode());
+		model.setSystemCode(this.getSystemCode());
+		model.setEquipmentCode(this.getEquipmentCode());
+		model.setParentCode(this.getParentCode());
+		return model;
+	}
+
+}

+ 9 - 0
dmp-rwd/src/main/java/com/persagy/dmp/rwd/repository/ClassDefWdRepository.java

@@ -0,0 +1,9 @@
+package com.persagy.dmp.rwd.repository;
+
+import com.persagy.dmp.rwd.entity.ClassDefWd;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.querydsl.QuerydslPredicateExecutor;
+
+public interface ClassDefWdRepository extends JpaRepository<ClassDefWd, String>, QuerydslPredicateExecutor<ClassDefWd> {
+}
+

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

@@ -13,7 +13,7 @@ import com.persagy.dmp.rwd.enums.FuncidDataType;
 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.repository.ClassDefWdRepository;
 import com.persagy.dmp.rwd.util.ClassCodeUtils;
 import com.querydsl.core.types.dsl.BooleanExpression;
 import lombok.extern.slf4j.Slf4j;
@@ -29,229 +29,229 @@ import java.util.stream.Collectors;
 @Service
 public class ClassDefService extends BaseService {
 
-	@Autowired
-	private ClassDefRepository classDefRepository;
+    @Autowired
+    private ClassDefWdRepository classDefWdRepository;
 
-	@Autowired
-	private FuncidDefService funcidDefService;
+    @Autowired
+    private FuncidDefService funcidDefService;
 
-	@Autowired
-	private CriteriaUtils criteriaUtils;
+    @Autowired
+    private CriteriaUtils criteriaUtils;
 
-	@Autowired
-	private ClassCodeUtils classCodeUtils;
+    @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");
+    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.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;
-			}
-		}
+        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);
-		}
+        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.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.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 (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 (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 (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) {
+            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();
+            //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;
-				}
+            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;
-				}
+                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);
-			}
-		}
+                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;
-	}
+        //
+        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;
-	}
+    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<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;
-	}
+    public PagedResponse<ClassDefModel> query(JacksonCriteria criteria) {
+        PagedResponse<ClassDefWd> resp = criteriaUtils.query(QClassDefWd.classDefWd, this::parse, criteria);
+        PagedResponse<ClassDefModel> result = new PagedResponse<>();
+        result.setCount(resp.getCount());
+        List<ClassDefWd> 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 create(ClassDefModel param) {
+        MapResponse response = new MapResponse();
+        // TODO
+        ClassDefWd entity = ClassDefWd.fromModel(param);
+        classDefWdRepository.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 update(ClassDefModel param) {
+        MapResponse response = new MapResponse();
+        // TODO
+        ClassDefWd entity = ClassDefWd.fromModel(param);
+        classDefWdRepository.save(entity);
+        return response;
+    }
 
-	@Transactional
-	public MapResponse delete(ClassDefModel param) {
-		MapResponse response = new MapResponse();
-		// TODO
-		return response;
-	}
+    @Transactional
+    public MapResponse delete(ClassDefModel param) {
+        MapResponse response = new MapResponse();
+        // TODO
+        return response;
+    }
 
 
 }

+ 258 - 0
dmp-rwd/src/main/java/com/persagy/dmp/rwd/service/ClassDefWdService.java

@@ -0,0 +1,258 @@
+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.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.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.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;
+	}
+
+
+}
+