This commit is contained in:
lu7213 committed 2026-08-13 02:26:24 -04:00
1 parent cf9c801b93
commit f0b438eb6c
8 files changed
+131 -62

No files matched your search

@@ -41,7 +41,9 @@ import java.util.zip.GZIPInputStream;
public class HttpHelper { public class HttpHelper {
private String proxyHost; private String proxyHost;
private Integer proxyPort; private Integer proxyPort;
private CloseableHttpClient httpsClient = null;
private CloseableHttpClient httpClient = null;
public String getProxyHost() { public String getProxyHost() {
return proxyHost; return proxyHost;
} }
@@ -57,7 +59,20 @@ public class HttpHelper {
public void setProxyPort(Integer proxyPort) { public void setProxyPort(Integer proxyPort) {
this.proxyPort = 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 { public static void main(String[] args) throws Exception {
BigDecimal decimal = new BigDecimal("1").divide(new BigDecimal(100)); BigDecimal decimal = new BigDecimal("1").divide(new BigDecimal(100));
@@ -444,13 +459,19 @@ public class HttpHelper {
* @return * @return
*/ */
public String getlHttpResult(String url, String method, Map<String, Object> headers, Map<String, Object> params) throws Exception { public String getlHttpResult(String url, String method, Map<String, Object> headers, Map<String, Object> params) throws Exception {
CloseableHttpClient httpClient = null; CloseableHttpClient tempClient = null;
if (url.startsWith("https")) { if (url.startsWith("https")) {
httpClient = getHttpsClient(); if(httpsClient == null){
httpsClient = getHttpsClient();
}
tempClient = httpsClient;
} else { } else {
if(httpClient == null) {
httpClient = getHttpClient(); httpClient = getHttpClient();
} }
CloseableHttpResponse response = this.send(httpClient, url, method, headers, params); tempClient = httpClient;
}
CloseableHttpResponse response = this.send(tempClient, url, method, headers, params);
if (method.toLowerCase().equals("options")) { if (method.toLowerCase().equals("options")) {
return response.getStatusLine().getStatusCode() + ""; return response.getStatusLine().getStatusCode() + "";
} else { } else {
@@ -466,24 +487,36 @@ public class HttpHelper {
} }
public String getlHttpResultCode(String url, String method, Map<String, Object> headers, Map<String, Object> params) throws Exception { public String getlHttpResultCode(String url, String method, Map<String, Object> headers, Map<String, Object> params) throws Exception {
CloseableHttpClient httpClient = null; CloseableHttpClient tempClient = null;
if (url.startsWith("https")) { if (url.startsWith("https")) {
httpClient = getHttpsClient(); if(httpsClient == null){
httpsClient = getHttpsClient();
}
tempClient = httpsClient;
} else { } else {
if(httpClient == null) {
httpClient = getHttpClient(); httpClient = getHttpClient();
} }
CloseableHttpResponse response = this.send(httpClient, url, method, headers, params); tempClient = httpClient;
}
CloseableHttpResponse response = this.send(tempClient, url, method, headers, params);
return response.getStatusLine().getStatusCode() + ""; return response.getStatusLine().getStatusCode() + "";
} }
public Boolean testHttp(String url, String method, Map<String, Object> headers, Map<String, Object> params) throws Exception { public Boolean testHttp(String url, String method, Map<String, Object> headers, Map<String, Object> params) throws Exception {
CloseableHttpClient httpClient = null; CloseableHttpClient tempClient = null;
if (url.startsWith("https")) { if (url.startsWith("https")) {
httpClient = getHttpsClient(); if(httpsClient == null){
httpsClient = getHttpsClient();
}
tempClient = httpsClient;
} else { } else {
if(httpClient == null) {
httpClient = getHttpClient(); httpClient = getHttpClient();
} }
CloseableHttpResponse response = this.send(httpClient, url, method, headers, params); tempClient = httpClient;
}
CloseableHttpResponse response = this.send(tempClient, url, method, headers, params);
boolean result = response.getStatusLine().getStatusCode() == 200; boolean result = response.getStatusLine().getStatusCode() == 200;
response.close(); response.close();
return result; return result;
@@ -494,12 +527,18 @@ public class HttpHelper {
} }
public String playLoad(String method, String url, Map<String, Object> headersMap, Object data, String contentType, String charset) throws Exception { public String playLoad(String method, String url, Map<String, Object> headersMap, Object data, String contentType, String charset) throws Exception {
CloseableHttpClient httpClient = null; CloseableHttpClient tempClient = null;
if (url.startsWith("https")) { if (url.startsWith("https")) {
httpClient = getHttpsClient(); if(httpsClient == null){
httpsClient = getHttpsClient();
}
tempClient = httpsClient;
} else { } else {
if(httpClient == null) {
httpClient = getHttpClient(); httpClient = getHttpClient();
} }
tempClient = httpClient;
}
String result = null; String result = null;
HttpEntityEnclosingRequestBase httpEntityEnclosingRequestBase = null; HttpEntityEnclosingRequestBase httpEntityEnclosingRequestBase = null;
if ("post".equalsIgnoreCase(method)) { if ("post".equalsIgnoreCase(method)) {
@@ -532,7 +571,7 @@ public class HttpHelper {
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
try { try {
// 由客户端执行(发送)Post请求 // 由客户端执行(发送)Post请求
response = (CloseableHttpResponse) httpClient.execute(httpEntityEnclosingRequestBase); response = (CloseableHttpResponse) tempClient.execute(httpEntityEnclosingRequestBase);
// 从响应模型中获取响应实体 // 从响应模型中获取响应实体
HttpEntity responseEntity = response.getEntity(); HttpEntity responseEntity = response.getEntity();
System.out.println("响应状态为:" + response.getStatusLine()); System.out.println("响应状态为:" + response.getStatusLine());
@@ -9,6 +9,7 @@ ruoyi:
- /system/file/uploadImage - /system/file/uploadImage
- /ec/device-api/report - /ec/device-api/report
- /ec/device-api/heartbeat - /ec/device-api/heartbeat
- /system/global/close-http-client
# 名称 # 名称
name: RuoYi name: RuoYi
# 版本 # 版本
@@ -1,26 +1,21 @@
package com.ruoyi.system.controller; 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.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; 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.Apps;
import com.ruoyi.system.domain.AppsPlus; import com.ruoyi.system.domain.AppsPlus;
import com.ruoyi.system.service.IAppsService; import com.ruoyi.system.service.IAppsService;
import com.ruoyi.common.utils.poi.ExcelUtil; import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.core.page.TableDataInfo; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* 应用管理Controller * 应用管理Controller
@@ -30,68 +25,67 @@ import com.ruoyi.common.core.page.TableDataInfo;
*/ */
@RestController @RestController
@RequestMapping("/system/apps") @RequestMapping("/system/apps")
public class AppsController extends BaseController public class AppsController extends BaseController {
{
@Autowired @Autowired
private IAppsService appsService; private IAppsService appsService;
@PreAuthorize("@ss.hasPermi('system:apps:getByIds')") @PreAuthorize("@ss.hasPermi('system:apps:getByIds')")
@PostMapping("/getByIds") @PostMapping("/getByIds")
public AjaxResult getByIds(@RequestBody Ids ids) public AjaxResult getByIds(@RequestBody Ids ids) {
{
List<AppsPlus> list = appsService.getByIds(ids.getLongIds(), false, AppsPlus::getName, AppsPlus::getId); List<AppsPlus> list = appsService.getByIds(ids.getLongIds(), false, AppsPlus::getName, AppsPlus::getId);
return AjaxResult.success(list); return AjaxResult.success(list);
} }
@PreAuthorize("@ss.hasPermi('system:apps:user-getByIds')") @PreAuthorize("@ss.hasPermi('system:apps:user-getByIds')")
@PostMapping("/user/getByIds") @PostMapping("/user/getByIds")
public AjaxResult userGetByIds(@RequestBody Ids ids) public AjaxResult userGetByIds(@RequestBody Ids ids) {
{
List<AppsPlus> list = appsService.getByIds(ids.getLongIds(), true, AppsPlus::getName, AppsPlus::getUserId, AppsPlus::getId); List<AppsPlus> list = appsService.getByIds(ids.getLongIds(), true, AppsPlus::getName, AppsPlus::getUserId, AppsPlus::getId);
return AjaxResult.success(list); return AjaxResult.success(list);
} }
@PreAuthorize("@ss.hasPermi('system:apps:select')") @PreAuthorize("@ss.hasPermi('system:apps:select')")
@GetMapping("/select") @GetMapping("/select")
public AjaxResult select(String keyword) public AjaxResult select(String keyword) {
{
List<SelectItem> list = appsService.select(keyword, false); List<SelectItem> list = appsService.select(keyword, false);
return AjaxResult.success(list); return AjaxResult.success(list);
} }
@PreAuthorize("@ss.hasPermi('system:apps:user-select')") @PreAuthorize("@ss.hasPermi('system:apps:user-select')")
@GetMapping("/user/select") @GetMapping("/user/select")
public AjaxResult userSelect(String keyword) public AjaxResult userSelect(String keyword) {
{
List<SelectItem> list = appsService.select(keyword, true); List<SelectItem> list = appsService.select(keyword, true);
return AjaxResult.success(list); return AjaxResult.success(list);
} }
/** /**
* 查询应用管理列表 * 查询应用管理列表
*/ */
@PreAuthorize("@ss.hasPermi('system:apps:list')") @PreAuthorize("@ss.hasPermi('system:apps:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(Apps apps) public TableDataInfo list(Apps apps) {
{
startPage(); startPage();
List<Apps> list = appsService.selectAppsList(apps, false); List<Apps> list = appsService.selectAppsList(apps, false);
return getDataTable(list); return getDataTable(list);
} }
/** /**
* 查询应用管理列表 * 查询应用管理列表
*/ */
@PreAuthorize("@ss.hasPermi('system:apps:user-list')") @PreAuthorize("@ss.hasPermi('system:apps:user-list')")
@GetMapping("/user/list") @GetMapping("/user/list")
public TableDataInfo userList(Apps apps) public TableDataInfo userList(Apps apps) {
{
startPage(); startPage();
List<Apps> list = appsService.selectAppsList(apps, true); List<Apps> list = appsService.selectAppsList(apps, true);
return getDataTable(list); return getDataTable(list);
} }
/** /**
* 导出应用管理列表 * 导出应用管理列表
*/ */
@PreAuthorize("@ss.hasPermi('system:apps:export')") @PreAuthorize("@ss.hasPermi('system:apps:export')")
@Log(title = "应用管理", businessType = BusinessType.EXPORT) @Log(title = "应用管理", businessType = BusinessType.EXPORT)
@GetMapping("/export") @GetMapping("/export")
public AjaxResult export(Apps apps) public AjaxResult export(Apps apps) {
{
List<Apps> list = appsService.selectAppsList(apps, false); List<Apps> list = appsService.selectAppsList(apps, false);
ExcelUtil<Apps> util = new ExcelUtil<Apps>(Apps.class); ExcelUtil<Apps> util = new ExcelUtil<Apps>(Apps.class);
return util.exportExcel(list, "apps"); return util.exportExcel(list, "apps");
@@ -102,74 +96,73 @@ public class AppsController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('system:apps:query')") @PreAuthorize("@ss.hasPermi('system:apps:query')")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) public AjaxResult getInfo(@PathVariable("id") Long id) {
{
return AjaxResult.success(appsService.selectAppsById(id, false)); return AjaxResult.success(appsService.selectAppsById(id, false));
} }
/** /**
* 获取应用管理详细信息 * 获取应用管理详细信息
*/ */
@PreAuthorize("@ss.hasPermi('system:apps:user-query')") @PreAuthorize("@ss.hasPermi('system:apps:user-query')")
@GetMapping(value = "/user/{id}") @GetMapping(value = "/user/{id}")
public AjaxResult userGetInfo(@PathVariable("id") Long id) public AjaxResult userGetInfo(@PathVariable("id") Long id) {
{
return AjaxResult.success(appsService.selectAppsById(id, true)); return AjaxResult.success(appsService.selectAppsById(id, true));
} }
/** /**
* 新增应用管理 * 新增应用管理
*/ */
@PreAuthorize("@ss.hasPermi('system:apps:add')") @PreAuthorize("@ss.hasPermi('system:apps:add')")
@Log(title = "应用管理", businessType = BusinessType.INSERT) @Log(title = "应用管理", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@RequestBody Apps apps) public AjaxResult add(@RequestBody Apps apps) {
{
return toAjax(appsService.insertApps(apps, false)); return toAjax(appsService.insertApps(apps, false));
} }
/** /**
* 新增应用管理 * 新增应用管理
*/ */
@PreAuthorize("@ss.hasPermi('system:apps:user-add')") @PreAuthorize("@ss.hasPermi('system:apps:user-add')")
@Log(title = "应用管理", businessType = BusinessType.INSERT) @Log(title = "应用管理", businessType = BusinessType.INSERT)
@PostMapping("/user") @PostMapping("/user")
public AjaxResult userAdd(@RequestBody Apps apps) public AjaxResult userAdd(@RequestBody Apps apps) {
{
return toAjax(appsService.insertApps(apps, true)); return toAjax(appsService.insertApps(apps, true));
} }
/** /**
* 修改应用管理 * 修改应用管理
*/ */
@PreAuthorize("@ss.hasPermi('system:apps:edit')") @PreAuthorize("@ss.hasPermi('system:apps:edit')")
@Log(title = "应用管理", businessType = BusinessType.UPDATE) @Log(title = "应用管理", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody Apps apps) public AjaxResult edit(@RequestBody Apps apps) {
{
return toAjax(appsService.updateApps(apps, false)); return toAjax(appsService.updateApps(apps, false));
} }
@PreAuthorize("@ss.hasPermi('system:apps:user-edit')") @PreAuthorize("@ss.hasPermi('system:apps:user-edit')")
@Log(title = "应用管理", businessType = BusinessType.UPDATE) @Log(title = "应用管理", businessType = BusinessType.UPDATE)
@PutMapping("/user") @PutMapping("/user")
public AjaxResult userEdit(@RequestBody Apps apps) public AjaxResult userEdit(@RequestBody Apps apps) {
{
return toAjax(appsService.updateApps(apps, true)); return toAjax(appsService.updateApps(apps, true));
} }
/** /**
* 删除应用管理 * 删除应用管理
*/ */
@PreAuthorize("@ss.hasPermi('system:apps:remove')") @PreAuthorize("@ss.hasPermi('system:apps:remove')")
@Log(title = "应用管理", businessType = BusinessType.DELETE) @Log(title = "应用管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) public AjaxResult remove(@PathVariable Long[] ids) {
{
return toAjax(appsService.deleteAppsByIds(ids, false)); return toAjax(appsService.deleteAppsByIds(ids, false));
} }
/** /**
* 删除应用管理 * 删除应用管理
*/ */
@PreAuthorize("@ss.hasPermi('system:apps:user-remove')") @PreAuthorize("@ss.hasPermi('system:apps:user-remove')")
@Log(title = "应用管理", businessType = BusinessType.DELETE) @Log(title = "应用管理", businessType = BusinessType.DELETE)
@DeleteMapping("/user/{ids}") @DeleteMapping("/user/{ids}")
public AjaxResult userRemove(@PathVariable Long[] ids) public AjaxResult userRemove(@PathVariable Long[] ids) {
{
return toAjax(appsService.deleteAppsByIds(ids, true)); return toAjax(appsService.deleteAppsByIds(ids, true));
} }
} }
@@ -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);
}
}
@@ -90,4 +90,6 @@ public interface IDmPlayerTaskGroupService extends IService<DmPlayerTaskGroupPlu
<T> List<T> countByGroupBy(String select, String where, String groupby, Class<T> tClass); <T> List<T> countByGroupBy(String select, String where, String groupby, Class<T> tClass);
boolean operate(DmGroupOperateVo vo); boolean operate(DmGroupOperateVo vo);
void closeHttpClient();
} }
@@ -71,7 +71,7 @@ public interface IDmPlayerentService extends IService<DmPlayerentPlus>
List<DmPlayerentPlus> getByIds(List<Long> ids, SFunction<DmPlayerentPlus, ?>... columns); List<DmPlayerentPlus> getByIds(List<Long> ids, SFunction<DmPlayerentPlus, ?>... columns);
DmPlayerentPlus getById(Long id, SFunction<DmPlayerentPlus, ?>... columns); DmPlayerentPlus getById(Long id, SFunction<DmPlayerentPlus, ?>... columns);
void closeHttpClient();
Map<Long, DmPlayerentPlus> getMapByIds(List<Long> ids, SFunction<DmPlayerentPlus, ?>... columns); Map<Long, DmPlayerentPlus> getMapByIds(List<Long> ids, SFunction<DmPlayerentPlus, ?>... columns);
List<DmPlayerentPlus> getByIds(List<Long> ids); List<DmPlayerentPlus> getByIds(List<Long> ids);
@@ -160,6 +160,11 @@ public class DmPlayerTaskGroupServiceImpl extends ServiceImpl<DmPlayerTaskGroupM
return false; return false;
} }
@Override
public void closeHttpClient() {
this.httpHelper.closeClient();
}
/** /**
* 查询大漠任务组 * 查询大漠任务组
* *
@@ -87,7 +87,10 @@ public class DmPlayerentServiceImpl extends ServiceImpl<DmPlayerentMapper, DmPla
} }
return map; return map;
} }
@Override
public void closeHttpClient() {
this.httpHelper.closeClient();
}
@Override @Override
public Map<Long, DmPlayerentPlus> getMapByIds(List<Long> ids) { public Map<Long, DmPlayerentPlus> getMapByIds(List<Long> ids) {
List<DmPlayerentPlus> list = this.getByIds(ids); List<DmPlayerentPlus> list = this.getByIds(ids);