Commit 1ee88893 authored by licc's avatar licc

代码优化3

parent 8da9308c
...@@ -21,24 +21,24 @@ ...@@ -21,24 +21,24 @@
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!--<dependency>-->
<!--<groupId>io.swagger</groupId>-->
<!--<artifactId>swagger-annotations</artifactId>-->
<!--<version>1.5.23</version>-->
<!--<scope>compile</scope>-->
<!--</dependency>-->
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.swagger</groupId>
<artifactId>springfox-swagger-ui</artifactId> <artifactId>swagger-annotations</artifactId>
<version>2.9.2</version> <version>1.5.23</version>
</dependency> <scope>compile</scope>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency> </dependency>
<!-- &lt;!&ndash; https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>io.springfox</groupId>-->
<!-- <artifactId>springfox-swagger-ui</artifactId>-->
<!-- <version>2.9.2</version>-->
<!-- </dependency>-->
<!-- &lt;!&ndash; https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>io.springfox</groupId>-->
<!-- <artifactId>springfox-swagger2</artifactId>-->
<!-- <version>2.9.2</version>-->
<!-- </dependency>-->
</dependencies> </dependencies>
<!-- MAVEN构建 --> <!-- MAVEN构建 -->
......
...@@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
/** /**
...@@ -18,7 +19,7 @@ import java.io.Serializable; ...@@ -18,7 +19,7 @@ import java.io.Serializable;
@Data @Data
@ApiModel(value = "AccountUsers") @ApiModel(value = "AccountUsers")
@TableName("shop_zx") @TableName("shop_zx")
public class shopZx extends Model<shopZx> implements Serializable{ public class shopZx extends Model<shopZx> implements Serializable {
private static final long serialVersionUID = 2525339404301884673L; private static final long serialVersionUID = 2525339404301884673L;
/** /**
...@@ -67,7 +68,7 @@ public class shopZx extends Model<shopZx> implements Serializable{ ...@@ -67,7 +68,7 @@ public class shopZx extends Model<shopZx> implements Serializable{
* 资讯数据创建时间 * 资讯数据创建时间
*/ */
@ApiModelProperty(name = "zxDate", value = "资讯数据创建时间") @ApiModelProperty(name = "zxDate", value = "资讯数据创建时间")
private Data zxDate; private Date zxDate;
/** /**
* 图片存放地址imgUrl,zxAddress,zxField,zxName,userid,zxUrl * 图片存放地址imgUrl,zxAddress,zxField,zxName,userid,zxUrl
...@@ -112,128 +113,4 @@ public class shopZx extends Model<shopZx> implements Serializable{ ...@@ -112,128 +113,4 @@ public class shopZx extends Model<shopZx> implements Serializable{
// this.size = size; // this.size = size;
// } // }
public String getImgUrl() {
return imgUrl;
}
public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
public String getZxAddress() {
return zxAddress;
}
public void setZxAddress(String zxAddress) {
this.zxAddress = zxAddress;
}
// public String getFileName() {
// return fileName;
// }
//
// public void setFileName(String fileName) {
// this.fileName = fileName;
// }
//
// public String getFileDownloadUri() {
// return fileDownloadUri;
// }
// public void setFileDownloadUri(String fileDownloadUri) {
// this.fileDownloadUri = fileDownloadUri;
// }
//
// public String getFileType() {
// return fileType;
// }
//
// public void setFileType(String fileType) {
// this.fileType = fileType;
// }
//
// public long getSize() {
// return size;
// }
//
// public void setSize(long size) {
// this.size = size;
// }
public Data getZxDate() {
return zxDate;
}
public void setZxDate(Data zxDate) {
this.zxDate = zxDate;
}
public Integer getZxid() {
return zxid;
}
public void setZxid(Integer zxid) {
this.zxid = zxid;
}
public String getZxUrl() {
return zxUrl;
}
public void setZxUrl(String zxUrl) {
this.zxUrl = zxUrl;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public Integer getZxLikes() {
return zxLikes;
}
public void setZxLikes(Integer zxLikes) {
this.zxLikes = zxLikes;
}
public String getZxName() {
return zxName;
}
public void setZxName(String zxName) {
this.zxName = zxName;
}
public Integer getZxShenHe() {
return zxShenHe;
}
public void setZxShenHe(Integer zxShenHe) {
this.zxShenHe = zxShenHe;
}
public String getZxField() {
return zxField;
}
public void setZxField(String zxField) {
this.zxField = zxField;
}
@Override
public String toString() {
return "shopzx{" +
"zxid=" + zxid +
", zxUrl=" + zxUrl +
", userid=" + userid +
", zxLikes=" + zxLikes +
", zxName=" + zxName +
", zxShenHe=" + zxShenHe +
", zxField=" + zxField +
"}";
}
} }
package cn.wisenergy.service.app; package cn.wisenergy.service.app;
import cn.wisenergy.model.app.shopZx;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -11,6 +11,7 @@ import java.util.Map; ...@@ -11,6 +11,7 @@ import java.util.Map;
/** /**
* Created by m1991 on 2021/2/24 13:49 * Created by m1991 on 2021/2/24 13:49
* TODO 资讯Service * TODO 资讯Service
* @author 86187
*/ */
public interface UploadService { public interface UploadService {
/** /**
......
...@@ -38,7 +38,7 @@ import org.springframework.util.ClassUtils; ...@@ -38,7 +38,7 @@ import org.springframework.util.ClassUtils;
*/ */
@Slf4j @Slf4j
@Transactional @Transactional
@Service("UploadService") @Service
public class UploadServiceImpl implements UploadService { public class UploadServiceImpl implements UploadService {
@Autowired @Autowired
...@@ -54,7 +54,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -54,7 +54,7 @@ public class UploadServiceImpl implements UploadService {
String basePath = request.getScheme() + "://" + request.getServerName() String basePath = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort()+"/mimi/upload/video/"; + ":" + request.getServerPort()+"/mimi/upload/video/";
Long time = new Date().getTime(); Long time = System.currentTimeMillis();
String zxName = file.getOriginalFilename();//文件原始名称 String zxName = file.getOriginalFilename();//文件原始名称
String suffixName = zxName.substring(zxName.lastIndexOf("."));//从最后一个.开始截取。截取zxName的后缀名 String suffixName = zxName.substring(zxName.lastIndexOf("."));//从最后一个.开始截取。截取zxName的后缀名
...@@ -107,7 +107,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -107,7 +107,7 @@ public class UploadServiceImpl implements UploadService {
String basePath = request.getScheme() + "://" + request.getServerName() String basePath = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort()+"/mimi/upload/images/"; + ":" + request.getServerPort()+"/mimi/upload/images/";
Long time = new Date().getTime(); Long time = System.currentTimeMillis();
String zxName = file.getOriginalFilename();//文件原始名称 String zxName = file.getOriginalFilename();//文件原始名称
String suffixName = zxName.substring(zxName.lastIndexOf("."));//从最后一个.开始截取。截取zxName的后缀名 String suffixName = zxName.substring(zxName.lastIndexOf("."));//从最后一个.开始截取。截取zxName的后缀名
...@@ -145,7 +145,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -145,7 +145,7 @@ public class UploadServiceImpl implements UploadService {
String basePath= ClassUtils.getDefaultClassLoader().getResource("").getPath(); String basePath= ClassUtils.getDefaultClassLoader().getResource("").getPath();
String oldPath=basePath+"/static/images/animate.png"; String oldPath=basePath+"/static/images/animate.png";
Long res =new Date().getTime(); Long res =System.currentTimeMillis();
//设置文件存储路径,可以存放在你想要指定的路径里面 //设置文件存储路径,可以存放在你想要指定的路径里面
String rootPath="D:/mimi/"+File.separator+"upload/images/"; String rootPath="D:/mimi/"+File.separator+"upload/images/";
// 新文件名 // 新文件名
...@@ -283,6 +283,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -283,6 +283,7 @@ public class UploadServiceImpl implements UploadService {
* @param file 文件 * @param file 文件
* @return 文件名 * @return 文件名
*/ */
@Override
public String storeFile(MultipartFile file) { public String storeFile(MultipartFile file) {
// Normalize file name // Normalize file name
String fileName = StringUtils.cleanPath(file.getOriginalFilename()); String fileName = StringUtils.cleanPath(file.getOriginalFilename());
...@@ -303,6 +304,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -303,6 +304,7 @@ public class UploadServiceImpl implements UploadService {
} }
} }
@Override
public Resource loadFileAsResource(String fileName) { public Resource loadFileAsResource(String fileName) {
try { try {
Path filePath = this.fileStorageLocation.resolve(fileName).normalize(); Path filePath = this.fileStorageLocation.resolve(fileName).normalize();
......
...@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; ...@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import io.swagger.annotations.*; import io.swagger.annotations.*;
...@@ -48,7 +49,7 @@ public class UploadController { ...@@ -48,7 +49,7 @@ public class UploadController {
*/ */
@ApiOperation(value = "上传视频,返回路径给前台", notes = "上传视频,返回路径给前台", httpMethod = "POST") @ApiOperation(value = "上传视频,返回路径给前台", notes = "上传视频,返回路径给前台", httpMethod = "POST")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "zxField", value = "资讯文字", required = false, dataType = "String"), @ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")}) @ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")})
@RequestMapping(value = "/uploadVideo", method = RequestMethod.POST) @RequestMapping(value = "/uploadVideo", method = RequestMethod.POST)
public Map<String, Object> uploadVideo(MultipartFile file, HttpServletRequest request, String userId, String zxField, String zxAddress) throws Exception { public Map<String, Object> uploadVideo(MultipartFile file, HttpServletRequest request, String userId, String zxField, String zxAddress) throws Exception {
...@@ -64,7 +65,7 @@ public class UploadController { ...@@ -64,7 +65,7 @@ public class UploadController {
*/ */
@ApiOperation(value = "上传图片,返回路径给前台", notes = "上传图片,返回路径给前台", httpMethod = "POST", produces = "application/json; charset=UTF-8") @ApiOperation(value = "上传图片,返回路径给前台", notes = "上传图片,返回路径给前台", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "zxField", value = "资讯文字", required = false, dataType = "String"), @ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")}) @ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")})
@RequestMapping(value = "/uploadImage", method = RequestMethod.POST) @RequestMapping(value = "/uploadImage", method = RequestMethod.POST)
public Map<String, Object> uploadImage(MultipartFile file, HttpServletRequest request, String userId, String zxField, String zxAddress) throws Exception { public Map<String, Object> uploadImage(MultipartFile file, HttpServletRequest request, String userId, String zxField, String zxAddress) throws Exception {
...@@ -87,14 +88,13 @@ public class UploadController { ...@@ -87,14 +88,13 @@ public class UploadController {
@ApiOperation(value = "上传多图片,返回路径给前台", notes = "上传图片,返回路径给前台", httpMethod = "POST", produces = "application/json; charset=UTF-8") @ApiOperation(value = "上传多图片,返回路径给前台", notes = "上传图片,返回路径给前台", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "zxField", value = "资讯文字", required = false, dataType = "String"), @ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
@ApiImplicitParam(name = "zxAddress", value = "发表地址", required = false, dataType = "String"), @ApiImplicitParam(name = "zxAddress", value = "发表地址", dataType = "String"),
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")}) @ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")})
@RequestMapping("/multipleImageUpload") @RequestMapping("/multipleImageUpload")
public List multipleImageUpload(MultipartFile[] files,String userId, String zxField, String zxAddress) { public List multipleImageUpload(MultipartFile[] files, String userId, String zxField, String zxAddress) {
return uploadService.imageUpload(files, userId, zxField, zxAddress); return uploadService.imageUpload(files, userId, zxField, zxAddress);
// ,
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment