From 6be90376dd1e39dc91702b54c738b36fa256c1ad Mon Sep 17 00:00:00 2001 From: wujingtao Date: Wed, 22 Sep 2021 18:31:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0form=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tmpfilerecord/domain/TempFileRecord.java | 58 ++++++----- .../rest/TempFileRecordController.java | 58 +++++------ .../service/TempFileRecordService.java | 98 ++++++++++--------- .../service/dto/TempFileRecordDto.java | 74 +++++++++----- .../dto/TempFileRecordQueryCriteria.java | 73 +++++++++----- .../impl/TempFileRecordServiceImpl.java | 77 ++++++++------- 6 files changed, 253 insertions(+), 185 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/domain/TempFileRecord.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/domain/TempFileRecord.java index 954ec1f..252afd3 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/domain/TempFileRecord.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/domain/TempFileRecord.java @@ -1,37 +1,39 @@ /* -* 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.tmpfilerecord.domain; import lombok.Data; import cn.hutool.core.bean.BeanUtil; import io.swagger.annotations.ApiModelProperty; import cn.hutool.core.bean.copier.CopyOptions; + import javax.persistence.*; import javax.validation.constraints.*; import java.io.Serializable; +import java.util.Date; /** -* @website https://el-admin.vip -* @description / -* @author X -* @date 2020-10-15 -**/ + * @author X + * @website https://el-admin.vip + * @description / + * @date 2020-10-15 + **/ @Entity @Data -@Table(name="tb_temp_file_record") +@Table(name = "tb_temp_file_record") public class TempFileRecord implements Serializable { @Id @@ -63,7 +65,19 @@ public class TempFileRecord implements Serializable { @ApiModelProperty(value = "文件保存状态") private Integer fileStatus; - public void copy(TempFileRecord source){ - BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + @Column(name = "origin") + @ApiModelProperty(value = "链接来源") + private Integer origin; + + @Column(name = "gmt_create") + @ApiModelProperty(value = "生成日期") + private Date gmtCreate; + + @Column(name = "act_name") + @ApiModelProperty(value = "业务名") + private String actName; + + public void copy(TempFileRecord source) { + BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true)); } } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java index 091588e..b7643b3 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java @@ -1,32 +1,24 @@ /* -* 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.tmpfilerecord.rest; -import cn.hutool.json.JSON; -import cn.hutool.json.JSONUtil; import me.zhengjie.annotation.Log; -import me.zhengjie.common.http.CommonResponse; -import me.zhengjie.common.http.ResponseCode; -import me.zhengjie.common.json.OnceLinkMsgJsonContent; import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; import me.zhengjie.modules.tmpfilerecord.service.TempFileRecordService; import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria; -import me.zhengjie.service.EmailService; -import me.zhengjie.utils.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -35,16 +27,15 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.*; -import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import javax.servlet.http.HttpServletResponse; /** -* @website https://el-admin.vip -* @author X -* @date 2020-10-15 -**/ + * @author X + * @website https://el-admin.vip + * @date 2020-10-15 + **/ @RestController @RequiredArgsConstructor @Api(tags = "tmpfilerecord管理") @@ -65,23 +56,23 @@ public class TempFileRecordController { @Log("查询tmpfilerecord") @ApiOperation("查询tmpfilerecord") @PreAuthorize("@el.check('tempFileRecord:list')") - public ResponseEntity query(TempFileRecordQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(tempFileRecordService.queryAll(criteria,pageable),HttpStatus.OK); + public ResponseEntity query(TempFileRecordQueryCriteria criteria, Pageable pageable) { + return new ResponseEntity<>(tempFileRecordService.queryAll(criteria, pageable), HttpStatus.OK); } - + @PostMapping @Log("新增tmpfilerecord") @ApiOperation("新增tmpfilerecord") @PreAuthorize("@el.check('tempFileRecord:add')") - public ResponseEntity create(@Validated @RequestBody TempFileRecord resources){ - return new ResponseEntity<>(tempFileRecordService.create(resources),HttpStatus.CREATED); + public ResponseEntity create(@Validated @RequestBody TempFileRecord resources) { + return new ResponseEntity<>(tempFileRecordService.create(resources), HttpStatus.CREATED); } @PutMapping @Log("修改tmpfilerecord") @ApiOperation("修改tmpfilerecord") @PreAuthorize("@el.check('tempFileRecord:edit')") - public ResponseEntity update(@Validated @RequestBody TempFileRecord resources){ + public ResponseEntity update(@Validated @RequestBody TempFileRecord resources) { tempFileRecordService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -94,4 +85,5 @@ public class TempFileRecordController { tempFileRecordService.deleteAll(ids); return new ResponseEntity<>(HttpStatus.OK); } + } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java index 34f6379..e8b0d5f 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java @@ -1,24 +1,25 @@ /* -* 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.tmpfilerecord.service; import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordDto; import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria; import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; import org.springframework.web.multipart.MultipartFile; import java.util.Map; @@ -27,67 +28,74 @@ import java.io.IOException; import javax.servlet.http.HttpServletResponse; /** -* @website https://el-admin.vip -* @description 服务接口 -* @author X -* @date 2020-10-15 -**/ + * @author X + * @website https://el-admin.vip + * @description 服务接口 + * @date 2020-10-15 + **/ public interface TempFileRecordService { /** - * 查询数据分页 - * @param criteria 条件 - * @param pageable 分页参数 - * @return Map - */ - Map queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable); + * 查询数据分页 + * + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable); /** - * 查询所有数据不分页 - * @param criteria 条件参数 - * @return List - */ + * 查询所有数据不分页 + * + * @param criteria 条件参数 + * @return List + */ List queryAll(TempFileRecordQueryCriteria criteria); /** * 根据ID查询 + * * @param id ID * @return TempFileRecordDto */ TempFileRecordDto findById(Integer id); /** - * 创建 - * @param resources / - * @return TempFileRecordDto - */ + * 创建 + * + * @param resources / + * @return TempFileRecordDto + */ TempFileRecordDto create(TempFileRecord resources); /** - * 编辑 - * @param resources / - */ + * 编辑 + * + * @param resources / + */ void update(TempFileRecord resources); /** - * 多选删除 - * @param ids / - */ + * 多选删除 + * + * @param ids / + */ void deleteAll(Integer[] ids); /** - * 导出数据 - * @param all 待导出的数据 - * @param response / - * @throws IOException / - */ + * 导出数据 + * + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ void download(List all, HttpServletResponse response) throws IOException; /** * 根据文件访问验证码进行访问 */ - TempFileRecord findByVerificationCode(String verificationCode, Integer fileStatus); + TempFileRecord findByVerificationCode(String verificationCode, Integer fileStatus); /** * 批量更新 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordDto.java index 512b5b2..2de9779 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordDto.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordDto.java @@ -1,47 +1,71 @@ /* -* 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.tmpfilerecord.service.dto; import lombok.Data; + import java.io.Serializable; +import java.util.Date; /** -* @website https://el-admin.vip -* @description / -* @author X -* @date 2020-10-15 -**/ + * @author X + * @website https://el-admin.vip + * @description / + * @date 2020-10-15 + **/ @Data public class TempFileRecordDto implements Serializable { - /** id */ + /** + * id + */ private Integer id; - /** 访问接口的ip地址记录 */ + /** + * 访问接口的ip地址记录 + */ private String ipAddrs; - /** 文件生成地址 */ + /** + * 文件生成地址 + */ private String filePaths; - /** 访问文件验证码 */ + /** + * 访问文件验证码 + */ private String verificationCode; - /** 有效保存时间 */ + /** + * 有效保存时间 + */ private Integer days; - /** 文件保存状态 */ + /** + * 文件保存状态 + */ private Integer fileStatus; + /** + * 来源 1-formManager 2-eladmin + */ + private Integer origin; + + private Date gmtCreate; + /** + * 业务名 + */ + private String actName; } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordQueryCriteria.java index e5c07b9..b51c1e3 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordQueryCriteria.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordQueryCriteria.java @@ -1,49 +1,74 @@ /* -* 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.tmpfilerecord.service.dto; import lombok.Data; + +import java.sql.Timestamp; +import java.util.Date; import java.util.List; + import me.zhengjie.annotation.Query; /** -* @website https://el-admin.vip -* @author X -* @date 2020-10-15 -**/ + * @author X + * @website https://el-admin.vip + * @date 2020-10-15 + **/ @Data -public class TempFileRecordQueryCriteria{ +public class TempFileRecordQueryCriteria { - /** 精确 */ + /** + * 精确 + */ @Query private Integer id; - /** 精确 */ + /** + * 精确 + */ @Query private String ipAddrs; - /** 精确 */ + /** + * 精确 + */ @Query private String verificationCode; - /** 精确 */ + /** + * 精确 + */ @Query private Integer days; - /** 精确 */ + /** + * 精确 + */ @Query private Integer fileStatus; + /** + * 精确 + */ + @Query + private Integer origin; + + /** + * BETWEEN + */ + @Query(type = Query.Type.BETWEEN) + private List gmtCreate; } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java index 2ab542c..d777afd 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java @@ -1,25 +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. -*/ + * 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.tmpfilerecord.service.impl; import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.util.RandomUtil; -import cn.hutool.system.OsInfo; -import cn.hutool.system.SystemUtil; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; import lombok.extern.slf4j.Slf4j; +import me.zhengjie.common.http.CommonResponse; +import me.zhengjie.common.http.ResponseCode; +import me.zhengjie.common.json.OnceLinkMsgJsonContent; +import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; import me.zhengjie.utils.*; import lombok.RequiredArgsConstructor; @@ -29,26 +32,23 @@ import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordDto; import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria; import me.zhengjie.modules.tmpfilerecord.service.mapstruct.TempFileRecordMapper; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.web.multipart.MultipartFile; -import java.nio.file.Paths; -import java.util.List; -import java.util.Map; +import java.util.*; import java.io.IOException; import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.LinkedHashMap; /** -* @website https://el-admin.vip -* @description 服务实现 -* @author X -* @date 2020-10-15 -**/ + * @author X + * @website https://el-admin.vip + * @description 服务实现 + * @date 2020-10-15 + **/ @Service @RequiredArgsConstructor @Slf4j @@ -56,23 +56,28 @@ public class TempFileRecordServiceImpl implements TempFileRecordService { private final TempFileRecordRepository tempFileRecordRepository; private final TempFileRecordMapper tempFileRecordMapper; + /** + * 远程服务器地址 + */ + @Value("${remote.link.address}") + private String remoteFileServerAddress; @Override - public Map queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable){ - Page page = tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + public Map queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable) { + Page page = tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); return PageUtil.toPage(page.map(tempFileRecordMapper::toDto)); } @Override - public List queryAll(TempFileRecordQueryCriteria criteria){ - return tempFileRecordMapper.toDto(tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + public List queryAll(TempFileRecordQueryCriteria criteria) { + return tempFileRecordMapper.toDto(tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); } @Override @Transactional public TempFileRecordDto findById(Integer id) { TempFileRecord tempFileRecord = tempFileRecordRepository.findById(id).orElseGet(TempFileRecord::new); - ValidationUtil.isNull(tempFileRecord.getId(),"TempFileRecord","id",id); + ValidationUtil.isNull(tempFileRecord.getId(), "TempFileRecord", "id", id); return tempFileRecordMapper.toDto(tempFileRecord); } @@ -86,7 +91,7 @@ public class TempFileRecordServiceImpl implements TempFileRecordService { @Transactional(rollbackFor = Exception.class) public void update(TempFileRecord resources) { TempFileRecord tempFileRecord = tempFileRecordRepository.findById(resources.getId()).orElseGet(TempFileRecord::new); - ValidationUtil.isNull( tempFileRecord.getId(),"TempFileRecord","id",resources.getId()); + ValidationUtil.isNull(tempFileRecord.getId(), "TempFileRecord", "id", resources.getId()); tempFileRecord.copy(resources); tempFileRecordRepository.save(tempFileRecord); } @@ -102,7 +107,7 @@ public class TempFileRecordServiceImpl implements TempFileRecordService { public void download(List all, HttpServletResponse response) throws IOException { List> list = new ArrayList<>(); for (TempFileRecordDto tempFileRecord : all) { - Map map = new LinkedHashMap<>(); + Map map = new LinkedHashMap<>(); map.put("访问接口的ip地址记录", tempFileRecord.getIpAddrs()); map.put("文件生成地址", tempFileRecord.getFilePaths()); map.put("访问文件验证码", tempFileRecord.getVerificationCode()); @@ -122,7 +127,7 @@ public class TempFileRecordServiceImpl implements TempFileRecordService { @Override public long batchUpdate(List TempFileRecordDto) { TempFileRecordDto.forEach( - each->{ + each -> { TempFileRecord tempFileRecord = new TempFileRecord(); BeanUtil.copyProperties(each, tempFileRecord); update(tempFileRecord); From 5a4bff855dbe7ab2c9139b93bc481618fb962da3 Mon Sep 17 00:00:00 2001 From: wujingtao Date: Thu, 23 Sep 2021 10:12:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0form=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=92=8C=E7=94=9F=E6=88=90=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rest/TempFileRecordController.java | 30 +++++++++- .../service/TempFileRecordService.java | 23 +++++++ .../impl/TempFileRecordServiceImpl.java | 60 +++++++++++++++++++ .../resources/config/application-test.yml | 9 ++- .../src/main/resources/config/application.yml | 3 +- pom.xml | 1 - 6 files changed, 119 insertions(+), 7 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java index b7643b3..56d94b6 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java @@ -15,6 +15,7 @@ */ package me.zhengjie.modules.tmpfilerecord.rest; +import me.zhengjie.annotation.AnonymousAccess; import me.zhengjie.annotation.Log; import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; import me.zhengjie.modules.tmpfilerecord.service.TempFileRecordService; @@ -29,6 +30,7 @@ import org.springframework.web.bind.annotation.*; import io.swagger.annotations.*; import java.io.IOException; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** @@ -59,7 +61,33 @@ public class TempFileRecordController { public ResponseEntity query(TempFileRecordQueryCriteria criteria, Pageable pageable) { return new ResponseEntity<>(tempFileRecordService.queryAll(criteria, pageable), HttpStatus.OK); } - + + @GetMapping("/link") + @Log("获取本地链接") + @ApiOperation("获取本地链接") + public ResponseEntity getFormLink(Integer id) { + return tempFileRecordService.getFormLink(id); + } + + @GetMapping("/remoterLink") + @Log("获取远程链接") + @ApiOperation("获取远程链接") + public ResponseEntity getFormRemoterLink(Integer id) { + return tempFileRecordService.getFormRemoterLink(id); + } + + /** + * 本地进行下载文件 + */ + @Log("下载文件") + @GetMapping("downloadFile") + @ApiOperation("下载文件") + @AnonymousAccess // fixme 需要测试完成后进行去除和使用上面的权限注解 + public void downLoadFormFile(HttpServletResponse response, HttpServletRequest request, @RequestParam(value = "rand") String rand) { + // 校验参数,进行下载文件 + tempFileRecordService.downloadFilesByRandCode(rand, response, request); + } + @PostMapping @Log("新增tmpfilerecord") @ApiOperation("新增tmpfilerecord") diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java index e8b0d5f..184ca08 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java @@ -25,6 +25,7 @@ import org.springframework.web.multipart.MultipartFile; import java.util.Map; import java.util.List; import java.io.IOException; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** @@ -104,4 +105,26 @@ public interface TempFileRecordService { */ long batchUpdate(List TempFileRecordDto); + /** + * 根据id,获取对应的链接 + * + * @param id + * @return + */ + ResponseEntity getFormLink(Integer id); + + /** + * 根据id,获取对应的链接 + * + * @param id + * @return + */ + ResponseEntity getFormRemoterLink(Integer id); + + /** + * 根据码来下载文件 + * + * @param rand 验证下载码 + */ + void downloadFilesByRandCode(String rand, HttpServletResponse response, HttpServletRequest request); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java index d777afd..7a7e35c 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java @@ -18,11 +18,13 @@ package me.zhengjie.modules.tmpfilerecord.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ZipUtil; import lombok.extern.slf4j.Slf4j; import me.zhengjie.common.http.CommonResponse; import me.zhengjie.common.http.ResponseCode; import me.zhengjie.common.json.OnceLinkMsgJsonContent; import me.zhengjie.exception.BadRequestException; +import me.zhengjie.modules.mnt.util.ZipUtils; import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; import me.zhengjie.utils.*; import lombok.RequiredArgsConstructor; @@ -39,8 +41,10 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import java.io.File; import java.util.*; import java.io.IOException; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** @@ -56,6 +60,11 @@ public class TempFileRecordServiceImpl implements TempFileRecordService { private final TempFileRecordRepository tempFileRecordRepository; private final TempFileRecordMapper tempFileRecordMapper; + /** + * 远程服务器地址 + */ + @Value("${tempFileRecord.link.address}") + private String tempFileRecordAddress; /** * 远程服务器地址 */ @@ -135,4 +144,55 @@ public class TempFileRecordServiceImpl implements TempFileRecordService { ); return TempFileRecordDto.size(); } + + @Override + public ResponseEntity getFormLink(Integer id) { + TempFileRecordDto byId = findById(id); + long num = DateUtil.between(byId.getGmtCreate(), DateUtil.date(), DateUnit.DAY); + if ((int) num > byId.getDays()) { + throw new BadRequestException("超过有效期"); + } + + String url = tempFileRecordAddress + "?" + "rand=" + byId.getVerificationCode(); + return getOnceLinkResponseEntity(url); + } + + @Override + public ResponseEntity getFormRemoterLink(Integer id) { + TempFileRecordDto byId = findById(id); + long num = DateUtil.between(byId.getGmtCreate(), DateUtil.date(), DateUnit.DAY); + if ((int) num > byId.getDays()) { + throw new BadRequestException("超过有效期"); + } + String url = remoteFileServerAddress + "?" + "rand=" + byId.getVerificationCode(); + return getOnceLinkResponseEntity(url); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void downloadFilesByRandCode(String rand, HttpServletResponse response, HttpServletRequest request) { + // 根据验证码查出需要的信息 + TempFileRecord tempFileRecord = findByVerificationCode(rand.trim(), 0); + // 切分需要的文件地址 + if (tempFileRecord != null) { + String filePaths = tempFileRecord.getFilePaths(); + if (StringUtils.isNotBlank(filePaths)) { + FileUtil.downloadFile(request, response, new File(filePaths), true); + // 更新下载结果 + tempFileRecord.setFileStatus(1); + update(tempFileRecord); + } + } + } + + private ResponseEntity getOnceLinkResponseEntity(String result) { + OnceLinkMsgJsonContent linkUrl = new OnceLinkMsgJsonContent(); + if (StringUtils.isNotBlank(result)) { + // 进行json相关的转换 + linkUrl.setOnceLink(result); + } else { + return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_MATCH_ARGUMENT_SET), HttpStatus.OK); + } + return new ResponseEntity<>(CommonResponse.createBySuccess(linkUrl), HttpStatus.OK); + } } \ No newline at end of file diff --git a/eladmin-system/src/main/resources/config/application-test.yml b/eladmin-system/src/main/resources/config/application-test.yml index 9e9e160..b25fa0e 100644 --- a/eladmin-system/src/main/resources/config/application-test.yml +++ b/eladmin-system/src/main/resources/config/application-test.yml @@ -1,9 +1,9 @@ #配置数据源 spring: shardingsphere: -# props: -# sql: -# show: true + # props: + # sql: + # show: true datasource: names: eladmin,schema eladmin: @@ -246,3 +246,6 @@ remote: file-base-path-linux: /home/eladmin/file/temp/ file-base-path-windows: C:\eladmin\file\temp\ file-base-path-mac: ~/file/eladmin/temp/ +tempFileRecord: + link: + address: 'http://116.62.197.152:8000/api/tempFileRecord/downloadFile' \ No newline at end of file diff --git a/eladmin-system/src/main/resources/config/application.yml b/eladmin-system/src/main/resources/config/application.yml index d09003c..41ee32c 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -25,7 +25,7 @@ spring: order_inserts: true order_updates: true open-in-view: true -# show-sql: true + # show-sql: true redis: #数据库索引 database: 0 @@ -34,7 +34,6 @@ spring: password: #连接超时时间 timeout: 5000 - task: pool: # 核心线程池大小 diff --git a/pom.xml b/pom.xml index 8dd167c..bf2aa48 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,6 @@ - org.apache.shardingSphere sharding-jdbc-spring-boot-starter