parent
d18b98f069
commit
4124aa2ed3
5 changed files with 262 additions and 1 deletions
@ -0,0 +1,37 @@ |
|||||||
|
package org.springblade.desk.device.pojo.request; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.core.mp.base.BaseEntity; |
||||||
|
|
||||||
|
import java.io.Serial; |
||||||
|
import java.math.BigDecimal; |
||||||
|
|
||||||
|
/** |
||||||
|
* 量具使用记录查询条件封装类 |
||||||
|
* |
||||||
|
* @author qyl |
||||||
|
* @since 2026-01-04 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class MeasuringUsageQuery { |
||||||
|
|
||||||
|
/** |
||||||
|
* 设备编码 |
||||||
|
*/ |
||||||
|
@Schema(description = "处理状态") |
||||||
|
private String toolStatus; |
||||||
|
/** |
||||||
|
* 设备名称 |
||||||
|
*/ |
||||||
|
@Schema(description = "工具规格") |
||||||
|
private String toolSpec; |
||||||
|
/** |
||||||
|
* 类别名称 |
||||||
|
*/ |
||||||
|
@Schema(description = "类别名称") |
||||||
|
private String typeName; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,62 @@ |
|||||||
|
package org.springblade.desk.device.controller; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.boot.ctrl.BladeController; |
||||||
|
import org.springblade.core.mp.support.Condition; |
||||||
|
import org.springblade.core.mp.support.Query; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.desk.device.pojo.request.MeasuringUsageQuery; |
||||||
|
import org.springblade.desk.device.service.IMeasuringUsageService; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 量具使用记录 控制器 |
||||||
|
* |
||||||
|
* @author qyl |
||||||
|
* @since 2026年1月4日 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@AllArgsConstructor |
||||||
|
@RequestMapping("/measuringUsage") |
||||||
|
@Tag(name = "量具使用记录", description = "量具使用记录接口") |
||||||
|
public class MeasuringUsageController extends BladeController { |
||||||
|
@Autowired |
||||||
|
IMeasuringUsageService iMeasuringUsageService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 量具使用记录 自定义分页 |
||||||
|
*/ |
||||||
|
@GetMapping("/page") |
||||||
|
@ApiOperationSupport(order = 3) |
||||||
|
@Operation(summary = "分页", description = "") |
||||||
|
public R<IPage<JSONObject>> page(MeasuringUsageQuery measuringUsageQuery, Query query) { |
||||||
|
IPage<JSONObject> pages = iMeasuringUsageService.selectMeasuringUsagePage(Condition.getPage(query), measuringUsageQuery); |
||||||
|
return R.data(pages); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 导出数据 |
||||||
|
*/ |
||||||
|
// @IsAdmin
|
||||||
|
// @GetMapping("/export-equipment")
|
||||||
|
// @ApiOperationSupport(order = 9)
|
||||||
|
// @Operation(summary = "导出数据", description = "传入equipment")
|
||||||
|
// public void exportEquipment(@Parameter(hidden = true) @RequestParam Map<String, Object> equipment, BladeUser bladeUser, HttpServletResponse response) {
|
||||||
|
// QueryWrapper<EquipmentEntity> queryWrapper = Condition.getQueryWrapper(equipment, EquipmentEntity.class);
|
||||||
|
// //if (!AuthUtil.isAdministrator()) {
|
||||||
|
// // queryWrapper.lambda().eq(Equipment::getTenantId, bladeUser.getTenantId());
|
||||||
|
// //}
|
||||||
|
// //queryWrapper.lambda().eq(EquipmentEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
|
||||||
|
// List<EquipmentExcel> list = measuringUsageService.exportEquipment(queryWrapper);
|
||||||
|
// ExcelUtil.export(response, "设备信息表数据" + DateUtil.time(), "设备信息表数据表", list, EquipmentExcel.class);
|
||||||
|
// }
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
package org.springblade.desk.device.service; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import org.springblade.desk.device.pojo.request.MeasuringUsageQuery; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* 量具使用记录 服务类 |
||||||
|
* |
||||||
|
* @author qyl |
||||||
|
* @since 2026年1月4日 |
||||||
|
*/ |
||||||
|
|
||||||
|
public interface IMeasuringUsageService { |
||||||
|
/** |
||||||
|
* 自定义分页 |
||||||
|
* |
||||||
|
* @param page 分页参数 |
||||||
|
* @param measuringUsageQuery 查询参数 |
||||||
|
* @return IPage<JSONObject> |
||||||
|
*/ |
||||||
|
IPage<JSONObject> selectMeasuringUsagePage(IPage<JSONObject> page, MeasuringUsageQuery measuringUsageQuery); |
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 导出数据
|
||||||
|
// *
|
||||||
|
// * @param queryWrapper 查询条件
|
||||||
|
// * @return List<EquipmentExcel>
|
||||||
|
// */
|
||||||
|
// List<EquipmentExcel> exportEquipment(Wrapper<EquipmentEntity> queryWrapper);
|
||||||
|
} |
||||||
@ -0,0 +1,121 @@ |
|||||||
|
package org.springblade.desk.device.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import jodd.util.StringUtil; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.desk.device.pojo.request.MeasuringUsageQuery; |
||||||
|
import org.springblade.desk.device.service.IMeasuringUsageService; |
||||||
|
import com.alibaba.fastjson.JSONArray; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.net.URI; |
||||||
|
import java.net.http.HttpClient; |
||||||
|
import java.net.http.HttpRequest; |
||||||
|
import java.net.http.HttpResponse; |
||||||
|
import java.time.Duration; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@Slf4j |
||||||
|
@Service |
||||||
|
public class IMeasuringUsageServiceImpl implements IMeasuringUsageService { |
||||||
|
// 使用JDK 17内置的HttpClient(线程安全,可复用)
|
||||||
|
private final HttpClient httpClient = HttpClient.newBuilder() |
||||||
|
.connectTimeout(Duration.ofSeconds(30)) |
||||||
|
.version(HttpClient.Version.HTTP_2) |
||||||
|
.build(); |
||||||
|
|
||||||
|
@Value("${request.measuringTool.url}") |
||||||
|
private String measuringTool; |
||||||
|
|
||||||
|
@Override |
||||||
|
public IPage<JSONObject> selectMeasuringUsagePage(IPage<JSONObject> page, MeasuringUsageQuery measuringUsageQuery) { |
||||||
|
|
||||||
|
// 构建请求体JSON
|
||||||
|
JSONObject requestBody = buildRequestBody(page, measuringUsageQuery); |
||||||
|
|
||||||
|
// 创建HTTP请求
|
||||||
|
HttpRequest request = HttpRequest.newBuilder() |
||||||
|
.uri(URI.create(measuringTool + "/server/external/getTool")) |
||||||
|
.header("Content-Type", "application/json") |
||||||
|
.header("Accept", "application/json") |
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(requestBody.toJSONString())) |
||||||
|
.timeout(Duration.ofSeconds(60)) |
||||||
|
.build(); |
||||||
|
|
||||||
|
try { |
||||||
|
// 发送同步请求
|
||||||
|
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); |
||||||
|
|
||||||
|
// 处理响应
|
||||||
|
return processResponse(response, page); |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
log.error("获取量具库存记录数据接口调用失败: {}", e.getMessage(), e); |
||||||
|
return page.setRecords(List.of()); // 返回空列表而不是null
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 构建请求体 |
||||||
|
*/ |
||||||
|
private JSONObject buildRequestBody(IPage<JSONObject> page, MeasuringUsageQuery measuringUsageQuery) { |
||||||
|
JSONObject requestBody = new JSONObject(); |
||||||
|
requestBody.put("currPage", page.getCurrent()); |
||||||
|
requestBody.put("pageSize", page.getSize()); |
||||||
|
|
||||||
|
if (measuringUsageQuery != null) { |
||||||
|
if (StringUtil.isNotEmpty(measuringUsageQuery.getToolStatus())) { |
||||||
|
requestBody.put("toolStatus", measuringUsageQuery.getToolStatus()); |
||||||
|
} |
||||||
|
if (StringUtil.isNotEmpty(measuringUsageQuery.getToolSpec())) { |
||||||
|
requestBody.put("toolSpec", measuringUsageQuery.getToolSpec()); |
||||||
|
} |
||||||
|
if (StringUtil.isNotEmpty(measuringUsageQuery.getTypeName())) { |
||||||
|
requestBody.put("typeName", measuringUsageQuery.getTypeName()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
log.debug("请求参数: {}", requestBody.toJSONString()); |
||||||
|
return requestBody; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 处理HTTP响应 |
||||||
|
*/ |
||||||
|
private IPage<JSONObject> processResponse(HttpResponse<String> response, IPage<JSONObject> page) { |
||||||
|
if (response.statusCode() != 200) { |
||||||
|
log.error("HTTP请求失败,状态码: {}", response.statusCode()); |
||||||
|
throw new RuntimeException("HTTP请求失败,状态码: " + response.statusCode()); |
||||||
|
} |
||||||
|
|
||||||
|
String responseBody = response.body(); |
||||||
|
if (responseBody == null || responseBody.trim().isEmpty()) { |
||||||
|
log.error("响应体为空"); |
||||||
|
return page.setRecords(List.of()); |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
JSONObject result = JSONObject.parseObject(responseBody); |
||||||
|
if (result != null && result.getInteger("code") != null && result.getInteger("code").equals(200)) { |
||||||
|
JSONObject data = result.getJSONObject("data"); |
||||||
|
if (data != null) { |
||||||
|
List<JSONObject> records = JSONArray.parseArray(data.toJSONString(), JSONObject.class); |
||||||
|
log.info("成功获取{}条量具库存记录", records != null ? records.size() : 0); |
||||||
|
return page.setRecords(records != null ? records : List.of()); |
||||||
|
} |
||||||
|
} else { |
||||||
|
String errorMsg = result != null ? result.getString("message") : "未知错误"; |
||||||
|
log.error("接口返回错误: {}", errorMsg); |
||||||
|
throw new RuntimeException("接口返回错误: " + errorMsg); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("响应数据解析失败: {}", e.getMessage(), e); |
||||||
|
throw new RuntimeException("响应数据解析失败: " + e.getMessage(), e); |
||||||
|
} |
||||||
|
|
||||||
|
return page.setRecords(List.of()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue