Commit 0c5f5861 authored by liqin's avatar liqin 💬

bug fixed

parent 3bc61681
...@@ -145,6 +145,22 @@ ...@@ -145,6 +145,22 @@
<artifactId>swagger-models</artifactId> <artifactId>swagger-models</artifactId>
<version>1.6.2</version> <version>1.6.2</version>
</dependency> </dependency>
<!-- 集成knife4j -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.8</version>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>swagger-models</artifactId>
<groupId>io.swagger</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- JWT Authentication --> <!-- JWT Authentication -->
<dependency> <dependency>
<groupId>com.auth0</groupId> <groupId>com.auth0</groupId>
......
...@@ -6,6 +6,7 @@ import org.csource.common.NameValuePair; ...@@ -6,6 +6,7 @@ import org.csource.common.NameValuePair;
import org.csource.fastdfs.*; import org.csource.fastdfs.*;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
...@@ -15,12 +16,13 @@ import java.util.Properties; ...@@ -15,12 +16,13 @@ import java.util.Properties;
/** /**
* 上传图片到FastDFS * 上传图片到FastDFS
*/ */
@Component
public class FastDFSUtils { public class FastDFSUtils {
private static String dfsFileAccessBasePath; private static String dfsFileAccessBasePath;
@Value("${dfsFileAccessBasePath:#{null}}") @Value("${dfsFileAccessBasePath:#{null}}")
public static void setDfsFileAccessBasePath(String dfsFileAccessBasePath) { public void setDfsFileAccessBasePath(String dfsFileAccessBasePath) {
FastDFSUtils.dfsFileAccessBasePath = dfsFileAccessBasePath; FastDFSUtils.dfsFileAccessBasePath = dfsFileAccessBasePath;
} }
......
package cn.wisenergy.chnmuseum.party.common.mybatis;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* 配置公共字段自动填充功能 @TableField(..fill = FieldFill.INSERT)
* 特别注意,3.0-gamma之前的版本 MetaObjectHandler 是抽象类
* 3.0-RC之后的版本MetaObjectHandler 是接口
*/
@Component
public class MetaObjectHandlerConfig implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
LocalDateTime now = LocalDateTime.now();
Object createTime = getFieldValByName("create_time", metaObject);
Object updateTime = getFieldValByName("update_time", metaObject);
if (createTime == null) {
this.setFieldValByName("create_time", now, metaObject);
}
if (updateTime == null) {
this.setFieldValByName("update_time", now, metaObject);
}
this.setFieldValByName("version", 1, metaObject);
// 创建人
// Principal currentUser = getCurrentUser();
// this.setFieldValByName("creatorId", currentUser.getId(), metaObject);
// this.setFieldValByName("creatorName", currentUser.getLoginName(), metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
LocalDateTime now = LocalDateTime.now();
Object updateTime = getFieldValByName("update_time", metaObject);
if (updateTime == null) {
this.setFieldValByName("update_time", now, metaObject);
}
//操作人
// this.setFieldValByName("createId", 111L, metaObject);
// this.setFieldValByName("modifierBy", 111L, metaObject);
}
/**
* 获取当前登录用户
*
* @return 用户对象
*/
// private Principal getCurrentUser() {
// Subject subject = SecurityUtils.getSubject();
// if (subject != null) {
// Principal user = (Principal) subject.getPrincipal();
// if (user != null) {
// return user;
// }
// }
// return null;
// return new Principal(1L, "admin");
// }
}
package cn.wisenergy.chnmuseum.party.common.vo;
import lombok.*;
import lombok.experimental.Accessors;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class AssetVo {
private String fileName;
private String fileExt;
private Long fileSize;
private String fileUrl;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFileExt() {
return fileExt;
}
public void setFileExt(String fileExt) {
this.fileExt = fileExt;
}
public Long getFileSize() {
return fileSize;
}
public void setFileSize(Long fileSize) {
this.fileSize = fileSize;
}
public String getFileUrl() {
return fileUrl;
}
public void setFileUrl(String fileUrl) {
this.fileUrl = fileUrl;
}
}
...@@ -2,7 +2,6 @@ package cn.wisenergy.chnmuseum.party.conf; ...@@ -2,7 +2,6 @@ package cn.wisenergy.chnmuseum.party.conf;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.ValueFilter;
import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
...@@ -46,14 +45,6 @@ public class FastJsonHttpMessageConvertersConfig { ...@@ -46,14 +45,6 @@ public class FastJsonHttpMessageConvertersConfig {
mediaTypes.add(MediaType.TEXT_PLAIN); mediaTypes.add(MediaType.TEXT_PLAIN);
//mediaTypes.add(new MediaType("text", "plain", Charset.forName("UTF-8"))); //mediaTypes.add(new MediaType("text", "plain", Charset.forName("UTF-8")));
converter.setSupportedMediaTypes(mediaTypes); converter.setSupportedMediaTypes(mediaTypes);
// o 是class,s 是key值,o1 是value值
ValueFilter valueFilter = (o1, s, o2) -> {
if (null == o2) {
o2 = "";
}
return o2;
};
fastJsonConfig.setSerializeFilters(valueFilter);
converter.setFastJsonConfig(fastJsonConfig); converter.setFastJsonConfig(fastJsonConfig);
return converter; return converter;
} }
......
package cn.wisenergy.chnmuseum.party.conf; package cn.wisenergy.chnmuseum.party.conf;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
...@@ -23,6 +23,7 @@ import static com.google.common.collect.Lists.newArrayList; ...@@ -23,6 +23,7 @@ import static com.google.common.collect.Lists.newArrayList;
*/ */
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2
@EnableKnife4j
public class SwaggerConfig { public class SwaggerConfig {
@Bean @Bean
......
...@@ -6,6 +6,7 @@ import cn.wisenergy.chnmuseum.party.common.enums.RESPONSE_CODE_ENUM; ...@@ -6,6 +6,7 @@ import cn.wisenergy.chnmuseum.party.common.enums.RESPONSE_CODE_ENUM;
import cn.wisenergy.chnmuseum.party.common.mvc.InterfaceException; import cn.wisenergy.chnmuseum.party.common.mvc.InterfaceException;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add; import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Update; import cn.wisenergy.chnmuseum.party.common.validator.groups.Update;
import cn.wisenergy.chnmuseum.party.common.vo.AssetVo;
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam; import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;
import cn.wisenergy.chnmuseum.party.model.Asset; import cn.wisenergy.chnmuseum.party.model.Asset;
import cn.wisenergy.chnmuseum.party.model.AssetType; import cn.wisenergy.chnmuseum.party.model.AssetType;
...@@ -14,7 +15,7 @@ import cn.wisenergy.chnmuseum.party.service.AssetService; ...@@ -14,7 +15,7 @@ import cn.wisenergy.chnmuseum.party.service.AssetService;
import cn.wisenergy.chnmuseum.party.service.AssetTypeService; import cn.wisenergy.chnmuseum.party.service.AssetTypeService;
import cn.wisenergy.chnmuseum.party.service.CopyrightOwnerService; import cn.wisenergy.chnmuseum.party.service.CopyrightOwnerService;
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController; import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import com.baidu.ueditor.extend.MultipartFile; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
...@@ -24,15 +25,18 @@ import io.swagger.annotations.ApiImplicitParam; ...@@ -24,15 +25,18 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -60,20 +64,27 @@ public class AssetController extends BaseController { ...@@ -60,20 +64,27 @@ public class AssetController extends BaseController {
@Resource @Resource
private AssetTypeService assetTypeService; private AssetTypeService assetTypeService;
@PostMapping(value = "/save", headers = "content-type=multipart/form-data", produces = MediaType.MULTIPART_FORM_DATA_VALUE) @ApiImplicitParams({
//@ApiImplicitParam(name = "files", value = "视频文件", paramType = "form", dataType = "__file", collectionFormat="array", allowMultiple = true)
})
@PostMapping(value = "/save",
headers = "content-type=multipart/form-data",
consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@RequiresPermissions("asset:save") @RequiresPermissions("asset:save")
@ApiOperation(value = "添加视频", notes = "添加视频") @ApiOperation(value = "添加视频", notes = "添加视频")
public Map<String, Object> saveAsset(@Validated(value = {Add.class}) Asset asset, @RequestParam(value = "files") MultipartFile[] files) throws IOException { public Map<String, Object> saveAsset(@Validated(value = {Add.class}) Asset asset, @RequestPart(value = "files", required = false) MultipartFile[] files) throws IOException {
if (files.length == 0) { if (files.length == 0) {
throw new InterfaceException(RESPONSE_CODE_ENUM.REQUEST_PARAMS_ERROR.getCode(), "视频必须上传"); throw new InterfaceException(RESPONSE_CODE_ENUM.REQUEST_PARAMS_ERROR.getCode(), "视频必须上传");
} }
final Map<String, String> filesMetadata = new LinkedHashMap<>(2); final List<AssetVo> filesMetadata = new ArrayList<>(2);
for (MultipartFile file : files) { for (MultipartFile file : files) {
// 原始文件名 // 原始文件名
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
String url = FastDFSUtils.uploadInputStream(file.getInputStream(), originalFilename, file.getSize()); String url = FastDFSUtils.uploadInputStream(file.getInputStream(), originalFilename, file.getSize());
filesMetadata.put(originalFilename.trim(), url); filesMetadata.add(AssetVo.builder().fileName(originalFilename).fileExt(FilenameUtils.getExtension(originalFilename))
.fileSize(file.getSize()).fileUrl(url).build());
} }
asset.setVideoUrl(JSONObject.toJSONString(filesMetadata));
asset.setAuditStatus(AuditStatusEnum.TBC.name()); asset.setAuditStatus(AuditStatusEnum.TBC.name());
// 保存业务节点信息 // 保存业务节点信息
boolean result = assetService.save(asset); boolean result = assetService.save(asset);
......
...@@ -43,6 +43,7 @@ spring.mvc.format.date=yyyy-MM-dd HH:mm:ss ...@@ -43,6 +43,7 @@ spring.mvc.format.date=yyyy-MM-dd HH:mm:ss
#spring.mvc.static-path-pattern=/** #spring.mvc.static-path-pattern=/**
#spring.mvc.static-path-pattern=/public/** #spring.mvc.static-path-pattern=/public/**
spring.web.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/statics/,classpath:/public/ spring.web.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/statics/,classpath:/public/
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-request-size=4096MB spring.servlet.multipart.max-request-size=4096MB
spring.servlet.multipart.max-file-size=2048MB spring.servlet.multipart.max-file-size=2048MB
spring.web.resources.add-mappings=true spring.web.resources.add-mappings=true
......
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