0%

实习-04-YMS-JDBC工程测试及接口编写

git拉取yms-library项目

image-20230209103638993

问题

运行报错找不到sql.translator.impl

询问诗涵解决

image-20230209103722555

已解决

进行test排查异常报错等

测试过程

测试test.BaseDAOTest#testUpdate

image-20230209110353196

存疑 有问题(已解决)

测试test.BaseDAOTest#testUpdate3

同上

测试test.BaseDAOTest#testUpdate2

同上

测试test.BaseDAOTest#testUpdate4

测试成功,实现update持久化

image-20230209135614895

1
2
3
4
5
6
7
8
@Test
public void testUpdate4() throws DAOException {
SQLParameter parameter = new SQLParameter();
parameter.addParam("btax_test5");
parameter.addParam("0000026a-f46f-4eee-98a7-ff4d4114bcf3");
parameter.addParam("2022-07-21 18:45:09.0");
baseDAO.update("update ipuquotation_test set btax=? where ipuquotaionid=? and pubts=? ", parameter);
}
  • 梳理流程

测试test.BaseDAOTest#testSaveWithPk

测试成功

image-20230209135550209

1
2
3
4
5
6
7
8
@Test
public void testSaveWithPk() throws DAOException {
//IpuQuotation quotation = baseDAO.queryByPK(IpuQuotation.class, "2", new String[]{"ipuquotaionid", "btax"});
IpuQuotation quotation1 = new IpuQuotation();
quotation1.setBtax("btax_test");
quotation1.setIpuquotaionid("5");
baseDAO.insertWithPK(quotation1);
}
  • 梳理流程

测试test.BaseDAOTest#testSave

测试成功

image-20230209135745373

1
2
3
4
5
6
7
@Test
public void testSave() throws DAOException {
IpuQuotation quotation = new IpuQuotation();
quotation.setBtax("btax_test1");
quotation.setIpuquotaionid("test_save12");
baseDAO.insert(quotation);
}
  • 梳理流程

测试test.BaseDAOTest#testSaveList

测试test.BaseDAOTest#testSaveList2

测试test.BaseDAOTest#testDelete

测试成功

image-20230209143756540

image-20230209143805344

1
2
3
4
5
6
7
8
9
10
11
12
13
@Test
public void testDelete() throws DAOException {
final IpuQuotation ipuQuotation = new IpuQuotation();
ipuQuotation.setIpuquotaionid("test2");
final IpuQuotation ipuQuotation2 = new IpuQuotation();
ipuQuotation2.setIpuquotaionid("test1");
baseDAO.remove(new ArrayList<IpuQuotation>() {
{
add(ipuQuotation);
add(ipuQuotation2);
}
});
}

测试test.BaseDAOTest#testQueryAll

测试成功

image-20230209144618751

1
2
3
4
5
6
@Test
public void testQueryAll() throws DAOException {
IpuQuotation ipuQuotation = new IpuQuotation();
List<IpuQuotation> quotation = baseDAO.queryAll(ipuQuotation);
System.out.println(quotation.size());
}

测试test.BaseDAOTest#testQueryByClause

测试成功

image-20230209144735753

1
2
3
4
5
6
7
8
9
10
@Test
public void testQueryByClause2() throws DAOException {
SQLParameter parameter = new SQLParameter();
parameter.addParam("btax_test");
IpuQuotation ipuQuotation = new IpuQuotation();
List<IpuQuotation> ipuQuotations =
baseDAO.queryByClause(ipuQuotation, "select * from ipuquotation_test" + " where btax=?",
parameter);
System.out.println(ipuQuotations.size());
}

测试test.BaseDAOTest#testQueryByClause2

测试成功

image-20230209144933387

image-20230209144857363

1
2
3
4
5
6
7
8
9
10
@Test
public void testQueryByClause2() throws DAOException {
SQLParameter parameter = new SQLParameter();
parameter.addParam("btax_test");
IpuQuotation ipuQuotation = new IpuQuotation();
List<IpuQuotation> ipuQuotations =
baseDAO.queryByClause(ipuQuotation, "select * from ipuquotation_test" + " where btax=?",
parameter);
System.out.println(ipuQuotations.size());
}

问题梳理总结

queryByPK

1
2
3
4
5
6
7
@Test
public void testUpdate() throws DAOException {
IpuQuotation ipuQuotation = new IpuQuotation();
IpuQuotation quotation = baseDAO.queryByPK(ipuQuotation, "2");
quotation.setBtax("btax_test4");
baseDAO.update(quotation, new String[]{"btax"});
}

com.yonyou.iuap.yms.dao.AbstractDAO#queryByPK(com.yonyou.iuap.yms.param.BaseEntity, ID)

1
2
3
4
5
6
7
8
9
10
/**
* 根据PK查询指定VO
*
* @param baseEntity
* @param pk 主键
*/
@Override
public <T> T queryByPK(BaseEntity baseEntity, ID pk) throws DAOException {
return queryByPK(baseEntity, pk, null);
}

com.yonyou.iuap.yms.dao.AbstractDAO#queryByPK(com.yonyou.iuap.yms.param.BaseEntity, ID, java.lang.String[])

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* 根据主键返回指定列的VO对象
*/
@Override
public <T> T queryByPK(BaseEntity baseEntity, ID pk, String[] selectedFields) throws DAOException {
try {
manager = createPersistenceManager();
return (T) manager.retrieveByPK(baseEntity, pk, selectedFields);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
}
}

com.yonyou.iuap.yms.jdbc.AbstractJdbcPersistenceManager#retrieveByPK(com.yonyou.iuap.yms.param.BaseEntity, ID, java.lang.String[])

Entity entity = MetaEntityHelper.getMetaEntity(fullName);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* 根据主键查询
*/
public <T, ID> T retrieveByPK(BaseEntity baseEntity, ID pk, String[] selectedFields) throws Exception {
if (pk == null) {
throw new IllegalArgumentException("pk is null");
}
T result = null;
boolean ormAttributeSign = BeanDataOperateHelper.initOrmAttributeSign(baseEntity);
Map<String, Object> resultMap = null;
SQLParameter param = new SQLParameter();
param.addParam(pk);
Class clz = baseEntity.getClass();
String fullName = baseEntity.getFullName();
Map<String, ORMColumnInfo> types = findColumnInfo(clz, fullName);
Entity entity = MetaEntityHelper.getMetaEntity(fullName);
List<Property> elasticAttributes = entity.getElasticAttributes();
//buildSQL
for (Property elasticProperty : elasticAttributes) {
types.remove(elasticProperty.columnName());
}
StringBuffer columnsForQuery = new StringBuffer();
for (String columnName : types.keySet()) {
columnsForQuery.append(columnName).append(",");
}
columnsForQuery.delete(columnsForQuery.length() - 1, columnsForQuery.length());

List<OneToOneType> parallelTypes = BizMetaHelper.getOneToOneField(baseEntity, null, null);
List<OneToOneType> characteristicTypes = BeanProcessorHelper.getCharacteristicOneToOneField(fullName);
String condition = BeanProcessorHelper.getPkColumn(baseEntity.getClass(), baseEntity.getFullName()) + "=?";

if (CollectionUtils.isEmpty(parallelTypes) && CollectionUtils.isEmpty(characteristicTypes)) {
String pkName = BeanProcessorHelper.getPkColumn(clz, fullName);
boolean hasPKField = false;
StringBuffer mainSQL = new StringBuffer();
String tableName = BeanProcessorHelper.getTableName(clz, fullName);
if (selectedFields == null) {
mainSQL.append("SELECT ").append(columnsForQuery).append(" FROM ").append(tableName);
} else {

selectedFields = transPropertyNameToFieldNames(clz, fullName, selectedFields);
String[] columns = getValidNames(fullName, clz, types, baseEntity, selectedFields);
mainSQL.append("SELECT ");
for (int i = 0; i < columns.length; i++) {
if (columns[i] != null) {
mainSQL.append(columns[i]).append(",");
if (columns[i].equalsIgnoreCase(pkName)) {
hasPKField = true;
}
}
}
if (!hasPKField) {
mainSQL.append(pkName).append(",");
}
mainSQL.setLength(mainSQL.length() - 1);
mainSQL.append(" FROM ").append(tableName);
}
mainSQL.append(" WHERE ").append(condition);
BaseProcessor processor = new BeanListProcessor(baseEntity);
List<T> results = getJdbcSession().executeQuery(mainSQL.toString(), param, processor);
if (results.size() >= 1) {
result = results.get(0);
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("query for oneToOne .. {} ", clz.getClasses());
}
Field[] fields = baseEntity.getClass().getDeclaredFields();
String[] propNames = new String[fields.length];
for (int i = 0; i < fields.length; i++) {
propNames[i] = fields[i].getName();
}
String pkName = BeanProcessorHelper.getPkColumn(clz, fullName);
boolean hasPKField = false;
StringBuffer mainSQL = new StringBuffer();
String tableName = BeanProcessorHelper.getTableName(clz, fullName);
StringBuilder mapSQL = new StringBuilder();
mapSQL.append("SELECT * FROM ").append(tableName).append(" WHERE ").append(condition);
List<Map> mapList = getJdbcSession().executeQuery(mapSQL.toString(), param, new MapListProcessor());
if (mapList.size() >= 1) {
resultMap = mapList.get(0);
} else {
logger.debug("查询结果为空!");
return null;
}
if (selectedFields == null) {
mainSQL.append("SELECT ").append(columnsForQuery).append(" FROM ").append(tableName).append(" WHERE ").append(condition);
List<T> results = getJdbcSession().executeQuery(mainSQL.toString(), param, new BeanListProcessor(baseEntity));
if (results.size() >= 1) {
result = results.get(0);
}
//特征
for (OneToOneType oneToOneType : characteristicTypes) {
String childSQL = buildSQLWithoutSelectFields(oneToOneType, clz, fullName, resultMap);
if (StringUtils.isNotEmpty(childSQL)) {
characteristicEntityHandler(baseEntity, childSQL, fullName, result, ormAttributeSign);
}
}
//平行
for (OneToOneType oneToOneType : parallelTypes) {
String childTable = BeanProcessorHelper.getTableName(oneToOneType.getTargetEntity(), oneToOneType.getTargetFullName());
String childSQL = buildSQLWithoutSelectFields(oneToOneType, clz, fullName, resultMap);
if (StringUtils.isNotEmpty(childSQL)) {
parallelEntityHandler(baseEntity, childSQL, childTable, result, ormAttributeSign);
}
}

} else {
String[] filterFileds = transPropertyNameToFieldNames(clz, fullName, selectedFields);
Set<String> filerdFieldSet = new HashSet<>();
filerdFieldSet.addAll(Arrays.asList(filterFileds));
StringBuilder columnBuilder = new StringBuilder();
for (int i = 0; i < filterFileds.length; i++) {
if (filterFileds[i] != null) {
columnBuilder.append(filterFileds[i]).append(",");
if (filterFileds[i].equalsIgnoreCase(pkName)) {
hasPKField = true;
}
}
}
columnBuilder.append("pubts").append(",");
columnBuilder.append("dr");
if (!hasPKField) {
columnBuilder.append(",").append(pkName);
}
StringBuilder sql = new StringBuilder();
sql.append("SELECT ").append(columnBuilder).append(" FROM ").append(tableName).append(" WHERE ").append(condition);
BaseProcessor processor = new BeanListProcessor(baseEntity);
List<T> results = getJdbcSession().executeQuery(sql.toString(), param, processor);
if (results.size() >= 1) {
result = results.get(0);
}

//特征
for (OneToOneType oneToOneType : characteristicTypes) {
Class childClz = oneToOneType.getTargetEntity();
String childTable = BeanProcessorHelper.getTableName(childClz, oneToOneType.getTargetFullName());
String childSQL = buildSQLWithSelectedFields(oneToOneType, clz, fullName, selectedFields, resultMap, childTable);
if (StringUtils.isNotEmpty(childSQL)) {
characteristicEntityHandler(baseEntity, childSQL, fullName, result, ormAttributeSign);
}
}
//平行
for (OneToOneType oneToOneType : parallelTypes) {
Class childClz = oneToOneType.getTargetEntity();
String childTable = BeanProcessorHelper.getTableName(childClz, oneToOneType.getTargetFullName());
String childSQL = buildSQLWithSelectedFields(oneToOneType, clz, fullName, selectedFields, resultMap, childTable);
if (StringUtils.isNotEmpty(childSQL)) {
parallelEntityHandler(baseEntity, childSQL, childTable, result, ormAttributeSign);
}
}
}

}

return result;
}

com.yonyou.iuap.yms.imeta.MetaEntityHelper#getMetaEntity

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* 根据fullName获取元数据信息
*
* @param fullName
* @return
*/
public static Entity getMetaEntity(String fullName) {
Entity entity = BizContext.getMetaRepository().entity(fullName);
if (entity == null) {
throw new IllegalArgumentException("can't get the meta info of" + fullName);
}
return entity;
}

BizContext.getMetaRepository()得到的是空指针,因此出现异常

解决方案

询问张健

  • 找到yms-jdbc-biz模块
  • 找到src/test/java/imetatest/MetaEntityHelperTest.java
  • 找到com.yonyou.iuap.yms.imeta.MetaEntityHelper
  • 将前者的类文件内容拷贝至后者中即可

YMS控制台配置数据源(诗涵解决)

image-20230209150237331

编写接口queryByUnionKeyMap实现联合查询

需求

public T queryByUnionKeyMap(BaseEntity baseEntity, Map<String,Object> unionKeyMap, String[] selectedFields) throws BusinessException;

实现:

select name,id from table where id=1;

map.put(“id”,1)
map.put(“ytenant_id”,1)
map.put(“dr”,1)
select name,id from table where id=1 and ytenant_id=aaa and dr=1

代码

IYmsJdbcApi#queryByUnionKeyMap

com.yonyou.iuap.yms.api.IYmsJdbcApi#queryByUnionKeyMap

1
2
3
4
5
6
7
8
9
10
/**
* 根据Map查询数据,只返回指定字段的数据
* @param baseEntity
* @param unionKeyMap
* @param selectedFields
* @param <T>
* @return
* @throws BusinessException
*/
public <T> T queryByUnionKeyMap(BaseEntity baseEntity, Map<String,Object> unionKeyMap, String[] selectedFields) throws BusinessException;

AbstractDAO#queryByUnionKeyMap&queryByUnionKeyMap

com.yonyou.iuap.yms.dao.AbstractDAO#queryByUnionKeyMap(com.yonyou.iuap.yms.param.BaseEntity, java.util.Map<java.lang.String,java.lang.Object>)以及com.yonyou.iuap.yms.dao.AbstractDAO#queryByUnionKeyMap(com.yonyou.iuap.yms.param.BaseEntity, java.util.Map<java.lang.String,java.lang.Object>, java.lang.String[])

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* 根据主键列表查询数据,查询指定VO
* @param baseEntity
* @param unionKeyMap
* @param <T>
* @return
* @throws BusinessException
*/
public <T> T queryByUnionKeyMap(BaseEntity baseEntity, Map<String, Object> unionKeyMap) throws BusinessException {
return queryByUnionKeyMap(baseEntity, unionKeyMap, null);
}

/**
* 根据主键列表查询数据,返回指定列的VO对象
* @param baseEntity
* @param unionKeyMap
* @param selectedFields
* @param <T>
* @return
* @throws BusinessException
*/
@Override
public <T> T queryByUnionKeyMap(BaseEntity baseEntity, Map<String, Object> unionKeyMap, String[] selectedFields) throws BusinessException {
try {
manager = createPersistenceManager();
return (T) manager.retrieveByUnionKeyMap(baseEntity, unionKeyMap, selectedFields);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
}
}

AbstractJdbcPersistenceManager#retrieveByPK&retrieveByUnionKeyMap

com.yonyou.iuap.yms.jdbc.AbstractJdbcPersistenceManager#retrieveByPK(com.yonyou.iuap.yms.param.BaseEntity, ID, java.lang.String[])以及com.yonyou.iuap.yms.jdbc.AbstractJdbcPersistenceManager#retrieveByUnionKeyMap(com.yonyou.iuap.yms.param.BaseEntity, java.util.Map<java.lang.String,java.lang.Object>)

修改原方法retrieveByPK(),添加现方法retrieveByUnionKeyMap()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
* 根据主键查询
*/
public <T, ID> T retrieveByPK(BaseEntity baseEntity, ID pk) throws Exception {
return retrieveByPK(baseEntity, pk, null);
}

/**
* 根据主键查询
*/
public <T, ID> T retrieveByPK(BaseEntity baseEntity, ID pk, String[] selectedFields) throws Exception {
if (pk == null) {
throw new IllegalArgumentException("pk is null");
}
T result = null;

Map<String, Object> unionKeyMap = new HashMap<>();
unionKeyMap.put(BeanProcessorHelper.getPkColumn(baseEntity.getClass(), baseEntity.getFullName()), pk);
//直接调用联合查询方法
result = retrieveByUnionKeyMap(baseEntity, unionKeyMap, selectedFields);

return result;
}


/**
* 联合查询,返回指定字段数据
*/
public <T> T retrieveByUnionKeyMap(BaseEntity baseEntity, Map<String, Object> unionKeyMap) throws Exception {
return retrieveByUnionKeyMap(baseEntity, unionKeyMap, null);
}


/**
* 联合查询,返回指定字段数据
*/
public <T> T retrieveByUnionKeyMap(BaseEntity baseEntity, Map<String, Object> unionKeyMap, String[] selectedFields) throws Exception {
//先判断传入的unionKeyMap是否为空,如果为空返回
if (unionKeyMap == null) {
throw new IllegalArgumentException("unionKeyMap is null"); //pk改为unionKeyMap
}
T result = null;
boolean ormAttributeSign = BeanDataOperateHelper.initOrmAttributeSign(baseEntity);
Map<String, Object> resultMap = null;
SQLParameter param = new SQLParameter();

//遍历Map的Key和Value,Key加入到临时conditionList中,Value加入到param.paramList中
List<String> conditionList = new ArrayList<>();
for(Map.Entry<String, Object> entry : unionKeyMap.entrySet()){
conditionList.add(entry.getKey());
param.addParam(entry.getValue());
}

Class clz = baseEntity.getClass();
String fullName = baseEntity.getFullName();
Map<String, ORMColumnInfo> types = findColumnInfo(clz, fullName);
Entity entity = MetaEntityHelper.getMetaEntity(fullName);
List<Property> elasticAttributes = entity.getElasticAttributes();

//buildSQL
for (Property elasticProperty : elasticAttributes) {
types.remove(elasticProperty.columnName());
}
StringBuffer columnsForQuery = new StringBuffer();
for (String columnName : types.keySet()) {
columnsForQuery.append(columnName).append(",");
}
//删掉最后一个逗号
columnsForQuery.delete(columnsForQuery.length() - 1, columnsForQuery.length());

List<OneToOneType> parallelTypes = BizMetaHelper.getOneToOneField(baseEntity, null, null);
List<OneToOneType> characteristicTypes = BeanProcessorHelper.getCharacteristicOneToOneField(fullName);
//改前:condition仅包括主键
//String condition = BeanProcessorHelper.getPkColumn(baseEntity.getClass(), baseEntity.getFullName()) + "=?";
//改后:condition包括unionKeyMap中的所有Key值
StringBuffer condition = new StringBuffer();
for(String s : conditionList){
condition.append(s + "=? and ");
}
condition.delete(condition.length() - 5, condition.length());

if (CollectionUtils.isEmpty(parallelTypes) && CollectionUtils.isEmpty(characteristicTypes)) {
String pkName = BeanProcessorHelper.getPkColumn(clz, fullName);
boolean hasPKField = false;
StringBuffer mainSQL = new StringBuffer();
String tableName = BeanProcessorHelper.getTableName(clz, fullName);
if (selectedFields == null) {
mainSQL.append("SELECT ").append(columnsForQuery).append(" FROM ").append(tableName);
} else {
selectedFields = transPropertyNameToFieldNames(clz, fullName, selectedFields);
String[] columns = getValidNames(fullName, clz, types, baseEntity, selectedFields);
mainSQL.append("SELECT ");
for (int i = 0; i < columns.length; i++) {
if (columns[i] != null) {
mainSQL.append(columns[i]).append(",");
if (columns[i].equalsIgnoreCase(pkName)) {
hasPKField = true;
}
}
}
if (!hasPKField) {
mainSQL.append(pkName).append(",");
}
mainSQL.setLength(mainSQL.length() - 1);
mainSQL.append(" FROM ").append(tableName);
}
mainSQL.append(" WHERE ").append(condition);
BaseProcessor processor = new BeanListProcessor(baseEntity);
List<T> results = getJdbcSession().executeQuery(mainSQL.toString(), param, processor);
if (results.size() >= 1) {
result = results.get(0);
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("query for oneToOne .. {} ", clz.getClasses());
}
Field[] fields = baseEntity.getClass().getDeclaredFields();
String[] propNames = new String[fields.length];
for (int i = 0; i < fields.length; i++) {
propNames[i] = fields[i].getName();
}
String pkName = BeanProcessorHelper.getPkColumn(clz, fullName);
boolean hasPKField = false;
StringBuffer mainSQL = new StringBuffer();
String tableName = BeanProcessorHelper.getTableName(clz, fullName);
StringBuilder mapSQL = new StringBuilder();
mapSQL.append("SELECT * FROM ").append(tableName).append(" WHERE ").append(condition);
List<Map> mapList = getJdbcSession().executeQuery(mapSQL.toString(), param, new MapListProcessor());
if (mapList.size() >= 1) {
resultMap = mapList.get(0);
} else {
logger.debug("查询结果为空!");
return null;
}
if (selectedFields == null) {
mainSQL.append("SELECT ").append(columnsForQuery).append(" FROM ").append(tableName).append(" WHERE ").append(condition);
List<T> results = getJdbcSession().executeQuery(mainSQL.toString(), param, new BeanListProcessor(baseEntity));
if (results.size() >= 1) {
result = results.get(0);
}
//特征
for (OneToOneType oneToOneType : characteristicTypes) {
String childSQL = buildSQLWithoutSelectFields(oneToOneType, clz, fullName, resultMap);
if (StringUtils.isNotEmpty(childSQL)) {
characteristicEntityHandler(baseEntity, childSQL, fullName, result, ormAttributeSign);
}
}
//平行
for (OneToOneType oneToOneType : parallelTypes) {
String childTable = BeanProcessorHelper.getTableName(oneToOneType.getTargetEntity(), oneToOneType.getTargetFullName());
String childSQL = buildSQLWithoutSelectFields(oneToOneType, clz, fullName, resultMap);
if (StringUtils.isNotEmpty(childSQL)) {
parallelEntityHandler(baseEntity, childSQL, childTable, result, ormAttributeSign);
}
}

} else {
String[] filterFileds = transPropertyNameToFieldNames(clz, fullName, selectedFields);
Set<String> filerdFieldSet = new HashSet<>();
filerdFieldSet.addAll(Arrays.asList(filterFileds));
StringBuilder columnBuilder = new StringBuilder();
for (int i = 0; i < filterFileds.length; i++) {
if (filterFileds[i] != null) {
columnBuilder.append(filterFileds[i]).append(",");
if (filterFileds[i].equalsIgnoreCase(pkName)) {
hasPKField = true;
}
}
}
columnBuilder.append("pubts").append(",");
columnBuilder.append("dr");
if (!hasPKField) {
columnBuilder.append(",").append(pkName);
}
StringBuilder sql = new StringBuilder();
sql.append("SELECT ").append(columnBuilder).append(" FROM ").append(tableName).append(" WHERE ").append(condition);
BaseProcessor processor = new BeanListProcessor(baseEntity);
List<T> results = getJdbcSession().executeQuery(sql.toString(), param, processor);
if (results.size() >= 1) {
result = results.get(0);
}

//特征
for (OneToOneType oneToOneType : characteristicTypes) {
Class childClz = oneToOneType.getTargetEntity();
String childTable = BeanProcessorHelper.getTableName(childClz, oneToOneType.getTargetFullName());
String childSQL = buildSQLWithSelectedFields(oneToOneType, clz, fullName, selectedFields, resultMap, childTable);
if (StringUtils.isNotEmpty(childSQL)) {
characteristicEntityHandler(baseEntity, childSQL, fullName, result, ormAttributeSign);
}
}
//平行
for (OneToOneType oneToOneType : parallelTypes) {
Class childClz = oneToOneType.getTargetEntity();
String childTable = BeanProcessorHelper.getTableName(childClz, oneToOneType.getTargetFullName());
String childSQL = buildSQLWithSelectedFields(oneToOneType, clz, fullName, selectedFields, resultMap, childTable);
if (StringUtils.isNotEmpty(childSQL)) {
parallelEntityHandler(baseEntity, childSQL, childTable, result, ormAttributeSign);
}
}
}

}

return result;
}

上传git

develop_wjc分支

image-20230213162630405

image-20230213162720140