From 8907b4f6eb634817434ae4b19d68f3ded2b2d7f1 Mon Sep 17 00:00:00 2001 From: Balaji <104271023+tbalaji0001@users.noreply.github.com> Date: Thu, 25 Sep 2025 18:27:36 +0530 Subject: [PATCH] New Modules Added New Modules --- .DS_Store | Bin 6148 -> 8196 bytes mobileservice/.DS_Store | Bin 8196 -> 10244 bytes mobileservice/src/.DS_Store | Bin 6148 -> 6148 bytes mobileservice/src/main/.DS_Store | Bin 6148 -> 6148 bytes .../controller/APIC_D_WasteController.java | 6 +- .../c_d_waste/service/c_d_WasteService.java | 18 +- .../configuration/DataSourceConfig.java | 13 +- .../service/GuidelinesService.java | 202 +++++++- .../erpPostData/erppostdataService.java | 24 +- .../Controller/DomesticWasteController.java | 3 +- .../Service/DomesticWasteService.java | 9 +- .../controller/APIActivityController.java | 34 ++ .../gccactivity/service/Activity.java | 326 ++++++++++++- .../controller/APIController.java | 115 +++++ .../service/RoadWarAPIService.java | 442 ++++++++++++++++++ .../src/main/resources/application.properties | 1 + 16 files changed, 1157 insertions(+), 36 deletions(-) create mode 100644 mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadwarregister/controller/APIController.java create mode 100644 mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadwarregister/service/RoadWarAPIService.java diff --git a/.DS_Store b/.DS_Store index ec53bb522cfc050dd3fc8ec5d418a228b8406281..94309aba678fd472902c03607131a785c4fea9d3 100644 GIT binary patch delta 394 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMA$hk3KH}hr%jz7$c**Q2SHn1>q zPL^kv+pNVR!^oLZoSc)CpP$135}NGBYOE|NB`FgxAe@w#oSj~jUz(TVoS&0ln?+M0si8Q{BlpASU^!~S!QZ^bb3){N^n79a%Nt-vi%338-PIB zAppXdT*s#2AJ_oqaE9dN=cRHgJ9tCnfR5H?aAfde2xiD&C}-$nn8mP+VF$xehFc78 z7=AIbFp4oMF={iKFxoQOGkP$3GDa~bGo~K8}r;|=91tBn&Juy(anM! Z-VZ9~Ruj z8IcJT2+piZo!l=Z%E&o+t&m1|#sZ){3=EthdHH#%$_@cw9)q%jH-rIniZ+8ILoh=O zLm@*0!*qtl4C@&VGMr<0%b8rYUL(CQ62GXt|A8suC&ODi4#uMaU1}2E#LBYYWIi6<@ FGXP9QJ=_2Q diff --git a/mobileservice/.DS_Store b/mobileservice/.DS_Store index bbd68fc71c71f2e4a4ab360fb17af4206954f258..8e2c6fe270dc03c2181cb81394f0f9bde43f75f2 100644 GIT binary patch delta 898 zcmZp1XbF&DU|?W$DortDU{C-uIe-{M3-C-V6q~50D5wJDFar4uIq8PM$@#ej8w;ng zPizp}%+A5WQ4f-3VbEj9Whi6FgQ)pOv-X9jwxh#@(pI5{UNKR*W; zkuV`-N3qO#A%~DbcA1hxi{llBwRu6 k*_im9c{0CBAP3MjAXhR>j^~*=*;YJkvX-P5RV+OV03$X>E&u=k diff --git a/mobileservice/src/.DS_Store b/mobileservice/src/.DS_Store index 173e3b33e1a56573c70d8700eca0eba43dabe3eb..87dbb0da7ea06fc452fc5183d7abc0ef7f24691f 100644 GIT binary patch delta 399 zcmZoMXfc=|#>B!ku~2NHo+2af#(>?7ixZfc7ST9yxt!tp8pleX8 zqfl*b0%Tg4o7UEHa)>JHTL;Bw=j7()cQAkfBO`=n;DypKsuRdyVaR1jWXNR5ODRsy zNy^X90V#$H=A;`2C+FuDfON3TxgZ6X3kK@Q&3AE0%E?ax3Ub76YH{47easQA04$$^ zSH2(vVK}RW0>fk$X6IZMh7yKUhGK>iWUGOuf&g3&*=DW!V{U6B)qu~2NHo+2a5#(>?7j4YFRSnL^hO!i?ZbeE{EHZe8OQP4FutJP7c zHaD@Z+`Rmb$qj7sMx6`{3@i*;42cY742dbl$vH{+`8kZpf;s7i!O8i#1wb(d q2I)%s$qK9zZ127<{65!yvK^}wj2Xu&&7|~Tb2V!v(`I&#zx)9FGA)+? delta 141 zcmZoMXfc@J&&aniU^g=(-((&Z`^mppg(kL^&4 zn@(o$YMxjC}T*>NjD5m&d)7i00E}BS3nXjmz(e6l9ZF51Qg>4l`mbupg%c~ cRf-MDEM%2tV&1U1kF}C%VuSEzc8@~ diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/c_d_waste/controller/APIC_D_WasteController.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/c_d_waste/controller/APIC_D_WasteController.java index 7c85890..0ed44d3 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/c_d_waste/controller/APIC_D_WasteController.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/c_d_waste/controller/APIC_D_WasteController.java @@ -90,9 +90,11 @@ public class APIC_D_WasteController { @GetMapping("/getMyticketllist") public List getMyticketllist( - @RequestParam(value = "loginId", required = true) String loginId + @RequestParam(value = "loginId", required = true) String loginId, + @RequestParam(value = "fromDate", required = false) String fromDATE, + @RequestParam(value = "toDate", required = false) String toDATE ) { - return c_d_WasteService.getMyticketllist(loginId); + return c_d_WasteService.getMyticketllist(loginId,fromDATE,toDATE); } @GetMapping("/getApprovalPendingList") diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/c_d_waste/service/c_d_WasteService.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/c_d_waste/service/c_d_WasteService.java index e0ded9b..f488aa4 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/c_d_waste/service/c_d_WasteService.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/c_d_waste/service/c_d_WasteService.java @@ -678,7 +678,20 @@ public class c_d_WasteService { return Collections.singletonList(response); } - public List> getMyticketllist(String loginId) { + public List> getMyticketllist(String loginId, String fromDATE, String toDATE) { + + // Define the input and output date formats + DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + // Parse the input dates to LocalDate + LocalDate fromDate = LocalDate.parse(fromDATE, inputFormatter); + LocalDate toDate = LocalDate.parse(toDATE, inputFormatter); + + // Format the LocalDate to the required format + String formattedFromDate = fromDate.format(outputFormatter); + String formattedToDate = toDate.format(outputFormatter); + String sql = "SELECT " + " `wlid` AS comp_id, " + " `zone` AS comp_zone, " @@ -707,10 +720,11 @@ public class c_d_WasteService { + "WHERE " + " `waste_location_mapping`.isactive = 1 " + " AND `cby`=? " + + " AND DATE(`waste_location_mapping`.cdate) BETWEEN ? AND ? " + "ORDER BY `cdate` DESC " + "LIMIT 50"; - return jdbcWasteTemplate.queryForList(sql, loginId); + return jdbcWasteTemplate.queryForList(sql, loginId, formattedFromDate, formattedToDate); } public String getWardByLoginId(String loginid, String type) { diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java index 91b16bc..45618e6 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java @@ -358,7 +358,7 @@ public class DataSourceConfig { return dataSource; } - //////////////////////////////(For Construction Guidelines) //////////////////////// + //////////////////////////////(For SpeedBrake ) //////////////////////// @Bean(name = "mysqlGccSpeedBrakeSource") public DataSource mysqlGccSpeedBrakeSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); @@ -380,6 +380,17 @@ public class DataSourceConfig { return dataSource; } + /////////////////////////////(For Construction Guidelines) //////////////////////// + @Bean(name = "mysqlGccRoadWarSource") + public DataSource mysqlGccRoadWarSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://"+host+"/gcc_roadwar"); + dataSource.setUsername("root"); + dataSource.setPassword(dbpassword); + return dataSource; + } + ////////////////////////////// ORACLE //////////////////////// @Bean(name = "oracleERPDataSource") public DataSource oracleERPDataSource() { diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/constructionGuidelines/service/GuidelinesService.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/constructionGuidelines/service/GuidelinesService.java index 87841d2..1e86f61 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/constructionGuidelines/service/GuidelinesService.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/constructionGuidelines/service/GuidelinesService.java @@ -4,6 +4,8 @@ import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -152,6 +154,147 @@ public class GuidelinesService { } } + public String sendMessage(String tempid, String cdid) { + + String sendTo=""; + String datetxt=""; + String name=""; + String Nos=""; + String fineAmount=""; + + String sql = "SELECT `id`, `name`, `mobile`, `userid`, `tempids` FROM `send_msg_to` WHERE `isactive` = 1 AND `isdelete` = 0 AND FIND_IN_SET(?, tempids);"; + List> mobileResult = jdbcGuidlines.queryForList(sql,tempid); + // Create a StringBuilder to hold the comma-separated mobile numbers + StringBuilder sendToBuilder = new StringBuilder(); + + // Iterate through the mobileResult list and build the sendTo string + for (Map mobileRow : mobileResult) { + String mobile = String.valueOf(mobileRow.get("mobile")); + + // Append the mobile number to the StringBuilder + if (sendToBuilder.length() > 0) { + sendToBuilder.append(","); + } + sendToBuilder.append(mobile); + } + + // Convert StringBuilder to String + sendTo = sendToBuilder.toString(); + + // Now you have the sendTo string with all mobile numbers + System.out.println("Mobile Numbers: " + sendTo); // For debugging, you can print this value + + String urlString=""; + + String username="2000233507"; + String password="h2YjFNcJ"; + + switch (tempid) { + case "1": + System.out.println("TempID is 1 (Initial Notice)"); + urlString="https://media.smsgupshup.com/GatewayAPI/rest?" + + "userid="+username + + "&password="+password + + "&send_to="+sendTo + + "&v=1.1" + + "&format=json" + + "&msg_type=TEXT" + + "&method=SENDMEDIAMESSAGE" + + "&msg=Your+Construction+%28"+name+"%29+falls+under+the+category+of+High+Significance+violations+as+per+GCC+Norms.+As+per+Clauses+%28"+Nos+"%29+of+the+Clean+and+Safe+Construction+guidelines.+%0A%0AYou+are+hereby+directed+to+rectify+the+violations+within+15+days+from+the+date+of+the+notice+issued.+%0A%0ASubmit+photographic%2Fvideo+evidence+and+compliance+report+to+this+office+upon+the+rectification+within+15+days." + + "&isTemplate=true" + + "&header=GCC+Clean+%26+Safe+Construction" + + "&footer=GCC+-+IT+Cell"; + break; + case "2": + System.out.println("TempID is 2 (Compliance resolved)"); + urlString="https://media.smsgupshup.com/GatewayAPI/rest?" + + "userid="+username + + "&password="+password + + "&send_to="+sendTo + + "&v=1.1" + + "&format=json" + + "&msg_type=TEXT" + + "&method=SENDMEDIAMESSAGE" + + "&msg=On+%28"+datetxt+"%29+the+Greater+Chennai+Corporation+instructed+you+to+rectify+the+violations+on+your+Construction+%28"+name+"%29+within+15+days.+Accordingly+it+has+been+found+that+the+violations+on+your+Construction+site+have+been+rectified." + + "&isTemplate=true" + + "&header=GCC+Clean+%26+Safe+Construction" + + "&footer=GCC+-+IT+Cell"; + break; + + case "3": + System.out.println("TempID is 3 (Penalty)"); + urlString="https://media.smsgupshup.com/GatewayAPI/rest?" + + "userid="+username + + "&password="+password + + "&send_to="+sendTo + + "&v=1.1" + + "&format=json" + + "&msg_type=TEXT" + + "&method=SENDMEDIAMESSAGE" + + "&msg=On+%28%2A"+datetxt+"%2A%29+the+Greater+Chennai+Corporation+has+issued+a+notice+and+instructed+you+to+rectify+the+violations+on+your+Construction+%28"+name+"%29+within+15+days.+Accordingly+it+has+been+found+that+the+violations+on+your+Construction+site+have+not+been+rectified+yet.+Hence+the+penalty+of+%2ARs."+fineAmount+"%2A+has+been+issued+to+your+Construction+site.+%0A%0AFailing+to+rectify+the+violations+within+7+Days+of+imposing+of+fine%2C+may+result+in+%E2%80%9C%2Astop+work+notice%2A%E2%80%9D+and+construction+activity+at+your+site+will+be+halted." + + "&isTemplate=true" + + "&header=GCC+Clean+%26+Safe+Construction" + + "&footer=GCC+-+IT+Cell"; + break; + case "4": + System.out.println("TempID is 4 (Compliance resolved Message After Penalty)"); + urlString="https://media.smsgupshup.com/GatewayAPI/rest?" + + "userid="+username + + "&password="+password + + "&send_to="+sendTo + + "&v=1.1" + + "&format=json" + + "&msg_type=TEXT" + + "&method=SENDMEDIAMESSAGE" + + "&msg=On+%28"+datetxt+"%29+the+Greater+Chennai+Corporation+as+issued+Fine+of+Rs."+fineAmount+"+and+instructed+you+to+rectify+the+violations+on+your+%28"+name+"%29+Construction+site+within+7+days.+Accordingly+it+has+been+found+that+the+violations+on+your+Construction+site+have+been+rectified." + + "&isTemplate=true" + + "&header=GCC+Clean+%26+Safe+Construction" + + "&footer=GCC+-+IT+Cell"; + break; + case "5": + System.out.println("TempID is 5 (Stop Work Notice)"); + urlString="https://media.smsgupshup.com/GatewayAPI/rest?" + + "userid="+username + + "&password="+password + + "&send_to="+sendTo + + "&v=1.1" + + "&format=json" + + "&msg_type=TEXT" + + "&method=SENDMEDIAMESSAGE" + + "&msg=On+%28"+datetxt+"%29+the+Greater+Chennai+Corporation+has+issued+Rs."+fineAmount+"+penalty+to+your+Construction+Site+for+not+rectifying+the+violations+and+instructed+to+rectify+the+violations+within+7+days%2C+on+your+%28"+name+"%29+Construction+site.+%0AAccordingly+it+has+been+found+that+the+violations+on+your+%2AConstruction+site+have+not+been+rectified+yet%2A.+%0AHence+it+results+in+%E2%80%9C%2Astop+work+notice%2A%E2%80%9D+and+%2Aconstruction+activity+at+your+site+is+halted%2A." + + "&isTemplate=true" + + "&header=GCC+Clean+%26+Safe+Construction" + + "&footer=GCC+-+IT+Cell"; + break; + default: + System.out.println("TempID ("+tempid+") is unknown"); + } + + if (!urlString.isBlank()) { + String response = sendWhatsAppMessage(urlString); + System.out.println("WhatsApp response: " + response); + } + + return "success"; + } + + private String sendWhatsAppMessage(String urlString) { + String response = ""; + try { + URL url = new URL(urlString); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + + int responseCode = connection.getResponseCode(); + response = String.valueOf(responseCode); + System.out.println("Response Code for URL: " + urlString + " is " + responseCode); + + } catch (Exception e) { + e.printStackTrace(); + } + return response; + } + public List> getConstructionList(String loginid, String latitude, String longitude) { @@ -160,8 +303,8 @@ public class GuidelinesService { + "ci.`ciid`, ci.`under_guidelines`, ci.`penalty` " + " FROM `construction_details` cd " + "LEFT JOIN `construction_inspection` ci ON ci.cdid=cd.cdid " - + "WHERE cd.`isactive`=1 AND ci.`isactive`=1"; - List> result = jdbcGuidlines.queryForList(sql); + + "WHERE cd.`isactive`=1 AND ci.`isactive`=1 AND ci.`cby` = ?"; + List> result = jdbcGuidlines.queryForList(sql,loginid); for (Map row : result) { String downloadLink =""; @@ -291,7 +434,28 @@ public class GuidelinesService { result.add(response); return result; } - + + private double getBuildupArea(String cdid) { + String sql = "SELECT buildup_area FROM construction_details WHERE cdid = ?"; + + List> result = jdbcGuidlines.queryForList(sql, cdid); + + if (result.isEmpty()) { + return 0.0; // default if not found + } + + Object value = result.get(0).get("buildup_area"); + if (value == null) { + return 0.0; + } + + try { + return Double.parseDouble(value.toString()); // ✅ always safe + } catch (NumberFormatException e) { + return 0.0; // or throw if you want to enforce valid data + } + } + @Transactional public int saveConstructionInspection(int cdid, String under_guidelines, String cby) { int ciid = 0; @@ -394,7 +558,30 @@ public class GuidelinesService { String penalty= findPenaltyType(q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18); - if(updateConstructionInspection(lastInsertId, ciid, cdid, penalty)) { + int fineAmount = 0; + double buildup_area = 0; + buildup_area = getBuildupArea(cdid); + if (buildup_area > 20000) { + if ("High".equalsIgnoreCase(penalty)) { + fineAmount = 500000; + } else { + fineAmount = 100000; + } + } else if (buildup_area > 500) { + if ("High".equalsIgnoreCase(penalty)) { + fineAmount = 25000; + } else { + fineAmount = 10000; + } + } else if (buildup_area >= 300 && buildup_area <= 500) { + if ("High".equalsIgnoreCase(penalty)) { + fineAmount = 10000; + } else { + fineAmount = 1000; + } + } + + if(updateConstructionInspection(lastInsertId, ciid, cdid, penalty, String.valueOf(fineAmount))) { response.put("status", "success"); response.put("message", "Feedback inserted successfully."); } @@ -412,10 +599,10 @@ public class GuidelinesService { } @Transactional - public boolean updateConstructionInspection(int giid, String ciid, String cdid, String penalty) { - String updateCISql = "UPDATE `construction_inspection` SET `penalty` = ? WHERE ciid = ? AND cdid = ?"; + public boolean updateConstructionInspection(int giid, String ciid, String cdid, String penalty, String fineAmount) { + String updateCISql = "UPDATE `construction_inspection` SET `penalty` = ?, `fine_amount` = ? WHERE ciid = ? AND cdid = ?"; - int affectedRows = jdbcGuidlines.update(updateCISql, penalty, ciid, cdid); + int affectedRows = jdbcGuidlines.update(updateCISql, penalty, fineAmount, ciid, cdid); if (affectedRows > 0) { return true; @@ -446,6 +633,7 @@ public class GuidelinesService { // Default to Low Penalty return "Low"; } + /* public List> getRevisitConstructionList(String loginid, String latitude, String longitude) { String sql = "SELECT cd.*, " diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/erpPostData/erppostdataService.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/erpPostData/erppostdataService.java index 97ad988..c074759 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/erpPostData/erppostdataService.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/erpPostData/erppostdataService.java @@ -36,12 +36,12 @@ public class erppostdataService { //@Scheduled(cron = "0 0 * * * *") // every hour at 0th minute public void postDataToERP() { // Call the logic you currently expose through controller - System.out.println("Posting data to ERP at " + java.time.LocalDateTime.now()); - postPOSToERP(); // FOR PENALTY POS (gcc_penalty_pos) + // System.out.println("Posting data to ERP at " + java.time.LocalDateTime.now()); + postPOStoERP(); // FOR PENALTY POS (gcc_penalty_pos) } - private String postPOSToERP() { - System.out.println("ERP txn: Started"); + private String postPOStoERP() { + // System.out.println("ERP txn: Started"); String sql = "SELECT " + " bt.id, " + " bt.txnDate, " @@ -71,15 +71,15 @@ public class erppostdataService { + "ORDER BY `bt`.`id` ASC"; try { - System.out.println("Running ERP sync..."); - System.out.println("Using SQL:\n" + sql); - System.out.println("Connecting to: " + jdbcTemplate.getDataSource().getConnection().getMetaData().getURL()); + // System.out.println("Running ERP sync..."); + // System.out.println("Using SQL:\n" + sql); + // System.out.println("Connecting to: " + jdbcTemplate.getDataSource().getConnection().getMetaData().getURL()); List> result = jdbcTemplate.queryForList(sql); - System.out.println("ERP txt Total records: : "+result.size()); + // System.out.println("ERP txt Total records: : "+result.size()); for (Map row : result) { String ID = String.valueOf(row.get("id")); - System.out.println("ERP TXT DATA : "+ID); + //System.out.println("ERP TXT DATA : "+ID); String ASSESSMENTNO = row.get("TRANSACTIONYEAR")+"/Fine/"+row.get("id"); String UNIQUERECEIPTID = String.valueOf(row.get("UNIQUERECEIPTID")); String TRANSACTIONNO = String.valueOf(row.get("TRANSACTIONNO")); @@ -116,7 +116,7 @@ public class erppostdataService { } // Optionally log response - System.out.println("ERP Response for txn: " + TRANSACTIONNO + " → " + response); + // System.out.println("ERP Response for txn: " + TRANSACTIONNO + " → " + response); } return "success"; @@ -141,7 +141,7 @@ public class erppostdataService { String PARTYNAME, String PARTYADDRESS, String PARTYMOBILE) { - System.out.println("ERP txn request: ERP"); + // System.out.println("ERP txn request: ERP"); String erpURL = "http://coc-staging.egovernments.org:9980/pgr/external/mobileservice?serviceId=getOtherCollection" + "&COLLECTION_TYPE=Fine Collection" + "&ASSESSMENTNO=" + ASSESSMENTNO @@ -158,7 +158,7 @@ public class erppostdataService { + "&PARTYMOBILE=" + PARTYMOBILE; RestTemplate restTemplate = new RestTemplate(); - System.out.println("ERP URL:" + erpURL); + //System.out.println("ERP URL:" + erpURL); try { ResponseEntity response = restTemplate.exchange(erpURL, HttpMethod.GET, null, String.class); diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Controller/DomesticWasteController.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Controller/DomesticWasteController.java index b932d83..4715cb0 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Controller/DomesticWasteController.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Controller/DomesticWasteController.java @@ -29,6 +29,7 @@ public class DomesticWasteController { @RequestParam String street_name, @RequestParam String street_id, @RequestParam String remarks, + @RequestParam(value="sofa_type", required = false) String sofa_type, @RequestParam("items") String itemsJson, @RequestParam (name = "image") MultipartFile imageFile) { @@ -37,7 +38,7 @@ public class DomesticWasteController { user_name, mobile, address, latitude, longitude, zone, division, street_name, street_id, remarks, - imageFile, itemsJson + imageFile, itemsJson,sofa_type ); return ResponseEntity.ok(result); diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Service/DomesticWasteService.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Service/DomesticWasteService.java index 982cbd3..cc5a7de 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Service/DomesticWasteService.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Service/DomesticWasteService.java @@ -96,7 +96,7 @@ public class DomesticWasteService { public Map saveMultipleWasteRequests(String user_name, String mobile, String address, String latitude, String longitude, String zone, String division, String street_name, String street_id, String remarks, - MultipartFile imageFile, String itemsJson) { + MultipartFile imageFile, String itemsJson, String sofa_type) { String imagePath = fileUpload(imageFile, "domestic_waste_photo"); if (imagePath == null) { @@ -106,8 +106,8 @@ public class DomesticWasteService { try { // Step 1: Insert main request (one time) String insertMainSql = "INSERT INTO user_request_table " + - "(request_id, user_name, mobile, address, latitude, longitude, zone, division, street_name, street_id, remarks, image_url) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + "(request_id, user_name, mobile, address, latitude, longitude, zone, division, street_name, street_id, remarks, image_url, sofa_type) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcDomesticWasteTemplate.update(con -> { @@ -124,6 +124,7 @@ public class DomesticWasteService { ps.setString(10, street_id); ps.setString(11, remarks); ps.setString(12, imagePath); + ps.setString(13, sofa_type); return ps; }, keyHolder); @@ -489,7 +490,7 @@ public class DomesticWasteService { // Step 3: Update user_request_table - status, officer_upload_url, and close_date from officer_data String updateSql = "UPDATE user_request_table u " + "JOIN officer_data o ON o.request_id = u.request_id " + - "SET u.status = '1', " + + "SET u.status = '2', " + " u.officer_upload_url = ?, " + " u.close_date = DATE(o.cdate) " + "WHERE u.id = ?"; diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java index fd7f23f..8a1fe0a 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java @@ -103,6 +103,40 @@ public class APIActivityController { return activity.filterReports(assetTypeId, fromDate, toDate, zone, ward, streetid,loginId); } + @GetMapping(value = "/asset/scpfilterReports") + public Map scpfilterReports( + @RequestParam(value = "assetTypeId", required = false) String assetTypeId, + @RequestParam(value = "fromDate", required = false) String fromDate, + @RequestParam(value = "toDate", required = false) String toDate, + @RequestParam(value = "zone", required = false) String zone, + @RequestParam(value = "ward", required = false) String ward, + @RequestParam(value = "streetid", required = false) String streetid, + @RequestParam(value = "loginId", required = false) String loginId + ){ + return activity.scpfilterReports(assetTypeId, fromDate, toDate, zone, ward, streetid,loginId); + } + + + @GetMapping(value = "/asset/scpReportAssetList") + public Map scpReportAssetList( + @RequestParam(value = "assetTypeId", required = false) String assetTypeId, + @RequestParam(value = "status", required = false) String status, + @RequestParam(value = "fromDate", required = false) String fromDate, + @RequestParam(value = "toDate", required = false) String toDate, + @RequestParam(value = "streetid", required = false) String streetid, + @RequestParam(value = "loginId", required = false) String loginId + ){ + return activity.scpReportAssetList(assetTypeId, status, fromDate, toDate, streetid,loginId); + } + + @GetMapping(value = "/asset/scpDeactivate") + public String scpDeactivate( + @RequestParam(value = "assetid", required = true) String id, + @RequestParam(value = "loginId", required = true) String loginId + ){ + return activity.scpDeactivate(id,loginId); + } + @GetMapping(value = "/asset/filterReportsByDate") public List> filterReportsByDate( @RequestParam(value = "assetTypeId", required = false) String assetTypeId, diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/Activity.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/Activity.java index ca904e7..cf570d5 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/Activity.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/Activity.java @@ -945,16 +945,17 @@ public class Activity { /* if(assetType != null && !assetType.isEmpty() && !assetType.isBlank() && "2".equals(assetType)) { - sqlQuery.append(" AND ((DATE(al.cdate) > '2024-08-01' AND DATE(al.cdate) <= '2025-06-12' AND al.zone IN (1,2,3,4,5,6,7)) OR\n" - + " (DATE(al.cdate) > '2025-05-01' AND DATE(al.cdate) <= '2025-06-12' AND al.zone = 8) OR\n" - + " (DATE(al.cdate) > '2025-05-20' AND DATE(al.cdate) <= '2025-06-12' AND al.zone = 9) OR\n" - + " (DATE(al.cdate) > '2024-09-06' AND DATE(al.cdate) <= '2025-06-12' AND al.zone IN (10)) OR\n" - + " (DATE(al.cdate) > '2024-10-01' AND DATE(al.cdate) <= '2025-06-12' AND al.zone IN (11)) OR\n" - + " (DATE(al.cdate) > '2024-09-01' AND DATE(al.cdate) <= '2025-06-12' AND al.zone IN (12)) OR\n" - + " (DATE(al.cdate) > '2024-05-03' AND DATE(al.cdate) <= '2025-06-12' AND al.zone IN (13,14,15))\n" + sqlQuery.append(" AND ((DATE(al.cdate) > '2024-08-01' AND DATE(al.cdate) <= '2025-06-12' AND al.zone IN (1,2,3,4,5,6,7)) OR" + + " (DATE(al.cdate) > '2025-05-01' AND DATE(al.cdate) <= '2025-06-12' AND al.zone = 8) OR" + + " (DATE(al.cdate) > '2025-05-20' AND DATE(al.cdate) <= '2025-06-12' AND al.zone = 9) OR" + + " (DATE(al.cdate) > '2024-09-06' AND DATE(al.cdate) <= '2025-06-12' AND al.zone IN (10)) OR" + + " (DATE(al.cdate) > '2024-10-01' AND DATE(al.cdate) <= '2025-06-12' AND al.zone IN (11)) OR" + + " (DATE(al.cdate) > '2024-09-01' AND DATE(al.cdate) <= '2025-06-12' AND al.zone IN (12)) OR" + + " (DATE(al.cdate) > '2024-05-03' AND DATE(al.cdate) <= '2025-06-12' AND al.zone IN (13,14,15))" + " )"); } */ + // Group by zone sqlQuery.append(" GROUP BY "+groupQuery); @@ -1431,5 +1432,316 @@ public class Activity { return ""; } + // ONlY for SCP + /* + @Transactional + public Map scpfilterReports( + String assetType, + String fromDate, + String toDate, + String zone, + String ward, + String streetid, + String loginId + ) { + + System.out.println("SCP REPORT SQL:IN"); + + String groupQuery="al.zone"; + + + // Add additional filters if provided + if (zone != null && !zone.isEmpty() && !zone.isBlank()) { + groupQuery="al.ward"; + } + if (ward != null && !ward.isEmpty() && !ward.isBlank()) { + groupQuery="al.streetid"; + } + + String groupQueryClass=groupQuery; + + String queryCon=""; + if (assetType != null && !assetType.isEmpty() && !assetType.isBlank()) { + queryCon="al.category_id = '"+assetType+"'"; + } + if (zone != null && !zone.isEmpty() && !zone.isBlank()) { + queryCon+="AND al.zone = '"+zone+"'"; + } + if (ward != null && !ward.isEmpty() && !ward.isBlank()) { + queryCon+="AND al.ward = '"+ward+"'"; + groupQueryClass="al.streetname"; + } + if (streetid != null && !streetid.isEmpty() && !streetid.isBlank()) { + queryCon+="AND al.streetid = '"+streetid+"'"; + } + + queryCon+="AND al.isactive = 1 AND al.isdelete = 0"; + + fromDate = convertDateFormat(fromDate,0); + toDate = convertDateFormat(toDate,0); + + + StringBuilder sqlQuery = new StringBuilder("SELECT " + + " CASE WHEN GROUPING("+groupQuery+") = 1 THEN 'TOTAL' ELSE "+groupQueryClass+" END AS CLASS," + + " CASE WHEN GROUPING("+groupQuery+") = 1 THEN 'TOTAL' ELSE "+groupQuery+" END AS VARIABLE," + //+ " COALESCE("+groupQueryClass+", 'TOTAL') AS CLASS," + //+ " COALESCE("+groupQuery+", 'TOTAL') AS VARIABLE," + + " COUNT(al.id) AS Total," + + " SUM(" + + " CASE" + + " WHEN EXISTS (" + + " SELECT 1" + + " FROM activity_feedback ab" + + " WHERE ab.asset_id = al.id" + //+ " AND ab.feedback_date BETWEEN '"+fromDate+"' AND '"+toDate+"'" + + " AND ab.feedback_date >= '" + fromDate + "'" + + " AND ab.feedback_date < DATE_ADD('" + toDate + "', INTERVAL 1 DAY)" + + " )" + + " THEN 1 ELSE 0" + + " END" + + " ) AS Cleaned," + + " SUM(" + + " CASE " + + " WHEN NOT EXISTS (" + + " SELECT 1" + + " FROM activity_feedback ab" + + " WHERE ab.asset_id = al.id" + //+ " AND ab.feedback_date BETWEEN '"+fromDate+"' AND '"+toDate+"'" + + " AND ab.feedback_date >= '" + fromDate + "'" + + " AND ab.feedback_date < DATE_ADD('" + toDate + "', INTERVAL 1 DAY)" + + " )" + + " THEN 1 ELSE 0" + + " END" + + " ) AS Pending" + + " FROM asset_list al" + + " WHERE "+queryCon+" " + + " GROUP BY "+groupQuery+" WITH ROLLUP"); + + System.out.println("SCP REPORT SQL:" + sqlQuery.toString()); + + List> result = jdbcActivityTemplate.queryForList(sqlQuery.toString()); + + // --- Final result --- + Map finalResult = new HashMap<>(); + finalResult.put("scpreport", result); + return finalResult; + } + */ + @Transactional + public Map scpfilterReports( + String assetType, + String fromDate, + String toDate, + String zone, + String ward, + String streetid, + String loginId + ) { + + System.out.println("SCP REPORT SQL:IN"); + + String groupQuery="al.zone"; + String having =""; + + // Add additional filters if provided + if (zone != null && !zone.isEmpty() && !zone.isBlank()) { + groupQuery="al.ward"; + } + if (ward != null && !ward.isEmpty() && !ward.isBlank()) { + groupQuery="al.streetid"; + } + + String groupQueryClass=groupQuery; + String FgroupQuery = groupQuery; + String queryCon=""; + if (assetType != null && !assetType.isEmpty() && !assetType.isBlank()) { + queryCon="al.category_id = '"+assetType+"'"; + } + if (zone != null && !zone.isEmpty() && !zone.isBlank()) { + queryCon+="AND al.zone = '"+zone+"'"; + } + if (ward != null && !ward.isEmpty() && !ward.isBlank()) { + queryCon+="AND al.ward = '"+ward+"'"; + FgroupQuery += ",al.streetname"; + groupQueryClass="al.streetname"; + having =" HAVING NOT (GROUPING(al.streetid) = 0 AND GROUPING(al.streetname) = 1)"; + } + if (streetid != null && !streetid.isEmpty() && !streetid.isBlank()) { + queryCon+="AND al.streetid = '"+streetid+"'"; + } + + queryCon+="AND al.isactive = 1 AND al.isdelete = 0"; + + fromDate = convertDateFormat(fromDate,0); + toDate = convertDateFormat(toDate,0); + + + StringBuilder sqlQuery = new StringBuilder("SELECT " + + " CASE WHEN GROUPING("+groupQuery+") = 1 THEN 'TOTAL' ELSE "+groupQueryClass+" END AS CLASS," + + " CASE WHEN GROUPING("+groupQuery+") = 1 THEN 'TOTAL' ELSE "+groupQuery+" END AS VARIABLE," + //+ " COALESCE("+groupQueryClass+", 'TOTAL') AS CLASS," + //+ " COALESCE("+groupQuery+", 'TOTAL') AS VARIABLE," + + " COUNT(al.id) AS Total," + + " COALESCE(SUM(CASE WHEN fc.asset_id IS NOT NULL THEN 1 ELSE 0 END), 0) AS Cleaned," + + " COALESCE(SUM(CASE WHEN fc.asset_id IS NULL THEN 1 ELSE 0 END), 0) AS Pending," + + " COALESCE(COUNT(DISTINCT CASE WHEN fc.category = 'Compressor' THEN al.id END), 0) AS Compressor, " + + " COALESCE(COUNT(DISTINCT CASE WHEN fc.category = 'Manual' THEN al.id END), 0) AS Manual, " + + " COALESCE(COUNT(DISTINCT CASE WHEN fc.category = 'Recycle' THEN al.id END), 0) AS Recycle " + + " FROM asset_list al " + + "LEFT JOIN (" + + " SELECT " + + " af.asset_id," + + " CASE " + + " WHEN SUM(CASE WHEN TRIM(LOWER(afd.feedback)) = 'compressor' THEN 1 ELSE 0 END) > 0 " + + " THEN 'Compressor'" + + " WHEN SUM(CASE WHEN TRIM(LOWER(afd.feedback)) IN ('recycle','yes') THEN 1 ELSE 0 END) > 0" + + " THEN 'Recycle'" + + " WHEN SUM(CASE WHEN TRIM(LOWER(afd.feedback)) IN ('manually','no') THEN 1 ELSE 0 END) > 0" + + " THEN 'Manual'" + + " ELSE 'Manual'" + + " END AS category" + + " FROM activity_feedback af" + + " LEFT JOIN activity_feedback_data afd " + + " ON afd.feedback_id = af.id AND afd.qid = 220" + + + " WHERE af.feedback_date >= '" + fromDate + "'" + + " AND af.feedback_date < DATE_ADD('" + toDate + "', INTERVAL 1 DAY)" + + " AND af.isactive = 1" + + " AND af.isdelete = 0" + + " GROUP BY af.asset_id" + + ") fc ON fc.asset_id = al.id" + + + " WHERE "+queryCon+" " + + " GROUP BY "+FgroupQuery+" WITH ROLLUP" + + having + + ""); + + System.out.println("SCP REPORT SQL:" + sqlQuery.toString()); + + List> result = jdbcActivityTemplate.queryForList(sqlQuery.toString()); + + // --- Final result --- + Map finalResult = new HashMap<>(); + finalResult.put("scpreport", result); + return finalResult; + } + + @Transactional + public Map scpReportAssetList( + String assetType, + String status, + String fromDate, + String toDate, + String streetid, + String loginId + ) { + assetType = "2"; + + fromDate = convertDateFormat(fromDate, 0); + toDate = convertDateFormat(toDate, 0); + + String serviceFolderName = environment.getProperty("activity_foldername"); + String filePath = serviceFolderName + assetType + "/"; + /* + StringBuilder sqlQuery = new StringBuilder( + "SELECT " + + " al.id, " + + " al.zone, " + + " al.ward, " + + " al.streetid, " + + " al.streetname, " + + " al.latitude, " + + " al.longitude, " + + " DATE_FORMAT(MAX(af.feedback_date), '%d-%m-%Y %H:%i') AS last_feedback_date, " + + " CASE WHEN MAX(af.feedback_date) IS NOT NULL THEN 'Cleaned' ELSE 'Pending' END AS Status, " + + " GROUP_CONCAT(DISTINCT CASE WHEN aff.fileaction = 'before' THEN CONCAT('" + fileBaseUrl + "/gccofficialapp/files/', '" + filePath + "', aff.filename) END SEPARATOR ',') AS before_filepath, " + + " GROUP_CONCAT(DISTINCT CASE WHEN aff.fileaction = 'after' THEN CONCAT('" + fileBaseUrl + "/gccofficialapp/files/', '" + filePath + "', aff.filename) END SEPARATOR ',') AS after_filepath " + + "FROM asset_list al " + + "LEFT JOIN activity_feedback af ON af.asset_id = al.id " + + " AND af.feedback_date >= ? " + + " AND af.feedback_date < DATE_ADD(?, INTERVAL 1 DAY) " + + "LEFT JOIN activity_feedback_file aff ON aff.feedback_id = af.id " + + "WHERE al.category_id = 2 " + + " AND al.streetid = ? " + + " AND al.isactive = 1 " + + " AND al.isdelete = 0 " + + "GROUP BY al.id, al.zone, al.ward, al.streetid, al.streetname, al.latitude, al.longitude " + ); + */ + StringBuilder sqlQuery = new StringBuilder( + "SELECT " + + " al.id, " + + " al.zone, " + + " al.ward, " + + " al.streetid, " + + " al.streetname, " + + " al.latitude, " + + " al.longitude, " + + " DATE_FORMAT(MAX(af.feedback_date), '%d-%m-%Y %H:%i') AS last_feedback_date, " + + " CASE " + + " WHEN " + + " SUM(CASE WHEN aff.fileaction = 'before' THEN 1 ELSE 0 END) > 0 " + + " AND SUM(CASE WHEN aff.fileaction = 'after' THEN 1 ELSE 0 END) > 0 " + + " THEN 'Cleaned' " + + " ELSE 'Pending' " + + " END AS Status, " + + " GROUP_CONCAT(DISTINCT CASE WHEN aff.fileaction = 'before' THEN CONCAT('" + fileBaseUrl + "/gccofficialapp/files/', '" + filePath + "', aff.filename) END SEPARATOR ',') AS before_filepath, " + + " GROUP_CONCAT(DISTINCT CASE WHEN aff.fileaction = 'after' THEN CONCAT('" + fileBaseUrl + "/gccofficialapp/files/', '" + filePath + "', aff.filename) END SEPARATOR ',') AS after_filepath " + + + "FROM asset_list al " + + "LEFT JOIN activity_feedback af " + + " ON af.asset_id = al.id " + + " AND af.feedback_date >= ? " + + " AND af.feedback_date < DATE_ADD(?, INTERVAL 1 DAY) " + + "LEFT JOIN activity_feedback_file aff " + + " ON aff.feedback_id = af.id " + + "WHERE al.category_id = 2 " + + " AND al.streetid = ? " + + " AND al.isactive = 1 " + + " AND al.isdelete = 0 " + + "GROUP BY al.id, al.zone, al.ward, al.streetid, al.streetname, al.latitude, al.longitude " + ); + + if (status != null && !status.isBlank()) { + sqlQuery.append("HAVING Status = ? "); + } + + List params = new ArrayList<>(); + params.add(fromDate); + params.add(toDate); + params.add(streetid); + if (status != null && !status.isBlank()) { + params.add(status); + } + + String finalSql = sqlQuery.toString(); + for (Object param : params) { + finalSql = finalSql.replaceFirst("\\?", "'" + String.valueOf(param) + "'"); + } + System.out.println("Final SQL: " + finalSql); + + List> result = jdbcActivityTemplate.queryForList(sqlQuery.toString(), params.toArray()); + + Map finalResult = new HashMap<>(); + finalResult.put("scpreport", result); + return finalResult; + } + public String scpDeactivate(String assetId, String userId) { + try { + // 1. Log the deactivation + String sqllog = "INSERT INTO asset_deactive_log(asset_id, deactive_by) VALUES (?, ?)"; + jdbcActivityTemplate.update(sqllog, assetId, userId); + + // 2. Update the asset to deactivate + String sqlUpdate = "UPDATE asset_list SET isactive = 0, isdelete = 1 WHERE id = ?"; + jdbcActivityTemplate.update(sqlUpdate, assetId); + + return "success"; + } catch (Exception e) { + e.printStackTrace(); + return "failure"; + } + } + } diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadwarregister/controller/APIController.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadwarregister/controller/APIController.java new file mode 100644 index 0000000..2068d3e --- /dev/null +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadwarregister/controller/APIController.java @@ -0,0 +1,115 @@ +package in.gov.chennaicorporation.mobileservice.roadwarregister.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import in.gov.chennaicorporation.mobileservice.roadwarregister.service.RoadWarAPIService; + +import java.util.List; +import java.util.Map; + +@RequestMapping("/gccofficialapp/api/roadwar/") +@RestController("gccofficialappsroadwar") +public class APIController { + @Autowired + private RoadWarAPIService apiService; + + + @GetMapping(value="/road-types") + public List getRoadTypes(){ + return apiService.getRoadTypes(); + } + + @GetMapping(value="/lay-types") + public List getRoadLayTypes(){ + return apiService.getRoadLayTypes(); + } + + /** + * Save Start Street details + */ + @PostMapping("/street/start") + public ResponseEntity> saveStartStreet( + @RequestParam String roadName, + @RequestParam String roadZone, + @RequestParam String roadWard, + @RequestParam String roadId, + @RequestParam String roadType, + @RequestParam String manualZone, + @RequestParam String manualWard, + @RequestParam String manualroadType, + @RequestParam String roadLayType, + @RequestParam(required = false) String lastLayOn, + @RequestParam String roadLength, + @RequestParam String carriagewayWidth, + @RequestParam String walltowallWidth, + @RequestParam String footpath, + @RequestParam String median, + @RequestParam String swd, + @RequestParam String inby, + @RequestParam String latitude, + @RequestParam String longitude, + @RequestParam String streetboard, + @RequestParam(required = false) MultipartFile roadImage + ) { + Map result = apiService.saveStreetDetails( + "START", roadName, roadZone, roadWard, roadId, roadType, + manualZone, manualWard, manualroadType, + roadLayType, lastLayOn, roadLength, carriagewayWidth, + walltowallWidth, footpath, median, swd, inby, latitude, + longitude, streetboard, roadImage, null + ); + return ResponseEntity.ok(result); + } + + @GetMapping(value="/street/startlist") + public List getStartRoadList(@RequestParam String inby){ + return apiService.getStartRoadList(inby); + } + + /** + * Save End Street details (linked with Start Street) + */ + @PostMapping("/street/end") + public ResponseEntity> saveEndStreet( + @RequestParam String roadName, + @RequestParam String roadZone, + @RequestParam String roadWard, + @RequestParam String roadId, + @RequestParam String roadType, + @RequestParam String manualZone, + @RequestParam String manualWard, + @RequestParam String manualroadType, + @RequestParam String roadLayType, + @RequestParam(required = false) String lastLayOn, + @RequestParam String roadLength, + @RequestParam String carriagewayWidth, + @RequestParam String walltowallWidth, + @RequestParam String footpath, + @RequestParam String median, + @RequestParam String swd, + @RequestParam String inby, + @RequestParam String latitude, + @RequestParam String longitude, + @RequestParam String streetboard, + @RequestParam(required = false) MultipartFile roadImage, + @RequestParam Integer startId // required for END street + ) { + Map result = apiService.saveStreetDetails( + "END", roadName, roadZone, roadWard, roadId, roadType, + manualZone, manualWard, manualroadType, + roadLayType, lastLayOn, roadLength, carriagewayWidth, + walltowallWidth, footpath, median, swd, inby, latitude, + longitude, streetboard, roadImage, startId + ); + return ResponseEntity.ok(result); + } + + + @GetMapping(value="/getCompletedRoadLists") + public List getCompletedRoadLists(){ + return apiService.getCompletedRoadLists(); + } +} diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadwarregister/service/RoadWarAPIService.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadwarregister/service/RoadWarAPIService.java new file mode 100644 index 0000000..22398fb --- /dev/null +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadwarregister/service/RoadWarAPIService.java @@ -0,0 +1,442 @@ +package in.gov.chennaicorporation.mobileservice.roadwarregister.service; + +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.SecureRandom; +import java.sql.PreparedStatement; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import javax.imageio.ImageIO; +import javax.imageio.ImageWriteParam; +import javax.imageio.ImageWriter; +import javax.imageio.stream.ImageOutputStream; +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.core.env.Environment; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.type.TypeReference; + +import in.gov.chennaicorporation.mobileservice.gccactivity.service.DateTimeUtil; + +@Service +public class RoadWarAPIService { + private JdbcTemplate jdbcRoadWar; + private final Environment environment; + private String fileBaseUrl; + + private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + private static final int STRING_LENGTH = 15; + private static final Random RANDOM = new SecureRandom(); + + @Autowired + public void setDataSource(@Qualifier("mysqlGccRoadWarSource") DataSource RoadWarDataSource) { + this.jdbcRoadWar = new JdbcTemplate(RoadWarDataSource); + } + + @Autowired + public RoadWarAPIService(Environment environment) { + this.environment = environment; + this.fileBaseUrl=environment.getProperty("fileBaseUrl"); + } + + public static String generateRandomString() { + StringBuilder result = new StringBuilder(STRING_LENGTH); + for (int i = 0; i < STRING_LENGTH; i++) { + result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); + } + return result.toString(); + } + + public static String generateRandomFileString(int lenthval) { + StringBuilder result = new StringBuilder(lenthval); + for (int i = 0; i < lenthval; i++) { + result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); + } + return result.toString(); + } + + private byte[] compressImage(BufferedImage image, float quality) throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream); + + ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next(); + writer.setOutput(imageOutputStream); + + ImageWriteParam param = writer.getDefaultWriteParam(); + if (param.canWriteCompressed()) { + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); + param.setCompressionQuality(quality); + } + + writer.write(null, new javax.imageio.IIOImage(image, null, null), param); + + writer.dispose(); + imageOutputStream.close(); + + return byteArrayOutputStream.toByteArray(); + } + + public String fileUpload(String name, String id, MultipartFile file) { + + int lastInsertId = 0; + // Set the file path where you want to save it + String uploadDirectory = environment.getProperty("file.upload.directory"); + String serviceFolderName = environment.getProperty("roadwar_foldername"); + var year = DateTimeUtil.getCurrentYear(); + var month = DateTimeUtil.getCurrentMonth(); + var date = DateTimeUtil.getCurrentDay(); + + uploadDirectory = uploadDirectory + serviceFolderName + year + "/" + month + "/" + date; + + try { + // Create directory if it doesn't exist + Path directoryPath = Paths.get(uploadDirectory); + if (!Files.exists(directoryPath)) { + Files.createDirectories(directoryPath); + } + + // Datetime string + String datetimetxt = DateTimeUtil.getCurrentDateTime(); + + datetimetxt = datetimetxt + "_"+ generateRandomFileString(6); // Attached Random text + + // File name + String fileName = name + "_" + id + "_" + datetimetxt + "_" + file.getOriginalFilename(); + fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename + + String filePath = uploadDirectory + "/" + fileName; + + String filepath_txt = "/" + serviceFolderName + year + "/" + month + "/" + date + "/" + fileName; + + // Create a new Path object + Path path = Paths.get(filePath); + + // Get the bytes of the file + byte[] bytes = file.getBytes(); + + // Compress the image + BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes)); + byte[] compressedBytes = compressImage(image, 0.5f); // Compress with 50% quality + + // Write the bytes to the file + Files.write(path, compressedBytes); + + System.out.println(filePath); + return filepath_txt; + + } catch (IOException e) { + e.printStackTrace(); + return "Failed to save file " + file.getOriginalFilename(); + } + } + + public List> getRoadTypes(){ + String sql = "SELECT `roadtype_id`, `name` FROM `road_type` WHERE `isactive`=1 AND `isdelete`=0 ORDER BY `orderby`"; + List> result = jdbcRoadWar.queryForList(sql); + Map response = new HashMap<>(); + response.put("status", "Success"); + response.put("message", "Road Type List."); + response.put("data", result); + + return Collections.singletonList(response); + } + + public List> getRoadLayTypes(){ + String sql = "SELECT `lay_type_id`, `name` FROM `road_lay_type` WHERE `isactive`=1 AND `isdelete`=0 ORDER BY `orderby`"; + List> result = jdbcRoadWar.queryForList(sql); + Map response = new HashMap<>(); + response.put("status", "Success"); + response.put("message", "Road Lay Type List."); + response.put("data", result); + + return Collections.singletonList(response); + } + + @Transactional + public List> checkAssetExists(String latitudeStr, String longitudeStr) { + double latitude = Double.parseDouble(latitudeStr); + double longitude = Double.parseDouble(longitudeStr); + + String checkSql = "SELECT COUNT(*) FROM road_list list " + + "WHERE (6371008.8 * ACOS(COS(RADIANS(?)) * COS(RADIANS(list.latitude)) * " + + "COS(RADIANS(list.longitude) - RADIANS(?)) + SIN(RADIANS(?)) * SIN(RADIANS(list.latitude)))) < 50"; + + Integer count = jdbcRoadWar.queryForObject( + checkSql, + Integer.class, + latitude, longitude, latitude + ); + + Map response = new HashMap<>(); + if (count != null && count > 0) { + response.put("count", count); + response.put("status", "error"); + response.put("message", "Duplicate: Road already exists."); + } else { + response.put("count", count); + response.put("status", "success"); + response.put("message", "No existing Road found."); + } + return Collections.singletonList(response); + } + + public List> getStartRoadList(String inby){ + /* + String sql = "SELECT *, " + + "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', start_img) AS start_img_url " + + " FROM `start_street_details` WHERE (`isactive`=1 AND `isdelete`=0) AND (`inby`=?) " + + "AND s.strat_id NOT IN ( SELECT e.start_id FROM end_street_details e )"; + */ + String sql ="SELECT " + + " s.*, " + + " CONCAT('" + fileBaseUrl + "/gccofficialapp/files', start_img) AS start_img_url " + + "FROM " + + " `start_street_details` s " + + "WHERE " + + " s.`isactive` = 1" + + " AND s.`isdelete` = 0 AND (`inby`=?)" + + " AND s.`strat_id` NOT IN (" + + " SELECT e.`start_id` " + + " FROM `end_street_details` e" + + " )"; + List> result = jdbcRoadWar.queryForList(sql,inby); + Map response = new HashMap<>(); + response.put("status", "Success"); + response.put("message", "Road Start List."); + response.put("data", result); + + return Collections.singletonList(response); + } + + @Transactional + public Map saveStreetDetails( + String type, // "START" or "END" + String roadName, + String roadZone, + String roadWard, + String roadId, + String roadType, + String manualZone, + String manualWard, + String manualroadType, + String roadLayType, + String lastLayOn, // yyyy-MM-dd or yyyy-MM format + String roadLength, + String carriagewayWidth, + String walltowallWidth, + String footpath, + String median, + String swd, + String inby, + String latitude, + String longitude, + String streetboard, + MultipartFile roadImage, + Integer startId // only for END street (foreign key to start_street_details) + ) { + Map response = new HashMap<>(); + + // ✅ Handle file upload safely + final String uploadedImg = (roadImage != null && !roadImage.isEmpty()) + ? fileUpload("RoadRegister", type.toLowerCase(), roadImage) + : null; + /* + String uploadedImg = null; + if (roadImage != null && !roadImage.isEmpty()) { + uploadedImg = fileUpload("RoadRegister", type.toLowerCase(), roadImage); + } + */ + // ✅ Choose table & generated key column + String sql; + String[] generatedKey = new String[1]; + + if ("START".equalsIgnoreCase(type)) { + sql = "INSERT INTO start_street_details " + + "(road_name, road_zone, road_ward, road_id, road_type, " + + "manual_zone, manual_ward, manual_roadType, road_lay_type, last_lay_on, " + + "road_length, carriageway_width, walltowall_width, footpath, median, " + + "swd, inby, start_latitude, start_longitude, streetboard, start_img) " + + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + generatedKey[0] = "strat_id"; + } else { + sql = "INSERT INTO end_street_details " + + "(road_name, road_zone, road_ward, road_id, road_type, " + + "manual_zone, manual_ward, manual_roadType, road_lay_type, last_lay_on, " + + "road_length, carriageway_width, walltowall_width, footpath, median, " + + "swd, inby, start_latitude, start_longitude, streetboard, start_id, end_img) " + + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + generatedKey[0] = "end_id"; + } + + KeyHolder keyHolder = new GeneratedKeyHolder(); + + int affected = jdbcRoadWar.update(connection -> { + PreparedStatement ps = connection.prepareStatement(sql, generatedKey); + int i = 1; + ps.setString(i++, roadName); + ps.setString(i++, roadZone); + ps.setString(i++, roadWard); + ps.setString(i++, roadId); + ps.setString(i++, roadType); + + // ✅ Manual fields + ps.setString(i++, manualZone); + ps.setString(i++, manualWard); + ps.setString(i++, manualroadType); + ps.setString(i++, roadLayType); + ps.setString(i++, lastLayOn); + + // ✅ Road dimensions + ps.setString(i++, roadLength); + ps.setString(i++, carriagewayWidth); + ps.setString(i++, walltowallWidth); + ps.setString(i++, footpath); + ps.setString(i++, median); + ps.setString(i++, swd); + ps.setString(i++, inby); + + // ✅ Location + Board + ps.setString(i++, latitude); + ps.setString(i++, longitude); + ps.setString(i++, streetboard); + + // ✅ Image & FK handling + if ("START".equalsIgnoreCase(type)) { + ps.setString(i++, uploadedImg); + } else { + ps.setObject(i++, startId); // foreign key + ps.setString(i++, uploadedImg); + } + return ps; + }, keyHolder); + + if (affected > 0) { + response.put("status", "success"); + response.put("insertId", keyHolder.getKey().intValue()); + response.put("message", type + " Street details saved successfully"); + } else { + response.put("status", "error"); + response.put("message", type + " Street details insert failed"); + } + + return response; + } + + public List> getCompletedRoadLists() { + String sql = "SELECT " + + " s.strat_id AS UnicID, " + + " s.road_name AS StreetName, " + + " JSON_OBJECT(" + + " 'strat_id', s.strat_id, " + + " 'road_name', s.road_name, " + + " 'road_zone', s.road_zone, " + + " 'road_ward', s.road_ward, " + + " 'road_id', s.road_id, " + + " 'road_type', s.road_type, " + + " 'manual_zone', s.manual_zone, " + + " 'manual_ward', s.manual_ward, " + + " 'manual_roadType', s.manual_roadType, " + + " 'road_lay_type', s.road_lay_type, " + + " 'last_lay_on', s.last_lay_on, " + + " 'road_length', s.road_length, " + + " 'carriageway_width', s.carriageway_width, " + + " 'walltowall_width', s.walltowall_width, " + + " 'footpath', s.footpath, " + + " 'median', s.median, " + + " 'swd', s.swd, " + + " 'inby', s.inby, " + + " 'indate', s.indate, " + + " 'start_latitude', s.start_latitude, " + + " 'start_longitude', s.start_longitude, " + + " 'isactive', s.isactive, " + + " 'isdelete', s.isdelete, " + + " 'streetboard', s.streetboard, " + + " 'start_img', s.start_img, " + + " 'start_img_url', CONCAT('" + fileBaseUrl + "/gccofficialapp/files', IFNULL(s.start_img, '/nostreetboard.png'))" + + " ) AS `start`, " + + " JSON_OBJECT(" + + " 'end_id', e.end_id, " + + " 'road_name', e.road_name, " + + " 'road_zone', e.road_zone, " + + " 'road_ward', e.road_ward, " + + " 'road_id', e.road_id, " + + " 'road_type', e.road_type, " + + " 'manual_zone', e.manual_zone, " + + " 'manual_ward', e.manual_ward, " + + " 'manual_roadType', e.manual_roadType, " + + " 'road_lay_type', e.road_lay_type, " + + " 'last_lay_on', e.last_lay_on, " + + " 'road_length', e.road_length, " + + " 'carriageway_width', e.carriageway_width, " + + " 'walltowall_width', e.walltowall_width, " + + " 'footpath', e.footpath, " + + " 'median', e.median, " + + " 'swd', e.swd, " + + " 'inby', e.inby, " + + " 'indate', e.indate, " + + " 'start_latitude', e.start_latitude, " + + " 'start_longitude', e.start_longitude, " + + " 'isactive', e.isactive, " + + " 'isdelete', e.isdelete, " + + " 'streetboard', e.streetboard, " + + " 'end_img', e.end_img, " + + " 'end_img_url', CONCAT('" + fileBaseUrl + "/gccofficialapp/files', IFNULL(e.end_img, '/nostreetboard.png'))" + + " ) AS `end` " + + "FROM start_street_details s " + + "INNER JOIN end_street_details e " + + " ON e.start_id = s.strat_id " + + "WHERE s.isactive = 1 " + + " AND s.isdelete = 0 " + + " AND e.isactive = 1 " + + " AND e.isdelete = 0"; + + List> rawResult = jdbcRoadWar.queryForList(sql); + + ObjectMapper mapper = new ObjectMapper(); + List> formattedResult = new ArrayList<>(); + + for (Map row : rawResult) { + Map formattedRow = new HashMap<>(); + formattedRow.put("UnicID", row.get("UnicID")); + formattedRow.put("StreetName", row.get("StreetName")); + + // Convert JSON strings to proper objects + try { + Map startObj = mapper.readValue(row.get("start").toString(), new TypeReference>() {}); + Map endObj = mapper.readValue(row.get("end").toString(), new TypeReference>() {}); + formattedRow.put("start", startObj); + formattedRow.put("end", endObj); + } catch (Exception ex) { + ex.printStackTrace(); + } + + formattedResult.add(formattedRow); + } + + Map response = new HashMap<>(); + response.put("status", "Success"); + response.put("message", "Completed road list."); + response.put("data", formattedResult); + + return Collections.singletonList(response); + } +} diff --git a/mobileservice/src/main/resources/application.properties b/mobileservice/src/main/resources/application.properties index 71e4be7..5bce45c 100644 --- a/mobileservice/src/main/resources/application.properties +++ b/mobileservice/src/main/resources/application.properties @@ -57,3 +57,4 @@ speedbrake_foldername=speedbrake_images/ busshelter_renovation_foldername=bus_shelter_renovation_files/ view_cutter_foldername = view_cutter_files/ buildingdemolition_foldername = building_demolition_files/ +roadwar_foldername = roadwar_register_files/