Merge remote-tracking branch '百业git1/master' into master

master
土豆兄弟 3 years ago
commit 7551fbfe4f

@ -1,37 +1,39 @@
/* /*
* Copyright 2019-2020 Zheng Jie * Copyright 2019-2020 Zheng Jie
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package me.zhengjie.modules.tmpfilerecord.domain; package me.zhengjie.modules.tmpfilerecord.domain;
import lombok.Data; import lombok.Data;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
/** /**
* @website https://el-admin.vip * @author X
* @description / * @website https://el-admin.vip
* @author X * @description /
* @date 2020-10-15 * @date 2020-10-15
**/ **/
@Entity @Entity
@Data @Data
@Table(name="tb_temp_file_record") @Table(name = "tb_temp_file_record")
public class TempFileRecord implements Serializable { public class TempFileRecord implements Serializable {
@Id @Id
@ -63,7 +65,19 @@ public class TempFileRecord implements Serializable {
@ApiModelProperty(value = "文件保存状态") @ApiModelProperty(value = "文件保存状态")
private Integer fileStatus; private Integer fileStatus;
public void copy(TempFileRecord source){ @Column(name = "origin")
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); @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));
} }
} }

@ -1,32 +1,25 @@
/* /*
* Copyright 2019-2020 Zheng Jie * Copyright 2019-2020 Zheng Jie
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package me.zhengjie.modules.tmpfilerecord.rest; package me.zhengjie.modules.tmpfilerecord.rest;
import cn.hutool.json.JSON; import me.zhengjie.annotation.AnonymousAccess;
import cn.hutool.json.JSONUtil;
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.common.json.OnceLinkMsgJsonContent;
import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord;
import me.zhengjie.modules.tmpfilerecord.service.TempFileRecordService; import me.zhengjie.modules.tmpfilerecord.service.TempFileRecordService;
import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria; 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 org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -35,16 +28,16 @@ import org.springframework.security.access.prepost.PreAuthorize;
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 io.swagger.annotations.*; import io.swagger.annotations.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
/** /**
* @website https://el-admin.vip * @author X
* @author X * @website https://el-admin.vip
* @date 2020-10-15 * @date 2020-10-15
**/ **/
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
@Api(tags = "tmpfilerecord管理") @Api(tags = "tmpfilerecord管理")
@ -65,23 +58,49 @@ public class TempFileRecordController {
@Log("查询tmpfilerecord") @Log("查询tmpfilerecord")
@ApiOperation("查询tmpfilerecord") @ApiOperation("查询tmpfilerecord")
@PreAuthorize("@el.check('tempFileRecord:list')") @PreAuthorize("@el.check('tempFileRecord:list')")
public ResponseEntity<Object> query(TempFileRecordQueryCriteria criteria, Pageable pageable){ public ResponseEntity<Object> query(TempFileRecordQueryCriteria criteria, Pageable pageable) {
return new ResponseEntity<>(tempFileRecordService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(tempFileRecordService.queryAll(criteria, pageable), HttpStatus.OK);
}
@GetMapping("/link")
@Log("获取本地链接")
@ApiOperation("获取本地链接")
public ResponseEntity<Object> getFormLink(Integer id) {
return tempFileRecordService.getFormLink(id);
}
@GetMapping("/remoterLink")
@Log("获取远程链接")
@ApiOperation("获取远程链接")
public ResponseEntity<Object> 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 @PostMapping
@Log("新增tmpfilerecord") @Log("新增tmpfilerecord")
@ApiOperation("新增tmpfilerecord") @ApiOperation("新增tmpfilerecord")
@PreAuthorize("@el.check('tempFileRecord:add')") @PreAuthorize("@el.check('tempFileRecord:add')")
public ResponseEntity<Object> create(@Validated @RequestBody TempFileRecord resources){ public ResponseEntity<Object> create(@Validated @RequestBody TempFileRecord resources) {
return new ResponseEntity<>(tempFileRecordService.create(resources),HttpStatus.CREATED); return new ResponseEntity<>(tempFileRecordService.create(resources), HttpStatus.CREATED);
} }
@PutMapping @PutMapping
@Log("修改tmpfilerecord") @Log("修改tmpfilerecord")
@ApiOperation("修改tmpfilerecord") @ApiOperation("修改tmpfilerecord")
@PreAuthorize("@el.check('tempFileRecord:edit')") @PreAuthorize("@el.check('tempFileRecord:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody TempFileRecord resources){ public ResponseEntity<Object> update(@Validated @RequestBody TempFileRecord resources) {
tempFileRecordService.update(resources); tempFileRecordService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} }
@ -94,4 +113,5 @@ public class TempFileRecordController {
tempFileRecordService.deleteAll(ids); tempFileRecordService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
} }

@ -1,93 +1,102 @@
/* /*
* Copyright 2019-2020 Zheng Jie * Copyright 2019-2020 Zheng Jie
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package me.zhengjie.modules.tmpfilerecord.service; package me.zhengjie.modules.tmpfilerecord.service;
import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord;
import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordDto; import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordDto;
import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria; import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.Map; import java.util.Map;
import java.util.List; import java.util.List;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
/** /**
* @website https://el-admin.vip * @author X
* @description * @website https://el-admin.vip
* @author X * @description
* @date 2020-10-15 * @date 2020-10-15
**/ **/
public interface TempFileRecordService { public interface TempFileRecordService {
/** /**
* *
* @param criteria *
* @param pageable * @param criteria
* @return Map<String,Object> * @param pageable
*/ * @return Map<String, Object>
Map<String,Object> queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable); */
Map<String, Object> queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable);
/** /**
* *
* @param criteria *
* @return List<TempFileRecordDto> * @param criteria
*/ * @return List<TempFileRecordDto>
*/
List<TempFileRecordDto> queryAll(TempFileRecordQueryCriteria criteria); List<TempFileRecordDto> queryAll(TempFileRecordQueryCriteria criteria);
/** /**
* ID * ID
*
* @param id ID * @param id ID
* @return TempFileRecordDto * @return TempFileRecordDto
*/ */
TempFileRecordDto findById(Integer id); TempFileRecordDto findById(Integer id);
/** /**
* *
* @param resources / *
* @return TempFileRecordDto * @param resources /
*/ * @return TempFileRecordDto
*/
TempFileRecordDto create(TempFileRecord resources); TempFileRecordDto create(TempFileRecord resources);
/** /**
* *
* @param resources / *
*/ * @param resources /
*/
void update(TempFileRecord resources); void update(TempFileRecord resources);
/** /**
* *
* @param ids / *
*/ * @param ids /
*/
void deleteAll(Integer[] ids); void deleteAll(Integer[] ids);
/** /**
* *
* @param all *
* @param response / * @param all
* @throws IOException / * @param response /
*/ * @throws IOException /
*/
void download(List<TempFileRecordDto> all, HttpServletResponse response) throws IOException; void download(List<TempFileRecordDto> all, HttpServletResponse response) throws IOException;
/** /**
* 访访 * 访访
*/ */
TempFileRecord findByVerificationCode(String verificationCode, Integer fileStatus); TempFileRecord findByVerificationCode(String verificationCode, Integer fileStatus);
/** /**
* *
@ -96,4 +105,26 @@ public interface TempFileRecordService {
*/ */
long batchUpdate(List<TempFileRecordDto> TempFileRecordDto); long batchUpdate(List<TempFileRecordDto> TempFileRecordDto);
/**
* id
*
* @param id
* @return
*/
ResponseEntity<Object> getFormLink(Integer id);
/**
* id
*
* @param id
* @return
*/
ResponseEntity<Object> getFormRemoterLink(Integer id);
/**
*
*
* @param rand
*/
void downloadFilesByRandCode(String rand, HttpServletResponse response, HttpServletRequest request);
} }

@ -1,47 +1,71 @@
/* /*
* Copyright 2019-2020 Zheng Jie * Copyright 2019-2020 Zheng Jie
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package me.zhengjie.modules.tmpfilerecord.service.dto; package me.zhengjie.modules.tmpfilerecord.service.dto;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
/** /**
* @website https://el-admin.vip * @author X
* @description / * @website https://el-admin.vip
* @author X * @description /
* @date 2020-10-15 * @date 2020-10-15
**/ **/
@Data @Data
public class TempFileRecordDto implements Serializable { public class TempFileRecordDto implements Serializable {
/** id */ /**
* id
*/
private Integer id; private Integer id;
/** 访问接口的ip地址记录 */ /**
* 访ip
*/
private String ipAddrs; private String ipAddrs;
/** 文件生成地址 */ /**
*
*/
private String filePaths; private String filePaths;
/** 访问文件验证码 */ /**
* 访
*/
private String verificationCode; private String verificationCode;
/** 有效保存时间 */ /**
*
*/
private Integer days; private Integer days;
/** 文件保存状态 */ /**
*
*/
private Integer fileStatus; private Integer fileStatus;
/**
* 1-formManager 2-eladmin
*/
private Integer origin;
private Date gmtCreate;
/**
*
*/
private String actName;
} }

@ -1,49 +1,74 @@
/* /*
* Copyright 2019-2020 Zheng Jie * Copyright 2019-2020 Zheng Jie
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package me.zhengjie.modules.tmpfilerecord.service.dto; package me.zhengjie.modules.tmpfilerecord.service.dto;
import lombok.Data; import lombok.Data;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List; import java.util.List;
import me.zhengjie.annotation.Query; import me.zhengjie.annotation.Query;
/** /**
* @website https://el-admin.vip * @author X
* @author X * @website https://el-admin.vip
* @date 2020-10-15 * @date 2020-10-15
**/ **/
@Data @Data
public class TempFileRecordQueryCriteria{ public class TempFileRecordQueryCriteria {
/** 精确 */ /**
*
*/
@Query @Query
private Integer id; private Integer id;
/** 精确 */ /**
*
*/
@Query @Query
private String ipAddrs; private String ipAddrs;
/** 精确 */ /**
*
*/
@Query @Query
private String verificationCode; private String verificationCode;
/** 精确 */ /**
*
*/
@Query @Query
private Integer days; private Integer days;
/** 精确 */ /**
*
*/
@Query @Query
private Integer fileStatus; private Integer fileStatus;
/**
*
*/
@Query
private Integer origin;
/**
* BETWEEN
*/
@Query(type = Query.Type.BETWEEN)
private List<Timestamp> gmtCreate;
} }

@ -1,25 +1,30 @@
/* /*
* Copyright 2019-2020 Zheng Jie * Copyright 2019-2020 Zheng Jie
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package me.zhengjie.modules.tmpfilerecord.service.impl; package me.zhengjie.modules.tmpfilerecord.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.date.DateUnit;
import cn.hutool.system.OsInfo; import cn.hutool.core.date.DateUtil;
import cn.hutool.system.SystemUtil; import cn.hutool.core.util.ZipUtil;
import lombok.extern.slf4j.Slf4j; 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.modules.tmpfilerecord.domain.TempFileRecord;
import me.zhengjie.utils.*; import me.zhengjie.utils.*;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -29,26 +34,25 @@ import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordDto;
import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria; import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria;
import me.zhengjie.modules.tmpfilerecord.service.mapstruct.TempFileRecordMapper; import me.zhengjie.modules.tmpfilerecord.service.mapstruct.TempFileRecordMapper;
import org.springframework.beans.factory.annotation.Value; 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import java.nio.file.Paths; import java.io.File;
import java.util.List; import java.util.*;
import java.util.Map;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
/** /**
* @website https://el-admin.vip * @author X
* @description * @website https://el-admin.vip
* @author X * @description
* @date 2020-10-15 * @date 2020-10-15
**/ **/
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
@ -56,23 +60,33 @@ public class TempFileRecordServiceImpl implements TempFileRecordService {
private final TempFileRecordRepository tempFileRecordRepository; private final TempFileRecordRepository tempFileRecordRepository;
private final TempFileRecordMapper tempFileRecordMapper; private final TempFileRecordMapper tempFileRecordMapper;
/**
*
*/
@Value("${tempFileRecord.link.address}")
private String tempFileRecordAddress;
/**
*
*/
@Value("${remote.link.address}")
private String remoteFileServerAddress;
@Override @Override
public Map<String,Object> queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable){ public Map<String, Object> queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable) {
Page<TempFileRecord> page = tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); Page<TempFileRecord> page = tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
return PageUtil.toPage(page.map(tempFileRecordMapper::toDto)); return PageUtil.toPage(page.map(tempFileRecordMapper::toDto));
} }
@Override @Override
public List<TempFileRecordDto> queryAll(TempFileRecordQueryCriteria criteria){ public List<TempFileRecordDto> queryAll(TempFileRecordQueryCriteria criteria) {
return tempFileRecordMapper.toDto(tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); return tempFileRecordMapper.toDto(tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
} }
@Override @Override
@Transactional @Transactional
public TempFileRecordDto findById(Integer id) { public TempFileRecordDto findById(Integer id) {
TempFileRecord tempFileRecord = tempFileRecordRepository.findById(id).orElseGet(TempFileRecord::new); 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); return tempFileRecordMapper.toDto(tempFileRecord);
} }
@ -86,7 +100,7 @@ public class TempFileRecordServiceImpl implements TempFileRecordService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(TempFileRecord resources) { public void update(TempFileRecord resources) {
TempFileRecord tempFileRecord = tempFileRecordRepository.findById(resources.getId()).orElseGet(TempFileRecord::new); 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); tempFileRecord.copy(resources);
tempFileRecordRepository.save(tempFileRecord); tempFileRecordRepository.save(tempFileRecord);
} }
@ -102,7 +116,7 @@ public class TempFileRecordServiceImpl implements TempFileRecordService {
public void download(List<TempFileRecordDto> all, HttpServletResponse response) throws IOException { public void download(List<TempFileRecordDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
for (TempFileRecordDto tempFileRecord : all) { for (TempFileRecordDto tempFileRecord : all) {
Map<String,Object> map = new LinkedHashMap<>(); Map<String, Object> map = new LinkedHashMap<>();
map.put("访问接口的ip地址记录", tempFileRecord.getIpAddrs()); map.put("访问接口的ip地址记录", tempFileRecord.getIpAddrs());
map.put("文件生成地址", tempFileRecord.getFilePaths()); map.put("文件生成地址", tempFileRecord.getFilePaths());
map.put("访问文件验证码", tempFileRecord.getVerificationCode()); map.put("访问文件验证码", tempFileRecord.getVerificationCode());
@ -122,7 +136,7 @@ public class TempFileRecordServiceImpl implements TempFileRecordService {
@Override @Override
public long batchUpdate(List<TempFileRecordDto> TempFileRecordDto) { public long batchUpdate(List<TempFileRecordDto> TempFileRecordDto) {
TempFileRecordDto.forEach( TempFileRecordDto.forEach(
each->{ each -> {
TempFileRecord tempFileRecord = new TempFileRecord(); TempFileRecord tempFileRecord = new TempFileRecord();
BeanUtil.copyProperties(each, tempFileRecord); BeanUtil.copyProperties(each, tempFileRecord);
update(tempFileRecord); update(tempFileRecord);
@ -130,4 +144,55 @@ public class TempFileRecordServiceImpl implements TempFileRecordService {
); );
return TempFileRecordDto.size(); return TempFileRecordDto.size();
} }
@Override
public ResponseEntity<Object> 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<Object> 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<Object> 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);
}
} }

@ -1,9 +1,9 @@
#配置数据源 #配置数据源
spring: spring:
shardingsphere: shardingsphere:
# props: # props:
# sql: # sql:
# show: true # show: true
datasource: datasource:
names: eladmin,schema names: eladmin,schema
eladmin: eladmin:
@ -246,3 +246,6 @@ remote:
file-base-path-linux: /home/eladmin/file/temp/ file-base-path-linux: /home/eladmin/file/temp/
file-base-path-windows: C:\eladmin\file\temp\ file-base-path-windows: C:\eladmin\file\temp\
file-base-path-mac: ~/file/eladmin/temp/ file-base-path-mac: ~/file/eladmin/temp/
tempFileRecord:
link:
address: 'http://116.62.197.152:8000/api/tempFileRecord/downloadFile'

@ -25,7 +25,7 @@ spring:
order_inserts: true order_inserts: true
order_updates: true order_updates: true
open-in-view: true open-in-view: true
# show-sql: true # show-sql: true
redis: redis:
#数据库索引 #数据库索引
database: 0 database: 0
@ -34,7 +34,6 @@ spring:
password: password:
#连接超时时间 #连接超时时间
timeout: 5000 timeout: 5000
task: task:
pool: pool:
# 核心线程池大小 # 核心线程池大小

@ -129,7 +129,6 @@
</dependency> </dependency>
<!-- 生成代码时候进行注释 --> <!-- 生成代码时候进行注释 -->
<dependency> <dependency>
<groupId>org.apache.shardingSphere</groupId> <groupId>org.apache.shardingSphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId> <artifactId>sharding-jdbc-spring-boot-starter</artifactId>

Loading…
Cancel
Save