|
|
@@ -22,7 +22,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.swing.plaf.ProgressBarUI;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.Date;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -46,7 +48,11 @@ public class ComCntToSnbServiceImpl extends CommonServiceImpl<ComCntToSnbVo, Com
|
|
|
*/
|
|
|
@Override
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
@@ -59,8 +65,11 @@ public class ComCntToSnbServiceImpl extends CommonServiceImpl<ComCntToSnbVo, Com
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
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)) {
|
|
|
return Result.of(null, false, "非法领取");
|
|
|
}
|
|
|
@@ -93,9 +102,8 @@ public class ComCntToSnbServiceImpl extends CommonServiceImpl<ComCntToSnbVo, Com
|
|
|
if (!redisLock.lock(redisKey, String.valueOf(time))) {
|
|
|
return Result.of(null, false, ResultEnum.SEED_SALE_SAVE_LOCK.getMessage(), ResultEnum.SEED_SALE_SAVE_LOCK.getCode());
|
|
|
}
|
|
|
- //单次领取数量
|
|
|
- BigDecimal div = NumberUtil.div(comCntToSnb.getTotalQuantity(), comCntToSnb.getTotalDay());
|
|
|
- BigDecimal receiveNum = NumberUtil.round(div, 2);
|
|
|
+ // 单次领取数量
|
|
|
+ BigDecimal receiveNum = NumberUtil.round(NumberUtil.div(comCntToSnb.getTotalQuantity(), comCntToSnb.getTotalDay()), 2, RoundingMode.DOWN);
|
|
|
log.info("每天领取数量:" + receiveNum);
|
|
|
// 本次领取量
|
|
|
BigDecimal thisReceiveQuantity;
|
|
|
@@ -116,7 +124,6 @@ public class ComCntToSnbServiceImpl extends CommonServiceImpl<ComCntToSnbVo, Com
|
|
|
comCntToSnbRespository.save(comCntToSnb);
|
|
|
|
|
|
// 更新comUsers snb+
|
|
|
- ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
|
|
|
comUsersVo.setSnbPart(comUsersVo.getSnbPart() + Convert.toDouble(thisReceiveQuantity));
|
|
|
comUsersService.save(comUsersVo);
|
|
|
|