|
@@ -4,16 +4,29 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.his.domain.AdProfitDetail;
|
|
import com.fs.his.domain.AdProfitDetail;
|
|
|
import com.fs.his.dto.AdProfitDetailDto;
|
|
import com.fs.his.dto.AdProfitDetailDto;
|
|
|
|
|
+import com.fs.his.enums.FsUserIntegralLogTypeEnum;
|
|
|
import com.fs.his.mapper.AdProfitDetailMapper;
|
|
import com.fs.his.mapper.AdProfitDetailMapper;
|
|
|
|
|
+import com.fs.his.mapper.FsIntegralRedPacketLogMapper;
|
|
|
|
|
+import com.fs.his.param.AdProfitDetailStatisticsParam;
|
|
|
import com.fs.his.service.IAdProfitDetailService;
|
|
import com.fs.his.service.IAdProfitDetailService;
|
|
|
|
|
+import com.fs.his.service.IFsUserIntegralLogsService;
|
|
|
|
|
+import com.fs.his.vo.AdProfitDetailStatisticsVo;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
+import java.util.concurrent.TimeoutException;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 广告分佣Service业务层处理
|
|
* 广告分佣Service业务层处理
|
|
@@ -22,7 +35,15 @@ import java.util.Map;
|
|
|
* @date 2025-11-27
|
|
* @date 2025-11-27
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
|
|
+@Slf4j
|
|
|
public class AdProfitDetailServiceImpl extends ServiceImpl<AdProfitDetailMapper, AdProfitDetail> implements IAdProfitDetailService {
|
|
public class AdProfitDetailServiceImpl extends ServiceImpl<AdProfitDetailMapper, AdProfitDetail> implements IAdProfitDetailService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsIntegralRedPacketLogMapper fsIntegralRedPacketLogMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsUserIntegralLogsService fsUserIntegralLogsService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ @Qualifier("threadPoolTaskExecutor")
|
|
|
|
|
+ private ThreadPoolTaskExecutor executor;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 查询广告分佣
|
|
* 查询广告分佣
|
|
@@ -112,9 +133,58 @@ public class AdProfitDetailServiceImpl extends ServiceImpl<AdProfitDetailMapper,
|
|
|
BigDecimal totalMayWithdraw = new BigDecimal(map.get("totalMayWithdraw").toString()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
|
|
BigDecimal totalMayWithdraw = new BigDecimal(map.get("totalMayWithdraw").toString()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
|
|
|
// 已提现总金额
|
|
// 已提现总金额
|
|
|
BigDecimal totalWithdrawFinish = new BigDecimal(map.get("totalWithdrawFinish").toString()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
|
|
BigDecimal totalWithdrawFinish = new BigDecimal(map.get("totalWithdrawFinish").toString()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
|
|
|
|
|
+ // 提现中金额
|
|
|
|
|
+ BigDecimal withdrawMoney = fsIntegralRedPacketLogMapper.sumMoneyByStatus(0);
|
|
|
|
|
+ if (withdrawMoney != null) {
|
|
|
|
|
+ totalMayWithdraw = totalMayWithdraw.subtract(withdrawMoney);
|
|
|
|
|
+ totalWithdrawFinish = totalWithdrawFinish.subtract(withdrawMoney);
|
|
|
|
|
+ withdrawMoney = withdrawMoney.setScale(2, RoundingMode.UP);
|
|
|
|
|
+ }
|
|
|
Map<String,Object> widthdrawMap = new HashMap<>();
|
|
Map<String,Object> widthdrawMap = new HashMap<>();
|
|
|
widthdrawMap.put("totalMayWithdraw",totalMayWithdraw);
|
|
widthdrawMap.put("totalMayWithdraw",totalMayWithdraw);
|
|
|
widthdrawMap.put("totalWithdrawFinish",totalWithdrawFinish);
|
|
widthdrawMap.put("totalWithdrawFinish",totalWithdrawFinish);
|
|
|
|
|
+ widthdrawMap.put("withdrawMoney",withdrawMoney);
|
|
|
return R.ok(widthdrawMap);
|
|
return R.ok(widthdrawMap);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<AdProfitDetailStatisticsVo> statisticsList(AdProfitDetailStatisticsParam param) {
|
|
|
|
|
+ // 并行执行两个查询
|
|
|
|
|
+ CompletableFuture<List<AdProfitDetailStatisticsVo>> vosFuture = CompletableFuture
|
|
|
|
|
+ .supplyAsync(() -> baseMapper.statisticsList(param), executor);
|
|
|
|
|
+
|
|
|
|
|
+ CompletableFuture<BigDecimal> integralFuture = CompletableFuture
|
|
|
|
|
+ .supplyAsync(() -> {
|
|
|
|
|
+ Long integral = fsUserIntegralLogsService.sumIntegralByLogTypeAndCreateTime(
|
|
|
|
|
+ FsUserIntegralLogTypeEnum.TYPE_31.getValue(), param
|
|
|
|
|
+ );
|
|
|
|
|
+ return integral != null && integral > 0
|
|
|
|
|
+ ? new BigDecimal(integral).divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP)
|
|
|
|
|
+ : BigDecimal.ZERO;
|
|
|
|
|
+ }, executor);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 等待两个都完成
|
|
|
|
|
+ CompletableFuture.allOf(vosFuture, integralFuture)
|
|
|
|
|
+ .get(60, TimeUnit.SECONDS);
|
|
|
|
|
+
|
|
|
|
|
+ List<AdProfitDetailStatisticsVo> vos = vosFuture.getNow(null);
|
|
|
|
|
+ BigDecimal totalIntegral = integralFuture.getNow(BigDecimal.ZERO);
|
|
|
|
|
+
|
|
|
|
|
+ if (vos != null && !vos.isEmpty()) {
|
|
|
|
|
+ vos.get(0).setAmountYuan(totalIntegral);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return vos != null ? vos : Collections.emptyList();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (TimeoutException e) {
|
|
|
|
|
+ log.error("查询超时", e);
|
|
|
|
|
+ vosFuture.cancel(true);
|
|
|
|
|
+ integralFuture.cancel(true);
|
|
|
|
|
+ throw new RuntimeException("查询超时,请稍后重试");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("查询异常", e);
|
|
|
|
|
+ throw new RuntimeException("查询执行异常", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|