Search in sources :

Example 1 with UserAccountOutput

use of com.amusing.start.client.output.UserAccountOutput in project amusing-project by m-lvqingyu.

the class AccountServiceImpl method account.

@Override
public UserAccountOutput account(String userId) {
    UserAccountOutput output = new UserAccountOutput();
    UserAccountInfo info = userAccountInfoMapper.selectByUserId(userId);
    Optional.ofNullable(info).ifPresent(i -> {
        BeanUtils.copyProperties(info, output);
    });
    return output;
}
Also used : UserAccountOutput(com.amusing.start.client.output.UserAccountOutput) UserAccountInfo(com.amusing.start.user.pojo.UserAccountInfo)

Example 2 with UserAccountOutput

use of com.amusing.start.client.output.UserAccountOutput in project amusing-project by m-lvqingyu.

the class InwardManager method accountDetail.

/**
 * 获取用户账户信息
 *
 * @param reserveId 预定人ID
 * @return
 * @throws OrderException
 */
public UserAccountOutput accountDetail(String reserveId) {
    UserAccountOutput userAccountOutput = null;
    try {
        userAccountOutput = userClient.account(reserveId);
    } catch (Exception e) {
        log.error("[order]-create getUserAccountDetails err! reserveUserId:{}, msg:{}", reserveId, Throwables.getStackTraceAsString(e));
    }
    log.info("[order]-create reserveUserId:{}, userAccount:{}", reserveId, userAccountOutput);
    return userAccountOutput;
}
Also used : UserAccountOutput(com.amusing.start.client.output.UserAccountOutput) OrderException(com.amusing.start.order.exception.OrderException)

Example 3 with UserAccountOutput

use of com.amusing.start.client.output.UserAccountOutput in project amusing-project by m-lvqingyu.

the class CreateServiceImpl method create.

/**
 * 创建订单
 *
 * @param createDto 订单信息
 * @return
 * @throws OrderException
 */
@GlobalTransactional
@Transactional(rollbackFor = Exception.class)
@Override
public String create(CreateDto createDto) throws OrderException {
    // 1.获取购物车信息
    Map<String, Integer> productMap = shopCarService.get(createDto.getReserveId());
    if (productMap == null || productMap.isEmpty()) {
        throw new OrderException(OrderCode.PRODUCT_NOT_FOUND);
    }
    // 2.判断库存是否足够
    Map<String, Long> productStock = inwardManager.productStock(productMap.keySet());
    if (productStock == null || productMap.size() != productStock.size()) {
        throw new OrderException(OrderCode.PRODUCT_NOT_FOUND);
    }
    Iterator<Map.Entry<String, Long>> iterator = productStock.entrySet().iterator();
    if (iterator.hasNext()) {
        Map.Entry<String, Long> next = iterator.next();
        Long value = next.getValue();
        if (value == null || value <= OrderConstant.ZERO) {
            throw new OrderException(OrderCode.PRODUCT_NOT_FOUND);
        }
    }
    // 3.获取预定人账户信息
    UserAccountOutput userAccount = inwardManager.accountDetail(createDto.getReserveId());
    Optional.ofNullable(userAccount).orElseThrow(() -> new OrderException(OrderCode.USER_NOT_FOUND));
    // 4.获取商品信息及单价
    Set<String> productIdSet = productMap.keySet();
    List<ProductOutput> productsDetails = inwardManager.productDetails(productIdSet);
    // 5.保存订单相关信息
    return doSaveOrder(createDto, userAccount, productMap, productsDetails);
}
Also used : UserAccountOutput(com.amusing.start.client.output.UserAccountOutput) ProductOutput(com.amusing.start.client.output.ProductOutput) OrderException(com.amusing.start.order.exception.OrderException) GlobalTransactional(io.seata.spring.annotation.GlobalTransactional) GlobalTransactional(io.seata.spring.annotation.GlobalTransactional) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserAccountOutput (com.amusing.start.client.output.UserAccountOutput)3 OrderException (com.amusing.start.order.exception.OrderException)2 ProductOutput (com.amusing.start.client.output.ProductOutput)1 UserAccountInfo (com.amusing.start.user.pojo.UserAccountInfo)1 GlobalTransactional (io.seata.spring.annotation.GlobalTransactional)1 Transactional (org.springframework.transaction.annotation.Transactional)1