Subversion Repositories SmartDukaan

Rev

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

Rev 32161 Rev 32169
Line 42... Line 42...
42
 
42
 
43
import javax.mail.MessagingException;
43
import javax.mail.MessagingException;
44
import javax.mail.internet.InternetAddress;
44
import javax.mail.internet.InternetAddress;
45
import javax.mail.internet.MimeMessage;
45
import javax.mail.internet.MimeMessage;
46
 
46
 
-
 
47
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
47
import org.apache.commons.io.output.ByteArrayOutputStream;
48
import org.apache.commons.io.output.ByteArrayOutputStream;
48
import org.apache.commons.lang.StringUtils;
49
import org.apache.commons.lang.StringUtils;
49
import org.apache.http.client.methods.CloseableHttpResponse;
50
import org.apache.http.client.methods.CloseableHttpResponse;
50
import org.apache.http.client.methods.HttpPost;
51
import org.apache.http.client.methods.HttpPost;
51
import org.apache.http.conn.HttpHostConnectException;
52
import org.apache.http.conn.HttpHostConnectException;
52
import org.apache.http.entity.StringEntity;
53
import org.apache.http.entity.StringEntity;
53
import org.apache.http.impl.client.CloseableHttpClient;
54
import org.apache.http.impl.client.CloseableHttpClient;
54
import org.apache.http.impl.client.HttpClients;
55
import org.apache.http.impl.client.HttpClients;
55
import org.apache.logging.log4j.LogManager;
56
import org.apache.logging.log4j.LogManager;
56
import org.apache.logging.log4j.Logger;
57
import org.apache.logging.log4j.Logger;
-
 
58
import org.hibernate.Session;
-
 
59
import org.hibernate.SessionFactory;
-
 
60
import org.hibernate.query.NativeQuery;
57
import org.json.JSONArray;
61
import org.json.JSONArray;
58
import org.json.JSONObject;
62
import org.json.JSONObject;
59
import org.json.XML;
63
import org.json.XML;
60
import org.springframework.beans.factory.annotation.Autowired;
64
import org.springframework.beans.factory.annotation.Autowired;
61
import org.springframework.beans.factory.annotation.Qualifier;
65
import org.springframework.beans.factory.annotation.Qualifier;
Line 1137... Line 1141...
1137
    @Autowired
1141
    @Autowired
1138
    StandAlone standAlone;
1142
    StandAlone standAlone;
1139
 
1143
 
1140
    public void test() throws Exception {
1144
    public void test() throws Exception {
1141
        try {
1145
        try {
1142
            standAlone.checkOppoImeiStatus();
1146
            checkAllPayoutsDuplicate();
1143
        } catch (Throwable e) {
1147
        } catch (Throwable e) {
1144
            throw new Exception(e);
1148
            throw new Exception(e);
1145
        }
1149
        }
1146
 
1150
 
1147
        //this.sendMailForSamsungRebilling();
1151
        //this.sendMailForSamsungRebilling();
Line 1155... Line 1159...
1155
        //this.sendMailForAgeingAlert();
1159
        //this.sendMailForAgeingAlert();
1156
        //System.out.println(brandRegionMappingRepository.getAvailabilityToVendorWarehouse(Arrays.asList(33353), 7720));
1160
        //System.out.println(brandRegionMappingRepository.getAvailabilityToVendorWarehouse(Arrays.asList(33353), 7720));
1157
 
1161
 
1158
    }
1162
    }
1159
 
1163
 
-
 
1164
    @Autowired
-
 
1165
    SessionFactory sessionFactory;
-
 
1166
 
-
 
1167
    private void checkAllPayoutsDuplicate() throws Exception {
-
 
1168
        final Session session = sessionFactory.getCurrentSession();
-
 
1169
        final NativeQuery<Object[]> nativeQuery = session.createNativeQuery("select sio.inventory_item_id, sio.scheme_id, sio.status, count(*) c\n" +
-
 
1170
                "from fofo.scheme_in_out sio\n" +
-
 
1171
                "         join catalog.scheme s on s.id = sio.scheme_id\n" +
-
 
1172
                "where (sio.status = 'CREDITED'\n" +
-
 
1173
                "    or sio.status = 'PENDING')\n" +
-
 
1174
                "  and s.type != 'INVESTMENT'\n" +
-
 
1175
                " and sio.create_timestamp >= '2023-01-01' " +
-
 
1176
                "group by sio.inventory_item_id, sio.scheme_id, sio.status\n" +
-
 
1177
                "having c > 1");
-
 
1178
        List<Object[]> resultList = nativeQuery.getResultList();
-
 
1179
        for (Object[] tuple : resultList) {
-
 
1180
            LOGGER.info("RESULT -- {}, {}, {}", tuple[0], tuple[1], tuple[2]);
-
 
1181
            int inventoryItemId = (Integer) tuple[0];
-
 
1182
            int schemeId = (Integer) tuple[1];
-
 
1183
            SchemePayoutStatus schemePayoutStatus = SchemePayoutStatus.valueOf((String) tuple[2]);
-
 
1184
            List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByScheme(schemeId, inventoryItemId);
-
 
1185
            List<SchemeInOut> statusSpecificSchemeInOuts = schemeInOuts.stream().filter(x -> x.getStatus().equals(schemePayoutStatus)).collect(Collectors.toList());
-
 
1186
            if (statusSpecificSchemeInOuts.size() > 0) {
-
 
1187
                InventoryItem inventoryItem = inventoryItemRepository.selectById(inventoryItemId);
-
 
1188
                Scheme scheme = schemeRepository.selectById(schemeId);
-
 
1189
                List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(inventoryItemId);
-
 
1190
                if (scheme.getType().equals(SchemeType.IN)) {
-
 
1191
                    LOGGER.info("Skipping -- {}", inventoryItem.getSerialNumber());
-
 
1192
                } else {
-
 
1193
                    int fofoOrderId = scanRecords.stream().filter(x -> x.getOrderId() != 0).max(Comparator.comparing(x -> x.getOrderId())).get().getOrderId();
-
 
1194
                    WalletReferenceType walletReferenceType = SchemeType.ACTIVATION.equals(scheme.getType()) ? WalletReferenceType.ACTIVATION_SCHEME : SchemeType.SPECIAL_SUPPORT.equals(scheme.getType()) ? WalletReferenceType.SPECIAL_SUPPORT : WalletReferenceType.SCHEME_OUT;
-
 
1195
                    List<UserWalletHistory> userWalletHistoryList = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(fofoOrderId, walletReferenceType).stream().filter(x -> x.getAmount() == Math.round(statusSpecificSchemeInOuts.get(0).getAmount())).collect(Collectors.toList());
-
 
1196
                    LOGGER.info("UserwalletHistory Entry --> {}, Sios --> {}", userWalletHistoryList.size(), statusSpecificSchemeInOuts.size());
-
 
1197
                    if (userWalletHistoryList.size() != statusSpecificSchemeInOuts.size()) {
-
 
1198
                        //Skipping them in first run as it is the special casw of upgrade where mismatch has happend.
-
 
1199
                        LOGGER.info("problem with {}, sio status - {}, inventoryItem id {}, schemeID {} ", fofoOrderId, statusSpecificSchemeInOuts.stream().map(x -> x.getStatus()).collect(Collectors.toList()), inventoryItemId, schemeId);
-
 
1200
                        //Primarily multiple pending cases
-
 
1201
                        statusSpecificSchemeInOuts.stream().skip(1).forEach(schemeInOut -> {
-
 
1202
                            schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
-
 
1203
                            schemeInOut.setStatusDescription("Rejected as entry is duplicate");
-
 
1204
                        });
-
 
1205
                    } else {
-
 
1206
                        userWalletHistoryList.stream().skip(1).forEach(userWalletHistory -> {
-
 
1207
                            try {
-
 
1208
                                walletService.rollbackAmountFromWallet(inventoryItem.getFofoId(), userWalletHistory.getAmount(), userWalletHistory.getReference(), userWalletHistory.getReferenceType(), "Reversal as multiple entries created", userWalletHistory.getBusinessTimestamp());
-
 
1209
                            } catch (ProfitMandiBusinessException e) {
-
 
1210
                                throw new RuntimeException(e);
-
 
1211
                            }
-
 
1212
                        });
-
 
1213
 
-
 
1214
                        statusSpecificSchemeInOuts.stream().skip(1).forEach(schemeInOut -> {
-
 
1215
                            schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
-
 
1216
                            if (schemePayoutStatus.equals(SchemePayoutStatus.CREDITED)) {
-
 
1217
                                schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
-
 
1218
                                schemeInOut.setStatusDescription("Rolled back as entry is duplicate");
-
 
1219
                            } else {
-
 
1220
                                LOGGER.info("This seems higly unreachable should not come here");
-
 
1221
                                schemeInOut.setStatusDescription("Rejected as entry is duplicate");
-
 
1222
                            }
-
 
1223
                        });
-
 
1224
                    }
-
 
1225
                }
-
 
1226
            }
-
 
1227
        }
-
 
1228
    }
-
 
1229
 
1160
    public void test1() throws Exception {
1230
    public void test1() throws Exception {
1161
        System.out.println("Starting test");
1231
        System.out.println("Starting test");
1162
        processScheme(LocalDate.of(2023, 05, 06).atStartOfDay(), LocalDate.of(2023, 05, 9).atStartOfDay(), false);
1232
        processScheme(LocalDate.of(2023, 05, 06).atStartOfDay(), LocalDate.of(2023, 05, 9).atStartOfDay(), false);
1163
        /*partnerTypeChangeService.getTypeOnDate(175139287, LocalDate.of(2023,02, 01));
1233
        /*partnerTypeChangeService.getTypeOnDate(175139287, LocalDate.of(2023,02, 01));
1164
        partnerTypeChangeService.getTypeOnDate(175139287, LocalDate.of(2023,03, 01));
1234
        partnerTypeChangeService.getTypeOnDate(175139287, LocalDate.of(2023,03, 01));
Line 1201... Line 1271...
1201
    public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
1271
    public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
1202
        LocalDate yesterDay = LocalDate.now().minusDays(1);
1272
        LocalDate yesterDay = LocalDate.now().minusDays(1);
1203
        List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1273
        List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1204
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
1274
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
1205
 
1275
 
1206
        List<String> headers = Arrays.asList("Code", "Outlet name", "State Manager", "Teritory/Team Lead", "Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount", "Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty", "Short Days");
1276
        List<String> headers = Arrays.asList("Code", "Outlet name", "State Manager", "Territory/Team Lead", "Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount", "Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty", "Short Days");
1207
        List<List<?>> rows = new ArrayList<>();
1277
        List<List<?>> rows = new ArrayList<>();
1208
        Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
1278
        Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
1209
 
1279
 
1210
        Map<Integer, FofoReportingModel> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
1280
        Map<Integer, FofoReportingModel> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
1211
 
1281
 
Line 4172... Line 4242...
4172
        }
4242
        }
4173
 
4243
 
4174
    }
4244
    }
4175
 
4245
 
4176
    private String getMessageHygieneAlertForPartner(
4246
    private String getMessageHygieneAlertForPartner(
4177
                                                    Map<Integer, Map<YearMonth, List<HygieneData>>> partnerYearMonthData, Map<Integer, Map<LocalDate, List<HygieneData>>> partnerDateWiseData) {
4247
            Map<Integer, Map<YearMonth, List<HygieneData>>> partnerYearMonthData, Map<Integer, Map<LocalDate, List<HygieneData>>> partnerDateWiseData) {
4178
 
4248
 
4179
        Map<Integer, CustomRetailer> customeRetailerMap = retailerService.getAllFofoRetailers();
4249
        Map<Integer, CustomRetailer> customeRetailerMap = retailerService.getAllFofoRetailers();
4180
 
4250
 
4181
        LocalDateTime startDate = LocalDate.now().withDayOfMonth(1).atStartOfDay();
4251
        LocalDateTime startDate = LocalDate.now().withDayOfMonth(1).atStartOfDay();
4182
        LocalDateTime endDate = LocalDateTime.now();
4252
        LocalDateTime endDate = LocalDateTime.now();