下载文件管理列表

master
gongzhenkun 2 years ago
parent 8b019a4f44
commit 4aa2040982

@ -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<TDownloadZip> list = itDownloadZipService.queryByPage(tDownloadZip);
return getDataTable(list);
}
}

@ -3,18 +3,23 @@ package com.ruoyi.web.controller.pc;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils; 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.file.FileUtils;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TDownloadZip;
import com.ruoyi.system.domain.TImage; import com.ruoyi.system.domain.TImage;
import com.ruoyi.system.domain.TRecord; import com.ruoyi.system.domain.TRecord;
import com.ruoyi.system.domain.req.AppRecordReq; import com.ruoyi.system.domain.req.AppRecordReq;
import com.ruoyi.system.domain.req.TRecordResultReq; import com.ruoyi.system.domain.req.TRecordResultReq;
import com.ruoyi.system.domain.resp.TRecordResp; import com.ruoyi.system.domain.resp.TRecordResp;
import com.ruoyi.system.service.ITDownloadZipService;
import com.ruoyi.system.service.ITImageService; import com.ruoyi.system.service.ITImageService;
import com.ruoyi.system.service.ITRecordService; import com.ruoyi.system.service.ITRecordService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -31,10 +36,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* Controller * Controller
@ -56,6 +58,9 @@ public class TRecordController extends BaseController
@Value("${export.img.url}") @Value("${export.img.url}")
private String imgUrl; private String imgUrl;
@Autowired
private ITDownloadZipService itDownloadZipService;
/** /**
* *
*/ */
@ -130,8 +135,8 @@ public class TRecordController extends BaseController
{ {
List<TImage> images = imageService.queryImagByExport(tRecord); List<TImage> images = imageService.queryImagByExport(tRecord);
List<Map<String,Object>> exportInfo = new ArrayList<>(); List<Map<String,Object>> exportInfo = new ArrayList<>();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
if(CollectionUtils.isNotEmpty(images)){ if(CollectionUtils.isNotEmpty(images)){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
images.forEach(image -> { images.forEach(image -> {
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
map.put("urlPath",imgUrl + image.getPath()); map.put("urlPath",imgUrl + image.getPath());
@ -152,9 +157,28 @@ public class TRecordController extends BaseController
} }
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
try { try {
FileUtils.setAttachmentResponseHeader(response, "舌面舌下图片下载"); // FileUtils.setAttachmentResponseHeader(response, "舌面舌下图片下载");
FileUtils.urlResourceWriteBytes(exportInfo, response.getOutputStream()); // 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) { } catch (Exception e) {
logger.error("图片下载方法exportImg报错",e);
e.printStackTrace(); e.printStackTrace();
} }
} }

@ -125,6 +125,14 @@ public class RuoYiConfig
return getProfile() + "/download/"; return getProfile() + "/download/";
} }
/**
*
*/
public static String getZipDownloadPath()
{
return getProfile() + "/downloadZip";
}
/** /**
* *
*/ */

@ -3,6 +3,8 @@ package com.ruoyi.common.utils.file;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; 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 * byte
* *
@ -147,6 +183,57 @@ public class FileUtils
} }
} }
/**
* byte
*
* @param filePathList
* @param localFile
* @return
*/
public static void downloadLocalZip(List<Map<String,Object>> 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<String,Object> 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);
}
}
/** /**
* *
* *

@ -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();
}
}

@ -55,6 +55,16 @@ public class TRecordResultReq
@ApiModelProperty("医生是否修改标识") @ApiModelProperty("医生是否修改标识")
private String updateFlag; 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) { public void setUpdateFlag(String updateFlag) {
this.updateFlag = updateFlag; this.updateFlag = updateFlag;

@ -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<TDownloadZip> queryByPage(TDownloadZip tDownloadZip);
/**
*
* @param tDownloadZip
* @return
*/
int insertTDownloadZip(TDownloadZip tDownloadZip);
/**
*
* @param tDownloadZip
* @return
*/
int updateTDownloadZip(TDownloadZip tDownloadZip);
}

@ -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<TDownloadZip> queryByPage(TDownloadZip tDownloadZip);
/**
*
* @param tDownloadZip
* @return
*/
int insertTDownloadZip(TDownloadZip tDownloadZip);
/**
*
* @param tDownloadZip
* @return
*/
int updateTDownloadZip(TDownloadZip tDownloadZip);
}

@ -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<TDownloadZip> 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);
}
}

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.TDownloadZipMapper">
<resultMap type="TDownloadZip" id="TDownloadZipResult">
<result property="id" column="id" />
<result property="path" column="path" />
<result property="name" column="name" />
<result property="status" column="status" />
<result property="userId" column="user_id" />
<result property="createTime" column="create_time"/>
</resultMap>
<sql id="selectTHospitalVo">
select id, path, name, status, user_id, create_time from t_download_zip
</sql>
<insert id="insertTDownloadZip" parameterType="TDownloadZip" useGeneratedKeys="true" keyProperty="id">
insert into t_download_zip
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="path != null and path != ''">path,</if>
<if test="name != null and name != ''">name,</if>
<if test="status != null">status,</if>
<if test="userId != null">user_id,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="path != null and path != ''">#{path},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="status != null">#{status},</if>
<if test="userId != null">#{userId},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="updateTDownloadZip" parameterType="TDownloadZip">
update t_download_zip
<trim prefix="SET" suffixOverrides=",">
<if test="path != null and path != ''">path = #{path},</if>
<if test="name != null and name != ''">name = #{name},</if>
<if test="status != null">status = #{status},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="createTime != null">create_time = #{createTime},</if>
</trim>
where id = #{id}
</update>
<select id="queryByPage" resultMap="TDownloadZipResult">
select
id,
path,
name,
status,
user_id,
create_time
from t_download_zip
where user_id = #{userId}
order by create_time desc
</select>
</mapper>
Loading…
Cancel
Save