|
@@ -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.dto.mongo.SaveTcpMessageDTO;
|
|
import com.pig4cloud.pig.marketing.api.entity.mongo.Device;
|
|
import com.pig4cloud.pig.marketing.api.entity.mongo.Device;
|
|
import com.pig4cloud.pig.marketing.api.entity.mongo.Message;
|
|
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.repository.MessageRepository;
|
|
import com.pig4cloud.pig.marketing.service.TcpDataService;
|
|
import com.pig4cloud.pig.marketing.service.TcpDataService;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
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.PageRequest;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
@@ -23,6 +26,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
@@ -60,6 +64,7 @@ public class TcpDataServiceImpl implements TcpDataService {
|
|
Device device = new Device();
|
|
Device device = new Device();
|
|
device.setClientID(reqDto.getClientID());
|
|
device.setClientID(reqDto.getClientID());
|
|
device.setDeviceInfo(reqDto.getDeviceInfo());
|
|
device.setDeviceInfo(reqDto.getDeviceInfo());
|
|
|
|
+ device.setHeadInfo(reqDto.getHeadInfo());
|
|
// 设置创建时间和更新时间为当前时间的字符串格式
|
|
// 设置创建时间和更新时间为当前时间的字符串格式
|
|
String currentTime = LocalDateTime.now().format(DATE_TIME_FORMATTER);
|
|
String currentTime = LocalDateTime.now().format(DATE_TIME_FORMATTER);
|
|
device.setCreateTime(currentTime);
|
|
device.setCreateTime(currentTime);
|
|
@@ -68,11 +73,16 @@ public class TcpDataServiceImpl implements TcpDataService {
|
|
return insert.getId();
|
|
return insert.getId();
|
|
} else {
|
|
} 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 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));
|
|
update.set("updateTime", LocalDateTime.now().format(DATE_TIME_FORMATTER));
|
|
|
|
|
|
@@ -102,7 +112,7 @@ public class TcpDataServiceImpl implements TcpDataService {
|
|
* @return 设备信息列表
|
|
* @return 设备信息列表
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public Page<Device> pageDeviceInfo(PageDeviceInfoDTO reqDto) {
|
|
|
|
|
|
+ public Page<PageDeviceInfoVO> pageDeviceInfo(PageDeviceInfoDTO reqDto) {
|
|
// 创建查询条件
|
|
// 创建查询条件
|
|
Criteria criteria = new Criteria();
|
|
Criteria criteria = new Criteria();
|
|
|
|
|
|
@@ -150,9 +160,21 @@ public class TcpDataServiceImpl implements TcpDataService {
|
|
// 执行查询
|
|
// 执行查询
|
|
List<Device> devices = mongoTemplate.find(query, Device.class);
|
|
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;
|
|
return page;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -243,4 +265,20 @@ public class TcpDataServiceImpl implements TcpDataService {
|
|
page.setRecords(messages);
|
|
page.setRecords(messages);
|
|
return page;
|
|
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);
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|