会员、福利
This commit is contained in:
@@ -89,4 +89,7 @@ public class WelfareProjectSubjectOption extends BaseModel {
|
||||
@Comment("简短备注")
|
||||
@ColDefine(type = ColType.VARCHAR,width = 100)
|
||||
private String simpleDesc;
|
||||
|
||||
private Integer rank;
|
||||
private Long selectCount;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import io.v.nutz.base.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import io.v.nutz.zhgh.welfare.model.WelfareProject;
|
||||
import io.v.nutz.zhgh.welfare.model.WelfareProjectSubject;
|
||||
import io.v.nutz.zhgh.welfare.model.WelfareProjectSubjectOption;
|
||||
import io.v.nutz.zhgh.welfare.model.WelfareUserSelection;
|
||||
import io.v.nutz.zhgh.welfare.service.WelfareProjectService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
@@ -19,7 +21,10 @@ import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -64,6 +69,44 @@ public class WelfareProjectServiceImpl extends ViServiceImpl<WelfareProject> imp
|
||||
MatchConditionStructure conditionStructure = fetchLinks(dao().fetch(MatchConditionStructure.class, project.getConditionStructureId()), "conditions");
|
||||
project.setConditionStructure(conditionStructure);
|
||||
}
|
||||
|
||||
//获取用户选择数据
|
||||
List<WelfareUserSelection> userSelections = dao().query(WelfareUserSelection.class, Cnd.where("welfareId", "=", projectId));
|
||||
//统计每项选了多少个
|
||||
Map<String, Long> selectCountMap = userSelections.stream().collect(Collectors.groupingBy(WelfareUserSelection::getSelectOptionId, Collectors.counting()))
|
||||
.entrySet().stream()
|
||||
.sorted(Map.Entry.<String, Long>comparingByValue().reversed()) // 根据选择的数量降序排序
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
Map.Entry::getValue,
|
||||
(e1, e2) -> e1, LinkedHashMap::new));// 保持排序;
|
||||
//排名
|
||||
LinkedHashMap<String, Integer> sortMap = new LinkedHashMap<>();
|
||||
int rank = 1;
|
||||
//记录上一个的数量,如果相同,则排名相同
|
||||
Long previousValue = null;
|
||||
for (Map.Entry<String, Long> entry : selectCountMap.entrySet()) {
|
||||
if (previousValue != null && !Objects.equals(previousValue, entry.getValue())) {
|
||||
rank++;
|
||||
}
|
||||
sortMap.put(entry.getKey(), rank);
|
||||
previousValue = entry.getValue();
|
||||
}
|
||||
|
||||
if (Lang.isNotEmpty(welfareProjectSubjects)) {
|
||||
fetchLinks(welfareProjectSubjects, "options", Cnd.NEW().asc("optionSort"));
|
||||
welfareProjectSubjects.forEach(o -> {
|
||||
List<WelfareProjectSubjectOption> options = o.getOptions();
|
||||
options.forEach(op -> {
|
||||
op.setSelectCount(selectCountMap.getOrDefault(op.getId(), 0L));
|
||||
op.setRank(sortMap.getOrDefault(op.getId(), 0));
|
||||
});
|
||||
});
|
||||
}
|
||||
if (Strings.isNotBlank(project.getConditionStructureId())) {
|
||||
MatchConditionStructure conditionStructure = fetchLinks(dao().fetch(MatchConditionStructure.class, project.getConditionStructureId()), "conditions");
|
||||
project.setConditionStructure(conditionStructure);
|
||||
}
|
||||
return project;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user