Merge branch 'master' of http://192.168.1.26:3000/dianliang/dl_admin
This commit is contained in:
commit
6147418efe
@ -228,8 +228,7 @@ public class BusiNoticeController extends BaseController
|
|||||||
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
|
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
|
||||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize)
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize)
|
||||||
{
|
{
|
||||||
Page<BusiNotice> page = new Page<>(pageNum, pageSize);
|
List<BusiNoticeVo> list = busiNoticeService.appFootprintList(query);
|
||||||
IPage<BusiNoticeVo> list = busiNoticeService.appFootprintList(query,page);
|
|
||||||
return success(list);
|
return success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -52,6 +52,10 @@ public class BusiNotice extends DlBaseEntity
|
|||||||
private String province;
|
private String province;
|
||||||
/** 城市 */
|
/** 城市 */
|
||||||
private String city;
|
private String city;
|
||||||
|
/**
|
||||||
|
* 是否急招0否1是
|
||||||
|
*/
|
||||||
|
private String isUrgent;
|
||||||
//是否平台结算
|
//是否平台结算
|
||||||
private Integer isPlatformFree;
|
private Integer isPlatformFree;
|
||||||
/** 稿费下限 */
|
/** 稿费下限 */
|
||||||
|
|||||||
@ -43,11 +43,10 @@ public class BusiNoticeSign extends DlBaseEntity
|
|||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
/** 报名用户头像 */
|
/** 报名用户头像 */
|
||||||
@Excel(name = "报名用户头像")
|
@Excel(name = "报名用户头像", cellType = Excel.ColumnType.IMAGE)
|
||||||
private String avatar;
|
private String avatar;
|
||||||
|
|
||||||
/** 是否超级报名 */
|
|
||||||
@Excel(name = "是否超级报名")
|
|
||||||
private String isSuper;
|
private String isSuper;
|
||||||
|
|
||||||
/** 联系方式 */
|
/** 联系方式 */
|
||||||
@ -59,18 +58,18 @@ public class BusiNoticeSign extends DlBaseEntity
|
|||||||
private String addrId;
|
private String addrId;
|
||||||
|
|
||||||
/** 通告合作状态 */
|
/** 通告合作状态 */
|
||||||
@Excel(name = "通告合作状态")
|
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
/** 稿件内容 */
|
/** 稿件内容 */
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
/** 稿件图片 */
|
/** 稿件图片 */
|
||||||
@Excel(name = "稿件图片")
|
|
||||||
private String images;
|
private String images;
|
||||||
|
|
||||||
/** 已发布的文章链接 */
|
/** 已发布的文章链接 */
|
||||||
@Excel(name = "已发布的文章链接")
|
|
||||||
private String articleRef;
|
private String articleRef;
|
||||||
/**
|
/**
|
||||||
* 动态表单json
|
* 动态表单json
|
||||||
|
|||||||
@ -49,7 +49,7 @@ public interface BusiNoticeMapper extends BaseMapper<BusiNotice> {
|
|||||||
* @param query 查询条件
|
* @param query 查询条件
|
||||||
* @return com.ruoyi.common.core.domain.AjaxResult
|
* @return com.ruoyi.common.core.domain.AjaxResult
|
||||||
**/
|
**/
|
||||||
IPage<BusiNoticeVo> appFootprintList(@Param("entity") AppNoticeQuery query, Page<BusiNotice> page);
|
List<BusiNoticeVo> appFootprintList(@Param("entity") AppNoticeQuery query, @Param("num") Integer num);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小程序端查询订阅通告列表
|
* 小程序端查询订阅通告列表
|
||||||
|
|||||||
@ -37,5 +37,11 @@ public class AppNoticeQuery {
|
|||||||
//'进行中', '已关闭'
|
//'进行中', '已关闭'
|
||||||
private String status;
|
private String status;
|
||||||
private String noticeId;
|
private String noticeId;
|
||||||
|
//是否急招
|
||||||
|
private String isUrgent;
|
||||||
|
//是否平台结算
|
||||||
|
private String isPlatformFree;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,7 @@ public interface IBusiNoticeService extends IService<BusiNotice>
|
|||||||
* @param query 查询条件
|
* @param query 查询条件
|
||||||
* @return com.ruoyi.common.core.domain.AjaxResult
|
* @return com.ruoyi.common.core.domain.AjaxResult
|
||||||
**/
|
**/
|
||||||
IPage<BusiNoticeVo> appFootprintList(AppNoticeQuery query, Page<BusiNotice> page);
|
List<BusiNoticeVo> appFootprintList(AppNoticeQuery query);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import com.ruoyi.member.domain.MemberApply;
|
|||||||
import com.ruoyi.member.domain.MemberUser;
|
import com.ruoyi.member.domain.MemberUser;
|
||||||
import com.ruoyi.member.service.IMemberApplyService;
|
import com.ruoyi.member.service.IMemberApplyService;
|
||||||
import com.ruoyi.member.service.IMemberCardService;
|
import com.ruoyi.member.service.IMemberCardService;
|
||||||
|
import com.ruoyi.member.service.IMemberCouponService;
|
||||||
import com.ruoyi.member.service.IMemberUserService;
|
import com.ruoyi.member.service.IMemberUserService;
|
||||||
import com.ruoyi.system.service.ISysDictDataService;
|
import com.ruoyi.system.service.ISysDictDataService;
|
||||||
import com.ruoyi.system.service.ISysDictTypeService;
|
import com.ruoyi.system.service.ISysDictTypeService;
|
||||||
@ -83,6 +84,8 @@ public class BusiNoticeServiceImpl extends ServiceImpl<BusiNoticeMapper,BusiNoti
|
|||||||
@Resource
|
@Resource
|
||||||
private IMemberCardService cardService;
|
private IMemberCardService cardService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMemberCouponService memberCouponService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<BusiNoticeVo> queryListPage(BusiNoticeQuery query, Page<BusiNotice> page) {
|
public IPage<BusiNoticeVo> queryListPage(BusiNoticeQuery query, Page<BusiNotice> page) {
|
||||||
@ -216,7 +219,12 @@ public class BusiNoticeServiceImpl extends ServiceImpl<BusiNoticeMapper,BusiNoti
|
|||||||
}else {
|
}else {
|
||||||
this.saveVo(data);
|
this.saveVo(data);
|
||||||
}
|
}
|
||||||
cardService.dealMemberRights(userId,null,"add_notice",1);
|
try {
|
||||||
|
cardService.dealMemberRights(userId,null,"add_notice",1);
|
||||||
|
}catch (Exception e){
|
||||||
|
memberCouponService.saveCoupon( userId, "2", data.getId(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (CollectionUtil.isNotEmpty(data.getCustomForm())) {
|
if (CollectionUtil.isNotEmpty(data.getCustomForm())) {
|
||||||
cardService.dealMemberRights(userId,null,"report_info_collect",1);
|
cardService.dealMemberRights(userId,null,"report_info_collect",1);
|
||||||
}
|
}
|
||||||
@ -346,16 +354,17 @@ public class BusiNoticeServiceImpl extends ServiceImpl<BusiNoticeMapper,BusiNoti
|
|||||||
* @return com.ruoyi.common.core.domain.AjaxResult
|
* @return com.ruoyi.common.core.domain.AjaxResult
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public IPage<BusiNoticeVo> appFootprintList(AppNoticeQuery query, Page<BusiNotice> page) {
|
public List<BusiNoticeVo> appFootprintList(AppNoticeQuery query) {
|
||||||
query.setUserId(SecurityUtils.getUserId());
|
query.setUserId(SecurityUtils.getUserId());
|
||||||
IPage<BusiNoticeVo> pageList = busiNoticeMapper.appFootprintList(query,page);
|
Integer num = cardService.getCardRightsValue(SecurityUtils.getUserId(), "02", "history");
|
||||||
List<String> idList = pageList.getRecords().stream().map(BusiNotice::getId).collect(Collectors.toList());
|
List<BusiNoticeVo> pageList = busiNoticeMapper.appFootprintList(query,num);
|
||||||
|
List<String> idList = pageList.stream().map(BusiNotice::getId).collect(Collectors.toList());
|
||||||
if(!idList.isEmpty()){
|
if(!idList.isEmpty()){
|
||||||
//查博主类型字典
|
//查博主类型字典
|
||||||
List<BaseCategory> categoryList = baseCategoryService.listByParentCode(DictConstants.BLOGGER_TYPES_KEY,null);
|
List<BaseCategory> categoryList = baseCategoryService.listByParentCode(DictConstants.BLOGGER_TYPES_KEY,null);
|
||||||
//转map
|
//转map
|
||||||
Map<String,String> categoryMap = categoryList.stream().collect(Collectors.toMap(BaseCategory::getCode,BaseCategory::getTitle));
|
Map<String,String> categoryMap = categoryList.stream().collect(Collectors.toMap(BaseCategory::getCode,BaseCategory::getTitle));
|
||||||
pageList.getRecords().forEach(item->{
|
pageList.forEach(item->{
|
||||||
//报名数量、浏览量、相关字典转换
|
//报名数量、浏览量、相关字典转换
|
||||||
if(null==item.getViewNum()){
|
if(null==item.getViewNum()){
|
||||||
item.setViewNum(0);
|
item.setViewNum(0);
|
||||||
|
|||||||
@ -65,7 +65,7 @@ public class BusiNoticeSignServiceImpl extends ServiceImpl<BusiNoticeSignMapper,
|
|||||||
busiNoticeSign.setUserId(loginUser.getUserId());
|
busiNoticeSign.setUserId(loginUser.getUserId());
|
||||||
busiNoticeSign.setNickname(sysUser.getNickName());
|
busiNoticeSign.setNickname(sysUser.getNickName());
|
||||||
busiNoticeSign.setAvatar(sysUser.getAvatar());
|
busiNoticeSign.setAvatar(sysUser.getAvatar());
|
||||||
busiNoticeSign.setStatus("0");
|
busiNoticeSign.setStatus("01");
|
||||||
busiNoticeSign.setFormData(JSONArray.toJSONString(appNoticeSign.getCustomForm()));
|
busiNoticeSign.setFormData(JSONArray.toJSONString(appNoticeSign.getCustomForm()));
|
||||||
busiNoticeSign.setCardId(cardInfo.getString("id"));
|
busiNoticeSign.setCardId(cardInfo.getString("id"));
|
||||||
busiNoticeSign.setPrice(cardInfo.getBigDecimal("price"));
|
busiNoticeSign.setPrice(cardInfo.getBigDecimal("price"));
|
||||||
|
|||||||
@ -56,7 +56,7 @@ public class MemberCouponServiceImpl extends ServiceImpl<MemberCouponMapper,Memb
|
|||||||
if ("2".equals(type)){
|
if ("2".equals(type)){
|
||||||
int initNum = getCoupon(userId);
|
int initNum = getCoupon(userId);
|
||||||
if (initNum == 0) {
|
if (initNum == 0) {
|
||||||
throw new Exception("当前暂无可用的通告券");
|
throw new Exception("暂无可用报名次数");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//查询当前用户最新变动记录
|
//查询当前用户最新变动记录
|
||||||
|
|||||||
@ -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
|
addNotice: 3
|
||||||
report: 5
|
report: 5
|
||||||
|
#################### 腾讯COS相关配置 ####################
|
||||||
|
cos:
|
||||||
|
baseUrl: notice-1348525010.cos.ap-beijing.myqcloud.com
|
||||||
|
accessKey: AKIDDbyY3Wr9D4i9LK6f085pLfleJlz60hAP
|
||||||
|
secretKey: 82kJfnu11ulW5TghV5TecVYP3TghXAZl
|
||||||
|
regionName: ap-beijing
|
||||||
|
bucketName: notice-1348525010
|
||||||
|
folderPrefix: /files
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
select main.id, main.user_id, main.title, main.platform_code, main.province, main.city, main.fee_down, main.fee_up, main.is_self_price, main.gift_detail,
|
select main.id, main.user_id, main.title, main.platform_code, main.province, main.city, main.fee_down, main.fee_up, main.is_self_price, main.gift_detail,
|
||||||
main.gift_price, main.end_date, main.brand, main.is_show_brand, main.need_num, main.fans_down, main.fans_up, main.is_eligible, main.pic, main.collect, main.detail, main.images,
|
main.gift_price, main.end_date, main.brand, main.is_show_brand, main.need_num, main.fans_down, main.fans_up, main.is_eligible, main.pic, main.collect, main.detail, main.images,
|
||||||
main.blogger_types, main.is_show_tel, main.wechat, main.tel, main.group_image, main.is_use_coupon, main.approval_status, main.approval_user_id, main.approval_time,
|
main.blogger_types, main.is_show_tel, main.wechat, main.tel, main.group_image, main.is_use_coupon, main.approval_status, main.approval_user_id, main.approval_time,
|
||||||
main.approval_remark, main.creator, main.create_time, main.updater, main.update_time, main.del_flag,
|
main.approval_remark, main.creator, main.create_time, main.updater, main.update_time, main.del_flag,main.is_platform_free,main.is_urgent,
|
||||||
uTable.nick_name as userNickName,auditTable.nick_name as approvalUserName,ifnull(noticeView.view_num,0) as viewNum,
|
uTable.nick_name as userNickName,auditTable.nick_name as approvalUserName,ifnull(noticeView.view_num,0) as viewNum,
|
||||||
bTable.title as platformName
|
bTable.title as platformName
|
||||||
from dl_busi_notice main
|
from dl_busi_notice main
|
||||||
@ -25,6 +25,8 @@
|
|||||||
<if test="entity.city != null "> and main.city = #{entity.city}</if>
|
<if test="entity.city != null "> and main.city = #{entity.city}</if>
|
||||||
<if test="entity.title != null and entity.title != ''"> and main.title like concat('%', #{entity.title}, '%')</if>
|
<if test="entity.title != null and entity.title != ''"> and main.title like concat('%', #{entity.title}, '%')</if>
|
||||||
<if test="entity.platformCode != null and entity.platformCode != ''"> and main.platform_code = #{entity.platformCode}</if>
|
<if test="entity.platformCode != null and entity.platformCode != ''"> and main.platform_code = #{entity.platformCode}</if>
|
||||||
|
<if test="entity.isUrgent != null and entity.isUrgent != ''"> and main.is_urgent = #{entity.isUrgent}</if>
|
||||||
|
<if test="entity.isPlatformFree != null and entity.isPlatformFree != ''"> and main.is_platform_free = #{entity.isPlatformFree}</if>
|
||||||
|
|
||||||
<if test="entity.params.beginFeeDown != null and entity.params.beginFeeDown != ''">
|
<if test="entity.params.beginFeeDown != null and entity.params.beginFeeDown != ''">
|
||||||
and main.fee_down <![CDATA[>= ]]> #{entity.params.beginFeeDown}
|
and main.fee_down <![CDATA[>= ]]> #{entity.params.beginFeeDown}
|
||||||
@ -74,7 +76,7 @@ order by dbns.create_time desc
|
|||||||
LEFT JOIN sys_user su ON dbn.user_id = su.user_id
|
LEFT JOIN sys_user su ON dbn.user_id = su.user_id
|
||||||
left join dl_busi_notice_sign sign on sign.notice_id = dbn.id and sign.del_flag = 0
|
left join dl_busi_notice_sign sign on sign.notice_id = dbn.id and sign.del_flag = 0
|
||||||
WHERE
|
WHERE
|
||||||
dbn.del_flag = 0
|
dbn.del_flag = 0 and dbn.end_date >= CURDATE()
|
||||||
AND (dbn.approval_status = '1')
|
AND (dbn.approval_status = '1')
|
||||||
<if test="entity.gift!=null and entity.gift!=''">
|
<if test="entity.gift!=null and entity.gift!=''">
|
||||||
AND ( dbn.gift_detail IS NOT NULL AND dbn.gift_detail != '' )
|
AND ( dbn.gift_detail IS NOT NULL AND dbn.gift_detail != '' )
|
||||||
@ -82,6 +84,8 @@ order by dbns.create_time desc
|
|||||||
<if test="entity.platformCode!=null and entity.platformCode!=''">
|
<if test="entity.platformCode!=null and entity.platformCode!=''">
|
||||||
AND ( dbn.platform_code =#{entity.platformCode} )
|
AND ( dbn.platform_code =#{entity.platformCode} )
|
||||||
</if>
|
</if>
|
||||||
|
<if test="entity.isUrgent != null and entity.isUrgent != ''"> and dbn.is_urgent = #{entity.isUrgent}</if>
|
||||||
|
<if test="entity.isPlatformFree != null and entity.isPlatformFree != ''"> and dbn.is_platform_free = #{entity.isPlatformFree}</if>
|
||||||
<if test="entity.bloggerType!=null and entity.bloggerType!=''">
|
<if test="entity.bloggerType!=null and entity.bloggerType!=''">
|
||||||
AND ( dbn.blogger_types LIKE CONCAT('%',#{entity.bloggerType},'%') )
|
AND ( dbn.blogger_types LIKE CONCAT('%',#{entity.bloggerType},'%') )
|
||||||
</if>
|
</if>
|
||||||
@ -109,20 +113,20 @@ order by dbns.create_time desc
|
|||||||
</if>
|
</if>
|
||||||
group by dbn.id
|
group by dbn.id
|
||||||
ORDER BY
|
ORDER BY
|
||||||
<choose>
|
<choose>
|
||||||
<when test="entity.sortBy=='new'">
|
<when test="entity.sortBy=='new'">
|
||||||
-- 查最新的 --
|
-- 查最新的 --
|
||||||
dbn.create_time DESC
|
dbn.create_time DESC
|
||||||
</when>
|
</when>
|
||||||
<when test="entity.sortBy=='money'">
|
<when test="entity.sortBy=='money'">
|
||||||
-- 查高奖励 --
|
-- 查高奖励 --
|
||||||
dbn.fee_up DESC
|
dbn.fee_up DESC
|
||||||
</when>
|
</when>
|
||||||
<otherwise>
|
<otherwise>
|
||||||
-- 默认正序排列 --
|
-- 默认正序排列 --
|
||||||
dbn.create_time DESC
|
dbn.create_time DESC
|
||||||
</otherwise>
|
</otherwise>
|
||||||
</choose>
|
</choose>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
<select id="selectByIdVo" resultType="com.ruoyi.busi.vo.BusiNoticeVo">
|
<select id="selectByIdVo" resultType="com.ruoyi.busi.vo.BusiNoticeVo">
|
||||||
@ -159,6 +163,8 @@ order by dbns.create_time desc
|
|||||||
<if test="entity.platformCode!=null and entity.platformCode!=''">
|
<if test="entity.platformCode!=null and entity.platformCode!=''">
|
||||||
AND ( dbn.platform_code =#{entity.platformCode} )
|
AND ( dbn.platform_code =#{entity.platformCode} )
|
||||||
</if>
|
</if>
|
||||||
|
<if test="entity.isUrgent != null and entity.isUrgent != ''"> and dbn.is_urgent = #{entity.isUrgent}</if>
|
||||||
|
<if test="entity.isPlatformFree != null and entity.isPlatformFree != ''"> and dbn.is_platform_free = #{entity.isPlatformFree}</if>
|
||||||
<if test="entity.bloggerType!=null and entity.bloggerType!=''">
|
<if test="entity.bloggerType!=null and entity.bloggerType!=''">
|
||||||
AND ( dbn.blogger_types LIKE CONCAT('%',#{entity.bloggerType},'%') )
|
AND ( dbn.blogger_types LIKE CONCAT('%',#{entity.bloggerType},'%') )
|
||||||
</if>
|
</if>
|
||||||
@ -200,6 +206,7 @@ order by dbns.create_time desc
|
|||||||
dbn.create_time ASC
|
dbn.create_time ASC
|
||||||
</otherwise>
|
</otherwise>
|
||||||
</choose>
|
</choose>
|
||||||
|
limit #{num}
|
||||||
</select>
|
</select>
|
||||||
<select id="subscribeList" resultType="com.ruoyi.busi.vo.BusiNoticeVo">
|
<select id="subscribeList" resultType="com.ruoyi.busi.vo.BusiNoticeVo">
|
||||||
SELECT
|
SELECT
|
||||||
@ -252,6 +259,8 @@ order by dbns.create_time desc
|
|||||||
<if test="entity.feeDown!=null">
|
<if test="entity.feeDown!=null">
|
||||||
AND ( dbn.fee_down >=#{entity.feeDown} )
|
AND ( dbn.fee_down >=#{entity.feeDown} )
|
||||||
</if>
|
</if>
|
||||||
|
<if test="entity.isUrgent != null and entity.isUrgent != ''"> and dbn.is_urgent = #{entity.isUrgent}</if>
|
||||||
|
<if test="entity.isPlatformFree != null and entity.isPlatformFree != ''"> and dbn.is_platform_free = #{entity.isPlatformFree}</if>
|
||||||
group by dbn.id
|
group by dbn.id
|
||||||
ORDER BY
|
ORDER BY
|
||||||
|
|
||||||
|
|||||||
@ -165,6 +165,11 @@
|
|||||||
<artifactId>mybatis-plus</artifactId>
|
<artifactId>mybatis-plus</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.qcloud</groupId>
|
||||||
|
<artifactId>cos-sts_api</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@ -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