Browse Source

Health Camp controller added and POS API Changes

master
kanimozhi 9 months ago
parent
commit
95db5f6e70
  1. 4
      src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java
  2. 57
      src/main/java/com/gcc/commissionerreview/controller/MainController.java
  3. 4
      src/main/java/com/gcc/commissionerreview/controller/POSAPIController.java
  4. 37
      src/main/java/com/gcc/commissionerreview/service/POSService.java
  5. 0
      src/main/resources/templates/modules/healthcamp/healthcampreport.html

4
src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java

@ -96,8 +96,7 @@ public class DataSourceConfig {
return dataSource;
}
////////////////////////////// Health Camp ////////////////////////
////////////////////////////// Health Camp ////////////////////////
@Bean(name = "mysqlHealthCampDataSource")
public DataSource mysqlHealthCampDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
@ -108,5 +107,4 @@ public class DataSourceConfig {
return dataSource;
}
}

57
src/main/java/com/gcc/commissionerreview/controller/MainController.java

@ -1,18 +1,32 @@
package com.gcc.commissionerreview.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpSession;
@Controller
@RequestMapping(value = { "/commissionerreview" })
public class MainController {
private static final String LOGIN_URL = "http://3.26.245.178:3000/login";
@GetMapping("/uphcreport")
public String uphcreport(Model model) {
return "modules/uphcreport";
@ -180,4 +194,47 @@ public class MainController {
return "modules/food_scheme/driverreport";
}
@GetMapping("/petdashboard")
public String petdashboard(Model model, HttpSession session) {
String authToken = "";
try {
RestTemplate restTemplate = new RestTemplate();
// Request body
Map<String, String> requestBody = new HashMap<>();
requestBody.put("username", "admin@getryt.io");
requestBody.put("password", "Reset@123");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Map<String, String>> request = new HttpEntity<>(requestBody, headers);
ResponseEntity<String> response = restTemplate.postForEntity(LOGIN_URL, request, String.class);
if (response.getStatusCode() != HttpStatus.OK) {
throw new RuntimeException("Login failed");
}
// Parse JSON response
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(response.getBody());
// Equivalent to: json.data.session
authToken = root.path("data").path("session").asText();
System.out.println("Auth Token: " + authToken);
session.setAttribute("AUTH_TOKEN", authToken);
} catch (Exception e) {
e.printStackTrace();
}
model.addAttribute("AUTH_TOKEN", authToken);
return "modules/pet/petreport";
}
@GetMapping("/healthcampreport")
public String abstractreport(Model model) {
return "modules/healthcamp/healthcampreport";
}
}

4
src/main/java/com/gcc/commissionerreview/controller/POSAPIController.java

@ -72,7 +72,7 @@ public class POSAPIController {
@GetMapping("/getCategoryCollectionDetails")
@ResponseBody
public ResponseEntity<?> categoryCollectionDetails(@RequestParam String fromDate, @RequestParam String toDate,
@RequestParam String zone) {
@RequestParam String zone, @RequestParam String unitNo) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
String formattedDateTime = LocalDateTime.now().format(formatter);
@ -88,7 +88,7 @@ public class POSAPIController {
String formattedToDate = todate.format(outputFormatter);
List<Map<String, Object>> reportList = posService.getCategoryCollectionDetailsBetweenDates(formattedFromDate,
formattedToDate, zone);
formattedToDate, zone, unitNo);
Map<String, Object> response = new HashMap<>();
response.put("dateTime", formattedDateTime);

37
src/main/java/com/gcc/commissionerreview/service/POSService.java

@ -153,11 +153,11 @@ public class POSService {
public List<Map<String, Object>> getZonewiseTransactionReport(String fromDate, String toDate) {
String sql = " SELECT CAST(d.ZONE_HQ AS UNSIGNED) AS zone, " +
" CONCAT(IFNULL(d.LOC_FLAG,'ALL'),'-',IFNULL(d.ACTUAL_LOC,'ALL')) AS unit, ifnull(d.VEHICLE_REG_NO,'') as VEHICLE_NO, "
+
" COUNT(CASE WHEN DATE(a.txnDate) BETWEEN ? AND ? THEN a.txnId END) AS total_transactions, " +
" FORMAT(SUM(CASE WHEN DATE(a.txnDate) BETWEEN ? AND ? THEN a.transactionAmount END),0, 'en_IN') AS total_transaction_amount "
+
"d.ACTUAL_LOC as unitNo, " +
"CONCAT(IFNULL(d.LOC_FLAG,'ALL'),'-',IFNULL(d.ACTUAL_LOC,'ALL')) AS unit, "+
"ifnull(d.VEHICLE_REG_NO,'') as VEHICLE_NO, "+
"COUNT(CASE WHEN DATE(a.txnDate) BETWEEN ? AND ? THEN a.txnId END) AS total_transactions, " +
"FORMAT(SUM(CASE WHEN DATE(a.txnDate) BETWEEN ? AND ? THEN a.transactionAmount END),0, 'en_IN') AS total_transaction_amount "+
" FROM bank_transactions a " +
" JOIN penalty_challan b ON b.orderid = a.txnId " +
" JOIN penalty_category c ON c.id = b.category_id " +
@ -168,31 +168,14 @@ public class POSService {
" AND d.ZONE_HQ <> 0 " +
" AND DATE(a.txnDate) BETWEEN ? AND ? " +
" GROUP BY CAST(d.ZONE_HQ AS UNSIGNED), d.LOC_FLAG, d.ACTUAL_LOC, d.VEHICLE_REG_NO " +
" ORDER BY zone, unit ";
" UNION ALL " +
" SELECT 0 AS zone, 'TOTAL' AS unit, 'VTOTAL' as VEHICLE_REG_NO, " +
" COUNT(CASE WHEN DATE(a.txnDate) BETWEEN ? AND ? THEN a.txnId END), " +
" FORMAT(SUM(CASE WHEN DATE(a.txnDate) BETWEEN ? AND ? THEN a.transactionAmount END), 0, 'en_IN') "
+
" FROM bank_transactions a " +
" JOIN penalty_challan b ON b.orderid = a.txnId " +
" JOIN penalty_category c ON c.id = b.category_id " +
" JOIN user_zone d ON d.ID = b.challan_by " +
" WHERE c.name <> 'Testing' " +
" AND d.USER_NAME LIKE 'ENF%' " +
" AND d.LOC_FLAG <> 'H' " +
" AND d.ZONE_HQ <> 0 " +
" AND DATE(a.txnDate) BETWEEN ? AND ? " +
" ORDER BY CASE WHEN zone = 0 THEN 1 ELSE 0 END,zone, unit ";
return jdbcTemplate.queryForList(sql, fromDate, toDate, fromDate, toDate, fromDate, toDate,
fromDate, toDate, fromDate, toDate, fromDate, toDate);
return jdbcTemplate.queryForList(sql, fromDate, toDate, fromDate, toDate, fromDate, toDate);
}
public List<Map<String, Object>> getCategoryCollectionDetailsBetweenDates(String formattedFromDate,
String formattedToDate, String zone) {
String formattedToDate, String zone, String unitNo) {
String sql = "SELECT CONCAT(IFNULL(d.LOC_FLAG,'ALL'),'-',IFNULL(d.ACTUAL_LOC,'ALL')) AS unit, e.name as type, "+
"c.name as category, "+
@ -209,11 +192,11 @@ public class POSService {
"AND d.LOC_FLAG != 'H' " +
"AND d.ZONE_HQ != 0 " +
"AND date(a.txnDate) >= ? AND date(a.txnDate) <= ? " +
"AND CAST(d.ZONE_HQ AS UNSIGNED) = 1 " +
"AND CAST(d.ZONE_HQ AS UNSIGNED) = ? " +
"AND d.ACTUAL_LOC = ? " +
"ORDER BY date(a.txnDate)";
return jdbcTemplate.queryForList(sql, formattedFromDate, formattedToDate, zone);
return jdbcTemplate.queryForList(sql, formattedFromDate, formattedToDate, zone, unitNo);
}
}

0
src/main/resources/templates/modules/healthcamp/abstractreport.html → src/main/resources/templates/modules/healthcamp/healthcampreport.html

Loading…
Cancel
Save