[新增功能](master): 新增加表单分发功能需求

新增加表单分发功能需求骨架
master
土豆兄弟 3 years ago
parent e3be3f41b5
commit 6060c73073

@ -28,6 +28,10 @@ public enum ResponseCode {
NO_MATCH_ARGUMENT_SET(1,"不能满足要求的参数设置"), NO_MATCH_ARGUMENT_SET(1,"不能满足要求的参数设置"),
/**没有文件输入*/ /**没有文件输入*/
NO_FILE_INPUT(1,"没有文件输入"), NO_FILE_INPUT(1,"没有文件输入"),
/**
*
*/
FILE_HANDLE_FAIL(1, "文件处理失败"),
/** modeify by wzx /** modeify by wzx
*/ */

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
@Generated( @Generated(
value = "org.mapstruct.ap.MappingProcessor", value = "org.mapstruct.ap.MappingProcessor",
date = "2021-04-24T00:12:04+0800", date = "2021-08-05T14:00:16+0800",
comments = "version: 1.3.1.Final, compiler: javac, environment: Java 1.8.0_261 (Oracle Corporation)" comments = "version: 1.3.1.Final, compiler: javac, environment: Java 1.8.0_261 (Oracle Corporation)"
) )
@Component @Component

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
@Generated( @Generated(
value = "org.mapstruct.ap.MappingProcessor", value = "org.mapstruct.ap.MappingProcessor",
date = "2021-04-24T00:12:04+0800", date = "2021-08-05T14:00:16+0800",
comments = "version: 1.3.1.Final, compiler: javac, environment: Java 1.8.0_261 (Oracle Corporation)" comments = "version: 1.3.1.Final, compiler: javac, environment: Java 1.8.0_261 (Oracle Corporation)"
) )
@Component @Component

@ -0,0 +1,29 @@
package me.zhengjie.modules.constant;
/**
*
*/
public class FileConstant {
/**
* .
*/
public static final String SPLIT_FILE_SYMBOL = ".";
/**
* xlsx
*/
public static final String XLSX_FILE_SUB_NAME = "xlsx";
/**
* zip
*/
public static final String ZIP_FILE_SUB_NAME = "zip";
/**
* rar
*/
public static final String RAR_FILE_SUB_NAME = "rar";
}

@ -0,0 +1,75 @@
/*
* 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.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @website https://el-admin.vip
* @description /
* @author x
* @date 2021-08-05
**/
@Entity
@Data
@Table(name="t_formdata")
public class Formdata implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@ApiModelProperty(value = "主键")
private Long id;
@Column(name = "upload_time")
@ApiModelProperty(value = "上传时间")
private Timestamp uploadTime;
@Column(name = "source_id")
@ApiModelProperty(value = "渠道方id")
private Integer sourceId;
@Column(name = "name")
@ApiModelProperty(value = "称呼")
private String name;
@Column(name = "phone")
@ApiModelProperty(value = "联系方式")
private String 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;
public void copy(Formdata source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

@ -0,0 +1,28 @@
/*
* 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.repository;
import me.zhengjie.modules.formdata.domain.Formdata;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @website https://el-admin.vip
* @author x
* @date 2021-08-05
**/
public interface FormdataRepository extends JpaRepository<Formdata, Long>, JpaSpecificationExecutor<Formdata> {
}

@ -0,0 +1,89 @@
/*
* 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.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.formdata.domain.Formdata;
import me.zhengjie.modules.formdata.service.FormdataService;
import me.zhengjie.modules.formdata.service.dto.FormdataQueryCriteria;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @website https://el-admin.vip
* @author x
* @date 2021-08-05
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "表单文件解析接口管理")
@RequestMapping("/api/formdata")
public class FormdataController {
private final FormdataService formdataService;
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('formdata:list')")
public void download(HttpServletResponse response, FormdataQueryCriteria criteria) throws IOException {
formdataService.download(formdataService.queryAll(criteria), response);
}
@GetMapping
@Log("查询表单文件解析接口")
@ApiOperation("查询表单文件解析接口")
@PreAuthorize("@el.check('formdata:list')")
public ResponseEntity<Object> query(FormdataQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(formdataService.queryAll(criteria,pageable),HttpStatus.OK);
}
@PostMapping
@Log("新增表单文件解析接口")
@ApiOperation("新增表单文件解析接口")
@PreAuthorize("@el.check('formdata:add')")
public ResponseEntity<Object> create(@Validated @RequestBody Formdata resources){
return new ResponseEntity<>(formdataService.create(resources),HttpStatus.CREATED);
}
@PutMapping
@Log("修改表单文件解析接口")
@ApiOperation("修改表单文件解析接口")
@PreAuthorize("@el.check('formdata:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody Formdata resources){
formdataService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除表单文件解析接口")
@ApiOperation("删除表单文件解析接口")
@PreAuthorize("@el.check('formdata:del')")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
formdataService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

@ -0,0 +1,101 @@
/*
* 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;
import me.zhengjie.modules.formdata.service.dto.FormdataDto;
import me.zhengjie.modules.formdata.service.dto.FormdataQueryCriteria;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* @website https://el-admin.vip
* @description
* @author x
* @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
* @return List<FormdataDto>
*/
List<FormdataDto> queryAll(FormdataQueryCriteria criteria);
/**
* ID
* @param id ID
* @return FormdataDto
*/
FormdataDto findById(Long id);
/**
*
* @param resources /
* @return FormdataDto
*/
FormdataDto create(Formdata resources);
/**
*
* @param resources /
*/
void update(Formdata resources);
/**
*
* @param ids /
*/
void deleteAll(Long[] ids);
/**
*
* @param all
* @param response /
* @throws IOException /
*/
void download(List<FormdataDto> all, HttpServletResponse response) throws IOException;
/**
*
*
* @param file
* @return
*/
boolean parseFileAndSaveToDB(MultipartFile file);
/**
*
*
* @param file
* @return
*/
String parseMediaFileToLocal(MultipartFile file);
}

@ -0,0 +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.
*/
package me.zhengjie.modules.formdata.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://el-admin.vip
* @description /
* @author x
* @date 2021-08-05
**/
@Data
public class FormdataDto implements Serializable {
/** 主键 */
private Long id;
/** 上传时间 */
private Timestamp uploadTime;
/** 渠道方id */
private Integer sourceId;
/** 称呼 */
private String name;
/** 联系方式 */
private String phone;
/** 年龄 */
private Integer age;
/** 省份 */
private String province;
/** 城市 */
private String city;
}

@ -0,0 +1,50 @@
/*
* 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.dto;
import lombok.Data;
import me.zhengjie.annotation.Query;
import java.sql.Timestamp;
import java.util.List;
/**
* @website https://el-admin.vip
* @author x
* @date 2021-08-05
**/
@Data
public class FormdataQueryCriteria{
/** 精确 */
@Query
private Timestamp uploadTime;
/** 精确 */
@Query
private String phone;
/** 精确 */
@Query
private String province;
/** 精确 */
@Query
private String city;
/** BETWEEN */
@Query(type = Query.Type.BETWEEN)
private List<Integer> age;
}

@ -0,0 +1,150 @@
/*
* 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 lombok.RequiredArgsConstructor;
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.task.TransFormDataTask;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
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;
/**
* @website https://el-admin.vip
* @description
* @author x
* @date 2021-08-05
**/
@Service
@RequiredArgsConstructor
public class FormdataServiceImpl implements FormdataService {
private final FormdataRepository formdataRepository;
private final FormdataMapper formdataMapper;
@Autowired
private TransFormDataTask transFormDataTask;
@Override
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)));
}
@Override
@Transactional
public FormdataDto findById(Long id) {
Formdata formdata = formdataRepository.findById(id).orElseGet(Formdata::new);
ValidationUtil.isNull(formdata.getId(),"Formdata","id",id);
return formdataMapper.toDto(formdata);
}
@Override
@Transactional(rollbackFor = Exception.class)
public FormdataDto create(Formdata resources) {
return formdataMapper.toDto(formdataRepository.save(resources));
}
@Override
@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());
formdata.copy(resources);
formdataRepository.save(formdata);
}
@Override
public void deleteAll(Long[] ids) {
for (Long id : ids) {
formdataRepository.deleteById(id);
}
}
@Override
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.put("上传时间", formdata.getUploadTime());
map.put("渠道方id", formdata.getSourceId());
map.put("称呼", formdata.getName());
map.put("联系方式", formdata.getPhone());
map.put("年龄", formdata.getAge());
map.put("省份", formdata.getProvince());
map.put("城市", formdata.getCity());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
/**
*
*
* @param file
* @return
*/
@Override
public boolean parseFileAndSaveToDB(MultipartFile file) {
List<FormdataDto> formdataDtos = new ArrayList<>();
// 1. todo 先进行解析 excel 文件
// 2. todo 把解析后的结果进行入库
// 3. todo 异步发送给 下游接口
transFormDataTask.doRunTask(formdataDtos);
return false;
}
/**
*
* @param file
* @return
*/
@Override
public String parseMediaFileToLocal(MultipartFile file) {
// todo 存储音频压缩文件到指定目录下 每次上传以 2021-8-5 为 文件名进行记录 每次记录一天的 并保存记录
return "";
}
}

@ -0,0 +1,32 @@
/*
* 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.mapstruct;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.formdata.domain.Formdata;
import me.zhengjie.modules.formdata.service.dto.FormdataDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @website https://el-admin.vip
* @author x
* @date 2021-08-05
**/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface FormdataMapper extends BaseMapper<FormdataDto, Formdata> {
}

@ -15,27 +15,26 @@
*/ */
package me.zhengjie.modules.upload.domain; package me.zhengjie.modules.upload.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import javax.validation.constraints.*;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.io.Serializable;
/** /**
* @website https://el-admin.vip * @website https://el-admin.vip
* @description / * @description /
* @author x * @author x
* @date 2021-01-03 * @date 2021-08-05
**/ **/
@Entity @Entity
@Data @Data
@Table(name="tb_upload_file") @Table(name="tb_upload_file")
public class UploadFile implements Serializable { public class UploadFile implements Serializable {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
@ -46,16 +45,9 @@ public class UploadFile implements Serializable {
@ApiModelProperty(value = "上传日期") @ApiModelProperty(value = "上传日期")
private Timestamp uploadTime; private Timestamp uploadTime;
/** @Column(name = "opration")
* ps,
*/
@Column(name = "upload_file_task_name")
@ApiModelProperty(value = "上传任务名称")
private String uploadFileTaskName;
@Column(name = "operation")
@ApiModelProperty(value = "操作人") @ApiModelProperty(value = "操作人")
private String operation; private String opration;
@Column(name = "file_count") @Column(name = "file_count")
@ApiModelProperty(value = "文件解析总数") @ApiModelProperty(value = "文件解析总数")
@ -69,10 +61,6 @@ public class UploadFile implements Serializable {
@ApiModelProperty(value = "上传状态") @ApiModelProperty(value = "上传状态")
private Integer uploadTag; private Integer uploadTag;
@Column(name = "local_save_path")
@ApiModelProperty(value = "文件上传保存路径")
private String localSavePath;
public void copy(UploadFile source){ public void copy(UploadFile source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
} }

@ -22,7 +22,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/** /**
* @website https://el-admin.vip * @website https://el-admin.vip
* @author x * @author x
* @date 2021-01-03 * @date 2021-08-05
**/ **/
public interface UploadFileRepository extends JpaRepository<UploadFile, Long>, JpaSpecificationExecutor<UploadFile> { public interface UploadFileRepository extends JpaRepository<UploadFile, Long>, JpaSpecificationExecutor<UploadFile> {
} }

@ -15,79 +15,34 @@
*/ */
package me.zhengjie.modules.upload.rest; package me.zhengjie.modules.upload.rest;
import cn.hutool.core.collection.CollectionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log; 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.upload.consts.SysConst;
import me.zhengjie.modules.upload.domain.UploadFile; import me.zhengjie.modules.upload.domain.UploadFile;
import me.zhengjie.modules.upload.service.UploadFileService; import me.zhengjie.modules.upload.service.UploadFileService;
import me.zhengjie.modules.upload.service.dto.UploadFileDto;
import me.zhengjie.modules.upload.service.dto.UploadFileQueryCriteria; import me.zhengjie.modules.upload.service.dto.UploadFileQueryCriteria;
import me.zhengjie.modules.upload.task.SaveToFileTask;
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.task.SaveToFileNewTask;
import me.zhengjie.utils.SecurityUtils;
import me.zhengjie.utils.StringUtils;
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 lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import io.swagger.annotations.*;
import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import javax.servlet.http.HttpServletResponse;
import java.util.Objects;
import static me.zhengjie.modules.upload.consts.UploadFileConst.FILE_PATH_SPLIT;
import static me.zhengjie.modules.upload.consts.UploadFileConst.WHITE_LIST;
import static me.zhengjie.modules.uploadnew.consts.SysConstNew.*;
/** /**
* @website https://el-admin.vip * @website https://el-admin.vip
* @author x * @author x
* @date 2021-01-03 * @date 2021-08-05
**/ **/
//@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
@Controller
@Api(tags = "上传文件解析发送管理") @Api(tags = "上传文件解析发送管理")
@RequestMapping("/api/uploadFile") @RequestMapping("/api/uploadFile")
@Slf4j
public class UploadFileController { public class UploadFileController {
private final UploadFileService uploadFileService; private final UploadFileService uploadFileService;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private SaveToFileNewTask saveToFileNewTask;
@Autowired
private TbUploadFileNewService tbUploadFileNewService;
@Autowired
private SaveToFileTask saveToFileTask;
@Log("导出数据") @Log("导出数据")
@ApiOperation("导出数据") @ApiOperation("导出数据")
@GetMapping(value = "/download") @GetMapping(value = "/download")
@ -101,28 +56,9 @@ public class UploadFileController {
@ApiOperation("查询上传文件解析发送") @ApiOperation("查询上传文件解析发送")
@PreAuthorize("@el.check('uploadFile:list')") @PreAuthorize("@el.check('uploadFile:list')")
public ResponseEntity<Object> query(UploadFileQueryCriteria criteria, Pageable pageable){ public ResponseEntity<Object> query(UploadFileQueryCriteria criteria, Pageable pageable){
filterOfWriteList(criteria);
log.info("======= [ criteria is {} ] =======", criteria.toString());
return new ResponseEntity<>(uploadFileService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(uploadFileService.queryAll(criteria,pageable),HttpStatus.OK);
} }
/**
* ,,
*
* @param criteria
*
* @return
*/
private void filterOfWriteList(UploadFileQueryCriteria criteria) {
if (!SysConst.sysDebug){
if (!CollectionUtil.contains(WHITE_LIST, SecurityUtils.getCurrentUsername())){
criteria.setOperation(SecurityUtils.getCurrentUsername());
log.info("======= [UploadFileServiceImpl|filterOfWriteList, userName is {} ] =======", SecurityUtils.getCurrentUsername());
}
}
}
@PostMapping @PostMapping
@Log("新增上传文件解析发送") @Log("新增上传文件解析发送")
@ApiOperation("新增上传文件解析发送") @ApiOperation("新增上传文件解析发送")
@ -148,139 +84,4 @@ public class UploadFileController {
uploadFileService.deleteAll(ids); uploadFileService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
// ==== 去重开发 =====
@Log("上传并加密任务")
@ApiOperation("上传并加密任务")
@PostMapping(value = "/sendTask")
@PreAuthorize("@el.check('uploadFile:list')")
// @AnonymousAccess // fixme 需要测试完成后进行去除和使用上面的权限注解
public ResponseEntity<Object> sendTask(@RequestParam(value = "files", required = false) MultipartFile[] files, @RequestParam(value = "taskName") String 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);
}
UploadFileQueryCriteria criteria = new UploadFileQueryCriteria();
criteria.setUploadFileTaskName(taskName);
List<UploadFileDto> uploadFileDtos = uploadFileService.queryAll(criteria);
if (CollectionUtil.isNotEmpty(uploadFileDtos)){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_NAME_IS_EXIST), HttpStatus.OK);
}
}else {
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.EMPTY_ARGUMENT), HttpStatus.OK);
}
// 校验上传是否有文件
if (files!= null && files.length<= 0){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_FILE_INPUT), HttpStatus.OK);
}
// 生成本地文件
UploadFileDto uploadFileDto = uploadFileService.encryptDataAndSaveToFile(files, taskName);
// 如果临时生成失败就修改状态为失败
if (Objects.isNull(uploadFileDto)){
log.error("UploadFileController:sendTask | Operation Fail.UploadFile is Null");
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_FILE_SAVE_FAIL), HttpStatus.OK);
}
// 调用异步任务
saveToFileTask.doRunTask(uploadFileDto);
return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK);
}
/**
*
*
* @return
*/
@Log("上传并加密任务")
@ApiOperation("上传并加密任务")
@AnonymousAccess
@PostMapping("/fileUpload")
@PreAuthorize("@el.check('uploadFile:list')")
// @ResponseBody
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);
// 校验上传是否有文件
if (file== null ){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_FILE_INPUT), HttpStatus.OK);
}
Integer isEcryption = 1;
if (StringUtils.isNotBlank(isEcryptionNew)){
try {
isEcryption = Integer.parseInt(isEcryptionNew);
} catch (NumberFormatException e) {
log.error("TbUploadFileNewController|fileUpload 转换异常!!!!");
throw new BadRequestException("转换异常!!!");
}
}
String name=file.getOriginalFilename();
String keyName = "";
String token = "";
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
Cookie[] cookies = httpServletRequest.getCookies();
if (cookies != null){
for(Cookie cookie : cookies) {
//获取cookie的名字
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);
//防止用户多次提交
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"))){
redisParentDao.remove(keyName);
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_FILE_FORMAT), HttpStatus.OK);
}
// 任务名称检验,为必填参数,且不能重复
if (org.apache.commons.lang3.StringUtils.isNotBlank(taskName)){
// modify by x bug fix on POSTMAN request
if (org.apache.commons.lang3.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)){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_NAME_IS_EXIST), HttpStatus.OK);
}
}else {
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.EMPTY_ARGUMENT), HttpStatus.OK);
}
// 生成本地文件
TbUploadFileNewDto tbUploadFileNewDto = tbUploadFileNewService.encryptDataAndSaveToFileNew(file, taskName, isEcryption);
// 如果临时生成失败就修改状态为失败
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);
}
// 调用异步任务
saveToFileNewTask.doRunTask(tbUploadFileNewDto);
redisParentDao.remove(keyName);
return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK);
}
} }

@ -19,18 +19,16 @@ import me.zhengjie.modules.upload.domain.UploadFile;
import me.zhengjie.modules.upload.service.dto.UploadFileDto; import me.zhengjie.modules.upload.service.dto.UploadFileDto;
import me.zhengjie.modules.upload.service.dto.UploadFileQueryCriteria; import me.zhengjie.modules.upload.service.dto.UploadFileQueryCriteria;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/** /**
* @website https://el-admin.vip * @website https://el-admin.vip
* @description * @description
* @author x * @author x
* @date 2021-01-03 * @date 2021-08-05
**/ **/
public interface UploadFileService { public interface UploadFileService {
@ -82,11 +80,4 @@ public interface UploadFileService {
* @throws IOException / * @throws IOException /
*/ */
void download(List<UploadFileDto> all, HttpServletResponse response) throws IOException; void download(List<UploadFileDto> all, HttpServletResponse response) throws IOException;
/**
*
*
* @param files
*/
UploadFileDto encryptDataAndSaveToFile(MultipartFile[] files, String taskName);
} }

@ -16,15 +16,14 @@
package me.zhengjie.modules.upload.service.dto; package me.zhengjie.modules.upload.service.dto;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.io.Serializable;
/** /**
* @website https://el-admin.vip * @website https://el-admin.vip
* @description / * @description /
* @author x * @author x
* @date 2021-01-03 * @date 2021-08-05
**/ **/
@Data @Data
public class UploadFileDto implements Serializable { public class UploadFileDto implements Serializable {
@ -36,7 +35,7 @@ public class UploadFileDto implements Serializable {
private Timestamp uploadTime; private Timestamp uploadTime;
/** 操作人 */ /** 操作人 */
private String operation; private String opration;
/** 文件解析总数 */ /** 文件解析总数 */
private Long fileCount; private Long fileCount;
@ -46,10 +45,4 @@ public class UploadFileDto implements Serializable {
/** 上传状态 */ /** 上传状态 */
private Integer uploadTag; private Integer uploadTag;
/** 上传保存路径 */
private String localSavePath;
/** 上传的文件名称 **/
private String uploadFileTaskName;
} }

@ -16,35 +16,29 @@
package me.zhengjie.modules.upload.service.dto; package me.zhengjie.modules.upload.service.dto;
import lombok.Data; import lombok.Data;
import me.zhengjie.annotation.Query;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.List; import java.util.List;
import me.zhengjie.annotation.Query;
/** /**
* @website https://el-admin.vip * @website https://el-admin.vip
* @author x * @author x
* @date 2021-01-03 * @date 2021-08-05
**/ **/
@Data @Data
public class UploadFileQueryCriteria{ public class UploadFileQueryCriteria{
/** 精确 */ /** 精确 */
@Query(type = Query.Type.EQUAL) @Query
private Long id; private Long id;
/** 精确 */ /** 模糊 */
@Query(type = Query.Type.EQUAL) @Query(type = Query.Type.INNER_LIKE)
private String operation; private String opration;
/** 精确 */ /** 精确 */
@Query(type = Query.Type.EQUAL) @Query
private Integer uploadTag; private Integer uploadTag;
/** 精确 */
@Query(type = Query.Type.EQUAL)
private String uploadFileTaskName;
/** BETWEEN */ /** BETWEEN */
@Query(type = Query.Type.BETWEEN) @Query(type = Query.Type.BETWEEN)
private List<Timestamp> uploadTime; private List<Timestamp> uploadTime;

@ -15,87 +15,47 @@
*/ */
package me.zhengjie.modules.upload.service.impl; package me.zhengjie.modules.upload.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.system.OsInfo;
import cn.hutool.system.SystemUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.upload.consts.SysConst;
import me.zhengjie.modules.upload.domain.UploadFile; import me.zhengjie.modules.upload.domain.UploadFile;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.upload.repository.UploadFileRepository; import me.zhengjie.modules.upload.repository.UploadFileRepository;
import me.zhengjie.modules.upload.service.UploadFileService; import me.zhengjie.modules.upload.service.UploadFileService;
import me.zhengjie.modules.upload.service.dto.UploadFileDto; import me.zhengjie.modules.upload.service.dto.UploadFileDto;
import me.zhengjie.modules.upload.service.dto.UploadFileQueryCriteria; import me.zhengjie.modules.upload.service.dto.UploadFileQueryCriteria;
import me.zhengjie.modules.upload.service.mapstruct.UploadFileMapper; import me.zhengjie.modules.upload.service.mapstruct.UploadFileMapper;
import me.zhengjie.utils.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse; import me.zhengjie.utils.PageUtil;
import java.io.File; import me.zhengjie.utils.QueryHelp;
import java.util.List;
import java.util.Map;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Paths; import javax.servlet.http.HttpServletResponse;
import java.sql.Timestamp; import java.util.ArrayList;
import java.text.SimpleDateFormat; import java.util.LinkedHashMap;
import java.util.*;
import static me.zhengjie.modules.upload.consts.SysConst.TEST_USER_NAME;
import static me.zhengjie.modules.upload.consts.UploadFileConst.*;
/** /**
* @author x
* @website https://el-admin.vip * @website https://el-admin.vip
* @description * @description
* @date 2021-01-03 * @author x
* @date 2021-08-05
**/ **/
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j
public class UploadFileServiceImpl implements UploadFileService { public class UploadFileServiceImpl implements UploadFileService {
/**
*
*/
@Value("${remote.link.address}")
private String remoteFileServerAddress;
/**
* - 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 final UploadFileRepository uploadFileRepository; private final UploadFileRepository uploadFileRepository;
private final UploadFileMapper uploadFileMapper; private final UploadFileMapper uploadFileMapper;
@Override @Override
public Map<String,Object> queryAll(UploadFileQueryCriteria criteria, Pageable pageable){ public Map<String,Object> queryAll(UploadFileQueryCriteria criteria, Pageable pageable){
Page<UploadFile> page = uploadFileRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); Page<UploadFile> page = uploadFileRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(uploadFileMapper::toDto)); return PageUtil.toPage(page.map(uploadFileMapper::toDto));
} }
@Override @Override
public List<UploadFileDto> queryAll(UploadFileQueryCriteria criteria){ public List<UploadFileDto> queryAll(UploadFileQueryCriteria criteria){
return uploadFileMapper.toDto(uploadFileRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); return uploadFileMapper.toDto(uploadFileRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
@ -137,7 +97,7 @@ public class UploadFileServiceImpl implements UploadFileService {
for (UploadFileDto uploadFile : all) { for (UploadFileDto uploadFile : all) {
Map<String,Object> map = new LinkedHashMap<>(); Map<String,Object> map = new LinkedHashMap<>();
map.put("上传日期", uploadFile.getUploadTime()); map.put("上传日期", uploadFile.getUploadTime());
map.put("操作人", uploadFile.getOperation()); map.put("操作人", uploadFile.getOpration());
map.put("文件解析总数", uploadFile.getFileCount()); map.put("文件解析总数", uploadFile.getFileCount());
map.put("上传成功总数", uploadFile.getFileTransSuccessCount()); map.put("上传成功总数", uploadFile.getFileTransSuccessCount());
map.put("上传状态", uploadFile.getUploadTag()); map.put("上传状态", uploadFile.getUploadTag());
@ -145,99 +105,4 @@ public class UploadFileServiceImpl implements UploadFileService {
} }
FileUtil.downloadExcel(list, response); FileUtil.downloadExcel(list, response);
} }
@Override
public UploadFileDto encryptDataAndSaveToFile(MultipartFile[] files, String taskName) {
// 1. 文件存储到本地
long count = 0; // 统计总数
String baseStr = ""; // 生成通用随机文件夹存放每次的文件
StringBuilder pathBuilder = new StringBuilder();
for (MultipartFile file : files) {
// 获取原来的文件后缀
String originalFilename = file.getOriginalFilename();
if (StringUtils.isBlank(originalFilename)) {
log.error("===================== [input file name is empty, please check ]===================");
}
String extName = FileUtil.extName(originalFilename);
baseStr += FileUtil.mainName(originalFilename);
String eachFilePath = buildFileWritePath(baseStr, extName);
try {
// 把文件保存到本地路径
file.transferTo(Paths.get(eachFilePath));
baseStr = "";
} catch (IOException e) {
log.error("============== [transferTo file fail, path is {} ] ==============", eachFilePath,e);
}
// 统计行数
List<String> tempList = FileUtil.readLines(eachFilePath, "UTF-8");
if (CollectionUtil.isNotEmpty(tempList)){
count += tempList.size();
}
// 保存所有的临时存放路径
pathBuilder.append(eachFilePath);
pathBuilder.append(FILE_PATH_SPLIT);
}
// 2. 更新上传记录为正在上传,解析了有多少条
UploadFile uploadFile = new UploadFile();
uploadFile.setUploadFileTaskName(taskName);
uploadFile.setUploadTime(new Timestamp(new Date().getTime()));
String currentUsername;
if (SysConst.sysDebug){
uploadFile.setOperation(TEST_USER_NAME);//fixme 这边测试环境补充一下需要的操作人
}else {
currentUsername = SecurityUtils.getCurrentUsername();
uploadFile.setOperation(currentUsername);
}
uploadFile.setFileCount(count);
uploadFile.setFileTransSuccessCount(0L);
uploadFile.setUploadTag(DOING_TAG);
String tempFilesPath = pathBuilder.toString().substring(0, pathBuilder.length() - 1);
if (StringUtils.isNotBlank(tempFilesPath)){
uploadFile.setLocalSavePath(tempFilesPath); // 去掉最后的那个通配符 FILE_PATH_SPLIT
}
UploadFileDto uploadFileDto = create(uploadFile);
return uploadFileDto;
}
/**
*
*/
private String buildFileWritePath(String baseStr, String extName) {
// 获取环境配置信息
OsInfo osInfo = SystemUtil.getOsInfo();
// 定义的时间格式
String timeFormate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String dirPath;
// 生成一个随机文件夹目录,方便整理和打包
String filePath = RandomUtil.randomString(6) + FILE_NAME_SPLIT + baseStr + FILE_SPLIT + extName;
if (osInfo.isWindows()) {
dirPath = remoteLinkFileBasePathWindows + timeFormate + File.separator;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath + filePath;
} else if (osInfo.isLinux()) {
dirPath = remoteLinkFileBasePathLinux + timeFormate + File.separator;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath + filePath;
} else if (osInfo.isMac()) {
dirPath = remoteLinkFileBasePathMac + timeFormate + File.separator;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath + filePath;
} else {
return "";
}
}
} }

@ -24,7 +24,7 @@ import org.mapstruct.ReportingPolicy;
/** /**
* @website https://el-admin.vip * @website https://el-admin.vip
* @author x * @author x
* @date 2021-01-03 * @date 2021-08-05
**/ **/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UploadFileMapper extends BaseMapper<UploadFileDto, UploadFile> { public interface UploadFileMapper extends BaseMapper<UploadFileDto, UploadFile> {

@ -25,6 +25,7 @@ import me.zhengjie.annotation.Log;
import me.zhengjie.common.http.CommonResponse; import me.zhengjie.common.http.CommonResponse;
import me.zhengjie.common.http.ResponseCode; import me.zhengjie.common.http.ResponseCode;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.formdata.service.FormdataService;
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;
@ -50,6 +51,7 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
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.*;
@ -67,14 +69,22 @@ import static me.zhengjie.modules.uploadnew.consts.SysConstNew.*;
@Slf4j @Slf4j
public class TbUploadFileNewController { public class TbUploadFileNewController {
private final TbUploadFileNewService tbUploadFileNewService; private TbUploadFileNewService tbUploadFileNewService;
@Autowired
private SaveToFileNewTask saveToFileNewTask; private SaveToFileNewTask saveToFileNewTask;
@Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
private FormdataService formdataService;
@Autowired
public TbUploadFileNewController(TbUploadFileNewService tbUploadFileNewService, SaveToFileNewTask saveToFileNewTask, RedisTemplate redisTemplate, FormdataService formdataService) {
this.tbUploadFileNewService = tbUploadFileNewService;
this.saveToFileNewTask = saveToFileNewTask;
this.redisTemplate = redisTemplate;
this.formdataService = formdataService;
}
@Log("导出数据") @Log("导出数据")
@ApiOperation("导出数据") @ApiOperation("导出数据")
@GetMapping(value = "/download") @GetMapping(value = "/download")
@ -117,6 +127,84 @@ public class TbUploadFileNewController {
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
/**
*
*
* @param files
* @param taskName
* @return
*/
@Log("新的成单数据及录音文件导入接口")
@ApiOperation("新的成单数据及录音文件导入接口")
// @AnonymousAccess
@PostMapping("/newFileUpload")
@PreAuthorize("@el.check('tbUploadFileNew:list')") // 这个换下相关按钮的权限控制
// @ResponseBody
public ResponseEntity<Object> newFileUpload(@RequestParam("file") MultipartFile[] files,
@RequestParam(value = "taskName") String taskName) {
// 记录日志
log.info("TbUploadFileNewController:newFileUpload | taskName : {} start ", taskName);
// 校验上传是否有文件
if (null == files) {
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_FILE_INPUT), HttpStatus.OK);
}
// todo 记录文件上传记录
int finishTag = 0;
for (MultipartFile file : files) {
String originalFilename = file.getOriginalFilename();
if (StringUtils.isNotBlank(originalFilename)) {
String subOriginalFilename = StringUtils.substringAfterLast(originalFilename, SPLIT_FILE_SYMBOL);
finishTag = handleEachUploadFile(file , subOriginalFilename, 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 上传完成更新文件上传记录
return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK);
}
/**
* finishTag ,
*
* @param subOriginalFilename
* @return
*/
private int handleEachUploadFile(MultipartFile file, String subOriginalFilename, int finishTag) {
if (XLSX_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)) {
// 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 记录保存位置
finishTag += 1;
}
}
return finishTag;
}
/** /**
* *
* *

@ -0,0 +1,31 @@
package me.zhengjie.modules.uploadnew.task;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.formdata.service.dto.FormdataDto;
import me.zhengjie.utils.ConvertUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
@Component
@Scope("prototype")
@Slf4j
public class TransFormDataTask {
@Async(value = "SendBigDataTaskExecutor")
public void doRunTask(List<FormdataDto> formdataDtos) {
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start running, task name is {} ] ======", "TransFormDataTask");
runTask(formdataDtos);
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) {
}
}

@ -2,6 +2,8 @@ package me.zhengjie;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.FileUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
@ -10,6 +12,14 @@ import java.util.Set;
public class DemoTest { public class DemoTest {
@Before
public void be(){
// TODO: 2021/5/7 0007 dc1 dc2 ...
// shuju
}
/** /**
* *
*/ */
@ -29,4 +39,14 @@ public class DemoTest {
} }
} }
@After
public void af(){
// TODO: 2021/5/7 0007 dc1 dc2 ...
// shuju
}
} }

@ -151,7 +151,12 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- excel工具 --> <!-- excel工具 https://www.yuque.com/easyexcel/doc/update -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.8</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId> <artifactId>poi</artifactId>

Loading…
Cancel
Save