Search in sources :

Example 1 with BookOrder

use of com.github.lybgeek.orm.mybatis.model.BookOrder in project springboot-learning by lyb-geek.

the class BookOrderServiceImpl method pageBookOrder.

@Override
public PageResult<BookOrderDTO> pageBookOrder(PageQuery<BookOrderDTO> pageQuery) {
    Integer pageNo = ObjectUtils.isEmpty(pageQuery.getPageNo()) ? 1 : pageQuery.getPageNo();
    Integer pageSize = ObjectUtils.isEmpty(pageQuery.getPageSize()) ? 5 : pageQuery.getPageSize();
    BookOrderDTO bookOrderDTO = pageQuery.getQueryParams();
    Page<BookOrder> page = PageHelper.startPage(pageNo, pageSize);
    PageHelper.orderBy("bo.create_date DESC");
    List<BookOrderDTO> list = listBookOrders(bookOrderDTO);
    return PageUtil.INSTANCE.getPage(page, list);
}
Also used : BookOrder(com.github.lybgeek.orm.mybatis.model.BookOrder) BookOrderDTO(com.github.lybgeek.orm.mybatis.dto.BookOrderDTO)

Example 2 with BookOrder

use of com.github.lybgeek.orm.mybatis.model.BookOrder in project springboot-learning by lyb-geek.

the class BookOrderServiceImpl method listBookOrders.

@Override
public List<BookOrderDTO> listBookOrders(BookOrderDTO bookOrderDTO) {
    BookOrder bookOrder = new BookOrder();
    if (bookOrderDTO != null) {
        bookOrder = dozerMapper.map(bookOrderDTO, BookOrder.class);
    }
    List<BookOrder> bookOrders = bookOrderDao.listBookOrders(bookOrder);
    if (CollectionUtils.isNotEmpty(bookOrders)) {
        return BeanMapperUtils.mapList(bookOrders, BookOrderDTO.class);
    }
    return Collections.emptyList();
}
Also used : BookOrder(com.github.lybgeek.orm.mybatis.model.BookOrder)

Example 3 with BookOrder

use of com.github.lybgeek.orm.mybatis.model.BookOrder in project springboot-learning by lyb-geek.

the class BookOrderServiceImpl method editBookOrder.

@Override
@Transactional
public BookOrderDTO editBookOrder(BookOrderDTO bookOrderDTO) {
    BookOrder bookOrder = dozerMapper.map(bookOrderDTO, BookOrder.class);
    BookOrder dbBookOrder = bookOrderDao.editBookOrder(bookOrder);
    return dozerMapper.map(dbBookOrder, BookOrderDTO.class);
}
Also used : BookOrder(com.github.lybgeek.orm.mybatis.model.BookOrder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with BookOrder

use of com.github.lybgeek.orm.mybatis.model.BookOrder in project springboot-learning by lyb-geek.

the class BookOrderServiceImpl method createBookOrder.

@Override
@Transactional
public BookOrderDTO createBookOrder(BookOrderDTO bookOrderDTO) {
    BookOrder bookOrder = dozerMapper.map(bookOrderDTO, BookOrder.class);
    OrderItemsDTO orderItemsDTO = OrderItemUtil.INSTANCE.getOrderItems(bookOrder.getBookOrderItems());
    Map<String, Integer> orderCountMap = orderItemsDTO.getItemContMap();
    boolean isCanCreate = true;
    String bookName = null;
    for (Map.Entry<String, Integer> entry : orderCountMap.entrySet()) {
        BookDTO bookDTO = bookService.getBookByName(entry.getKey());
        if (ObjectUtils.isEmpty(bookDTO)) {
            log.warn("不存在书目{}", entry.getKey());
            bookName = entry.getKey();
            isCanCreate = false;
            break;
        }
        int updateBookCount = bookService.updateStockById(bookDTO.getId(), entry.getValue());
        if (updateBookCount <= 0) {
            log.warn("当前书目:{},还有库存:{},欲购数目:{}", entry.getKey(), bookDTO.getStock(), entry.getValue());
            throw new BizException("当前书目->" + entry.getKey() + "已经售罄");
        }
    }
    if (!isCanCreate) {
        throw new BizException("不存在书目->" + bookName);
    }
    bookOrder.setTotal(orderItemsDTO.getTotalPrice());
    bookOrder.setOrderNo(String.valueOf(System.currentTimeMillis()));
    BookOrder dbBookOrder = bookOrderDao.createBookOrder(bookOrder);
    applicationEventPublisher.publishEvent(dbBookOrder);
    return dozerMapper.map(dbBookOrder, BookOrderDTO.class);
}
Also used : BookDTO(com.github.lybgeek.orm.mybatisplus.dto.BookDTO) OrderItemsDTO(com.github.lybgeek.orm.mybatis.dto.OrderItemsDTO) BizException(com.github.lybgeek.orm.common.exception.BizException) BookOrder(com.github.lybgeek.orm.mybatis.model.BookOrder) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BookOrder (com.github.lybgeek.orm.mybatis.model.BookOrder)4 Transactional (org.springframework.transaction.annotation.Transactional)2 BizException (com.github.lybgeek.orm.common.exception.BizException)1 BookOrderDTO (com.github.lybgeek.orm.mybatis.dto.BookOrderDTO)1 OrderItemsDTO (com.github.lybgeek.orm.mybatis.dto.OrderItemsDTO)1 BookDTO (com.github.lybgeek.orm.mybatisplus.dto.BookDTO)1