a65a31ce by sunchenjie

create:创建git库

0 parents
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="excel" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="excel" options="-parameters" />
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="UTF-8" addBOMForNewFiles="with NO BOM">
<file url="file://$PROJECT_DIR$" charset="UTF-8" />
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>phase</groupId>
<artifactId>excel</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.phase;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
//用于excel中的列名和属性名映射,提高可读性和方便维护
public enum ColDesc {
COL_PHASE_NUM("phaseNum", "大环节No"),
COL_PHASE_TITLE("phaseTitle", "大环节名称"),
COL_HINT_NUM("littlePhaseSerialNum", "小环节No"),
COL_HINT_NAME("littlePhaseName", "小环节名称"),
COL_HINT_TITLE("littlePhaseTitle", "环节展示标题"),
COL_TTS("ttsContent", "TTS报读内容"),
COL_CONDITION_TYPE("triggerConditionSwitch", "触发条件(1=开启,2=关闭,3=自定义)"),
COL_CONDITION_CONTENT("triggerConditionContent", "触发条件内容"),
COL_HINT_TYPE("phaseType", "环节类型(1=问答环节,2=陈述环节,3=文件出示环节,4=证件出示环节,5=通用环节,6=人脸识别环节,7=人工报读环节)"),
COL_SURE("sure", "肯定答复"),
COL_NO("no", "否定答复"),
COL_DOCTYPE("fileType", "文件识别类别(1=通用文件)"),
COL_CERTIFICATE_TYPE("identityType", "证件类别(1=身份证信息面,2=身份证国徽面,3=执业证正面,4=执业正反面)"),
COL_OCR("idcardOcrSwitch", "OCR开启(1=开启,2=关闭)");
private String attr;
private String col;
ColDesc(String attr, String col) {
this.attr = attr;
this.col = col;
}
public String getAttr() {
return attr;
}
public String getCol() {
return col;
}
private static Map<String, String> attrMap = new HashMap<>();
static {
for (ColDesc c : ColDesc.values()) {
if (!StringUtils.isEmpty(c.getCol()) && !attrMap.containsKey(c.getCol())) {
attrMap.put(c.getCol(), c.getAttr());
}
}
}
public static String getAttr(String col) {
return attrMap.get(col);
}
}
package com.phase;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Excel导入导出
* @Author: guandezhi
* @Date: 2019/3/9 9:47
*/
public class ExcelUtil {
/**
* 从excel中读内容
*
* @param filePath
* @param sheetIndex
* @return
*/
public static List<Map<String, String>> readExcel(String filePath, Integer sheetIndex) {
List<Map<String, String>> dataList = new ArrayList<>();
Workbook wb = ExcelUtil.createWorkBook(filePath);
if (wb != null) {
Sheet sheet = wb.getSheetAt(sheetIndex);
int maxRownum = sheet.getPhysicalNumberOfRows();
Row firstRow = sheet.getRow(0);
int maxColnum = firstRow.getPhysicalNumberOfCells();
String columns[] = new String[maxColnum];
for (int i = 0; i < maxRownum; i++) {
Map<String, String> map = null;
if (i > 0) {
map = new LinkedHashMap<>();
firstRow = sheet.getRow(i);
}
if (firstRow != null) {
String cellData = null;
for (int j = 0; j < maxColnum; j++) {
cellData = (String) ExcelUtil.getCellFormatValue(firstRow.getCell(j));
if (i == 0) {
columns[j] = cellData;
} else {
map.put(columns[j], cellData);
}
}
} else {
break;
}
if (i > 0) {
dataList.add(map);
}
}
}
return dataList;
}
private static Workbook createWorkBook(String filePath) {
Workbook wb = null;
if (filePath == null) {
return null;
}
String extString = filePath.substring(filePath.lastIndexOf("."));
InputStream is = null;
try {
is = new FileInputStream(filePath);
if (".xls".equals(extString)) {
return wb = new HSSFWorkbook(is);
} else if (".xlsx".equals(extString)) {
return wb = new XSSFWorkbook(is);
} else {
return wb;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return wb;
}
/**
* 将字段转为相应的格式
*
* @param cell
* @return
*/
private static Object getCellFormatValue(Cell cell) {
Object cellValue = null;
if (cell != null) {
//判断cell类型
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC: {
double numericCellValue = cell.getNumericCellValue();
cellValue = String.valueOf(Double.valueOf(numericCellValue).intValue());
break;
}
case Cell.CELL_TYPE_FORMULA: {
if (DateUtil.isCellDateFormatted(cell)) {
cellValue = cell.getDateCellValue();////转换为日期格式YYYY-mm-dd
} else {
cellValue = String.valueOf(cell.getNumericCellValue()); //数字
}
break;
}
case Cell.CELL_TYPE_STRING: {
cellValue = cell.getRichStringCellValue().getString();
break;
}
default:
cellValue = "";
}
} else {
cellValue = "";
}
return cellValue;
}
}
\ No newline at end of file
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()))) {
//获取大环节对象
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;
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) {
}
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("")
.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;
}
}
package com.phase;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.List;
@Setter
@Getter
@NoArgsConstructor
public class SpeechBigPhaseEditDTO {
private Integer phaseNum;
private String phaseTitle;
private List<SpeechLittlePhaseEditDTO> hintsList;
}
package com.phase;
import lombok.*;
import org.springframework.util.StringUtils;
import java.util.HashMap;
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SpeechLittlePhaseAddDTO {
private int littlePhaseSerialNum;
private String littlePhaseName;
//触发条件状态(1 = 开, 2 = 关, 3 = 自定义条件开启)
private int triggerConditionSwitch;
//触发条件内容
private String triggerConditionContent;
// 环节类型(1 = 问答环节, 2 = 陈述环节, 3 = 文件初始环节, 4 = 证件初始环节, 5 = 通用环节, 6 = 人脸识别环节)
private int phaseType;
//肯定答复
private String sure;
//否定答复
private String no;
//文件出示环节---文件类型(1 = 通用文件)
private int fileType;
//证件出示环节---证件类型(1 = 身份证正面, 2 = 身份证反面, 3 = 执业证正面, 4 = 执业证反面)
private int identityType;
//身份证证件ocr(正/反)开关(1 = 开, 2 = 关)
private int idcardOcrSwitch;
// 环节展示标题
private String littlePhaseTitle;
//tts播报内容
private String ttsContent;
private int bindBefore;
private int bindAfter;
private String bindUnique;
public SpeechLittlePhaseEditDTO transToVO() {
return SpeechLittlePhaseEditDTO.builder().hintNum(this.littlePhaseSerialNum).hintName(this.littlePhaseName)
.hintTitle(this.littlePhaseTitle).tts(this.ttsContent).condition(getConditionMap()).hintType(getHintType()).
bindBefore(this.bindBefore).bindAfter(this.bindAfter).bindUnique(this.bindUnique).classIndex(0).build();
}
private HashMap<String, Object> getConditionMap() {
HashMap<String, Object> conditionMap = new HashMap<>();
conditionMap.put("conditionType", this.triggerConditionSwitch);
if (this.triggerConditionSwitch == 3) {
conditionMap.put("conditionContent", this.triggerConditionContent);
}
return conditionMap;
}
private HashMap<String, Object> getHintType() {
HashMap<String, Object> hintTypeMap = new HashMap<>();
hintTypeMap.put("hintType", this.phaseType);
if (this.phaseType == 1) {
if (!StringUtils.isEmpty(this.sure)) {
hintTypeMap.put("sure", this.sure);
}
if (!StringUtils.isEmpty(this.no)) {
hintTypeMap.put("no", this.no);
}
} else if (this.phaseType == 3) {
hintTypeMap.put("docType", this.fileType);
} else if (this.phaseType == 4) {
hintTypeMap.put("certificateType", this.identityType);
if (this.identityType == 1 || this.identityType == 2) {
hintTypeMap.put("ocr", this.idcardOcrSwitch);
}
}
return hintTypeMap;
}
}
package com.phase;
import lombok.*;
import java.util.HashMap;
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SpeechLittlePhaseEditDTO {
private Integer hintNum;
private String hintName;
private String hintTitle;
private String tts;
//触发条件状态(1 = 开, 2 = 关, 3 = 自定义条件开启),map中包含条件状态以及条件内容;
private HashMap condition;
//触发条件内容,环节类型已经相关内容,为了便于匹配前端入参格式,用hashMap封装入参
private HashMap hintType;
private Integer bindBefore;
private Integer bindAfter;
private String bindUnique;
private Integer classIndex;
}
package com.phase;
import lombok.*;
import java.util.List;
/**
* 话术编辑
*
* @author sunchenjie <sunchenjie@situdata.com> 2020/03/31
**/
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SpeechPhaseDTO {
private Long stlId;
private String speechName;
private List<SpeechBigPhaseEditDTO> phaseList;
}
No preview for this file type
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!