| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | 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.enums.BusinessType; |
| | | import com.ruoyi.common.utils.file.FileUploadUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.framework.config.ServerConfig; |
| | | import com.ruoyi.system.dto.SysVersionUpdateAddRequest; |
| | | import com.ruoyi.system.dto.SysVersionUpdateDeleteRequest; |
| | | import com.ruoyi.system.dto.SysVersionUpdateDetailRequest; |
| | | import com.ruoyi.system.dto.SysVersionUpdatePageRequest; |
| | | import com.ruoyi.system.service.ISysVersionUpdateService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * 版本更新接口 |
| | |
| | | @RequestMapping("/system/version/update") |
| | | public class SysVersionUpdateController extends BaseController |
| | | { |
| | | private static final long MAX_PACKAGE_SIZE = 200L * 1024 * 1024; |
| | | |
| | | private static final String[] ALLOWED_PACKAGE_EXTENSION = { "apk" }; |
| | | |
| | | @Autowired |
| | | private ISysVersionUpdateService versionUpdateService; |
| | | |
| | | @Autowired |
| | | private ServerConfig serverConfig; |
| | | |
| | | /** |
| | | * 分页查询版本更新列表 |
| | | */ |
| | | @Log(title = "版本更新", businessType = BusinessType.SELECT) |
| | | @PreAuthorize("@ss.hasPermi('visitor:version:view')") |
| | | @PostMapping("/page") |
| | | public AjaxResult page(@RequestBody(required = false) SysVersionUpdatePageRequest request) |
| | | { |
| | |
| | | * 查看版本更新详情 |
| | | */ |
| | | @Log(title = "版本更新", businessType = BusinessType.SELECT) |
| | | @PreAuthorize("@ss.hasPermi('visitor:version:view')") |
| | | @PostMapping("/detail") |
| | | public AjaxResult detail(@RequestBody SysVersionUpdateDetailRequest request) |
| | | { |
| | |
| | | * 新增版本更新 |
| | | */ |
| | | @Log(title = "版本更新", businessType = BusinessType.INSERT) |
| | | @PreAuthorize("@ss.hasPermi('visitor:version:add')") |
| | | @PostMapping("/add") |
| | | public AjaxResult add(@RequestBody SysVersionUpdateAddRequest request) |
| | | { |
| | | return toAjax(versionUpdateService.add(request, getUsername())); |
| | | } |
| | | |
| | | @Log(title = "版本更新", businessType = BusinessType.INSERT) |
| | | @PreAuthorize("@ss.hasPermi('visitor:version:add')") |
| | | @PostMapping("/upload") |
| | | public AjaxResult upload(MultipartFile file) |
| | | { |
| | | if (file == null || file.isEmpty()) |
| | | { |
| | | return error("请上传安装包"); |
| | | } |
| | | if (file.getSize() >= MAX_PACKAGE_SIZE) |
| | | { |
| | | return error("安装包大小必须小于200M"); |
| | | } |
| | | try |
| | | { |
| | | String fileName = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file, |
| | | ALLOWED_PACKAGE_EXTENSION, MAX_PACKAGE_SIZE); |
| | | AjaxResult ajax = success(); |
| | | ajax.put("url", serverConfig.getUrl() + fileName); |
| | | ajax.put("fileName", fileName); |
| | | ajax.put("newFileName", FileUtils.getName(fileName)); |
| | | ajax.put("originalFilename", file.getOriginalFilename()); |
| | | return ajax; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除版本更新 |
| | | */ |
| | | @Log(title = "版本更新", businessType = BusinessType.DELETE) |
| | | @PreAuthorize("@ss.hasPermi('visitor:version:remove')") |
| | | @PostMapping("/delete") |
| | | public AjaxResult delete(@RequestBody SysVersionUpdateDeleteRequest request) |
| | | { |