济菏高速数据中心代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
5.1 KiB

package com.zc.business.controller;
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;
10 months ago
import com.ruoyi.common.exception.file.FileSizeLimitExceededException;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.config.ServerConfig;
import com.zc.business.domain.DcFileDownload;
import com.zc.business.enums.UniversalEnum;
import com.zc.business.service.IDcFileDownloadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 文件管理Controller
*
* @author ruoyi
* @date 2024-06-12
*/
@RestController
@RequestMapping("/business/download")
public class DcFileDownloadController extends BaseController {
@Autowired
private IDcFileDownloadService dcFileDownloadService;
@Autowired
private ServerConfig serverConfig;
10 months ago
/**
* 默认大小 30M
10 months ago
*/
public static final long DEFAULT_MAX_SIZE = 30 * 1024 * 1024;
/**
* 查询文件管理列表
*/
10 months ago
//@PreAuthorize("@ss.hasPermi('business:download:list')")
@GetMapping("/list")
public TableDataInfo list(DcFileDownload dcFileDownload) {
startPage();
List<DcFileDownload> list = dcFileDownloadService.selectDcFileDownloadList(dcFileDownload);
return getDataTable(list);
}
/**
* 导出文件管理列表
*/
10 months ago
//@PreAuthorize("@ss.hasPermi('business:download:export')")
@Log(title = "文件管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, DcFileDownload dcFileDownload) {
List<DcFileDownload> list = dcFileDownloadService.selectDcFileDownloadList(dcFileDownload);
ExcelUtil<DcFileDownload> util = new ExcelUtil<>(DcFileDownload.class);
util.exportExcel(response, list, UniversalEnum.FILE_MANAGEMENT_DATA.getValue());
}
/**
* 获取文件管理详细信息
*/
10 months ago
// @PreAuthorize("@ss.hasPermi('business:download:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(dcFileDownloadService.selectDcFileDownloadById(id));
}
/**
* 新增文件管理
*/
10 months ago
//@PreAuthorize("@ss.hasPermi('business:download:add')")
@Log(title = "文件管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody DcFileDownload dcFileDownload) {
return toAjax(dcFileDownloadService.insertDcFileDownload(dcFileDownload));
}
/**
* 修改文件管理
*/
10 months ago
//@PreAuthorize("@ss.hasPermi('business:download:edit')")
@Log(title = "文件管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody DcFileDownload dcFileDownload) {
return toAjax(dcFileDownloadService.updateDcFileDownload(dcFileDownload));
}
/**
* 删除文件管理
*/
10 months ago
//@PreAuthorize("@ss.hasPermi('business:download:remove')")
@Log(title = "文件管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(dcFileDownloadService.deleteDcFileDownloadByIds(ids));
}
/**
* 文件管理-文件上传请求
*/
@PostMapping("/uploadFileManagement")
public AjaxResult uploadFileManagement(MultipartFile file) throws Exception
{
try
{
// 上传文件路径
String filePath = RuoYiConfig.getFileManagementPath();
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
10 months ago
//文件后缀
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;
AjaxResult ajax = AjaxResult.success();
ajax.put("url", url);
ajax.put("fileName", fileName);
ajax.put("newFileName", FileUtils.getName(fileName));
ajax.put("originalFilename", file.getOriginalFilename());
10 months ago
ajax.put("extension", extension);
ajax.put("size", size);
return ajax;
}
catch (Exception e)
{
return AjaxResult.error(e.getMessage());
}
}
10 months ago
//下载请求接口-下载数量+1
@GetMapping("/downloadIncrease/{id}")
public AjaxResult downloadIncrease(@PathVariable Long id) {
return toAjax(dcFileDownloadService.downloadIncrease(id));
}
}