diff --git a/nladmin-system/src/main/resources/config/application.yml b/nladmin-system/src/main/resources/config/application.yml index 62a49efae..dac2e02cb 100644 --- a/nladmin-system/src/main/resources/config/application.yml +++ b/nladmin-system/src/main/resources/config/application.yml @@ -73,4 +73,6 @@ security: - /druid/** # actuator 监控配置 - /actuator - - /actuator/** \ No newline at end of file + - /actuator/** + # 上传 + - /api/localStorage/pictures \ No newline at end of file diff --git a/nladmin-tools/src/main/java/org/nl/domain/QiniuConfig.java b/nladmin-tools/src/main/java/org/nl/domain/QiniuConfig.java deleted file mode 100644 index 6e4b6534c..000000000 --- a/nladmin-tools/src/main/java/org/nl/domain/QiniuConfig.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 org.nl.domain; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - -/** - * 七牛云对象存储配置类 - * @author Zheng Jie - * @date 2018-12-31 - */ -@Data -@Entity -@Table(name = "tool_qiniu_config") -public class QiniuConfig implements Serializable { - - @Id - @Column(name = "config_id") - @ApiModelProperty(value = "ID") - private Long id; - - @NotBlank - @ApiModelProperty(value = "accessKey") - private String accessKey; - - @NotBlank - @ApiModelProperty(value = "secretKey") - private String secretKey; - - @NotBlank - @ApiModelProperty(value = "存储空间名称作为唯一的 Bucket 识别符") - private String bucket; - - /** - * Zone表示与机房的对应关系 - * 华东 Zone.zone0() - * 华北 Zone.zone1() - * 华南 Zone.zone2() - * 北美 Zone.zoneNa0() - * 东南亚 Zone.zoneAs0() - */ - @NotBlank - @ApiModelProperty(value = "Zone表示与机房的对应关系") - private String zone; - - @NotBlank - @ApiModelProperty(value = "外链域名,可自定义,需在七牛云绑定") - private String host; - - @ApiModelProperty(value = "空间类型:公开/私有") - private String type = "公开"; -} diff --git a/nladmin-tools/src/main/java/org/nl/domain/QiniuContent.java b/nladmin-tools/src/main/java/org/nl/domain/QiniuContent.java deleted file mode 100644 index 21d8b351a..000000000 --- a/nladmin-tools/src/main/java/org/nl/domain/QiniuContent.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 org.nl.domain; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import org.hibernate.annotations.UpdateTimestamp; -import javax.persistence.*; -import java.io.Serializable; -import java.sql.Timestamp; - -/** - * 上传成功后,存储结果 - * @author Zheng Jie - * @date 2018-12-31 - */ -@Data -@Entity -@Table(name = "tool_qiniu_content") -public class QiniuContent implements Serializable { - - @Id - @Column(name = "content_id") - @ApiModelProperty(value = "ID", hidden = true) - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(name = "name") - @ApiModelProperty(value = "文件名") - private String key; - - @ApiModelProperty(value = "空间名") - private String bucket; - - @ApiModelProperty(value = "大小") - private String size; - - @ApiModelProperty(value = "文件地址") - private String url; - - @ApiModelProperty(value = "文件类型") - private String suffix; - - @ApiModelProperty(value = "空间类型:公开/私有") - private String type = "公开"; - - @UpdateTimestamp - @ApiModelProperty(value = "创建或更新时间") - @Column(name = "update_time") - private Timestamp updateTime; -} diff --git a/nladmin-tools/src/main/java/org/nl/domain/vo/TradeVo.java b/nladmin-tools/src/main/java/org/nl/domain/vo/TradeVo.java deleted file mode 100644 index b4f622aac..000000000 --- a/nladmin-tools/src/main/java/org/nl/domain/vo/TradeVo.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 org.nl.domain.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import javax.validation.constraints.NotBlank; -import java.sql.Date; -import java.sql.Timestamp; - -/** - * 交易详情,按需应该存入数据库,这里存入数据库,仅供临时测试 - * @author Zheng Jie - * @date 2018-12-31 - */ -@Data -public class TradeVo { - - /** (必填)商品描述 */ - @NotBlank - private String body; - - /** (必填)商品名称 */ - @NotBlank - private String subject; - - /** (必填)商户订单号,应该由后台生成 */ - @ApiModelProperty(hidden = true) - private String outTradeNo; - - /** (必填)第三方订单号 */ - @ApiModelProperty(hidden = true) - private String tradeNo; - - /** (必填)价格 */ - @NotBlank - private String totalAmount; - - /** 订单状态,已支付,未支付,作废 */ - @ApiModelProperty(hidden = true) - private String state; - - /** 创建时间,存入数据库时需要 */ - @ApiModelProperty(hidden = true) - private Timestamp createTime; - - /** 作废时间,存入数据库时需要 */ - @ApiModelProperty(hidden = true) - private Date cancelTime; -} diff --git a/nladmin-tools/src/main/java/org/nl/repository/QiNiuConfigRepository.java b/nladmin-tools/src/main/java/org/nl/repository/QiNiuConfigRepository.java deleted file mode 100644 index 6100fc00f..000000000 --- a/nladmin-tools/src/main/java/org/nl/repository/QiNiuConfigRepository.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 org.nl.repository; - -import org.nl.domain.QiniuConfig; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -/** - * @author Zheng Jie - * @date 2018-12-31 - */ -public interface QiNiuConfigRepository extends JpaRepository { - - /** - * 编辑类型 - * @param type - */ - @Modifying - @Query(value = "update QiniuConfig set type = ?1") - void update(String type); -} diff --git a/nladmin-tools/src/main/java/org/nl/repository/QiniuContentRepository.java b/nladmin-tools/src/main/java/org/nl/repository/QiniuContentRepository.java deleted file mode 100644 index 1b03085bf..000000000 --- a/nladmin-tools/src/main/java/org/nl/repository/QiniuContentRepository.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 org.nl.repository; - -import org.nl.domain.QiniuContent; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -/** - * @author Zheng Jie - * @date 2018-12-31 - */ -public interface QiniuContentRepository extends JpaRepository, JpaSpecificationExecutor { - - /** - * 根据key查询 - * @param key 文件名 - * @return QiniuContent - */ - QiniuContent findByKey(String key); -} diff --git a/nladmin-tools/src/main/java/org/nl/rest/QiniuController.java b/nladmin-tools/src/main/java/org/nl/rest/QiniuController.java deleted file mode 100644 index 5aba6b929..000000000 --- a/nladmin-tools/src/main/java/org/nl/rest/QiniuController.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 org.nl.rest; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.annotation.Log; -import org.nl.domain.QiniuConfig; -import org.nl.domain.QiniuContent; -import org.nl.service.dto.QiniuQueryCriteria; -import org.nl.service.QiNiuService; -import org.springframework.data.domain.Pageable; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -/** - * 发送邮件 - * @author 郑杰 - * @date 2018/09/28 6:55:53 - */ -@Slf4j -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/qiNiuContent") -@Api(tags = "工具:七牛云存储管理") -public class QiniuController { - - private final QiNiuService qiNiuService; - - @GetMapping(value = "/config") - public ResponseEntity queryConfig(){ - return new ResponseEntity<>(qiNiuService.find(), HttpStatus.OK); - } - - @Log("配置七牛云存储") - @ApiOperation("配置七牛云存储") - @PutMapping(value = "/config") - public ResponseEntity updateConfig(@Validated @RequestBody QiniuConfig qiniuConfig){ - qiNiuService.config(qiniuConfig); - qiNiuService.update(qiniuConfig.getType()); - return new ResponseEntity<>(HttpStatus.OK); - } - - @ApiOperation("导出数据") - @GetMapping(value = "/download") - public void download(HttpServletResponse response, QiniuQueryCriteria criteria) throws IOException { - qiNiuService.downloadList(qiNiuService.queryAll(criteria), response); - } - - @ApiOperation("查询文件") - @GetMapping - public ResponseEntity query(QiniuQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(qiNiuService.queryAll(criteria,pageable),HttpStatus.OK); - } - - @Log("上传文件") - @ApiOperation("上传文件") - @PostMapping - public ResponseEntity upload(@RequestParam MultipartFile file){ - QiniuContent qiniuContent = qiNiuService.upload(file,qiNiuService.find()); - Map map = new HashMap<>(3); - map.put("id",qiniuContent.getId()); - map.put("errno",0); - map.put("data",new String[]{qiniuContent.getUrl()}); - return new ResponseEntity<>(map,HttpStatus.OK); - } - - @Log("同步七牛云数据") - @ApiOperation("同步七牛云数据") - @PostMapping(value = "/synchronize") - public ResponseEntity synchronize(){ - qiNiuService.synchronize(qiNiuService.find()); - return new ResponseEntity<>(HttpStatus.OK); - } - - @Log("下载文件") - @ApiOperation("下载文件") - @GetMapping(value = "/download/{id}") - public ResponseEntity download(@PathVariable Long id){ - Map map = new HashMap<>(1); - map.put("url", qiNiuService.download(qiNiuService.findByContentId(id),qiNiuService.find())); - return new ResponseEntity<>(map,HttpStatus.OK); - } - - @Log("删除文件") - @ApiOperation("删除文件") - @DeleteMapping(value = "/{id}") - public ResponseEntity delete(@PathVariable Long id){ - qiNiuService.delete(qiNiuService.findByContentId(id),qiNiuService.find()); - return new ResponseEntity<>(HttpStatus.OK); - } - - @Log("删除多张图片") - @ApiOperation("删除多张图片") - @DeleteMapping - public ResponseEntity deleteAll(@RequestBody Long[] ids) { - qiNiuService.deleteAll(ids, qiNiuService.find()); - return new ResponseEntity<>(HttpStatus.OK); - } -} diff --git a/nladmin-tools/src/main/java/org/nl/service/QiNiuService.java b/nladmin-tools/src/main/java/org/nl/service/QiNiuService.java deleted file mode 100644 index 386b33f7b..000000000 --- a/nladmin-tools/src/main/java/org/nl/service/QiNiuService.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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 org.nl.service; - -import org.nl.domain.QiniuConfig; -import org.nl.domain.QiniuContent; -import org.nl.service.dto.QiniuQueryCriteria; -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; - -/** - * @author Zheng Jie - * @date 2018-12-31 - */ -public interface QiNiuService { - - /** - * 查配置 - * @return QiniuConfig - */ - QiniuConfig find(); - - /** - * 修改配置 - * @param qiniuConfig 配置 - * @return QiniuConfig - */ - QiniuConfig config(QiniuConfig qiniuConfig); - - /** - * 分页查询 - * @param criteria 条件 - * @param pageable 分页参数 - * @return / - */ - Object queryAll(QiniuQueryCriteria criteria, Pageable pageable); - - /** - * 查询全部 - * @param criteria 条件 - * @return / - */ - List queryAll(QiniuQueryCriteria criteria); - - /** - * 上传文件 - * @param file 文件 - * @param qiniuConfig 配置 - * @return QiniuContent - */ - QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig); - - /** - * 查询文件 - * @param id 文件ID - * @return QiniuContent - */ - QiniuContent findByContentId(Long id); - - /** - * 下载文件 - * @param content 文件信息 - * @param config 配置 - * @return String - */ - String download(QiniuContent content, QiniuConfig config); - - /** - * 删除文件 - * @param content 文件 - * @param config 配置 - */ - void delete(QiniuContent content, QiniuConfig config); - - /** - * 同步数据 - * @param config 配置 - */ - void synchronize(QiniuConfig config); - - /** - * 删除文件 - * @param ids 文件ID数组 - * @param config 配置 - */ - void deleteAll(Long[] ids, QiniuConfig config); - - /** - * 更新数据 - * @param type 类型 - */ - void update(String type); - - /** - * 导出数据 - * @param queryAll / - * @param response / - * @throws IOException / - */ - void downloadList(List queryAll, HttpServletResponse response) throws IOException; -} diff --git a/nladmin-tools/src/main/java/org/nl/service/dto/PictureQueryCriteria.java b/nladmin-tools/src/main/java/org/nl/service/dto/PictureQueryCriteria.java deleted file mode 100644 index 900690f1c..000000000 --- a/nladmin-tools/src/main/java/org/nl/service/dto/PictureQueryCriteria.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 org.nl.service.dto; - -import lombok.Data; -import org.nl.annotation.Query; - -import java.sql.Timestamp; -import java.util.List; - -/** - * sm.ms图床 - * - * @author Zheng Jie - * @date 2019-6-4 09:52:09 - */ -@Data -public class PictureQueryCriteria{ - - @Query(type = Query.Type.INNER_LIKE) - private String filename; - - @Query(type = Query.Type.INNER_LIKE) - private String username; - - @Query(type = Query.Type.BETWEEN) - private List createTime; -} diff --git a/nladmin-tools/src/main/java/org/nl/service/dto/QiniuQueryCriteria.java b/nladmin-tools/src/main/java/org/nl/service/dto/QiniuQueryCriteria.java deleted file mode 100644 index fcf72a187..000000000 --- a/nladmin-tools/src/main/java/org/nl/service/dto/QiniuQueryCriteria.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 org.nl.service.dto; - -import lombok.Data; -import org.nl.annotation.Query; - -import java.sql.Timestamp; -import java.util.List; - -/** - * @author Zheng Jie - * @date 2019-6-4 09:54:37 - */ -@Data -public class QiniuQueryCriteria{ - - @Query(type = Query.Type.INNER_LIKE) - private String key; - - @Query(type = Query.Type.BETWEEN) - private List createTime; -} diff --git a/nladmin-tools/src/main/java/org/nl/service/impl/QiNiuServiceImpl.java b/nladmin-tools/src/main/java/org/nl/service/impl/QiNiuServiceImpl.java deleted file mode 100644 index c9e854a9f..000000000 --- a/nladmin-tools/src/main/java/org/nl/service/impl/QiNiuServiceImpl.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * 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 org.nl.service.impl; - -import com.alibaba.fastjson.JSON; -import com.qiniu.common.QiniuException; -import com.qiniu.http.Response; -import com.qiniu.storage.BucketManager; -import com.qiniu.storage.Configuration; -import com.qiniu.storage.UploadManager; -import com.qiniu.storage.model.DefaultPutRet; -import com.qiniu.storage.model.FileInfo; -import com.qiniu.util.Auth; -import lombok.RequiredArgsConstructor; -import org.nl.domain.QiniuConfig; -import org.nl.domain.QiniuContent; -import org.nl.repository.QiniuContentRepository; -import org.nl.service.dto.QiniuQueryCriteria; -import org.nl.utils.QiNiuUtil; -import org.nl.exception.BadRequestException; -import org.nl.repository.QiNiuConfigRepository; -import org.nl.service.QiNiuService; -import org.nl.utils.FileUtil; -import org.nl.utils.PageUtil; -import org.nl.utils.QueryHelp; -import org.nl.utils.ValidationUtil; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.CachePut; -import org.springframework.cache.annotation.Cacheable; -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.*; - -/** - * @author Zheng Jie - * @date 2018-12-31 - */ -@Service -@RequiredArgsConstructor -@CacheConfig(cacheNames = "qiNiu") -public class QiNiuServiceImpl implements QiNiuService { - - private final QiNiuConfigRepository qiNiuConfigRepository; - private final QiniuContentRepository qiniuContentRepository; - - @Value("${qiniu.max-size}") - private Long maxSize; - - @Override - @Cacheable(key = "'config'") - public QiniuConfig find() { - Optional qiniuConfig = qiNiuConfigRepository.findById(1L); - return qiniuConfig.orElseGet(QiniuConfig::new); - } - - @Override - @CachePut(key = "'config'") - @Transactional(rollbackFor = Exception.class) - public QiniuConfig config(QiniuConfig qiniuConfig) { - qiniuConfig.setId(1L); - String http = "http://", https = "https://"; - if (!(qiniuConfig.getHost().toLowerCase().startsWith(http)||qiniuConfig.getHost().toLowerCase().startsWith(https))) { - throw new BadRequestException("外链域名必须以http://或者https://开头"); - } - return qiNiuConfigRepository.save(qiniuConfig); - } - - @Override - public Object queryAll(QiniuQueryCriteria criteria, Pageable pageable){ - return PageUtil.toPage(qiniuContentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable)); - } - - @Override - public List queryAll(QiniuQueryCriteria criteria) { - return qiniuContentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig) { - FileUtil.checkSize(maxSize, file.getSize()); - if(qiniuConfig.getId() == null){ - throw new BadRequestException("请先添加相应配置,再操作"); - } - // 构造一个带指定Zone对象的配置类 - Configuration cfg = new Configuration(QiNiuUtil.getRegion(qiniuConfig.getZone())); - UploadManager uploadManager = new UploadManager(cfg); - Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey()); - String upToken = auth.uploadToken(qiniuConfig.getBucket()); - try { - String key = file.getOriginalFilename(); - if(qiniuContentRepository.findByKey(key) != null) { - key = QiNiuUtil.getKey(key); - } - Response response = uploadManager.put(file.getBytes(), key, upToken); - //解析上传成功的结果 - - DefaultPutRet putRet = JSON.parseObject(response.bodyString(), DefaultPutRet.class); - QiniuContent content = qiniuContentRepository.findByKey(FileUtil.getFileNameNoEx(putRet.key)); - if(content == null){ - //存入数据库 - QiniuContent qiniuContent = new QiniuContent(); - qiniuContent.setSuffix(FileUtil.getExtensionName(putRet.key)); - qiniuContent.setBucket(qiniuConfig.getBucket()); - qiniuContent.setType(qiniuConfig.getType()); - qiniuContent.setKey(FileUtil.getFileNameNoEx(putRet.key)); - qiniuContent.setUrl(qiniuConfig.getHost()+"/"+putRet.key); - qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(file.getSize()+""))); - return qiniuContentRepository.save(qiniuContent); - } - return content; - } catch (Exception e) { - throw new BadRequestException(e.getMessage()); - } - } - - @Override - public QiniuContent findByContentId(Long id) { - QiniuContent qiniuContent = qiniuContentRepository.findById(id).orElseGet(QiniuContent::new); - ValidationUtil.isNull(qiniuContent.getId(),"QiniuContent", "id",id); - return qiniuContent; - } - - @Override - public String download(QiniuContent content,QiniuConfig config){ - String finalUrl; - String type = "公开"; - if(type.equals(content.getType())){ - finalUrl = content.getUrl(); - } else { - Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey()); - // 1小时,可以自定义链接过期时间 - long expireInSeconds = 3600; - finalUrl = auth.privateDownloadUrl(content.getUrl(), expireInSeconds); - } - return finalUrl; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(QiniuContent content, QiniuConfig config) { - //构造一个带指定Zone对象的配置类 - Configuration cfg = new Configuration(QiNiuUtil.getRegion(config.getZone())); - Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey()); - BucketManager bucketManager = new BucketManager(auth, cfg); - try { - bucketManager.delete(content.getBucket(), content.getKey() + "." + content.getSuffix()); - qiniuContentRepository.delete(content); - } catch (QiniuException ex) { - qiniuContentRepository.delete(content); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void synchronize(QiniuConfig config) { - if(config.getId() == null){ - throw new BadRequestException("请先添加相应配置,再操作"); - } - //构造一个带指定Zone对象的配置类 - Configuration cfg = new Configuration(QiNiuUtil.getRegion(config.getZone())); - Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey()); - BucketManager bucketManager = new BucketManager(auth, cfg); - //文件名前缀 - String prefix = ""; - //每次迭代的长度限制,最大1000,推荐值 1000 - int limit = 1000; - //指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串 - String delimiter = ""; - //列举空间文件列表 - BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(config.getBucket(), prefix, limit, delimiter); - while (fileListIterator.hasNext()) { - //处理获取的file list结果 - QiniuContent qiniuContent; - FileInfo[] items = fileListIterator.next(); - for (FileInfo item : items) { - if(qiniuContentRepository.findByKey(FileUtil.getFileNameNoEx(item.key)) == null){ - qiniuContent = new QiniuContent(); - qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(item.fsize+""))); - qiniuContent.setSuffix(FileUtil.getExtensionName(item.key)); - qiniuContent.setKey(FileUtil.getFileNameNoEx(item.key)); - qiniuContent.setType(config.getType()); - qiniuContent.setBucket(config.getBucket()); - qiniuContent.setUrl(config.getHost()+"/"+item.key); - qiniuContentRepository.save(qiniuContent); - } - } - } - } - - @Override - public void deleteAll(Long[] ids, QiniuConfig config) { - for (Long id : ids) { - delete(findByContentId(id), config); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(String type) { - qiNiuConfigRepository.update(type); - } - - @Override - public void downloadList(List queryAll, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (QiniuContent content : queryAll) { - Map map = new LinkedHashMap<>(); - map.put("文件名", content.getKey()); - map.put("文件类型", content.getSuffix()); - map.put("空间名称", content.getBucket()); - map.put("文件大小", content.getSize()); - map.put("空间类型", content.getType()); - map.put("创建日期", content.getUpdateTime()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } -} diff --git a/nladmin-tools/src/main/java/org/nl/utils/QiNiuUtil.java b/nladmin-tools/src/main/java/org/nl/utils/QiNiuUtil.java deleted file mode 100644 index 0669891e9..000000000 --- a/nladmin-tools/src/main/java/org/nl/utils/QiNiuUtil.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 org.nl.utils; - -import com.qiniu.storage.Region; -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * 七牛云存储工具类 - * @author Zheng Jie - * @date 2018-12-31 - */ -public class QiNiuUtil { - - private static final String HUAD = "华东"; - - private static final String HUAB = "华北"; - - private static final String HUAN = "华南"; - - private static final String BEIM = "北美"; - - /** - * 得到机房的对应关系 - * @param zone 机房名称 - * @return Region - */ - public static Region getRegion(String zone){ - - if(HUAD.equals(zone)){ - return Region.huadong(); - } else if(HUAB.equals(zone)){ - return Region.huabei(); - } else if(HUAN.equals(zone)){ - return Region.huanan(); - } else if (BEIM.equals(zone)){ - return Region.beimei(); - // 否则就是东南亚 - } else { - return Region.qvmHuadong(); - } - } - - /** - * 默认不指定key的情况下,以文件内容的hash值作为文件名 - * @param file 文件名 - * @return String - */ - public static String getKey(String file){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); - Date date = new Date(); - return FileUtil.getFileNameNoEx(file) + "-" + - sdf.format(date) + - "." + - FileUtil.getExtensionName(file); - } -} diff --git a/nladmin-ui/src/api/tools/qiniu.js b/nladmin-ui/src/api/tools/qiniu.js deleted file mode 100644 index 6d5677101..000000000 --- a/nladmin-ui/src/api/tools/qiniu.js +++ /dev/null @@ -1,40 +0,0 @@ -import request from '@/utils/request' - -export function get() { - return request({ - url: 'api/qiNiuContent/config', - method: 'get' - }) -} - -export function update(data) { - return request({ - url: 'api/qiNiuContent/config', - data, - method: 'put' - }) -} - -export function download(id) { - return request({ - url: 'api/qiNiuContent/download/' + id, - method: 'get' - }) -} - -export function sync() { - return request({ - url: 'api/qiNiuContent/synchronize', - method: 'post' - }) -} - -export function del(ids) { - return request({ - url: 'api/qiNiuContent', - method: 'delete', - data: ids - }) -} - -export default { del, download, sync } diff --git a/nladmin-ui/src/views/tools/storage/index.vue b/nladmin-ui/src/views/tools/storage/index.vue deleted file mode 100644 index 5bb3fc0a7..000000000 --- a/nladmin-ui/src/views/tools/storage/index.vue +++ /dev/null @@ -1,36 +0,0 @@ - - - - - diff --git a/nladmin-ui/src/views/tools/storage/local/index.vue b/nladmin-ui/src/views/tools/storage/local/index.vue deleted file mode 100644 index fa790e082..000000000 --- a/nladmin-ui/src/views/tools/storage/local/index.vue +++ /dev/null @@ -1,184 +0,0 @@ - - - - - diff --git a/nladmin-ui/src/views/tools/storage/qiniu/form.vue b/nladmin-ui/src/views/tools/storage/qiniu/form.vue deleted file mode 100644 index 6f2db6f31..000000000 --- a/nladmin-ui/src/views/tools/storage/qiniu/form.vue +++ /dev/null @@ -1,98 +0,0 @@ - - - - - diff --git a/nladmin-ui/src/views/tools/storage/qiniu/index.vue b/nladmin-ui/src/views/tools/storage/qiniu/index.vue deleted file mode 100644 index e5d5e652e..000000000 --- a/nladmin-ui/src/views/tools/storage/qiniu/index.vue +++ /dev/null @@ -1,193 +0,0 @@ - - - - -