Subversion Repositories SmartDukaan

Rev

Rev 36402 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36402 Rev 36420
Line 91... Line 91...
91
import com.spice.profitmandi.service.user.RetailerService;
91
import com.spice.profitmandi.service.user.RetailerService;
92
import com.spice.profitmandi.service.wallet.CommonPaymentService;
92
import com.spice.profitmandi.service.wallet.CommonPaymentService;
93
import com.spice.profitmandi.service.wallet.WalletService;
93
import com.spice.profitmandi.service.wallet.WalletService;
94
import com.spice.profitmandi.service.warehouse.WarehouseInventoryService;
94
import com.spice.profitmandi.service.warehouse.WarehouseInventoryService;
95
import com.spice.profitmandi.service.warehouse.WarehouseService;
95
import com.spice.profitmandi.service.warehouse.WarehouseService;
-
 
96
import com.spice.profitmandi.common.web.client.HttpClientFactory;
-
 
97
import com.spice.profitmandi.common.web.client.RestClient;
96
import in.shop2020.model.v1.order.OrderStatus;
98
import in.shop2020.model.v1.order.OrderStatus;
97
import in.shop2020.model.v1.order.WalletReferenceType;
99
import in.shop2020.model.v1.order.WalletReferenceType;
-
 
100
import org.apache.http.client.methods.CloseableHttpResponse;
98
import okhttp3.OkHttpClient;
101
import org.apache.http.client.methods.HttpDelete;
99
import okhttp3.Request;
102
import org.apache.http.impl.client.CloseableHttpClient;
100
import okhttp3.Response;
103
import org.apache.http.util.EntityUtils;
101
import org.apache.commons.csv.CSVRecord;
104
import org.apache.commons.csv.CSVRecord;
102
import org.apache.commons.io.output.ByteArrayOutputStream;
105
import org.apache.commons.io.output.ByteArrayOutputStream;
103
import org.apache.commons.lang.StringUtils;
106
import org.apache.commons.lang.StringUtils;
104
import org.apache.logging.log4j.LogManager;
107
import org.apache.logging.log4j.LogManager;
105
import org.apache.logging.log4j.Logger;
108
import org.apache.logging.log4j.Logger;
Line 137... Line 140...
137
@Component
140
@Component
138
@Transactional(rollbackFor = Throwable.class)
141
@Transactional(rollbackFor = Throwable.class)
139
public class RunOnceTasks {
142
public class RunOnceTasks {
140
 
143
 
141
    private static final Logger LOGGER = LogManager.getLogger(RunOnceTasks.class);
144
    private static final Logger LOGGER = LogManager.getLogger(RunOnceTasks.class);
-
 
145
 
-
 
146
    @Autowired
-
 
147
    private RestClient restClient;
-
 
148
 
142
    @Autowired
149
    @Autowired
143
    private LineItemRepository lineItemRepository;
150
    private LineItemRepository lineItemRepository;
144
 
151
 
145
    @Autowired
152
    @Autowired
146
    private LeadRepository leadRepository;
153
    private LeadRepository leadRepository;
Line 1456... Line 1463...
1456
 
1463
 
1457
        // List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1464
        // List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1458
        // for (FofoStore fofoStore : fofoStores) {
1465
        // for (FofoStore fofoStore : fofoStores) {
1459
        // if (fofoStore.getLatitude() != null && fofoStore.getLongitude() != null) {
1466
        // if (fofoStore.getLatitude() != null && fofoStore.getLongitude() != null) {
1460
        CustomRetailer customRetailer = retailerService.getFofoRetailer(175138812);
1467
        CustomRetailer customRetailer = retailerService.getFofoRetailer(175138812);
1461
        OkHttpClient client = new OkHttpClient();
-
 
1462
        okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
-
 
1463
        JSONObject geofe = new JSONObject();
1468
        JSONObject geofe = new JSONObject();
1464
        JSONArray geofences = new JSONArray();
1469
        JSONArray geofences = new JSONArray();
1465
        JSONObject geometry = new JSONObject();
1470
        JSONObject geometry = new JSONObject();
1466
        JSONObject geo = new JSONObject();
1471
        JSONObject geo = new JSONObject();
1467
        JSONArray coordinates = new JSONArray();
1472
        JSONArray coordinates = new JSONArray();
1468
        ArrayList<Double> crds = new ArrayList<>();
1473
        ArrayList<Double> crds = new ArrayList<>();
1469
        // crds.add(Double.parseDouble(fofoStore.getLongitude()));
-
 
1470
        // crds.add(Double.parseDouble(fofoStore.getLatitude()));
-
 
1471
        crds.add(79.739197);
1474
        crds.add(79.739197);
1472
        crds.add(27.961215);
1475
        crds.add(27.961215);
1473
        // crds.add(77.08596155373755);
-
 
1474
        // crds.add(28.64944201113976);
-
 
1475
        // coordinates.put(fofoStore.getLongitude());
-
 
1476
        // coordinates.put(fofoStore.getLatitude());
-
 
1477
        geo.put("type", "Point");
1476
        geo.put("type", "Point");
1478
        geo.put("coordinates", crds);
1477
        geo.put("coordinates", crds);
1479
        geometry.put("geometry", geo);
1478
        geometry.put("geometry", geo);
1480
        JSONObject metadata = new JSONObject();
1479
        JSONObject metadata = new JSONObject();
1481
        metadata.put("name", customRetailer.getBusinessName());
1480
        metadata.put("name", customRetailer.getBusinessName());
Line 1484... Line 1483...
1484
        geometry.put("metadata", metadata);
1483
        geometry.put("metadata", metadata);
1485
        geometry.put("radius", 200);
1484
        geometry.put("radius", 200);
1486
 
1485
 
1487
        geofences.put(geometry);
1486
        geofences.put(geometry);
1488
        geofe.put("geofences", geofences);
1487
        geofe.put("geofences", geofences);
1489
        okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
-
 
1490
        String authString = "Basic "
1488
        String authString = "Basic "
1491
                + Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1489
                + Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1492
 
1490
 
1493
        Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
1491
        String responseBody = restClient.postJson("https://v3.api.hypertrack.com/geofences",
1494
                .addHeader("Authorization", authString).build();
1492
                geofe.toString(), Collections.singletonMap("Authorization", authString));
1495
 
-
 
1496
        Response response = client.newCall(request1).execute();
-
 
1497
 
-
 
1498
        JSONArray ja = new JSONArray(response.body().string());
1493
        JSONArray ja = new JSONArray(responseBody);
1499
        LOGGER.info("geofence" + ja);
1494
        LOGGER.info("geofence" + ja);
1500
        LOGGER.info("jalength" + ja.length());
1495
        LOGGER.info("jalength" + ja.length());
1501
        /*
1496
        /*
1502
         * for (int i = 0; i < ja.length(); i++) { JSONObject c = ja.getJSONObject(i);
1497
         * for (int i = 0; i < ja.length(); i++) { JSONObject c = ja.getJSONObject(i);
1503
         * String geofenceId = c.getString("geofence_id"); LOGGER.info("geofenceId" +
1498
         * String geofenceId = c.getString("geofence_id"); LOGGER.info("geofenceId" +
Line 1510... Line 1505...
1510
         * }
1505
         * }
1511
         */
1506
         */
1512
 
1507
 
1513
    }
1508
    }
1514
 
1509
 
1515
    public void getAllGeofences() throws IOException, ProfitMandiBusinessException {
1510
    public void getAllGeofences() throws Exception {
1516
 
-
 
1517
        OkHttpClient client = new OkHttpClient();
-
 
1518
 
-
 
1519
        String authString = "Basic "
1511
        String authString = "Basic "
1520
                + Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1512
                + Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1521
 
-
 
1522
        // Get geofences created for all app users
-
 
1523
        Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences")
1513
        String body = restClient.get("https://v3.api.hypertrack.com/geofences",
1524
                .addHeader("Authorization", authString).build();
1514
                null, Collections.singletonMap("Authorization", authString));
1525
 
-
 
1526
        Response response = client.newCall(request1).execute();
-
 
1527
 
-
 
1528
        LOGGER.info("response" + response.body().string());
1515
        LOGGER.info("response" + body);
1529
    }
1516
    }
1530
 
1517
 
1531
    public void deleteGeofences(List<String> geofenceIds) throws IOException, ProfitMandiBusinessException {
1518
    public void deleteGeofences(List<String> geofenceIds) throws IOException, ProfitMandiBusinessException {
1532
        OkHttpClient client = new OkHttpClient();
-
 
1533
 
-
 
1534
        String authString = "Basic "
1519
        String authString = "Basic "
1535
                + Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1520
                + Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1536
 
1521
 
-
 
1522
        try (CloseableHttpClient client = HttpClientFactory.apacheHttp()) {
1537
        for (String geofenceId : geofenceIds) {
1523
            for (String geofenceId : geofenceIds) {
1538
            Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences/" + geofenceId)
1524
                HttpDelete delete = new HttpDelete("https://v3.api.hypertrack.com/geofences/" + geofenceId);
1539
                    .delete().addHeader("Authorization", authString).build();
1525
                delete.setHeader("Authorization", authString);
1540
            LOGGER.info("geofenceId" + geofenceId);
1526
                LOGGER.info("geofenceId" + geofenceId);
1541
            Response response = client.newCall(request1).execute();
1527
                try (CloseableHttpResponse response = client.execute(delete)) {
1542
 
-
 
-
 
1528
                    String body = response.getEntity() != null ? EntityUtils.toString(response.getEntity()) : "";
1543
            LOGGER.info("response" + response.body().string());
1529
                    LOGGER.info("response" + body);
-
 
1530
                }
-
 
1531
            }
1544
        }
1532
        }
1545
 
-
 
1546
    }
1533
    }
1547
 
1534
 
1548
    public void processSchemeOut(int fofoId, int orderId) throws Exception {
1535
    public void processSchemeOut(int fofoId, int orderId) throws Exception {
1549
        schemeService.processSchemeOut(orderId, fofoId);
1536
        schemeService.processSchemeOut(orderId, fofoId);
1550
 
1537