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