|
@@ -1,7 +1,6 @@
|
|
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.constant.CompanyTrafficConstants;
|
|
import com.fs.company.domain.Company;
|
|
import com.fs.company.domain.Company;
|
|
@@ -53,7 +52,7 @@ public class IndexStatisticsController {
|
|
*/
|
|
*/
|
|
@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();
|
|
|
|
|
|
@@ -64,7 +63,24 @@ 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(param.getCompanyId() != null){
|
|
|
|
+ analysisPreviewDTO = redisCache.getCacheObject(String.format("%s:%d:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType,param.getCompanyId()));
|
|
|
|
+ }else if(param.getDeptId() == 1){
|
|
|
|
+ analysisPreviewDTO = redisCache.getCacheObject(String.format("%s:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType));
|
|
|
|
+ }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) {
|
|
|
|
+ long currentWatchUserCount = analysisPreviewDTO.getWatchUserCount();
|
|
|
|
+ long childWatchUserCount = clildDTO.getWatchUserCount();
|
|
|
|
+ analysisPreviewDTO.setWatchUserCount(currentWatchUserCount + childWatchUserCount);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
return R.ok().put("data",analysisPreviewDTO);
|
|
return R.ok().put("data",analysisPreviewDTO);
|
|
}
|
|
}
|
|
@@ -124,45 +140,28 @@ public class IndexStatisticsController {
|
|
result.setTraffic(configValue);
|
|
result.setTraffic(configValue);
|
|
}
|
|
}
|
|
if(param.getCompanyId() != null){
|
|
if(param.getCompanyId() != null){
|
|
- //昨天
|
|
|
|
- LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
|
- result.setYesterday(redisCache.getCacheObject(String.format("%s:%d:%d:%s", CompanyTrafficConstants.CACHE_KEY,param.getDeptId(),param.getCompanyId(),yesterday)));
|
|
|
|
- //今天
|
|
|
|
- result.setToday(redisCache.getCacheObject(String.format("%s:%d:%d:%s", CompanyTrafficConstants.CACHE_KEY,param.getDeptId(),param.getCompanyId(),LocalDate.now())));
|
|
|
|
- //本月
|
|
|
|
- result.setThisMonth(redisCache.getCacheObject(String.format("%s:%d:%d:%s", CompanyTrafficConstants.CACHE_KEY,param.getDeptId(),param.getCompanyId(),YearMonth.now())));
|
|
|
|
- //剩余
|
|
|
|
- result.setTraffic(redisCache.getCacheObject(String.format("%s:%d:%d", CompanyTrafficConstants.CACHE_KEY,param.getDeptId(),param.getCompanyId())));
|
|
|
|
-
|
|
|
|
|
|
+ Company company = companyService.selectCompanyById(param.getCompanyId());
|
|
|
|
+ getTrafficLogResult(result,CompanyTrafficConstants.CACHE_KEY+":"+company.getDeptId()+":"+param.getCompanyId());
|
|
}else if(param.getDeptId() != null) {
|
|
}else if(param.getDeptId() != null) {
|
|
- //昨天
|
|
|
|
- LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
|
- result.setYesterday(redisCache.getCacheObject(String.format("%s:%s:%s", CompanyTrafficConstants.CACHE_KEY,":1:",yesterday)));
|
|
|
|
- //今天
|
|
|
|
- result.setToday(redisCache.getCacheObject(String.format("%s:%s:%s", CompanyTrafficConstants.CACHE_KEY,":1:",LocalDate.now())));
|
|
|
|
- //本月
|
|
|
|
- result.setThisMonth(redisCache.getCacheObject(String.format("%s:%s:%s", CompanyTrafficConstants.CACHE_KEY,":1:",YearMonth.now())));
|
|
|
|
- //剩余
|
|
|
|
- result.setTraffic(redisCache.getCacheObject(String.format("%s:%s", CompanyTrafficConstants.CACHE_KEY,":1")));
|
|
|
|
-
|
|
|
|
|
|
+ getTrafficLogResult(result,CompanyTrafficConstants.CACHE_KEY+":"+param.getDeptId());
|
|
}
|
|
}
|
|
return R.ok().put("data",result);
|
|
return R.ok().put("data",result);
|
|
}
|
|
}
|
|
|
|
|
|
- private TrafficLogDTO getTrafficLogCompany(String key){
|
|
|
|
- TrafficLogDTO dto = new TrafficLogDTO();
|
|
|
|
|
|
+ private void getTrafficLogResult(TrafficLogDTO result, String key){
|
|
//昨天
|
|
//昨天
|
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
- dto.setYesterday(redisCache.getCacheObject(key+yesterday));
|
|
|
|
|
|
+ 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((yesterdayCount == null)?0L:((Integer)yesterdayCount).longValue());
|
|
//今天
|
|
//今天
|
|
- dto.setToday(redisCache.getCacheObject(key+LocalDate.now()));
|
|
|
|
|
|
+ result.setToday(todayCount == null?0L:((Integer)todayCount).longValue());
|
|
//本月
|
|
//本月
|
|
- dto.setThisMonth(redisCache.getCacheObject(key+YearMonth.now()));
|
|
|
|
|
|
+ result.setThisMonth(thisMonthCount == null?0L:((Integer)thisMonthCount).longValue());
|
|
//剩余
|
|
//剩余
|
|
- //删除key最后一个字符
|
|
|
|
- key = key.substring(0,key.lastIndexOf(":"));
|
|
|
|
- dto.setTraffic(redisCache.getCacheObject(key));
|
|
|
|
- return dto;
|
|
|
|
|
|
+ result.setTraffic(traffic == null?"0":traffic.toString());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|