SDK模块
This commit is contained in:
parent
30bee64275
commit
55a8c19a0d
@ -17,6 +17,161 @@ public enum OperationLogEnum {
|
||||
* 系统用户退出登录
|
||||
*/
|
||||
SYSTEM_LOGOUT(1, "i18n_operationLog_systemLogout", "SystemLoginModel", 6, 4),
|
||||
//10-15 OAM菜单管理
|
||||
/**
|
||||
* 新增OAM菜单
|
||||
*/
|
||||
INSERT_OAM_MENU(10, "i18n_operationLog_insertOamMenu", "OamMenuModel", 5, 3),
|
||||
/**
|
||||
* 修改OAM菜单
|
||||
*/
|
||||
UPDATE_OAM_MENU(11, "i18n_operationLog_updateOamMenu", "OamMenuModel", 5, 3),
|
||||
/**
|
||||
* 删除OAM菜单
|
||||
*/
|
||||
REMOVE_OAM_MENU(12, "i18n_operationLog_removeOamMenu", "OamMenuModel", 4, 2),
|
||||
//16-20 角色管理
|
||||
/**
|
||||
* 新增系统角色
|
||||
*/
|
||||
INSERT_OAM_ROLE(16, "i18n_operationLog_insertOamRole", "OamRoleModel", 5, 3),
|
||||
/**
|
||||
* 修改系统角色
|
||||
*/
|
||||
UPDATE_OAM_ROLE(17, "i18n_operationLog_updateOamRole", "OamRoleModel", 5, 3),
|
||||
/**
|
||||
* 删除系统角色
|
||||
*/
|
||||
REMOVE_OAM_ROLE(18, "i18n_operationLog_removeOamRole", "OamRoleModel", 4, 2),
|
||||
//21-25 部门管理
|
||||
/**
|
||||
* 新增系统部门
|
||||
*/
|
||||
INSERT_OAM_DEPT(21, "i18n_operationLog_insertOamDept", "OamDeptModel", 5, 3),
|
||||
/**
|
||||
* 修改系统部门
|
||||
*/
|
||||
UPDATE_OAM_DEPT(22, "i18n_operationLog_updateOamDept", "OamDeptModel", 5, 3),
|
||||
/**
|
||||
* 删除系统部门
|
||||
*/
|
||||
REMOVE_OAM_DEPT(23, "i18n_operationLog_removeOamDept", "OamDeptModel", 4, 2),
|
||||
//26-30 系统员工管理
|
||||
/**
|
||||
* 新增员工
|
||||
*/
|
||||
INSERT_OAM_STAFF(26, "i18n_operationLog_insertOamStaff", "OamStaffModel", 6, 4),
|
||||
/**
|
||||
* 修改系统用户
|
||||
*/
|
||||
UPDATE_OAM_STAFF(27, "i18n_operationLog_updateOamStaff", "OamStaffModel", 6, 4),
|
||||
/**
|
||||
* 删除系统用户
|
||||
*/
|
||||
REMOVE_OAM_STAFF(28, "i18n_operationLog_removeOamStaff", "OamStaffModel", 5, 3),
|
||||
/**
|
||||
* 修改系统用户密码
|
||||
*/
|
||||
MODIFY_OAM_STAFF_PASSWORD(29, "i18n_operationLog_updateOamStaffPassword", "OamStaffModel", 5, 3),
|
||||
//31-35 值班管理
|
||||
/**
|
||||
* 添加值班
|
||||
*/
|
||||
INSERT_OAM_DUTY(31,"i18n_operationLog_insertOamDuty" ,"OamDutyModel" ,6 , 4),
|
||||
/**
|
||||
* 删除值班
|
||||
*/
|
||||
REMOVE_OAM_DUTY(32,"i18n_operationLog_removeOamDuty" ,"OamDutyModel" ,6 , 4),
|
||||
//36-45 任务管理
|
||||
/**
|
||||
* 新增迭代任务
|
||||
*/
|
||||
INSERT_ITERATION_TASK(36, "i18n_operationLog_insertIterationTask", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 领取任务
|
||||
*/
|
||||
CLAIM_TASK(37, "i18n_operationLog_claimTask", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 删除任务
|
||||
*/
|
||||
REMOVE_TASK(38, "i18n_operationLog_removeTask", "OamTaskModel", 5, 3),
|
||||
/**
|
||||
* 添加任务组成员
|
||||
*/
|
||||
INSERT_TASK_STAFF_GROUP(39, "i18n_operationLog_insertTaskStaffGroup", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 更新员工绩点
|
||||
*/
|
||||
UPDATE_STAFF_GRADE_POINT(40, "i18n_operationLog_updateStaffGrandPoint", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 删除任务员工组
|
||||
*/
|
||||
REMOVE_TASK_STAFF_GROUP(41, "i18n_operationLog_removeTaskStaffGroup", "OamTaskModel", 5, 3),
|
||||
/**
|
||||
* 修改任务进度
|
||||
*/
|
||||
UPDATE_TASK_ITEM(42, "i18n_operationLog_updateTaskItem", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 转交任务负责人
|
||||
*/
|
||||
UPDATE_TASK_RESPONSIBLE_STAFF(43, "i18n_operationLog_updateTaskResponsibleStaff", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 新增投诉任务
|
||||
*/
|
||||
INSERT_DEMAND_TASK(44, "i18n_operationLog_insertDemandTask", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 设置审核意见
|
||||
*/
|
||||
SET_TASK_AUDIT_COMMENTS(45,"i18n_operationLog_setTaskAuditComments", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 完成任务
|
||||
*/
|
||||
FINISH_TASK(46,"i18n_operationLog_finishTask", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 新增工单
|
||||
*/
|
||||
INSERT_WORK_ORDER(47,"i18n_operationLog_insertWorkOrder", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 新增工单记录concludeWorkOrder
|
||||
*/
|
||||
INSERT_WORK_ORDER_RECORD(48,"i18n_operationLog_insertWorkOrderRecord", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 工单完结
|
||||
*/
|
||||
CONCLUDE_WORK_ORDER(49,"i18n_operationLog_concludeWorkOrder", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 暂停工单
|
||||
*/
|
||||
PAUSE_WORK_ORDER(50,"i18n_operationLog_concludeWorkOrder", "OamTaskModel", 6, 4),
|
||||
//60-70 报销模块
|
||||
/**
|
||||
* 添加报销申请
|
||||
*/
|
||||
INSERT_REIMBURSE_APPLICATION(60, "i18n_operationLog_concludeWorkOrder", "OamTaskModel", 6, 4),
|
||||
/**
|
||||
* 审核员工申请
|
||||
*/
|
||||
AUDIT_STAFF_APPLICATION(62, "i18n_operationLog_auditStaffApplication", "OamFinanceModel", 6, 4),
|
||||
/**
|
||||
* 报销驳回
|
||||
*/
|
||||
REIMBURSE_REJECT(63, "i18n_operationLog_reimburseReject", "OamFinanceModel", 6, 4),
|
||||
/**
|
||||
* 报销下款
|
||||
*/
|
||||
REIMBURSE_PAY(64, "i18n_operationLog_reimbursePay", "OamFinanceModel", 6, 4),
|
||||
/**
|
||||
* 添加报销类型
|
||||
*/
|
||||
INSERT_REIMBURSE_TYPE(65, "i18n_operationLog_insertReimburseType", "OamFinanceModel", 6, 4),
|
||||
/**
|
||||
* 修改报销类型
|
||||
*/
|
||||
UPDATE_REIMBURSE_TYPE(66, "i18n_operationLog_updateReimburseType", "OamFinanceModel", 6, 4),
|
||||
/**
|
||||
* 删除报销类型
|
||||
*/
|
||||
REMOVE_REIMBURSE_TYPE(67, "i18n_operationLog_removeReimburseType", "OamFinanceModel", 6, 4),
|
||||
;
|
||||
|
||||
/**
|
||||
|
||||
@ -1 +0,0 @@
|
||||
|
||||
@ -18,6 +18,10 @@
|
||||
<groupId>com.cpop</groupId>
|
||||
<artifactId>Cpop-Core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cpop</groupId>
|
||||
<artifactId>Cpop-Sdk</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@ -26,6 +26,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.mybatisflex.core.query.QueryMethods.distinct;
|
||||
import static com.mybatisflex.core.query.QueryMethods.groupConcat;
|
||||
import static com.cpop.jambox.business.entity.table.BrandStaffMidCampusTableDef.BRAND_STAFF_MID_CAMPUS;
|
||||
import static com.cpop.jambox.business.entity.table.BrandStaffTableDef.BRAND_STAFF;
|
||||
|
||||
@ -23,6 +23,10 @@
|
||||
<groupId>com.cpop</groupId>
|
||||
<artifactId>Cpop-Api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cpop</groupId>
|
||||
<artifactId>Cpop-Jambox</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@ -4,7 +4,7 @@ import com.cpop.core.utils.SpringUtils;
|
||||
import com.cpop.oam.business.entity.TaskWorkOrder;
|
||||
import com.cpop.oam.business.service.TaskService;
|
||||
import com.cpop.oam.business.service.TaskWorkOrderService;
|
||||
import com.pupu.oam.business.service.TaskStaffGroupService;
|
||||
import com.cpop.oam.business.service.TaskStaffGroupService;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
|
||||
38
Cpop-Sdk/pom.xml
Normal file
38
Cpop-Sdk/pom.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.cpop</groupId>
|
||||
<artifactId>Cpop-Union</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<artifactId>Cpop-Sdk</artifactId>
|
||||
<name>Cpop-Sdk</name>
|
||||
<description>Cpop-Sdk</description>
|
||||
|
||||
<dependencies>
|
||||
<!--核心包-->
|
||||
<dependency>
|
||||
<groupId>com.cpop</groupId>
|
||||
<artifactId>Cpop-Core</artifactId>
|
||||
</dependency>
|
||||
<!--微信小程序-->
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-miniapp</artifactId>
|
||||
</dependency>
|
||||
<!-- 腾讯云-->
|
||||
<dependency>
|
||||
<groupId>com.qcloud</groupId>
|
||||
<artifactId>cos_api</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,130 @@
|
||||
package com.cpop.sdk.framework.config;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import cn.binarywang.wx.miniapp.message.WxMaMessageHandler;
|
||||
import cn.binarywang.wx.miniapp.message.WxMaMessageRouter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxRuntimeException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(WxMaProperties.class)
|
||||
public class WxMaConfiguration {
|
||||
private final WxMaProperties properties;
|
||||
|
||||
@Autowired
|
||||
public WxMaConfiguration(WxMaProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WxMaService wxMaService() {
|
||||
List<WxMaProperties.Config> configs = this.properties.getConfigs();
|
||||
if (configs == null) {
|
||||
throw new WxRuntimeException("未配置WechatMiniApp");
|
||||
}
|
||||
WxMaService maService = new WxMaServiceImpl();
|
||||
maService.setMultiConfigs(
|
||||
configs.stream()
|
||||
.map(a -> {
|
||||
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
||||
//WxMaDefaultConfigImpl config = new WxMaRedisConfigImpl(new JedisPool());
|
||||
// 使用上面的配置时,需要同时引入jedis-lock的依赖,否则会报类无法找到的异常
|
||||
config.setAppid(a.getAppid());
|
||||
config.setSecret(a.getSecret());
|
||||
config.setToken(a.getToken());
|
||||
config.setAesKey(a.getAesKey());
|
||||
config.setMsgDataFormat(a.getMsgDataFormat());
|
||||
return config;
|
||||
}).collect(Collectors.toMap(WxMaDefaultConfigImpl::getAppid, a -> a, (o, n) -> o)));
|
||||
return maService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WxMaMessageRouter wxMaMessageRouter(WxMaService wxMaService) {
|
||||
final WxMaMessageRouter router = new WxMaMessageRouter(wxMaService);
|
||||
router
|
||||
.rule().handler(logHandler).next()
|
||||
.rule().async(false).content("订阅消息").handler(subscribeMsgHandler).end()
|
||||
.rule().async(false).content("文本").handler(textHandler).end()
|
||||
.rule().async(false).content("图片").handler(picHandler).end()
|
||||
.rule().async(false).content("二维码").handler(qrcodeHandler).end();
|
||||
return router;
|
||||
}
|
||||
|
||||
private final WxMaMessageHandler subscribeMsgHandler = (wxMessage, context, service, sessionManager) -> {
|
||||
service.getMsgService().sendSubscribeMsg(WxMaSubscribeMessage.builder()
|
||||
.templateId("此处更换为自己的模板id")
|
||||
.data(Arrays.asList(new WxMaSubscribeMessage.MsgData("keyword1", "339208499")))
|
||||
.toUser(wxMessage.getFromUser())
|
||||
.build());
|
||||
return null;
|
||||
};
|
||||
|
||||
private final WxMaMessageHandler logHandler = (wxMessage, context, service, sessionManager) -> {
|
||||
log.info("收到消息:" + wxMessage.toString());
|
||||
service.getMsgService().sendKefuMsg(WxMaKefuMessage.newTextBuilder().content("收到信息为:" + wxMessage.toJson())
|
||||
.toUser(wxMessage.getFromUser()).build());
|
||||
return null;
|
||||
};
|
||||
|
||||
private final WxMaMessageHandler textHandler = (wxMessage, context, service, sessionManager) -> {
|
||||
service.getMsgService().sendKefuMsg(WxMaKefuMessage.newTextBuilder().content("回复文本消息")
|
||||
.toUser(wxMessage.getFromUser()).build());
|
||||
return null;
|
||||
};
|
||||
|
||||
private final WxMaMessageHandler picHandler = (wxMessage, context, service, sessionManager) -> {
|
||||
try {
|
||||
WxMediaUploadResult uploadResult = service.getMediaService()
|
||||
.uploadMedia("image", "png",
|
||||
ClassLoader.getSystemResourceAsStream("tmp.png"));
|
||||
service.getMsgService().sendKefuMsg(
|
||||
WxMaKefuMessage
|
||||
.newImageBuilder()
|
||||
.mediaId(uploadResult.getMediaId())
|
||||
.toUser(wxMessage.getFromUser())
|
||||
.build());
|
||||
} catch (WxErrorException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
private final WxMaMessageHandler qrcodeHandler = (wxMessage, context, service, sessionManager) -> {
|
||||
try {
|
||||
final File file = service.getQrcodeService().createQrcode("123", 430);
|
||||
WxMediaUploadResult uploadResult = service.getMediaService().uploadMedia("image", file);
|
||||
service.getMsgService().sendKefuMsg(
|
||||
WxMaKefuMessage
|
||||
.newImageBuilder()
|
||||
.mediaId(uploadResult.getMediaId())
|
||||
.toUser(wxMessage.getFromUser())
|
||||
.build());
|
||||
} catch (WxErrorException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package com.cpop.sdk.framework.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author DB
|
||||
* @createTime 2023/09/28 10:01
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "wx.miniapp")
|
||||
public class WxMaProperties {
|
||||
|
||||
private List<Config> configs;
|
||||
|
||||
@Data
|
||||
public static class Config {
|
||||
/**
|
||||
* 设置微信小程序的appid
|
||||
*/
|
||||
private String appid;
|
||||
|
||||
/**
|
||||
* 设置微信小程序的Secret
|
||||
*/
|
||||
private String secret;
|
||||
|
||||
/**
|
||||
* 设置微信小程序消息服务器配置的token
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 设置微信小程序消息服务器配置的EncodingAESKey
|
||||
*/
|
||||
private String aesKey;
|
||||
|
||||
/**
|
||||
* 消息格式,XML或者JSON
|
||||
*/
|
||||
private String msgDataFormat;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,151 @@
|
||||
package com.cpop.sdk.framework.handler;
|
||||
|
||||
import com.cpop.core.utils.uuid.IdUtils;
|
||||
import com.qcloud.cos.COSClient;
|
||||
import com.qcloud.cos.ClientConfig;
|
||||
import com.qcloud.cos.auth.BasicCOSCredentials;
|
||||
import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.exception.CosClientException;
|
||||
import com.qcloud.cos.http.HttpProtocol;
|
||||
import com.qcloud.cos.model.ObjectMetadata;
|
||||
import com.qcloud.cos.model.PutObjectRequest;
|
||||
import com.qcloud.cos.model.StorageClass;
|
||||
import com.qcloud.cos.model.UploadResult;
|
||||
import com.qcloud.cos.region.Region;
|
||||
import com.qcloud.cos.transfer.TransferManager;
|
||||
import com.qcloud.cos.transfer.TransferManagerConfiguration;
|
||||
import com.qcloud.cos.transfer.Upload;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @author DB
|
||||
* @createTime 2023/09/28 11:08
|
||||
* @description 腾讯云handler
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "q-cloud.cos")
|
||||
public class QCloudCosHandler {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String secretId;
|
||||
|
||||
/**
|
||||
* 密钥
|
||||
*/
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* 资源桶
|
||||
*/
|
||||
private String bucketName;
|
||||
|
||||
/**
|
||||
* CDN加速路径
|
||||
*/
|
||||
private String cndUrl;
|
||||
|
||||
/**
|
||||
* @descriptions 获取client
|
||||
* @author DB
|
||||
* @date 2023/09/28 11:12
|
||||
* @return: com.qcloud.cos.COSClient
|
||||
*/
|
||||
private COSClient createCosClient() {
|
||||
//初始化
|
||||
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
|
||||
Region region = new Region("ap-guangzhou");
|
||||
ClientConfig clientConfig = new ClientConfig(region);
|
||||
//从 5.6.54 版本开始,默认使用了 https
|
||||
clientConfig.setHttpProtocol(HttpProtocol.https);
|
||||
//生成 cos 客户端。
|
||||
return new COSClient(cred, clientConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 创建 TransferManager 实例,这个实例用来后续调用高级接口
|
||||
* @author DB
|
||||
* @date 2023/09/28 11:20
|
||||
* @return: TransferManager
|
||||
*/
|
||||
TransferManager createTransferManager() {
|
||||
// 创建一个 COSClient 实例,这是访问 COS 服务的基础实例。
|
||||
COSClient cosClient = createCosClient();
|
||||
// 自定义线程池大小,建议在客户端与 COS 网络充足(例如使用腾讯云的 CVM,同地域上传 COS)的情况下,设置成16或32即可,可较充分的利用网络资源
|
||||
// 对于使用公网传输且网络带宽质量不高的情况,建议减小该值,避免因网速过慢,造成请求超时。
|
||||
ExecutorService threadPool = Executors.newFixedThreadPool(32);
|
||||
// 传入一个 threadPool, 若不传入线程池,默认 TransferManager 中会生成一个单线程的线程池。
|
||||
TransferManager transferManager = new TransferManager(cosClient, threadPool);
|
||||
// 设置高级接口的配置项
|
||||
// 分块上传阈值和分块大小分别为 5MB 和 1MB
|
||||
TransferManagerConfiguration transferManagerConfiguration = new TransferManagerConfiguration();
|
||||
transferManagerConfiguration.setMultipartUploadThreshold(5 * 1024 * 1024);
|
||||
transferManagerConfiguration.setMinimumUploadPartSize(1 * 1024 * 1024);
|
||||
transferManager.setConfiguration(transferManagerConfiguration);
|
||||
return transferManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 关闭 TransferManager
|
||||
* @author DB
|
||||
* @date 2023/09/28 11:24
|
||||
* @param transferManager TransferManager 实例
|
||||
* @return: void
|
||||
*/
|
||||
void shutdownTransferManager(TransferManager transferManager) {
|
||||
// 指定参数为 true, 则同时会关闭 transferManager 内部的 COSClient 实例。
|
||||
// 指定参数为 false, 则不会关闭 transferManager 内部的 COSClient 实例。
|
||||
transferManager.shutdownNow(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 文件上传
|
||||
* @author DB
|
||||
* @date 2023/09/28 13:56
|
||||
* @param file 文件
|
||||
* @return: 返回cdn加速路径
|
||||
*/
|
||||
public String upload(File file) {
|
||||
// 使用高级接口必须先保证本进程存在一个 TransferManager 实例,如果没有则创建
|
||||
// 详细代码参见本页:高级接口 -> 创建 TransferManager
|
||||
TransferManager transferManager = createTransferManager();
|
||||
// 对象键(Key)是对象在存储桶中的唯一标识。
|
||||
String key = IdUtils.fastSimpleUUID();
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file);
|
||||
// 设置存储类型(如有需要,不需要请忽略此行代码), 默认是标准(Standard), 低频(standard_ia)
|
||||
// 更多存储类型请参见 https://cloud.tencent.com/document/product/436/33417
|
||||
putObjectRequest.setStorageClass(StorageClass.Standard);
|
||||
//若需要设置对象的自定义 Headers 可参照下列代码,若不需要可省略下面这几行,对象自定义 Headers 的详细信息可参考 https://cloud.tencent.com/document/product/436/13361
|
||||
ObjectMetadata objectMetadata = new ObjectMetadata();
|
||||
//若设置 Content-Type、Cache-Control、Content-Disposition、Content-Encoding、Expires 这五个字自定义 Headers,推荐采用 objectMetadata.setHeader()
|
||||
//若要设置 “x-cos-meta-[自定义后缀]” 这样的自定义 Header,推荐采用
|
||||
Map<String, String> userMeta = new HashMap<String, String>();
|
||||
objectMetadata.setUserMetadata(userMeta);
|
||||
putObjectRequest.withMetadata(objectMetadata);
|
||||
UploadResult uploadResult = null;
|
||||
try {
|
||||
// 高级接口会返回一个异步结果Upload
|
||||
// 可同步地调用 waitForUploadResult 方法等待上传完成,成功返回 UploadResult, 失败抛出异常
|
||||
Upload upload = transferManager.upload(putObjectRequest);
|
||||
upload.waitForUploadResult();
|
||||
return "https://" + bucketName + cndUrl + key;
|
||||
} catch (CosClientException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 确定本进程不再使用 transferManager 实例之后,关闭即可
|
||||
shutdownTransferManager(transferManager);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
22
Cpop-Sdk/src/main/resources/application-sdk.yml
Normal file
22
Cpop-Sdk/src/main/resources/application-sdk.yml
Normal file
@ -0,0 +1,22 @@
|
||||
#腾讯云
|
||||
qCloud:
|
||||
cos:
|
||||
secretId: AKIDFK8hz0kDRP6XjdGciX5LK3VfYBWaMs7V
|
||||
secretKey: 92g38wUlkSt50e17wUllUw71pMcaIjtl
|
||||
bucketName: dataresource-1302318474
|
||||
cndUrl: .cos.accelerate.myqcloud.com/
|
||||
|
||||
#微信SDK
|
||||
wx:
|
||||
#小程序
|
||||
miniapp:
|
||||
configs:
|
||||
#\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u7684appid
|
||||
- appid: wx1eb0e5fb7dac3c05
|
||||
#\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u7684Secret
|
||||
secret: f274d2ca01cc58cb5387379356c005c1
|
||||
#\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u6D88\u606F\u670D\u52A1\u5668\u914D\u7F6E\u7684token
|
||||
token:
|
||||
#\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u6D88\u606F\u670D\u52A1\u5668\u914D\u7F6E\u7684EncodingAESKey
|
||||
aesKey:
|
||||
msgDataFormat: JSON
|
||||
28
pom.xml
28
pom.xml
@ -19,6 +19,8 @@
|
||||
<module>Cpop-Common</module>
|
||||
<module>Cpop-Core</module>
|
||||
<module>Cpop-Generator</module>
|
||||
<module>Cpop-Api</module>
|
||||
<module>Cpop-Sdk</module>
|
||||
<module>Cpop-Oam</module>
|
||||
<module>Cpop-Oam/Cpop-Oam-Web</module>
|
||||
<module>Cpop-Jambox</module>
|
||||
@ -38,6 +40,9 @@
|
||||
<jjwt.version>0.9.1</jjwt.version>
|
||||
<HikariCP.version>4.0.3</HikariCP.version>
|
||||
<knife4j.version>4.2.0</knife4j.version>
|
||||
<wechat-java.version>4.5.0</wechat-java.version>
|
||||
<bcprov-jdk15on.version>1.70</bcprov-jdk15on.version>
|
||||
<cos_api.version>5.6.155</cos_api.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -89,6 +94,11 @@
|
||||
<artifactId>Cpop-Api</artifactId>
|
||||
<version>${cpop.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cpop</groupId>
|
||||
<artifactId>Cpop-Sdk</artifactId>
|
||||
<version>${cpop.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cpop</groupId>
|
||||
<artifactId>Cpop-Oam</artifactId>
|
||||
@ -140,6 +150,24 @@
|
||||
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
|
||||
<version>${knife4j.version}</version>
|
||||
</dependency>
|
||||
<!--微信小程序-->
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-miniapp</artifactId>
|
||||
<version>${wechat-java.version}</version>
|
||||
</dependency>
|
||||
<!-- 腾讯云-->
|
||||
<dependency>
|
||||
<groupId>com.qcloud</groupId>
|
||||
<artifactId>cos_api</artifactId>
|
||||
<version>${cos_api.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>${bcprov-jdk15on.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user