From 4aa20409828a26dafa375f5164990bca7798ae1a Mon Sep 17 00:00:00 2001 From: gongzhenkun <1658878546@qq.com> Date: Mon, 27 Mar 2023 16:48:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/pc/TDownloadZipController.java | 49 ++++++++ .../web/controller/pc/TRecordController.java | 38 ++++-- .../com/ruoyi/common/config/RuoYiConfig.java | 8 ++ .../ruoyi/common/utils/file/FileUtils.java | 87 ++++++++++++++ .../com/ruoyi/system/domain/TDownloadZip.java | 108 ++++++++++++++++++ .../system/domain/req/TRecordResultReq.java | 10 ++ .../system/mapper/TDownloadZipMapper.java | 38 ++++++ .../system/service/ITDownloadZipService.java | 36 ++++++ .../service/impl/TDownloadZipServiceImpl.java | 49 ++++++++ .../mapper/system/TDownloadZipMapper.xml | 62 ++++++++++ 10 files changed, 478 insertions(+), 7 deletions(-) create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/TDownloadZipController.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/TDownloadZip.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/TDownloadZipMapper.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/ITDownloadZipService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDownloadZipServiceImpl.java create mode 100644 ruoyi-system/src/main/resources/mapper/system/TDownloadZipMapper.xml diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/TDownloadZipController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/TDownloadZipController.java new file mode 100644 index 0000000..f6dd0ba --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/TDownloadZipController.java @@ -0,0 +1,49 @@ +package com.ruoyi.web.controller.pc; + +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +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.poi.ExcelUtil; +import com.ruoyi.system.domain.TDownloadZip; +import com.ruoyi.system.domain.THospital; +import com.ruoyi.system.domain.resp.THospitalPageResp; +import com.ruoyi.system.service.ITDownloadZipService; +import com.ruoyi.system.service.ITHospitalService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 医院信息Controller + * + * @author ruoyi + * @date 2022-08-03 + */ +@Api("pc-下载列表") +@RestController +@RequestMapping("/system/downloadZip") +public class TDownloadZipController extends BaseController +{ + @Autowired + private ITDownloadZipService itDownloadZipService; + + /** + * 查询医院信息列表 + */ + @ApiOperation("查询医院信息列表") + @PostMapping("/list") + @Log(title = "查询医院信息列表", businessType = BusinessType.OTHER) + public TableDataInfo list(@RequestBody TDownloadZip tDownloadZip) + { + startPage(); + List list = itDownloadZipService.queryByPage(tDownloadZip); + return getDataTable(list); + } + +} 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 5b9478b..c91fd61 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 @@ -3,18 +3,23 @@ package com.ruoyi.web.controller.pc; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.core.controller.BaseController; 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.DateUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.domain.TDownloadZip; import com.ruoyi.system.domain.TImage; import com.ruoyi.system.domain.TRecord; import com.ruoyi.system.domain.req.AppRecordReq; import com.ruoyi.system.domain.req.TRecordResultReq; import com.ruoyi.system.domain.resp.TRecordResp; +import com.ruoyi.system.service.ITDownloadZipService; import com.ruoyi.system.service.ITImageService; import com.ruoyi.system.service.ITRecordService; import io.swagger.annotations.Api; @@ -31,10 +36,7 @@ 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; +import java.util.*; /** * 诊断记录信息Controller @@ -56,6 +58,9 @@ public class TRecordController extends BaseController @Value("${export.img.url}") private String imgUrl; + @Autowired + private ITDownloadZipService itDownloadZipService; + /** * 查询诊断记录信息列表 */ @@ -130,8 +135,8 @@ public class TRecordController extends BaseController { List images = imageService.queryImagByExport(tRecord); List> exportInfo = new ArrayList<>(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); if(CollectionUtils.isNotEmpty(images)){ - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); images.forEach(image -> { Map map = new HashMap<>(); map.put("urlPath",imgUrl + image.getPath()); @@ -152,9 +157,28 @@ public class TRecordController extends BaseController } response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); try { - FileUtils.setAttachmentResponseHeader(response, "舌面舌下图片下载"); - FileUtils.urlResourceWriteBytes(exportInfo, response.getOutputStream()); +// FileUtils.setAttachmentResponseHeader(response, "舌面舌下图片下载"); +// FileUtils.urlResourceWriteBytes(exportInfo, response.getOutputStream()); + String fileName = simpleDateFormat.format(new Date())+".zip"; + String partPathName = DateUtils.datePath()+"/"+ fileName; + TDownloadZip insertParam = new TDownloadZip(); + insertParam.setCreateTime(new Date()); + insertParam.setName(fileName); + insertParam.setUserId(tRecord.getUserId()); + //第一次保存下载文件到数据库 + itDownloadZipService.insertTDownloadZip(insertParam); + //下载zip到服务器 + FileUtils.downloadLocalZip(exportInfo, RuoYiConfig.getZipDownloadPath()+"/"+ partPathName); + //再将完整文件路径保存到数据库 + String filePath = FileUploadUtils.getPathFileName(RuoYiConfig.getZipDownloadPath(), partPathName); + //第二次保存下载文件到数据库 + TDownloadZip updateParam = new TDownloadZip(); + updateParam.setId(insertParam.getId()); + updateParam.setStatus(1); + updateParam.setPath(filePath); + itDownloadZipService.updateTDownloadZip(updateParam); } catch (Exception e) { + logger.error("图片下载方法exportImg报错:",e); e.printStackTrace(); } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java index 52c9db0..bf9541a 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java @@ -125,6 +125,14 @@ public class RuoYiConfig return getProfile() + "/download/"; } + /** + * 获取下载路径 + */ + public static String getZipDownloadPath() + { + return getProfile() + "/downloadZip"; + } + /** * 获取上传路径 */ 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 0d26163..c43f430 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 @@ -3,6 +3,8 @@ package com.ruoyi.common.utils.file; import java.io.*; import java.net.URL; import java.net.URLEncoder; +import java.nio.channels.Channels; +import java.nio.channels.WritableByteChannel; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -69,6 +71,40 @@ public class FileUtils } } + /** + * 输出指定文件的byte数组 + * + * @param filePath 文件路径 + * @param os 输出流 + * @return + */ + public static void downloadZip(String filePath, OutputStream os) throws IOException + { + FileInputStream fis = null; + WritableByteChannel wchannel = null; + try + { + wchannel = Channels.newChannel(os); + File file = new File(filePath); + if (!file.exists()) + { + throw new FileNotFoundException(filePath); + } + fis = new FileInputStream(file); + fis.getChannel().transferTo(0,Long.MAX_VALUE,wchannel); + } + catch (IOException e) + { + throw e; + } + finally + { + IOUtils.close(os); + IOUtils.close(wchannel); + IOUtils.close(fis); + } + } + /** * 输出指定文件的byte数组 * @@ -147,6 +183,57 @@ public class FileUtils } } + /** + * 输出指定文件的byte数组 + * + * @param filePathList 文件路径 + * @param localFile 本地文件 + * @return + */ + public static void downloadLocalZip(List> filePathList, String localFile) throws IOException + { + BufferedInputStream bufIn = null; + ZipEntry zipEntry = null; + ZipOutputStream zipOutputStream = null; + FileOutputStream fileOut = null; + try + { + File desc = new File(localFile); + if (!desc.exists()) + { + if (!desc.getParentFile().exists()) + { + desc.getParentFile().mkdirs(); + } + } + fileOut = new FileOutputStream(desc); + zipOutputStream = new ZipOutputStream(fileOut); + for(Map filePath:filePathList){ + URL file = new URL(filePath.get("urlPath").toString()); + bufIn = new BufferedInputStream(file.openStream()); + zipEntry = new ZipEntry(filePath.get("downloadPath").toString()); + zipOutputStream.putNextEntry(zipEntry); + byte[] b = new byte[1024*4]; + int length; + while ((length = bufIn.read(b)) > 0) + { + zipOutputStream.write(b, 0, length); + } + } + } + catch (IOException e) + { + throw e; + } + finally + { + zipOutputStream.closeEntry(); + IOUtils.close(zipOutputStream); + IOUtils.close(bufIn); + IOUtils.close(fileOut); + } + } + /** * 写数据到文件中 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TDownloadZip.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TDownloadZip.java new file mode 100644 index 0000000..a0cb053 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TDownloadZip.java @@ -0,0 +1,108 @@ +package com.ruoyi.system.domain; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; + +/** + * 下载文件表 t_hospital + * + * @author ruoyi + * @date 2022-08-04 + */ +@ApiModel(value = "TDownloadZip", description = "PC端下载文件表") +public class TDownloadZip extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** ID */ + @ApiModelProperty("id") + private Long id; + + /** 名称 */ + @ApiModelProperty("名称") + private String name; + + /** 路径 */ + @ApiModelProperty("路径") + private String path; + + /** 文件下载状态,0 未完成, 1 已完成 */ + @ApiModelProperty("文件下载状态,0 未完成, 1 已完成") + private int status; + + /** 用户ID */ + @ApiModelProperty("用户ID") + private Long userId; + + /** 创建时间 */ + @ApiModelProperty("创建时间") + private Date createTime; + + public void setId(Long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setPath(String path) { + this.path = path; + } + + public void setStatus(int status) { + this.status = status; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + @Override + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getPath() { + return path; + } + + public int getStatus() { + return status; + } + + public Long getUserId() { + return userId; + } + + @Override + public Date getCreateTime() { + return createTime; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("name", getName()) + .append("path", getPath()) + .append("status", getStatus()) + .append("userId", getUserId()) + .append("createTime", getCreateTime()) + .toString(); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/TRecordResultReq.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/TRecordResultReq.java index e974717..d4ba81c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/TRecordResultReq.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/TRecordResultReq.java @@ -55,6 +55,16 @@ public class TRecordResultReq @ApiModelProperty("医生是否修改标识") private String updateFlag; + //用户id + private Long userId; + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getUserId() { + return userId; + } public void setUpdateFlag(String updateFlag) { this.updateFlag = updateFlag; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TDownloadZipMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TDownloadZipMapper.java new file mode 100644 index 0000000..c17ee96 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TDownloadZipMapper.java @@ -0,0 +1,38 @@ +package com.ruoyi.system.mapper; + +import com.ruoyi.system.domain.TDownloadZip; +import com.ruoyi.system.domain.THospital; +import com.ruoyi.system.domain.resp.THospitalPageResp; + +import java.util.List; + +/** + * Mapper接口 + * + * @author ruoyi + * @date 2022-08-03 + */ +public interface TDownloadZipMapper +{ + /** + * 分页查询 + * @param tDownloadZip + * @return + */ + List queryByPage(TDownloadZip tDownloadZip); + + + /** + * 新增下载信息 + * @param tDownloadZip + * @return + */ + int insertTDownloadZip(TDownloadZip tDownloadZip); + + /** + * 修改下载信息 + * @param tDownloadZip + * @return + */ + int updateTDownloadZip(TDownloadZip tDownloadZip); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ITDownloadZipService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITDownloadZipService.java new file mode 100644 index 0000000..d829821 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITDownloadZipService.java @@ -0,0 +1,36 @@ +package com.ruoyi.system.service; + +import com.ruoyi.system.domain.TDownloadZip; +import com.ruoyi.system.domain.THospital; + +import java.util.List; + +/** + * Service接口 + * + * @author ruoyi + * @date 2022-08-03 + */ +public interface ITDownloadZipService +{ + /** + * 分页查询 + * @param tDownloadZip + * @return + */ + List queryByPage(TDownloadZip tDownloadZip); + + /** + * 新增下载信息 + * @param tDownloadZip + * @return + */ + int insertTDownloadZip(TDownloadZip tDownloadZip); + + /** + * 修改下载信息 + * @param tDownloadZip + * @return + */ + int updateTDownloadZip(TDownloadZip tDownloadZip); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDownloadZipServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDownloadZipServiceImpl.java new file mode 100644 index 0000000..b4bf1fc --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDownloadZipServiceImpl.java @@ -0,0 +1,49 @@ +package com.ruoyi.system.service.impl; + +import com.ruoyi.system.domain.TDownloadZip; +import com.ruoyi.system.mapper.TDownloadZipMapper; +import com.ruoyi.system.service.ITDownloadZipService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * Service业务层处理 + * + * @author ruoyi + * @date 2022-08-03 + */ +@Service +public class TDownloadZipServiceImpl implements ITDownloadZipService +{ + @Autowired + private TDownloadZipMapper tDownloadZipMapper; + + @Override + public List queryByPage(TDownloadZip tDownloadZip) { + return tDownloadZipMapper.queryByPage(tDownloadZip); + } + + /** + * 新增下载信息 + * + * @param tDownloadZip + * @return + */ + @Override + public int insertTDownloadZip(TDownloadZip tDownloadZip) { + return tDownloadZipMapper.insertTDownloadZip(tDownloadZip); + } + + /** + * 修改下载信息 + * + * @param tDownloadZip + * @return + */ + @Override + public int updateTDownloadZip(TDownloadZip tDownloadZip) { + return tDownloadZipMapper.updateTDownloadZip(tDownloadZip); + } +} diff --git a/ruoyi-system/src/main/resources/mapper/system/TDownloadZipMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TDownloadZipMapper.xml new file mode 100644 index 0000000..789ef9c --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/system/TDownloadZipMapper.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + select id, path, name, status, user_id, create_time from t_download_zip + + + + insert into t_download_zip + + path, + name, + status, + user_id, + create_time, + + + #{path}, + #{name}, + #{status}, + #{userId}, + #{createTime}, + + + + + update t_download_zip + + path = #{path}, + name = #{name}, + status = #{status}, + user_id = #{userId}, + create_time = #{createTime}, + + where id = #{id} + + + + \ No newline at end of file