|
|
@@ -15,16 +15,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.kxs.common.core.constant.SecurityConstants;
|
|
|
import com.kxs.common.core.constant.enums.ErrorTypeEnum;
|
|
|
-import com.kxs.common.core.constant.enums.LeaderTypeEnum;
|
|
|
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.stat.api.feign.RemoteKxsStatService;
|
|
|
import com.kxs.system.api.dto.kxsapp.camp.PrizePoolDTO;
|
|
|
import com.kxs.system.api.feign.RemoteOldService;
|
|
|
+import com.kxs.system.api.model.KxsCamp;
|
|
|
import com.kxs.system.api.model.KxsCampUser;
|
|
|
import com.kxs.system.api.vo.admin.CampUserExcelVO;
|
|
|
import com.kxs.system.api.vo.kxsapp.camp.CampGetByIdVO;
|
|
|
@@ -32,7 +30,6 @@ 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.service.KxsCampService;
|
|
|
import com.kxs.system.biz.service.KxsCampUserService;
|
|
|
import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
|
@@ -63,8 +60,6 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
|
|
|
private final RemoteKxsUserService remoteKxsUserService;
|
|
|
|
|
|
- private final RemoteKxsProductService remoteKxsProductService;
|
|
|
- private final RemoteKxsStatService remoteKxsStatService;
|
|
|
|
|
|
private final RemoteOldService remoteOldService;
|
|
|
|
|
|
@@ -89,13 +84,11 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
@Override
|
|
|
public R updateData(KxsCamp param) {
|
|
|
|
|
|
- if (param.getId() == null) {
|
|
|
+ if (Objects.isNull(param.getId())) {
|
|
|
return R.failed(SysErrorTypeEnum.PARAM_ERROR.getDescription());
|
|
|
}
|
|
|
KxsCamp kxsCamp = baseMapper.selectById(param.getId());
|
|
|
- if (kxsCamp == null) {
|
|
|
- return R.failed(SysErrorTypeEnum.NOT_DATA.getDescription());
|
|
|
- }
|
|
|
+ Optional.ofNullable(kxsCamp).orElseThrow(()-> new GlobalCustomerException(SysErrorTypeEnum.NOT_DATA.getDescription()));
|
|
|
|
|
|
R<KxsUser> kxsUserR = remoteKxsUserService.loadUserById(param.getCreateUserId(), SecurityConstants.FROM_IN);
|
|
|
KxsUser user = RetOps.of(kxsUserR)
|
|
|
@@ -115,9 +108,6 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
return R.failed(SysErrorTypeEnum.IMPORT_EMPTY.getDescription());
|
|
|
}
|
|
|
|
|
|
- //查询正在进行中的活动
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
-
|
|
|
// 通用校验获取失败的数据
|
|
|
List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
|
|
|
// 执行数据插入操作
|
|
|
@@ -129,8 +119,9 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
.getData()
|
|
|
.orElse(null);
|
|
|
KxsCamp kxsCamp = baseMapper.selectById(excel.getCampId());
|
|
|
- if (kxsCamp == null) {
|
|
|
- return R.failed(excel.getCampId() + "训练营编号不存在,请重新上传!");
|
|
|
+ Optional.ofNullable(kxsCamp).orElseThrow(()-> new GlobalCustomerException(excel.getCampId() + "训练营编号不存在,请重新上传!"));
|
|
|
+ if(Objects.equals(kxsCamp.getStatus(), CampStatusEnum.STATUS_END.getType())){
|
|
|
+ throw new GlobalCustomerException(excel.getCampId() + "训练营已结束,不允许导入!");
|
|
|
}
|
|
|
|
|
|
if (Objects.isNull(user)) {
|
|
|
@@ -140,16 +131,12 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
errorMsg.add(excel.getUserCode() + "创客未实名!");
|
|
|
}
|
|
|
//判断创客是否已在其他训练营
|
|
|
- KxsCampUser kxsCampUser = baseMapper.selectByUserId(user.getId(), now);
|
|
|
- if (kxsCampUser != null) {
|
|
|
+ KxsCamp camp = baseMapper.selectUserCamp(user.getId());
|
|
|
+ if (camp != null) {
|
|
|
errorMsg.add(excel.getUserCode() + "已在训练营!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //判断创客是否加入
|
|
|
-// KxsCampUser kxsCampUser = kxsCampUserService.getOne(Wrappers.<KxsCampUser>lambdaQuery()
|
|
|
-// .eq(KxsCampUser::getCampId, excel.getCampId())
|
|
|
-// .eq(KxsCampUser::getUserId, user.getId()));
|
|
|
|
|
|
// 数据合法情况
|
|
|
if (CollUtil.isEmpty(errorMsg)) {
|
|
|
@@ -179,20 +166,15 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
|
|
|
@Override
|
|
|
public IPage<CampPageVO> getByPage(Page<CampPageVO> page) {
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
+
|
|
|
Long userId = SecurityUtils.getUser().getId();
|
|
|
- IPage<CampPageVO> pageData = baseMapper.getByPage(page, userId);
|
|
|
- pageData.getRecords().forEach(item -> statusChange(item, now));
|
|
|
- return pageData;
|
|
|
+ return baseMapper.getByPage(page, userId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public R getByData(Integer id) {
|
|
|
KxsCamp kxsCamp = baseMapper.selectById(id);
|
|
|
- if (kxsCamp == null) {
|
|
|
- return R.failed(SysErrorTypeEnum.NOT_DATA.getDescription());
|
|
|
- }
|
|
|
- statusChange(kxsCamp, LocalDateTime.now());
|
|
|
+ Optional.ofNullable(kxsCamp).orElseThrow(() -> new GlobalCustomerException(SysErrorTypeEnum.NOT_DATA.getDescription()));
|
|
|
CampGetByIdVO campGetByIdVO = new CampGetByIdVO();
|
|
|
BeanUtil.copyProperties(kxsCamp, campGetByIdVO);
|
|
|
return R.ok(campGetByIdVO);
|
|
|
@@ -206,7 +188,7 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
//查询正在进行中的活动
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
//兑换券下单
|
|
|
- if(param.getProductId() == 10 || param.getProductId() == 11) {
|
|
|
+ if (param.getProductId() == 10 || param.getProductId() == 11) {
|
|
|
|
|
|
log.info("开始处理兑换券下单订单号:{}统计到训练营奖金池", param.getOrderNo());
|
|
|
|
|
|
@@ -215,11 +197,11 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
//订单奖金
|
|
|
BigDecimal amount = NumberUtil.mul(number, 60);
|
|
|
//查询此用户是否参加进行中的训练营
|
|
|
- KxsCamp kxsCamp = baseMapper.selectUserCamp(param.getUserId(), now);
|
|
|
+ KxsCamp kxsCamp = baseMapper.selectUserCamp(param.getUserId());
|
|
|
if (kxsCamp != null) {
|
|
|
//给训练营加金额
|
|
|
kxsCamp.setBonusPool(NumberUtil.add(kxsCamp.getBonusPool(), amount));
|
|
|
- kxsCamp.setOrderNum(kxsCamp.getOrderNum() + number.intValue());
|
|
|
+ kxsCamp.setOrderNum(kxsCamp.getOrderNum() + number.intValue());
|
|
|
baseMapper.updateById(kxsCamp);
|
|
|
|
|
|
//给创客团队加金额
|
|
|
@@ -251,7 +233,7 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
|
|
|
//给创客团队加金额
|
|
|
campUser.setTeamOrderPool(NumberUtil.add(campUser.getTeamOrderPool(), amount));
|
|
|
- campUser.setTeamOrderNum(campUser.getTeamOrderNum() + number.intValue());
|
|
|
+ campUser.setTeamOrderNum(campUser.getTeamOrderNum() + number.intValue());
|
|
|
kxsCampUserService.updateById(campUser);
|
|
|
log.info("用户{}的上级{}参加训练营{},订单ID{},奖金池{},订单数{}", param.getUserId(), campUser.getUserId(), camp.getId(), param.getId(), camp.getBonusPool(), camp.getOrderNum());
|
|
|
}
|
|
|
@@ -302,17 +284,13 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
|
|
|
@Override
|
|
|
public IPage<KxsCamp> getBySysPage(Page<KxsCamp> page, KxsCamp param) {
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- Page<KxsCamp> pageData = this.page(page, Wrappers.<KxsCamp>lambdaQuery()
|
|
|
+
|
|
|
+ return this.page(page, Wrappers.<KxsCamp>lambdaQuery()
|
|
|
.eq(StrUtil.isNotEmpty(param.getCreateCode()), KxsCamp::getCreateCode, param.getCreateCode())
|
|
|
.orderByDesc(KxsCamp::getId));
|
|
|
-
|
|
|
- pageData.getRecords().forEach(item -> statusChange(item, now));
|
|
|
- return pageData;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
@Async
|
|
|
public void poweronQuantityStatistics() {
|
|
|
@@ -364,7 +342,7 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
String[] pidPaths = user.getPidPath().split(",");
|
|
|
//通过用户的pidPath倒序查找最近所属的上级
|
|
|
Integer userId = SysUtils.checkUserIsChildren(pidPaths, userIds);
|
|
|
- if(userId != null){
|
|
|
+ if (userId != null) {
|
|
|
|
|
|
//刷新参与创客的团队累计
|
|
|
KxsCampUser kxsCampUser = campUsersMap.get(userId);
|
|
|
@@ -384,8 +362,8 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
data.put("StartTime", LocalDateTimeUtil.format(kxsCamp.getStartTime(), DatePattern.PURE_DATE_PATTERN));
|
|
|
data.put("EndTime", LocalDateTimeUtil.format(kxsCamp.getStartTime(), DatePattern.PURE_DATE_PATTERN));
|
|
|
R resR = remoteOldService.teamOpenTotalData(JSON.toJSONString(data));
|
|
|
- if(resR.getStatus() == 1){
|
|
|
- if(resR.getData() != null){
|
|
|
+ if (resR.getStatus() == 1) {
|
|
|
+ if (resR.getData() != null) {
|
|
|
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(resR.getData()));
|
|
|
int total = jsonObject.getInteger("TeamPosMerchantCount")
|
|
|
+ jsonObject.getInteger("TeamSimMerchantCount")
|
|
|
@@ -413,33 +391,57 @@ public class KxsCampServiceImpl extends ServiceImpl<KxsCampMapper, KxsCamp> impl
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R changeStatus(KxsCamp param) {
|
|
|
|
|
|
- /**
|
|
|
- * 状态变更
|
|
|
- *
|
|
|
- * @param campT 营地
|
|
|
- * @param now 现在
|
|
|
- */
|
|
|
- private <T> void statusChange(T campT, LocalDateTime now) {
|
|
|
- if (campT instanceof KxsCamp camp) {
|
|
|
- if (camp.getEndTime().isBefore(now)) {
|
|
|
- camp.setStatus(CampStatusEnum.STATUS_END.getType());
|
|
|
- } else if (LocalDateTimeUtil.isIn(now, camp.getStartTime(), camp.getEndTime(), false, false)) {
|
|
|
- camp.setStatus(CampStatusEnum.STATUS_NORMAL.getType());
|
|
|
- } else {
|
|
|
- camp.setStatus(CampStatusEnum.STATUS_CLOSE.getType());
|
|
|
- }
|
|
|
+ if(!Objects.equals(param.getStatus(), CampStatusEnum.STATUS_NORMAL.getType()) && !Objects.equals(param.getStatus(), CampStatusEnum.STATUS_END.getType())){
|
|
|
+ return R.failed(SysErrorTypeEnum.PARAM_ERROR.getDescription());
|
|
|
}
|
|
|
- if (campT instanceof CampPageVO camp) {
|
|
|
- if (camp.getEndTime().isBefore(now)) {
|
|
|
- camp.setStatus(CampStatusEnum.STATUS_END.getType());
|
|
|
- } else if (LocalDateTimeUtil.isIn(now, camp.getStartTime(), camp.getEndTime(), false, false)) {
|
|
|
- camp.setStatus(CampStatusEnum.STATUS_NORMAL.getType());
|
|
|
- } else {
|
|
|
- camp.setStatus(CampStatusEnum.STATUS_CLOSE.getType());
|
|
|
- }
|
|
|
+ KxsCamp camp = baseMapper.selectById(param.getId());
|
|
|
+ Optional.ofNullable(camp).orElseThrow(()-> new GlobalCustomerException("训练营不存在"));
|
|
|
+
|
|
|
+ if(Objects.equals(camp.getStatus(), CampStatusEnum.STATUS_END.getType())){
|
|
|
+ return R.failed("已结束的训练营无法再次开启");
|
|
|
+ }
|
|
|
+ if(Objects.equals(camp.getStatus(), CampStatusEnum.STATUS_NORMAL.getType())){
|
|
|
+ return R.failed("训练营已开启");
|
|
|
+ }
|
|
|
+
|
|
|
+ camp.setStatus(param.getStatus());
|
|
|
+
|
|
|
+ //开启活动刷新实际开始时间
|
|
|
+ if(Objects.equals(param.getStatus(), CampStatusEnum.STATUS_NORMAL.getType())){
|
|
|
+ camp.setStartTime(LocalDateTime.now());
|
|
|
}
|
|
|
+ //结束活动刷新实际结束时间
|
|
|
+ if(Objects.equals(param.getStatus(), CampStatusEnum.STATUS_END.getType())){
|
|
|
+ camp.setEndTime(LocalDateTime.now());
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(baseMapper.updateById(camp));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+// private <T> void statusChange(T campT, LocalDateTime now) {
|
|
|
+// if (campT instanceof KxsCamp camp) {
|
|
|
+// if (camp.getEndTime().isBefore(now)) {
|
|
|
+// camp.setStatus(CampStatusEnum.STATUS_END.getType());
|
|
|
+// } else if (LocalDateTimeUtil.isIn(now, camp.getStartTime(), camp.getEndTime(), false, false)) {
|
|
|
+// camp.setStatus(CampStatusEnum.STATUS_NORMAL.getType());
|
|
|
+// } else {
|
|
|
+// camp.setStatus(CampStatusEnum.STATUS_CLOSE.getType());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (campT instanceof CampPageVO camp) {
|
|
|
+// if (camp.getEndTime().isBefore(now)) {
|
|
|
+// camp.setStatus(CampStatusEnum.STATUS_END.getType());
|
|
|
+// } else if (LocalDateTimeUtil.isIn(now, camp.getStartTime(), camp.getEndTime(), false, false)) {
|
|
|
+// camp.setStatus(CampStatusEnum.STATUS_NORMAL.getType());
|
|
|
+// } else {
|
|
|
+// camp.setStatus(CampStatusEnum.STATUS_CLOSE.getType());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
}
|
|
|
|