lwh 2 недель назад
Родитель
Сommit
9ee473a972

+ 2 - 2
pig-marketing/pig-marketing-api/src/main/java/com/pig4cloud/pig/marketing/api/dto/mongo/PageDeviceInfoDTO.java

@@ -41,12 +41,12 @@ public class PageDeviceInfoDTO implements Serializable {
 	/**
 	 * 起始时间
 	 */
-	@Schema(description = "起始时间")
+	@Schema(description = "起始时间", example = "2025-08-28 12:00:00")
 	private LocalDateTime startTime;
 
 	/**
 	 * 结束时间
 	 */
-	@Schema(description = "结束时间")
+	@Schema(description = "结束时间", example = "2025-08-29 12:00:00")
 	private LocalDateTime endTime;
 }

+ 2 - 2
pig-marketing/pig-marketing-api/src/main/java/com/pig4cloud/pig/marketing/api/dto/mongo/PageMessageDTO.java

@@ -49,12 +49,12 @@ public class PageMessageDTO implements Serializable {
 	/**
 	 * 起始时间
 	 */
-	@Schema(description = "起始时间")
+	@Schema(description = "起始时间", example = "2025-08-28 12:00:00")
 	private LocalDateTime startTime;
 
 	/**
 	 * 结束时间
 	 */
-	@Schema(description = "结束时间")
+	@Schema(description = "结束时间", example = "2025-08-29 12:00:00")
 	private LocalDateTime endTime;
 }

+ 3 - 0
pig-marketing/pig-marketing-api/src/main/java/com/pig4cloud/pig/marketing/api/dto/mongo/SaveDeviceInfoDTO.java

@@ -26,4 +26,7 @@ public class SaveDeviceInfoDTO implements Serializable {
 
 	@Schema(description = "设备信息")
 	private String deviceInfo;
+
+	@Schema(description = "头信息")
+	private String headInfo;
 }

+ 1 - 1
pig-marketing/pig-marketing-api/src/main/java/com/pig4cloud/pig/marketing/api/dto/mongo/SaveTcpMessageDTO.java

@@ -20,7 +20,7 @@ public class SaveTcpMessageDTO implements Serializable {
 	@Serial
 	private static final long serialVersionUID = 1L;
 
-	@Schema(description = "客户端ID")
+	@Schema(description = "客户端ID", example = "e478d52e-c773-45e7-b7f9-20ffeb14e730")
 	@NotBlank(message = "客户端ID不能为空")
 	private String clientID;
 

+ 3 - 0
pig-marketing/pig-marketing-api/src/main/java/com/pig4cloud/pig/marketing/api/entity/mongo/Device.java

@@ -27,6 +27,9 @@ public class Device {
 	@Schema(description = "设备信息")
 	private String deviceInfo; // 设备信息字符串
 
+	@Schema(description = "头信息")
+	private String headInfo;
+
 	@Schema(description = "创建时间")
 	private String createTime; // 创建时间
 

+ 2 - 1
pig-marketing/pig-marketing-biz/src/main/java/com/pig4cloud/pig/marketing/controller/TcpDataController.java

@@ -9,6 +9,7 @@ import com.pig4cloud.pig.marketing.api.dto.mongo.SaveDeviceInfoDTO;
 import com.pig4cloud.pig.marketing.api.dto.mongo.SaveTcpMessageDTO;
 import com.pig4cloud.pig.marketing.api.entity.mongo.Device;
 import com.pig4cloud.pig.marketing.api.entity.mongo.Message;
+import com.pig4cloud.pig.marketing.api.vo.mongo.PageDeviceInfoVO;
 import com.pig4cloud.pig.marketing.service.TcpDataService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -50,7 +51,7 @@ public class TcpDataController {
 
 	@PostMapping("/device/page")
 	@Operation(summary = "分页查询设备信息")
-	public R<Page<Device>> PageDeviceInfo(@RequestBody PageDeviceInfoDTO reqDto) {
+	public R<Page<PageDeviceInfoVO>> PageDeviceInfo(@RequestBody PageDeviceInfoDTO reqDto) {
 		return R.ok(tcpDataService.pageDeviceInfo(reqDto));
 	}
 

+ 2 - 1
pig-marketing/pig-marketing-biz/src/main/java/com/pig4cloud/pig/marketing/service/TcpDataService.java

@@ -8,6 +8,7 @@ import com.pig4cloud.pig.marketing.api.dto.mongo.SaveDeviceInfoDTO;
 import com.pig4cloud.pig.marketing.api.dto.mongo.SaveTcpMessageDTO;
 import com.pig4cloud.pig.marketing.api.entity.mongo.Device;
 import com.pig4cloud.pig.marketing.api.entity.mongo.Message;
+import com.pig4cloud.pig.marketing.api.vo.mongo.PageDeviceInfoVO;
 
 /**
  * @author: lwh
@@ -36,7 +37,7 @@ public interface TcpDataService {
 	 * @param reqDto 入参
 	 * @return 设备信息列表
 	 */
-	Page<Device> pageDeviceInfo(PageDeviceInfoDTO reqDto);
+	Page<PageDeviceInfoVO> pageDeviceInfo(PageDeviceInfoDTO reqDto);
 
 
 	/******************************************* 消息 *******************************************

+ 44 - 6
pig-marketing/pig-marketing-biz/src/main/java/com/pig4cloud/pig/marketing/service/impl/TcpDataServiceImpl.java

@@ -8,10 +8,13 @@ import com.pig4cloud.pig.marketing.api.dto.mongo.SaveDeviceInfoDTO;
 import com.pig4cloud.pig.marketing.api.dto.mongo.SaveTcpMessageDTO;
 import com.pig4cloud.pig.marketing.api.entity.mongo.Device;
 import com.pig4cloud.pig.marketing.api.entity.mongo.Message;
+import com.pig4cloud.pig.marketing.api.vo.mongo.PageDeviceInfoVO;
 import com.pig4cloud.pig.marketing.repository.MessageRepository;
 import com.pig4cloud.pig.marketing.service.TcpDataService;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
@@ -23,6 +26,7 @@ import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 
@@ -60,6 +64,7 @@ public class TcpDataServiceImpl implements TcpDataService {
 			Device device = new Device();
 			device.setClientID(reqDto.getClientID());
 			device.setDeviceInfo(reqDto.getDeviceInfo());
+			device.setHeadInfo(reqDto.getHeadInfo());
 			// 设置创建时间和更新时间为当前时间的字符串格式
 			String currentTime = LocalDateTime.now().format(DATE_TIME_FORMATTER);
 			device.setCreateTime(currentTime);
@@ -68,11 +73,16 @@ public class TcpDataServiceImpl implements TcpDataService {
 			return insert.getId();
 		} else {
 			// 有数据时对比设备信息是否一致
-			if (!Objects.equals(existingDevice.getDeviceInfo(), reqDto.getDeviceInfo())) {
+			if (!Objects.equals(existingDevice.getDeviceInfo(), reqDto.getDeviceInfo())
+					|| !Objects.equals(existingDevice.getHeadInfo(), reqDto.getHeadInfo())) {
 				// 信息不一致则更新
 				Update update = new Update();
-				update.set("deviceInfo", reqDto.getDeviceInfo());
-
+				if (!StringUtils.isBlank(reqDto.getDeviceInfo())) {
+					update.set("deviceInfo", reqDto.getDeviceInfo());
+				}
+				if (!StringUtils.isBlank(reqDto.getHeadInfo())) {
+					update.set("headInfo", reqDto.getHeadInfo());
+				}
 				// 设置更新时间为当前时间的字符串格式
 				update.set("updateTime", LocalDateTime.now().format(DATE_TIME_FORMATTER));
 
@@ -102,7 +112,7 @@ public class TcpDataServiceImpl implements TcpDataService {
 	 * @return 设备信息列表
 	 */
 	@Override
-	public Page<Device> pageDeviceInfo(PageDeviceInfoDTO reqDto) {
+	public Page<PageDeviceInfoVO> pageDeviceInfo(PageDeviceInfoDTO reqDto) {
 		// 创建查询条件
 		Criteria criteria = new Criteria();
 
@@ -150,9 +160,21 @@ public class TcpDataServiceImpl implements TcpDataService {
 		// 执行查询
 		List<Device> devices = mongoTemplate.find(query, Device.class);
 
+		List<PageDeviceInfoVO> result = new ArrayList<>();
+		// 组装数据
+		for (Device device : devices) {
+			PageDeviceInfoVO info = new PageDeviceInfoVO();
+			BeanUtils.copyProperties(device, info);
+
+			// 查询总条数
+			Long dataTotal = getMsgDataTotal(device.getClientID());
+			info.setTotal(dataTotal);
+			result.add(info);
+		}
+
 		// 封装分页结果
-		Page<Device> page = new Page<>(reqDto.getCurrent(), reqDto.getSize(), total);
-		page.setRecords(devices);
+		Page<PageDeviceInfoVO> page = new Page<>(reqDto.getCurrent(), reqDto.getSize(), total);
+		page.setRecords(result);
 		return page;
 	}
 
@@ -243,4 +265,20 @@ public class TcpDataServiceImpl implements TcpDataService {
 		page.setRecords(messages);
 		return page;
 	}
+
+
+	private Long getMsgDataTotal(String clientId){
+		// 创建查询条件
+		Criteria criteria = new Criteria();
+
+		// 添加clientID条件
+		criteria.and("clientID").is(clientId);
+
+		// 创建查询对象
+		Query query = new Query(criteria);
+
+		// 计算总记录数
+		return mongoTemplate.count(query, Message.class);
+
+	}
 }