PhaseUtil.java
6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.phase;
import com.alibaba.fastjson.JSON;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
public class PhaseUtil {
public static void main(String[] args) {
String speechName = args[0];
String currentDir = System.getProperty("user.dir");
String filePath = currentDir + File.separator + speechName + ".xlsx";
//获取excel文件
List<Map<String, String>> orgPhaseList = ExcelUtil.readExcel(filePath,
0);
//将excel文件转换为格式化的json
ArrayList<SpeechBigPhaseEditDTO> bigPhaseList = getBigPhaseListByMapList(orgPhaseList);
//将json输出到系统文件
SpeechPhaseDTO speechPhaseDTO = SpeechPhaseDTO.builder().phaseList(bigPhaseList).speechName(speechName).stlId(0L).build();
String phaseJson = JSON.toJSONString(speechPhaseDTO);
System.out.println(phaseJson);
putOutFile(phaseJson, currentDir, speechName);
}
private static void putOutFile(String phaseJson, String currentDir, String speechName) {
String filePath = currentDir + File.separator + speechName + ".txt";
FileOutputStream out = null;
try {
out = new FileOutputStream(new File(filePath));
out.write(phaseJson.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static ArrayList<SpeechBigPhaseEditDTO> getBigPhaseListByMapList(List<Map<String, String>> orgPhaseList) {
ArrayList<SpeechBigPhaseEditDTO> bigPhaseList = new ArrayList<>();
HashMap<Integer, SpeechBigPhaseEditDTO> bigPhaseNumMap = new HashMap<>();
//循环处理每一条话术配置
int rowNum = 2;
for (Map<String, String> orgPhase : orgPhaseList) {
if (!StringUtils.isEmpty(orgPhase.get(ColDesc.COL_HINT_NUM.getCol()))) {
System.out.println("当前处理excel行号:" + rowNum);
//获取大环节对象
SpeechBigPhaseEditDTO bigPhaseEditDTO = fetchBigPhase(bigPhaseNumMap, bigPhaseList, orgPhase);
//生成小环节对象
SpeechLittlePhaseAddDTO littlePhaseAddDTO;
try {
littlePhaseAddDTO = fetchLittlePhase(orgPhase);
} catch (Exception e) {
throw new RuntimeException("请检查第" + rowNum + "行的数据是否存在参数缺失,或者数据格式问题!");
}
//将小环节封装入大环节对象的hintList属性中
bigPhaseEditDTO.getHintsList().add(littlePhaseAddDTO.transToVO());
}
rowNum++;
}
sortHintList(bigPhaseList);
return bigPhaseList;
}
private static void sortHintList(ArrayList<SpeechBigPhaseEditDTO> bigPhaseList) {
//将大环节列表按小环节序号排序
bigPhaseList.sort(Comparator.comparingInt(SpeechBigPhaseEditDTO::getPhaseNum));
for (SpeechBigPhaseEditDTO speechBigPhaseEditDTO : bigPhaseList) {
List<SpeechLittlePhaseEditDTO> hintsList = speechBigPhaseEditDTO.getHintsList();
//将小环节列表按小环节序号排序
hintsList.sort(Comparator.comparingInt(SpeechLittlePhaseEditDTO::getHintNum));
}
}
private static SpeechLittlePhaseAddDTO fetchLittlePhase(Map<String, String> orgPhase) {
int littlePhaseSerialNum = Integer.parseInt(orgPhase.get(ColDesc.COL_HINT_NUM.getCol()));
String littlePhaseName = orgPhase.get(ColDesc.COL_HINT_NAME.getCol());
int triggerConditionSwitch = Integer.parseInt(orgPhase.get(ColDesc.COL_CONDITION_TYPE.getCol()));
String triggerConditionContent = orgPhase.get(ColDesc.COL_CONDITION_CONTENT.getCol());
int phaseType = Integer.parseInt(orgPhase.get(ColDesc.COL_HINT_TYPE.getCol()));
int fileType = 0;
int identityType = 0;
int idcardOcrSwitch = 0;
int popup = 2;
try {
fileType = Integer.parseInt(orgPhase.get(ColDesc.COL_DOCTYPE.getCol()));
} catch (NumberFormatException e) {
}
try {
identityType = Integer.parseInt(orgPhase.get(ColDesc.COL_CERTIFICATE_TYPE.getCol()));
} catch (NumberFormatException e) {
}
try {
idcardOcrSwitch = Integer.parseInt(orgPhase.get(ColDesc.COL_OCR.getCol()));
} catch (NumberFormatException e) {
}
try {
popup = Integer.parseInt(orgPhase.get(ColDesc.COL_POPUP.getCol()));
} catch (NumberFormatException e) {
}
String ttsContent = orgPhase.get(ColDesc.COL_TTS.getCol());
String littlePhaseTitle = orgPhase.get(ColDesc.COL_HINT_TITLE.getCol());
String sure = orgPhase.get(ColDesc.COL_SURE.getCol());
String no = orgPhase.get(ColDesc.COL_NO.getCol());
return SpeechLittlePhaseAddDTO.builder()
.littlePhaseSerialNum(littlePhaseSerialNum)
.littlePhaseName(littlePhaseName)
.triggerConditionSwitch(triggerConditionSwitch)
.triggerConditionContent(triggerConditionContent)
.phaseType(phaseType)
.sure(sure)
.no(no)
.fileType(fileType)
.identityType(identityType)
.idcardOcrSwitch(idcardOcrSwitch)
.ttsContent(ttsContent)
.littlePhaseTitle(littlePhaseTitle)
.bindUnique("")
.popup(popup)
.build();
}
private static SpeechBigPhaseEditDTO fetchBigPhase(HashMap<Integer, SpeechBigPhaseEditDTO> bigPhaseNumMap, ArrayList<SpeechBigPhaseEditDTO> bigPhaseList, Map<String, String> orgPhase) {
Integer bigPhaseNum = Integer.parseInt(orgPhase.get(ColDesc.COL_PHASE_NUM.getCol()));
SpeechBigPhaseEditDTO bigPhaseEditDTO = bigPhaseNumMap.get(bigPhaseNum);
if (bigPhaseEditDTO == null) {
bigPhaseEditDTO = new SpeechBigPhaseEditDTO();
bigPhaseEditDTO.setPhaseNum(bigPhaseNum);
bigPhaseEditDTO.setPhaseTitle(orgPhase.get(ColDesc.COL_PHASE_TITLE.getCol()));
bigPhaseEditDTO.setHintsList(new ArrayList<>());
bigPhaseNumMap.put(bigPhaseNum, bigPhaseEditDTO);
bigPhaseList.add(bigPhaseEditDTO);
}
return bigPhaseEditDTO;
}
}