| 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.time.LocalDate;
|
4 |
import java.time.LocalDate;
|
| 4 |
import java.time.LocalDateTime;
|
5 |
import java.time.LocalDateTime;
|
| 5 |
import java.time.LocalTime;
|
6 |
import java.time.LocalTime;
|
| - |
|
7 |
import java.util.ArrayList;
|
| 6 |
import java.util.Arrays;
|
8 |
import java.util.Arrays;
|
| 7 |
import java.util.Collections;
|
9 |
import java.util.Collections;
|
| 8 |
import java.util.List;
|
10 |
import java.util.List;
|
| 9 |
import java.util.Map;
|
11 |
import java.util.Map;
|
| 10 |
import java.util.stream.Collectors;
|
12 |
import java.util.stream.Collectors;
|
| 11 |
|
13 |
|
| - |
|
14 |
import javax.mail.internet.InternetAddress;
|
| - |
|
15 |
import javax.mail.internet.MimeMessage;
|
| - |
|
16 |
|
| - |
|
17 |
import org.apache.commons.io.FileUtils;
|
| 12 |
import org.apache.commons.lang.StringUtils;
|
18 |
import org.apache.commons.lang.StringUtils;
|
| 13 |
import org.apache.logging.log4j.LogManager;
|
19 |
import org.apache.logging.log4j.LogManager;
|
| 14 |
import org.apache.logging.log4j.Logger;
|
20 |
import org.apache.logging.log4j.Logger;
|
| 15 |
import org.apache.poi.util.SystemOutLogger;
|
- |
|
| 16 |
import org.springframework.beans.factory.annotation.Autowired;
|
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
22 |
import org.springframework.mail.javamail.JavaMailSender;
|
| - |
|
23 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 17 |
import org.springframework.stereotype.Component;
|
24 |
import org.springframework.stereotype.Component;
|
| 18 |
import org.springframework.transaction.annotation.Transactional;
|
25 |
import org.springframework.transaction.annotation.Transactional;
|
| 19 |
|
26 |
|
| 20 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
27 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| - |
|
28 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 21 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
29 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 22 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
30 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 23 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
31 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
| 24 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
32 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
| 25 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
33 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| Line 41... |
Line 49... |
| 41 |
|
49 |
|
| 42 |
@Autowired
|
50 |
@Autowired
|
| 43 |
private LineItemRepository lineItemRepository;
|
51 |
private LineItemRepository lineItemRepository;
|
| 44 |
|
52 |
|
| 45 |
@Autowired
|
53 |
@Autowired
|
| - |
|
54 |
private JavaMailSender mailSender;
|
| - |
|
55 |
|
| - |
|
56 |
@Autowired
|
| 46 |
private WalletService walletService;
|
57 |
private WalletService walletService;
|
| 47 |
|
58 |
|
| 48 |
@Autowired
|
59 |
@Autowired
|
| 49 |
private InventoryService inventoryService;
|
60 |
private InventoryService inventoryService;
|
| 50 |
|
61 |
|
| Line 124... |
Line 135... |
| 124 |
}
|
135 |
}
|
| 125 |
LOGGER.info("Migrated LineItems Successfully");
|
136 |
LOGGER.info("Migrated LineItems Successfully");
|
| 126 |
}
|
137 |
}
|
| 127 |
|
138 |
|
| 128 |
public void getInvestmentDetails() throws Exception {
|
139 |
public void getInvestmentDetails() throws Exception {
|
| - |
|
140 |
File f = new File("/tmp/InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()));
|
| - |
|
141 |
List<String> lines = new ArrayList<>();
|
| 129 |
LOGGER.info(
|
142 |
lines.add(
|
| 130 |
"Code\tStoreName\tEmail\tMobile\tminimumInvestment\twalletAmount\tinStockAmount\tunbilledStockAmount\tgrnPendingStockAmount\tTotalInvested");
|
143 |
"Code\tStoreName\tEmail\tMobile\tminimumInvestment\twalletAmount\tinStockAmount\tunbilledStockAmount\tgrnPendingStockAmount\tTotalInvested");
|
| 131 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
144 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
| 132 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
145 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
| 133 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
146 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 134 |
for (FofoStore fofoStore : fofoStores) {
|
147 |
for (FofoStore fofoStore : fofoStores) {
|
| Line 142... |
Line 155... |
| 142 |
for (Order unBilledOrder : unbilledOrders) {
|
155 |
for (Order unBilledOrder : unbilledOrders) {
|
| 143 |
unbilledStockAmount += unBilledOrder.getTotalAmount();
|
156 |
unbilledStockAmount += unBilledOrder.getTotalAmount();
|
| 144 |
}
|
157 |
}
|
| 145 |
|
158 |
|
| 146 |
float grnPendingStockAmount = 0;
|
159 |
float grnPendingStockAmount = 0;
|
| 147 |
List<Order> grnPendingOrders = transactionService.getGrnPendingOrders(fofoStore.getId());
|
160 |
List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoStore.getId());
|
| 148 |
for (Order grnPendingOrder : grnPendingOrders) {
|
161 |
for (Order grnPendingOrder : grnPendingOrders) {
|
| 149 |
grnPendingStockAmount += grnPendingOrder.getTotalAmount();
|
162 |
grnPendingStockAmount += grnPendingOrder.getTotalAmount();
|
| 150 |
}
|
163 |
}
|
| 151 |
float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
|
164 |
float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
|
| 152 |
LOGGER.info(
|
- |
|
| 153 |
String.join("\t", fofoStore.getCode(), retailer.getBusinessName(), retailer.getMobileNumber(),
|
165 |
lines.add(String.join("\t", fofoStore.getCode(), retailer.getBusinessName(), retailer.getMobileNumber(),
|
| 154 |
String.valueOf(fofoStore.getMinimumInvestment()), String.valueOf(walletAmount),
|
166 |
String.valueOf(fofoStore.getMinimumInvestment()), String.valueOf(walletAmount),
|
| 155 |
String.valueOf(inStockAmount), String.valueOf(unbilledStockAmount),
|
167 |
String.valueOf(inStockAmount), String.valueOf(unbilledStockAmount),
|
| 156 |
String.valueOf(grnPendingStockAmount), String.valueOf(totalInvestedAmount)));
|
168 |
String.valueOf(grnPendingStockAmount), String.valueOf(totalInvestedAmount)));
|
| 157 |
} catch (Exception e) {
|
169 |
} catch (Exception e) {
|
| 158 |
e.printStackTrace();
|
170 |
e.printStackTrace();
|
| 159 |
continue;
|
171 |
continue;
|
| 160 |
}
|
172 |
}
|
| - |
|
173 |
FileUtils.writeLines(f, lines);
|
| - |
|
174 |
this.sendMailWithAttachments("amit.gupta@shop2020.in", "Partner Investment Summary", "PFA", Arrays.asList(f));
|
| 161 |
}
|
175 |
}
|
| 162 |
|
176 |
|
| 163 |
}
|
177 |
}
|
| - |
|
178 |
|
| - |
|
179 |
private void sendMailWithAttachments(String email, String subject, String body, List<File> attachments) throws Exception {
|
| - |
|
180 |
|
| - |
|
181 |
MimeMessage message = mailSender.createMimeMessage();
|
| - |
|
182 |
MimeMessageHelper helper = new MimeMessageHelper(message,true);
|
| - |
|
183 |
helper.setSubject(subject);
|
| - |
|
184 |
helper.setText(body);
|
| - |
|
185 |
String[] cc = {"backup@shop2020.in", "gadgetcops.01@gmail.com"};
|
| - |
|
186 |
//String[] cc = {"amit.gupta@shop2020.in"};
|
| - |
|
187 |
helper.setCc(cc);
|
| - |
|
188 |
helper.setTo(email);
|
| - |
|
189 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
|
| - |
|
190 |
helper.setTo("help@smartdukaan.com");
|
| - |
|
191 |
helper.setFrom(senderAddress);
|
| - |
|
192 |
for (File file : attachments) {
|
| - |
|
193 |
helper.addAttachment(file.getName(), file);
|
| - |
|
194 |
}
|
| - |
|
195 |
mailSender.send(message);
|
| - |
|
196 |
|
| - |
|
197 |
}
|
| 164 |
}
|
198 |
}
|
| 165 |
|
199 |
|