肖海南登录修复

master
总裁 5 months ago
parent 30a1d1f557
commit 52398db536
  1. 16
      src/main/java/com/teaching/backend/controller/umsAdmin/UmsStudentManageController.java
  2. 89
      src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java
  3. 2
      src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsUserServiceImpl.java
  4. 5
      src/main/java/com/teaching/backend/service/umsAdmin/UmsStudentManageService.java

@ -1,5 +1,6 @@
package com.teaching.backend.controller.umsAdmin; package com.teaching.backend.controller.umsAdmin;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.CommonResult; import com.teaching.backend.common.CommonResult;
import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO;
import com.teaching.backend.model.entity.umsAdmin.UmsStudentManage; import com.teaching.backend.model.entity.umsAdmin.UmsStudentManage;
@ -9,6 +10,9 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@ -65,8 +69,18 @@ public class UmsStudentManageController {
@PutMapping @PutMapping
@ApiOperation("编辑学生信息") @ApiOperation("编辑学生信息")
public CommonResult update(@RequestBody UmsStudentManage umsStudentManage){ public CommonResult update(@RequestBody UmsStudentManage umsStudentManage){
log.info("编辑学生信息: {}",umsStudentManage);
umsStudentManageService.updateStudentAndUser(umsStudentManage); umsStudentManageService.updateStudentAndUser(umsStudentManage);
return CommonResult.success("修改成功"); return CommonResult.success("修改成功");
} }
/**
* 根据ids批量删除
* @param ids
* @return
*/
@ApiOperation("学生信息批量删除")
@DeleteMapping("/batchDelete")
public CommonResult<String> batchDelete(@RequestParam List<Long> ids){
return umsStudentManageService.batchRemove(ids);
}
} }

@ -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();
}
}
}
} }

@ -105,7 +105,7 @@ public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsUser> impl
if(!passwordEncoder.matches(password,userDetails.getPassword())){ if(!passwordEncoder.matches(password,userDetails.getPassword())){
throw new BusinessException(400,"密码错误"); throw new BusinessException(400,"密码错误");
} }
if(!userDetails.isEnabled()){ if(userDetails.isEnabled()){
throw new BusinessException(400,"帐号已被禁用"); throw new BusinessException(400,"帐号已被禁用");
} }
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());

@ -3,9 +3,12 @@ package com.teaching.backend.service.umsAdmin;
import cn.hutool.db.PageResult; import cn.hutool.db.PageResult;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.CommonResult;
import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO;
import com.teaching.backend.model.entity.umsAdmin.UmsStudentManage; import com.teaching.backend.model.entity.umsAdmin.UmsStudentManage;
import java.util.List;
import java.util.Map; import java.util.Map;
public interface UmsStudentManageService extends IService<UmsStudentManage> { public interface UmsStudentManageService extends IService<UmsStudentManage> {
@ -18,4 +21,6 @@ public interface UmsStudentManageService extends IService<UmsStudentManage> {
void updateStudentAndUser(UmsStudentManage umsStudentManage); void updateStudentAndUser(UmsStudentManage umsStudentManage);
void startOrStop(String status, Long id); void startOrStop(String status, Long id);
CommonResult<String> batchRemove(List<Long> ids);
} }

Loading…
Cancel
Save