TASK:mixi;

This commit is contained in:
shahaibo
2024-05-07 16:05:19 +08:00
parent 1de9d4a8d9
commit 90862b2a0f

View File

@@ -11,6 +11,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable; import org.springframework.retry.annotation.Retryable;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
@@ -316,24 +317,28 @@ public class MiTuExportScheduledTask {
* Customer purchase report * Customer purchase report
*/ */
@Retryable(value = Exception.class, maxAttempts = 3, backoff = @Backoff(delay = 1000)) @Retryable(value = Exception.class, maxAttempts = 3, backoff = @Backoff(delay = 1000))
@Scheduled(cron = "0 0 23 L * ? *") @Scheduled(cron = "0 0 23 28-31 * ?")
public void customerPurchaseReport() { public void customerPurchaseReport() {
MiTuExport miTuExport = createMiTuExport("Customer purchase report", "month"); final Calendar c = Calendar.getInstance();
try { //如果是最后一天 则执行定时任务
List<TransactionData> transactionData = retrieveTransactionData(); if (c.get(Calendar.DATE) == c.getActualMaximum(Calendar.DATE)) {
List<String> userMembers = transactionData.stream().map(TransactionData::getUserMember).collect(Collectors.toList()); MiTuExport miTuExport = createMiTuExport("Customer purchase report", "month");
List<CustomerData> customerData = retrieveCustomerData(userMembers); try {
updateCustomerDataWithTransactionData(customerData, transactionData); List<TransactionData> transactionData = retrieveTransactionData();
String filePath = miTuExport.getExportName()+".xlsx"; List<String> userMembers = transactionData.stream().map(TransactionData::getUserMember).collect(Collectors.toList());
exportToExcelCustomerPurchaseReport(customerData, filePath); List<CustomerData> customerData = retrieveCustomerData(userMembers);
miTuExport.setUrl("mi-tu/export/" + filePath); updateCustomerDataWithTransactionData(customerData, transactionData);
miTuExport.setStatus(1); String filePath = miTuExport.getExportName()+".xlsx";
} catch (Exception e) { exportToExcelCustomerPurchaseReport(customerData, filePath);
miTuExport.setStatus(0); miTuExport.setUrl("mi-tu/export/" + filePath);
e.printStackTrace(); miTuExport.setStatus(1);
} finally { } catch (Exception e) {
miTuExportMapper.insert(miTuExport); miTuExport.setStatus(0);
System.out.println("接口执行完成!"); e.printStackTrace();
} finally {
miTuExportMapper.insert(miTuExport);
System.out.println("接口执行完成!");
}
} }
} }
@@ -703,7 +708,7 @@ public class MiTuExportScheduledTask {
System.out.println("接口执行完成!"); System.out.println("接口执行完成!");
} }
} }
@Bean
public String calculateLastDayOfQuarterCron() { public String calculateLastDayOfQuarterCron() {
// 获取当前日期 // 获取当前日期
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();