-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
396 changed files
with
20,626 additions
and
425 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...rocessor/src/main/java/cn/sliew/carp/example/ageiport/controller/EasyExcelController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...p-ageiport-processor/src/main/java/cn/sliew/carp/example/ageiport/util/DataFakerUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...rt-processor/src/main/java/cn/sliew/carp/processor/core/exporter/BaseExportProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
54 changes: 1 addition & 53 deletions
54
...ort-processor/src/main/java/cn/sliew/carp/processor/core/exporter/CSVExportProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 1 addition & 46 deletions
47
...processor/src/main/java/cn/sliew/carp/processor/core/exporter/ClusterExportProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.