Compare commits
No commits in common. "554a0893c3c5155685dc6b8276c24d33260345be" and "50bfce4b230d9e8d396ed7891a8eaee9772cd2df" have entirely different histories.
554a0893c3
...
50bfce4b23
11
pom.xml
11
pom.xml
@ -165,17 +165,6 @@
|
|||||||
<artifactId>mysql</artifactId>
|
<artifactId>mysql</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.poi</groupId>
|
|
||||||
<artifactId>poi-ooxml</artifactId>
|
|
||||||
<version>5.2.3</version> <!-- 请使用最新版本 -->
|
|
||||||
</dependency><!-- BY JERRY -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
|
||||||
<version>4.0.1</version> <!-- 请使用最新版本 -->
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -4,8 +4,6 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ -13,22 +11,13 @@ public class SecurityConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
// Disable CSRF
|
// Use the new API to disable CSRF
|
||||||
http.csrf(AbstractHttpConfigurer::disable)
|
http.csrf(AbstractHttpConfigurer::disable)
|
||||||
// Permit all requests to all endpoints
|
// Permit all requests
|
||||||
.authorizeHttpRequests(authorize -> authorize
|
.authorizeHttpRequests(authorize -> authorize
|
||||||
.anyRequest().permitAll() // Allow all requests without authentication
|
.anyRequest().permitAll()
|
||||||
)
|
);
|
||||||
// Disable form login
|
|
||||||
.formLogin(AbstractHttpConfigurer::disable)
|
|
||||||
// Disable logout
|
|
||||||
.logout(AbstractHttpConfigurer::disable);
|
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public PasswordEncoder passwordEncoder() {
|
|
||||||
return new BCryptPasswordEncoder();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,153 +0,0 @@
|
|||||||
package org.cmh.backend.MeetingManagement.controller;
|
|
||||||
|
|
||||||
import org.cmh.backend.MeetingManagement.model.Meeting;
|
|
||||||
import org.cmh.backend.MeetingManagement.service.MeetingService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/meetings")
|
|
||||||
public class MeetingController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MeetingService meetingService;
|
|
||||||
|
|
||||||
private final DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
||||||
|
|
||||||
@GetMapping("/listAll")
|
|
||||||
public ResponseEntity<List<Meeting>> listAll() {
|
|
||||||
List<Meeting> data = meetingService.getAllMeetings();
|
|
||||||
return ResponseEntity.ok(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/addMeeting")
|
|
||||||
public ResponseEntity<Meeting> add(@RequestBody Map<String, String> credentials) {
|
|
||||||
try {
|
|
||||||
Meeting meeting = new Meeting();
|
|
||||||
if (credentials.get("id") != null) {
|
|
||||||
meeting.setId(Long.parseLong(credentials.get("id")));
|
|
||||||
}
|
|
||||||
meeting.setName(credentials.get("name"));
|
|
||||||
meeting.setOrganizer(credentials.get("organizer"));
|
|
||||||
|
|
||||||
// Parse startTime and endTime to OffsetDateTime, then convert to LocalDateTime
|
|
||||||
OffsetDateTime startTime = OffsetDateTime.parse(credentials.get("startTime"), formatter);
|
|
||||||
OffsetDateTime endTime = OffsetDateTime.parse(credentials.get("endTime"), formatter);
|
|
||||||
meeting.setStartTime(startTime.toLocalDateTime());
|
|
||||||
meeting.setEndTime(endTime.toLocalDateTime());
|
|
||||||
|
|
||||||
meeting.setContent(credentials.get("content"));
|
|
||||||
meeting.setStatus(credentials.get("status"));
|
|
||||||
|
|
||||||
Meeting meetingAdd = meetingService.createMeeting(meeting);
|
|
||||||
return new ResponseEntity<>(meetingAdd, HttpStatus.CREATED);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/deleteMeeting")
|
|
||||||
public ResponseEntity<String> delete(@RequestBody Map<String, String> credentials) {
|
|
||||||
try {
|
|
||||||
meetingService.deleteMeeting(Long.valueOf(credentials.get("id")));
|
|
||||||
return new ResponseEntity<>("success", HttpStatus.OK);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return new ResponseEntity<>("failure", HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/updateMeeting")
|
|
||||||
public ResponseEntity<Meeting> update(@RequestBody Map<String, String> credentials) {
|
|
||||||
try {
|
|
||||||
// Validate and parse id
|
|
||||||
String idStr = credentials.get("id");
|
|
||||||
if (idStr == null || idStr.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("ID cannot be null or empty");
|
|
||||||
}
|
|
||||||
Long id = Long.parseLong(idStr);
|
|
||||||
|
|
||||||
// Validate and parse other fields
|
|
||||||
String name = credentials.get("name");
|
|
||||||
if (name == null || name.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Name cannot be null or empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
String organizer = credentials.get("organizer");
|
|
||||||
if (organizer == null || organizer.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Organizer cannot be null or empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
String startTimeStr = credentials.get("startTime");
|
|
||||||
if (startTimeStr == null || startTimeStr.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Start time cannot be null or empty");
|
|
||||||
}
|
|
||||||
LocalDateTime startTime = LocalDateTime.parse(startTimeStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
|
||||||
|
|
||||||
String endTimeStr = credentials.get("endTime");
|
|
||||||
if (endTimeStr == null || endTimeStr.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("End time cannot be null or empty");
|
|
||||||
}
|
|
||||||
LocalDateTime endTime = LocalDateTime.parse(endTimeStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
|
||||||
|
|
||||||
String content = credentials.get("content");
|
|
||||||
if (content == null || content.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Content cannot be null or empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
String status = credentials.get("status");
|
|
||||||
if (status == null || status.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Status cannot be null or empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and update meeting
|
|
||||||
Meeting meeting = new Meeting();
|
|
||||||
meeting.setId(id);
|
|
||||||
meeting.setName(name);
|
|
||||||
meeting.setOrganizer(organizer);
|
|
||||||
meeting.setStartTime(startTime);
|
|
||||||
meeting.setEndTime(endTime);
|
|
||||||
meeting.setContent(content);
|
|
||||||
meeting.setStatus(status);
|
|
||||||
|
|
||||||
Meeting updatedMeeting = meetingService.updateMeeting(meeting.getId(), meeting);
|
|
||||||
return new ResponseEntity<>(updatedMeeting, HttpStatus.OK);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/getMeetingById")
|
|
||||||
public ResponseEntity<Meeting> getById(@RequestBody Map<String, String> credentials) {
|
|
||||||
try {
|
|
||||||
Meeting meeting = meetingService.getMeetingById(Long.valueOf(credentials.get("id"))).orElse(null);
|
|
||||||
return new ResponseEntity<>(meeting, HttpStatus.OK);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/searchMeetings")
|
|
||||||
public ResponseEntity<List<Meeting>> searchMeetings(@RequestBody Map<String, String> params) {
|
|
||||||
String name = params.get("name");
|
|
||||||
String organizer = params.get("organizer");
|
|
||||||
OffsetDateTime startTimeStr = OffsetDateTime.parse(params.get("startTime"), formatter);
|
|
||||||
LocalDateTime startTime1 = (startTimeStr.toLocalDateTime());
|
|
||||||
//LocalDateTime startTime = startTimeStr != null ? LocalDateTime.parse(startTimeStr) : null;
|
|
||||||
|
|
||||||
List<Meeting> meetings = meetingService.searchMeetings(name, organizer, startTime1);
|
|
||||||
return new ResponseEntity<>(meetings, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,48 +0,0 @@
|
|||||||
package org.cmh.backend.MeetingManagement.model;
|
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.GenerationType;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
@Getter
|
|
||||||
@Entity
|
|
||||||
public class Meeting {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
private String name;
|
|
||||||
private String organizer;
|
|
||||||
private LocalDateTime startTime; // Changed to LocalDateTime
|
|
||||||
private LocalDateTime endTime; // Changed to LocalDateTime
|
|
||||||
private String content;
|
|
||||||
private String status;
|
|
||||||
|
|
||||||
public Meeting() {}
|
|
||||||
|
|
||||||
public Meeting(String name, String organizer, LocalDateTime startTime, LocalDateTime endTime, String content, String status) {
|
|
||||||
this.name = name;
|
|
||||||
this.organizer = organizer;
|
|
||||||
this.startTime = startTime;
|
|
||||||
this.endTime = endTime;
|
|
||||||
this.content = content;
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Meeting{" +
|
|
||||||
"id=" + id +
|
|
||||||
", name='" + name + '\'' +
|
|
||||||
", organizer='" + organizer + '\'' +
|
|
||||||
", startTime=" + startTime +
|
|
||||||
", endTime=" + endTime +
|
|
||||||
", content='" + content + '\'' +
|
|
||||||
", status='" + status + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
package org.cmh.backend.MeetingManagement.repository;
|
|
||||||
|
|
||||||
import org.cmh.backend.MeetingManagement.model.Meeting;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
|
|
||||||
public interface MeetingRepository extends JpaRepository<Meeting, Long> {
|
|
||||||
@Query("SELECT m FROM Meeting m WHERE " +
|
|
||||||
"(?1 IS NULL OR m.name LIKE %?1%) AND " +
|
|
||||||
"(?2 IS NULL OR m.organizer LIKE %?2%) AND " +
|
|
||||||
"(?3 IS NULL OR m.startTime >= ?3)")
|
|
||||||
List<Meeting> searchMeetings(String name, String organizer, LocalDateTime startTime);
|
|
||||||
}
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
package org.cmh.backend.MeetingManagement.service;
|
|
||||||
|
|
||||||
import org.cmh.backend.MeetingManagement.model.Meeting;
|
|
||||||
import org.cmh.backend.MeetingManagement.repository.MeetingRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class MeetingService {
|
|
||||||
@Autowired
|
|
||||||
private MeetingRepository meetingRepository;
|
|
||||||
|
|
||||||
public List<Meeting> getAllMeetings() {
|
|
||||||
return meetingRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Meeting> getMeetingById(Long id) {
|
|
||||||
return meetingRepository.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Meeting createMeeting(Meeting meeting) {
|
|
||||||
validateMeeting(meeting);
|
|
||||||
return meetingRepository.save(meeting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Meeting updateMeeting(Long id, Meeting meetingDetails) {
|
|
||||||
validateMeeting(meetingDetails);
|
|
||||||
Meeting meeting = meetingRepository.findById(id)
|
|
||||||
.orElseThrow(() -> new RuntimeException("Meeting not found with id " + id));
|
|
||||||
meeting.setName(meetingDetails.getName());
|
|
||||||
meeting.setOrganizer(meetingDetails.getOrganizer());
|
|
||||||
meeting.setStartTime(meetingDetails.getStartTime());
|
|
||||||
meeting.setEndTime(meetingDetails.getEndTime());
|
|
||||||
meeting.setContent(meetingDetails.getContent());
|
|
||||||
meeting.setStatus(meetingDetails.getStatus());
|
|
||||||
return meetingRepository.save(meeting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteMeeting(Long id) {
|
|
||||||
Meeting meeting = meetingRepository.findById(id)
|
|
||||||
.orElseThrow(() -> new RuntimeException("Meeting not found with id " + id));
|
|
||||||
meetingRepository.delete(meeting);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateMeeting(Meeting meeting) {
|
|
||||||
if (meeting.getName() == null || meeting.getName().isEmpty()) {
|
|
||||||
throw new RuntimeException("会议名称不能为空");
|
|
||||||
}
|
|
||||||
if (meeting.getOrganizer() == null || meeting.getOrganizer().isEmpty()) {
|
|
||||||
throw new RuntimeException("组织者不能为空");
|
|
||||||
}
|
|
||||||
if (meeting.getStartTime() == null) {
|
|
||||||
throw new RuntimeException("开始时间不能为空");
|
|
||||||
}
|
|
||||||
if (meeting.getEndTime() == null) {
|
|
||||||
throw new RuntimeException("结束时间不能为空");
|
|
||||||
}
|
|
||||||
if (meeting.getStatus() == null || meeting.getStatus().isEmpty()) {
|
|
||||||
throw new RuntimeException("状态不能为空");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<Meeting> searchMeetings(String name, String organizer, LocalDateTime startTime) {
|
|
||||||
// 根据条件搜索会议
|
|
||||||
return meetingRepository.searchMeetings(name, organizer, startTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user