master
wujingtao 3 years ago
parent 5e61db3a54
commit 5661e7b1dd

@ -40,10 +40,10 @@
</dependency>
<!-- Spring boot websocket -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
@ -87,16 +87,16 @@
</dependency>
<!-- linux的管理 -->
<dependency>
<groupId>ch.ethz.ganymed</groupId>
<artifactId>ganymed-ssh2</artifactId>
<version>build210</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
<dependency>
<groupId>ch.ethz.ganymed</groupId>
<artifactId>ganymed-ssh2</artifactId>
<version>build210</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
<!-- 获取系统信息 -->
<dependency>
@ -106,12 +106,18 @@
</dependency>
<!--<dependency>-->
<!--<groupId>com.google.guava</groupId>-->
<!--<artifactId>guava-parent</artifactId>-->
<!--<version>23.0</version>-->
<!--<groupId>com.google.guava</groupId>-->
<!--<artifactId>guava-parent</artifactId>-->
<!--<version>23.0</version>-->
<!--</dependency>-->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.10.0</version>
</dependency>
</dependencies>
<!-- 打包 -->
<build>
<plugins>

@ -1,18 +1,18 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.zhengjie.modules.formdata.service;
import me.zhengjie.modules.formdata.domain.Formdata;
@ -27,60 +27,67 @@ import java.util.List;
import java.util.Map;
/**
* @website https://el-admin.vip
* @description
* @author x
* @date 2021-08-05
**/
* @author x
* @website https://el-admin.vip
* @description
* @date 2021-08-05
**/
public interface FormdataService {
/**
*
* @param criteria
* @param pageable
* @return Map<String,Object>
*/
Map<String,Object> queryAll(FormdataQueryCriteria criteria, Pageable pageable);
*
*
* @param criteria
* @param pageable
* @return Map<String, Object>
*/
Map<String, Object> queryAll(FormdataQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return List<FormdataDto>
*/
*
*
* @param criteria
* @return List<FormdataDto>
*/
List<FormdataDto> queryAll(FormdataQueryCriteria criteria);
/**
* ID
*
* @param id ID
* @return FormdataDto
*/
FormdataDto findById(Long id);
/**
*
* @param resources /
* @return FormdataDto
*/
*
*
* @param resources /
* @return FormdataDto
*/
FormdataDto create(Formdata resources);
/**
*
* @param resources /
*/
*
*
* @param resources /
*/
void update(Formdata resources);
/**
*
* @param ids /
*/
*
*
* @param ids /
*/
void deleteAll(Long[] ids);
/**
*
* @param all
* @param response /
* @throws IOException /
*/
*
*
* @param all
* @param response /
* @throws IOException /
*/
void download(List<FormdataDto> all, HttpServletResponse response) throws IOException;
/**
@ -98,4 +105,11 @@ public interface FormdataService {
* @return
*/
String parseMediaFileToLocal(MultipartFile file);
/**
* oos
*
* @param file
*/
void uploadOOS(MultipartFile file);
}

@ -1,33 +1,54 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.ExcelReader;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest;
import lombok.Data;
import lombok.RequiredArgsConstructor;
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.repository.FormdataRepository;
import me.zhengjie.modules.formdata.service.FormdataService;
import me.zhengjie.modules.formdata.service.dto.FormdataDto;
import me.zhengjie.modules.formdata.service.dto.FormdataQueryCriteria;
import me.zhengjie.modules.formdata.service.mapstruct.FormdataMapper;
import me.zhengjie.modules.uploadnew.listener.EasyExcelListener;
import me.zhengjie.modules.uploadnew.service.dto.ExcelDataDTO;
import me.zhengjie.modules.uploadnew.service.dto.OosDTO;
import me.zhengjie.modules.uploadnew.service.dto.WavDTO;
import me.zhengjie.modules.uploadnew.task.TransFormDataTask;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@ -35,44 +56,67 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.io.*;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import static me.zhengjie.modules.constant.FileConstant.SPLIT_FILE_SYMBOL;
/**
* @website https://el-admin.vip
* @description
* @author x
* @date 2021-08-05
**/
* @author x
* @website https://el-admin.vip
* @description
* @date 2021-08-05
**/
@Slf4j
@Service
@RequiredArgsConstructor
public class FormdataServiceImpl implements FormdataService {
private final FormdataRepository formdataRepository;
private final FormdataMapper formdataMapper;
@Autowired
private 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<>();
@Override
public Map<String,Object> queryAll(FormdataQueryCriteria criteria, Pageable pageable){
Page<Formdata> page = formdataRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
public Map<String, Object> queryAll(FormdataQueryCriteria criteria, Pageable pageable) {
Page<Formdata> page = formdataRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
return PageUtil.toPage(page.map(formdataMapper::toDto));
}
@Override
public List<FormdataDto> queryAll(FormdataQueryCriteria criteria){
return formdataMapper.toDto(formdataRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
public List<FormdataDto> queryAll(FormdataQueryCriteria criteria) {
return formdataMapper.toDto(formdataRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
}
@Override
@Transactional
public FormdataDto findById(Long id) {
Formdata formdata = formdataRepository.findById(id).orElseGet(Formdata::new);
ValidationUtil.isNull(formdata.getId(),"Formdata","id",id);
ValidationUtil.isNull(formdata.getId(), "Formdata", "id", id);
return formdataMapper.toDto(formdata);
}
@ -86,7 +130,7 @@ public class FormdataServiceImpl implements FormdataService {
@Transactional(rollbackFor = Exception.class)
public void update(Formdata resources) {
Formdata formdata = formdataRepository.findById(resources.getId()).orElseGet(Formdata::new);
ValidationUtil.isNull( formdata.getId(),"Formdata","id",resources.getId());
ValidationUtil.isNull(formdata.getId(), "Formdata", "id", resources.getId());
formdata.copy(resources);
formdataRepository.save(formdata);
}
@ -102,7 +146,7 @@ public class FormdataServiceImpl implements FormdataService {
public void download(List<FormdataDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (FormdataDto formdata : all) {
Map<String,Object> map = new LinkedHashMap<>();
Map<String, Object> map = new LinkedHashMap<>();
map.put("上传时间", formdata.getUploadTime());
map.put("渠道方id", formdata.getSourceId());
map.put("称呼", formdata.getName());
@ -123,28 +167,202 @@ public class FormdataServiceImpl implements FormdataService {
*/
@Override
public boolean parseFileAndSaveToDB(MultipartFile file) {
List<FormdataDto> formdataDtos = new ArrayList<>();
List<Formdata> formData;
// 1. todo 先进行解析 excel 文件
try {
InputStream inputStream = file.getInputStream();
EasyExcelListener listener = new EasyExcelListener();
EasyExcelFactory.read(inputStream, ExcelDataDTO.class, listener).sheet().doRead();
//获取到解析后的数据
formData = listener.getData();
// 2. todo 把解析后的结果进行入库
formdataRepository.saveAll(formData);
list = formdataMapper.toDto(formData);
//
// 2. todo 把解析后的结果进行入库
// 3. todo 异步发送给 下游接口
transFormDataTask.doRunTask(formdataDtos);
return false;
} catch (Exception e) {
log.error("解析失败");
e.printStackTrace();
return false;
}
return true;
}
/**
*
*
* @param file
* @return
*/
@Override
public String parseMediaFileToLocal(MultipartFile file) {
// todo 存储音频压缩文件到指定目录下 每次上传以 2021-8-5 为 文件名进行记录 每次记录一天的 并保存记录
//文件名
String fileName = file.getOriginalFilename();
//文件保存地址
String path = buildFilePath(fileName);
OutputStream os = null;
InputStream inputStream = null;
try {
//获取流
inputStream = file.getInputStream();
byte[] bs = new byte[1024];
// 读取到的数据长度
int len;
// 输出的文件流保存到本地文件
File tempFile = new File(path);
if (!tempFile.exists()) {
tempFile.mkdirs();
}
os = new FileOutputStream(tempFile.getPath() + File.separator + fileName);
// 开始读取
while ((len = inputStream.read(bs)) != -1) {
os.write(bs, 0, len);
}
} catch (Exception e) {
log.error("上传失败");
return "";
} finally {
//关闭连接
try {
assert os != null;
os.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return path;
}
/**
* oos
*
* @param file
* @return
*/
@Override
public void uploadOOS(MultipartFile file) {
String accessKeyId = "LTAI5t8agDMumxcjAVuuwqPY";
String accessKeySecret = "i93lzrZwb2BUgtB9r0y0LT2Dt7tNbP";
String bucketName = "hjrecording";
String endpoint = "oss-cn-shanghai.aliyuncs.com";
String fileName = file.getOriginalFilename();
String subFixFile = StringUtils.substringAfterLast(fileName, SPLIT_FILE_SYMBOL);
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
List<WavDTO> wavList = zipUtil(file);
for (WavDTO wavDTO : wavList) {
for (FormdataDto info : list) {
if (wavDTO.getName().equals(info.getPhone())) {
//上传oos
String newFileName = buildFileOosPath(subFixFile);
ossClient.putObject(bucketName, newFileName, wavDTO.getLine());
ossClient.shutdown();
OosDTO oosDTO = toBean(info, newFileName);
//发送下游
transFormDataTask.doRunTask(oosDTO);
}
}
}
}
private List<WavDTO> zipUtil(MultipartFile file) {
List<WavDTO> wavDTOS = new ArrayList<>();
String zipFileName = null;
try {
ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream(), Charset.forName("GBK"));
BufferedInputStream bs = new BufferedInputStream(zipInputStream);
ZipEntry zipEntry;
byte[] bytes = null;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
WavDTO wavDTO = new WavDTO();
zipFileName = zipEntry.getName();
wavDTO.setName(zipFileName.substring(0, zipFileName.lastIndexOf(".")));
bytes = new byte[(int) zipEntry.getSize()];
bs.read(bytes, 0, (int) zipEntry.getSize());
InputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
wavDTO.setLine(byteArrayInputStream);
wavDTOS.add(wavDTO);
}
} catch (Exception e) {
log.error("读取部署包文件内容失败,请确认部署包格式正确:" + zipFileName, e);
}
return wavDTOS;
}
private OosDTO toBean(FormdataDto info, String newFileName) {
OosDTO oosDTO = new OosDTO();
oosDTO.setId(info.getSourceId());
oosDTO.setAge(info.getAge());
oosDTO.setCity(info.getCity());
oosDTO.setName(info.getName());
oosDTO.setPhone(info.getPhone());
oosDTO.setProvince(info.getProvince());
oosDTO.setVoiceaddr(newFileName);
return oosDTO;
}
/**
*
*/
private String buildFilePath(String fileName) {
// 获取环境配置信息
OsInfo osInfo = SystemUtil.getOsInfo();
// 定义的时间格式
String timeFormate = DateUtil.today() ;
return "";
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,7 +135,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 所有类型的接口都放行
.antMatchers(anonymousUrls.get(RequestMethodEnum.ALL.getType()).toArray(new String[0])).permitAll()
// 所有请求都需要认证
.anyRequest().authenticated()
// .anyRequest().authenticated()
.antMatchers().permitAll()
.anyRequest().permitAll()
.and().apply(securityConfigurerAdapter());
}

@ -0,0 +1,55 @@
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;
import java.util.Map;
/**
* @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;
}
}

@ -0,0 +1,42 @@
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));
}
}

@ -0,0 +1,51 @@
package me.zhengjie.modules.uploadnew.listener;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.ObjectId;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.formdata.domain.Formdata;
import me.zhengjie.modules.uploadnew.service.dto.ExcelDataDTO;
import java.util.ArrayList;
import java.util.List;
/**
* @author wjt
* @date 2021/8/6
*/
@Slf4j
public class EasyExcelListener extends AnalysisEventListener<ExcelDataDTO> {
/**
*
*/
private List<Formdata> FormDataList = new ArrayList<>();
@Override
public void invoke(ExcelDataDTO excelDataDTO, AnalysisContext analysisContext) {
log.info("解析到一条数据:{}", JSONUtil.toJsonStr(excelDataDTO));
Formdata formdata = new Formdata();
formdata.setSourceId((int) IdUtil.getSnowflake(1, 1).nextId());
formdata.setUploadTime(DateUtil.date().toTimestamp());
formdata.setName(excelDataDTO.getName());
formdata.setAge(excelDataDTO.getAge());
formdata.setCity(excelDataDTO.getCity());
formdata.setPhone(String.valueOf(excelDataDTO.getPhone()));
formdata.setProvince(excelDataDTO.getProvince());
FormDataList.add(formdata);
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
log.info("解析完成");
}
public List<Formdata> getData() {
return FormDataList;
}
}

@ -16,6 +16,8 @@
package me.zhengjie.modules.uploadnew.rest;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@ -25,13 +27,19 @@ import me.zhengjie.annotation.Log;
import me.zhengjie.common.http.CommonResponse;
import me.zhengjie.common.http.ResponseCode;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.constant.DefaultConstant;
import me.zhengjie.modules.formdata.service.FormdataService;
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.redis.RedisParentDao;
import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService;
import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto;
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.TransFormDataTask;
import me.zhengjie.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
@ -48,6 +56,7 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -76,6 +85,9 @@ public class TbUploadFileNewController {
private RedisTemplate redisTemplate;
private FormdataService formdataService;
@Autowired
private TbUploadFileNewMapper tbUploadFileNewMapper;
@Autowired
public TbUploadFileNewController(TbUploadFileNewService tbUploadFileNewService, SaveToFileNewTask saveToFileNewTask, RedisTemplate redisTemplate, FormdataService formdataService) {
@ -150,9 +162,20 @@ public class TbUploadFileNewController {
if (null == files) {
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_FILE_INPUT), HttpStatus.OK);
}
// todo 记录文件上传记录
//记录文件上传记录
TbUploadFileNew resources = new TbUploadFileNew();
resources.setUploadTime(DateUtil.date().toTimestamp());
resources.setUploadFileTaskName(taskName);
resources.setFileCount((long) files.length);
resources.setGmtCreate(DateUtil.date().toTimestamp());
//操作人 获取当前登录人
resources.setOperation(SecurityUtils.getCurrentUser().getUsername());
TbUploadFileNewDto resourcesDto = tbUploadFileNewService.create(resources);
if (ObjectUtil.isEmpty(resourcesDto)) {
log.error("保存失败");
}
int finishTag = 0;
for (MultipartFile file : files) {
@ -160,7 +183,7 @@ public class TbUploadFileNewController {
if (StringUtils.isNotBlank(originalFilename)) {
String subOriginalFilename = StringUtils.substringAfterLast(originalFilename, SPLIT_FILE_SYMBOL);
finishTag = handleEachUploadFile(file , subOriginalFilename, finishTag);
finishTag = handleEachUploadFile(file, subOriginalFilename, finishTag, resourcesDto);
}
}
@ -172,7 +195,9 @@ public class TbUploadFileNewController {
}
// 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);
}
@ -183,23 +208,29 @@ public class TbUploadFileNewController {
* @param subOriginalFilename
* @return
*/
private int handleEachUploadFile(MultipartFile file, String subOriginalFilename, int finishTag) {
private int handleEachUploadFile(MultipartFile file, String subOriginalFilename, int finishTag, TbUploadFileNewDto resourcesDto) {
if (XLSX_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)) {
// TODO: 2021/8/5 0005 解析 入库 异步发送到下游
if (formdataService.parseFileAndSaveToDB(file)){
// TODO: 2021/8/5 0005 解析 入库
if (formdataService.parseFileAndSaveToDB(file)) {
finishTag += 1;
}
}
if (RAR_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)
|| ZIP_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)) {
// TODO: 2021/8/5 0005 以 压缩文件结尾的格式 则直接进行保存文件到指定文件夹目录下
String localSavePath = formdataService.parseMediaFileToLocal(file);
if (StringUtils.isNotBlank(localSavePath)){
// todo 记录保存位置
if (StringUtils.isNotBlank(localSavePath)) {
// todo 记录保存位置
resourcesDto.setLocalSavePath(localSavePath);
resourcesDto.setFileFormat(subOriginalFilename);
finishTag += 1;
}
// 3. todo 上传oos 并 异步发送给 下游接口
formdataService.uploadOOS(file);
}
return finishTag;
}

@ -0,0 +1,33 @@
package me.zhengjie.modules.uploadnew.service.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
/**
* @author wjt
* @date 2021/8/6
*/
@Data
public class ExcelDataDTO {
@Column(name = "name")
@ApiModelProperty(value = "称呼")
private String name;
@Column(name = "phone")
@ApiModelProperty(value = "联系方式")
private Integer phone;
@Column(name = "age")
@ApiModelProperty(value = "年龄")
private Integer age;
@Column(name = "province")
@ApiModelProperty(value = "省份")
private String province;
@Column(name = "city")
@ApiModelProperty(value = "城市")
private String city;
}

@ -0,0 +1,18 @@
package me.zhengjie.modules.uploadnew.service.dto;
import lombok.Data;
/**
* @author wjt
* @date 2021/8/6
*/
@Data
public class OosDTO {
private Integer id;
private String name;
private Integer age;
private String province;
private String city;
private String voiceaddr;
private String phone;
}

@ -0,0 +1,16 @@
package me.zhengjie.modules.uploadnew.service.dto;
import lombok.Data;
import java.io.InputStream;
/**
* @author wjt
* @date 2021/8/6
*
*/
@Data
public class WavDTO {
private String name;
private InputStream line;
}

@ -1,7 +1,10 @@
package me.zhengjie.modules.uploadnew.task;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.formdata.service.dto.FormdataDto;
import me.zhengjie.modules.uploadnew.httpRequest.HttpClient;
import me.zhengjie.modules.uploadnew.service.dto.OosDTO;
import me.zhengjie.utils.ConvertUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
@ -18,15 +21,16 @@ public class TransFormDataTask {
@Async(value = "SendBigDataTaskExecutor")
public void doRunTask(List<FormdataDto> formdataDtos) {
public void doRunTask(OosDTO oosDTO) {
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start running, task name is {} ] ======", "TransFormDataTask");
runTask(formdataDtos);
runTask(oosDTO);
Long endMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "TransFormDataTask", ConvertUtil.secondToTime(endMilliSecond - satrtMilliSecond));
}
private void runTask(List<FormdataDto> formdataDtos) {
private void runTask(OosDTO oosDTO) {
// String jsonStr = JSONUtil.toJsonStr(oosDTO);
// HttpClient.doPost(jsonStr, "utf-8");
}
}

@ -6,7 +6,7 @@ spring:
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://localhost:3306/eladmin-plat2?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: root
password: root
password: 12345678
# 初始连接数
initial-size: 5
# 最小连接数
@ -100,7 +100,7 @@ ip:
# 文件存储路径
file:
mac:
path: ~/file/
path: usr/file/
avatar: ~/avatar/
linux:
path: /home/eladmin/file/

@ -24,12 +24,12 @@ spring:
redis:
#数据库索引
database: 0
host: 127.0.0.1
port: 6379
host: 118.178.137.129
# port: 6379
password:
#连接超时时间
timeout: 5000
open: false
task:
pool:
# 核心线程池大小
@ -59,7 +59,7 @@ remote:
address: 'http://47.110.11.213:8000/api/temp/file/download'
file-base-path-linux: /home/eladmin/file/temp/
file-base-path-windows: C:\eladmin\file\temp\
file-base-path-mac: ~/file/eladmin/temp/
file-base-path-mac: /Users/wujingtao/file/eladmin/temp/
# 发送加密家口需要的一些参数
inter:
address: https://bd.hzdaba.cn:8085/v3/Accounts/yuyoukeji/BigData/EncryptTel

Loading…
Cancel
Save