parent
4124aa2ed3
commit
d988480ba4
4 changed files with 358 additions and 0 deletions
@ -0,0 +1,140 @@ |
||||
package org.springblade.desk.device.pojo.entity; |
||||
|
||||
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.util.Date; |
||||
|
||||
/** |
||||
* 计量记录 实体类 |
||||
* |
||||
* @author qyl |
||||
* @since 2026年1月4日 |
||||
*/ |
||||
@Data |
||||
@Schema(description = "计量记录对象") |
||||
@EqualsAndHashCode(callSuper = true) |
||||
public class MeasurementRecordsEntity extends BaseEntity { |
||||
@Schema(name = "名称(设备名称)") |
||||
//@Column(name = "mc_name")
|
||||
private String mcName; |
||||
|
||||
@Schema(name = "规格") |
||||
//@Column(name = "norms")
|
||||
private String norms; |
||||
|
||||
@Schema(name = "类别(管理类别)") |
||||
//@Column(name = "mc_class")
|
||||
private String mcClass; |
||||
|
||||
@Schema(name = "计量类型") |
||||
//@Column(name = "label_no")
|
||||
private String labelNo; |
||||
|
||||
@Schema(name = "计量子类型") |
||||
//@Column(name = "str2")
|
||||
private String str2; |
||||
|
||||
@Schema(name = "编号(测量设备编码)") |
||||
//@Column(name = "mc_code")
|
||||
private String mcCode; |
||||
|
||||
@Schema(name = "使用单位(试用部门)") |
||||
//@Column(name = "use_unit")
|
||||
private String useUnit; |
||||
|
||||
@Schema(name = "精度(精度等级)") |
||||
//@Column(name = "accuracy")
|
||||
private String accuracy; |
||||
|
||||
@Schema(name = "出厂编号") |
||||
//@Column(name = "oem_code")
|
||||
private String oemCode; |
||||
|
||||
@Schema(name = "生产厂家(制造厂商)") |
||||
//@Column(name = "mc_oem")
|
||||
private String mcOem; |
||||
|
||||
@Schema(name = "启用日期") |
||||
//@Column(name = "enable_date")
|
||||
private Date enableDate; |
||||
|
||||
@Schema(name = "检定日期") |
||||
//@Column(name = "when_dccept")
|
||||
private String whenDccept; |
||||
|
||||
@Schema(name = "型号(型号)") |
||||
//@Column(name = "mc_type")
|
||||
private String mcType; |
||||
|
||||
@Schema(name = "检定周期(检定周期)") |
||||
//@Column(name = "test_cycle")
|
||||
private Integer testCycle; |
||||
|
||||
@Schema(name = "到期日期(有效日期)") |
||||
//@Column(name = "due_date")
|
||||
private Date dueDate; |
||||
|
||||
@Schema(name = "报废日期") |
||||
//@Column(name = "date2")
|
||||
private Date date2; |
||||
|
||||
@Schema(name = "状态") |
||||
//@Column(name = "belong")
|
||||
private String belong; |
||||
|
||||
@Schema(name = "停用日期") |
||||
//@Column(name = "when_buy")
|
||||
private Date whenBuy; |
||||
|
||||
@Schema(name = "检定部门") |
||||
//@Column(name = "test_dept")
|
||||
private String testDept; |
||||
|
||||
@Schema(name = "检定/校验方法(检定校准方法)") |
||||
//@Column(name = "test_method")
|
||||
private String testMethod; |
||||
|
||||
@Schema(name = "备注") |
||||
//@Column(name = "str9")
|
||||
private String str9; |
||||
|
||||
@Schema(name = "备注2") |
||||
//@Column(name = "str10")
|
||||
private String str10; |
||||
|
||||
@Schema(name = "使用人工号") |
||||
//@Column(name = "assets_no")
|
||||
private String assetsNo; |
||||
|
||||
@Schema(name = "责任人") |
||||
//@Column(name = "str6")
|
||||
private String str6; |
||||
|
||||
@Schema(name = "用途分类") |
||||
//@Column(name = "purpose_class")
|
||||
private String purposeClass; |
||||
|
||||
@Schema(name = "超期情况") |
||||
//@Column(name = "is_over_str")
|
||||
private String isOverStr; |
||||
|
||||
@Schema(name = "类型", title = "1、仪表计量;2、设备计量") |
||||
//@Column(name = "cm_type")
|
||||
private Short cmType; |
||||
|
||||
@Schema(name = "是否送检", title = "1:是,0:否") |
||||
//@Column(name = "censorship")
|
||||
private Boolean censorship; |
||||
|
||||
@Schema(name = "检验状态", title = "1:在检,0:未检") |
||||
//@Column(name = "check_status")
|
||||
private Boolean checkStatus; |
||||
|
||||
@Schema(name = "检验结果", title = "1:合格,0:不合格") |
||||
//@Column(name = "check_result")
|
||||
private Boolean checkResult; |
||||
} |
||||
@ -0,0 +1,71 @@ |
||||
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.entity.MeasurementRecordsEntity; |
||||
import org.springblade.desk.device.pojo.request.MeasuringUsageQuery; |
||||
import org.springblade.desk.device.service.IMeasurementRecordsService; |
||||
import org.springblade.desk.device.service.IMeasuringUsageService; |
||||
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.RequestParam; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
|
||||
/** |
||||
* 计量记录 控制器 |
||||
* |
||||
* @author qyl |
||||
* @since 2026年1月4日 |
||||
*/ |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/measurementRecords") |
||||
@Tag(name = "计量记录", description = "计量记录接口") |
||||
public class MeasurementRecordsController extends BladeController { |
||||
@Autowired |
||||
IMeasurementRecordsService iMeasurementRecordsService; |
||||
|
||||
/** |
||||
* 计量记录 自定义分页 |
||||
* |
||||
* @param cmType 1、仪表计量;2、设备计量 |
||||
* @param query |
||||
* @return |
||||
*/ |
||||
@GetMapping("/page") |
||||
@ApiOperationSupport(order = 3) |
||||
@Operation(summary = "分页", description = "") |
||||
public R<IPage<JSONObject>> page(@RequestParam("cmType") Integer cmType, Query query) { |
||||
IPage<JSONObject> pages = iMeasurementRecordsService.selectMeasurementRecordsPage(Condition.getPage(query), cmType); |
||||
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.entity.MeasurementRecordsEntity; |
||||
import org.springblade.desk.device.pojo.request.MeasuringUsageQuery; |
||||
|
||||
/** |
||||
* 计量记录 服务类 |
||||
* |
||||
* @author qyl |
||||
* @since 2026年1月4日 |
||||
*/ |
||||
|
||||
public interface IMeasurementRecordsService { |
||||
/** |
||||
* 自定义分页 |
||||
* |
||||
* @param page 分页参数 |
||||
* @param cmType 查询参数 |
||||
* @return IPage<JSONObject> |
||||
*/ |
||||
IPage<JSONObject> selectMeasurementRecordsPage(IPage<JSONObject> page, Integer cmType); |
||||
|
||||
|
||||
// /**
|
||||
// * 导出数据
|
||||
// *
|
||||
// * @param queryWrapper 查询条件
|
||||
// * @return List<EquipmentExcel>
|
||||
// */
|
||||
// List<EquipmentExcel> exportEquipment(Wrapper<EquipmentEntity> queryWrapper);
|
||||
} |
||||
@ -0,0 +1,114 @@ |
||||
package org.springblade.desk.device.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import jodd.util.StringUtil; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.desk.device.pojo.entity.MeasurementRecordsEntity; |
||||
import org.springblade.desk.device.pojo.request.MeasuringUsageQuery; |
||||
import org.springblade.desk.device.service.IMeasurementRecordsService; |
||||
import org.springblade.desk.device.service.IMeasuringUsageService; |
||||
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 IMeasurementRecordsServiceImpl implements IMeasurementRecordsService { |
||||
// 使用JDK 17内置的HttpClient(线程安全,可复用)
|
||||
private final HttpClient httpClient = HttpClient.newBuilder() |
||||
.connectTimeout(Duration.ofSeconds(30)) |
||||
.version(HttpClient.Version.HTTP_2) |
||||
.build(); |
||||
|
||||
@Value("${request.lims.url}") |
||||
private String limsUrl; |
||||
|
||||
@Override |
||||
public IPage<JSONObject> selectMeasurementRecordsPage(IPage<JSONObject> page, Integer cmType) { |
||||
|
||||
// 构建请求体JSON
|
||||
JSONObject requestBody = buildRequestBody(page, cmType); |
||||
|
||||
// 创建HTTP请求
|
||||
HttpRequest request = HttpRequest.newBuilder() |
||||
.uri(URI.create(limsUrl + "/api/cloud-customized/zhgdDeviceParams/getDeviceListZhgd")) |
||||
.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, Integer cmType) { |
||||
JSONObject requestBody = new JSONObject(); |
||||
requestBody.put("currPage", page.getCurrent()); |
||||
requestBody.put("pageSize", page.getSize()); |
||||
requestBody.put("workGuideNo", "热表分厂"); |
||||
requestBody.put("labId", "2"); |
||||
requestBody.put("str1", cmType == null ? 1 : 2); |
||||
|
||||
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