济菏高速数据中心代码
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.

130 lines
4.7 KiB

package com.zc.business.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zc.business.domain.DcFileDownload;
import com.zc.business.service.IDcFileDownloadService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.config.ServerConfig;
import org.springframework.web.multipart.MultipartFile;
/**
* 文件管理Controller
*
* @author ruoyi
* @date 2024-06-12
*/
@RestController
@RequestMapping("/business/download")
public class DcFileDownloadController extends BaseController {
@Autowired
private IDcFileDownloadService dcFileDownloadService;
@Autowired
private ServerConfig serverConfig;
/**
* 查询文件管理列表
*/
@PreAuthorize("@ss.hasPermi('business:download:list')")
@GetMapping("/list")
public TableDataInfo list(DcFileDownload dcFileDownload) {
startPage();
List<DcFileDownload> list = dcFileDownloadService.selectDcFileDownloadList(dcFileDownload);
return getDataTable(list);
}
/**
* 导出文件管理列表
*/
@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, "文件管理数据");
}
/**
* 获取文件管理详细信息
*/
@PreAuthorize("@ss.hasPermi('business:download:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(dcFileDownloadService.selectDcFileDownloadById(id));
}
/**
* 新增文件管理
*/
@PreAuthorize("@ss.hasPermi('business:download:add')")
@Log(title = "文件管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody DcFileDownload dcFileDownload) {
return toAjax(dcFileDownloadService.insertDcFileDownload(dcFileDownload));
}
/**
* 修改文件管理
*/
@PreAuthorize("@ss.hasPermi('business:download:edit')")
@Log(title = "文件管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody DcFileDownload dcFileDownload) {
return toAjax(dcFileDownloadService.updateDcFileDownload(dcFileDownload));
}
/**
* 删除文件管理
*/
@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);
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());
return ajax;
}
catch (Exception e)
{
return AjaxResult.error(e.getMessage());
}
}
}