|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.teaching.backend.service.impl.umsAdmin; |
|
|
|
package com.teaching.backend.service.impl.umsAdmin; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
|
|
|
import com.teaching.backend.common.CommonResult; |
|
|
|
import com.teaching.backend.exception.BusinessException; |
|
|
|
import com.teaching.backend.exception.BusinessException; |
|
|
|
import com.teaching.backend.mapper.umsAdmin.*; |
|
|
|
import com.teaching.backend.mapper.umsAdmin.*; |
|
|
|
import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; |
|
|
|
import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; |
|
|
@ -10,15 +11,21 @@ import com.teaching.backend.service.umsAdmin.UmsStudentManageService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection; |
|
|
|
|
|
|
|
import java.sql.DriverManager; |
|
|
|
|
|
|
|
import java.sql.PreparedStatement; |
|
|
|
|
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class UmsStudentManageServiceImpl extends ServiceImpl<UmsStudentManageMapper, UmsStudentManage> implements UmsStudentManageService { |
|
|
|
public class UmsStudentManageServiceImpl extends ServiceImpl<UmsStudentManageMapper, UmsStudentManage> implements UmsStudentManageService { |
|
|
@ -32,6 +39,13 @@ public class UmsStudentManageServiceImpl extends ServiceImpl<UmsStudentManageMap |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private CoursesServiceImpl coursesService; |
|
|
|
private CoursesServiceImpl coursesService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${spring.datasource.url}") |
|
|
|
|
|
|
|
private String myUrl; |
|
|
|
|
|
|
|
@Value("${spring.datasource.username}") |
|
|
|
|
|
|
|
private String myUsername; |
|
|
|
|
|
|
|
@Value("${spring.datasource.password}") |
|
|
|
|
|
|
|
private String myPassword; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Map<String, Object> pageQuery(UmsStudentPageQueryDTO umsStudentPageQueryDTO) { |
|
|
|
public Map<String, Object> pageQuery(UmsStudentPageQueryDTO umsStudentPageQueryDTO) { |
|
|
@ -91,4 +105,77 @@ public class UmsStudentManageServiceImpl extends ServiceImpl<UmsStudentManageMap |
|
|
|
throw new BusinessException(400,"账号状态修改失败"); |
|
|
|
throw new BusinessException(400,"账号状态修改失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public CommonResult<String> batchRemove(List<Long> ids) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String url = myUrl; // 数据库URL
|
|
|
|
|
|
|
|
String user = myUsername; // 数据库用户名
|
|
|
|
|
|
|
|
String password = myPassword; // 数据库密码
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn = null; |
|
|
|
|
|
|
|
PreparedStatement pstmt1 = null; |
|
|
|
|
|
|
|
PreparedStatement pstmt2 = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// 建立数据库连接
|
|
|
|
|
|
|
|
conn = DriverManager.getConnection(url, user, password); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 关闭自动提交
|
|
|
|
|
|
|
|
conn.setAutoCommit(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder inClause = new StringBuilder("("); |
|
|
|
|
|
|
|
for (int i = 0; i < ids.size(); i++) { |
|
|
|
|
|
|
|
inClause.append("?"); |
|
|
|
|
|
|
|
if (i < ids.size() - 1) { |
|
|
|
|
|
|
|
inClause.append(", "); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
inClause.append(")"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 准备SQL语句
|
|
|
|
|
|
|
|
String sql1 = "DELETE FROM ums_user WHERE id IN " + inClause.toString(); |
|
|
|
|
|
|
|
String sql2 = "DELETE FROM ums_student WHERE user_id IN " + inClause.toString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建PreparedStatement对象
|
|
|
|
|
|
|
|
pstmt1 = conn.prepareStatement(sql1); |
|
|
|
|
|
|
|
pstmt2 = conn.prepareStatement(sql2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 为IN子句中的每个ID设置参数
|
|
|
|
|
|
|
|
for (int i = 0; i < ids.size(); i++) { |
|
|
|
|
|
|
|
pstmt1.setInt(i + 1, Math.toIntExact(ids.get(i))); |
|
|
|
|
|
|
|
pstmt2.setInt(i + 1, Math.toIntExact(ids.get(i))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 执行DELETE语句
|
|
|
|
|
|
|
|
pstmt1.executeUpdate(); |
|
|
|
|
|
|
|
pstmt2.executeUpdate(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 提交事务
|
|
|
|
|
|
|
|
conn.commit(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return CommonResult.success("数据删除成功!"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
if (conn != null) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// 发生异常时回滚事务
|
|
|
|
|
|
|
|
conn.rollback(); |
|
|
|
|
|
|
|
} catch (SQLException ex) { |
|
|
|
|
|
|
|
ex.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
return CommonResult.failed("数据删除失败!"); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
// 关闭资源(在实际应用中,应该使用try-with-resources语句或确保在finally块中关闭所有资源)
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (pstmt1 != null) pstmt1.close(); |
|
|
|
|
|
|
|
if (pstmt2 != null) pstmt2.close(); |
|
|
|
|
|
|
|
if (conn != null) conn.close(); |
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|