Compare commits
No commits in common. "049e91db822f65474a8ca3a988863ab19b4d7688" and "182d4c796164dc4c24579045606b6a1fc4b682e8" have entirely different histories.
049e91db82
...
182d4c7961
1
pom.xml
1
pom.xml
@ -145,6 +145,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
@ -26,14 +26,16 @@ public class WebSocketInterceptor implements HandshakeInterceptor {
|
||||
private ProductService productService;
|
||||
|
||||
@Override
|
||||
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) {
|
||||
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
|
||||
if (request instanceof ServletServerHttpRequest) {
|
||||
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
|
||||
// 获取完整路径
|
||||
// 获取路径变量
|
||||
String path = servletRequest.getRequestURI();
|
||||
String[] pathParts = path.split("/");
|
||||
String pathVariable = pathParts[pathParts.length - 1];
|
||||
|
||||
// 根据路径设置不同的业务逻辑 Supplier
|
||||
switch (path) {
|
||||
// 根据路径变量设置不同的业务逻辑 Supplier
|
||||
switch (pathVariable) {
|
||||
case "/api/rest/device/ws/device/status":
|
||||
attributes.put("dataSupplier", (Supplier<String>) () -> String.valueOf(deviceService.status()));
|
||||
break;
|
||||
@ -44,7 +46,7 @@ public class WebSocketInterceptor implements HandshakeInterceptor {
|
||||
attributes.put("dataSupplier", (Supplier<String>) () -> String.valueOf(productService.status()));
|
||||
break;
|
||||
default:
|
||||
attributes.put("dataSupplier", (Supplier<String>) () -> "Unknown path: " + path);
|
||||
attributes.put("dataSupplier", (Supplier<String>) () -> "Unknown path: " + pathVariable);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.attachment.controller;
|
||||
|
||||
import com.zsc.edu.gateway.exception.StorageException;
|
||||
import com.zsc.edu.gateway.framework.storage.exception.StorageFileNotFoundException;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import com.zsc.edu.gateway.modules.attachment.service.AttachmentService;
|
||||
import com.zsc.edu.gateway.modules.operationLog.entity.OperationLogAnnotation;
|
||||
@ -9,7 +8,6 @@ import lombok.AllArgsConstructor;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ContentDisposition;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -75,43 +73,6 @@ public class AttachmentController {
|
||||
}
|
||||
return ResponseEntity.ok(wrapper.resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览附件
|
||||
*
|
||||
* @param id 附件ID
|
||||
* @return 附件文件内容(直接预览)
|
||||
*/
|
||||
@GetMapping("/preview/{id}")
|
||||
public ResponseEntity<?> preview(
|
||||
@PathVariable("id") String id
|
||||
) {
|
||||
try {
|
||||
Attachment.Wrapper wrapper = service.loadAsWrapper(id);
|
||||
String mimeType = wrapper.attachment.mimeType;
|
||||
|
||||
// 如果是图片或 PDF,直接返回文件流
|
||||
if (mimeType.startsWith("image/") || mimeType.equals("application/pdf")) {
|
||||
ContentDisposition contentDisposition = ContentDisposition.builder("inline")
|
||||
.filename(wrapper.attachment.fileName, StandardCharsets.UTF_8)
|
||||
.build();
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition.toString())
|
||||
.header(HttpHeaders.CONTENT_TYPE, mimeType)
|
||||
.body(wrapper.resource);
|
||||
} else {
|
||||
// 如果是文本文件,直接返回文本内容
|
||||
String content = new String(wrapper.resource.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
return ResponseEntity.ok(content);
|
||||
}
|
||||
} catch (StorageFileNotFoundException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
} catch (IOException e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("文件读取失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据附件ID获取附件信息
|
||||
* */
|
||||
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.framework.message.sse.SseConfig;
|
||||
import com.zsc.edu.gateway.framework.mybatisplus.DataPermission;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.BatchDeviceDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceDto;
|
||||
@ -37,6 +38,8 @@ public class DeviceController {
|
||||
DeviceService service;
|
||||
|
||||
RecordDataService recordService;
|
||||
@Resource
|
||||
private SseConfig sseConfig;
|
||||
|
||||
/**
|
||||
* 创建设备
|
||||
|
@ -64,5 +64,4 @@ public class DeviceDto {
|
||||
*/
|
||||
public String previewId;
|
||||
|
||||
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class Device extends BaseEntity {
|
||||
* 设备预览图附件ID
|
||||
*/
|
||||
public String previewId;
|
||||
//TODO 设备运行状态
|
||||
|
||||
|
||||
public enum Status implements IEnum<Integer>, IState<Status> {
|
||||
UNACTIVATED(0, "未激活"),
|
||||
|
@ -43,7 +43,10 @@ public class DeviceQuery {
|
||||
* 设态是否在线
|
||||
*/
|
||||
public Boolean isOnline;
|
||||
|
||||
/**
|
||||
* 产品名称
|
||||
*/
|
||||
public String productName;
|
||||
|
||||
public LambdaQueryWrapper<Device> wrapper() {
|
||||
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
@ -32,6 +32,4 @@ public interface DeviceRepository extends BaseMapper<Device> {
|
||||
Device findByClientId(@Param("clientId") String clientId);
|
||||
|
||||
List<Device> selectListByName(@Param("name") String name);
|
||||
|
||||
IPage<Device> selectPageByConditions(Page<Device> page, @Param("query") DeviceQuery query);
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
*/
|
||||
@Override
|
||||
public IPage<Device> query(Page<Device> page, DeviceQuery query) {
|
||||
return baseMapper.selectPageByConditions(page, query);
|
||||
return deviceRepo.selectPage(page, query.wrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,6 +126,7 @@ public class DeviceVo {
|
||||
*/
|
||||
public Attachment preview;
|
||||
|
||||
|
||||
/**
|
||||
* 所属产品ID
|
||||
*/
|
||||
|
@ -1,12 +1,14 @@
|
||||
package com.zsc.edu.gateway.modules.iot.product.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.framework.message.sse.SseConfig;
|
||||
import com.zsc.edu.gateway.framework.mybatisplus.DataPermission;
|
||||
import com.zsc.edu.gateway.modules.iot.product.dto.ProductDto;
|
||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||
import com.zsc.edu.gateway.modules.iot.product.query.ProductQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.product.service.ProductService;
|
||||
import com.zsc.edu.gateway.modules.operationLog.entity.OperationLogAnnotation;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -23,6 +25,8 @@ public class ProductController {
|
||||
|
||||
private final ProductService service;
|
||||
|
||||
@Resource
|
||||
SseConfig sseConfig;
|
||||
|
||||
/**
|
||||
* 创建产品
|
||||
|
@ -82,27 +82,10 @@
|
||||
where d.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectPageByConditions" resultType="com.zsc.edu.gateway.modules.iot.device.entity.Device">
|
||||
SELECT d.*, p.*
|
||||
<select id="selectList" resultType="com.zsc.edu.gateway.modules.iot.device.entity.Device">
|
||||
SELECT d.*, p.name AS productName
|
||||
FROM iot_device d
|
||||
LEFT JOIN iot_product p ON d.product_id = p.id
|
||||
<where>
|
||||
<if test="query.name != null and query.name != ''">
|
||||
AND d.name LIKE concat('%', #{query.name}, '%')
|
||||
</if>
|
||||
<if test="query.clientId != null and query.clientId != ''">
|
||||
AND d.client_id = #{query.clientId}
|
||||
</if>
|
||||
<if test="query.state != null and query.state != ''">
|
||||
AND d.state = #{query.state}
|
||||
</if>
|
||||
<if test="query.isOnline != null and query.isOnline != ''">
|
||||
AND d.online = #{query.isOnline}
|
||||
</if>
|
||||
<if test="query.productId != null and query.productId != ''">
|
||||
AND d.product_id = #{query.productId}
|
||||
</if>
|
||||
</where>
|
||||
LEFT JOIN iot_product p ON d.product_id = p.id
|
||||
</select>
|
||||
|
||||
<select id="selectListByName" resultMap="BaseResultMap">
|
||||
@ -122,8 +105,6 @@
|
||||
left join iot_param ip on p.id = ip.foreign_id and ip.foreign_type = 3
|
||||
left join attachment ai on d.icon_id = ai.id
|
||||
left join attachment ap on d.preview_id = ap.id
|
||||
<if test="name != null">
|
||||
WHERE d.name LIKE concat('%', #{name}, '%')
|
||||
</if>
|
||||
WHERE d.name LIKE concat('%', #{name}, '%')
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user