Browse Source

服务具体内容导入接口

ops-management-platform-backend-dev
gjh 1 month ago
parent
commit
e0de9e725c
  1. 23
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/AgreementInfoController.java
  2. 16
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/AgreementInfo.java
  3. 66
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/listener/AgreementInfoListener.java
  4. 5
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/service/IAgreementInfoService.java
  5. 5
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/service/impl/AgreementInfoServiceImpl.java

23
ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/AgreementInfoController.java

@ -1,11 +1,18 @@
package org.dromara.platform.controller;
import java.io.IOException;
import java.util.List;
import com.alibaba.excel.EasyExcel;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.extern.slf4j.Slf4j;
import org.dromara.platform.domain.AgreementInfo;
import org.dromara.platform.domain.ProjectManager;
import org.dromara.platform.listener.AgreementInfoListener;
import org.dromara.platform.listener.ProjectManagerListener;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
@ -21,6 +28,7 @@ import org.dromara.platform.domain.vo.AgreementInfoVo;
import org.dromara.platform.domain.bo.AgreementInfoBo;
import org.dromara.platform.service.IAgreementInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/**
* 协议信息
@ -31,6 +39,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
@Validated
@RequiredArgsConstructor
@RestController
@Slf4j
@RequestMapping("/platform/agreementInfo")
public class AgreementInfoController extends BaseController {
@ -102,4 +111,18 @@ public class AgreementInfoController extends BaseController {
@PathVariable String[] ids) {
return toAjax(agreementInfoService.deleteWithValidByIds(List.of(ids), true));
}
@PostMapping("/upload")
public void upload(MultipartFile file, HttpServletResponse response,String categoryId) throws IOException {
long t1 = System.currentTimeMillis();
EasyExcel.read(file.getInputStream(), AgreementInfo.class, new AgreementInfoListener(agreementInfoService,categoryId)).sheet().doRead();
response.setContentType("text/html;charset=utf8");
long t2 = System.currentTimeMillis();
response.getWriter().println("导入数据成功!,共用时:"+(t2-t1));
log.info("导入协议信息表数据成功! 共用时:{}ms",(t2-t1));
}
}

16
ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/AgreementInfo.java

@ -1,5 +1,7 @@
package org.dromara.platform.domain;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import org.dromara.common.tenant.core.TenantEntity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
@ -25,61 +27,73 @@ public class AgreementInfo extends TenantEntity {
* 自增id
*/
@TableId(value = "id")
@ExcelIgnore
private String id;
/**
* 服务目录id
*/
@ExcelIgnore
private String serviceCategoryId;
/**
* 交付内容
*/
@ExcelProperty("交付内容")
private String deliverContent;
/**
* 服务项目
*/
@ExcelProperty("服务项目")
private String serviceProject;
/**
* 代码
*/
@ExcelProperty("代码")
private String code;
/**
* 服务内容
*/
@ExcelProperty("服务内容")
private String serviceContent;
/**
* 应级别
* 应级别
*/
@ExcelProperty("响应级别")
private String responseLevel;
/**
* 服务频率
*/
@ExcelProperty("服务频率")
private String frequency;
/**
* 请求类型
*/
@ExcelProperty("请求类型")
private String responseType;
/**
* 交付方式
*/
@ExcelProperty("交付方式")
private String deliverType;
/**
* 交付成果
*/
@ExcelProperty("交付成果")
private String deliverResult;
/**
* 当前状态
*/
@ExcelIgnore
private Long status;
/**

66
ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/listener/AgreementInfoListener.java

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

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

@ -1,5 +1,7 @@
package org.dromara.platform.service;
import org.dromara.platform.domain.AgreementInfo;
import org.dromara.platform.domain.ProjectManager;
import org.dromara.platform.domain.vo.AgreementInfoVo;
import org.dromara.platform.domain.bo.AgreementInfoBo;
import org.dromara.common.mybatis.core.page.TableDataInfo;
@ -65,4 +67,7 @@ public interface IAgreementInfoService {
* @return 是否删除成功
*/
Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid);
void addData(List<AgreementInfo> list);
}

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

@ -136,4 +136,9 @@ public class AgreementInfoServiceImpl implements IAgreementInfoService {
}
return baseMapper.deleteByIds(ids) > 0;
}
@Override
public void addData(List<AgreementInfo> list) {
baseMapper.insert(list);
}
}

Loading…
Cancel
Save