1. 添加word生成测试用例

topo_dev
xueqingkun 9 months ago
parent 28a081c5d0
commit cb3343ebf2

@ -152,9 +152,10 @@ public class CaseScoreDetailBuilder {
caseScoreDetailDTO.setCommonScore(this.getCommonScore());
Integer crimeScore = this.getCrimeScore();
Integer crimeOutScore = this.getCrimeOutScore();
caseScoreDetailDTO.setCrimeScore(crimeScore < crimeOutScore? crimeOutScore:crimeScore);
caseScoreDetailDTO.setSpecificCrimeScore(crimeScore < crimeOutScore? crimeOutScore:crimeScore);
caseScoreDetailDTO.setTotalScore(crimeScore + crimeOutScore);
int sumScore = caseScoreDetailDTO.getCommonScore() + caseScoreDetailDTO.getCrimeScore();
int sumScore = caseScoreDetailDTO.getCommonScore() + caseScoreDetailDTO.getSpecificCrimeScore();
ScoreEnum scoreEnum = ScoreEnum.getScoreEnum(sumScore);
if (scoreEnum != null){
caseScoreDetailDTO.setScoreDesc(scoreEnum.getDesc());

@ -1,5 +1,7 @@
package com.supervision.police.dto.caseScore;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@ -16,8 +18,11 @@ public class CaseScoreDetailDTO {
@Schema(description = "共性指标分数")
private Integer commonScore;
@Schema(description = "入罪指标分数")
private Integer crimeScore;
@Schema(description = "入罪/出罪指标分数")
private Integer specificCrimeScore;
@Schema(description = "总分数")
private Integer totalScore;
@Schema(description = "分数描述")
private String scoreDesc;
@ -49,5 +54,46 @@ public class CaseScoreDetailDTO {
@Schema(description = "缺失的原子指标数量")
private Integer missAtomicIndexCount;
// 公共指标描述
private String commonIndexDesc;
// 出罪\入罪指标描述
private String specificCrimeIndexDesc;
public void buildDesc(){
if (CollUtil.isNotEmpty(this.getCommonIndexDescList())){
StringBuilder append = new StringBuilder();
for (int i = 0; i < this.getCommonIndexDescList().size(); i++) {
String text = this.getCommonIndexDescList().get(i);
if (!StrUtil.endWith(text,"。")){
text = text + "。";
}
if (i > 0){
append.append("\t");
}
append.append(i+1).append(".\t").append(text);
if (i < this.getCommonIndexDescList().size()-1){
append.append("\n");
}
}
this.setCommonIndexDesc(append.toString());
append = new StringBuilder();
for (int i = 0; i < this.getSpecificCrimeIndexDescList().size(); i++) {
String text = this.getSpecificCrimeIndexDescList().get(i);
if (!StrUtil.endWith(text,"。")){
text = text + "。";
}
if (i > 0){
append.append("\t");
}
append.append(i+1).append(".\t").append(text);
if (i < this.getSpecificCrimeIndexDescList().size()-1){
append.append("\n");
}
}
this.setSpecificCrimeIndexDesc(append.toString());
}
}
}

@ -1,11 +1,22 @@
package com.supervision.springaidemo;
import com.deepoove.poi.XWPFTemplate;
import com.supervision.police.dto.caseScore.CaseScoreDetailDTO;
import com.supervision.police.service.ModelService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.*;
import java.util.HashMap;
@Slf4j
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WordRenderTest {
@Autowired
private ModelService modelService;
public static void main(String[] args) throws FileNotFoundException {
HashMap<String, Object> data = new HashMap<>();
data.put("name", "张三");
@ -23,5 +34,24 @@ public class WordRenderTest {
throw new RuntimeException(e);
}
}
//裴金禄涉嫌合同诈骗案详情-v0.docx
@Test
public void test() throws FileNotFoundException {
CaseScoreDetailDTO caseScoreDetailDTO = modelService.caseScoreDetail("1810902613967384577");
caseScoreDetailDTO.buildDesc();
// 加载本地模板文件
InputStream inputStream = new FileInputStream("F:\\out\\裴金禄涉嫌合同诈骗案详情-v0.docx");
// 渲染模板
XWPFTemplate template = XWPFTemplate.compile(inputStream).render(caseScoreDetailDTO);
try {
// 写出到文件
template.writeAndClose(new FileOutputStream("F:\\out\\output.docx"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

Loading…
Cancel
Save