|
@@ -1,16 +1,32 @@
|
|
package com.fs.api.controller;
|
|
package com.fs.api.controller;
|
|
|
|
|
|
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.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
|
+import com.fs.company.constant.CompanyTrafficConstants;
|
|
|
|
+import com.fs.company.domain.Company;
|
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
|
+import com.fs.company.service.ICompanyTrafficRecordService;
|
|
|
|
+import com.fs.company.service.impl.CompanyTrafficRecordServiceImpl;
|
|
|
|
+import com.fs.his.utils.ConfigUtil;
|
|
|
|
+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.system.domain.SysConfig;
|
|
import com.fs.system.domain.SysConfig;
|
|
import com.fs.system.service.ISysConfigService;
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
|
+import com.fs.system.service.ISysDeptService;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.YearMonth;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.function.BinaryOperator;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.fs.statis.StatisticsRedisConstant.*;
|
|
import static com.fs.statis.StatisticsRedisConstant.*;
|
|
|
|
|
|
@@ -19,18 +35,31 @@ import static com.fs.statis.StatisticsRedisConstant.*;
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/index/statistics")
|
|
@RequestMapping("/index/statistics")
|
|
|
|
+@Slf4j
|
|
public class IndexStatisticsController {
|
|
public class IndexStatisticsController {
|
|
@Autowired
|
|
@Autowired
|
|
private RedisCache redisCache;
|
|
private RedisCache redisCache;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private ISysConfigService sysConfigService;
|
|
private ISysConfigService sysConfigService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ConfigUtil configUtil;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysDeptService deptService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICompanyService companyService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MedicalMallConfig medicalMallConfig;
|
|
/**
|
|
/**
|
|
* 分析概览
|
|
* 分析概览
|
|
*/
|
|
*/
|
|
@PostMapping("/analysisPreview")
|
|
@PostMapping("/analysisPreview")
|
|
public R analysisPreview(@RequestBody AnalysisPreviewQueryDTO param){
|
|
public R analysisPreview(@RequestBody AnalysisPreviewQueryDTO param){
|
|
- AnalysisPreviewDTO analysisPreviewDTO = null;
|
|
|
|
|
|
+ AnalysisPreviewDTO analysisPreviewDTO = new AnalysisPreviewDTO();
|
|
Integer type = param.getType();
|
|
Integer type = param.getType();
|
|
Integer userType = param.getUserType();
|
|
Integer userType = param.getUserType();
|
|
|
|
|
|
@@ -41,7 +70,69 @@ public class IndexStatisticsController {
|
|
if(userType == null) {
|
|
if(userType == null) {
|
|
userType = 0;
|
|
userType = 0;
|
|
}
|
|
}
|
|
- analysisPreviewDTO = redisCache.getCacheObject(String.format("%s:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType));
|
|
|
|
|
|
+ if(!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
|
+ analysisPreviewDTO = redisCache.getCacheObject(String.format("%s:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType));
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ analysisPreviewDTO = redisCache.getCacheObject(String.format("%s:%d:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType,param.getCompanyId()));
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ 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())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(analysisPreviewDTO.getAnswerMemberCount() != 0){
|
|
|
|
+ analysisPreviewDTO.setCorrectRate(
|
|
|
|
+ analysisPreviewDTO.getCorrectUserCount() == 0 ? "0" : String.format("%.2f", analysisPreviewDTO.getCorrectUserCount() * 100.0 / analysisPreviewDTO.getAnswerMemberCount())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ if(analysisPreviewDTO.getWatchUserCount() != 0){
|
|
|
|
+ analysisPreviewDTO.setCompletedRate(
|
|
|
|
+ analysisPreviewDTO.getCompletedUserCount() == 0 ? "0" : String.format("%.2f", analysisPreviewDTO.getCompletedUserCount() * 100.0 / analysisPreviewDTO.getWatchUserCount())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ if(analysisPreviewDTO.getWatchCount() != 0){
|
|
|
|
+ analysisPreviewDTO.setWatchRate(
|
|
|
|
+ analysisPreviewDTO.getCompletedCount() == 0 ? "0" : String.format("%.2f", analysisPreviewDTO.getCompletedCount() * 100.0 / analysisPreviewDTO.getWatchCount())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
return R.ok().put("data",analysisPreviewDTO);
|
|
return R.ok().put("data",analysisPreviewDTO);
|
|
}
|
|
}
|
|
@@ -51,8 +142,32 @@ public class IndexStatisticsController {
|
|
* 消费余额
|
|
* 消费余额
|
|
*/
|
|
*/
|
|
@GetMapping("/rechargeComsumption")
|
|
@GetMapping("/rechargeComsumption")
|
|
- public R rechargeComsumption(){
|
|
|
|
- ConsumptionBalanceDataDTO consumptionBalanceDataDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_BALANCE);
|
|
|
|
|
|
+ public R rechargeComsumption(StatisticsDeptCompanyParam param){
|
|
|
|
+ ConsumptionBalanceDataDTO consumptionBalanceDataDTO = new ConsumptionBalanceDataDTO();
|
|
|
|
+ if(!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)) {
|
|
|
|
+ consumptionBalanceDataDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_BALANCE);
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ consumptionBalanceDataDTO = redisCache.getCacheObject(String.format("%s:%d",DATA_OVERVIEW_DEALER_BALANCE,param.getCompanyId()));
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ for(Long companyId : companyIds){
|
|
|
|
+ ConsumptionBalanceDataDTO clildDTO = redisCache.getCacheObject(String.format("%s:%d",DATA_OVERVIEW_DEALER_BALANCE,companyId));
|
|
|
|
+ consumptionBalanceDataDTO.setBalance(
|
|
|
|
+ (consumptionBalanceDataDTO.getBalance() == null ? BigDecimal.ZERO : consumptionBalanceDataDTO.getBalance())
|
|
|
|
+ .add(clildDTO.getBalance() == null ? BigDecimal.ZERO : clildDTO.getBalance())
|
|
|
|
+ );
|
|
|
|
+ consumptionBalanceDataDTO.setTodayComsumption(
|
|
|
|
+ (consumptionBalanceDataDTO.getTodayComsumption() == null ? BigDecimal.ZERO : consumptionBalanceDataDTO.getTodayComsumption())
|
|
|
|
+ .add(clildDTO.getTodayComsumption() == null ? BigDecimal.ZERO : clildDTO.getTodayComsumption())
|
|
|
|
+ );
|
|
|
|
+ consumptionBalanceDataDTO.setYesterdayComsumption(
|
|
|
|
+ (consumptionBalanceDataDTO.getYesterdayComsumption() == null ? BigDecimal.ZERO : consumptionBalanceDataDTO.getYesterdayComsumption())
|
|
|
|
+ .add(clildDTO.getYesterdayComsumption() == null ? BigDecimal.ZERO : clildDTO.getYesterdayComsumption())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
return R.ok().put("data", consumptionBalanceDataDTO);
|
|
return R.ok().put("data", consumptionBalanceDataDTO);
|
|
}
|
|
}
|
|
@@ -62,15 +177,58 @@ public class IndexStatisticsController {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@GetMapping("/trafficLog")
|
|
@GetMapping("/trafficLog")
|
|
- public R getTrafficLog(){
|
|
|
|
- TrafficLogDTO trafficLogDTO = redisCache.getCacheObject(DATA_OVERVIEW_TRAFFIC_LOG);
|
|
|
|
- SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("redPacket.Traffic.config");
|
|
|
|
- if(trafficLogDTO == null || sysConfig == null) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ public R getTrafficLog(StatisticsDeptCompanyParam param){
|
|
|
|
+ TrafficLogDTO result = new TrafficLogDTO();
|
|
|
|
+ if(!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)) {
|
|
|
|
+ result = redisCache.getCacheObject(DATA_OVERVIEW_TRAFFIC_LOG);
|
|
|
|
+ if (!"1".equals(medicalMallConfig.getStatics())) {
|
|
|
|
+ SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("redPacket.Traffic.config");
|
|
|
|
+ if(result == null || sysConfig == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String configValue = sysConfig.getConfigValue();
|
|
|
|
+ result.setTraffic(configValue);
|
|
|
|
+ } else {
|
|
|
|
+ //所有部门流量之和
|
|
|
|
+ SysDept dept = new SysDept();
|
|
|
|
+ dept.setParentId(1L);
|
|
|
|
+ Long[] deptIds = deptService.selectDeptList(dept).stream().map(SysDept::getDeptId).toArray(Long[]::new);
|
|
|
|
+ long trafficTemp = 0L;
|
|
|
|
+ for(Long deptId : deptIds){
|
|
|
|
+ Object clildTraffic = redisCache.getCacheObject(CompanyTrafficConstants.CACHE_KEY+":"+deptId);
|
|
|
|
+ if(clildTraffic != null){
|
|
|
|
+ trafficTemp += Long.parseLong(clildTraffic.toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ result.setTraffic(String.format("%.2f",trafficTemp * 1024.0));
|
|
|
|
+ }
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ Company company = companyService.selectCompanyById(param.getCompanyId());
|
|
|
|
+ getTrafficLogResult(result,CompanyTrafficConstants.CACHE_KEY+":"+company.getDeptId()+":"+param.getCompanyId());
|
|
|
|
+ }else{
|
|
|
|
+ getTrafficLogResult(result,CompanyTrafficConstants.CACHE_KEY+":"+param.getDeptId());
|
|
}
|
|
}
|
|
- String configValue = sysConfig.getConfigValue();
|
|
|
|
- trafficLogDTO.setTraffic(configValue);
|
|
|
|
- return R.ok().put("data",trafficLogDTO);
|
|
|
|
|
|
+ return R.ok().put("data",result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getTrafficLogResult(TrafficLogDTO result, String key){
|
|
|
|
+ //昨天
|
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
|
+ Object yesterdayCount = redisCache.getCacheObject(key+":"+yesterday);
|
|
|
|
+ Object todayCount = redisCache.getCacheObject(key+":"+LocalDate.now());
|
|
|
|
+ Object thisMonthCount = redisCache.getCacheObject(key+":"+YearMonth.now());
|
|
|
|
+ Object traffic = redisCache.getCacheObject(key);
|
|
|
|
+ result.setYesterday(parseRedisNumberValueToLong(yesterdayCount));
|
|
|
|
+ //今天
|
|
|
|
+ result.setToday(parseRedisNumberValueToLong(todayCount));
|
|
|
|
+ //本月
|
|
|
|
+ result.setThisMonth(parseRedisNumberValueToLong(thisMonthCount));
|
|
|
|
+ //剩余
|
|
|
|
+ result.setTraffic(traffic == null?"0":traffic.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Long parseRedisNumberValueToLong(Object value){
|
|
|
|
+ return value == null ? 0 : Long.parseLong(value.toString());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -87,9 +245,73 @@ public class IndexStatisticsController {
|
|
if(userType == null){
|
|
if(userType == null){
|
|
userType = 0;
|
|
userType = 0;
|
|
}
|
|
}
|
|
- String key = String.format("%s:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType);
|
|
|
|
- List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = redisCache.getCacheObject(key);
|
|
|
|
- return R.ok().put("data", deaMemberTopTenDTOS);
|
|
|
|
|
|
+ List<WatchEndPlayTrendDTO> watchEndPlayTrendDTOS;
|
|
|
|
+ // 参考watchCourseTopTen方法的处理逻辑
|
|
|
|
+ if (!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
|
+ String key = String.format("%s:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType);
|
|
|
|
+ watchEndPlayTrendDTOS = redisCache.getCacheObject(key);
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,param.getCompanyId());
|
|
|
|
+ watchEndPlayTrendDTOS = redisCache.getCacheObject(key);
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ List<WatchEndPlayTrendDTO> tempDTOS = new ArrayList<>();
|
|
|
|
+ for(Long companyId : companyIds){
|
|
|
|
+ String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,companyId);
|
|
|
|
+ List<WatchEndPlayTrendDTO> companyData = redisCache.getCacheObject(key);
|
|
|
|
+ if (companyData != null) {
|
|
|
|
+ tempDTOS.addAll(companyData);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 根据startDate 和 x 分组,合并watchUserCount和completedUserCount 限制最多返回10条记录
|
|
|
|
+ watchEndPlayTrendDTOS = tempDTOS.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
+ dto -> dto.getStartDate() + ":" + dto.getX(), // 根据startDate和x分组
|
|
|
|
+ Collectors.reducing(new WatchEndPlayTrendDTO(), (dto1, dto2) -> {
|
|
|
|
+ // 合并watchUserCount和completedUserCount
|
|
|
|
+ WatchEndPlayTrendDTO result = new WatchEndPlayTrendDTO();
|
|
|
|
+ // 复制分组标识字段
|
|
|
|
+ if (dto2 != null && dto2.getStartDate() != null) {
|
|
|
|
+ result.setStartDate(dto2.getStartDate());
|
|
|
|
+ } else if (dto1 != null) {
|
|
|
|
+ result.setStartDate(dto1.getStartDate());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (dto2 != null && dto2.getX() != null) {
|
|
|
|
+ result.setX(dto2.getX());
|
|
|
|
+ } else if (dto1 != null) {
|
|
|
|
+ result.setX(dto1.getX());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 合并数值字段
|
|
|
|
+ result.setWatchUserCount(
|
|
|
|
+ (dto1 == null || dto1.getWatchUserCount() == null ? 0 : dto1.getWatchUserCount()) +
|
|
|
|
+ (dto2 == null || dto2.getWatchUserCount() == null ? 0 : dto2.getWatchUserCount())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ result.setCompletedUserCount(
|
|
|
|
+ (dto1 == null || dto1.getCompletedUserCount() == null ? 0 : dto1.getCompletedUserCount()) +
|
|
|
|
+ (dto2 == null || dto2.getCompletedUserCount() == null ? 0 : dto2.getCompletedUserCount())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ })
|
|
|
|
+ ))
|
|
|
|
+ .values()
|
|
|
|
+ .stream()
|
|
|
|
+ .filter(Objects::nonNull) // 过滤掉null值
|
|
|
|
+ .limit(10)
|
|
|
|
+ .sorted(Comparator.comparing(WatchEndPlayTrendDTO::getX))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(watchEndPlayTrendDTOS == null){
|
|
|
|
+ watchEndPlayTrendDTOS = new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return R.ok().put("data", watchEndPlayTrendDTOS);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -107,8 +329,49 @@ public class IndexStatisticsController {
|
|
if(userType == null){
|
|
if(userType == null){
|
|
userType = 0;
|
|
userType = 0;
|
|
}
|
|
}
|
|
|
|
+ List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = new ArrayList<>();
|
|
|
|
+ // 参考deaMemberTopTen方法处理逻辑
|
|
|
|
+ if (!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
|
+ String key = String.format("%s:%d:%d:%d", CHARTS_MEMBER_TOP_TEN_WATCH, type, statisticalType,userType);
|
|
|
|
+ deaMemberTopTenDTOS = redisCache.getCacheObject(key);
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ String key = String.format("%s:%d:%d:%d:%d", CHARTS_MEMBER_TOP_TEN_WATCH, type, statisticalType,userType,param.getCompanyId());
|
|
|
|
+ deaMemberTopTenDTOS = redisCache.getCacheObject(key);
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ List<DeaMemberTopTenDTO> tempDTOS = new ArrayList<>();
|
|
|
|
+ for(Long companyId : companyIds){
|
|
|
|
+ String key = String.format("%s:%d:%d:%d:%d", CHARTS_MEMBER_TOP_TEN_WATCH, type, statisticalType,userType,companyId);
|
|
|
|
+ List<DeaMemberTopTenDTO> companyData = redisCache.getCacheObject(key);
|
|
|
|
+ if (companyData != null) {
|
|
|
|
+ tempDTOS.addAll(companyData);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // companyId 和 companyName 分组,合并watchUserCount 限制最多返回10条记录
|
|
|
|
+ deaMemberTopTenDTOS = tempDTOS.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
+ dto -> dto.getCompanyId() + ":" + dto.getCompanyName(), // 根据companyId和companyName分组
|
|
|
|
+ Collectors.reducing(new DeaMemberTopTenDTO(), (dto1, dto2) -> {
|
|
|
|
+ DeaMemberTopTenDTO result = new DeaMemberTopTenDTO();
|
|
|
|
+ result.setCompanyId(dto1.getCompanyId());
|
|
|
|
+ result.setCompanyName(dto1.getCompanyName());
|
|
|
|
+ result.setWatchUserCount(
|
|
|
|
+ (dto1.getWatchUserCount() == null ? 0 : dto1.getWatchUserCount()) +
|
|
|
|
+ (dto2 == null || dto2.getWatchUserCount() == null ? 0 : dto2.getWatchUserCount())
|
|
|
|
+ );
|
|
|
|
+ return result;
|
|
|
|
+ })
|
|
|
|
+ ))
|
|
|
|
+ .values()
|
|
|
|
+ .stream()
|
|
|
|
+ .filter(Objects::nonNull) // 过滤掉null值
|
|
|
|
+ .limit(10)
|
|
|
|
+ .sorted(Comparator.comparing(DeaMemberTopTenDTO::getWatchUserCount, Comparator.nullsLast(Comparator.reverseOrder())))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
|
|
- List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = redisCache.getCacheObject(String.format("%s:%d:%d:%d", CHARTS_MEMBER_TOP_TEN_WATCH, type, statisticalType,userType));
|
|
|
|
if(deaMemberTopTenDTOS == null){
|
|
if(deaMemberTopTenDTOS == null){
|
|
deaMemberTopTenDTOS = new ArrayList<>();
|
|
deaMemberTopTenDTOS = new ArrayList<>();
|
|
}
|
|
}
|
|
@@ -123,8 +386,50 @@ public class IndexStatisticsController {
|
|
Integer type = param.getType();
|
|
Integer type = param.getType();
|
|
Integer dataType = param.getDataType();
|
|
Integer dataType = param.getDataType();
|
|
Integer userType = param.getUserType();
|
|
Integer userType = param.getUserType();
|
|
|
|
+ List<RewardMoneyTopTenDTO> rewardMoneyTopTenDTOS = new ArrayList<>();
|
|
|
|
+ // 参考rewardMoneyTopTen方法处理逻辑
|
|
|
|
+ if(!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
|
+ String key = String.format("%s:%d:%d:%d", CHARTS_REWARD_MONEY_TOP_TEN, type,dataType,userType);
|
|
|
|
+ rewardMoneyTopTenDTOS = redisCache.getCacheObject(key);
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ String key = String.format("%s:%d:%d:%d:%d", CHARTS_REWARD_MONEY_TOP_TEN, type,dataType,userType,param.getCompanyId());
|
|
|
|
+ rewardMoneyTopTenDTOS = redisCache.getCacheObject(key);
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ List<RewardMoneyTopTenDTO> tempDTOS = new ArrayList<>();
|
|
|
|
+ for(Long companyId : companyIds){
|
|
|
|
+ String key = String.format("%s:%d:%d:%d:%d", CHARTS_REWARD_MONEY_TOP_TEN, type,dataType,userType,companyId);
|
|
|
|
+ List<RewardMoneyTopTenDTO> companyData = redisCache.getCacheObject(key);
|
|
|
|
+ if (companyData != null) {
|
|
|
|
+ tempDTOS.addAll(companyData);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ rewardMoneyTopTenDTOS = tempDTOS.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
+ dto -> dto.getCompanyId() + ":" + dto.getCompanyName(), // 根据companyId和companyName分组
|
|
|
|
+ Collectors.reducing(new RewardMoneyTopTenDTO(), (dto1, dto2) -> {
|
|
|
|
+ RewardMoneyTopTenDTO result = new RewardMoneyTopTenDTO();
|
|
|
|
+ result.setCompanyId(dto1.getCompanyId());
|
|
|
|
+ result.setCompanyName(dto1.getCompanyName());
|
|
|
|
+ result.setRewardMoney(
|
|
|
|
+ (dto1.getRewardMoney() == null ? BigDecimal.ZERO : dto1.getRewardMoney())
|
|
|
|
+ .add(
|
|
|
|
+ (dto2 == null || dto2.getRewardMoney() == null ? BigDecimal.ZERO : dto2.getRewardMoney())
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ return result;
|
|
|
|
+ })
|
|
|
|
+ ))
|
|
|
|
+ .values()
|
|
|
|
+ .stream()
|
|
|
|
+ .filter(Objects::nonNull) // 过滤掉null值
|
|
|
|
+ .limit(10)
|
|
|
|
+ .sorted(Comparator.comparing(RewardMoneyTopTenDTO::getRewardMoney, Comparator.nullsLast(Comparator.reverseOrder())))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
|
|
- List<RewardMoneyTopTenDTO> rewardMoneyTopTenDTOS = redisCache.getCacheObject( String.format("%s:%d:%d:%d", CHARTS_REWARD_MONEY_TOP_TEN, type,dataType,userType));
|
|
|
|
return R.ok().put("data", rewardMoneyTopTenDTOS);
|
|
return R.ok().put("data", rewardMoneyTopTenDTOS);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -135,7 +440,47 @@ public class IndexStatisticsController {
|
|
public R rewardMoneyTrend(@RequestBody AnalysisPreviewQueryDTO param){
|
|
public R rewardMoneyTrend(@RequestBody AnalysisPreviewQueryDTO param){
|
|
Integer type = param.getType();
|
|
Integer type = param.getType();
|
|
Integer userType = param.getUserType();
|
|
Integer userType = param.getUserType();
|
|
- List<RewardMoneyTrendDTO> rewardMoneyTrendDTOS = redisCache.getCacheObject( String.format("%s:%d:%d", CHARTS_REWARD_MONEY_TREND, type,userType));
|
|
|
|
|
|
+ List<RewardMoneyTrendDTO> rewardMoneyTrendDTOS = new ArrayList<>();
|
|
|
|
+ // 参考rewardMoneyTrend方法处理逻辑
|
|
|
|
+ if(!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
|
+ String key = String.format("%s:%d:%d", CHARTS_REWARD_MONEY_TREND, type,userType);
|
|
|
|
+ rewardMoneyTrendDTOS = redisCache.getCacheObject(key);
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ String key = String.format("%s:%d:%d:%d", CHARTS_REWARD_MONEY_TREND, type,userType,param.getCompanyId());
|
|
|
|
+ rewardMoneyTrendDTOS = redisCache.getCacheObject(key);
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ List<RewardMoneyTrendDTO> tempDTOS = new ArrayList<>();
|
|
|
|
+ for(Long companyId : companyIds){
|
|
|
|
+ String key = String.format("%s:%d:%d:%d", CHARTS_REWARD_MONEY_TREND, type,userType,companyId);
|
|
|
|
+ List<RewardMoneyTrendDTO> companyData = redisCache.getCacheObject(key);
|
|
|
|
+ if (companyData != null) {
|
|
|
|
+ tempDTOS.addAll(companyData);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //根据startDate和x分组,合并rewardMoney,根据x排序,限制10
|
|
|
|
+ rewardMoneyTrendDTOS = tempDTOS.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(dto -> dto.getStartDate() + ":" + dto.getX(),
|
|
|
|
+ Collectors.reducing(new RewardMoneyTrendDTO(), (dto1, dto2) -> {
|
|
|
|
+ RewardMoneyTrendDTO result = new RewardMoneyTrendDTO();
|
|
|
|
+ result.setStartDate(dto1.getStartDate());
|
|
|
|
+ result.setX(dto1.getX());
|
|
|
|
+ result.setRewardMoney(
|
|
|
|
+ (dto1.getRewardMoney() == null ? BigDecimal.ZERO : dto1.getRewardMoney())
|
|
|
|
+ .add(
|
|
|
|
+ (dto2 == null || dto2.getRewardMoney() == null ? BigDecimal.ZERO : dto2.getRewardMoney())
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ return result;
|
|
|
|
+ })))
|
|
|
|
+ .values()
|
|
|
|
+ .stream()
|
|
|
|
+ .sorted(Comparator.comparing(RewardMoneyTrendDTO::getX))
|
|
|
|
+ .limit(10)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
return R.ok().put("data", rewardMoneyTrendDTOS);
|
|
return R.ok().put("data", rewardMoneyTrendDTOS);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -148,29 +493,196 @@ public class IndexStatisticsController {
|
|
String sort = param.getSort();
|
|
String sort = param.getSort();
|
|
Integer statisticalType = param.getStatisticalType();
|
|
Integer statisticalType = param.getStatisticalType();
|
|
Integer userType = param.getUserType();
|
|
Integer userType = param.getUserType();
|
|
|
|
+ List<CourseStatsDTO> courseStatsDTOS;
|
|
|
|
+ if (!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
|
+ courseStatsDTOS = redisCache.getCacheObject(String.format("%s:%d:%d:%d:%s", CHARTS_WATCH_TOP_TEN, type,statisticalType,userType,sort));
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ courseStatsDTOS = redisCache.getCacheObject(String.format("%s:%d:%d:%d:%s:%d", CHARTS_WATCH_TOP_TEN, type,statisticalType,userType,sort,param.getCompanyId()));
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ List<CourseStatsDTO> tempDTOS = new ArrayList<>();
|
|
|
|
+ for(Long companyId : companyIds){
|
|
|
|
+ List<CourseStatsDTO> companyDTO = redisCache.getCacheObject(String.format("%s:%d:%d:%d:%s:%d", CHARTS_WATCH_TOP_TEN, type,statisticalType,userType,sort,companyId));
|
|
|
|
+ if (companyDTO != null) {
|
|
|
|
+ tempDTOS.addAll(companyDTO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // courseId和courseName分组,合并watchUserCount、completedUserCount、answerUserCount、correctUserCount 限制最多返回10条记录
|
|
|
|
+ courseStatsDTOS = tempDTOS.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(dto -> dto.getCourseId() + ":" + dto.getCourseName()))
|
|
|
|
+ .values()
|
|
|
|
+ .stream()
|
|
|
|
+ .map(group -> {
|
|
|
|
+ if (group.isEmpty()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 取第一个作为基础对象
|
|
|
|
+ CourseStatsDTO result = new CourseStatsDTO();
|
|
|
|
+ CourseStatsDTO first = group.get(0);
|
|
|
|
+ result.setCourseId(first.getCourseId());
|
|
|
|
+ result.setCourseName(first.getCourseName());
|
|
|
|
+
|
|
|
|
+ // 合并所有数值字段
|
|
|
|
+ int watchUserCount = 0;
|
|
|
|
+ int completedUserCount = 0;
|
|
|
|
+ int answerUserCount = 0;
|
|
|
|
+ int correctUserCount = 0;
|
|
|
|
+
|
|
|
|
+ for (CourseStatsDTO dto : group) {
|
|
|
|
+ watchUserCount += (dto.getWatchUserCount() == null ? 0 : dto.getWatchUserCount());
|
|
|
|
+ completedUserCount += (dto.getCompletedUserCount() == null ? 0 : dto.getCompletedUserCount());
|
|
|
|
+ answerUserCount += (dto.getAnswerUserCount() == null ? 0 : dto.getAnswerUserCount());
|
|
|
|
+ correctUserCount += (dto.getCorrectUserCount() == null ? 0 : dto.getCorrectUserCount());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ result.setWatchUserCount(watchUserCount);
|
|
|
|
+ result.setCompletedUserCount(completedUserCount);
|
|
|
|
+ result.setAnswerUserCount(answerUserCount);
|
|
|
|
+ result.setCorrectUserCount(correctUserCount);
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ })
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
+ .sorted(Comparator.comparing(CourseStatsDTO::getWatchUserCount, Comparator.nullsLast(Comparator.reverseOrder())))
|
|
|
|
+ .limit(10)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
- List<CourseStatsDTO> courseStatsDTOS = redisCache.getCacheObject(String.format("%s:%d:%d:%d:%s", CHARTS_WATCH_TOP_TEN, type,statisticalType,userType,sort));
|
|
|
|
return R.ok().put("data", courseStatsDTOS);
|
|
return R.ok().put("data", courseStatsDTOS);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private List<CourseStatsDTO> groupAndSumCourseStatsWithStream(List<CourseStatsDTO> courseStatsList) {
|
|
|
|
+ // 定义合并逻辑
|
|
|
|
+ BinaryOperator<CourseStatsDTO> mergeFunction = (s1, s2) -> {
|
|
|
|
+ s1.setWatchUserCount(
|
|
|
|
+ (s1.getWatchUserCount() == null ? 0 : s1.getWatchUserCount()) +
|
|
|
|
+ (s2.getWatchUserCount() == null ? 0 : s2.getWatchUserCount())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ s1.setCompletedUserCount(
|
|
|
|
+ (s1.getCompletedUserCount() == null ? 0 : s1.getCompletedUserCount()) +
|
|
|
|
+ (s2.getCompletedUserCount() == null ? 0 : s2.getCompletedUserCount())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ s1.setAnswerUserCount(
|
|
|
|
+ (s1.getAnswerUserCount() == null ? 0 : s1.getAnswerUserCount()) +
|
|
|
|
+ (s2.getAnswerUserCount() == null ? 0 : s2.getAnswerUserCount())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ s1.setCorrectUserCount(
|
|
|
|
+ (s1.getCorrectUserCount() == null ? 0 : s1.getCorrectUserCount()) +
|
|
|
|
+ (s2.getCorrectUserCount() == null ? 0 : s2.getCorrectUserCount())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ return s1;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // 分组、合并并排序、限制10条
|
|
|
|
+ return courseStatsList.stream()
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
+ CourseStatsDTO::getCourseId,
|
|
|
|
+ dto -> {
|
|
|
|
+ CourseStatsDTO copy = new CourseStatsDTO();
|
|
|
|
+ copy.setCourseId(dto.getCourseId());
|
|
|
|
+ copy.setCourseName(dto.getCourseName());
|
|
|
|
+ copy.setWatchUserCount(dto.getWatchUserCount() == null ? 0 : dto.getWatchUserCount());
|
|
|
|
+ copy.setCompletedUserCount(dto.getCompletedUserCount() == null ? 0 : dto.getCompletedUserCount());
|
|
|
|
+ copy.setAnswerUserCount(dto.getAnswerUserCount() == null ? 0 : dto.getAnswerUserCount());
|
|
|
|
+ copy.setCorrectUserCount(dto.getCorrectUserCount() == null ? 0 : dto.getCorrectUserCount());
|
|
|
|
+ return copy;
|
|
|
|
+ },
|
|
|
|
+ mergeFunction,
|
|
|
|
+ LinkedHashMap::new
|
|
|
|
+ ))
|
|
|
|
+ .values()
|
|
|
|
+ .stream()
|
|
|
|
+ .sorted(Comparator.comparing(CourseStatsDTO::getWatchUserCount, Comparator.nullsLast(Comparator.reverseOrder())))
|
|
|
|
+ .limit(10)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 数据概览
|
|
* 数据概览
|
|
*/
|
|
*/
|
|
@GetMapping("/dealerAggregated")
|
|
@GetMapping("/dealerAggregated")
|
|
- public R dealerAggregated(){
|
|
|
|
- DealerAggregatedDTO dealerAggregatedDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_AGGREGATED);
|
|
|
|
|
|
+ public R dealerAggregated(StatisticsDeptCompanyParam param){
|
|
|
|
+ DealerAggregatedDTO result = new DealerAggregatedDTO();
|
|
|
|
+ if (!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)) {
|
|
|
|
+ result = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_AGGREGATED);
|
|
|
|
+ }else if (param.getCompanyId() != null) {
|
|
|
|
+ result = redisCache.getCacheObject(String.format("%s:%d", DATA_OVERVIEW_DEALER_AGGREGATED, param.getCompanyId()));
|
|
|
|
+ //没选中销售公司,部门不为总公司
|
|
|
|
+ }else{
|
|
|
|
+ //Long padMaxNum = deptLimiteService.selectById(param.getDeptId()).getMaxPadNum();
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ for(Long companyId : companyIds) {
|
|
|
|
+ DealerAggregatedDTO dealerAggregatedDTO = redisCache.getCacheObject(String.format("%s:%d", DATA_OVERVIEW_DEALER_AGGREGATED, companyId));
|
|
|
|
+ // 添加空值检查
|
|
|
|
+ if (dealerAggregatedDTO != null) {
|
|
|
|
+ result.setDealderCount((result.getDealderCount() == null ? 0 : result.getDealderCount())
|
|
|
|
+ + (dealerAggregatedDTO.getDealderCount() == null ? 0 : dealerAggregatedDTO.getDealderCount()));
|
|
|
|
+ result.setGroupMgrCount((result.getGroupMgrCount() == null ? 0 : result.getGroupMgrCount())
|
|
|
|
+ + (dealerAggregatedDTO.getGroupMgrCount() == null ? 0 : dealerAggregatedDTO.getGroupMgrCount()));
|
|
|
|
+ result.setMemberCount((result.getMemberCount() == null ? 0 : result.getMemberCount())
|
|
|
|
+ + (dealerAggregatedDTO.getMemberCount() == null ? 0 : dealerAggregatedDTO.getMemberCount()));
|
|
|
|
+ result.setNormalNum((result.getNormalNum() == null ? 0 : result.getNormalNum())
|
|
|
|
+ + (dealerAggregatedDTO.getNormalNum() == null ? 0 : dealerAggregatedDTO.getNormalNum()));
|
|
|
|
+ result.setBlackNum((result.getBlackNum() == null ? 0 : result.getBlackNum())
|
|
|
|
+ + (dealerAggregatedDTO.getBlackNum() == null ? 0 : dealerAggregatedDTO.getBlackNum()));
|
|
|
|
+ result.setQwMemberNum((result.getQwMemberNum() == null ? 0 : result.getQwMemberNum())
|
|
|
|
+ + (dealerAggregatedDTO.getQwMemberNum() == null ? 0 : dealerAggregatedDTO.getQwMemberNum()));
|
|
|
|
+ result.setTodayIncreaseUserNum((result.getTodayIncreaseUserNum() == null ? 0 : result.getTodayIncreaseUserNum())
|
|
|
|
+ + (dealerAggregatedDTO.getTodayIncreaseUserNum() == null ? 0 : dealerAggregatedDTO.getTodayIncreaseUserNum()));
|
|
|
|
+ result.setOrderTotalNum((result.getOrderTotalNum() == null ? 0 : result.getOrderTotalNum())
|
|
|
|
+ + (dealerAggregatedDTO.getOrderTotalNum() == null ? 0 : dealerAggregatedDTO.getOrderTotalNum()));
|
|
|
|
+ result.setTodayOrderNum((result.getTodayOrderNum() == null ? 0 : result.getTodayOrderNum())
|
|
|
|
+ + (dealerAggregatedDTO.getTodayOrderNum() == null ? 0 : dealerAggregatedDTO.getTodayOrderNum()));
|
|
|
|
+ result.setRecvTodayNum((result.getRecvTodayNum() == null ? 0 : result.getRecvTodayNum())
|
|
|
|
+ + (dealerAggregatedDTO.getRecvTodayNum() == null ? 0 : dealerAggregatedDTO.getRecvTodayNum()));
|
|
|
|
+ result.setRecvTotalNum((result.getRecvTotalNum() == null ? 0 : result.getRecvTotalNum())
|
|
|
|
+ + (dealerAggregatedDTO.getRecvTotalNum() == null ? 0 : dealerAggregatedDTO.getRecvTotalNum()));
|
|
|
|
+ result.setGoodsTotalNum((result.getGoodsTotalNum() == null ? 0 : result.getGoodsTotalNum())
|
|
|
|
+ + (dealerAggregatedDTO.getGoodsTotalNum() == null ? 0 : dealerAggregatedDTO.getGoodsTotalNum()));
|
|
|
|
+ result.setTodayGoodsNum((result.getTodayGoodsNum() == null ? 0 : result.getTodayGoodsNum())
|
|
|
|
+ + (dealerAggregatedDTO.getTodayGoodsNum() == null ? 0 : dealerAggregatedDTO.getTodayGoodsNum()));
|
|
|
|
+ result.setPadUsedNum((result.getPadUsedNum() == null ? 0 : result.getPadUsedNum())
|
|
|
|
+ + (dealerAggregatedDTO.getPadUsedNum() == null ? 0 : dealerAggregatedDTO.getPadUsedNum()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- return R.ok().put("data",dealerAggregatedDTO);
|
|
|
|
|
|
+ return R.ok().put("data",result);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 短信余额
|
|
* 短信余额
|
|
*/
|
|
*/
|
|
@GetMapping("/smsBalance")
|
|
@GetMapping("/smsBalance")
|
|
- public R smsBalance(){
|
|
|
|
- Long smsBalance = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_SMS_BALANCE);
|
|
|
|
-
|
|
|
|
- return R.ok().put("data", smsBalance);
|
|
|
|
|
|
+ public R smsBalance(StatisticsDeptCompanyParam param){
|
|
|
|
+ if (!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
|
+ return R.ok().put("data", redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_SMS_BALANCE));
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ return R.ok().put("data", redisCache.getCacheObject(String.format("%s:%d", DATA_OVERVIEW_DEALER_SMS_BALANCE, param.getCompanyId())));
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ long smsBalance = 0L;
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ for(Long companyId : companyIds) {
|
|
|
|
+ Long smsBalanceCompany = redisCache.getCacheObject(String.format("%s:%d", DATA_OVERVIEW_DEALER_SMS_BALANCE, companyId));
|
|
|
|
+ if (smsBalanceCompany != null) {
|
|
|
|
+ smsBalance += smsBalanceCompany;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return R.ok().put("data", smsBalance);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -178,8 +690,33 @@ public class IndexStatisticsController {
|
|
* 授权信息
|
|
* 授权信息
|
|
*/
|
|
*/
|
|
@GetMapping("/authorizationInfo")
|
|
@GetMapping("/authorizationInfo")
|
|
- public R authorizationInfo(){
|
|
|
|
- AuthorizationInfoDTO authorizationInfoDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_AUTHORIZATION_INFO);
|
|
|
|
|
|
+ public R authorizationInfo(StatisticsDeptCompanyParam param){
|
|
|
|
+ AuthorizationInfoDTO authorizationInfoDTO = new AuthorizationInfoDTO();
|
|
|
|
+ if (!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
|
+ return R.ok().put("data", redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_AUTHORIZATION_INFO));
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ return R.ok().put("data", redisCache.getCacheObject(String.format("%s:%d", DATA_OVERVIEW_DEALER_AUTHORIZATION_INFO, param.getCompanyId())));
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ AuthorizationInfoDTO authorizationInfoDTO1 = new AuthorizationInfoDTO();
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ for(Long companyId : companyIds) {
|
|
|
|
+ AuthorizationInfoDTO companyDTO = redisCache.getCacheObject(String.format("%s:%d", DATA_OVERVIEW_DEALER_AUTHORIZATION_INFO, companyId));
|
|
|
|
+ log.info("授权信息:{}", authorizationInfoDTO);
|
|
|
|
+ if (companyDTO != null) {
|
|
|
|
+ authorizationInfoDTO1.setTodayWatchUserCount(
|
|
|
|
+ (authorizationInfoDTO1.getTodayWatchUserCount() == null ? 0 : authorizationInfoDTO1.getTodayWatchUserCount()) +
|
|
|
|
+ (companyDTO.getTodayWatchUserCount() == null ? 0 : companyDTO.getTodayWatchUserCount())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ authorizationInfoDTO1.setVersionLimit(
|
|
|
|
+ (authorizationInfoDTO1.getVersionLimit() == null ? 0 : authorizationInfoDTO1.getVersionLimit()) +
|
|
|
|
+ (companyDTO.getVersionLimit() == null ? 0 : companyDTO.getVersionLimit())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
return R.ok().put("data", authorizationInfoDTO);
|
|
return R.ok().put("data", authorizationInfoDTO);
|
|
}
|
|
}
|
|
@@ -190,9 +727,29 @@ public class IndexStatisticsController {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@GetMapping("/thisMonthOrderCount")
|
|
@GetMapping("/thisMonthOrderCount")
|
|
- public R thisMonthOrderCount(){
|
|
|
|
- R result = redisCache.getCacheObject(StatisticsRedisConstant.THIS_MONTH_ORDER_COUNT);
|
|
|
|
- return result;
|
|
|
|
|
|
+ public R thisMonthOrderCount(StatisticsDeptCompanyParam param){
|
|
|
|
+ if (!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
|
+ return redisCache.getCacheObject(StatisticsRedisConstant.THIS_MONTH_ORDER_COUNT);
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ return redisCache.getCacheObject(String.format("%s:%d", THIS_MONTH_ORDER_COUNT, param.getCompanyId()));
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ List<String> datesList = new ArrayList<>();
|
|
|
|
+ List<Integer> orderCountList = new ArrayList<>();
|
|
|
|
+ List<Integer> payPriceList = new ArrayList<>();
|
|
|
|
+ for(Long companyId : companyIds) {
|
|
|
|
+ R result = redisCache.getCacheObject(String.format("%s:%d", THIS_MONTH_ORDER_COUNT, companyId));
|
|
|
|
+ Object datas = result.get("datas");
|
|
|
|
+ Object orderCount = result.get("orderCount");
|
|
|
|
+ Object payPrice = result.get("payPrice");
|
|
|
|
+ if(datas != null){
|
|
|
|
+ mergeDataListsForInteger(datesList, orderCountList, payPriceList, (List<String>)datas, (List<Integer>)orderCount, (List<Integer>)payPrice);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return R.ok().put("dates", datesList).put("orderCount", orderCountList).put("payPrice", payPriceList);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -201,8 +758,97 @@ public class IndexStatisticsController {
|
|
*/
|
|
*/
|
|
|
|
|
|
@GetMapping("/thisMonthRecvCount")
|
|
@GetMapping("/thisMonthRecvCount")
|
|
- public R thisMonthRecvCount(){
|
|
|
|
- R result = redisCache.getCacheObject(StatisticsRedisConstant.THIS_MONTH_RECV_COUNT);
|
|
|
|
- return result;
|
|
|
|
|
|
+ public R thisMonthRecvCount(StatisticsDeptCompanyParam param){
|
|
|
|
+ if (!"1".equals(medicalMallConfig.getStatics()) || (param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
|
+ return redisCache.getCacheObject(StatisticsRedisConstant.THIS_MONTH_RECV_COUNT);
|
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
|
+ return redisCache.getCacheObject(String.format("%s:%d", THIS_MONTH_RECV_COUNT, param.getCompanyId()));
|
|
|
|
+ }else{
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ company.setDeptId(param.getDeptId());
|
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
|
+ List<String> datesList = new ArrayList<>();
|
|
|
|
+ List<Integer> orderCountList = new ArrayList<>();
|
|
|
|
+ List<Float> payMoneyList = new ArrayList<>();
|
|
|
|
+ for(Long companyId : companyIds) {
|
|
|
|
+ R result = redisCache.getCacheObject(String.format("%s:%d", THIS_MONTH_RECV_COUNT, companyId));
|
|
|
|
+ Object datas = result.get("datas");
|
|
|
|
+ Object orderCount = result.get("orderCount");
|
|
|
|
+ Object payMoney = result.get("payMoney");
|
|
|
|
+ if(datas != null){
|
|
|
|
+ mergeDataLists(datesList, orderCountList, payMoneyList, (List<String>)datas, (List<Integer>)orderCount, (List<Float>)payMoney);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return R.ok().put("dates", datesList).put("orderCount", orderCountList).put("payMoney", payMoneyList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void mergeDataLists(List<String> datasList, List<Integer> orderCountList, List<Float> payMoneyList,
|
|
|
|
+ List<String> datas, List<Integer> orderCount, List<Float> payMoney) {
|
|
|
|
+
|
|
|
|
+ // 遍历新数据
|
|
|
|
+ for (int i = 0; i < datas.size(); i++) {
|
|
|
|
+ String newData = datas.get(i);
|
|
|
|
+ Integer newOrderCount = orderCount.get(i);
|
|
|
|
+ Float newPayMoney = payMoney.get(i);
|
|
|
|
+
|
|
|
|
+ // 查找在现有列表中的位置
|
|
|
|
+ int existingIndex = datasList.indexOf(newData);
|
|
|
|
+
|
|
|
|
+ if (existingIndex != -1) {
|
|
|
|
+ // 如果存在,将orderCount和payMoney相加
|
|
|
|
+ Integer existingOrderCount = orderCountList.get(existingIndex);
|
|
|
|
+ Float existingPayMoney = payMoneyList.get(existingIndex);
|
|
|
|
+
|
|
|
|
+ // 累加orderCount
|
|
|
|
+ orderCountList.set(existingIndex,
|
|
|
|
+ (existingOrderCount == null ? 0 : existingOrderCount) +
|
|
|
|
+ (newOrderCount == null ? 0 : newOrderCount));
|
|
|
|
+
|
|
|
|
+ // 累加payMoney
|
|
|
|
+ payMoneyList.set(existingIndex,
|
|
|
|
+ (existingPayMoney == null ? 0.0f : existingPayMoney) +
|
|
|
|
+ (newPayMoney == null ? 0.0f : newPayMoney));
|
|
|
|
+ } else {
|
|
|
|
+ // 如果不存在,直接添加新项
|
|
|
|
+ datasList.add(newData);
|
|
|
|
+ orderCountList.add(newOrderCount);
|
|
|
|
+ payMoneyList.add(newPayMoney);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void mergeDataListsForInteger(List<String> datasList, List<Integer> orderCountList, List<Integer> payMoneyList,
|
|
|
|
+ List<String> datas, List<Integer> orderCount, List<Integer> payMoney) {
|
|
|
|
+ // 遍历新数据
|
|
|
|
+ for (int i = 0; i < datas.size(); i++) {
|
|
|
|
+ String newData = datas.get(i);
|
|
|
|
+ Integer newOrderCount = orderCount.get(i);
|
|
|
|
+ Integer newPayMoney = payMoney.get(i);
|
|
|
|
+
|
|
|
|
+ // 查找在现有列表中的位置
|
|
|
|
+ int existingIndex = datasList.indexOf(newData);
|
|
|
|
+
|
|
|
|
+ if (existingIndex != -1) {
|
|
|
|
+ // 如果存在,将orderCount和payMoney相加
|
|
|
|
+ Integer existingOrderCount = orderCountList.get(existingIndex);
|
|
|
|
+ Integer existingPayMoney = payMoneyList.get(existingIndex);
|
|
|
|
+
|
|
|
|
+ // 累加orderCount
|
|
|
|
+ orderCountList.set(existingIndex,
|
|
|
|
+ (existingOrderCount == null ? 0 : existingOrderCount) +
|
|
|
|
+ (newOrderCount == null ? 0 : newOrderCount));
|
|
|
|
+
|
|
|
|
+ // 累加payMoney
|
|
|
|
+ payMoneyList.set(existingIndex,
|
|
|
|
+ (existingPayMoney == null ? 0 : existingPayMoney) +
|
|
|
|
+ (newPayMoney == null ? 0 : newPayMoney));
|
|
|
|
+ } else {
|
|
|
|
+ // 如果不存在,直接添加新项
|
|
|
|
+ datasList.add(newData);
|
|
|
|
+ orderCountList.add(newOrderCount);
|
|
|
|
+ payMoneyList.add(newPayMoney);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|