Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b632c78472
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.base.domain.BaseCategory;
|
||||
import com.ruoyi.base.service.IBaseCategoryService;
|
||||
import com.ruoyi.common.config.DlRightsConfig;
|
||||
import com.ruoyi.common.core.domain.DlBaseEntity;
|
||||
import com.ruoyi.member.domain.MemberPoints;
|
||||
@ -25,6 +27,8 @@ import java.util.List;
|
||||
public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, MemberPoints> implements IMemberPointsService {
|
||||
@Autowired
|
||||
private MemberPointsMapper memberPointsMapper;
|
||||
@Autowired
|
||||
private IBaseCategoryService categoryService;
|
||||
|
||||
|
||||
/**
|
||||
@ -50,6 +54,12 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
||||
**/
|
||||
@Override
|
||||
public void savePoints(MemberPoints memberPoints) {
|
||||
if(memberPoints.getFromCode() != null){
|
||||
List<BaseCategory> categoryList = categoryService.selectByCode(memberPoints.getFromCode());
|
||||
BaseCategory category = categoryList.get(0);
|
||||
memberPoints.setPoints(Integer.parseInt(category.getContent()));
|
||||
memberPoints.setTitle(category.getTitle());
|
||||
}
|
||||
//查询当前用户最近变动记录
|
||||
LambdaQueryWrapper<MemberPoints> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(DlBaseEntity::getDelFlag,0)
|
||||
@ -62,7 +72,7 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
||||
} else {
|
||||
//如果有记录则取最新记录中的剩余值进行计算后得出新值
|
||||
Integer oldBalance = list.get(0).getBalance();
|
||||
Integer newBalance;
|
||||
int newBalance;
|
||||
if ("1".equals(memberPoints.getType())) {
|
||||
newBalance = oldBalance + memberPoints.getPoints();
|
||||
} else {
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.ruoyi.web.controller.cos;
|
||||
|
||||
import com.ruoyi.system.service.CosStsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.security.PermitAll;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: sts
|
||||
* @Author: 86187
|
||||
* @Date: 2025/03/20 16:34
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/cos")
|
||||
@RequiredArgsConstructor
|
||||
public class CosStsController {
|
||||
|
||||
private final CosStsService cosStsService;
|
||||
|
||||
/**
|
||||
* 获取cos临时密钥
|
||||
*
|
||||
* @return sts
|
||||
*/
|
||||
@GetMapping("/sts")
|
||||
@PermitAll
|
||||
public Map<String, Object> getCosSts() {
|
||||
return cosStsService.getTempKeys();
|
||||
}
|
||||
}
|
@ -173,3 +173,11 @@ dl-rights:
|
||||
# 每月发布通告额度
|
||||
addNotice: 3
|
||||
report: 5
|
||||
#################### 腾讯COS相关配置 ####################
|
||||
cos:
|
||||
baseUrl: notice-1348525010.cos.ap-beijing.myqcloud.com
|
||||
accessKey: AKIDDbyY3Wr9D4i9LK6f085pLfleJlz60hAP
|
||||
secretKey: 82kJfnu11ulW5TghV5TecVYP3TghXAZl
|
||||
regionName: ap-beijing
|
||||
bucketName: notice-1348525010
|
||||
folderPrefix: /files
|
||||
|
@ -70,13 +70,13 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- JSON工具类 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- 阿里JSON解析器 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
@ -165,7 +165,12 @@
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qcloud</groupId>
|
||||
<artifactId>cos-sts_api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
@ -0,0 +1,82 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.tencent.cloud.CosStsClient;
|
||||
import com.tencent.cloud.Response;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* @Description: sts
|
||||
* @Author: 86187
|
||||
* @Date: 2025/03/20 16:18
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class CosStsService {
|
||||
// 你的腾讯云账号的 SecretId 和 SecretKey
|
||||
@Value("${cos.accessKey}")
|
||||
private String SECRET_ID;
|
||||
@Value("${cos.secretKey}")
|
||||
private String SECRET_KEY;
|
||||
|
||||
// 存储桶所属的地域,例如 "ap-shanghai"
|
||||
@Value("${cos.regionName}")
|
||||
private String REGION;
|
||||
|
||||
// 你的存储桶名,例如 "example-1250000000"
|
||||
@Value("${cos.bucketName}")
|
||||
private String BUCKET;
|
||||
|
||||
// 临时密钥有效期(单位秒),最长不超过 2 小时(7200 秒)
|
||||
private static final int DURATION_SECONDS = 1800;
|
||||
|
||||
public Map<String, Object> getTempKeys() {
|
||||
TreeMap<String, Object> config = new TreeMap<String, Object>();
|
||||
|
||||
try {
|
||||
// 云 api 密钥 SecretId
|
||||
config.put("secretId", SECRET_ID);
|
||||
// 云 api 密钥 SecretKey
|
||||
config.put("secretKey", SECRET_KEY);
|
||||
// 临时密钥有效时长,单位是秒
|
||||
config.put("durationSeconds", 1800);
|
||||
// 换成你的 bucket
|
||||
config.put("bucket", BUCKET);
|
||||
// 换成 bucket 所在地区
|
||||
config.put("region", REGION);
|
||||
|
||||
// 可以通过 allowPrefixes 指定前缀数组, 例子: a.jpg 或者 a/* 或者 * (使用通配符*存在重大安全风险, 请谨慎评估使用)
|
||||
config.put("allowPrefixes", new String[] {
|
||||
"*"
|
||||
});
|
||||
|
||||
// 密钥的权限列表。简单上传和分片需要以下的权限,其他权限列表请看 https://cloud.tencent.com/document/product/436/31923
|
||||
String[] allowActions = new String[] {
|
||||
// 简单上传
|
||||
"name/cos:PutObject",
|
||||
"name/cos:PostObject",
|
||||
// 分片上传
|
||||
"name/cos:InitiateMultipartUpload",
|
||||
"name/cos:ListMultipartUploads",
|
||||
"name/cos:ListParts",
|
||||
"name/cos:UploadPart",
|
||||
"name/cos:CompleteMultipartUpload"
|
||||
};
|
||||
config.put("allowActions", allowActions);
|
||||
|
||||
Response response = CosStsClient.getCredential(config);
|
||||
Map<String, Object> result= new HashMap<>();
|
||||
result.put("credentials", response.credentials);
|
||||
result.put("startTime", response.startTime);
|
||||
result.put("expiredTime", response.expiredTime);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new IllegalArgumentException("no valid secret !");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user