Merge remote-tracking branch 'origin/dev_1'

# Conflicts:
#	eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/rest/TbUploadFileNewController.java
master
bynt 3 years ago
commit d42752793f

@ -22,6 +22,9 @@ public enum ResponseCode {
EMPTY_ARGUMENT(1,"请求参数为空"),
NO_MATCH_ARGUMENT_SET(1,"不能满足要求的参数设置"),
NO_FILE_INPUT(1,"没有文件输入"),
/** modeify by wzx
*/
NO_WORD_INPUT(1,"短信和url链接不能为空"),
NO_FILE_FORMAT(1,"文件格式不对"),
// 特殊需要进行前端返回说明的参数定义

@ -24,6 +24,7 @@ import me.zhengjie.common.http.ResponseCode;
import me.zhengjie.modules.sms.domain.TbTemplate;
import me.zhengjie.modules.sms.service.TbTemplateService;
import me.zhengjie.modules.sms.service.dto.TbTemplateQueryCriteria;
import me.zhengjie.modules.sms.vo.SendNewVo;
import me.zhengjie.modules.sms.vo.SendVo;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
@ -35,6 +36,7 @@ import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
@ -105,16 +107,18 @@ public class TbTemplateController {
// @PreAuthorize("@el.check('taskRecord:list')")
@PostMapping(value = "/getSmsInfo")
@AnonymousAccess // fixme 需要测试完成后进行去除和使用上面的权限注解
public ResponseEntity<Object> getSmsInfo(@RequestBody SendVo sendVo){
public ResponseEntity<Object> getSmsInfo(@RequestBody SendNewVo sendVo){
log.info("========== [TbTemplateController|getSmsInfo ========== SmsContent"+sendVo.getSmsContent()+" LinkUrl:"+sendVo.getLinkUrl());
if (sendVo == null){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.EMPTY_ARGUMENT), HttpStatus.OK);
}
if (sendVo.getSmsContent() != null && sendVo.getLinkUrl() != null){
TbTemplate tbTemplate = new TbTemplate();
tbTemplate.setLinkUrl(sendVo.getLinkUrl());
tbTemplate.setTaskName(sendVo.getTaskName());
tbTemplate.setSendMessage(sendVo.getSmsContent());
tbTemplate.setReviewer(sendVo.getOperator());
Date date = new Date();
Timestamp nousedate = new Timestamp(date.getTime());
Timestamp nousedate = new Timestamp(System.currentTimeMillis());
tbTemplate.setLastUpdateTime(nousedate);
tbTemplate.setGmtModified(nousedate);
tbTemplate.setGmtCreate(nousedate);

@ -0,0 +1,19 @@
package me.zhengjie.modules.sms.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class SendNewVo {
@ApiModelProperty("发送链接")
private String linkUrl;
@ApiModelProperty("短信内容")
private String smsContent;
@ApiModelProperty("任务名称")
private String taskName;
@ApiModelProperty("审核人")
private String operator;
}

@ -30,7 +30,7 @@ public class SysConst {
public static final String REMOTE_TRANS_DIR_PATH = "/home/";
// fixme 以后改成rpc调用的地址
public static final String REMOTE_UPDATE_ADDR = "http://116.62.197.152:8001/api/remoteRecord/remote/rec";
public static final String REMOTE_UPDATE_ADDR = "http://116.62.197.152:8000/api/remoteRecord/remote/rec";
// 测试内容临时定义
public static final String TEST_USER_NAME = "测试用户";

@ -16,42 +16,45 @@
package me.zhengjie.modules.uploadnew.rest;
import cn.hutool.core.collection.CollectionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.annotation.AnonymousAccess;
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.security.security.TokenFilter;
import me.zhengjie.modules.upload.service.dto.UploadFileDto;
import me.zhengjie.modules.upload.service.dto.UploadFileQueryCriteria;
import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew;
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.task.SaveToFileNewTask;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import org.springframework.web.multipart.MultipartFile;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import static me.zhengjie.modules.upload.consts.UploadFileConst.FILE_PATH_SPLIT;
//import org.springframework.util.StringUtils;
/**
* @website https://el-admin.vip
* @author weizhongxi
@ -124,43 +127,38 @@ public class TbUploadFileNewController {
@AnonymousAccess
@PostMapping("/fileUpload")
// @ResponseBody
public ResponseEntity<Object> fileUpload(@RequestParam("file") MultipartFile file,
@RequestParam(value = "taskName") String taskName,
@RequestParam(value = "isEcryptionNew") String isEcryptionNew,
ServletRequest servletRequest) {
public ResponseEntity<Object> fileUpload(@RequestParam("file") MultipartFile file, @RequestParam(value = "taskName") String taskName, @RequestParam(value = "isEcryptionNew") String isEcryptionNew, ServletRequest servletRequest) {
// 记录日志
log.info("TbUploadFileNewController:fileUpload | taskName="+taskName+"===== isEcryptionNew="+isEcryptionNew);
// FIXME: 2021/4/23 0023
Integer isEcryption = Integer.parseInt(isEcryptionNew);
// FIXME: 2021/4/23 0023
String name=file.getOriginalFilename();
String keyName = "";
String token = "";
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
Cookie[] cookies = httpServletRequest.getCookies();
if (cookies != null){
for(Cookie cookie : cookies) {
//获取cookie的名字
String cookieName = cookie.getName();
token=cookie.getValue();
// FIXME: 2021/4/23 0023
// System.out.println(cookieName);
// System.out.println(cookieName+" : "+ cookie.getValue() );
System.out.println(cookieName);
System.out.println(cookieName+" : "+ cookie.getValue() );
}
}
// FIXME: 2021/4/23 0023 ===
keyName = token+"==="+name;
Object keyValue = redisTemplate.opsForValue().get(keyName);
//防止用户多次提交
if (keyValue != null){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_STAETING), HttpStatus.OK);
}
redisTemplate.opsForValue().set(keyName, "value11");
int lastIndexOf = name.lastIndexOf(".");
// 校验文件格式
String nameStr = name.substring(lastIndexOf);
// 校验文件格式
if (!((nameStr.equals(".xlsx")||nameStr.equals(".xls")) || nameStr.equals(".txt") ||nameStr.equals(".csv"))){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_FILE_FORMAT), HttpStatus.OK);
}

@ -176,7 +176,8 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
// FIXME: 2021/4/23 0023
if(nameStr.equals(".xlsx")||nameStr.equals(".xls")){
fileFormat = "excel文件";
list = FileUtil.readLines(eachFilePath, "UTF-8");
ExcelUtils excelUtils = new ExcelUtils();
list = excelUtils.excelParseList(file.getInputStream());
}else if (nameStr.equals(".txt")){
fileFormat = "txt文件";

@ -15,6 +15,7 @@ import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists;
import com.jcraft.jsch.Session;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.upload.domain.UploadFile;
import me.zhengjie.modules.upload.service.dto.UploadFileDto;
import me.zhengjie.modules.upload.task.model.ResponseEncryptJsonContent;
@ -147,18 +148,19 @@ public class SaveToFileNewTask {
List<String> list = null;
try {
if("excel文件".equals(tbUploadFileNewDto.getFileFormat())){
list = ExcelUtils.excelParseListByUrl(filePath);
ExcelUtils excelUtils = new ExcelUtils();
list = excelUtils.excelParseListByUrl(filePath);
}else if ("txt文件".equals(tbUploadFileNewDto.getFileFormat())){
list = TxtUtils.txtParseListVyUrl(filePath);
}else if ("csv文件".equals(tbUploadFileNewDto.getFileFormat())){
list = TxtUtils.csvParseListByUrl(filePath);
}
}catch (Exception e){
e.printStackTrace();
log.error("SaveToFileTask|batchSendToEncrypt ready send json is : {}", "");
throw new BadRequestException("解析文件异常");
}
if (CollectionUtil.isNotEmpty(list)){
batchSendToEncrypt(filePath, list);
}
// 加入一个全局控制开关
@ -222,6 +224,7 @@ public class SaveToFileNewTask {
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());
}

@ -22,7 +22,7 @@ public class ExcelUtils {
* @return
* @throws IOException
*/
public static List<String> excelParseList(InputStream inputStream) throws IOException {
public List<String> excelParseList(InputStream inputStream) throws IOException {
List<String> list = new ArrayList<>();
try {
Workbook workbook = new XSSFWorkbook(inputStream);
@ -58,7 +58,7 @@ public class ExcelUtils {
* @return
* @throws IOException
*/
public static List<String> excelParseListByUrl(String url) throws IOException {
public List<String> excelParseListByUrl(String url) throws IOException {
List<String> list = new ArrayList<>();
InputStream inputStream = new FileInputStream(new File(url)) ;
try {

Loading…
Cancel
Save