作者 王勇

做了上传图片demo,再次备份

@@ -3,6 +3,9 @@ server: @@ -3,6 +3,9 @@ server:
3 3
4 # spring 配置 4 # spring 配置
5 spring: 5 spring:
  6 + servlet:
  7 + multipart:
  8 + max-file-size: 100MB
6 security: 9 security:
7 user: 10 user:
8 name: admin 11 name: admin
@@ -109,6 +109,12 @@ @@ -109,6 +109,12 @@
109 </dependency> 109 </dependency>
110 110
111 <dependency> 111 <dependency>
  112 + <groupId>com.google.guava</groupId>
  113 + <artifactId>guava</artifactId>
  114 + <version>29.0-jre</version>
  115 + </dependency>
  116 +
  117 + <dependency>
112 <groupId>org.springframework.boot</groupId> 118 <groupId>org.springframework.boot</groupId>
113 <artifactId>spring-boot-configuration-processor</artifactId> 119 <artifactId>spring-boot-configuration-processor</artifactId>
114 <optional>true</optional> 120 <optional>true</optional>
@@ -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 }
1 package com.sunyo.wlpt.vehicle.manage.domain; 1 package com.sunyo.wlpt.vehicle.manage.domain;
2 2
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
3 import io.swagger.annotations.ApiModel; 4 import io.swagger.annotations.ApiModel;
4 import io.swagger.annotations.ApiModelProperty; 5 import io.swagger.annotations.ApiModelProperty;
5 6
@@ -140,6 +141,7 @@ public class LandRoadVeRecord implements Serializable { @@ -140,6 +141,7 @@ public class LandRoadVeRecord implements Serializable {
140 * 行驶证有效期日期(yyyyMMdd-0) 141 * 行驶证有效期日期(yyyyMMdd-0)
141 */ 142 */
142 @ApiModelProperty(value = "行驶证有效期日期(yyyyMMdd-0)") 143 @ApiModelProperty(value = "行驶证有效期日期(yyyyMMdd-0)")
  144 + @JsonFormat(pattern="yyyy-MM-dd",timezone="GMT+8")
143 private Date veFactoryDate; 145 private Date veFactoryDate;
144 146
145 /** 147 /**
@@ -75,6 +75,8 @@ public class LandRoadVeRecordServiceImpl implements LandRoadVeRecordService { @@ -75,6 +75,8 @@ public class LandRoadVeRecordServiceImpl implements LandRoadVeRecordService {
75 return validateInsert; 75 return validateInsert;
76 } 76 }
77 record.setId(IdUtils.generateId()); 77 record.setId(IdUtils.generateId());
  78 + // TODO: 添加车辆信息的具体逻辑
  79 +
78 return landRoadVeRecordMapper.insertSelective(record) > 0 80 return landRoadVeRecordMapper.insertSelective(record) > 0
79 ? ResultJson.success("200", "添加车辆信息,成功") 81 ? ResultJson.success("200", "添加车辆信息,成功")
80 : ResultJson.error("500", "添加车辆信息,失败"); 82 : ResultJson.error("500", "添加车辆信息,失败");
@@ -114,6 +114,7 @@ @@ -114,6 +114,7 @@
114 AND VE_STATE = #{veState,jdbcType=VARCHAR} 114 AND VE_STATE = #{veState,jdbcType=VARCHAR}
115 </if> 115 </if>
116 </where> 116 </where>
  117 + order by UPDATE_DATE desc
117 </select> 118 </select>
118 119
119 <select id="selectByTrailerLicenseNo" parameterType="java.lang.String" resultMap="BaseResultMap"> 120 <select id="selectByTrailerLicenseNo" parameterType="java.lang.String" resultMap="BaseResultMap">