Browse Source

added notapplicable_qid in document master and added one child question for rescue family response

master
AJITHKUMAR12 2 weeks ago
parent
commit
57c1b579f6
  1. 188
      src/main/java/in/gov/chennaicorporation/mobileservice/gccNightShelterInspection/Service/NightShelterInspectionService.java
  2. 32
      src/main/java/in/gov/chennaicorporation/mobileservice/gccShelter/Service/ShelterResucueService.java

188
src/main/java/in/gov/chennaicorporation/mobileservice/gccNightShelterInspection/Service/NightShelterInspectionService.java

@ -9,6 +9,7 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -118,7 +119,7 @@ public class NightShelterInspectionService {
return finalList; return finalList;
} }
private Map<String, Object> buildQuestionWithOptions(Map<String, Object> q) {
private Map<String, Object> buildQuestionWithOptions1(Map<String, Object> q) {
Integer qid = (Integer) q.get("qid"); Integer qid = (Integer) q.get("qid");
String masterTable = (String) safe(q.get("master_table_name")); String masterTable = (String) safe(q.get("master_table_name"));
@ -185,6 +186,191 @@ public class NightShelterInspectionService {
return questionMap; return questionMap;
} }
private Map<String, Object> buildQuestionWithOptions(Map<String, Object> q) {
Integer qid = (Integer) q.get("qid");
String masterTable = (String) safe(q.get("master_table_name"));
// Maintain order
Map<String, Object> questionMap = new LinkedHashMap<>();
questionMap.put("qid", q.get("qid"));
questionMap.put("q_english", q.get("q_english"));
questionMap.put("q_tamil", safe(q.get("q_tamil")));
questionMap.put("field_name", q.get("field_name"));
questionMap.put("cdate", q.get("cdate"));
questionMap.put("question_type", q.get("question_type"));
questionMap.put("isactive", q.get("isactive"));
questionMap.put("isdelete", q.get("isdelete"));
questionMap.put("orderby", q.get("orderby"));
questionMap.put("is_mandatory", q.get("is_mandatory"));
questionMap.put("is_dropdown", q.get("is_dropdown"));
questionMap.put("flag", q.get("flag"));
questionMap.put("master_table_name", masterTable);
List<Map<String, Object>> options = new ArrayList<>();
if (masterTable != null && !masterTable.isEmpty()) {
if (masterTable.equalsIgnoreCase("state_master")
|| masterTable.equalsIgnoreCase("district_master")) {
options = new ArrayList<>();
} else {
// Existing master options
options = getOptionsFromMaster(masterTable, qid);
// =====================================================
// NOT APPLICABLE LOGIC - ONLY FOR document_master
// =====================================================
if (masterTable.equalsIgnoreCase("document_master")) {
// Remove Not applicable from the normal master options
// because we will add it conditionally below.
options.removeIf(option ->
"Not applicable".equalsIgnoreCase(
String.valueOf(option.get("english_name"))
)
);
String notApplicableSql =
"SELECT id AS option_id, " +
" english_name, " +
" notapplicable_qid " +
"FROM gcc_night_shelter_inspection.document_master " +
"WHERE LOWER(english_name) = 'not applicable' " +
"AND isactive = 1 " +
"AND isdelete = 0";
List<Map<String, Object>> notApplicableOptions =
jdbcNightShelterInspectionTemplate.queryForList(
notApplicableSql
);
for (Map<String, Object> opt : notApplicableOptions) {
Object qidObj = opt.get("notapplicable_qid");
if (qidObj == null) {
continue;
}
String notApplicableQids = qidObj.toString().trim();
boolean shouldShow = false;
// 0 = show for ALL questions
if ("0".equals(notApplicableQids)) {
shouldShow = true;
} else {
// Example:
// 29,30,31,32,34,40
shouldShow = Arrays.stream(
notApplicableQids.split(",")
)
.map(String::trim)
.anyMatch(id ->
id.equals(String.valueOf(qid))
);
}
if (shouldShow) {
Map<String, Object> optionMap =
new LinkedHashMap<>();
optionMap.put(
"option_id",
opt.get("option_id")
);
optionMap.put(
"english_name",
opt.get("english_name")
);
optionMap.put("tamil_name", "");
optionMap.put("orderby", 999);
optionMap.put("is_mandatory", 0);
optionMap.put("is_others", false);
optionMap.put("text", false);
optionMap.put(
"child_questions",
new ArrayList<>()
);
options.add(optionMap);
}
}
}
}
} else {
String optSql =
"SELECT id AS option_id, answer AS english_name, " +
"orderby, is_mandatory " +
"FROM night_shelter_inspection_answer_master " +
"WHERE qid=? " +
"AND isactive=1 " +
"AND isdelete=0 " +
"ORDER BY orderby";
List<Map<String, Object>> dbOptions =
jdbcNightShelterInspectionTemplate.queryForList(
optSql,
qid
);
for (Map<String, Object> opt : dbOptions) {
Map<String, Object> optionMap =
new LinkedHashMap<>();
String englishName =
(String) opt.get("english_name");
optionMap.put("option_id", opt.get("option_id"));
optionMap.put("english_name", englishName);
optionMap.put("tamil_name", "");
optionMap.put("orderby", opt.get("orderby"));
optionMap.put(
"is_mandatory",
opt.get("is_mandatory")
);
boolean isOthers =
englishName != null
&& englishName.equalsIgnoreCase("Others");
optionMap.put("is_others", isOthers);
optionMap.put("text", isOthers);
Integer aid =
(Integer) opt.get("option_id");
List<Map<String, Object>> childQuestions =
getChildQuestionsRecursive(aid);
optionMap.put(
"child_questions",
childQuestions
);
options.add(optionMap);
}
}
questionMap.put("options", options);
return questionMap;
}
private List<Map<String, Object>> getChildQuestionsRecursive(Integer parentAid) { private List<Map<String, Object>> getChildQuestionsRecursive(Integer parentAid) {

32
src/main/java/in/gov/chennaicorporation/mobileservice/gccShelter/Service/ShelterResucueService.java

@ -61,7 +61,6 @@ public class ShelterResucueService {
this.jdbcShelterRescueTemplate = new JdbcTemplate(ShelterRescueataSource); this.jdbcShelterRescueTemplate = new JdbcTemplate(ShelterRescueataSource);
} }
public List<Map<String, Object>> getSurveyQuestions(Integer cid) { public List<Map<String, Object>> getSurveyQuestions(Integer cid) {
String childSql = "SELECT DISTINCT child_qid FROM shelter_resuce_question_mapping " + String childSql = "SELECT DISTINCT child_qid FROM shelter_resuce_question_mapping " +
@ -429,7 +428,8 @@ public class ShelterResucueService {
if (cid != null && cid.equals("1") && (zone != null || resolvedLat != null || resolvedLng != null)) { if (cid != null && cid.equals("1") && (zone != null || resolvedLat != null || resolvedLng != null)) {
try { try {
// String logindetailsSql = "INSERT INTO surveyor_location_resuce_details " + // String logindetailsSql = "INSERT INTO surveyor_location_resuce_details " +
// "(loginId, zone, ward, latitude, longitude, shelter_id, is_active, is_delete, cdate) " +
// "(loginId, zone, ward, latitude, longitude, shelter_id, is_active, is_delete,
// cdate) " +
// "VALUES (?, ?, ?, ?, ?, ?, 1, 0, NOW())"; // "VALUES (?, ?, ?, ?, ?, ?, 1, 0, NOW())";
String logindetailsSql = "INSERT INTO surveyor_location_resuce_details " + String logindetailsSql = "INSERT INTO surveyor_location_resuce_details " +
@ -496,7 +496,8 @@ public class ShelterResucueService {
// if (familyMembersJson != null && !familyMembersJson.trim().isEmpty() // if (familyMembersJson != null && !familyMembersJson.trim().isEmpty()
// && familyMembersJson.trim().startsWith("[")) { // && familyMembersJson.trim().startsWith("[")) {
// try { // try {
// List<Map<String, Object>> familyList = parseFamilyMembersJson(familyMembersJson);
// List<Map<String, Object>> familyList =
// parseFamilyMembersJson(familyMembersJson);
// if (familyList != null && !familyList.isEmpty()) { // if (familyList != null && !familyList.isEmpty()) {
// saveFamilyMembers(familyList, surveyId, cby); // saveFamilyMembers(familyList, surveyId, cby);
// } // }
@ -572,14 +573,10 @@ public class ShelterResucueService {
+ +
"VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), 1, 0)"; "VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), 1, 0)";
String insertSql = "INSERT INTO shelter_resuce_response (qid, answer, others_answer, survey_id, cid, cby, parent_answer_id, cdate, isactive, isdelete) " String insertSql = "INSERT INTO shelter_resuce_response (qid, answer, others_answer, survey_id, cid, cby, parent_answer_id, cdate, isactive, isdelete) "
+ +
"VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), 1, 0)"; "VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), 1, 0)";
String qSql = "SELECT qid, question_type, field_name, q_english FROM shelter_resuce_questions_master " String qSql = "SELECT qid, question_type, field_name, q_english FROM shelter_resuce_questions_master "
+ "WHERE cid = ? AND (isactive = 1 AND isdelete = 0 OR (cid = '1' AND field_name IN ('q2', 'q78', 'q11', 'q8', 'q9', 'q10', 'q77')))"; + "WHERE cid = ? AND (isactive = 1 AND isdelete = 0 OR (cid = '1' AND field_name IN ('q2', 'q78', 'q11', 'q8', 'q9', 'q10', 'q77')))";
List<Map<String, Object>> questions = jdbcShelterRescueTemplate.queryForList(qSql, cid); List<Map<String, Object>> questions = jdbcShelterRescueTemplate.queryForList(qSql, cid);
@ -1098,7 +1095,6 @@ public class ShelterResucueService {
return resultList; return resultList;
} }
private List<Map<String, Object>> parseFamilyMembersJson(String jsonStr) { private List<Map<String, Object>> parseFamilyMembersJson(String jsonStr) {
if (jsonStr == null || jsonStr.trim().isEmpty()) { if (jsonStr == null || jsonStr.trim().isEmpty()) {
return new ArrayList<>(); return new ArrayList<>();
@ -1156,7 +1152,6 @@ public class ShelterResucueService {
return list; return list;
} }
private void saveFamilyMembers(List<Map<String, Object>> familyList, String surveyId, String cby) { private void saveFamilyMembers(List<Map<String, Object>> familyList, String surveyId, String cby) {
if (familyList == null || familyList.isEmpty()) { if (familyList == null || familyList.isEmpty()) {
return; return;
@ -1202,14 +1197,13 @@ public class ShelterResucueService {
qid = 8; qid = 8;
} else if ("gender".equals(cleanKey)) { } else if ("gender".equals(cleanKey)) {
qid = 9; qid = 9;
}
else if ("remark".equals(cleanKey)) {
} else if ("remark".equals(cleanKey)) {
qid = 10; qid = 10;
} else if ("resucelocaton".equals(cleanKey)) {
qid = 11;
} }
} }
// Fallback: If still null, try resolving by field_name or matching q_english // Fallback: If still null, try resolving by field_name or matching q_english
// (case-insensitive) from DB without active/delete constraint // (case-insensitive) from DB without active/delete constraint
if (qid == null) { if (qid == null) {
@ -1251,20 +1245,20 @@ public class ShelterResucueService {
parentAnswerId = 2; parentAnswerId = 2;
} else if (qid == 9) { } else if (qid == 9) {
parentAnswerId = 3; parentAnswerId = 3;
}
else if (qid == 10) {
} else if (qid == 10) {
parentAnswerId = 4; parentAnswerId = 4;
} else if (qid == 11) {
parentAnswerId = 5;
} }
} }
// Fallback: If still null, try resolving from mapping table (without // Fallback: If still null, try resolving from mapping table (without
// active/delete constraint) // active/delete constraint)
if (parentAnswerId == null) { if (parentAnswerId == null) {
try { try {
String parentAidSql = "SELECT parent_aid FROM rag_picker_question_mapping WHERE child_qid = ? LIMIT 1"; String parentAidSql = "SELECT parent_aid FROM rag_picker_question_mapping WHERE child_qid = ? LIMIT 1";
List<Integer> list = jdbcShelterRescueTemplate.queryForList(parentAidSql, Integer.class, qid);
List<Integer> list = jdbcShelterRescueTemplate.queryForList(parentAidSql, Integer.class,
qid);
if (!list.isEmpty()) { if (!list.isEmpty()) {
parentAnswerId = list.get(0); parentAnswerId = list.get(0);
} }
@ -1290,6 +1284,4 @@ public class ShelterResucueService {
} }
} }
} }
Loading…
Cancel
Save