Please enter the commit message for your changes. Lines starting
with '#' will be ignored, and an empty message aborts the commit. On branch develop Your branch is ahead of 'goflyapp/develop' by 2 commits. (use "git push" to publish your local commits) Changes to be committed: modified: README.md modified: pom.xml modified: zlt-business/device-center/pom.xml modified: zlt-business/device-center/src/main/java/com/central/device/controller/AgeDeviceController.java modified: zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java modified: zlt-business/device-center/src/main/java/com/central/device/controller/LineFileController.java modified: zlt-business/device-center/src/main/java/com/central/device/feign/OrderCenterService.java modified: zlt-business/device-center/src/main/java/com/central/device/feign/fallback/OrderCenterServiceFallbackFactory.java modified: zlt-business/device-center/src/main/java/com/central/device/listener/DeviceImportListener.java modified: zlt-business/device-center/src/main/java/com/central/device/model/AgeDevice.java modified: zlt-business/device-center/src/main/java/com/central/device/model/LineFile.java modified: zlt-business/device-center/src/main/java/com/central/device/model/excel/AgeDeviceExcel.java modified: zlt-business/device-center/src/main/java/com/central/device/service/IAgeDeviceService.java modified: zlt-business/device-center/src/main/java/com/central/device/service/ILineFileService.java modified: zlt-business/device-center/src/main/java/com/central/device/service/impl/AgeDeviceServiceImpl.java modified: zlt-business/device-center/src/main/java/com/central/device/service/impl/LineFileServiceImpl.java modified: zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java modified: zlt-business/file-center/src/main/java/com/central/file/service/impl/OssService.java modified: zlt-business/file-center/src/main/resources/application.yml modified: zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java modified: zlt-business/order-center/src/main/java/com/central/order/controller/QrCodeController.java modified: zlt-business/order-center/src/main/java/com/central/order/feign/DeviceCenterService.java modified: zlt-business/order-center/src/main/java/com/central/order/feign/fallback/DeviceCenterServiceFallbackFactory.java modified: zlt-business/order-center/src/main/java/com/central/order/model/Order.java modified: zlt-commons/zlt-common-core/src/main/java/com/central/common/model/FileInfo.java modified: zlt-web/react-web/src/main/frontend/config/config.ts modified: zlt-web/react-web/src/main/frontend/config/routes.ts modified: zlt-web/react-web/src/main/frontend/nginx.conf modified: zlt-web/react-web/src/main/frontend/package.json new file: zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/UpdateForm.tsx new file: zlt-web/react-web/src/main/frontend/src/pages/device/Device/index.tsx modified: zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/components/UpdateForm.tsx modified: zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/index.tsx deleted: zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/components/UpdateForm.tsx deleted: zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/index.less deleted: zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/index.tsx modified: zlt-web/react-web/src/main/frontend/src/pages/orders/OrderFile/index.tsx modified: zlt-web/react-web/src/main/frontend/src/services/device/api.ts modified: zlt-web/react-web/src/main/frontend/src/services/device/typings.d.ts
This commit is contained in:
@@ -89,6 +89,11 @@
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<!-- 验证依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+205
-12
@@ -1,20 +1,32 @@
|
||||
package com.central.device.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.device.model.AgeDevice;
|
||||
import com.central.device.model.excel.AgeDeviceExcel;
|
||||
import com.central.device.service.IAgeDeviceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.central.device.model.AgeDevice;
|
||||
import com.central.device.service.IAgeDeviceService;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Device information
|
||||
@@ -24,8 +36,8 @@ import com.central.common.model.Result;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/age")
|
||||
@Tag(name = "Device information")
|
||||
@RequestMapping("/device")
|
||||
@Tag(name = "设备管理")
|
||||
@RequiredArgsConstructor
|
||||
public class AgeDeviceController {
|
||||
private final IAgeDeviceService ageDeviceService;
|
||||
@@ -73,4 +85,185 @@ public class AgeDeviceController {
|
||||
ageDeviceService.removeById(id);
|
||||
return Result.succeed("删除成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备信息
|
||||
*/
|
||||
@Operation(summary = "导出设备信息")
|
||||
@PostMapping("/export")
|
||||
public void exportDevices(@RequestBody Map<String, Object> params, HttpServletResponse response) {
|
||||
try {
|
||||
// 设置响应头
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
String fileName = URLEncoder.encode("设备信息", StandardCharsets.UTF_8.name()).replaceAll("\\+", "%20");
|
||||
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
||||
|
||||
// 查询导出数据
|
||||
List<AgeDevice> deviceList = ageDeviceService.findListByParams(params);
|
||||
if (CollUtil.isEmpty(deviceList)) {
|
||||
deviceList = new ArrayList<>();
|
||||
}
|
||||
|
||||
// 转换并写入Excel
|
||||
List<AgeDeviceExcel> excelList = deviceList.stream()
|
||||
.map(AgeDeviceExcel::fromDevice)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
EasyExcel.write(response.getOutputStream(), AgeDeviceExcel.class)
|
||||
.excelType(ExcelTypeEnum.XLSX)
|
||||
.sheet("设备信息")
|
||||
.doWrite(excelList);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("导出设备信息失败", e);
|
||||
// 重置response
|
||||
response.reset();
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
try {
|
||||
response.getWriter().println("{\"code\":500,\"msg\":\"导出失败\"}");
|
||||
} catch (IOException ex) {
|
||||
log.error("写入响应失败", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入设备信息
|
||||
*/
|
||||
@Operation(summary = "导入设备信息")
|
||||
@PostMapping("/import")
|
||||
public Result<String> importDevices(@RequestParam("file") MultipartFile file) {
|
||||
try {
|
||||
if (file.isEmpty()) {
|
||||
return Result.failed("请选择要导入的文件");
|
||||
}
|
||||
|
||||
// 文件大小校验(10MB)
|
||||
if (file.getSize() > 10 * 1024 * 1024) {
|
||||
return Result.failed("文件大小不能超过10MB");
|
||||
}
|
||||
|
||||
// 文件类型校验
|
||||
String fileName = file.getOriginalFilename();
|
||||
if (fileName == null || (!fileName.endsWith(".xlsx") && !fileName.endsWith(".xls"))) {
|
||||
return Result.failed("请上传Excel文件");
|
||||
}
|
||||
|
||||
// 读取Excel数据
|
||||
List<AgeDeviceExcel> excelList = EasyExcel.read(file.getInputStream())
|
||||
.head(AgeDeviceExcel.class)
|
||||
.sheet()
|
||||
.doReadSync();
|
||||
|
||||
if (CollUtil.isEmpty(excelList)) {
|
||||
return Result.failed("导入数据为空");
|
||||
}
|
||||
|
||||
// 数据校验和转换
|
||||
List<String> errorMsgs = new ArrayList<>();
|
||||
List<AgeDevice> deviceList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < excelList.size(); i++) {
|
||||
AgeDeviceExcel excelData = excelList.get(i);
|
||||
try {
|
||||
// 数据校验
|
||||
validateExcelData(excelData, i + 1, errorMsgs);
|
||||
if (errorMsgs.isEmpty()) {
|
||||
deviceList.add(excelData.toDevice());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("第{}行数据处理失败", i + 1, e);
|
||||
errorMsgs.add(String.format("第%d行数据处理失败:%s", i + 1, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
if (!errorMsgs.isEmpty()) {
|
||||
return Result.failed("导入失败:" + String.join("; ", errorMsgs));
|
||||
}
|
||||
|
||||
// 批量保存数据
|
||||
boolean success = ageDeviceService.importDevices(deviceList);
|
||||
return success ? Result.succeed("导入成功") : Result.failed("导入失败");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("导入设备信息失败", e);
|
||||
return Result.failed("导入失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "下载导入模板")
|
||||
@GetMapping("/template")
|
||||
public void downloadTemplate(HttpServletResponse response) {
|
||||
try {
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
String fileName = URLEncoder.encode("设备导入模板", StandardCharsets.UTF_8.name()).replaceAll("\\+", "%20");
|
||||
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
||||
|
||||
// 创建模板数据
|
||||
List<AgeDeviceExcel> templateList = new ArrayList<>();
|
||||
// 可以添加一行示例数据
|
||||
AgeDeviceExcel template = new AgeDeviceExcel();
|
||||
template.setDeviceSn("示例:DEVICE001");
|
||||
template.setDeviceName("示例:测试设备1");
|
||||
templateList.add(template);
|
||||
|
||||
EasyExcel.write(response.getOutputStream(), AgeDeviceExcel.class)
|
||||
.excelType(ExcelTypeEnum.XLSX)
|
||||
.sheet("设备信息")
|
||||
.doWrite(templateList);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("下载模板失败", e);
|
||||
response.reset();
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
try {
|
||||
response.getWriter().println("{\"code\":500,\"msg\":\"下载模板失败\"}");
|
||||
} catch (IOException ex) {
|
||||
log.error("写入响应失败", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证Excel数据
|
||||
*/
|
||||
private void validateExcelData(AgeDeviceExcel excelData, int rowIndex, List<String> errorMsgs) {
|
||||
if (excelData == null) {
|
||||
errorMsgs.add(String.format("第%d行数据为空", rowIndex));
|
||||
return;
|
||||
}
|
||||
|
||||
// 必填字段校验
|
||||
if (org.springframework.util.StringUtils.isEmpty(excelData.getDeviceSn())) {
|
||||
errorMsgs.add(String.format("第%d行:设备序列号不能为空", rowIndex));
|
||||
}
|
||||
if (org.springframework.util.StringUtils.isEmpty(excelData.getDeviceName())) {
|
||||
errorMsgs.add(String.format("第%d行:设备名称不能为空", rowIndex));
|
||||
}
|
||||
|
||||
// 字段格式校验
|
||||
if (excelData.getDeviceType() != null && (excelData.getDeviceType() < 0 || excelData.getDeviceType() > 100)) {
|
||||
errorMsgs.add(String.format("第%d行:设备类型取值范围为0-100", rowIndex));
|
||||
}
|
||||
|
||||
// 重复性校验
|
||||
if (!org.springframework.util.StringUtils.isEmpty(excelData.getDeviceSn())) {
|
||||
boolean exists = ageDeviceService.checkDeviceSnExists(excelData.getDeviceSn());
|
||||
if (exists) {
|
||||
errorMsgs.add(String.format("第%d行:设备序列号已存在", rowIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<AgeDeviceExcel> convertToExcelList(List<AgeDevice> deviceList) {
|
||||
return deviceList.stream().map(device -> {
|
||||
AgeDeviceExcel excel = new AgeDeviceExcel();
|
||||
BeanUtils.copyProperties(device, excel);
|
||||
return excel;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
+84
-38
@@ -7,10 +7,13 @@ import com.central.common.model.Result;
|
||||
import com.central.device.feign.OrderCenterService;
|
||||
import com.central.device.message.ControlEnum;
|
||||
import com.central.device.message.ControlMessageConstant;
|
||||
import com.central.device.model.LineFile;
|
||||
import com.central.device.service.ILineFileService;
|
||||
import com.central.device.util.IotRequestResult;
|
||||
import com.central.device.util.MapUtil;
|
||||
import com.central.device.util.RequestUtils;
|
||||
import com.central.device.util.http.HeaderUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -47,6 +50,9 @@ public class ApiDeviceController {
|
||||
|
||||
@Autowired
|
||||
private OrderCenterService orderCenterService;
|
||||
|
||||
@Autowired
|
||||
private ILineFileService lineFileService;
|
||||
/**
|
||||
* 获取设备属性
|
||||
*/
|
||||
@@ -69,53 +75,93 @@ public class ApiDeviceController {
|
||||
*/
|
||||
@Operation(summary = "设备属性设置")
|
||||
@PostMapping("/setting/{deviceId}/property")
|
||||
public Result writeProperties(@RequestBody Map<String,Object> param, @PathVariable("deviceId") String deviceId) throws IOException {
|
||||
String url = baseUrl + "/device/instance/" + deviceId + "/property";
|
||||
Gson gson = new Gson();
|
||||
JsonObject jsonObject;
|
||||
String property = MapUtil.getStrValue(param, "control");
|
||||
String value = MapUtil.getStrValue(param, "order_no");
|
||||
Assert.notNull(value,"任务编号不能为空");
|
||||
String orderStatus = orderCenterService.getOrderStatusByOrderNo(value);
|
||||
if (!StringUtils.isEmpty(orderStatus)) {
|
||||
if (!orderStatus.equals("1")){
|
||||
public Result writeProperties(@RequestBody Map<String, Object> param, @PathVariable("deviceId") String deviceId) {
|
||||
log.info("开始设置设备属性: deviceId={}, param={}", deviceId, param);
|
||||
try {
|
||||
// 1. 参数校验
|
||||
String control = MapUtil.getStrValue(param, "control");
|
||||
String orderNo = MapUtil.getStrValue(param, "order_no");
|
||||
if (!validateParams(control, orderNo)) {
|
||||
return Result.failed("参数错误");
|
||||
}
|
||||
|
||||
// 2. 检查订单状态
|
||||
String orderStatus = orderCenterService.getOrderStatusByOrderNo(orderNo);
|
||||
if (!isValidOrderStatus(orderStatus)) {
|
||||
return Result.succeed("设备已执行");
|
||||
}
|
||||
}
|
||||
try {
|
||||
assert property != null;
|
||||
if (ControlEnum.contains(ControlEnum.valueOf(property.toUpperCase()))) {
|
||||
jsonObject = gson.fromJson(controlMessageConstant.CONTROL_MESSAGE_MAP.get(property), JsonObject.class);
|
||||
|
||||
JsonObject data = jsonObject.getAsJsonObject("data");
|
||||
data.addProperty("order_no", value);
|
||||
String waylinLinkUrl = orderCenterService.getOrderStatusByOrderNo(value);
|
||||
data.addProperty("wayline_link_url", waylinLinkUrl);
|
||||
|
||||
}else {
|
||||
// 3. 构建控制消息
|
||||
JsonObject controlMessage = buildControlMessage(control, orderNo);
|
||||
if (controlMessage == null) {
|
||||
return Result.succeed("暂未开放控制权限");
|
||||
}
|
||||
Map<String, String> result = requestUtils.getPostRequestResultMap(url, jsonObject.toString());
|
||||
JSONObject object = JSONObject.parseObject(result.get(""));
|
||||
Assert.notNull(object,"请求IOT平台异常");
|
||||
IotRequestResult requestResult = IotRequestResult.getInstance(object);
|
||||
//500为设备回复超时
|
||||
if (requestResult.getStatus() == 200 || requestResult.getStatus() == 500) {
|
||||
//更新订单状态为进行中
|
||||
Result result1 = orderCenterService.updateOrderStatusDoing(value);
|
||||
if (result1.getResp_code() != null && result1.getResp_code() == 0){
|
||||
return Result.succeed(result1.getData(),"设置成功");
|
||||
}
|
||||
}
|
||||
return Result.failed("请重试");
|
||||
|
||||
// 4. 发送设备控制请求
|
||||
String url = baseUrl + "/device/instance/" + deviceId + "/property";
|
||||
Map<String, String> result = requestUtils.getPostRequestResultMap(url, controlMessage.toString());
|
||||
|
||||
// 5. 处理响应结果
|
||||
return handleDeviceResponse(result, orderNo);
|
||||
|
||||
} catch (Exception e) {
|
||||
return Result.failed(e.getMessage());
|
||||
log.error("设置设备属性异常: deviceId={}, error={}", deviceId, e.getMessage(), e);
|
||||
return Result.failed("系统异常");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateParams(String control, String orderNo) {
|
||||
return !StringUtils.isEmpty(control) && !StringUtils.isEmpty(orderNo);
|
||||
}
|
||||
|
||||
private boolean isValidOrderStatus(String orderStatus) {
|
||||
return !StringUtils.isEmpty(orderStatus) && orderStatus.equals("1");
|
||||
}
|
||||
|
||||
private JsonObject buildControlMessage(String control, String orderNo) {
|
||||
if (!ControlEnum.contains(ControlEnum.valueOf(control.toUpperCase()))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
JsonObject jsonObject = gson.fromJson(controlMessageConstant.CONTROL_MESSAGE_MAP.get(control), JsonObject.class);
|
||||
JsonObject data = jsonObject.getAsJsonObject("data");
|
||||
|
||||
// 设置订单信息
|
||||
data.addProperty("order_no", orderNo);
|
||||
|
||||
// 获取航线信息
|
||||
Map<String, Object> wayResult = orderCenterService.getWaylineByOrderNo(orderNo);
|
||||
String waylineFilePath = MapUtil.getStrValue(wayResult, "waylineFilePath");
|
||||
String waylineId = MapUtil.getStrValue(wayResult, "waylineId");
|
||||
|
||||
data.addProperty("wayline_link_url", waylineFilePath);
|
||||
LineFile lineFile = lineFileService.findLineFileByWaylineId(waylineId);
|
||||
Assert.notNull(lineFile,"航线文件签名不正确");
|
||||
data.addProperty("file_md5", lineFile.getSign());
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@GetMapping("/wayline")
|
||||
public Result<String> getWayline(@RequestParam String no){
|
||||
return Result.succeed(orderCenterService.getOrderStatusByOrderNo(no));
|
||||
private Result handleDeviceResponse(Map<String, String> result, String orderNo) throws JsonProcessingException {
|
||||
JSONObject object = JSONObject.parseObject(result.get(""));
|
||||
if (object == null) {
|
||||
return Result.failed("请求IOT平台异常");
|
||||
}
|
||||
|
||||
IotRequestResult requestResult = IotRequestResult.getInstance(object);
|
||||
if (requestResult.getStatus() == 200 || requestResult.getStatus() == 500) {
|
||||
Result updateResult = orderCenterService.updateOrderStatusDoing(orderNo);
|
||||
if (updateResult.getResp_code() != null && updateResult.getResp_code() == 0) {
|
||||
return Result.succeed(updateResult.getData(), "设置成功");
|
||||
}
|
||||
}
|
||||
|
||||
return Result.failed("请重试");
|
||||
}
|
||||
|
||||
@GetMapping("/device/wayline")
|
||||
public Result<Map> getWayline(@RequestParam String no){
|
||||
return Result.succeed(orderCenterService.getWaylineByOrderNo(no));
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -47,11 +47,21 @@ public class LineFileController {
|
||||
*/
|
||||
@Operation(summary = "查询")
|
||||
@GetMapping("/{id}")
|
||||
public Result findById(@PathVariable Long id) {
|
||||
LineFile model = lineFileService.getById(id);
|
||||
public Result findById(@PathVariable String id) {
|
||||
LineFile model = lineFileService.findLineFileByWaylineId(id);
|
||||
return Result.succeed(model, "查询成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
@Operation(summary = "查询")
|
||||
@GetMapping("/sign/{id}")
|
||||
public String findLineSignById(@PathVariable String id) {
|
||||
LineFile model = lineFileService.findLineFileByWaylineId(id);
|
||||
return model.getSign();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增or更新
|
||||
*/
|
||||
|
||||
+3
-1
@@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* user-center模块远程调用
|
||||
*
|
||||
@@ -27,5 +29,5 @@ public interface OrderCenterService {
|
||||
String getOrderStatusByOrderNo(@PathVariable("orderNo") String orderNo);
|
||||
|
||||
@GetMapping("/qrcode/wayline/{orderNo}")
|
||||
String getWaylineByOrderNo(@PathVariable("orderNo") String orderNo);
|
||||
Map<String,Object> getWaylineByOrderNo(@PathVariable("orderNo") String orderNo);
|
||||
}
|
||||
|
||||
+4
-2
@@ -6,6 +6,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 任务中心调用失败回调
|
||||
*
|
||||
@@ -33,8 +35,8 @@ public class OrderCenterServiceFallbackFactory implements FallbackFactory<OrderC
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWaylineByOrderNo(String orderNo) {
|
||||
return "";
|
||||
public Map<String,Object> getWaylineByOrderNo(String orderNo) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+71
-2
@@ -1,4 +1,73 @@
|
||||
package com.central.device.model;
|
||||
package com.central.device.listener;
|
||||
|
||||
public class DeviceImportListener {
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.read.listener.ReadListener;
|
||||
import com.central.device.model.AgeDevice;
|
||||
import com.central.device.model.excel.AgeDeviceExcel;
|
||||
import com.central.device.service.IAgeDeviceService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceImportListener implements ReadListener<AgeDeviceExcel> {
|
||||
private final IAgeDeviceService deviceService;
|
||||
private final List<AgeDevice> deviceList = new ArrayList<>();
|
||||
private static final int BATCH_COUNT = 100;
|
||||
|
||||
@Override
|
||||
public void invoke(AgeDeviceExcel data, AnalysisContext context) {
|
||||
log.info("解析到一条数据: {}", data);
|
||||
|
||||
// 数据校验
|
||||
validateData(data);
|
||||
|
||||
// 转换为实体
|
||||
AgeDevice device = data.convertToDevice();
|
||||
|
||||
// 设置默认值
|
||||
if (device.getCreateTime() == null) {
|
||||
device.setCreateTime(new Date());
|
||||
}
|
||||
device.setUpdateTime(new Date());
|
||||
|
||||
deviceList.add(device);
|
||||
|
||||
if (deviceList.size() >= BATCH_COUNT) {
|
||||
saveData();
|
||||
deviceList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
saveData();
|
||||
log.info("所有数据解析完成!");
|
||||
}
|
||||
|
||||
private void validateData(AgeDeviceExcel data) {
|
||||
if (StringUtils.isEmpty(data.getDeviceSn())) {
|
||||
throw new IllegalArgumentException("设备序列号不能为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(data.getDeviceName())) {
|
||||
throw new IllegalArgumentException("设备名称不能为空");
|
||||
}
|
||||
// 检查设备序列号是否已存在
|
||||
AgeDevice existDevice = deviceService.getByDeviceSn(data.getDeviceSn());
|
||||
if (existDevice != null) {
|
||||
throw new IllegalArgumentException("设备序列号已存在:" + data.getDeviceSn());
|
||||
}
|
||||
}
|
||||
|
||||
private void saveData() {
|
||||
if (!deviceList.isEmpty()) {
|
||||
log.info("开始保存数据,数量:{}", deviceList.size());
|
||||
deviceService.saveBatch(deviceList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@ package com.central.device.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -20,7 +21,6 @@ import java.util.Date;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("manage_device")
|
||||
public class AgeDevice extends SuperEntity {
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String deviceSn;
|
||||
private String deviceName;
|
||||
@@ -45,4 +45,6 @@ public class AgeDevice extends SuperEntity {
|
||||
private String deviceDesc;
|
||||
private String urlNormal;
|
||||
private String urlSelect;
|
||||
private String deviceStatus;
|
||||
private String tenantId;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@ package com.central.device.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -36,4 +37,5 @@ public class LineFile extends SuperEntity {
|
||||
private Date createTime;
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
private String tenantId;
|
||||
}
|
||||
|
||||
+177
-1
@@ -1,4 +1,180 @@
|
||||
package com.central.device.model;
|
||||
package com.central.device.model.excel;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import com.central.device.model.AgeDevice;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 设备信息Excel导入导出实体
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AgeDeviceExcel {
|
||||
|
||||
@ExcelProperty(value = "设备序列号", index = 0)
|
||||
@ColumnWidth(20)
|
||||
@NotBlank(message = "设备序列号不能为空")
|
||||
private String deviceSn;
|
||||
|
||||
@ExcelProperty(value = "设备名称", index = 1)
|
||||
@ColumnWidth(20)
|
||||
@NotBlank(message = "设备名称不能为空")
|
||||
private String deviceName;
|
||||
|
||||
@ExcelProperty(value = "设备类型", index = 2)
|
||||
@ColumnWidth(15)
|
||||
private Integer deviceType;
|
||||
|
||||
@ExcelProperty(value = "子类型", index = 3)
|
||||
@ColumnWidth(15)
|
||||
private Integer subType;
|
||||
|
||||
@ExcelProperty(value = "固件版本", index = 4)
|
||||
@ColumnWidth(20)
|
||||
private String firmwareVersion;
|
||||
|
||||
@ExcelProperty(value = "设备状态", index = 5)
|
||||
@ColumnWidth(15)
|
||||
private String deviceStatus;
|
||||
|
||||
@ExcelProperty(value = "设备描述", index = 6)
|
||||
@ColumnWidth(30)
|
||||
private String deviceDesc;
|
||||
|
||||
@ExcelProperty(value = "工作空间ID", index = 7)
|
||||
@ColumnWidth(20)
|
||||
private String workspaceId;
|
||||
|
||||
@ExcelProperty(value = "域", index = 8)
|
||||
@ColumnWidth(15)
|
||||
private Integer domain;
|
||||
|
||||
@ExcelProperty(value = "兼容状态", index = 9)
|
||||
@ColumnWidth(15)
|
||||
private Integer compatibleStatus;
|
||||
|
||||
@ExcelProperty(value = "版本", index = 10)
|
||||
@ColumnWidth(15)
|
||||
private String version;
|
||||
|
||||
@ExcelProperty(value = "设备索引", index = 11)
|
||||
@ColumnWidth(20)
|
||||
private String deviceIndex;
|
||||
|
||||
@ExcelProperty(value = "子设备序列号", index = 12)
|
||||
@ColumnWidth(20)
|
||||
private String childSn;
|
||||
|
||||
@ExcelProperty(value = "绑定状态", index = 13)
|
||||
@ColumnWidth(15)
|
||||
private Integer boundStatus;
|
||||
|
||||
@ExcelProperty(value = "租户ID", index = 14)
|
||||
@ColumnWidth(20)
|
||||
private String tenantId;
|
||||
|
||||
// 以下字段在Excel中不显示,但在实体转换时需要
|
||||
@ExcelIgnore
|
||||
private String userId;
|
||||
|
||||
@ExcelIgnore
|
||||
private String nickname;
|
||||
|
||||
@ExcelIgnore
|
||||
private Long boundTime;
|
||||
|
||||
@ExcelIgnore
|
||||
private Long loginTime;
|
||||
|
||||
@ExcelIgnore
|
||||
private String urlNormal;
|
||||
|
||||
@ExcelIgnore
|
||||
private String urlSelect;
|
||||
|
||||
@ExcelProperty(value = "创建时间", index = 15)
|
||||
@ColumnWidth(20)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
@ExcelProperty(value = "更新时间", index = 16)
|
||||
@ColumnWidth(20)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 转换为设备实体
|
||||
*/
|
||||
public AgeDevice toDevice() {
|
||||
AgeDevice device = new AgeDevice();
|
||||
// 必填字段
|
||||
device.setDeviceSn(this.deviceSn);
|
||||
device.setDeviceName(this.deviceName);
|
||||
device.setDeviceType(this.deviceType);
|
||||
|
||||
// 可选字段,需要判空
|
||||
device.setSubType(this.subType);
|
||||
device.setFirmwareVersion(this.firmwareVersion);
|
||||
device.setDeviceStatus(this.deviceStatus);
|
||||
device.setDeviceDesc(this.deviceDesc);
|
||||
device.setWorkspaceId(this.workspaceId);
|
||||
device.setDomain(this.domain);
|
||||
device.setCompatibleStatus(this.compatibleStatus);
|
||||
device.setVersion(this.version);
|
||||
device.setDeviceIndex(this.deviceIndex);
|
||||
device.setChildSn(this.childSn);
|
||||
device.setBoundStatus(this.boundStatus);
|
||||
device.setTenantId(this.tenantId);
|
||||
|
||||
// 系统字段
|
||||
device.setCreateTime(this.createTime);
|
||||
device.setUpdateTime(this.updateTime);
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从设备实体转换
|
||||
*/
|
||||
public static AgeDeviceExcel fromDevice(AgeDevice device) {
|
||||
if (device == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AgeDeviceExcel excel = new AgeDeviceExcel();
|
||||
// 必填字段
|
||||
excel.setDeviceSn(device.getDeviceSn());
|
||||
excel.setDeviceName(device.getDeviceName());
|
||||
excel.setDeviceType(device.getDeviceType());
|
||||
|
||||
// 可选字段
|
||||
excel.setSubType(device.getSubType());
|
||||
excel.setFirmwareVersion(device.getFirmwareVersion());
|
||||
excel.setDeviceStatus(device.getDeviceStatus());
|
||||
excel.setDeviceDesc(device.getDeviceDesc());
|
||||
excel.setWorkspaceId(device.getWorkspaceId());
|
||||
excel.setDomain(device.getDomain());
|
||||
excel.setCompatibleStatus(device.getCompatibleStatus());
|
||||
excel.setVersion(device.getVersion());
|
||||
excel.setDeviceIndex(device.getDeviceIndex());
|
||||
excel.setChildSn(device.getChildSn());
|
||||
excel.setBoundStatus(device.getBoundStatus());
|
||||
excel.setTenantId(device.getTenantId());
|
||||
|
||||
// 系统字段
|
||||
excel.setCreateTime(device.getCreateTime());
|
||||
excel.setUpdateTime(device.getUpdateTime());
|
||||
|
||||
return excel;
|
||||
}
|
||||
}
|
||||
|
||||
+21
@@ -4,6 +4,7 @@ import com.central.device.model.AgeDevice;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.service.ISuperService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -19,5 +20,25 @@ public interface IAgeDeviceService extends ISuperService<AgeDevice> {
|
||||
* @return
|
||||
*/
|
||||
PageResult<AgeDevice> findList(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 根据参数查询设备列表
|
||||
*/
|
||||
List<AgeDevice> findListByParams(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 根据设备序列号查询设备
|
||||
*/
|
||||
AgeDevice getByDeviceSn(String deviceSn);
|
||||
|
||||
/**
|
||||
* 检查设备序列号是否存在
|
||||
*/
|
||||
boolean checkDeviceSnExists(String deviceSn);
|
||||
|
||||
/**
|
||||
* 批量导入设备信息
|
||||
*/
|
||||
boolean importDevices(List<AgeDevice> deviceList);
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -1,8 +1,8 @@
|
||||
package com.central.device.service;
|
||||
|
||||
import com.central.device.model.LineFile;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.device.model.LineFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -19,5 +19,7 @@ public interface ILineFileService extends ISuperService<LineFile> {
|
||||
* @return
|
||||
*/
|
||||
PageResult<LineFile> findList(Map<String, Object> params);
|
||||
|
||||
LineFile findLineFileByWaylineId(String waylineId);
|
||||
}
|
||||
|
||||
|
||||
+52
@@ -1,5 +1,6 @@
|
||||
package com.central.device.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
@@ -9,6 +10,8 @@ import com.central.device.service.IAgeDeviceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -33,4 +36,53 @@ public class AgeDeviceServiceImpl extends SuperServiceImpl<AgeDeviceMapper, AgeD
|
||||
List<AgeDevice> list = baseMapper.findList(page, params);
|
||||
return PageResult.<AgeDevice>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AgeDevice> findListByParams(Map<String, Object> params) {
|
||||
QueryWrapper<AgeDevice> wrapper = new QueryWrapper<>();
|
||||
// 添加查询条件
|
||||
if (params.get("deviceSn") != null) {
|
||||
wrapper.like("device_sn", params.get("deviceSn"));
|
||||
}
|
||||
if (params.get("deviceName") != null) {
|
||||
wrapper.like("device_name", params.get("deviceName"));
|
||||
}
|
||||
if (params.get("deviceType") != null) {
|
||||
wrapper.eq("device_type", params.get("deviceType"));
|
||||
}
|
||||
// 可以添加更多查询条件...
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgeDevice getByDeviceSn(String deviceSn) {
|
||||
return this.getOne(new QueryWrapper<AgeDevice>().eq("device_sn", deviceSn));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkDeviceSnExists(String deviceSn) {
|
||||
return this.baseMapper.exists(new QueryWrapper<AgeDevice>()
|
||||
.eq("device_sn", deviceSn));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean importDevices(List<AgeDevice> deviceList) {
|
||||
if (CollUtil.isEmpty(deviceList)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// 批量保存,每批100条
|
||||
int batchSize = 100;
|
||||
List<List<AgeDevice>> partition = CollUtil.partition(deviceList, batchSize);
|
||||
for (List<AgeDevice> batch : partition) {
|
||||
this.saveBatch(batch, batchSize);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("批量导入设备信息失败", e);
|
||||
throw new RuntimeException("批量导入设备信息失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -1,5 +1,6 @@
|
||||
package com.central.device.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
@@ -33,4 +34,10 @@ public class LineFileServiceImpl extends SuperServiceImpl<LineFileMapper, LineFi
|
||||
List<LineFile> list = baseMapper.findList(page, params);
|
||||
return PageResult.<LineFile>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LineFile findLineFileByWaylineId(String waylineId) {
|
||||
return baseMapper.selectOne(new QueryWrapper<LineFile>()
|
||||
.eq("wayline_id",waylineId));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -5,6 +5,7 @@ import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.file.service.IFileService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -26,6 +27,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author 作者 owen E-mail: 624191343@qq.com
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class FileController {
|
||||
@Autowired
|
||||
@@ -103,7 +105,10 @@ public class FileController {
|
||||
|
||||
@GetMapping("/file/{id}")
|
||||
public String getFileViewUrl(@PathVariable String id) {
|
||||
return fileService.getViewUrl(id);
|
||||
log.info("请求文件可访问链接,参数文件Id:{}",id);
|
||||
String viewUrl = fileService.getViewUrl(id);
|
||||
log.info("请求文件可访问链接,链接值:{}",viewUrl);
|
||||
return viewUrl;
|
||||
}
|
||||
|
||||
@GetMapping("/files/{id}")
|
||||
|
||||
+22
-1
@@ -8,8 +8,10 @@ import com.central.common.model.FileInfo;
|
||||
import com.central.oss.model.ObjectInfo;
|
||||
import com.central.oss.properties.FileServerProperties;
|
||||
import com.central.oss.template.OssTemplate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -22,6 +24,7 @@ import java.io.OutputStream;
|
||||
* @date 2025/1/13
|
||||
* <p>
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@ConditionalOnProperty(prefix = FileServerProperties.PREFIX, name = "type", havingValue = FileServerProperties.TYPE_OSS)
|
||||
public class OssService extends AbstractIFileService {
|
||||
@@ -87,7 +90,25 @@ public class OssService extends AbstractIFileService {
|
||||
|
||||
@Override
|
||||
public FileInfo getFileInfo(String id) {
|
||||
return baseMapper.findById(id);
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
log.warn("文件ID为空");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
log.info("开始查询文件信息: fileId={}", id);
|
||||
FileInfo fileInfo = baseMapper.selectById(id.trim()); // 添加trim()去除可能的空格
|
||||
|
||||
if (fileInfo == null) {
|
||||
log.warn("未找到文件信息: fileId={}", id);
|
||||
return null;
|
||||
}
|
||||
|
||||
log.info("查询文件信息成功: fileId={}, path={}", fileInfo.getId(), fileInfo.getPath());
|
||||
return fileInfo;
|
||||
} catch (Exception e) {
|
||||
log.error("查询文件信息异常: fileId={}, error={}", id, e.getMessage(), e);
|
||||
throw new RuntimeException("查询文件信息失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,7 @@ zlt:
|
||||
bucketName: ${zlt.oss.bucketName}
|
||||
#多租户配置
|
||||
tenant:
|
||||
enable: true
|
||||
enable: false
|
||||
|
||||
#fastDFS配置
|
||||
#fdfs:
|
||||
|
||||
+19
-1
@@ -12,6 +12,7 @@ import com.central.log.annotation.AuditLog;
|
||||
import com.central.order.config.TencentPayProperties;
|
||||
import com.central.order.enums.CommonStatus;
|
||||
import com.central.order.enums.OrderStatus;
|
||||
import com.central.order.feign.DeviceCenterService;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.feign.UserCenterService;
|
||||
import com.central.order.model.*;
|
||||
@@ -93,6 +94,11 @@ public class OrderController {
|
||||
// 获取当前日期,格式化为 yyyyMMdd
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(CommonConstant.DATEMINUTE_FORMAT);
|
||||
|
||||
@Autowired
|
||||
private DeviceCenterService deviceCenterService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@@ -335,7 +341,19 @@ public class OrderController {
|
||||
if (orderService.getUnCompleteOrderCount(deviceSn)==0){
|
||||
List<Order> orders = orderService.getOrdersInQueueByDevice(deviceSn);
|
||||
if (!orders.isEmpty()){
|
||||
return Result.succeed(orders.get(0),"获取成功");
|
||||
Order order = orders.get(0);
|
||||
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
||||
Assert.notNull(qrCode,"二维码数据不能为空");
|
||||
|
||||
// 从二维码中获取航线ID
|
||||
String waylineId = qrCode.getWaylineId();
|
||||
// 根据航线ID获取对应的文件路径
|
||||
String waylineFilePath = fileCenterService.getFileViewUrl(waylineId);
|
||||
Assert.notNull(waylineFilePath,"订单航线数据不能为空");
|
||||
|
||||
order.setFileMd5(deviceCenterService.getLineFileSign(waylineId));
|
||||
order.setWaylineLinkUrl(waylineFilePath);
|
||||
return Result.succeed(order,"获取成功");
|
||||
}
|
||||
}
|
||||
return Result.failed("未存在排队队列");
|
||||
|
||||
+6
-2
@@ -20,6 +20,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -133,13 +134,16 @@ public class QrCodeController {
|
||||
}
|
||||
|
||||
@GetMapping("/wayline/{orderNo}")
|
||||
public String getWaylineByOrderNo(@PathVariable("orderNo") String orderNo){
|
||||
public Map<String,Object> getWaylineByOrderNo(@PathVariable("orderNo") String orderNo){
|
||||
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
Assert.notNull(order,"订单No不能为空");
|
||||
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
||||
Assert.notNull(qrCode,"二维码数据不能为空");
|
||||
String waylineFilePath = fileCenterService.getFileViewUrl(qrCode.getWaylineId());
|
||||
return waylineFilePath;
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("waylineFilePath",waylineFilePath);
|
||||
map.put("waylineId",qrCode.getWaylineId());
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-26
@@ -1,46 +1,29 @@
|
||||
package com.central.order.feign;
|
||||
|
||||
import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.common.model.FileInfo;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.fallback.FileCenterServiceFallbackFactory;
|
||||
import com.central.order.feign.fallback.DeviceCenterServiceFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
/**
|
||||
* user-center模块远程调用
|
||||
* device-center模块远程调用
|
||||
*
|
||||
* @author lsl
|
||||
* @version 1.0
|
||||
* @description user-center模块远程调用
|
||||
* @create 2025/1/13
|
||||
**/
|
||||
@FeignClient(name = ServiceNameConstants.FILE_SERVICE, fallbackFactory = FileCenterServiceFallbackFactory.class, dismiss404 = true)
|
||||
public interface FileCenterService {
|
||||
@FeignClient(name = ServiceNameConstants.DEVICE_SERVICE, fallbackFactory = DeviceCenterServiceFallbackFactory.class, dismiss404 = true)
|
||||
public interface DeviceCenterService {
|
||||
|
||||
/**
|
||||
* 通过ID查询预览地址
|
||||
* 通过ID查询文件sign
|
||||
*
|
||||
* @param id 文件ID
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/file/{id}")
|
||||
String getFileViewUrl(@PathVariable("id") String id);
|
||||
@GetMapping("/wayline/sign/{id}")
|
||||
String getLineFileSign(@PathVariable("id") String id);
|
||||
|
||||
@GetMapping("/type/{id}")
|
||||
String getFileContentType(@PathVariable("id") String id);
|
||||
|
||||
@GetMapping("/qrcode/{codeId}")
|
||||
Result<Map> uploadQrCodeFile(@PathVariable("codeId") String codeId) throws Exception;
|
||||
|
||||
@PostMapping("/path")
|
||||
FileInfo creatFileInfo(@RequestBody String path);
|
||||
|
||||
@GetMapping("/files/path")
|
||||
String getViewUrlByPath(@RequestParam("path") String path) ;
|
||||
|
||||
@GetMapping("/files/path/style")
|
||||
String getViewUrlByPathStyle(@RequestParam("params") Map<String,String> params) ;
|
||||
}
|
||||
|
||||
+6
-36
@@ -1,60 +1,30 @@
|
||||
package com.central.order.feign.fallback;
|
||||
|
||||
import com.central.common.model.FileInfo;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.feign.DeviceCenterService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件中心调用失败回调
|
||||
*
|
||||
* @author lsl
|
||||
* @version 1.0
|
||||
* @description 用户中心调用失败回调
|
||||
* @description 设备中心调用失败回调
|
||||
* @create 2025/1/17 11:33
|
||||
**/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FileCenterServiceFallbackFactory implements FallbackFactory<FileCenterService> {
|
||||
public class DeviceCenterServiceFallbackFactory implements FallbackFactory<DeviceCenterService> {
|
||||
|
||||
@Override
|
||||
public FileCenterService create(Throwable cause) {
|
||||
return new FileCenterService() {
|
||||
public DeviceCenterService create(Throwable cause) {
|
||||
return new DeviceCenterService() {
|
||||
|
||||
@Override
|
||||
public String getFileViewUrl(String id) {
|
||||
public String getLineFileSign(String id) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileContentType(String id) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Map> uploadQrCodeFile(String codeId) throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo creatFileInfo(String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getViewUrlByPath(String path) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getViewUrlByPathStyle(Map<String, String> params) {
|
||||
return "";
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ public class Order extends SuperEntity {
|
||||
private Date payTime;
|
||||
|
||||
private transient String createdTime;
|
||||
private transient String fileMd5;
|
||||
|
||||
private String codeId;
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@@ -48,5 +49,7 @@ public class Order extends SuperEntity {
|
||||
private String company;
|
||||
private Integer isDel;
|
||||
|
||||
private transient String waylineLinkUrl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user