From 42922f126d7259f8a1da6a81d5ee8e9e45300278 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期五, 22 十一月 2024 15:23:22 +0800
Subject: [PATCH] 设计实现导出当前升级任务成功与失败RTU功能

---
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java |  129 +++++++++++++++++++++++++++++--------------
 1 files changed, 87 insertions(+), 42 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java
index 0fdd253..ec86f88 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java
@@ -1,7 +1,8 @@
 package com.dy.pipIrrRemote.rtuUpgrage;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.support.ExcelTypeEnum;
 import com.dy.common.aop.SsoAop;
-import com.dy.common.multiDataSource.DataSourceContext;
 import com.dy.common.softUpgrade.state.UpgradeRtu;
 import com.dy.common.softUpgrade.state.UpgradeTaskVo;
 import com.dy.common.springUtil.SpringContextUtil;
@@ -12,6 +13,8 @@
 import com.dy.pipIrrGlobal.pojoUg.UgRtuProgram;
 import com.dy.pipIrrGlobal.pojoUg.UgRtuTask;
 import com.dy.pipIrrGlobal.rtuMw.ToRtuMwCom;
+import com.dy.pipIrrGlobal.voPr.VoDivide;
+import com.dy.pipIrrGlobal.voUg.VoUgRtuResult;
 import com.dy.pipIrrGlobal.voUg.VoWatch;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.media.Content;
@@ -19,16 +22,21 @@
 import io.swagger.v3.oas.annotations.responses.ApiResponse;
 import io.swagger.v3.oas.annotations.responses.ApiResponses;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.servlet.http.HttpServletResponse;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.env.Environment;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.client.RestTemplate;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.ArrayList;
+import java.util.Base64;
 import java.util.List;
 
 /**
@@ -43,6 +51,9 @@
 public class RtuUpgradeCtrl extends ToRtuMwCom {
     @Autowired
     private RtuUpgradeSv sv ;
+
+    @Autowired
+    RtuUpgradeResSv resSv ;
 
     @Autowired
     private Environment env;
@@ -67,7 +78,7 @@
     @GetMapping(path = "/issuedTask")
     @SsoAop()
     public BaseResponse<Boolean> issuedTask(String id){
-        if(id == null || !id.trim().equals("")){
+        if(id == null || id.trim().equals("")){
             return BaseResponseUtils.buildError("浠诲姟id涓嶈兘涓虹┖") ;
         }
         UgRtuTask tpo = this.sv.selectTaskById(id) ;
@@ -87,7 +98,7 @@
             return BaseResponseUtils.buildError("浠诲姟鎵�娑夊強鐨勬帶鍒跺櫒杩樻湭璁剧疆") ;
         }
 
-        String ugCallbackUrl_rm = env.getProperty("mw." + DataSourceContext.get() + ".ugCallbackUrl_rm" );
+        String ugCallbackUrl_rm = env.getProperty("mw.ugCallbackUrl_rm" );
         if(ugCallbackUrl_rm == null || ugCallbackUrl_rm.trim().equals("")){
             return BaseResponseUtils.buildError("鏈厤缃崌绾т换鍔″洖璋冪綉鍧�") ;
         }
@@ -104,8 +115,12 @@
                 this.sv.setUpgradeTaskExecuted(id);
                 return BaseResponseUtils.buildSuccess(true) ;
             }else{
-                log.error("閫氫俊涓棿浠舵墽琛屼笅鍙戝崌绾т换鍔″け璐�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ;
-                return BaseResponseUtils.buildFail("閫氫俊涓棿浠舵墽琛屽け璐�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ;
+                String msg = res.getContent()==null?null:(String)res.getContent() ;
+                if(msg == null){
+                    msg = res.getMsg() ;
+                }
+                log.error("閫氫俊涓棿浠舵墽琛屼笅鍙戝崌绾т换鍔″け璐�" + msg) ;
+                return BaseResponseUtils.buildFail("閫氫俊涓棿浠舵墽琛屽け璐�" + msg) ;
             }
         }else{
             log.error("閫氫俊涓棿浠惰繑鍥炵粨鏋滀负null") ;
@@ -118,9 +133,28 @@
         vo.softFileName = ppo.hexFileName ;
         vo.softStoreAddr = ppo.storeRamAddr ;
         vo.softStartAddr = ppo.startRamAddr ;
-        vo.softFileData = ppo.programBytes ;
+        vo.softFileData64 = Base64.getEncoder().encodeToString(ppo.programBytes) ;
+        //vo.softFileData = ppo.programBytes ;
         vo.softBytesCalculate = ppo.programCalculateBytes ;
         vo.softByteSrc16 = ppo.programCrc16 ;
+    }
+
+
+    /**
+     * 閲嶇疆杩滅▼鍗囩骇婕旂ず绋嬪簭
+     * @return 鎿嶄綔缁撴灉
+     */
+    @GetMapping(path = "/demoReset")
+    @SsoAop()
+    public BaseResponse<Boolean> demoReset(){
+        if(RtuUpgradeStateReceiverCtrl.cache != null){
+            //return BaseResponseUtils.buildError("褰撳墠娌℃湁鍗囩骇浠诲姟") ;
+            //姝e紡杩愯鏃讹紝涓嬮潰涓よ鍘绘帀锛屼笂闈竴琛屾墦寮�
+            RtuUpgradeStateReceiverCtrl ctrl = SpringContextUtil.getBean(RtuUpgradeStateReceiverCtrl.class);
+            ctrl.resetDemo();
+            ctrl.demo();
+        }
+        return BaseResponseUtils.buildSuccess(true) ;
     }
 
     /**
@@ -134,7 +168,7 @@
                     responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                     description = "杩斿洖鎿嶄綔鎴愬姛涓庡惁鏁版嵁锛圔aseResponse.content:Boolean锛�",
                     content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
-                            schema = @Schema(implementation = Boolean.class))}
+                            schema = @Schema(implementation = VoWatch.class))}
             )
     })
     @GetMapping(path = "/curUpgradeState")
@@ -142,6 +176,8 @@
     public BaseResponse<QueryResultVo<VoWatch> > curUpgradeState(QueryVo qvo){
         if(qvo == null){
             qvo = new QueryVo();
+            qvo.pageCurr = 1 ;
+            qvo.pageSize = 49 ;
         }
         if(RtuUpgradeStateReceiverCtrl.cache == null){
             //return BaseResponseUtils.buildError("褰撳墠娌℃湁鍗囩骇浠诲姟") ;
@@ -149,41 +185,50 @@
             RtuUpgradeStateReceiverCtrl ctrl = SpringContextUtil.getBean(RtuUpgradeStateReceiverCtrl.class);
             ctrl.demo();
         }
-
-        QueryResultVo<VoWatch> rsVo = new QueryResultVo();
-        VoWatch vo = new VoWatch() ;
-        vo.upgrade = this.sv.selectTaskDetail(RtuUpgradeStateReceiverCtrl.cache.ugTaskId);
-        vo.overall = RtuUpgradeStateReceiverCtrl.cache.ugOverallState ;
-        vo.rtus = new ArrayList<>() ;
-        if(RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList != null && RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.size() > 0){
-            if(qvo.rtuAddr != null && !qvo.rtuAddr.trim().equals("")){
-                qvo.pageCurr = 1 ;
-                final String queryAddr = qvo.rtuAddr ;
-                RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.stream().filter(rtu -> rtu.rtuAddr.equals(queryAddr)).forEach(ugRtu -> {
-                    VoWatch.VoWatchRtu rtu = new VoWatch.VoWatchRtu() ;
-                    rtu.fromCache(ugRtu) ;
-                    vo.rtus.add(rtu) ;
-                }); ;
-            }else{
-                if(qvo.pageCurr < 1){
-                    qvo.pageCurr = 1 ;
-                }
-                int start = (qvo.pageCurr - 1) * qvo.pageSize ;
-                if(start >= RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.size()){
-                    start = RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.size() - 1 ;
-                }
-                for(int i = start; i < (start + qvo.pageSize) && i < RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.size(); i++){
-                    UpgradeRtu ugRtu = RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.get(i) ;
-                    VoWatch.VoWatchRtu rtu = new VoWatch.VoWatchRtu() ;
-                    rtu.fromCache(ugRtu) ;
-                    vo.rtus.add(rtu) ;
-                }
-            }
-        }
-        rsVo.obj = vo ;
-        rsVo.pageSize = qvo.pageSize ;
-        rsVo.pageCurr = qvo.pageCurr ;
-        rsVo.calculateAndSet(0L + vo.rtus.size(), null);
+        QueryResultVo<VoWatch> rsVo = this.resSv.curUpgradeState(qvo) ;
         return BaseResponseUtils.buildSuccess(rsVo) ;
     }
+
+    /**
+     * 瀵煎嚭鍗囩骇澶辫触RTU鍒楄〃
+     * @param response
+     */
+    @RequestMapping(value = "/exportUgFail", method = RequestMethod.GET)
+    public void exportUgFail(HttpServletResponse response) throws Exception {
+        setExcelRespProp(response, "鍗囩骇澶辫触RTU鍒楄〃");
+        List<VoUgRtuResult> rsList = resSv.exportUgFail();
+        EasyExcel.write(response.getOutputStream())
+                .head(VoUgRtuResult.class)
+                .excelType(ExcelTypeEnum.XLSX)
+                .sheet("鍗囩骇澶辫触RTU鍒楄〃")
+                .doWrite(rsList);
+    }
+
+
+    /**
+     * 瀵煎嚭闀跨骇鎴愬姛RTU鍒楄〃
+     * @param response
+     */
+    @RequestMapping(value = "/exportUgSuccess", method = RequestMethod.GET)
+    public void exportUgSuccess(HttpServletResponse response) throws Exception {
+        setExcelRespProp(response, "鍗囩骇鎴愬姛RTU鍒楄〃");
+        List<VoUgRtuResult> rsList = resSv.exportUgSuccess();
+        EasyExcel.write(response.getOutputStream())
+                .head(VoUgRtuResult.class)
+                .excelType(ExcelTypeEnum.XLSX)
+                .sheet("鍗囩骇鎴愬姛RTU鍒楄〃")
+                .doWrite(rsList);
+    }
+
+
+    /**
+     * 璁剧疆excel涓嬭浇鍝嶅簲澶村睘鎬�
+     */
+    private void setExcelRespProp(HttpServletResponse response, String rawFileName) throws UnsupportedEncodingException {
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+        response.setCharacterEncoding("utf-8");
+        String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20");
+        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
+    }
+
 }

--
Gitblit v1.8.0