Commit 7c46287b by liyanlin

fix

parent f091a576
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD cost-service-1.0-SNAPSHOT.jar cost-service-1.0-SNAPSHOT.jar
ENV LANG en_GB.UTF-8
RUN echo "Asia/Shanghai" > /etc/timezone
RUN echo -e "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main\n\
https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/community" > /etc/apk/repositories
RUN apk --update add curl bash ttf-dejavu && \
rm -rf /var/cache/apk/*
ENTRYPOINT ["java","-Xms1G","-Xmx1G","-jar","-Dspring.profiles.active=test","/cost-service-1.0-SNAPSHOT.jar"]
ENTRYPOINT ["java","-Xms100m","-Xmx300m","-jar","-Dspring.profiles.active=prod","/app.jar"]
EXPOSE 8082
......@@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
/**
* <p>
*
......@@ -30,10 +32,13 @@ public class FileController {
public CostResult<String> upload(MultipartFile file) {
/*附件字段*/
if (file != null) {
// 文件上传的路径
String filePath = PathUtil.getBasePath() + PathUtil.getPath("cost/");
// 调用工具类执行保存,并返回 path
String path = CostFileUtil.upload(file, filePath);
String path = null;
try {
path = CostFileUtil.qiniuUpload(file);
} catch (IOException e) {
throw new BizRuntimeException("上传文件失败");
}
return CostResult.success(path);
}
throw new BizRuntimeException("文件不能为空");
......
......@@ -242,9 +242,9 @@ public class CostApiServiceImpl implements CostApiService {
CostDetailDomain costDetailDomain = new CostDetailDomain();
// 文件上传的路径
String filePath = PathUtil.getBasePath() + PathUtil.getPath("cost/" + costDomain.getCostNo() + "/");
//String filePath = PathUtil.getBasePath() + PathUtil.getPath("cost/" + costDomain.getCostNo() + "/");
// 调用工具类执行保存,并返回 path
String path = CostFileUtil.upload(wageCostDto.getFileUrl(), filePath);
String path = CostFileUtil.qiniuUpload(wageCostDto.getFileUrl());
BeanUtils.copyProperties(costDomain, costDetailDomain);
costDetailDomain.setDetailNo(costNo + "-1");
......
......@@ -3,6 +3,7 @@ package com.blt.other.module.cost.service.impl;
import com.bailuntec.common.BeanUtils;
import com.bailuntec.common.ListUtil;
import com.bailuntec.common.StringUtils;
import com.bailuntec.common.exception.BizException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blt.other.common.exception.BizRuntimeException;
......@@ -24,6 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -74,9 +76,14 @@ public class CostDetailServiceImpl extends ServiceImpl<CostDetailDao, CostDetail
if (req.getFileSelect2() != null) {
// 文件上传的路径
String filePath = PathUtil.getBasePath() + PathUtil.getPath("cost/" + costDetailDomain.getDetailNo() + "/");
//String filePath = PathUtil.getBasePath() + PathUtil.getPath("cost/" + costDetailDomain.getDetailNo() + "/");
// 调用工具类执行保存,并返回 path
String path = CostFileUtil.upload(req.getFileSelect2(), filePath);
String path = null;
try {
path = CostFileUtil.qiniuUpload(req.getFileSelect2());
} catch (IOException e) {
throw new BizException("上传文件失败");
}
costDetailDomain.setFilePath(path);
}
......
......@@ -200,6 +200,7 @@ public class CostPlanServiceFactory {
throw new BizException("找不到文件:"+ costPlanDomain.getFilePath());
}
String path = CostFileUtil.qiniuUpload(currentFile);
currentFile.deleteOnExit();
if (path == null) {
throw new Exception("上传附件失败");
}
......
......@@ -102,6 +102,31 @@ public class CostFileUtil {
return qiniuUpload(localFile);
}
public static String qiniuUpload(String netUrl) throws IOException {
RestTemplate restTemplate = new RestTemplate();
byte[] bytes = restTemplate.getForObject(netUrl, byte[].class);
if (bytes == null || bytes.length == 0) {
throw new RuntimeException("附件内容为空");
}
int dotIndex = netUrl.lastIndexOf(".");
File tempFile = File.createTempFile(UidUtils.VM_ID + "fee-original", "."+netUrl.substring(dotIndex + 1));
OutputStream outputStream = new FileOutputStream(tempFile.getAbsolutePath());
outputStream.write(bytes);
outputStream.close();
String path = "http://dcfile.blsct.com/" + qiniuUpload(tempFile);
tempFile.deleteOnExit();
return path;
}
public static String qiniuUpload(MultipartFile file) throws IOException {
File tempFile = File.createTempFile(UidUtils.VM_ID + "fee-original", file.getOriginalFilename().replaceAll("_", ""));
file.transferTo(tempFile);
String path = "http://dcfile.blsct.com/" + qiniuUpload(tempFile);
tempFile.deleteOnExit();
return path;
}
public static String qiniuUpload(File localFilePath) {
//1、构造一个带指定Zone对象的配置类
// Configuration cfg = new Configuration(Zone.zone2());
......
package com.blt.other.module.purchasing.controller;
import com.alibaba.fastjson.JSON;
import com.bailuntec.common.exception.BizException;
import com.bailuntec.cost.api.domain.BuyDomain;
import com.blt.other.common.annotation.LoginIgnore;
import com.blt.other.common.config.property.CostUrlProperties;
......@@ -240,9 +241,14 @@ public class PurchasingListDetailController {
}
if (file != null) {
// 文件上传的路径
String filePath = PathUtil.getBasePath() + PathUtil.getPath("buy/" + buyDomain.getBuyno() + "/");
//String filePath = PathUtil.getBasePath() + PathUtil.getPath("buy/" + buyDomain.getBuyno() + "/");
// 调用工具类执行保存,并返回 path
String path = CostFileUtil.upload(file, filePath);
String path = null;
try {
path = CostFileUtil.qiniuUpload(file);
} catch (IOException e) {
throw new BizException("上传文件失败");
}
buyDomain.setFilepath(path);
}
Integer update = buyService.getUpdate(buyDomain);
......
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