修复下载记录列表查询接口分页数据不正确问题
This commit is contained in:
parent
ef4366d148
commit
4694649c67
@ -146,10 +146,11 @@ public class FiletransferController {
|
||||
httpServletResponse.addHeader("Content-Disposition", "attachment;fileName=" + fileName);// 设置文件名
|
||||
|
||||
filetransferService.downloadFile(httpServletResponse, downloadFileDTO);
|
||||
List<String> userFileIds = Arrays.asList(downloadFileDTO.getUserFileId());
|
||||
// 保存下载记录
|
||||
downloadRecordService.saveDownloadRecord(Arrays.asList(downloadFileDTO.getUserFileId()));
|
||||
downloadRecordService.saveDownloadRecord(userFileIds);
|
||||
// 增加下载次数
|
||||
userFileService.incrementDownloadCount(Arrays.asList(downloadFileDTO.getUserFileId()));
|
||||
userFileService.incrementDownloadCount(userFileIds);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量下载文件", description = "批量下载文件", tags = {"filetransfer"})
|
||||
|
||||
@ -29,6 +29,9 @@ public class DownloadRecord extends BaseEntity
|
||||
@Excel(name = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Excel(name = "文件名称")
|
||||
private String fileNames;
|
||||
|
||||
/** 下载时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "下载时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
@ -56,6 +59,4 @@ public class DownloadRecord extends BaseEntity
|
||||
/** 用户昵称 */
|
||||
private String nickName;
|
||||
|
||||
/** 文件名称(多个用,隔开) */
|
||||
private String fileNames;
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.ip.AddressUtils;
|
||||
import com.ruoyi.common.utils.ip.IpUtils;
|
||||
import com.ruoyi.file.domain.UserFile;
|
||||
import com.ruoyi.file.mapper.UserFileMapper;
|
||||
import eu.bitwalker.useragentutils.UserAgent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -36,6 +37,9 @@ public class DownloadRecordServiceImpl implements IDownloadRecordService
|
||||
@Autowired
|
||||
private DownloadRecordMapper downloadRecordMapper;
|
||||
|
||||
@Autowired
|
||||
private UserFileMapper userFileMapper;
|
||||
|
||||
/**
|
||||
* 查询下载记录
|
||||
*
|
||||
@ -57,30 +61,7 @@ public class DownloadRecordServiceImpl implements IDownloadRecordService
|
||||
@Override
|
||||
public List<DownloadRecord> selectDownloadRecordList(DownloadRecord downloadRecord)
|
||||
{
|
||||
List<DownloadRecord> recordList = downloadRecordMapper.selectDownloadRecordList(downloadRecord);
|
||||
for (DownloadRecord record : recordList) {
|
||||
List<DownloadRecordItem> itemList = record.getDownloadRecordItemList();
|
||||
if (itemList != null && !itemList.isEmpty()) {
|
||||
String fileNames = itemList.stream()
|
||||
.map(DownloadRecordItem::getUserFile) // 取出 UserFile
|
||||
.filter(Objects::nonNull)
|
||||
.map(userFile -> {
|
||||
String name = userFile.getFileName();
|
||||
String ext = userFile.getExtendName();
|
||||
if (ext != null && !ext.isEmpty()) {
|
||||
return name + "." + ext;
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining(","));
|
||||
record.setFileNames(fileNames);
|
||||
} else {
|
||||
record.setFileNames("");
|
||||
}
|
||||
}
|
||||
return recordList;
|
||||
return downloadRecordMapper.selectDownloadRecordList(downloadRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,6 +145,21 @@ public class DownloadRecordServiceImpl implements IDownloadRecordService
|
||||
downloadRecord.setBrowser(browser);
|
||||
downloadRecord.setDownloadTime(DateUtils.getNowDate());
|
||||
List<DownloadRecordItem> itemList = new ArrayList<>();
|
||||
List<UserFile> userFileList = userFileMapper.selectByUserFileIds(userFileIds);
|
||||
String fileNames = userFileList.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(userFile -> {
|
||||
String name = userFile.getFileName();
|
||||
String ext = userFile.getExtendName();
|
||||
if (ext != null && !ext.isEmpty()) {
|
||||
return name + "." + ext;
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining(","));
|
||||
downloadRecord.setFileNames(fileNames);
|
||||
for (String userFileId : userFileIds) {
|
||||
DownloadRecordItem downloadRecordItem = new DownloadRecordItem();
|
||||
downloadRecordItem.setUserFileId(userFileId);
|
||||
|
||||
@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<resultMap type="DownloadRecord" id="DownloadRecordResult">
|
||||
<result property="recordId" column="record_id" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="fileNames" column="file_names" />
|
||||
<result property="downloadTime" column="download_time" />
|
||||
<result property="ipaddr" column="ipaddr" />
|
||||
<result property="location" column="location" />
|
||||
@ -28,23 +29,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDownloadRecordVo">
|
||||
select record_id, user_id, download_time, ipaddr, location, browser, os from download_record
|
||||
select record_id, user_id, file_names, download_time, ipaddr, location, browser, os from download_record
|
||||
</sql>
|
||||
|
||||
<select id="selectDownloadRecordList" parameterType="DownloadRecord" resultMap="DownloadRecordDownloadRecordItemResult">
|
||||
select a.record_id, a.user_id, a.download_time, a.ipaddr, a.location, a.browser, a.os, u.nick_name as nick_name,
|
||||
b.item_id as sub_item_id, b.record_id as sub_record_id, b.userFileId as sub_userFileId
|
||||
<select id="selectDownloadRecordList" parameterType="DownloadRecord" resultMap="DownloadRecordResult">
|
||||
select a.record_id, a.user_id, a.file_names, a.download_time, a.ipaddr, a.location, a.browser, a.os, u.nick_name as nick_name
|
||||
from download_record a
|
||||
left join download_record_item b on b.record_id = a.record_id
|
||||
left join sys_user u on u.user_id = a.user_id
|
||||
<where>
|
||||
<if test="params.beginDownloadTime != null and params.beginDownloadTime != '' and params.endDownloadTime != null and params.endDownloadTime != ''"> and download_time between #{params.beginDownloadTime} and #{params.endDownloadTime}</if>
|
||||
<if test="location != null and location != ''"> and location like concat('%', #{location}, '%')</if>
|
||||
</where>
|
||||
order by a.download_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectDownloadRecordByRecordId" parameterType="Long" resultMap="DownloadRecordDownloadRecordItemResult">
|
||||
select a.record_id, a.user_id, a.download_time, a.ipaddr, a.location, a.browser, a.os,
|
||||
select a.record_id, a.user_id, a.file_names, a.download_time, a.ipaddr, a.location, a.browser, a.os,
|
||||
b.item_id as sub_item_id, b.record_id as sub_record_id, b.userFileId as sub_userFileId
|
||||
from download_record a
|
||||
left join download_record_item b on b.record_id = a.record_id
|
||||
@ -55,6 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
insert into download_record
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="fileNames != null">file_names,</if>
|
||||
<if test="downloadTime != null">download_time,</if>
|
||||
<if test="ipaddr != null">ipaddr,</if>
|
||||
<if test="location != null">location,</if>
|
||||
@ -63,6 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="fileNames != null">#{fileNames},</if>
|
||||
<if test="downloadTime != null">#{downloadTime},</if>
|
||||
<if test="ipaddr != null">#{ipaddr},</if>
|
||||
<if test="location != null">#{location},</if>
|
||||
@ -75,6 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
update download_record
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="userId != null">user_id = #{userId},</if>
|
||||
<if test="fileNames != null">file_names = #{fileNames},</if>
|
||||
<if test="downloadTime != null">download_time = #{downloadTime},</if>
|
||||
<if test="ipaddr != null">ipaddr = #{ipaddr},</if>
|
||||
<if test="location != null">location = #{location},</if>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user