| 说明 | 请求信息 |
| **接口地址** | http://sf.mgt.itheima.net/api/insurance-mgt/safeguard/page/{pageNum}/{pageSize} |
| **请求方式** | POST |
| **请求参数** | SafeguardVO 对应的数据结构如:{pageSize: 10, total: 1, pageNum: 1, safeguardKey: "", safeguardKeyName: "身故保险金"} |
| **响应结果** | ResponseResult { "code": 200, "msg": "操作成功", "data": { "records": [ { "id": "1753336375152783362", "createTime": "2024-02-02 16:35:42", "updateTime": "2024-05-13 18:44:03", "createBy": "1371500419615895553", "updateBy": "1371500419615895553", "dataState": "0", "creator": null, "safeguardKey": "BZ056", "safeguardKeyName": "身故保险金", "safeguardVal": "[{\"val\": \"1\", \"name\": \"详见保险条款\", \"score\": \"100\"}]", "safeguardType": "0", "sortNo": null, "remake": null, "checkedIds": null } ], "total": 1, "size": 10, "current": 1, "orders": [], "optimizeCountSql": true, "hitCount": false, "countId": null, "maxLimit": null, "searchCount": true, "pages": 1 }, "operatorId": 1371500419615895553, "operatorName": "admin@qq.com", "operatorSex": "0", "_class": "com.baomidou.mybatisplus.extension.plugins.pagination.Page", "tip": "本站点所有接口仅用于教学演示,所有数据均非真实数据,请勿用作其它用途!", "operationTime": "2024-05-13 18:44:03" } |
| 说明 | 请求信息 |
| **接口地址** | http://sf.mgt.itheima.net/api/insurance-mgt/safeguard |
| **请求方式** | PUT ---> 全量更新,如果不存在则新增 |
| **请求参数** | { "safeguardKeyName": "test111", "safeguardKey": "111", "safeguardVal": "[{\"name\":\"111\",\"val\":\"11\",\"score\":\"1\"}]", "safeguardType": "1", "icon": "", "dataState": "0", "resourceType": "F" } |
| **响应结果** | ResponseResult { "code": 200, "msg": "操作成功", "data": { "id": "1789999088167677954", "createTime": "2024-05-13 20:40:13", "updateTime": "2024-05-13 20:40:13", "createBy": "1371500419615895553", "updateBy": "1371500419615895553", "dataState": "0", "creator": null, "safeguardKey": "111", "safeguardKeyName": "test111", "safeguardVal": "[{\"name\":\"111\",\"val\":\"11\",\"score\":\"1\"}]", "safeguardType": "1", "sortNo": null, "remake": null, "checkedIds": null }, "operatorId": 1371500419615895553, "operatorName": "admin@qq.com", "operatorSex": "0", "_class": "com.itheima.sfbx.insurance.dto.SafeguardVO", "tip": "本站点所有接口仅用于教学演示,所有数据均非真实数据,请勿用作其它用途!", "operationTime": "2024-05-13 20:40:13" } |
| 说明 | 请求信息 |
| **接口地址** | http://sf.mgt.itheima.net/api/insurance-mgt/safeguard |
| **请求方式** | PATCH ---》部分更新,不存在的话更新失败 |
| **请求参数** | SafeguardVO 数据结构参考如下: { "id": "1789999088167677954", "createTime": "2024-05-13 20:40:14", "updateTime": "2024-05-13 20:40:14", "createBy": "1371500419615895553", "updateBy": "1371500419615895553", "dataState": "0", "creator": null, "safeguardKey": "111", "safeguardKeyName": "test1112", "safeguardVal": "[{\"val\":\"11\",\"name\":\"111\",\"score\":\"1\"}]", "safeguardType": "1", "sortNo": null, "remake": null, "checkedIds": null } |
| **响应结果** | ResponseResult { "code": 200, "msg": "操作成功", "data": true, "operatorId": 1371500419615895553, "operatorName": "admin@qq.com", "operatorSex": "0", "_class": "java.lang.Boolean", "tip": "本站点所有接口仅用于教学演示,所有数据均非真实数据,请勿用作其它用途!", "operationTime": "2024-05-13 20:45:02" } |
| 说明 | 请求信息 |
| **接口地址** | http://sf.mgt.itheima.net/api/insurance-mgt/safeguard |
| **请求方式** | DELETE |
| **请求参数** | SafeguardVO 只传递了要删除的Id数组;数据结构参考:{checkedIds: ["1789999088167677954"]} |
| **响应结果** | ResponseResult { "code": 200, "msg": "操作成功", "data": true, "operatorId": 1371500419615895553, "operatorName": "admin@qq.com", "operatorSex": "0", "_class": "java.lang.Boolean", "tip": "本站点所有接口仅用于教学演示,所有数据均非真实数据,请勿用作其它用途!", "operationTime": "2024-05-13 21:04:36" } |
| 说明 | 请求信息 |
| 接口地址 | http://sf.mgt.itheima.net/api/insurance-mgt/coefficent/page/{pageNum}/{pageSize} |
| **请求方式** | POST |
| **请求参数** | CoefficentVO 对应的数据结构如: {pageSize: 10, total: 15, pageNum: 1, coefficentKey: "", coefficentKeyName: "投保人数", insuranceType: ""} |
| **响应结果** | ResponseResult { "code": 200, "msg": "操作成功", "data": { "records": [ { "id": "1718453920591900673", "createTime": "2023-10-29 10:25:17", "updateTime": "2023-11-30 16:40:55", "createBy": "1371500419615895553", "updateBy": "1371500419615895553", "dataState": "0", "creator": null, "coefficentKey": "XS016", "coefficentKeyName": "投保人数", "coefficentVal": "[{\"end\": \"\", \"start\": \"\", \"endUnit\": \"\", \"startUnit\": \"\"}]", "sortNo": 0, "remake": null, "coefficentType": "1", "checkedIds": null } ], "total": 1, "size": 10, "current": 1, "orders": [], "optimizeCountSql": true, "hitCount": false, "countId": null, "maxLimit": null, "searchCount": true, "pages": 1 }, "operatorId": 1371500419615895553, "operatorName": "admin@qq.com", "operatorSex": "0", "_class": "com.baomidou.mybatisplus.extension.plugins.pagination.Page", "tip": "本站点所有接口仅用于教学演示,所有数据均非真实数据,请勿用作其它用途!", "operationTime": "2024-05-15 18:11:12" } |
| 说明 | 请求信息 |
| **接口地址** | http://sf.mgt.itheima.net/api/insurance-mgt/coefficent |
| **请求方式** | PUT |
| **请求参数** | { "coefficentKeyName": "test系数名称", "coefficentKey": "123", "dataState": "0", "coefficentType": "1", "sortNo": 0, "coefficentVal": "[{\"start\":\"\",\"startUnit\":\"\",\"end\":\"\",\"endUnit\":\"\"}]" } |
| **响应结果** | ResponseResult { "code": 200, "msg": "操作成功", "data": { "id": "1790686821181591553", "createTime": "2024-05-15 18:13:02", "updateTime": "2024-05-15 18:13:02", "createBy": "1371500419615895553", "updateBy": "1371500419615895553", "dataState": "0", "creator": null, "coefficentKey": "123", "coefficentKeyName": "test系数名称", "coefficentVal": "[{\"start\":\"\",\"startUnit\":\"\",\"end\":\"\",\"endUnit\":\"\"}]", "sortNo": 0, "remake": null, "coefficentType": "1", "checkedIds": null }, "operatorId": 1371500419615895553, "operatorName": "admin@qq.com", "operatorSex": "0", "_class": "com.itheima.sfbx.insurance.dto.CoefficentVO", "tip": "本站点所有接口仅用于教学演示,所有数据均非真实数据,请勿用作其它用途!", "operationTime": "2024-05-15 18:13:02" } |
| 说明 | 请求信息 |
| **接口地址** | http://sf.mgt.itheima.net/api/insurance-mgt/cofficent |
| **请求方式** | PATCH |
| **请求参数** | CoefficentVO数据结构参考如下: { "id": "1790686821181591553", "createTime": "2024-05-15 18:13:02", "updateTime": "2024-05-15 18:13:02", "createBy": "1371500419615895553", "updateBy": "1371500419615895553", "dataState": "0", "creator": null, "coefficentKey": "123", "coefficentKeyName": "test系数名称22", "coefficentVal": "[{\"end\":\"\",\"start\":\"\",\"endUnit\":\"\",\"startUnit\":\"\"}]", "sortNo": 0, "remake": null, "coefficentType": "1", "checkedIds": null } |
| **响应结果** | ResponseResult { "code": 200, "msg": "操作成功", "data": true, "operatorId": 13715004196158955xx, "operatorName": "admin@qq.com", "operatorSex": "0", "_class": "java.lang.Boolean", "tip": "本站点所有接口仅用于教学演示,所有数据均非真实数据,请勿用作其它用途!", "operationTime": "2024-05-13 20:45:12" } |
| 说明 | 请求信息 |
| **接口地址** | http://sf.mgt.itheima.net/api/insurance-mgt/coefficent |
| **请求方式** | DELETE |
| **请求参数** | CoefficentVO 只传递了要删除的Id数组;数据结构参考:{checkedIds: ["1790686821181591553"]} |
| **响应结果** | ResponseResult { "code": 200, "msg": "操作成功", "data": true, "operatorId": 13715004196158955yy, "operatorName": "admin@qq.com", "operatorSex": "0", "_class": "java.lang.Boolean", "tip": "本站点所有接口仅用于教学演示,所有数据均非真实数据,请勿用作其它用途!", "operationTime": "2024-05-13 21:04:46" } |
| 说明 | 请求信息 |
| 接口地址 | http://sf.mgt.itheima.net/api/insurance-mgt/safeguard/list |
| **请求方式** | POST |
| **请求参数** | 无 |
| **响应结果** | ResponseResult
|
+ * Qiniu服务配置类 + *
+ * 声明创建Qiniu核心配置对象 + */ +@Slf4j +@Configuration +@EnableConfigurationProperties(QiniuProperties.class) +public class QiniuConfig { + + @Autowired + private QiniuProperties qiniuConfigProperties; + + private static Map+ * 七牛服务区域标识 + *
+ * 此标识是由七牛的kodo对象存储中定义,参考 {@link Region} + */ + public interface QiniuRegion { + + /** + * z0 华东 + */ + String REGION_HUADONG = "z0"; + /** + * z1 华北 + */ + String REGION_HUABEI = "z1"; + /** + * z2 华南 + */ + String REGION_HUANAN = "z2"; + /** + * na0 北美 + */ + String REGION_BEIMEI = "na0"; + /** + * as0 东南亚 + */ + String REGION_DONGNANYA = "as0"; + } + +} diff --git a/day02/sfbx-file/file-web/src/main/java/com/itheima/sfbx/file/handler/qiniu/impl/KodoFileStorageHandlerImpl.java b/day02/sfbx-file/file-web/src/main/java/com/itheima/sfbx/file/handler/qiniu/impl/KodoFileStorageHandlerImpl.java new file mode 100644 index 0000000..687c41a --- /dev/null +++ b/day02/sfbx-file/file-web/src/main/java/com/itheima/sfbx/file/handler/qiniu/impl/KodoFileStorageHandlerImpl.java @@ -0,0 +1,169 @@ +package com.itheima.sfbx.file.handler.qiniu.impl; + +import com.aliyun.oss.ClientException; +import com.google.common.io.ByteStreams; +import com.google.gson.Gson; +import com.itheima.sfbx.file.handler.qiniu.properties.QiniuProperties; +import com.itheima.sfbx.framework.commons.enums.file.FileEnum; +import com.itheima.sfbx.framework.commons.exception.ProjectException; +import com.itheima.sfbx.framework.commons.utils.EmptyUtil; +import com.itheima.sfbx.file.handler.AbsFileStorageHandler; +import com.itheima.sfbx.file.handler.FileStorageHandler; +import com.itheima.sfbx.file.pojo.File; +import com.qiniu.common.QiniuException; +import com.qiniu.http.Response; +import com.qiniu.storage.BucketManager; +import com.qiniu.storage.Configuration; +import com.qiniu.storage.DownloadUrl; +import com.qiniu.storage.UploadManager; +import com.qiniu.storage.model.BatchStatus; +import com.qiniu.storage.model.DefaultPutRet; +import com.qiniu.util.Auth; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.List; + +/** + * @ClassName OssFileStorageHandlerImpl.java + * @Description 七牛云文件上传 + */ +@Slf4j +@Service("kodoFileStorageHandler") +public class KodoFileStorageHandlerImpl extends AbsFileStorageHandler implements FileStorageHandler { + + @Autowired + private Auth qiniuAuth; + + @Autowired + private Configuration qiniuConfiguration; + + @Autowired + private BucketManager bucketManager; + + @Autowired + QiniuProperties qiniuConfigProperties; + + @Override + public String uploadFile(String suffix, String filename, String bucketName, boolean autoCatalog, InputStream inputStream) { + if (EmptyUtil.isNullOrEmpty(bucketName)){ + bucketName=qiniuConfigProperties.getKodo().getBucketName(); + } + String pathUrl = null; + // 是否自动生成存储路径并设置文件路径和名称(Key) + String key = autoCatalog?builderOssPath(filename):filename; + log.info("七牛Kodo文件上传开始:{}", key); + try { + String upToken = qiniuAuth.uploadToken(bucketName); + String mimeType = metaMimeTypeMap.get(suffix); + UploadManager uploadManager = new UploadManager(qiniuConfiguration); + Response response = uploadManager.put(inputStream, key, upToken, null, mimeType); + //解析上传成功的结果 + DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class); + if (!(StringUtils.isEmpty(putRet.key))) { + log.info("七牛Kodo文件上传成功:{}", putRet.key); + pathUrl = putRet.key; + } + } catch (QiniuException oe) { + log.error("七牛Kodo文件上传错误:{}", oe); + throw new ProjectException(FileEnum.UPLOAD_FAIL); + } catch (ClientException ce) { + log.error("七牛Kodo文件上传客户端错误:{}", ce); + throw new ProjectException(FileEnum.UPLOAD_FAIL); + } + return pathUrl; + } + + @Override + public File initiateMultipartUpload(String suffix, String filename, String bucketName, boolean autoCatalog) { + return null; + } + + @Override + public String uploadPart(String uploadId, String filename, int partNumber, long partSize, String bucketName, InputStream inputStream) { + return null; + } + + @Override + public String completeMultipartUpload(String uploadId, List+ * 获得资源文件完整路径地址上下文对象 + * 如果添加了新的对象存储资源,需要在此类中对 initMap 方法添加新的路径前缀 + *
+ * + * @Description: + */ +@Component +public class FileUrlContext { + + @Autowired + private OssAliyunConfigProperties ossAliyunConfigProperties; + + @Autowired + private QiniuProperties qiniuProperties; + + private static Map