征询本人意见后删除了meetingController中的无效方法
This commit is contained in:
parent
8b12bb4201
commit
554a0893c3
@ -12,15 +12,6 @@ import java.time.OffsetDateTime;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import java.io.IOException;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -30,7 +21,7 @@ public class MeetingController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MeetingService meetingService;
|
private MeetingService meetingService;
|
||||||
|
|
||||||
private DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
private final DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||||
|
|
||||||
@GetMapping("/listAll")
|
@GetMapping("/listAll")
|
||||||
public ResponseEntity<List<Meeting>> listAll() {
|
public ResponseEntity<List<Meeting>> listAll() {
|
||||||
@ -133,7 +124,6 @@ public class MeetingController {
|
|||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(); // 打印异常信息
|
|
||||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,44 +150,4 @@ public class MeetingController {
|
|||||||
return new ResponseEntity<>(meetings, HttpStatus.OK);
|
return new ResponseEntity<>(meetings, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/export")
|
|
||||||
public void exportMeetings(@RequestBody Map<String, String> params, HttpServletResponse response) {
|
|
||||||
String name = params.get("name");
|
|
||||||
String organizer = params.get("organizer");
|
|
||||||
String startTimeStr = params.get("startTime");
|
|
||||||
LocalDateTime startTime = startTimeStr != null ? LocalDateTime.parse(startTimeStr) : null;
|
|
||||||
|
|
||||||
List<Meeting> meetings = meetingService.searchMeetings(name, organizer, startTime);
|
|
||||||
|
|
||||||
// 生成Excel文件
|
|
||||||
try (XSSFWorkbook workbook = new XSSFWorkbook()) {
|
|
||||||
XSSFSheet sheet = workbook.createSheet("Meetings");
|
|
||||||
XSSFRow header = sheet.createRow(0);
|
|
||||||
header.createCell(0).setCellValue("会议ID");
|
|
||||||
header.createCell(1).setCellValue("会议名称");
|
|
||||||
header.createCell(2).setCellValue("组织者");
|
|
||||||
header.createCell(3).setCellValue("开始时间");
|
|
||||||
header.createCell(4).setCellValue("结束时间");
|
|
||||||
header.createCell(5).setCellValue("状态");
|
|
||||||
|
|
||||||
int rowIdx = 1;
|
|
||||||
for (Meeting meeting : meetings) {
|
|
||||||
XSSFRow row = sheet.createRow(rowIdx++);
|
|
||||||
row.createCell(0).setCellValue(meeting.getId());
|
|
||||||
row.createCell(1).setCellValue(meeting.getName());
|
|
||||||
row.createCell(2).setCellValue(meeting.getOrganizer());
|
|
||||||
row.createCell(3).setCellValue(meeting.getStartTime().toString());
|
|
||||||
row.createCell(4).setCellValue(meeting.getEndTime().toString());
|
|
||||||
row.createCell(5).setCellValue(meeting.getStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=meetings.xlsx");
|
|
||||||
workbook.write(response.getOutputStream());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user