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.
507 lines
19 KiB
507 lines
19 KiB
|
|
import FeatureLayer from '@arcgis/core/layers/FeatureLayer'
|
|
import esriRequest from '@arcgis/core/request';
|
|
import { execute } from '@arcgis/core/rest/geoprocessor';
|
|
import { submitJob } from '@arcgis/core/rest/geoprocessor';
|
|
import { notifyResultData } from 'dist/widgets/arcgis/analysis/src/utils/events';
|
|
import { FaHippo } from 'react-icons/fa6';
|
|
|
|
interface GPServiceResponseItem {
|
|
MatchedData?: string;
|
|
misDataNull?: string;
|
|
'Property Count'?: number;
|
|
ConsolidatedValues?: any[];
|
|
NodueData?: string;
|
|
DueData?: string;
|
|
}
|
|
const Property_w_54 = new FeatureLayer({
|
|
url: "https://gisgcc.chennaicorporation.gov.in/server/rest/services/Revenue/Buildings_Revenue_MIS/MapServer/1"
|
|
})
|
|
const building_queryLayer = new FeatureLayer({
|
|
url: "https://gisgcc.chennaicorporation.gov.in/server/rest/services/Revenue/SurveyTables/FeatureServer/0"
|
|
})
|
|
const Property_queryLayer = new FeatureLayer({
|
|
url: "https://gisgcc.chennaicorporation.gov.in/server/rest/services/Revenue/SurveyTables/FeatureServer/4"
|
|
})
|
|
const Floor_queryLayer = new FeatureLayer({
|
|
url: "https://gisgcc.chennaicorporation.gov.in/server/rest/services/Revenue/SurveyTables/FeatureServer/2"
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const fetchGISIDFetch = async (GISIds: any) => {
|
|
try {
|
|
let gisID_input
|
|
if (typeof GISIds == 'string') {
|
|
gisID_input = GISIds
|
|
}
|
|
|
|
else if (GISIds && GISIds.length == 1) {
|
|
gisID_input = GISIds[0]
|
|
}
|
|
else {
|
|
return
|
|
}
|
|
let GISIdInput = gisID_input.replace(/^"|"$/g, "")
|
|
|
|
// const GISIdInput = JSON.stringify(GISIds);
|
|
const newAPIEndPoint = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=common_api&jsonResp=Yes&subService=getPropByGisId&gisId="
|
|
|
|
// const reportInput = JSON.stringify({ inputs: { GIS_ID: GISIds } });
|
|
|
|
// const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
|
|
// const channelID = 3;
|
|
// const serviceId = 'getPropGisInfo';
|
|
// const formatType = 'json';
|
|
// const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(reportInput)}`;
|
|
|
|
const requestUrl = newAPIEndPoint + `${encodeURIComponent(GISIdInput)}`;
|
|
try {
|
|
// Fetch the data
|
|
const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
|
|
|
|
// Ensure we have the data and GisInfos is available
|
|
if (apiResponse.data && apiResponse.data.ListResult && Object.keys(apiResponse.data.ListResult).length > 0) {
|
|
// Filter the response to include only matching GISIds
|
|
const matchingGisInfos = apiResponse.data.ListResult.filter((items: any) =>
|
|
GISIds.includes(items.GISID)
|
|
);
|
|
|
|
return matchingGisInfos; // Return only the matching GISId objects
|
|
}
|
|
|
|
return []; // Return an empty array if no matching results
|
|
} catch (err) {
|
|
console.error('Error fetching data:', err);
|
|
return [];
|
|
}
|
|
|
|
} catch (err) {
|
|
console.error('Error querying features:', err);
|
|
}
|
|
return [];
|
|
};
|
|
|
|
|
|
export const fetchBillNoData_New = async (GISIds: string) => {
|
|
try {
|
|
if (GISIds) {
|
|
let GISIdInput = GISIds.replace(/^"|"$/g, "")
|
|
// const GISIdInput = JSON.stringify(GISIds);
|
|
const newAPIEndPoint = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=common_api&jsonResp=Yes&subService=getPropByGisId&gisId="
|
|
|
|
// const reportInput = JSON.stringify({ inputs: { GIS_ID: GISIds } });
|
|
|
|
// const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
|
|
// const channelID = 3;
|
|
// const serviceId = 'getPropGisInfo';
|
|
// const formatType = 'json';
|
|
// const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(reportInput)}`;
|
|
|
|
const requestUrl = newAPIEndPoint + `${encodeURIComponent(GISIdInput)}`;
|
|
try {
|
|
const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
|
|
return apiResponse.data.ListResult
|
|
} catch (err) {
|
|
console.log('Error fetching data:', err);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
} catch (err) {
|
|
console.log('Error querying features:', err);
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const fetchBillNoData = async (billNo: string) => {
|
|
try {
|
|
|
|
|
|
if (billNo) {
|
|
const reportInput = JSON.stringify({ inputs: { P_ID: [billNo] } });
|
|
const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
|
|
const channelID = 3;
|
|
const serviceId = 'getPropGisInfo';
|
|
const formatType = 'json';
|
|
const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(reportInput)}`;
|
|
try {
|
|
const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
|
|
return apiResponse.data.GisInfos
|
|
} catch (err) {
|
|
console.log('Error fetching data:', err);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
} catch (err) {
|
|
console.log('Error querying features:', err);
|
|
}
|
|
};
|
|
|
|
export const fetchBuildingUsageData = async (buildingUsage: string, reportInput: object) => {
|
|
// Simulate an API call or actual query to fetch Building Type data
|
|
let query = Property_w_54.createQuery()
|
|
query.where = "property_usage_mis='" + buildingUsage + "'"
|
|
query.returnDistinctValues = true
|
|
try {
|
|
const result = await Property_w_54.queryFeatures(query)
|
|
if (result.features.length === 0) {
|
|
return []
|
|
}
|
|
else {
|
|
return result;
|
|
}
|
|
} catch (err) {
|
|
console.log('Error fetching data:', err);
|
|
return [];
|
|
}
|
|
};
|
|
|
|
|
|
// export const fetchBuildingUsageData = async (buildingUsage: string, reportInput: object) => {
|
|
// // Simulate an API call or actual query to fetch Building Type data
|
|
// let input = JSON.stringify(reportInput);
|
|
// const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
|
|
// const channelID = 3;
|
|
// const serviceId = 'getPropGisInfo';
|
|
// const formatType = 'json';
|
|
// const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(input)}`;
|
|
// try {
|
|
// const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
|
|
// if (apiResponse.data.Message === 'No Data') return [];
|
|
// const gisInfos = apiResponse.data?.GisInfos || [];
|
|
|
|
|
|
// const filteredData = gisInfos.filter(item => item.SystemPropertyUsage === buildingUsage);
|
|
// return filteredData;
|
|
// } catch (err) {
|
|
// console.log('Error fetching data:', err);
|
|
// return [];
|
|
// }
|
|
// };
|
|
|
|
export const fetchBuildingData = async (BuildingQryInput: string, reportInput: object, searchFilter: string) => {
|
|
let input = JSON.stringify(reportInput);
|
|
const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
|
|
const channelID = 3;
|
|
const serviceId = 'getPropGisInfo';
|
|
const formatType = 'json';
|
|
const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(input)}`;
|
|
try {
|
|
const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
|
|
if (apiResponse.data.Message === 'No Data') return [];
|
|
const gisInfos = apiResponse.data?.GisInfos || [];
|
|
const filteredData = gisInfos.filter(item => item[searchFilter] === BuildingQryInput)//gisInfos.filter(item => item.SystemBuildingType === BuildingQryInput);
|
|
return filteredData;
|
|
} catch (err) {
|
|
console.log('Error fetching data:', err);
|
|
return [];
|
|
}
|
|
};
|
|
|
|
export const fetchBuildingFloorData = async (min: any, max: any, reportInput: object) => {
|
|
let input = JSON.stringify(reportInput);
|
|
const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
|
|
const channelID = 3;
|
|
const serviceId = 'getPropGisInfo';
|
|
const formatType = 'json';
|
|
const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(input)}`;
|
|
try {
|
|
const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
|
|
if (apiResponse.data.Message === 'No Data') return [];
|
|
const gisInfos = apiResponse.data?.GisInfos || [];
|
|
const filteredData = gisInfos.filter(item => {
|
|
const systemFloorCount = item.SystemFloorCount && !isNaN(Number(item.SystemFloorCount))
|
|
? Number(item.SystemFloorCount)
|
|
: null;
|
|
return systemFloorCount !== null && systemFloorCount >= min && systemFloorCount <= max;
|
|
});
|
|
|
|
return filteredData;
|
|
|
|
} catch (err) {
|
|
console.log('Error fetching data:', err);
|
|
return [];
|
|
} return [];
|
|
};
|
|
|
|
// Function to execute a GP service
|
|
const fetchRevenueDataFromGPService = async (gpServiceUrl: string, params: any) => {
|
|
|
|
|
|
try {
|
|
|
|
// var gpUrl = "https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCDepts/newbillstatus/GPServer/New Bill Status Report";
|
|
|
|
|
|
// submitJob(gpUrl)
|
|
// .then(function (jobInfo) {
|
|
// jobInfo.waitForJobCompletion().then(() => {
|
|
|
|
// jobInfo.fetchResultData("Location")
|
|
// .then(function (result) {
|
|
// console.log(result)
|
|
// })
|
|
// })
|
|
// })
|
|
// execute(gpServiceUrl, params).then(fetchGPResult);
|
|
|
|
try {
|
|
const jobInfo = await submitJob(gpServiceUrl, params);
|
|
console.log("Job submitted successfully:", jobInfo);
|
|
const statusCallback = ({ jobStatus, progress }) => {
|
|
if (jobStatus === "job-executing") {
|
|
console.log(`Status: ${progress}`);
|
|
}
|
|
};
|
|
|
|
// Wait for the job to complete
|
|
await jobInfo.waitForJobCompletion({ statusCallback });
|
|
|
|
if (jobInfo.jobStatus === "job-succeeded") {
|
|
|
|
const availableResults = await jobInfo.fetchAllResults();
|
|
console.log("Available GP Service results:", availableResults);
|
|
if (availableResults.Output) {
|
|
let Output = "Output"
|
|
const result = await jobInfo.fetchResultData(Output);
|
|
console.log("GP Service result:", result);
|
|
} else {
|
|
console.error("Output not found in GP service results.");
|
|
}
|
|
} else {
|
|
console.error("Job failed with status:", jobInfo.jobStatus);
|
|
}
|
|
} catch (error) {
|
|
console.error("Error submitting or processing GP job:", error);
|
|
}
|
|
|
|
|
|
|
|
async function getGPOutput(outputUrl) {
|
|
const response = await fetch(outputUrl);
|
|
const data = await response.json();
|
|
return data;
|
|
}
|
|
|
|
} catch (error) {
|
|
console.log('Error executing GP service:', error);
|
|
throw error; // Rethrow error for further handling
|
|
return []
|
|
}
|
|
}
|
|
|
|
|
|
function fetchGPResult(result) {
|
|
console.log(result)
|
|
}
|
|
const fetchDueDetails = (filteredProperties, MisInput, matchKey) => {
|
|
// After getting the matched GIS data from the query, you can now process the filteredProperties further
|
|
let dueData: any[] = [];
|
|
let nodueData: any[] = [];
|
|
let consolidatedDict: { [key: string]: number } = {};
|
|
let nullData: any[] = []
|
|
// Loop through matched API properties and apply Due/Nodue logic
|
|
filteredProperties.forEach(item => {
|
|
const misValue = parseFloat(item[MisInput]); // Get the MisInput value
|
|
const gisId = item.GISId;
|
|
|
|
if (misValue > 0) {
|
|
// If there's a due, add to DueData
|
|
dueData.push(item);
|
|
|
|
// Consolidate by summing up misValue for each gcc_gis_id
|
|
if (consolidatedDict[gisId]) {
|
|
consolidatedDict[gisId] += misValue;
|
|
} else {
|
|
consolidatedDict[gisId] = misValue;
|
|
}
|
|
} else {
|
|
nodueData.push(item); // No dues, add to NodueData
|
|
}
|
|
if (item[matchKey] === null || item[matchKey] === '') {
|
|
nullData.push(item);
|
|
}
|
|
|
|
});
|
|
|
|
// Prepare the final result
|
|
const consolidatedData = Object.keys(consolidatedDict).map(gisId => ({
|
|
gcc_gis_id: gisId,
|
|
totalMisInput: consolidatedDict[gisId]
|
|
}));
|
|
|
|
// Output the final result to log or further process
|
|
const resultDict = {
|
|
NullData: JSON.stringify(nullData),
|
|
MatchedData: JSON.stringify(filteredProperties),
|
|
NodueData: JSON.stringify(nodueData),
|
|
DueData: JSON.stringify(dueData),
|
|
ConsolidatedValues: JSON.stringify(consolidatedData)
|
|
};
|
|
// console.log('FINAL RESULT:', resultDict);
|
|
return resultDict
|
|
}
|
|
export const fetchRevenueData = async (taxType: any, MisKey: any, MisInput: any, revenueinputs: any, reportInput: any) => {
|
|
const queryParams = `Zoneid=${revenueinputs.Zoneid}&WardId=${revenueinputs.WardId}&AreaId=${revenueinputs.AreaId}&LocationId=${revenueinputs.LocationId}&StreetId=${revenueinputs.StreetId}`;
|
|
let report_input = JSON.stringify(reportInput);
|
|
const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
|
|
const channelID = 3;
|
|
const serviceId = 'getPropGisInfo';
|
|
const formatType = 'json';
|
|
const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${report_input}`;
|
|
let gpServiceUrl
|
|
if (taxType == 'Property') {
|
|
gpServiceUrl = 'https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCPropertyTax/proprevenue/GPServer/proprevenue'
|
|
try {
|
|
// try {
|
|
// const gpResult = await fetchRevenueDataFromGPService(gpServiceUrl, revenueinputs);
|
|
// return (gpResult);
|
|
// } catch (err) {
|
|
// console.log('Error fetching data:', err);
|
|
// return [];
|
|
// }
|
|
|
|
// return filteredData;
|
|
|
|
const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
|
|
if (apiResponse.data.Message === 'No Data') return [];
|
|
const revenueData = apiResponse.data?.GisInfos
|
|
// const filteredProperties = apiResponse.data?.GisInfos.filter(item => {
|
|
// const dueValue = item[MisInput]; // Access the queried field dynamically
|
|
// const hasDues = dueValue && parseFloat(dueValue) > 0;
|
|
// return hasDues;
|
|
// });
|
|
let resultData = fetchDueDetails(revenueData, MisInput, 'PropertyNo')
|
|
return resultData
|
|
|
|
|
|
} catch (error) {
|
|
console.log("Error fetching Revenue API response:", error);
|
|
if (error.name === 'SyntaxError') {
|
|
console.log("Malformed JSON response. Verify the GP service output.");
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
else if (taxType == 'Trade') {
|
|
// gpServiceUrl = 'https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCPropertyTax/EstRevenue/GPServer/EstRevenue'
|
|
const requestUrl = `https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=getGisRevenueData&` + queryParams;
|
|
let apiResponse
|
|
try {
|
|
// setInterval(async () => {
|
|
apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
|
|
// }, 3000);
|
|
if (apiResponse.data.Message === 'Connection Failure') return [];
|
|
const revenueData = apiResponse.data[0].Revenue;
|
|
|
|
const revenueTypeData = revenueData.find(item => Object.keys(item)[0] === taxType);
|
|
|
|
let taxType_Filtered = revenueTypeData.Trade.filter(item => item.ISRENEWED === MisInput);
|
|
if (taxType_Filtered.length > 0)
|
|
return taxType_Filtered
|
|
else return []
|
|
// }, 3000);
|
|
} catch (error) {
|
|
console.log("Error fetching Revenue API response:", error);
|
|
if (error.name === 'SyntaxError') {
|
|
console.log("Malformed JSON response. Verify the GP service output.");
|
|
}
|
|
return null;
|
|
}
|
|
} else {
|
|
// gpServiceUrl = 'https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCPropertyTax/EstRevenue/GPServer/EstRevenue'
|
|
const requestUrl = `https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=getGisRevenueData&` + queryParams;
|
|
let apiResponse
|
|
try {
|
|
// setInterval(async () => {
|
|
apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
|
|
// }, 3000);
|
|
if (apiResponse.data.Message === 'Connection Failure') return [];
|
|
const revenueData = apiResponse.data[0].Revenue;
|
|
|
|
// Find the array of data that matches the key (Company, Profession, or Trade)
|
|
const revenueTypeData = revenueData.find(item => Object.keys(item)[0] === taxType);
|
|
|
|
|
|
|
|
// let resultData = fetchDueDetails(revenueTypeData[taxType], MisInput, 'PROPERTYTAX_NUMBER')
|
|
// return resultData
|
|
|
|
|
|
|
|
if (revenueTypeData[taxType].length > 0)
|
|
return revenueTypeData[taxType]
|
|
else return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }, 3000);
|
|
} catch (error) {
|
|
console.log("Error fetching GP result data:", error);
|
|
if (error.name === 'SyntaxError') {
|
|
console.log("Malformed JSON response. Verify the GP service output.");
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const fetchBuildingTypeList = async (layer, query) => {
|
|
const result = await layer.queryFeatures(query)
|
|
if (result.features.length === 0) {
|
|
return []// Exit the loop if no more features are returned
|
|
}
|
|
else {
|
|
return result;
|
|
}
|
|
}
|
|
export const fetchBuildingInputList = async (layer, query) => {
|
|
const result = await layer.queryFeatures(query)
|
|
if (result.features.length === 0) {
|
|
return []// Exit the loop if no more features are returned
|
|
}
|
|
else {
|
|
return result;
|
|
}
|
|
}
|
|
export const fetchAllFeatures = async (layer, query) => {
|
|
let allFeatures = [];
|
|
const pageSize = 2000;
|
|
let offset = 0;
|
|
while (true) {
|
|
query.start = offset;
|
|
query.num = pageSize;
|
|
const result = await layer.queryFeatures(query)
|
|
if (result.features.length === 0) {
|
|
break; // Exit the loop if no more features are returned
|
|
}
|
|
allFeatures = allFeatures.concat(result.features);
|
|
offset += pageSize;
|
|
// If the number of features returned is less than the page size, we've fetched all features
|
|
if (result.features.length < pageSize) {
|
|
break;
|
|
}
|
|
}
|
|
return allFeatures;
|
|
}
|