Web Developer Work - I
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.

104 lines
2.9 KiB

3 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. import React, { useEffect, useState } from 'react';
  2. import FeatureLayer from '@arcgis/core/layers/FeatureLayer';
  3. import { Box, Typography } from '@mui/material';
  4. interface ZoneData {
  5. zone_no: string;
  6. pendingCount: number;
  7. toBeVerifiedCount: number;
  8. }
  9. const ZoneIntimationOnly = () => {
  10. const [zoneData, setZoneData] = useState<ZoneData[]>([]);
  11. useEffect(() => {
  12. fetchData();
  13. }, []);
  14. const normalizeZone = (zone: any) => {
  15. if (zone == null) return '';
  16. const s = String(zone);
  17. const match = s.match(/\d+/);
  18. return match ? match[0].padStart(2, '0') : '';
  19. };
  20. const fetchData = async () => {
  21. const BUILDING_LAYER_URL =
  22. 'https://gisgcc.chennaicorporation.gov.in/server/rest/services/Revenue/Building_Updation/FeatureServer/0';
  23. const buildingLayer = new FeatureLayer({
  24. url: BUILDING_LAYER_URL
  25. });
  26. const query = buildingLayer.createQuery();
  27. query.outFields = ['zone', 'approval'];
  28. query.where = '1=1';
  29. query.returnGeometry = false;
  30. query.num = 2000;
  31. let features: any[] = [];
  32. let offset = 0;
  33. while (true) {
  34. query.start = offset;
  35. const res = await buildingLayer.queryFeatures(query);
  36. features = features.concat(res.features);
  37. if (res.features.length < query.num) break;
  38. offset += query.num;
  39. }
  40. const zonePendingMap: Record<string, number> = {};
  41. const zoneTBVMap: Record<string, number> = {};
  42. features.forEach(f => {
  43. const rawZone = f.attributes?.zone ?? '';
  44. const approval = (f.attributes?.approval ?? '').trim().toLowerCase();
  45. const zone = normalizeZone(rawZone);
  46. if (!zone) return;
  47. if (approval === 'pending') {
  48. zonePendingMap[zone] = (zonePendingMap[zone] || 0) + 1;
  49. }
  50. if (approval === 'to be verified') {
  51. zoneTBVMap[zone] = (zoneTBVMap[zone] || 0) + 1;
  52. }
  53. });
  54. const allZones = new Set([
  55. ...Object.keys(zonePendingMap),
  56. ...Object.keys(zoneTBVMap)
  57. ]);
  58. const result: ZoneData[] = Array.from(allZones).map(zone => ({
  59. zone_no: zone,
  60. pendingCount: zonePendingMap[zone] || 0,
  61. toBeVerifiedCount: zoneTBVMap[zone] || 0
  62. }));
  63. result.sort((a, b) => parseInt(a.zone_no, 10) - parseInt(b.zone_no, 10));
  64. setZoneData(result);
  65. };
  66. return (
  67. <Box p={2} sx={{ maxHeight: 300, overflowY: 'auto' }}>
  68. {zoneData.length === 0 ? (
  69. <Typography variant="body2" sx={{ color: 'white' }}>
  70. No Pending or To Be Verified records found.
  71. </Typography>
  72. ) : (
  73. zoneData.map(z => (
  74. <Typography key={z.zone_no} variant="body2" sx={{ color: 'white', mb: 1 }}>
  75. <strong>Zone {z.zone_no}</strong> — Pending:
  76. <strong> {z.pendingCount} </strong> | To be Verified:
  77. <strong> {z.toBeVerifiedCount} </strong>
  78. </Typography>
  79. ))
  80. )}
  81. </Box>
  82. );
  83. };
  84. export default ZoneIntimationOnly;