Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 AggregationProvider 的问题 #743

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<properties>
<jdk.version>1.8</jdk.version>
<mapper-module.version>1.1.5</mapper-module.version>
<argLine>-Dfile.encoding=UTF-8</argLine>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public static String aggregationSelectClause(Class<?> entityClass, String wrapKe
if (StringUtil.isNotEmpty(condition.getAggregateAliasName())) {
selectBuilder.append(condition.getAggregateAliasName());
} else {
selectBuilder.append(wrapKeyword(wrapKeyword, columnName));
selectBuilder.append(wrapKeyword(wrapKeyword, condition.getAggregateProperty()));
}
if (condition.getGroupByProperties() != null && condition.getGroupByProperties().size() > 0) {
for (String property : condition.getGroupByProperties()) {
selectBuilder.append(", ");
columnName = propertyMap.get(property).getColumn();
selectBuilder.append(columnName).append(" AS ").append(wrapKeyword(wrapKeyword, columnName));
selectBuilder.append(columnName).append(" AS ").append(wrapKeyword(wrapKeyword, property));
}
}
return selectBuilder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testCount() {
try {
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
AggregateCondition aggregateCondition = AggregateCondition.builder().
aggregateBy("id").aliasName("total").aggregateType(AggregateType.COUNT).groupBy("role");
aggregateBy("id").aliasName("total").aggregateType(AggregateType.COUNT).groupBy("roLe");
Example example = new Example(User.class);
List<User> m = mapper.selectAggregationByExample(example, aggregateCondition);
Assert.assertEquals(2, m.size());
Expand Down Expand Up @@ -86,9 +86,9 @@ public void testMax() {
try {
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
AggregateCondition aggregateCondition = AggregateCondition.builder().
aggregateBy("id").aliasName("aggregation").aggregateType(AggregateType.MAX).groupBy("role");
aggregateBy("id").aliasName("aggregation").aggregateType(AggregateType.MAX).groupBy("roLe");
Example example = new Example(User.class);
example.setOrderByClause("role desc");
example.setOrderByClause("ro_le desc");
List<User> m = mapper.selectAggregationByExample(example, aggregateCondition);
Assert.assertEquals(2, m.size());
Assert.assertEquals(new Long(6), m.get(0).getAggregation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ drop table user if exists;
create table user (
id integer NOT NULL PRIMARY KEY,
name varchar(32),
role VARCHAR(32)
ro_le VARCHAR(32)
);

INSERT INTO user (id, name, role) VALUES (1, 'Angola', 'Admin');
INSERT INTO user (id, name, role) VALUES (2, 'Afghanistan', 'Admin');
INSERT INTO user (id, name, role) VALUES (3, 'Albania', 'Admin');
INSERT INTO user (id, name, role) VALUES (4, 'Algeria', 'USER');
INSERT INTO user (id, name, role) VALUES (5, 'Andorra', 'USER');
INSERT INTO user (id, name, role) VALUES (6, 'Anguilla', 'USER');
INSERT INTO user (id, name, ro_le) VALUES (1, 'Angola', 'Admin');
INSERT INTO user (id, name, ro_le) VALUES (2, 'Afghanistan', 'Admin');
INSERT INTO user (id, name, ro_le) VALUES (3, 'Albania', 'Admin');
INSERT INTO user (id, name, ro_le) VALUES (4, 'Algeria', 'USER');
INSERT INTO user (id, name, ro_le) VALUES (5, 'Andorra', 'USER');
INSERT INTO user (id, name, ro_le) VALUES (6, 'Anguilla', 'USER');
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class User implements Serializable {
@Id
private Long id;
private String name;
private String role;
private String roLe;
//存储聚合函数值
@Transient
private Long aggregation;
Expand All @@ -57,12 +57,12 @@ public void setName(String name) {
this.name = name;
}

public String getRole() {
return role;
public String getRoLe() {
return roLe;
}

public void setRole(String role) {
this.role = role;
public void setRoLe(String roLe) {
this.roLe = roLe;
}

public Long getAggregation() {
Expand Down