Merge branch 'master' of 47.110.11.213:BY_BE_team/plat2-eladmin into master

 Conflicts:
	eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/httpRequest/HttpClient.java
	eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/TransFormDataTask.java
master
土豆兄弟 3 years ago
commit e5210d4df1

@ -24,6 +24,10 @@ public class DefaultConstant {
*/ */
public static final int TWO_NUMBER = 2; public static final int TWO_NUMBER = 2;
/**
* 3
*/
public static final int THREE_NUMBER = 3;
/** /**
* 5 * 5

@ -96,7 +96,7 @@ public interface FormdataService {
* @param file * @param file
* @return * @return
*/ */
boolean parseFileAndSaveToDB(MultipartFile file); List<FormdataDto> parseFileAndSaveToDB(MultipartFile file);
/** /**
* *
@ -111,5 +111,5 @@ public interface FormdataService {
* *
* @param file * @param file
*/ */
void uploadOOS(MultipartFile file); void uploadOOS(MultipartFile file, List<FormdataDto> list);
} }

@ -15,22 +15,12 @@
*/ */
package me.zhengjie.modules.formdata.service.impl; package me.zhengjie.modules.formdata.service.impl;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.system.OsInfo;
import cn.hutool.system.SystemUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory; import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelReader;
import com.aliyun.oss.OSS; import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest; import com.aliyun.oss.model.PutObjectResult;
import lombok.Data;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.zhengjie.common.http.CommonResponse;
import me.zhengjie.common.http.ResponseCode;
import me.zhengjie.modules.formdata.domain.Formdata; import me.zhengjie.modules.formdata.domain.Formdata;
import me.zhengjie.modules.formdata.repository.FormdataRepository; import me.zhengjie.modules.formdata.repository.FormdataRepository;
import me.zhengjie.modules.formdata.service.FormdataService; import me.zhengjie.modules.formdata.service.FormdataService;
@ -42,6 +32,7 @@ import me.zhengjie.modules.uploadnew.service.dto.ExcelDataDTO;
import me.zhengjie.modules.uploadnew.service.dto.OosDTO; import me.zhengjie.modules.uploadnew.service.dto.OosDTO;
import me.zhengjie.modules.uploadnew.service.dto.WavDTO; import me.zhengjie.modules.uploadnew.service.dto.WavDTO;
import me.zhengjie.modules.uploadnew.task.TransFormDataTask; import me.zhengjie.modules.uploadnew.task.TransFormDataTask;
import me.zhengjie.modules.uploadnew.service.impl.BuildPathUtils;
import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp; import me.zhengjie.utils.QueryHelp;
@ -58,7 +49,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -80,26 +70,18 @@ public class FormdataServiceImpl implements FormdataService {
private final FormdataMapper formdataMapper; private final FormdataMapper formdataMapper;
@Autowired @Autowired
private final TransFormDataTask transFormDataTask; private final TransFormDataTask transFormDataTask;
/**
* - linux
*/
@Value("${remote.link.file-base-path-linux}")
private String remoteLinkFileBasePathLinux;
/**
* - linux
*/
@Value("${remote.link.file-base-path-windows}")
private String remoteLinkFileBasePathWindows;
/**
* - linux
*/
@Value("${remote.link.file-base-path-mac}")
private String remoteLinkFileBasePathMac;
private List<FormdataDto> list = new ArrayList<>(); @Autowired
private BuildPathUtils buildPathUtils;
@Value("${upload.accessKeyId}")
private String accessKeyId;
@Value("${upload.accessKeySecret}")
private String accessKeySecret;
@Value("${upload.bucketName}")
private String bucketName;
@Value("${upload.endpoint}")
private String endpoint;
@Override @Override
public Map<String, Object> queryAll(FormdataQueryCriteria criteria, Pageable pageable) { public Map<String, Object> queryAll(FormdataQueryCriteria criteria, Pageable pageable) {
@ -166,7 +148,7 @@ public class FormdataServiceImpl implements FormdataService {
* @return * @return
*/ */
@Override @Override
public boolean parseFileAndSaveToDB(MultipartFile file) { public List<FormdataDto> parseFileAndSaveToDB(MultipartFile file) {
List<Formdata> formData; List<Formdata> formData;
// 1. todo 先进行解析 excel 文件 // 1. todo 先进行解析 excel 文件
try { try {
@ -177,15 +159,11 @@ public class FormdataServiceImpl implements FormdataService {
formData = listener.getData(); formData = listener.getData();
// 2. todo 把解析后的结果进行入库 // 2. todo 把解析后的结果进行入库
formdataRepository.saveAll(formData); formdataRepository.saveAll(formData);
list = formdataMapper.toDto(formData); return formdataMapper.toDto(formData);
//
} catch (Exception e) { } catch (Exception e) {
log.error("解析失败"); log.error("解析失败");
e.printStackTrace(); throw new RuntimeException("");
return false;
} }
return true;
} }
/** /**
@ -200,8 +178,7 @@ public class FormdataServiceImpl implements FormdataService {
//文件名 //文件名
String fileName = file.getOriginalFilename(); String fileName = file.getOriginalFilename();
//文件保存地址 //文件保存地址
String path = buildFilePath(fileName); String path = buildPathUtils.buildFilePath();
OutputStream os = null; OutputStream os = null;
InputStream inputStream = null; InputStream inputStream = null;
try { try {
@ -244,24 +221,18 @@ public class FormdataServiceImpl implements FormdataService {
* @return * @return
*/ */
@Override @Override
public void uploadOOS(MultipartFile file) { public void uploadOOS(MultipartFile file, List<FormdataDto> list) {
String accessKeyId = "LTAI5t8agDMumxcjAVuuwqPY";
String accessKeySecret = "i93lzrZwb2BUgtB9r0y0LT2Dt7tNbP";
String bucketName = "hjrecording";
String endpoint = "oss-cn-shanghai.aliyuncs.com";
String fileName = file.getOriginalFilename(); String fileName = file.getOriginalFilename();
String subFixFile = StringUtils.substringAfterLast(fileName, SPLIT_FILE_SYMBOL); String subFixFile = StringUtils.substringAfterLast(fileName, SPLIT_FILE_SYMBOL);
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
List<WavDTO> wavList = zipUtil(file); List<WavDTO> wavList = zipUtil(file);
for (WavDTO wavDTO : wavList) { for (WavDTO wavDTO : wavList) {
for (FormdataDto info : list) { for (FormdataDto info : list) {
if (wavDTO.getName().equals(info.getPhone())) { if (wavDTO.getName().equals(info.getPhone())) {
//上传oos //上传路径
String newFileName = buildFileOosPath(subFixFile); String newFileName = buildPathUtils.buildFileOosPath(subFixFile);
ossClient.putObject(bucketName, newFileName, wavDTO.getLine()); OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
PutObjectResult putObjectResult = ossClient.putObject(bucketName, newFileName, wavDTO.getLine());
ossClient.shutdown(); ossClient.shutdown();
OosDTO oosDTO = toBean(info, newFileName); OosDTO oosDTO = toBean(info, newFileName);
//发送下游 //发送下游
@ -272,7 +243,6 @@ public class FormdataServiceImpl implements FormdataService {
} }
private List<WavDTO> zipUtil(MultipartFile file) { private List<WavDTO> zipUtil(MultipartFile file) {
List<WavDTO> wavDTOS = new ArrayList<>(); List<WavDTO> wavDTOS = new ArrayList<>();
String zipFileName = null; String zipFileName = null;
@ -299,7 +269,7 @@ public class FormdataServiceImpl implements FormdataService {
private OosDTO toBean(FormdataDto info, String newFileName) { private OosDTO toBean(FormdataDto info, String newFileName) {
OosDTO oosDTO = new OosDTO(); OosDTO oosDTO = new OosDTO();
oosDTO.setId(info.getSourceId()); oosDTO.setId(info.getSourceId().longValue());
oosDTO.setAge(info.getAge()); oosDTO.setAge(info.getAge());
oosDTO.setCity(info.getCity()); oosDTO.setCity(info.getCity());
oosDTO.setName(info.getName()); oosDTO.setName(info.getName());
@ -308,61 +278,4 @@ public class FormdataServiceImpl implements FormdataService {
oosDTO.setVoiceaddr(newFileName); oosDTO.setVoiceaddr(newFileName);
return oosDTO; return oosDTO;
} }
/**
*
*/
private String buildFilePath(String fileName) {
// 获取环境配置信息
OsInfo osInfo = SystemUtil.getOsInfo();
// 定义的时间格式
String timeFormate = DateUtil.today() ;
String dirPath;
if (osInfo.isWindows()) {
dirPath = remoteLinkFileBasePathWindows + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isLinux()) {
dirPath = remoteLinkFileBasePathLinux + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isMac()) {
dirPath = remoteLinkFileBasePathMac + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else {
return "";
}
}
/**
*
*/
private String buildFileOosPath(String subFixFile) {
OsInfo osInfo = SystemUtil.getOsInfo();
String timeFormate = DateUtil.date() + "" + (Math.random() * 9 + 1) * 10000 + "." + subFixFile;
String dirPath;
if (osInfo.isWindows()) {
dirPath = remoteLinkFileBasePathWindows + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isLinux()) {
dirPath = remoteLinkFileBasePathLinux + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isMac()) {
dirPath = remoteLinkFileBasePathMac + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else {
return "";
}
}
} }

@ -135,9 +135,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 所有类型的接口都放行 // 所有类型的接口都放行
.antMatchers(anonymousUrls.get(RequestMethodEnum.ALL.getType()).toArray(new String[0])).permitAll() .antMatchers(anonymousUrls.get(RequestMethodEnum.ALL.getType()).toArray(new String[0])).permitAll()
// 所有请求都需要认证 // 所有请求都需要认证
// .anyRequest().authenticated() .anyRequest().authenticated()
.antMatchers().permitAll() // .antMatchers().permitAll()
.anyRequest().permitAll() // .anyRequest().permitAll()
.and().apply(securityConfigurerAdapter()); .and().apply(securityConfigurerAdapter());
} }

@ -1,53 +0,0 @@
package me.zhengjie.modules.uploadnew.httpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
/**
* @author wjt
* @date 2021/8/6
*/
public class HttpClient {
/**
* token2
* b1540b934765484d9364792914be0027
* d2170b4d14c44f75aec196f2c8b911fc
*/
private static final String URL = "https://app.hjdata.com/api/dymaticform/channel/save?formId=1&token=xxdfdfgdgd";
public static String doPost(String map, String charset) {
org.apache.http.client.HttpClient httpClient = null;
HttpPost httpPost = null;
String result = null;
try {
httpClient = new SSLClient();
httpPost = new HttpPost(URL);
//设置参数
httpPost.addHeader("Accept", "application/json");
httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
StringEntity stringEntity = new StringEntity(map);
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
HttpResponse response = httpClient.execute(httpPost);
if (response != null) {
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
result = EntityUtils.toString(resEntity, charset);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
JSONObject json = JSONUtil.parseObj(result);
if (Integer.parseInt(json.get("code").toString()) == 200) {
}
return result;
}
}

@ -1,42 +0,0 @@
package me.zhengjie.modules.uploadnew.httpRequest;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
//用于进行Https请求的HttpClient
public class SSLClient extends DefaultHttpClient {
public SSLClient() throws Exception {
super();
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = this.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
}
}

@ -1,7 +1,6 @@
package me.zhengjie.modules.uploadnew.listener; package me.zhengjie.modules.uploadnew.listener;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.ObjectId;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;

@ -30,17 +30,15 @@ import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.constant.DefaultConstant; import me.zhengjie.modules.constant.DefaultConstant;
import me.zhengjie.modules.formdata.service.FormdataService; import me.zhengjie.modules.formdata.service.FormdataService;
import me.zhengjie.modules.formdata.service.dto.FormdataDto; import me.zhengjie.modules.formdata.service.dto.FormdataDto;
import me.zhengjie.modules.formdata.service.mapstruct.FormdataMapper;
import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew; import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew;
import me.zhengjie.modules.uploadnew.redis.RedisParentDao; import me.zhengjie.modules.uploadnew.redis.RedisParentDao;
import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService; import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService;
import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto; import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto;
import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewQueryCriteria; import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewQueryCriteria;
import me.zhengjie.modules.uploadnew.service.mapstruct.TbUploadFileNewMapper;
import me.zhengjie.modules.uploadnew.task.SaveToFileNewTask; import me.zhengjie.modules.uploadnew.task.SaveToFileNewTask;
import me.zhengjie.modules.uploadnew.task.TransFormDataTask;
import me.zhengjie.utils.SecurityUtils; import me.zhengjie.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -64,7 +62,6 @@ import static me.zhengjie.modules.constant.FileConstant.*;
import static me.zhengjie.modules.upload.consts.UploadFileConst.FILE_PATH_SPLIT; import static me.zhengjie.modules.upload.consts.UploadFileConst.FILE_PATH_SPLIT;
import static me.zhengjie.modules.uploadnew.consts.SysConstNew.*; import static me.zhengjie.modules.uploadnew.consts.SysConstNew.*;
//import org.springframework.util.StringUtils;
/** /**
* @author weizhongxi * @author weizhongxi
@ -78,6 +75,7 @@ import static me.zhengjie.modules.uploadnew.consts.SysConstNew.*;
@Slf4j @Slf4j
public class TbUploadFileNewController { public class TbUploadFileNewController {
private TbUploadFileNewService tbUploadFileNewService; private TbUploadFileNewService tbUploadFileNewService;
private SaveToFileNewTask saveToFileNewTask; private SaveToFileNewTask saveToFileNewTask;
@ -85,9 +83,6 @@ public class TbUploadFileNewController {
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
private FormdataService formdataService; private FormdataService formdataService;
@Autowired
private TbUploadFileNewMapper tbUploadFileNewMapper;
@Autowired @Autowired
public TbUploadFileNewController(TbUploadFileNewService tbUploadFileNewService, SaveToFileNewTask saveToFileNewTask, RedisTemplate redisTemplate, FormdataService formdataService) { public TbUploadFileNewController(TbUploadFileNewService tbUploadFileNewService, SaveToFileNewTask saveToFileNewTask, RedisTemplate redisTemplate, FormdataService formdataService) {
@ -149,9 +144,9 @@ public class TbUploadFileNewController {
*/ */
@Log("新的成单数据及录音文件导入接口") @Log("新的成单数据及录音文件导入接口")
@ApiOperation("新的成单数据及录音文件导入接口") @ApiOperation("新的成单数据及录音文件导入接口")
@AnonymousAccess // @AnonymousAccess
@PostMapping("/newFileUpload") @PostMapping("/newFileUpload")
// @PreAuthorize("@el.check('tbUploadFileNew:list')") // 这个换下相关按钮的权限控制 @PreAuthorize("@el.check('tbUploadFileNew:list')") // 这个换下相关按钮的权限控制
// @ResponseBody // @ResponseBody
public ResponseEntity<Object> newFileUpload(@RequestParam("file") MultipartFile[] files, public ResponseEntity<Object> newFileUpload(@RequestParam("file") MultipartFile[] files,
@RequestParam(value = "taskName") String taskName) { @RequestParam(value = "taskName") String taskName) {
@ -177,50 +172,21 @@ public class TbUploadFileNewController {
log.error("保存失败"); log.error("保存失败");
} }
int finishTag = 0; int finishTag = 0;
List<FormdataDto> list = new ArrayList<>();
for (MultipartFile file : files) { for (MultipartFile file : files) {
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
if (StringUtils.isNotBlank(originalFilename)) { if (StringUtils.isNotBlank(originalFilename)) {
String subOriginalFilename = StringUtils.substringAfterLast(originalFilename, SPLIT_FILE_SYMBOL); String subOriginalFilename = StringUtils.substringAfterLast(originalFilename, SPLIT_FILE_SYMBOL);
finishTag = handleEachUploadFile(file, subOriginalFilename, finishTag, resourcesDto);
}
}
// 确保所有文件都经过了响应的处理
if (finishTag != files.length) {
// todo 上传完成更新文件上传记录
log.error("TbUploadFileNewController:newFileUpload | taskName : {} fail ", taskName);
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.FILE_HANDLE_FAIL), HttpStatus.OK);
}
// todo 上传完成更新文件上传记录
resourcesDto.setUploadTag(DefaultConstant.TWO_NUMBER);
resourcesDto.setGmtModified(DateUtil.date().toTimestamp());
tbUploadFileNewService.create(tbUploadFileNewMapper.toEntity(resourcesDto));
return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK);
}
/**
* finishTag ,
*
* @param subOriginalFilename
* @return
*/
private int handleEachUploadFile(MultipartFile file, String subOriginalFilename, int finishTag, TbUploadFileNewDto resourcesDto) {
if (XLSX_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)) { if (XLSX_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)) {
// TODO: 2021/8/5 0005 解析 入库 // TODO: 2021/8/5 0005 解析 入库
if (formdataService.parseFileAndSaveToDB(file)) { list = formdataService.parseFileAndSaveToDB(file);
if (CollectionUtil.isNotEmpty(list)) {
finishTag += 1; finishTag += 1;
} }
} }
if (RAR_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename) if (RAR_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)
|| ZIP_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)) { || ZIP_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)) {
// TODO: 2021/8/5 0005 以 压缩文件结尾的格式 则直接进行保存文件到指定文件夹目录下 // TODO: 2021/8/5 0005 以 压缩文件结尾的格式 则直接进行保存文件到指定文件夹目录下
String localSavePath = formdataService.parseMediaFileToLocal(file); String localSavePath = formdataService.parseMediaFileToLocal(file);
if (StringUtils.isNotBlank(localSavePath)) { if (StringUtils.isNotBlank(localSavePath)) {
@ -229,12 +195,37 @@ public class TbUploadFileNewController {
resourcesDto.setFileFormat(subOriginalFilename); resourcesDto.setFileFormat(subOriginalFilename);
finishTag += 1; finishTag += 1;
} }
}
// finishTag = handleEachUploadFile(file, subOriginalFilename, finishTag, resourcesDto, list);
}
}
for (MultipartFile file : files) {
String subOriginalFilename = StringUtils.substringAfterLast(file.getOriginalFilename(), SPLIT_FILE_SYMBOL);
if (CollectionUtil.isNotEmpty(list)) {
if (RAR_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename) || ZIP_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)) {
// 3. todo 上传oos 并 异步发送给 下游接口 // 3. todo 上传oos 并 异步发送给 下游接口
formdataService.uploadOOS(file); formdataService.uploadOOS(file, list);
}
}
} }
return finishTag; // 确保所有文件都经过了响应的处理
if (finishTag != files.length) {
// todo 上传完成更新文件上传记录
log.error("TbUploadFileNewController:newFileUpload | taskName : {} fail ", taskName);
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.FILE_HANDLE_FAIL), HttpStatus.OK);
} }
// todo 上传完成更新文件上传记录
resourcesDto.setUploadTag(DefaultConstant.TWO_NUMBER);
resourcesDto.setGmtModified(DateUtil.date().toTimestamp());
TbUploadFileNew tbUploadFileNew = new TbUploadFileNew();
BeanUtils.copyProperties(resourcesDto, tbUploadFileNew);
tbUploadFileNewService.create(tbUploadFileNew);
return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK);
}
/** /**
* *

@ -8,7 +8,7 @@ import lombok.Data;
*/ */
@Data @Data
public class OosDTO { public class OosDTO {
private Integer id; private Long id;
private String name; private String name;
private Integer age; private Integer age;
private String province; private String province;

@ -0,0 +1,94 @@
package me.zhengjie.modules.uploadnew.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.system.OsInfo;
import cn.hutool.system.SystemUtil;
import me.zhengjie.utils.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.File;
/**
* @author wjt
* @date 2021/8/6
*/
@Service
public class BuildPathUtils {
/**
* - linux
*/
@Value("${remote.link.file-base-path-linux}")
private String fileBasePathLinux;
/**
* - linux
*/
@Value("${remote.link.file-base-path-windows}")
private String fileBasePathWindows;
/**
* - linux
*/
@Value("${remote.link.file-base-path-mac}")
private String fileBasePathMac;
/**
*
*/
public String buildFilePath() {
// 获取环境配置信息
OsInfo osInfo = SystemUtil.getOsInfo();
// 定义的时间格式
String timeFormate = DateUtil.today();
String dirPath;
if (osInfo.isWindows()) {
dirPath = fileBasePathWindows + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isLinux()) {
dirPath = fileBasePathLinux + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isMac()) {
dirPath = fileBasePathMac + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else {
return "";
}
}
/**
*
*/
public String buildFileOosPath(String subFixFile) {
OsInfo osInfo = SystemUtil.getOsInfo();
String timeFormate = DateUtil.now() + "" + (Math.random() * 9 + 1) * 10000 + "." + subFixFile;
String dirPath;
if (osInfo.isWindows()) {
dirPath = fileBasePathWindows + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isLinux()) {
dirPath = fileBasePathLinux + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isMac()) {
dirPath = fileBasePathMac + timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else {
return "";
}
}
}

@ -1,18 +1,18 @@
/* /*
* Copyright 2019-2020 Zheng Jie * Copyright 2019-2020 Zheng Jie
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package me.zhengjie.modules.uploadnew.service.mapstruct; package me.zhengjie.modules.uploadnew.service.mapstruct;
import me.zhengjie.base.BaseMapper; import me.zhengjie.base.BaseMapper;
@ -22,10 +22,10 @@ import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy; import org.mapstruct.ReportingPolicy;
/** /**
* @website https://el-admin.vip * @author weizhongxi
* @author weizhongxi * @website https://el-admin.vip
* @date 2021-04-14 * @date 2021-04-14
**/ **/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TbUploadFileNewMapper extends BaseMapper<TbUploadFileNewDto, TbUploadFileNew> { public interface TbUploadFileNewMapper extends BaseMapper<TbUploadFileNewDto, TbUploadFileNew> {

@ -1,10 +1,15 @@
package me.zhengjie.modules.uploadnew.task; package me.zhengjie.modules.uploadnew.task;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.uploadnew.httpRequest.HttpClient; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.constant.DefaultConstant;
import me.zhengjie.modules.uploadnew.service.dto.OosDTO; import me.zhengjie.modules.uploadnew.service.dto.OosDTO;
import me.zhengjie.utils.ConvertUtil; import me.zhengjie.utils.ConvertUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -12,12 +17,25 @@ import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
@Component @Component
@Scope("prototype") @Scope("prototype")
@Slf4j @Slf4j
public class TransFormDataTask { public class TransFormDataTask {
@Value("${upload.url}")
private String url;
// private static String url = "https://app.hjdata.com/api/dymaticform/channel/save?";
/**
* token2
* b1540b934765484d9364792914be0027
* d2170b4d14c44f75aec196f2c8b911fc
*/
private final static String TOKEN = "d2170b4d14c44f75aec196f2c8b911fc";
/**
* @param oosDTO
*/
@Async(value = "SendBigDataTaskExecutor") @Async(value = "SendBigDataTaskExecutor")
public void doRunTask(OosDTO oosDTO) { public void doRunTask(OosDTO oosDTO) {
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
@ -28,7 +46,44 @@ public class TransFormDataTask {
} }
private void runTask(OosDTO oosDTO) { private void runTask(OosDTO oosDTO) {
String newUrl = url + "formId=3" + "&token=" + TOKEN;
String jsonStr = JSONUtil.toJsonStr(oosDTO); String jsonStr = JSONUtil.toJsonStr(oosDTO);
HttpClient.doPost(jsonStr, "utf-8"); int count = 0;
while (count < DefaultConstant.THREE_NUMBER) {
// 调用HTTP请求发送数据
HttpResponse httpResponse = sendPostReq(jsonStr, newUrl);
JSONObject object = JSONUtil.parseObj(httpResponse.body());
if (httpResponse.isOk() && object.get("retcode").equals(DefaultConstant.ZERO_NUMBER)) {
log.info("========== [SaveToFileTask|batchSendToEncrypt request success, response is {} ] ==========", object);
break;
} else {
count++;
try {
// 重新发送前休眠3秒
Thread.sleep(3_0000);
} catch (InterruptedException e) {
log.error("SaveToFileTask|batchSendToEncrypt sleep ERROR. message is", e.getMessage(), e);
throw new BadRequestException("请求异常!!!");
}
log.error("========== [SaveToFileTask|batchSendToEncrypt request fail, response is {} ] ==========", httpResponse.body());
}
}
if (count >= DefaultConstant.THREE_NUMBER) {
log.error("========== [SaveToFileTask|batchSendToEncrypt update send status fail, url is {} ] ==========", newUrl);
}
}
/**
* HTTPPost
*
* @param json body
* @return
*/
private HttpResponse sendPostReq(String json, String newUrl) {
return HttpRequest
.post(newUrl)
.header("Content-Type", "application/json;charset=utf-8")
.body(json)
.execute();
} }
} }

@ -5,7 +5,7 @@ spring:
freemarker: freemarker:
check-template-location: false check-template-location: false
profiles: profiles:
active: dev active: prod
jackson: jackson:
time-zone: GMT+8 time-zone: GMT+8
data: data:
@ -25,7 +25,7 @@ spring:
#数据库索引 #数据库索引
database: 0 database: 0
host: 118.178.137.129 host: 118.178.137.129
# port: 6379 # port: 6379
password: password:
#连接超时时间 #连接超时时间
timeout: 5000 timeout: 5000
@ -57,11 +57,18 @@ rsa:
remote: remote:
link: link:
address: 'http://47.110.11.213:8000/api/temp/file/download' address: 'http://47.110.11.213:8000/api/temp/file/download'
file-base-path-linux: /home/eladmin/file/temp/ file-base-path-linux: ~/home/eladmin/file/temp/
file-base-path-windows: C:\eladmin\file\temp\ file-base-path-windows: C:\eladmin\file\temp\
file-base-path-mac: /Users/wujingtao/file/eladmin/temp/ file-base-path-mac: ~/file/eladmin/temp/
# 发送加密家口需要的一些参数 # 发送加密家口需要的一些参数
inter: inter:
address: https://bd.hzdaba.cn:8085/v3/Accounts/yuyoukeji/BigData/EncryptTel address: https://bd.hzdaba.cn:8085/v3/Accounts/yuyoukeji/BigData/EncryptTel
appid: yuyoukeji appid: yuyoukeji
tk: e3fb7090b4babe44a5113601487af433 tk: e3fb7090b4babe44a5113601487af433
upload:
accessKeyId: LTAI5t8agDMumxcjAVuuwqPY
accessKeySecret: i93lzrZwb2BUgtB9r0y0LT2Dt7tNbP
bucketName: hjrecording
endpoint: oss-cn-shanghai.aliyuncs.com
url: https://app.hjdata.com/api/dymaticform/channel/save?

@ -77,7 +77,7 @@
<root level="INFO"> <root level="INFO">
<!-- TODO prod 环境去掉std --> <!-- TODO prod 环境去掉std -->
<appender-ref ref="stdAppender"/> <!-- <appender-ref ref="stdAppender"/>-->
<!-- <appender-ref ref="fileAppender"/>--> <appender-ref ref="fileAppender"/>
</root> </root>
</configuration> </configuration>
Loading…
Cancel
Save