use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project waynboot-mall by wayn111.
the class DictServiceImpl method checkDictNameUnique.
@Override
public String checkDictNameUnique(Dict dict) {
long dictId = Objects.isNull(dict.getDictId()) ? -1L : dict.getDictId();
QueryWrapper<Dict> queryWrapper = new QueryWrapper<>();
if (dict.getType() == 1) {
queryWrapper.eq("name", dict.getName()).eq("type", 1);
} else {
queryWrapper.eq("name", dict.getName()).eq("type", 2).eq("parent_type", dict.getParentType());
}
Dict sysDict = getOne(queryWrapper);
if (sysDict != null && sysDict.getDictId() != dictId) {
return SysConstants.NOT_UNIQUE;
}
return SysConstants.UNIQUE;
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project waynboot-mall by wayn111.
the class MenuServiceImpl method selectCheckedkeys.
@Override
public List<Long> selectCheckedkeys(Long roleId) {
List<RoleMenu> roleMenus = iRoleMenuService.list(new QueryWrapper<RoleMenu>().eq("role_id", roleId));
List<Long> menuIds = roleMenus.stream().map(RoleMenu::getMenuId).collect(Collectors.toList());
if (!menuIds.isEmpty()) {
// 去掉菜单中的父菜单
List<Menu> menus = listByIds(menuIds);
for (Menu menu : menus) {
menuIds.remove(menu.getParentId());
}
}
return menuIds;
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project waynboot-mall by wayn111.
the class UserServiceImpl method checkEmailUnique.
@Override
public String checkEmailUnique(User user) {
long userId = Objects.nonNull(user.getUserId()) ? user.getUserId() : 0;
User info = getOne(new QueryWrapper<User>().eq("email", user.getEmail()));
if (info != null && info.getUserId() != userId) {
return SysConstants.NOT_UNIQUE;
}
return SysConstants.UNIQUE;
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project waynboot-mall by wayn111.
the class GoodsDetailServiceImpl method getGoodsDetailData.
@Override
public R getGoodsDetailData(Long goodsId) {
R success = R.success();
Callable<Object> specificationCall = () -> iGoodsSpecificationService.getSpecificationVOList(goodsId);
Callable<List<GoodsProduct>> productCall = () -> iGoodsProductService.list(new QueryWrapper<GoodsProduct>().eq("goods_id", goodsId));
Callable<List<GoodsAttribute>> attrCall = () -> iGoodsAttributeService.list(new QueryWrapper<GoodsAttribute>().eq("goods_id", goodsId));
FutureTask<Object> specificationTask = new FutureTask<>(specificationCall);
FutureTask<List<GoodsProduct>> productTask = new FutureTask<>(productCall);
FutureTask<List<GoodsAttribute>> attrTask = new FutureTask<>(attrCall);
homeThreadPoolTaskExecutor.submit(specificationTask);
homeThreadPoolTaskExecutor.submit(productTask);
homeThreadPoolTaskExecutor.submit(attrTask);
try {
success.add("info", iGoodsService.getById(goodsId));
success.add("specificationList", specificationTask.get());
success.add("productList", productTask.get());
success.add("attributes", attrTask.get());
} catch (InterruptedException | ExecutionException e) {
log.error(e.getMessage(), e);
}
return success;
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project waynboot-mall by wayn111.
the class OrderServiceImpl method asyncSubmit.
@Override
public R asyncSubmit(OrderVO orderVO) {
OrderDTO orderDTO = new OrderDTO();
MyBeanUtil.copyProperties(orderVO, orderDTO);
Long userId = orderDTO.getUserId();
// 获取用户订单商品,为空默认取购物车已选中商品
List<Long> cartIdArr = orderDTO.getCartIdArr();
List<Cart> checkedGoodsList;
if (CollectionUtils.isEmpty(cartIdArr)) {
checkedGoodsList = iCartService.list(new QueryWrapper<Cart>().eq("checked", true).eq("user_id", userId));
} else {
checkedGoodsList = iCartService.listByIds(cartIdArr);
}
List<Long> goodsIds = checkedGoodsList.stream().map(Cart::getGoodsId).collect(Collectors.toList());
List<GoodsProduct> goodsProducts = iGoodsProductService.list(new QueryWrapper<GoodsProduct>().in("goods_id", goodsIds));
Map<Long, GoodsProduct> goodsIdMap = goodsProducts.stream().collect(Collectors.toMap(GoodsProduct::getId, goodsProduct -> goodsProduct));
// 商品货品数量减少
for (Cart checkGoods : checkedGoodsList) {
Long productId = checkGoods.getProductId();
Long goodsId = checkGoods.getGoodsId();
GoodsProduct product = goodsIdMap.get(productId);
int remainNumber = product.getNumber() - checkGoods.getNumber();
if (remainNumber < 0) {
Goods goods = iGoodsService.getById(goodsId);
String goodsName = goods.getName();
String[] specifications = product.getSpecifications();
throw new BusinessException(String.format("%s,%s 库存不足", goodsName, StringUtils.join(specifications, " ")));
}
if (!iGoodsProductService.reduceStock(productId, checkGoods.getNumber())) {
throw new BusinessException("商品货品库存减少失败");
}
}
// 商品费用
BigDecimal checkedGoodsPrice = new BigDecimal("0.00");
for (Cart checkGoods : checkedGoodsList) {
checkedGoodsPrice = checkedGoodsPrice.add(checkGoods.getPrice().multiply(new BigDecimal(checkGoods.getNumber())));
}
// 根据订单商品总价计算运费,满足条件(例如88元)则免运费,否则需要支付运费(例如8元);
BigDecimal freightPrice = new BigDecimal("0.00");
/*if (checkedGoodsPrice.compareTo(SystemConfig.getFreightLimit()) < 0) {
freightPrice = SystemConfig.getFreight();
}*/
// 可以使用的其他钱,例如用户积分
BigDecimal integralPrice = new BigDecimal("0.00");
// 优惠卷抵扣费用
BigDecimal couponPrice = new BigDecimal("0.00");
// 团购抵扣费用
BigDecimal grouponPrice = new BigDecimal("0.00");
// 订单费用
BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice).max(new BigDecimal("0.00"));
// 最终支付费用
BigDecimal actualPrice = orderTotalPrice.subtract(integralPrice);
String orderSn = OrderSnGenUtil.generateOrderSn(userId);
orderDTO.setOrderSn(orderSn);
// 异步下单
String uid = IdUtil.getUid();
System.out.println(uid);
CorrelationData correlationData = new CorrelationData(uid);
Map<String, Object> map = new HashMap<>();
map.put("order", orderDTO);
map.put("notifyUrl", WaynConfig.getMobileUrl() + "/message/order/submit");
try {
Message message = MessageBuilder.withBody(JSON.toJSONString(map).getBytes(Constants.UTF_ENCODING)).setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN).setDeliveryMode(MessageDeliveryMode.PERSISTENT).build();
rabbitTemplate.convertAndSend(SysConstants.ORDER_DIRECT_EXCHANGE, SysConstants.ORDER_DIRECT_ROUTING, message, correlationData);
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage(), e);
}
return R.success().add("actualPrice", actualPrice).add("orderSn", orderSn);
}
Aggregations