|
|
@ -7,6 +7,8 @@ import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
|
import org.apache.http.HttpResponse; |
|
|
import org.apache.http.HttpResponse; |
|
|
import org.apache.http.auth.AuthScope; |
|
|
import org.apache.http.auth.AuthScope; |
|
|
import org.apache.http.auth.UsernamePasswordCredentials; |
|
|
import org.apache.http.auth.UsernamePasswordCredentials; |
|
|
@ -18,6 +20,7 @@ import org.apache.http.impl.client.BasicCredentialsProvider; |
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
import org.apache.http.util.EntityUtils; |
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
@ -36,7 +39,9 @@ import com.bw.opai.app.service.AppService; |
|
|
import com.bw.opai.common.Res; |
|
|
import com.bw.opai.common.Res; |
|
|
import com.bw.opai.utils.Constants; |
|
|
import com.bw.opai.utils.Constants; |
|
|
import com.bw.opai.utils.DownLoadUtil; |
|
|
import com.bw.opai.utils.DownLoadUtil; |
|
|
|
|
|
import com.bw.opai.utils.JwtUtil; |
|
|
|
|
|
|
|
|
|
|
|
import io.jsonwebtoken.Claims; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
|
@ -63,6 +68,14 @@ public class AppServiceImpl implements AppService { |
|
|
@Value("${elasticsearch.index-name}") |
|
|
@Value("${elasticsearch.index-name}") |
|
|
private String indexName; |
|
|
private String indexName; |
|
|
|
|
|
|
|
|
|
|
|
// 从 Nacos 加载密钥,并设置一个默认值防止配置缺失导致启动失败 |
|
|
|
|
|
@Value("${jwt.secret:my_secret_key_default_2026}") |
|
|
|
|
|
private String secret; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private HttpServletRequest request; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Res<?> getApps(Integer page, Integer size) { |
|
|
public Res<?> getApps(Integer page, Integer size) { |
|
|
// 参数校验 |
|
|
// 参数校验 |
|
|
@ -133,6 +146,11 @@ public class AppServiceImpl implements AppService { |
|
|
log.error("启动应用请求异常, param={},download error:{}", param, downloadRes); |
|
|
log.error("启动应用请求异常, param={},download error:{}", param, downloadRes); |
|
|
return Res.fail("启动应用请求异常"); |
|
|
return Res.fail("启动应用请求异常"); |
|
|
} |
|
|
} |
|
|
|
|
|
//获取Authorization |
|
|
|
|
|
String authorization = request.getHeader(Constants.AUTHORIZATION); |
|
|
|
|
|
//获取用户id |
|
|
|
|
|
Claims claims = JwtUtil.getClaimsFromToken(authorization, secret); |
|
|
|
|
|
int userId = (int) claims.get(Constants.USERID); |
|
|
//任务录入表中 |
|
|
//任务录入表中 |
|
|
Task task = new Task(); |
|
|
Task task = new Task(); |
|
|
task.setId(taskId); |
|
|
task.setId(taskId); |
|
|
@ -140,7 +158,7 @@ public class AppServiceImpl implements AppService { |
|
|
task.setAppId(appId); |
|
|
task.setAppId(appId); |
|
|
task.setDel(0); |
|
|
task.setDel(0); |
|
|
task.setStatus(0); |
|
|
task.setStatus(0); |
|
|
task.setUserId("1"); |
|
|
|
|
|
|
|
|
task.setUserId(userId); |
|
|
taskMapper.insert(task); |
|
|
taskMapper.insert(task); |
|
|
// ---------- 返回 ---------- |
|
|
// ---------- 返回 ---------- |
|
|
return Res.ok(task); |
|
|
return Res.ok(task); |
|
|
@ -163,10 +181,11 @@ public class AppServiceImpl implements AppService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 从登录上下文获取 userId(你项目里已有) 先写死 |
|
|
// 从登录上下文获取 userId(你项目里已有) 先写死 |
|
|
String userId = "1"; |
|
|
|
|
|
if (userId == null || userId.trim().equals("")) { |
|
|
|
|
|
return Res.fail("未获取到用户信息"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
String authorization = request.getHeader(Constants.AUTHORIZATION); |
|
|
|
|
|
log.info("authorization:{}",authorization); |
|
|
|
|
|
//获取用户id |
|
|
|
|
|
Claims claims = JwtUtil.getClaimsFromToken(authorization, secret); |
|
|
|
|
|
int userId = (int) claims.get(Constants.USERID); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
Page<Task> pageParam = new Page<>(page, size); |
|
|
Page<Task> pageParam = new Page<>(page, size); |
|
|
@ -174,7 +193,7 @@ public class AppServiceImpl implements AppService { |
|
|
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>(); |
|
|
wrapper.eq(Task::getDel, 0) |
|
|
wrapper.eq(Task::getDel, 0) |
|
|
.eq(Task::getAppId,appId) |
|
|
.eq(Task::getAppId,appId) |
|
|
.eq(userId != null, Task::getUserId, userId) |
|
|
|
|
|
|
|
|
.eq(Task::getUserId, userId) |
|
|
.orderByDesc(Task::getCreateTime); |
|
|
.orderByDesc(Task::getCreateTime); |
|
|
|
|
|
|
|
|
Page<Task> result = taskMapper.selectPage(pageParam, wrapper); |
|
|
Page<Task> result = taskMapper.selectPage(pageParam, wrapper); |
|
|
|