tangzy
2022-07-21 a98b1db4392c357304036e8b3cdd01646920300d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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.mountainrain.controller;
 
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jodd.io.PathUtil;
import liquibase.pro.packaged.S;
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.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.python.antlr.ast.Str;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.modules.mountainrain.entity.Yucbig;
import org.springblade.modules.mountainrain.service.IBigriverService;
import org.springblade.modules.mountainrain.vo.BigriverVO;
import org.springblade.modules.mountainrain.wrapper.BigriverWrapper;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.security.MessageDigest;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * 控制器
 *
 * @author Blade
 * @since 2019-11-07
 */
@RestController
@AllArgsConstructor
@RequestMapping("/bigriver")
@Api(value = "", tags = "接口")
public class BigriverController extends BladeController {
 
    private IBigriverService iBigriverService;
 
    /**
     * 详情
     */
    @ApiLog("详情")
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "site")
    public R<Yucbig> detail(Yucbig yucbig) {
        Yucbig detail = iBigriverService.getOne(Condition.getQueryWrapper(yucbig));
        return R.data(BigriverWrapper.build().entityVO(detail));
    }
 
 
    /**
     * 新增
     */
    @ApiLog("新增")
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入site")
    public R save(@Valid @RequestBody Yucbig yucbig) {
        return R.status(iBigriverService.save(yucbig));
    }
 
    /**
     * 修改
     */
    @ApiLog("修改")
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入site")
    public R update(@Valid @RequestBody Yucbig yucbig) {
        return R.status(iBigriverService.updateById(yucbig));
    }
 
 
//    /**
//     * 大江大河预报数据导入
//     */
//    @PostMapping("import-bgr")
//    public R importbgr(MultipartFile file) {
//        BgrImporter bgrImporter = new BgrImporter(iBigriverService, false);
//        ExcelUtil.save(file, bgrImporter, BgrExcel.class);
//        return R.success("导入成功");
//    }
 
    /**
     * 大江大河预警
     *
     * @return
     */
    @GetMapping("/selectbgriver")
    public R selectbgriver() {
        List<Map<String, Object>> selctsmriver = iBigriverService.selctbgriver();
        //预警数据
        List listyj = new ArrayList();
        //无预警数据
        List listzc = new ArrayList();
        for (int i = 0; i < selctsmriver.size(); i++) {
            //警戒水位
            String yjsw = selctsmriver.get(i).get("yjsw").toString();
            Double yjz = Double.parseDouble(yjsw);
            //水位
            String zs = selctsmriver.get(i).get("Z").toString();
            Double z = Double.parseDouble(zs);
            if (z > yjz) {
                listyj.add(selctsmriver.get(i));
            } else {
                listzc.add(selctsmriver.get(i));
            }
        }
        Map map = new HashMap();
        map.put("yj", listyj);
        map.put("zc", listzc);
        List list = new ArrayList();
        list.add(map);
        return R.data(list);
    }
 
 
    @PostMapping("import-bgr")
    public void importbgr(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(3).setCellType(CellType.STRING);
            sheet.getRow(4).getCell(8).setCellType(CellType.STRING);
            sheet.getRow(4).getCell(9).setCellType(CellType.STRING);
            sheet.getRow(4).getCell(10).setCellType(CellType.STRING);
            sheet.getRow(4).getCell(11).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 drp = sheet.getRow(4).getCell(3).getStringCellValue();
            //降雨起止时间
            String drptime = sheet.getRow(4).getCell(4).getStringCellValue();
            //起涨时间
            String qztime = sheet.getRow(4).getCell(7).getStringCellValue();
            //起涨流量
            String qzll = sheet.getRow(4).getCell(9).getStringCellValue();
            //发布水位
            String fbsw = sheet.getRow(4).getCell(10).getStringCellValue();
            //发布流量
            String fbll = sheet.getRow(4).getCell(11).getStringCellValue();
            //预报时间
            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 dbi = sheet.getRow(4).getCell(16).getStringCellValue();
            //起涨水位
            String qzsw = sheet.getRow(4).getCell(8).getStringCellValue();
            Yucbig yucbig = new Yucbig();
            yucbig.setStcd(stcd);
            yucbig.setStname(stnames);
            yucbig.setRiver(river);
            yucbig.setFtime(ftime);
            yucbig.setYjsw(yjsw);
            yucbig.setYtime(ytime);
            yucbig.setYuz(yuz);
            yucbig.setYq(yq);
            yucbig.setQzsw(qzsw);
            yucbig.setDrp(drp);
            yucbig.setDrptime(drptime);
            yucbig.setQztime(qztime);
            yucbig.setQzsw(qzsw);
            yucbig.setQzll(qzll);
            yucbig.setFbsw(fbsw);
            yucbig.setFbll(fbll);
            yucbig.setDbi(dbi);
            iBigriverService.save(yucbig);
        } else {
            //有多少个sheet
            int sheets = workbook.getNumberOfSheets();
            System.out.println("其他:" + sheets);
        }
    }
 
 
    /**
     * 主要河流导出预警模板
     *
     * @param emp01
     * @throws IOException
     * @throws InvalidFormatException
     */
    @PostMapping("createEmpExcel")
    public void createEmpExcel(@RequestBody Map<String, Object> emp01) throws IOException, InvalidFormatException {
        // import為需要導入的EXCEL模板,exportFilePath為生成的員工EXCEL文件
        String importFilePath = "D://excel//temple.xls";
        //String exportFilePath = "D:\\Excel";
 
        File fi = new File(importFilePath);
        InputStream in = new FileInputStream(fi);
        Workbook wb = WorkbookFactory.create(in);
        Sheet sheet = wb.getSheetAt(1);  //示意访问sheet
//        //读取excel模板
//        XSSFWorkbook wb = new XSSFWorkbook(in);
//        //读取了模板内所有sheet内容
//        XSSFSheet sheet = wb.getSheetAt(0);
        //如果这行没有了,整个公式都不会有自动计算的效果的
        sheet.setForceFormulaRecalculation(true);
        //河名
        sheet.getRow(4).getCell(0).setCellValue(emp01.get("river").toString());
        //站名
        sheet.getRow(4).getCell(1).setCellValue(emp01.get("stname").toString());
        //pa
        sheet.getRow(4).getCell(2).setCellValue(emp01.get("pa").toString());
        //降雨量
        sheet.getRow(4).getCell(3).setCellValue(emp01.get("drp").toString());
        //降雨起止时间
        sheet.getRow(4).getCell(4).setCellValue(emp01.get("drptime").toString());
        CellRangeAddress region = new CellRangeAddress(4, 4, 4, 6);
        sheet.addMergedRegion(region);
        //起涨时间
        sheet.getRow(4).getCell(7).setCellValue(emp01.get("qztime").toString());
        //起涨水位
        sheet.getRow(4).getCell(8).setCellValue(emp01.get("qzsw").toString());
        //起涨流量
        sheet.getRow(4).getCell(9).setCellValue(emp01.get("qzll").toString());
        //发布时间水位
        sheet.getRow(4).getCell(10).setCellValue(emp01.get("fbsw").toString());
        //发布时间流量
        sheet.getRow(4).getCell(11).setCellValue(emp01.get("fbll").toString());
        //预报时间
        sheet.getRow(4).getCell(12).setCellValue(emp01.get("ytime").toString());
        //预报水位
        sheet.getRow(4).getCell(13).setCellValue(emp01.get("Z").toString());
        //预报流量
        sheet.getRow(4).getCell(14).setCellValue(emp01.get("yq").toString());
        //警戒水位
        sheet.getRow(4).getCell(15).setCellValue(emp01.get("yjsw").toString());
        //预报水位与警戒水位比较
        sheet.getRow(4).getCell(16).setCellValue(emp01.get("dbi").toString());
        //防洪对象
        sheet.getRow(5).getCell(3).setCellValue(emp01.get("fh").toString());
        CellRangeAddress regions = new CellRangeAddress(5, 6, 3, 16);
        sheet.addMergedRegion(regions);
        //发布时间
        sheet.getRow(1).getCell(11).setCellValue("发布时间:" + emp01.get("ftime").toString());
        CellRangeAddress regionf = new CellRangeAddress(1, 1, 11, 16);
        sheet.addMergedRegion(regionf);
        FileOutputStream out = new FileOutputStream("D://Software//nginx-1.20.0//dist//fzswz//excel//主要河流预警.xls");
        //FileOutputStream out = new FileOutputStream("D://Temp//主要河流预警.xls");
        wb.write(out);
        out.close();
    }
 
 
    /**
     * 大江大河预报库读取
     *
     * @return
     */
    @GetMapping("/selectYb")
    public R selectYb(String time) throws ParseException {
        //预警数据
        List listyj = new ArrayList();
        //无预警数据
        List listzc = new ArrayList();
        Map mnum = new HashMap();
        String s = iBigriverService.selectCode();
        String[] split = s.split(",");
        String strArrays = "";
        for (int i = 0; i < split.length; i++) {
            strArrays += "'" + split[i] + "',";
        }
        String code = strArrays.substring(0, strArrays.length() - 1);
        String substrings = time.substring(0, 10);
        String ftimez = substrings + " 08:00:00";
        List<BigriverVO> list = iBigriverService.selectYb(ftimez, code);
        for (int i = 0; i < list.size(); i++) {
            String stcd = list.get(i).getStcd();
            String ftime = list.get(i).getFtime();
            String substring = ftime.substring(0, 13);
            String times = substring + ":00:00";
            String endTime = times;
            Date dates = beforeHourToNowDate(time, 1);
            DateFormat sdfc = new SimpleDateFormat("yyyy-MM-dd 08:00:00");
            String beginTime = sdfc.format(dates);
            List<Map<String, Object>> list1 = iBigriverService.selecF(stcd, times, beginTime, endTime);
            for (int c = 0; c < list1.size(); c++) {
                list.get(i).setFbsw(list1.get(c).get("fbsw").toString());
                list.get(i).setFbll(list1.get(c).get("fbll").toString());
                list.get(i).setQzll(list1.get(c).get("qzll").toString());
                list.get(i).setQztime(list1.get(c).get("qztime").toString());
                list.get(i).setQzsw(list1.get(c).get("qzsw").toString());
            }
        }
        for (int i = 0; i < list.size(); i++) {
            String yjsw = list.get(i).getYjsw();
            Double yjz = Double.parseDouble(yjsw);
            BigDecimal ybsws = list.get(i).getYbsw();
            Double ybsw = ybsws.doubleValue();
            if (ybsw > yjz) {
                if (mnum.containsKey(list.get(i).getStcd()) == true) {
                } else {
                    mnum.put(list.get(i).getStcd(), i);
                    listyj.add(list.get(i));
                }
            } else {
                if (mnum.containsKey(list.get(i).getStcd()) == true) {
                } else {
                    mnum.put(list.get(i).getStcd(), i);
                    listzc.add(list.get(i));
                }
            }
        }
        Map map = new HashMap();
        map.put("yj", listyj);
        map.put("zc", listzc);
        List lists = new ArrayList();
        lists.add(map);
        return R.data(lists);
    }
 
    public static Date beforeHourToNowDate(String date, int hours) {
        Calendar c = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            c.setTime(sdf.parse(date));
            //c.set(Calendar.HOUR_OF_DAY, c.get(Calendar.HOUR_OF_DAY) - hours);
            c.set(Calendar.DATE, c.get(Calendar.DATE) - hours);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return c.getTime();
    }
 
    @GetMapping("/ss")
    public void ss() {
        String s = iBigriverService.selectCode();
        String[] split = s.split(",");
        String strArrays = "";
        for (int i = 0; i < split.length; i++) {
            strArrays += "'" + split[i] + "',";
        }
        String code = strArrays.substring(0, strArrays.length() - 1);
        System.out.println(code);
    }
 
    /**
     * 大江大河预报库读取
     *
     * @return
     */
    @GetMapping("/selectYbs")
    public R selectYbs(String time) throws ParseException {
        //预警数据
        List listyj = new ArrayList();
        //无预警数据
        List listzc = new ArrayList();
        Map mnum = new HashMap();
        String s = iBigriverService.selectCode();
        String[] split = s.split(",");
        String strArrays = "";
        for (int i = 0; i < split.length; i++) {
            strArrays += "'" + split[i] + "',";
        }
        String code = strArrays.substring(0, strArrays.length() - 1);
        List<Map<String, Object>> listz = new ArrayList<Map<String, Object>>();
        List<BigriverVO> list = iBigriverService.selectYb(time, code);
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            String stcd = list.get(i).getStcd();
            String ftime = list.get(i).getFtime();
            String substring = ftime.substring(0, 13);
            String times = substring + ":00:00";
            String endTime = times;
            Date dates = beforeHourToNowDate(time, 1);
            DateFormat sdfc = new SimpleDateFormat("yyyy-MM-dd 08:00:00");
            String beginTime = sdfc.format(dates);
            map.put("beginTime", beginTime);
            map.put("endTime", endTime);
            map.put("stcd", stcd);
            map.put("times", times);
            listz.add(map);
        }
        List<Map<String, Object>> list1 = iBigriverService.selectStation(listz);
        for (int i = 0; i < list.size(); i++) {
            for (int c = 0; c < list1.size(); c++) {
                String stcd = list.get(i).getStcd();
                String stcdz = list1.get(i).get("STCD").toString();
                if (stcd == stcdz) {
                    list.get(i).setFbsw(list1.get(c).get("fbsw").toString());
                    list.get(i).setFbll(list1.get(c).get("fbll").toString());
                    list.get(i).setQzll(list1.get(c).get("qzll").toString());
                    list.get(i).setQztime(list1.get(c).get("qztime").toString());
                    list.get(i).setQzsw(list1.get(c).get("qzsw").toString());
                } else {
                    continue;
                }
 
            }
        }
        for (int i = 0; i < list.size(); i++) {
            String yjsw = list.get(i).getYjsw();
            Double yjz = Double.parseDouble(yjsw);
            BigDecimal ybsws = list.get(i).getYbsw();
            Double ybsw = ybsws.doubleValue();
            if (ybsw > yjz) {
                if (mnum.containsKey(list.get(i).getStcd()) == true) {
                } else {
                    mnum.put(list.get(i).getStcd(), i);
                    listyj.add(list.get(i));
                }
            } else {
                if (mnum.containsKey(list.get(i).getStcd()) == true) {
                } else {
                    mnum.put(list.get(i).getStcd(), i);
                    listzc.add(list.get(i));
                }
            }
        }
        Map map = new HashMap();
        map.put("yj", listyj);
        map.put("zc", listzc);
        List lists = new ArrayList();
        lists.add(map);
        return R.data(lists);
    }
 
}