| | |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @Transactional |
| | | public Boolean importData(MultipartFile file) { |
| | | try { |
| | | ExcelUtil<Manufacturer> util = new ExcelUtil<>(Manufacturer.class); |
| | | List<Manufacturer> list = util.importExcel(file.getInputStream()); |
| | | if (list != null && !list.isEmpty()) { |
| | | this.saveBatch(list); |
| | | } |
| | | ExcelUtil<ManufacturerExcelDto> util = new ExcelUtil<>(ManufacturerExcelDto.class); |
| | | List<ManufacturerExcelDto> list = util.importExcel(file.getInputStream()); |
| | | ArrayList<Manufacturer> manufacturers = new ArrayList<>(); |
| | | list.stream().forEach(dto -> { |
| | | Manufacturer manufacturer = new Manufacturer(); |
| | | BeanUtils.copyProperties(dto,manufacturer); |
| | | manufacturer.setMaintainTime(LocalDate.now()); |
| | | manufacturer.setMaintainUserId(SecurityUtils.getLoginUser().getUser().getUserId()); |
| | | manufacturers.add(manufacturer); |
| | | }); |
| | | this.saveOrUpdateBatch(manufacturers); |
| | | return true; |
| | | } catch (Exception e) { |
| | | log.error("导入失败", e); |