Przeglądaj źródła

计划停电导出

jichaobo 3 lat temu
rodzic
commit
0a8bb74ce2

+ 18 - 0
fiveep-controller/src/main/java/com/bizmatics/controller/web/WcBlackoutPlanController.java

@@ -64,6 +64,7 @@ public class WcBlackoutPlanController {
 
     /**
      * 停电计划-查询
+     *
      * @param plannedOutageVo
      * @return
      */
@@ -72,5 +73,22 @@ public class WcBlackoutPlanController {
         return ApiResult.success(wcBlackoutPlanService.plannedOutageList(plannedOutageVo));
     }
 
+
+    /**
+     * 停电计划-导出
+     *
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @param type 状态 1 未执行 2执行中 3 已执行
+     * @return
+     */
+    @GetMapping("outagePlanListExport")
+    public ApiResult<Void> outagePlanListExport(@RequestParam(value = "startTime", required = false) String startTime,
+                                                @RequestParam(value = "endTime", required = false) String endTime,
+                                                @RequestParam(value = "type", required = false, defaultValue = "0") Integer type) {
+        wcBlackoutPlanService.outagePlanListExport(startTime, endTime, type);
+        return ApiResult.success();
+    }
+
 }
 

+ 85 - 0
fiveep-model/src/main/java/com/bizmatics/model/vo/WcBlackoutPlanOneVo.java

@@ -0,0 +1,85 @@
+package com.bizmatics.model.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author ya
+ * @since 2021-07-07
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class WcBlackoutPlanOneVo implements Serializable {
+
+    private static final long serialVersionUID=1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 站点ID
+     */
+    private Integer siteId;
+
+    /**
+     * 计划类型:1.计划检修停电、2.计划施工停电、3.客户申请停电
+     */
+    private Integer planType;
+
+    /**
+     * 开始时间
+     */
+    private Date startTime;
+
+    /**
+     * 结束时间
+     */
+    private Date endTime;
+
+    /**
+     * 联系人 
+     */
+    private String contacts;
+
+    /**
+     * 手机号
+     */
+    private String phone;
+
+    /**
+     * 使能标识:1可用;0不可用
+     */
+    private Integer enable;
+
+    /**
+     * 添加人
+     */
+    private String creator;
+
+    /**
+     * 添加时间
+     */
+    private Date createTime;
+
+    /**
+     * 站点名称
+     */
+    private String siteName;
+
+    /**
+     * 状态 1 未执行 2执行中 3 已执行
+     */
+    private String type;
+
+}

+ 2 - 0
fiveep-service/src/main/java/com/bizmatics/service/WcBlackoutPlanService.java

@@ -23,4 +23,6 @@ public interface WcBlackoutPlanService extends CrudService<WcBlackoutPlan> {
     void plannedOutageDel(int id);
 
     CommonPage<WcBlackoutPlanVo> plannedOutageList(PlannedOutageVo plannedOutageVo);
+
+    String outagePlanListExport(String startTime, String endTime, Integer type);
 }

+ 73 - 0
fiveep-service/src/main/java/com/bizmatics/service/impl/WcBlackoutPlanServiceImpl.java

@@ -1,17 +1,30 @@
 package com.bizmatics.service.impl;
 
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
 import com.bizmatics.common.core.bean.CommonPage;
+import com.bizmatics.common.core.exception.BusinessException;
+import com.bizmatics.common.core.util.BeanMapperUtils;
+import com.bizmatics.common.core.util.FileUtils;
 import com.bizmatics.common.mvc.base.AbstractCrudService;
+import com.bizmatics.common.spring.util.GlobalUtils;
 import com.bizmatics.model.WcBlackoutPlan;
 import com.bizmatics.model.system.SysUser;
 import com.bizmatics.model.vo.CorrespondDeviceVO;
 import com.bizmatics.model.vo.PlannedOutageVo;
+import com.bizmatics.model.vo.WcBlackoutPlanOneVo;
 import com.bizmatics.model.vo.WcBlackoutPlanVo;
 import com.bizmatics.persistence.mapper.WcBlackoutPlanMapper;
 import com.bizmatics.service.WcBlackoutPlanService;
 import com.bizmatics.service.util.SecurityUtils;
+import com.bizmatics.service.vo.CorrespondDeviceExportVO;
+import com.bizmatics.service.vo.WcBlackoutPlanOneExportVo;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.stereotype.Service;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Date;
@@ -85,4 +98,64 @@ public class WcBlackoutPlanServiceImpl extends AbstractCrudService<WcBlackoutPla
         }
         return new CommonPage<>(plannedOutageListOne, total, plannedOutageVo.getSize(), plannedOutageVo.getCurrent());
     }
+
+    @Override
+    public String outagePlanListExport(String startTime,String endTime,Integer type) {
+        Workbook workbook = null;
+        File file = null;
+        try {
+            List<WcBlackoutPlanOneVo> plannedOutageListOne = new ArrayList<>();
+            ExportParams params = new ExportParams(null, "停电计划列表");
+            workbook = ExcelExportUtil.exportBigExcel(params, WcBlackoutPlanOneExportVo.class,
+                    (o, i) -> {
+                        int startCurrent = (i - 1) * 30;
+                        List<WcBlackoutPlanVo> plannedOutageList = baseMapper.plannedOutageList(startTime, endTime, type, 0,30,startCurrent);
+                        if (plannedOutageList.size()>0){
+                            for (int j = 0; j< plannedOutageList.size(); j++) {
+                                WcBlackoutPlanOneVo wcBlackoutPlanVo = new WcBlackoutPlanOneVo();
+                                wcBlackoutPlanVo.setEndTime(plannedOutageList.get(j).getEndTime());
+                                wcBlackoutPlanVo.setContacts(plannedOutageList.get(j).getContacts());
+                                wcBlackoutPlanVo.setStartTime(plannedOutageList.get(j).getStartTime());
+                                wcBlackoutPlanVo.setEnable(plannedOutageList.get(j).getEnable());
+                                wcBlackoutPlanVo.setCreator(plannedOutageList.get(j).getCreator());
+                                wcBlackoutPlanVo.setCreateTime(plannedOutageList.get(j).getCreateTime());
+                                wcBlackoutPlanVo.setPhone(plannedOutageList.get(j).getPhone());
+                                wcBlackoutPlanVo.setSiteName(plannedOutageList.get(j).getSiteName());
+                                wcBlackoutPlanVo.setId(plannedOutageList.get(j).getId());
+                                wcBlackoutPlanVo.setPlanType(plannedOutageList.get(j).getPlanType());
+                                wcBlackoutPlanVo.setSiteId(plannedOutageList.get(j).getSiteId());
+                                if (plannedOutageList.get(j).getStartTime().getTime()>new Date().getTime()){
+                                    wcBlackoutPlanVo.setType("未执行");
+                                }else if(plannedOutageList.get(j).getStartTime().getTime()<new Date().getTime()&&plannedOutageList.get(j).getEndTime().getTime()>new Date().getTime()){
+                                    wcBlackoutPlanVo.setType("执行中");
+                                }else if (plannedOutageList.get(j).getEndTime().getTime()<new Date().getTime()){
+                                    wcBlackoutPlanVo.setType("已执行");
+                                }
+                                plannedOutageListOne.add(wcBlackoutPlanVo);
+                            }
+                        }
+                        return new ArrayList<>(BeanMapperUtils.mapList(plannedOutageList, WcBlackoutPlanVo.class, WcBlackoutPlanOneExportVo.class));
+                    }, null);
+            if (null != workbook) {
+                file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "停电计划列表", System.currentTimeMillis() + ""));
+                FileUtils.createFile(file.getAbsolutePath());
+                FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
+                workbook.write(allListingFileOutputStream);
+            } else {
+                throw new BusinessException("表格数据为空");
+            }
+        } catch (Exception e) {
+            log.error("导出文件失败", e);
+            throw new BusinessException("导出文件失败");
+        } finally {
+            if (workbook != null) {
+                try {
+                    workbook.close();
+                } catch (IOException e) {
+                    log.error("===export spec=== 关闭workbook失败", e);
+                }
+            }
+        }
+        return file.getName();
+    }
 }

+ 81 - 0
fiveep-service/src/main/java/com/bizmatics/service/vo/WcBlackoutPlanOneExportVo.java

@@ -0,0 +1,81 @@
+package com.bizmatics.service.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author ya
+ * @since 2021-07-07
+ */
+@Data
+public class WcBlackoutPlanOneExportVo {
+
+    private Integer id;
+
+    /**
+     * 站点ID
+     */
+    private Integer siteId;
+
+    /**
+     * 计划类型:1.计划检修停电、2.计划施工停电、3.客户申请停电
+     */
+    private Integer planType;
+
+    /**
+     * 开始时间
+     */
+    @Excel(name = "开始时间 ", height = 6, width = 20)
+    private Date startTime;
+
+    /**
+     * 结束时间
+     */
+    @Excel(name = "结束时间 ", height = 6, width = 20)
+    private Date endTime;
+
+    /**
+     * 联系人
+     */
+    private String contacts;
+
+    /**
+     * 手机号
+     */
+    private String phone;
+
+    /**
+     * 使能标识:1可用;0不可用
+     */
+    private Integer enable;
+
+    /**
+     * 添加人
+     */
+    @Excel(name = "添加人 ", height = 6, width = 20)
+    private String creator;
+
+    /**
+     * 添加时间
+     */
+    @Excel(name = "添加时间 ", height = 6, width = 20)
+    private Date createTime;
+
+    /**
+     * 站点名称
+     */
+    @Excel(name = "站点名称 ", height = 6, width = 20)
+    private String siteName;
+
+    /**
+     * 状态 1 未执行 2执行中 3 已执行
+     */
+    @Excel(name = "状态 ", height = 6, width = 20)
+    private Integer type;
+}