|
|
@@ -1,18 +1,35 @@
|
|
|
package com.fs.company.controller.company;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.utils.PubFun;
|
|
|
import com.fs.common.utils.ServletUtils;
|
|
|
+import com.fs.common.utils.date.DateUtil;
|
|
|
+import com.fs.company.domain.Company;
|
|
|
+import com.fs.company.domain.CompanyTrafficRecord;
|
|
|
+import com.fs.company.domain.CompanyTrafficRecordLog;
|
|
|
+import com.fs.company.mapper.CompanyMapper;
|
|
|
+import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
+import com.fs.company.mapper.CompanyTrafficRecordLogMapper;
|
|
|
+import com.fs.company.mapper.CompanyTrafficRecordMapper;
|
|
|
import com.fs.framework.security.LoginUser;
|
|
|
import com.fs.framework.service.TokenService;
|
|
|
import com.fs.statis.StatisticsRedisConstant;
|
|
|
import com.fs.statis.dto.*;
|
|
|
import com.fs.statis.service.IStatisticsService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.MathContext;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.fs.statis.StatisticsRedisConstant.*;
|
|
|
|
|
|
@@ -30,6 +47,34 @@ public class IndexStatisticsController {
|
|
|
|
|
|
@Autowired
|
|
|
private IStatisticsService statisticsService;
|
|
|
+ @Autowired
|
|
|
+ private CompanyMoneyLogsMapper moneyLogsMapper;
|
|
|
+ @Autowired
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
+ @Autowired
|
|
|
+ private CompanyTrafficRecordMapper companyTrafficRecordMapper;
|
|
|
+ @Autowired
|
|
|
+ private CompanyTrafficRecordLogMapper companyTrafficRecordLogMapper;
|
|
|
+ @Value("${cloud_host.company_name}")
|
|
|
+ private String signProjectName;
|
|
|
+
|
|
|
+ Function<Long, String> tranTraffic = traffic -> {
|
|
|
+ int unitInt = 1024;
|
|
|
+ BigDecimal unit = BigDecimal.valueOf(unitInt);
|
|
|
+ BigDecimal kb = BigDecimal.valueOf(traffic);
|
|
|
+ if(traffic < unitInt){
|
|
|
+ return traffic + "KB";
|
|
|
+ }
|
|
|
+ BigDecimal mb = kb.divide(unit, 2, RoundingMode.HALF_UP);
|
|
|
+ if(mb.doubleValue() < unitInt){
|
|
|
+ return mb + "MB";
|
|
|
+ }
|
|
|
+ BigDecimal gb = mb.divide(unit, 2, RoundingMode.HALF_UP);
|
|
|
+ if(gb.doubleValue() < unitInt){
|
|
|
+ return mb + "GB";
|
|
|
+ }
|
|
|
+ return gb.divide(unit, 2, RoundingMode.HALF_UP) + "TB";
|
|
|
+ };
|
|
|
|
|
|
/**
|
|
|
* 分析概览
|
|
|
@@ -62,9 +107,17 @@ public class IndexStatisticsController {
|
|
|
public R rechargeComsumption(){
|
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
Long companyId = loginUser.getCompany().getCompanyId();
|
|
|
-
|
|
|
- ConsumptionBalanceDataDTO consumptionBalanceDataDTO = redisCache.getCacheObject(String.format("%s:%d",StatisticsRedisConstant.DATA_OVERVIEW_DEALER_BALANCE,companyId));
|
|
|
- return R.ok().put("data", consumptionBalanceDataDTO);
|
|
|
+ ConsumptionBalanceDataDTO dto;
|
|
|
+ if("医健宝".equals(signProjectName)){
|
|
|
+ dto = new ConsumptionBalanceDataDTO();
|
|
|
+ Company company = companyMapper.selectCompanyById(companyId);
|
|
|
+ List<BigDecimal> subList = moneyLogsMapper.selectCompanyRedPackage(companyId);
|
|
|
+ dto.setBalance(company.getMoney());
|
|
|
+ dto.setTodayComsumption(subList.stream().map(BigDecimal::abs).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }else{
|
|
|
+ dto = redisCache.getCacheObject(String.format("%s:%d",StatisticsRedisConstant.DATA_OVERVIEW_DEALER_BALANCE,companyId));
|
|
|
+ }
|
|
|
+ return R.ok().put("data", dto);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -75,7 +128,21 @@ public class IndexStatisticsController {
|
|
|
public R getTrafficLog(){
|
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
Long companyId = loginUser.getCompany().getCompanyId();
|
|
|
- TrafficLogDTO trafficLogDTO = redisCache.getCacheObject(String.format("%s:%d",DATA_OVERVIEW_TRAFFIC_LOG,companyId));
|
|
|
+ CompanyTrafficRecord companyTrafficRecord = companyTrafficRecordMapper.selectOne(new QueryWrapper<CompanyTrafficRecord>().eq("company_id", companyId));
|
|
|
+ TrafficLogDTO trafficLogDTO;
|
|
|
+ if("医健宝".equals(signProjectName)){
|
|
|
+ trafficLogDTO = new TrafficLogDTO();
|
|
|
+ if(companyTrafficRecord != null){
|
|
|
+ trafficLogDTO.setTraffic(tranTraffic.apply(companyTrafficRecord.getBalance()));
|
|
|
+ List<CompanyTrafficRecordLog> monthLogs = companyTrafficRecordLogMapper.selectMonth(companyId);
|
|
|
+ List<CompanyTrafficRecordLog> toDayLos = monthLogs.stream().filter(e -> DateUtil.dateToLocalDateTime(e.getCreateTime()).toLocalDate().equals(LocalDate.now())).collect(Collectors.toList());
|
|
|
+ Function<List<CompanyTrafficRecordLog>, Long> traffic = list -> list.stream().mapToLong(CompanyTrafficRecordLog::getTrafficAmount).sum();
|
|
|
+ trafficLogDTO.setToday(traffic.apply(toDayLos));
|
|
|
+ trafficLogDTO.setThisMonth(traffic.apply(monthLogs));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ trafficLogDTO = redisCache.getCacheObject(String.format("%s:%d",DATA_OVERVIEW_TRAFFIC_LOG,companyId));
|
|
|
+ }
|
|
|
return R.ok().put("data",trafficLogDTO);
|
|
|
}
|
|
|
|