| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | @RequestMapping(value = "/apkBuildTask/{id}/auth") |
| | | @ManagerAuth |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok(apkBuildTaskService.selectById(id)); |
| | | return R.ok(apkBuildTaskService.getById(id)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @RequestParam(required = false) String orderByType, |
| | | @RequestParam Map<String, Object> param) { |
| | | excludeTrash(param); |
| | | EntityWrapper<ApkBuildTask> wrapper = new EntityWrapper<>(); |
| | | QueryWrapper<ApkBuildTask> wrapper = new QueryWrapper<>(); |
| | | convert(param, wrapper); |
| | | |
| | | if (!Cools.isEmpty(orderByField)) { |
| | | wrapper.orderBy(orderByField, "asc".equalsIgnoreCase(orderByType)); |
| | | wrapper.orderBy(true, "asc".equalsIgnoreCase(orderByType), orderByField); |
| | | } else { |
| | | wrapper.orderBy("id", false); |
| | | wrapper.orderBy(true, false, "id"); |
| | | } |
| | | |
| | | return R.ok(apkBuildTaskService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | return R.ok(apkBuildTaskService.page(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | /** |
| | | * 搜索参数转换 |
| | | */ |
| | | private void convert(Map<String, Object> map, EntityWrapper<ApkBuildTask> wrapper) { |
| | | private void convert(Map<String, Object> map, QueryWrapper<ApkBuildTask> wrapper) { |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| | | String key = entry.getKey(); |
| | | Object value = entry.getValue(); |
| | |
| | | try { |
| | | int count = apkBuildTaskService.refreshAllPendingTasks(); |
| | | // 返回所有任务列表 |
| | | EntityWrapper<ApkBuildTask> wrapper = new EntityWrapper<>(); |
| | | wrapper.orderBy("id", false); |
| | | List<ApkBuildTask> tasks = apkBuildTaskService.selectList(wrapper); |
| | | QueryWrapper<ApkBuildTask> wrapper = new QueryWrapper<>(); |
| | | wrapper.orderBy(true, false, "id"); |
| | | List<ApkBuildTask> tasks = apkBuildTaskService.list(wrapper); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("tasks", tasks); |
| | | result.put("refreshedCount", count); |
| | |
| | | return R.ok(result); |
| | | } catch (Exception e) { |
| | | return R.error("下载APK失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/apkBuildTask/downloadFile/{id}/auth", method = RequestMethod.GET) |
| | | @ManagerAuth |
| | | public void downloadApkFile(@PathVariable("id") Long id, HttpServletResponse response) { |
| | | try { |
| | | String localPath = apkBuildTaskService.downloadApk(id); |
| | | File file = new File(localPath); |
| | | if (!file.exists()) { |
| | | throw new RuntimeException("APK文件不存在"); |
| | | } |
| | | String fileName = URLEncoder.encode(file.getName(), "UTF-8"); |
| | | response.setContentType("application/vnd.android.package-archive"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setHeader("Content-Length", String.valueOf(file.length())); |
| | | try (InputStream inputStream = new FileInputStream(file); |
| | | OutputStream outputStream = response.getOutputStream()) { |
| | | byte[] buffer = new byte[8192]; |
| | | int len; |
| | | while ((len = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, len); |
| | | } |
| | | outputStream.flush(); |
| | | } |
| | | } catch (Exception e) { |
| | | try { |
| | | response.reset(); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setContentType("application/json; charset=utf-8"); |
| | | response.getWriter().print(JSON.toJSONString(R.error("下载APK失败: " + e.getMessage()))); |
| | | } catch (IOException ignore) { |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if (ids == null || ids.length == 0) { |
| | | return R.error(); |
| | | } |
| | | apkBuildTaskService.deleteBatchIds(Arrays.asList(ids)); |
| | | apkBuildTaskService.removeByIds(Arrays.asList(ids)); |
| | | return R.ok(); |
| | | } |
| | | |