提交 1139fb66 authored 作者: 李秋林's avatar 李秋林

获取阿里云sts_token,职能角色上传计划

上级 6925b5c2
......@@ -245,6 +245,13 @@
<artifactId>aliyun-sdk-oss</artifactId>
<version>${aliyun.oss.version}</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>sts20150401</artifactId>
<version>${aliyun.sts.version}</version>
</dependency>
</dependencies>
<build>
......
......@@ -30,7 +30,7 @@ public class PromPlanCoreController {
/**
* 城市经理 - 上传计划
* 城市经理 - 上传计划(新增)
* 当月只能上传次月的新增(当月需要新增需要交由职能角色上传)
*/
@PostMapping("/self/upload")
......@@ -61,39 +61,61 @@ public class PromPlanCoreController {
}
}
@GetMapping("/self/upload/{uuid}")
/**
* todo 城市经理修改
*/
/**
* todo 职能角色修改
*/
/**
* 职能角色 - 上传计划(新增)
*/
@PostMapping("/auth/upload")
public R authPlan(@RequestBody ActivityPlanVo activityPlanVo) {
// 判断当前账号是否是城市经理
boolean isAuth = manageEmployeeQueryService.isAuth(activityPlanVo.getEmployeeId());
if (!isAuth) {
throw new DataException(RCode.EMP_PRIVILEGE_ERROR);
}
try {
String[] urlArr = activityPlanVo.getExcelUrl().split("weda-uploader/");
String fileId = urlArr[urlArr.length - 1];
if (fileId.length() > 53) {
throw new DataException(RCode.ACTIVITY_PLAN_FILENAME_LONG);
}
String filePath = "/home/" + fileId;
FileUtils.downloadExcel(activityPlanVo.getExcelUrl(), filePath);
// todo String filePath = "/Users/a02200059/Desktop/职能角色-新增-1.xlsx";
activityPlanVo.setExcelId(fileId);
Map<String, Object> map = promPlanCoreService.authPlanUp(activityPlanVo, filePath);
return R.success(map);
} catch (DataException e) {
return new R(e.getCode(), e.getMsg(), null);
} catch (Exception e) {
return R.fail();
}
}
/**
* 确认上传(根据任一UUID)
*/
@GetMapping("/upload/{uuid}")
public R selfPlanAf(@PathVariable("uuid") String planUuid){
promPlanCoreService.selfPlanAf(planUuid);
return R.success();
}
/**
* 职能角色 - 上传计划
*/
@GetMapping("/auth/upload")
public void authPlan(@RequestBody ActivityPlanVo activityPlanVo) {
// 判断当前账号是否是城市经理
// boolean isSelf = manageEmployeeQueryService.isOneSelf(activityPlanVo.getEmployeeId());
// if (!isSelf) {
// throw new DataException(RCode.EMP_PRIVILEGE_ERROR);
// }
//
// try {
// String[] urlArr = activityPlanVo.getExcelUrl().split("weda-uploader/");
// String fileId = urlArr[urlArr.length - 1];
// if (fileId.length() > 53) {
// throw new DataException(RCode.ACTIVITY_PLAN_FILENAME_LONG);
// }
//
// String filePath = "/home/" + fileId;
// FileUtils.downloadExcel(activityPlanVo.getExcelUrl(), filePath);
// String filePath = "/Users/a02200059/Desktop/测试新增v3 2.xlsx";
// activityPlanVo.setExcelId(fileId);
// Map<String, Object> map = promPlanCoreService.selfPlanUp(activityPlanVo, filePath);
// return R.success(map);
// } catch (DataException e) {
// return new R(e.getCode(), e.getMsg(), null);
}
/**
* 删除计划 计划日期大于今日可直接删除,如果计划日期是今日则必需是10点之前,包含过去日期不可删除
......
package com.wangxiaolu.promotion.controller.yun;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.utils.AliyunUtils;
......@@ -10,6 +9,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
/**
* @author : liqiulin
* @date : 2025-02-06 13
......@@ -31,4 +32,14 @@ public class AliyunGetToken {
return R.fail();
}
}
@GetMapping("/sts_token")
public R getStsToken() {
try {
String stsToken = aliyunUtils.getStsToken();
return R.success(stsToken);
} catch (Exception e) {
return R.fail(e.getMessage());
}
}
}
......@@ -26,4 +26,6 @@ public interface ManageEmployeeInfoDao {
void updateAccount(String employeeNo, Integer privilegeId, String status);
boolean isOneSelf(Integer employeeId);
boolean isAuth(Integer employeeId);
}
......@@ -92,6 +92,11 @@ public class ManageEmployeeInfoInfoDaoImpl implements ManageEmployeeInfoDao {
return manageEmployeeInfoMapper.isOneSelf(employeeId);
}
@Override
public boolean isAuth(Integer employeeId) {
return manageEmployeeInfoMapper.isAuth(employeeId);
}
/**
* 增加权限
*/
......
......@@ -29,6 +29,7 @@ public interface ManageEmployeeInfoMapper extends BaseMapper<ManageEmployeeInfoD
void updatePrivilege(@Param("employeeNo") String employeeNo,@Param("privilegeId") Integer privilegeId);
boolean isOneSelf(Integer employeeId);
boolean isAuth(Integer employeeId);
}
......
......@@ -18,4 +18,5 @@ public interface PromPlanCoreService {
void deletePlan(List<Long> planIds);
Map<String, Object> authPlanUp(ActivityPlanVo activityPlanVo, String filePath);
}
......@@ -23,4 +23,6 @@ public interface ManageEmployeeQueryService {
boolean hasByEmpNo(String employeeNo);
boolean isOneSelf(Integer employeeId);
boolean isAuth(Integer employeeId);
}
......@@ -62,4 +62,9 @@ public class ManageEmployeeQueryServiceImpl implements ManageEmployeeQueryServic
public boolean isOneSelf(Integer employeeId) {
return manageEmployeeInfoDao.isOneSelf(employeeId);
}
@Override
public boolean isAuth(Integer employeeId) {
return manageEmployeeInfoDao.isAuth(employeeId);
}
}
......@@ -14,6 +14,7 @@ import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.aliyun.sts20150401.Client;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
......@@ -53,11 +54,11 @@ public class AliyunUtils {
public JSONObject getSignature() throws JsonProcessingException {
//获取发送STS请求基础信息
//环境变量中获取access_key_id
//获取access_key_id
String accessKeyId = OSS_ACCESS_KEY_ID;
//环境变量中获取access_key_secret
//获取access_key_secret
String accessKeySecret = OSS_ACCESS_KEY_SECRET;
//环境变量中获取ARN
//获取ARN
String roleArnForOssUpload = OSS_STS_ROLE_ARN;
//色会话名称,用来区分不同的令牌,可自定义
String roleSessionName = YOUR_ROLE_SESSION_NAME;
......@@ -180,4 +181,22 @@ public class AliyunUtils {
throw new RuntimeException("Failed to calculate HMAC-SHA256", e);
}
}
public String getStsToken() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(OSS_ACCESS_KEY_ID)
.setAccessKeySecret(OSS_ACCESS_KEY_SECRET);
config.endpoint = "sts." + REGION_ID + ".aliyuncs.com";
Client client = new Client(config);
com.aliyun.sts20150401.models.AssumeRoleRequest assumeRoleRequest = new com.aliyun.sts20150401.models.AssumeRoleRequest()
.setDurationSeconds(3600L)
.setRoleArn(OSS_STS_ROLE_ARN)
.setRoleSessionName("000516");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
com.aliyun.sts20150401.models.AssumeRoleResponse assumeRoleResponse = client.assumeRoleWithOptions(assumeRoleRequest, runtime);
return assumeRoleResponse.body.getCredentials().getSecurityToken();
}
}
\ No newline at end of file
......@@ -67,8 +67,15 @@
where employee_id = (select id from manage_employee_info where employee_no = #{employeeNo});
</update>
<!-- 权限(1:oneself,2:admin)-->
<select id="isOneSelf" resultType="boolean">
select count(*) > 0
from manage_employee_ref_privilege where employee_id = #{employeeId} and privilege_id = 1;
</select>
<!-- 权限(1:oneself,2:admin)-->
<select id="isAuth" resultType="boolean">
select count(*) > 0
from manage_employee_ref_privilege where employee_id = #{employeeId} and privilege_id = 2;
</select>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论