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;
}
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);
}
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;
}
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));
}
}
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));
}
Aggregations