TASK:mixi;

This commit is contained in:
shahaibo
2024-09-14 19:29:26 +08:00
parent 47a6e9d23b
commit a39c60b5e5
8 changed files with 317 additions and 202 deletions

View File

@@ -28,6 +28,7 @@ import org.springframework.retry.annotation.Retryable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
@@ -79,9 +80,9 @@ public class MiTuExportScheduledTask {
// WeeklyHeavyStockReport();
// QuarterlyProductGroupingReport();
// customerTypeAnalysis();
// getBestSell();
getBestSell30Days();
// getData();
// runDailySalesIncentiveStatisticsForPast30Days();
runDailySalesIncentiveStatisticsForPast30Days();
// updateProductStock();
}
@@ -179,89 +180,27 @@ public class MiTuExportScheduledTask {
// today = today.minusDays(1);
// }
private void getBestSell30Days() {
LocalDate today = LocalDate.now();
for (int i = 0; i < 30; i++) {
today = today.minusDays(1);
getBestSell(today);
}
}
@Scheduled(cron = "0 0 1 * * ?")
private void getBestSell() {
QueryWrapper<TProduct> bestSellIsNotNull = new QueryWrapper<>();
// bestSellIsNotNull.lambda().isNotNull(TProduct::getBestSell);
List<TProduct> productListAll = productMapper.selectList(bestSellIsNotNull);
private void getBestSell1Day() {
LocalDate today = LocalDate.now();
for (int i = 0; i < 1; i++) {
// 将这一天的商品销售数量入库
miTuProductSellNumEntry(today, productListAll);
today = today.minusDays(1);
getBestSell(today);
}
// for (TProduct tProduct : productList1) {
// tProduct.setBestSell(null);
// productMapper.updateById(tProduct);
// }
// Map<String, List<String>> itemNameMap = getBestSellItemNameList();
// for (String s : itemNameMap.keySet()) {
// if (s.equals("yesterdayItemNameList")) {
// QueryWrapper<MiTuProduct> qw = new QueryWrapper<>();
// qw.lambda().in(MiTuProduct::getItemName, itemNameMap.get(s));
// List<MiTuProduct> miTuProductList = miTuProductMapper.selectList(qw);
// if (!CollectionUtils.isEmpty(miTuProductList)) {
// Set<Long> collect = miTuProductList.stream().map(MiTuProduct::getProductId).collect(Collectors.toSet());
// if (!CollectionUtils.isEmpty(collect)) {
// QueryWrapper<TProduct> qwBestSell = new QueryWrapper<>();
// qwBestSell.lambda().in(TProduct::getId, new ArrayList<>(collect));
// List<TProduct> productList = productMapper.selectList(qwBestSell);
// if (!CollectionUtils.isEmpty(productList)) {
// for (TProduct tProduct : productList) {
// tProduct.setBestSell("1");
// productMapper.updateById(tProduct);
// }
// }
// }
// }
// }
// if (s.equals("lastWeekItemNameList")) {
// QueryWrapper<MiTuProduct> qw = new QueryWrapper<>();
// qw.lambda().in(MiTuProduct::getItemName, itemNameMap.get(s));
// List<MiTuProduct> miTuProductList = miTuProductMapper.selectList(qw);
// if (!CollectionUtils.isEmpty(miTuProductList)) {
// Set<Long> collect = miTuProductList.stream().map(MiTuProduct::getProductId).collect(Collectors.toSet());
// if (!CollectionUtils.isEmpty(collect)) {
// QueryWrapper<TProduct> qwBestSell = new QueryWrapper<>();
// qwBestSell.lambda().in(TProduct::getId, new ArrayList<>(collect));
// List<TProduct> productList = productMapper.selectList(qwBestSell);
// if (!CollectionUtils.isEmpty(productList)) {
// for (TProduct tProduct : productList) {
// if (StringUtils.isEmpty(tProduct.getBestSell())) {
// tProduct.setBestSell("2");
// }else {
// tProduct.setBestSell(tProduct.getBestSell() + ",2");
// }
// productMapper.updateById(tProduct);
// }
// }
// }
// }
// }
// if (s.equals("lastMonthItemNameList")) {
// QueryWrapper<MiTuProduct> qw = new QueryWrapper<>();
// qw.lambda().in(MiTuProduct::getItemName, itemNameMap.get(s));
// List<MiTuProduct> miTuProductList = miTuProductMapper.selectList(qw);
// if (!CollectionUtils.isEmpty(miTuProductList)) {
// Set<Long> collect = miTuProductList.stream().map(MiTuProduct::getProductId).collect(Collectors.toSet());
// if (!CollectionUtils.isEmpty(collect)) {
// QueryWrapper<TProduct> qwBestSell = new QueryWrapper<>();
// qwBestSell.lambda().in(TProduct::getId, new ArrayList<>(collect));
// List<TProduct> productList = productMapper.selectList(qwBestSell);
// if (!CollectionUtils.isEmpty(productList)) {
// for (TProduct tProduct : productList) {
// if (StringUtils.isEmpty(tProduct.getBestSell())) {
// tProduct.setBestSell("3");
// }else {
// tProduct.setBestSell(tProduct.getBestSell() + ",3");
// }
// productMapper.updateById(tProduct);
// }
// }
// }
// }
// }
// }
}
private void getBestSell(LocalDate today) {
QueryWrapper<TProduct> bestSellIsNotNull = new QueryWrapper<>();
List<TProduct> productListAll = productMapper.selectList(bestSellIsNotNull);
miTuProductSellNumEntry(today, productListAll);
}
private void miTuProductSellNumEntry(LocalDate today, List<TProduct> productListAll) {
@@ -642,6 +581,7 @@ public class MiTuExportScheduledTask {
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Weekly Sell Through Report");
// 创建表头
Row headerRow = sheet.createRow(0);
String[] headers = {"PLU_CODE", "ToShopDate", "SalesDay", "CATEGORY", "SUB_CAT", "ItemName",
"PriceOriginal", "ToRetailQty", "TotalSaleNum", "MAS_count", "MEL_count",
@@ -653,7 +593,6 @@ public class MiTuExportScheduledTask {
int rowNum = 1;
int startRow = rowNum;
String previousPluCode = "";
String imagePath = "";
Session session = null;
@@ -672,61 +611,61 @@ public class MiTuExportScheduledTask {
channelSftp = (ChannelSftp) session.openChannel("sftp");
channelSftp.connect();
for (TransactionSummary summary : transactionSummaryList) {
String currentPluCode = summary.getPLU_CODE();
if (!currentPluCode.equals(previousPluCode)) {
imagePath = getImagePath(summary.getPLU_CODE());
// 遍历数据并生成行
if (transactionSummaryList.size() > 0) {
String previousPluCode = transactionSummaryList.get(0).getPLU_CODE();
for (TransactionSummary summary : transactionSummaryList) {
String currentPluCode = summary.getPLU_CODE();
if (!currentPluCode.equals(previousPluCode)) {
imagePath = getImagePath(previousPluCode);
// 判断 imagePath 是否为空
if (imagePath != null && !imagePath.isEmpty()) {
// 合并单元格并插入图片或占位符
if (startRow < rowNum) {
mergeCells(sheet, startRow, rowNum - 1);
linkImageToCell(workbook, sheet, startRow, rowNum - 1, headers.length - 1, imagePath, channelSftp);
}
} else {
System.out.println("Image path is empty for PLU_CODE: " + currentPluCode);
// 在这里可以添加其他处理逻辑,例如记录日志或使用默认图片
startRow = rowNum;
previousPluCode = currentPluCode;
}
startRow = rowNum;
previousPluCode = currentPluCode;
// 创建每一行并填充数据
Row row = sheet.createRow(rowNum);
row.createCell(0).setCellValue(summary.getPLU_CODE());
row.createCell(1).setCellValue(summary.getToShopDate() != null ? summary.getToShopDate().toString() : "");
row.createCell(2).setCellValue(summary.getSalesDay());
row.createCell(3).setCellValue(summary.getCATEGORY());
row.createCell(4).setCellValue(summary.getSUB_CAT());
row.createCell(5).setCellValue(summary.getItemName());
row.createCell(6).setCellValue(summary.getPriceOriginal());
row.createCell(7).setCellValue(summary.getToRetailQty());
row.createCell(8).setCellValue(summary.getTotalSaleNum());
row.createCell(9).setCellValue(summary.getMAS_count());
row.createCell(10).setCellValue(summary.getMEL_count());
row.createCell(11).setCellValue(summary.getMPC_count());
row.createCell(12).setCellValue(summary.getMPS_count());
row.createCell(13).setCellValue(summary.getMTF_count());
row.createCell(14).setCellValue(summary.getMWP_count());
row.createCell(15).setCellValue(summary.getMYO_count());
row.createCell(16).setCellValue(summary.getLwSalesQty());
row.createCell(17).setCellValue(summary.getRetailOnHand());
row.createCell(18).setCellValue(summary.getSalesRate());
rowNum++;
}
// 处理最后一个PLU_CODE的数据
if (startRow < rowNum) {
mergeCells(sheet, startRow, rowNum - 1);
linkImageToCell(workbook, sheet, startRow, rowNum - 1, headers.length - 1, imagePath, channelSftp);
}
Row row = sheet.createRow(rowNum);
row.createCell(0).setCellValue(summary.getPLU_CODE());
// 填充其他列的数据
row.createCell(1).setCellValue(summary.getToShopDate() != null ? summary.getToShopDate().toString() : "");
row.createCell(2).setCellValue(summary.getSalesDay());
row.createCell(3).setCellValue(summary.getCATEGORY());
row.createCell(4).setCellValue(summary.getSUB_CAT());
row.createCell(5).setCellValue(summary.getItemName());
row.createCell(6).setCellValue(summary.getPriceOriginal());
row.createCell(7).setCellValue(summary.getToRetailQty());
row.createCell(8).setCellValue(summary.getTotalSaleNum());
row.createCell(9).setCellValue(summary.getMAS_count());
row.createCell(10).setCellValue(summary.getMEL_count());
row.createCell(11).setCellValue(summary.getMPC_count());
row.createCell(12).setCellValue(summary.getMPS_count());
row.createCell(13).setCellValue(summary.getMTF_count());
row.createCell(14).setCellValue(summary.getMWP_count());
row.createCell(15).setCellValue(summary.getMYO_count());
row.createCell(16).setCellValue(summary.getLwSalesQty());
row.createCell(17).setCellValue(summary.getRetailOnHand());
row.createCell(18).setCellValue(summary.getSalesRate());
rowNum++;
}
// 处理最后一个PLU_CODE的数据
if (startRow < rowNum) {
mergeCells(sheet, startRow, rowNum - 1);
linkImageToCell(workbook, sheet, startRow, rowNum - 1, headers.length - 1, imagePath, channelSftp);
}
// 保存文件
try (FileOutputStream outputStream = new FileOutputStream(file)) {
workbook.write(outputStream);
}
// 上传文件到MinIO
FileItem a = getMultipartFile(file, file.getName());
MultipartFile multipartFile = new CommonsMultipartFile(a);
minioUtil.upload("mi-tu", "export", multipartFile);
@@ -846,6 +785,7 @@ public class MiTuExportScheduledTask {
}
} catch (Exception e) {
log.info(imagePath);
throw new RuntimeException("Error while processing the report", e);
} finally {
if (channelSftp != null && channelSftp.isConnected()) {
@@ -865,6 +805,19 @@ public class MiTuExportScheduledTask {
minioUtil.upload("mi-tu", "export", multipartFile);
}
private boolean doesFileExist(ChannelSftp channelSftp, String path) {
try {
channelSftp.lstat(path);
return true;
} catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
return false;
} else {
throw new RuntimeException("Error while checking file existence: " + path, e);
}
}
}
@@ -1070,11 +1023,35 @@ public class MiTuExportScheduledTask {
private void linkImageToCell(Workbook workbook, Sheet sheet, int startRow, int endRow, int colNum, String imagePath, ChannelSftp channelSftp) throws IOException {
try {
if (imagePath == null) {
sheet.setColumnWidth(colNum, 150 * 35); // 设置列宽
for (int i = startRow; i <= endRow; i++) {
if (sheet.getRow(i) == null) {
sheet.createRow(i); // 创建空行
}
sheet.getRow(i).setHeight((short) (150 * 20)); // 设置行高
}
return;
}
String[] split = imagePath.split("\\.");
// 拼接完整路径
String fullPath = "PIC/" + split[0] + ".bmp";
// 下载图片
// 判断SFTP服务器上是否存在图片
if (!doesFileExist(channelSftp, fullPath)) {
System.out.println("Image does not exist: " + fullPath + ", leaving empty placeholder.");
// 设置列宽和行高,但不插入图片,作为空占位符
sheet.setColumnWidth(colNum, 150 * 35); // 设置列宽
for (int i = startRow; i <= endRow; i++) {
if (sheet.getRow(i) == null) {
sheet.createRow(i); // 创建空行
}
sheet.getRow(i).setHeight((short) (150 * 20)); // 设置行高
}
return; // 直接返回,跳过图片插入部分
}
// 下载并插入图片
try (InputStream inputStream = channelSftp.get(fullPath)) {
byte[] bytes = IOUtils.toByteArray(inputStream);
int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
@@ -1083,24 +1060,26 @@ public class MiTuExportScheduledTask {
Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
// 将图片设置为150x150像素的大小并转换为EMU单位
// 设置图片的插入位置和大小
int widthInEMU = 150 * 9525;
int heightInEMU = 150 * 9525;
// 设置图片的插入位置和大小确保只覆盖Image
anchor.setCol1(colNum); // 设置开始列为Image列
anchor.setRow1(startRow); // 设置开始行
anchor.setCol2(colNum); // 设置结束列为Image列不应影响Plu Code列
anchor.setRow2(endRow + 1); // 设置结束行
anchor.setCol1(colNum); // 图片开始
anchor.setRow1(startRow); // 图片开始行
anchor.setCol2(colNum); // 图片结束列
anchor.setRow2(endRow); // 图片结束行
// 设置图片的宽度和高度
anchor.setDx1(0); // 起始点x偏移量
anchor.setDy1(0); // 起始点y偏移量
anchor.setDx2(widthInEMU); // 结束点x偏移量使得图片只占用Image列的空间
anchor.setDy2(heightInEMU); // 结束点y偏移量
anchor.setDx1(0);
anchor.setDy1(0);
anchor.setDx2(widthInEMU);
anchor.setDy2(heightInEMU);
Picture pict = drawing.createPicture(anchor, pictureIdx);
// // 调整图片列的宽度和行的高度
// sheet.setColumnWidth(colNum, 100 * 35); // 设置列宽
// sheet.getRow(startRow).setHeight((short) (heightInEMU / 20)); // 设置行高为图片的高度
// 设置Image列的宽度为150像素
sheet.setColumnWidth(colNum, 150 * 35); // 设置列宽Excel列宽的单位为1/256个字符宽度
@@ -1115,7 +1094,7 @@ public class MiTuExportScheduledTask {
throw new IOException("Failed to download image from SFTP server", e);
}
} catch (Exception e) {
throw new RuntimeException("Error while downloading image from SFTP server", e);
throw new RuntimeException("Error while processing image from SFTP server", e);
}
}
@@ -2627,81 +2606,130 @@ public class MiTuExportScheduledTask {
}
}
@Resource
private TaskRuleMapper taskRuleMapper;
@Resource
private TaskConditionMapper taskConditionMapper;
public void dailySalesIncentiveStatistics(LocalDate localDate) {
// 获取前一日所有商品销售记录
// 全日最高個人生意額 (每日計)
List<Transaction> saleRecordList = getSales(localDate);
if (!CollectionUtils.isEmpty(saleRecordList)) {
Transaction transaction = saleRecordList.get(0);
SalesRecord salesRecord = new SalesRecord();
salesRecord.setSalesmanName(transaction.getSalesmanName());
salesRecord.setIncentiveNum(3);
salesRecord.setTaskId(1);
salesRecordMapper.insert(salesRecord);
TaskRule taskRule1 = taskRuleMapper.selectById(1L);
LocalDateTime startTime = taskRule1.getStartTime();
LocalDateTime endTime = taskRule1.getEndTime();
// 将 LocalDateTime 转换为 LocalDate
LocalDate startDate = startTime.toLocalDate();
LocalDate endDate = endTime.toLocalDate();
// 判断 localDate 是否在 startDate 和 endDate 之间,包括边界
if (!localDate.isBefore(startDate) && !localDate.isAfter(endDate)) {
List<Transaction> saleRecordList = getSales(localDate);
if (!CollectionUtils.isEmpty(saleRecordList)) {
Transaction transaction = saleRecordList.get(0);
SalesRecord salesRecord = new SalesRecord();
salesRecord.setSalesmanName(transaction.getSalesmanName());
salesRecord.setIncentiveNum(taskRule1.getTargetValue());
salesRecord.setTaskId(1);
salesRecord.setCreateTime(LocalDateTime.now());
salesRecordMapper.insert(salesRecord);
}
}
// 全日最高個人銷售件數 (每日計)
List<Transaction> saleRecordList1 = getSalesNumTop(localDate);
if (!CollectionUtils.isEmpty(saleRecordList1)) {
int i = 0;
Transaction transaction = saleRecordList1.get(0);
Integer totalNum = transaction.getTotalNum();
TaskRule taskRule2 = taskRuleMapper.selectById(2L);
startTime = taskRule2.getStartTime();
endTime = taskRule2.getEndTime();
startDate = startTime.toLocalDate();
endDate = endTime.toLocalDate();
if (!localDate.isBefore(startDate) && !localDate.isAfter(endDate)) {
List<Transaction> saleRecordList1 = getSalesNumTop(localDate);
if (!CollectionUtils.isEmpty(saleRecordList1)) {
int i = 0;
Transaction transaction = saleRecordList1.get(0);
Integer totalNum = transaction.getTotalNum();
for (int i1 = 1; i1 < saleRecordList1.size(); i1++) {
if (Objects.equals(saleRecordList1.get(i1).getTotalNum(), totalNum)) {
i ++;
for (int i1 = 1; i1 < saleRecordList1.size(); i1++) {
if (Objects.equals(saleRecordList1.get(i1).getTotalNum(), totalNum)) {
i ++;
}
}
for (int i1 = 0; i1 < i; i1++) {
Transaction transaction1 = saleRecordList1.get(i1);
SalesRecord salesRecord = new SalesRecord();
salesRecord.setSalesmanName(transaction1.getSalesmanName());
salesRecord.setIncentiveNum(taskRule2.getTargetValue());
salesRecord.setTaskId(2);
salesRecord.setCreateTime(LocalDateTime.now());
salesRecordMapper.insert(salesRecord);
}
}
}
for (int i1 = 0; i1 < i; i1++) {
Transaction transaction1 = saleRecordList1.get(i1);
SalesRecord salesRecord = new SalesRecord();
salesRecord.setSalesmanName(transaction1.getSalesmanName());
salesRecord.setIncentiveNum(3);
salesRecord.setTaskId(2);
salesRecordMapper.insert(salesRecord);
// TEA 連身裙销售
TaskRule taskRule3 = taskRuleMapper.selectById(3L);
startTime = taskRule3.getStartTime();
endTime = taskRule3.getEndTime();
startDate = startTime.toLocalDate();
endDate = endTime.toLocalDate();
if (!localDate.isBefore(startDate) && !localDate.isAfter(endDate)) {
List<Transaction> saleRecordList2 = getSalesByCategory(localDate);
if (!CollectionUtils.isEmpty(saleRecordList2)) {
for (Transaction transaction : saleRecordList2) {
SalesRecord salesRecord = new SalesRecord();
salesRecord.setSalesmanName(transaction.getSalesmanName());
salesRecord.setIncentiveNum(taskRule3.getTargetValue() * transaction.getTotalNum());
salesRecord.setTaskId(3);
salesRecord.setCreateTime(LocalDateTime.now());
salesRecordMapper.insert(salesRecord);
}
}
}
List<Transaction> saleRecordList2 = getSalesByCategory(localDate);
if (!CollectionUtils.isEmpty(saleRecordList2)) {
for (Transaction transaction : saleRecordList2) {
SalesRecord salesRecord = new SalesRecord();
salesRecord.setSalesmanName(transaction.getSalesmanName());
salesRecord.setIncentiveNum(transaction.getTotalNum());
salesRecord.setTaskId(3);
salesRecordMapper.insert(salesRecord);
// 单一发票达 4 件或以上
TaskRule taskRule4 = taskRuleMapper.selectById(4L);
startTime = taskRule4.getStartTime();
endTime = taskRule4.getEndTime();
startDate = startTime.toLocalDate();
endDate = endTime.toLocalDate();
if (!localDate.isBefore(startDate) && !localDate.isAfter(endDate)) {
List<Transaction> saleRecordList3 = getSalesByMultiSelling(localDate);
if (!CollectionUtils.isEmpty(saleRecordList3)) {
for (Transaction transaction : saleRecordList3) {
SalesRecord salesRecord = new SalesRecord();
salesRecord.setSalesmanName(transaction.getSalesmanName());
salesRecord.setIncentiveNum(taskRule4.getTargetValue());
salesRecord.setTaskId(4);
salesRecord.setCreateTime(LocalDateTime.now());
salesRecordMapper.insert(salesRecord);
}
}
}
List<Transaction> saleRecordList3 = getSalesByMultiSelling(localDate);
if (!CollectionUtils.isEmpty(saleRecordList3)) {
for (Transaction transaction : saleRecordList3) {
SalesRecord salesRecord = new SalesRecord();
salesRecord.setSalesmanName(transaction.getSalesmanName());
salesRecord.setIncentiveNum(2);
salesRecord.setTaskId(4);
salesRecordMapper.insert(salesRecord);
// 每日 ad-hoc 指定款式
TaskRule taskRule5 = taskRuleMapper.selectById(5L);
startTime = taskRule5.getStartTime();
endTime = taskRule5.getEndTime();
startDate = startTime.toLocalDate();
endDate = endTime.toLocalDate();
if (!localDate.isBefore(startDate) && !localDate.isAfter(endDate)) {
List<Transaction> saleRecordList4 = getSalesByPluCode(localDate);
if (!CollectionUtils.isEmpty(saleRecordList4)) {
for (Transaction transaction : saleRecordList4) {
SalesRecord salesRecord = new SalesRecord();
salesRecord.setSalesmanName(transaction.getSalesmanName());
salesRecord.setIncentiveNum(taskRule5.getTargetValue());
salesRecord.setTaskId(5);
salesRecord.setCreateTime(LocalDateTime.now());
salesRecordMapper.insert(salesRecord);
}
}
}
List<Transaction> saleRecordList4 = getSalesByPluCode(localDate);
if (!CollectionUtils.isEmpty(saleRecordList4)) {
for (Transaction transaction : saleRecordList4) {
SalesRecord salesRecord = new SalesRecord();
salesRecord.setSalesmanName(transaction.getSalesmanName());
salesRecord.setIncentiveNum(2);
salesRecord.setTaskId(5);
salesRecordMapper.insert(salesRecord);
}
}
}
private List<Transaction> getSalesByPluCode(LocalDate localDate) {
@@ -2726,6 +2754,18 @@ public class MiTuExportScheduledTask {
System.out.println("连接数据库...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
QueryWrapper<TaskCondition> qw = new QueryWrapper<>();
qw.lambda().eq(TaskCondition::getTaskId, 5L);
List<TaskCondition> taskConditionList = taskConditionMapper.selectList(qw);
String pluCodes = null;
if (!CollectionUtils.isEmpty(taskConditionList)) {
pluCodes = taskConditionList.get(0).getConditionValue();
}
String inCondition = null;
if (!StringUtils.isEmpty(pluCodes)) {
inCondition = convertToSQLInCondition(pluCodes);
}
// 执行查询
System.out.println("创建声明...");
stmt = conn.createStatement();
@@ -2738,7 +2778,7 @@ public class MiTuExportScheduledTask {
" FROM V_MZG013\n" +
"WHERE trx_date >= '" + yesterdayStr + "'\n" +
"AND trx_date < '" + todayStr + "')\n" +
"AND plu_code in ('MTDTEAN29367','MTDTEAN29350')";
"AND plu_code in " + inCondition;
ResultSet rs = stmt.executeQuery(sql);
// 处理结果集
@@ -2761,6 +2801,32 @@ public class MiTuExportScheduledTask {
return result;
}
// 将输入字符串转换为SQL IN条件的方法
public static String convertToSQLInCondition(String input) {
// 去除首尾空格,避免意外的空格影响处理
input = input.trim();
// 检查输入是否为空
if (input.isEmpty()) {
return "IN ()"; // 返回空的IN条件
}
// 按逗号分隔输入字符串,如果没有逗号就只返回一个值
String[] values = input.split(",");
StringBuilder sb = new StringBuilder();
sb.append("IN (");
for (int i = 0; i < values.length; i++) {
sb.append("'").append(values[i].trim()).append("'");
if (i < values.length - 1) {
sb.append(", ");
}
}
sb.append(")");
return sb.toString();
}
private List<Transaction> getSalesByMultiSelling(LocalDate localDate) {
// 获取今日日期
LocalDate today = localDate;
@@ -2941,6 +3007,10 @@ public class MiTuExportScheduledTask {
}
private List<Transaction> getSalesByCategory(LocalDate localDate) {
String year = taskConditionMapper.selectById(3).getConditionValue();
String season = taskConditionMapper.selectById(4).getConditionValue();
String category = taskConditionMapper.selectById(5).getConditionValue();
// 获取今日日期
LocalDate today = localDate;
@@ -2973,9 +3043,9 @@ public class MiTuExportScheduledTask {
"WHERE trx_no in (SELECT trx_no FROM V_MZG013\n" +
"WHERE trx_date >= '" + yesterdayStr + "'\n" +
"AND trx_date < '" + todayStr + "')\n" +
"AND YEAR = 'TE'\n" +
"AND SEASON = 'A'\n" +
"AND CATEGORY = 'ONE PIECE'\n" +
"AND YEAR = '" + year + "'\n" +
"AND SEASON = '" + season + "'\n" +
"AND CATEGORY = '" + category + "'\n" +
"GROUP BY saleman_name\n" +
"ORDER BY total_count desc";

View File

@@ -22,6 +22,10 @@ public class TaskRule implements Serializable {
private Integer isDeleted = 0;
private LocalDateTime startTime;
private LocalDateTime endTime;
private LocalDateTime createTime;
private LocalDateTime updateTime;

View File

@@ -29,4 +29,8 @@ public class AppNewProductVO {
@ApiModelProperty("颜色,rgb值,下划线分割")
private String rgb;
private String pluCode;
private int isSoldOut;
}

View File

@@ -49,6 +49,8 @@ public class ProductVO {
@ApiModelProperty("商品md5值")
private String md5;
private String pluCode;
@ApiModelProperty("商品标签信息 数组")
private List<ProductLabelVO> productLabelInfo;

View File

@@ -609,11 +609,11 @@ public class TAppProductService extends ServiceImpl<TProductMapper, TProduct> {
// 分页数据
QueryWrapper<TProduct> queryWrapper = new QueryWrapper<>();
if (!StringUtils.isEmpty(query.getStoreId())) {
List<Long> productIds= tProductStockService.findByStoreIds(Collections.singletonList(query.getStoreId()));
if(CollectionUtils.isEmpty(productIds)){
return PageBaseResponse.success(new Page<>());
}
queryWrapper.in("id", productIds);
// List<Long> productIds= tProductStockService.findByStoreIds(Collections.singletonList(query.getStoreId()));
// if(CollectionUtils.isEmpty(productIds)){
// return PageBaseResponse.success(new Page<>());
// }
// queryWrapper.in("id", productIds);
}else{
//查询用户店铺
List<StoreVO> storeVOS = storeService.queryUserStore(null, null);
@@ -688,11 +688,32 @@ public class TAppProductService extends ServiceImpl<TProductMapper, TProduct> {
AppNewProductVO result = CopyUtil.copyObject(product, AppNewProductVO.class);
result.setId(product.getId().toString());
result.setPictureUrl(minioUtil.getPresignedUrl(result.getPictureUrl(), 24 * 60));
QueryWrapper<MiTuProduct> qw = new QueryWrapper<>();
qw.lambda().eq(MiTuProduct::getProductId, result.getId());
List<MiTuProduct> miTuProductList = miTuProductMapper.selectList(qw);
result.setPluCode(miTuProductList.get(0).getPluCode());
result.setProductLabelInfo(CopyUtil.copyList(productToLabelMap.get(product.getId()),ProductLabelVO.class,(o,d) ->{
d.setId(o.getLabelId().toString());
d.setName(labelMap.get(o.getLabelId()).getName());
d.setType(labelMap.get(o.getLabelId()).getType());
}));
if (!StringUtils.isEmpty(query.getStoreId())) {
QueryWrapper<TProductStock> productStockQueryWrapper = new QueryWrapper<>();
productStockQueryWrapper.lambda().eq(TProductStock::getStoreId, query.getStoreId());
productStockQueryWrapper.lambda().eq(TProductStock::getProductId, result.getId());
productStockQueryWrapper.lambda().orderByDesc(TProductStock::getCreateDate);
List<TProductStock> list = tProductStockService.list(productStockQueryWrapper);
if (CollectionUtils.isEmpty(list)) {
result.setIsSoldOut(1);
}else {
TProductStock tProductStock = list.get(0);
if (tProductStockService.hasPositiveStock(tProductStock)) {
result.setIsSoldOut(0);
}else {
result.setIsSoldOut(1);
}
}
}
return result;
});
return PageBaseResponse.success(convert);

View File

@@ -233,6 +233,7 @@ public class TProductService extends ServiceImpl<TProductMapper, TProduct> {
result.setStoreInfoList(resolveStoreInfo(productToStoreMap.get(product.getId()), storeIdToNameMap));
result.setAssortmentList(resolveProductAssortmentInfo(tProductAssortmentsMap.get(product.getId()), productIdToPriceMap));
result.setPictureUrl(minioUtil.getPresignedUrl(result.getPictureUrl(), 24 * 60));
result.setPluCode(getPluCodeByProductId(result.getId()));
return result;
});
return PageBaseResponse.success(convert);
@@ -535,9 +536,20 @@ public class TProductService extends ServiceImpl<TProductMapper, TProduct> {
result.setStoreInfoList(resolveStoreInfo(productStocks, storeIdToNameMap));
result.setAssortmentList(resolveProductAssortmentInfo(tProductAssortments,productIdToPriceMap));
result.setPictureUrl(minioUtil.getPresignedUrl(result.getPictureUrl(), 24 * 60));
result.setPluCode(getPluCodeByProductId(result.getId()));
return result;
}
private String getPluCodeByProductId(String id) {
QueryWrapper<MiTuProduct> qw = new QueryWrapper<>();
qw.lambda().eq(MiTuProduct::getProductId, id);
List<MiTuProduct> miTuProductList = miTuProductMapper.selectList(qw);
if (CollectionUtils.isEmpty(miTuProductList)) {
return null;
}
return miTuProductList.get(0).getPluCode();
}
private List<List<ProductAssortmentVO>> resolveProductAssortmentInfo(List<TProductAssortment> tProductAssortments,Map<Long, BigDecimal> productIdToPriceMap) {
List<List<ProductAssortmentVO>> returnProducts = Lists.newArrayList();
Map<Integer,List<TProductAssortment>> tProductAssortmentsMap = CollectionUtil.emptyIfNull(tProductAssortments).stream().collect(

View File

@@ -60,7 +60,9 @@ public class TProductStockService extends ServiceImpl<TProductStockMapper, TProd
}
// 判断 stock_content 中是否有 num > 0
private boolean hasPositiveStock(TProductStock productStock) {
public boolean hasPositiveStock(TProductStock productStock) {
List<Map<String, Object>> stockContent;
try {
stockContent = new ObjectMapper().readValue(productStock.getStockContent(), new TypeReference<List<Map<String, Object>>>() {});

View File

@@ -65,11 +65,11 @@ public class SalesIncentivesServiceImpl extends ServiceImpl<TaskRuleMapper, Task
}else {
taskRuleMapper.updateById(taskRule);
deleteBatchByTaskId(taskRule.getId());
// deleteBatchByTaskId(taskRule.getId());
List<TaskCondition> taskConditionList = CopyUtil.copyList(taskRuleDTO.getTaskConditionList(), TaskCondition.class);
for (TaskCondition taskCondition : taskConditionList) {
taskConditionMapper.insert(taskCondition);
taskConditionMapper.updateById(taskCondition);
}
}
return Boolean.TRUE;