Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqi committed Nov 16, 2024
2 parents 2c80bc0 + d30970e commit f4bbbd4
Show file tree
Hide file tree
Showing 396 changed files with 20,626 additions and 425 deletions.
706 changes: 706 additions & 0 deletions carp-dependencies/pom.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion carp-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>cn.sliew</groupId>
<artifactId>carp</artifactId>
<version>0.0.12-SNAPSHOT</version>
<version>0.0.13-SNAPSHOT</version>
</parent>
<artifactId>carp-dist</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>cn.sliew</groupId>
<artifactId>carp-ageiport-example</artifactId>
<version>0.0.12-SNAPSHOT</version>
<version>0.0.13-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>carp-ageiport-processor</artifactId>
Expand All @@ -43,6 +43,11 @@
<artifactId>ageiport-processor-core</artifactId>
</dependency>

<dependency>
<groupId>net.datafaker</groupId>
<artifactId>datafaker</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cn.sliew.carp.example.ageiport.controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.UUID;
import cn.sliew.carp.example.ageiport.util.DataFakerUtil;
import cn.sliew.carp.processor.core.model.UserData;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

@RestController
@RequestMapping("/api/carp/example/ageiport/easyexcel")
@Tag(name = "测试模块-EasyExcel功能")
public class EasyExcelController {

@GetMapping
@Operation(summary = "测试流式导出", description = "测试流式导出")
public void testStreamExport() throws Exception {
File file = FileUtil.file(FileUtil.getUserHomePath() + "/Downloads/export/" + UUID.fastUUID().toString(true) + ".xlsx");
if (FileUtil.exist(file) == false) {
file.createNewFile();
}

// EasyExcel.write(file).head(UserData.class).sheet(1).doWrite(DataFakerUtil.generateList(5));
// 这种指定 sheet 的方式必须执行 finish() 方法。上面的 doWrite() 方法内部会自己执行 finish() 方法
try (ExcelWriter excelWriter = EasyExcel.write(file).head(UserData.class).inMemory(false).autoCloseStream(true).build()) {
// excel 单个 sheet 最多可写入 1048576 条数据。超出后需重新写
for (int i = 1 ; i <= 10; i++) {
WriteSheet writeSheet = EasyExcel.writerSheet(i, "测试" + i).head(UserData.class).build();
doWriteSheet(excelWriter, writeSheet);
System.out.println(String.format("写入第%d批次数据", i));
}
}
}

private void doWriteSheet(ExcelWriter excelWriter, WriteSheet writeSheet) {
for (int i = 0; i < 50; i++) {
excelWriter.write(DataFakerUtil.generateList(10000), writeSheet);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cn.sliew.carp.example.ageiport.util;

import cn.sliew.carp.processor.core.model.UserData;
import net.datafaker.Faker;
import net.datafaker.transformations.Field;
import net.datafaker.transformations.JavaObjectTransformer;
import net.datafaker.transformations.Schema;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public enum DataFakerUtil {
;

private static final Faker FAKER = new Faker();
private static final JavaObjectTransformer J_TRANSFORMER = new JavaObjectTransformer();

public static Schema<Object, ?> userDataSchema() {
return Schema.of(
Field.field("id", () -> FAKER.number().positive()),
Field.field("name", () -> FAKER.name().fullName()),
Field.field("gender", () -> FAKER.gender().types()),
Field.field("age", () -> BigDecimal.valueOf(FAKER.number().numberBetween(1, 100))),
Field.field("groupIndex", () -> FAKER.number().numberBetween(1, 3)),

Field.field("manQuestion1", () -> FAKER.name().fullName()),
Field.field("manQuestion2", () -> FAKER.name().fullName()),
Field.field("womenQuestion1", () -> FAKER.name().fullName()),
Field.field("womenQuestion2", () -> FAKER.name().fullName()),
Field.field("otherQuestion1", () -> FAKER.name().fullName()),
Field.field("otherQuestion2", () -> FAKER.name().fullName())
);
}

public static UserData generate() {
return (UserData) J_TRANSFORMER.apply(UserData.class, userDataSchema());
}

public static List<UserData> generateList(Integer count) {
return IntStream.range(0, count).mapToObj(index -> generate()).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cn.sliew.carp.processor.core.exporter;

import cn.sliew.carp.processor.core.model.UserData;
import cn.sliew.carp.processor.core.model.UserQuery;
import cn.sliew.carp.processor.core.model.UserView;
import com.alibaba.ageiport.common.utils.BeanUtils;
import com.alibaba.ageiport.processor.core.exception.BizException;
import com.alibaba.ageiport.processor.core.model.api.BizExportPage;
import com.alibaba.ageiport.processor.core.model.api.BizUser;
import com.alibaba.ageiport.processor.core.task.exporter.ExportProcessor;
import com.alibaba.ageiport.processor.core.task.exporter.api.BizExportTaskRuntimeConfig;
import com.alibaba.ageiport.processor.core.task.exporter.api.BizExportTaskRuntimeConfigImpl;

import java.util.ArrayList;
import java.util.List;

public class BaseExportProcessor implements ExportProcessor<UserQuery, UserData, UserView> {

@Override
public Integer totalCount(BizUser bizUser, UserQuery query) throws BizException {
return query.getTotalCount();
}

@Override
public List<UserData> queryData(BizUser user, UserQuery query, BizExportPage bizExportPage) throws BizException {
List<UserData> dataList = new ArrayList<>();

Integer totalCount = query.getTotalCount();
for (int i = 1; i <= totalCount; i++) {
final UserData data = new UserData();
data.setId(i);
data.setName("name" + i);
if (i % 3 == 0) {
data.setGender("男");
}
if (i % 3 == 1) {
data.setGender("女");
}
if (i % 3 == 2) {
data.setGender("其他");
}
dataList.add(data);
}
return dataList;
}

@Override
public List<UserView> convert(BizUser user, UserQuery query, List<UserData> data) throws BizException {
List<UserView> dataList = new ArrayList<>();
for (UserData datum : data) {
UserView view = BeanUtils.cloneProp(datum, UserView.class);
dataList.add(view);
}
return dataList;
}

public BizExportTaskRuntimeConfig taskRuntimeConfig(BizUser user, UserQuery query) throws BizException {
final BizExportTaskRuntimeConfigImpl runtimeConfig = new BizExportTaskRuntimeConfigImpl();
runtimeConfig.setExecuteType("STANDALONE");
return runtimeConfig;
}
}
Original file line number Diff line number Diff line change
@@ -1,68 +1,16 @@
package cn.sliew.carp.processor.core.exporter;

import cn.sliew.carp.processor.core.model.UserData;
import cn.sliew.carp.processor.core.model.UserQuery;
import cn.sliew.carp.processor.core.model.UserView;
import com.alibaba.ageiport.common.utils.BeanUtils;
import com.alibaba.ageiport.processor.core.annotation.ExportSpecification;
import com.alibaba.ageiport.processor.core.exception.BizException;
import com.alibaba.ageiport.processor.core.model.api.BizExportPage;
import com.alibaba.ageiport.processor.core.model.api.BizUser;
import com.alibaba.ageiport.processor.core.task.exporter.ExportProcessor;
import com.alibaba.ageiport.processor.core.task.exporter.api.BizExportTaskRuntimeConfig;
import com.alibaba.ageiport.processor.core.task.exporter.api.BizExportTaskRuntimeConfigImpl;

import java.util.ArrayList;
import java.util.List;


//1.实现ExportProcessor接口
@ExportSpecification(code = "CSVExportProcessor", name = "CSVExportProcessor")
public class CSVExportProcessor implements ExportProcessor<UserQuery, UserData, UserView> {

//2.实现ExportProcessor接口的TotalCount方法
@Override
public Integer totalCount(BizUser bizUser, UserQuery query) throws BizException {
return query.getTotalCount();
}
public class CSVExportProcessor extends BaseExportProcessor {

//3.实现ExportProcessor接口的queryData方法
@Override
public List<UserData> queryData(BizUser user, UserQuery query, BizExportPage bizExportPage) throws BizException {
List<UserData> dataList = new ArrayList<>();

Integer offset = bizExportPage.getOffset();
Integer size = bizExportPage.getSize();
for (int i = 1; i <= size; i++) {
int index = offset + i;
final UserData data = new UserData();
data.setId(index);
data.setName("name" + index);
if (index % 3 == 0) {
data.setGender("男");
}
if (index % 3 == 1) {
data.setGender("女");
}
if (index % 3 == 2) {
data.setGender("其他");
}
dataList.add(data);
}
return dataList;
}

//4.实现ExportProcessor接口的convert方法
@Override
public List<UserView> convert(BizUser user, UserQuery query, List<UserData> data) throws BizException {
List<UserView> dataList = new ArrayList<>();
for (UserData datum : data) {
UserView view = BeanUtils.cloneProp(datum, UserView.class);
dataList.add(view);
}
return dataList;
}

public BizExportTaskRuntimeConfig taskRuntimeConfig(BizUser user, UserQuery query) throws BizException {
final BizExportTaskRuntimeConfigImpl runtimeConfig = new BizExportTaskRuntimeConfigImpl();
runtimeConfig.setExecuteType("STANDALONE");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,15 @@
package cn.sliew.carp.processor.core.exporter;

import cn.sliew.carp.processor.core.model.UserData;
import cn.sliew.carp.processor.core.model.UserQuery;
import cn.sliew.carp.processor.core.model.UserView;
import com.alibaba.ageiport.common.utils.BeanUtils;
import com.alibaba.ageiport.processor.core.annotation.ExportSpecification;
import com.alibaba.ageiport.processor.core.constants.ExecuteType;
import com.alibaba.ageiport.processor.core.exception.BizException;
import com.alibaba.ageiport.processor.core.model.api.BizExportPage;
import com.alibaba.ageiport.processor.core.model.api.BizUser;
import com.alibaba.ageiport.processor.core.task.exporter.ExportProcessor;
import com.alibaba.ageiport.processor.core.task.exporter.api.BizExportTaskRuntimeConfig;
import com.alibaba.ageiport.processor.core.task.exporter.api.BizExportTaskRuntimeConfigImpl;

import java.util.ArrayList;
import java.util.List;

@ExportSpecification(code = "ClusterExportProcessor", name = "ClusterExportProcessor", executeType = ExecuteType.CLUSTER)
public class ClusterExportProcessor implements ExportProcessor<UserQuery, UserData, UserView> {
@Override
public Integer totalCount(BizUser bizUser, UserQuery query) throws BizException {
return query.getTotalCount();
}

@Override
public List<UserData> queryData(BizUser user, UserQuery query, BizExportPage bizExportPage) throws BizException {
List<UserData> dataList = new ArrayList<>();

Integer totalCount = query.getTotalCount();
for (int i = 1; i <= totalCount; i++) {
final UserData data = new UserData();
data.setId(i);
data.setName("name" + i);
if (i % 3 == 0) {
data.setGender("男");
}
if (i % 3 == 1) {
data.setGender("女");
}
if (i % 3 == 2) {
data.setGender("其他");
}
dataList.add(data);
}
return dataList;
}

@Override
public List<UserView> convert(BizUser user, UserQuery query, List<UserData> data) throws BizException {
List<UserView> dataList = new ArrayList<>();
for (UserData datum : data) {
UserView view = BeanUtils.cloneProp(datum, UserView.class);
dataList.add(view);
}
return dataList;
}
public class ClusterExportProcessor extends BaseExportProcessor {

@Override
public BizExportTaskRuntimeConfig taskRuntimeConfig(BizUser user, UserQuery query) throws BizException {
Expand Down
Loading

0 comments on commit f4bbbd4

Please sign in to comment.