Search in sources :

Example 1 with ExcelImportResult

use of cn.afterturn.easypoi.excel.entity.result.ExcelImportResult 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 2 with ExcelImportResult

use of cn.afterturn.easypoi.excel.entity.result.ExcelImportResult 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)2 BizException (com.github.lybgeek.common.exception.BizException)2 Result (com.github.lybgeek.common.model.Result)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 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 ImageVO (com.github.lybgeek.modules.image.vo.ImageVO)1