Search in sources :

Example 6 with BizException

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;
}
Also used : BookDTO(com.github.lybgeek.spilt.dto.BookDTO) Book(com.github.lybgeek.spilt.model.Book) BizException(com.github.lybgeek.common.exception.BizException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with BizException

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;
}
Also used : BookDTO(com.github.lybgeek.redis.dto.BookDTO) Book(com.github.lybgeek.redis.model.Book) BizException(com.github.lybgeek.common.exception.BizException) Date(java.util.Date) Cacheable(org.springframework.cache.annotation.Cacheable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with BizException

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;
}
Also used : Cookie(javax.servlet.http.Cookie) BizException(com.github.lybgeek.common.exception.BizException)

Example 9 with BizException

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;
}
Also used : BookDTO(com.github.lybgeek.dynamic.dto.BookDTO) Book(com.github.lybgeek.dynamic.model.Book) BizException(com.github.lybgeek.common.exception.BizException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with BizException

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;
}
Also used : BizException(com.github.lybgeek.common.exception.BizException) ImageDTO(com.github.lybgeek.modules.image.dto.ImageDTO) ImageVO(com.github.lybgeek.modules.image.vo.ImageVO) Result(com.github.lybgeek.common.model.Result) ExcelImportResult(cn.afterturn.easypoi.excel.entity.result.ExcelImportResult) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

BizException (com.github.lybgeek.common.exception.BizException)14 Date (java.util.Date)4 Transactional (org.springframework.transaction.annotation.Transactional)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 ExcelImportResult (cn.afterturn.easypoi.excel.entity.result.ExcelImportResult)2 Result (com.github.lybgeek.common.model.Result)2 FileUploadDTO (com.github.lybgeek.upload.dto.FileUploadDTO)2 IOException (java.io.IOException)2 RandomAccessFile (java.io.RandomAccessFile)2 WriteSheet (com.alibaba.excel.write.metadata.WriteSheet)1 FillConfig (com.alibaba.excel.write.metadata.fill.FillConfig)1 BookDTO (com.github.lybgeek.dynamic.dto.BookDTO)1 Book (com.github.lybgeek.dynamic.model.Book)1 FileConvertResultDTO (com.github.lybgeek.file.dto.FileConvertResultDTO)1 CustomerserviceWagesDTO (com.github.lybgeek.modules.customerservice.dto.CustomerserviceWagesDTO)1 CustomerserviceWagesVO (com.github.lybgeek.modules.customerservice.vo.CustomerserviceWagesVO)1 ImageDTO (com.github.lybgeek.modules.image.dto.ImageDTO)1