Commit 0e152f77 authored by 赵啸非's avatar 赵啸非

修改人员学习

parent ab9ea16a
...@@ -33,4 +33,9 @@ public class ProjectVo extends BaseEntityLong { ...@@ -33,4 +33,9 @@ public class ProjectVo extends BaseEntityLong {
*/ */
private String studyPersonRadio; private String studyPersonRadio;
/**
* 学习人数数量
*/
private Integer studyPersonCount;
} }
\ No newline at end of file
package com.mortals.xhx.module.study.service; package com.mortals.xhx.module.study.service;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.study.model.StudyStatEntity; import com.mortals.xhx.module.study.model.StudyStatEntity;
import java.util.Map;
/** /**
* StudyStatService * StudyStatService
* *
...@@ -11,4 +15,7 @@ import com.mortals.xhx.module.study.model.StudyStatEntity; ...@@ -11,4 +15,7 @@ import com.mortals.xhx.module.study.model.StudyStatEntity;
*/ */
public interface StudyStatService extends ICRUDService<StudyStatEntity,Long>{ public interface StudyStatService extends ICRUDService<StudyStatEntity,Long>{
void indexStat(Map<String, Object> model,Context context);
} }
\ No newline at end of file
package com.mortals.xhx.module.study.service.impl; package com.mortals.xhx.module.study.service.impl;
import cn.hutool.core.date.DateUtil;
import com.mortals.xhx.common.code.ProjectTypeEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.project.model.ProjectEntity;
import com.mortals.xhx.module.project.model.ProjectQuery;
import com.mortals.xhx.module.project.model.ProjectStudyEntity;
import com.mortals.xhx.module.project.model.ProjectStudyQuery;
import com.mortals.xhx.module.project.service.ProjectService;
import com.mortals.xhx.module.project.service.ProjectStudyService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Indexed;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
...@@ -6,14 +19,78 @@ import com.mortals.framework.model.Context; ...@@ -6,14 +19,78 @@ import com.mortals.framework.model.Context;
import com.mortals.xhx.module.study.dao.StudyStatDao; import com.mortals.xhx.module.study.dao.StudyStatDao;
import com.mortals.xhx.module.study.model.StudyStatEntity; import com.mortals.xhx.module.study.model.StudyStatEntity;
import com.mortals.xhx.module.study.service.StudyStatService; import com.mortals.xhx.module.study.service.StudyStatService;
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.stream.Collectors;
/** /**
* StudyStatService * StudyStatService
* 学习统计 service实现 * 学习统计 service实现
* *
* @author zxfei * @author zxfei
* @date 2023-03-06 * @date 2023-03-06
*/ */
@Service("studyStatService") @Service("studyStatService")
public class StudyStatServiceImpl extends AbstractCRUDServiceImpl<StudyStatDao, StudyStatEntity, Long> implements StudyStatService { public class StudyStatServiceImpl extends AbstractCRUDServiceImpl<StudyStatDao, StudyStatEntity, Long> implements StudyStatService {
@Autowired
private ProjectService projectService;
@Autowired
private ProjectStudyService projectStudyService;
@Override
public void indexStat(Map<String, Object> model, Context context) {
//最近7天学习人数趋势
ProjectStudyQuery studyQuery = new ProjectStudyQuery();
studyQuery.setUpdateTimeStart(DateUtil.offsetDay(new Date(), -7).toString());
studyQuery.setUpdateTimeEnd(DateUtil.today());
studyQuery.setStudyStatus(YesNoEnum.YES.getValue());
List<ProjectStudyEntity> projectStudyEntities = projectStudyService.find(studyQuery, context);
//按天分组数量
Map<String, List<ProjectStudyEntity>> collect = projectStudyEntities.stream().collect(Collectors.groupingBy(x -> {
if (!ObjectUtils.isEmpty(x.getUpdateTime())) {
return DateUtil.formatDate(x.getUpdateTime());
} else {
return "";
}
}));
Map<String, Integer> map = new HashMap<>();
for (int i = 7; i > 0; i--) {
String beforeDay = DateUtil.offsetDay(new Date(), -i).toString();
if (collect.containsKey(beforeDay)) {
map.put(beforeDay, collect.getOrDefault(beforeDay, new ArrayList<>()).size());
} else {
map.put(beforeDay, 0);
}
}
model.put("dayTrend", map);
//首页统计。
//统计学些类型占比
List<ProjectEntity> projectEntities = projectService.find(new ProjectQuery());
Map<String, Long> studyTypeStat = projectEntities.stream().collect(Collectors.groupingBy(x -> ProjectTypeEnum.getByValue(x.getProjectType()).getDesc(), Collectors.counting()));
model.put("studyTypeStat", studyTypeStat);
//学习量前
for (ProjectEntity projectEntity : projectEntities) {
ProjectStudyQuery projectStudyQuery = new ProjectStudyQuery();
projectStudyQuery.setStudyStatus(YesNoEnum.YES.getValue());
projectStudyQuery.setProjectId(projectEntity.getId());
int count = projectStudyService.count(projectStudyQuery, context);
projectEntity.setStudyPersonCount(count);
}
List<ProjectEntity> leaderList = projectEntities.stream()
.sorted(Comparator.comparing(ProjectEntity::getStudyPersonCount, Comparator.reverseOrder()))
.limit(5).collect(Collectors.toList());
model.put("leaderList", leaderList);
}
} }
\ No newline at end of file
package com.mortals.xhx.module.study.web; package com.mortals.xhx.module.study.web;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -46,4 +47,27 @@ public class StudyStatController extends BaseCRUDJsonBodyMappingController<Study ...@@ -46,4 +47,27 @@ public class StudyStatController extends BaseCRUDJsonBodyMappingController<Study
} }
/**
* 首页统计
*/
@PostMapping(value = "indexStat")
@UnAuth
public String indexStat() {
JSONObject jsonObject = new JSONObject();
Map<String, Object> model = new HashMap<>();
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
jsonObject.put(KEY_RESULT_MSG, "");
try {
this.service.indexStat(model,getContext());
jsonObject.put(KEY_RESULT_DATA, model);
recordSysLog(request, "首页统计 【成功】");
} catch (Exception e) {
log.error("异常", e);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
jsonObject.put(KEY_RESULT_MSG, super.convertException(e));
}
return jsonObject.toJSONString();
}
} }
\ No newline at end of file
...@@ -14,5 +14,9 @@ ...@@ -14,5 +14,9 @@
"portal": { "portal": {
"baseUrl": "http://192.168.0.98:11072/zwfw", "baseUrl": "http://192.168.0.98:11072/zwfw",
"baseLogin": "http://192.168.0.98:11078/base" "baseLogin": "http://192.168.0.98:11078/base"
},
"prod": {
"baseUrl": "http://125.64.74.247:11089/study"
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment