From a921772e19ac36471485c8fd2e86dfd335d6641a Mon Sep 17 00:00:00 2001 From: wjt Date: Fri, 10 Mar 2023 19:05:11 +0800 Subject: [PATCH] xhs --- .../resources/config/application-prod.yml | 12 +- .../baiye/controller/UploadController.java | 48 +++ .../main/resources/config/application-dev.yml | 4 +- .../resources/config/application-prod.yml | 4 +- .../resources/config/application-test.yml | 4 +- .../java/com/baiye/entity/SourceOrganize.java | 3 + .../main/java/com/baiye/entity/Template.java | 7 + .../main/java/com/baiye/entity/Variable.java | 7 + .../main/java/com/baiye/util/FileUtil.java | 331 ++++++++++++++++++ .../impl/ResourceVariableServiceImpl.java | 7 +- .../service/impl/SmartWriteServiceImpl.java | 25 +- .../impl/SourceOrganizeServiceImpl.java | 2 + .../baiye/service/impl/SourceServiceImpl.java | 76 ++-- .../main/resources/mapper/TemplateMapper.xml | 7 +- .../main/resources/mapper/VariableMapper.xml | 8 +- 15 files changed, 493 insertions(+), 52 deletions(-) create mode 100644 cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/java/com/baiye/controller/UploadController.java create mode 100644 cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/util/FileUtil.java diff --git a/cdp-iaas/gateway-server/src/main/resources/config/application-prod.yml b/cdp-iaas/gateway-server/src/main/resources/config/application-prod.yml index dcf662d..a76bc90 100644 --- a/cdp-iaas/gateway-server/src/main/resources/config/application-prod.yml +++ b/cdp-iaas/gateway-server/src/main/resources/config/application-prod.yml @@ -1,5 +1,5 @@ server: - port: 80 + port: 8899 spring: redis: #数据库索引 @@ -38,11 +38,11 @@ spring: filters: - StripPrefix=1 - id: cdp-tool-xhs-api - uri: lb://cdp-tool-xhs-api - predicates: - - Path=/api-xhs/** - filters: - - StripPrefix=1 + uri: lb://cdp-tool-xhs-api + predicates: + - Path=/api-xhs/** + filters: + - StripPrefix=1 nacos: server-addr: 172.16.69.134:8848 # server-addr: 101.35.109.129:8848 diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/java/com/baiye/controller/UploadController.java b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/java/com/baiye/controller/UploadController.java new file mode 100644 index 0000000..c39a538 --- /dev/null +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/java/com/baiye/controller/UploadController.java @@ -0,0 +1,48 @@ +package com.baiye.controller; + +import cn.hutool.core.text.CharSequenceUtil; +import com.baiye.exception.global.BadRequestException; +import com.baiye.properties.FileProperties; +import com.baiye.util.FileUtil; +import com.google.common.collect.ImmutableMap; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; + +/** + * @author jt + */ +@RestController +@RequestMapping("/pictures") +@RequiredArgsConstructor +@Slf4j +public class UploadController { + + private final FileProperties properties; + @ApiOperation("修改头像") + @PostMapping(value = "/upload") + public ResponseEntity updateAvatar(@RequestParam("file") MultipartFile uploadFile) { + String image = "gif jpg png jpeg"; + String fileType = FileUtil.getExtensionName + (uploadFile.getOriginalFilename()); + if (fileType != null && !image.contains(fileType)) { + throw new BadRequestException("文件格式错误!, 仅支持 " + image + " 格式"); + } + // 应改为File路径 + File file = FileUtil.upload + (uploadFile, properties.getPath().getAvatar()); + ImmutableMap picture = ImmutableMap.of + ("picture", file != null + ? file.getName() : CharSequenceUtil.SPACE); + return new ResponseEntity<>(picture, HttpStatus.OK); + } +} diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-dev.yml b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-dev.yml index 7a6bfa8..9b468d1 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-dev.yml +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-dev.yml @@ -63,5 +63,5 @@ swagger: # 文件存储 storage: - download-word: C:\Users\jt\Desktop\word.xls - download-variable: C:\Users\jt\Desktop\variable.xls \ No newline at end of file + download-word: C:\Users\jt\Desktop\word.xlsx + download-variable: C:\Users\jt\Desktop\wordVariable.xlsx \ No newline at end of file diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-prod.yml b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-prod.yml index 91e5428..4336322 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-prod.yml +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-prod.yml @@ -90,5 +90,5 @@ ip: # 文件存储 storage: - download-word: http://116.62.78.17/xhs/template/word.xls - download-variable: http://116.62.78.17/xhs/template/variable.xls \ No newline at end of file + download-word: https://cdp.baiyee.vip/xhs/template/word.xlsx + download-variable: https://cdp.baiyee.vip/xhs/template/wordVariable.xlsx \ No newline at end of file diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-test.yml b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-test.yml index 33ff0f7..48386d9 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-test.yml +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-api/src/main/resources/config/application-test.yml @@ -63,5 +63,5 @@ swagger: # 文件存储 storage: - download-word: http://8.130.96.163:8001/xhs/template/word.xls - download-variable: http://8.130.96.163:8001/xhs/template/wordVariable.xls \ No newline at end of file + download-word: http://8.130.96.163:8001/xhs/template/word.xlsx + download-variable: http://8.130.96.163:8001/xhs/template/wordVariable.xlsx \ No newline at end of file diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/SourceOrganize.java b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/SourceOrganize.java index de6d004..4218a5f 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/SourceOrganize.java +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/SourceOrganize.java @@ -30,4 +30,7 @@ public class SourceOrganize implements Serializable { @ApiModelProperty(value = "创建时间") private Date createTime; + + @ApiModelProperty(value = "创建人") + private Long createBy; } diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/Template.java b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/Template.java index 8791944..60ce60d 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/Template.java +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/Template.java @@ -8,6 +8,7 @@ import io.swagger.annotations.ApiOperation; import lombok.Data; import java.io.Serializable; +import java.util.Date; /** * @author jt @@ -29,4 +30,10 @@ public class Template implements Serializable { @ApiModelProperty(value = "类型 1-文字模板 2-图片 3-文字变量模板") private int templateType; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "创建人") + private Long createBy; } diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/Variable.java b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/Variable.java index 8ad5759..1480309 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/Variable.java +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/entity/Variable.java @@ -9,6 +9,7 @@ import lombok.Data; import javax.validation.constraints.NotNull; import java.io.Serializable; +import java.util.Date; /** * @author jt @@ -30,4 +31,10 @@ public class Variable implements Serializable { @ApiModelProperty(value = "变量内容") private String variableContent; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "创建人") + private Long createBy; } diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/util/FileUtil.java b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/util/FileUtil.java new file mode 100644 index 0000000..49bd6ad --- /dev/null +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-core/src/main/java/com/baiye/util/FileUtil.java @@ -0,0 +1,331 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.baiye.util; + +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.poi.excel.BigExcelWriter; +import cn.hutool.poi.excel.ExcelUtil; +import org.apache.poi.util.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.security.MessageDigest; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * File工具类,扩展 hutool 工具包 + * + * @author Zheng Jie + * @date 2018-12-27 + */ +public class FileUtil extends cn.hutool.core.io.FileUtil { + + private static final Logger log = LoggerFactory.getLogger(FileUtil.class); + + /** + * 系统临时目录 + *
+ * windows 包含路径分割符,但Linux 不包含, + * 在windows \\==\ 前提下, + * 为安全起见 同意拼装 路径分割符, + *
+     *       java.io.tmpdir
+     *       windows : C:\Users/xxx\AppData\Local\Temp\
+     *       linux: /temp
+     * 
+ */ + public static final String SYS_TEM_DIR = System.getProperty("java.io.tmpdir") + File.separator; + /** + * 定义GB的计算常量 + */ + private static final int GB = 1024 * 1024 * 1024; + /** + * 定义MB的计算常量 + */ + private static final int MB = 1024 * 1024; + /** + * 定义KB的计算常量 + */ + private static final int KB = 1024; + + /** + * 格式化小数 + */ + private static final DecimalFormat DF = new DecimalFormat("0.00"); + + public static final String IMAGE = "图片"; + public static final String TXT = "文档"; + public static final String MUSIC = "音乐"; + public static final String VIDEO = "视频"; + public static final String OTHER = "其他"; + + + /** + * MultipartFile转File + */ + public static File toFile(MultipartFile multipartFile) { + // 获取文件名 + String fileName = multipartFile.getOriginalFilename(); + // 获取文件后缀 + String prefix = "." + getExtensionName(fileName); + File file = null; + try { + // 用uuid作为文件名,防止生成的临时文件重复 + file = File.createTempFile(IdUtil.simpleUUID(), prefix); + // MultipartFile to File + multipartFile.transferTo(file); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + return file; + } + + /** + * 获取文件扩展名,不带 . + */ + public static String getExtensionName(String filename) { + if ((filename != null) && (filename.length() > 0)) { + int dot = filename.lastIndexOf('.'); + if ((dot > -1) && (dot < (filename.length() - 1))) { + return filename.substring(dot + 1); + } + } + return filename; + } + + /** + * Java文件操作 获取不带扩展名的文件名 + */ + public static String getFileNameNoEx(String filename) { + if ((filename != null) && (filename.length() > 0)) { + int dot = filename.lastIndexOf('.'); + if ((dot > -1) && (dot < (filename.length()))) { + return filename.substring(0, dot); + } + } + return filename; + } + + /** + * 文件大小转换 + */ + public static String getSize(long size) { + String resultSize; + if (size / GB >= 1) { + //如果当前Byte的值大于等于1GB + resultSize = DF.format(size / (float) GB) + "GB "; + } else if (size / MB >= 1) { + //如果当前Byte的值大于等于1MB + resultSize = DF.format(size / (float) MB) + "MB "; + } else if (size / KB >= 1) { + //如果当前Byte的值大于等于1KB + resultSize = DF.format(size / (float) KB) + "KB "; + } else { + resultSize = size + "B "; + } + return resultSize; + } + + /** + * inputStream 转 File + */ + static File inputStreamToFile(InputStream ins, String name) throws Exception { + File file = new File(SYS_TEM_DIR + name); + if (file.exists()) { + return file; + } + OutputStream os = new FileOutputStream(file); + int bytesRead; + int len = 8192; + byte[] buffer = new byte[len]; + while ((bytesRead = ins.read(buffer, 0, len)) != -1) { + os.write(buffer, 0, bytesRead); + } + os.close(); + ins.close(); + return file; + } + + /** + * 将文件名解析成文件的上传路径 + */ + public static File upload(MultipartFile file, String filePath) { + Date date = new Date(); + SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS"); + String name = getFileNameNoEx(file.getOriginalFilename()); + String suffix = getExtensionName(file.getOriginalFilename()); + String nowStr = "-" + format.format(date); + try { + String fileName = name + nowStr + "." + suffix; + String path = filePath + fileName; + // getCanonicalFile 可解析正确各种路径 + File dest = new File(path).getCanonicalFile(); + // 检测是否存在目录 + if (!dest.getParentFile().exists()) { + if (!dest.getParentFile().mkdirs()) { + System.out.println("was not successful."); + } + } + // 文件写入 + file.transferTo(dest); + return dest; + } catch (Exception e) { + log.error(e.getMessage(), e); + } + return null; + } + + /** + * 导出excel + */ + public static void downloadExcel(List> list, HttpServletResponse response) throws IOException { + String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx"; + File file = new File(tempPath); + BigExcelWriter writer = ExcelUtil.getBigWriter(file); + // 一次性写出内容,使用默认样式,强制输出标题 + writer.write(list, true); + //response为HttpServletResponse对象 + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); + //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 + response.setHeader("Content-Disposition", "attachment;filename=file.xlsx"); + ServletOutputStream out = response.getOutputStream(); + // 终止后删除临时文件 + file.deleteOnExit(); + writer.flush(out, true); + //此处记得关闭输出Servlet流 + IoUtil.close(out); + } + + public static String getFileType(String type) { + String documents = "txt doc pdf ppt pps xlsx xls docx"; + String music = "mp3 wav wma mpa ram ra aac aif m4a"; + String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg"; + String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg"; + if (image.contains(type)) { + return IMAGE; + } else if (documents.contains(type)) { + return TXT; + } else if (music.contains(type)) { + return MUSIC; + } else if (video.contains(type)) { + return VIDEO; + } else { + return OTHER; + } + } + + /** + * 判断两个文件是否相同 + */ + public static boolean check(File file1, File file2) { + String img1Md5 = getMd5(file1); + String img2Md5 = getMd5(file2); + return img1Md5.equals(img2Md5); + } + + /** + * 判断两个文件是否相同 + */ + public static boolean check(String file1Md5, String file2Md5) { + return file1Md5.equals(file2Md5); + } + + private static byte[] getByte(File file) { + // 得到文件长度 + byte[] b = new byte[(int) file.length()]; + try { + InputStream in = new FileInputStream(file); + try { + System.out.println(in.read(b)); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } catch (FileNotFoundException e) { + log.error(e.getMessage(), e); + return null; + } + return b; + } + + private static String getMd5(byte[] bytes) { + // 16进制字符 + char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + try { + MessageDigest mdTemp = MessageDigest.getInstance("MD5"); + mdTemp.update(bytes); + byte[] md = mdTemp.digest(); + int j = md.length; + char[] str = new char[j * 2]; + int k = 0; + // 移位 输出字符串 + for (byte byte0 : md) { + str[k++] = hexDigits[byte0 >>> 4 & 0xf]; + str[k++] = hexDigits[byte0 & 0xf]; + } + return new String(str); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + return null; + } + + /** + * 下载文件 + * + * @param request / + * @param response / + * @param file / + */ + public static void downloadFile(HttpServletRequest request, HttpServletResponse response, File file, boolean deleteOnExit) { + response.setCharacterEncoding(request.getCharacterEncoding()); + response.setContentType("application/octet-stream"); + FileInputStream fis = null; + try { + fis = new FileInputStream(file); + response.setHeader("Content-Disposition", "attachment; filename=" + file.getName()); + IOUtils.copy(fis, response.getOutputStream()); + response.flushBuffer(); + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + if (fis != null) { + try { + fis.close(); + if (deleteOnExit) { + file.deleteOnExit(); + } + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + } + } + + public static String getMd5(File file) { + return getMd5(getByte(file)); + } + +} diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/ResourceVariableServiceImpl.java b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/ResourceVariableServiceImpl.java index d231db8..bd3a7ef 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/ResourceVariableServiceImpl.java +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/ResourceVariableServiceImpl.java @@ -1,6 +1,7 @@ package com.baiye.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONUtil; import com.baiye.core.base.api.Result; import com.baiye.dao.VariableMapper; @@ -9,12 +10,12 @@ import com.baiye.entity.Variable; import com.baiye.query.SourceVariableQuery; import com.baiye.service.ResourceVariableService; import com.baiye.util.QueryHelpUtils; +import com.baiye.util.SecurityUtils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import javax.transaction.Transactional; import java.util.List; @@ -41,6 +42,10 @@ public class ResourceVariableServiceImpl implements ResourceVariableService { } if (CollUtil.isNotEmpty(operateVariableDTO.getSourceVariableDTO())) { List variables = JSONUtil.toList(JSONUtil.toJsonStr(operateVariableDTO.getSourceVariableDTO()), Variable.class); + variables.forEach(item -> { + item.setCreateTime(DateUtil.date()); + item.setCreateBy(SecurityUtils.getCurrentUserId()); + }); variableMapper.insertAll(variables); } return Result.success("操作成功"); diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SmartWriteServiceImpl.java b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SmartWriteServiceImpl.java index bba0042..3ef996c 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SmartWriteServiceImpl.java +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SmartWriteServiceImpl.java @@ -15,7 +15,6 @@ import com.baiye.entity.Template; import com.baiye.entity.Variable; import com.baiye.exception.global.BadRequestException; import com.baiye.properties.FileProperties; -import com.baiye.request.RequestBaiDuApi; import com.baiye.service.SmartWriteService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.hankcs.hanlp.HanLP; @@ -76,10 +75,10 @@ public class SmartWriteServiceImpl implements SmartWriteService { Map mapByNumber = variables.stream().collect(Collectors.toMap(Variable::getNumber, Variable::getVariableContent)); List deal = new ArrayList<>(); - String[] templateSpilt = templateContent.split("&v&"); - if (templateSpilt.length == 2) { + int count = (templateContent + " ").split("&v&").length - 1; + if (count == 1) { deal = deal(mapByNumber, templateContent); - } else if (templateSpilt.length < 2) { + } else if (count == 0) { deal.add(templateContent); } else { Map map = new HashMap<>(4); @@ -136,10 +135,8 @@ public class SmartWriteServiceImpl implements SmartWriteService { Word07Writer writer = new Word07Writer(); for (String templateContent : randomSeries) { if (CollUtil.isNotEmpty(picTrues)) { - //下载图片 - File file = FileUtil.file(properties.getPath().getAvatar() + picTrues.get(rand.nextInt(picTrues.size()))); //添加图片 - writer.addPicture(file, 350, 250); + getFile(picTrues, writer, rand); } // 添加段落(标题) if (smartWriteDTO.getSourceId() != null) { @@ -172,6 +169,20 @@ public class SmartWriteServiceImpl implements SmartWriteService { writer.close(); } + private void getFile(List picTrues, Word07Writer writer, Random rand) { + if (CollUtil.isNotEmpty(picTrues)) { + String path = picTrues.get(rand.nextInt(picTrues.size())); + File file = FileUtil.file(properties.getPath().getAvatar() + path); + try { + writer.addPicture(file, 350, 250); + } catch (Exception e) { + log.error("图片地址不存在:{}", path); + picTrues.removeIf(s -> s.equals(path)); + getFile(picTrues, writer, rand); + } + } + } + private String getTitle(List titles, Boolean isCreate, String templateContent) { Random rand = new Random(); String title = titles.get(rand.nextInt(titles.size())); diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SourceOrganizeServiceImpl.java b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SourceOrganizeServiceImpl.java index 81639c1..74301a6 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SourceOrganizeServiceImpl.java +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SourceOrganizeServiceImpl.java @@ -8,6 +8,7 @@ import com.baiye.exception.global.BadRequestException; import com.baiye.query.SourceOrganizeQuery; import com.baiye.service.SourceOrganizeService; import com.baiye.util.QueryHelpUtils; +import com.baiye.util.SecurityUtils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; @@ -42,6 +43,7 @@ public class SourceOrganizeServiceImpl implements SourceOrganizeService { sourceOrganize.setOrganizeName(sourceOrganizeDTO.getOrganizeName()); sourceOrganize.setOrganizeRemark(sourceOrganizeDTO.getOrganizeRemark()); sourceOrganize.setCreateTime(new Date()); + sourceOrganize.setCreateBy(SecurityUtils.getCurrentUserId()); sourceOrganizeMapper.insert(sourceOrganize); return Result.success("新增成功"); } diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SourceServiceImpl.java b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SourceServiceImpl.java index 2157b49..13b82b0 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SourceServiceImpl.java +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/SourceServiceImpl.java @@ -8,7 +8,6 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; -import com.baiye.User; import com.baiye.core.base.api.Result; import com.baiye.core.page.PageResult; import com.baiye.dao.SourceMapper; @@ -16,7 +15,6 @@ import com.baiye.dao.TemplateMapper; import com.baiye.dao.VariableMapper; import com.baiye.dto.SourceDTO; import com.baiye.dto.SourceVariableDTO; -import com.baiye.dto.UserDto; import com.baiye.entity.Source; import com.baiye.entity.SourceOrganize; import com.baiye.entity.Template; @@ -36,7 +34,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.domain.Pageable; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -120,6 +117,8 @@ public class SourceServiceImpl implements SourceService { template.setSourceId(source.getId()); template.setTemplateContent(pic); template.setTemplateType(source.getSourceType()); + template.setCreateTime(new Date()); + template.setCreateBy(SecurityUtils.getCurrentUserId()); list.add(template); } templateMapper.insertAll(list); @@ -128,7 +127,7 @@ public class SourceServiceImpl implements SourceService { //文字变量模板 addSourceByVariable(sourceDTO, source.getId(), source.getSourceType(), file); } else { - //文字素材 和文字模板 + //文字素材 和标题模板 addSourceByWord(sourceDTO, source.getId(), source.getSourceType(), file); } @@ -181,19 +180,22 @@ public class SourceServiceImpl implements SourceService { */ private void addSourceByWord(SourceDTO sourceDTO, Long sourceId, Integer type, MultipartFile file) { List