|
|
|
|
@@ -1,21 +1,26 @@
|
|
|
|
|
package com.mixi.common.tasks;
|
|
|
|
|
|
|
|
|
|
import com.mixi.common.tasks.mituExportEntity.*;
|
|
|
|
|
import com.mixi.common.utils.MinioUtil;
|
|
|
|
|
import com.mixi.mapper.MiTuExportMapper;
|
|
|
|
|
import com.mixi.mapper.entity.MiTuExport;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import org.apache.commons.fileupload.FileItem;
|
|
|
|
|
import org.apache.commons.fileupload.FileItemFactory;
|
|
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
|
|
|
import org.springframework.retry.annotation.Backoff;
|
|
|
|
|
import org.springframework.retry.annotation.Retryable;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.sql.*;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.DayOfWeek;
|
|
|
|
|
@@ -32,6 +37,9 @@ import java.util.stream.Collectors;
|
|
|
|
|
@Component
|
|
|
|
|
public class MiTuExportScheduledTask {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private MinioUtil minioUtil;
|
|
|
|
|
|
|
|
|
|
static final String JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
|
|
|
|
static final String DB_URL = "jdbc:sqlserver://118.142.0.178:1550;databaseName=Hayman_prod";
|
|
|
|
|
|
|
|
|
|
@@ -45,10 +53,10 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
@PostConstruct
|
|
|
|
|
public void executeWeeklyHeavyStockReport() {
|
|
|
|
|
// customerPurchaseReport();
|
|
|
|
|
// NewJoinVIPReport();
|
|
|
|
|
// weeklySellThrReport();
|
|
|
|
|
// WeeklyHeavyStockReport();
|
|
|
|
|
// QuarterlyProductGroupingReport();
|
|
|
|
|
NewJoinVIPReport();
|
|
|
|
|
weeklySellThrReport();
|
|
|
|
|
WeeklyHeavyStockReport();
|
|
|
|
|
QuarterlyProductGroupingReport();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -63,8 +71,9 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
List<String> userMembers = transactionData.stream().map(TransactionData::getUserMember).collect(Collectors.toList());
|
|
|
|
|
List<CustomerData> customerData = retrieveCustomerData(userMembers);
|
|
|
|
|
updateCustomerDataWithTransactionData(customerData, transactionData);
|
|
|
|
|
String filePath = "C:\\Users\\10233\\Desktop\\MiTuExport\\"+miTuExport.getExportName()+".xlsx";
|
|
|
|
|
String filePath = miTuExport.getExportName()+".xlsx";
|
|
|
|
|
exportToExcelCustomerPurchaseReport(customerData, filePath);
|
|
|
|
|
miTuExport.setUrl("mi-tu/export/" + filePath);
|
|
|
|
|
miTuExport.setStatus(1);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
miTuExport.setStatus(0);
|
|
|
|
|
@@ -147,7 +156,8 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
MiTuExport miTuExport = createMiTuExport("New Join VIP report", "week");
|
|
|
|
|
try {
|
|
|
|
|
List<TransactionNewCustomer> transactionNewCustomerList = getTransactionNewCustomerList();
|
|
|
|
|
String filePath = "C:\\Users\\10233\\Desktop\\MiTuExport\\"+miTuExport.getExportName()+".xlsx";
|
|
|
|
|
String filePath = miTuExport.getExportName()+".xlsx";
|
|
|
|
|
miTuExport.setUrl("mi-tu/export/" + filePath);
|
|
|
|
|
exportNewJoinVIPReport(transactionNewCustomerList, filePath);
|
|
|
|
|
miTuExport.setStatus(1);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
@@ -159,12 +169,11 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void exportNewJoinVIPReport(List<TransactionNewCustomer> transactionNewCustomerList, String filePathName) throws IOException {
|
|
|
|
|
File file = new File(filePathName);
|
|
|
|
|
boolean fileExists = file.exists();
|
|
|
|
|
|
|
|
|
|
// 如果文件不存在,则创建一个新的 Workbook
|
|
|
|
|
Workbook workbook = fileExists ? WorkbookFactory.create(file) : new XSSFWorkbook();
|
|
|
|
|
private void exportNewJoinVIPReport(List<TransactionNewCustomer> transactionNewCustomerList, String filePathName) throws IOException {
|
|
|
|
|
String currentPath = Paths.get("").toAbsolutePath().toString();
|
|
|
|
|
File file = new File(currentPath + "/" + filePathName);
|
|
|
|
|
// 如果文件不存在或者为空,则创建一个新的 Workbook
|
|
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
|
|
|
|
|
|
|
// 创建一个新的 Sheet 或获取现有的 Sheet
|
|
|
|
|
Sheet sheet = workbook.getSheet("Transaction New Customer");
|
|
|
|
|
@@ -207,7 +216,9 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
try (FileOutputStream outputStream = new FileOutputStream(file)) {
|
|
|
|
|
workbook.write(outputStream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileItem a = getMultipartFile(file, file.getName());
|
|
|
|
|
MultipartFile multipartFile = new CommonsMultipartFile(a);
|
|
|
|
|
minioUtil.upload("mi-tu", "export", multipartFile);
|
|
|
|
|
System.out.println("Excel file has been created successfully!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -221,7 +232,8 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
MiTuExport miTuExport = createMiTuExport("weeklySellThrReport", "week");
|
|
|
|
|
try {
|
|
|
|
|
List<TransactionSummary> transactionSummaryList = getTransactionSummaryList();
|
|
|
|
|
String filePath = "C:\\Users\\10233\\Desktop\\MiTuExport\\"+miTuExport.getExportName()+".xlsx";
|
|
|
|
|
String filePath = miTuExport.getExportName()+".xlsx";
|
|
|
|
|
miTuExport.setUrl("mi-tu/export/" + filePath);
|
|
|
|
|
exportWeeklySellThrReport(transactionSummaryList, filePath);
|
|
|
|
|
miTuExport.setStatus(1);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
@@ -233,12 +245,11 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void exportWeeklySellThrReport(List<TransactionSummary> transactionSummaryList, String weeklySellThrReportName) throws IOException {
|
|
|
|
|
File file = new File(weeklySellThrReportName);
|
|
|
|
|
boolean fileExists = file.exists();
|
|
|
|
|
|
|
|
|
|
// 如果文件不存在,则创建一个新的 Workbook
|
|
|
|
|
Workbook workbook = fileExists ? WorkbookFactory.create(file) : new XSSFWorkbook();
|
|
|
|
|
private void exportWeeklySellThrReport(List<TransactionSummary> transactionSummaryList, String filePathName) throws IOException {
|
|
|
|
|
String currentPath = Paths.get("").toAbsolutePath().toString();
|
|
|
|
|
File file = new File(currentPath + "/" + filePathName);
|
|
|
|
|
// 如果文件不存在或者为空,则创建一个新的 Workbook
|
|
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
|
|
|
|
|
|
|
// 创建一个新的 Sheet 或获取现有的 Sheet
|
|
|
|
|
Sheet sheet = workbook.getSheet("Weekly Sell Through Report");
|
|
|
|
|
@@ -305,6 +316,9 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
try (FileOutputStream outputStream = new FileOutputStream(file)) {
|
|
|
|
|
workbook.write(outputStream);
|
|
|
|
|
}
|
|
|
|
|
FileItem a = getMultipartFile(file, file.getName());
|
|
|
|
|
MultipartFile multipartFile = new CommonsMultipartFile(a);
|
|
|
|
|
minioUtil.upload("mi-tu", "export", multipartFile);
|
|
|
|
|
|
|
|
|
|
System.out.println("Excel file has been created successfully!");
|
|
|
|
|
}
|
|
|
|
|
@@ -319,7 +333,8 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
MiTuExport miTuExport = createMiTuExport("WeeklyHeavyStockReport", "week");
|
|
|
|
|
try {
|
|
|
|
|
List<WeeklyHeavyStock> weeklyHeavyStockList = getWeeklyHeavyStockList();
|
|
|
|
|
String filePath = "C:\\Users\\10233\\Desktop\\MiTuExport\\"+miTuExport.getExportName()+".xlsx";
|
|
|
|
|
String filePath = miTuExport.getExportName()+".xlsx";
|
|
|
|
|
miTuExport.setUrl("mi-tu/export/" + filePath);
|
|
|
|
|
exportWeeklyHeavyStock(weeklyHeavyStockList, filePath);
|
|
|
|
|
miTuExport.setStatus(1);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
@@ -331,7 +346,9 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void exportWeeklyHeavyStock(List<WeeklyHeavyStock> weeklyHeavyStockList, String weeklyHeavyStockReportName) {
|
|
|
|
|
private void exportWeeklyHeavyStock(List<WeeklyHeavyStock> weeklyHeavyStockList, String weeklyHeavyStockReportName) {
|
|
|
|
|
String currentPath = Paths.get("").toAbsolutePath().toString();
|
|
|
|
|
File file = new File(currentPath + "/" + weeklyHeavyStockReportName);
|
|
|
|
|
// 创建工作簿
|
|
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
|
|
// 创建工作表
|
|
|
|
|
@@ -386,11 +403,14 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将工作簿写入文件
|
|
|
|
|
try (FileOutputStream outputStream = new FileOutputStream(weeklyHeavyStockReportName)) {
|
|
|
|
|
try (FileOutputStream outputStream = new FileOutputStream(file)) {
|
|
|
|
|
workbook.write(outputStream);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
FileItem a = getMultipartFile(file, file.getName());
|
|
|
|
|
MultipartFile multipartFile = new CommonsMultipartFile(a);
|
|
|
|
|
minioUtil.upload("mi-tu", "export", multipartFile);
|
|
|
|
|
|
|
|
|
|
System.out.println("Excel file has been created successfully!");
|
|
|
|
|
}
|
|
|
|
|
@@ -405,7 +425,8 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
MiTuExport miTuExport = createMiTuExport("Quarterly Product Grouping Report", "week");
|
|
|
|
|
try {
|
|
|
|
|
List<WeeklyHeavyStock> QuarterlyProductGroupingList = getQuarterlyProductGroupingList();
|
|
|
|
|
String filePath = "C:\\Users\\10233\\Desktop\\MiTuExport\\"+miTuExport.getExportName()+".xlsx";
|
|
|
|
|
String filePath = miTuExport.getExportName()+".xlsx";
|
|
|
|
|
miTuExport.setUrl("mi-tu/export/" + filePath);
|
|
|
|
|
exportQuarterlyProductGrouping(QuarterlyProductGroupingList, filePath);
|
|
|
|
|
miTuExport.setStatus(1);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
@@ -417,7 +438,9 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void exportQuarterlyProductGrouping(List<WeeklyHeavyStock> weeklyHeavyStockList, String weeklyHeavyStockReportName) {
|
|
|
|
|
private void exportQuarterlyProductGrouping(List<WeeklyHeavyStock> weeklyHeavyStockList, String weeklyHeavyStockReportName) {
|
|
|
|
|
String currentPath = Paths.get("").toAbsolutePath().toString();
|
|
|
|
|
File file = new File(currentPath + "/" + weeklyHeavyStockReportName);
|
|
|
|
|
// 创建工作簿
|
|
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
|
|
// 创建工作表
|
|
|
|
|
@@ -482,11 +505,14 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将工作簿写入文件
|
|
|
|
|
try (FileOutputStream outputStream = new FileOutputStream(weeklyHeavyStockReportName)) {
|
|
|
|
|
try (FileOutputStream outputStream = new FileOutputStream(file)) {
|
|
|
|
|
workbook.write(outputStream);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
FileItem a = getMultipartFile(file, file.getName());
|
|
|
|
|
MultipartFile multipartFile = new CommonsMultipartFile(a);
|
|
|
|
|
minioUtil.upload("mi-tu", "export", multipartFile);
|
|
|
|
|
|
|
|
|
|
System.out.println("Excel file has been created successfully!");
|
|
|
|
|
}
|
|
|
|
|
@@ -1180,12 +1206,13 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
return transactionNewCustomerList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void exportToExcelCustomerPurchaseReport(List<CustomerData> customerDataList, String filePath) throws IOException {
|
|
|
|
|
File file = new File(filePath);
|
|
|
|
|
boolean fileExists = file.exists() && file.length() > 0; // 检查文件是否存在且非空
|
|
|
|
|
public final static String MITU = "mi-tu";
|
|
|
|
|
|
|
|
|
|
public void exportToExcelCustomerPurchaseReport(List<CustomerData> customerDataList, String fileName) throws IOException {
|
|
|
|
|
String currentPath = Paths.get("").toAbsolutePath().toString();
|
|
|
|
|
File file = new File(currentPath + "/" + fileName);
|
|
|
|
|
// 如果文件不存在或者为空,则创建一个新的 Workbook
|
|
|
|
|
Workbook workbook = fileExists ? WorkbookFactory.create(file) : new XSSFWorkbook();
|
|
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
|
|
|
|
|
|
|
// 创建一个新的 Sheet 或获取现有的 Sheet
|
|
|
|
|
Sheet sheet = workbook.getSheet("Customer Data");
|
|
|
|
|
@@ -1264,10 +1291,46 @@ public class MiTuExportScheduledTask {
|
|
|
|
|
try (FileOutputStream outputStream = new FileOutputStream(file)) {
|
|
|
|
|
workbook.write(outputStream);
|
|
|
|
|
}
|
|
|
|
|
FileItem a = getMultipartFile(file, file.getName());
|
|
|
|
|
MultipartFile multipartFile = new CommonsMultipartFile(a);
|
|
|
|
|
minioUtil.upload("mi-tu", "export", multipartFile);
|
|
|
|
|
|
|
|
|
|
System.out.println("Excel file has been created successfully!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static FileItem getMultipartFile(File file, String fieldName) {
|
|
|
|
|
// 使用 DiskFileItemFactory 创建一个 FileItemFactory
|
|
|
|
|
FileItemFactory factory = new DiskFileItemFactory(16, null);
|
|
|
|
|
|
|
|
|
|
// 使用 FileItemFactory 创建一个 FileItem 对象
|
|
|
|
|
String mimeType = getMimeType(file);
|
|
|
|
|
FileItem item = factory.createItem(fieldName, mimeType, true, file.getName());
|
|
|
|
|
|
|
|
|
|
byte[] buffer = new byte[8192];
|
|
|
|
|
int bytesRead;
|
|
|
|
|
|
|
|
|
|
try (FileInputStream fis = new FileInputStream(file);
|
|
|
|
|
OutputStream os = item.getOutputStream()) {
|
|
|
|
|
// 从文件中读取数据并写入 FileItem
|
|
|
|
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
|
|
|
|
os.write(buffer, 0, bytesRead);
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String getMimeType(File file) {
|
|
|
|
|
try {
|
|
|
|
|
return Files.probeContentType(file.toPath());
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<CustomerData> retrieveCustomerData(List<String> collect) {
|
|
|
|
|
List<CustomerData> customerDataList = new ArrayList<>();
|
|
|
|
|
Connection conn = null;
|
|
|
|
|
|