ソースを参照

历史数据查手动导出——未完

LLL 9 ヶ月 前
コミット
6920615bb6

+ 16 - 1
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/controller/InterlockDetailHistoryController.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.history.controller;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -54,7 +55,21 @@ public class InterlockDetailHistoryController extends JeecgController<InterlockD
 	@Autowired
 	private IInterlockDetailHistoryService interlockDetailHistoryService;
 
-	/**
+
+
+
+	 /**
+	  * 手动导出excel
+	  */
+	 //@RequiresPermissions("org.jeecg.modules:interlock_detail_history:exportXls")
+	 @RequestMapping(value = "/sdexportLS7")
+	 @ApiOperation("手动导出excel")
+	 public ModelAndView exportXls1(HttpServletRequest request, InterlockHistoryQueryDTO dto) {
+		 return interlockDetailHistoryService.exportXls1(dto, InterlockSummaryHistoryVO.class, "联锁历史数据");
+	 }
+
+
+	 /**
 	 * 联锁历史数据——各种逻辑状态分页查询
 	 */
 	@ApiOperation(".联锁历史数据——各种逻辑状态分页查询")

+ 5 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/mapper/InterlockDetailHistoryMapper.java

@@ -30,4 +30,9 @@ public interface InterlockDetailHistoryMapper extends BaseMapper<InterlockDetail
      */
     IPage<InterlockSummaryHistoryVO> getPage(Page<InterlockSummaryHistoryVO> page, InterlockHistoryQueryDTO dto);
 
+    /**
+     * 联锁历史数据——各种逻辑状态分页查询——用于手动导出
+     */
+    List<InterlockSummaryHistoryVO> getForExport(InterlockHistoryQueryDTO dto);
+
 }

+ 8 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/mapper/InterlockSummaryHistoryMapper.java

@@ -3,8 +3,11 @@ package org.jeecg.modules.history.mapper;
 import java.util.List;
 
 import org.apache.ibatis.annotations.Param;
+import org.jeecg.modules.history.dto.InterlockHistoryQueryDTO;
 import org.jeecg.modules.history.entity.InterlockSummaryHistory;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.summary.entity.InterlockSummary;
+import org.jeecg.modules.summary.vo.InterlockSummaryVO;
 
 /**
  * @Description: 联锁总历史数据表
@@ -14,4 +17,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface InterlockSummaryHistoryMapper extends BaseMapper<InterlockSummaryHistory> {
 
+    /**
+     * 根据查询条件查所有不重复的系统及其所属装置
+     */
+    List<InterlockSummaryHistory> getDistinctZZXTSummaryList(InterlockHistoryQueryDTO dto);
+
 }

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

@@ -21,13 +21,13 @@
         s.interlock_status, s.loop_health_level, d.bypass, s.tag_time
         from interlock_detail_history d left join interlock_summary_history s on d.summaryid = s.id
         <where>
-            <if test="dto.interlockSystemId != null and dto.interlockSystemId != ''"> and d.interlock_system_id =  #{dto.interlockSystemId}</if>
-            <if test="dto.interlockApparatusId != null and dto.interlockApparatusId != ''"> and d.interlock_apparatus_id =  #{dto.interlockApparatusId}</if>
+            <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>
 
             <if test="dto.interlockname != null and dto.interlockname != ''"> and d.interlockname like concat('%', #{dto.interlockname}, '%')</if>
             <if test="dto.interlockCondition != null and dto.interlockCondition != ''"> and d.interlock_condition = #{dto.interlockCondition}</if>
-            <if test="dto.interlockConditionTag != null and dto.interlockConditionTag != ''"> and d.interlock_condition_tag like concat('%',#{dtodtodto.interlockConditionTag},'%')</if>
-            <if test="dto.instrumentStatus != null and dtodto.instrumentStatus != ''"> and d.instrument_status = #{dto.instrumentStatus}</if>
+            <if test="dto.interlockConditionTag != null and dto.interlockConditionTag != ''"> and d.interlock_condition_tag like concat('%',#{dto.interlockConditionTag},'%')</if>
+            <if test="dto.instrumentStatus != null and dto.instrumentStatus != ''"> and d.instrument_status = #{dto.instrumentStatus}</if>
             <if test="dto.controlSystemStatus != null and dto.controlSystemStatus != ''"> and d.control_system_status = #{dto.controlSystemStatus}</if>
             <if test="dto.interlockStatus != null and dto.interlockStatus != ''"> and s.interlock_status = #{dto.interlockStatus}</if>
             <if test="dto.loopHealthLevel != null and dto.loopHealthLevel != ''"> and s.loop_health_level = #{dto.loopHealthLevel}</if>
@@ -37,4 +37,30 @@
         order by s.create_time desc
     </select>
 
+    <!-- 联锁总历史数据表查询(各种逻辑状态)——用于手动导出  -->
+    <select id="getForExport" 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
+        from interlock_detail_history d left join interlock_summary_history s on d.summaryid = s.id
+        <where>
+            <if test="interlockSystemId != null and interlockSystemId != ''"> and s.interlock_system_id =  #{interlockSystemId}</if>
+            <if test="interlockApparatusId != null and interlockApparatusId != ''"> and s.interlock_apparatus_id =  #{interlockApparatusId}</if>
+
+            <if test="interlockname != null and interlockname != ''"> and d.interlockname like concat('%', #{interlockname}, '%')</if>
+            <if test="interlockCondition != null and interlockCondition != ''"> and d.interlock_condition = #{interlockCondition}</if>
+            <if test="interlockConditionTag != null and interlockConditionTag != ''"> and d.interlock_condition_tag like concat('%',#{interlockConditionTag},'%')</if>
+            <if test="instrumentStatus != null and instrumentStatus != ''"> and d.instrument_status = #{instrumentStatus}</if>
+            <if test="controlSystemStatus != null and controlSystemStatus != ''"> and d.control_system_status = #{controlSystemStatus}</if>
+            <if test="interlockStatus != null and interlockStatus != ''"> and s.interlock_status = #{interlockStatus}</if>
+            <if test="loopHealthLevel != null and loopHealthLevel != ''"> and s.loop_health_level = #{loopHealthLevel}</if>
+            <if test="beginTime != null "> and STR_TO_DATE(s.tag_time, '%Y-%m-%d %H:%i:%s')  &gt; #{beginTime} </if>
+            <if test="endTime != null "> and STR_TO_DATE(s.tag_time, '%Y-%m-%d %H:%i:%s')  &lt; #{endTime} </if>
+        </where>
+        order by s.create_time desc
+    </select>
+
+
+
+
+
 </mapper>

+ 23 - 1
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/mapper/xml/InterlockSummaryHistoryMapper.xml

@@ -2,4 +2,26 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.history.mapper.InterlockSummaryHistoryMapper">
 
-</mapper>
+    <!--    根据查询条件查所有不重复的系统及其所属装置      -->
+    <select id="getDistinctZZXTSummaryList" parameterType="org.jeecg.modules.history.dto.InterlockHistoryQueryDTO" resultType="org.jeecg.modules.history.entity.InterlockSummaryHistory">
+        select distinct s.interlock_system_id, s.interlock_apparatus_id
+        from interlock_detail_history d left join interlock_summary_history s on d.summaryid = s.id
+        <where>
+            <if test="interlockSystemId != null and interlockSystemId != ''"> and s.interlock_system_id =  #{interlockSystemId}</if>
+            <if test="interlockApparatusId != null and interlockApparatusId != ''"> and s.interlock_apparatus_id =  #{interlockApparatusId}</if>
+
+            <if test="interlockname != null and interlockname != ''"> and d.interlockname like concat('%', #{interlockname}, '%')</if>
+            <if test="interlockCondition != null and interlockCondition != ''"> and d.interlock_condition = #{interlockCondition}</if>
+            <if test="interlockConditionTag != null and interlockConditionTag != ''"> and d.interlock_condition_tag like concat('%',#{interlockConditionTag},'%')</if>
+            <if test="instrumentStatus != null and instrumentStatus != ''"> and d.instrument_status = #{instrumentStatus}</if>
+            <if test="controlSystemStatus != null and controlSystemStatus != ''"> and d.control_system_status = #{controlSystemStatus}</if>
+            <if test="interlockStatus != null and interlockStatus != ''"> and s.interlock_status = #{interlockStatus}</if>
+            <if test="loopHealthLevel != null and loopHealthLevel != ''"> and s.loop_health_level = #{loopHealthLevel}</if>
+            <if test="beginTime != null "> and STR_TO_DATE(s.tag_time, '%Y-%m-%d %H:%i:%s')  &gt; #{beginTime} </if>
+            <if test="endTime != null "> and STR_TO_DATE(s.tag_time, '%Y-%m-%d %H:%i:%s')  &lt; #{endTime} </if>
+            and s.interlock_system_id IS NOT NULL
+            AND s.interlock_apparatus_id IS NOT NULL
+        </where>
+        order by s.interlock_apparatus_id
+    </select>
+</mapper>

+ 14 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/service/IInterlockDetailHistoryService.java

@@ -8,6 +8,9 @@ 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.InterlockSummaryHistoryVO;
+import org.springframework.web.servlet.ModelAndView;
+
+import java.util.List;
 
 /**
  * @Description: 联锁详细信息历史数据表
@@ -27,4 +30,15 @@ public interface IInterlockDetailHistoryService extends IService<InterlockDetail
      */
     IPage<InterlockSummaryHistoryVO> getPage(Page<InterlockSummaryHistoryVO> page, InterlockHistoryQueryDTO dto);
 
+
+    /**
+     * 联锁历史数据——各种逻辑状态分页查询——用于手动导出
+     */
+    List<InterlockSummaryHistoryVO> getForExport(InterlockHistoryQueryDTO dto);
+
+    /**
+     * 手动导出excel
+     */
+    ModelAndView exportXls1(InterlockHistoryQueryDTO dto, Class<InterlockSummaryHistoryVO> clazz, String title);
+
 }

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

@@ -1,19 +1,45 @@
 package org.jeecg.modules.history.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.system.vo.LoginUser;
+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.entity.InterlockSummaryHistory;
 import org.jeecg.modules.history.mapper.InterlockDetailHistoryMapper;
 import org.jeecg.modules.history.mapper.InterlockSummaryHistoryMapper;
 import org.jeecg.modules.history.service.IInterlockDetailHistoryService;
 import org.jeecg.modules.history.vo.InterlockDetailHistoryQueryVO;
 import org.jeecg.modules.history.vo.InterlockSummaryHistoryVO;
+import org.jeecg.modules.summary.entity.InterlockSummary;
+import org.jeecg.modules.summary.mapper.InterlockSummaryMapper;
+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.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.*;
 
 /**
  * @Description: 联锁详细信息历史数据表
@@ -27,6 +53,12 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
     @Autowired
     @SuppressWarnings("all")
     private InterlockDetailHistoryMapper interlockDetailHistoryMapper;
+    @Autowired
+    @SuppressWarnings("all")
+    private InterlockSummaryHistoryMapper summaryHistoryMapper;
+
+    @Value("${jeecg.path.upload}")
+    private String upLoadPath;
 
     /**
      * 联锁历史数据详细信息-分页查询
@@ -42,4 +74,85 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
         return interlockDetailHistoryMapper.getPage(page, dto);
     }
 
+
+
+
+    /**
+     * 联锁历史数据——各种逻辑状态分页查询——用于手动导出
+     */
+    public List<InterlockSummaryHistoryVO> getForExport(InterlockHistoryQueryDTO dto){
+        return interlockDetailHistoryMapper.getForExport(dto);
+    }
+
+    /**
+     * 导出excel
+     */
+    public ModelAndView exportXls1(InterlockHistoryQueryDTO dto, Class<InterlockSummaryHistoryVO> clazz, String title) {
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+
+        //按装置、系统分sheet
+        if(dto.getInterlockSystemId()!=null && !"".equals(dto.getInterlockSystemId())){
+            //一个系统
+            List<InterlockSummaryHistoryVO> exportList = interlockDetailHistoryMapper.getForExport(dto);
+            ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+            mv.addObject(NormalExcelConstants.FILE_NAME, title);//此处设置的filename无效 ,前端会重更新设置一下
+            mv.addObject(NormalExcelConstants.CLASS, clazz);
+            ExportParams  exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
+            exportParams.setImageBasePath(upLoadPath);
+            mv.addObject(NormalExcelConstants.PARAMS,exportParams);
+            mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
+            return mv;
+        }else if(dto.getInterlockApparatusId()!=null && !"".equals(dto.getInterlockApparatusId())){
+            //一个装置,多个系统
+            List<Map<String, Object>> list = new ArrayList<>();
+
+            InterlockHistoryQueryDTO dto1 = new InterlockHistoryQueryDTO();
+            dto1.setInterlockApparatusId(dto.getInterlockApparatusId());//装置id
+            List<InterlockSummaryHistory> summaryList = summaryHistoryMapper.getDistinctZZXTSummaryList(dto1);
+
+            int i = 1;
+            for (InterlockSummaryHistory summaryHistory : summaryList){
+                dto.setInterlockSystemId(summaryHistory.getInterlockSystemId());//系统id
+                List<InterlockSummaryHistoryVO> exportList = interlockDetailHistoryMapper.getForExport(dto);
+
+                Map<String, Object> map = new HashMap<>();
+                map.put(NormalExcelConstants.CLASS, InterlockSummaryHistoryVO.class);
+                map.put(NormalExcelConstants.PARAMS, new ExportParams(summaryHistory.getInterlockApparatusId()+ "-"+summaryHistory.getInterlockSystemId() , "第"+ i+ "页"));
+                map.put(NormalExcelConstants.DATA_LIST, exportList);
+                list.add(map);
+                i++;
+            }
+
+            ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+            mv.addObject(NormalExcelConstants.FILE_NAME, title);//此处设置的filename无效 ,前端会重更新设置一下
+            mv.addObject(NormalExcelConstants.MAP_LIST, list);
+            return mv;
+        }else {
+            //多个装置,多个系统
+            List<Map<String, Object>> list = new ArrayList<>();
+
+            List<InterlockSummaryHistory> summaryList = summaryHistoryMapper.getDistinctZZXTSummaryList(new InterlockHistoryQueryDTO());
+
+            int i = 1;
+            for (InterlockSummaryHistory summaryHistory : summaryList){
+                dto.setInterlockSystemId(summaryHistory.getInterlockSystemId());//系统id
+                List<InterlockSummaryHistoryVO> exportList = interlockDetailHistoryMapper.getForExport(dto);
+
+                Map<String, Object> map = new HashMap<>();
+                map.put(NormalExcelConstants.CLASS, InterlockSummaryHistoryVO.class);
+                map.put(NormalExcelConstants.PARAMS, new ExportParams(summaryHistory.getInterlockApparatusId()+ "-"+summaryHistory.getInterlockSystemId() , "第"+ i+ "页"));
+                map.put(NormalExcelConstants.DATA_LIST, exportList);
+                list.add(map);
+                i++;
+            }
+
+            ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+            mv.addObject(NormalExcelConstants.FILE_NAME, title);//此处设置的filename无效 ,前端会重更新设置一下
+            mv.addObject(NormalExcelConstants.MAP_LIST, list);
+            return mv;
+        }
+
+
+    }
+
 }

+ 1 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/vo/InterlockSummaryHistoryVO.java

@@ -56,6 +56,7 @@ public class InterlockSummaryHistoryVO {
     @ApiModelProperty(value = "回路健康级别")
     private java.lang.String loopHealthLevel;
     /**旁路状态*/
+    @Excel(name = "旁路状态", width = 15)
     @Dict(dicCode = "bypass")
     @ApiModelProperty(value = "旁路状态")
     private java.lang.String bypass;