|
@@ -15,11 +15,20 @@ import com.persagy.dmp.rwd.entity.QObjectInstance;
|
|
import com.persagy.dmp.rwd.entity.QRelationInstance;
|
|
import com.persagy.dmp.rwd.entity.QRelationInstance;
|
|
import com.persagy.dmp.rwd.enums.FuncidDataType;
|
|
import com.persagy.dmp.rwd.enums.FuncidDataType;
|
|
import com.persagy.dmp.rwd.model.FuncidDefModel;
|
|
import com.persagy.dmp.rwd.model.FuncidDefModel;
|
|
|
|
+import com.persagy.dmp.rwd.repository.ObjectInstanceRepository;
|
|
|
|
+import com.persagy.dmp.rwd.repository.ProjectDao;
|
|
import com.querydsl.core.types.dsl.BooleanExpression;
|
|
import com.querydsl.core.types.dsl.BooleanExpression;
|
|
import com.querydsl.core.types.dsl.Expressions;
|
|
import com.querydsl.core.types.dsl.Expressions;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.persistence.EntityManager;
|
|
|
|
+import javax.persistence.Query;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -35,6 +44,10 @@ public class ObjectInstanceQueryService extends BaseService {
|
|
private FuncidDefService funcidDefService;
|
|
private FuncidDefService funcidDefService;
|
|
|
|
|
|
private Set<String> set = new HashSet<>();
|
|
private Set<String> set = new HashSet<>();
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProjectDao projectDao;
|
|
|
|
+ @Value("${persagy.mysql.database:dmp_rwd}")
|
|
|
|
+ private String rwdDatabaseName;
|
|
|
|
|
|
{
|
|
{
|
|
set.add("ProjID");
|
|
set.add("ProjID");
|
|
@@ -301,96 +314,153 @@ public class ObjectInstanceQueryService extends BaseService {
|
|
|
|
|
|
public PagedResponse<ObjectNode> query(JacksonCriteria criteria) {
|
|
public PagedResponse<ObjectNode> query(JacksonCriteria criteria) {
|
|
PagedResponse<ObjectNode> result = new PagedResponse<>();
|
|
PagedResponse<ObjectNode> result = new PagedResponse<>();
|
|
-// Integer grouping = criteria.getInteger("grouping");
|
|
|
|
-// if (grouping == null) {
|
|
|
|
-// criteria.add("grouping", 1);
|
|
|
|
-// }
|
|
|
|
super.checkParam(result, RwdConstants.QUERY_GROUPCODE, RwdConstants.QUERY_PROJECTID);
|
|
super.checkParam(result, RwdConstants.QUERY_GROUPCODE, RwdConstants.QUERY_PROJECTID);
|
|
if (!result.success()) {
|
|
if (!result.success()) {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
criteria.add(RwdConstants.OBJECT_GROUPCODE, DmpParameterStorage.getGroupCode());
|
|
criteria.add(RwdConstants.OBJECT_GROUPCODE, DmpParameterStorage.getGroupCode());
|
|
criteria.add(RwdConstants.OBJECT_PROJECTID, DmpParameterStorage.getProjectId());
|
|
criteria.add(RwdConstants.OBJECT_PROJECTID, DmpParameterStorage.getProjectId());
|
|
|
|
+ queryObjInstance(criteria,result);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ /***
|
|
|
|
+ * Description: 查询对象实例
|
|
|
|
+ * @param criteria : 查询条件
|
|
|
|
+ * @param result : 结果
|
|
|
|
+ * @return : void
|
|
|
|
+ * @author : lijie
|
|
|
|
+ * @date :2021/6/30 17:48
|
|
|
|
+ * Update By lijie 2021/6/30 17:48
|
|
|
|
+ */
|
|
|
|
+ private void queryObjInstance(JacksonCriteria criteria,PagedResponse<ObjectNode> result){
|
|
prepareCriteria(criteria);
|
|
prepareCriteria(criteria);
|
|
PagedResponse<ObjectInstance> resp = criteriaUtils.query(QObjectInstance.objectInstance, this::parse, criteria);
|
|
PagedResponse<ObjectInstance> resp = criteriaUtils.query(QObjectInstance.objectInstance, this::parse, criteria);
|
|
result.setCount(resp.getCount());
|
|
result.setCount(resp.getCount());
|
|
List<ObjectInstance> dataList = resp.getData();
|
|
List<ObjectInstance> dataList = resp.getData();
|
|
|
|
+ analysisQueryResult(dataList,criteria,result);
|
|
|
|
+ }
|
|
|
|
+ /***
|
|
|
|
+ * Description:解析查询结果
|
|
|
|
+ * @param dataList : 结果集
|
|
|
|
+ * @return : void
|
|
|
|
+ * @author : lijie
|
|
|
|
+ * @date :2021/6/30 22:36
|
|
|
|
+ * Update By lijie 2021/6/30 22:36
|
|
|
|
+ */
|
|
|
|
+ private void analysisQueryResult(List<ObjectInstance> dataList,JacksonCriteria criteria,PagedResponse<ObjectNode> result) {
|
|
Map<String, List<String>> infoCodes = new HashMap<>();
|
|
Map<String, List<String>> infoCodes = new HashMap<>();
|
|
- if (dataList != null && dataList.size() > 0) {
|
|
|
|
- List<ObjectNode> collect = dataList.stream().map(entity -> {
|
|
|
|
- ObjectNode model = JsonNodeFactory.instance.objectNode();
|
|
|
|
- model.put(RwdConstants.OBJECT_ID, entity.getId());
|
|
|
|
- model.put(RwdConstants.OBJECT_CLASSCODE, entity.getClassCode());
|
|
|
|
- model.put(RwdConstants.OBJECT_PROJECTID, entity.getProjectId());
|
|
|
|
- model.put(RwdConstants.OBJECT_GROUPING, entity.getGrouping());
|
|
|
|
- model.put(RwdConstants.OBJECT_OBJTYPE, entity.getObjType());
|
|
|
|
- model.put(RwdConstants.OBJECT_VALID, entity.getValid());
|
|
|
|
- if (entity.getName() != null) {
|
|
|
|
- model.put(RwdConstants.OBJECT_NAME, entity.getName());
|
|
|
|
- }
|
|
|
|
- if (entity.getLocalId() != null) {
|
|
|
|
- model.put(RwdConstants.OBJECT_LOCALID, entity.getLocalId());
|
|
|
|
- }
|
|
|
|
- if (entity.getLocalName() != null) {
|
|
|
|
- model.put(RwdConstants.OBJECT_LOCALNAME, entity.getLocalName());
|
|
|
|
- }
|
|
|
|
- if (entity.getCreateUser() != null) {
|
|
|
|
- model.put(RwdConstants.OBJECT_CREATE_USER, entity.getCreateUser());
|
|
|
|
- }
|
|
|
|
- if (entity.getCreateTime() != null) {
|
|
|
|
- model.putPOJO(RwdConstants.OBJECT_CREATE_TIME, entity.getCreateTime());
|
|
|
|
- }
|
|
|
|
- if (entity.getCreateApp() != null) {
|
|
|
|
- model.put(RwdConstants.OBJECT_CREATE_APP, entity.getCreateApp());
|
|
|
|
- }
|
|
|
|
- if (entity.getUpdateUser() != null) {
|
|
|
|
- model.put(RwdConstants.OBJECT_UPDATE_USER, entity.getUpdateUser());
|
|
|
|
- }
|
|
|
|
- if (entity.getUpdateTime() != null) {
|
|
|
|
- model.putPOJO(RwdConstants.OBJECT_UPDATE_TIME, entity.getUpdateTime());
|
|
|
|
- }
|
|
|
|
- if (entity.getUpdateApp() != null) {
|
|
|
|
- model.put(RwdConstants.OBJECT_UPDATE_APP, entity.getUpdateApp());
|
|
|
|
- }
|
|
|
|
- if (entity.getVirtualInfoCodes() != null || entity.getVirtualInfoCodes().size() == 0) {
|
|
|
|
- model.putPOJO(RwdConstants.OBJECT_VIRTUAL_INFO_CODES, entity.getVirtualInfoCodes());
|
|
|
|
- }
|
|
|
|
|
|
+ if (dataList == null || dataList.size() <= 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ List<ObjectNode> collect = dataList.stream().map(entity -> {
|
|
|
|
+ ObjectNode model = JsonNodeFactory.instance.objectNode();
|
|
|
|
+ model.put(RwdConstants.OBJECT_ID, entity.getId());
|
|
|
|
+ model.put(RwdConstants.OBJECT_CLASSCODE, entity.getClassCode());
|
|
|
|
+ model.put(RwdConstants.OBJECT_PROJECTID, entity.getProjectId());
|
|
|
|
+ model.put(RwdConstants.OBJECT_GROUPING, entity.getGrouping());
|
|
|
|
+ model.put(RwdConstants.OBJECT_OBJTYPE, entity.getObjType());
|
|
|
|
+ model.put(RwdConstants.OBJECT_VALID, entity.getValid());
|
|
|
|
+ if (entity.getName() != null) {
|
|
|
|
+ model.put(RwdConstants.OBJECT_NAME, entity.getName());
|
|
|
|
+ }
|
|
|
|
+ if (entity.getLocalId() != null) {
|
|
|
|
+ model.put(RwdConstants.OBJECT_LOCALID, entity.getLocalId());
|
|
|
|
+ }
|
|
|
|
+ if (entity.getLocalName() != null) {
|
|
|
|
+ model.put(RwdConstants.OBJECT_LOCALNAME, entity.getLocalName());
|
|
|
|
+ }
|
|
|
|
+ if (entity.getCreateUser() != null) {
|
|
|
|
+ model.put(RwdConstants.OBJECT_CREATE_USER, entity.getCreateUser());
|
|
|
|
+ }
|
|
|
|
+ if (entity.getCreateTime() != null) {
|
|
|
|
+ model.putPOJO(RwdConstants.OBJECT_CREATE_TIME, entity.getCreateTime());
|
|
|
|
+ }
|
|
|
|
+ if (entity.getCreateApp() != null) {
|
|
|
|
+ model.put(RwdConstants.OBJECT_CREATE_APP, entity.getCreateApp());
|
|
|
|
+ }
|
|
|
|
+ if (entity.getUpdateUser() != null) {
|
|
|
|
+ model.put(RwdConstants.OBJECT_UPDATE_USER, entity.getUpdateUser());
|
|
|
|
+ }
|
|
|
|
+ if (entity.getUpdateTime() != null) {
|
|
|
|
+ model.putPOJO(RwdConstants.OBJECT_UPDATE_TIME, entity.getUpdateTime());
|
|
|
|
+ }
|
|
|
|
+ if (entity.getUpdateApp() != null) {
|
|
|
|
+ model.put(RwdConstants.OBJECT_UPDATE_APP, entity.getUpdateApp());
|
|
|
|
+ }
|
|
|
|
+ if (entity.getVirtualInfoCodes() != null && entity.getVirtualInfoCodes().size() > 0) {
|
|
|
|
+ model.putPOJO(RwdConstants.OBJECT_VIRTUAL_INFO_CODES, entity.getVirtualInfoCodes());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
- String classCode = entity.getClassCode();
|
|
|
|
- Set<String> withColumns = criteria.getWithColumns();
|
|
|
|
- if (!infoCodes.containsKey(classCode)) {
|
|
|
|
- JacksonCriteria funcidCriteria = JacksonCriteria.newInstance();
|
|
|
|
- funcidCriteria.setWithoutCount(true);
|
|
|
|
- funcidCriteria.add(RwdConstants.OBJECT_CLASSCODE, classCode);
|
|
|
|
- ListResponse<FuncidDefModel> funcidDefModelListResponse = funcidDefService.queryFuncid(DmpParameterStorage.getGroupCode(),
|
|
|
|
- DmpParameterStorage.getSchemaId(), DmpParameterStorage.getProjectId(), DmpParameterStorage.getAppId(), funcidCriteria);
|
|
|
|
|
|
+ String classCode = entity.getClassCode();
|
|
|
|
+ Set<String> withColumns = criteria.getWithColumns();
|
|
|
|
+ if (!infoCodes.containsKey(classCode)) {
|
|
|
|
+ JacksonCriteria funcidCriteria = JacksonCriteria.newInstance();
|
|
|
|
+ funcidCriteria.setWithoutCount(true);
|
|
|
|
+ funcidCriteria.add(RwdConstants.OBJECT_CLASSCODE, classCode);
|
|
|
|
+ ListResponse<FuncidDefModel> funcidDefModelListResponse = funcidDefService.queryFuncid(DmpParameterStorage.getGroupCode(),
|
|
|
|
+ DmpParameterStorage.getSchemaId(), DmpParameterStorage.getProjectId(), DmpParameterStorage.getAppId(), funcidCriteria);
|
|
|
|
|
|
- if (funcidDefModelListResponse.getData() == null) {
|
|
|
|
- infoCodes.put(classCode, Collections.emptyList());
|
|
|
|
- } else {
|
|
|
|
- List<String> codes = funcidDefModelListResponse.getData().stream()
|
|
|
|
- .map(FuncidDefModel::getCode)
|
|
|
|
- .filter(code -> withColumns == null || withColumns.size() == 0 || withColumns.contains(code))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- infoCodes.put(classCode, codes);
|
|
|
|
- }
|
|
|
|
|
|
+ if (funcidDefModelListResponse.getData() == null) {
|
|
|
|
+ infoCodes.put(classCode, Collections.emptyList());
|
|
|
|
+ } else {
|
|
|
|
+ List<String> codes = funcidDefModelListResponse.getData().stream()
|
|
|
|
+ .map(FuncidDefModel::getCode)
|
|
|
|
+ .filter(code -> withColumns == null || withColumns.size() == 0 || withColumns.contains(code))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ infoCodes.put(classCode, codes);
|
|
}
|
|
}
|
|
- List<String> codes = infoCodes.get(classCode);
|
|
|
|
- ObjectNode infos = entity.getInfos();
|
|
|
|
- if (codes.size() > 0 && infos != null) {
|
|
|
|
- for (String code : codes) {
|
|
|
|
- if (infos.has(code)) {
|
|
|
|
- model.put(code, infos.get(code));
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ List<String> codes = infoCodes.get(classCode);
|
|
|
|
+ ObjectNode infos = entity.getInfos();
|
|
|
|
+ if (codes.size() > 0 && infos != null) {
|
|
|
|
+ for (String code : codes) {
|
|
|
|
+ if (infos.has(code)) {
|
|
|
|
+ model.put(code, infos.get(code));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return model;
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
- result.setData(collect);
|
|
|
|
|
|
+ }
|
|
|
|
+ return model;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ result.setData(collect);
|
|
|
|
+ result.setCount((long) collect.size());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /***
|
|
|
|
+ * Description: 批量查询项目信息.因为之前的query参数校验了项目必填,为防止改之前的代码出问题所以新增一个接口
|
|
|
|
+ * @return : com.persagy.common.web.PagedResponse<com.fasterxml.jackson.databind.node.ObjectNode>
|
|
|
|
+ * @author : lijie
|
|
|
|
+ * @date :2021/6/30 17:44
|
|
|
|
+ * Update By lijie 2021/6/30 17:44
|
|
|
|
+ */
|
|
|
|
+ public PagedResponse<ObjectNode> batchQueryProjectByIds(List<String> idList) {
|
|
|
|
+ PagedResponse<ObjectNode> result = new PagedResponse<>();
|
|
|
|
+ super.checkParam(result, RwdConstants.QUERY_GROUPCODE);
|
|
|
|
+ if (!result.success()) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ // 1.查询rwd_object所有的集团下的表
|
|
|
|
+ String tableNames = projectDao.queryRwdObjectTableNamesByGroupCode(DmpParameterStorage.getGroupCode(),rwdDatabaseName);
|
|
|
|
+ if (StringUtils.isBlank(tableNames)){
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
|
|
+ // 2.去掉最后的UNION
|
|
|
|
+ String querySql = tableNames.substring(0, tableNames.lastIndexOf("UNION"));
|
|
|
|
+ Query nativeQuery = entityManager.createNativeQuery(querySql,ObjectInstance.class);
|
|
|
|
+ List<ObjectInstance> projects = nativeQuery.getResultList();
|
|
|
|
+ //List<ObjectInstance> projects = projectDao.queryAllProjects(querySql);
|
|
|
|
+ if (CollectionUtils.isEmpty(projects)){
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(idList)
|
|
|
|
+ && !CollectionUtils.isEmpty(projects)){
|
|
|
|
+ HashSet<String> filterProjectIds = new HashSet<>(idList);
|
|
|
|
+ projects = projects.stream()
|
|
|
|
+ .filter(project->filterProjectIds.contains(project.getId()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+ JacksonCriteria criteria = JacksonCriteria.newInstance();
|
|
|
|
+ analysisQueryResult(projects,criteria,result);
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|