| | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.poi.hssf.usermodel.HSSFSheet; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | | import org.springblade.core.boot.ctrl.BladeController; |
| | | import org.springblade.core.excel.util.ExcelUtil; |
| | | import org.springblade.core.log.annotation.ApiLog; |
| | |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.modules.mountainrain.entity.Yucbig; |
| | | import org.springblade.modules.mountainrain.entity.Yucsma; |
| | | import org.springblade.modules.mountainrain.excel.BgrExcel; |
| | | import org.springblade.modules.mountainrain.excel.BgrImporter; |
| | | import org.springblade.modules.mountainrain.excel.MgrExcel; |
| | | import org.springblade.modules.mountainrain.excel.MgrImporter; |
| | | import org.springblade.modules.mountainrain.service.IBigriverService; |
| | | import org.springblade.modules.mountainrain.service.ISmariverService; |
| | | import org.springblade.modules.mountainrain.wrapper.BigriverWrapper; |
| | | import org.springblade.modules.mountainrain.wrapper.SmariverWrapper; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | |
| | | public class SmariverController extends BladeController { |
| | | |
| | | private ISmariverService iSmariverService; |
| | | |
| | | private IBigriverService iBigriverService; |
| | | /** |
| | | * 详情 |
| | | */ |
| | |
| | | return R.status(iSmariverService.updateById(yucsma)); |
| | | } |
| | | |
| | | /** |
| | | * 中小河流预报数据导入 |
| | | */ |
| | | @PostMapping("import-mgr") |
| | | public R importmgr(MultipartFile file) { |
| | | MgrImporter mgrImporter = new MgrImporter(iSmariverService, false); |
| | | ExcelUtil.save(file, mgrImporter, MgrExcel.class); |
| | | return R.success("操作成功"); |
| | | } |
| | | // /** |
| | | // * 中小河流预报数据导入 |
| | | // */ |
| | | // @PostMapping("import-mgr") |
| | | // public R importmgr(MultipartFile file) { |
| | | // MgrImporter mgrImporter = new MgrImporter(iSmariverService, false); |
| | | // ExcelUtil.save(file, mgrImporter, MgrExcel.class); |
| | | // return R.success("操作成功"); |
| | | // } |
| | | |
| | | /** |
| | | * 中小河流预警 |
| | |
| | | String yjsw = selctsmriver.get(i).get("yjsw").toString(); |
| | | Double yjz = Double.parseDouble(yjsw); |
| | | //水位 |
| | | String zs = selctsmriver.get(i).get("yuz").toString(); |
| | | String zs = selctsmriver.get(i).get("Z").toString(); |
| | | Double z = Double.parseDouble(zs); |
| | | if (z > yjz) { |
| | | listyj.add(selctsmriver.get(i)); |
| | |
| | | return R.data(list); |
| | | } |
| | | |
| | | |
| | | |
| | | @PostMapping("import-mgr") |
| | | public void importmgr(MultipartFile file) throws IOException, InvalidFormatException { |
| | | InputStream is = file.getInputStream(); |
| | | HSSFWorkbook workbook = new HSSFWorkbook(is); |
| | | //确定版本 |
| | | boolean isExcel2003 = file.getOriginalFilename().endsWith("xls") ? true : false; |
| | | List<Map<String, Object>> returnMap;//返回execlClass类见下 |
| | | if (isExcel2003) { //判断版本 |
| | | HSSFSheet sheet = workbook.getSheetAt(1); |
| | | sheet.getRow(4).getCell(12).setCellType(CellType.STRING); |
| | | sheet.getRow(4).getCell(13).setCellType(CellType.STRING); |
| | | sheet.getRow(4).getCell(14).setCellType(CellType.STRING); |
| | | sheet.getRow(4).getCell(15).setCellType(CellType.STRING); |
| | | sheet.getRow(4).getCell(8).setCellType(CellType.STRING); |
| | | //发布时间 |
| | | String ftimes = sheet.getRow(1).getCell(11).getStringCellValue(); |
| | | String substring = ftimes.substring(5, ftimes.length()); |
| | | String year = substring.substring(0, substring.lastIndexOf("年")); |
| | | String yues = substring.substring(substring.indexOf("年")+1, substring.lastIndexOf("月")); |
| | | String yue; |
| | | if (yues.length()==1){ |
| | | yue=0+yues; |
| | | } |
| | | else { |
| | | yue=yues; |
| | | } |
| | | String r = substring.substring(substring.indexOf("月")+1, substring.lastIndexOf("日")); |
| | | String ms = substring.substring(substring.indexOf("日")+1, substring.lastIndexOf("时")); |
| | | String ftime=year+"-"+yue+"-"+r+" "+ms+":00:00"; |
| | | //河名 |
| | | String river = sheet.getRow(4).getCell(0).getStringCellValue(); |
| | | //站点名称 |
| | | String stnames = sheet.getRow(4).getCell(1).getStringCellValue(); |
| | | String stcd = iBigriverService.selectINfo(stnames); |
| | | //预报时间 |
| | | String ytimes = sheet.getRow(4).getCell(12).getStringCellValue(); |
| | | String[] split = ytimes.split(","); |
| | | String a; |
| | | if (split[0].length()==1){ |
| | | a=0+yues; |
| | | } |
| | | else { |
| | | a=yues; |
| | | } |
| | | String ytime=year+"-"+a+"-"+split[1]+" "+split[2]+":00:00"; |
| | | //预测水位 |
| | | String yuz = sheet.getRow(4).getCell(13).getStringCellValue(); |
| | | //预警流量 |
| | | String yq = sheet.getRow(4).getCell(14).getStringCellValue(); |
| | | //预警水位 |
| | | String yjsw = sheet.getRow(4).getCell(15).getStringCellValue(); |
| | | String qzsw = sheet.getRow(4).getCell(8).getStringCellValue(); |
| | | Yucsma yucsma=new Yucsma(); |
| | | yucsma.setStcd(stcd); |
| | | yucsma.setStname(stnames); |
| | | yucsma.setRiver(river); |
| | | yucsma.setFtime(ftime); |
| | | yucsma.setYjsw(yjsw); |
| | | yucsma.setYtime(ytime); |
| | | yucsma.setYuz(yuz); |
| | | yucsma.setYq(yq); |
| | | yucsma.setQzsw(qzsw); |
| | | iSmariverService.save(yucsma); |
| | | } else { |
| | | //有多少个sheet |
| | | int sheets = workbook.getNumberOfSheets(); |
| | | System.out.println("其他:" + sheets); |
| | | } |
| | | } |
| | | } |