|
|
@ -1,22 +1,29 @@ |
|
|
|
package com.ccsens.logistics.service; |
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ccsens.logistics.Util.Constant; |
|
|
|
import com.ccsens.logistics.bean.dto.ThermalImageryDto; |
|
|
|
import com.ccsens.logistics.bean.po.LogisticsEnvironmentRecord; |
|
|
|
import com.ccsens.logistics.bean.po.LogisticsEquipment; |
|
|
|
import com.ccsens.logistics.bean.po.LogisticsEquipmentExample; |
|
|
|
import com.ccsens.logistics.bean.po.LogisticsHeatImagingRecord; |
|
|
|
import com.ccsens.logistics.persist.mapper.LogisticsEnvironmentRecordMapper; |
|
|
|
import com.ccsens.logistics.persist.mapper.LogisticsEquipmentMapper; |
|
|
|
import com.ccsens.logistics.persist.mapper.LogisticsHeatImagingRecordMapper; |
|
|
|
import com.ccsens.util.Base64FileUtil; |
|
|
|
import com.ccsens.util.PropUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.File; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
@ -35,6 +42,8 @@ public class ThermalImageryService implements IThermalImageryService { |
|
|
|
private LogisticsHeatImagingRecordMapper heatImagingRecordMapper; |
|
|
|
@Resource |
|
|
|
private Snowflake snowflake; |
|
|
|
@Resource |
|
|
|
private LogisticsEnvironmentRecordMapper environmentRecordMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<String> getImagery() { |
|
|
@ -61,29 +70,49 @@ public class ThermalImageryService implements IThermalImageryService { |
|
|
|
public void disposeMessage(String value) { |
|
|
|
//解析字符串
|
|
|
|
try { |
|
|
|
//将接收到的信息转换成对象
|
|
|
|
ThermalImageryDto.RequestThermalImagery thermalImagery = JSONObject.parseObject(value, ThermalImageryDto.RequestThermalImagery.class); |
|
|
|
|
|
|
|
//根据编号获取设备id
|
|
|
|
LogisticsEquipment equipment; |
|
|
|
LogisticsEquipmentExample equipmentExample = new LogisticsEquipmentExample(); |
|
|
|
equipmentExample.createCriteria().andEquipmentNumberEqualTo(thermalImagery.getThing_id()); |
|
|
|
List<LogisticsEquipment> logisticsEquipments = logisticsEquipmentMapper.selectByExample(equipmentExample); |
|
|
|
if (CollectionUtil.isEmpty(logisticsEquipments)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
equipment = logisticsEquipments.get(0); |
|
|
|
switch (thermalImagery.getType()) { |
|
|
|
case Constant.HEARTBEAT: |
|
|
|
//TODO 心跳不处理
|
|
|
|
if (StrUtil.isNotEmpty(thermalImagery.getData())) { |
|
|
|
ThermalImageryDto.Heartbeat date = JSONObject.parseObject(thermalImagery.getData(), ThermalImageryDto.Heartbeat.class); |
|
|
|
//将心跳报警信息存储至设备记录表
|
|
|
|
LogisticsEnvironmentRecord environmentRecord = new LogisticsEnvironmentRecord(); |
|
|
|
environmentRecord.setId(snowflake.nextId()); |
|
|
|
environmentRecord.setNumType((byte) 3); |
|
|
|
environmentRecord.setNumValue(new BigDecimal(date.getMaxt())); |
|
|
|
environmentRecord.setEquipmentId(equipment.getId()); |
|
|
|
environmentRecord.setRecordTime(System.currentTimeMillis()); |
|
|
|
environmentRecord.setIsAlarm((byte) ("True".equalsIgnoreCase(date.getAlarm())?1:0)); |
|
|
|
environmentRecordMapper.insertSelective(environmentRecord); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
case Constant.THERMAL_IMAGERY: |
|
|
|
LogisticsEquipmentExample equipmentExample = new LogisticsEquipmentExample(); |
|
|
|
equipmentExample.createCriteria().andEquipmentNumberEqualTo(thermalImagery.getThing_id()); |
|
|
|
List<LogisticsEquipment> logisticsEquipments = logisticsEquipmentMapper.selectByExample(equipmentExample); |
|
|
|
if (CollectionUtil.isNotEmpty(logisticsEquipments)) { |
|
|
|
LogisticsEquipment equipment = logisticsEquipments.get(0); |
|
|
|
if (StrUtil.isNotEmpty(thermalImagery.getData())) { |
|
|
|
ThermalImageryDto.GetThermalImageryDate date = JSONObject.parseObject(thermalImagery.getData(), ThermalImageryDto.GetThermalImageryDate.class); |
|
|
|
LogisticsHeatImagingRecord heatImagingRecord = new LogisticsHeatImagingRecord(); |
|
|
|
heatImagingRecord.setId(snowflake.nextId()); |
|
|
|
heatImagingRecord.setMaxT(new BigDecimal(date.getMaxT())); |
|
|
|
heatImagingRecord.setMaxTx(date.getMaxTx()); |
|
|
|
heatImagingRecord.setMaxTy(date.getMaxTy()); |
|
|
|
heatImagingRecord.setImageData("data:image/png;base64," + date.getImageData()); |
|
|
|
heatImagingRecord.setRecordTime(System.currentTimeMillis()); |
|
|
|
heatImagingRecord.setEquipmentId(equipment.getId()); |
|
|
|
heatImagingRecordMapper.insertSelective(heatImagingRecord); |
|
|
|
} |
|
|
|
if (StrUtil.isNotEmpty(thermalImagery.getData())) { |
|
|
|
ThermalImageryDto.GetThermalImageryDate date = JSONObject.parseObject(thermalImagery.getData(), ThermalImageryDto.GetThermalImageryDate.class); |
|
|
|
LogisticsHeatImagingRecord heatImagingRecord = new LogisticsHeatImagingRecord(); |
|
|
|
heatImagingRecord.setId(snowflake.nextId()); |
|
|
|
heatImagingRecord.setMaxT(new BigDecimal(date.getMaxT())); |
|
|
|
heatImagingRecord.setMaxTx(date.getMaxTx()); |
|
|
|
heatImagingRecord.setMaxTy(date.getMaxTy()); |
|
|
|
//处理图片
|
|
|
|
String path = Base64FileUtil.base64ToFile("data:image/png;base64," + date.getImageData(), PropUtil.path, "/file/" + DateUtil.today() + "/"); |
|
|
|
heatImagingRecord.setImageData(PropUtil.imgDomain + path); |
|
|
|
|
|
|
|
heatImagingRecord.setRecordTime(System.currentTimeMillis()); |
|
|
|
heatImagingRecord.setEquipmentId(equipment.getId()); |
|
|
|
heatImagingRecordMapper.insertSelective(heatImagingRecord); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|