|
@@ -5,9 +5,17 @@ import com.sunyo.wlpt.vehicle.manage.response.ResultJson; |
|
@@ -5,9 +5,17 @@ import com.sunyo.wlpt.vehicle.manage.response.ResultJson; |
|
5
|
import com.sunyo.wlpt.vehicle.manage.service.LandRoadTrailerRecordService;
|
5
|
import com.sunyo.wlpt.vehicle.manage.service.LandRoadTrailerRecordService;
|
|
6
|
import io.swagger.annotations.Api;
|
6
|
import io.swagger.annotations.Api;
|
|
7
|
import io.swagger.annotations.ApiOperation;
|
7
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
8
|
+import jdk.nashorn.internal.ir.CallNode;
|
|
8
|
import org.springframework.web.bind.annotation.*;
|
9
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
10
|
+import org.springframework.web.multipart.MultipartFile;
|
|
9
|
|
11
|
|
|
10
|
import javax.annotation.Resource;
|
12
|
import javax.annotation.Resource;
|
|
|
|
13
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
14
|
+import java.io.File;
|
|
|
|
15
|
+import java.io.IOException;
|
|
|
|
16
|
+import java.text.SimpleDateFormat;
|
|
|
|
17
|
+import java.util.Date;
|
|
|
|
18
|
+import java.util.UUID;
|
|
11
|
|
19
|
|
|
12
|
/**
|
20
|
/**
|
|
13
|
* @author 子诚
|
21
|
* @author 子诚
|
|
@@ -97,4 +105,43 @@ public class TrailerController { |
|
@@ -97,4 +105,43 @@ public class TrailerController { |
|
97
|
return id.contains(",") ? landRoadTrailerRecordService.batchRemoveByIds(id)
|
105
|
return id.contains(",") ? landRoadTrailerRecordService.batchRemoveByIds(id)
|
|
98
|
: landRoadTrailerRecordService.deleteByPrimaryKey(id);
|
106
|
: landRoadTrailerRecordService.deleteByPrimaryKey(id);
|
|
99
|
}
|
107
|
}
|
|
|
|
108
|
+
|
|
|
|
109
|
+ /**
|
|
|
|
110
|
+ * 上传图片,以后有了文件管理系统,接口弃用
|
|
|
|
111
|
+ *
|
|
|
|
112
|
+ * @param file 文件
|
|
|
|
113
|
+ * @param request request
|
|
|
|
114
|
+ * @return
|
|
|
|
115
|
+ */
|
|
|
|
116
|
+ @RequestMapping("/upload")
|
|
|
|
117
|
+ public ResultJson uploadImage(@RequestParam(value = "file", required = false) MultipartFile file,
|
|
|
|
118
|
+ HttpServletRequest request)
|
|
|
|
119
|
+ {
|
|
|
|
120
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
|
121
|
+ if (!originalFilename.endsWith(".jpg") && !originalFilename.endsWith(".png")) {
|
|
|
|
122
|
+ return ResultJson.error("400", "图片格式不对,只允许jpg/png格式");
|
|
|
|
123
|
+ }
|
|
|
|
124
|
+
|
|
|
|
125
|
+ String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
|
|
126
|
+ // 临时路径
|
|
|
|
127
|
+ String realPath = request.getServletContext().getRealPath("/") + format;
|
|
|
|
128
|
+
|
|
|
|
129
|
+
|
|
|
|
130
|
+ File folder = new File(realPath);
|
|
|
|
131
|
+ if (!folder.exists()) {
|
|
|
|
132
|
+ folder.mkdirs();
|
|
|
|
133
|
+ }
|
|
|
|
134
|
+ String[] split = originalFilename.split("\\.");
|
|
|
|
135
|
+ String newName = UUID.randomUUID().toString() + "." + split[split.length - 1];
|
|
|
|
136
|
+
|
|
|
|
137
|
+ try {
|
|
|
|
138
|
+ file.transferTo(new File(folder, newName));
|
|
|
|
139
|
+ String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
|
|
|
|
140
|
+ + "/" + format + "/" + newName;
|
|
|
|
141
|
+ return ResultJson.success("200", "上传图片,成功", url);
|
|
|
|
142
|
+ } catch (IOException e) {
|
|
|
|
143
|
+ e.printStackTrace();
|
|
|
|
144
|
+ return ResultJson.error("500", "上传图片,失败");
|
|
|
|
145
|
+ }
|
|
|
|
146
|
+ }
|
|
100
|
} |
147
|
} |