Search in sources :

Example 1 with BizException

use of com.github.lybgeek.common.exception.BizException in project springboot-learning by lyb-geek.

the class ExcelWriter method writeTemplate.

public <T> void writeTemplate(String templateFileName, List<T> data) throws Exception {
    if (StringUtils.isBlank(templateFileName)) {
        throw new BizException("模板不能为空");
    }
    setRepHeader();
    com.alibaba.excel.ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(templateFileName).build();
    WriteSheet writeSheet = EasyExcel.writerSheet().build();
    FillConfig fillConfig = FillConfig.builder().forceNewRow(forceNewRow).build();
    excelWriter.fill(data, fillConfig, writeSheet);
    if (MapUtils.isNotEmpty(templateParamsMap)) {
        excelWriter.fill(templateParamsMap, writeSheet);
    }
    excelWriter.finish();
}
Also used : BizException(com.github.lybgeek.common.exception.BizException) WriteSheet(com.alibaba.excel.write.metadata.WriteSheet) FillConfig(com.alibaba.excel.write.metadata.fill.FillConfig)

Example 2 with BizException

use of com.github.lybgeek.common.exception.BizException in project springboot-learning by lyb-geek.

the class CustomerserviceWagesController method importExcel.

/**
 * 本方法用的模板是位于excel-template下的-->复杂表头样例.xls
 * @param file
 * @return
 * @throws Exception
 */
@PostMapping(value = "/import")
@ResponseBody
public Result<CustomerserviceWagesDTO> importExcel(MultipartFile file) throws Exception {
    ExcelImportResult<CustomerserviceWagesVO> excelData = ExcelReader.builder().titleRows(1).headRowNumber(2).sheetNo(0).inputStream(file.getInputStream()).build().read(CustomerserviceWagesVO.class, true);
    boolean verifyFail = excelData.isVerifyFail();
    if (verifyFail) {
        String errorMsg = ExcelUtils.getErrorMsg(excelData.getFailList());
        throw new BizException(errorMsg);
    }
    List<CustomerserviceWagesDTO> customerserviceWagesDTOS = customerserviceWagesConverter.convertVOList2DTOList(excelData.getList());
    customerserviceWagesService.saveCustomerserviceWages(customerserviceWagesDTOS);
    Result result = new Result().builder().data(customerserviceWagesDTOS).build();
    return result;
}
Also used : CustomerserviceWagesVO(com.github.lybgeek.modules.customerservice.vo.CustomerserviceWagesVO) BizException(com.github.lybgeek.common.exception.BizException) CustomerserviceWagesDTO(com.github.lybgeek.modules.customerservice.dto.CustomerserviceWagesDTO) 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)

Example 3 with BizException

use of com.github.lybgeek.common.exception.BizException in project springboot-learning by lyb-geek.

the class FileServiceImpl method upload.

@Override
public FileUploadDTO upload(FileUploadRequestDTO param) throws IOException {
    if (Objects.isNull(param.getFile())) {
        throw new BizException("file can not be empty", 404);
    }
    param.setPath(FileUtil.withoutHeadAndTailDiagonal(param.getPath()));
    String md5 = FileMD5Util.getFileMD5(param.getFile());
    param.setMd5(md5);
    String filePath = filePathUtil.getPath(param);
    File targetFile = new File(filePath);
    if (!targetFile.exists()) {
        targetFile.mkdirs();
    }
    String path = filePath + FileConstant.FILE_SEPARATORCHAR + param.getFile().getOriginalFilename();
    FileOutputStream out = new FileOutputStream(path);
    out.write(param.getFile().getBytes());
    out.flush();
    FileUtil.close(out);
    redisUtil.hset(FileConstant.FILE_UPLOAD_STATUS, md5, "true");
    return FileUploadDTO.builder().path(path).mtime(DateUtil.getCurrentTimeStamp()).uploadComplete(true).build();
}
Also used : BizException(com.github.lybgeek.common.exception.BizException) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 4 with BizException

use of com.github.lybgeek.common.exception.BizException in project springboot-learning by lyb-geek.

the class FileServiceImpl method sliceUpload.

@Override
public FileUploadDTO sliceUpload(FileUploadRequestDTO fileUploadRequestDTO) {
    try {
        completionService.submit(new FileCallable(UploadModeEnum.RANDOM_ACCESS, fileUploadRequestDTO));
        FileUploadDTO fileUploadDTO = completionService.take().get();
        return fileUploadDTO;
    } catch (InterruptedException e) {
        log.error(e.getMessage(), e);
        throw new BizException(e.getMessage(), 406);
    } catch (ExecutionException e) {
        log.error(e.getMessage(), e);
        throw new BizException(e.getMessage(), 406);
    }
}
Also used : FileUploadDTO(com.github.lybgeek.upload.dto.FileUploadDTO) FileCallable(com.github.lybgeek.upload.concurrent.FileCallable) BizException(com.github.lybgeek.common.exception.BizException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 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.swagger.dto.BookDTO) Book(com.github.lybgeek.swagger.model.Book) BizException(com.github.lybgeek.common.exception.BizException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

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