This application is used for whatsapp governance, which contains the API for the several services provided by GCC.
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.

757 lines
32 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package com.gcc.restapiservices.petregistration.controller;
  2. import java.time.LocalDate;
  3. import java.time.LocalDateTime;
  4. import java.time.format.DateTimeFormatter;
  5. import java.time.format.DateTimeParseException;
  6. import java.util.ArrayList;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.Random;
  11. import org.json.JSONObject;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.dao.EmptyResultDataAccessException;
  14. import org.springframework.http.HttpStatus;
  15. import org.springframework.http.ResponseEntity;
  16. import org.springframework.web.bind.annotation.GetMapping;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.RequestBody;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RequestParam;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import org.springframework.web.client.RestTemplate;
  23. import org.springframework.web.multipart.MultipartFile;
  24. import com.fasterxml.jackson.databind.ObjectMapper;
  25. import com.fasterxml.jackson.databind.node.ObjectNode;
  26. import com.gcc.restapiservices.configuration.AppConfig;
  27. import com.gcc.restapiservices.petregistration.constants.AppConstants;
  28. import com.gcc.restapiservices.petregistration.service.PetRegistrationApiService;
  29. import com.gcc.restapiservices.petregistration.util.ApiResponseUtil;
  30. import com.gcc.restapiservices.swimmingpool.util.ApiResponse;
  31. import com.razorpay.Order;
  32. import com.razorpay.RazorpayClient;
  33. import com.razorpay.RazorpayException;
  34. import jakarta.servlet.http.HttpServletRequest;
  35. import jakarta.servlet.http.HttpSession;
  36. @RestController
  37. @RequestMapping("/gccrestservices/petregistration/api")
  38. public class PetRegistrationApiController {
  39. @Autowired
  40. private PetRegistrationApiService petRegistrationApiService;
  41. @Autowired
  42. private AppConfig appConfig;
  43. @GetMapping("/breed")
  44. public ResponseEntity<?> getBreedList(@RequestParam int type) {
  45. List<Map<String, Object>> result = petRegistrationApiService.getBreedList(type);
  46. try {
  47. if (result.isEmpty()) {
  48. return ApiResponseUtil.notFound("No data found");
  49. }
  50. return ApiResponseUtil.success(result, "Data found");
  51. } catch (Exception e) {
  52. return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  53. }
  54. }
  55. // get owner details
  56. @GetMapping("/ownerinfo")
  57. public ResponseEntity<?> getOwnerDetails(@RequestParam String mobile) {
  58. List<Map<String, Object>> result = petRegistrationApiService.getOwnerDetails(mobile);
  59. try {
  60. // Check if mobile is missing or blank
  61. if (mobile == null || mobile.trim().isEmpty()) {
  62. return ApiResponseUtil.error("Mobile number is required", HttpStatus.BAD_REQUEST);
  63. }
  64. // Check if mobile is not 10 digits
  65. if (!mobile.matches("\\d{10}")) {
  66. return ApiResponseUtil.error("Mobile number must be exactly 10 digits", HttpStatus.BAD_REQUEST);
  67. }
  68. if (result.isEmpty()) {
  69. return ApiResponseUtil.notFound("No data found");
  70. }
  71. return ApiResponseUtil.success(result, "Data found");
  72. } catch (Exception e) {
  73. return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  74. }
  75. }
  76. // get pet type
  77. @GetMapping("/pettypes")
  78. public ResponseEntity<?> getPetTypes() {
  79. List<Map<String, Object>> result = petRegistrationApiService.getTypeOfPets();
  80. try {
  81. if (result.isEmpty()) {
  82. return ApiResponseUtil.notFound("No data found");
  83. }
  84. return ApiResponseUtil.success(result, "Data found");
  85. } catch (Exception e) {
  86. return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  87. }
  88. }
  89. // get pet type
  90. @GetMapping("/allyears")
  91. public ResponseEntity<?> getAllYears() {
  92. List<Map<String, Object>> result = petRegistrationApiService.getAllYears();
  93. try {
  94. if (result.isEmpty()) {
  95. return ApiResponseUtil.notFound("No data found");
  96. }
  97. return ApiResponseUtil.success(result, "Data found");
  98. } catch (Exception e) {
  99. return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  100. }
  101. }
  102. // get pet type
  103. @GetMapping("/allmonths")
  104. public ResponseEntity<?> getAllMonths() {
  105. List<Map<String, Object>> result = petRegistrationApiService.getAllMonths();
  106. try {
  107. if (result.isEmpty()) {
  108. return ApiResponseUtil.notFound("No data found");
  109. }
  110. return ApiResponseUtil.success(result, "Data found");
  111. } catch (Exception e) {
  112. return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  113. }
  114. }
  115. @GetMapping("/userexistornot")
  116. public ResponseEntity<?> userExistOrNot(@RequestParam String mobilenum) {
  117. try {
  118. // Check if mobile is missing or blank
  119. if (mobilenum == null || mobilenum.trim().isEmpty()) {
  120. return ApiResponseUtil.error("Mobile number is required", HttpStatus.BAD_REQUEST);
  121. }
  122. // Check if mobile is not 10 digits
  123. if (!mobilenum.matches("\\d{10}")) {
  124. return ApiResponseUtil.error("Mobile number must be exactly 10 digits", HttpStatus.BAD_REQUEST);
  125. }
  126. boolean result = petRegistrationApiService.isPhoneRegistered(mobilenum);
  127. System.out.println("result: " + result);
  128. String message = result ? "Mobile number already registered" : "Mobile number not registered";
  129. return ApiResponseUtil.success(result, message);
  130. } catch (Exception e) {
  131. return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  132. }
  133. }
  134. // save new owner registration
  135. @PostMapping("/pet-owner/register")
  136. public ResponseEntity<?> savePinDetails(HttpServletRequest request,
  137. @RequestParam(required = false) String title,
  138. @RequestParam(required = false) String username,
  139. @RequestParam(required = false) String doornumber,
  140. @RequestParam(required = false) String street,
  141. @RequestParam(required = false) String area,
  142. @RequestParam(required = false) String city,
  143. @RequestParam(required = false) String pincode,
  144. @RequestParam(required = false) String zone,
  145. @RequestParam(required = false) String ward,
  146. @RequestParam(required = false) String phone,
  147. @RequestParam(required = false) String email,
  148. @RequestParam(required = false) String pin) {
  149. List<String> missingFields = new ArrayList<>();
  150. if (title == null || title.trim().isEmpty())
  151. missingFields.add("title");
  152. if (username == null || username.trim().isEmpty())
  153. missingFields.add("username");
  154. if (doornumber == null || doornumber.trim().isEmpty())
  155. missingFields.add("doornumber");
  156. if (street == null || street.trim().isEmpty())
  157. missingFields.add("street");
  158. if (area == null || area.trim().isEmpty())
  159. missingFields.add("area");
  160. if (city == null || city.trim().isEmpty())
  161. missingFields.add("city");
  162. if (pincode == null || pincode.trim().isEmpty())
  163. missingFields.add("pincode");
  164. if (zone == null || zone.trim().isEmpty())
  165. missingFields.add("zone");
  166. if (ward == null || ward.trim().isEmpty())
  167. missingFields.add("ward");
  168. if (phone == null || phone.trim().isEmpty())
  169. missingFields.add("phone");
  170. if (email == null || email.trim().isEmpty())
  171. missingFields.add("email");
  172. if (pin == null || pin.trim().isEmpty())
  173. missingFields.add("pin");
  174. if (!missingFields.isEmpty()) {
  175. return ApiResponseUtil.invalidRequest("Missing required fields: " + String.join(", ", missingFields));
  176. }
  177. try {
  178. // Check if mobile is missing or blank
  179. if (phone == null || phone.trim().isEmpty()) {
  180. return ApiResponseUtil.error("Mobile number is required", HttpStatus.BAD_REQUEST);
  181. }
  182. // Check if mobile is not 10 digits
  183. if (!phone.matches("\\d{10}")) {
  184. return ApiResponseUtil.error("Mobile number must be exactly 10 digits", HttpStatus.BAD_REQUEST);
  185. }
  186. // Check if mobile is not 10 digits
  187. if (!pincode.matches("\\d{6}")) {
  188. return ApiResponseUtil.error("Pincode must be exactly 6 digits", HttpStatus.BAD_REQUEST);
  189. }
  190. // Validate email if provided
  191. if (email != null && !email.isBlank()) {
  192. String emailRegex = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.com$";
  193. if (!email.matches(emailRegex)) {
  194. return ApiResponseUtil.error("Invalid email id", HttpStatus.BAD_REQUEST);
  195. }
  196. }
  197. // Check if mobile is not 10 digits
  198. if (!pincode.matches("\\d{6}")) {
  199. return ApiResponseUtil.error("Pincode must be exactly 6 digits", HttpStatus.BAD_REQUEST);
  200. }
  201. // pin validation
  202. if (!pin.matches("\\d{4}")) {
  203. return ApiResponseUtil.error("pin must be 4 digits only", HttpStatus.BAD_REQUEST);
  204. }
  205. return petRegistrationApiService.insertPetOwner(
  206. title, username, doornumber, street, area, city, pincode, zone, ward, phone, email, pin);
  207. } catch (Exception ex) {
  208. return ApiResponseUtil.error("Internal server error: " + ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  209. }
  210. }
  211. @PostMapping("/saveregistrationdetails")
  212. public ResponseEntity<?> saveRegistrationDetails(
  213. @RequestParam(required = false) String petname,
  214. @RequestParam(required = false) String species,
  215. @RequestParam(required = false) String breed,
  216. @RequestParam(required = false) String identification_mark,
  217. @RequestParam(required = false) String petcolor,
  218. @RequestParam(required = false) String gender,
  219. @RequestParam(required = false) String age_year,
  220. @RequestParam(required = false) String months,
  221. @RequestParam(required = false) String is_sterilized,
  222. @RequestParam(required = false) String is_adopted_street,
  223. @RequestParam(required = false) String is_rabies_vaccination,
  224. @RequestParam(required = false) String arv_date,
  225. @RequestParam(required = false) String lastdate_of_deworming,
  226. @RequestParam(required = false) String other_vaccination,
  227. @RequestParam(required = false) String previous_licenseNo,
  228. @RequestParam(required = false) String consultant_name,
  229. @RequestParam(required = false) String council_number,
  230. @RequestParam(required = false) String mobilenum,
  231. @RequestParam(required = false) MultipartFile applicantphoto,
  232. @RequestParam(required = false) MultipartFile addressproof,
  233. @RequestParam(required = false) MultipartFile petphoto,
  234. @RequestParam(required = false) MultipartFile rabiesvacCertificate) {
  235. LocalDate today = LocalDate.now();
  236. String registerdate = today.toString();
  237. List<String> missingFields = new ArrayList<>();
  238. if (petname == null || petname.trim().isEmpty())
  239. missingFields.add("petname");
  240. if (species == null || species.trim().isEmpty())
  241. missingFields.add("species");
  242. if (breed == null || breed.trim().isEmpty())
  243. missingFields.add("breed");
  244. // if (identification_mark == null || identification_mark.trim().isEmpty())
  245. // missingFields.add("identification_mark"); optional
  246. if (petcolor == null || petcolor.trim().isEmpty())
  247. missingFields.add("petcolor");
  248. if (gender == null || gender.trim().isEmpty())
  249. missingFields.add("gender");
  250. if (age_year == null || age_year.trim().isEmpty())
  251. missingFields.add("age_year");
  252. if (months == null || months.trim().isEmpty())
  253. missingFields.add("months");
  254. if (is_sterilized == null || is_sterilized.trim().isEmpty())
  255. missingFields.add("is_sterilized");
  256. if (is_adopted_street == null || is_adopted_street.trim().isEmpty())
  257. missingFields.add("is_adopted_street");
  258. if (is_rabies_vaccination == null || is_rabies_vaccination.trim().isEmpty())
  259. missingFields.add("is_rabies_vaccination");
  260. if (arv_date == null || arv_date.trim().isEmpty())
  261. missingFields.add("arv_date");
  262. // if (lastdate_of_deworming == null || lastdate_of_deworming.trim().isEmpty())
  263. // missingFields.add("lastdate_of_deworming"); optional
  264. // if (other_vaccination == null || other_vaccination.trim().isEmpty())
  265. // missingFields.add("other_vaccination"); optional
  266. // if (previous_licenseNo == null || previous_licenseNo.trim().isEmpty())
  267. // missingFields.add("previous_licenseNo"); optional
  268. // if (consultant_name == null || consultant_name.trim().isEmpty())
  269. // missingFields.add("consultant_name"); optional
  270. // if (council_number == null || council_number.trim().isEmpty())
  271. // missingFields.add("council_number"); optional
  272. if (mobilenum == null || mobilenum.trim().isEmpty())
  273. missingFields.add("mobilenum");
  274. if (applicantphoto == null || applicantphoto.isEmpty())
  275. missingFields.add("applicantphoto");
  276. if (addressproof == null || addressproof.isEmpty())
  277. missingFields.add("addressproof");
  278. if (petphoto == null || petphoto.isEmpty())
  279. missingFields.add("petphoto");
  280. if (rabiesvacCertificate == null || rabiesvacCertificate.isEmpty())
  281. missingFields.add("rabiesvacCertificate");
  282. if (!missingFields.isEmpty()) {
  283. return ApiResponseUtil.invalidRequest("Missing required fields: " + String.join(", ", missingFields));
  284. }
  285. try {
  286. // Save to DB
  287. String saveStatus = petRegistrationApiService.saveAllRegistrationDetails(petname, species, breed,
  288. identification_mark, petcolor, gender, age_year, months,
  289. is_sterilized, is_adopted_street, is_rabies_vaccination,
  290. arv_date, lastdate_of_deworming, other_vaccination, previous_licenseNo, consultant_name,
  291. council_number, mobilenum,
  292. applicantphoto, addressproof, petphoto, rabiesvacCertificate, registerdate);
  293. Map<String, Object> response = new HashMap<>();
  294. System.out.println("saveStatus " + saveStatus);
  295. // Check if mobile is missing or blank
  296. if (mobilenum == null || mobilenum.trim().isEmpty()) {
  297. return ApiResponseUtil.error("Mobile number is required", HttpStatus.BAD_REQUEST);
  298. }
  299. // Check if mobile is not 10 digits
  300. if (!mobilenum.matches("\\d{10}")) {
  301. return ApiResponseUtil.error("Mobile number must be exactly 10 digits", HttpStatus.BAD_REQUEST);
  302. }
  303. if (is_rabies_vaccination != null && !is_rabies_vaccination.isBlank()
  304. && is_rabies_vaccination.equalsIgnoreCase("Yes")) {
  305. // Continue registration
  306. } else {
  307. return ApiResponseUtil.error(
  308. "You can't register a pet without Rabies Vaccination. Please select 'Yes' only.",
  309. HttpStatus.BAD_REQUEST);
  310. }
  311. // Define the date format used in the request (adjust as needed)
  312. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
  313. if (arv_date != null && !arv_date.isBlank()) {
  314. LocalDate arvDate = LocalDate.parse(arv_date.trim(), formatter);
  315. if (arvDate.isAfter(LocalDate.now())) {
  316. return ApiResponseUtil.error("ARV date cannot be in the future", HttpStatus.BAD_REQUEST);
  317. }
  318. }
  319. if (lastdate_of_deworming != null && !lastdate_of_deworming.isBlank()) {
  320. LocalDate dewormDate = LocalDate.parse(lastdate_of_deworming.trim(), formatter);
  321. if (dewormDate.isAfter(LocalDate.now())) {
  322. return ApiResponseUtil.error("Deworming date cannot be in the future", HttpStatus.BAD_REQUEST);
  323. }
  324. }
  325. int yearsInt = 0;
  326. int monthsInt = 0;
  327. try {
  328. if (age_year != null && !age_year.isBlank()) {
  329. yearsInt = Integer.parseInt(age_year.trim());
  330. }
  331. if (months != null && !months.isBlank()) {
  332. monthsInt = Integer.parseInt(months.trim());
  333. }
  334. if (yearsInt <= 0 && monthsInt <= 0) {
  335. return ApiResponseUtil.error("Pet age must be at least 1 month (either in years or months)",
  336. HttpStatus.BAD_REQUEST);
  337. }
  338. } catch (NumberFormatException e) {
  339. return ApiResponseUtil.error("Invalid value for age_year or months. Both must be numbers.",
  340. HttpStatus.BAD_REQUEST);
  341. }
  342. if (saveStatus == null || saveStatus.isEmpty() || saveStatus.contains("error")) {
  343. response.put("status", false);
  344. response.put("message", saveStatus);
  345. response.put("description", "Failed to save the details");
  346. return ResponseEntity.ok(response);
  347. } else {
  348. response.put("status", true);
  349. response.put("message", "success");
  350. response.put("description", "Details were saved successfully");
  351. response.put("petId", saveStatus);
  352. }
  353. // Add uniqueid to response
  354. return ResponseEntity.ok(response);
  355. } catch (Exception ex) {
  356. return ApiResponseUtil.error("Internal server error: " + ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  357. }
  358. }
  359. // getpetdetails
  360. // get pet type
  361. @GetMapping("/getpetdetails")
  362. public ResponseEntity<?> getPetDetails(@RequestParam String mobilenum) {
  363. try {
  364. // Check if mobile is missing or blank
  365. if (mobilenum == null || mobilenum.trim().isEmpty()) {
  366. return ApiResponseUtil.error("Mobile number is required", HttpStatus.BAD_REQUEST);
  367. }
  368. // Check if mobile is not 10 digits
  369. if (!mobilenum.matches("\\d{10}")) {
  370. return ApiResponseUtil.error("Mobile number must be exactly 10 digits", HttpStatus.BAD_REQUEST);
  371. }
  372. List<Map<String, Object>> results = petRegistrationApiService.getPetRegistrationDetailsbyMobile(mobilenum);
  373. // if (results == null || results.isEmpty()) {
  374. // return ResponseEntity.status(HttpStatus.NOT_FOUND)
  375. // .body("No Registration Data for mobile number: " + mobilenum);
  376. // }
  377. if (results == null || results.isEmpty()) {
  378. return ApiResponseUtil.error("No PET Registration Details for mobile number ", HttpStatus.BAD_REQUEST);
  379. }
  380. return ApiResponseUtil.success(results, "Data found");
  381. } catch (Exception e) {
  382. return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  383. }
  384. }
  385. // renewal the pet certificate
  386. @PostMapping("/updateARVDetails")
  387. public ResponseEntity<?> updateARVDetails(
  388. @RequestParam("uniqueid") String uniqueid,
  389. @RequestParam("arvdate") String arvdate,
  390. @RequestParam("rabiesvacCertificate") MultipartFile rabiesvacCertificate) {
  391. try {
  392. if (uniqueid == null || uniqueid.trim().isEmpty()) {
  393. return ApiResponseUtil.error("Unique ID is required", HttpStatus.BAD_REQUEST);
  394. }
  395. if (arvdate == null || arvdate.trim().isEmpty()) {
  396. return ApiResponseUtil.error("ARV date is required", HttpStatus.BAD_REQUEST);
  397. }
  398. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
  399. LocalDate arvDate;
  400. try {
  401. arvDate = LocalDate.parse(arvdate.trim(), formatter);
  402. } catch (DateTimeParseException e) {
  403. return ApiResponseUtil.error("Invalid date format. Please use dd-MM-yyyy", HttpStatus.BAD_REQUEST);
  404. }
  405. // if (arvDate.isAfter(LocalDate.now())) {
  406. // return ApiResponseUtil.error("ARV date cannot be in the future",
  407. // HttpStatus.BAD_REQUEST);
  408. // }
  409. if (rabiesvacCertificate == null || rabiesvacCertificate.isEmpty()) {
  410. return ApiResponseUtil.error("Rabies vaccination certificate is required", HttpStatus.BAD_REQUEST);
  411. }
  412. String result = petRegistrationApiService.updateARVAndRabiesCertificate(uniqueid, arvdate,
  413. rabiesvacCertificate);
  414. if ("success".equalsIgnoreCase(result)) {
  415. return ApiResponseUtil.success(null, "Details updated successfully");
  416. } else if (result.startsWith("Renewal allowed only after:")) {
  417. return ApiResponseUtil.error(result, HttpStatus.BAD_REQUEST);
  418. } else if (result.startsWith("No license validity")) {
  419. return ApiResponseUtil.error(result, HttpStatus.NOT_FOUND);
  420. } else if (result.startsWith("Invalid ARV date format")) {
  421. return ApiResponseUtil.error(result, HttpStatus.BAD_REQUEST);
  422. } else {
  423. return ApiResponseUtil.error(result, HttpStatus.INTERNAL_SERVER_ERROR);
  424. }
  425. // if ("success".equalsIgnoreCase(result)) {
  426. // return ApiResponseUtil.success(null, "Details updated successfully");
  427. // } else {
  428. // return ApiResponseUtil.error(result, HttpStatus.NOT_FOUND);
  429. // }
  430. } catch (Exception e) {
  431. return ApiResponseUtil.error("Exception: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  432. }
  433. }
  434. // @PostMapping("/create_order")
  435. // public ResponseEntity<?> createOrder(@RequestParam String petId) throws RazorpayException {
  436. // try {
  437. // Map<String, Object> petDetail = petRegistrationApiService.getpetdetails(petId);
  438. // int petStatus = 0;
  439. // // Check if petDetail is empty
  440. // if (!petDetail.isEmpty()) {
  441. // petStatus = (int) petDetail.get("status");
  442. // }
  443. // if (petStatus != 2 && petStatus != 4) {
  444. // return new ResponseEntity<>(
  445. // new ApiResponse("error", "PET request must be accepted by the officer to proceed with payment.",
  446. // null, HttpStatus.BAD_REQUEST.value()),
  447. // HttpStatus.BAD_REQUEST);
  448. // }
  449. // System.out.println("key ID :-----" + appConfig.getKeyId());
  450. // int pet_id = Integer.parseInt(petId);
  451. // double amount = Double.parseDouble("50");
  452. // // To enable testing mode in appConstants if required for testing & development
  453. // var client = new RazorpayClient(AppConstants.key_id, AppConstants.key_secret);
  454. // JSONObject options = new JSONObject();
  455. // options.put("amount", amount * 100);
  456. // options.put("currency", "INR");
  457. // // options.put("receipt","Pet_ID/"+pet_id);
  458. // Order od = client.orders.create(options);
  459. // petRegistrationApiService.saveorderLog(od.get("id").toString(), od.toString(), pet_id);
  460. // System.out.println(od);
  461. // return ResponseEntity.ok(new ApiResponse("success", "Order created successfully", od.toJson().toMap(),
  462. // HttpStatus.OK.value()));
  463. // } catch (NumberFormatException ex) {
  464. // throw new RuntimeException(ex);
  465. // } catch (RazorpayException e) {
  466. // return new ResponseEntity<>(new ApiResponse("error", "Razorpay error: " + e.getMessage(), null,
  467. // HttpStatus.INTERNAL_SERVER_ERROR.value()), HttpStatus.INTERNAL_SERVER_ERROR);
  468. // } catch (EmptyResultDataAccessException ex) {
  469. // return new ResponseEntity<>(
  470. // new ApiResponse("error", "PET request must be accepted by the officer to proceed with payment.",
  471. // null, HttpStatus.BAD_REQUEST.value()),
  472. // HttpStatus.BAD_REQUEST);
  473. // } catch (Exception e) {
  474. // return new ResponseEntity<>(new ApiResponse("error", "Unexpected error: " + e.getMessage(), null,
  475. // HttpStatus.INTERNAL_SERVER_ERROR.value()), HttpStatus.INTERNAL_SERVER_ERROR);
  476. // }
  477. // }
  478. @PostMapping("/Confirm")
  479. public ResponseEntity<?> confirmPayment(
  480. @RequestParam("petId") String petId,
  481. @RequestParam(name = "source", defaultValue = "0") String source,
  482. @RequestParam("mobno") String mobno,
  483. @RequestParam(value = "orderId", required = true) String orderId,
  484. @RequestBody Map<String, Object> paymentResponse) {
  485. try {
  486. // Validate orderId is not null or empty
  487. if (orderId == null || orderId.trim().isEmpty()) {
  488. return ResponseEntity.badRequest().body(Map.of(
  489. "message", "Order ID is required and cannot be null or empty",
  490. "error", "Missing required parameter: orderId"));
  491. }
  492. System.out.println("Controller Testing.................");
  493. return petRegistrationApiService.processPaymentConfirmation(petId, source, mobno, orderId, paymentResponse);
  494. } catch (Exception e) {
  495. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  496. .body(Map.of("message", "Failed to confirm payment", "error", e.getMessage()));
  497. }
  498. }
  499. // get zones
  500. @GetMapping("/getZones")
  501. public ResponseEntity<?> getZones() {
  502. List<Map<String, Object>> result = petRegistrationApiService.getZones();
  503. try {
  504. if (result.isEmpty()) {
  505. return ApiResponseUtil.notFound("No data found");
  506. }
  507. return ApiResponseUtil.success(result, "Data found");
  508. } catch (Exception e) {
  509. return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  510. }
  511. }
  512. // get Ward by zoneid
  513. @GetMapping("/getWardByZoneId")
  514. public ResponseEntity<?> getWardByZoneId(@RequestParam String zoneid) {
  515. List<Map<String, Object>> result = petRegistrationApiService.getWardByZoneId(zoneid);
  516. try {
  517. // Check if mobile is missing or blank
  518. if (zoneid == null || zoneid.trim().isEmpty()) {
  519. return ApiResponseUtil.error("ZoneId is required", HttpStatus.BAD_REQUEST);
  520. }
  521. if (result.isEmpty()) {
  522. return ApiResponseUtil.notFound("No data found");
  523. }
  524. return ApiResponseUtil.success(result, "Data found");
  525. } catch (Exception e) {
  526. return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  527. }
  528. }
  529. @GetMapping(value = "/sendOTP")
  530. public String sendOtp(HttpServletRequest request, @RequestParam String mobileNo) {
  531. Map<String, Object> response = new HashMap<>();
  532. String MobileNo = mobileNo;
  533. System.out.print("\n MobileNo---:" + mobileNo);
  534. Random rand = new Random();
  535. int otp = rand.nextInt(90000) + 10000;
  536. System.out.print("\n otp---:" + otp);
  537. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm");
  538. LocalDateTime now = LocalDateTime.now();
  539. System.out.println(dtf.format(now));
  540. String generatedToken = "Welcome to GCC " + otp + " is your OTP for gcc QR System";
  541. String key = "pfTEYN6H";
  542. String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP&key=" + key + "&sender=GCCCRP&to=" + MobileNo
  543. + "&body=" + generatedToken + "&entityid=1401572690000011081&templateid=1407168250479102852";
  544. System.out.print("\n urlString---: " + urlString);
  545. String bodyMessage = "";
  546. if (mobileNo == null || mobileNo.trim().isEmpty()) {
  547. throw new IllegalArgumentException("Mobile number is required");
  548. }
  549. // Validate mobile number is exactly 10 digits
  550. if (!mobileNo.matches("\\d{10}")) {
  551. throw new IllegalArgumentException("Mobile number must be exactly 10 digits");
  552. }
  553. try {
  554. RestTemplate restTemplate = new RestTemplate();
  555. String Response = restTemplate.getForObject(urlString, String.class);
  556. // Using Jackson ObjectMapper to parse the response JSON
  557. ObjectMapper objectMapper = new ObjectMapper();
  558. ObjectNode jsonResponse = (ObjectNode) objectMapper.readTree(Response);
  559. // Add mobileNo and otp to the response JSON
  560. jsonResponse.put("MobileNo", MobileNo);
  561. jsonResponse.put("otp", otp);
  562. // Convert the updated JSON object back to string
  563. bodyMessage = jsonResponse.toString();
  564. // bodyMessage=Response;
  565. System.out.println("\n bodyMessage" + bodyMessage);
  566. System.out.println("OTP sent successfully!");
  567. } catch (Exception e) {
  568. System.out.print("ERROR---: " + e);
  569. bodyMessage = "Error";
  570. }
  571. HttpSession session = request.getSession();
  572. session.setAttribute("otp", otp);
  573. return bodyMessage;
  574. }
  575. // get licensedetails api
  576. @GetMapping("/getLicenseDetails")
  577. public ResponseEntity<?> getLicenseDetailsByMobileNo(
  578. @RequestParam(value = "licenseno", required = false) String licenseno) {
  579. if (licenseno == null || licenseno.isEmpty()) {
  580. return ApiResponseUtil.invalidRequest("license number is required.");
  581. }
  582. try {
  583. List<Map<String, Object>> licenseDetails = petRegistrationApiService.getLicenseListByMobNo(licenseno);
  584. if (licenseDetails == null || licenseDetails.isEmpty()) {
  585. return ApiResponseUtil.notFound("No bookings found for licenseno: " + licenseno);
  586. }
  587. // Success response
  588. Map<String, Object> response = new HashMap<>();
  589. response.put("status", "SUCCESS");
  590. response.put("statuscode", "200");
  591. response.put("licenseDetails", licenseDetails);
  592. return ResponseEntity.ok(response);
  593. } catch (Exception e) {
  594. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  595. .body("Internal server error: " + e.getMessage());
  596. }
  597. }
  598. @GetMapping("/getCountByMobileNo")
  599. public ResponseEntity<?> getCountByMobileNo(String mobileno) {
  600. int mobileCount = petRegistrationApiService.getCountByMobileNo(mobileno);
  601. System.out.println("mobileCount: " + mobileCount);
  602. if(mobileCount>=3) {
  603. return ApiResponseUtil.success(mobileCount, "Already you reached the license limit (Max 3 pets)");
  604. }else {
  605. return ApiResponseUtil.success(mobileCount, "You can proceed with the license registration");
  606. }
  607. }
  608. }