Subversion Repositories SmartDukaan

Rev

Rev 27459 | Rev 27461 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27459 Rev 27460
Line 62... Line 62...
62
import com.spice.profitmandi.dao.entity.fofo.DebitNote;
62
import com.spice.profitmandi.dao.entity.fofo.DebitNote;
63
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
63
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
64
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
64
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
65
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
65
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
66
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
66
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
67
import com.spice.profitmandi.dao.entity.fofo.FofoStoreGeofence;
67
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
68
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
68
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
69
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
69
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
70
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
70
import com.spice.profitmandi.dao.entity.fofo.PrebookingOrder;
71
import com.spice.profitmandi.dao.entity.fofo.PrebookingOrder;
71
import com.spice.profitmandi.dao.entity.fofo.Purchase;
72
import com.spice.profitmandi.dao.entity.fofo.Purchase;
Line 1082... Line 1083...
1082
		// throw new Exception();
1083
		// throw new Exception();
1083
	}
1084
	}
1084
 
1085
 
1085
	public void createGeofence() throws IOException, ProfitMandiBusinessException {
1086
	public void createGeofence() throws IOException, ProfitMandiBusinessException {
1086
 
1087
 
1087
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1088
		// List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1088
		for (FofoStore fofoStore : fofoStores) {
1089
		// for (FofoStore fofoStore : fofoStores) {
1089
			if (fofoStore.getLatitude() != null && fofoStore.getLongitude() != null) {
1090
		// if (fofoStore.getLatitude() != null && fofoStore.getLongitude() != null) {
-
 
1091
		// CustomRetailer customRetailer =
1090
				CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoStore.getId());
1092
		// retailerService.getFofoRetailer(fofoStore.getId());
1091
				OkHttpClient client = new OkHttpClient();
1093
		OkHttpClient client = new OkHttpClient();
1092
				okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
1094
		okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
1093
				JSONObject geofe = new JSONObject();
1095
		JSONObject geofe = new JSONObject();
1094
				JSONArray geofences = new JSONArray();
1096
		JSONArray geofences = new JSONArray();
1095
				JSONObject geometry = new JSONObject();
1097
		JSONObject geometry = new JSONObject();
1096
				JSONObject geo = new JSONObject();
1098
		JSONObject geo = new JSONObject();
1097
				JSONArray coordinates = new JSONArray();
1099
		JSONArray coordinates = new JSONArray();
1098
				ArrayList<Double> crds = new ArrayList<>();
1100
		ArrayList<Double> crds = new ArrayList<>();
1099
				crds.add(Double.parseDouble(fofoStore.getLongitude()));
1101
		// crds.add(Double.parseDouble(fofoStore.getLongitude()));
1100
				crds.add(Double.parseDouble(fofoStore.getLatitude()));
1102
		// crds.add(Double.parseDouble(fofoStore.getLatitude()));
1101
 
-
 
-
 
1103
		crds.add(77.08596155373755);
-
 
1104
		crds.add(28.64944201113976);
1102
				// coordinates.put(fofoStore.getLongitude());
1105
		// coordinates.put(fofoStore.getLongitude());
1103
				// coordinates.put(fofoStore.getLatitude());
1106
		// coordinates.put(fofoStore.getLatitude());
1104
				geo.put("type", "Point");
1107
		geo.put("type", "Point");
1105
				geo.put("coordinates", crds);
1108
		geo.put("coordinates", crds);
1106
				geometry.put("geometry", geo);
1109
		geometry.put("geometry", geo);
1107
				JSONObject metadata = new JSONObject();
1110
		JSONObject metadata = new JSONObject();
1108
				metadata.put("name", customRetailer.getBusinessName());
1111
		// metadata.put("name", customRetailer.getBusinessName());
1109
				metadata.put("city", customRetailer.getAddress().getCity());
1112
		// metadata.put("city", customRetailer.getAddress().getCity());
-
 
1113
		metadata.put("name", "Test");
1110
				geometry.put("metadata", metadata);
1114
		geometry.put("metadata", metadata);
1111
				geometry.put("radius", 500);
1115
		geometry.put("radius", 500);
1112
 
1116
 
1113
				geofences.put(geometry);
1117
		geofences.put(geometry);
1114
				geofe.put("geofences", geofences);
1118
		geofe.put("geofences", geofences);
1115
				okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
1119
		okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
1116
				String authString = "Basic "
1120
		String authString = "Basic "
1117
						+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1121
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1118
 
1122
 
1119
				Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
1123
		Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
1120
						.addHeader("Authorization", authString).build();
1124
				.addHeader("Authorization", authString).build();
1121
 
1125
 
1122
				Response response = client.newCall(request1).execute();
1126
		Response response = client.newCall(request1).execute();
1123
 
1127
 
-
 
1128
		String geofenceId = null;
1124
				LOGGER.info("response" + response.body().string());
1129
		JSONArray ja = new JSONArray(response.body().string());
-
 
1130
		for (int i = 0; i < ja.length(); i++) {
1125
			}
1131
			JSONObject c = ja.getJSONObject(i);
-
 
1132
			geofenceId = c.getString("geofence_id");
1126
		}
1133
		}
1127
 
1134
 
-
 
1135
		LOGGER.info("geofenceId" + geofenceId);
-
 
1136
 
-
 
1137
		LOGGER.info("response" + response.body().string());
1128
	}
1138
	}
1129
 
1139
 
-
 
1140
	// }
-
 
1141
 
-
 
1142
	// }
-
 
1143
 
1130
	public void getAllGeofences() throws IOException, ProfitMandiBusinessException {
1144
	public void getAllGeofences() throws IOException, ProfitMandiBusinessException {
1131
 
1145
 
1132
		OkHttpClient client = new OkHttpClient();
1146
		OkHttpClient client = new OkHttpClient();
1133
 
1147
 
1134
		String authString = "Basic "
1148
		String authString = "Basic "
Line 1148... Line 1162...
1148
 
1162
 
1149
		String authString = "Basic "
1163
		String authString = "Basic "
1150
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1164
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1151
 
1165
 
1152
		for (String geofenceId : geofenceIds) {
1166
		for (String geofenceId : geofenceIds) {
1153
			Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences/"+geofenceId)
1167
			Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences/" + geofenceId)
1154
					.delete().addHeader("Authorization", authString).build();
1168
					.delete().addHeader("Authorization", authString).build();
1155
			LOGGER.info("url" + "https://v3.api.hypertrack.com/geofences/"+geofenceId);
-
 
1156
			LOGGER.info("geofenceId" + geofenceId);
1169
			LOGGER.info("geofenceId" + geofenceId);
1157
			Response response = client.newCall(request1).execute();
1170
			Response response = client.newCall(request1).execute();
1158
 
1171
 
1159
			LOGGER.info("response"+response);
1172
			LOGGER.info("response" + response.body().string());
1160
		}
1173
		}
1161
 
1174
 
1162
	}
1175
	}
1163
 
1176
 
1164
	public void processSchemeOut(int fofoId, int orderId) throws Exception {
1177
	public void processSchemeOut(int fofoId, int orderId) throws Exception {