|
@@ -3,6 +3,7 @@ package cn.com.qmth.examcloud.core.reports.service.impl;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -19,10 +20,12 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetOrgsByIdListReq;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.response.GetOrgsByIdListResp;
|
|
|
+import cn.com.qmth.examcloud.core.reports.api.request.SaveStudentTotalCountReq;
|
|
|
import cn.com.qmth.examcloud.core.reports.base.bean.StudentCountBean;
|
|
|
import cn.com.qmth.examcloud.core.reports.base.util.BatchGetDataUtil;
|
|
|
import cn.com.qmth.examcloud.core.reports.dao.ExamStudentCountRepo;
|
|
@@ -34,146 +37,175 @@ import cn.com.qmth.examcloud.core.reports.service.StudentTotalCountService;
|
|
|
|
|
|
@Service
|
|
|
public class StudentTotalCountServiceImpl implements StudentTotalCountService {
|
|
|
- @Autowired
|
|
|
- private StudentTotalCountRepo studentTotalCountRepo;
|
|
|
- @Autowired
|
|
|
- private ExamStudentCountRepo examStudentCountRepo;
|
|
|
- @Autowired
|
|
|
- private StudentCountService studentCountService;
|
|
|
- @Autowired
|
|
|
- private OrgCloudService orgCloudService;
|
|
|
-
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
- public synchronized void compute() {
|
|
|
- // TODO
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Long getSumTotalCount() {
|
|
|
- return studentTotalCountRepo.getSumTotalCount();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public PageInfo<StudentCountBean> queryPage(String rootOrgId, Integer pageNo, Integer pageSize) {
|
|
|
- Specification<StudentTotalCountEntity> specification = (root, query, cb) -> {
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
- if (null != rootOrgId) {
|
|
|
- predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
- }
|
|
|
-
|
|
|
- return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
- };
|
|
|
-
|
|
|
- List<StudentTotalCountEntity> es = studentTotalCountRepo.findAll(specification);
|
|
|
-
|
|
|
- List<StudentCountBean> ret = Lists.newArrayList();
|
|
|
-
|
|
|
- for (StudentTotalCountEntity cur : es) {
|
|
|
- StudentCountBean bean = new StudentCountBean();
|
|
|
- bean.setTotalCount(cur.getTotalCount());
|
|
|
- bean.setRootOrgId(cur.getRootOrgId());
|
|
|
- bean.setOnlineCount(0);
|
|
|
- bean.setOnExamCount(0);
|
|
|
- ret.add(bean);
|
|
|
- }
|
|
|
- fillOnlineCount(ret);
|
|
|
- fillOnExamCount(ret);
|
|
|
- fillRootOrgName(ret);
|
|
|
- Collections.sort(ret, new Comparator<StudentCountBean>() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public int compare(StudentCountBean o1, StudentCountBean o2) {
|
|
|
- if (o1.getOnlineCount() > o2.getOnlineCount()) {
|
|
|
- return -1;
|
|
|
- } else if (o1.getOnlineCount() < o2.getOnlineCount()) {
|
|
|
- return 1;
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- int total = ret.size();
|
|
|
- ret = ret.stream().skip((pageNo - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
|
- PageInfo<StudentCountBean> pi=new PageInfo<StudentCountBean>();
|
|
|
- pi.setLimit(pageSize);
|
|
|
- pi.setList(ret);
|
|
|
- pi.setPages(pageNo);
|
|
|
- pi.setTotal(total);
|
|
|
- return pi;
|
|
|
- }
|
|
|
-
|
|
|
- private void fillOnlineCount(List<StudentCountBean> ret) {
|
|
|
- if (CollectionUtils.isEmpty(ret)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- List<Long> temList = ret.stream().map(str -> str.getRootOrgId()).collect(Collectors.toList());
|
|
|
- List<StudentCountBean> sl = studentCountService.getCountByRootOrgIds(temList);
|
|
|
- if (CollectionUtils.isEmpty(sl)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Map<Long, Integer> map = sl.stream().collect(Collectors.toMap(StudentCountBean::getRootOrgId,
|
|
|
- account -> account.getOnlineCount(), (key1, key2) -> key2));
|
|
|
- for(StudentCountBean b:ret) {
|
|
|
- if(map.get(b.getRootOrgId())!=null) {
|
|
|
- b.setOnlineCount(map.get(b.getRootOrgId()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- private void fillOnExamCount(List<StudentCountBean> ret) {
|
|
|
- if (CollectionUtils.isEmpty(ret)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- List<Long> temList = ret.stream().map(str -> str.getRootOrgId()).collect(Collectors.toList());
|
|
|
- List<ExamStudentCountEntity> sl = examStudentCountRepo.getByRootOrgIds(temList);
|
|
|
- if (CollectionUtils.isEmpty(sl)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Map<Long, Integer> map = groupByRootOrg(sl);
|
|
|
- for(StudentCountBean b:ret) {
|
|
|
- if(map.get(b.getRootOrgId())!=null) {
|
|
|
- b.setOnExamCount(map.get(b.getRootOrgId()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- private Map<Long, Integer> groupByRootOrg(List<ExamStudentCountEntity> sl){
|
|
|
- Map<Long, Integer> map=new HashMap<Long, Integer>();
|
|
|
- for(ExamStudentCountEntity s:sl) {
|
|
|
- Integer c=map.get(s.getRootOrgId());
|
|
|
- if(c==null) {
|
|
|
- map.put(s.getRootOrgId(), s.getOnlineCount());
|
|
|
- }else {
|
|
|
- map.put(s.getRootOrgId(), s.getOnlineCount()+c);
|
|
|
- }
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
- private void fillRootOrgName(List<StudentCountBean> ret) {
|
|
|
- if (CollectionUtils.isEmpty(ret)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- List<Long> param = ret.stream().map(str -> str.getRootOrgId()).collect(Collectors.toList());
|
|
|
- List<OrgBean> retList=new ArrayList<OrgBean>();
|
|
|
- GetOrgsByIdListReq req= new GetOrgsByIdListReq();
|
|
|
- BatchGetDataUtil<OrgBean, Long> tool = new BatchGetDataUtil<OrgBean, Long>() {
|
|
|
- @Override
|
|
|
- public List<OrgBean> getData(List<Long> paramList) {
|
|
|
-
|
|
|
- req.setOrgIdList(paramList);
|
|
|
- GetOrgsByIdListResp resp=orgCloudService.getOrgsByIdList(req);
|
|
|
- return resp.getOrgList();
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
- tool.getDataForBatch(retList, param, 100);
|
|
|
- if (CollectionUtils.isEmpty(retList)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Map<Long, String> map = retList.stream().collect(Collectors.toMap(OrgBean::getId,
|
|
|
- account -> account.getName(), (key1, key2) -> key2));
|
|
|
- for(StudentCountBean b:ret) {
|
|
|
- b.setRootOrgName(map.get(b.getRootOrgId()));
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentTotalCountRepo studentTotalCountRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentCountRepo examStudentCountRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentCountService studentCountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrgCloudService orgCloudService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getSumTotalCount() {
|
|
|
+ Long ret = studentTotalCountRepo.getSumTotalCount();
|
|
|
+ if (ret == null) {
|
|
|
+ ret = 0l;
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageInfo<StudentCountBean> queryPage(String rootOrgId, Integer pageNo, Integer pageSize) {
|
|
|
+ Specification<StudentTotalCountEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ if (null != rootOrgId) {
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ List<StudentTotalCountEntity> es = studentTotalCountRepo.findAll(specification);
|
|
|
+
|
|
|
+ List<StudentCountBean> ret = Lists.newArrayList();
|
|
|
+
|
|
|
+ for (StudentTotalCountEntity cur : es) {
|
|
|
+ StudentCountBean bean = new StudentCountBean();
|
|
|
+ bean.setTotalCount(cur.getTotalCount());
|
|
|
+ bean.setRootOrgId(cur.getRootOrgId());
|
|
|
+ bean.setOnlineCount(0);
|
|
|
+ bean.setOnExamCount(0);
|
|
|
+ ret.add(bean);
|
|
|
+ }
|
|
|
+ fillOnlineCount(ret);
|
|
|
+ fillOnExamCount(ret);
|
|
|
+ fillRootOrgName(ret);
|
|
|
+ Collections.sort(ret, new Comparator<StudentCountBean>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int compare(StudentCountBean o1, StudentCountBean o2) {
|
|
|
+ if (o1.getOnlineCount() > o2.getOnlineCount()) {
|
|
|
+ return -1;
|
|
|
+ } else if (o1.getOnlineCount() < o2.getOnlineCount()) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ int total = ret.size();
|
|
|
+ ret = ret.stream().skip((pageNo - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
|
+ PageInfo<StudentCountBean> pi = new PageInfo<StudentCountBean>();
|
|
|
+ pi.setLimit(pageSize);
|
|
|
+ pi.setList(ret);
|
|
|
+ pi.setPages(pageNo);
|
|
|
+ pi.setTotal(total);
|
|
|
+ return pi;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillOnlineCount(List<StudentCountBean> ret) {
|
|
|
+ if (CollectionUtils.isEmpty(ret)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Long> temList = ret.stream().map(str -> str.getRootOrgId()).collect(Collectors.toList());
|
|
|
+ List<StudentCountBean> sl = studentCountService.getCountByRootOrgIds(temList);
|
|
|
+ if (CollectionUtils.isEmpty(sl)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, Integer> map = sl.stream().collect(Collectors.toMap(StudentCountBean::getRootOrgId,
|
|
|
+ account -> account.getOnlineCount(), (key1, key2) -> key2));
|
|
|
+ for (StudentCountBean b : ret) {
|
|
|
+ if (map.get(b.getRootOrgId()) != null) {
|
|
|
+ b.setOnlineCount(map.get(b.getRootOrgId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillOnExamCount(List<StudentCountBean> ret) {
|
|
|
+ if (CollectionUtils.isEmpty(ret)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Long> temList = ret.stream().map(str -> str.getRootOrgId()).collect(Collectors.toList());
|
|
|
+ List<ExamStudentCountEntity> sl = examStudentCountRepo.getByRootOrgIds(temList);
|
|
|
+ if (CollectionUtils.isEmpty(sl)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, Integer> map = groupByRootOrg(sl);
|
|
|
+ for (StudentCountBean b : ret) {
|
|
|
+ if (map.get(b.getRootOrgId()) != null) {
|
|
|
+ b.setOnExamCount(map.get(b.getRootOrgId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Long, Integer> groupByRootOrg(List<ExamStudentCountEntity> sl) {
|
|
|
+ Map<Long, Integer> map = new HashMap<Long, Integer>();
|
|
|
+ for (ExamStudentCountEntity s : sl) {
|
|
|
+ Integer c = map.get(s.getRootOrgId());
|
|
|
+ if (c == null) {
|
|
|
+ map.put(s.getRootOrgId(), s.getOnlineCount());
|
|
|
+ } else {
|
|
|
+ map.put(s.getRootOrgId(), s.getOnlineCount() + c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillRootOrgName(List<StudentCountBean> ret) {
|
|
|
+ if (CollectionUtils.isEmpty(ret)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Long> param = ret.stream().map(str -> str.getRootOrgId()).collect(Collectors.toList());
|
|
|
+ List<OrgBean> retList = new ArrayList<OrgBean>();
|
|
|
+ GetOrgsByIdListReq req = new GetOrgsByIdListReq();
|
|
|
+ BatchGetDataUtil<OrgBean, Long> tool = new BatchGetDataUtil<OrgBean, Long>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OrgBean> getData(List<Long> paramList) {
|
|
|
+
|
|
|
+ req.setOrgIdList(paramList);
|
|
|
+ GetOrgsByIdListResp resp = orgCloudService.getOrgsByIdList(req);
|
|
|
+ return resp.getOrgList();
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+ tool.getDataForBatch(retList, param, 100);
|
|
|
+ if (CollectionUtils.isEmpty(retList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, String> map = retList.stream()
|
|
|
+ .collect(Collectors.toMap(OrgBean::getId, account -> account.getName(), (key1, key2) -> key2));
|
|
|
+ for (StudentCountBean b : ret) {
|
|
|
+ b.setRootOrgName(map.get(b.getRootOrgId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void save(SaveStudentTotalCountReq req) {
|
|
|
+ Long rootOrgId = req.getRootOrgId();
|
|
|
+ Integer totalCount = req.getCount();
|
|
|
+ if (totalCount == null) {
|
|
|
+ totalCount = 0;
|
|
|
+ }
|
|
|
+ if (rootOrgId == null) {
|
|
|
+ throw new StatusException("1000001", "rootOrgId不能为空");
|
|
|
+ }
|
|
|
+ StudentTotalCountEntity se = studentTotalCountRepo.findByRootOrgId(rootOrgId);
|
|
|
+ if (se == null) {
|
|
|
+ Date now = new Date();
|
|
|
+ se = new StudentTotalCountEntity();
|
|
|
+ se.setRootOrgId(rootOrgId);
|
|
|
+ se.setCreationTime(now);
|
|
|
+ se.setUpdateTime(now);
|
|
|
+ }
|
|
|
+ se.setTotalCount(totalCount.intValue());
|
|
|
+ studentTotalCountRepo.save(se);
|
|
|
+ }
|
|
|
}
|