diff --git a/luqj-common/src/main/java/com/luqj/util/HttpHelper.java b/luqj-common/src/main/java/com/luqj/util/HttpHelper.java index 9037059..ea514e5 100644 --- a/luqj-common/src/main/java/com/luqj/util/HttpHelper.java +++ b/luqj-common/src/main/java/com/luqj/util/HttpHelper.java @@ -41,7 +41,9 @@ import java.util.zip.GZIPInputStream; public class HttpHelper { private String proxyHost; private Integer proxyPort; + private CloseableHttpClient httpsClient = null; + private CloseableHttpClient httpClient = null; public String getProxyHost() { return proxyHost; } @@ -57,7 +59,20 @@ public class HttpHelper { public void setProxyPort(Integer proxyPort) { this.proxyPort = proxyPort; } - + public void closeClient(){ + try { + if (httpsClient != null) { + httpsClient.close(); + httpsClient = null; + } + if (httpClient != null) { + httpClient.close(); + httpClient = null; + } + }catch (Exception e){ + log.error(e.getMessage(),e); + } + } public static void main(String[] args) throws Exception { BigDecimal decimal = new BigDecimal("1").divide(new BigDecimal(100)); @@ -444,13 +459,19 @@ public class HttpHelper { * @return */ public String getlHttpResult(String url, String method, Map headers, Map params) throws Exception { - CloseableHttpClient httpClient = null; + CloseableHttpClient tempClient = null; if (url.startsWith("https")) { - httpClient = getHttpsClient(); + if(httpsClient == null){ + httpsClient = getHttpsClient(); + } + tempClient = httpsClient; } else { - httpClient = getHttpClient(); + if(httpClient == null) { + httpClient = getHttpClient(); + } + tempClient = httpClient; } - CloseableHttpResponse response = this.send(httpClient, url, method, headers, params); + CloseableHttpResponse response = this.send(tempClient, url, method, headers, params); if (method.toLowerCase().equals("options")) { return response.getStatusLine().getStatusCode() + ""; } else { @@ -466,24 +487,36 @@ public class HttpHelper { } public String getlHttpResultCode(String url, String method, Map headers, Map params) throws Exception { - CloseableHttpClient httpClient = null; + CloseableHttpClient tempClient = null; if (url.startsWith("https")) { - httpClient = getHttpsClient(); + if(httpsClient == null){ + httpsClient = getHttpsClient(); + } + tempClient = httpsClient; } else { - httpClient = getHttpClient(); + if(httpClient == null) { + httpClient = getHttpClient(); + } + tempClient = httpClient; } - CloseableHttpResponse response = this.send(httpClient, url, method, headers, params); + CloseableHttpResponse response = this.send(tempClient, url, method, headers, params); return response.getStatusLine().getStatusCode() + ""; } public Boolean testHttp(String url, String method, Map headers, Map params) throws Exception { - CloseableHttpClient httpClient = null; + CloseableHttpClient tempClient = null; if (url.startsWith("https")) { - httpClient = getHttpsClient(); + if(httpsClient == null){ + httpsClient = getHttpsClient(); + } + tempClient = httpsClient; } else { - httpClient = getHttpClient(); + if(httpClient == null) { + httpClient = getHttpClient(); + } + tempClient = httpClient; } - CloseableHttpResponse response = this.send(httpClient, url, method, headers, params); + CloseableHttpResponse response = this.send(tempClient, url, method, headers, params); boolean result = response.getStatusLine().getStatusCode() == 200; response.close(); return result; @@ -494,11 +527,17 @@ public class HttpHelper { } public String playLoad(String method, String url, Map headersMap, Object data, String contentType, String charset) throws Exception { - CloseableHttpClient httpClient = null; + CloseableHttpClient tempClient = null; if (url.startsWith("https")) { - httpClient = getHttpsClient(); + if(httpsClient == null){ + httpsClient = getHttpsClient(); + } + tempClient = httpsClient; } else { - httpClient = getHttpClient(); + if(httpClient == null) { + httpClient = getHttpClient(); + } + tempClient = httpClient; } String result = null; HttpEntityEnclosingRequestBase httpEntityEnclosingRequestBase = null; @@ -532,7 +571,7 @@ public class HttpHelper { CloseableHttpResponse response = null; try { // 由客户端执行(发送)Post请求 - response = (CloseableHttpResponse) httpClient.execute(httpEntityEnclosingRequestBase); + response = (CloseableHttpResponse) tempClient.execute(httpEntityEnclosingRequestBase); // 从响应模型中获取响应实体 HttpEntity responseEntity = response.getEntity(); System.out.println("响应状态为:" + response.getStatusLine()); diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 4c58b25..7678f64 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -9,6 +9,7 @@ ruoyi: - /system/file/uploadImage - /ec/device-api/report - /ec/device-api/heartbeat + - /system/global/close-http-client # 名称 name: RuoYi # 版本 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppsController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppsController.java index 87f6581..23bb925 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppsController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppsController.java @@ -1,98 +1,92 @@ package com.ruoyi.system.controller; -import com.ruoyi.common.select.Ids; -import com.ruoyi.common.select.SelectItem; -import java.util.List; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; + import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.select.Ids; +import com.ruoyi.common.select.SelectItem; +import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.system.domain.Apps; import com.ruoyi.system.domain.AppsPlus; import com.ruoyi.system.service.IAppsService; -import com.ruoyi.common.utils.poi.ExcelUtil; -import com.ruoyi.common.core.page.TableDataInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.List; /** * 应用管理Controller - * + * * @author luqj * @date 2025-11-25 */ @RestController @RequestMapping("/system/apps") -public class AppsController extends BaseController -{ +public class AppsController extends BaseController { @Autowired private IAppsService appsService; + @PreAuthorize("@ss.hasPermi('system:apps:getByIds')") @PostMapping("/getByIds") - public AjaxResult getByIds(@RequestBody Ids ids) - { - List list = appsService.getByIds(ids.getLongIds(),false,AppsPlus::getName,AppsPlus::getId); + public AjaxResult getByIds(@RequestBody Ids ids) { + List list = appsService.getByIds(ids.getLongIds(), false, AppsPlus::getName, AppsPlus::getId); return AjaxResult.success(list); } + @PreAuthorize("@ss.hasPermi('system:apps:user-getByIds')") @PostMapping("/user/getByIds") - public AjaxResult userGetByIds(@RequestBody Ids ids) - { - List list = appsService.getByIds(ids.getLongIds(),true,AppsPlus::getName,AppsPlus::getUserId,AppsPlus::getId); + public AjaxResult userGetByIds(@RequestBody Ids ids) { + List list = appsService.getByIds(ids.getLongIds(), true, AppsPlus::getName, AppsPlus::getUserId, AppsPlus::getId); return AjaxResult.success(list); } + @PreAuthorize("@ss.hasPermi('system:apps:select')") @GetMapping("/select") - public AjaxResult select(String keyword) - { - List list = appsService.select(keyword,false); + public AjaxResult select(String keyword) { + List list = appsService.select(keyword, false); return AjaxResult.success(list); } + @PreAuthorize("@ss.hasPermi('system:apps:user-select')") @GetMapping("/user/select") - public AjaxResult userSelect(String keyword) - { - List list = appsService.select(keyword,true); + public AjaxResult userSelect(String keyword) { + List list = appsService.select(keyword, true); return AjaxResult.success(list); } + /** * 查询应用管理列表 */ @PreAuthorize("@ss.hasPermi('system:apps:list')") @GetMapping("/list") - public TableDataInfo list(Apps apps) - { + public TableDataInfo list(Apps apps) { startPage(); - List list = appsService.selectAppsList(apps,false); + List list = appsService.selectAppsList(apps, false); return getDataTable(list); } -/** - * 查询应用管理列表 - */ -@PreAuthorize("@ss.hasPermi('system:apps:user-list')") -@GetMapping("/user/list") - public TableDataInfo userList(Apps apps) - { + + /** + * 查询应用管理列表 + */ + @PreAuthorize("@ss.hasPermi('system:apps:user-list')") + @GetMapping("/user/list") + public TableDataInfo userList(Apps apps) { startPage(); - List list = appsService.selectAppsList(apps,true); + List list = appsService.selectAppsList(apps, true); return getDataTable(list); } - /** + + /** * 导出应用管理列表 */ @PreAuthorize("@ss.hasPermi('system:apps:export')") @Log(title = "应用管理", businessType = BusinessType.EXPORT) @GetMapping("/export") - public AjaxResult export(Apps apps) - { - List list = appsService.selectAppsList(apps,false); + public AjaxResult export(Apps apps) { + List list = appsService.selectAppsList(apps, false); ExcelUtil util = new ExcelUtil(Apps.class); return util.exportExcel(list, "apps"); } @@ -102,74 +96,73 @@ public class AppsController extends BaseController */ @PreAuthorize("@ss.hasPermi('system:apps:query')") @GetMapping(value = "/{id}") - public AjaxResult getInfo(@PathVariable("id") Long id) - { - return AjaxResult.success(appsService.selectAppsById(id,false)); + public AjaxResult getInfo(@PathVariable("id") Long id) { + return AjaxResult.success(appsService.selectAppsById(id, false)); } + /** * 获取应用管理详细信息 */ @PreAuthorize("@ss.hasPermi('system:apps:user-query')") @GetMapping(value = "/user/{id}") - public AjaxResult userGetInfo(@PathVariable("id") Long id) - { - return AjaxResult.success(appsService.selectAppsById(id,true)); + public AjaxResult userGetInfo(@PathVariable("id") Long id) { + return AjaxResult.success(appsService.selectAppsById(id, true)); } + /** * 新增应用管理 */ @PreAuthorize("@ss.hasPermi('system:apps:add')") @Log(title = "应用管理", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody Apps apps) - { - return toAjax(appsService.insertApps(apps,false)); + public AjaxResult add(@RequestBody Apps apps) { + return toAjax(appsService.insertApps(apps, false)); } + /** * 新增应用管理 */ @PreAuthorize("@ss.hasPermi('system:apps:user-add')") @Log(title = "应用管理", businessType = BusinessType.INSERT) @PostMapping("/user") - public AjaxResult userAdd(@RequestBody Apps apps) - { - return toAjax(appsService.insertApps(apps,true)); + public AjaxResult userAdd(@RequestBody Apps apps) { + return toAjax(appsService.insertApps(apps, true)); } + /** * 修改应用管理 */ @PreAuthorize("@ss.hasPermi('system:apps:edit')") @Log(title = "应用管理", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody Apps apps) - { - return toAjax(appsService.updateApps(apps,false)); + public AjaxResult edit(@RequestBody Apps apps) { + return toAjax(appsService.updateApps(apps, false)); } + @PreAuthorize("@ss.hasPermi('system:apps:user-edit')") @Log(title = "应用管理", businessType = BusinessType.UPDATE) @PutMapping("/user") - public AjaxResult userEdit(@RequestBody Apps apps) - { - return toAjax(appsService.updateApps(apps,true)); + public AjaxResult userEdit(@RequestBody Apps apps) { + return toAjax(appsService.updateApps(apps, true)); } + /** * 删除应用管理 */ @PreAuthorize("@ss.hasPermi('system:apps:remove')") @Log(title = "应用管理", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable Long[] ids) - { - return toAjax(appsService.deleteAppsByIds(ids,false)); + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(appsService.deleteAppsByIds(ids, false)); } + /** * 删除应用管理 */ @PreAuthorize("@ss.hasPermi('system:apps:user-remove')") @Log(title = "应用管理", businessType = BusinessType.DELETE) @DeleteMapping("/user/{ids}") - public AjaxResult userRemove(@PathVariable Long[] ids) - { - return toAjax(appsService.deleteAppsByIds(ids,true)); + public AjaxResult userRemove(@PathVariable Long[] ids) { + return toAjax(appsService.deleteAppsByIds(ids, true)); } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/GlobalController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/GlobalController.java new file mode 100644 index 0000000..ec0d79f --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/GlobalController.java @@ -0,0 +1,26 @@ +package com.ruoyi.system.controller; + +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.system.service.IDmPlayerTaskGroupService; +import com.ruoyi.system.service.IDmPlayerentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +// +@RestController +@RequestMapping("/system/global") +public class GlobalController { + @Autowired + private IDmPlayerentService dmPlayerentService; + @Autowired + private IDmPlayerTaskGroupService dmPlayerTaskGroupService; + + @GetMapping(value = "/close-http-client") + public AjaxResult closeHttpClient() { + dmPlayerentService.closeHttpClient(); + dmPlayerTaskGroupService.closeHttpClient(); + return AjaxResult.success(true); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IDmPlayerTaskGroupService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IDmPlayerTaskGroupService.java index 2f7cc1a..e4c4d1f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IDmPlayerTaskGroupService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IDmPlayerTaskGroupService.java @@ -90,4 +90,6 @@ public interface IDmPlayerTaskGroupService extends IService List countByGroupBy(String select, String where, String groupby, Class tClass); boolean operate(DmGroupOperateVo vo); + + void closeHttpClient(); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IDmPlayerentService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IDmPlayerentService.java index e899d34..c155be9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IDmPlayerentService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IDmPlayerentService.java @@ -71,7 +71,7 @@ public interface IDmPlayerentService extends IService List getByIds(List ids, SFunction... columns); DmPlayerentPlus getById(Long id, SFunction... columns); - + void closeHttpClient(); Map getMapByIds(List ids, SFunction... columns); List getByIds(List ids); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DmPlayerTaskGroupServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DmPlayerTaskGroupServiceImpl.java index d14e4b0..535d4c4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DmPlayerTaskGroupServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DmPlayerTaskGroupServiceImpl.java @@ -160,6 +160,11 @@ public class DmPlayerTaskGroupServiceImpl extends ServiceImpl getMapByIds(List ids) { List list = this.getByIds(ids);