学年管理-新增模块标签
This commit is contained in:
@@ -35,6 +35,9 @@ public class SrsStuYearController extends BaseController
|
|||||||
public AjaxResult listAllYear(){
|
public AjaxResult listAllYear(){
|
||||||
return srsStuYearService.listAllYear();
|
return srsStuYearService.listAllYear();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 所有启用的学年
|
||||||
|
*/
|
||||||
@GetMapping("/listQiyongYear")
|
@GetMapping("/listQiyongYear")
|
||||||
public AjaxResult listQiyongYear(){
|
public AjaxResult listQiyongYear(){
|
||||||
return srsStuYearService.listQiyongYear();
|
return srsStuYearService.listQiyongYear();
|
||||||
@@ -148,4 +151,29 @@ public class SrsStuYearController extends BaseController
|
|||||||
return success("解析成功").put("导入失败的数据",srsStuYearService.addStuYear());
|
return success("解析成功").put("导入失败的数据",srsStuYearService.addStuYear());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为学年分配标签
|
||||||
|
*/
|
||||||
|
@PostMapping("/{yearId}/assign-tag")
|
||||||
|
public AjaxResult assignTag(@PathVariable Long yearId, @RequestParam String tag) {
|
||||||
|
return srsStuYearService.assignTagToYear(tag, yearId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据标签查询学年
|
||||||
|
*/
|
||||||
|
@GetMapping("/by-tag")
|
||||||
|
public AjaxResult getByTag(@RequestParam String tag) {
|
||||||
|
List<SrsStuYear> years = srsStuYearService.getYearsByTag(tag);
|
||||||
|
return AjaxResult.success(years);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除年份中的标签
|
||||||
|
*/
|
||||||
|
/*@PostMapping("/{yearId}/removeTag")
|
||||||
|
public AjaxResult removeTag(@PathVariable Long yearId, @RequestParam List<String> tags) {
|
||||||
|
return srsStuYearService.removeTagFromYear(tags, yearId);
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,15 +81,15 @@ spring:
|
|||||||
# redis 配置
|
# redis 配置
|
||||||
redis:
|
redis:
|
||||||
# 地址
|
# 地址
|
||||||
host: localhost #正式环境redis
|
# host: localhost #正式环境redis
|
||||||
# host: 47.112.118.149 #测试开发地址
|
host: 47.112.118.149 #测试开发地址
|
||||||
# 端口,默认为6379
|
# 端口,默认为6379
|
||||||
port: 6379
|
port: 6379
|
||||||
# 数据库索引
|
# 数据库索引
|
||||||
database: 0
|
database: 0
|
||||||
# 密码SSSS
|
# 密码SSSS
|
||||||
# password: Houpuyfb #测试开发密码
|
password: Houpuyfb #测试开发密码
|
||||||
password: #正式环境密码
|
# password: #正式环境密码
|
||||||
# 连接超时时间
|
# 连接超时时间
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
lettuce:
|
lettuce:
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ public class SrsStuYear extends BaseEntity
|
|||||||
@Excel(name = "学年名称")
|
@Excel(name = "学年名称")
|
||||||
private String stuYearName;
|
private String stuYearName;
|
||||||
|
|
||||||
|
/** 模块标签 */
|
||||||
|
@Excel(name = "模块标签")
|
||||||
|
private String moduleTags;
|
||||||
|
|
||||||
/** 开始时间 */
|
/** 开始时间 */
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
@Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
|
@Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||||
@@ -69,6 +73,15 @@ public class SrsStuYear extends BaseEntity
|
|||||||
{
|
{
|
||||||
return stuYearName;
|
return stuYearName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setModuleTags(String moduleTags) {
|
||||||
|
this.moduleTags = moduleTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModuleTags() {
|
||||||
|
return moduleTags;
|
||||||
|
}
|
||||||
public void setStartTime(Date startTime)
|
public void setStartTime(Date startTime)
|
||||||
{
|
{
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
@@ -102,6 +115,7 @@ public class SrsStuYear extends BaseEntity
|
|||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
.append("id", getId())
|
.append("id", getId())
|
||||||
.append("stuYearName", getStuYearName())
|
.append("stuYearName", getStuYearName())
|
||||||
|
.append("moduleTags", getModuleTags())
|
||||||
.append("startTime", getStartTime())
|
.append("startTime", getStartTime())
|
||||||
.append("endTime", getEndTime())
|
.append("endTime", getEndTime())
|
||||||
.append("delFlag", getDelFlag())
|
.append("delFlag", getDelFlag())
|
||||||
|
|||||||
@@ -74,5 +74,24 @@ public interface SrsStuYearMapper extends BaseMapper<SrsStuYear>
|
|||||||
*/
|
*/
|
||||||
public int deleteSrsStuYearByIds(Long[] ids);
|
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();
|
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;
|
package com.srs.comprehensive.service.impl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.srs.common.core.domain.AjaxResult;
|
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.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 【学年表】Service业务层处理
|
* 【学年表】Service业务层处理
|
||||||
@@ -170,5 +170,141 @@ public class SrsStuYearServiceImpl implements ISrsStuYearService
|
|||||||
return strings;
|
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());
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="id" column="id" />
|
<result property="id" column="id" />
|
||||||
<result property="stuYearName" column="stu_year_name" />
|
<result property="stuYearName" column="stu_year_name" />
|
||||||
<result property="xndm" column="xndm" />
|
<result property="xndm" column="xndm" />
|
||||||
|
<result property="moduleTags" column="module_tags"/>
|
||||||
<result property="startTime" column="start_time" />
|
<result property="startTime" column="start_time" />
|
||||||
<result property="endTime" column="end_time" />
|
<result property="endTime" column="end_time" />
|
||||||
<result property="delFlag" column="del_flag" />
|
<result property="delFlag" column="del_flag" />
|
||||||
@@ -18,7 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="updateTime" column="update_time" />
|
<result property="updateTime" column="update_time" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<sql id="selectSrsStuYearVo">
|
<sql id="selectSrsStuYearVo">
|
||||||
select id,xndm, stu_year_name, start_time, end_time, del_flag,status, create_by, create_time, update_by, update_time from srs_stu_year
|
select id,xndm, stu_year_name,module_tags, start_time, end_time, del_flag,status, create_by, create_time, update_by, update_time from srs_stu_year
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectSrsStuYearList" parameterType="SrsStuYear" resultMap="SrsStuYearResult">
|
<select id="selectSrsStuYearList" parameterType="SrsStuYear" resultMap="SrsStuYearResult">
|
||||||
@@ -50,6 +51,46 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<select id="selectQiYongList" resultType="com.srs.comprehensive.domain.SrsStuYear">
|
<select id="selectQiYongList" resultType="com.srs.comprehensive.domain.SrsStuYear">
|
||||||
select id,stu_year_name from srs_stu_year where status in (1,3) order by stu_year_name desc
|
select id,stu_year_name from srs_stu_year where status in (1,3) order by stu_year_name desc
|
||||||
</select>
|
</select>
|
||||||
|
<!-- 根据标签查询学年 -->
|
||||||
|
<!-- 根据标签查询学年(精确匹配) -->
|
||||||
|
<select id="selectYearsByTag" parameterType="string" resultMap="SrsStuYearResult">
|
||||||
|
<include refid="selectSrsStuYearVo"/>
|
||||||
|
where module_tags = #{tag}
|
||||||
|
or module_tags like concat(#{tag}, ',%')
|
||||||
|
or module_tags like concat('%,', #{tag}, ',%')
|
||||||
|
or module_tags like concat('%,', #{tag})
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 获取包含指定标签的所有学年(用于标签移除) -->
|
||||||
|
<select id="getYearsContainingTag" parameterType="string" resultMap="SrsStuYearResult">
|
||||||
|
<include refid="selectSrsStuYearVo"/>
|
||||||
|
where module_tags = #{tag}
|
||||||
|
or module_tags like concat(#{tag}, ',%')
|
||||||
|
or module_tags like concat('%,', #{tag}, ',%')
|
||||||
|
or module_tags like concat('%,', #{tag})
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 直接移除指定标签 -->
|
||||||
|
<update id="removeTagDirectly" parameterType="string">
|
||||||
|
UPDATE srs_stu_year
|
||||||
|
SET module_tags = CASE
|
||||||
|
WHEN module_tags = #{tag} THEN NULL
|
||||||
|
WHEN module_tags LIKE concat(#{tag}, ',%') THEN REPLACE(module_tags, concat(#{tag}, ','), '')
|
||||||
|
WHEN module_tags LIKE concat('%,', #{tag}) THEN REPLACE(module_tags, concat(',', #{tag}), '')
|
||||||
|
WHEN module_tags LIKE concat('%,', #{tag}, ',%') THEN REPLACE(module_tags, concat(',', #{tag}, ','), ',')
|
||||||
|
ELSE module_tags
|
||||||
|
END
|
||||||
|
WHERE module_tags = #{tag}
|
||||||
|
OR module_tags LIKE concat(#{tag}, ',%')
|
||||||
|
OR module_tags LIKE concat('%,', #{tag})
|
||||||
|
OR module_tags LIKE concat('%,', #{tag}, ',%')
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!-- 获取所有包含标签的学年 -->
|
||||||
|
<select id="getYearsWithTags" resultMap="SrsStuYearResult">
|
||||||
|
<include refid="selectSrsStuYearVo"/>
|
||||||
|
where module_tags is not null and module_tags != ''
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertSrsStuYear" parameterType="SrsStuYear">
|
<insert id="insertSrsStuYear" parameterType="SrsStuYear">
|
||||||
insert into srs_stu_year
|
insert into srs_stu_year
|
||||||
@@ -57,6 +98,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="id != null">id,</if>
|
<if test="id != null">id,</if>
|
||||||
<if test="xndm != null">xndm,</if>
|
<if test="xndm != null">xndm,</if>
|
||||||
<if test="stuYearName != null">stu_year_name,</if>
|
<if test="stuYearName != null">stu_year_name,</if>
|
||||||
|
<if test="moduleTags != null ">module_tags,</if>
|
||||||
<if test="startTime != null">start_time,</if>
|
<if test="startTime != null">start_time,</if>
|
||||||
<if test="endTime != null">end_time,</if>
|
<if test="endTime != null">end_time,</if>
|
||||||
<if test="status != null">`status`,</if>
|
<if test="status != null">`status`,</if>
|
||||||
@@ -70,6 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="id != null">#{id},</if>
|
<if test="id != null">#{id},</if>
|
||||||
<if test="xndm != null">#{xndm},</if>
|
<if test="xndm != null">#{xndm},</if>
|
||||||
<if test="stuYearName != null">#{stuYearName},</if>
|
<if test="stuYearName != null">#{stuYearName},</if>
|
||||||
|
<if test="moduleTags != null">#{moduleTags},</if>
|
||||||
<if test="startTime != null">#{startTime},</if>
|
<if test="startTime != null">#{startTime},</if>
|
||||||
<if test="endTime != null">#{endTime},</if>
|
<if test="endTime != null">#{endTime},</if>
|
||||||
<if test="status != null">#{status},</if>
|
<if test="status != null">#{status},</if>
|
||||||
@@ -86,6 +129,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<trim prefix="SET" suffixOverrides=",">
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
<if test="xndm != null">xndm = #{xndm},</if>
|
<if test="xndm != null">xndm = #{xndm},</if>
|
||||||
<if test="stuYearName != null">stu_year_name = #{stuYearName},</if>
|
<if test="stuYearName != null">stu_year_name = #{stuYearName},</if>
|
||||||
|
module_tags = #{moduleTags},
|
||||||
<if test="startTime != null">start_time = #{startTime},</if>
|
<if test="startTime != null">start_time = #{startTime},</if>
|
||||||
<if test="endTime != null">end_time = #{endTime},</if>
|
<if test="endTime != null">end_time = #{endTime},</if>
|
||||||
<if test="delFlag != null">del_flag = #{delFlag},</if>
|
<if test="delFlag != null">del_flag = #{delFlag},</if>
|
||||||
|
|||||||
Reference in New Issue
Block a user