Search in sources :

Example 6 with BookDTO

use of com.github.lybgeek.orm.mybatisplus.dto.BookDTO in project springboot-learning by lyb-geek.

the class BookServiceImpl method pageBook.

@Override
public PageResult<BookDTO> pageBook(PageQuery<BookDTO> pageQuery) {
    BookDTO bookDTO = pageQuery.getQueryParams();
    Wrapper<Book> wrapper = wrapperQueryCondition(bookDTO);
    IPage<Book> page = new Page<>(pageQuery.getPageNo(), pageQuery.getPageSize());
    IPage<Book> bookIPage = baseMapper.selectPage(page, wrapper);
    if (bookIPage != null) {
        List<BookDTO> bookDTOS = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(bookIPage.getRecords())) {
            bookDTOS = BeanMapperUtils.mapList(bookIPage.getRecords(), BookDTO.class);
        }
        return PageUtil.INSTANCE.getPage(bookIPage, bookDTOS);
    }
    return null;
}
Also used : BookDTO(com.github.lybgeek.orm.mybatisplus.dto.BookDTO) Book(com.github.lybgeek.orm.mybatisplus.model.Book) ArrayList(java.util.ArrayList) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage)

Example 7 with BookDTO

use of com.github.lybgeek.orm.mybatisplus.dto.BookDTO 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)

Example 8 with BookDTO

use of com.github.lybgeek.orm.mybatisplus.dto.BookDTO in project springboot-learning by lyb-geek.

the class BookController method upadteBook.

@PostMapping(value = "/update")
public Result<BookDTO> upadteBook(BookDTO bookDTO) {
    Result<BookDTO> result = new Result<>();
    if (bookDTO.getId() == null) {
        result.setStatus(Result.fail);
        result.setMessage("id不能为空");
        return result;
    }
    BookDTO book = bookService.editBook(bookDTO);
    result.setData(book);
    return result;
}
Also used : BookDTO(com.github.lybgeek.orm.mybatisplus.dto.BookDTO) BindingResult(org.springframework.validation.BindingResult) Result(com.github.lybgeek.orm.common.model.Result) PageResult(com.github.lybgeek.orm.common.model.PageResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 9 with BookDTO

use of com.github.lybgeek.orm.mybatisplus.dto.BookDTO in project springboot-learning by lyb-geek.

the class OrmApplicationTest method testPageBook.

@Test
public void testPageBook() {
    PageQuery pageQuery = new PageQuery<>().setPageNo(1).setPageSize(5);
    BookDTO bookDTO = new BookDTO();
    bookDTO.setAuthor("张三");
    // bookDTO.setBookName("图解Http");
    // bookDTO.setId(4L);
    pageQuery.setQueryParams(bookDTO);
    PageResult<BookDTO> pageResult = bookService.pageBook(pageQuery);
    if (pageResult != null) {
        pageResult.getList().forEach(book -> System.out.println(book));
    }
}
Also used : PageQuery(com.github.lybgeek.orm.common.model.PageQuery) BookDTO(com.github.lybgeek.orm.mybatisplus.dto.BookDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with BookDTO

use of com.github.lybgeek.orm.mybatisplus.dto.BookDTO in project springboot-learning by lyb-geek.

the class OrmApplicationTest method testListBook.

@Test
public void testListBook() {
    BookDTO bookDTO = new BookDTO();
    bookDTO.setAuthor("张三");
    bookDTO.setBookName("java");
    // bookDTO.setId(5L);
    List<BookDTO> bookDTOS = bookService.listBooks(bookDTO);
    bookDTOS.forEach(book -> System.out.println(book));
}
Also used : BookDTO(com.github.lybgeek.orm.mybatisplus.dto.BookDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

BookDTO (com.github.lybgeek.orm.mybatisplus.dto.BookDTO)10 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Book (com.github.lybgeek.orm.mybatisplus.model.Book)3 BizException (com.github.lybgeek.orm.common.exception.BizException)2 PageResult (com.github.lybgeek.orm.common.model.PageResult)2 Result (com.github.lybgeek.orm.common.model.Result)2 Transactional (org.springframework.transaction.annotation.Transactional)2 BindingResult (org.springframework.validation.BindingResult)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 PageQuery (com.github.lybgeek.orm.common.model.PageQuery)1 OrderItemsDTO (com.github.lybgeek.orm.mybatis.dto.OrderItemsDTO)1 BookOrder (com.github.lybgeek.orm.mybatis.model.BookOrder)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1