|
@@ -22,7 +22,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import javax.swing.plaf.ProgressBarUI;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -46,7 +48,11 @@ public class ComCntToSnbServiceImpl extends CommonServiceImpl<ComCntToSnbVo, Com
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public ComCntToSnbVo findByUserId(String userId) {
|
|
public ComCntToSnbVo findByUserId(String userId) {
|
|
|
- ComCntToSnb comCntToSnb = comCntToSnbRespository.findByUserId(userId).orElse(null);
|
|
|
|
|
|
|
+ ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
|
|
|
|
|
+ if (comUsersVo == null || StrUtil.isBlank(comUsersVo.getAddress())) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ ComCntToSnb comCntToSnb = comCntToSnbRespository.findByAddress(comUsersVo.getAddress());
|
|
|
return comCntToSnb == null ? null : CopyUtil.copy(comCntToSnb, ComCntToSnbVo.class);
|
|
return comCntToSnb == null ? null : CopyUtil.copy(comCntToSnb, ComCntToSnbVo.class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -59,14 +65,20 @@ public class ComCntToSnbServiceImpl extends CommonServiceImpl<ComCntToSnbVo, Com
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Result<String> receiveByUserId(String userId) {
|
|
public Result<String> receiveByUserId(String userId) {
|
|
|
-
|
|
|
|
|
- ComCntToSnb comCntToSnb = comCntToSnbRespository.findByUserId(userId).orElse(null);
|
|
|
|
|
|
|
+ ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
|
|
|
|
|
+ if (comUsersVo == null || StrUtil.isBlank(comUsersVo.getAddress())) {
|
|
|
|
|
+ return Result.of(null, false, "未找到用户或钱包地址");
|
|
|
|
|
+ }
|
|
|
|
|
+ ComCntToSnb comCntToSnb = comCntToSnbRespository.findByAddress(comUsersVo.getAddress());
|
|
|
if (comCntToSnb == null || comCntToSnb.getStatus().equals(0)) {
|
|
if (comCntToSnb == null || comCntToSnb.getStatus().equals(0)) {
|
|
|
return Result.of(null, false, "非法领取");
|
|
return Result.of(null, false, "非法领取");
|
|
|
}
|
|
}
|
|
|
if (comCntToSnb.getReceivedDay() >= comCntToSnb.getTotalDay()) {
|
|
if (comCntToSnb.getReceivedDay() >= comCntToSnb.getTotalDay()) {
|
|
|
return Result.of(null, false, "已全部领取完毕");
|
|
return Result.of(null, false, "已全部领取完毕");
|
|
|
}
|
|
}
|
|
|
|
|
+ if (comCntToSnb.getBeginTime() == null) {
|
|
|
|
|
+ return Result.of(null, false, "未设置领取开始时间");
|
|
|
|
|
+ }
|
|
|
// 服务器时间
|
|
// 服务器时间
|
|
|
Date serverDate = new Date();
|
|
Date serverDate = new Date();
|
|
|
// 未到领取时间
|
|
// 未到领取时间
|
|
@@ -82,11 +94,6 @@ public class ComCntToSnbServiceImpl extends CommonServiceImpl<ComCntToSnbVo, Com
|
|
|
if (day <= 0) {
|
|
if (day <= 0) {
|
|
|
return Result.of(null, false, "领取失败,今日已领取");
|
|
return Result.of(null, false, "领取失败,今日已领取");
|
|
|
}
|
|
}
|
|
|
- // 特例:领取周期100天,这个人间隔100以后上线
|
|
|
|
|
- if (day > comCntToSnb.getTotalDay() - comCntToSnb.getReceivedDay()) {
|
|
|
|
|
- day = comCntToSnb.getTotalDay() - comCntToSnb.getReceivedDay();
|
|
|
|
|
- log.info("由于本次领取天数大于剩余领取天数,所以最终领取天数:" + day);
|
|
|
|
|
- }
|
|
|
|
|
long time = System.currentTimeMillis() + RedisData.getSnbTimeout();
|
|
long time = System.currentTimeMillis() + RedisData.getSnbTimeout();
|
|
|
String redisKey = StrUtil.format("SNB_SAVE_{}", userId);
|
|
String redisKey = StrUtil.format("SNB_SAVE_{}", userId);
|
|
|
|
|
|
|
@@ -95,9 +102,21 @@ public class ComCntToSnbServiceImpl extends CommonServiceImpl<ComCntToSnbVo, Com
|
|
|
if (!redisLock.lock(redisKey, String.valueOf(time))) {
|
|
if (!redisLock.lock(redisKey, String.valueOf(time))) {
|
|
|
return Result.of(null, false, ResultEnum.SEED_SALE_SAVE_LOCK.getMessage(), ResultEnum.SEED_SALE_SAVE_LOCK.getCode());
|
|
return Result.of(null, false, ResultEnum.SEED_SALE_SAVE_LOCK.getMessage(), ResultEnum.SEED_SALE_SAVE_LOCK.getCode());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ // 单次领取数量
|
|
|
|
|
+ BigDecimal receiveNum = NumberUtil.round(NumberUtil.div(comCntToSnb.getTotalQuantity(), comCntToSnb.getTotalDay()), 2, RoundingMode.DOWN);
|
|
|
|
|
+ log.info("每天领取数量:" + receiveNum);
|
|
|
// 本次领取量
|
|
// 本次领取量
|
|
|
- BigDecimal thisReceiveQuantity = NumberUtil.mul(comCntToSnb.getUnitQuantity(), day);
|
|
|
|
|
|
|
+ BigDecimal thisReceiveQuantity;
|
|
|
|
|
+ // 特例:领取周期100天,这个人间隔100以后上线
|
|
|
|
|
+ if (day >= comCntToSnb.getTotalDay() - comCntToSnb.getReceivedDay()) {
|
|
|
|
|
+ day = comCntToSnb.getTotalDay() - comCntToSnb.getReceivedDay();
|
|
|
|
|
+ log.info("由于本次领取天数大于剩余领取天数,所以最终领取天数:" + day);
|
|
|
|
|
+ thisReceiveQuantity = NumberUtil.sub(comCntToSnb.getTotalQuantity(), NumberUtil.mul(comCntToSnb.getReceivedDay(), receiveNum));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 本次领取量
|
|
|
|
|
+ thisReceiveQuantity = NumberUtil.mul(receiveNum, day);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
comCntToSnb.setReceivedQuantity(comCntToSnb.getReceivedQuantity().add(thisReceiveQuantity));
|
|
comCntToSnb.setReceivedQuantity(comCntToSnb.getReceivedQuantity().add(thisReceiveQuantity));
|
|
|
// 本次领取天数
|
|
// 本次领取天数
|
|
|
comCntToSnb.setReceivedDay(comCntToSnb.getReceivedDay() + day);
|
|
comCntToSnb.setReceivedDay(comCntToSnb.getReceivedDay() + day);
|
|
@@ -105,7 +124,6 @@ public class ComCntToSnbServiceImpl extends CommonServiceImpl<ComCntToSnbVo, Com
|
|
|
comCntToSnbRespository.save(comCntToSnb);
|
|
comCntToSnbRespository.save(comCntToSnb);
|
|
|
|
|
|
|
|
// 更新comUsers snb+
|
|
// 更新comUsers snb+
|
|
|
- ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
|
|
|
|
|
comUsersVo.setSnbPart(comUsersVo.getSnbPart() + Convert.toDouble(thisReceiveQuantity));
|
|
comUsersVo.setSnbPart(comUsersVo.getSnbPart() + Convert.toDouble(thisReceiveQuantity));
|
|
|
comUsersService.save(comUsersVo);
|
|
comUsersService.save(comUsersVo);
|
|
|
|
|
|