这是我自己写的代码 我觉得很差 希望能优化下 能用表驱动吗/
输出的结果是
统计年龄分布数据[ApproveCustomerEntity(area=null, fqzScore=null, ageGroup=[18,25], peopleNum=4),
[ApproveCustomerEntity(area=null, fqzScore=null, ageGroup=[26,30], peopleNum=4)......]
List<ApproveCustomerEntity> list = statisticsService.findApproveCustomerList(approveCustomer);
Integer sumNum = list.size();
List<ApproveCustomerEntity> list1 = new ArrayList<>();
String ageGroup1 = "[18,25]";
String ageGroup2 = "[26,30]";
String ageGroup3 = "[31,35]";
String ageGroup4 = "[36,40]";
String ageGroup5 = "[41,45]";
String ageGroup6 = "[46,50]";
String ageGroup7 = "[51,65]";
Integer age1 = 0;
Integer passAge1 = 0;
Integer rejectAge1 = 0;
Integer age2 = 0;
Integer passAge2 = 0;
Integer rejectAge2 = 0;
Integer age3 = 0;
Integer passAge3 = 0;
Integer rejectAge3 = 0;
Integer age4 = 0;
Integer passAge4 = 0;
Integer rejectAge4 = 0;
Integer age5 = 0;
Integer passAge5 = 0;
Integer rejectAge5 = 0;
Integer age6 = 0;
Integer passAge6 = 0;
Integer rejectAge6 = 0;
Integer age7 = 0;
Integer passAge7 = 0;
Integer rejectAge7 = 0;
Integer otherAge = 0;
Integer otherPassAge = 0;
Integer otherRejectAge = 0;
for (int i = 0; i < list.size(); i++) {
Integer age = list.get(i).getAge();
String rejectCode = list.get(i).getRejectCode();
if(age >= 18 && age <= 25){
age1 ++;
if(JdConstans.REJECT_APPROVAL.equals(rejectCode)){
passAge1++;
}else {
rejectAge1++;
}
}
}
ApproveCustomerEntity approveCustomerEntity = new ApproveCustomerEntity();
approveCustomerEntity.setAgeGroup(ageGroup1);
approveCustomerEntity.setPeopleNum(age1);
approveCustomerEntity.setPassNum(passAge1);
approveCustomerEntity.setRejectNum(rejectAge1);
for (int i = 0; i < list.size(); i++) {
Integer age = list.get(i).getAge();
String rejectCode = list.get(i).getRejectCode();
if(age >= 26 && age <= 30){
age2 ++;
if(JdConstans.REJECT_APPROVAL.equals(rejectCode)){
passAge2++;
}else {
rejectAge2++;
}
}
}
ApproveCustomerEntity approveCustomerEntity1 = new ApproveCustomerEntity();
approveCustomerEntity1.setAgeGroup(ageGroup2);
approveCustomerEntity1.setPeopleNum(age2);
approveCustomerEntity1.setPassNum(passAge2);
approveCustomerEntity1.setRejectNum(rejectAge2);
for (int i = 0; i < list.size(); i++) {
Integer age = list.get(i).getAge();
String rejectCode = list.get(i).getRejectCode();
if(age >= 31 && age <= 35){
age3 ++;
if(JdConstans.REJECT_APPROVAL.equals(rejectCode)){
passAge3++;
}else {
rejectAge3++;
}
}
}
ApproveCustomerEntity approveCustomerEntity2 = new ApproveCustomerEntity();
approveCustomerEntity2.setAgeGroup(ageGroup3);
approveCustomerEntity2.setPeopleNum(age3);
approveCustomerEntity2.setPassNum(passAge3);
approveCustomerEntity2.setRejectNum(rejectAge3);
for (int i = 0; i < list.size(); i++) {
Integer age = list.get(i).getAge();
String rejectCode = list.get(i).getRejectCode();
if(age >= 36 && age <= 40){
age4 ++;
if(JdConstans.REJECT_APPROVAL.equals(rejectCode)){
passAge4 ++;
} else {
rejectAge4 ++;
}
}
}
ApproveCustomerEntity approveCustomerEntity3 = new ApproveCustomerEntity();
approveCustomerEntity3.setAgeGroup(ageGroup4);
approveCustomerEntity3.setPeopleNum(age4);
approveCustomerEntity3.setPassNum(passAge4);
approveCustomerEntity3.setRejectNum(rejectAge4);
for (int i = 0; i < list.size(); i++) {
Integer age = list.get(i).getAge();
String rejectCode = list.get(i).getRejectCode();
if(age >= 41 && age <= 45){
age5 ++;
if(JdConstans.REJECT_APPROVAL.equals(rejectCode)){
passAge5 ++;
} else {
rejectAge5 ++;
}
}
}
ApproveCustomerEntity approveCustomerEntity4 = new ApproveCustomerEntity();
approveCustomerEntity4.setAgeGroup(ageGroup5);
approveCustomerEntity4.setPeopleNum(age5);
approveCustomerEntity4.setPassNum(passAge5);
approveCustomerEntity4.setRejectNum(rejectAge5);
for (int i = 0; i < list.size(); i++) {
String rejectCode = list.get(i).getRejectCode();
Integer age = list.get(i).getAge();
if(age >= 46 && age <= 50){
age6 ++;
if(JdConstans.REJECT_APPROVAL.equals(rejectCode)){
passAge6 ++;
} else {
rejectAge6 ++;
}
}
}
ApproveCustomerEntity approveCustomerEntity5 = new ApproveCustomerEntity();
approveCustomerEntity5.setAgeGroup(ageGroup6);
approveCustomerEntity5.setPeopleNum(age6);
approveCustomerEntity5.setPassNum(passAge6);
approveCustomerEntity5.setRejectNum(rejectAge6);
for (int i = 0; i < list.size(); i++) {
String rejectCode = list.get(i).getRejectCode();
Integer age = list.get(i).getAge();
if(age >= 51 && age <= 65){
age7 ++;
if(JdConstans.REJECT_APPROVAL.equals(rejectCode)){
passAge7 ++;
} else {
rejectAge7 ++;
}
}
}
ApproveCustomerEntity approveCustomerEntity6 = new ApproveCustomerEntity();
approveCustomerEntity6.setAgeGroup(ageGroup7);
approveCustomerEntity6.setPeopleNum(age7);
approveCustomerEntity6.setPassNum(passAge7);
approveCustomerEntity6.setRejectNum(rejectAge7);
list1.add(approveCustomerEntity);
list1.add(approveCustomerEntity1);
list1.add(approveCustomerEntity2);
list1.add(approveCustomerEntity3);
list1.add(approveCustomerEntity4);
list1.add(approveCustomerEntity5);
list1.add(approveCustomerEntity6);
System.out.println("统计年龄分布数据"+list1);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…