1.添加测试用例

2. 修改字段类型
master
gitee 3 days ago
parent dc15471f2e
commit 1033f7fe87

@ -42,7 +42,7 @@ public class ScriptKeypoints implements Serializable {
/** /**
* *
*/ */
private String scriptTypeOrderNum; private Integer scriptTypeOrderNum;
/** /**
* *

@ -11,14 +11,14 @@
<result property="keyPoint" column="key_point " jdbcType="VARCHAR"/> <result property="keyPoint" column="key_point " jdbcType="VARCHAR"/>
<result property="keyPointExample" column="key_point_example" jdbcType="VARCHAR"/> <result property="keyPointExample" column="key_point_example" jdbcType="VARCHAR"/>
<result property="scriptTypeOrderNum" column="script_type_order_num" jdbcType="INTEGER"/> <result property="scriptTypeOrderNum" column="script_type_order_num" jdbcType="INTEGER"/>
<result property="keyPointOrderNum" column="keypoint_order_num" jdbcType="INTEGER"/> <result property="keyPointOrderNum" column="key_point_order_num" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id,script_type,script_id, id,script_type,script_id,
key_point ,key_point_example,script_type_order_num,keypoint_order_num, key_point ,key_point_example,script_type_order_num,key_point_order_num,
create_time,update_time create_time,update_time
</sql> </sql>
<select id="listByUserIdAndProductCategory" resultType="com.supervision.livedigitalavatarmanage.dto.ScriptKeyPointsDTO"> <select id="listByUserIdAndProductCategory" resultType="com.supervision.livedigitalavatarmanage.dto.ScriptKeyPointsDTO">

@ -1,13 +1,124 @@
package com.supervision.livedigitalavatarmanage; package com.supervision.livedigitalavatarmanage;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.supervision.livedigitalavatarmanage.domain.ScriptKeypoints;
import com.supervision.livedigitalavatarmanage.service.ScriptKeypointsService;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@SpringBootTest @SpringBootTest
class LiveDigitalAvatarManageApplicationTests { class LiveDigitalAvatarManageApplicationTests {
@Autowired
private ScriptKeypointsService scriptKeypointsService;
@Test @Test
void contextLoads() { void contextLoads() {
String path = "C:\\Users\\Administrator\\Desktop\\script.txt";
List<String> datas = FileUtil.readUtf8Lines(path);
List<HashMap<String, String>> list = datas.stream().map(i -> StrUtil.split(i, "\t")).map(i -> {
HashMap<String, String> map = new HashMap<>();
map.put("scriptType", i.get(0));
map.put("scriptKeyPoint", i.get(1));
map.put("exampleTemplate", i.get(2));
return map;
}).toList();
List<String> scriptTypes = List.of("开场信息","场控文案","讲品内容","品牌价值","应用场景","促单信息");
// 话术类型 话术关键点 示例模板
Map<String, List<Map<String, String>>> scriptTypeMap = list.stream().collect(Collectors.groupingBy(m -> m.get("scriptType")));
Map<String, List<List<Map<String, String>>>> groupMap = new HashMap<>();
for (String scriptType : scriptTypes) {
List<Map<String, String>> maps = scriptTypeMap.get(scriptType);
if (null == maps) {
System.out.println("话术类型:" + scriptType + ",无数据");
continue;
}
// 随机取五组话术关键点每组关键点条数小于6条大于两条
List<List<Integer>> lists = generateIndexCombinations(maps.size());
List<List<Map<String, String>>> list1 = lists.stream().filter(l -> l.size() <= 6 && l.size() >= 2).map(l -> {
List<Map<String, String>> group = new ArrayList<>();
for (Integer index : l) {
group.add(maps.get(index));
}
return group;
}).toList();
groupMap.put(scriptType, list1);
}
List<List<Map<String, String>>> result = new ArrayList<>();
for (int i = 0; i < 5; i++) {
List<Map<String, String>> objects = new ArrayList<>();
for (String scriptType : scriptTypes) {
List<List<Map<String, String>>> lists = groupMap.get(scriptType);
if (null == lists) {
continue;
}
int i1 = RandomUtil.randomInt(0, lists.size());
List<Map<String, String>> maps = lists.get(i1);
objects.addAll(maps);
}
result.add(objects);
}
for (List<Map<String, String>> mapList : result) {
String scriptId = StrUtil.uuid();
int i = 0;
int index = 0;
String current = "";
for (Map<String, String> mao : mapList) {
String scriptKeyPoint = mao.get("scriptKeyPoint");
String exampleTemplate = mao.get("exampleTemplate");
String scriptType = mao.get("scriptType");
if (StrUtil.equals(scriptKeyPoint, current)){
index ++;
}else {
current = scriptKeyPoint;
index = 0;
}
ScriptKeypoints keypoints = new ScriptKeypoints();
keypoints.setScriptType(scriptType);
keypoints.setKeyPoint(scriptKeyPoint);
keypoints.setScriptId(scriptId);
keypoints.setScriptTypeOrderNum(i);
keypoints.setKeyPointOrderNum(index);
keypoints.setKeyPointExample(exampleTemplate);
scriptKeypointsService.save(keypoints);
i ++;
} }
}
}
/**
* n
* @param n
* @return
*/
private List<List<Integer>> generateIndexCombinations(int n) {
List<List<Integer>> result = new ArrayList<>();
int total = 1 << n; // 2^n
for (int mask = 1; mask < total; mask++) { // 从1开始跳过空集
List<Integer> current = new ArrayList<>();
for (int i = 0; i < n; i++) {
if ((mask & (1 << i)) != 0) { // 检查第i位是否被选中
current.add(i);
}
}
result.add(current);
}
return result;
}
} }

Loading…
Cancel
Save