|
|
|
@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
@ -38,6 +39,8 @@ public class UmsStudentManageServiceImpl extends ServiceImpl<UmsStudentManageMap |
|
|
|
|
private UmsUserMapper umsUserMapper; |
|
|
|
|
@Autowired |
|
|
|
|
private CoursesServiceImpl coursesService; |
|
|
|
|
@Autowired |
|
|
|
|
private PasswordEncoder passwordEncoder; |
|
|
|
|
|
|
|
|
|
@Value("${spring.datasource.url}") |
|
|
|
|
private String myUrl; |
|
|
|
@ -178,4 +181,46 @@ public class UmsStudentManageServiceImpl extends ServiceImpl<UmsStudentManageMap |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public CommonResult<String> initialPassword(List<Long> ids) { |
|
|
|
|
String encodePassword = passwordEncoder.encode("123456"); |
|
|
|
|
|
|
|
|
|
String url = myUrl; // 数据库URL
|
|
|
|
|
String user = myUsername; // 数据库用户名
|
|
|
|
|
String password = myPassword; // 数据库密码
|
|
|
|
|
|
|
|
|
|
Connection conn = null; |
|
|
|
|
|
|
|
|
|
String sql = "UPDATE ums_user SET password = ? WHERE id = ?"; |
|
|
|
|
try{ |
|
|
|
|
conn = DriverManager.getConnection(url, user, password); |
|
|
|
|
|
|
|
|
|
PreparedStatement pstmt = conn.prepareStatement(sql); |
|
|
|
|
|
|
|
|
|
conn.setAutoCommit(false); // 关闭自动提交,以便进行批处理
|
|
|
|
|
|
|
|
|
|
for (Long userId : ids) { |
|
|
|
|
pstmt.setString(1, encodePassword); |
|
|
|
|
pstmt.setLong(2, userId); |
|
|
|
|
pstmt.addBatch(); // 将SQL语句添加到批处理中
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pstmt.executeBatch(); // 执行批处理中的所有更新
|
|
|
|
|
conn.commit(); // 提交事务
|
|
|
|
|
|
|
|
|
|
return CommonResult.success("修改成功!"); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
try { |
|
|
|
|
if (conn != null) { |
|
|
|
|
conn.rollback(); // 发生异常时回滚事务
|
|
|
|
|
} |
|
|
|
|
} catch (SQLException ex) { |
|
|
|
|
ex.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
return CommonResult.failed("修改失败!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|