| | |
| | | package org.springblade.jfpt.nettyUdpServer.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springblade.jfpt.nettyTcpServer.ParseString; |
| | | import org.springblade.jfpt.nettyUdpServer.entity.BladeAnimalHeat; |
| | | import org.springblade.jfpt.nettyUdpServer.mapper.AnimalHeatMapper; |
| | | import org.springblade.jfpt.nettyUdpServer.service.AnimalHeatService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.lang.reflect.Array; |
| | | import java.util.Map; |
| | | import static org.springblade.core.tool.utils.DateUtil.now; |
| | | |
| | | /** |
| | | * 体温数据服务层 |
| | | * |
| | | */ |
| | | @Service |
| | | public class AnimalHeatServiceImpl extends ServiceImpl<AnimalHeatMapper, BladeAnimalHeat> implements AnimalHeatService { |
| | | @Override |
| | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 新增体温数据 |
| | | * @param body 体温数据 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void save(String body) { |
| | | //1.截取信息 |
| | | int i = body.indexOf("{"); |
| | | //2.从 { 处开始截取 |
| | | int length = body.length(); |
| | | //3.截取 |
| | | String dataBody = body.substring(i, length); |
| | | System.out.println("dataBody = " + dataBody); |
| | | //4.数据转换 |
| | | Map<String,Object> data = (Map<String, Object>) JSONObject.parse(dataBody); |
| | | System.out.println("data = " + data); |
| | | //5.创建体温数据对象 |
| | | BladeAnimalHeat bladeAnimalHeat = new BladeAnimalHeat(); |
| | | //6.取出数据,封装数据到对象 |
| | | bladeAnimalHeat.setPicture(data.get("picture").toString()); |
| | | String temp_red =data.get("temp_red").toString(); |
| | | bladeAnimalHeat.setTempRed(Float.parseFloat(temp_red.substring(1,temp_red.length()-1))); |
| | | String person_rects = data.get("person_rect").toString(); |
| | | bladeAnimalHeat.setPersonRect(person_rects.substring(2,person_rects.length()-2).split(",")); |
| | | bladeAnimalHeat.setCreateTime(now()); |
| | | //7.插入数据 |
| | | int idata = baseMapper.insert(bladeAnimalHeat); |
| | | } |
| | | } |