cn.hutool.core.util.NumberUtil Java Examples
The following examples show how to use
cn.hutool.core.util.NumberUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MerchantOrderService.java From runscore with Apache License 2.0 | 6 votes |
/** * 客服取消订单退款 * * @param orderId */ @Transactional public void customerServiceCancelOrderRefund(@NotBlank String orderId) { MerchantOrder merchantOrder = merchantOrderRepo.getOne(orderId); if (!(Constant.商户订单状态_申诉中.equals(merchantOrder.getOrderState()))) { throw new BizException(BizError.只有申诉中的商户订单才能取消订单退款); } UserAccount userAccount = merchantOrder.getReceivedAccount(); Double cashDeposit = NumberUtil.round(userAccount.getCashDeposit() + merchantOrder.getGatheringAmount(), 4) .doubleValue(); userAccount.setCashDeposit(cashDeposit); userAccountRepo.save(userAccount); merchantOrder.customerCancelOrderRefund(); merchantOrderRepo.save(merchantOrder); accountChangeLogRepo.save(AccountChangeLog.buildWithCustomerCancelOrderRefund(userAccount, merchantOrder)); }
Example #2
Source File: HutoolController.java From mall-learning with Apache License 2.0 | 6 votes |
@ApiOperation("NumberUtil使用:数字处理工具类") @GetMapping("/numberUtil") public CommonResult numberUtil() { double n1 = 1.234; double n2 = 1.234; double result; //对float、double、BigDecimal做加减乘除操作 result = NumberUtil.add(n1, n2); result = NumberUtil.sub(n1, n2); result = NumberUtil.mul(n1, n2); result = NumberUtil.div(n1, n2); //保留两位小数 BigDecimal roundNum = NumberUtil.round(n1, 2); String n3 = "1.234"; //判断是否为数字、整数、浮点数 NumberUtil.isNumber(n3); NumberUtil.isInteger(n3); NumberUtil.isDouble(n3); return CommonResult.success(null, "操作成功"); }
Example #3
Source File: SystemHardwareInfo.java From Guns with GNU Lesser General Public License v3.0 | 6 votes |
/** * 设置磁盘信息 */ private void setSysFiles(OperatingSystem os) { FileSystem fileSystem = os.getFileSystem(); OSFileStore[] fsArray = fileSystem.getFileStores(); for (OSFileStore fs : fsArray) { long free = fs.getUsableSpace(); long total = fs.getTotalSpace(); long used = total - free; SysFileInfo sysFile = new SysFileInfo(); sysFile.setDirName(fs.getMount()); sysFile.setSysTypeName(fs.getType()); sysFile.setTypeName(fs.getName()); sysFile.setTotal(convertFileSize(total)); sysFile.setFree(convertFileSize(free)); sysFile.setUsed(convertFileSize(used)); if (total == 0) { sysFile.setUsage(0); } else { sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100)); } sysFiles.add(sysFile); } }
Example #4
Source File: WithdrawService.java From runscore with Apache License 2.0 | 6 votes |
@ParamValid @Transactional public void startWithdraw(StartWithdrawParam param) { UserAccount userAccount = userAccountRepo.getOne(param.getUserAccountId()); if (!new BCryptPasswordEncoder().matches(param.getMoneyPwd(), userAccount.getMoneyPwd())) { throw new BizException(BizError.资金密码不正确); } double cashDeposit = NumberUtil.round(userAccount.getCashDeposit() - param.getWithdrawAmount(), 4) .doubleValue(); if (cashDeposit < 0) { throw new BizException(BizError.保证金余额不足); } if (userAccount.getBankInfoLatelyModifyTime() == null) { throw new BizException(BizError.银行卡未绑定无法进行提现); } WithdrawRecord withdrawRecord = param.convertToPo(); withdrawRecord.setBankInfo(userAccount); withdrawRecordRepo.save(withdrawRecord); userAccount.setCashDeposit(cashDeposit); userAccountRepo.save(userAccount); accountChangeLogRepo.save(AccountChangeLog.buildWithStartWithdraw(userAccount, withdrawRecord)); }
Example #5
Source File: WithdrawService.java From runscore with Apache License 2.0 | 6 votes |
/** * 审核不通过 * * @param id */ @ParamValid @Transactional public void notApproved(@NotBlank String id, String note) { WithdrawRecord withdrawRecord = withdrawRecordRepo.getOne(id); if (!(Constant.提现记录状态_发起提现.equals(withdrawRecord.getState()) || Constant.提现记录状态_审核通过.equals(withdrawRecord.getState()))) { throw new BizException(BizError.只有状态为发起提现或审核通过的记录才能进行审核不通过操作); } withdrawRecord.notApproved(note); withdrawRecordRepo.save(withdrawRecord); UserAccount userAccount = withdrawRecord.getUserAccount(); double cashDeposit = NumberUtil.round(userAccount.getCashDeposit() + withdrawRecord.getWithdrawAmount(), 4) .doubleValue(); userAccount.setCashDeposit(cashDeposit); userAccountRepo.save(userAccount); accountChangeLogRepo.save(AccountChangeLog.buildWithWithdrawNotApprovedRefund(userAccount, withdrawRecord)); }
Example #6
Source File: RechargeService.java From runscore with Apache License 2.0 | 6 votes |
/** * 充值订单结算 */ @Transactional public void rechargeOrderSettlement(String orderNo) { RechargeOrder rechargeOrder = rechargeOrderRepo.findByOrderNo(orderNo); if (rechargeOrder == null) { throw new BizException(BizError.充值订单不存在); } if (!Constant.充值订单状态_已支付.equals(rechargeOrder.getOrderState())) { return; } rechargeOrder.settlement(); rechargeOrderRepo.save(rechargeOrder); UserAccount userAccount = rechargeOrder.getUserAccount(); double cashDeposit = userAccount.getCashDeposit() + rechargeOrder.getActualPayAmount(); userAccount.setCashDeposit(NumberUtil.round(cashDeposit, 4).doubleValue()); userAccountRepo.save(userAccount); accountChangeLogRepo.save(AccountChangeLog.buildWithRecharge(userAccount, rechargeOrder)); updateCashDepositWithRechargePreferential(userAccount, rechargeOrder.getActualPayAmount()); }
Example #7
Source File: MerchantOrderService.java From runscore with Apache License 2.0 | 6 votes |
/** * 订单返点结算 */ @Transactional public void orderRebateSettlement(@NotBlank String orderRebateId) { OrderRebate orderRebate = orderRebateRepo.getOne(orderRebateId); if (orderRebate.getSettlementTime() != null) { log.warn("当前的订单返点记录已结算,无法重复结算;id:{}", orderRebateId); return; } orderRebate.settlement(); orderRebateRepo.save(orderRebate); UserAccount userAccount = orderRebate.getRebateAccount(); double cashDeposit = userAccount.getCashDeposit() + orderRebate.getRebateAmount(); userAccount.setCashDeposit(NumberUtil.round(cashDeposit, 4).doubleValue()); userAccountRepo.save(userAccount); accountChangeLogRepo.save(AccountChangeLog.buildWithOrderRebate(userAccount, orderRebate)); }
Example #8
Source File: MerchantOrderService.java From runscore with Apache License 2.0 | 6 votes |
/** * 生成订单返点 * * @param bettingOrder */ public void generateOrderRebate(MerchantOrder merchantOrder) { UserAccount userAccount = merchantOrder.getReceivedAccount(); UserAccount superior = merchantOrder.getReceivedAccount().getInviter(); while (superior != null) { double rebate = NumberUtil.round(superior.getRebate() - userAccount.getRebate(), 4).doubleValue(); if (rebate < 0) { log.error("订单返点异常,下级账号的返点不能大于上级账号;下级账号id:{},上级账号id:{}", userAccount.getId(), superior.getId()); break; } double rebateAmount = NumberUtil.round(merchantOrder.getGatheringAmount() * rebate * 0.01, 4).doubleValue(); OrderRebate orderRebate = OrderRebate.build(rebate, rebateAmount, merchantOrder.getId(), superior.getId()); orderRebateRepo.save(orderRebate); userAccount = superior; superior = superior.getInviter(); } }
Example #9
Source File: MerchantOrderService.java From runscore with Apache License 2.0 | 6 votes |
/** * 接单奖励金结算 */ @Transactional public void receiveOrderBountySettlement(MerchantOrder merchantOrder) { UserAccount userAccount = merchantOrder.getReceivedAccount(); double bounty = NumberUtil.round(merchantOrder.getGatheringAmount() * userAccount.getRebate() * 0.01, 4) .doubleValue(); merchantOrder.updateBounty(bounty); merchantOrderRepo.save(merchantOrder); userAccount.setCashDeposit(NumberUtil.round(userAccount.getCashDeposit() + bounty, 4).doubleValue()); userAccountRepo.save(userAccount); accountChangeLogRepo .save(AccountChangeLog.buildWithReceiveOrderBounty(userAccount, bounty, userAccount.getRebate())); generateOrderRebate(merchantOrder); ThreadPoolUtils.getPaidMerchantOrderPool().schedule(() -> { redisTemplate.opsForList().leftPush(Constant.商户订单ID, merchantOrder.getId()); }, 1, TimeUnit.SECONDS); }
Example #10
Source File: Server.java From spring-boot-demo with MIT License | 6 votes |
/** * 设置磁盘信息 */ private void setSysFiles(OperatingSystem os) { FileSystem fileSystem = os.getFileSystem(); OSFileStore[] fsArray = fileSystem.getFileStores(); for (OSFileStore fs : fsArray) { long free = fs.getUsableSpace(); long total = fs.getTotalSpace(); long used = total - free; SysFile sysFile = new SysFile(); sysFile.setDirName(fs.getMount()); sysFile.setSysTypeName(fs.getType()); sysFile.setTypeName(fs.getName()); sysFile.setTotal(convertFileSize(total)); sysFile.setFree(convertFileSize(free)); sysFile.setUsed(convertFileSize(used)); sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100)); sysFiles.add(sysFile); } }
Example #11
Source File: Server.java From spring-boot-demo with MIT License | 6 votes |
/** * 设置磁盘信息 */ private void setSysFiles(OperatingSystem os) { FileSystem fileSystem = os.getFileSystem(); OSFileStore[] fsArray = fileSystem.getFileStores(); for (OSFileStore fs : fsArray) { long free = fs.getUsableSpace(); long total = fs.getTotalSpace(); long used = total - free; SysFile sysFile = new SysFile(); sysFile.setDirName(fs.getMount()); sysFile.setSysTypeName(fs.getType()); sysFile.setTypeName(fs.getName()); sysFile.setTotal(convertFileSize(total)); sysFile.setFree(convertFileSize(free)); sysFile.setUsed(convertFileSize(used)); sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100)); sysFiles.add(sysFile); } }
Example #12
Source File: AccountChangeLog.java From runscore with Apache License 2.0 | 5 votes |
/** * 构建退还保证金账变日志 * * @param userAccount * @param withdrawRecord * @return */ public static AccountChangeLog buildWithRefundCashDeposit(UserAccount userAccount, MerchantOrder merchantOrder) { AccountChangeLog log = new AccountChangeLog(); log.setId(IdUtils.getId()); log.setOrderNo(merchantOrder.getOrderNo()); log.setAccountChangeTime(merchantOrder.getDealTime()); log.setAccountChangeTypeCode(Constant.账变日志类型_退还保证金); log.setAccountChangeAmount(NumberUtil.round(merchantOrder.getGatheringAmount(), 4).doubleValue()); log.setCashDeposit(userAccount.getCashDeposit()); log.setUserAccountId(userAccount.getId()); return log; }
Example #13
Source File: AppealService.java From runscore with Apache License 2.0 | 5 votes |
@Transactional public void alterToActualPayAmount(@NotBlank String appealId) { Appeal appeal = appealRepo.findById(appealId).orElse(null); if (appeal == null) { throw new BizException(BizError.参数异常); } if (!Constant.申诉状态_待处理.equals(appeal.getState())) { throw new BizException(BizError.当前申诉已完结无法更改处理方式); } if (!Constant.申诉类型_实际支付金额小于收款金额.equals(appeal.getAppealType())) { throw new BizException(BizError.该申诉类型的处理方式不能是改为实际支付金额); } appeal.alterToActualPayAmount(); appealRepo.save(appeal); MerchantOrder merchantOrder = appeal.getMerchantOrder(); UserAccount userAccount = merchantOrder.getReceivedAccount(); Double refundAmount = merchantOrder.getGatheringAmount() - appeal.getActualPayAmount(); Double cashDeposit = NumberUtil.round(userAccount.getCashDeposit() + refundAmount, 4).doubleValue(); userAccount.setCashDeposit(cashDeposit); userAccountRepo.save(userAccount); merchantOrder.setGatheringAmount(appeal.getActualPayAmount()); merchantOrderRepo.save(merchantOrder); accountChangeLogRepo.save(AccountChangeLog.buildWithAlterToActualPayAmountRefund(userAccount, merchantOrder.getOrderNo(), refundAmount)); merchantOrderService.customerServiceConfirmToPaid(merchantOrder.getId(), "客服改单为实际支付金额并确认已支付"); }
Example #14
Source File: AccountChangeLog.java From runscore with Apache License 2.0 | 5 votes |
/** * 构建充值优惠账变日志 * * @param userAccount * @param returnWater * @param returnWaterRate * @return */ public static AccountChangeLog buildWithRechargePreferential(UserAccount userAccount, Double returnWater, Double returnWaterRate) { AccountChangeLog log = new AccountChangeLog(); log.setId(IdUtils.getId()); log.setOrderNo(log.getId()); log.setAccountChangeTime(new Date()); log.setAccountChangeTypeCode(Constant.账变日志类型_充值优惠); log.setAccountChangeAmount(NumberUtil.round(returnWater, 4).doubleValue()); log.setNote(MessageFormat.format("充值返水率:{0}%", returnWaterRate)); log.setCashDeposit(userAccount.getCashDeposit()); log.setUserAccountId(userAccount.getId()); return log; }
Example #15
Source File: AccountChangeLog.java From runscore with Apache License 2.0 | 5 votes |
/** * 构建接单奖励金账变日志 * * @param userAccount * @param bounty * @param rebate * @return */ public static AccountChangeLog buildWithReceiveOrderBounty(UserAccount userAccount, Double bounty, Double rebate) { AccountChangeLog log = new AccountChangeLog(); log.setId(IdUtils.getId()); log.setOrderNo(log.getId()); log.setAccountChangeTime(new Date()); log.setAccountChangeTypeCode(Constant.账变日志类型_接单奖励金); log.setAccountChangeAmount(NumberUtil.round(bounty, 4).doubleValue()); log.setNote(MessageFormat.format("接单返点:{0}%", rebate)); log.setCashDeposit(userAccount.getCashDeposit()); log.setUserAccountId(userAccount.getId()); return log; }
Example #16
Source File: AccountChangeLog.java From runscore with Apache License 2.0 | 5 votes |
/** * 构建充值账变日志 * * @param userAccount * @param bettingOrder * @return */ public static AccountChangeLog buildWithRecharge(UserAccount userAccount, RechargeOrder rechargeOrder) { AccountChangeLog log = new AccountChangeLog(); log.setId(IdUtils.getId()); log.setOrderNo(rechargeOrder.getOrderNo()); log.setAccountChangeTime(rechargeOrder.getSettlementTime()); log.setAccountChangeTypeCode(Constant.账变日志类型_账号充值); log.setAccountChangeAmount(NumberUtil.round(rechargeOrder.getActualPayAmount(), 4).doubleValue()); log.setCashDeposit(userAccount.getCashDeposit()); log.setUserAccountId(userAccount.getId()); return log; }
Example #17
Source File: StatisticalAnalysisService.java From runscore with Apache License 2.0 | 5 votes |
@Transactional(readOnly = true) public Double findTotalCashDeposit() { TotalCashDeposit totalCashDeposit = totalCashDepositRepo.findTopBy(); if(totalCashDeposit == null){ return 0.0; } return NumberUtil.round(totalCashDeposit.getTotalCashDeposit(), 4).doubleValue(); }
Example #18
Source File: AccountChangeLog.java From runscore with Apache License 2.0 | 5 votes |
public static AccountChangeLog buildWithAlterToActualPayAmountRefund(UserAccount userAccount, String orderNo, Double refundAmount) { AccountChangeLog log = new AccountChangeLog(); log.setId(IdUtils.getId()); log.setOrderNo(orderNo); log.setAccountChangeTime(new Date()); log.setAccountChangeTypeCode(Constant.账变日志类型_改单为实际支付金额并退款); log.setAccountChangeAmount(NumberUtil.round(refundAmount, 4).doubleValue()); log.setCashDeposit(userAccount.getCashDeposit()); log.setUserAccountId(userAccount.getId()); return log; }
Example #19
Source File: YxUserServiceImpl.java From yshopmall with Apache License 2.0 | 5 votes |
@Override @Transactional(rollbackFor = Exception.class) public void updateMoney(UserMoneyDto param) { YxUserDto userDTO = generator.convert(getById(param.getUid()),YxUserDto.class); Double newMoney = 0d; String mark = ""; String type = "system_add"; Integer pm = 1; String title = "系统增加余额"; if(param.getPtype() == 1){ mark = "系统增加了"+param.getMoney()+"余额"; newMoney = NumberUtil.add(userDTO.getNowMoney(),param.getMoney()).doubleValue(); }else{ title = "系统减少余额"; mark = "系统扣除了"+param.getMoney()+"余额"; type = "system_sub"; pm = 0; newMoney = NumberUtil.sub(userDTO.getNowMoney(),param.getMoney()).doubleValue(); if(newMoney < 0) newMoney = 0d; } YxUser user = new YxUser(); user.setUid(userDTO.getUid()); user.setNowMoney(BigDecimal.valueOf(newMoney)); saveOrUpdate(user); YxUserBill userBill = new YxUserBill(); userBill.setUid(userDTO.getUid()); userBill.setLinkId("0"); userBill.setPm(pm); userBill.setTitle(title); userBill.setCategory("now_money"); userBill.setType(type); userBill.setNumber(BigDecimal.valueOf(param.getMoney())); userBill.setBalance(BigDecimal.valueOf(newMoney)); userBill.setMark(mark); userBill.setAddTime(OrderUtil.getSecondTimestampTwo()); userBill.setStatus(1); yxUserBillService.save(userBill); }
Example #20
Source File: Jvm.java From spring-boot-demo with MIT License | 4 votes |
public double getUsage() { return NumberUtil.mul(NumberUtil.div(total - free, total, 4), 100); }
Example #21
Source File: CpuInfo.java From Guns with GNU Lesser General Public License v3.0 | 4 votes |
public double getWait() { return NumberUtil.round(NumberUtil.mul(wait / total, 100), 2).doubleValue(); }
Example #22
Source File: Jvm.java From spring-boot-demo with MIT License | 4 votes |
public double getFree() { return NumberUtil.div(free, (1024 * 1024), 2); }
Example #23
Source File: Jvm.java From spring-boot-demo with MIT License | 4 votes |
public double getUsed() { return NumberUtil.div(total - free, (1024 * 1024), 2); }
Example #24
Source File: JvmInfo.java From Guns with GNU Lesser General Public License v3.0 | 4 votes |
public double getMax() { return NumberUtil.div(max, (1024 * 1024), 2); }
Example #25
Source File: Cpu.java From spring-boot-demo with MIT License | 4 votes |
public double getTotal() { return NumberUtil.round(NumberUtil.mul(total, 100), 2) .doubleValue(); }
Example #26
Source File: Cpu.java From spring-boot-demo with MIT License | 4 votes |
public double getSys() { return NumberUtil.round(NumberUtil.mul(sys / total, 100), 2) .doubleValue(); }
Example #27
Source File: JvmInfo.java From Guns with GNU Lesser General Public License v3.0 | 4 votes |
public double getFree() { return NumberUtil.div(free, (1024 * 1024), 2); }
Example #28
Source File: Cpu.java From spring-boot-demo with MIT License | 4 votes |
public double getWait() { return NumberUtil.round(NumberUtil.mul(wait / total, 100), 2) .doubleValue(); }
Example #29
Source File: Cpu.java From spring-boot-demo with MIT License | 4 votes |
public double getFree() { return NumberUtil.round(NumberUtil.mul(free / total, 100), 2) .doubleValue(); }
Example #30
Source File: Jvm.java From spring-boot-demo with MIT License | 4 votes |
public double getTotal() { return NumberUtil.div(total, (1024 * 1024), 2); }