| | |
| | | package com.thhy; |
| | | |
| | | import com.thhy.materials.modules.biz.helmet.smoke.SmokeServer; |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.boot.CommandLineRunner; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.cloud.openfeign.EnableFeignClients; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @SpringBootApplication |
| | | @MapperScan(basePackages = {"com.thhy.materials.modules.*.*.mapper"}) |
| | | @EnableFeignClients |
| | | @EnableScheduling |
| | | public class MaterialsApplication { |
| | | public class MaterialsApplication implements CommandLineRunner { |
| | | |
| | | @Resource |
| | | private SmokeServer smokeServer; |
| | | |
| | | public static void main(String[] args) { |
| | | SpringApplication.run(MaterialsApplication.class,args); |
| | | } |
| | | |
| | | @Override |
| | | public void run(String... args) throws Exception { |
| | | smokeServer.run(8973); |
| | | } |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.thhy.materials.modules.biz.helmet.entity; |
| | | |
| | | import lombok.Data; |
| | | import lombok.Getter; |
| | | import lombok.Setter; |
| | | import lombok.ToString; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | @Data |
| | | @Getter |
| | | @Setter |
| | | @ToString |
| | | public class TDataSmock implements Serializable { |
| | | /** |
| | | * |
| | | */ |
| | | private Integer smokeId; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String gatewayCyc; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String fans; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String v1run; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String uv1run; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String fanrun; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String uv2run; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String ssvrun; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String dp; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String t; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String oc; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String gatew; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String nxrun; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String alarm; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String times; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String rtcVolt; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String v2run; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String dxqvrun; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String press; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String dc; |
| | | |
| | | /** |
| | | * This field was generated by MyBatis Generator. |
| | | * This field corresponds to the database table t_data_smock |
| | | * |
| | | * @mbg.generated Wed Oct 18 15:12:02 CST 2023 |
| | | */ |
| | | private static final long serialVersionUID = 1L; |
| | | } |
| | |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | List<ReportNumDto> helmetReportTotal(Map<String, Object> values); |
| | | |
| | | List<THelmetReport> helmetReportUser(Map<String, Object> values); |
| | | |
| | | void smockInsert(TDataSmock tDataSmock); |
| | | |
| | | } |
| | |
| | | import com.thhy.general.common.BasicResult; |
| | | import com.thhy.materials.modules.biz.helmet.entity.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | BasicResult helmetReportTotal(Map<String, Object> values); |
| | | |
| | | BasicResult helmetReportUser(Map<String, Object> values); |
| | | |
| | | void smockInsert(TDataSmock tDataSmock); |
| | | } |
| | |
| | | List<THelmetReport> helmetReports = helmetMapper.helmetReportUser(values); |
| | | return BasicResult.success(helmetReports); |
| | | } |
| | | |
| | | @Override |
| | | public void smockInsert(TDataSmock tDataSmock) { |
| | | System.out.println("参数为---"+tDataSmock.toString()); |
| | | helmetMapper.smockInsert(tDataSmock); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.thhy.materials.modules.biz.helmet.smoke; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.thhy.materials.modules.biz.helmet.entity.TDataSmock; |
| | | import com.thhy.materials.modules.biz.helmet.mapper.HelmetMapper; |
| | | import com.thhy.materials.modules.biz.helmet.service.HelmetService; |
| | | import com.thhy.materials.modules.biz.utils.ApplicationContextUtil; |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.buffer.Unpooled; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import io.netty.channel.SimpleChannelInboundHandler; |
| | | import io.netty.util.CharsetUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.ApplicationContextAware; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | public class SmokeMessage extends SimpleChannelInboundHandler<ByteBuf>{ |
| | | |
| | | @Autowired |
| | | public HelmetService helmetService; |
| | | |
| | | private static String[] alphabets = {"A", "B", "C", "D", "E", "F", "G", "H", "I", |
| | | "J", "K", "L", "M", "N", "O", "P"}; |
| | | |
| | | @Override |
| | | public void channelActive(ChannelHandlerContext ctx) { |
| | | for(int i=0; i<10; i++) { |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append("这是第"); |
| | | builder.append(i); |
| | | builder.append("条消息, 内容是:"); |
| | | for(int j=0; j<100; j++) { |
| | | builder.append(alphabets[i]); |
| | | } |
| | | builder.append("......"); |
| | | builder.append("#"); |
| | | |
| | | |
| | | System.out.println(builder.toString().getBytes().length); |
| | | |
| | | ctx.writeAndFlush(Unpooled.copiedBuffer(builder.toString(), |
| | | CharsetUtil.UTF_8)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) { |
| | | System.out.println("客户端接收到消息: " + in.toString(CharsetUtil.UTF_8)); |
| | | JSONObject jsonObject11 = JSONObject.parseObject(in.toString(CharsetUtil.UTF_8)); |
| | | System.out.println("客户端接收到消息: " + jsonObject11); |
| | | TDataSmock tDataSmock = new TDataSmock(); |
| | | tDataSmock.setGatewayCyc(jsonObject11.get("gateway_cyc").toString()); |
| | | tDataSmock.setFans(jsonObject11.get("FanS").toString()); |
| | | tDataSmock.setV1run(jsonObject11.get("V1Run").toString()); |
| | | tDataSmock.setUv1run(jsonObject11.get("UV1Run").toString()); |
| | | tDataSmock.setFanrun(jsonObject11.get("FanRun").toString()); |
| | | tDataSmock.setUv2run(jsonObject11.get("UV2Run").toString()); |
| | | tDataSmock.setSsvrun(jsonObject11.get("SSVRun").toString()); |
| | | tDataSmock.setDp(jsonObject11.get("DP").toString()); |
| | | tDataSmock.setT(jsonObject11.get("T").toString()); |
| | | tDataSmock.setOc(jsonObject11.get("OC").toString()); |
| | | tDataSmock.setGatew(jsonObject11.get("gatew").toString()); |
| | | tDataSmock.setNxrun(jsonObject11.get("NXRun").toString()); |
| | | tDataSmock.setTimes(jsonObject11.get("time").toString()); |
| | | tDataSmock.setRtcVolt(jsonObject11.get("RTC_VOLT").toString()); |
| | | tDataSmock.setV2run(jsonObject11.get("V2Run").toString()); |
| | | tDataSmock.setDxqvrun(jsonObject11.get("DXQVRun").toString()); |
| | | tDataSmock.setPress(jsonObject11.get("Press").toString()); |
| | | tDataSmock.setDc(jsonObject11.get("Dc").toString()); |
| | | System.out.println("-------"+tDataSmock); |
| | | getUserService().smockInsert(tDataSmock); |
| | | } |
| | | @Override |
| | | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { |
| | | cause.printStackTrace(); |
| | | ctx.close(); |
| | | } |
| | | |
| | | |
| | | public static HelmetService getUserService(){ |
| | | ApplicationContext ac = ApplicationContextUtil.getApplicationContext(); |
| | | HelmetService userService = (HelmetService) ac.getBean("helmetServiceImpl"); |
| | | return userService; |
| | | } |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.thhy.materials.modules.biz.helmet.smoke; |
| | | |
| | | import io.netty.bootstrap.ServerBootstrap; |
| | | import io.netty.channel.ChannelFuture; |
| | | import io.netty.channel.ChannelInitializer; |
| | | import io.netty.channel.EventLoopGroup; |
| | | import io.netty.channel.nio.NioEventLoopGroup; |
| | | import io.netty.channel.socket.SocketChannel; |
| | | import io.netty.channel.socket.nio.NioServerSocketChannel; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Component |
| | | public class SmokeServer { |
| | | |
| | | // public static void main(String[] args) throws Exception { |
| | | // int port = 8084; |
| | | // if (args != null && args.length > 0) { |
| | | // try { |
| | | // port = Integer.valueOf(args[0]); |
| | | // } catch (NumberFormatException e) { |
| | | // // 采用默认值 |
| | | // } |
| | | // } |
| | | // new Smoke().bind(port); |
| | | // } |
| | | |
| | | |
| | | public void run(int port) throws Exception { |
| | | new SmokeServer().bind(port); |
| | | System.out.println("服务器启动成功!"); |
| | | } |
| | | |
| | | |
| | | public void bind(int port) throws Exception { |
| | | // 第一步: |
| | | // 配置服务端的NIO线程组 |
| | | // 主线程组, 用于接受客户端的连接,但是不做任何具体业务处理,像老板一样,负责接待客户,不具体服务客户 |
| | | EventLoopGroup bossGroup = new NioEventLoopGroup(1); |
| | | // 工作线程组, 老板线程组会把任务丢给他,让手下线程组去做任务,服务客户 |
| | | EventLoopGroup workerGroup = new NioEventLoopGroup(); |
| | | try { |
| | | // 类ServerBootstrap用于配置Server相关参数,并启动Server |
| | | ServerBootstrap b = new ServerBootstrap(); |
| | | |
| | | // 链式调用 |
| | | // 配置parentGroup和childGroup |
| | | b.group(bossGroup, workerGroup) |
| | | // 配置Server通道 |
| | | .channel(NioServerSocketChannel.class) |
| | | // 配置通道的ChannelPipeline |
| | | .childHandler(new ChildChannelHandler()); |
| | | |
| | | // 绑定端口,并启动server,同时设置启动方式为同步 |
| | | ChannelFuture f = b.bind(port).sync(); |
| | | |
| | | System.out.println( |
| | | SmokeServer.class.getName() + " 启动成功,在地址[" + f.channel().localAddress() + "]上等待客户请求......"); |
| | | |
| | | // 等待服务端监听端口关闭 |
| | | f.channel().closeFuture().sync(); |
| | | } finally { |
| | | // 优雅退出,释放线程池资源 |
| | | bossGroup.shutdownGracefully(); |
| | | workerGroup.shutdownGracefully(); |
| | | } |
| | | } |
| | | |
| | | private class ChildChannelHandler extends ChannelInitializer<SocketChannel> { |
| | | @Override |
| | | protected void initChannel(SocketChannel ch) throws Exception { |
| | | ch.pipeline().addLast(new SmokeMessage()); |
| | | } |
| | | } |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.thhy.materials.modules.biz.utils; |
| | | |
| | | import org.springframework.beans.BeansException; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.ApplicationContextAware; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Component |
| | | public class ApplicationContextUtil implements ApplicationContextAware { |
| | | /** |
| | | * 上下文对象实例 |
| | | */ |
| | | private static ApplicationContext applicationContext; |
| | | |
| | | @Override |
| | | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
| | | ApplicationContextUtil.applicationContext = applicationContext; |
| | | } |
| | | |
| | | /** |
| | | * 获取applicationContext |
| | | * |
| | | * @return |
| | | */ |
| | | public static ApplicationContext getApplicationContext() { |
| | | return applicationContext; |
| | | } |
| | | |
| | | /** |
| | | * 通过name获取 Bean. |
| | | * |
| | | * @param name |
| | | * @return |
| | | */ |
| | | public static Object getBean(String name) { |
| | | return getApplicationContext().getBean(name); |
| | | } |
| | | |
| | | /** |
| | | * 通过class获取Bean. |
| | | * |
| | | * @param clazz |
| | | * @param <T> |
| | | * @return |
| | | */ |
| | | public static <T> T getBean(Class<T> clazz) { |
| | | return getApplicationContext().getBean(clazz); |
| | | } |
| | | |
| | | /** |
| | | * 通过name,以及Clazz返回指定的Bean |
| | | * |
| | | * @param name |
| | | * @param clazz |
| | | * @param <T> |
| | | * @return |
| | | */ |
| | | public static <T> T getBean(String name, Class<T> clazz) { |
| | | return getApplicationContext().getBean(name, clazz); |
| | | } |
| | | } |
| | |
| | | WHERE |
| | | user_id = #{userId} |
| | | <if test="strTime!=null and strTime!='' and endTime!=null and endTime!='' "> |
| | | and sm_time between #{strTime} and #{endTime} |
| | | and DATE(sm_time) between #{strTime} and #{endTime} |
| | | </if> |
| | | GROUP BY |
| | | DATE( sm_time ) |
| | |
| | | user_id=#{userId} |
| | | order by sm_time desc |
| | | </select> |
| | | |
| | | <insert id="smockInsert" > |
| | | insert into t_data_smock |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="smokeId != null"> |
| | | smoke_id, |
| | | </if> |
| | | <if test="gatewayCyc != null"> |
| | | gateway_cyc, |
| | | </if> |
| | | <if test="fans != null"> |
| | | FanS, |
| | | </if> |
| | | <if test="v1run != null"> |
| | | V1Run, |
| | | </if> |
| | | <if test="uv1run != null"> |
| | | UV1Run, |
| | | </if> |
| | | <if test="fanrun != null"> |
| | | FanRun, |
| | | </if> |
| | | <if test="uv2run != null"> |
| | | UV2Run, |
| | | </if> |
| | | <if test="ssvrun != null"> |
| | | SSVRun, |
| | | </if> |
| | | <if test="dp != null"> |
| | | DP, |
| | | </if> |
| | | <if test="t != null"> |
| | | T, |
| | | </if> |
| | | <if test="oc != null"> |
| | | OC, |
| | | </if> |
| | | <if test="gatew != null"> |
| | | gatew, |
| | | </if> |
| | | <if test="nxrun != null"> |
| | | NXRun, |
| | | </if> |
| | | <if test="alarm != null"> |
| | | Alarm, |
| | | </if> |
| | | <if test="times != null"> |
| | | times, |
| | | </if> |
| | | <if test="rtcVolt != null"> |
| | | RTC_VOLT, |
| | | </if> |
| | | <if test="v2run != null"> |
| | | V2Run, |
| | | </if> |
| | | <if test="dxqvrun != null"> |
| | | DXQVRun, |
| | | </if> |
| | | <if test="press != null"> |
| | | Press, |
| | | </if> |
| | | <if test="dc != null"> |
| | | Dc, |
| | | </if> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="smokeId != null"> |
| | | #{smokeId,jdbcType=INTEGER}, |
| | | </if> |
| | | <if test="gatewayCyc != null"> |
| | | #{gatewayCyc,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="fans != null"> |
| | | #{fans,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="v1run != null"> |
| | | #{v1run,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="uv1run != null"> |
| | | #{uv1run,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="fanrun != null"> |
| | | #{fanrun,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="uv2run != null"> |
| | | #{uv2run,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="ssvrun != null"> |
| | | #{ssvrun,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="dp != null"> |
| | | #{dp,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="t != null"> |
| | | #{t,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="oc != null"> |
| | | #{oc,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="gatew != null"> |
| | | #{gatew,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="nxrun != null"> |
| | | #{nxrun,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="alarm != null"> |
| | | #{alarm,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="times != null"> |
| | | #{times,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="rtcVolt != null"> |
| | | #{rtcVolt,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="v2run != null"> |
| | | #{v2run,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="dxqvrun != null"> |
| | | #{dxqvrun,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="press != null"> |
| | | #{press,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="dc != null"> |
| | | #{dc,jdbcType=VARCHAR}, |
| | | </if> |
| | | </trim> |
| | | </insert> |
| | | |
| | | </mapper> |