增加平均星数

This commit is contained in:
cyk
2023-07-07 10:05:13 +08:00
parent cd32495cce
commit c4dd18b0c0
2 changed files with 27 additions and 0 deletions

View File

@@ -151,4 +151,14 @@ public class projectEntity {
public void setNum(long num) {
this.num = num;
}
double average;
public double getAverage() {
return average;
}
public void setAverage(double average) {
this.average = average;
}
}

View File

@@ -8,6 +8,7 @@ import com.hellogithub.dao.commentDao;
import com.hellogithub.dao.projectDao;
import com.hellogithub.dao.supportDao;
import com.hellogithub.entity.categoryEntity;
import com.hellogithub.entity.commentEntity;
import com.hellogithub.entity.projectEntity;
import com.hellogithub.entity.supportEntity;
@@ -146,6 +147,22 @@ public class projectService {
projectEntity projectEntity = projectDao.selectProById(id);
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
projectEntity.setCategoryName(categoryEntity.getCategoryName());
List<commentEntity> commentEntityList = commentDao.selectByProjectId(id);
if(commentEntityList.size() != 0)
{
int sum = 0;
for(int i= 0;i<commentEntityList.size();i++)
{
sum +=commentEntityList.get(i).getStar();
}
double average = sum/commentEntityList.size();
projectEntity.setAverage(average);
}
else{
projectEntity.setAverage(0);
}
return projectEntity;
}
public int addProjectLookcount(String id ){