|
@@ -1,14 +1,25 @@
|
|
|
package com.fs.api.controller;
|
|
|
|
|
|
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.company.constant.CompanyTrafficConstants;
|
|
|
+import com.fs.company.domain.Company;
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
+import com.fs.his.utils.ConfigUtil;
|
|
|
+import com.fs.hisStore.config.MedicalMallConfig;
|
|
|
import com.fs.statis.StatisticsRedisConstant;
|
|
|
import com.fs.statis.dto.*;
|
|
|
+import com.fs.statis.param.StatisticsDeptCompanyParam;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
+import com.fs.system.service.ISysDeptService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.YearMonth;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -25,6 +36,18 @@ public class IndexStatisticsController {
|
|
|
|
|
|
@Autowired
|
|
|
private ISysConfigService sysConfigService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ConfigUtil configUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptService deptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICompanyService companyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MedicalMallConfig medicalMallConfig;
|
|
|
/**
|
|
|
* 分析概览
|
|
|
*/
|
|
@@ -51,8 +74,35 @@ public class IndexStatisticsController {
|
|
|
* 消费余额
|
|
|
*/
|
|
|
@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())) {
|
|
|
+ consumptionBalanceDataDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_BALANCE);
|
|
|
+ }
|
|
|
+ if(param.getCompanyId() != null){
|
|
|
+ consumptionBalanceDataDTO = redisCache.getCacheObject(String.format("%s:%d",DATA_OVERVIEW_DEALER_BALANCE,param.getCompanyId()));
|
|
|
+ }else if(param.getDeptId() == 1) {
|
|
|
+ consumptionBalanceDataDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_BALANCE);
|
|
|
+ }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);
|
|
|
}
|
|
@@ -62,15 +112,57 @@ public class IndexStatisticsController {
|
|
|
* @return
|
|
|
*/
|
|
|
@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())) {
|
|
|
+ result = redisCache.getCacheObject(DATA_OVERVIEW_TRAFFIC_LOG);
|
|
|
+ SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("redPacket.Traffic.config");
|
|
|
+ if(result == null || sysConfig == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String configValue = sysConfig.getConfigValue();
|
|
|
+ result.setTraffic(configValue);
|
|
|
+ }
|
|
|
+ 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())));
|
|
|
+
|
|
|
+ }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")));
|
|
|
+
|
|
|
}
|
|
|
- String configValue = sysConfig.getConfigValue();
|
|
|
- trafficLogDTO.setTraffic(configValue);
|
|
|
- return R.ok().put("data",trafficLogDTO);
|
|
|
+ return R.ok().put("data",result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private TrafficLogDTO getTrafficLogCompany(String key){
|
|
|
+ TrafficLogDTO dto = new TrafficLogDTO();
|
|
|
+ //昨天
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
+ dto.setYesterday(redisCache.getCacheObject(key+yesterday));
|
|
|
+ //今天
|
|
|
+ dto.setToday(redisCache.getCacheObject(key+LocalDate.now()));
|
|
|
+ //本月
|
|
|
+ dto.setThisMonth(redisCache.getCacheObject(key+YearMonth.now()));
|
|
|
+ //剩余
|
|
|
+ //删除key最后一个字符
|
|
|
+ key = key.substring(0,key.lastIndexOf(":"));
|
|
|
+ dto.setTraffic(redisCache.getCacheObject(key));
|
|
|
+ return dto;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -157,12 +249,63 @@ public class IndexStatisticsController {
|
|
|
* 数据概览
|
|
|
*/
|
|
|
@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)) {
|
|
|
+ return R.ok().put("data",redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_AGGREGATED));
|
|
|
+ }
|
|
|
+ //选中销售公司
|
|
|
+ if (param.getCompanyId() != null) {
|
|
|
+ result = redisCache.getCacheObject(String.format("%s:%d", DATA_OVERVIEW_DEALER_AGGREGATED, param.getCompanyId()));
|
|
|
+ //没选中销售公司,选中部门为总公司
|
|
|
+ }else if (param.getDeptId() == 1){
|
|
|
+ result = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_AGGREGATED);
|
|
|
+ //没选中销售公司,部门不为总公司
|
|
|
+ }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);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 短信余额
|
|
|
*/
|