Explorar el Código

fix定时导出、手动导出;fix查询各状态按系统设置的名称

LLL hace 8 meses
padre
commit
fbc18f2829

+ 9 - 2
jeecg-module-interlock/src/main/java/org/jeecg/modules/detail/mapper/xml/InterlockDetailMapper.xml

@@ -18,8 +18,15 @@
     <!-- 联锁总表-分页列表查询(各种逻辑状态)-->
     <select id="getPage" parameterType="org.jeecg.modules.summary.vo.InterlockSummaryVO" resultType="org.jeecg.modules.summary.vo.InterlockSummaryVO">
         select d.id, d.summaryid, d.interlockname, d.interlock_condition, d.interlock_condition_tag, d.instrument_status, d.control_system_status,
-               s.interlock_status, s.loop_health_level, d.bypass, s.interlock_apparatus_id, s.interlock_system_id
-        from interlock_detail d left join interlock_summary s on d.summaryid = s.id
+               s.interlock_status, s.loop_health_level, d.bypass, s.interlock_apparatus_id, s.interlock_system_id,
+        h1.interlock_status_name , h2.bypass_name ,
+        h3.instrument_status_name , h4.control_system_status_name
+        from interlock_detail d
+            left join interlock_summary s on d.summaryid = s.id
+            left join interlock_base_hy h1 on h1.interlock_status = s.interlock_status and h1.interlock_system_id = s.interlock_system_id
+            left join interlock_base_hy h2 on h2.bypass = d.bypass and h2.interlock_system_id = s.interlock_system_id
+            left join interlock_base_hy h3 on h3.instrument_status = d.instrument_status and h3.interlock_system_id = s.interlock_system_id
+            left join interlock_base_hy h4 on h4.control_system_status = d.control_system_status and h4.interlock_system_id = s.interlock_system_id
         <where>
             <if test="interlockSummaryVO.interlockApparatusId != null and interlockSummaryVO.interlockApparatusId != ''"> and s.interlock_apparatus_id like concat('%', #{interlockSummaryVO.interlockApparatusId}, '%')</if>
             <if test="interlockSummaryVO.interlockSystemId != null and interlockSummaryVO.interlockSystemId != ''"> and s.interlock_system_id like concat('%', #{interlockSummaryVO.interlockSystemId}, '%')</if>

+ 46 - 37
jeecg-module-interlock/src/main/java/org/jeecg/modules/detail/service/impl/InterlockDetailServiceImpl.java

@@ -37,7 +37,52 @@ public class InterlockDetailServiceImpl extends ServiceImpl<InterlockDetailMappe
     /**联锁详细信息表分页列表查询*/
     public IPage<InterlockDetailQueryVO> getPage2(Page<InterlockDetailQueryVO> page, InterlockDetailQueryDTO dto){
         IPage<InterlockDetailQueryVO> voiPage = interlockDetailMapper.getPage2(page, dto);
-        InterlockBase base = interlockBaseMapper.selectById(dto.getInterlockSystemId());
+        return zhDetailQueryVOIPage(voiPage,dto.getInterlockSystemId());
+    }
+
+
+    /**联锁总表-分页列表查询(各种逻辑状态)*/
+    public IPage<InterlockSummaryVO> getPage(Page<InterlockSummaryVO> page, InterlockSummaryVO interlockSummaryVO) {
+//        IPage<InterlockSummaryVO> voiPage = interlockDetailMapper.getPage(page, interlockSummaryVO);
+        return interlockDetailMapper.getPage(page, interlockSummaryVO);
+    }
+
+    /**
+    *   author: dzc
+    *   version: 1.0
+    *   des: 根据联锁id查询出所有的联锁条件
+    *   date: 2024/5/30
+    */
+    @Override
+    public List<InterlockDetail> selectListBySummaryId(String summaryId) {
+        return interlockDetailMapper.selectListBySummaryId(summaryId);
+    }
+
+    private IPage<InterlockSummaryVO> zhSummaryVOIPage(IPage<InterlockSummaryVO> voiPage){
+        List<InterlockSummaryVO> list = voiPage.getRecords().stream().map(i->{
+            InterlockBase base = interlockBaseMapper.selectById(i.getInterlockSystemId());
+            if(base != null){
+                //控制系统状态转换
+                if(base.getControlSystemStatusNormal().equals(i.getControlSystemStatus())) i.setControlSystemStatusName(base.getControlSystemStatusNormalName());
+                else i.setControlSystemStatusName(base.getControlSystemStatusAbnormalName());
+                //联锁状态转换
+                if(base.getInterlockStatusTy().equals(i.getInterlockStatus())) i.setInterlockStatusName(base.getInterlockStatusTyName());
+                else i.setInterlockStatusName(base.getInterlockStatusWtyName());
+                //旁路状态转换
+                if(base.getBypassYes().equals(i.getBypass())) i.setBypassName(base.getBypassYesName());
+                else i.setBypassName(base.getBypassNoName());
+                //仪表状态转换
+                if(base.getInstrumentStatusNormal().equals(i.getInstrumentStatus())) i.setInstrumentStatusName(base.getInstrumentStatusNormalName());
+                else i.setInstrumentStatusName(base.getInstrumentStatusAbnormalName());
+            }
+            return i;
+        }).collect(Collectors.toList());
+        voiPage.setRecords(list);
+        return voiPage;
+    }
+
+    private IPage<InterlockDetailQueryVO> zhDetailQueryVOIPage(IPage<InterlockDetailQueryVO> voiPage, String interlockSystemId){
+        InterlockBase base = interlockBaseMapper.selectById(interlockSystemId);
         if(base != null){
             List<InterlockDetailQueryVO> list = voiPage.getRecords().stream().map(i->{
                 //旁路状态转换
@@ -67,40 +112,4 @@ public class InterlockDetailServiceImpl extends ServiceImpl<InterlockDetailMappe
         return voiPage;
     }
 
-
-    /**联锁总表-分页列表查询(各种逻辑状态)*/
-    public IPage<InterlockSummaryVO> getPage(Page<InterlockSummaryVO> page, InterlockSummaryVO interlockSummaryVO) {
-        IPage<InterlockSummaryVO> voiPage = interlockDetailMapper.getPage(page, interlockSummaryVO);
-        List<InterlockSummaryVO> list = voiPage.getRecords().stream().map(i->{
-            InterlockBase base = interlockBaseMapper.selectById(i.getInterlockSystemId());
-            if(base != null){
-                //控制系统状态转换
-                if(base.getControlSystemStatusNormal().equals(i.getControlSystemStatus())) i.setControlSystemStatus_dictText(base.getControlSystemStatusNormalName());
-                else i.setControlSystemStatus_dictText(base.getControlSystemStatusAbnormalName());
-                //联锁状态转换
-                if(base.getInterlockStatusTy().equals(i.getInterlockStatus())) i.setInterlockStatus_dictText(base.getInterlockStatusTyName());
-                else i.setInterlockStatus_dictText(base.getInterlockStatusWtyName());
-                //旁路状态转换
-                if(base.getBypassYes().equals(i.getBypass())) i.setBypass_dictText(base.getBypassYesName());
-                else i.setBypass_dictText(base.getBypassNoName());
-                //仪表状态转换
-                if(base.getInstrumentStatusNormal().equals(i.getInstrumentStatus())) i.setInstrumentStatus_dictText(base.getInstrumentStatusNormalName());
-                else i.setInstrumentStatus_dictText(base.getInstrumentStatusAbnormalName());
-            }
-            return i;
-        }).collect(Collectors.toList());
-        voiPage.setRecords(list);
-        return voiPage;
-    }
-
-    /**
-    *   author: dzc
-    *   version: 1.0
-    *   des: 根据联锁id查询出所有的联锁条件
-    *   date: 2024/5/30
-    */
-    @Override
-    public List<InterlockDetail> selectListBySummaryId(String summaryId) {
-        return interlockDetailMapper.selectListBySummaryId(summaryId);
-    }
 }

+ 45 - 6
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/controller/InterlockDetailHistoryController.java

@@ -1,21 +1,23 @@
 package org.jeecg.modules.history.controller;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
 import java.util.stream.Collectors;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.detail.dto.InterlockDetailQueryDTO;
 import org.jeecg.modules.history.dto.InterlockHistoryQueryDTO;
 import org.jeecg.modules.history.entity.InterlockDetailHistory;
+import org.jeecg.modules.history.mapper.InterlockSummaryHistoryMapper;
 import org.jeecg.modules.history.service.IInterlockDetailHistoryService;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -24,6 +26,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
 
 import org.jeecg.modules.history.vo.InterlockDetailHistoryQueryVO;
+import org.jeecg.modules.history.vo.InterlockHistoryDistinctZZXTVO;
 import org.jeecg.modules.history.vo.InterlockSummaryHistoryVO;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
@@ -32,6 +35,8 @@ import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
@@ -56,18 +61,52 @@ public class InterlockDetailHistoryController extends JeecgController<InterlockD
 	private IInterlockDetailHistoryService interlockDetailHistoryService;
 
 
+	 @Autowired
+	 @SuppressWarnings("all")
+	 private InterlockSummaryHistoryMapper summaryHistoryMapper;
 
 
 	 /**
 	  * 手动导出excel
 	  */
 	 //@RequiresPermissions("org.jeecg.modules:interlock_detail_history:exportXls")
-	 @RequestMapping(value = "/sdexportLS")
-	 @ApiOperation("手动导出excel")
+	 @RequestMapping(value = "/sdexportLS1")
+	 @ApiOperation("手动导出excel")
 	 public ModelAndView exportXls1(HttpServletRequest request, InterlockHistoryQueryDTO dto) {
 		 return interlockDetailHistoryService.exportXls1(dto, InterlockSummaryHistoryVO.class, "联锁历史数据");
 	 }
 
+	 @GetMapping(value = "/sdexportLS")
+	 @ApiOperation("..............测试手动导出excel")
+	 public void downloadExcel(HttpServletRequest request, HttpServletResponse response, InterlockHistoryQueryDTO dto) {
+
+		 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
+		 String timestamp = dateFormat.format(new Date());
+		 String fileName = String.format("联锁历史数据" + "报表_%s.xlsx", timestamp);
+
+	 	List<InterlockHistoryDistinctZZXTVO> zzxtvoList = summaryHistoryMapper.getDistinctZZXTSummaryList(dto);
+
+	 	Workbook workbook = new XSSFWorkbook();
+	 	try {
+	 		workbook = interlockDetailHistoryService.exportXlsToFile(dto, zzxtvoList, InterlockSummaryHistoryVO.class, "联锁历史数据");
+	 	} catch (IOException e) {
+	 		e.printStackTrace();
+	 	}
+
+		 // 设置响应头使浏览器能够下载文件
+		 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+		 response.setHeader("Content-Disposition", "attachment; filename=sample.xlsx");
+
+		 // 将Excel文件写入响应输出流
+		 try {
+			 workbook.write(response.getOutputStream());
+			 workbook.close();
+		 } catch (IOException e) {
+			 e.printStackTrace();
+		 }
+
+	 }
+
 
 	 /**
 	 * 联锁历史数据——各种逻辑状态分页查询

+ 10 - 3
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/mapper/xml/InterlockDetailHistoryMapper.xml

@@ -19,8 +19,15 @@
     <!-- 联锁总历史数据表-分页列表查询(各种逻辑状态)-->
     <select id="getPage" parameterType="org.jeecg.modules.history.dto.InterlockHistoryQueryDTO" resultType="org.jeecg.modules.history.vo.InterlockSummaryHistoryVO">
         select d.id, d.summaryid, d.interlockname, d.interlock_condition, d.interlock_condition_tag, d.instrument_status, d.control_system_status,
-        s.interlock_status, s.loop_health_level, d.bypass, s.tag_time, d.summary_origin_id
-        from interlock_detail_history d left join interlock_summary_history s on d.summaryid = s.id
+        s.interlock_status, s.loop_health_level, d.bypass, s.tag_time, d.summary_origin_id, s.interlock_apparatus_id, s.interlock_system_id,
+        h1.interlock_status_name as interlockStatus_dictText, h2.bypass_name as bypass_dictText,
+        h3.instrument_status_name as instrument_status_dictText, h4.control_system_status_name as controlSystemStatus_dictText
+        from interlock_detail_history d
+        left join interlock_summary_history s on d.summaryid = s.id
+        left join interlock_base_hy h1 on h1.interlock_status = s.interlock_status and h1.interlock_system_id = s.interlock_system_id
+        left join interlock_base_hy h2 on h2.bypass = d.bypass and h2.interlock_system_id = s.interlock_system_id
+        left join interlock_base_hy h3 on h3.instrument_status = d.instrument_status and h3.interlock_system_id = s.interlock_system_id
+        left join interlock_base_hy h4 on h4.control_system_status = d.control_system_status and h4.interlock_system_id = s.interlock_system_id
         <where>
             <if test="dto.interlockSystemId != null and dto.interlockSystemId != ''"> and s.interlock_system_id =  #{dto.interlockSystemId}</if>
             <if test="dto.interlockApparatusId != null and dto.interlockApparatusId != ''"> and s.interlock_apparatus_id =  #{dto.interlockApparatusId}</if>
@@ -39,7 +46,7 @@
                 <![CDATA[ AND TO_TIMESTAMP(s.tag_time, 'YYYY-MM-DD HH24:MI:SS') < #{dto.endTime} ]]>
             </if>
         </where>
-        order by s.create_time desc
+        order by s.tag_time desc
     </select>
 
     <!-- 联锁总历史数据表查询(各种逻辑状态)——用于手动导出  -->

+ 37 - 4
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/quartz/ReportJob.java

@@ -1,9 +1,13 @@
 package org.jeecg.modules.history.quartz;
 
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.history.dto.InterlockHistoryQueryDTO;
+import org.jeecg.modules.history.mapper.InterlockSummaryHistoryMapper;
 import org.jeecg.modules.history.service.IInterlockDetailHistoryService;
+import org.jeecg.modules.history.vo.InterlockHistoryDistinctZZXTVO;
 import org.jeecg.modules.history.vo.InterlockSummaryHistoryVO;
 import org.jeecg.modules.iotedgeCollectData.service.RestClientService;
 import org.jeecg.modules.report.entity.InterlockDataReport;
@@ -15,10 +19,12 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 功能描述
@@ -40,6 +46,11 @@ public class ReportJob implements Job {
     @Autowired
     private RestClientService restClientService;
 
+    @Autowired
+    @SuppressWarnings("all")
+    private InterlockSummaryHistoryMapper summaryHistoryMapper;
+
+
     /**
      * 若参数变量名
      */
@@ -120,10 +131,32 @@ public class ReportJob implements Job {
 
         String filePath = fileUrlPrex  + fileName;
 
-        try {
-            if(0 == interlockDetailHistoryService.exportXlsToFile(dto, InterlockSummaryHistoryVO.class, "联锁历史数据", filePath)) return;
-        } catch (IOException e) {
-            e.printStackTrace();
+        List< InterlockHistoryDistinctZZXTVO > zzxtvoList = summaryHistoryMapper.getDistinctZZXTSummaryList(dto);
+
+        if(zzxtvoList == null || zzxtvoList.size()==0) return;
+        else {
+            Workbook workbook = new XSSFWorkbook();
+            try {
+                workbook = interlockDetailHistoryService.exportXlsToFile(dto, zzxtvoList, InterlockSummaryHistoryVO.class, "联锁历史数据");
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+            try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
+                workbook.write(fileOut);
+            } catch (IOException e) {
+                // 处理异常
+                e.printStackTrace();
+            } finally {
+                try {
+                    if (workbook != null) {
+                        workbook.close();
+                    }
+                } catch (IOException e) {
+                    // 处理关闭 workbook 时可能发生的异常
+                    e.printStackTrace();
+                }
+            }
         }
 
         //新增报表记录

+ 6 - 1
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/service/IInterlockDetailHistoryService.java

@@ -2,14 +2,19 @@ package org.jeecg.modules.history.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.jeecg.modules.detail.dto.InterlockDetailQueryDTO;
 import org.jeecg.modules.history.dto.InterlockHistoryQueryDTO;
 import org.jeecg.modules.history.entity.InterlockDetailHistory;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.history.vo.InterlockDetailHistoryQueryVO;
+import org.jeecg.modules.history.vo.InterlockHistoryDistinctZZXTVO;
 import org.jeecg.modules.history.vo.InterlockSummaryHistoryVO;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.servlet.ModelAndView;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.List;
 
@@ -45,7 +50,7 @@ public interface IInterlockDetailHistoryService extends IService<InterlockDetail
     /**
      * 导定时任务导出excel
      */
-    public Integer exportXlsToFile(InterlockHistoryQueryDTO dto, Class<InterlockSummaryHistoryVO> clazz, String title, String filePath) throws IOException;
+    public Workbook exportXlsToFile(InterlockHistoryQueryDTO dto, List<InterlockHistoryDistinctZZXTVO> zzxtvoList, Class<InterlockSummaryHistoryVO> clazz, String title) throws IOException;
 
 
     /**

+ 203 - 76
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/service/impl/InterlockDetailHistoryServiceImpl.java

@@ -8,8 +8,10 @@ import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.modules.base.entity.InterlockBase;
 import org.jeecg.modules.base.mapper.InterlockBaseMapper;
 import org.jeecg.modules.detail.dto.InterlockDetailQueryDTO;
+import org.jeecg.modules.detail.vo.InterlockDetailQueryVO;
 import org.jeecg.modules.history.convert.InterlockSummaryHistoryConvert;
 import org.jeecg.modules.history.dto.InterlockHistoryQueryDTO;
 import org.jeecg.modules.history.entity.InterlockDetailHistory;
@@ -19,21 +21,25 @@ import org.jeecg.modules.history.service.IInterlockDetailHistoryService;
 import org.jeecg.modules.history.vo.InterlockDetailHistoryQueryVO;
 import org.jeecg.modules.history.vo.InterlockHistoryDistinctZZXTVO;
 import org.jeecg.modules.history.vo.InterlockSummaryHistoryVO;
+import org.jeecg.modules.summary.vo.InterlockSummaryVO;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.web.servlet.ModelAndView;
 
-import java.io.FileOutputStream;
-import java.io.IOException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -62,13 +68,15 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
      * 联锁历史数据详细信息-分页查询
      */
     public IPage<InterlockDetailHistoryQueryVO> getPage2(Page<InterlockDetailHistoryQueryVO> page, InterlockDetailQueryDTO dto){
-        return interlockDetailHistoryMapper.getPage2(page, dto);
+        IPage<InterlockDetailHistoryQueryVO> voiPage = interlockDetailHistoryMapper.getPage2(page, dto);
+        return zhDetailHistoryQueryVOIPage(voiPage,dto.getInterlockSystemId());
     }
 
     /**
      * 联锁历史数据——各种逻辑状态分页查询
      */
     public IPage<InterlockSummaryHistoryVO> getPage(Page<InterlockSummaryHistoryVO> page, InterlockHistoryQueryDTO dto){
+//        IPage<InterlockSummaryHistoryVO> voiPage = interlockDetailHistoryMapper.getPage(page, dto);
         return interlockDetailHistoryMapper.getPage(page, dto);
     }
 
@@ -149,27 +157,72 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
     /**
      * 导定时任务导出excel
      */
-    public Integer exportXlsToFile(InterlockHistoryQueryDTO dto, Class<InterlockSummaryHistoryVO> clazz, String title, String filePath) throws IOException {
+    public Workbook exportXlsToFile(InterlockHistoryQueryDTO dto, List<InterlockHistoryDistinctZZXTVO> zzxtvoList, Class<InterlockSummaryHistoryVO> clazz, String title) throws IOException {
 
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String formattedBeginTime = dto.getBeginTime() != null ? sdf.format(dto.getBeginTime()) : "";
         String formattedEndTime = dto.getEndTime() != null ? sdf.format(dto.getEndTime()) : "";
 
-        List<InterlockHistoryDistinctZZXTVO> zzxtvoList = summaryHistoryMapper.getDistinctZZXTSummaryList(dto);
+        Workbook workbook = new XSSFWorkbook();
 
-        if(zzxtvoList == null || zzxtvoList.size()==0) return 0;
+        // 创建字体对象
+        Font font = workbook.createFont();
+        font.setBold(true); // 设置字体加粗
+
+        // 创建第一行的样式
+        CellStyle firstStyle = workbook.createCellStyle();
+        firstStyle.setAlignment(HorizontalAlignment.CENTER);
+        firstStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        // 设置背景颜色为灰色
+        firstStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
+        firstStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        // 设置字体
+        firstStyle.setFont(font);
 
-        Workbook workbook = new XSSFWorkbook();
 
-        // 创建居中对齐的样式
+        // 创建居中对齐-加边框-字体加粗的样式
         CellStyle centerAlignStyle = workbook.createCellStyle();
         centerAlignStyle.setAlignment(HorizontalAlignment.CENTER);
         centerAlignStyle.setVerticalAlignment(VerticalAlignment.CENTER);
-
-        // 创建居右对齐的样式
-        CellStyle rightAlignStyle = workbook.createCellStyle();
-        rightAlignStyle.setAlignment(HorizontalAlignment.RIGHT);
-        rightAlignStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        // 设置边框
+        centerAlignStyle.setBorderTop(BorderStyle.THIN);
+        centerAlignStyle.setBorderBottom(BorderStyle.THIN);
+        centerAlignStyle.setBorderLeft(BorderStyle.THIN);
+        centerAlignStyle.setBorderRight(BorderStyle.THIN);
+        // 设置边框颜色(使用IndexedColors枚举)
+        centerAlignStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
+        centerAlignStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
+        centerAlignStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
+        centerAlignStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
+        // 设置字体
+        centerAlignStyle.setFont(font);
+
+        // 创建居中对齐-不加边框-字体加粗的样式
+        CellStyle centerAlignStyle1 = workbook.createCellStyle();
+        centerAlignStyle1.setAlignment(HorizontalAlignment.CENTER);
+        centerAlignStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
+        // 设置字体
+        centerAlignStyle1.setFont(font);
+
+        // 创建居中对齐-不加边框-字体不加粗的样式
+        CellStyle centerAlignStyle2 = workbook.createCellStyle();
+        centerAlignStyle2.setAlignment(HorizontalAlignment.CENTER);
+        centerAlignStyle2.setVerticalAlignment(VerticalAlignment.CENTER);
+
+        // 创建居中对齐-加边框-字体不加粗的样式
+        CellStyle centerAlignStyle3 = workbook.createCellStyle();
+        centerAlignStyle3.setAlignment(HorizontalAlignment.CENTER);
+        centerAlignStyle3.setVerticalAlignment(VerticalAlignment.CENTER);
+        // 设置边框
+        centerAlignStyle3.setBorderTop(BorderStyle.THIN);
+        centerAlignStyle3.setBorderBottom(BorderStyle.THIN);
+        centerAlignStyle3.setBorderLeft(BorderStyle.THIN);
+        centerAlignStyle3.setBorderRight(BorderStyle.THIN);
+        // 设置边框颜色(使用IndexedColors枚举)
+        centerAlignStyle3.setTopBorderColor(IndexedColors.BLACK.getIndex());
+        centerAlignStyle3.setBottomBorderColor(IndexedColors.BLACK.getIndex());
+        centerAlignStyle3.setLeftBorderColor(IndexedColors.BLACK.getIndex());
+        centerAlignStyle3.setRightBorderColor(IndexedColors.BLACK.getIndex());
 
         if (zzxtvoList != null) {
             for (InterlockHistoryDistinctZZXTVO zzxtvo : zzxtvoList) {
@@ -183,8 +236,6 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
                 String sheetName = zzxtvo.getInterlockApparatusName() + "-" + zzxtvo.getInterlockSystemName();
                 Sheet sheet = workbook.createSheet(sheetName);
 
-                // 设置默认行高为 24.6 点
-                sheet.setDefaultRowHeightInPoints(24.6f);
                 // 设置列宽——30或15个字符宽度
                 int[] columnWidths = {30, 30, 30, 15, 15, 15, 15, 15};
                 for (int j = 0; j < columnWidths.length; j++) {
@@ -208,43 +259,72 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
                 int loopHealthLevelC = summaryHistoryMapper.cocuntTYOrHL(dto2);
                 int loopHealthLevel = loopHealthLevelA * 3 + loopHealthLevelB * 2 + loopHealthLevelC * 1;
 
-                String secondTitle = "  投用率:" + tyl + "%" + "  总回路数:" + loopHealthLevel;
-                if (dto.getBeginTime() != null && dto.getEndTime() == null) {
-                    secondTitle = "起始时间:" + formattedBeginTime + secondTitle;
-                } else if (dto.getBeginTime() == null && dto.getEndTime() != null) {
-                    secondTitle = "结束时间:" + formattedEndTime + secondTitle;
-                } else if (dto.getBeginTime() != null && dto.getEndTime() != null) {
-                    secondTitle = "起始时间:" + formattedBeginTime + "  结束时间:" + formattedEndTime + secondTitle;
-                }
 
-                //标题行
+                //第一行:联锁历史数据报表
                 int rowNum = 0;
                 Row titleRow = sheet.createRow(rowNum++);
+                titleRow.setHeightInPoints(19.8f);
                 Cell titleCell = titleRow.createCell(0);
-                titleCell.setCellValue(title + "报表");
-                titleCell.setCellStyle(centerAlignStyle); // 应用居中对齐的样式
+                titleCell.setCellValue("联锁历史数据报表");
+                titleCell.setCellStyle(firstStyle); // 第一行的样式
+                // 合并第一行的前4列
+                sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 0, 3));
 
-                //第二行标题行
+                // 第二行:报表生成时间:
                 Row secondTitleRow = sheet.createRow(rowNum++);
-                Cell secondTitleCell = secondTitleRow.createCell(0);
-                secondTitleCell.setCellValue(secondTitle);
-                secondTitleCell.setCellStyle(rightAlignStyle); // 应用居右对齐的样式
-
-                //第三行列名
+                // 设置第2行数据
+                String[] s2 = {"报表生成时间:",sdf.format(new Date()),"","","",""};
+                createCellOfRowWithValueStyle(secondTitleRow,s2,centerAlignStyle2);
+                // 合并第2行的后5列
+                sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 1, 5));
+
+                // 第3行:装置名称
+                Row thirdTitleRow = sheet.createRow(rowNum++);
+                // 设置第3行数据
+                String[] s3 = {"装置名称:",zzxtvo.getInterlockApparatusName(),"","","",""};
+                CellStyle[] style3 = {centerAlignStyle,centerAlignStyle3,centerAlignStyle3,centerAlignStyle3,centerAlignStyle3,centerAlignStyle3};
+                createCellOfRowWithValueStyleName(thirdTitleRow,s3,style3);
+                // 合并第3行的后5列
+                sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 1, 5));
+
+                // 第四行:系统名称
+                Row fourthTitleRow = sheet.createRow(rowNum++);
+                // 设置第4行数据
+                String[] s4 = {"系统名称:",zzxtvo.getInterlockSystemName(),"","","",""};
+                CellStyle[] style4 = {centerAlignStyle,centerAlignStyle3,centerAlignStyle3,centerAlignStyle3,centerAlignStyle3,centerAlignStyle3};
+                createCellOfRowWithValueStyleName(fourthTitleRow,s4,style4);
+                // 合并第4行的后5列
+                sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 1, 5));
+
+                //第五行:起始时间、结束时间
+                Row fifthTitleRow = sheet.createRow(rowNum++);
+                //设置第5行数据
+                String[] s5 = {"起始时间:",formattedBeginTime,"","结束时间:",formattedEndTime,""};
+                CellStyle[] style5 = {centerAlignStyle,centerAlignStyle3,centerAlignStyle3,centerAlignStyle,centerAlignStyle3,centerAlignStyle3};
+                createCellOfRowWithValueStyleName(fifthTitleRow,s5,style5);
+                // 分别合并第2、3列 和 第5、6列
+                sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 1, 2));
+                sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 4, 5));
+
+                //第六行:连锁回路数量、未投用联锁数量、投用率统计
+                Row sixTitleRow = sheet.createRow(rowNum++);
+                String[] s6 = {"联锁回路数量:", String.valueOf(loopHealthLevel),"未投用联锁数量:", String.valueOf(wty),"投用率统计:", String.valueOf(tyl)};
+                CellStyle[] style6 = {centerAlignStyle,centerAlignStyle3,centerAlignStyle,centerAlignStyle3,centerAlignStyle,centerAlignStyle3};
+                createCellOfRowWithValueStyleName(sixTitleRow,s6,style6);
+
+                //第七行空白
+                rowNum++;
+
+                //第8行:历史数据
+                Row eightTitleRow = sheet.createRow(rowNum++);
+                //设置第8行数据
+                createCellWithValueStyle(eightTitleRow, 0, "历史数据:", centerAlignStyle1);
+
+                //第9行:列名
                 Row columnRow= sheet.createRow(rowNum++);
-                int column = 0;
-                createCellWithValueStyle(columnRow, column++, "采集时间", centerAlignStyle);
-                createCellWithValueStyle(columnRow, column++, "联锁名称", centerAlignStyle);
-                createCellWithValueStyle(columnRow, column++, "联锁条件点位", centerAlignStyle);
-                createCellWithValueStyle(columnRow, column++, "仪表状态", centerAlignStyle);
-                createCellWithValueStyle(columnRow, column++, "联锁状态", centerAlignStyle);
-                createCellWithValueStyle(columnRow, column++, "旁路状态", centerAlignStyle);
-                createCellWithValueStyle(columnRow, column++, "控制系统状态", centerAlignStyle);
-                createCellWithValueStyle(columnRow, column++, "回路健康级别", centerAlignStyle);
-
-                // 分别合并第一行、第二行的前8列
-                sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));
-                sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7));
+                String[] s9 = {"采集时间", "联锁名称", "联锁条件点位", "仪表状态", "控制系统状态", "旁路状态", "联锁状态", "回路健康级别"};
+                createCellOfRowWithValueStyle(columnRow,s9,centerAlignStyle);
+
 
                 // 创建单元格、设置格式、填充数据
                 int startTagTimeRow = 0;
@@ -257,15 +337,8 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
 
                     int i = 0;
                     Row row = sheet.createRow(rowNum);
-                    createCellWithValueStyle(row, i++, record.getTagTime(), centerAlignStyle);
-                    createCellWithValueStyle(row, i++, record.getInterlockname(), centerAlignStyle);
-                    createCellWithValueStyle(row, i++, record.getInterlockConditionTag(), centerAlignStyle);
-                    createCellWithValueStyle(row, i++, record.getInstrumentStatus(), centerAlignStyle);
-                    createCellWithValueStyle(row, i++, record.getInterlockStatus(), centerAlignStyle);
-                    createCellWithValueStyle(row, i++, record.getBypass(), centerAlignStyle);
-                    createCellWithValueStyle(row, i++, record.getControlSystemStatus(), centerAlignStyle);
-                    createCellWithValueStyle(row, i++, record.getLoopHealthLevel(), centerAlignStyle);
-
+                    String[] s = {record.getTagTime(), record.getInterlockname(), record.getInterlockConditionTag(), record.getInstrumentStatus(), record.getControlSystemStatus(), record.getBypass(), record.getInterlockStatus(), record.getLoopHealthLevel()};
+                    createCellOfRowWithValueStyle(row,s,centerAlignStyle3);
 
                     // 合并 "采集时间" 列单元格
                     if (idx == 0 || !record.getTagTime().equals(exportList.get(idx - 1).getTagTime())) {
@@ -286,7 +359,7 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
                     // 合并 "联锁状态" 列单元格,基于 "采集时间"
                     if (idx == 0 || !record.getTagTime().equals(exportList.get(idx - 1).getTagTime())) {
                         if (idx > 0 && (rowNum - startInterlockStatusRow) > 1) {
-                            sheet.addMergedRegion(new CellRangeAddress(startInterlockStatusRow, rowNum - 1, 4, 4));
+                            sheet.addMergedRegion(new CellRangeAddress(startInterlockStatusRow, rowNum - 1, 6, 6));
                         }
                         startInterlockStatusRow = rowNum;
                     }
@@ -319,26 +392,24 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
             }
         }
 
-        try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
-            workbook.write(fileOut);
-        } catch (IOException e) {
-            // 处理异常
-            e.printStackTrace();
-        } finally {
-            try {
-                if (workbook != null) {
-                    workbook.close();
-                }
-            } catch (IOException e) {
-                // 处理关闭 workbook 时可能发生的异常
-                e.printStackTrace();
-            }
-        }
-
-        return 1;
+        return workbook;
+    }
 
+    //创建单元格,每个单元格都有自己的样式
+    private static void createCellOfRowWithValueStyleName(Row row, String[] s1, CellStyle[] style) {
+        int i = 0;
+        for (String s : s1){
+            createCellWithValueStyle(row, i++, s, style[i-1]);
+        }
     }
 
+    // 创建第五行的单元格
+    private static void createCellOfRowWithValueStyle(Row row, String[] s1, CellStyle style) {
+        int i = 0;
+        for (String s : s1){
+            createCellWithValueStyle(row, i++, s, style);
+        }
+    }
 
     // 创建单元格
     private static void createCellWithValueStyle(Row row, int col, Object value, CellStyle style) {
@@ -393,4 +464,60 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
     public List<InterlockDetailHistory> getYbStatusListBySummaryIdAndTagTime(String id, String yesterday) {
         return interlockDetailHistoryMapper.getYbStatusListBySummaryIdAndTagTime(id,yesterday);
     }
+
+
+    private IPage<InterlockSummaryHistoryVO> zhSummaryHistoryVOIPage(IPage<InterlockSummaryHistoryVO> voiPage){
+        List<InterlockSummaryHistoryVO> list = voiPage.getRecords().stream().map(i->{
+            InterlockBase base = interlockBaseMapper.selectById(i.getInterlockSystemId());
+            if(base != null){
+                //控制系统状态转换
+                if(base.getControlSystemStatusNormal().equals(i.getControlSystemStatus())) i.setControlSystemStatusName(base.getControlSystemStatusNormalName());
+                else i.setControlSystemStatusName(base.getControlSystemStatusAbnormalName());
+                //联锁状态转换
+                if(base.getInterlockStatusTy().equals(i.getInterlockStatus())) i.setInterlockStatusName(base.getInterlockStatusTyName());
+                else i.setInterlockStatusName(base.getInterlockStatusWtyName());
+                //旁路状态转换
+                if(base.getBypassYes().equals(i.getBypass())) i.setBypassName(base.getBypassYesName());
+                else i.setBypassName(base.getBypassNoName());
+                //仪表状态转换
+                if(base.getInstrumentStatusNormal().equals(i.getInstrumentStatus())) i.setInstrumentStatusName(base.getInstrumentStatusNormalName());
+                else i.setInstrumentStatusName(base.getInstrumentStatusAbnormalName());
+            }
+            return i;
+        }).collect(Collectors.toList());
+        voiPage.setRecords(list);
+        return voiPage;
+    }
+
+    private IPage<InterlockDetailHistoryQueryVO> zhDetailHistoryQueryVOIPage(IPage<InterlockDetailHistoryQueryVO> voiPage, String interlockSystemId){
+        InterlockBase base = interlockBaseMapper.selectById(interlockSystemId);
+        if(base != null){
+            List<InterlockDetailHistoryQueryVO> list = voiPage.getRecords().stream().map(i->{
+                //旁路状态转换
+                if(i.getBypass()!=null && base.getBypassYes()!=null){
+                    if(i.getBypass().equals(base.getBypassYes())) i.setBypass_dictText(base.getBypassYesName());
+                    else i.setBypass_dictText(base.getBypassNoName());
+                }
+                //输入卡件状态转换
+                if(i.getInputStatus()!=null && base.getControlSystemStatusNormal()!=null){
+                    if(i.getInputStatus().equals(base.getControlSystemStatusNormal())) i.setInputStatus_dictText(base.getControlSystemStatusNormalName());
+                    else i.setInputStatus_dictText(base.getControlSystemStatusAbnormalName());
+                }
+                //输出卡件状态转换
+                if(i.getOutputStatus()!=null && base.getControlSystemStatusNormal()!=null){
+                    if(i.getOutputStatus().equals(base.getControlSystemStatusNormal())) i.setOutputStatus_dictText(base.getControlSystemStatusNormalName());
+                    else i.setOutputStatus_dictText(base.getControlSystemStatusAbnormalName());
+                }
+                //MP状态转换
+                if(i.getMpStatus()!=null && base.getControlSystemStatusNormal()!=null){
+                    if(i.getMpStatus().equals(base.getControlSystemStatusNormal())) i.setMpStatus_dictText(base.getControlSystemStatusNormalName());
+                    else i.setMpStatus_dictText(base.getControlSystemStatusAbnormalName());
+                }
+                return i;
+            }).collect(Collectors.toList());
+            voiPage.setRecords(list);
+        }
+        return voiPage;
+    }
+
 }

+ 5 - 1
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/vo/InterlockDetailHistoryQueryVO.java

@@ -51,21 +51,25 @@ public class InterlockDetailHistoryQueryVO {
     private java.lang.String ifBypass;
     /**旁路状态(0否1是)*/
     @Excel(name = "旁路状态(0否1是)", width = 15, dicCode = "bypass")
-    @Dict(dicCode = "bypass")
+//    @Dict(dicCode = "bypass")
     @ApiModelProperty(value = "旁路状态(0否1是)")
     private java.lang.String bypass;
+    private java.lang.String bypass_dictText;
     /**输入卡件状态*/
     @Excel(name = "输入卡件状态", width = 15)
     @ApiModelProperty(value = "输入卡件状态")
     private java.lang.String inputStatus;
+    private java.lang.String inputStatus_dictText;
     /**输出卡件状态*/
     @Excel(name = "输出卡件状态", width = 15)
     @ApiModelProperty(value = "输出卡件状态")
     private java.lang.String outputStatus;
+    private java.lang.String outputStatus_dictText;
     /**MP状态*/
     @Excel(name = "MP状态", width = 15)
     @ApiModelProperty(value = "MP状态")
     private java.lang.String mpStatus;
+    private java.lang.String mpStatus_dictText;
 
     /**逻辑关系*/
     @Excel(name = "逻辑关系", width = 15)

+ 17 - 4
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/vo/InterlockSummaryHistoryVO.java

@@ -41,23 +41,27 @@ public class InterlockSummaryHistoryVO {
     /**仪表状态*/
     @Excel(name = "仪表状态", width = 15,dicCode="instrument_status")
     @ApiModelProperty(value = "仪表状态")
-    @Dict(dicCode = "instrument_status")
+//    @Dict(dicCode = "instrument_status")
     private java.lang.String instrumentStatus;
+    private java.lang.String instrumentStatusName;
     /**联锁状态*/
     @Excel(name = "联锁状态", width = 15,dicCode="interlock_status", mergeVertical = true, mergeRely = {0})
     @ApiModelProperty(value = "联锁状态")
-    @Dict(dicCode = "interlock_status")
+//    @Dict(dicCode = "interlock_status")
     private java.lang.String interlockStatus;
+    private java.lang.String interlockStatusName;
     /**旁路状态*/
     @Excel(name = "旁路状态", width = 15,dicCode="bypass")
-    @Dict(dicCode = "bypass")
+//    @Dict(dicCode = "bypass")
     @ApiModelProperty(value = "旁路状态")
     private java.lang.String bypass;
+    private java.lang.String bypassName;
     /**控制系统状态*/
     @Excel(name = "控制系统状态", width = 15,dicCode="control_system_status")
     @ApiModelProperty(value = "控制系统状态")
-    @Dict(dicCode = "control_system_status")
+//    @Dict(dicCode = "control_system_status")
     private java.lang.String controlSystemStatus;
+    private java.lang.String controlSystemStatusName;
     /**回路健康级别*/
     @Excel(name = "回路健康级别", width = 15, mergeVertical = true, mergeRely = {0})
     @ApiModelProperty(value = "回路健康级别")
@@ -67,4 +71,13 @@ public class InterlockSummaryHistoryVO {
     @ApiModelProperty(value = "该联锁在原联锁总表的id")
     private java.lang.String summaryOriginId;
 
+    /**装置id*/
+    @Excel(name = "装置id", width = 15)
+    @ApiModelProperty(value = "装置id")
+    private java.lang.String interlockApparatusId;
+    /**系统id*/
+    @Excel(name = "系统id", width = 15)
+    @ApiModelProperty(value = "系统id")
+    private java.lang.String interlockSystemId;
+
 }

+ 4 - 4
jeecg-module-interlock/src/main/java/org/jeecg/modules/summary/vo/InterlockSummaryVO.java

@@ -43,19 +43,19 @@ public class InterlockSummaryVO {
     @ApiModelProperty(value = "仪表状态")
 //    @Dict(dicCode = "instrument_status")
     private java.lang.String instrumentStatus;
-    private java.lang.String instrumentStatus_dictText;
+    private java.lang.String instrumentStatusName;
     /**控制系统状态*/
     @Excel(name = "控制系统状态", width = 15)
     @ApiModelProperty(value = "控制系统状态")
 //    @Dict(dicCode = "control_system_status")
     private java.lang.String controlSystemStatus;
-    private java.lang.String controlSystemStatus_dictText;
+    private java.lang.String controlSystemStatusName;
     /**联锁状态*/
     @Excel(name = "联锁状态", width = 15)
     @ApiModelProperty(value = "联锁状态")
 //    @Dict(dicCode = "interlock_status")
     private java.lang.String interlockStatus;
-    private java.lang.String interlockStatus_dictText;
+    private java.lang.String interlockStatusName;
     /**回路健康级别*/
     @Excel(name = "回路健康级别", width = 15)
     @ApiModelProperty(value = "回路健康级别")
@@ -64,7 +64,7 @@ public class InterlockSummaryVO {
 //    @Dict(dicCode = "bypass")
     @ApiModelProperty(value = "旁路状态")
     private java.lang.String bypass;
-    private java.lang.String bypass_dictText;
+    private java.lang.String bypassName;
 
 
     /**装置id*/