Commit 2ab772f7 authored by 查济's avatar 查济

Merge branch 'feature-zhaji' into 'develop'

Feature zhaji

See merge request fangxinjiang/yifu!186
parents 2939d6a1 a050d457
...@@ -245,6 +245,10 @@ public interface CommonConstants { ...@@ -245,6 +245,10 @@ public interface CommonConstants {
public static final String SPOT = "."; public static final String SPOT = ".";
int FIFTY_INT = 50;
int BYTE = 1024;
/** /**
* 员工初始序列 * 员工初始序列
* @Author pwang * @Author pwang
......
...@@ -471,4 +471,28 @@ public class Common { ...@@ -471,4 +471,28 @@ public class Common {
} }
return obj; return obj;
} }
/**
* 商险附件允许上传的文件类型
*
* @Author pwang
* @Date 2020-01-07 15:52
* @param null
* @return
**/
private static final String insuranceSuffixList = "pdf|png|jpg|word|excel|rar|zip";
/**
* 判断是否为允许的上传文件类型,true表示允许
*/
public static boolean checkInsuranceFile(String fileName) {
// 获取文件后缀
String suffix = getSuffix(fileName);
if (null != suffix) {
if (insuranceSuffixList.contains(suffix.trim().toLowerCase())) {
return true;
}
}
return false;
}
} }
...@@ -39,8 +39,6 @@ public class TInsuranceEnclosureController { ...@@ -39,8 +39,6 @@ public class TInsuranceEnclosureController {
@Resource @Resource
TInsuranceEnclosureService tInsuranceEnclosureService; TInsuranceEnclosureService tInsuranceEnclosureService;
private final OSSUtil ossUtil;
/** /**
* 商险文件上传 * 商险文件上传
* *
......
...@@ -13,14 +13,17 @@ import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils; ...@@ -13,14 +13,17 @@ import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceEnclosure; import com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceEnclosure;
import com.yifu.cloud.plus.v1.yifu.insurances.mapper.TInsuranceEnclosureMapper; import com.yifu.cloud.plus.v1.yifu.insurances.mapper.TInsuranceEnclosureMapper;
import com.yifu.cloud.plus.v1.yifu.insurances.service.TInsuranceEnclosureService; import com.yifu.cloud.plus.v1.yifu.insurances.service.TInsuranceEnclosureService;
import com.yifu.cloud.plus.v1.yifu.insurances.util.ValidityUtil;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceEnclosureParam; import com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceEnclosureParam;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Objects;
/** /**
* @author Administrator * @author Administrator
...@@ -50,10 +53,19 @@ public class TInsuranceEnclosureServiceImpl extends ServiceImpl<TInsuranceEnclos ...@@ -50,10 +53,19 @@ public class TInsuranceEnclosureServiceImpl extends ServiceImpl<TInsuranceEnclos
*/ */
@Override @Override
public R uploadInsuranceEnclosure(MultipartFile file, String filePath, String remark) throws IOException { public R uploadInsuranceEnclosure(MultipartFile file, String filePath, String remark) throws IOException {
String enclosureName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")); if(Common.isEmpty(file)){
return R.failed("商险附件为空");
}
if(!Common.checkInsuranceFile(file.getOriginalFilename())){
return R.failed("非法的文件类型");
}
if (file.getSize() > (CommonConstants.FIFTY_INT*CommonConstants.BYTE*CommonConstants.BYTE)){
return R.failed("文件超出上传上限");
}
String enclosureName = Objects.requireNonNull(file.getOriginalFilename()).substring(0,file.getOriginalFilename().lastIndexOf("."));
String fileName = System.currentTimeMillis() + "_" + file.getOriginalFilename(); String fileName = System.currentTimeMillis() + "_" + file.getOriginalFilename();
//filePath不传默认存储空间的根目录 //filePath不传默认存储空间的根目录
//jpg,jpeg,png,bmp //支持的附件格式
String key = ""; String key = "";
if (!Common.isNotNull(filePath)) { if (!Common.isNotNull(filePath)) {
key = fileName; key = fileName;
...@@ -61,13 +73,17 @@ public class TInsuranceEnclosureServiceImpl extends ServiceImpl<TInsuranceEnclos ...@@ -61,13 +73,17 @@ public class TInsuranceEnclosureServiceImpl extends ServiceImpl<TInsuranceEnclos
key = filePath + "/" + fileName; key = filePath + "/" + fileName;
} }
boolean flag = ossUtil.uploadFileByStream(file.getInputStream(), key, null); boolean flag = ossUtil.uploadFileByStream(file.getInputStream(), key, null);
FileVo fileVo;
TInsuranceEnclosure insuranceEnclosure = new TInsuranceEnclosure();
URL url = null;
if (flag) { if (flag) {
TInsuranceEnclosure insuranceEnclosure = new TInsuranceEnclosure();
log.info("文件:" + fileName + "上传至存储空间" + ossUtil.getBucketName() + "成功!"); log.info("文件:" + fileName + "上传至存储空间" + ossUtil.getBucketName() + "成功!");
insuranceEnclosure.setDeleteFlag(CommonConstants.ZERO_INT); insuranceEnclosure.setDeleteFlag(CommonConstants.ZERO_INT);
if(StringUtils.isNotBlank(remark)){
if(!ValidityUtil.validate50(remark)){
return R.failed("备注字段不能超过50");
}else{
insuranceEnclosure.setRemark(remark); insuranceEnclosure.setRemark(remark);
}
}
insuranceEnclosure.setEnclosureName(enclosureName); insuranceEnclosure.setEnclosureName(enclosureName);
insuranceEnclosure.setEnclosureAddress(key); insuranceEnclosure.setEnclosureAddress(key);
try { try {
...@@ -77,9 +93,7 @@ public class TInsuranceEnclosureServiceImpl extends ServiceImpl<TInsuranceEnclos ...@@ -77,9 +93,7 @@ public class TInsuranceEnclosureServiceImpl extends ServiceImpl<TInsuranceEnclos
ossUtil.deleteObject(null, key); ossUtil.deleteObject(null, key);
return R.failed("failed:" + e.getMessage()); return R.failed("failed:" + e.getMessage());
} }
url = ossUtil.getObjectUrl(null, insuranceEnclosure.getEnclosureAddress()); return R.ok("商险附件上传成功");
fileVo = new FileVo(insuranceEnclosure.getId().toString(), insuranceEnclosure.getEnclosureName(), url.toString());
return R.ok(fileVo);
} else { } else {
return R.failed("failed:上传至存储空间失败"); return R.failed("failed:上传至存储空间失败");
} }
......
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