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.
158 lines
5.7 KiB
158 lines
5.7 KiB
package com.volunteersregistration.service;
|
|
|
|
import com.volunteersregistration.entity.CorporateInformation;
|
|
import com.volunteersregistration.entity.NgoInformation;
|
|
import com.volunteersregistration.entity.VolunteerInformation;
|
|
import com.volunteersregistration.repository.CompanyInfoRepo;
|
|
import com.volunteersregistration.repository.NgoInfoRepo;
|
|
import com.volunteersregistration.repository.VolunteerRegistrationRepo;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.StringJoiner;
|
|
|
|
@Service
|
|
public class VolunteerRegistrationService {
|
|
@Autowired
|
|
private VolunteerRegistrationRepo volunteerRegistrationRepo;
|
|
|
|
@Autowired
|
|
private CompanyInfoRepo companyInfoRepo;
|
|
|
|
@Autowired
|
|
private NgoInfoRepo ngoInfoRepo;
|
|
|
|
|
|
|
|
public String register(VolunteerInformation volun) {
|
|
|
|
volun.setCdate(LocalDateTime.now());
|
|
volun.setIsactive(true);
|
|
try{
|
|
if(volun!=null){
|
|
String preferredAreas[] =volun.getPreferredAreas();
|
|
if (preferredAreas != null) {
|
|
StringJoiner zones = new StringJoiner(",");
|
|
StringJoiner joiner = new StringJoiner(",");
|
|
for (String area : preferredAreas) {
|
|
String areaWZone[] =area.split("-");
|
|
if(areaWZone != null && areaWZone.length==2) {
|
|
joiner.add(areaWZone[1]);
|
|
zones.add(areaWZone[0]);
|
|
}else{
|
|
joiner.add(area);
|
|
}
|
|
}
|
|
volun.setPreferred_area(joiner.toString());
|
|
volun.setPreferred_zones(zones.toString());
|
|
}
|
|
volun= volunteerRegistrationRepo.save(volun);
|
|
return "VOL-"+String.format("%05d",volun.getVolunteer_id());
|
|
} else {
|
|
return "Not Saved";
|
|
}
|
|
|
|
}catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return "error";
|
|
}
|
|
|
|
public String registerAsNgo(NgoInformation ngo) {
|
|
|
|
try {
|
|
if (ngo != null) {
|
|
ngo.setCdate(LocalDateTime.now());
|
|
ngo.setIsactive(true);
|
|
String preferredAreas[] = ngo.getPreferredAreas();
|
|
if (preferredAreas != null) {
|
|
StringJoiner zones = new StringJoiner(",");
|
|
StringJoiner joiner = new StringJoiner(",");
|
|
for (String area : preferredAreas) {
|
|
String areaWZone[] = area.split("-");
|
|
if (areaWZone != null && areaWZone.length == 2) {
|
|
joiner.add(areaWZone[1]);
|
|
zones.add(areaWZone[0]);
|
|
} else {
|
|
joiner.add(area);
|
|
}
|
|
}
|
|
ngo.setPreferred_area(joiner.toString());
|
|
ngo.setPreferred_zones(zones.toString());
|
|
}
|
|
ngo= ngoInfoRepo.save(ngo);
|
|
return "NGO_VOL-"+String.format("%05d",ngo.getNgo_id());
|
|
} else {
|
|
return "Not Saved";
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return "error";
|
|
}
|
|
|
|
public String registerAsCorporate(CorporateInformation cop){
|
|
try{
|
|
if(cop!=null){
|
|
cop.setCdate(LocalDateTime.now());
|
|
cop.setIsactive(true);
|
|
String preferredAreas[] =cop.getPreferredAreas();
|
|
if (preferredAreas != null) {
|
|
StringJoiner zones = new StringJoiner(",");
|
|
StringJoiner joiner = new StringJoiner(",");
|
|
for (String area : preferredAreas) {
|
|
String areaWZone[] =area.split("-");
|
|
if(areaWZone != null && areaWZone.length==2) {
|
|
joiner.add(areaWZone[1]);
|
|
zones.add(areaWZone[0]);
|
|
}else{
|
|
joiner.add(area);
|
|
}
|
|
}
|
|
cop.setPreferred_area(joiner.toString());
|
|
cop.setPreferred_zones(zones.toString());
|
|
}
|
|
cop= companyInfoRepo.save(cop);
|
|
return "COR_VOL-"+String.format("%05d",cop.getCop_id());
|
|
} else {
|
|
return "Not Saved";
|
|
}
|
|
|
|
}catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return "error";
|
|
}
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getKynReport(String fromDate, String toDate, int category) {
|
|
if (category == 0) {
|
|
return volunteerRegistrationRepo.findByReferByAndDateRange("kyn", fromDate, toDate);
|
|
} else if (category == 1) {
|
|
return companyInfoRepo.findByReferByAndDateRange("kyn", fromDate, toDate);
|
|
} else if (category == 2) {
|
|
return ngoInfoRepo.findByReferByAndDateRange("kyn", fromDate, toDate);
|
|
}
|
|
return new ArrayList<>();
|
|
}
|
|
|
|
public List<Map<String, Object>> getAllReport(String fromDate, String toDate, int category) {
|
|
if (category == 3) {
|
|
return volunteerRegistrationRepo.findByDateRange(fromDate, toDate);
|
|
|
|
} else if (category == 4) {
|
|
return companyInfoRepo.findByDateRange(fromDate, toDate);
|
|
} else if (category == 5) {
|
|
return ngoInfoRepo.findByDateRange(fromDate, toDate);
|
|
}
|
|
return new ArrayList<>();
|
|
}
|
|
|
|
}
|