You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
5.4 KiB
162 lines
5.4 KiB
package com.volunteersregistration.controller;
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import com.volunteersregistration.config.UserSession;
|
|
import com.volunteersregistration.repository.VolunteerRegistrationRepo;
|
|
import com.volunteersregistration.service.VolunteerRegistrationService;
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpSession;
|
|
|
|
|
|
|
|
@Controller
|
|
@RequestMapping("/volunteer")
|
|
public class VolunteerController {
|
|
|
|
@Autowired
|
|
private HttpSession session;
|
|
|
|
@Autowired
|
|
private UserSession usersession;
|
|
|
|
|
|
@Autowired
|
|
public VolunteerRegistrationService volunteerRegistrationService;
|
|
|
|
@GetMapping("/web")
|
|
public String registerweb(@RequestParam(required = false) String ref, Model model) {
|
|
System.out.println("indesx page....." + ref);
|
|
model.addAttribute("ref", ref);
|
|
|
|
|
|
//return "webindex";
|
|
return "coming_soon";
|
|
}
|
|
|
|
@GetMapping("/webtamil")
|
|
public String registerwebtamil(@RequestParam(required = false) String ref, Model model) {
|
|
System.out.println("indesx page....." + ref);
|
|
model.addAttribute("ref", ref);
|
|
|
|
|
|
//return "webindex_tamil";
|
|
return "coming_soon";
|
|
}
|
|
|
|
@GetMapping(value = { "/", "", "/index" })
|
|
public String MobileViewregister(@RequestParam(required = false) String ref, Model model) {
|
|
System.out.println("indesx page....." + ref);
|
|
model.addAttribute("ref", ref);
|
|
|
|
|
|
//return "index";
|
|
return "coming_soon";
|
|
}
|
|
|
|
@GetMapping(value = {"/index_tamil" })
|
|
public String MobileViewtamilregister(@RequestParam(required = false) String ref, Model model) {
|
|
System.out.println("indesx page....." + ref);
|
|
model.addAttribute("ref", ref);
|
|
|
|
|
|
//return "index_tamil";
|
|
return "coming_soon";
|
|
}
|
|
|
|
|
|
|
|
// Check session and redirect to login if user is not logged in
|
|
private boolean isLoggedIn() {
|
|
return session.getAttribute("userId") != null; // Check if userId is in session store the user type if the user type not quals to kyn n s pls logout
|
|
}
|
|
|
|
@GetMapping(value = {"/kynreport"})
|
|
public String kynreport(Model model, HttpServletRequest request) {
|
|
if (!isLoggedIn()) {
|
|
return "redirect:/volunteer/kynreportlogin"; // Redirect to login if not logged in
|
|
}
|
|
return "kynreport"; // Render page if logged in
|
|
}
|
|
|
|
|
|
@GetMapping(value = {"/allreports"})
|
|
public String allreports(Model model, HttpServletRequest request) {
|
|
if (!isLoggedIn()) {
|
|
return "redirect:/volunteer/kynreportlogin"; // Redirect to login if not logged in
|
|
}
|
|
return "allreports"; // Render page if logged in
|
|
}
|
|
|
|
|
|
@PostMapping(value = {"/allreports"})
|
|
public String allreports(
|
|
@RequestParam("fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate fromDate,
|
|
@RequestParam("toDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate toDate,
|
|
@RequestParam("category") int category,
|
|
Model model) {
|
|
|
|
if (!isLoggedIn()) {
|
|
return "redirect:/volunteer/kynreportlogin";
|
|
}
|
|
|
|
LocalDateTime fromDateTime = fromDate.atStartOfDay();
|
|
LocalDateTime toDateTime = toDate.atTime(23, 59, 59);
|
|
String fromDateString = fromDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
String toDateString = toDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
List<Map<String, Object>> alldata = volunteerRegistrationService.getAllReport(fromDateString, toDateString, category);
|
|
|
|
model.addAttribute("alldata", alldata);
|
|
model.addAttribute("category", category);
|
|
model.addAttribute("fromdate", fromDate);
|
|
model.addAttribute("todate", toDate);
|
|
return "allreports";
|
|
}
|
|
|
|
@PostMapping(value = {"/kynreport"})
|
|
public String kynreport(
|
|
@RequestParam("fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate fromDate,
|
|
@RequestParam("toDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate toDate,
|
|
@RequestParam("category") int category,
|
|
Model model) {
|
|
|
|
if (!isLoggedIn()) {
|
|
return "redirect:/volunteer/kynreportlogin";
|
|
}
|
|
|
|
LocalDateTime fromDateTime = fromDate.atStartOfDay();
|
|
LocalDateTime toDateTime = toDate.atTime(23, 59, 59);
|
|
String fromDateString = fromDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
String toDateString = toDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
List<Map<String, Object>> reportData = volunteerRegistrationService.getKynReport(fromDateString, toDateString, category);
|
|
|
|
model.addAttribute("fromdate", fromDate);
|
|
model.addAttribute("todate", toDate);
|
|
model.addAttribute("reportData", reportData);
|
|
model.addAttribute("category", category);
|
|
return "kynreport";
|
|
}
|
|
|
|
@GetMapping(value = {"/kynreportlogin"})
|
|
public String kynreportlogin(Model model) {
|
|
return "kynreportlogin";
|
|
}
|
|
|
|
|
|
}
|