提交 65ea4a83 authored 作者: 吴德鹏's avatar 吴德鹏

优化

上级 c14cc3db
......@@ -89,7 +89,9 @@ public class BonusController extends Controller {
nativeQuery.setParameter("year", year);
List<Bonus> bonuses = repository.findAllByUser_IdAndCreateDateMonthAndCreateDateYear(byId.get(), month, year, PageRequest.of(pageNo, pageSize)).toList();
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("total", BigDecimal.valueOf((double) nativeQuery.getSingleResult()).setScale(3, RoundingMode.HALF_UP));
Double singleResult = (Double) nativeQuery.getSingleResult();
BigDecimal totalBonus = BigDecimal.valueOf(singleResult);
hashMap.put("total", totalBonus.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : totalBonus.setScale(3, BigDecimal.ROUND_DOWN));
hashMap.put("list", bonuses);
return hashMap;
}
......@@ -123,7 +125,9 @@ public class BonusController extends Controller {
nativeQuery.setParameter("year", year);
List<Bonus> bonuses = repository.findAllByUser_IdAndCreateDateMonthAndCreateDateYear(byId.get(), month, year, PageRequest.of(pageNo, pageSize)).toList();
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("total", BigDecimal.valueOf((double) nativeQuery.getSingleResult()).setScale(3, RoundingMode.HALF_UP));
Double singleResult = (Double) nativeQuery.getSingleResult();
BigDecimal totalBonus = BigDecimal.valueOf(singleResult);
hashMap.put("total", totalBonus.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : totalBonus.setScale(3, BigDecimal.ROUND_DOWN));
hashMap.put("list", bonuses);
return hashMap;
}
......@@ -151,7 +155,9 @@ public class BonusController extends Controller {
nativeQuery.setParameter("year", year);
List<Bonus> bonuses = repository.findAllByUser_IdAndCreateDate(byId.get(), dayOfYear, year, PageRequest.of(pageNo, pageSize)).toList();
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("total", BigDecimal.valueOf((double) nativeQuery.getSingleResult()).setScale(3, RoundingMode.HALF_UP));
Double singleResult = (Double) nativeQuery.getSingleResult();
BigDecimal totalBonus = BigDecimal.valueOf(singleResult);
hashMap.put("total", totalBonus.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : totalBonus.setScale(3, BigDecimal.ROUND_DOWN));
hashMap.put("list", bonuses);
return hashMap;
}
......
......@@ -81,7 +81,7 @@ public class FlutterWaveController extends Controller {
public ResponseEntity<String> payForOrderByCard(@RequestParam("orderId") String orderId, @RequestBody FlutterWaveCard flutterWaveCard) {
RaveConstant.PUBLIC_KEY = PUBLIC_KEY;
RaveConstant.SECRET_KEY = SECRET_KEY;
RaveConstant.ENVIRONMENT = Environment.LIVE; //or live
RaveConstant.ENVIRONMENT = Environment.STAGING; //or live
// Result result = new Result();
Optional<TbCfOrder> byId = repository.findById(orderId);
......@@ -135,7 +135,7 @@ public class FlutterWaveController extends Controller {
public ResponseEntity<String> payForOrderByPhone(@RequestParam("orderId") String orderId, @RequestBody FlutterWaveCard flutterWaveCard) {
RaveConstant.PUBLIC_KEY = PUBLIC_KEY;
RaveConstant.SECRET_KEY = SECRET_KEY;
RaveConstant.ENVIRONMENT = Environment.LIVE; //or live
RaveConstant.ENVIRONMENT = Environment.STAGING; //or live
// Result result = new Result();
Optional<TbCfOrder> byId = repository.findById(orderId);
......
......@@ -45,7 +45,7 @@ public class Bonus extends Model {
private boolean status = false;
@Column(columnDefinition = "is_withdraw",name = "is_withdraw")
@Column(columnDefinition = "is_withdraw", name = "is_withdraw")
public boolean withdraw = false;
@Transient
......@@ -89,28 +89,27 @@ public class Bonus extends Model {
}
public BigDecimal getAmount() {
return amount == null ? BigDecimal.ZERO : amount.setScale(3,RoundingMode.HALF_UP);
return (amount == null || amount.compareTo(BigDecimal.ZERO) == 0) ? BigDecimal.ZERO : amount.setScale(3, BigDecimal.ROUND_DOWN);
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
private void withDrawChange(){
private void withDrawChange() {
this.withdraw = true;
}
public void reverseAmount(){
public void reverseAmount() {
this.withDrawChange();
amount = getAmount().multiply(BigDecimal.valueOf(-1));
}
public String getUserId(){
public String getUserId() {
return userInfo == null ? null : userInfo.getUserId();
}
public void setPercentage(double percentage) {
this.percentage = percentage;
}
......@@ -124,7 +123,7 @@ public class Bonus extends Model {
this.userInfo = userInfo;
}
public Optional<String> userId(){
public Optional<String> userId() {
return userInfo == null ? Optional.empty() : Optional.ofNullable(userInfo.getUserId());
}
......@@ -136,7 +135,7 @@ public class Bonus extends Model {
this.stationItem = stationItem;
}
public Date getDate(){
public Date getDate() {
return createDate;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论