yxm
2024-07-08 e7835f5a5feee4cad2388efe4e3af9003cb5e5c6
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
package cn.gistack.sm.sjztmd.feign;
 
import cn.gistack.alerts.sms.feign.ISmsRecordClient;
import cn.gistack.alerts.sms.vo.SmsResultVO;
import cn.gistack.resource.feign.IOssClient;
import cn.gistack.resource.vo.MyMultipartFile;
import cn.gistack.sm.intelligentCall.service.CallService;
import cn.gistack.sm.intelligentCall.vo.CallTaskResultVO;
import cn.gistack.sm.sjztmd.entity.AttResBase;
import cn.gistack.sm.sjztmd.entity.YwFloodReportInfo;
import cn.gistack.sm.sjztmd.feign.IAttResBaseClient;
import cn.gistack.sm.sjztmd.feign.ISjztMdClient;
import cn.gistack.sm.sjztmd.service.IAttResBaseService;
import cn.gistack.sm.sjztmd.service.ITbProjectService;
import cn.gistack.sm.sjztmd.service.IYwFloodReportInfoService;
import cn.gistack.sm.sjztmd.util.MyDateUtils;
import cn.gistack.sm.sjztmd.word.service.ISjztmdService;
import cn.gistack.sm.sjztmd.word.util.WordUtil;
import cn.gistack.sm.sjztmd.word.vo.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tenant.annotation.NonDS;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
 
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
 
@NonDS
@ApiIgnore
@RestController
@AllArgsConstructor
public class SjztMdClientImpl implements ISjztMdClient {
 
    private final ISjztmdService sjztmdService;
    private final IOssClient ossClient;
 
    private final ISmsRecordClient smsRecordClient;
 
    private final CallService callService;
 
    private final ITbProjectService tbProjectService;
 
    private final IYwFloodReportInfoService ywFloodReportInfoService;
 
    @Override
    public String saveYesterdayFloodReportContent(String isShow) throws Exception {
        //获取总览、大中库、明细数据
        List<TotalInfo> totalList = sjztmdService.getTotalInfo(isShow);
        OverWord overWord = WordUtil.GetOverInfo(totalList);
//        bladeRedis.set("yesterDayFloodReport-totalinfo",overWord.getTotalInfo());
//        bladeRedis.set("yesterDayFloodReport-oversmallinfo",overWord.getOverSmallInfo());
        YwFloodReportInfo info = new YwFloodReportInfo();
        info.setCreateTime(new Date());
        info.setTotalInfo(overWord.getTotalInfo());
        info.setOversmallInfo(overWord.getOverSmallInfo());
        ywFloodReportInfoService.save(info);
        return "保存昨日报汛内容";
    }
 
    @Override
    @GetMapping(GENERATE_DAY_REPORT_FLOOD)
    public String generateDayReportFlood(String isShow) throws Exception {
 
 
        //获取总览、大中库、明细数据
        List<TotalInfo> totalList = sjztmdService.getTotalInfo(isShow);
        List<DzkInfo> dzkList = sjztmdService.getDzkInfo(isShow);
        List<OverDetail> overDetailList = sjztmdService.getOverDetailInfo(isShow);
        List<SzInfo> szInfoList = sjztmdService.getSzInfo(isShow);
 
        //短信预警数量
        SmsResultVO vo = new SmsResultVO();
        // 获取当前日期
        LocalDateTime now = LocalDateTime.now();
        // 获取前一天日期
        LocalDateTime oneDayBefore = now.minusDays(1);
        // 格式化日期并打印
        // 定义日期时间格式,包含年-月-日 时:分:秒
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        vo.setStartTime(oneDayBefore.format(formatter));
        vo.setEndTime(now.format(formatter));
        vo.setSmsType("2");
        vo.setResCode("0");
        List<SmsResultVO> dxyjList = smsRecordClient.smsSuccessList(vo);
 
        //外呼统计
        CallTaskResultVO callTaskResult = new CallTaskResultVO();
        callTaskResult.setStartTime(oneDayBefore.format(formatter));
        callTaskResult.setEndTime(now.format(formatter));
        List<CallTaskResultVO> whtjList = (List<CallTaskResultVO>) callService.getCallResultListTemp(null, callTaskResult);
 
        HashMap<String, String> over10Params = new HashMap<>();
        //small_start_stag=0&small_end_stag=2&mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2
        over10Params.put("small_start_stag", "0.1");
        over10Params.put("mid_start_stag", "0.1");
        over10Params.put("big_start_stag", "0.1");
 
        HashMap<String, String> normalParams = new HashMap<>();
        //small_start_stag=0&small_end_stag=2&mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2
        normalParams.put("small_start_stag", "0");
        normalParams.put("mid_start_stag", "0");
        normalParams.put("big_start_stag", "0");
 
        List<TotalInfo> totalOverList = sjztmdService.getTotalOverInfo(isShow, normalParams);
        List<TotalInfo> totalOver10List = sjztmdService.getTotalOverInfo(isShow, over10Params);
 
 
        //昨日报汛内容
        QueryWrapper queryWrapper = new QueryWrapper();
        YwFloodReportInfo ywFloodReportInfo = ywFloodReportInfoService.getLatestReport(queryWrapper);
 
        byte[] data = null;
        if (MyDateUtils.isTodayInFloodSeason()) {
            data = WordUtil.GetOverInfo(totalList, dzkList, overDetailList, szInfoList, dxyjList, whtjList, ywFloodReportInfo);
        } else {
            data = WordUtil.GetNotInSeasonOverInfo(totalList, dzkList, overDetailList, szInfoList, totalOverList, totalOver10List);
 
        }
        // 创建响应实体并设置响应头,将输出流作为响应体返回给客户端
//        InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(data));
        String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        String fileName = time + "全省水库防汛情况.docx";
        MultipartFile file = new MyMultipartFile("file", fileName, "text/plain", data);
        String path = ossClient.uploadFile(fileName, file);
        return path;
    }
 
    @Override
    @GetMapping(ISjztMdClient.GET_RESERVOIR_RAINFALL_FORECAST)
    public void getReservoirRainfallForecast(List<String> dayIndexList) {
        sjztmdService.getReservoirRainfallForecast(dayIndexList);
    }
 
    @Override
    public void setGetProjectCheckStatus() throws Exception {
        tbProjectService.updateallcheck();
    }
 
    private void createFile(String filePath, byte[] bytes) {
        // 将byte[]写入文件
        try (FileOutputStream fos = new FileOutputStream(filePath)) {
            fos.write(bytes);
            System.out.println("文件已成功生成!");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("生成文件时发生错误。");
        }
    }
}