/**
* 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.water.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.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.modules.water.entity.water;
import org.springblade.modules.water.mapper.WaterMapper;
import org.springblade.modules.water.service.WaterService;
import org.springblade.modules.water.vo.WaterVO;
import org.springblade.modules.water.wrapper.WaterWrapper;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;
/**
* 服务实现类
*
* @author Blade
* @since 2019-11-07
*/
@Service
@DS("slaves")
public class WaterServiceImpl extends ServiceImpl implements WaterService {
@Override
public IPage childList(Map dict, Long parentId, Query query) {
dict.remove("parentId");
IPage page = this.page(Condition.getPage(query), Condition.getQueryWrapper(dict, water.class).lambda().eq(water::getParentId, parentId).orderByAsc(water::getOrigin));
return WaterWrapper.build().pageVO(page);
}
@Override
public List queryList(String pid, String loc) {
return baseMapper.queryList(pid,loc);
}
@Override
public void upLoadFile(MultipartFile file) {
try{
InputStream in = file.getInputStream();
Workbook workbook = null;
try{
workbook = new HSSFWorkbook(in);
}catch(Exception e){
workbook = new XSSFWorkbook(in);
}
int numberOfSheets = workbook.getNumberOfSheets();
//第一个sheet
for (int j=0;j1){
waterLine.setCjtime(temp[1]);
}*/
//有效行数
int rowNubms = sheet1.getPhysicalNumberOfRows();
for (int i = 1; i < rowNubms; i++) {
Row rowi = sheet1.getRow(i);
if (rowi == null) {
continue;
}
//创建数据库表对应的实体类
water water = new water();
Cell cell1 = rowi.getCell(0);//水面线编码
if(cell1.getCellType() == Cell.CELL_TYPE_BLANK) {
continue;
}
Cell cell2 = rowi.getCell(1);//序号
Cell cell3 = rowi.getCell(2);//位置
Cell cell4 = rowi.getCell(3);//经度
Cell cell5 = rowi.getCell(4);//纬度
Cell cell6 = rowi.getCell(5);//起点距
Cell cell7 = rowi.getCell(6);//水面线高程(黄海)
//此处判断为null,以防get值的时候 报空指针
DecimalFormat df = new DecimalFormat("0");
String smxbm = (cell1 != null) ? getCellValue(cell1) : null;
String xh = df.format(cell2.getNumericCellValue());
int number = WaterServiceImpl.super.baseMapper.selectInfo(smxbm, xh);
if(number==1){
WaterServiceImpl.super.baseMapper.deleteInfo(smxbm, xh);
}
String wz = (cell3 != null) ? getCellValue(cell3) : null;
String jd = (cell4 != null) ? getCellValue(cell4) : null;
String wd = (cell5 != null) ? getCellValue(cell5) : null;
String qdj = (cell6 != null) ? getCellValue(cell6) : null;
String gc = (cell7 != null) ? getCellValue(cell7) : null;
water.setParentId(smxbm);
water.setXh(Integer.parseInt(xh));
water.setLocation(wz);
water.setLng(jd);
water.setLat(wd);
water.setOrigin(qdj);
water.setWater(gc);
//水面线新增
WaterServiceImpl.super.save(water);
in.close(); //关闭流
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public int selectInfo(String pid, String num) {
return baseMapper.selectInfo(pid, num);
}
@Override
public void deleteInfo(String pid, String num) {
baseMapper.deleteInfo(pid, num);
}
@Override
public List