Browse Source

点位信息的导入导出

ops-management-platform-backend-dev
gjh 1 day ago
parent
commit
203e6d94ce
  1. 71
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/ExcelController.java
  2. 35
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/PointInfo.java
  3. 15
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/PointInfoVo.java
  4. 69
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/listener/PointInfoListener.java
  5. 3
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/service/IPointInfoService.java
  6. 5
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/service/impl/PointInfoServiceImpl.java

71
ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/ExcelController.java

@ -0,0 +1,71 @@
package org.dromara.platform.controller;
import com.alibaba.excel.EasyExcel;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.platform.domain.PerformanceManagement;
import org.dromara.platform.domain.PointInfo;
import org.dromara.platform.domain.bo.PerformanceManagementBo;
import org.dromara.platform.domain.bo.PointInfoBo;
import org.dromara.platform.domain.vo.PerformanceManagementVo;
import org.dromara.platform.domain.vo.PointInfoVo;
import org.dromara.platform.listener.PerformanceManagementListener;
import org.dromara.platform.listener.PointInfoListener;
import org.dromara.platform.service.IPointInfoService;
import org.dromara.platform.service.IProjectInfoService;
import org.dromara.platform.service.ProjectManagerService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.util.List;
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/platform/excel")
public class ExcelController {
@Resource
private IPointInfoService pointInfoService ;
@PostMapping("/uploadPointInfo")
public void uploadPointInfo(MultipartFile file, HttpServletResponse response) throws IOException {
long t1 = System.currentTimeMillis();
// 业务层
EasyExcel.read(file.getInputStream(), PointInfoVo.class, new PointInfoListener(pointInfoService)).sheet().doRead();
response.setContentType("text/html;charset=utf8");
long t2 = System.currentTimeMillis();
response.getWriter().println("导入数据成功!,共用时:"+(t2-t1)+"ms");
log.info("批量导入点位信息项目成功! 共用时:{}ms",(t2-t1));
}
/**
* 导出点位信息
*/
@PostMapping("/ExportPointInfo")
public void ExportPointInfo(PointInfoBo bo, HttpServletResponse response) throws IOException {
List<PointInfoVo> list = pointInfoService.queryList(bo);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
String flag = "点位信息";
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
LocalDate currentDate = LocalDate.now();
System.out.println("当前日期: " + currentDate);
String fileName = URLEncoder.encode( flag+currentDate, "UTF-8")
.replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
EasyExcel.write(response.getOutputStream(), PointInfoVo.class)
.sheet("点位信息"+currentDate)
.doWrite(list);
}
}

35
ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/PointInfo.java

@ -1,10 +1,11 @@
package org.dromara.platform.domain;
import com.alibaba.excel.annotation.ExcelProperty;
import org.dromara.common.tenant.core.TenantEntity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.tenant.core.TenantEntity;
import java.io.Serial;
@ -26,6 +27,7 @@ public class PointInfo extends TenantEntity {
* 自增id
*/
@TableId(value = "id")
private String id;
/**
@ -48,6 +50,11 @@ public class PointInfo extends TenantEntity {
*/
private String organizationName;
/**
* 链路维护单位
*/
private String linkUnit;
/**
* 维护单位
*/
@ -68,37 +75,17 @@ public class PointInfo extends TenantEntity {
*/
private String latitude;
/**
* 项目名称
*/
private String projectName;
/**
* 项目id
*/
private String projectId;
/**
* 备注
*/
private String remark;
/**
* 端口
*/
private String port;
/**
* ip地址
*/
private String ip;
/**
* 链路维护单位
*/
private String linkUnit;
private String port;
/**
* 建设项目

15
ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/PointInfoVo.java

@ -1,5 +1,6 @@
package org.dromara.platform.domain.vo;
import com.alibaba.excel.annotation.ExcelIgnore;
import org.dromara.common.tenant.core.TenantEntity;
import org.dromara.platform.domain.PointInfo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
@ -32,7 +33,7 @@ public class PointInfoVo extends TenantEntity implements Serializable {
/**
* 自增id
*/
@ExcelProperty(value = "自增id")
@ExcelProperty(value = "唯一标识码")
private String id;
/**
@ -107,7 +108,7 @@ public class PointInfoVo extends TenantEntity implements Serializable {
/**
* 项目名称
*/
@ExcelProperty(value = "项目名称")
@ExcelProperty(value = "所属项目")
private String projectName;
/**
@ -125,21 +126,23 @@ public class PointInfoVo extends TenantEntity implements Serializable {
/**
* 端口
*/
@ExcelProperty(value = "端口")
@ExcelProperty(value = "设备端口")
private String port;
/**
* ip地址
*/
@ExcelProperty(value = "ip地址")
@ExcelProperty(value = "设备IP")
private String ip;
/**
* 当前状态
*/
@ExcelProperty(value = "当前状态")
//@ExcelProperty(value = "当前状态")
@ExcelIgnore
private Long status;
@ExcelProperty(value = "故障地点")
//@ExcelProperty(value = "故障地点")
@ExcelIgnore
private String faultLocation;
}

69
ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/listener/PointInfoListener.java

@ -0,0 +1,69 @@
package org.dromara.platform.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.dromara.platform.domain.AgreementInfo;
import org.dromara.platform.domain.PointInfo;
import org.dromara.platform.domain.vo.PointInfoVo;
import org.dromara.platform.service.IAgreementInfoService;
import org.dromara.platform.service.IPointInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
/**
* 自定义监听器读数据
* @author gjh
*/
@Slf4j
public class PointInfoListener implements ReadListener<PointInfoVo> {
@Resource
private IPointInfoService pointInfoService ;
private List<PointInfo> list = new ArrayList<>();
/**
* 自己定义一个缓冲量
*/
private static final int BATCH_COUNT = 20;
public PointInfoListener( IPointInfoService pointInfoService) {
this.pointInfoService = pointInfoService;
}
/**
* 每读一行数据都会调用这个方法
*
* @param pointInfoVo
* @param analysisContext
*/
@Override
public void invoke(PointInfoVo pointInfoVo, AnalysisContext analysisContext) {
PointInfo pointInfo = new PointInfo();
BeanUtils.copyProperties(pointInfoVo,pointInfo);
// 读取一行数据就添加到集合
list.add(pointInfo);
// 判断是否到达缓存量了
if (list.size() >= BATCH_COUNT){
// 操作数据库
pointInfoService.addData(list);
list = new ArrayList<>(BATCH_COUNT);
}
}
/**
* 读完整个excel之后再调用这个方法
*
* @param analysisContext
*/
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
if (list.size()>0){
pointInfoService.addData(list);
}
}
}

3
ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/service/IPointInfoService.java

@ -1,5 +1,6 @@
package org.dromara.platform.service;
import org.dromara.platform.domain.PointInfo;
import org.dromara.platform.domain.vo.PointInfoVo;
import org.dromara.platform.domain.bo.PointInfoBo;
import org.dromara.common.mybatis.core.page.TableDataInfo;
@ -72,4 +73,6 @@ public interface IPointInfoService {
* @return
*/
List<PointSelectVo> queryPointNames();
void addData(List<PointInfo> list);
}

5
ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/service/impl/PointInfoServiceImpl.java

@ -163,4 +163,9 @@ public class PointInfoServiceImpl implements IPointInfoService {
return pointSelectVos;
}
@Override
public void addData(List<PointInfo> list) {
baseMapper.insert(list);
}
}

Loading…
Cancel
Save