From e62569856fdfb0c7c31ee88cf96628af08eabf85 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期一, 03 十一月 2025 12:34:15 +0800
Subject: [PATCH] 标准wms2.0
---
src/main/java/com/zy/asrs/controller/AppVersionController.java | 144 ++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 121 insertions(+), 23 deletions(-)
diff --git a/src/main/java/com/zy/asrs/controller/AppVersionController.java b/src/main/java/com/zy/asrs/controller/AppVersionController.java
index a3568dd..0d5d98e 100644
--- a/src/main/java/com/zy/asrs/controller/AppVersionController.java
+++ b/src/main/java/com/zy/asrs/controller/AppVersionController.java
@@ -1,21 +1,26 @@
package com.zy.asrs.controller;
-import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
-import com.core.common.DateUtils;
-import com.zy.asrs.entity.AppVersion;
-import com.zy.asrs.service.AppVersionService;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
+import com.core.common.DateUtils;
import com.core.common.R;
+import com.zy.asrs.entity.AppVersion;
+import com.zy.asrs.service.AppVersionService;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.text.SimpleDateFormat;
import java.util.*;
@RestController
@@ -32,24 +37,46 @@
@RequestMapping(value = "/appVersion/list/auth")
@ManagerAuth
- public R list(@RequestParam(defaultValue = "1")Integer curr,
- @RequestParam(defaultValue = "10")Integer limit,
- @RequestParam(required = false)String orderByField,
- @RequestParam(required = false)String orderByType,
- @RequestParam(required = false)String condition,
- @RequestParam Map<String, Object> param){
+ public R list(@RequestParam(defaultValue = "1") Integer curr,
+ @RequestParam(defaultValue = "10") Integer limit,
+ @RequestParam(required = false) String orderByField,
+ @RequestParam(required = false) String orderByType,
+ @RequestParam(required = false) String condition,
+ @RequestParam Map<String, Object> param) {
EntityWrapper<AppVersion> wrapper = new EntityWrapper<>();
excludeTrash(param);
convert(param, wrapper);
allLike(AppVersion.class, param.keySet(), wrapper, condition);
- if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
+ if (!Cools.isEmpty(orderByField)) {
+ wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));
+ }
return R.ok(appVersionService.selectPage(new Page<>(curr, limit), wrapper));
}
- private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
- for (Map.Entry<String, Object> entry : map.entrySet()){
+ @RequestMapping(value = "/appVersion/checkUpdate/{version}/{type}")
+ public R checkUpdate(@PathVariable("version") String version,
+ @PathVariable("type") Integer type) {
+ EntityWrapper<AppVersion> wrapper = new EntityWrapper<>();
+ AppVersion appVersion = appVersionService.selectOne(wrapper);
+ if (Cools.isEmpty(appVersion)) {
+ return R.ok("宸叉槸鏈�鏂扮増鏈�");
+ }
+ AppVersion latestApp = appVersionService.getLatestApp(type);
+ if (latestApp == null) {
+ return R.error();
+ }
+
+ if (latestApp.getVersion().equals(version)) {
+ return R.ok("宸叉槸鏈�鏂扮増鏈�");
+ }
+
+ return R.ok("鏈夋柊鐗堟湰锛岄渶瑕佹洿鏂�").add(latestApp);
+ }
+
+ private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper) {
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
String val = String.valueOf(entry.getValue());
- if (val.contains(RANGE_TIME_LINK)){
+ if (val.contains(RANGE_TIME_LINK)) {
String[] dates = val.split(RANGE_TIME_LINK);
wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
@@ -62,15 +89,23 @@
@RequestMapping(value = "/appVersion/add/auth")
@ManagerAuth
public R add(AppVersion appVersion) {
+ if (appVersion.getLatest() == 1) {
+ //淇敼鏈�鏂扮増鏈椂锛岄渶瑕佸皢鍏朵粬鐗堟湰璁剧疆涓洪潪鏈�鏂扮増
+ appVersionService.updateLatest(0, appVersion.getType());
+ }
appVersionService.insert(appVersion);
return R.ok();
}
- @RequestMapping(value = "/appVersion/update/auth")
- @ManagerAuth
- public R update(AppVersion appVersion){
- if (Cools.isEmpty(appVersion) || null==appVersion.getId()){
+ @RequestMapping(value = "/appVersion/update/auth")
+ @ManagerAuth
+ public R update(AppVersion appVersion) {
+ if (Cools.isEmpty(appVersion) || null == appVersion.getId()) {
return R.error();
+ }
+ if (appVersion.getLatest() == 1) {
+ //淇敼鏈�鏂扮増鏈椂锛岄渶瑕佸皢鍏朵粬鐗堟湰璁剧疆涓洪潪鏈�鏂扮増
+ appVersionService.updateLatest(0, appVersion.getType());
}
appVersionService.updateById(appVersion);
return R.ok();
@@ -78,8 +113,8 @@
@RequestMapping(value = "/appVersion/delete/auth")
@ManagerAuth
- public R delete(@RequestParam(value="ids[]") Long[] ids){
- for (Long id : ids){
+ public R delete(@RequestParam(value = "ids[]") Long[] ids) {
+ for (Long id : ids) {
appVersionService.deleteById(id);
}
return R.ok();
@@ -87,7 +122,7 @@
@RequestMapping(value = "/appVersion/export/auth")
@ManagerAuth
- public R export(@RequestBody JSONObject param){
+ public R export(@RequestBody JSONObject param) {
EntityWrapper<AppVersion> wrapper = new EntityWrapper<>();
List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
Map<String, Object> map = excludeTrash(param.getJSONObject("appVersion"));
@@ -103,7 +138,7 @@
wrapper.like("id", condition);
Page<AppVersion> page = appVersionService.selectPage(new Page<>(0, 10), wrapper);
List<Map<String, Object>> result = new ArrayList<>();
- for (AppVersion appVersion : page.getRecords()){
+ for (AppVersion appVersion : page.getRecords()) {
Map<String, Object> map = new HashMap<>();
map.put("id", appVersion.getId());
map.put("value", appVersion.getId());
@@ -116,10 +151,73 @@
@ManagerAuth
public R query(@RequestBody JSONObject param) {
Wrapper<AppVersion> wrapper = new EntityWrapper<AppVersion>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
- if (null != appVersionService.selectOne(wrapper)){
+ if (null != appVersionService.selectOne(wrapper)) {
return R.parse(BaseRes.REPEAT).add(getComment(AppVersion.class, String.valueOf(param.get("key"))));
}
return R.ok();
}
+ @RequestMapping(value = "/appVersion/uploadApp/auth")
+ @ManagerAuth
+ public R uploadApp(@RequestParam("id") Integer id,
+ @RequestParam("file") MultipartFile[] files) {
+ AppVersion appVersion = appVersionService.selectById(id);
+
+ MultipartFile file = files[0];
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
+ String path = ClassUtils.getDefaultClassLoader().getResource("appVersion").getPath();
+ //鏂囦欢鍚庣紑鍚�
+ String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
+ //涓婁紶鏂囦欢鍚�
+ String filename = format.format(new Date()) + suffix;
+ //鏈�缁堟枃浠惰矾寰�
+ String filepath = path + "/" + filename;
+
+
+ //鏈嶅姟鍣ㄧ淇濆瓨鐨勬枃浠跺璞�
+ File serverFile = new File(filepath);
+ if (!serverFile.exists()) {
+ try {
+ //鍒涘缓鏂囦欢
+ serverFile.createNewFile();
+ //灏嗕笂浼犵殑鏂囦欢鍐欏叆鍒版湇鍔″櫒绔枃浠跺唴
+ file.transferTo(serverFile);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ //淇濆瓨鏂囦欢鍚�
+ appVersion.setPath(filename);
+ appVersionService.updateById(appVersion);
+ return R.ok();
+ }
+
+ @RequestMapping("/appVersion/downloadApp/{filename}")
+ public void download(@PathVariable String filename, HttpServletResponse response) {
+ try {
+ ClassPathResource pathResource = new ClassPathResource("appVersion/" + filename);
+ File file = pathResource.getFile();
+ InputStream inputStream = pathResource.getInputStream();
+ //杈撳嚭鏂囦欢
+ InputStream fis = new BufferedInputStream(inputStream);
+ byte[] buffer = new byte[fis.available()];
+ fis.read(buffer);
+ fis.close();
+ response.reset();
+
+ //鑾峰彇鏂囦欢鐨勫悕瀛楀啀娴忚鍣ㄤ笅杞介〉闈�
+ String name = file.getName();
+ response.addHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "iso-8859-1"));
+ response.addHeader("Content-Length", "" + file.length());
+ OutputStream out = new BufferedOutputStream(response.getOutputStream());
+ response.setContentType("application/octet-stream");
+ out.write(buffer);
+ out.flush();
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ response.setStatus(404);
+ }
+ }
}
--
Gitblit v1.9.1