新增体温数据接口分页,本周每天数据统计接口,数据插入修改
| | |
| | | |
| | | import org.springblade.core.cloud.feign.EnableBladeFeign; |
| | | import org.springblade.core.launch.BladeApplication; |
| | | import org.springblade.jfpt.nettyServer.Server; |
| | | import org.springblade.jfpt.nettyTcpServer.TcpServer; |
| | | import org.springframework.boot.CommandLineRunner; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | |
| | | @Override |
| | | public void run(String... args) throws Exception { |
| | | //Server server=new Server(8088); |
| | | TcpServer server=new TcpServer(8099); //测试用 |
| | | TcpServer tcpServer = new TcpServer(8088); |
| | | //UdpServer udpServer=new UdpServer(8099); |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @GetMapping("/getAnimalStatis") |
| | | public List<StatisVo> getAnimalStatis(AnimalHeatVo animalHeatVo){ |
| | | return animalHeatService.getAnimalStatis(animalHeatVo); |
| | | public R getAnimalStatis(AnimalHeatVo animalHeatVo){ |
| | | return R.data(animalHeatService.getAnimalStatis(animalHeatVo)); |
| | | } |
| | | |
| | | |
| | |
| | | return R.data(animalHeatService.selectAnimalHeatPage(Condition.getPage(query), animalHeatVo)); |
| | | } |
| | | |
| | | /** |
| | | * 查询本周每天的体温数据数量 |
| | | * @return |
| | | */ |
| | | @GetMapping("/selWeekDayAnimalStatis") |
| | | public R selWeekDayAnimalStatis(){ |
| | | return R.data(animalHeatService.selWeekDayAnimalStatis()); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | private Integer method;// int(1) NOT NULL COMMENT '方法名: 0 表示 infrared_aiom_picture 图片数据, 1 表示 engine_echo 心跳包 ', |
| | | |
| | | private String serialno;//varchar(20) 序列号 |
| | | |
| | | private String ip;// varchar(63) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '设备IP地址', |
| | | |
| | | private String picture;// varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '图片url路径', |
| | |
| | | import org.springblade.jfpt.animalheat.vo.StatisVo; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * mapper 映射层 |
| | |
| | | * 获取体温数据统计 --当天 |
| | | * @return |
| | | */ |
| | | List<StatisVo> getAnimalStatis(); |
| | | List<Map<String, Object>> getAnimalStatis(); |
| | | |
| | | /** |
| | | * 获取体温数据统计 --本周 |
| | | * @return |
| | | */ |
| | | List<StatisVo> getAnimalStatisWeek(); |
| | | List<Map<String, Object>> getAnimalStatisWeek(); |
| | | |
| | | /** |
| | | * 体温数据的分页数据 |
| | |
| | | * @return |
| | | */ |
| | | List<BladeAnimalHeat> selectAnimalHeatPageList(IPage<BladeAnimalHeat> page, AnimalHeatVo animalHeatVo); |
| | | |
| | | /** |
| | | * 查询本周每天的体温数据数量 |
| | | * @return |
| | | */ |
| | | List<Map<String, Integer>> selWeekDayAnimalStatis(); |
| | | } |
| | |
| | | <mapper namespace="org.springblade.jfpt.animalheat.mapper.AnimalHeatMapper"> |
| | | |
| | | <!--查询当天体温数据统计--> |
| | | <select id="getAnimalStatis" resultType="org.springblade.jfpt.animalheat.vo.StatisVo"> |
| | | <select id="getAnimalStatis" resultType="java.util.HashMap"> |
| | | SELECT 1 `status`,count(`status`) number FROM `blade_animal_heat` where |
| | | TO_DAYS(create_time)=TO_DAYS(now()) and `status`=1 |
| | | UNION |
| | |
| | | </select> |
| | | |
| | | <!--获取本周的体温统计数据--> |
| | | <select id="getAnimalStatisWeek" resultType="org.springblade.jfpt.animalheat.vo.StatisVo"> |
| | | <select id="getAnimalStatisWeek" resultType="java.util.HashMap"> |
| | | SELECT 1 `status`,count(`status`) number FROM `blade_animal_heat` where |
| | | YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now()) and `status`=1 |
| | | UNION |
| | |
| | | ORDER BY create_time asc |
| | | </select> |
| | | |
| | | <!--查询本周每天的体温数据(按礼拜一开始计算)--> |
| | | <select id="selWeekDayAnimalStatis" resultType="java.util.HashMap"> |
| | | select DATE_FORMAT(date(subdate(curdate(),date_format(curdate(),'%w')-1)),'%m-%d') time,ifNull(count(*),0) as number |
| | | from blade_animal_heat |
| | | where |
| | | date_format(create_time,'%Y-%m-%d')=date(subdate(curdate(),date_format(curdate(),'%w')-1)) |
| | | union all |
| | | select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 1 day)),'%m-%d') time,ifNull(count(*),0) as number |
| | | from blade_animal_heat |
| | | where |
| | | date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 1 day)) |
| | | union all |
| | | select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 2 day)),'%m-%d') time,ifNull(count(*),0) as number |
| | | from blade_animal_heat |
| | | where |
| | | date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 2 day)) |
| | | union all |
| | | select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 3 day)),'%m-%d') time,ifNull(count(*),0) as number |
| | | from blade_animal_heat |
| | | where |
| | | date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 3 day)) |
| | | union all |
| | | select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 4 day)),'%m-%d') time,ifNull(count(*),0) as number |
| | | from blade_animal_heat |
| | | where |
| | | date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 4 day)) |
| | | union all |
| | | select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 5 day)),'%m-%d') time,ifNull(count(*),0) as number |
| | | from blade_animal_heat |
| | | where |
| | | date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 5 day)) |
| | | union all |
| | | select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 6 day)),'%m-%d') time,ifNull(count(*),0) as number |
| | | from blade_animal_heat |
| | | where |
| | | date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 6 day)) |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | import org.springblade.jfpt.animalheat.vo.StatisVo; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 体温监测服务层接口层 |
| | |
| | | * @param animalHeatVo 条件参数 开始时间,结束时间 |
| | | * @return |
| | | */ |
| | | List<StatisVo> getAnimalStatis(AnimalHeatVo animalHeatVo); |
| | | List<Map<String, Object>> getAnimalStatis(AnimalHeatVo animalHeatVo); |
| | | |
| | | /** |
| | | * 体温数据的分页数据 |
| | |
| | | * @return |
| | | */ |
| | | IPage<BladeAnimalHeat> selectAnimalHeatPage(IPage<BladeAnimalHeat> page, AnimalHeatVo animalHeatVo); |
| | | |
| | | /** |
| | | * 查询本周每天的体温数据数量 |
| | | * @return |
| | | */ |
| | | List<Map<String,Integer>> selWeekDayAnimalStatis(); |
| | | } |
| | |
| | | @Value("${picture.addUrl}") |
| | | private String picAddUrl; |
| | | |
| | | @Value("${picture.pre}") |
| | | private String picPre; |
| | | |
| | | |
| | | /** |
| | | * 新增体温数据 |
| | |
| | | public void save(String body) { |
| | | //1.截取信息 |
| | | int i = body.indexOf("{"); |
| | | String host = body.substring(body.indexOf("192."), body.indexOf("Accept-Encoding")); |
| | | //2.从 { 处开始截取 |
| | | int length = body.length(); |
| | | //3.截取,由于获取数据时,} 被去除,需要加上 |
| | |
| | | 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.取出数据,封装数据到对象 |
| | | String method = data.get("method").toString(); |
| | | if (method.contains("infrared_aiom_picture")){ |
| | | bladeAnimalHeat.setMethod(0); |
| | | } |
| | | bladeAnimalHeat.setSerialno(data.get("serialno").toString()); |
| | | bladeAnimalHeat.setIp(host); |
| | | String picture = data.get("picture").toString(); |
| | | //将二进制原始图片转换成图片 |
| | | ImageUtil.base64StringToImage(picture); |
| | | //bladeAnimalHeat.setPicture(data.get("picture").toString()); //暂时不存入 |
| | | String imageUrl = ImageUtil.base64StringToImage(picture); |
| | | //存入图片地址url |
| | | bladeAnimalHeat.setPicture(picAddUrl+imageUrl); |
| | | String temp_red =data.get("temp_red").toString(); |
| | | String[] temRedArr = temp_red.substring(1,temp_red.length()-1).split(","); |
| | | if (temRedArr.length>1){ |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<StatisVo> getAnimalStatis(AnimalHeatVo animalHeatVo) { |
| | | public List<Map<String, Object>> getAnimalStatis(AnimalHeatVo animalHeatVo) { |
| | | if(null!= animalHeatVo.getStatus()){ |
| | | //查询当天的统计数据 |
| | | if (animalHeatVo.getStatus()==0){ |
| | |
| | | public IPage<BladeAnimalHeat> selectAnimalHeatPage(IPage<BladeAnimalHeat> page, AnimalHeatVo animalHeatVo) { |
| | | return page.setRecords(baseMapper.selectAnimalHeatPageList(page, animalHeatVo)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询本周每天的体温数据数量 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Map<String, Integer>> selWeekDayAnimalStatis() { |
| | | List<Map<String,Integer>> selWeekDayAnimalStatis; |
| | | return baseMapper.selWeekDayAnimalStatis(); |
| | | } |
| | | } |
| | |
| | | static BASE64Encoder encoder = new sun.misc.BASE64Encoder(); |
| | | static BASE64Decoder decoder = new sun.misc.BASE64Decoder(); |
| | | |
| | | @Value("${picture.addUrl}") |
| | | private String picAddUrl; |
| | | |
| | | @Value("${picture.pre}") |
| | | private static String picPre; |
| | | private static String PRE_URL = "software/minio/data/jfpt/animalHeat/"; |
| | | |
| | | /** |
| | | * 二进制原始数据转换为图片 |
| | |
| | | public static String base64StringToImage(String base64String){ |
| | | try { |
| | | byte[] bytes1 = decoder.decodeBuffer(base64String); |
| | | |
| | | ByteArrayInputStream bais = new ByteArrayInputStream(bytes1); |
| | | BufferedImage bi1 = ImageIO.read(bais); |
| | | String yyyyMMddHHmmss = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); |
| | | File w2 = new File("D://"+picPre+StringPool.SLASH+ DateUtil.today()+StringPool.SLASH+ StringUtil.randomUUID() |
| | | File w2 = new File("D://"+PRE_URL+StringPool.SLASH+ DateUtil.today()+StringPool.SLASH+ StringUtil.randomUUID() |
| | | +".jpg");//可以是jpg,png,gif格式 |
| | | |
| | | //判断父文件夹存在与否 |
| | | File parentFile = w2.getParentFile(); |
| | | System.out.println("parentFile = " + parentFile); |
| | | if (!parentFile.exists()){ |
| | | //如果不存在,则创建 |
| | | parentFile.mkdirs(); |
| | | } |
| | | ImageIO.write(bi1, "jpg", w2);//不管输出什么格式图片,此处不需改动 |
| | | //返回图片路径 |
| | | return picPre+ StringPool.SLASH+ DateUtil.today()+StringPool.SLASH+ StringUtil.randomUUID() |
| | | return PRE_URL+ StringPool.SLASH+ DateUtil.today()+StringPool.SLASH+ StringUtil.randomUUID() |
| | | +StringPool.DOT+ "jpg"; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | |
| | | import io.netty.channel.socket.SocketChannel; |
| | | import io.netty.channel.socket.nio.NioServerSocketChannel; |
| | | import io.netty.handler.codec.DelimiterBasedFrameDecoder; |
| | | import io.netty.util.ReferenceCountUtil; |
| | | |
| | | |
| | | public class TcpServer { |
| | |
| | | //优雅地退出,释放线程池资源 |
| | | boss.shutdownGracefully(); |
| | | worker.shutdownGracefully(); |
| | | |
| | | } |
| | | } |
| | | }); |
| | |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import io.netty.channel.ChannelInboundHandlerAdapter; |
| | | import io.netty.channel.SimpleChannelInboundHandler; |
| | | import io.netty.util.ReferenceCountUtil; |
| | | import org.springblade.jfpt.alarm.service.IAlarmService; |
| | | import org.springblade.jfpt.equipment.service.IEquipmentService; |
| | | import org.springblade.jfpt.nettyServer.NettyConfig; |
| | |
| | | public void channelActive(ChannelHandlerContext ctx) throws Exception { |
| | | System.out.println("CTX:"+ctx.channel()); |
| | | System.out.println("客户端与服务端连接开始..."); |
| | | // ChannelId id = ctx.channel().id(); |
| | | // String s = id.toString(); |
| | | //NettyConfig.group.add(ctx.channel()); |
| | | } |
| | | |
| | | /** |
| | |
| | | ByteBuf buf = (ByteBuf) info; |
| | | byte[] req = new byte[buf.readableBytes()]; |
| | | buf.readBytes(req); |
| | | //手动释放内存 |
| | | ReferenceCountUtil.release(info); |
| | | |
| | | String body = new String(req, "UTF-8"); |
| | | String content = body; |
| | | System.out.println("接收客户端数据:" + body); |
| | |
| | | picture.addUrl= http://36.134.81.48:9000/ |
| | | picture.pre= software/minio/data/animalHeat/ |
| | | picture.pre= software/minio/data/jfpt/animalHeat/ |