...
|
...
|
@@ -5,9 +5,17 @@ import com.sunyo.wlpt.vehicle.manage.response.ResultJson; |
|
|
import com.sunyo.wlpt.vehicle.manage.service.LandRoadTrailerRecordService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import jdk.nashorn.internal.ir.CallNode;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* @author 子诚
|
...
|
...
|
@@ -97,4 +105,43 @@ public class TrailerController { |
|
|
return id.contains(",") ? landRoadTrailerRecordService.batchRemoveByIds(id)
|
|
|
: landRoadTrailerRecordService.deleteByPrimaryKey(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 上传图片,以后有了文件管理系统,接口弃用
|
|
|
*
|
|
|
* @param file 文件
|
|
|
* @param request request
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping("/upload")
|
|
|
public ResultJson uploadImage(@RequestParam(value = "file", required = false) MultipartFile file,
|
|
|
HttpServletRequest request)
|
|
|
{
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
if (!originalFilename.endsWith(".jpg") && !originalFilename.endsWith(".png")) {
|
|
|
return ResultJson.error("400", "图片格式不对,只允许jpg/png格式");
|
|
|
}
|
|
|
|
|
|
String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
|
// 临时路径
|
|
|
String realPath = request.getServletContext().getRealPath("/") + format;
|
|
|
|
|
|
|
|
|
File folder = new File(realPath);
|
|
|
if (!folder.exists()) {
|
|
|
folder.mkdirs();
|
|
|
}
|
|
|
String[] split = originalFilename.split("\\.");
|
|
|
String newName = UUID.randomUUID().toString() + "." + split[split.length - 1];
|
|
|
|
|
|
try {
|
|
|
file.transferTo(new File(folder, newName));
|
|
|
String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
|
|
|
+ "/" + format + "/" + newName;
|
|
|
return ResultJson.success("200", "上传图片,成功", url);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
return ResultJson.error("500", "上传图片,失败");
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|