推广海报程序优化日志输出
This commit is contained in:
parent
aa7253d71e
commit
195a1d6735
@ -30,6 +30,78 @@ public class OssUtils {
|
||||
@Autowired
|
||||
private OssService ossService;
|
||||
|
||||
/**
|
||||
* 网络图片转输入流(改进版)
|
||||
*
|
||||
* @param fileUrl 网络文件URL
|
||||
* @return InputStream 输入流,如果失败返回null
|
||||
*/
|
||||
public static InputStream urlToInputSteam(String fileUrl) {
|
||||
if (fileUrl == null || fileUrl.trim().isEmpty()) {
|
||||
System.err.println("文件URL为空");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
URL url = new URL(fileUrl);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(10 * 1000);
|
||||
connection.setReadTimeout(10 * 1000);
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode != HttpURLConnection.HTTP_OK) {
|
||||
System.err.println("HTTP响应码错误: " + responseCode);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 直接返回连接的输入流,由调用者负责关闭
|
||||
return connection.getInputStream();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("网络图片转输入流失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 缓冲图像转输入流
|
||||
*
|
||||
* @param bufferedImage
|
||||
* @Return Map
|
||||
*/
|
||||
public static Map toStreamMap(BufferedImage bufferedImage) {
|
||||
InputStream stream = null;
|
||||
ByteArrayOutputStream arrayOutputStream = null;
|
||||
try {
|
||||
arrayOutputStream = new ByteArrayOutputStream();
|
||||
ImageIO.write(bufferedImage, "png", arrayOutputStream);
|
||||
|
||||
int file_size = arrayOutputStream.size();
|
||||
byte[] result = arrayOutputStream.toByteArray();
|
||||
|
||||
stream = new ByteArrayInputStream(result);
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("stream", stream);
|
||||
resultMap.put("file_size", Convert.toLong(file_size));
|
||||
return resultMap;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 释放连接
|
||||
try {
|
||||
arrayOutputStream.close();
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* oos直传,本地不存储图片
|
||||
*
|
||||
@ -79,83 +151,4 @@ public class OssUtils {
|
||||
return ossFilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 网络图片转输入流
|
||||
*
|
||||
* @param fileUrl
|
||||
* @return
|
||||
*/
|
||||
public static InputStream urlToInputSteam(String fileUrl) {
|
||||
HttpURLConnection connection = null;
|
||||
InputStream is = null;
|
||||
InputStream stream = null;
|
||||
try {
|
||||
// 打开服务器图片路径
|
||||
URL url = new URL(fileUrl);
|
||||
//创建连接
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET"); // 提交模式
|
||||
connection.setConnectTimeout(10 * 1000); //连接超时5秒
|
||||
connection.setReadTimeout(10 * 1000); //读取超时10秒
|
||||
|
||||
is = connection.getInputStream();
|
||||
int file_size = connection.getContentLength(); //文件大小
|
||||
byte[] result = new byte[file_size];
|
||||
int readCount = 0;
|
||||
while (readCount < file_size) {
|
||||
readCount += is.read(result, readCount, file_size - readCount);
|
||||
}
|
||||
stream = new ByteArrayInputStream(result);
|
||||
return stream;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
connection.disconnect();
|
||||
is.close();
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓冲图像转输入流
|
||||
*
|
||||
* @param bufferedImage
|
||||
* @Return Map
|
||||
*/
|
||||
public static Map toStreamMap(BufferedImage bufferedImage) {
|
||||
InputStream stream = null;
|
||||
ByteArrayOutputStream arrayOutputStream = null;
|
||||
try {
|
||||
arrayOutputStream = new ByteArrayOutputStream();
|
||||
ImageIO.write(bufferedImage, "png", arrayOutputStream);
|
||||
|
||||
int file_size = arrayOutputStream.size();
|
||||
byte[] result = arrayOutputStream.toByteArray();
|
||||
|
||||
stream = new ByteArrayInputStream(result);
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("stream", stream);
|
||||
resultMap.put("file_size", Convert.toLong(file_size));
|
||||
return resultMap;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 释放连接
|
||||
try {
|
||||
arrayOutputStream.close();
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -669,30 +669,67 @@ public class ShopDistributionUserServiceImpl extends BaseServiceImpl<ShopDistrib
|
||||
*/
|
||||
@Override
|
||||
public CommonResult poster(PosterDTO posterDTO) {
|
||||
|
||||
UserDto user = getCurrentUser();
|
||||
if (user == null) {
|
||||
logger.warn("用户未登录,无法生成海报");
|
||||
throw new ApiException(ResultCode.NEED_LOGIN);
|
||||
}
|
||||
|
||||
// 参数校验
|
||||
if (posterDTO == null) {
|
||||
logger.warn("海报参数为空,用户ID: {}", user.getId());
|
||||
return CommonResult.failed("参数不能为空");
|
||||
}
|
||||
|
||||
String cacheKey = RedisConstant.Poster_NameSpace + Md5Utils.getMD5(JSONUtil.toJsonStr(posterDTO).getBytes());
|
||||
if (redisService.hasKey(cacheKey)) {
|
||||
return CommonResult.success(redisService.get(cacheKey));
|
||||
try {
|
||||
if (redisService.hasKey(cacheKey)) {
|
||||
Object cachedData = redisService.get(cacheKey);
|
||||
if (cachedData != null) {
|
||||
logger.debug("从缓存中获取海报数据,用户ID: {}", user.getId());
|
||||
return CommonResult.success(cachedData);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("读取海报缓存失败,用户ID: {}: {}", user.getId(), e.getMessage());
|
||||
}
|
||||
|
||||
Integer poster_type = posterDTO.getPoster_type(); // 海报类型:1-H5;2-小程序
|
||||
String poster_name = Optional.ofNullable(posterDTO.getMainTitle()).orElse(Optional.ofNullable(posterDTO.getMainTitle()).orElse(accountBaseConfigService.getConfig("site_name")));
|
||||
if (poster_type == null || (poster_type != 1 && poster_type != 2)) {
|
||||
logger.warn("无效的海报类型: {}, 用户ID: {}", poster_type, user.getId());
|
||||
return CommonResult.failed("无效的海报类型");
|
||||
}
|
||||
|
||||
String poster_name = Optional.ofNullable(posterDTO.getMainTitle())
|
||||
.orElse(accountBaseConfigService.getConfig("site_name"));
|
||||
|
||||
// 防止poster_name为null
|
||||
if (poster_name == null) {
|
||||
poster_name = "默认海报";
|
||||
}
|
||||
|
||||
String main_price = posterDTO.getMainPrice();
|
||||
String main_img = posterDTO.getMainImg();
|
||||
|
||||
// 获取存文本
|
||||
Document post_name_doc = Jsoup.parse(poster_name);
|
||||
poster_name = post_name_doc.text();
|
||||
if (poster_name != null) {
|
||||
Document post_name_doc = Jsoup.parse(poster_name);
|
||||
poster_name = post_name_doc.text();
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(main_img)) {
|
||||
AccountUserInfo userInfo = accountService.getUserInfo(user.getId());
|
||||
String user_avatar = userInfo.getUser_avatar();
|
||||
main_img = ObjectUtil.defaultIfBlank(user_avatar, accountBaseConfigService.getConfig("user_no_avatar"));
|
||||
try {
|
||||
AccountUserInfo userInfo = accountService.getUserInfo(user.getId());
|
||||
if (userInfo != null) {
|
||||
String user_avatar = userInfo.getUser_avatar();
|
||||
main_img = ObjectUtil.defaultIfBlank(user_avatar, accountBaseConfigService.getConfig("user_no_avatar"));
|
||||
} else {
|
||||
main_img = accountBaseConfigService.getConfig("user_no_avatar");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("获取用户信息失败,使用默认头像,用户ID: {}: {}", user.getId(), e.getMessage());
|
||||
main_img = accountBaseConfigService.getConfig("user_no_avatar");
|
||||
}
|
||||
}
|
||||
|
||||
// 图像是否输出价格字样
|
||||
@ -706,10 +743,12 @@ public class ShopDistributionUserServiceImpl extends BaseServiceImpl<ShopDistrib
|
||||
|
||||
String wap_url = "";
|
||||
String qrcode = "";
|
||||
Map data = new HashMap();
|
||||
wap_url = Optional.ofNullable(posterDTO.getPath()).orElse(base_ip + "/pages/index/index?uid=" + user_id);
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
|
||||
Map params = new HashMap();
|
||||
wap_url = Optional.ofNullable(posterDTO.getPath())
|
||||
.orElse(base_ip + "/pages/index/index?uid=" + user_id);
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("user_id", user_id);
|
||||
params.put("poster_type", poster_type);
|
||||
params.put("poster_name", poster_name);
|
||||
@ -723,193 +762,288 @@ public class ShopDistributionUserServiceImpl extends BaseServiceImpl<ShopDistrib
|
||||
File qrcode_file = null;
|
||||
InputStream qrcode_stream = null;
|
||||
|
||||
if (poster_type == 1) {
|
||||
// 生成新版本H5 URL
|
||||
qrcode = accountBaseConfigService.qrcode(wap_url, 300, 300);
|
||||
try {
|
||||
if (poster_type == 1) {
|
||||
// 生成新版本H5 URL
|
||||
try {
|
||||
qrcode = accountBaseConfigService.qrcode(wap_url, 300, 300);
|
||||
} catch (Exception e) {
|
||||
logger.error("生成H5二维码失败,用户ID: {}: {}", user.getId(), e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("生成二维码失败"));
|
||||
}
|
||||
|
||||
// 移动端H5
|
||||
data.put("invite_url", wap_url);
|
||||
data.put("qrcode", qrcode);
|
||||
data.put("download_url", qrcode + "&d=1");
|
||||
|
||||
} else if (poster_type == 2) {
|
||||
// 生成小程序 URL
|
||||
Map unlimitedMap = wxQrCodeService.genUnlimitedWxQrCode(wap_url, params);
|
||||
qrcode = Convert.toStr(unlimitedMap.get("floder"));
|
||||
if (!ConfigConstant.FILE_STORAGE_DISK) {
|
||||
String qr_filename = (String) unlimitedMap.get("qr_filename");
|
||||
// 这里不能使用微信返回的流
|
||||
qrcode_stream = OssUtils.urlToInputSteam(qrcode);
|
||||
filename = qr_filename;
|
||||
}
|
||||
|
||||
if (null != qrcode) {
|
||||
// 移动端H5
|
||||
data.put("invite_url", wap_url);
|
||||
data.put("qrcode", qrcode);
|
||||
data.put("download_url", qrcode + "&d=1");
|
||||
|
||||
} else if (poster_type == 2) {
|
||||
// 生成小程序 URL
|
||||
try {
|
||||
Map unlimitedMap = wxQrCodeService.genUnlimitedWxQrCode(wap_url, params);
|
||||
if (unlimitedMap != null) {
|
||||
qrcode = Convert.toStr(unlimitedMap.get("floder"));
|
||||
if (!ConfigConstant.FILE_STORAGE_DISK) {
|
||||
String qr_filename = (String) unlimitedMap.get("qr_filename");
|
||||
if (StrUtil.isNotBlank(qrcode)) {
|
||||
// 这里不能使用微信返回的流
|
||||
qrcode_stream = OssUtils.urlToInputSteam(qrcode);
|
||||
}
|
||||
filename = qr_filename != null ? qr_filename : filename;
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(qrcode)) {
|
||||
data.put("qrcode", qrcode);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("生成小程序二维码失败,用户ID: {}: {}", user.getId(), e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("生成小程序二维码失败"));
|
||||
}
|
||||
|
||||
data.put("invite_url", wap_url);
|
||||
data.put("download_url", qrcode != null ? qrcode + "&d=1" : "");
|
||||
}
|
||||
|
||||
data.put("invite_url", wap_url);
|
||||
data.put("download_url", qrcode + "&d=1");
|
||||
}
|
||||
FileUtil.mkParentDirs(poster_path);
|
||||
File poster_file = FileUtil.file(poster_path);
|
||||
|
||||
FileUtil.mkParentDirs(poster_path);
|
||||
File poster_file = FileUtil.file(poster_path);
|
||||
String qrcode_url = String.format("%s/media/plantform/poster/%s/%s-qrcode.png", static_file_url, poster_type, filename);
|
||||
String qrcode_path = String.format("%s/media/plantform/poster/%s/%s-qrcode.png", static_file_path, poster_type, filename);
|
||||
|
||||
String qrcode_url = String.format("%s/media/plantform/poster/%s/%s-qrcode.png", static_file_url, poster_type, filename);
|
||||
String qrcode_path = String.format("%s/media/plantform/poster/%s/%s-qrcode.png", static_file_path, poster_type, filename);
|
||||
// todo 暂时写死
|
||||
String dir = "media/plantform/";
|
||||
filename = filename + "-qrcode.png";
|
||||
|
||||
// todo 暂时写死
|
||||
String dir = "media/plantform/";
|
||||
filename = filename + "-qrcode.png";
|
||||
// 判断H5与小程序环境
|
||||
if (poster_type == 1) {
|
||||
BufferedImage image = QrCodeUtil.generate(wap_url, 300, 300);
|
||||
// 生成二维码
|
||||
if (!ConfigConstant.FILE_STORAGE_DISK) {
|
||||
String url = null;
|
||||
Integer uploadType = accountBaseConfigService.getConfig("upload", 1);
|
||||
|
||||
// 判断H5与小程序环境
|
||||
if (poster_type == 1) {
|
||||
BufferedImage image = QrCodeUtil.generate(wap_url, 300, 300);
|
||||
// 生成二维码
|
||||
if (!ConfigConstant.FILE_STORAGE_DISK) {
|
||||
String url = null;
|
||||
Integer uploadType = accountBaseConfigService.getConfig("upload", 1);
|
||||
|
||||
if (uploadType.equals(1)) {
|
||||
url = ConfigConstant.URL_BASE + "/admin/oss/upload/" + dir + "/" + filename; // 文件本地路径
|
||||
} else if (uploadType.equals(2)) {
|
||||
// oss 服务
|
||||
try {
|
||||
Map streamMap = OssUtils.toStreamMap(image);
|
||||
InputStream stream = (InputStream) streamMap.get("stream");
|
||||
Long file_size = (Long) streamMap.get("file_size");
|
||||
String floder = ALIYUN_OSS_DIR_PREFIX.concat("/") + dir + "poster/1/";
|
||||
url = ossService.uploadObject2OSS(null, floder + filename, stream, filename, file_size);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("文件上传失败!", e);
|
||||
return null;
|
||||
if (uploadType.equals(1)) {
|
||||
url = ConfigConstant.URL_BASE + "/admin/oss/upload/" + dir + "/" + filename; // 文件本地路径
|
||||
} else if (uploadType.equals(2)) {
|
||||
// oss 服务
|
||||
try {
|
||||
Map streamMap = OssUtils.toStreamMap(image);
|
||||
if (streamMap != null) {
|
||||
InputStream stream = (InputStream) streamMap.get("stream");
|
||||
Long file_size = (Long) streamMap.get("file_size");
|
||||
String floder = ALIYUN_OSS_DIR_PREFIX.concat("/") + dir + "poster/1/";
|
||||
url = ossService.uploadObject2OSS(null, floder + filename, stream, filename, file_size);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("OSS上传二维码失败,用户ID: {}: {}", user.getId(), e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("二维码上传失败"));
|
||||
}
|
||||
} else if (uploadType.equals(4)) {
|
||||
try {
|
||||
FileUtil.mkParentDirs(qrcode_path);
|
||||
qrcode_file = FileUtil.file(qrcode_path);
|
||||
ImageIO.write(image, "png", qrcode_file);
|
||||
} catch (IOException e) {
|
||||
logger.error("生成二维码文件失败,用户ID: {}: {}", user.getId(), e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("生成二维码失败!"));
|
||||
}
|
||||
try {
|
||||
url = ossService.uploadObject4OSS(qrcode_file, TENGXUN_DEFAULT_DIR.concat("/").concat(dir).concat("/").concat(filename));
|
||||
} catch (Exception e) {
|
||||
logger.error("腾讯云上传二维码失败,用户ID: {}: {}", user.getId(), e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("二维码上传失败"));
|
||||
}
|
||||
}
|
||||
} else if (uploadType.equals(4)) {
|
||||
|
||||
if (url != null) {
|
||||
qrcode_stream = OssUtils.urlToInputSteam(url);
|
||||
data.put("qrcode", url);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
FileUtil.mkParentDirs(qrcode_path);
|
||||
qrcode_file = FileUtil.file(qrcode_path);
|
||||
ImageIO.write(image, "png", qrcode_file);
|
||||
} catch (IOException e) {
|
||||
logger.error("生成二维码文件失败,用户ID: {}: {}", user.getId(), e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("生成二维码失败!"));
|
||||
}
|
||||
url = ossService.uploadObject4OSS(qrcode_file, TENGXUN_DEFAULT_DIR.concat("/").concat(dir).concat("/").concat(filename));
|
||||
}
|
||||
qrcode_stream = OssUtils.urlToInputSteam(url);
|
||||
} else if (poster_type == 2) {
|
||||
if (StrUtil.isNotBlank(qrcode)) {
|
||||
qrcode_file = new File(qrcode);
|
||||
data.put("qrcode", qrcode);
|
||||
}
|
||||
}
|
||||
|
||||
data.put("qrcode", url);
|
||||
} else {
|
||||
// 生成产品图片
|
||||
File main_file = null;
|
||||
if (StrUtil.isNotBlank(main_img)) {
|
||||
try {
|
||||
FileUtil.mkParentDirs(qrcode_path);
|
||||
qrcode_file = FileUtil.file(qrcode_path);
|
||||
ImageIO.write(image, "png", qrcode_file);
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(I18nUtil._("生成二维码失败!"));
|
||||
main_file = getFile(main_img);
|
||||
if (main_file == null || !main_file.exists()) {
|
||||
logger.warn("获取主图文件失败,用户ID: {}, 图片URL: {}", user.getId(), main_img);
|
||||
throw new ApiException(I18nUtil._("图片不存在!"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("获取主图文件失败,用户ID: {}, 图片URL: {}: {}", user.getId(), main_img, e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("图片不存在!"));
|
||||
}
|
||||
}
|
||||
} else if (poster_type == 2) {
|
||||
qrcode_file = new File(qrcode);
|
||||
data.put("qrcode", qrcode);
|
||||
}
|
||||
|
||||
// 生成产品图片
|
||||
File main_file = null;
|
||||
try {
|
||||
main_file = getFile(main_img);
|
||||
} catch (Exception e) {
|
||||
throw new ApiException(I18nUtil._("图片不存在!"));
|
||||
}
|
||||
|
||||
String plantform_poster_bg = "";
|
||||
if (StrUtil.isNotBlank(main_price)) {
|
||||
// 产品海报
|
||||
plantform_poster_bg = accountBaseConfigService.getConfig("product_poster_bg");
|
||||
} else {
|
||||
// 推广海报
|
||||
plantform_poster_bg = accountBaseConfigService.getConfig("plantform_poster_bg");
|
||||
}
|
||||
|
||||
// 绘制海报图
|
||||
try {
|
||||
BufferedImage background = ImageIO.read(OssUtils.urlToInputSteam(plantform_poster_bg));
|
||||
BufferedImage qrcodeImage = null;
|
||||
if (!ConfigConstant.FILE_STORAGE_DISK) {
|
||||
qrcodeImage = ImageIO.read(qrcode_stream);
|
||||
} else {
|
||||
qrcodeImage = ImageIO.read(qrcode_file);
|
||||
}
|
||||
BufferedImage productImage = ImageIO.read(main_file);
|
||||
PromotePoster poster = PromotePoster.builder()
|
||||
.backgroundImage(background)
|
||||
.qrcodeImage(qrcodeImage)
|
||||
.productName(poster_name)
|
||||
.productPrice(main_price)
|
||||
.build();
|
||||
|
||||
String plantform_poster_bg = "";
|
||||
if (StrUtil.isNotBlank(main_price)) {
|
||||
// 产品海报
|
||||
poster.setProductImage(productImage);
|
||||
plantform_poster_bg = accountBaseConfigService.getConfig("product_poster_bg");
|
||||
} else {
|
||||
// 推广海报
|
||||
poster.setPlantformImage(productImage);
|
||||
plantform_poster_bg = accountBaseConfigService.getConfig("plantform_poster_bg");
|
||||
}
|
||||
|
||||
PosterDefaultImpl<PromotePoster> impl = new PosterDefaultImpl<>();
|
||||
BufferedImage bufferedImage = impl.annotationDrawPoster(poster).draw(null);
|
||||
if (!ConfigConstant.FILE_STORAGE_DISK) {
|
||||
filename = filename.replace("-qrcode", "");
|
||||
|
||||
String postUrl = null;
|
||||
Integer uploadType = accountBaseConfigService.getConfig("upload", 1);
|
||||
|
||||
if (uploadType.equals(1)) {
|
||||
postUrl = ConfigConstant.URL_BASE + "/admin/oss/upload/" + dir + "/" + filename; // 文件本地路径
|
||||
} else if (uploadType.equals(2)) {
|
||||
// oss 服务
|
||||
try {
|
||||
Map streamMap = OssUtils.toStreamMap(bufferedImage);
|
||||
InputStream stream = (InputStream) streamMap.get("stream");
|
||||
Long file_size = (Long) streamMap.get("file_size");
|
||||
String floder = null;
|
||||
if (poster_type == 1) {
|
||||
floder = ALIYUN_OSS_DIR_PREFIX.concat("/") + dir + "poster/1/";
|
||||
} else if (poster_type == 2) {
|
||||
floder = ALIYUN_OSS_DIR_PREFIX.concat("/") + dir + "poster/2/";
|
||||
}
|
||||
postUrl = ossService.uploadObject2OSS(null, floder + filename, stream, filename, file_size);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("文件上传失败!", e);
|
||||
return null;
|
||||
}
|
||||
} else if (uploadType.equals(4)) {
|
||||
try {
|
||||
ImageIO.write(bufferedImage, "png", poster_file);
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(I18nUtil._("生成海报失败!"));
|
||||
}
|
||||
postUrl = ossService.uploadObject4OSS(poster_file, TENGXUN_DEFAULT_DIR.concat("/").concat(dir).concat("/").concat(filename));
|
||||
// 绘制海报图
|
||||
try {
|
||||
InputStream backgroundStream = OssUtils.urlToInputSteam(plantform_poster_bg);
|
||||
if (backgroundStream == null) {
|
||||
logger.error("获取海报背景图失败,用户ID: {}, 背景图URL: {}", user.getId(), plantform_poster_bg);
|
||||
throw new ApiException(I18nUtil._("获取背景图失败"));
|
||||
}
|
||||
|
||||
data.put("poster_url", String.format("%s?rand=%s", postUrl, RandomUtil.randomString(13)));
|
||||
BufferedImage background = ImageIO.read(backgroundStream);
|
||||
BufferedImage qrcodeImage = null;
|
||||
|
||||
} else {
|
||||
ImageIO.write(bufferedImage, "png", poster_file);
|
||||
if (!ConfigConstant.FILE_STORAGE_DISK) {
|
||||
if (qrcode_stream != null) {
|
||||
qrcodeImage = ImageIO.read(qrcode_stream);
|
||||
}
|
||||
} else {
|
||||
if (qrcode_file != null && qrcode_file.exists()) {
|
||||
qrcodeImage = ImageIO.read(qrcode_file);
|
||||
}
|
||||
}
|
||||
|
||||
BufferedImage productImage = null;
|
||||
if (main_file != null && main_file.exists()) {
|
||||
productImage = ImageIO.read(main_file);
|
||||
}
|
||||
|
||||
if (background == null) {
|
||||
logger.error("读取背景图失败,用户ID: {}", user.getId());
|
||||
throw new ApiException(I18nUtil._("读取背景图失败"));
|
||||
}
|
||||
|
||||
PromotePoster poster = new PromotePoster();
|
||||
poster.setBackgroundImage(background);
|
||||
poster.setProductName(poster_name);
|
||||
|
||||
if (qrcodeImage != null) {
|
||||
poster.setQrcodeImage(qrcodeImage);
|
||||
}
|
||||
|
||||
if (main_price != null) {
|
||||
poster.setProductPrice(main_price);
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(main_price)) {
|
||||
// 产品海报
|
||||
if (productImage != null) {
|
||||
poster.setProductImage(productImage);
|
||||
}
|
||||
} else {
|
||||
// 推广海报
|
||||
if (productImage != null) {
|
||||
poster.setPlantformImage(productImage);
|
||||
}
|
||||
}
|
||||
|
||||
PosterDefaultImpl<PromotePoster> impl = new PosterDefaultImpl<>();
|
||||
BufferedImage bufferedImage = impl.annotationDrawPoster(poster).draw(null);
|
||||
|
||||
if (bufferedImage == null) {
|
||||
logger.error("绘制海报失败,用户ID: {}", user.getId());
|
||||
throw new ApiException(I18nUtil._("绘制海报失败"));
|
||||
}
|
||||
|
||||
if (!ConfigConstant.FILE_STORAGE_DISK) {
|
||||
filename = filename.replace("-qrcode", "");
|
||||
|
||||
String postUrl = null;
|
||||
Integer uploadType = accountBaseConfigService.getConfig("upload", 1);
|
||||
|
||||
if (uploadType.equals(1)) {
|
||||
postUrl = ConfigConstant.URL_BASE + "/admin/oss/upload/" + dir + "/" + filename; // 文件本地路径
|
||||
} else if (uploadType.equals(2)) {
|
||||
// oss 服务
|
||||
try {
|
||||
Map streamMap = OssUtils.toStreamMap(bufferedImage);
|
||||
if (streamMap != null) {
|
||||
InputStream stream = (InputStream) streamMap.get("stream");
|
||||
Long file_size = (Long) streamMap.get("file_size");
|
||||
String floder = null;
|
||||
if (poster_type == 1) {
|
||||
floder = ALIYUN_OSS_DIR_PREFIX.concat("/") + dir + "poster/1/";
|
||||
} else if (poster_type == 2) {
|
||||
floder = ALIYUN_OSS_DIR_PREFIX.concat("/") + dir + "poster/2/";
|
||||
}
|
||||
postUrl = ossService.uploadObject2OSS(null, floder + filename, stream, filename, file_size);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("OSS上传海报失败,用户ID: {}: {}", user.getId(), e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("海报上传失败"));
|
||||
}
|
||||
} else if (uploadType.equals(4)) {
|
||||
try {
|
||||
ImageIO.write(bufferedImage, "png", poster_file);
|
||||
} catch (IOException e) {
|
||||
logger.error("生成海报文件失败,用户ID: {}: {}", user.getId(), e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("生成海报失败!"));
|
||||
}
|
||||
try {
|
||||
postUrl = ossService.uploadObject4OSS(poster_file, TENGXUN_DEFAULT_DIR.concat("/").concat(dir).concat("/").concat(filename));
|
||||
} catch (Exception e) {
|
||||
logger.error("腾讯云上传海报失败,用户ID: {}: {}", user.getId(), e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("海报上传失败"));
|
||||
}
|
||||
}
|
||||
|
||||
if (postUrl != null) {
|
||||
data.put("poster_url", String.format("%s?rand=%s", postUrl, RandomUtil.randomString(13)));
|
||||
}
|
||||
|
||||
} else {
|
||||
ImageIO.write(bufferedImage, "png", poster_file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("生成海报失败,用户ID: {}: {}", user.getId(), e.getMessage(), e);
|
||||
throw new ApiException(I18nUtil._("生成海报失败!"));
|
||||
}
|
||||
|
||||
Float plantform_fx_cps_rate_1 = accountBaseConfigService.getConfig("plantform_fx_cps_rate_1", 0f);
|
||||
Float plantform_fx_cps_rate_2 = accountBaseConfigService.getConfig("plantform_fx_cps_rate_2", 0f);
|
||||
Float plantform_fx_cps_rate_3 = accountBaseConfigService.getConfig("plantform_fx_cps_rate_3", 0f);
|
||||
|
||||
data.put("plantform_fx_cps_rate_1", plantform_fx_cps_rate_1);
|
||||
data.put("plantform_fx_cps_rate_2", plantform_fx_cps_rate_2);
|
||||
data.put("plantform_fx_cps_rate_3", plantform_fx_cps_rate_3);
|
||||
|
||||
try {
|
||||
redisService.set(cacheKey, data);
|
||||
} catch (Exception e) {
|
||||
logger.warn("海报数据缓存失败,用户ID: {}: {}", user.getId(), e.getMessage());
|
||||
}
|
||||
|
||||
return CommonResult.success(data);
|
||||
|
||||
} finally {
|
||||
// 确保资源被正确关闭
|
||||
if (qrcode_stream != null) {
|
||||
try {
|
||||
qrcode_stream.close();
|
||||
} catch (IOException e) {
|
||||
logger.warn("关闭二维码输入流失败,用户ID: {}: {}", user.getId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ApiException(I18nUtil._("生成海报失败!"));
|
||||
}
|
||||
|
||||
Float plantform_fx_cps_rate_1 = accountBaseConfigService.getConfig("plantform_fx_cps_rate_1", 0f);
|
||||
Float plantform_fx_cps_rate_2 = accountBaseConfigService.getConfig("plantform_fx_cps_rate_2", 0f);
|
||||
Float plantform_fx_cps_rate_3 = accountBaseConfigService.getConfig("plantform_fx_cps_rate_3", 0f);
|
||||
|
||||
data.put("plantform_fx_cps_rate_1", plantform_fx_cps_rate_1);
|
||||
data.put("plantform_fx_cps_rate_2", plantform_fx_cps_rate_2);
|
||||
data.put("plantform_fx_cps_rate_3", plantform_fx_cps_rate_3);
|
||||
|
||||
redisService.set(cacheKey, data);
|
||||
|
||||
return CommonResult.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -550,7 +550,6 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
payload.put("category", CommonConstant.PUSH_MSG_CATE_EC);
|
||||
pushMessageService.noticeMerchantSignEcContract(shopMchEntry.getCreated_by(), payload);
|
||||
|
||||
|
||||
return Pair.of(true, "商家入网申请电子合同成功");
|
||||
}
|
||||
|
||||
|
||||
@ -695,7 +695,6 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
|
||||
|
||||
if (approvalStatus.equals(CommonConstant.MCH_APPR_STA_LKL_PADDING)) {
|
||||
approvalRemark = "初审通过,等待进一步审核。";
|
||||
// updateWrapper.set("signed_status", CommonConstant.CONTRACT_SIGN_STA_ING); // 合同签署中
|
||||
approvalInvalidCol = "[]";
|
||||
}
|
||||
|
||||
@ -753,6 +752,13 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
|
||||
return CommonResult.failed(resultPair.getSecond());
|
||||
}
|
||||
|
||||
record.setApproval_remark("入网申请已成功提交!");
|
||||
// 执行更新操作
|
||||
if (!updateById(record)) {
|
||||
log.error("系统处理审批出错,请联系管理员!当前记录ID: {}", id);
|
||||
return CommonResult.failed("系统处理审批出错,请联系管理员!");
|
||||
}
|
||||
|
||||
|
||||
// E签宝暂时停止使用
|
||||
// if (approvalStatus.equals(CommonConstant.Enable)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user