bug修改

This commit is contained in:
方亮 2025-09-16 14:17:05 +08:00
parent a61e9074eb
commit 2d512b38c3
3 changed files with 50 additions and 101 deletions

View File

@ -27,7 +27,7 @@ import javax.annotation.Resource;
/**
* 宣传物料信息Service业务层处理
*
*
* @author 黑子
* @date 2025-09-10
*/
@ -54,7 +54,7 @@ public class TbPromotionMaterialServiceImpl implements ITbPromotionMaterialServi
/**
* 查询宣传物料信息列表
*
*
* @param tbPromotionMaterial 宣传物料信息
* @return 宣传物料信息
*/
@ -103,7 +103,7 @@ public class TbPromotionMaterialServiceImpl implements ITbPromotionMaterialServi
/**
* 新增宣传物料信息
*
*
* @param tbPromotionMaterial 宣传物料信息
* @return 结果
*/
@ -113,7 +113,7 @@ public class TbPromotionMaterialServiceImpl implements ITbPromotionMaterialServi
tbPromotionMaterial.setCreateUser(SecurityUtils.getUserId());
tbPromotionMaterial.setCreateTime(DateUtils.getNowDate());
int i = mapper.insertTbPromotionMaterial(tbPromotionMaterial);
if (i > 0) {
if (tbPromotionMaterial.getProductId() != null && !tbPromotionMaterial.getProductId().isEmpty() && i > 0) {
//将产品与物料关系存到另一张表
List<TbPromotionMaterial> split = tbPromotionMaterial.split(tbPromotionMaterial);
int n = mapper.insertMaterialProductRelevance(split);
@ -125,7 +125,7 @@ public class TbPromotionMaterialServiceImpl implements ITbPromotionMaterialServi
/**
* 修改宣传物料信息
*
*
* @param tbPromotionMaterial 宣传物料信息
* @return 结果
*/
@ -135,7 +135,7 @@ public class TbPromotionMaterialServiceImpl implements ITbPromotionMaterialServi
tbPromotionMaterial.setUpdateUser(SecurityUtils.getUserId());
tbPromotionMaterial.setUpdateTime(DateUtils.getNowDate());
int i = mapper.updateTbPromotionMaterial(tbPromotionMaterial);
if (i > 0) {
if (tbPromotionMaterial.getProductId() != null && !tbPromotionMaterial.getProductId().isEmpty() && i > 0) {
//删除以前的关联关系
int x = mapper.deleteMaterialProductRelevance(tbPromotionMaterial.getId());
//将产品与物料关系存到另一张表
@ -160,7 +160,7 @@ public class TbPromotionMaterialServiceImpl implements ITbPromotionMaterialServi
/**
* 删除宣传物料信息信息
*
*
* @param id 宣传物料信息主键
* @return 结果
*/

View File

@ -3,7 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.business.mapper.TbPromotionMaterialMapper">
<resultMap type="TbPromotionMaterial" id="TbPromotionMaterialResult">
<result property="id" column="id" />
<result property="name" column="name" />
@ -29,13 +29,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from tb_promotion_material aaa
left join sys_user su on su.user_id = aaa.create_user
where aaa.del_flag = 0
<where>
<if test="name != null and name != ''"> and aaa.name like concat('%', #{name}, '%')</if>
<if test="typeId != null "> and aaa.type_id = #{typeId}</if>
<if test="typeName != null and typeName != ''"> and aaa.type_name like concat('%', #{typeName}, '%')</if>
</where>
<if test="name != null and name != ''"> and aaa.name like concat('%', #{name}, '%')</if>
<if test="typeId != null "> and aaa.type_id = #{typeId}</if>
<if test="typeName != null and typeName != ''"> and aaa.type_name like concat('%', #{typeName}, '%')</if>
</select>
<select id="selectTbPromotionMaterialById" parameterType="Long" resultMap="TbPromotionMaterialResult">
<include refid="selectTbPromotionMaterialVo"/>
where id = #{id}
@ -127,6 +125,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<select id="getProductByMaterialId" resultType="java.lang.String">
select product_id from tb_promotion_material_product where material_id = #{id}
select product_id from tb_promotion_material_product where material_id = #{id} limit 1
</select>
</mapper>
</mapper>

View File

@ -3,6 +3,8 @@ package com.bonus.common.utils.file;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;
@ -15,39 +17,31 @@ import org.springframework.web.multipart.MultipartFile;
public class FileTypeUtils
{
// 常见视频文件的文件头十六进制
private static final String[] VIDEO_HEADER_PREFIXES = {
"000001BA", // MPEG
"000001B3", // MPEG
"66747970", // MP4
"464C56", // FLV
"494433", // MP3 (音频可排除)
"89504E47", // PNG (图片)
"47494638", // GIF
"25504446", // PDF
"FFD8FFE0", // JPEG
"52494646", // WebP / AVI (RIFF 容器)
"4D5A" // EXE (危险文件)
};
// 常见的视频文件扩展名小写
private static final Set<String> VIDEO_EXTENSIONS = new HashSet<>();
// 真正的视频 MIME 类型
private static final String[] VIDEO_CONTENT_TYPES = {
"video/mp4",
"video/avi",
"video/x-msvideo",
"video/mpeg",
"video/quicktime",
"video/x-flv",
"video/webm",
"video/3gpp",
"video/ogg"
};
static {
VIDEO_EXTENSIONS.add("mp4");
VIDEO_EXTENSIONS.add("avi");
VIDEO_EXTENSIONS.add("mkv");
VIDEO_EXTENSIONS.add("mov");
VIDEO_EXTENSIONS.add("wmv");
VIDEO_EXTENSIONS.add("flv");
VIDEO_EXTENSIONS.add("rmvb");
VIDEO_EXTENSIONS.add("3gp");
VIDEO_EXTENSIONS.add("webm");
VIDEO_EXTENSIONS.add("m4v");
VIDEO_EXTENSIONS.add("mpg");
VIDEO_EXTENSIONS.add("mpeg");
VIDEO_EXTENSIONS.add("vob");
VIDEO_EXTENSIONS.add("ogv");
}
/**
* 获取文件类型
* <p>
* 例如: bonus.txt, 返回: txt
*
*
* @param file 文件名
* @return 后缀不含".")
*/
@ -80,7 +74,7 @@ public class FileTypeUtils
/**
* 获取文件类型
*
*
* @param photoByte 文件字节码
* @return 后缀不含".")
*/
@ -108,70 +102,27 @@ public class FileTypeUtils
}
/**
* 判断 MultipartFile 是否为视频文件Java 8 兼容版
* 判断 MultipartFile 是否为视频文件基于后缀名
*
* @param file 上传的文件
* @return true 表示是视频文件false 不是
*/
public static boolean isVideoFile(MultipartFile file) {
if (file == null || file.isEmpty()) {
return false;
}
String contentType = file.getContentType();
if (contentType == null) {
String fileName = file.getOriginalFilename();
if (fileName == null || fileName.trim().isEmpty()) {
return false;
}
// 先用 MIME 类型快速判断备用方案
boolean isVideoByMimeType = Arrays.stream(VIDEO_CONTENT_TYPES)
.anyMatch(contentType::startsWith);
try {
byte[] headerBytes = new byte[12];
int read = file.getInputStream().read(headerBytes);
if (read < 4) {
return false;
}
String headerHex = bytesToHex(headerBytes, Math.min(read, 8)).toUpperCase();
boolean isVideo = false; // 用一个变量保存结果
switch (headerHex) {
case "66747970": // MP4
case "000001BA": // MPEG
case "000001B3": // MPEG
case "464C56": // FLV
isVideo = true;
break;
case "52494646": // RIFF (AVI, WebM)
// 进一步判断子类型AVI WebM
if (read >= 12) {
String subType = bytesToHex(Arrays.copyOfRange(headerBytes, 8, 12)).toUpperCase();
isVideo = "41564920".equals(subType) || "5745424D".equals(subType); // "AVI " "WEBM"
}
break;
default:
// 文件头不匹配降级使用 MIME 类型判断
isVideo = isVideoByMimeType;
break;
}
return isVideo;
} catch (IOException e) {
// 读取出错降级使用 MIME 类型判断
return isVideoByMimeType;
// 获取最后一个点的位置防止文件名含多个点
int lastDotIndex = fileName.lastIndexOf('.');
if (lastDotIndex < 0 || lastDotIndex == fileName.length() - 1) {
return false; // 没有后缀名或以.结尾
}
// 提取后缀名并转小写
String extension = fileName.substring(lastDotIndex + 1).toLowerCase();
return VIDEO_EXTENSIONS.contains(extension);
}
/**
* 将字节数组转为十六进制字符串
*/
private static String bytesToHex(byte[] bytes, int len) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) {
sb.append(String.format("%02X", bytes[i] & 0xFF));
}
return sb.toString();
}
/**
* 获取字节数组的十六进制表示完整
*/
private static String bytesToHex(byte[] bytes) {
return bytesToHex(bytes, bytes.length);
}
}
}