学年管理-新增模块标签
This commit is contained in:
@@ -36,6 +36,10 @@ public class SrsStuYear extends BaseEntity
|
||||
@Excel(name = "学年名称")
|
||||
private String stuYearName;
|
||||
|
||||
/** 模块标签 */
|
||||
@Excel(name = "模块标签")
|
||||
private String moduleTags;
|
||||
|
||||
/** 开始时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@@ -69,6 +73,15 @@ public class SrsStuYear extends BaseEntity
|
||||
{
|
||||
return stuYearName;
|
||||
}
|
||||
|
||||
|
||||
public void setModuleTags(String moduleTags) {
|
||||
this.moduleTags = moduleTags;
|
||||
}
|
||||
|
||||
public String getModuleTags() {
|
||||
return moduleTags;
|
||||
}
|
||||
public void setStartTime(Date startTime)
|
||||
{
|
||||
this.startTime = startTime;
|
||||
@@ -102,6 +115,7 @@ public class SrsStuYear extends BaseEntity
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("stuYearName", getStuYearName())
|
||||
.append("moduleTags", getModuleTags())
|
||||
.append("startTime", getStartTime())
|
||||
.append("endTime", getEndTime())
|
||||
.append("delFlag", getDelFlag())
|
||||
|
||||
@@ -74,5 +74,24 @@ public interface SrsStuYearMapper extends BaseMapper<SrsStuYear>
|
||||
*/
|
||||
public int deleteSrsStuYearByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 根据标签查询学年
|
||||
* @param tag
|
||||
* @return
|
||||
*/
|
||||
public List<SrsStuYear> selectYearsByTag(String tag);
|
||||
|
||||
// 直接移除指定标签(不考虑其他标签)
|
||||
public int removeTagDirectly(String tag);
|
||||
|
||||
// 获取包含特定标签的学年列表
|
||||
public List<SrsStuYear> getYearsContainingTag(String tag);
|
||||
|
||||
// 获取所有包含特定标签的学年
|
||||
public List<SrsStuYear> getYearsWithTags();
|
||||
|
||||
// 获取包含指定标签的所有学年(用于标签移除)
|
||||
//public List<SrsStuYear> getYearsContainingTag(String tag);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -75,4 +75,26 @@ public interface ISrsStuYearService
|
||||
//中间表数据导入
|
||||
List<String> addStuYear();
|
||||
|
||||
/**
|
||||
* 为学年分配标签
|
||||
* @param tag
|
||||
* @param yearId
|
||||
* @return
|
||||
*/
|
||||
AjaxResult assignTagToYear(String tag, Long yearId);
|
||||
|
||||
/**
|
||||
* 根据标签查询学年
|
||||
* @param tag
|
||||
* @return
|
||||
*/
|
||||
List<SrsStuYear> getYearsByTag(String tag);
|
||||
|
||||
/**
|
||||
* 删除标签
|
||||
* @param tags
|
||||
* @param yearId
|
||||
* @return
|
||||
*/
|
||||
/*AjaxResult removeTagFromYear(List<String> tags, Long yearId);*/
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.srs.comprehensive.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.srs.common.core.domain.AjaxResult;
|
||||
@@ -14,6 +13,7 @@ import com.srs.comprehensive.service.ISrsStuYearService;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 【学年表】Service业务层处理
|
||||
@@ -170,5 +170,141 @@ public class SrsStuYearServiceImpl implements ISrsStuYearService
|
||||
return strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给指定标签的学年分配标签
|
||||
* @param tag
|
||||
* @param yearId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public AjaxResult assignTagToYear(String tag, Long yearId) {
|
||||
try {
|
||||
// 参数校验
|
||||
if (tag == null || tag.trim().isEmpty() || yearId == null) {
|
||||
return AjaxResult.error("参数无效");
|
||||
}
|
||||
|
||||
// 支持批量标签处理,按逗号分割
|
||||
String[] tags = tag.split(",");
|
||||
List<String> tagList = new ArrayList<>();
|
||||
for (String t : tags) {
|
||||
if (t != null && !t.trim().isEmpty()) {
|
||||
tagList.add(t.trim());
|
||||
}
|
||||
}
|
||||
|
||||
if (tagList.isEmpty()) {
|
||||
return AjaxResult.error("未提供有效标签");
|
||||
}
|
||||
|
||||
// 对每个标签执行分配操作
|
||||
for (String singleTag : tagList) {
|
||||
// 从所有包含该标签的学年中移除该标签
|
||||
srsStuYearMapper.removeTagDirectly(singleTag);
|
||||
}
|
||||
|
||||
// 将所有标签添加到目标学年
|
||||
SrsStuYear targetYear = srsStuYearMapper.selectSrsStuYearById(yearId);
|
||||
if (targetYear != null) {
|
||||
String currentTags = targetYear.getModuleTags();
|
||||
Set<String> tagSet = new LinkedHashSet<>();
|
||||
|
||||
// 保留现有标签
|
||||
if (currentTags != null && !currentTags.isEmpty()) {
|
||||
String[] existingTags = currentTags.split(",");
|
||||
for (String existingTag : existingTags) {
|
||||
String cleanTag = existingTag.trim();
|
||||
if (!cleanTag.isEmpty()) {
|
||||
tagSet.add(cleanTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加所有新标签
|
||||
tagSet.addAll(tagList);
|
||||
|
||||
// 更新标签
|
||||
String newTags = String.join(",", tagSet);
|
||||
targetYear.setModuleTags(newTags);
|
||||
srsStuYearMapper.updateSrsStuYear(targetYear);
|
||||
|
||||
return AjaxResult.success("标签分配成功");
|
||||
} else {
|
||||
return AjaxResult.error("指定的学年不存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return AjaxResult.error("标签分配失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定标签的学年列表
|
||||
* @param tag
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SrsStuYear> getYearsByTag(String tag) {
|
||||
return srsStuYearMapper.selectYearsByTag(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定标签的指定学年
|
||||
* @param tags
|
||||
* @param yearId
|
||||
* @return
|
||||
*/
|
||||
/* @Override
|
||||
public AjaxResult removeTagFromYear(List<String> tags, Long yearId) {
|
||||
try {
|
||||
// 参数校验
|
||||
if (tags == null || tags.isEmpty() || yearId == null) {
|
||||
return AjaxResult.error("参数无效");
|
||||
}
|
||||
// 获取指定学年
|
||||
SrsStuYear targetYear = srsStuYearMapper.selectSrsStuYearById(yearId);
|
||||
if (targetYear == null) {
|
||||
return AjaxResult.error("指定的学年不存在");
|
||||
}
|
||||
System.out.println("找到学年: " + targetYear.getStuYearName() + ", 当前标签: " + targetYear.getModuleTags());
|
||||
String currentTags = targetYear.getModuleTags();
|
||||
if (currentTags == null || currentTags.isEmpty()) {
|
||||
return AjaxResult.success("该学年没有标签");
|
||||
}
|
||||
// 分割标签并移除指定标签
|
||||
String[] tagsArray = currentTags.split(",");
|
||||
List<String> remainingTags = new ArrayList<>();
|
||||
Set<String> tagsToRemove = new HashSet<>();
|
||||
// 清理标签列表,去除空格
|
||||
for (String tag : tags) {
|
||||
if (tag != null && !tag.trim().isEmpty()) {
|
||||
tagsToRemove.add(tag.trim());
|
||||
}
|
||||
}
|
||||
int removedCount = 0;
|
||||
for (String existingTag : tagsArray) {
|
||||
String trimmedTag = existingTag.trim();
|
||||
if (tagsToRemove.contains(trimmedTag)) {
|
||||
removedCount++; // 找到要移除的标签
|
||||
} else {
|
||||
remainingTags.add(trimmedTag); // 保留其他标签
|
||||
}
|
||||
}
|
||||
if (removedCount == 0) {
|
||||
return AjaxResult.success("该学年未包含指定标签");
|
||||
}
|
||||
// 更新标签
|
||||
String newTags = remainingTags.isEmpty() ? null : String.join(",", remainingTags);
|
||||
targetYear.setModuleTags(newTags);
|
||||
int result = srsStuYearMapper.updateSrsStuYear(targetYear);
|
||||
if (result > 0) {
|
||||
return AjaxResult.success("成功移除" + removedCount + "个标签");
|
||||
} else {
|
||||
return AjaxResult.error("标签移除失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("标签移除失败:" + e.getMessage());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user