|
@@ -0,0 +1,219 @@
|
|
|
+package com.ruoyi.web.controller.api;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import com.ruoyi.common.config.RuoYiConfig;
|
|
|
+import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
+import com.ruoyi.common.exception.CustomException;
|
|
|
+import com.ruoyi.common.utils.ReadAPPUtil;
|
|
|
+import com.ruoyi.common.utils.ServletUtils;
|
|
|
+import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
|
+import com.ruoyi.common.utils.file.FileUtils;
|
|
|
+import com.ruoyi.framework.web.service.TokenService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+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.ruoyi.app.domain.TAppUpgrade;
|
|
|
+import com.ruoyi.app.service.ITAppUpgradeService;
|
|
|
+import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
+import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+/**
|
|
|
+ * app升级
|
|
|
+ *
|
|
|
+ * @author luobo
|
|
|
+ * @date 2020-10-28
|
|
|
+ */
|
|
|
+@Api(value = "app升级", tags = "app升级")
|
|
|
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
|
|
+@RestController
|
|
|
+@RequestMapping("/system/appUpgrade")
|
|
|
+public class TAppUpgradeController extends BaseController {
|
|
|
+
|
|
|
+ private final ITAppUpgradeService iTAppUpgradeService;
|
|
|
+ private final TokenService tokenService;
|
|
|
+ /**
|
|
|
+ * 查询app升级列表
|
|
|
+ */
|
|
|
+ @ApiOperation("查询app升级列表")
|
|
|
+ @PreAuthorize("@ss.hasPermi('system:appUpgrade:list')")
|
|
|
+ @GetMapping("/list")
|
|
|
+ public TableDataInfo list(TAppUpgrade tAppUpgrade) {
|
|
|
+ startPage();
|
|
|
+ LambdaQueryWrapper<TAppUpgrade> lqw = new LambdaQueryWrapper<TAppUpgrade>();
|
|
|
+ if (StringUtils.isNotBlank(tAppUpgrade.getName())) {
|
|
|
+ lqw.like(TAppUpgrade::getName, tAppUpgrade.getName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(tAppUpgrade.getIconUrl())) {
|
|
|
+ lqw.eq(TAppUpgrade::getIconUrl, tAppUpgrade.getIconUrl());
|
|
|
+ }
|
|
|
+ if (tAppUpgrade.getUpgradeMode() != null) {
|
|
|
+ lqw.eq(TAppUpgrade::getUpgradeMode, tAppUpgrade.getUpgradeMode());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(tAppUpgrade.getUpgradeNote())) {
|
|
|
+ lqw.eq(TAppUpgrade::getUpgradeNote, tAppUpgrade.getUpgradeNote());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(tAppUpgrade.getUpgradeUrl())) {
|
|
|
+ lqw.eq(TAppUpgrade::getUpgradeUrl, tAppUpgrade.getUpgradeUrl());
|
|
|
+ }
|
|
|
+ if (tAppUpgrade.getUpgradeType() != null) {
|
|
|
+ lqw.eq(TAppUpgrade::getUpgradeType, tAppUpgrade.getUpgradeType());
|
|
|
+ }
|
|
|
+ if (tAppUpgrade.getUserId() != null) {
|
|
|
+ lqw.eq(TAppUpgrade::getUserId, tAppUpgrade.getUserId());
|
|
|
+ }
|
|
|
+ if (tAppUpgrade.getPlatformType() != null) {
|
|
|
+ lqw.eq(TAppUpgrade::getPlatformType, tAppUpgrade.getPlatformType());
|
|
|
+ }
|
|
|
+ List<TAppUpgrade> list = iTAppUpgradeService.list(lqw);
|
|
|
+ return getDataTable(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出app升级列表
|
|
|
+ */
|
|
|
+ @ApiOperation("导出app升级列表")
|
|
|
+ @PreAuthorize("@ss.hasPermi('system:appUpgrade:export')")
|
|
|
+ //@Log(title = "app升级", businessType = BusinessType.EXPORT)
|
|
|
+ @GetMapping("/export")
|
|
|
+ public AjaxResult export(TAppUpgrade tAppUpgrade) {
|
|
|
+ LambdaQueryWrapper<TAppUpgrade> lqw = new LambdaQueryWrapper<TAppUpgrade>(tAppUpgrade);
|
|
|
+ List<TAppUpgrade> list = iTAppUpgradeService.list(lqw);
|
|
|
+ ExcelUtil<TAppUpgrade> util = new ExcelUtil<TAppUpgrade>(TAppUpgrade.class);
|
|
|
+ return util.exportExcel(list, "appUpgrade");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取app升级详细信息
|
|
|
+ */
|
|
|
+ @ApiOperation("获取app升级详细信息")
|
|
|
+ @PreAuthorize("@ss.hasPermi('system:appUpgrade:query')")
|
|
|
+ @GetMapping(value = "/{id}")
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") Long id) {
|
|
|
+ return AjaxResult.success(iTAppUpgradeService.getById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增app升级
|
|
|
+ */
|
|
|
+ @ApiOperation("新增app升级")
|
|
|
+ @PreAuthorize("@ss.hasPermi('system:appUpgrade:add')")
|
|
|
+ //@Log(title = "app升级", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping
|
|
|
+ public AjaxResult add(@RequestBody TAppUpgrade tAppUpgrade) {
|
|
|
+
|
|
|
+ LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
+ Long userId = loginUser.getUser().getUserId();
|
|
|
+ tAppUpgrade.setUserId(userId);
|
|
|
+ tAppUpgrade.setCreateTime(new Date());
|
|
|
+ tAppUpgrade.setDelFlag("0");
|
|
|
+ return toAjax(iTAppUpgradeService.save(tAppUpgrade) ? 1 : 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改app升级
|
|
|
+ */
|
|
|
+ @ApiOperation("修改app升级")
|
|
|
+ @PreAuthorize("@ss.hasPermi('system:appUpgrade:edit')")
|
|
|
+ //@Log(title = "app升级", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping
|
|
|
+ public AjaxResult edit(@RequestBody TAppUpgrade tAppUpgrade) {
|
|
|
+ return toAjax(iTAppUpgradeService.updateById(tAppUpgrade) ? 1 : 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除app升级
|
|
|
+ */
|
|
|
+ @ApiOperation("删除app升级")
|
|
|
+ @PreAuthorize("@ss.hasPermi('system:appUpgrade:remove')")
|
|
|
+ //@Log(title = "app升级", businessType = BusinessType.DELETE)
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public AjaxResult remove(@PathVariable Long[] ids) {
|
|
|
+ return toAjax(iTAppUpgradeService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传文件
|
|
|
+ */
|
|
|
+ @ApiOperation("上传文件")
|
|
|
+ @PreAuthorize("@ss.hasPermi('system:appUpgrade:upload')")
|
|
|
+ @PostMapping("/upload")
|
|
|
+ public AjaxResult upload(@RequestParam("file") MultipartFile file) throws Exception {
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ throw new CustomException("上传文件不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ File file1 = FileUtils.transfer(file);
|
|
|
+
|
|
|
+ if (file1 == null) {
|
|
|
+ throw new CustomException("上传文件不能为空");
|
|
|
+ }
|
|
|
+ //获取文件后缀
|
|
|
+ String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
|
+ Map fileInfo = null;
|
|
|
+
|
|
|
+ //获取文件信息
|
|
|
+ int ptype = 0;
|
|
|
+ if (suffix.equalsIgnoreCase(".ipa")) {
|
|
|
+ fileInfo = ReadAPPUtil.readIPA(file1);
|
|
|
+ ptype = 2;
|
|
|
+ } else {
|
|
|
+ fileInfo = ReadAPPUtil.readAPK(file1);
|
|
|
+ ptype = 1;
|
|
|
+ }
|
|
|
+ if (fileInfo.get("code").equals("-1")) {
|
|
|
+ throw new CustomException(fileInfo.get("error").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ TAppUpgrade entity = new TAppUpgrade();
|
|
|
+ entity.setDelFlag("0");
|
|
|
+ entity.setName(fileInfo.get("name").toString());
|
|
|
+ entity.setPackageName(fileInfo.get("packageName").toString());
|
|
|
+ entity.setVersionCode(fileInfo.get("versionCode").toString());
|
|
|
+ entity.setVersionName(fileInfo.get("versionName").toString());
|
|
|
+ entity.setPlatformType(ptype);
|
|
|
+ entity.setSize((file.getSize()));
|
|
|
+ entity.setSuffix(suffix);
|
|
|
+
|
|
|
+
|
|
|
+ //上传文件
|
|
|
+// String url = OSSFactory.build().uploadSuffix(file.getBytes(), suffix);
|
|
|
+
|
|
|
+ // 上传文件路径
|
|
|
+ String filePath = RuoYiConfig.getUploadPath();
|
|
|
+ //@TODO 上传添加模块名称 luobo
|
|
|
+
|
|
|
+ filePath += "/appFile";
|
|
|
+ // 上传并返回新文件名称
|
|
|
+ String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
+ entity.setUpgradeUrl(fileName);
|
|
|
+ entity.setUpgradeMode(1);
|
|
|
+ entity.setUpgradeType(1);
|
|
|
+
|
|
|
+ if (file1.exists()) {
|
|
|
+ File del = new File(file1.toURI());
|
|
|
+ del.delete();
|
|
|
+
|
|
|
+ }
|
|
|
+ return AjaxResult.success(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|