perf:优化部分代码

This commit is contained in:
曾文豪
2023-08-14 15:43:48 +08:00
parent 28a2fa0262
commit 0fabc7aae9
11 changed files with 79534 additions and 46 deletions

View File

@@ -1,6 +1,17 @@
stages:
- deploy
qodana:
stage: deploy
tags:
- zengos
image:
name: jetbrains/qodana-jvm
entrypoint: [ "" ]
script:
- qodana --save-report --baseline=qodana.sarif.json --results-dir=$CI_PROJECT_DIR/.qodana
deploy-jar:
stage: deploy
tags:

79447
qodana.sarif.json Normal file

File diff suppressed because it is too large Load Diff

24
qodana.yaml Normal file
View File

@@ -0,0 +1,24 @@
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#
version: "1.0"
#Specify inspection profile for code analysis
profile:
name: qodana.starter
#Enable inspections
#include:
# - name: <SomeEnabledInspectionId>
#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>
projectJDK: 1.8 #(Applied in CI/CD pipeline)
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
#bootstrap: sh ./prepare-qodana.sh
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
#plugins:
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-jvm:latest

View File

@@ -31,9 +31,6 @@ public class DemoWebConfigurer implements TieshengWebConfigurer {
TokenBean tokenBean = null;
if (!StrUtil.isEmpty(platformUnique.getUserId())) {
tokenBean = new TokenBean(platformUnique.getUserId(), "", globalConfig.getService());
} else {
// 获取用户信息判断是否可登录
}
return tokenBean;

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
@@ -125,9 +126,11 @@ public class PlatformDingConfig {
* @see <a href="https://open.dingtalk.com/document/isvapp-server/obtain-the-userid-of-a-user-by-using-the-log-free"></a>
*/
public String getUserIdByCode(String service, String code) {
String response = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo?access_token=" + getAccessToken(service))
.body(JSONUtil.createObj().putOpt("code", code).toString()).execute().body();
return JSONUtil.parseObj(response).getJSONObject("result").getStr("userid");
HttpRequest request = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo?access_token=" + getAccessToken(service))
.body(JSONUtil.createObj().putOpt("code", code).toString());
try (HttpResponse response = request.execute()) {
return JSONUtil.parseObj(response.body()).getJSONObject("result").getStr("userid");
}
}
@@ -141,16 +144,17 @@ public class PlatformDingConfig {
*/
public DingUserInfo topapiV2UserGet(String service, String ddUserId) {
DingConfigBean dingConfigBean = getConfigBean(service);
String response = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/user/get?access_token=" + getAccessToken(service))
.body(JSONUtil.createObj().putOpt("userid", ddUserId).toString()).execute().body();
JSONObject resultJson = JSONUtil.parseObj(response).getJSONObject("result");
try (HttpResponse response = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/user/get?access_token="
+ getAccessToken(service))
.body(JSONUtil.createObj().putOpt("userid", ddUserId).toString()).execute()) {
JSONObject resultJson = JSONUtil.parseObj(response.body()).getJSONObject("result");
DingUserInfo userInfo = JSONUtil.toBean(resultJson, DingUserInfo.class);
// 设置一下job_number
userInfo.setJobNumber(resultJson.getStr("job_number"));
userInfo.setAppId(dingConfigBean.getAppKey());
return userInfo;
}
}
/**
* 获取部门列表
@@ -164,9 +168,9 @@ public class PlatformDingConfig {
if (StrUtil.isEmpty(token)) {
return new ArrayList<>();
}
String response = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/department/listsub?access_token=" + token)
.body(JSONUtil.createObj().putOpt("dept_id", deptId).toString()).execute().body();
DingResponse<List<DingDeptVo>> result = JSONUtil.toBean(response, new TypeReference<DingResponse<List<DingDeptVo>>>() {
try (HttpResponse response = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/department/listsub?access_token=" + token)
.body(JSONUtil.createObj().putOpt("dept_id", deptId).toString()).execute()) {
DingResponse<List<DingDeptVo>> result = JSONUtil.toBean(response.body(), new TypeReference<DingResponse<List<DingDeptVo>>>() {
}.getType(), true);
if (!result.isOk()) {
@@ -174,6 +178,7 @@ public class PlatformDingConfig {
}
return result.getResult();
}
}
/**
@@ -187,17 +192,17 @@ public class PlatformDingConfig {
if (StrUtil.isEmpty(token)) {
return DingUserListVo.fail();
}
String response = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/user/list?access_token=" + token)
try (HttpResponse response = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/user/list?access_token=" + token)
.body(JSONUtil.createObj().putOpt("dept_id", deptId).putOpt("cursor", cursor).putOpt("size", 100).toString())
.execute().body();
DingResponse<DingUserListVo> result = JSONUtil.toBean(response, new TypeReference<DingResponse<DingUserListVo>>() {
.execute()) {
DingResponse<DingUserListVo> result = JSONUtil.toBean(response.body(), new TypeReference<DingResponse<DingUserListVo>>() {
}.getType(), true);
if (!result.isOk()) {
result.setResult(DingUserListVo.fail());
}
return result.getResult();
}
}
/**
* 同步钉钉的通讯录

View File

@@ -3,6 +3,7 @@ package com.tiesheng.platform.config.wxmini;
import cn.hutool.core.map.MapUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
@@ -50,13 +51,14 @@ public class PlatformWxminiConfig {
*/
public String jscode2session(String service, String code) {
WxConfigBean configBean = getConfigBean(service);
String body = HttpRequest.get("https://api.weixin.qq.com/sns/jscode2session"
try (HttpResponse response = HttpRequest.get("https://api.weixin.qq.com/sns/jscode2session"
+ "?appid=" + configBean.getAppId()
+ "&secret=" + configBean.getAppSecret()
+ "&js_code=" + code + "&grant_type=authorization_code").execute().body();
JSONObject object = JSONUtil.parseObj(body);
+ "&js_code=" + code + "&grant_type=authorization_code").execute()) {
JSONObject object = JSONUtil.parseObj(response.body());
return object.getStr("openid");
}
}
/**
* 获取access_token
@@ -65,12 +67,13 @@ public class PlatformWxminiConfig {
*/
public String getAccessToken(String service) {
WxConfigBean configBean = getConfigBean(service);
String body = HttpRequest.get("https://api.weixin.qq.com/cgi-bin/token"
try (HttpResponse response = HttpRequest.get("https://api.weixin.qq.com/cgi-bin/token"
+ "?grant_type=client_credential&appid=" + configBean.getAppId()
+ "&secret=" + configBean.getAppSecret()).execute().body();
JSONObject object = JSONUtil.parseObj(body);
+ "&secret=" + configBean.getAppSecret()).execute()) {
JSONObject object = JSONUtil.parseObj(response.body());
return object.getStr("access_token");
}
}
///////////////////////////////////////////////////////////////////////////

View File

@@ -26,7 +26,8 @@ public class ServletKit extends ServletUtil {
* @return
*/
public static String getClientIP() {
return getClientIP(getRequest());
HttpServletRequest request = getRequest();
return getClientIP(request);
}

View File

@@ -179,7 +179,7 @@ public class Searcher {
this.ioCount = 0;
// locate the segment index block based on the vector index
int sPtr = 0, ePtr = 0;
int sPtr, ePtr;
int il0 = (int) ((ip >> 24) & 0xFF);
int il1 = (int) ((ip >> 16) & 0xFF);
int idx = il0 * VectorIndexCols * VectorIndexSize + il1 * VectorIndexSize;

View File

@@ -11,6 +11,7 @@ import com.tiesheng.core.pojos.dao.CoreJobUser;
import com.tiesheng.util.pojos.IdName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@@ -35,6 +36,7 @@ public class CoreJobService extends TsServiceBase<CoreJobMapper, CoreJob> {
* @param remark
* @param isSystem
*/
@Transactional(rollbackFor = Exception.class)
public void refresh(String id, String name, String remark, Integer isSystem) {
CoreJob coreJob = new CoreJob();
coreJob.setId(id);

View File

@@ -8,6 +8,7 @@ import com.tiesheng.login.pojos.DoLoginInfo;
import com.tiesheng.login.service.TieshengLoginConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
@@ -23,6 +24,7 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
CoreLogService coreLogService;
@Override
@Transactional(rollbackFor = Exception.class)
public TokenBean doLogin(DoLoginInfo loginInfo) {
CorePlatformUnique platformUnique = getOneByColumn("unique_id", loginInfo.getUnique());

View File

@@ -14,6 +14,7 @@ import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
/**
@@ -159,12 +160,7 @@ public class FileUploadService {
//将文件数组转成list并排序
List<File> chunkFileList = new ArrayList<>(Arrays.asList(chunkFiles));
//排序
chunkFileList.sort((o1, o2) -> {
if (Integer.parseInt(o1.getName()) > Integer.parseInt(o2.getName())) {
return 1;
}
return -1;
});
chunkFileList.sort(Comparator.comparingInt(o -> Integer.parseInt(o.getName())));
return chunkFileList;
}