Browse Source

性能优化

dev
vincent 3 days ago
parent
commit
fdb2da532d
  1. 89
      zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/common/util/HttpUtil.java
  2. 56
      zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/controller/app/enforcement/AppEnforcementRegistrationController.java
  3. 1
      zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/controller/app/enterprise/AppEntEnforcementRegistrationController.java
  4. 5
      zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/domain/bo/EnforcementRegistrationQueryBo.java
  5. 15
      zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/service/impl/EnforcementRegistrationServiceImpl.java
  6. 4
      zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/service/thirdparty/impl/SzyServiceImpl.java
  7. 5
      zdxt-modules/zdxt-system/src/main/java/org/dromara/system/service/impl/PasswordPartyServiceImpl.java
  8. 6
      zdxt-web-server/zdxt-admin-web-server/src/main/resources/application-prod.yml

89
zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/common/util/HttpUtil.java

@ -1,8 +1,25 @@
package com.zdxt.enforcementcode.common.util;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.BufferedReader;
import java.io.DataOutputStream;
@ -15,8 +32,8 @@ import java.util.Map;
public class HttpUtil {
private static final Logger log = LoggerFactory.getLogger(HttpUtil.class);
/**
* 发送 POST 请求
*
@ -29,44 +46,44 @@ public class HttpUtil {
log.info("============================== Post请求开始 ==============================");
log.info("---> url: {}",url);
try {
URL uri = new URL(url);
HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/json");
connection.setRequestProperty("Charsert","UTF-8");
for (Map.Entry<String, Object> entry : heardMap.entrySet()) {
// 对value进行相应的操作
connection.setRequestProperty(entry.getKey(), String.valueOf(entry.getValue()));
}
connection.setDoOutput(true);
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
// out.writeBytes(params);
out.write(params.getBytes(StandardCharsets.UTF_8)); //解决中文乱码
out.flush();
out.close();
int responseCode = connection.getResponseCode();
if(responseCode == HttpURLConnection.HTTP_OK){
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null){
response.append(inputLine);
// 内网用 IP 访问时证书是 *.szssfj.cn,与 GET 保持一致:信任所有证书并跳过主机名校验
SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", new SSLConnectionSocketFactory(sc, NoopHostnameVerifier.INSTANCE))
.build();
PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry);
try (CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(manager).build()) {
HttpPost httpPost = new HttpPost(url);
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(30000)
.setSocketTimeout(30000)
.build();
httpPost.setConfig(config);
httpPost.setHeader("Content-Type", "application/json");
for (Map.Entry<String, Object> entry : heardMap.entrySet()) {
httpPost.setHeader(entry.getKey(), String.valueOf(entry.getValue()));
}
httpPost.setEntity(new StringEntity(params, ContentType.create("application/json", StandardCharsets.UTF_8)));
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
int responseCode = response.getStatusLine().getStatusCode();
String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
if (responseCode == HttpURLConnection.HTTP_OK) {
log.info("post请求成功: {}", body);
return body;
} else {
log.error("============================== Post请求调用失败 ==============================");
log.error("---> 失败码:{}", responseCode);
log.error("---> url: {}", url);
log.error("---> params: {}", params);
log.error("---> 响应体:{}", body);
log.error("============================== =========================== ==============================");
}
}
in.close();
log.info("post请求成功"+response.toString());
return response.toString();
}else{
log.error("============================== Post请求调用失败 ==============================");
log.error("---> 失败码:{}",responseCode);
log.error("---> url: {}",url);
log.error("---> params: {}",params);
log.error("---> heardMap: {}",heardMap);
log.error("============================== =========================== ==============================");
// BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
}
} catch (Exception e) {
e.printStackTrace();
log.error("Post请求异常, url: {}", url, e);
}
return "";

56
zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/controller/app/enforcement/AppEnforcementRegistrationController.java

@ -62,7 +62,7 @@ import java.util.*;
@RequestMapping("/app-enf/enfRegistration")
public class AppEnforcementRegistrationController extends BaseController {
private final ISysConfigService sysConfigService;
private final IEnforcementRegistrationService enforcementRegistrationService;
private final ISysDeptService sysDeptService;
@Autowired
@ -570,10 +570,6 @@ public class AppEnforcementRegistrationController extends BaseController {
if (list == null || list.isEmpty()) {
return pageResult;
}
//todo: 性能测试开启
if(isListFunEnabled()){
return pageResult;
}
// 1. 批量获取字典数据(只查询一次)
List<SysDictDataVo> dicts = getCheckCategoryDicts();
Map<String, String> dictMap = buildDictMap(dicts);
@ -581,6 +577,8 @@ public class AppEnforcementRegistrationController extends BaseController {
// 2. 收集所有用户ID并批量查询(只查询一次)
List<Long> allUserIds = collectAllUserIds(list);
Map<Long, SysUserVo> userMap = buildUserMap(allUserIds);
// 2.5 按用户预构建展示文本(每人只解密一次,避免跨行重复解密)
Map<Long, String> displayTextMap = buildEnforcerDisplayTextMap(userMap);
// 3. 批量查询投诉标记(只查询一次)
List<String> recordIds = extractRecordIds(list);
@ -590,20 +588,14 @@ public class AppEnforcementRegistrationController extends BaseController {
for (EnforcementRegistrationVo vo : list) {
fillComplaintFlagFromMap(vo, complaintMap);
fillCheckCategoryText(vo, dictMap);
fillLawEnforcerInfo(vo, userMap);
fillLawEnforcerInfo(vo, displayTextMap);
fillOutTimeDayNum(vo);
}
return pageResult;
}
/**
* 校验系统参数 opt.fun 是否开启(1=true=Y 视为开启)
*/
private boolean isListFunEnabled() {
String value = sysConfigService.selectConfigByKey("list.fun");
return "1".equals(value) || "true".equalsIgnoreCase(value) || "Y".equalsIgnoreCase(value);
}
/**
* 获取检查类别字典数据
*/
@ -743,24 +735,23 @@ public class AppEnforcementRegistrationController extends BaseController {
/**
* 填充执法人员信息
*/
private void fillLawEnforcerInfo(EnforcementRegistrationVo vo, Map<Long, SysUserVo> userMap) {
fillLawEnforcer1(vo, userMap);
fillLawEnforcer2(vo, userMap);
private void fillLawEnforcerInfo(EnforcementRegistrationVo vo, Map<Long, String> displayTextMap) {
fillLawEnforcer1(vo, displayTextMap);
fillLawEnforcer2(vo, displayTextMap);
}
/**
* 填充执法人员1信息
*/
private void fillLawEnforcer1(EnforcementRegistrationVo vo, Map<Long, SysUserVo> userMap) {
private void fillLawEnforcer1(EnforcementRegistrationVo vo, Map<Long, String> displayTextMap) {
if (StringUtils.isEmpty(vo.getLawEnforcerId())) {
return;
}
try {
Long userId = Long.parseLong(vo.getLawEnforcerId());
SysUserVo user = userMap.get(userId);
if (user != null) {
String lawCN = buildEnforcerDisplayText(user);
vo.setLawEnforcer(lawCN);
String displayText = displayTextMap.get(userId);
if (displayText != null) {
vo.setLawEnforcer(displayText);
}
} catch (NumberFormatException ignored) {
}
@ -769,7 +760,7 @@ public class AppEnforcementRegistrationController extends BaseController {
/**
* 填充执法人员2信息列表
*/
private void fillLawEnforcer2(EnforcementRegistrationVo vo, Map<Long, SysUserVo> userMap) {
private void fillLawEnforcer2(EnforcementRegistrationVo vo, Map<Long, String> displayTextMap) {
List<String> lawTwoList = new ArrayList<>();
if (StringUtils.isEmpty(vo.getLawEnforcerIdTwo())) {
vo.setLawEnforcer2List(lawTwoList);
@ -783,9 +774,9 @@ public class AppEnforcementRegistrationController extends BaseController {
}
try {
Long userId = Long.parseLong(id.trim());
SysUserVo user = userMap.get(userId);
if (user != null) {
lawTwoList.add(buildEnforcerDisplayText(user));
String displayText = displayTextMap.get(userId);
if (displayText != null) {
lawTwoList.add(displayText);
}
} catch (NumberFormatException ignored) {
}
@ -793,6 +784,21 @@ public class AppEnforcementRegistrationController extends BaseController {
vo.setLawEnforcer2List(lawTwoList);
}
/**
* 按用户批量构建执法人员展示文本(用户名 + 执法码/脱敏手机号)
* <p>每页每个用户只解密一次,行级填充直接复用。</p>
*/
private Map<Long, String> buildEnforcerDisplayTextMap(Map<Long, SysUserVo> userMap) {
Map<Long, String> displayTextMap = new HashMap<>();
if (userMap == null || userMap.isEmpty()) {
return displayTextMap;
}
for (Map.Entry<Long, SysUserVo> entry : userMap.entrySet()) {
displayTextMap.put(entry.getKey(), buildEnforcerDisplayText(entry.getValue()));
}
return displayTextMap;
}
/**
* 构建执法人员展示文本(用户名 + 执法码/加密手机号)
*/

1
zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/controller/app/enterprise/AppEntEnforcementRegistrationController.java

@ -53,6 +53,7 @@ public class AppEntEnforcementRegistrationController extends BaseController {
@GetMapping("/queryEnforcementRegistrationPageList")
public TableDataInfo<EnforcementRegistrationListVo> queryEnforcementRegistrationPageList( EnforcementRegistrationQueryBo bo, PageQuery pageQuery) {
bo.setIsSubmit(1L);
bo.setIsEnt(1L);
return enforcementRegistrationService.queryEnforcementRegistrationPageList(bo, pageQuery);
}

5
zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/domain/bo/EnforcementRegistrationQueryBo.java

@ -86,4 +86,9 @@ public class EnforcementRegistrationQueryBo implements Serializable {
* 是否提交(0:未提交; 1:已提交)
*/
private Long IsSubmit;
/**
* 是否企业端(0:未提交; 1:已提交)
*/
private Long IsEnt;
}

15
zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/service/impl/EnforcementRegistrationServiceImpl.java

@ -34,6 +34,7 @@ import org.dromara.system.domain.vo.SysDeptVo;
import org.dromara.system.domain.vo.SysDictDataVo;
import org.dromara.system.mapper.SysDeptMapper;
import org.dromara.system.mapper.SysUserMapper;
import org.dromara.system.service.ISysConfigService;
import org.dromara.system.service.ISysDictTypeService;
import org.springframework.stereotype.Service;
import com.zdxt.enforcementcode.service.IEnforcementRegistrationService;
@ -67,7 +68,7 @@ public class EnforcementRegistrationServiceImpl implements IEnforcementRegistrat
private final ZdxtFileMapper zdxtFileMapper;
private final SysDeptMapper sysDeptMapper;
private final EnterpriseInformationMapper enterpriseInformationMapper;
private final ISysConfigService sysConfigService;
/**
* 查询企业端-执法登记记录
@ -439,6 +440,10 @@ public class EnforcementRegistrationServiceImpl implements IEnforcementRegistrat
IPage<EnforcementRegistrationListVo> result = baseMapper.selectEnforcementRegistrationPage(page, bo);
List<EnforcementRegistrationListVo> records = result.getRecords();
if(bo.getIsEnt() != null && bo.getIsEnt() == 1 && isListFunEnabled()){
return TableDataInfo.build(result);
}
// ===== 1. 批量查询执法人员信息 =====
// 收集所有用户ID(执法人员1 + 执法人员2)
Set<Long> allUserIds = new HashSet<>();
@ -537,6 +542,14 @@ public class EnforcementRegistrationServiceImpl implements IEnforcementRegistrat
return TableDataInfo.build(result);
}
/**
* 校验系统参数 opt.fun 是否开启(1=true=Y 视为开启)
*/
private boolean isListFunEnabled() {
String value = sysConfigService.selectConfigByKey("ent.list.fun");
return "1".equals(value) || "true".equalsIgnoreCase(value) || "Y".equalsIgnoreCase(value);
}
/**
* 企业端-执法登记详情
* @param id

4
zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/service/thirdparty/impl/SzyServiceImpl.java

@ -51,7 +51,7 @@ public class SzyServiceImpl implements ISzyService {
String accessTokenJson = HttpUtil.HttpSendGet(szyptUrl + "/cgi-bin/gettoken?corpid="+szyptCorpid+"&corpsecret="+szyptCorpsecret, null);
JSONObject tokenObj = JSONObject.parseObject(accessTokenJson);
String token = tokenObj.getString("access_token");
log.info("深政易主动发送消息:access_token:{}", token);
// log.info("深政易主动发送消息:access_token:{}", token);
// 2.拼接消息内容
JSONObject params = new JSONObject();
@ -64,7 +64,7 @@ public class SzyServiceImpl implements ISzyService {
log.info("深政易主动发送消息:params:{}", params);
// 3.调用发送消息接口
String data = com.zdxt.enforcementcode.common.util.HttpUtil.httpSendPost(szyptUrl + "cgi-bin/message/send?access_token="+token, JSONObject.toJSONString(params), new HashMap<>());
String data = com.zdxt.enforcementcode.common.util.HttpUtil.httpSendPost(szyptUrl + "/cgi-bin/message/send?access_token="+token, JSONObject.toJSONString(params), new HashMap<>());
JSONObject jsonObject = JSONObject.parseObject(data);
log.info("深政易主动发送消息:data:{}", jsonObject);

5
zdxt-modules/zdxt-system/src/main/java/org/dromara/system/service/impl/PasswordPartyServiceImpl.java

@ -50,11 +50,6 @@ public class PasswordPartyServiceImpl implements IPasswordPartyService {
*/
@Override
public SymmetryEncryptVo symmetryEncrypt(String inputData) {
// SymmetryEncryptVo symmetryEncryptVo = new SymmetryEncryptVo();
// symmetryEncryptVo.setIvData("1234567890123456");
// symmetryEncryptVo.setOutData("123");
// return symmetryEncryptVo;
// TODO 生成随机数,目前使用SecureRandom,后续需要替换为HSM生成随机数
String iv = generateRandom(16);
JSONObject params = buildSymmetryParams(iv, inputData);

6
zdxt-web-server/zdxt-admin-web-server/src/main/resources/application-prod.yml

@ -75,12 +75,12 @@ spring:
username: SSFJJDM
password: "6AK$xi7AH+"
hikari:
# 最大连接池数量
maxPoolSize: 1000
# 最大连接池数量:4 个 DB 节点分摊,单实例 100 已远超 Undertow 256 worker 的并发需求
maxPoolSize: 100
# 最小空闲线程数量
minIdle: 20
# 配置获取连接等待超时的时间
connectionTimeout: 30000
connectionTimeout: 10000
# 校验超时时间
validationTimeout: 5000
# 空闲连接存活最大时间,默认10分钟

Loading…
Cancel
Save