Browse Source

Merge branch 'develop' of gitadmin/tuoheng_lc into release

tags/v1.1.0^2
gitadmin 1 year ago
parent
commit
f2181aec2f
2 changed files with 103 additions and 3 deletions
  1. +97
    -0
      tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AliyunOssController.java
  2. +6
    -3
      tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/ThInspectionServiceImpl.java

+ 97
- 0
tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AliyunOssController.java View File

@@ -0,0 +1,97 @@
package com.tuoheng.admin.controller;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.sts.model.v20150401.AssumeRoleRequest;
import com.aliyuncs.sts.model.v20150401.AssumeRoleResponse;
import com.tuoheng.admin.config.AliyuncsVodConfig;
import com.tuoheng.common.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
* 阿里云对象存储OSS 前端控制器
*
* @author WangHaoran
* @since 2022-03-15
*/
@Slf4j
@RestController
@RequestMapping("/aliyunOss")
public class AliyunOssController {

/**
* 获取securityToken
*
* @return
*/
@GetMapping("/getSecurityToken")
public JsonResult getSecurityToken() {
// STS接入地址,例如sts.cn-shanghai.aliyuncs.com。
String endpoint = "sts.cn-shanghai.aliyuncs.com";
// 填写步骤1生成的访问密钥AccessKey ID和AccessKey Secret。
String AccessKeyId = AliyuncsVodConfig.accessKeyId;
String accessKeySecret = AliyuncsVodConfig.accessKeySecret;
// 填写步骤3获取的角色ARN。
String roleArn = AliyuncsVodConfig.roleArn;
// 自定义角色会话名称,用来区分不同的令牌,例如可填写为SessionTest。
// String roleSessionName = "<yourRoleSessionName>";
// 以下Policy用于限制仅允许使用临时访问凭证向目标存储空间examplebucket上传文件。
// 临时访问凭证最后获得的权限是步骤4设置的角色权限和该Policy设置权限的交集,即仅允许将文件上传至目标存储空间examplebucket下的exampledir目录。
String policy = "{\n" +
" \"Version\": \"1\", \n" +
" \"Statement\": [\n" +
" {\n" +
" \"Action\": [\n" +
" \"oss:PutObject\"\n" +
" ], \n" +
" \"Resource\": [\n" +
" \"acs:oss:*:*:ta-tech-image/imagedir/*\" \n" +
" ], \n" +
" \"Effect\": \"Allow\"\n" +
" }\n" +
" ]\n" +
"}";
try {
// regionId表示RAM的地域ID。以华东1(杭州)地域为例,regionID填写为cn-hangzhou。也可以保留默认值,默认值为空字符串("")。
String regionId = "";
// 添加endpoint。适用于Java SDK 3.12.0及以上版本。
DefaultProfile.addEndpoint(regionId, "Sts", endpoint);
// 添加endpoint。适用于Java SDK 3.12.0以下版本。
// DefaultProfile.addEndpoint("",regionId, "Sts", endpoint);
// 构造default profile。
IClientProfile profile = DefaultProfile.getProfile(regionId, AccessKeyId, accessKeySecret);
// 构造client。
DefaultAcsClient client = new DefaultAcsClient(profile);
final AssumeRoleRequest request = new AssumeRoleRequest();
// 适用于Java SDK 3.12.0及以上版本。
request.setSysMethod(MethodType.POST);
// 适用于Java SDK 3.12.0以下版本。
//request.setMethod(MethodType.POST);
request.setRoleArn(roleArn);
request.setRoleSessionName("SessionTest");
request.setPolicy(policy); // 如果policy为空,则用户将获得该角色下所有权限。
request.setDurationSeconds(3600L); // 设置临时访问凭证的有效时间为3600秒。
final AssumeRoleResponse response = client.getAcsResponse(request);
log.info("Expiration: " + response.getCredentials().getExpiration());
log.info("Access Key Id: " + response.getCredentials().getAccessKeyId());
log.info("Access Key Secret: " + response.getCredentials().getAccessKeySecret());
log.info("Security Token: " + response.getCredentials().getSecurityToken());
log.info("RequestId: " + response.getRequestId());
return JsonResult.success(response);
} catch (ClientException e) {
log.error("Error code: " + e.getErrCode());
log.error("Error message: " + e.getErrMsg());
log.error("RequestId: " + e.getRequestId());
}
return JsonResult.error();
}


}

+ 6
- 3
tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/ThInspectionServiceImpl.java View File

@@ -25,7 +25,7 @@ import com.tuoheng.common.config.CommonConfig;
import com.tuoheng.common.exception.ServiceException;
import com.tuoheng.common.utils.*;
import com.tuoheng.system.utils.ShiroUtils;
import groovy.util.logging.Slf4j;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -132,7 +132,7 @@ public class ThInspectionServiceImpl extends BaseServiceImpl<ThInspectionMapper,

@Override
public JsonResult executeTask(String taskId,PushAndPullURLRequest pushAndPull) throws ServiceException{
Tenant tenant = tenantMapper.selectById(ShiroUtils.getTenantId());
ThMission thMission = missionMapper.selectById(taskId);
Assert.notNull(thMission,"任务不能为空!");
taskId=thMission.getInspectionLine().toString();
@@ -140,8 +140,11 @@ public class ThInspectionServiceImpl extends BaseServiceImpl<ThInspectionMapper,
//这边需要配置到yml文件里面
String url = CommonConfig.airportUrl + "/api/airportInterface/executeTask";
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", "hhz");
jsonObject.put("tenantName", tenant.getName());
jsonObject.put("taskId", taskId);

jsonObject.put("requestId", String.valueOf(thMission.getId()));
log.info("***** executeTask url:{};param:{}", url, jsonObject.toJSONString());
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST");
if(StringUtils.isEmpty(airPortStr)){
return JsonResult.error("机场接口返回数据为空");

Loading…
Cancel
Save