/** * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springblade.modules.dvoule.service.impl; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springblade.modules.dvoule.entity.Dvoule; import org.springblade.modules.dvoule.mapper.DvouleMapper; import org.springblade.modules.dvoule.service.DvouleService; import org.springblade.modules.dvoule.vo.DvouleVO; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.InputStream; import java.text.DecimalFormat; import java.util.Map; /** * 服务实现类 * * @author Blade * @since 2019-11-07 */ @Service @DS("slaves") public class DvouleServiceImpl extends ServiceImpl implements DvouleService { private final static String xls = "xls"; private final static String xlsx = "xlsx"; @Override public Map selecthz(String stcd) { return baseMapper.selecthz(stcd); } @Override public void upLoadFile(MultipartFile file) { try{ //获得文件名 String fileName = file.getOriginalFilename(); InputStream in = file.getInputStream(); Workbook workbooks = null; if(fileName.endsWith(xls)) { workbooks = new HSSFWorkbook(in); } else { workbooks = new XSSFWorkbook(in); } int numberOfSheets = workbooks.getNumberOfSheets(); //第一个sheet for (int j=0;j selectCz(IPage page, DvouleVO dvouleVO) { return baseMapper.selectCz(page, dvouleVO); } @Override public int selectInfo(String pid) { return baseMapper.selectInfo(pid); } @Override public void deleteInfo(String pid) { baseMapper.deleteInfo(pid); } private String getCellValue(Cell cell){ String value =""; switch (cell.getCellType()){ case Cell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; case Cell.CELL_TYPE_NUMERIC: value = String.valueOf(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_BLANK: value = ""; break; case Cell.CELL_TYPE_BOOLEAN: value = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: value = String.valueOf(cell.getErrorCellValue()); break; case Cell.CELL_TYPE_FORMULA: value = String.valueOf(cell.getCellFormula()); break; } return value; } }