Subversion Repositories SmartDukaan

Rev

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

Rev 27430 Rev 27450
Line 1... Line 1...
1
package com.smartdukaan.cron.migrations;
1
package com.smartdukaan.cron.migrations;
2
 
2
 
3
import java.io.File;
3
import java.io.File;
-
 
4
import java.io.IOException;
4
import java.time.LocalDate;
5
import java.time.LocalDate;
5
import java.time.LocalDateTime;
6
import java.time.LocalDateTime;
6
import java.time.LocalTime;
7
import java.time.LocalTime;
7
import java.time.temporal.ChronoUnit;
8
import java.time.temporal.ChronoUnit;
8
import java.time.temporal.Temporal;
9
import java.time.temporal.Temporal;
9
import java.time.temporal.TemporalUnit;
10
import java.time.temporal.TemporalUnit;
10
import java.util.ArrayList;
11
import java.util.ArrayList;
11
import java.util.Arrays;
12
import java.util.Arrays;
-
 
13
import java.util.Base64;
12
import java.util.Collections;
14
import java.util.Collections;
13
import java.util.Comparator;
15
import java.util.Comparator;
14
import java.util.HashMap;
16
import java.util.HashMap;
15
import java.util.HashSet;
17
import java.util.HashSet;
16
import java.util.List;
18
import java.util.List;
17
import java.util.Map;
19
import java.util.Map;
18
import java.util.Set;
20
import java.util.Set;
19
import java.util.concurrent.TimeUnit;
21
import java.util.concurrent.TimeUnit;
20
import java.util.stream.Collectors;
22
import java.util.stream.Collectors;
21
 
23
 
-
 
24
import javax.servlet.http.HttpServletRequest;
-
 
25
 
22
import org.apache.commons.io.output.ByteArrayOutputStream;
26
import org.apache.commons.io.output.ByteArrayOutputStream;
23
import org.apache.commons.lang.StringUtils;
27
import org.apache.commons.lang.StringUtils;
24
import org.apache.logging.log4j.LogManager;
28
import org.apache.logging.log4j.LogManager;
25
import org.apache.logging.log4j.Logger;
29
import org.apache.logging.log4j.Logger;
26
import org.apache.solr.common.util.Hash;
30
import org.apache.solr.common.util.Hash;
-
 
31
import org.json.JSONArray;
-
 
32
import org.json.JSONObject;
27
import org.openqa.selenium.Dimension;
33
import org.openqa.selenium.Dimension;
28
import org.openqa.selenium.OutputType;
34
import org.openqa.selenium.OutputType;
29
import org.openqa.selenium.TakesScreenshot;
35
import org.openqa.selenium.TakesScreenshot;
30
import org.openqa.selenium.WebDriver;
36
import org.openqa.selenium.WebDriver;
31
import org.openqa.selenium.chrome.ChromeDriver;
37
import org.openqa.selenium.chrome.ChromeDriver;
32
import org.openqa.selenium.chrome.ChromeOptions;
38
import org.openqa.selenium.chrome.ChromeOptions;
33
import org.springframework.beans.factory.annotation.Autowired;
39
import org.springframework.beans.factory.annotation.Autowired;
34
import org.springframework.core.io.ByteArrayResource;
40
import org.springframework.core.io.ByteArrayResource;
-
 
41
import org.springframework.http.MediaType;
-
 
42
import org.springframework.http.ResponseEntity;
35
import org.springframework.mail.javamail.JavaMailSender;
43
import org.springframework.mail.javamail.JavaMailSender;
36
import org.springframework.stereotype.Component;
44
import org.springframework.stereotype.Component;
37
import org.springframework.transaction.annotation.Transactional;
45
import org.springframework.transaction.annotation.Transactional;
-
 
46
import org.springframework.web.bind.annotation.RequestMapping;
-
 
47
import org.springframework.web.bind.annotation.RequestMethod;
38
 
48
 
39
import com.smartdukaan.cron.scheduled.SamsungIMEIActivationService;
49
import com.smartdukaan.cron.scheduled.SamsungIMEIActivationService;
40
import com.smartdukaan.cron.scheduled.ScheduledTasks;
50
import com.smartdukaan.cron.scheduled.ScheduledTasks;
41
import com.spice.profitmandi.common.enumuration.ItemType;
51
import com.spice.profitmandi.common.enumuration.ItemType;
42
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
52
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
53
import com.spice.profitmandi.common.model.CustomRetailer;
43
import com.spice.profitmandi.common.util.FileUtil;
54
import com.spice.profitmandi.common.util.FileUtil;
44
import com.spice.profitmandi.common.util.FormattingUtils;
55
import com.spice.profitmandi.common.util.FormattingUtils;
45
import com.spice.profitmandi.common.util.Utils;
56
import com.spice.profitmandi.common.util.Utils;
46
import com.spice.profitmandi.dao.entity.catalog.Item;
57
import com.spice.profitmandi.dao.entity.catalog.Item;
47
import com.spice.profitmandi.dao.entity.catalog.Scheme;
58
import com.spice.profitmandi.dao.entity.catalog.Scheme;
Line 123... Line 134...
123
import com.spice.profitmandi.service.user.RetailerService;
134
import com.spice.profitmandi.service.user.RetailerService;
124
import com.spice.profitmandi.service.wallet.WalletService;
135
import com.spice.profitmandi.service.wallet.WalletService;
125
 
136
 
126
import in.shop2020.model.v1.order.OrderStatus;
137
import in.shop2020.model.v1.order.OrderStatus;
127
import in.shop2020.model.v1.order.WalletReferenceType;
138
import in.shop2020.model.v1.order.WalletReferenceType;
-
 
139
import okhttp3.OkHttpClient;
-
 
140
import okhttp3.Request;
-
 
141
import okhttp3.Response;
128
 
142
 
129
@Component
143
@Component
130
@Transactional(rollbackFor = Throwable.class)
144
@Transactional(rollbackFor = Throwable.class)
131
public class RunOnceTasks {
145
public class RunOnceTasks {
132
 
146
 
Line 147... Line 161...
147
	@Autowired
161
	@Autowired
148
	private CsService csService;
162
	private CsService csService;
149
 
163
 
150
	@Autowired
164
	@Autowired
151
	private Mongo mongoClient;
165
	private Mongo mongoClient;
152
	
166
 
153
	@Autowired
167
	@Autowired
154
	private PaymentOptionTransactionRepository paymentOptionTransactionRepository;
168
	private PaymentOptionTransactionRepository paymentOptionTransactionRepository;
155
 
169
 
156
	@Autowired
170
	@Autowired
157
	private SamsungIMEIActivationService samsungActivationService;
171
	private SamsungIMEIActivationService samsungActivationService;
Line 171... Line 185...
171
	@Autowired
185
	@Autowired
172
	private SellerWarehouseRepository sellerWarehouseRepository;
186
	private SellerWarehouseRepository sellerWarehouseRepository;
173
 
187
 
174
	@Autowired
188
	@Autowired
175
	private FofoOrderItemRepository fofoOrderItemRepository;
189
	private FofoOrderItemRepository fofoOrderItemRepository;
176
	
190
 
177
	@Autowired
191
	@Autowired
178
	private FofoLineItemRepository fofoLineItemRepository;
192
	private FofoLineItemRepository fofoLineItemRepository;
179
 
193
 
180
	@Autowired
194
	@Autowired
181
	private FofoOrderRepository fofoOrderRepository;
195
	private FofoOrderRepository fofoOrderRepository;
Line 271... Line 285...
271
	@Autowired
285
	@Autowired
272
	private ScanRecordRepository scanRecordRepository;
286
	private ScanRecordRepository scanRecordRepository;
273
 
287
 
274
	@Autowired
288
	@Autowired
275
	private JavaMailSender mailSender;
289
	private JavaMailSender mailSender;
-
 
290
	
-
 
291
	private static final String ACCOUNT_ID = "aZ6flHhrgPIEl18buHdPBdueEN4";
-
 
292
	private static final String SECRET_KEY = "a7rsX5B4UNNfTTx1-IJ19qdH48BT4YvBKlQJg3n3_KKNe7WWych55g";
-
 
293
 
276
 
294
 
277
	public void populateGrnTimestamp() {
295
	public void populateGrnTimestamp() {
278
		List<Purchase> allPurchases = purchaseRepository.selectAll();
296
		List<Purchase> allPurchases = purchaseRepository.selectAll();
279
		for (Purchase p : allPurchases) {
297
		for (Purchase p : allPurchases) {
280
			String invoiceNumber = p.getPurchaseReference();
298
			String invoiceNumber = p.getPurchaseReference();
Line 1049... Line 1067...
1049
		}
1067
		}
1050
		LOGGER.info("Total Sale Amount Reversal - {}, Total Wallet Amount Reversal {}, Total Scheme Reversal Amount - {}", saleAmount, totalAmount, schemeReverseAmount);
1068
		LOGGER.info("Total Sale Amount Reversal - {}, Total Wallet Amount Reversal {}, Total Scheme Reversal Amount - {}", saleAmount, totalAmount, schemeReverseAmount);
1051
		//throw new Exception();
1069
		//throw new Exception();
1052
	}
1070
	}
1053
 
1071
 
-
 
1072
	public void createGeofence() throws IOException, ProfitMandiBusinessException {
-
 
1073
 
-
 
1074
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
-
 
1075
		for (FofoStore fofoStore : fofoStores) {
-
 
1076
			if (fofoStore.getLatitude() != null && fofoStore.getLongitude() != null) {
-
 
1077
				CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoStore.getId());
-
 
1078
				OkHttpClient client = new OkHttpClient();
-
 
1079
 
-
 
1080
				okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
-
 
1081
				JSONObject geofe = new JSONObject();
-
 
1082
				JSONArray geofences = new JSONArray();
-
 
1083
				JSONObject geometry = new JSONObject();
-
 
1084
				JSONObject geo = new JSONObject();
-
 
1085
				JSONArray coordinates = new JSONArray();
-
 
1086
				coordinates.put(fofoStore.getLongitude());
-
 
1087
				coordinates.put(fofoStore.getLatitude());
-
 
1088
				geo.put("type", "Point");
-
 
1089
				geo.put("coordinates", coordinates);
-
 
1090
				geometry.put("geometry", geo);
-
 
1091
				JSONObject metadata = new JSONObject();
-
 
1092
				metadata.put("name", customRetailer.getBusinessName());
-
 
1093
				metadata.put("city", customRetailer.getAddress().getCity());
-
 
1094
				geometry.put("metadata", metadata);
-
 
1095
				geometry.put("radius", 500);
-
 
1096
 
-
 
1097
				geofences.put(geometry);
-
 
1098
				geofe.put("geofences", geofences);
-
 
1099
				okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
-
 
1100
				String authString = "Basic "
-
 
1101
						+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
-
 
1102
 
-
 
1103
				Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
-
 
1104
						.addHeader("Authorization", authString).build();
-
 
1105
 
-
 
1106
				Response response = client.newCall(request1).execute();
-
 
1107
 
-
 
1108
				LOGGER.info("response" + response.body().string());
-
 
1109
			}
-
 
1110
		}
-
 
1111
 
-
 
1112
	}
-
 
1113
 
-
 
1114
	
-
 
1115
	public void getAllGeofences()
-
 
1116
			throws IOException, ProfitMandiBusinessException {
-
 
1117
 
-
 
1118
		OkHttpClient client = new OkHttpClient();
-
 
1119
 
-
 
1120
		String authString = "Basic "
-
 
1121
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
-
 
1122
 
-
 
1123
		// Get geofences created for all app users
-
 
1124
		Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences")
-
 
1125
				.addHeader("Authorization", authString).build();
-
 
1126
 
-
 
1127
		Response response = client.newCall(request1).execute();
-
 
1128
			
-
 
1129
		LOGGER.info("response" + response.body().string());
-
 
1130
	}
-
 
1131
 
1054
	public void processSchemeOut(int fofoId, int orderId) throws Exception {
1132
	public void processSchemeOut(int fofoId, int orderId) throws Exception {
1055
		schemeService.processSchemeOut(orderId, fofoId);
1133
		schemeService.processSchemeOut(orderId, fofoId);
1056
		
1134
		
1057
	}
1135
	}
1058
}
1136
}