This commit is contained in:
黎润豪 2026-01-04 16:53:42 +08:00
commit 4a4a1af7ca
6 changed files with 51 additions and 128 deletions

View File

@ -10,6 +10,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -33,14 +34,14 @@ public class EntBaseExpelledInfoController {
@Resource @Resource
private IEntBaseExpelledInfoService entBaseExpelledInfoService; private IEntBaseExpelledInfoService entBaseExpelledInfoService;
@ApiOperation(value = "1.分页查询市场主体拟除名名单信息", position = 1) @ApiOperation(value = "1.分页查询市场主体拟除名名单信息")
@PostMapping("/list") @PostMapping("/list")
public RestResult<IPage<EntBaseExpelledInfo>> list(@RequestBody BaseQuery<EntBaseExpelledInfo> query) { public RestResult<IPage<EntBaseExpelledInfo>> list(@RequestBody BaseQuery<EntBaseExpelledInfo> query) {
IPage<EntBaseExpelledInfo> data = entBaseExpelledInfoService.listEntBaseExpelledInfo(query); IPage<EntBaseExpelledInfo> data = entBaseExpelledInfoService.listEntBaseExpelledInfo(query);
return RestResult.ok(data); return RestResult.ok(data);
} }
@ApiOperation(value = "2.新增、更新、删除市场主体拟除名名单信息", position = 2) @ApiOperation(value = "2.新增、更新、删除市场主体拟除名名单信息")
@PostMapping("/save") @PostMapping("/save")
public RestResult<?> save(@RequestBody EntBaseExpelledInfo query){ public RestResult<?> save(@RequestBody EntBaseExpelledInfo query){
entBaseExpelledInfoService.saveOrUpdateEntBaseExpelledInfo(query); entBaseExpelledInfoService.saveOrUpdateEntBaseExpelledInfo(query);
@ -60,6 +61,11 @@ public class EntBaseExpelledInfoController {
if (annex == null || annex.isEmpty()) { if (annex == null || annex.isEmpty()) {
return RestResult.error(ResultCode.PARAM_IS_BLANK); return RestResult.error(ResultCode.PARAM_IS_BLANK);
} }
String fileName = annex.getOriginalFilename();
if (StringUtils.isBlank(fileName)
|| (!fileName.toLowerCase().endsWith(".xls") && !fileName.toLowerCase().endsWith(".xlsx"))) {
return RestResult.error(ResultCode.BUSINESS_LOGIC_ERROR,"文件类型错误");
}
entBaseExpelledInfoService.batchImportExpelledInfo(annex); entBaseExpelledInfoService.batchImportExpelledInfo(annex);
return RestResult.ok(); return RestResult.ok();
} }

View File

@ -8,7 +8,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.List;
/** /**
* @Description: 市场主体拟除名名单信息表接口类 * @Description: 市场主体拟除名名单信息表接口类
@ -42,9 +41,4 @@ public interface IEntBaseExpelledInfoService extends IService<EntBaseExpelledInf
* 批量导入市场主体拟除名名单信息 * 批量导入市场主体拟除名名单信息
*/ */
void batchImportExpelledInfo(MultipartFile annex) throws IOException; void batchImportExpelledInfo(MultipartFile annex) throws IOException;
/**
* 批量导入市场主体拟除名名单信息
*/
void batchImportExpelledInfo(List<EntBaseExpelledInfo> datas);
} }

View File

@ -1,6 +1,5 @@
package com.chinaweal.aiccs.aiccs.expelled.service.impl; package com.chinaweal.aiccs.aiccs.expelled.service.impl;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@ -9,9 +8,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinaweal.aiccs.aiccs.expelled.entity.EntBaseExpelledInfo; import com.chinaweal.aiccs.aiccs.expelled.entity.EntBaseExpelledInfo;
import com.chinaweal.aiccs.aiccs.expelled.mapper.EntBaseExpelledInfoMapper; import com.chinaweal.aiccs.aiccs.expelled.mapper.EntBaseExpelledInfoMapper;
import com.chinaweal.aiccs.aiccs.expelled.service.IEntBaseExpelledInfoService; import com.chinaweal.aiccs.aiccs.expelled.service.IEntBaseExpelledInfoService;
import com.chinaweal.aiccs.listener.EasyExcelReadListener; import com.chinaweal.aiccs.aiccs.expelled.vo.EntBaseExpelledInfoExcelVo;
import com.chinaweal.aiccs.aiccs.punishment.util.ExcelIePortUtils;
import com.chinaweal.aiccs.aiccs.punishment.util.ExcelListener;
import com.chinaweal.aiccs.utils.BeanUtil; import com.chinaweal.aiccs.utils.BeanUtil;
import com.chinaweal.youfool.framework.springboot.base.query.BaseQuery; import com.chinaweal.youfool.framework.springboot.base.query.BaseQuery;
import com.chinaweal.youfool.framework.springboot.exception.custom.BusinessException;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -101,20 +104,18 @@ public class EntBaseExpelledInfoServiceImpl extends ServiceImpl<EntBaseExpelledI
@Override @Override
public void batchImportExpelledInfo(MultipartFile annex) throws IOException { public void batchImportExpelledInfo(MultipartFile annex) throws IOException {
EasyExcelReadListener readListener = new EasyExcelReadListener<EntBaseExpelledInfo>(datas -> { ExcelListener excelListener = ExcelIePortUtils.getExcelListener(annex, new EntBaseExpelledInfoExcelVo(), 1, 1);
// 数据处理逻辑 Object objects = excelListener.getDatas();
batchImportExpelledInfo(datas); if (objects == null) {
}); throw new BusinessException("读取不到数据,请检查上传的附件是否有录入数据");
EasyExcel.read(new ByteArrayInputStream(annex.getBytes()), EntBaseExpelledInfo.class, readListener).sheet().doRead();
}
@Override
public void batchImportExpelledInfo(List<EntBaseExpelledInfo> datas) {
if (datas == null) {
return;
} }
// 再插入 List<EntBaseExpelledInfoExcelVo> datas = (List<EntBaseExpelledInfoExcelVo>) objects;
for (EntBaseExpelledInfo expelledInfo : datas) { if (CollectionUtils.isEmpty(datas)) {
throw new BusinessException("读取不到数据,请检查上传的附件是否有录入数据");
}
for (EntBaseExpelledInfoExcelVo excelVo : datas) {
EntBaseExpelledInfo expelledInfo = new EntBaseExpelledInfo();
BeanUtil.copyBean(excelVo, expelledInfo);
saveOrUpdateEntBaseExpelledInfo(expelledInfo); saveOrUpdateEntBaseExpelledInfo(expelledInfo);
} }
} }

View File

@ -0,0 +1,27 @@
package com.chinaweal.aiccs.aiccs.expelled.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import lombok.Data;
/**
* @Description:
* @Author: TiAmo-cc
* @Email: 1049976610@qq.com
* @Date: 2026/1/4 16:25
*/
@Data
public class EntBaseExpelledInfoExcelVo extends BaseRowModel {
@ExcelProperty(value = "市场主体名称", index = 0)
private String entName;
@ExcelProperty(value = "统一社会信用代码", index = 1)
private String uscc;
@ExcelProperty(value = "法定代表人(负责人、经营者)", index = 2)
private String lerepName;
@ExcelProperty(value = "住所(经营场所)", index = 3)
private String address;
}

View File

@ -1,84 +0,0 @@
package com.chinaweal.aiccs.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.CellExtra;
import com.alibaba.excel.read.listener.ReadListener;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
/**
* @Description alibaba读取excel数据监听器
* @Author Radish Angelo
* @Date 2022/11/18 14:56
* @Email 1049976610@qq.com
*/
public class EasyExcelReadListener<T> implements ReadListener<T> {
/**
* 每隔100条存储数据库然后清理list 方便内存回收
*/
private static final int BATCH_COUNT = 100;
/**
* 缓存的数据
*/
private List<T> cachedData = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
/**
* 数据处理逻辑接口
*/
private Consumer<List<T>> consumer;
/**
* 构造方法需要将具体的数据处理逻辑通过consumer传进来
*/
public EasyExcelReadListener(Consumer<List<T>> consumer) {
this.consumer = consumer;
}
@Override
public void onException(Exception e, AnalysisContext analysisContext) throws Exception {
}
@Override
public void invokeHead(Map<Integer, CellData> map, AnalysisContext analysisContext) {
}
/**
* 这里每一条数据解析都会来调用
*/
@Override
public void invoke(T t, AnalysisContext analysisContext) {
cachedData.add(t);
// 达到BATCH_COUNT了需要去存储一次数据库防止数据几万条数据在内存容易OOM
if (cachedData.size() >= BATCH_COUNT) {
consumer.accept(cachedData);
// 存储完成清理 list
cachedData = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
}
}
@Override
public void extra(CellExtra cellExtra, AnalysisContext analysisContext) {
}
/**
* 所有数据解析完成了 都会来调用
*/
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
// 这里也要保存数据,确保最后遗留的数据也存储到数据库
consumer.accept(cachedData);
}
@Override
public boolean hasNext(AnalysisContext analysisContext) {
return false;
}
}

View File

@ -1,21 +0,0 @@
package com.chinaweal.aiccs.listener;
import java.util.ArrayList;
import java.util.List;
/**
* @Description:
* @Author: TiAmo-cc
* @Email: 1049976610@qq.com
* @Date: 2026/1/3 20:56
*/
public class ListUtils {
public static <T> List<T> newArrayList() {
return new ArrayList<>();
}
public static <T> List<T> newArrayListWithExpectedSize(int size) {
return new ArrayList<>(size);
}
}