mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-16 22:36:50 +08:00
fix: 【FCJDFDXTXS-144】优化复制课程的逻辑
This commit is contained in:
@@ -224,6 +224,19 @@ public class CourseDao extends BaseDao<Course> {
|
||||
return count.longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询课程名称
|
||||
* @param courseName
|
||||
* @return
|
||||
*/
|
||||
public List<String> queryCourseNames(String courseName) {
|
||||
String sql = "SELECT name FROM boe_course WHERE deleted = 0 AND (name = :courseName OR name LIKE CONCAT(:courseName,'(%)'))";
|
||||
Query query = entityManager.createNativeQuery(sql);
|
||||
query.setParameter("courseName", courseName);
|
||||
|
||||
return (List<String>) query.getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接FROM及查询条件语句
|
||||
*
|
||||
|
||||
@@ -1882,6 +1882,29 @@ public class CourseServiceImpl implements ICourseService {
|
||||
return course.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成新的课程名称
|
||||
* @param originalName
|
||||
* @param existingNames
|
||||
* @return
|
||||
*/
|
||||
private String generateNewCourseName(String originalName, List<String> existingNames) {
|
||||
int maxNum = 0;
|
||||
String baseName = originalName.replaceAll("\\s*\\(\\d+\\)\\s*$", "").trim();
|
||||
|
||||
for (String name : existingNames) {
|
||||
// 匹配 "baseName (数字)"
|
||||
if (name.startsWith(baseName)) {
|
||||
String suffix = name.substring(baseName.length()).trim();
|
||||
if (suffix.matches("^\\(\\d+\\)$")) {
|
||||
int num = Integer.parseInt(suffix.substring(1, suffix.length() - 1));
|
||||
maxNum = Math.max(maxNum, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
return baseName + " (" + (maxNum + 1) + ")";
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
@Override
|
||||
public String copyCourse(String id, String refId, String refType, String aid, String aname) {
|
||||
@@ -1902,6 +1925,8 @@ public class CourseServiceImpl implements ICourseService {
|
||||
|
||||
String newId = IDGenerator.generate();
|
||||
String courseName = this.courseName(id);
|
||||
List<String> cpCourseNameList = courseDao.queryCourseNames(courseName);
|
||||
String newCourseName = generateNewCourseName(courseName, cpCourseNameList);
|
||||
LocalDateTime time = LocalDateTime.now();
|
||||
String mess = null;
|
||||
if (courseName.length() < 96) {
|
||||
@@ -1915,7 +1940,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
"order_study,status)" +
|
||||
"select '" + newId + "',org_id,'" + id + "','" + refId + "','" + refType + "'," + visible + ",'" + aid + "','" + aname + "','" + time + "',0,'" + aname + "'," +
|
||||
"'" + time + "',1,comments,cover_img,dead_time,device,enable_remark,enabled," +
|
||||
"erasable,0,for_scene,for_users,0,keywords,'" + courseName + "(1)" + "',open_object," +
|
||||
"erasable,0,for_scene,for_users,0,keywords,'" + newCourseName + "',open_object," +
|
||||
"overview,pass_formula,0,publish_time,0,res_owner1,res_owner2," +
|
||||
"res_owner3,score,score_formula,0,source,study_time,0,summary," +
|
||||
"sys_type1,sys_type2,sys_type3,tags,top_time,trample_count,type,value,0," +
|
||||
|
||||
Reference in New Issue
Block a user