use of com.github.lybgeek.common.exception.BizException in project springboot-learning by lyb-geek.
the class BookServiceImpl method addBook.
@Override
@Transactional
public // @DS("follow")
BookDTO addBook(BookDTO bookDTO) {
Book book = dozerMapper.map(bookDTO, Book.class);
boolean isExitBookByName = ObjectUtils.isNotEmpty(getBookByName(bookDTO.getBookName()));
if (isExitBookByName) {
throw new BizException("书名已经存在");
}
book.setCreateDate(new Date());
book.setUpdateDate(new Date());
baseMapper.insert(book);
bookDTO = dozerMapper.map(book, BookDTO.class);
return bookDTO;
}
use of com.github.lybgeek.common.exception.BizException in project springboot-learning by lyb-geek.
the class BookServiceImpl method addBook.
@Override
@Transactional
@Cacheable(cacheNames = "book", key = "'add_'+#bookDTO.bookName")
public BookDTO addBook(BookDTO bookDTO) {
Book book = dozerMapper.map(bookDTO, Book.class);
boolean isExitBookByName = ObjectUtils.isNotEmpty(getBookByName(bookDTO.getBookName()));
if (isExitBookByName) {
throw new BizException("书名已经存在");
}
book.setCreateDate(new Date());
book.setUpdateDate(new Date());
baseMapper.insert(book);
bookDTO = dozerMapper.map(book, BookDTO.class);
return bookDTO;
}
use of com.github.lybgeek.common.exception.BizException in project springboot-learning by lyb-geek.
the class AuthIntercepors method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String accessToken = null;
Cookie[] cookies = request.getCookies();
if (cookies != null && cookies.length > 0) {
for (Cookie cookie : cookies) {
if (Constant.ACCESS_TOKEN.equals(cookie.getName())) {
accessToken = cookie.getValue();
break;
}
}
}
if (StringUtils.isBlank(accessToken)) {
accessToken = request.getHeader(Constant.ACCESS_TOKEN);
}
if (Constant.ACCESS_TOKEN_PASS_VALUE.equals(accessToken)) {
return true;
}
log.error("illegal request uri : {}", request.getRequestURI());
throw new BizException("非法请求调用", 401);
// response.sendRedirect(request.getContextPath() + "/");
// return false;
}
use of com.github.lybgeek.common.exception.BizException in project springboot-learning by lyb-geek.
the class BookServiceImpl method addBook.
@Override
@Transactional
public // @DS("follow")
BookDTO addBook(BookDTO bookDTO) {
Book book = dozerMapper.map(bookDTO, Book.class);
boolean isExitBookByName = ObjectUtils.isNotEmpty(getBookByName(bookDTO.getBookName()));
if (isExitBookByName) {
throw new BizException("书名已经存在");
}
book.setCreateDate(new Date());
book.setUpdateDate(new Date());
baseMapper.insert(book);
bookDTO = dozerMapper.map(book, BookDTO.class);
return bookDTO;
}
use of com.github.lybgeek.common.exception.BizException in project springboot-learning by lyb-geek.
the class ImageController method importImage.
@PostMapping(value = "/import")
@ResponseBody
public Result<ImageDTO> importImage(MultipartFile file) throws Exception {
ExcelImportResult<ImageVO> excelData = ExcelReader.builder().headRowNumber(1).sheetNo(0).inputStream(file.getInputStream()).build().read(ImageVO.class, true);
boolean verifyFail = excelData.isVerifyFail();
if (verifyFail) {
String errorMsg = ExcelUtils.getErrorMsg(excelData.getFailList());
throw new BizException(errorMsg);
}
List<ImageDTO> imageDTOS = imageConvertMapper.listImageVO2ListDTO(excelData.getList());
imageService.saveImages(imageDTOS);
Result result = Result.builder().data(imageDTOS).build();
return result;
}
Aggregations