Browse Source

feature1.0.0-img:优化压缩配置

master
chengkun 4 years ago
parent
commit
4295be8591
  1. 25
      bnyer-services/bnyer-file/src/main/java/com/bnyer/file/config/ImgConfig.java
  2. 2
      bnyer-services/bnyer-file/src/main/java/com/bnyer/file/config/TikTokConfig.java
  3. 5
      bnyer-services/bnyer-file/src/main/java/com/bnyer/file/controller/SysFileController.java
  4. 2
      bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/impl/TikTokImageServiceImpl.java

25
bnyer-services/bnyer-file/src/main/java/com/bnyer/file/config/ImgConfig.java

@ -0,0 +1,25 @@
package com.bnyer.file.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
/**
* @Author: chengkun
* @Date: 2022-06-12-16:24
* @Description:
*/
@Configuration
@RefreshScope
@Getter
@Setter
public class ImgConfig {
@Value("${img.fileSize}")
private String fileSize;
@Value("${img.accuracy}")
private String accuracy;
}

2
bnyer-services/bnyer-file/src/main/java/com/bnyer/file/config/TikTokConfig.java

@ -23,7 +23,7 @@ public class TikTokConfig {
private String secret; private String secret;
@Value("${tiktok.grant_type}") @Value("${tiktok.grant_type}")
private String grant_type; private String grantType;
@Value("${tiktok.tokenUrl}") @Value("${tiktok.tokenUrl}")
private String tokenUrl; private String tokenUrl;

5
bnyer-services/bnyer-file/src/main/java/com/bnyer/file/controller/SysFileController.java

@ -1,6 +1,7 @@
package com.bnyer.file.controller; package com.bnyer.file.controller;
import com.bnyer.common.core.domain.R; import com.bnyer.common.core.domain.R;
import com.bnyer.file.config.ImgConfig;
import com.bnyer.file.service.IFileService; import com.bnyer.file.service.IFileService;
import com.bnyer.file.service.IQiniuService; import com.bnyer.file.service.IQiniuService;
import com.bnyer.file.service.MinioService; import com.bnyer.file.service.MinioService;
@ -35,6 +36,8 @@ public class SysFileController {
private IQiniuService qiniuService; private IQiniuService qiniuService;
@Autowired @Autowired
private IFileService fileService; private IFileService fileService;
@Autowired
private ImgConfig imgConfig;
/** /**
* 批量上传图片 * 批量上传图片
@ -67,7 +70,7 @@ public class SysFileController {
public R<List<String>> compression(MultipartFile[] files) throws IOException { public R<List<String>> compression(MultipartFile[] files) throws IOException {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
for (MultipartFile file : files) { for (MultipartFile file : files) {
MultipartFile file1 = ImgUtil.commpressPicCycle(100, 0.5f, file); MultipartFile file1 = ImgUtil.commpressPicCycle(Long.parseLong(imgConfig.getFileSize()), Double.parseDouble(imgConfig.getAccuracy()), file);
System.out.println("sssss"); System.out.println("sssss");
String url = qiniuService.userUpload(file1); String url = qiniuService.userUpload(file1);
list.add(url); list.add(url);

2
bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/impl/TikTokImageServiceImpl.java

@ -29,7 +29,7 @@ public class TikTokImageServiceImpl implements ITikTokImage {
HashMap<String, Object> param = new HashMap<>(); HashMap<String, Object> param = new HashMap<>();
param.put("appId", tikTokConfig.getAppId()); param.put("appId", tikTokConfig.getAppId());
param.put("secret", tikTokConfig.getSecret()); param.put("secret", tikTokConfig.getSecret());
param.put("grant_type", tikTokConfig.getGrant_type()); param.put("grant_type", tikTokConfig.getGrantType());
String body = JSON.toJSONString(param); String body = JSON.toJSONString(param);
String res = HttpUtils.sendPost(tikTokConfig.getTokenUrl(), body); String res = HttpUtils.sendPost(tikTokConfig.getTokenUrl(), body);
String err_tips = JSON.parseObject(res).get("err_tips").toString(); String err_tips = JSON.parseObject(res).get("err_tips").toString();

Loading…
Cancel
Save