|
@@ -1,18 +1,30 @@
|
|
|
package com.fs.tenant.service.impl;
|
|
package com.fs.tenant.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.fs.billing.domain.BillingDetail;
|
|
|
|
|
+import com.fs.billing.domain.FeePlanItem;
|
|
|
|
|
+import com.fs.billing.domain.UsageEvent;
|
|
|
|
|
+import com.fs.billing.mapper.BillingDetailMapper;
|
|
|
|
|
+import com.fs.billing.mapper.UsageEventMapper;
|
|
|
import com.fs.common.constant.UserConstants;
|
|
import com.fs.common.constant.UserConstants;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.domain.TreeSelect;
|
|
import com.fs.common.core.domain.TreeSelect;
|
|
|
import com.fs.common.core.domain.entity.SysMenu;
|
|
import com.fs.common.core.domain.entity.SysMenu;
|
|
|
import com.fs.common.core.domain.entity.TenantCompanyMenu;
|
|
import com.fs.common.core.domain.entity.TenantCompanyMenu;
|
|
|
|
|
+import com.fs.common.enums.DataSourceType;
|
|
|
import com.fs.common.exception.CustomException;
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
import com.fs.common.utils.StringUtils;
|
|
|
|
|
|
|
|
|
|
+import com.fs.company.domain.CompanyVoiceRoboticCallLogCallphone;
|
|
|
|
|
+import com.fs.qw.domain.QwRestrictionPushRecord;
|
|
|
import com.fs.system.service.ISysMenuService;
|
|
import com.fs.system.service.ISysMenuService;
|
|
|
import com.fs.tenant.domain.TenantInfo;
|
|
import com.fs.tenant.domain.TenantInfo;
|
|
|
|
|
+import com.fs.tenant.dto.SopTokenDto;
|
|
|
import com.fs.tenant.mapper.TenantInfoMapper;
|
|
import com.fs.tenant.mapper.TenantInfoMapper;
|
|
|
import com.fs.tenant.service.TenantAsyncService;
|
|
import com.fs.tenant.service.TenantAsyncService;
|
|
|
import com.fs.tenant.service.TenantInfoService;
|
|
import com.fs.tenant.service.TenantInfoService;
|
|
@@ -23,8 +35,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.sql.Connection;
|
|
import java.sql.Connection;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -41,6 +55,10 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
private TenantAsyncService tenantAsyncService;
|
|
private TenantAsyncService tenantAsyncService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISysMenuService menuService;
|
|
private ISysMenuService menuService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private UsageEventMapper usageEventMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BillingDetailMapper billingDetailMapper;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 查询租户基础信息
|
|
* 查询租户基础信息
|
|
@@ -389,6 +407,131 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
public int deleteComMenuById(Long menuId) {
|
|
public int deleteComMenuById(Long menuId) {
|
|
|
return baseMapper.deleteComMenuById(menuId);
|
|
return baseMapper.deleteComMenuById(menuId);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<FeePlanItem> selectFeeItem(String feePlanCode) {
|
|
|
|
|
+ return baseMapper.selectFeeItem(feePlanCode);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Map<String, Object> getYesterDayTraffic(DateTime yesterDayBegin, DateTime yesterdayEnd, FeePlanItem item, TenantInfo tenant) {
|
|
|
|
|
+ // 查询流量
|
|
|
|
|
+ String traffic = baseMapper.getYesterDayTraffic(yesterDayBegin, yesterdayEnd);
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal trafficB = traffic == null ? BigDecimal.ZERO : new BigDecimal(traffic);
|
|
|
|
|
+
|
|
|
|
|
+ // 根据计费方案单位,转换成对应单位
|
|
|
|
|
+ String unit = item.getUnit();
|
|
|
|
|
+ BigDecimal usage = BigDecimal.ZERO;
|
|
|
|
|
+
|
|
|
|
|
+ switch (unit) {
|
|
|
|
|
+ case "MB":
|
|
|
|
|
+ usage = trafficB.divide(new BigDecimal("1024"), 6, BigDecimal.ROUND_HALF_UP)
|
|
|
|
|
+ .divide(new BigDecimal("1024"), 6, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "GB":
|
|
|
|
|
+ usage = trafficB.divide(new BigDecimal("1024"), 6, BigDecimal.ROUND_HALF_UP)
|
|
|
|
|
+ .divide(new BigDecimal("1024"), 6, BigDecimal.ROUND_HALF_UP)
|
|
|
|
|
+ .divide(new BigDecimal("1024"), 6, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ usage = trafficB.divide(new BigDecimal("1024"), 6, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 计算费用
|
|
|
|
|
+ BigDecimal totalPrice = usage.multiply(item.getUnitPrice()).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+
|
|
|
|
|
+ // 返回结果
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("usage", usage);
|
|
|
|
|
+ map.put("price", totalPrice);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Map<String, Object> getYesterCallOut(DateTime yesterDayBegin, DateTime yesterdayEnd, FeePlanItem item,BigDecimal aiCallFee,TenantInfo tenant) {
|
|
|
|
|
+ List<CompanyVoiceRoboticCallLogCallphone> list = baseMapper.getYesterCallOut(yesterDayBegin, yesterdayEnd);
|
|
|
|
|
+
|
|
|
|
|
+ // 初始金额 0
|
|
|
|
|
+ BigDecimal totalPrice = BigDecimal.ZERO;
|
|
|
|
|
+ long minutes = 0;
|
|
|
|
|
+ for (CompanyVoiceRoboticCallLogCallphone c : list) {
|
|
|
|
|
+ // 通话时长(不足1分钟按1分钟算)
|
|
|
|
|
+ Long callTime = c.getCallTime();
|
|
|
|
|
+ if (callTime == null || callTime <= 0) {
|
|
|
|
|
+ continue; // 空或0秒跳过
|
|
|
|
|
+ }
|
|
|
|
|
+ minutes = (callTime + 60 - 1) / 60;
|
|
|
|
|
+
|
|
|
|
|
+ // 计算单价
|
|
|
|
|
+ BigDecimal itemPrice = 2 == c.getCallType() ?
|
|
|
|
|
+ item.getUnitPrice().add(aiCallFee).multiply(new BigDecimal(minutes))
|
|
|
|
|
+ : item.getUnitPrice().multiply(new BigDecimal(minutes));
|
|
|
|
|
+
|
|
|
|
|
+ totalPrice = totalPrice.add(itemPrice);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal totalFee = totalPrice.setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("usage", minutes);
|
|
|
|
|
+ map.put("price", totalFee);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Map<String, Object> getYesterAddWechat(DateTime yesterDayBegin, DateTime yesterdayEnd, FeePlanItem item,TenantInfo tenant) {
|
|
|
|
|
+ int count = 0;
|
|
|
|
|
+ count = baseMapper.getYesterAddWechat(yesterDayBegin, yesterdayEnd);
|
|
|
|
|
+ BigDecimal totalFee = BigDecimal.ZERO;
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ totalFee = item.getUnitPrice().multiply(new BigDecimal(count)).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("usage", count);
|
|
|
|
|
+ map.put("price", totalFee);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Map<String, Object> getYesterAiReplyToken(DateTime yesterDayBegin, DateTime yesterdayEnd, FeePlanItem item,TenantInfo tenant) {
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ long token = 0L;
|
|
|
|
|
+ token = baseMapper.getYesterAiReplyToken(yesterDayBegin, yesterdayEnd);
|
|
|
|
|
+ if (BeanUtil.isEmpty(token)) {
|
|
|
|
|
+ map.put("usage", token);
|
|
|
|
|
+ map.put("price", BigDecimal.ZERO);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal tokenCount = new BigDecimal(token).divide(new BigDecimal(item.getTokenUnit()), 6, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ BigDecimal totalFee = item.getUnitPrice().multiply(tokenCount).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ map.put("usage", token);
|
|
|
|
|
+ map.put("price", totalFee);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Map<String, Object> getYesterSopToken(DateTime yesterDayBegin, DateTime yesterdayEnd, FeePlanItem item,TenantInfo tenant) {
|
|
|
|
|
+ List<SopTokenDto> list = baseMapper.getYesterSopToken(yesterDayBegin, yesterdayEnd);
|
|
|
|
|
+ BigDecimal totalToken = BigDecimal.ZERO;
|
|
|
|
|
+ for (SopTokenDto sopToken : list) {
|
|
|
|
|
+ int type = sopToken.getType();
|
|
|
|
|
+ if (type == 7) {
|
|
|
|
|
+ totalToken = totalToken.add(new BigDecimal(sopToken.getCount() * 450));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ totalToken = totalToken.add(new BigDecimal(sopToken.getCount() * 150));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal tokenCount = totalToken.divide(new BigDecimal(item.getTokenUnit()), 6, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ BigDecimal totalFee = item.getUnitPrice().multiply(tokenCount).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("usage", totalToken);
|
|
|
|
|
+ map.put("price", totalFee);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|