|
|
@@ -2,6 +2,9 @@ package com.kxs.system.biz.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
@@ -12,26 +15,32 @@ import com.kxs.common.core.constant.enums.ErrorTypeEnum;
|
|
|
import com.kxs.common.core.exception.GlobalCustomerException;
|
|
|
import com.kxs.common.core.util.R;
|
|
|
import com.kxs.common.core.util.RetOps;
|
|
|
+import com.kxs.common.core.util.SysUtils;
|
|
|
import com.kxs.common.security.util.SecurityUtils;
|
|
|
+import com.kxs.product.api.feign.RemoteKxsProductService;
|
|
|
+import com.kxs.product.api.vo.kxsapp.shop.ShopOrderGoodsUserVO;
|
|
|
import com.kxs.system.api.model.KxsCampUser;
|
|
|
import com.kxs.system.api.vo.admin.CampUserExcelVO;
|
|
|
import com.kxs.system.api.vo.kxsapp.camp.CampGetByIdVO;
|
|
|
import com.kxs.system.api.vo.kxsapp.camp.CampPageVO;
|
|
|
+import com.kxs.system.biz.constant.enums.CampStatusEnum;
|
|
|
import com.kxs.system.biz.constant.enums.SysErrorTypeEnum;
|
|
|
import com.kxs.system.biz.mapper.KxsCampMapper;
|
|
|
import com.kxs.system.api.model.KxsCamp;
|
|
|
import com.kxs.system.biz.mapper.KxsCampUserMapper;
|
|
|
+import com.kxs.system.biz.service.KxsCampBonusLogService;
|
|
|
import com.kxs.system.biz.service.KxsCampService;
|
|
|
+import com.kxs.system.biz.service.KxsCampUserService;
|
|
|
import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
|
+import com.kxs.user.api.model.KxsLeader;
|
|
|
import com.kxs.user.api.model.KxsUser;
|
|
|
import com.pig4cloud.plugin.excel.vo.ErrorMessage;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 训练营(KxsCamp)表服务实现类
|
|
|
@@ -45,7 +54,12 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
|
|
|
private final RemoteKxsUserService remoteKxsUserService;
|
|
|
|
|
|
- private final KxsCampUserMapper kxsCampUserMapper;
|
|
|
+ private final RemoteKxsProductService remoteKxsProductService;
|
|
|
+
|
|
|
+
|
|
|
+ private final KxsCampUserService kxsCampUserService;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public R addData(KxsCamp param) {
|
|
|
@@ -109,7 +123,7 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
errorMsg.add(excel.getUserCode() + "创客未找到!");
|
|
|
}
|
|
|
//判断创客是否加入
|
|
|
- KxsCampUser kxsCampUser = kxsCampUserMapper.selectOne(Wrappers.<KxsCampUser>lambdaQuery()
|
|
|
+ KxsCampUser kxsCampUser = kxsCampUserService.getOne(Wrappers.<KxsCampUser>lambdaQuery()
|
|
|
.eq(KxsCampUser::getCampId, excel.getCampId())
|
|
|
.eq(KxsCampUser::getUserId, user.getId()));
|
|
|
if(kxsCampUser != null){
|
|
|
@@ -123,7 +137,7 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
campUser.setUserId(user.getId());
|
|
|
campUser.setUsername(user.getUsername());
|
|
|
campUser.setUserCode(user.getUserCode());
|
|
|
- kxsCampUserMapper.insert(campUser);
|
|
|
+ kxsCampUserService.save(campUser);
|
|
|
}
|
|
|
else {
|
|
|
// 数据不合法
|
|
|
@@ -153,5 +167,126 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
BeanUtil.copyProperties(kxsCamp, campGetByIdVO);
|
|
|
return R.ok(campGetByIdVO);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void prizePoolIsRefreshed() {
|
|
|
+ //查询正在进行中的活动
|
|
|
+ List<KxsCamp> list = baseMapper.selectList(Wrappers.<KxsCamp>lambdaQuery().eq(KxsCamp::getStatus, CampStatusEnum.STATUS_NORMAL.getType()));
|
|
|
+ //查询活动参与的创客
|
|
|
+ for (KxsCamp kxsCamp : list) {
|
|
|
+ //初始化奖金池
|
|
|
+ BigDecimal totalBonusPool = BigDecimal.ZERO;
|
|
|
+ //开机数
|
|
|
+ int openNum;
|
|
|
+ //下单数
|
|
|
+ int orderNum = 0;
|
|
|
+
|
|
|
+ List<KxsCampUser> campUsers = kxsCampUserService.list(Wrappers.<KxsCampUser>lambdaQuery().eq(KxsCampUser::getCampId, kxsCamp.getId()));
|
|
|
+ //清除参与创客的所有统计数据然后封装在map里方便统计
|
|
|
+ Map<Integer, KxsCampUser> campUsersMap = new HashMap<>();
|
|
|
+ for (KxsCampUser campUser : campUsers) {
|
|
|
+ KxsCampUser kxsCampUser = new KxsCampUser();
|
|
|
+ BeanUtil.copyProperties(campUser, kxsCampUser);
|
|
|
+ kxsCampUser.setTeamBonusPool(BigDecimal.ZERO);
|
|
|
+ kxsCampUser.setTeamOrderNum(0);
|
|
|
+ kxsCampUser.setTeamOpenNum(0);
|
|
|
+ campUsersMap.put(campUser.getUserId(), kxsCampUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ //转换为userID集合
|
|
|
+ List<Integer> userIds = campUsers.stream().map(KxsCampUser::getUserId).toList();
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 查询当前活动的时间区间所有电签大机的订单
|
|
|
+ */
|
|
|
+ R<List<ShopOrderGoodsUserVO>> ordersR = remoteKxsProductService.getDateBetweenOrders(LocalDateTimeUtil.format(kxsCamp.getStartTime(), DatePattern.NORM_DATETIME_PATTERN)
|
|
|
+ , LocalDateTimeUtil.format(kxsCamp.getEndTime(), DatePattern.NORM_DATETIME_PATTERN), SecurityConstants.FROM_IN);
|
|
|
+ List<ShopOrderGoodsUserVO> orders = RetOps.of(ordersR)
|
|
|
+ .getData()
|
|
|
+ .orElse(Collections.emptyList());
|
|
|
+ //循环区间订单查询用户的上级是否包含参与创客的ID
|
|
|
+ for (ShopOrderGoodsUserVO order : orders) {
|
|
|
+ //如果是参与者自己下的单
|
|
|
+ if (userIds.contains(order.getUserId())) {
|
|
|
+ BigDecimal amount = NumberUtil.mul(NumberUtil.div(order.getTotalPrice(), 600), 90);
|
|
|
+ totalBonusPool = NumberUtil.add(totalBonusPool, amount);
|
|
|
+ orderNum += NumberUtil.div(order.getTotalPrice(), 600).intValue();
|
|
|
+ //刷新参与创客的团队累计
|
|
|
+ KxsCampUser kxsCampUser = campUsersMap.get(order.getUserId());
|
|
|
+ kxsCampUser.setTeamBonusPool(NumberUtil.add(kxsCampUser.getTeamBonusPool(), amount));
|
|
|
+ kxsCampUser.setTeamOrderNum(kxsCampUser.getTeamOrderNum() + orderNum);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ R<KxsUser> kxsUserR = remoteKxsUserService.loadUserById(order.getUserId(), SecurityConstants.FROM_IN);
|
|
|
+ KxsUser user = RetOps.of(kxsUserR)
|
|
|
+ .getData()
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(ErrorTypeEnum.USER_NOT_FOUND.getDescription()));
|
|
|
+ //下单用户的上级路径
|
|
|
+ String[] pidPaths = user.getPidPath().split(",");
|
|
|
+ //通过用户的pidPath倒序查找最近所属的上级
|
|
|
+ Integer userId = SysUtils.checkUserIsChildren(pidPaths, userIds);
|
|
|
+ if(userId != null){
|
|
|
+ BigDecimal amount = NumberUtil.mul(NumberUtil.div(order.getTotalPrice(), 600), 90);
|
|
|
+ totalBonusPool = NumberUtil.add(totalBonusPool, amount);
|
|
|
+ orderNum += NumberUtil.div(order.getTotalPrice(), 600).intValue();
|
|
|
+
|
|
|
+ //刷新参与创客的团队累计
|
|
|
+ KxsCampUser kxsCampUser = campUsersMap.get(order.getUserId());
|
|
|
+ kxsCampUser.setTeamBonusPool(NumberUtil.add(kxsCampUser.getTeamBonusPool(), amount));
|
|
|
+ kxsCampUser.setTeamOrderNum(kxsCampUser.getTeamOrderNum() + orderNum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 查询活动区间开通的大盟主添加到奖金池
|
|
|
+ */
|
|
|
+ R<List<KxsLeader>> leadersR = remoteKxsUserService.getDateBetweenLeaders(LocalDateTimeUtil.format(kxsCamp.getStartTime(), DatePattern.NORM_DATETIME_PATTERN)
|
|
|
+ , LocalDateTimeUtil.format(kxsCamp.getEndTime(), DatePattern.NORM_DATETIME_PATTERN), SecurityConstants.FROM_IN);
|
|
|
+ List<KxsLeader> leaders = RetOps.of(leadersR)
|
|
|
+ .getData()
|
|
|
+ .orElse(Collections.emptyList());
|
|
|
+ for (KxsLeader leader : leaders) {
|
|
|
+ //如果是参与者自己下的单
|
|
|
+ if (userIds.contains(leader.getUserId())) {
|
|
|
+ BigDecimal amount = new BigDecimal("2000");
|
|
|
+ totalBonusPool = NumberUtil.add(totalBonusPool, amount);
|
|
|
+
|
|
|
+ //刷新参与创客的团队累计
|
|
|
+ KxsCampUser kxsCampUser = campUsersMap.get(leader.getUserId());
|
|
|
+ kxsCampUser.setTeamBonusPool(NumberUtil.add(kxsCampUser.getTeamBonusPool(), amount));
|
|
|
+ kxsCampUser.setTeamOrderNum(kxsCampUser.getTeamOrderNum() + orderNum);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ R<KxsUser> kxsUserR = remoteKxsUserService.loadUserById(leader.getUserId(), SecurityConstants.FROM_IN);
|
|
|
+ KxsUser user = RetOps.of(kxsUserR)
|
|
|
+ .getData()
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(ErrorTypeEnum.USER_NOT_FOUND.getDescription()));
|
|
|
+ //下单用户的上级路径
|
|
|
+ String[] pidPaths = user.getPidPath().split(",");
|
|
|
+ //通过用户的pidPath倒序查找最近所属的上级
|
|
|
+ Integer userId = SysUtils.checkUserIsChildren(pidPaths, userIds);
|
|
|
+ if(userId != null){
|
|
|
+ BigDecimal amount = new BigDecimal("2000");
|
|
|
+ totalBonusPool = NumberUtil.add(totalBonusPool, amount);
|
|
|
+
|
|
|
+ //刷新参与创客的团队累计
|
|
|
+ KxsCampUser kxsCampUser = campUsersMap.get(leader.getUserId());
|
|
|
+ kxsCampUser.setTeamBonusPool(NumberUtil.add(kxsCampUser.getTeamBonusPool(), amount));
|
|
|
+ kxsCampUser.setTeamOrderNum(kxsCampUser.getTeamOrderNum() + orderNum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ kxsCamp.setBonusPool(totalBonusPool);
|
|
|
+ kxsCamp.setOrderNum(orderNum);
|
|
|
+ baseMapper.updateById(kxsCamp);
|
|
|
+ //刷新参与创客的统计
|
|
|
+ kxsCampUserService.updateBatchById(new ArrayList<>(campUsersMap.values()));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|