|
@ -3,19 +3,22 @@ package com.yihu.jw.basic.resource.service;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JavaType;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.jw.basic.resource.dao.RsResourceDefaultParamDao;
|
|
|
import com.yihu.jw.constants.ErrorCode;
|
|
|
import com.yihu.jw.basic.resource.dao.ResourceBrowseDao;
|
|
|
import com.yihu.jw.entity.ehr.resource.RsResourceDefaultParam;
|
|
|
import com.yihu.jw.exception.ApiException;
|
|
|
import com.yihu.jw.mysql.enums.Operation;
|
|
|
import com.yihu.jw.mysql.model.QueryCondition;
|
|
|
import com.yihu.jw.mysql.query.BaseJpaService;
|
|
|
import com.yihu.jw.profile.ProfileType;
|
|
|
import com.yihu.jw.profile.family.ResourceCells;
|
|
|
import com.yihu.jw.restmodel.ehr.resource.MRsColumnsModel;
|
|
|
import com.yihu.jw.basic.resource.dao.ResourceBrowseMetadataDao;
|
|
|
import com.yihu.jw.basic.resource.dao.RsResourceDao;
|
|
|
import com.yihu.jw.entity.ehr.resource.DtoResourceMetadata;
|
|
|
import com.yihu.jw.entity.ehr.resource.RsResource;
|
|
|
import com.yihu.jw.restmodel.web.Envelop;
|
|
|
import com.yihu.jw.restmodel.web.PageEnvelop;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
@ -48,6 +51,11 @@ public class ResourceBrowseService extends BaseJpaService {
|
|
|
private RsResourceService rsResourceService;
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
@Autowired
|
|
|
private RsResourceDefaultParamDao resourceDefaultParamDao;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 资源浏览 -- 资源数据元结构
|
|
|
*
|
|
@ -79,9 +87,9 @@ public class ResourceBrowseService extends BaseJpaService {
|
|
|
if (!isOtherVersion) {
|
|
|
mRsColumnsModel.setValue(r.getName());
|
|
|
if (!StringUtils.isEmpty(r.getDictCode())) {
|
|
|
mRsColumnsModel.setCode(r.getId() + "_VALUE");
|
|
|
mRsColumnsModel.setCode(r.getEhrId());
|
|
|
} else {
|
|
|
mRsColumnsModel.setCode(r.getId());
|
|
|
mRsColumnsModel.setCode(r.getEhrId());
|
|
|
}
|
|
|
mRsColumnsModel.setType(r.getColumnType());
|
|
|
mRsColumnsModel.setDict(r.getDictCode());
|
|
@ -117,7 +125,7 @@ public class ResourceBrowseService extends BaseJpaService {
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public Envelop getResourceData(String resourcesCode, String roleId, String orgCode, String areaCode, String queryCondition, Integer page, Integer size) throws Exception {
|
|
|
public Object getResourceData(String resourcesCode, String roleId, String orgCode, String areaCode, String queryCondition, Integer page, Integer size) throws Exception {
|
|
|
String queryParams = "";
|
|
|
//获取资源信息
|
|
|
List<QueryCondition> ql = new ArrayList<>();
|
|
@ -305,7 +313,7 @@ public class ResourceBrowseService extends BaseJpaService {
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public PageEnvelop getResultData(String resourcesCode, String roleId, String orgCode, String areaCode, String queryParams, Integer page, Integer size) throws Exception {
|
|
|
public Object getResultData(String resourcesCode, String roleId, String orgCode, String areaCode, String queryParams, Integer page, Integer size) throws Exception {
|
|
|
RsResource rsResources = rsResourceService.getResourceByCategory(resourcesCode,"standard");
|
|
|
if (rsResources != null) {
|
|
|
StringBuilder saas = new StringBuilder();
|
|
@ -343,11 +351,11 @@ public class ResourceBrowseService extends BaseJpaService {
|
|
|
if(method.equalsIgnoreCase("getMysqlData")){
|
|
|
Method _method = clazz.getMethod(method, new Class[]{ String.class, Integer.class, Integer.class});
|
|
|
_method.setAccessible(true);
|
|
|
return (PageEnvelop) _method.invoke(resourceBrowseDao, queryParams, page, size);
|
|
|
return _method.invoke(resourceBrowseDao, rsResources.getCode(), page, size);
|
|
|
}{
|
|
|
Method _method = clazz.getMethod(method, new Class[]{String.class, String.class, String.class, String.class, Integer.class, Integer.class});
|
|
|
_method.setAccessible(true);
|
|
|
return (PageEnvelop) _method.invoke(resourceBrowseDao, resourcesCode, roleId, saas.toString(), queryParams, page, size);
|
|
|
return _method.invoke(resourceBrowseDao, resourcesCode, roleId, saas.toString(), queryParams, page, size);
|
|
|
}
|
|
|
|
|
|
}
|
|
@ -423,78 +431,133 @@ public class ResourceBrowseService extends BaseJpaService {
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
// public Envelop getCustomizeData(String resourcesCodes, String metaData, String orgCode, String areaCode, String queryCondition, Integer page, Integer size) throws Exception {
|
|
|
// //获取资源编码列表
|
|
|
// List<String> codeList = (List<String>) objectMapper.readValue(resourcesCodes, List.class);
|
|
|
// //资源判空检查
|
|
|
// for (String code : codeList) {
|
|
|
// RsResource rsResources = rsResourceService.getResourceByCategory(code,"standard");
|
|
|
//
|
|
|
// if (rsResources == null) {
|
|
|
// throw new ApiException( "无效的资源编码" + code,ErrorCode.BAD_REQUEST.value());
|
|
|
// }
|
|
|
// }
|
|
|
// StringBuilder saas = new StringBuilder();
|
|
|
// if ("*".equals(orgCode) && "*".equals(areaCode)) {
|
|
|
// saas.append("*");
|
|
|
// } else {
|
|
|
// List<String> orgCodeList = objectMapper.readValue(orgCode, List.class);
|
|
|
// List<String> areaCodeList = objectMapper.readValue(areaCode, List.class);
|
|
|
// if (orgCodeList != null && orgCodeList.size() > 0) {
|
|
|
// orgCodeList.forEach(item -> {
|
|
|
// if (saas.length() <= 0) {
|
|
|
// saas.append("(org_code:" + item);
|
|
|
// } else {
|
|
|
// saas.append(" OR org_code:" + item);
|
|
|
// }
|
|
|
// });
|
|
|
// }
|
|
|
// if (areaCodeList != null && areaCodeList.size() > 0) {
|
|
|
// areaCodeList.forEach(item -> {
|
|
|
// if (saas.length() <= 0) {
|
|
|
// saas.append("(org_area:" + item);
|
|
|
// } else {
|
|
|
// saas.append(" OR org_area:" + item);
|
|
|
// }
|
|
|
// });
|
|
|
// }
|
|
|
// if (saas.length() > 0) {
|
|
|
// saas.append(")");
|
|
|
// } else {
|
|
|
// throw new ApiException(ErrorCode.FORBIDDEN, "无SAAS权限访问资源");
|
|
|
// }
|
|
|
// }
|
|
|
// List<QueryCondition> ql = new ArrayList<>();
|
|
|
// if (!StringUtils.isEmpty(queryCondition)) {
|
|
|
// ql = parseCondition(queryCondition);
|
|
|
// }
|
|
|
// String queryParams = "";
|
|
|
// if (ql.size() > 0) {
|
|
|
// if (solrQuery.conditionToString(ql).contains(":")) {
|
|
|
// queryParams = addParams(queryParams, "q", solrQuery.conditionToString(ql));
|
|
|
// } else {
|
|
|
// queryParams = addParams(queryParams, "q", "*:*");
|
|
|
// }
|
|
|
// } else {
|
|
|
// queryParams = addParams(queryParams, "q", "*:*");
|
|
|
// }
|
|
|
// queryParams = addParams(queryParams, "sort", "{\"create_date\":\"desc\"}");
|
|
|
// //基础数据字段
|
|
|
// queryParams = addParams(queryParams, "basicFl", org.apache.commons.lang3.StringUtils.join(ResourceCells.getMasterBasicCell(ProfileType.Standard), ","));
|
|
|
// //数据元信息字段
|
|
|
// List<String> customizeList = (List<String>) objectMapper.readValue(metaData, List.class);
|
|
|
// //参数集合
|
|
|
// List<String> paramList = new ArrayList<>(customizeList.size() * 2);
|
|
|
// for (String id : customizeList) {
|
|
|
// paramList.add(id);
|
|
|
// String dictCode = redisService.getRsMetadataDict(id);
|
|
|
// if (!StringUtils.isEmpty(dictCode)) {
|
|
|
// paramList.add(id + "_VALUE");
|
|
|
// }
|
|
|
// }
|
|
|
// queryParams = addParams(queryParams, "dFl", org.apache.commons.lang3.StringUtils.join(paramList, ","));
|
|
|
// return resourceBrowseDao.getEhrCenter(null, "*", saas.toString(), queryParams, page, size);
|
|
|
// }
|
|
|
public Envelop getCustomizeData(String resourcesCodes, String metaData, String orgCode, String areaCode, String queryCondition, Integer page, Integer size) throws Exception {
|
|
|
//获取资源编码列表
|
|
|
List<String> codeList = (List<String>) objectMapper.readValue(resourcesCodes, List.class);
|
|
|
//资源判空检查
|
|
|
for (String code : codeList) {
|
|
|
RsResource rsResources = rsResourceService.getResourceByCategory(code,"standard");
|
|
|
|
|
|
if (rsResources == null) {
|
|
|
throw new ApiException( "无效的资源编码" + code,ErrorCode.BAD_REQUEST.value());
|
|
|
}
|
|
|
}
|
|
|
StringBuilder saas = new StringBuilder();
|
|
|
if ("*".equals(orgCode) && "*".equals(areaCode)) {
|
|
|
saas.append("*");
|
|
|
} else {
|
|
|
List<String> orgCodeList = objectMapper.readValue(orgCode, List.class);
|
|
|
List<String> areaCodeList = objectMapper.readValue(areaCode, List.class);
|
|
|
if (orgCodeList != null && orgCodeList.size() > 0) {
|
|
|
orgCodeList.forEach(item -> {
|
|
|
if (saas.length() <= 0) {
|
|
|
saas.append("(org_code:" + item);
|
|
|
} else {
|
|
|
saas.append(" OR org_code:" + item);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
if (areaCodeList != null && areaCodeList.size() > 0) {
|
|
|
areaCodeList.forEach(item -> {
|
|
|
if (saas.length() <= 0) {
|
|
|
saas.append("(org_area:" + item);
|
|
|
} else {
|
|
|
saas.append(" OR org_area:" + item);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
if (saas.length() > 0) {
|
|
|
saas.append(")");
|
|
|
} else {
|
|
|
throw new ApiException("无SAAS权限访问资源");
|
|
|
}
|
|
|
}
|
|
|
List<QueryCondition> ql = new ArrayList<>();
|
|
|
if (!StringUtils.isEmpty(queryCondition)) {
|
|
|
ql = parseCondition(queryCondition);
|
|
|
}
|
|
|
String queryParams = "";
|
|
|
if (ql.size() > 0) {
|
|
|
/* if (solrQuery.conditionToString(ql).contains(":")) {
|
|
|
queryParams = addParams(queryParams, "q", solrQuery.conditionToString(ql));
|
|
|
} else {
|
|
|
queryParams = addParams(queryParams, "q", "*:*");
|
|
|
}*/
|
|
|
} else {
|
|
|
queryParams = addParams(queryParams, "q", "*:*");
|
|
|
}
|
|
|
queryParams = addParams(queryParams, "sort", "{\"create_date\":\"desc\"}");
|
|
|
//基础数据字段
|
|
|
queryParams = addParams(queryParams, "basicFl", org.apache.commons.lang3.StringUtils.join(ResourceCells.getMasterBasicCell(ProfileType.Standard), ","));
|
|
|
//数据元信息字段
|
|
|
List<String> customizeList = (List<String>) objectMapper.readValue(metaData, List.class);
|
|
|
//参数集合
|
|
|
List<String> paramList = new ArrayList<>(customizeList.size() * 2);
|
|
|
for (String id : customizeList) {
|
|
|
paramList.add(id);
|
|
|
String dictCode = redisService.getRsMetadataDict(id);
|
|
|
if (!StringUtils.isEmpty(dictCode)) {
|
|
|
paramList.add(id + "_VALUE");
|
|
|
}
|
|
|
}
|
|
|
String queryString = org.apache.commons.lang3.StringUtils.join(paramList, ",");
|
|
|
queryParams = addParams(queryParams, "dFl", org.apache.commons.lang3.StringUtils.join(paramList, ","));
|
|
|
return resourceBrowseDao.getEhrCenter(null, "*", saas.toString(), queryParams, page, size);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 综合查询档案数据检索
|
|
|
*
|
|
|
* @param resourcesCodes
|
|
|
* @param metaData
|
|
|
* @param queryCondition
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public Page<Map<String, Object>> getCustomizeDataMysql(String resourcesCodes, String metaData, String queryCondition, Integer page, Integer size) throws Exception {
|
|
|
//获取资源编码列表
|
|
|
List<String> codeList = (List<String>) objectMapper.readValue(resourcesCodes, List.class);
|
|
|
String tableName = "";
|
|
|
//资源判空检查
|
|
|
for (String code : codeList) {
|
|
|
RsResource rsResources = rsResourceService.getResourceByCategory(code,"standard");
|
|
|
if (rsResources == null) {
|
|
|
throw new ApiException( "无效的资源编码" + code,ErrorCode.BAD_REQUEST.value());
|
|
|
}
|
|
|
String sortOrder = "";
|
|
|
List<RsResourceDefaultParam> paramsList = resourceDefaultParamDao.findByResourcesCode(code);
|
|
|
for (RsResourceDefaultParam param : paramsList) {
|
|
|
if (param.getParamKey().equals("sort")) {
|
|
|
Map<String, String> temp = objectMapper.readValue(param.getParamValue(), Map.class);
|
|
|
for (Map.Entry<String, String> entry:temp.entrySet()){
|
|
|
String key = entry.getKey();
|
|
|
String value = entry.getValue();
|
|
|
sortOrder ="T."+key+" "+ value+",";
|
|
|
}
|
|
|
}else if (param.getParamKey().equals("table")){
|
|
|
tableName += " ("+param.getParamValue()+") "+ code;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
if (!StringUtils.isEmpty(queryCondition)) {
|
|
|
stringBuffer = parseCondition1(queryCondition);
|
|
|
}
|
|
|
//数据元信息字段
|
|
|
List<String> customizeList = (List<String>) objectMapper.readValue(metaData, List.class);
|
|
|
//参数集合
|
|
|
List<String> paramList = new ArrayList<>(customizeList.size() * 2);
|
|
|
for (String id : customizeList) {
|
|
|
paramList.add(id);
|
|
|
}
|
|
|
String queryString = org.apache.commons.lang3.StringUtils.join(paramList, ",");
|
|
|
String sql = " select "+queryString+" from "+tableName;
|
|
|
String sortParam = "";
|
|
|
return resourceBrowseDao.getMysqlDataAndCondition(sql, stringBuffer.toString(),sortParam, page, size);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取主表数据
|
|
@ -578,7 +641,7 @@ public class ResourceBrowseService extends BaseJpaService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public Page<Map<String, Object>> getMysqlData(String queryParams, Integer page, Integer size) throws Exception {
|
|
|
return resourceBrowseDao.getMysqlData(queryParams, page, size);
|
|
|
return resourceBrowseDao.getMysqlData1(queryParams, page, size);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -620,6 +683,31 @@ public class ResourceBrowseService extends BaseJpaService {
|
|
|
return ql;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询条件转换
|
|
|
*
|
|
|
* @param queryCondition
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
private StringBuffer parseCondition1(String queryCondition) throws Exception {
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
JavaType javaType = mapper.getTypeFactory().constructParametricType(List.class, Map.class);
|
|
|
List<Map<String, Object>> list = objectMapper.readValue(queryCondition, javaType);
|
|
|
if (list != null && list.size() > 0) {
|
|
|
for (Map<String, Object> item : list) {
|
|
|
String andOr = String.valueOf(item.get("andOr")).trim();
|
|
|
String field = String.valueOf(item.get("field")).trim();
|
|
|
String cond = String.valueOf(item.get("condition")).trim();
|
|
|
String value = String.valueOf(item.get("value"));
|
|
|
stringBuffer.append(" "+andOr+" "+field+cond+"'"+value+"' ");
|
|
|
}
|
|
|
}
|
|
|
return stringBuffer;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增参数
|
|
|
*
|