TASK:mixi;

This commit is contained in:
shahaibo
2024-08-12 12:03:13 +08:00
parent 309322b2e8
commit ac8b327555
7 changed files with 122 additions and 19 deletions

View File

@@ -70,6 +70,14 @@ public enum RolePermissionResourceEnum {
* Mi-Tu 报表
*/
REPORT_EXPORTING("Report Exporting","REPORT_EXPORTING",null,null,null,11),
/**
* 激励规则
*/
MOTIVATIONAL_TASKS("Motivational Tasks","MOTIVATIONAL_TASKS",null,null,null,12),
/**
* 激励排名
*/
MOTIVATIONAL_RANKING("Motivational Ranking","MOTIVATIONAL_RANKING",null,null,null,13),
;
/**

View File

@@ -27,6 +27,7 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.file.Files;
@@ -37,6 +38,7 @@ import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Component
@@ -893,7 +895,7 @@ public class MiTuExportScheduledTask {
}
private void linkImageToCell(Workbook workbook, Sheet sheet, int startRow, int endRow, int colNum, String imagePath) throws IOException {
try (InputStream inputStream = minioUtil.download("mi-tu/26/BOTTOM/PANTS/MKTS27000_0BLK.jpg")) {
try (InputStream inputStream = minioUtil.download("mi-tu/26/BOTTOM/PANTS/MKTS27000_0CMY_copy.jpg")) {
byte[] bytes = IOUtils.toByteArray(inputStream);
int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
@@ -2766,4 +2768,44 @@ public class MiTuExportScheduledTask {
return result;
}
/**
* 压缩图片
* @param inputImagePath 原始图片路径
* @param outputImagePath 压缩后图片保存路径
* @param scaledWidth 压缩后图片的宽度
* @param scaledHeight 压缩后图片的高度
* @throws IOException
*/
// public static void compressImage(String inputImagePath, String outputImagePath, int scaledWidth, int scaledHeight) throws IOException {
// // 读取图片
// BufferedImage inputImage = ImageIO.read(new File(inputImagePath));
//
// // 创建输出图片
// BufferedImage outputImage = new BufferedImage(scaledWidth, scaledHeight, inputImage.getType());
//
// // 绘制缩放后的图片
// Graphics2D g2d = outputImage.createGraphics();
// g2d.drawImage(inputImage.getScaledInstance(scaledWidth, scaledHeight, Image.SCALE_SMOOTH), 0, 0, null);
// g2d.dispose();
//
// // 保存到文件
// ImageIO.write(outputImage, "jpg", new File(outputImagePath));
// }
//
// public static void main(String[] args) {
// String inputImagePath = "C:\\Users\\10233\\Desktop\\2024 SS\\MKTS27000_0CMY.jpg";
// String outputImagePath = "C:\\Users\\10233\\Desktop\\2024 SS\\MKTS27000_0CMY_copy.jpg";
//
// try {
// // 压缩图片到指定大小
// int scaledWidth = 300;
// int scaledHeight = 300;
// compressImage(inputImagePath, outputImagePath, scaledWidth, scaledHeight);
//
// System.out.println("图片压缩完成。");
// } catch (IOException ex) {
// System.out.println("图片压缩出错: " + ex.getMessage());
// }
// }
}

View File

@@ -1,17 +1,12 @@
package com.mixi.service;
import com.mixi.common.response.PageBaseResponse;
import com.mixi.common.response.Response;
import com.mixi.mapper.entity.MiTuExport;
import com.mixi.mapper.entity.MiTuMember;
import com.mixi.model.dto.QueryMiTuExportPageDTO;
import com.mixi.model.vo.MiTuExportVO;
import io.minio.errors.MinioException;
import org.springframework.core.io.InputStreamResource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
@@ -30,5 +25,5 @@ public interface MiTuExportService {
List<MiTuMember> queryMiTuMemberList(String phone);
List<Long> getProductIdsByMiTuMemberCode(String memberCode);
List<Long> getProductIdsByMiTuMemberCode(String memberCode, List<Long> productIds);
}

View File

@@ -163,10 +163,31 @@ public class TAppProductService extends ServiceImpl<TProductMapper, TProduct> {
List<Long> productIds = new ArrayList<>();
List<Long> productIdsByMemberCode = new ArrayList<>(); // 初始化 productIdsByMemberCode
if (!StringUtils.isEmpty(query.getLabelItem())) {
List<Long> byItemAndType = tProductAttributeService.findByItemAndType(query.getLabelItem(), null);
if (CollectionUtils.isEmpty(byItemAndType)) {
return PageBaseResponse.success(new Page<>());
}
productIds.addAll(byItemAndType);
}
if (!StringUtils.isEmpty(query.getStoreId())) {
List<Long> stockProductIdList = tProductStockService.findByStoreIds(Collections.singletonList(query.getStoreId()));
if(CollectionUtils.isEmpty(stockProductIdList)){
return PageBaseResponse.success(new Page<>());
}
if (!StringUtils.isEmpty(query.getLabelItem())) {
productIds.retainAll(stockProductIdList);
}else {
productIds.addAll(stockProductIdList);
}
}
if (!StringUtils.isEmpty(query.getMemberCode())) {
// 获取三页商品ID列表
productIdsByMemberCode = miTuExportService.getProductIdsByMiTuMemberCode(query.getMemberCode());
productIds.addAll(productIdsByMemberCode);
productIdsByMemberCode = miTuExportService.getProductIdsByMiTuMemberCode(query.getMemberCode(), productIds);
// productIds.addAll(productIdsByMemberCode);
productIds = productIdsByMemberCode;
if (CollectionUtils.isEmpty(productIds)) {
return PageBaseResponse.success(new Page<>());
}

View File

@@ -2,6 +2,9 @@ package com.mixi.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mixi.mapper.TProductStockMapper;
import com.mixi.mapper.entity.TProduct;
import com.mixi.mapper.entity.TProductLabel;
@@ -14,6 +17,7 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -41,10 +45,35 @@ public class TProductStockService extends ServiceImpl<TProductStockMapper, TProd
QueryWrapper<TProductStock> queryWrapper = new QueryWrapper<>();
queryWrapper.in("store_id", storeIds);
List<TProductStock> result = tProductStockMapper.selectList(queryWrapper);
return CollectionUtils.isEmpty(result)?null :
result.stream().map(TProductStock::getProductId).distinct().collect(Collectors.toList());
// 如果查询结果为空,返回 null
if (CollectionUtils.isEmpty(result)) {
return null;
}
// 过滤并获取 productId
return result.stream()
.filter(this::hasPositiveStock) // 使用单独的方法来处理过滤逻辑
.map(TProductStock::getProductId)
.distinct()
.collect(Collectors.toList());
}
// 判断 stock_content 中是否有 num > 0
private boolean hasPositiveStock(TProductStock productStock) {
List<Map<String, Object>> stockContent;
try {
stockContent = new ObjectMapper().readValue(productStock.getStockContent(), new TypeReference<List<Map<String, Object>>>() {});
} catch (JsonProcessingException e) {
e.printStackTrace();
return false; // 解析失败的记录跳过
}
// 检查是否有 num > 0 的情况
return stockContent.stream()
.anyMatch(entry -> (Integer) entry.get("num") > 0);
}
public List<TProductStock> findByProductIds(List<Long> productIds) {
QueryWrapper<TProductStock> queryWrapper = new QueryWrapper<>();
queryWrapper.in("product_id", productIds);

View File

@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mixi.common.config.exception.BusinessException;
import com.mixi.common.response.PageBaseResponse;
import com.mixi.common.tasks.mituExportEntity.WeeklyHeavyStock;
import com.mixi.common.utils.CopyUtil;
import com.mixi.common.utils.MinioUtil;
import com.mixi.mapper.MiTuExportMapper;
@@ -34,7 +33,6 @@ import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
//import com.ai.da.common.utils.SendSmsUtil;
@@ -148,7 +146,7 @@ public class MiTuExportServiceImpl implements MiTuExportService {
}
@Override
public List<Long> getProductIdsByMiTuMemberCode(String memberCode) {
public List<Long> getProductIdsByMiTuMemberCode(String memberCode, List<Long> productIds) {
// 顾客类型筛选
QueryWrapper<MiTuMember> qw = new QueryWrapper<>();
qw.lambda().eq(MiTuMember::getMbrCode, memberCode);
@@ -160,6 +158,7 @@ public class MiTuExportServiceImpl implements MiTuExportService {
MiTuMember member = miTuMembers.get(0);
// 根据顾客代码获取筛选后的商品ID列表
List<Long> productIdList = getProductIdListByMemberType(member);
productIdList.retainAll(productIds);
if (CollectionUtils.isEmpty(productIdList)) {
return new ArrayList<>();
}

View File

@@ -135,13 +135,22 @@
<foreach item="item" index="index" collection="productIdList" open="(" separator="," close=")">
#{item}
</foreach>
)
),
MaxScorePerGroup AS (
SELECT
product_id,
price_sales,
sum(score) as score
size,
MAX(score) AS max_score
FROM ProductScores
GROUP BY product_id,price_sales
ORDER BY score DESC
GROUP BY product_id, size
)
SELECT
ps.product_id,
ps.price_sales,
MAX(ms.max_score) AS score
FROM ProductScores ps
JOIN MaxScorePerGroup ms ON ps.product_id = ms.product_id AND ps.size = ms.size AND ps.score = ms.max_score
GROUP BY ps.product_id, ps.price_sales
ORDER BY score DESC;
</select>
</mapper>