From 77f01cabdcdecc703922149641688c98e523fd2c Mon Sep 17 00:00:00 2001 From: yijiegong Date: Fri, 30 Aug 2024 11:49:42 +0800 Subject: [PATCH] =?UTF-8?q?userId=20=20=E4=B8=BAnull=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/shopimpl/TbShopUserServiceImpl.java | 61 +++++++++---------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopUserServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopUserServiceImpl.java index a4818d52..e32b223b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopUserServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopUserServiceImpl.java @@ -72,15 +72,16 @@ public class TbShopUserServiceImpl implements TbShopUserService { shopUserInfoVo.setTelephone(tbShopUser.getTelephone()); shopUserInfoVo.setTotalScore(0); }); - - if (shopUserInfoVo.getUserId() == null) { - shopUserInfoVo.setUserId(0); - } } - Integer orderNumber=tbOrderInfoRepository.countByUserIdAndStatusAndShopId(shopUserInfoVo.getUserId().toString(),criteria.getShopId()); - shopUserInfoVo.setOrderNumber(Objects.isNull(orderNumber)?0:orderNumber); - shopUserInfoVo.setInMoney(tbShopUserRepository.sumAmount(shopUserInfoVo.getId())); + if (shopUserInfoVo.getUserId() == null) { + shopUserInfoVo.setUserId(0); + shopUserInfoVo.setOrderNumber(0); + } else { + Integer orderNumber = tbOrderInfoRepository.countByUserIdAndStatusAndShopId(shopUserInfoVo.getUserId().toString(), criteria.getShopId()); + shopUserInfoVo.setOrderNumber(Objects.isNull(orderNumber) ? 0 : orderNumber); + } + shopUserInfoVo.setInMoney(tbShopUserRepository.sumAmount(shopUserInfoVo.getId())); } return PageUtil.toPlusPage(iPage.getRecords(), Integer.valueOf(iPage.getTotal() + "")); @@ -198,51 +199,49 @@ public class TbShopUserServiceImpl implements TbShopUserService { @Override public void modfiyAccount(Map map) { - if(ObjectUtil.isNull(map)||ObjectUtil.isEmpty(map)||!map.containsKey("id")||!map.containsKey("type")||!map.containsKey("amount") - ||ObjectUtil.isEmpty(map.get("id"))||ObjectUtil.isNull(map.get("id"))||ObjectUtil.isNull(map.get("type"))||ObjectUtil.isEmpty(map.get("type")) - ||ObjectUtil.isEmpty(map.get("amount"))||ObjectUtil.isNull(map.get("amount"))||!map.containsKey("operationType")||ObjectUtil.isEmpty(map.get("operationType"))||ObjectUtil.isNull(map.get("operationType")) + if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map) || !map.containsKey("id") || !map.containsKey("type") || !map.containsKey("amount") + || ObjectUtil.isEmpty(map.get("id")) || ObjectUtil.isNull(map.get("id")) || ObjectUtil.isNull(map.get("type")) || ObjectUtil.isEmpty(map.get("type")) + || ObjectUtil.isEmpty(map.get("amount")) || ObjectUtil.isNull(map.get("amount")) || !map.containsKey("operationType") || ObjectUtil.isEmpty(map.get("operationType")) || ObjectUtil.isNull(map.get("operationType")) - ){ + ) { throw new BadRequestException("参数错误"); } String regex = "^(([1-9][0-9]*)|(([0]\\.\\d{1,2}|[1-9][0-9]*\\.\\d{1,2})))$"; - if(!map.get("amount").toString().matches(regex)){ + if (!map.get("amount").toString().matches(regex)) { throw new BadRequestException("请输入正确的数字"); } - - TbShopUser tbShopUser= tbShopUserRepository.getById(Integer.valueOf(map.get("id")+"")); - if(ObjectUtil.isNull(tbShopUser)){ - throw new BadRequestException("不存在的会员信息"); + TbShopUser tbShopUser = tbShopUserRepository.getById(Integer.valueOf(map.get("id") + "")); + if (ObjectUtil.isNull(tbShopUser)) { + throw new BadRequestException("不存在的会员信息"); } - String operationType=map.get("operationType").toString(); + String operationType = map.get("operationType").toString(); - BigDecimal amount=new BigDecimal(map.get("amount").toString()); - if("out".equals(operationType)){ - if(amount.compareTo(tbShopUser.getAmount())>0){ + BigDecimal amount = new BigDecimal(map.get("amount").toString()); + if ("out".equals(operationType)) { + if (amount.compareTo(tbShopUser.getAmount()) > 0) { throw new BadRequestException("账户余额不足,请输入正确的金额"); } } + String type = map.get("type").toString(); + TbShopUserFlow flow = new TbShopUserFlow(); - String type=map.get("type").toString(); - TbShopUserFlow flow=new TbShopUserFlow(); - - if("in".equals(operationType)){ + if ("in".equals(operationType)) { flow.setType("+"); - flow.setBizName("inMoney".equals(type)?"充值":"消费退款"); - flow.setBizCode("inMoney".equals(type)?"inMoneyIn":"consumeIn"); + flow.setBizName("inMoney".equals(type) ? "充值" : "消费退款"); + flow.setBizCode("inMoney".equals(type) ? "inMoneyIn" : "consumeIn"); tbShopUser.setAmount(tbShopUser.getAmount().add(amount)); - }else if("out".equals(operationType)){ - flow.setBizName("inMoneyOut".equals(type)?"充值退款":"消费"); - flow.setBizCode("inMoneyOut".equals(type)?"inMoneyOut":"consumeOut"); + } else if ("out".equals(operationType)) { + flow.setBizName("inMoneyOut".equals(type) ? "充值退款" : "消费"); + flow.setBizCode("inMoneyOut".equals(type) ? "inMoneyOut" : "consumeOut"); flow.setType("-"); tbShopUser.setAmount(tbShopUser.getAmount().subtract(amount)); - }else { + } else { throw new BadRequestException("错误的请求类型"); } @@ -258,8 +257,6 @@ public class TbShopUserServiceImpl implements TbShopUserService { tbShopUserFlowMapper.insert(flow); - - } }