|
@@ -4,17 +4,28 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.domain.entity.SysDept;
|
|
import com.fs.common.core.domain.entity.SysDept;
|
|
|
|
|
+import com.fs.common.core.domain.model.LoginUser;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
|
|
+import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.company.constant.CompanyTrafficConstants;
|
|
import com.fs.company.constant.CompanyTrafficConstants;
|
|
|
import com.fs.company.domain.Company;
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
import com.fs.company.service.ICompanyService;
|
|
|
|
|
+import com.fs.framework.web.service.TokenService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
|
|
+import com.fs.his.vo.SystemGoodsStatisticsVo;
|
|
|
|
|
+import com.fs.his.vo.SystemOrderStatisticsVo;
|
|
|
|
|
+import com.fs.his.vo.SystemUserStatisticsVo;
|
|
|
import com.fs.hisStore.config.MedicalMallConfig;
|
|
import com.fs.hisStore.config.MedicalMallConfig;
|
|
|
import com.fs.statis.StatisticsRedisConstant;
|
|
import com.fs.statis.StatisticsRedisConstant;
|
|
|
import com.fs.statis.dto.*;
|
|
import com.fs.statis.dto.*;
|
|
|
import com.fs.statis.param.StatisticsDeptCompanyParam;
|
|
import com.fs.statis.param.StatisticsDeptCompanyParam;
|
|
|
|
|
+import com.fs.statis.param.StatisticsStroeParam;
|
|
|
|
|
+import com.fs.statis.param.StatisticsUserParam;
|
|
|
import com.fs.statis.service.IStatisticsService;
|
|
import com.fs.statis.service.IStatisticsService;
|
|
|
|
|
+import com.fs.statis.vo.StatisticsStroeInfoVo;
|
|
|
|
|
+import com.fs.statis.vo.StatisticsUserInfoVo;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
import com.fs.system.domain.SysConfig;
|
|
|
|
|
+import com.fs.system.mapper.SysDeptMapper;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.system.service.ISysDeptService;
|
|
import com.fs.system.service.ISysDeptService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -57,6 +68,16 @@ public class IndexStatisticsController {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IStatisticsService statisticsService;
|
|
private IStatisticsService statisticsService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TokenService tokenService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysDeptMapper sysDeptMapper;
|
|
|
|
|
+
|
|
|
|
|
+ //统计redis_key
|
|
|
|
|
+ private final String REDIS_KEY_PREFIX = "system:statistics:";
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 分析概览
|
|
* 分析概览
|
|
|
*/
|
|
*/
|
|
@@ -84,41 +105,23 @@ public class IndexStatisticsController {
|
|
|
company.setDeptId(param.getDeptId());
|
|
company.setDeptId(param.getDeptId());
|
|
|
Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
for(Long companyId : companyIds){
|
|
for(Long companyId : companyIds){
|
|
|
- AnalysisPreviewDTO clildDTO = redisCache.getCacheObject(String.format("%s:%d:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType,companyId));
|
|
|
|
|
- if (clildDTO != null) {
|
|
|
|
|
- //将除了completedRate、correctRate和watchRate之外的数据相加,并计算completedRate、correctRate和watchRate
|
|
|
|
|
- analysisPreviewDTO.setWatchUserCount(
|
|
|
|
|
- analysisPreviewDTO.getWatchUserCount() == 0 ? 0 : analysisPreviewDTO.getWatchUserCount()
|
|
|
|
|
- +(clildDTO.getWatchUserCount() == 0 ? 0 : clildDTO.getWatchUserCount())
|
|
|
|
|
- );
|
|
|
|
|
- analysisPreviewDTO.setCompletedUserCount(
|
|
|
|
|
- analysisPreviewDTO.getCompletedUserCount() == 0 ? 0 : analysisPreviewDTO.getCompletedUserCount()
|
|
|
|
|
- +(clildDTO.getCompletedUserCount() == 0 ? 0 : clildDTO.getCompletedUserCount())
|
|
|
|
|
- );
|
|
|
|
|
- analysisPreviewDTO.setCompletedCount(
|
|
|
|
|
- analysisPreviewDTO.getCompletedCount() == 0 ? 0 : analysisPreviewDTO.getCompletedCount()
|
|
|
|
|
- +(clildDTO.getCompletedCount() == 0 ? 0 : clildDTO.getCompletedCount())
|
|
|
|
|
- );
|
|
|
|
|
- analysisPreviewDTO.setWatchCount(
|
|
|
|
|
- analysisPreviewDTO.getWatchCount() == 0 ? 0 : analysisPreviewDTO.getWatchCount()
|
|
|
|
|
- +(clildDTO.getWatchCount() == 0 ? 0 : clildDTO.getWatchCount())
|
|
|
|
|
- );
|
|
|
|
|
- analysisPreviewDTO.setAnswerMemberCount(
|
|
|
|
|
- analysisPreviewDTO.getAnswerMemberCount() == 0 ? 0 : analysisPreviewDTO.getAnswerMemberCount()
|
|
|
|
|
- +(clildDTO.getAnswerMemberCount() == 0 ? 0 : clildDTO.getAnswerMemberCount())
|
|
|
|
|
- );
|
|
|
|
|
- analysisPreviewDTO.setCorrectUserCount(
|
|
|
|
|
- analysisPreviewDTO.getCorrectUserCount() == 0 ? 0 : analysisPreviewDTO.getCorrectUserCount()
|
|
|
|
|
- +(clildDTO.getCorrectUserCount() == 0 ? 0 : clildDTO.getCorrectUserCount())
|
|
|
|
|
- );
|
|
|
|
|
- analysisPreviewDTO.setRewardCount(
|
|
|
|
|
- analysisPreviewDTO.getRewardCount() == 0 ? 0 : analysisPreviewDTO.getRewardCount()
|
|
|
|
|
- +(clildDTO.getRewardCount() == 0 ? 0 : clildDTO.getRewardCount())
|
|
|
|
|
- );
|
|
|
|
|
- analysisPreviewDTO.setRewardMoney(
|
|
|
|
|
- analysisPreviewDTO.getRewardMoney() == null ? BigDecimal.ZERO : analysisPreviewDTO.getRewardMoney()
|
|
|
|
|
- .add(clildDTO.getRewardMoney() == null ? BigDecimal.ZERO : clildDTO.getRewardMoney())
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ AnalysisPreviewDTO childDTO = redisCache.getCacheObject(String.format("%s:%d:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType,companyId));
|
|
|
|
|
+ if (childDTO != null) {
|
|
|
|
|
+ // 累加 long 类型字段(直接相加即可)
|
|
|
|
|
+ analysisPreviewDTO.setWatchUserCount(analysisPreviewDTO.getWatchUserCount() + childDTO.getWatchUserCount());
|
|
|
|
|
+ analysisPreviewDTO.setCompletedUserCount(analysisPreviewDTO.getCompletedUserCount() + childDTO.getCompletedUserCount());
|
|
|
|
|
+ analysisPreviewDTO.setCompletedCount(analysisPreviewDTO.getCompletedCount() + childDTO.getCompletedCount());
|
|
|
|
|
+ analysisPreviewDTO.setWatchCount(analysisPreviewDTO.getWatchCount() + childDTO.getWatchCount());
|
|
|
|
|
+ analysisPreviewDTO.setAnswerMemberCount(analysisPreviewDTO.getAnswerMemberCount() + childDTO.getAnswerMemberCount());
|
|
|
|
|
+ analysisPreviewDTO.setCorrectUserCount(analysisPreviewDTO.getCorrectUserCount() + childDTO.getCorrectUserCount());
|
|
|
|
|
+ analysisPreviewDTO.setRewardCount(analysisPreviewDTO.getRewardCount() + childDTO.getRewardCount());
|
|
|
|
|
+ BigDecimal current = analysisPreviewDTO.getRewardMoney();
|
|
|
|
|
+ BigDecimal child = childDTO.getRewardMoney();
|
|
|
|
|
+ if (current == null) {
|
|
|
|
|
+ analysisPreviewDTO.setRewardMoney(child == null ? BigDecimal.ZERO : child);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ analysisPreviewDTO.setRewardMoney(current.add(child == null ? BigDecimal.ZERO : child));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if(analysisPreviewDTO.getAnswerMemberCount() != 0){
|
|
if(analysisPreviewDTO.getAnswerMemberCount() != 0){
|
|
@@ -909,4 +912,125 @@ public class IndexStatisticsController {
|
|
|
|
|
|
|
|
return R.ok().put("data", data);
|
|
return R.ok().put("data", data);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取首页店铺相关数据
|
|
|
|
|
+ * **/
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/getStatisticsStroe")
|
|
|
|
|
+ public R getStatisticsStroe(@RequestBody StatisticsStroeParam param){
|
|
|
|
|
+ LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
|
|
+ StatisticsStroeInfoVo statisticsStroeInfoVo = new StatisticsStroeInfoVo();
|
|
|
|
|
+
|
|
|
|
|
+ if (loginUser.getUser().isAdmin() || checkDept(loginUser.getUser().getDeptId())) {
|
|
|
|
|
+ List<SystemGoodsStatisticsVo> goodsStatisticsVos =
|
|
|
|
|
+ redisCache.getCacheObject(REDIS_KEY_PREFIX + "goods");
|
|
|
|
|
+
|
|
|
|
|
+ if (goodsStatisticsVos != null && !goodsStatisticsVos.isEmpty()) {
|
|
|
|
|
+ long goodsTotalNum = goodsStatisticsVos.stream()
|
|
|
|
|
+ .filter(vo -> param.getStoreId() == null ||
|
|
|
|
|
+ Objects.equals(vo.getStoreId(), param.getStoreId()))
|
|
|
|
|
+ .mapToLong(SystemGoodsStatisticsVo::getGoodsNum)
|
|
|
|
|
+ .sum();
|
|
|
|
|
+ statisticsStroeInfoVo.setGoodsTotalNum(goodsTotalNum);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<SystemOrderStatisticsVo> orderStatisticsVos =redisCache.getCacheObject(REDIS_KEY_PREFIX+"order");
|
|
|
|
|
+ if (orderStatisticsVos != null && !orderStatisticsVos.isEmpty()) {
|
|
|
|
|
+ List<SystemOrderStatisticsVo> filteredList = orderStatisticsVos.stream()
|
|
|
|
|
+ .filter(v -> param.getStoreId() == null ||
|
|
|
|
|
+ Objects.equals(v.getStoreId(), param.getStoreId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ Long orderTotalNum = filteredList.stream()
|
|
|
|
|
+ .mapToLong(SystemOrderStatisticsVo::getOrderNum)
|
|
|
|
|
+ .sum();
|
|
|
|
|
+ BigDecimal recvTotalNum = filteredList.stream()
|
|
|
|
|
+ .map(SystemOrderStatisticsVo::getPaymentAmount)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ statisticsStroeInfoVo.setOrderTotalNum(orderTotalNum);
|
|
|
|
|
+ statisticsStroeInfoVo.setRecvTotalNum(recvTotalNum);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok().put("data",statisticsStroeInfoVo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取首页用户相关数据
|
|
|
|
|
+ * **/
|
|
|
|
|
+ @PostMapping("/getStatisticsUser")
|
|
|
|
|
+ public R getStatisticsUser(@RequestBody StatisticsUserParam param){
|
|
|
|
|
+ LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
|
|
+ StatisticsUserInfoVo userInfoVo = new StatisticsUserInfoVo();
|
|
|
|
|
+ //非管理员默认部门信息
|
|
|
|
|
+ if (!loginUser.getUser().isAdmin() && !checkDept(loginUser.getUser().getDeptId())) {
|
|
|
|
|
+ param.setDeptId(loginUser.getUser().getDeptId());
|
|
|
|
|
+ }else if(param.getDeptId() == 1){
|
|
|
|
|
+ param.setDeptId(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //总用户数
|
|
|
|
|
+ List<SystemUserStatisticsVo> totalUserList = redisCache.getCacheObject(REDIS_KEY_PREFIX+"manual:totalUser");
|
|
|
|
|
+ if (totalUserList != null && !totalUserList.isEmpty()) {
|
|
|
|
|
+ userInfoVo.setManualTotalUser(fileStatistics(totalUserList, param));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //今日新增用户数
|
|
|
|
|
+ List<SystemUserStatisticsVo> todayUserList = redisCache.getCacheObject(REDIS_KEY_PREFIX+"manual:todayUser");
|
|
|
|
|
+ if (todayUserList != null && !todayUserList.isEmpty()) {
|
|
|
|
|
+ userInfoVo.setManualTodayUser(fileStatistics(todayUserList, param));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //自动用户数
|
|
|
|
|
+ List<SystemUserStatisticsVo> automaticUserList = redisCache.getCacheObject(REDIS_KEY_PREFIX+"automatic:totalUser");
|
|
|
|
|
+ if (automaticUserList != null && !automaticUserList.isEmpty()){
|
|
|
|
|
+ userInfoVo.setAutomaticTotalUser(fileStatistics(automaticUserList, param));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //自动今日新增用户数
|
|
|
|
|
+ List<SystemUserStatisticsVo> automaticTodayUserList = redisCache.getCacheObject(REDIS_KEY_PREFIX+"automatic:todayUser");
|
|
|
|
|
+ if(automaticTodayUserList != null && !automaticTodayUserList.isEmpty()) {
|
|
|
|
|
+ userInfoVo.setAutomaticTodayUser(fileStatistics(automaticTodayUserList, param));
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok().put("data",userInfoVo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //筛选统计信息
|
|
|
|
|
+ private Long fileStatistics(List<SystemUserStatisticsVo> totalUserList, StatisticsUserParam param){
|
|
|
|
|
+ Long num = 0L;
|
|
|
|
|
+ List<SystemUserStatisticsVo> filteredList = totalUserList.stream()
|
|
|
|
|
+ .filter(vo -> {
|
|
|
|
|
+ if (param.getDeptId() == null && param.getCompanyId() == null) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (param.getDeptId() != null && param.getCompanyId() == null) {
|
|
|
|
|
+ return Objects.equals(vo.getDeptId(), param.getDeptId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (param.getDeptId() != null && param.getCompanyId() != null) {
|
|
|
|
|
+ return Objects.equals(vo.getDeptId(), param.getDeptId())
|
|
|
|
|
+ && Objects.equals(vo.getCompanyId(), param.getCompanyId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (param.getDeptId() == null && param.getCompanyId() != null) {
|
|
|
|
|
+ return Objects.equals(vo.getCompanyId(), param.getCompanyId());
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if(!filteredList.isEmpty()){
|
|
|
|
|
+ // 计算总用户数
|
|
|
|
|
+ num = filteredList.stream()
|
|
|
|
|
+ .mapToLong(SystemUserStatisticsVo::getUserNum)
|
|
|
|
|
+ .sum();
|
|
|
|
|
+ }
|
|
|
|
|
+ return num;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 校验是否总公司部门
|
|
|
|
|
+ * **/
|
|
|
|
|
+ public boolean checkDept(Long deptId){
|
|
|
|
|
+ SysDept dept = sysDeptMapper.selectDeptById(deptId);
|
|
|
|
|
+ if(dept == null || !dept.getDeptId().equals(1L)){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|