diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/TRecordController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/TRecordController.java index c502066..5b9478b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/TRecordController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/TRecordController.java @@ -8,6 +8,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.system.domain.TImage; import com.ruoyi.system.domain.TRecord; @@ -21,12 +22,16 @@ import io.swagger.annotations.ApiOperation; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; +import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -48,6 +53,9 @@ public class TRecordController extends BaseController @Resource private ITImageService imageService; + @Value("${export.img.url}") + private String imgUrl; + /** * 查询诊断记录信息列表 */ @@ -113,6 +121,44 @@ public class TRecordController extends BaseController util.exportExcel(response, list, "诊断记录信息数据"); } + /** + * 导出诊断记录信息列表 + */ + @Log(title = "诊断记录信息导出", businessType = BusinessType.EXPORT) + @PostMapping("/exportImg") + public void exportImg(HttpServletResponse response, @RequestBody @Validated TRecordResultReq tRecord) + { + List images = imageService.queryImagByExport(tRecord); + List> exportInfo = new ArrayList<>(); + if(CollectionUtils.isNotEmpty(images)){ + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + images.forEach(image -> { + Map map = new HashMap<>(); + map.put("urlPath",imgUrl + image.getPath()); + StringBuilder downloadPath = new StringBuilder(); + downloadPath.append(image.getIdentifier()); + downloadPath.append("_"); + downloadPath.append(simpleDateFormat.format(image.getCreateTime())); + downloadPath.append("/"); + if("sm_front".endsWith(image.getName())){ + downloadPath.append("舌面原图."); + }else if("sx_front".endsWith(image.getName())){ + downloadPath.append("舌下原图."); + } + downloadPath.append(StringUtils.substringAfterLast(image.getPath(), ".")); + map.put("downloadPath",downloadPath.toString()); + exportInfo.add(map); + }); + } + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + try { + FileUtils.setAttachmentResponseHeader(response, "舌面舌下图片下载"); + FileUtils.urlResourceWriteBytes(exportInfo, response.getOutputStream()); + } catch (Exception e) { + e.printStackTrace(); + } + } + /** * 获取诊断记录信息详细信息 */ diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index fe0a89e..1826c91 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -137,5 +137,7 @@ aiPost: port: 6000 url: /tongue/algo/sm_sx - +export: + img: + url: https://tonguediag.jiicm.com/prod-api diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java index 6547e4d..8f41381 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java @@ -1,12 +1,16 @@ package com.ruoyi.common.utils.file; import java.io.*; +import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Base64; import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -65,6 +69,87 @@ public class FileUtils } } + /** + * 输出指定文件的byte数组 + * + * @param filePath 文件路径 + * @param os 输出流 + * @return + */ + public static void urlResourceWriteBytes(String filePath, OutputStream os) throws IOException + { + InputStream fis = null; + ZipEntry zipEntry = null; + ZipOutputStream zipOutputStream = null; + try + { + URL file = new URL(filePath); + fis = file.openStream(); + zipEntry = new ZipEntry(filePath); + zipOutputStream = new ZipOutputStream(os); + zipOutputStream.putNextEntry(zipEntry); + byte[] b = new byte[1024]; + int length; + while ((length = fis.read(b)) > 0) + { + zipOutputStream.write(b, 0, length); + } + } + catch (IOException e) + { + throw e; + } + finally + { + zipOutputStream.closeEntry(); + IOUtils.close(zipOutputStream); + IOUtils.close(os); + IOUtils.close(fis); + } + } + + /** + * 输出指定文件的byte数组 + * + * @param filePathList 文件路径 + * @param os 输出流 + * @return + */ + public static void urlResourceWriteBytes(List> filePathList, OutputStream os) throws IOException + { +// InputStream fis = null; + BufferedInputStream buf = null; + ZipEntry zipEntry = null; + ZipOutputStream zipOutputStream = new ZipOutputStream(os); + try + { + for(Map filePath:filePathList){ + URL file = new URL(filePath.get("urlPath").toString()); +// fis = file.openStream(); + buf = new BufferedInputStream(file.openStream()); + zipEntry = new ZipEntry(filePath.get("downloadPath").toString()); + zipOutputStream.putNextEntry(zipEntry); + byte[] b = new byte[1024]; + int length; + while ((length = buf.read(b)) > 0) + { + zipOutputStream.write(b, 0, length); + } + } + } + catch (IOException e) + { + throw e; + } + finally + { + zipOutputStream.closeEntry(); + IOUtils.close(zipOutputStream); + IOUtils.close(os); + IOUtils.close(buf); + } + } + /** * 写数据到文件中 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TImage.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TImage.java index 8d5a06b..02f60d2 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TImage.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TImage.java @@ -30,7 +30,17 @@ public class TImage extends BaseEntity @Excel(name = "名称") private String name; - public void setId(Long id) + private String identifier; + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public String getIdentifier() { + return identifier; + } + + public void setId(Long id) { this.id = id; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TImageMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TImageMapper.java index 0fec12e..80da587 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TImageMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TImageMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.system.mapper; import java.util.List; import com.ruoyi.system.domain.TImage; +import com.ruoyi.system.domain.req.TRecordResultReq; /** * 图片Mapper接口 @@ -60,4 +61,6 @@ public interface TImageMapper public int deleteTImageByIds(Long[] ids); int deleteTImageByThirdId(Long id); + + List queryImagByExport(TRecordResultReq tRecord); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ITImageService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITImageService.java index 5586c57..cf5e83c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ITImageService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITImageService.java @@ -2,6 +2,7 @@ package com.ruoyi.system.service; import java.util.List; import com.ruoyi.system.domain.TImage; +import com.ruoyi.system.domain.req.TRecordResultReq; /** * 图片Service接口 @@ -60,4 +61,6 @@ public interface ITImageService public int deleteTImageById(Long id); int deleteTImageByThirdId(Long id); + + List queryImagByExport(TRecordResultReq tRecord); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TImageServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TImageServiceImpl.java index 2c145e8..bc34998 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TImageServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TImageServiceImpl.java @@ -2,6 +2,7 @@ package com.ruoyi.system.service.impl; import java.util.List; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.system.domain.req.TRecordResultReq; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.mapper.TImageMapper; @@ -98,4 +99,9 @@ public class TImageServiceImpl implements ITImageService { return tImageMapper.deleteTImageByThirdId(id); } + + @Override + public List queryImagByExport(TRecordResultReq tRecord) { + return tImageMapper.queryImagByExport(tRecord); + } } diff --git a/ruoyi-system/src/main/resources/mapper/system/TImageMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TImageMapper.xml index 4ec325a..4ec4fac 100644 --- a/ruoyi-system/src/main/resources/mapper/system/TImageMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/TImageMapper.xml @@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -72,4 +73,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from t_image where third_id = #{id} + +