|
|
|
@ -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.uploadnew.rest;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
@ -56,10 +56,10 @@ import static me.zhengjie.modules.uploadnew.consts.SysConstNew.*;
|
|
|
|
|
//import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @website https://el-admin.vip
|
|
|
|
|
* @author weizhongxi
|
|
|
|
|
* @date 2021-04-14
|
|
|
|
|
**/
|
|
|
|
|
* @author weizhongxi
|
|
|
|
|
* @website https://el-admin.vip
|
|
|
|
|
* @date 2021-04-14
|
|
|
|
|
**/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Api(tags = "文件上传接口管理")
|
|
|
|
@ -87,23 +87,23 @@ public class TbUploadFileNewController {
|
|
|
|
|
@Log("查询文件上传接口")
|
|
|
|
|
@ApiOperation("查询文件上传接口")
|
|
|
|
|
@PreAuthorize("@el.check('tbUploadFileNew:list')")
|
|
|
|
|
public ResponseEntity<Object> query(TbUploadFileNewQueryCriteria criteria, Pageable pageable){
|
|
|
|
|
return new ResponseEntity<>(tbUploadFileNewService.queryAll(criteria,pageable),HttpStatus.OK);
|
|
|
|
|
public ResponseEntity<Object> query(TbUploadFileNewQueryCriteria criteria, Pageable pageable) {
|
|
|
|
|
return new ResponseEntity<>(tbUploadFileNewService.queryAll(criteria, pageable), HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping
|
|
|
|
|
@Log("新增文件上传接口")
|
|
|
|
|
@ApiOperation("新增文件上传接口")
|
|
|
|
|
@PreAuthorize("@el.check('tbUploadFileNew:add')")
|
|
|
|
|
public ResponseEntity<Object> create(@Validated @RequestBody TbUploadFileNew resources){
|
|
|
|
|
return new ResponseEntity<>(tbUploadFileNewService.create(resources),HttpStatus.CREATED);
|
|
|
|
|
public ResponseEntity<Object> create(@Validated @RequestBody TbUploadFileNew resources) {
|
|
|
|
|
return new ResponseEntity<>(tbUploadFileNewService.create(resources), HttpStatus.CREATED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping
|
|
|
|
|
@Log("修改文件上传接口")
|
|
|
|
|
@ApiOperation("修改文件上传接口")
|
|
|
|
|
@PreAuthorize("@el.check('tbUploadFileNew:edit')")
|
|
|
|
|
public ResponseEntity<Object> update(@Validated @RequestBody TbUploadFileNew resources){
|
|
|
|
|
public ResponseEntity<Object> update(@Validated @RequestBody TbUploadFileNew resources) {
|
|
|
|
|
tbUploadFileNewService.update(resources);
|
|
|
|
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|
|
|
|
}
|
|
|
|
@ -133,67 +133,68 @@ public class TbUploadFileNewController {
|
|
|
|
|
@RequestParam(value = "isEcryptionNew") String isEcryptionNew,
|
|
|
|
|
ServletRequest servletRequest) {
|
|
|
|
|
// 记录日志
|
|
|
|
|
log.info("TbUploadFileNewController:fileUpload | taskName="+taskName+"===== isEcryptionNew="+isEcryptionNew);
|
|
|
|
|
log.info("TbUploadFileNewController:fileUpload | taskName=" + taskName + "===== isEcryptionNew=" + isEcryptionNew);
|
|
|
|
|
// 校验上传是否有文件
|
|
|
|
|
if (file== null ){
|
|
|
|
|
if (null == file) {
|
|
|
|
|
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_FILE_INPUT), HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
Integer isEcryption = 0;
|
|
|
|
|
|
|
|
|
|
int isEcryption = 1;
|
|
|
|
|
try {
|
|
|
|
|
isEcryption = Integer.parseInt(isEcryptionNew);
|
|
|
|
|
isEcryption = Integer.parseInt(isEcryptionNew);
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
log.error("TbUploadFileNewController|fileUpload 转换异常!!!!");
|
|
|
|
|
throw new BadRequestException("转换异常!!!");
|
|
|
|
|
}
|
|
|
|
|
String name=file.getOriginalFilename();
|
|
|
|
|
|
|
|
|
|
String name = file.getOriginalFilename();
|
|
|
|
|
String keyName = "";
|
|
|
|
|
String token = "";
|
|
|
|
|
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
|
|
|
|
|
Cookie[] cookies = httpServletRequest.getCookies();
|
|
|
|
|
if (cookies != null){
|
|
|
|
|
for(Cookie cookie : cookies) {
|
|
|
|
|
if (cookies != null) {
|
|
|
|
|
for (Cookie cookie : cookies) {
|
|
|
|
|
//获取cookie的名字
|
|
|
|
|
token=cookie.getValue();
|
|
|
|
|
log.info("TbUploadFileNewController:fileUpload | token="+token);
|
|
|
|
|
token = cookie.getValue();
|
|
|
|
|
log.info("TbUploadFileNewController:fileUpload | token: {} ", token);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RedisParentDao redisParentDao = new RedisParentDao();
|
|
|
|
|
redisParentDao.setRedisTemplate(redisTemplate);
|
|
|
|
|
keyName = token+TOKEN_NAME+name;
|
|
|
|
|
String keyValue = redisParentDao.getValue(keyName);
|
|
|
|
|
String keyValue = redisParentDao.getValue(token + TOKEN_NAME + name);
|
|
|
|
|
//防止用户多次提交
|
|
|
|
|
if (keyValue != null){
|
|
|
|
|
if (keyValue != null) {
|
|
|
|
|
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_STAETING), HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redisParentDao.cacheValue(keyName, TOKEN_VALUE, EXP_TIME);
|
|
|
|
|
int lastIndexOf = name.lastIndexOf(".");
|
|
|
|
|
// 校验文件格式
|
|
|
|
|
// 校验文件格式
|
|
|
|
|
String nameStr = name.substring(lastIndexOf);
|
|
|
|
|
if (!((nameStr.equals(".xlsx")||nameStr.equals(".xls")) || nameStr.equals(".txt") ||nameStr.equals(".csv"))){
|
|
|
|
|
if (!((nameStr.equals(".xlsx") || nameStr.equals(".xls")) || nameStr.equals(".txt") || nameStr.equals(".csv"))) {
|
|
|
|
|
redisParentDao.remove(keyName);
|
|
|
|
|
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_FILE_FORMAT), HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
// 任务名称检验,为必填参数,且不能重复
|
|
|
|
|
if (StringUtils.isNotBlank(taskName)){
|
|
|
|
|
if (StringUtils.isNotBlank(taskName)) {
|
|
|
|
|
// modify by x bug fix on POSTMAN request
|
|
|
|
|
if (StringUtils.contains(taskName, FILE_PATH_SPLIT)){
|
|
|
|
|
taskName = taskName.substring(0, taskName.length()-1);
|
|
|
|
|
if (StringUtils.contains(taskName, FILE_PATH_SPLIT)) {
|
|
|
|
|
taskName = taskName.substring(0, taskName.length() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TbUploadFileNewQueryCriteria criteria = new TbUploadFileNewQueryCriteria();
|
|
|
|
|
criteria.setUploadFileTaskName(taskName);
|
|
|
|
|
List<TbUploadFileNewDto> uploadFileDtos = tbUploadFileNewService.queryAll(criteria);
|
|
|
|
|
if (CollectionUtil.isNotEmpty(uploadFileDtos)){
|
|
|
|
|
if (CollectionUtil.isNotEmpty(uploadFileDtos)) {
|
|
|
|
|
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_NAME_IS_EXIST), HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.EMPTY_ARGUMENT), HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
// 生成本地文件
|
|
|
|
|
TbUploadFileNewDto tbUploadFileNewDto = tbUploadFileNewService.encryptDataAndSaveToFileNew(file, taskName, isEcryption);
|
|
|
|
|
// 如果临时生成失败就修改状态为失败
|
|
|
|
|
if (Objects.isNull(tbUploadFileNewDto)){
|
|
|
|
|
if (Objects.isNull(tbUploadFileNewDto)) {
|
|
|
|
|
log.error("TbUploadFileNewController:fileUpload | Operation Fail.tbUploadFileNewDto is Null");
|
|
|
|
|
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_FILE_SAVE_FAIL), HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
@ -202,12 +203,13 @@ public class TbUploadFileNewController {
|
|
|
|
|
redisParentDao.remove(keyName);
|
|
|
|
|
return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Log("上传并加密任务")
|
|
|
|
|
@ApiOperation("上传并加密任务")
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("/aa")
|
|
|
|
|
// @ResponseBody
|
|
|
|
|
public ResponseEntity<Object> aa(){
|
|
|
|
|
public ResponseEntity<Object> aa() {
|
|
|
|
|
RedisParentDao redisParentDao = new RedisParentDao();
|
|
|
|
|
redisParentDao.setRedisTemplate(redisTemplate);
|
|
|
|
|
redisParentDao.cacheValue("111", "2222", 180000);
|
|
|
|
|