Procházet zdrojové kódy

增加数据查询对比页面动态列表导出excel功能

xusl před 9 měsíci
rodič
revize
bd510dec40

+ 1 - 0
ipp-ap/src/api/forecastpowerultrashortterm.js

@@ -125,3 +125,4 @@ export function getCenterData(obj) {
     data: obj
   })
 }
+

+ 45 - 19
ipp-ap/src/router/axios.js

@@ -23,9 +23,9 @@ NProgress.configure({
 axios.interceptors.request.use(config => {
   NProgress.start() // start progress bar
   const isToken = (config.headers || {}).isToken === false
-  let token =  store.getters.access_token
+  let token = store.getters.access_token
   if (token && !isToken) {
-    config.headers['Authorization'] =  token// token
+    config.headers['Authorization'] = token// token
   }
   // headers中配置serialize为true开启序列化
   if (config.methods === 'post' && config.headers.serialize) {
@@ -36,7 +36,7 @@ axios.interceptors.request.use(config => {
   // 处理get 请求的数组 springmvc 可以处理
   if (config.method === 'get') {
     config.paramsSerializer = function (params) {
-      return qs.stringify(params, { arrayFormat: 'repeat' })
+      return qs.stringify(params, {arrayFormat: 'repeat'})
     }
   }
 
@@ -48,25 +48,51 @@ axios.interceptors.request.use(config => {
 
 // HTTPresponse拦截
 axios.interceptors.response.use(res => {
-  NProgress.done()
-  const status = Number(res.status) || 200
-  const message = res.data.msg || errorCode[status] || errorCode['default']
-  if (status === 401) {
-    store.dispatch('FedLogOut').then(() => {
-      router.push({path: '/login'})
-    })
-    return
-  }
 
-  if (status !== 200 || res.data.code === 1) {
-    Message({
-      message: message,
-      type: 'error'
-    })
-    return Promise.reject(new Error(message))
+  if (res.headers && res.headers['content-type'] && (res.headers['content-type'].indexOf('application/x-msdownload') != -1)) {
+    // 创建一个blob对象,file的一种
+    const blob = new Blob([res.data], {type: res.headers['content-type']})
+    const fileName = decodeURI(res.headers['content-disposition'].split('=')[1])
+    if (window.navigator.msSaveOrOpenBlob) {
+      // 兼容IE10
+      navigator.msSaveBlob(blob, fileName)
+    } else {
+      // 非IE下载
+      const elink = document.createElement('a')
+      elink.download = fileName
+      elink.style.display = 'none'
+      elink.href = URL.createObjectURL(blob)
+      document.body.appendChild(elink)
+      elink.click()
+      URL.revokeObjectURL(elink.href) // 释放URL 对象
+      document.body.removeChild(elink)
+    }
+
+    res.data = ''
+    res.headers['content-type'] = 'text/json'
+    return res
+  } else {
+    NProgress.done()
+    const status = Number(res.status) || 200
+    const message = res.data.msg || errorCode[status] || errorCode['default']
+    if (status === 401) {
+      store.dispatch('FedLogOut').then(() => {
+        router.push({path: '/login'})
+      })
+      return
+    }
+
+    if (status !== 200 || res.data.code === 1) {
+      Message({
+        message: message,
+        type: 'error'
+      })
+      return Promise.reject(new Error(message))
+    }
+
+    return res
   }
 
-  return res
 }, error => {
   NProgress.done()
   return Promise.reject(new Error(error))

+ 2 - 0
ipp-ap/src/util/request.js

@@ -10,7 +10,9 @@ const service = axios.create({
 
 // request interceptor
 service.interceptors.request.use(
+
   config => {
+
     // do something before request is sent
     if (store.getters.token) {
       // let each request carry token

+ 28 - 0
ipp-ap/src/views/idp/data/forecastpowerdata/index.vue

@@ -89,6 +89,7 @@
 
       <div class="timeQuery" style="display: inline-block">
         &#12288;<el-button size="small" :loading="loading" @click="getCompositeData">查询</el-button>
+        <el-button size="small" :loading="loading" @click="exportDataEvent">导出</el-button>
       </div>
     </div>
     <el-tabs type="card" v-model="activeName">
@@ -586,7 +587,34 @@ export default {
         this.tableLoading = false
       })
     },
+    exportDataEvent() {
+      if (this.startTime==null){
+        this.$message.warning('请选择开始时间')
+        return
+      }
+      if (this.endTime==null){
+        this.$message.warning('请选择结束时间')
+        return
+      }
+
+      this.$axios.get("/powerstationstatusdata/exportDataEvent/" + this.stationCode + "/" + this.startTime + "/" + this.endTime + '/' + this.cdqQueryPoint + '/' + this.dqQueryPoint + '/' + this.forecastManufactor, {
+        responseType: 'blob'// 用于解决中文乱码
+      }).then((response) => {
+        this.loading = false
+      }).catch((error) => {
+        this.loading = false
+        this.$message.error('导出失败' + error)
+      })
+    },
     getCompositeData() {
+      if (this.startTime==null){
+        this.$message.warning('请选择开始时间')
+        return
+      }
+      if (this.endTime==null){
+        this.$message.warning('请选择结束时间')
+        return
+      }
       const param = new URLSearchParams()
       param.append('stationCode', this.stationCode)
       param.append('startTime', this.startTime)

+ 95 - 1
ipp-idp/src/main/java/com/jiayue/ipp/idp/controller/PowerStationStatusDataController.java

@@ -1,7 +1,12 @@
 package com.jiayue.ipp.idp.controller;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
 import com.jiayue.ipp.common.data.entity.PowerStationStatusData;
 import com.jiayue.ipp.idp.service.PowerStationStatusDataService;
 import com.jiayue.ipp.idp.util.R;
@@ -11,8 +16,15 @@ import lombok.RequiredArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.net.URLEncoder;
 import java.text.ParseException;
-import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 
 /**
@@ -92,4 +104,86 @@ public class PowerStationStatusDataController {
             Long endTime) {
         return R.ok(powerStationStatusDataService.getCenterData(new Date(startTime), new Date(endTime)));
     }
+    @GetMapping(value = {"/exportDataEvent/{stationCode}/{startTime}/{endTime}/{cdqPoint}/{dqPoint}/{forecastManufactor}","/exportDataEvent/{stationCode}/{startTime}/{endTime}/{cdqPoint}/{dqPoint}" })
+    public R exportDataEvent(
+            @PathVariable("stationCode") String stationCode,
+            @PathVariable("startTime") Long startTime,
+            @PathVariable("endTime") Long endTime,
+            @PathVariable("cdqPoint") Integer cdqPoint,
+            @PathVariable("dqPoint") Integer dqPoint,
+            @PathVariable(value = "forecastManufactor",required = false) String forecastManufactor,
+            HttpServletResponse response) {
+
+
+        try {
+            Map<String, List> map = powerStationStatusDataService.getCompositeData(stationCode, new Date(startTime), new Date(endTime), forecastManufactor, cdqPoint,dqPoint);
+
+            ExcelWriter writer = ExcelUtil.getWriter(true);
+            writer.renameSheet(0, "数据查询对比");
+            List<String> header = new ArrayList();
+            List<String> headFieldName = new ArrayList();
+
+            List<Map> headerList = map.get("fromHead");
+            for (Map headMap:headerList){
+                header.add(headMap.get("label").toString());
+                headFieldName.add(headMap.get("field").toString());
+            }
+            List<List<String>> rowHeather = CollUtil.newArrayList();
+            rowHeather.add(header);
+
+            List<Map<String,Object>> contentList = map.get("tableList");
+
+            List<List<String>> rowsContent = CollUtil.newArrayList();
+
+            for (Map<String,Object> contentMap : contentList) {
+                List<String> rowList = new ArrayList();
+                for (String fieldStr:headFieldName){
+                    if (contentMap.get(fieldStr)==null){
+                        rowList.add("");
+                    }
+                    else{
+                        rowList.add(contentMap.get(fieldStr).toString());
+                    }
+                }
+                rowHeather.add(rowList);
+            }
+
+            writer.write(rowHeather, true);
+//
+//            ExcelWriter monthSheet = writer.setSheet("月");
+//
+//            List<List<String>> rowsMonth = CollUtil.newArrayList();
+//            rowsMonth.add(rowHeather);
+//            for (Map<String, BigDecimal> monthList : monthLists) {
+//                List<String> rowContent = CollUtil.newArrayList();
+//                rowContent.add(monthList.get("time") + "");
+//                rowContent.add(monthList.get("capacity") + "");
+//                rowContent.add(monthList.get("hourDA") + "");
+//                rowContent.add(monthList.get("ultraShortTermAccuracy") + "");
+//                rowContent.add(monthList.get("theoreticalPowerGeneration") + "");
+//                rowContent.add(monthList.get("actualPowerGeneration") + "");
+//                rowContent.add(monthList.get("prValue") + "");
+//                rowsMonth.add(rowContent);
+//            }
+//
+//            monthSheet.write(rowsMonth, true);
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
+            String fileName = "数据对比查询" + simpleDateFormat.format(startTime) + "至" + simpleDateFormat.format(endTime) + ".xlsx";
+            response.setContentType("application/x-msdownload;charset=utf-8");
+            response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
+            ServletOutputStream out = null;
+            out = response.getOutputStream();
+            writer.flush(out, true);
+            // 关闭writer,释放内存
+            writer.close();
+            //此处记得关闭输出Servlet流
+            IoUtil.close(out);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return R.ok();
+
+    }
 }

+ 22 - 17
ipp-idp/src/main/java/com/jiayue/ipp/idp/job/SendJyDqData.java

@@ -5,6 +5,7 @@ import com.jiayue.ipp.common.data.entity.an.ParsingChannel;
 import com.jiayue.ipp.common.data.entity.an.ParsingUrl;
 import com.jiayue.ipp.idp.service.DqInterveneService;
 import com.jiayue.ipp.idp.service.ForecastPowerShortTermService;
+import com.jiayue.ipp.idp.service.SysParameterService;
 import com.jiayue.ipp.idp.service.an.ParsingChannelService;
 import com.jiayue.ipp.idp.service.an.ParsingUrlService;
 import com.jiayue.ipp.idp.service.impl.SendJyDqDataServiceImpl;
@@ -38,26 +39,30 @@ public class SendJyDqData {
     SendJyDqDataServiceImpl sendDqDownloadFileImpl;
     @Autowired
     ParsingUrlService parsingUrlService;
+    @Autowired
+    SysParameterService sysParameterService;
 
-    @Scheduled(cron = "0 0 6 * * ?")
+    @Scheduled(cron = "0 0/1 * * * ?")
     public void sendJyDqData() {
-        log.info("中心侧下发DQ数据定时开始");
-        // 获取ftp通道
-        LambdaQueryWrapper<ParsingChannel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
-        lambdaQueryWrapper.eq(ParsingChannel::getAnChannelType, "E1");
-        lambdaQueryWrapper.eq(ParsingChannel::getUseStatus, "E1");
-        List<ParsingChannel> parsingChannels = parsingChannelService.list(lambdaQueryWrapper);
-        //遍历解析路径,对文件进行解析
-        for (ParsingChannel parsingChannel : parsingChannels) {
-            LambdaQueryWrapper<ParsingUrl> urlWrapper = new LambdaQueryWrapper<>();
-            urlWrapper.eq(ParsingUrl::getUrlStatus, "1");
-            urlWrapper.eq(ParsingUrl::getCId, parsingChannel.getId());
-            List<ParsingUrl> parsingUrlList = parsingUrlService.list(urlWrapper);
-            if (parsingUrlList.size()>0){
-                sendDqDownloadFileImpl.sendDqDownloadFile(parsingUrlList.get(0).getStationCode(),parsingChannel.getUsername());
+        int autoSendDq = Integer.parseInt(sysParameterService.getSysParameterAndAll("AUTO_SEND_DQ", "0"));
+        if (autoSendDq==1){
+            log.info("中心侧下发DQ数据定时开始");
+            // 获取ftp通道
+            LambdaQueryWrapper<ParsingChannel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+            lambdaQueryWrapper.eq(ParsingChannel::getAnChannelType, "E1");
+            lambdaQueryWrapper.eq(ParsingChannel::getUseStatus, "E1");
+            List<ParsingChannel> parsingChannels = parsingChannelService.list(lambdaQueryWrapper);
+            //遍历解析路径,对文件进行解析
+            for (ParsingChannel parsingChannel : parsingChannels) {
+                LambdaQueryWrapper<ParsingUrl> urlWrapper = new LambdaQueryWrapper<>();
+                urlWrapper.eq(ParsingUrl::getUrlStatus, "1");
+                urlWrapper.eq(ParsingUrl::getCId, parsingChannel.getId());
+                List<ParsingUrl> parsingUrlList = parsingUrlService.list(urlWrapper);
+                if (parsingUrlList.size()>0){
+                    sendDqDownloadFileImpl.sendDqDownloadFile(parsingUrlList.get(0).getStationCode(),parsingChannel.getUsername());
+                }
             }
+            log.info("中心侧下发DQ数据定时结束");
         }
-        log.info("中心侧下发DQ数据定时结束");
-
     }
 }

+ 2 - 0
ipp-idp/src/main/java/com/jiayue/ipp/idp/service/SysParameterService.java

@@ -15,4 +15,6 @@ public interface SysParameterService extends IService<SysParameter> {
     String getSysParameterAndStationCode(String sysKey, String defaultValue, String stationCode);
 
     SysParameter getParameterBySysKey(final String sysKey);
+
+    String getSysParameterAndAll(String sysKey, String defaultValue);
 }

+ 1 - 1
ipp-idp/src/main/java/com/jiayue/ipp/idp/service/impl/SendJyDqDataServiceImpl.java

@@ -49,7 +49,7 @@ public class SendJyDqDataServiceImpl{
     public void sendDqDownloadFile(String stationCode,String ftpAccount){
         try{
             // 获取人工干预下发未来短期数据天数
-            int dqForecastDays = Integer.parseInt(sysParameterService.getSysParameterAndStationCode("SEND_DQ_DAYS", "10", stationCode));
+            int dqForecastDays = Integer.parseInt(sysParameterService.getSysParameterAndAll("SEND_DQ_DAYS", "10"));
 
             String distPath = "/home"+ File.separator+ftpAccount+File.separator+"download";
             File dirFile = new File(distPath);

+ 15 - 0
ipp-idp/src/main/java/com/jiayue/ipp/idp/service/impl/SysParameterServiceImpl.java

@@ -43,6 +43,21 @@ public class SysParameterServiceImpl extends ServiceImpl<SysParameterMapper, Sys
 
     }
 
+    @Override
+    public String getSysParameterAndAll(String sysKey, String defaultValue) {
+        QueryWrapper<SysParameter> wrapper = new QueryWrapper<>();
+        wrapper.eq("station_code", "ALL");
+        if (sysKey != null && !sysKey.equals("")) {
+            wrapper.eq("sys_key", sysKey);
+        }
+        List<SysParameter> sysParameterList = baseMapper.selectList(wrapper);
+        if (sysParameterList.isEmpty()) {
+            return defaultValue;
+        } else {
+            return sysParameterList.get(0).getSysValue();
+        }
+    }
+
     /**
      * 查询参数值
      *