Both Volunteers and C and D Waste included in this project
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

2 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
  1. package com.volunteersregistration.service;
  2. import com.volunteersregistration.entity.CorporateInformation;
  3. import com.volunteersregistration.entity.NgoInformation;
  4. import com.volunteersregistration.entity.VolunteerInformation;
  5. import com.volunteersregistration.repository.CompanyInfoRepo;
  6. import com.volunteersregistration.repository.NgoInfoRepo;
  7. import com.volunteersregistration.repository.VolunteerRegistrationRepo;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import java.time.LocalDate;
  11. import java.time.LocalDateTime;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import java.util.Map;
  15. import java.util.StringJoiner;
  16. @Service
  17. public class VolunteerRegistrationService {
  18. @Autowired
  19. private VolunteerRegistrationRepo volunteerRegistrationRepo;
  20. @Autowired
  21. private CompanyInfoRepo companyInfoRepo;
  22. @Autowired
  23. private NgoInfoRepo ngoInfoRepo;
  24. public String register(VolunteerInformation volun) {
  25. volun.setCdate(LocalDateTime.now());
  26. volun.setIsactive(true);
  27. try{
  28. if(volun!=null){
  29. String preferredAreas[] =volun.getPreferredAreas();
  30. if (preferredAreas != null) {
  31. StringJoiner zones = new StringJoiner(",");
  32. StringJoiner joiner = new StringJoiner(",");
  33. for (String area : preferredAreas) {
  34. String areaWZone[] =area.split("-");
  35. if(areaWZone != null && areaWZone.length==2) {
  36. joiner.add(areaWZone[1]);
  37. zones.add(areaWZone[0]);
  38. }else{
  39. joiner.add(area);
  40. }
  41. }
  42. volun.setPreferred_area(joiner.toString());
  43. volun.setPreferred_zones(zones.toString());
  44. }
  45. volun= volunteerRegistrationRepo.save(volun);
  46. return "VOL-"+String.format("%05d",volun.getVolunteer_id());
  47. } else {
  48. return "Not Saved";
  49. }
  50. }catch(Exception e) {
  51. e.printStackTrace();
  52. }
  53. return "error";
  54. }
  55. public String registerAsNgo(NgoInformation ngo) {
  56. try {
  57. if (ngo != null) {
  58. ngo.setCdate(LocalDateTime.now());
  59. ngo.setIsactive(true);
  60. String preferredAreas[] = ngo.getPreferredAreas();
  61. if (preferredAreas != null) {
  62. StringJoiner zones = new StringJoiner(",");
  63. StringJoiner joiner = new StringJoiner(",");
  64. for (String area : preferredAreas) {
  65. String areaWZone[] = area.split("-");
  66. if (areaWZone != null && areaWZone.length == 2) {
  67. joiner.add(areaWZone[1]);
  68. zones.add(areaWZone[0]);
  69. } else {
  70. joiner.add(area);
  71. }
  72. }
  73. ngo.setPreferred_area(joiner.toString());
  74. ngo.setPreferred_zones(zones.toString());
  75. }
  76. ngo= ngoInfoRepo.save(ngo);
  77. return "NGO_VOL-"+String.format("%05d",ngo.getNgo_id());
  78. } else {
  79. return "Not Saved";
  80. }
  81. } catch (Exception e) {
  82. e.printStackTrace();
  83. }
  84. return "error";
  85. }
  86. public String registerAsCorporate(CorporateInformation cop){
  87. try{
  88. if(cop!=null){
  89. cop.setCdate(LocalDateTime.now());
  90. cop.setIsactive(true);
  91. String preferredAreas[] =cop.getPreferredAreas();
  92. if (preferredAreas != null) {
  93. StringJoiner zones = new StringJoiner(",");
  94. StringJoiner joiner = new StringJoiner(",");
  95. for (String area : preferredAreas) {
  96. String areaWZone[] =area.split("-");
  97. if(areaWZone != null && areaWZone.length==2) {
  98. joiner.add(areaWZone[1]);
  99. zones.add(areaWZone[0]);
  100. }else{
  101. joiner.add(area);
  102. }
  103. }
  104. cop.setPreferred_area(joiner.toString());
  105. cop.setPreferred_zones(zones.toString());
  106. }
  107. cop= companyInfoRepo.save(cop);
  108. return "COR_VOL-"+String.format("%05d",cop.getCop_id());
  109. } else {
  110. return "Not Saved";
  111. }
  112. }catch(Exception e) {
  113. e.printStackTrace();
  114. }
  115. return "error";
  116. }
  117. public List<Map<String, Object>> getKynReport(String fromDate, String toDate, int category) {
  118. if (category == 0) {
  119. return volunteerRegistrationRepo.findByReferByAndDateRange("kyn", fromDate, toDate);
  120. } else if (category == 1) {
  121. return companyInfoRepo.findByReferByAndDateRange("kyn", fromDate, toDate);
  122. } else if (category == 2) {
  123. return ngoInfoRepo.findByReferByAndDateRange("kyn", fromDate, toDate);
  124. }
  125. return new ArrayList<>();
  126. }
  127. public List<Map<String, Object>> getAllReport(String fromDate, String toDate, int category) {
  128. if (category == 3) {
  129. return volunteerRegistrationRepo.findByDateRange(fromDate, toDate);
  130. } else if (category == 4) {
  131. return companyInfoRepo.findByDateRange(fromDate, toDate);
  132. } else if (category == 5) {
  133. return ngoInfoRepo.findByDateRange(fromDate, toDate);
  134. }
  135. return new ArrayList<>();
  136. }
  137. }