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.

579 lines
27 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
2 years ago
2 years ago
​
​
​
​
2 years ago
2 years ago
​
​
​
​
2 years ago
2 years ago
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
2 years ago
​
2 years ago
2 years ago
2 years ago
2 years ago
​
​
​
2 years ago
2 years ago
2 years ago
2 years ago
​
​
​
2 years ago
2 years ago
2 years ago
2 years ago
​
​
​
2 years ago
2 years ago
2 years ago
2 years ago
​
​
2 years ago
2 years ago
​
​
​
​
2 years ago
2 years ago
2 years ago
2 years ago
​
​
2 years ago
2 years ago
​
​
​
2 years ago
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
2 years ago
2 years ago
​
2 years ago
​
​
​
​
​
​
2 years ago
2 years ago
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package in.gov.chennaicorporation.gccoffice.pensioner.service;
  2. import java.util.ArrayList;
  3. import java.util.Collections;
  4. import java.util.List;
  5. import java.util.Map;
  6. import javax.sql.DataSource;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.beans.factory.annotation.Qualifier;
  9. import org.springframework.jdbc.core.JdbcTemplate;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.web.client.RestTemplate;
  12. import com.fasterxml.jackson.databind.ObjectMapper;
  13. import in.gov.chennaicorporation.gccoffice.configuration.AppConfig;
  14. @Service
  15. public class ReportApiService {
  16. @Autowired
  17. private JdbcTemplate jdbcTemplate;
  18. private RestTemplate restTemplate;
  19. private ObjectMapper objectMapper;
  20. @Autowired
  21. private AppConfig appconfig;
  22. public ReportApiService(RestTemplate restTemplate, ObjectMapper objectMapper) {
  23. this.restTemplate = restTemplate;
  24. this.objectMapper = objectMapper;
  25. }
  26. @Autowired
  27. public void setDataSource(@Qualifier("mysqlPensionerDataSource") DataSource dataSource) {
  28. this.jdbcTemplate = new JdbcTemplate(dataSource);
  29. }
  30. @Autowired
  31. public GetFileStatusService getFileStatus;
  32. public List<Map<String, Object>> getFileCategories() {
  33. String sql = "SELECT id,file_name FROM file_category_master";
  34. return jdbcTemplate.queryForList(sql);
  35. }
  36. // String sql = "SELECT fm.file_name, " +
  37. // "COALESCE(SUM(CASE WHEN pd.file_status IN (1,3) THEN 1 ELSE 0 END), 0) AS audit_pending, " +
  38. // "COALESCE(SUM(CASE WHEN pd.file_status IN (2,5,6,9) THEN 1 ELSE 0 END), 0) AS department_pending, " +
  39. // "COALESCE(SUM(CASE WHEN pd.file_status IN (4,7,8,10) THEN 1 ELSE 0 END), 0) AS pension_pending, " +
  40. // "COALESCE(SUM(CASE WHEN pd.file_status = 11 THEN 1 ELSE 0 END), 0) AS completed " +
  41. // "FROM gcc_pensioner.file_category_master fm " +
  42. // "LEFT JOIN gcc_pensioner.pensioner_details pd " +
  43. // "ON pd.file_category = fm.id " +
  44. // "AND pd.created_date BETWEEN ? AND ? " +
  45. // "AND pd.dept_id = ? " +
  46. // "AND pd.is_closed = 0 " + // Ensure only active records are considered
  47. // "GROUP BY fm.file_name";
  48. public List<Map<String, Object>> getReportData(String startDate, String endDate, String deptId) {
  49. String sql = "SELECT fm.id, " +
  50. " fm.file_name AS file_name, " +
  51. // Audit Pending Count
  52. " (SELECT COUNT(*) FROM pensioner_details pd " +
  53. " WHERE pd.file_status IN (1,3) AND pd.dept_id = ? " +
  54. " AND pd.file_category=fm.id "+
  55. " AND pd.is_closed = 0 " +
  56. " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) AS audit_pending, " +
  57. // Department Pending Count
  58. " (SELECT COUNT(*) FROM pensioner_details pd " +
  59. " WHERE pd.file_status IN (2,5,6,9) AND pd.dept_id = ? " +
  60. " AND pd.file_category=fm.id "+
  61. " AND pd.is_closed = 0 " +
  62. " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) AS department_pending, " +
  63. // Pension Pending Count
  64. " (SELECT COUNT(*) FROM pensioner_details pd " +
  65. " WHERE pd.file_status IN (4,7,8,10) AND pd.dept_id = ? " +
  66. " AND pd.file_category=fm.id "+
  67. " AND pd.is_closed = 0 " +
  68. " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) AS pension_pending, " +
  69. // Completed Count (SUM of two tables)
  70. " (COALESCE((SELECT COUNT(*) FROM pensioner_details pd " +
  71. " WHERE pd.file_status = 11 AND pd.dept_id = ? " +
  72. " AND pd.file_category=fm.id "+
  73. " AND pd.is_closed = 0 " +
  74. " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)), 0) " +
  75. " + " +
  76. " COALESCE((SELECT COUNT(*) FROM cps_pensioner_details cps " +
  77. " WHERE cps.file_status = 11 AND cps.dept_id = ? " +
  78. " AND cps.file_category=fm.id "+
  79. " AND DATE(cps.created_date) BETWEEN DATE(?) AND DATE(?)), 0)) AS completed, " +
  80. // Total Files Count (SUM of two tables)
  81. " (COALESCE((SELECT COUNT(*) FROM pensioner_details pd " +
  82. " WHERE pd.dept_id = ? " +
  83. " AND pd.file_category=fm.id "+
  84. " AND pd.is_closed = 0 " +
  85. " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)), 0) " +
  86. " + " +
  87. " COALESCE((SELECT COUNT(*) FROM cps_pensioner_details cps " +
  88. " WHERE cps.dept_id = ? " +
  89. " AND cps.file_category=fm.id "+
  90. " AND DATE(cps.created_date) BETWEEN DATE(?) AND DATE(?)), 0)) AS total_files " +
  91. "FROM file_category_master fm " +
  92. "GROUP BY fm.id, fm.file_name " + // Correct placement of GROUP BY
  93. "ORDER BY fm.id"; // ORDER BY after GROUP BY
  94. List<Object> params = new ArrayList<>();
  95. // Adding parameters in the correct order for each subquery
  96. for (int i = 0; i < 7; i++) { // 6 subqueries that use deptId, startDate, endDate
  97. params.add(deptId);
  98. params.add(startDate);
  99. params.add(endDate);
  100. }
  101. return jdbcTemplate.queryForList(sql, params.toArray());
  102. }
  103. public List<Map<String, Object>> getReportDetails(String startDate, String endDate, Integer deptId, Integer fileCatId, List<String> fileStatus) {
  104. String sql = "";
  105. List<Object> params = new ArrayList<>();
  106. // Construct fileStatus condition
  107. String fileStatusCondition = (fileStatus != null && !fileStatus.isEmpty())
  108. ? " AND pd.file_status IN (" + String.join(",", Collections.nCopies(fileStatus.size(), "?")) + ")"
  109. : ""; // Skip condition if fileStatus is empty or null
  110. if (fileCatId == 6) {
  111. sql = "SELECT pd.emp_no, pd.emp_name, pd.designation, pd.type_of_retirement, pd.reason_for_pending, pd.retirement_date, " +
  112. "fm.file_status AS fst, pd.file_category_name, pd.remarks, DATE(pd.created_date) AS created_date " +
  113. "FROM cps_pensioner_details pd " +
  114. "INNER JOIN file_status_master fm ON pd.file_status = fm.id " +
  115. "WHERE DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?) " + // First date filter
  116. "AND pd.dept_id = ? " + // Next deptId
  117. "AND pd.file_category = ? " + // Next fileCatId
  118. fileStatusCondition; // Last fileStatus condition
  119. } else {
  120. sql = "SELECT pd.*, fm.file_status AS fst " +
  121. "FROM pensioner_details pd " +
  122. "INNER JOIN file_status_master fm ON pd.file_status = fm.id " +
  123. "WHERE DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?) " + // First date filter
  124. "AND pd.dept_id = ? " + // Next deptId
  125. "AND pd.file_category = ? " + // Next fileCatId
  126. fileStatusCondition; // Last fileStatus condition
  127. }
  128. // Add date range parameters first
  129. params.add(startDate);
  130. params.add(endDate);
  131. // Add deptId and fileCatId parameters
  132. params.add(deptId);
  133. params.add(fileCatId);
  134. // Add fileStatus parameters if present
  135. if (fileStatus != null && !fileStatus.isEmpty()) {
  136. params.addAll(fileStatus);
  137. }
  138. System.out.println("Executing SQL Query: " + sql);
  139. System.out.println("Query Parameters: " + params);
  140. return jdbcTemplate.queryForList(sql, params.toArray());
  141. }
  142. //pensioner side reorts methods
  143. public List<Map<String, Object>> getstatus() {
  144. String sql = "select id , file_status from file_status_master";
  145. return jdbcTemplate.queryForList(sql);
  146. }
  147. public List<Map<String, Object>> getdepartment() {
  148. String sql = "select dept_id ,dept_name from department_master WHERE dept_id <> 2000";
  149. return jdbcTemplate.queryForList(sql);
  150. }
  151. // public List<Map<String, Object>> getReportDatapension(String startDate, String endDate, String fileCategoryId) {
  152. // String sql = "SELECT fm.file_name, " +
  153. // "fm.id AS file_category_id, " +
  154. // "COALESCE(dm.dept_name, 'All Departments') AS dept_name, " +
  155. // "COALESCE(SUM(CASE WHEN pd.file_status IN (1,3) OR cps.file_status IN (1,3) THEN 1 ELSE 0 END), 0) AS audit_pending, " +
  156. // "COALESCE(SUM(CASE WHEN pd.file_status IN (2,5,6,9) OR cps.file_status IN (2,5,6,9) THEN 1 ELSE 0 END), 0) AS department_pending, " +
  157. // "COALESCE(SUM(CASE WHEN pd.file_status IN (4,7,8,10) OR cps.file_status IN (4,7,8,10) THEN 1 ELSE 0 END), 0) AS pension_pending, " +
  158. // "COALESCE(SUM(CASE WHEN pd.file_status = 11 OR cps.file_status = 11 THEN 1 ELSE 0 END), 0) AS completed, " +
  159. // "COALESCE(COUNT(pd.id) + COUNT(cps.id), 0) AS total_files " +
  160. // "FROM gcc_pensioner.file_category_master fm " +
  161. // "LEFT JOIN gcc_pensioner.cps_pensioner_details cps ON cps.file_category = fm.id " +
  162. // "LEFT JOIN gcc_pensioner.pensioner_details pd ON pd.file_category = fm.id " +
  163. // "LEFT JOIN gcc_pensioner.department_master dm ON dm.dept_id = COALESCE(pd.dept_id, cps.dept_id) " +
  164. // "WHERE (pd.created_date BETWEEN ? AND ? OR cps.created_date BETWEEN ? AND ?) " +
  165. // (fileCategoryId != null && !fileCategoryId.isEmpty() ? "AND fm.id = ? " : "") +
  166. // "GROUP BY fm.id, fm.file_name, dm.dept_name " +
  167. // "ORDER BY fm.id, dm.dept_name, fm.file_name";
  168. //
  169. // System.out.println("Executing SQL: " + sql);
  170. //
  171. // List<Object> params = new ArrayList<>();
  172. // params.add(startDate);
  173. // params.add(endDate);
  174. // params.add(startDate); // Date filter applies to both `pd` and `cps`
  175. // params.add(endDate);
  176. //
  177. // if (fileCategoryId != null && !fileCategoryId.isEmpty()) {
  178. // params.add(fileCategoryId);
  179. // }
  180. //
  181. // return jdbcTemplate.queryForList(sql, params.toArray());
  182. // }
  183. // public List<Map<String, Object>> getReportDatapension(String startDate, String endDate, String fileCategoryId) {
  184. // String sql = "SELECT dm.dept_id, " +
  185. // " dm.dept_name AS dept_name, " +
  186. //
  187. // // Audit Pending Count
  188. // " (SELECT COUNT(*) FROM pensioner_details pd " +
  189. // " WHERE pd.file_status IN (1,3) AND pd.dept_id = dm.dept_id " +
  190. // " AND pd.is_closed = 0 " + // Added condition
  191. // " AND ( ? IS NULL OR pd.file_category = ? ) " +
  192. // " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) AS audit_pending, " +
  193. //
  194. // // Department Pending Count
  195. // " (SELECT COUNT(*) FROM pensioner_details pd " +
  196. // " WHERE pd.file_status IN (2,5,6,9) AND pd.dept_id = dm.dept_id " +
  197. // " AND pd.is_closed = 0 " + // Added condition
  198. // " AND ( ? IS NULL OR pd.file_category = ? ) " +
  199. // " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) AS department_pending, " +
  200. //
  201. // // Pension Pending Count
  202. // " (SELECT COUNT(*) FROM pensioner_details pd " +
  203. // " WHERE pd.file_status IN (4,7,8,10) AND pd.dept_id = dm.dept_id " +
  204. // " AND pd.is_closed = 0 " + // Added condition
  205. // " AND ( ? IS NULL OR pd.file_category = ? ) " +
  206. // " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) AS pension_pending, " +
  207. //
  208. // // Completed Count
  209. // " (SELECT COUNT(*) FROM pensioner_details pd " +
  210. // " WHERE pd.file_status = 11 AND pd.dept_id = dm.dept_id " +
  211. // " AND pd.is_closed = 0 " + // Added condition
  212. // " AND ( ? IS NULL OR pd.file_category = ? ) " +
  213. // " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) " +
  214. // " + " +
  215. // " (SELECT COUNT(*) FROM cps_pensioner_details cps " +
  216. // " WHERE cps.file_status = 11 AND cps.dept_id = dm.dept_id " +
  217. // " AND ( ? IS NULL OR cps.file_category = ? ) " +
  218. // " AND DATE(cps.created_date) BETWEEN DATE(?) AND DATE(?)) AS completed, " +
  219. //
  220. // // Total Files Count
  221. // " (SELECT COUNT(*) pensioner_details pd " +
  222. // " WHERE pd.dept_id = dm.dept_id " +
  223. // " AND pd.is_closed = 0 " + // Added condition
  224. // " AND ( ? IS NULL OR pd.file_category = ? ) " +
  225. // " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) " +
  226. // " + " +
  227. // " (SELECT COUNT(*) FROM cps_pensioner_details cps " +
  228. // " WHERE cps.dept_id = dm.dept_id " +
  229. // " AND ( ? IS NULL OR cps.file_category = ? ) " +
  230. // " AND DATE(cps.created_date) BETWEEN DATE(?) AND DATE(?)) AS total_files " +
  231. //
  232. // "FROM department_master dm " +
  233. // "ORDER BY dm.dept_id";
  234. //
  235. // System.out.println("Executing SQL: " + sql);
  236. //
  237. // List<Object> params = new ArrayList<>();
  238. //
  239. // // Adding parameters explicitly without a loop
  240. // params.add(fileCategoryId != null && !fileCategoryId.isEmpty() ? fileCategoryId : null);
  241. // params.add(fileCategoryId);
  242. // params.add(startDate);
  243. // params.add(endDate);
  244. //
  245. // params.add(fileCategoryId != null && !fileCategoryId.isEmpty() ? fileCategoryId : null);
  246. // params.add(fileCategoryId);
  247. // params.add(startDate);
  248. // params.add(endDate);
  249. //
  250. // params.add(fileCategoryId != null && !fileCategoryId.isEmpty() ? fileCategoryId : null);
  251. // params.add(fileCategoryId);
  252. // params.add(startDate);
  253. // params.add(endDate);
  254. //
  255. // params.add(fileCategoryId != null && !fileCategoryId.isEmpty() ? fileCategoryId : null);
  256. // params.add(fileCategoryId);
  257. // params.add(startDate);
  258. // params.add(endDate);
  259. //
  260. // params.add(fileCategoryId != null && !fileCategoryId.isEmpty() ? fileCategoryId : null);
  261. // params.add(fileCategoryId);
  262. // params.add(startDate);
  263. // params.add(endDate);
  264. //
  265. // params.add(fileCategoryId != null && !fileCategoryId.isEmpty() ? fileCategoryId : null);
  266. // params.add(fileCategoryId);
  267. // params.add(startDate);
  268. // params.add(endDate);
  269. //
  270. // params.add(fileCategoryId != null && !fileCategoryId.isEmpty() ? fileCategoryId : null);
  271. // params.add(fileCategoryId);
  272. // params.add(startDate);
  273. // params.add(endDate);
  274. //
  275. // return jdbcTemplate.queryForList(sql, params.toArray());
  276. // }
  277. public List<Map<String, Object>> getReportDatapension(String startDate, String endDate, String fileCategoryId) {
  278. String sql = "SELECT dm.dept_id, " +
  279. " dm.dept_name AS dept_name, " +
  280. // Audit Pending Count
  281. " (SELECT COUNT(*) FROM pensioner_details pd " +
  282. " WHERE pd.file_status IN (1,3) AND pd.dept_id = dm.dept_id " +
  283. " AND pd.is_closed = 0 " +
  284. " AND ( ? IS NULL OR pd.file_category = ? ) " +
  285. " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) AS audit_pending, " +
  286. // Department Pending Count
  287. " (SELECT COUNT(*) FROM pensioner_details pd " +
  288. " WHERE pd.file_status IN (2,5,6,9) AND pd.dept_id = dm.dept_id " +
  289. " AND pd.is_closed = 0 " +
  290. " AND ( ? IS NULL OR pd.file_category = ? ) " +
  291. " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) AS department_pending, " +
  292. // Pension Pending Count
  293. " (SELECT COUNT(*) FROM pensioner_details pd " +
  294. " WHERE pd.file_status IN (4,7,8,10) AND pd.dept_id = dm.dept_id " +
  295. " AND pd.is_closed = 0 " +
  296. " AND ( ? IS NULL OR pd.file_category = ? ) " +
  297. " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) AS pension_pending, " +
  298. // Completed Count
  299. " (SELECT COUNT(*) FROM pensioner_details pd " +
  300. " WHERE pd.file_status = 11 AND pd.dept_id = dm.dept_id " +
  301. " AND pd.is_closed = 0 " +
  302. " AND ( ? IS NULL OR pd.file_category = ? ) " +
  303. " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) " +
  304. " + " +
  305. " (SELECT COUNT(*) FROM cps_pensioner_details cps " +
  306. " WHERE cps.file_status = 11 AND cps.dept_id = dm.dept_id " +
  307. " AND ( ? IS NULL OR cps.file_category = ? ) " +
  308. " AND DATE(cps.created_date) BETWEEN DATE(?) AND DATE(?)) AS completed, " +
  309. // Total Files Count
  310. " (SELECT COUNT(*) FROM pensioner_details pd " + // Fixed Syntax
  311. " WHERE pd.dept_id = dm.dept_id " +
  312. " AND pd.is_closed = 0 " +
  313. " AND ( ? IS NULL OR pd.file_category = ? ) " +
  314. " AND DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?)) " +
  315. " + " +
  316. " (SELECT COUNT(*) FROM cps_pensioner_details cps " +
  317. " WHERE cps.dept_id = dm.dept_id " +
  318. " AND ( ? IS NULL OR cps.file_category = ? ) " +
  319. " AND DATE(cps.created_date) BETWEEN DATE(?) AND DATE(?)) AS total_files " +
  320. "FROM department_master dm " +
  321. "ORDER BY dm.dept_id";
  322. System.out.println("Executing SQL: " + sql);
  323. List<Object> params = new ArrayList<>();
  324. for (int i = 0; i < 7; i++) {
  325. params.add(fileCategoryId != null && !fileCategoryId.isEmpty() ? fileCategoryId : null);
  326. params.add(fileCategoryId);
  327. params.add(startDate);
  328. params.add(endDate);
  329. }
  330. return jdbcTemplate.queryForList(sql, params.toArray());
  331. }
  332. // public List<Map<String, Object>> getReportDetailspension(String startDate, String endDate, List<String> deptIds, Integer fileCatId, List<String> fileStatus) {
  333. // String sql = "";
  334. // List<Object> params = new ArrayList<>();
  335. //
  336. // boolean selectAll = deptIds.contains("ALL");
  337. //
  338. // // ✅ If "ALL" is selected, remove department filtering
  339. // String deptCondition = selectAll ? "1=1" : "pd.dept_id IN (" + String.join(",", Collections.nCopies(deptIds.size(), "?")) + ")";
  340. //
  341. // // ✅ Handle fileStatus as multiple values in IN clause
  342. // String fileStatusCondition = (fileStatus != null && !fileStatus.isEmpty())
  343. // ? " AND pd.file_status IN (" + String.join(",", Collections.nCopies(fileStatus.size(), "?")) + ")"
  344. // : ""; // Skip condition if fileStatus is empty or null
  345. //
  346. // if (fileCatId == 6) {
  347. // sql = "SELECT pd.emp_no, pd.emp_name, pd.designation, pd.type_of_retirement, pd.reason_for_pending, " +
  348. // "fm.file_status AS fst, pd.file_category_name, pd.remarks, DATE(pd.created_date) AS created_date " +
  349. // "FROM cps_pensioner_details pd " +
  350. // "INNER JOIN file_status_master fm ON pd.file_status = fm.id " +
  351. // "WHERE " + deptCondition + " AND pd.file_category = ?" + fileStatusCondition;
  352. //
  353. // if (!selectAll) {
  354. // params.addAll(deptIds);
  355. // }
  356. // params.add(fileCatId);
  357. // if (fileStatus != null && !fileStatus.isEmpty()) {
  358. // params.addAll(fileStatus);
  359. // }
  360. // }
  361. // else {
  362. // sql = "SELECT pd.*, fm.file_status as fst FROM pensioner_details pd " +
  363. // "INNER JOIN file_status_master fm ON pd.file_status = fm.id " +
  364. // "WHERE " + deptCondition + " AND pd.file_category = ?" + fileStatusCondition;
  365. //
  366. // if (!selectAll) {
  367. // params.addAll(deptIds);
  368. // }
  369. // params.add(fileCatId);
  370. // if (fileStatus != null && !fileStatus.isEmpty()) {
  371. // params.addAll(fileStatus);
  372. // }
  373. // }
  374. //
  375. // System.out.println("Executing SQL Query: " + sql);
  376. // System.out.println("Query Parameters: " + params);
  377. //
  378. // return jdbcTemplate.queryForList(sql, params.toArray());
  379. // }
  380. // public List<Map<String, Object>> getReportDetailspension(String startDate, String endDate, List<String> deptIds, Integer fileCatId, List<String> fileStatus) {
  381. // String sql = "";
  382. // List<Object> params = new ArrayList<>();
  383. //
  384. // boolean selectAll = deptIds.contains("ALL");
  385. //
  386. // // ✅ If "ALL" is selected, remove department filtering
  387. // String deptCondition = selectAll ? "1=1" : "pd.dept_id IN (" + String.join(",", Collections.nCopies(deptIds.size(), "?")) + ")";
  388. //
  389. // // ✅ Handle fileStatus as multiple values in IN clause
  390. // String fileStatusCondition = (fileStatus != null && !fileStatus.isEmpty())
  391. // ? " AND pd.file_status IN (" + String.join(",", Collections.nCopies(fileStatus.size(), "?")) + ")"
  392. // : ""; // Skip condition if fileStatus is empty or null
  393. //
  394. // if (fileCatId == 6) {
  395. // sql = "SELECT pd.emp_no, pd.emp_name, pd.designation, pd.type_of_retirement, pd.reason_for_pending,pd.retirement_date, " +
  396. // "fm.file_status AS fst, pd.file_category_name, pd.remarks, DATE(pd.created_date) AS created_date " +
  397. // "FROM cps_pensioner_details pd " +
  398. // "INNER JOIN file_status_master fm ON pd.file_status = fm.id " +
  399. // "WHERE DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?) " + // First: Date filter
  400. // "AND pd.file_category = ? " + // Second: File category filter
  401. // "AND " + deptCondition + // Third: Department condition
  402. // fileStatusCondition; // Last: File status condition
  403. //
  404. // } else {
  405. // sql = "SELECT pd.*, fm.file_status as fst " +
  406. // "FROM pensioner_details pd " +
  407. // "INNER JOIN file_status_master fm ON pd.file_status = fm.id " +
  408. // "WHERE DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?) " + // First: Date filter
  409. // "AND pd.file_category = ? " + // Second: File category filter
  410. // "AND " + deptCondition + // Third: Department condition
  411. // fileStatusCondition; // Last: File status condition
  412. // }
  413. //
  414. // // Add date range parameters first
  415. // params.add(startDate);
  416. // params.add(endDate);
  417. //
  418. // // Add file category next
  419. // params.add(fileCatId);
  420. //
  421. // // Add department filter parameters if not "ALL"
  422. // if (!selectAll) {
  423. // params.addAll(deptIds);
  424. // }
  425. //
  426. // // Add fileStatus parameters if present
  427. // if (fileStatus != null && !fileStatus.isEmpty()) {
  428. // params.addAll(fileStatus);
  429. // }
  430. //
  431. // System.out.println("Executing SQL Query: " + sql);
  432. // System.out.println("Query Parameters: " + params);
  433. //
  434. // return jdbcTemplate.queryForList(sql, params.toArray());
  435. // }
  436. public List<Map<String, Object>> getReportDetailspension(String startDate, String endDate, List<String> deptIds, Integer fileCatId, List<String> fileStatus) {
  437. String sql = "";
  438. List<Object> params = new ArrayList<>();
  439. // ✅ Ensure deptIds is never empty, otherwise fetch nothing
  440. if (deptIds == null || deptIds.isEmpty()) {
  441. return new ArrayList<>();
  442. }
  443. // ✅ Construct IN clause for department filtering
  444. String deptCondition = "pd.dept_id IN (" + String.join(",", Collections.nCopies(deptIds.size(), "?")) + ")";
  445. // ✅ Handle fileStatus as multiple values in IN clause
  446. String fileStatusCondition = (fileStatus != null && !fileStatus.isEmpty())
  447. ? " AND pd.file_status IN (" + String.join(",", Collections.nCopies(fileStatus.size(), "?")) + ")"
  448. : ""; // Skip condition if fileStatus is empty or null
  449. if (fileCatId == 6) {
  450. sql = "SELECT pd.emp_no, pd.emp_name, pd.designation, pd.type_of_retirement, pd.reason_for_pending, pd.retirement_date, " +
  451. "fm.file_status AS fst, pd.file_category_name, pd.remarks, DATE(pd.created_date) AS created_date " +
  452. "FROM cps_pensioner_details pd " +
  453. "INNER JOIN file_status_master fm ON pd.file_status = fm.id " +
  454. "WHERE DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?) " +
  455. "AND pd.file_category = ? " +
  456. "AND " + deptCondition +
  457. fileStatusCondition;
  458. } else {
  459. sql = "SELECT pd.*, fm.file_status as fst " +
  460. "FROM pensioner_details pd " +
  461. "INNER JOIN file_status_master fm ON pd.file_status = fm.id " +
  462. "WHERE DATE(pd.created_date) BETWEEN DATE(?) AND DATE(?) " +
  463. "AND pd.file_category = ? " +
  464. "AND " + deptCondition +
  465. fileStatusCondition;
  466. }
  467. // Add date range parameters first
  468. params.add(startDate);
  469. params.add(endDate);
  470. // Add file category next
  471. params.add(fileCatId);
  472. // Add department filter parameters
  473. params.addAll(deptIds);
  474. // Add fileStatus parameters if present
  475. if (fileStatus != null && !fileStatus.isEmpty()) {
  476. params.addAll(fileStatus);
  477. }
  478. System.out.println("Executing SQL Query: " + sql);
  479. System.out.println("Query Parameters: " + params);
  480. return jdbcTemplate.queryForList(sql, params.toArray());
  481. }
  482. public List<Map<String, Object>> getDepartmentpending(int file_category) {
  483. String sql = "SELECT dept_name, emp_name, emp_no, file_category_name, file_status, file_moved_date, remarks " +
  484. "FROM pensioner_details WHERE file_status IN (2, 5, 6, 9) AND file_category=?";
  485. List<Map<String, Object>> results = jdbcTemplate.queryForList(sql, file_category);
  486. return jdbcTemplate.queryForList(sql, file_category);
  487. }
  488. }