Browse Source

文件上传修改

develop
wangsixiang 5 months ago
parent
commit
f03bb8c2ee
  1. 22
      zc-business/src/main/java/com/zc/business/controller/DcFileDownloadController.java
  2. 33
      zc-business/src/main/java/com/zc/business/domain/DcFileDownload.java
  3. 2
      zc-business/src/main/java/com/zc/business/mapper/DcFileDownloadMapper.java
  4. 2
      zc-business/src/main/java/com/zc/business/service/IDcFileDownloadService.java
  5. 5
      zc-business/src/main/java/com/zc/business/service/impl/DcFileDownloadServiceImpl.java
  6. 15
      zc-business/src/main/resources/mapper/business/DcFileDownloadMapper.xml

22
zc-business/src/main/java/com/zc/business/controller/DcFileDownloadController.java

@ -6,6 +6,7 @@ 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.exception.file.FileSizeLimitExceededException;
import com.ruoyi.common.utils.file.FileUploadUtils; 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;
@ -16,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
@ -41,6 +43,10 @@ public class DcFileDownloadController extends BaseController {
private IDcFileDownloadService dcFileDownloadService; private IDcFileDownloadService dcFileDownloadService;
@Autowired @Autowired
private ServerConfig serverConfig; private ServerConfig serverConfig;
/**
* 默认大小 20M
*/
public static final long DEFAULT_MAX_SIZE = 20 * 1024 * 1024;
/** /**
* 查询文件管理列表 * 查询文件管理列表
*/ */
@ -114,12 +120,23 @@ public class DcFileDownloadController extends BaseController {
String filePath = RuoYiConfig.getFileManagementPath(); String filePath = RuoYiConfig.getFileManagementPath();
// 上传并返回新文件名称 // 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file); String fileName = FileUploadUtils.upload(filePath, file);
//文件后缀
String extension = FileUploadUtils.getExtension(file);
//文件大小,单位为B
long size = file.getSize();
//文件大小验证
if (size > DEFAULT_MAX_SIZE)
{
throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
}
String url = serverConfig.getUrl() + fileName; String url = serverConfig.getUrl() + fileName;
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
ajax.put("url", url); ajax.put("url", url);
ajax.put("fileName", fileName); ajax.put("fileName", fileName);
ajax.put("newFileName", FileUtils.getName(fileName)); ajax.put("newFileName", FileUtils.getName(fileName));
ajax.put("originalFilename", file.getOriginalFilename()); ajax.put("originalFilename", file.getOriginalFilename());
ajax.put("extension", extension);
ajax.put("size", size);
return ajax; return ajax;
} }
catch (Exception e) catch (Exception e)
@ -127,5 +144,10 @@ public class DcFileDownloadController extends BaseController {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
} }
//下载请求接口-下载数量+1
@GetMapping("/downloadIncrease/{id}")
public AjaxResult downloadIncrease(@PathVariable Long id) {
return toAjax(dcFileDownloadService.downloadIncrease(id));
}
} }

33
zc-business/src/main/java/com/zc/business/domain/DcFileDownload.java

@ -25,8 +25,41 @@ public class DcFileDownload extends BaseEntity
/** 文件地址 */ /** 文件地址 */
@Excel(name = "文件地址") @Excel(name = "文件地址")
private String fileAddress; private String fileAddress;
/** 文件大小 */
@Excel(name = "文件大小(单位B)")
private Long size;
/** 文件后缀 */
@Excel(name = "文件后缀")
private String extension;
/** 文件后缀 */
@Excel(name = "文件下载次数")
private Integer number;
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public String getExtension() {
return extension;
}
public void setExtension(String extension) {
this.extension = extension;
}
public void setId(Long id) public void setId(Long id)
{ {

2
zc-business/src/main/java/com/zc/business/mapper/DcFileDownloadMapper.java

@ -58,4 +58,6 @@ public interface DcFileDownloadMapper
* @return 结果 * @return 结果
*/ */
int deleteDcFileDownloadByIds(Long[] ids); int deleteDcFileDownloadByIds(Long[] ids);
//下载请求接口-下载数量+1
int downloadIncrease(Long id);
} }

2
zc-business/src/main/java/com/zc/business/service/IDcFileDownloadService.java

@ -58,4 +58,6 @@ public interface IDcFileDownloadService
* @return 结果 * @return 结果
*/ */
int deleteDcFileDownloadById(Long id); int deleteDcFileDownloadById(Long id);
//下载请求接口-下载数量+1
int downloadIncrease(Long id);
} }

5
zc-business/src/main/java/com/zc/business/service/impl/DcFileDownloadServiceImpl.java

@ -96,4 +96,9 @@ public class DcFileDownloadServiceImpl implements IDcFileDownloadService
{ {
return dcFileDownloadMapper.deleteDcFileDownloadById(id); return dcFileDownloadMapper.deleteDcFileDownloadById(id);
} }
//下载请求接口-下载数量+1
@Override
public int downloadIncrease(Long id) {
return dcFileDownloadMapper.downloadIncrease(id);
}
} }

15
zc-business/src/main/resources/mapper/business/DcFileDownloadMapper.xml

@ -12,10 +12,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
<result property="size" column="size" />
<result property="extension" column="extension" />
<result property="number" column="number" />
</resultMap> </resultMap>
<sql id="selectDcFileDownloadVo"> <sql id="selectDcFileDownloadVo">
select id, file_name, file_address, create_time, create_by, update_time, update_by from dc_file_download select id,number,size,extension, file_name, file_address, create_time, create_by, update_time, update_by from dc_file_download
</sql> </sql>
<select id="selectDcFileDownloadList" parameterType="DcFileDownload" resultMap="DcFileDownloadResult"> <select id="selectDcFileDownloadList" parameterType="DcFileDownload" resultMap="DcFileDownloadResult">
@ -41,6 +44,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createBy != null">create_by,</if> <if test="createBy != null">create_by,</if>
<if test="updateTime != null">update_time,</if> <if test="updateTime != null">update_time,</if>
<if test="updateBy != null">update_by,</if> <if test="updateBy != null">update_by,</if>
<if test="size != null">size,</if>
<if test="extension != null">extension,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="fileName != null">#{fileName},</if> <if test="fileName != null">#{fileName},</if>
@ -49,6 +54,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createBy != null">#{createBy},</if> <if test="createBy != null">#{createBy},</if>
<if test="updateTime != null">#{updateTime},</if> <if test="updateTime != null">#{updateTime},</if>
<if test="updateBy != null">#{updateBy},</if> <if test="updateBy != null">#{updateBy},</if>
<if test="size != null">#{size},</if>
<if test="extension != null">#{extension},</if>
</trim> </trim>
</insert> </insert>
@ -61,9 +68,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createBy != null">create_by = #{createBy},</if> <if test="createBy != null">create_by = #{createBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if> <if test="updateTime != null">update_time = #{updateTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if> <if test="updateBy != null">update_by = #{updateBy},</if>
<if test="size != null">size = #{size},</if>
<if test="extension != null">extension = #{extension},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>
<update id="downloadIncrease">
update dc_file_download set number=number+1 where id=#{id}
</update>
<delete id="deleteDcFileDownloadById" parameterType="Long"> <delete id="deleteDcFileDownloadById" parameterType="Long">
delete from dc_file_download where id = #{id} delete from dc_file_download where id = #{id}

Loading…
Cancel
Save