Search in sources :

Example 1 with ImageVO

use of com.github.lybgeek.modules.image.vo.ImageVO 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

ExcelImportResult (cn.afterturn.easypoi.excel.entity.result.ExcelImportResult)1 BizException (com.github.lybgeek.common.exception.BizException)1 Result (com.github.lybgeek.common.model.Result)1 ImageDTO (com.github.lybgeek.modules.image.dto.ImageDTO)1 ImageVO (com.github.lybgeek.modules.image.vo.ImageVO)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1