shjung пре 3 година
родитељ
комит
d2e31f8841

+ 20 - 0
src/main/java/com/its/op/dto/its/dashboard/CmtrGradCountSttsDto.java

@@ -37,4 +37,24 @@ public class CmtrGradCountSttsDto implements Serializable {
     @JsonProperty("ltc0")
     private Integer ltc0;
 
+    @ApiModelProperty("전체갯수")
+    @JsonProperty("total")
+    private Integer total;
+
+    @ApiModelProperty("원활비율")
+    @JsonProperty("rate_ltc1")
+    private Double rateLtc1;
+
+    @ApiModelProperty("지체비율")
+    @JsonProperty("rate_ltc2")
+    private Double rateLtc2;
+
+    @ApiModelProperty("정체비율")
+    @JsonProperty("rate_ltc3")
+    private Double rateLtc3;
+
+    @ApiModelProperty("정보없음비율")
+    @JsonProperty("rate_ltc0")
+    private Double rateLtc0;
+
 }

+ 51 - 3
src/main/java/com/its/op/service/its/dashboard/DashboardService.java

@@ -15,12 +15,56 @@ public class DashboardService {
 
     private final DashboardMapper repo;
 
+    protected void checkGradeRate(List<CmtrGradCountSttsDto> result) {
+        result.forEach(obj -> {
+            float total = obj.getLtc0() + obj.getLtc1() + obj.getLtc2() + obj.getLtc3();
+            obj.setTotal((int)total);
+            if (total == 0.0) {
+                obj.setRateLtc1(0.0);
+                obj.setRateLtc2(0.0);
+                obj.setRateLtc3(0.0);
+                obj.setRateLtc0(0.0);
+            }
+            else {
+                double ltc0 = Double.parseDouble(String.format("%.1f", obj.getLtc0() / total * 100.0));
+                double ltc1 = Double.parseDouble(String.format("%.1f", obj.getLtc1() / total * 100.0));
+                double ltc2 = Double.parseDouble(String.format("%.1f", obj.getLtc2() / total * 100.0));
+                double ltc3 = Double.parseDouble(String.format("%.1f", obj.getLtc3() / total * 100.0));
+
+                double fSum = ltc0 + ltc1 + ltc2 + ltc3;
+                double[] rates = { ltc0, ltc1, ltc2, ltc3 };
+                if (fSum > 100.0) {
+                    for (int ii = 0; ii < 4; ii++) {
+                        if (rates[ii] > 0.0) {
+                            rates[ii] -= (fSum - 100.0);
+                            break;
+                        }
+                    }
+                }
+                if (fSum < 100.0) {
+                    for (int ii = 0; ii < 4; ii++) {
+                        if (rates[ii] > 0.0) {
+                            rates[ii] += (100.0 - fSum);
+                            break;
+                        }
+                    }
+                }
+                obj.setRateLtc0(rates[0]);
+                obj.setRateLtc1(rates[1]);
+                obj.setRateLtc2(rates[2]);
+                obj.setRateLtc3(rates[3]);
+            }
+        });
+    }
+
     /**
      * 소틍등급상태 링크
      * @return
      */
     public List<CmtrGradCountSttsDto> findAllCmtrGradCountSttsLink() {
-        return this.repo.findAllCmtrGradCountSttsLink();
+        List<CmtrGradCountSttsDto> result = this.repo.findAllCmtrGradCountSttsLink();
+        checkGradeRate(result);
+        return result;
     }
 
     /**
@@ -28,7 +72,9 @@ public class DashboardService {
      * @return
      */
     public List<CmtrGradCountSttsDto> findAllCmtrGradCountSttsIfsc() {
-        return this.repo.findAllCmtrGradCountSttsIfsc();
+        List<CmtrGradCountSttsDto> result = this.repo.findAllCmtrGradCountSttsIfsc();
+        checkGradeRate(result);
+        return result;
     }
 
     /**
@@ -36,6 +82,8 @@ public class DashboardService {
      * @return
      */
     public List<CmtrGradCountSttsDto> findAllCmtrGradCountSttsRoad() {
-        return this.repo.findAllCmtrGradCountSttsRoad();
+        List<CmtrGradCountSttsDto> result = this.repo.findAllCmtrGradCountSttsRoad();
+        checkGradeRate(result);
+        return result;
     }
 }

+ 6 - 6
src/main/java/com/its/op/xnettcp/client/NettyTcpClientVds.java

@@ -58,7 +58,7 @@ public class NettyTcpClientVds implements Callable<Object> {
     }
 
     public void connect() {
-        log.error("NettyTcpClientVds try connect: {}, {}", this.ipAddress, this.port);
+        log.info("VDS Server try connect: {}, {}", this.ipAddress, this.port);
         if (this.channelFuture != null && this.channelFuture.channel() != null) {
             this.channelFuture.channel().close();
             this.channelFuture = null;
@@ -69,10 +69,10 @@ public class NettyTcpClientVds implements Callable<Object> {
             @Override
             public void operationComplete(ChannelFuture future) throws Exception {
                 if (future.isSuccess()) {
-                    log.error("Channel open");
+                    log.info("VDS Server Channel open");
                     channelOpen(future.channel());
                 } else {
-                    log.error("Could not connect to server, {}", future.cause().toString());
+                    log.error("Could not connect to VDS Server, {}", future.cause().toString());
                 }
             }
         });
@@ -80,7 +80,7 @@ public class NettyTcpClientVds implements Callable<Object> {
             // 종료에 대한 리스너 추가
             @Override
             public void operationComplete(ChannelFuture future) throws Exception {
-                log.error("operationComplete: channelClosed, {}", future.toString());
+                //log.warn("operationComplete: channelClosed, {}", future.toString());
                 channelClosed(future.channel());
             }
         });
@@ -91,11 +91,11 @@ public class NettyTcpClientVds implements Callable<Object> {
     }
 
     protected void channelOpen(Channel channel) {
-        log.error("channelOpen: channel {}, channelFuture.channel {}", channel, this.channelFuture.channel());
+        log.info("VDS Server channelOpen: channel {}, channelFuture.channel {}", channel, this.channelFuture.channel());
     }
 
     protected synchronized void channelClosed(Channel channel) {
-        log.error("channelClosed: channel {}, channelFuture.channel {}", channel, this.channelFuture.channel());
+        log.error("VDS Server channelClosed: channel {}, channelFuture.channel {}", channel, this.channelFuture.channel());
         this.channelFuture.channel().close();
         this.channelFuture.channel().eventLoop().schedule(this, this.getReconnectTime(), TimeUnit.SECONDS);
     }

+ 1 - 1
src/main/java/com/its/op/xnettcp/client/NettyTcpClientVdsBootstrapFactory.java

@@ -49,7 +49,7 @@ public class NettyTcpClientVdsBootstrapFactory {
             // 핸들러가 실행되는 순서는 추가된 순서에 의해 결정된다.(Inbound: head=>tail, Outbound: tail=>head, name2ctx)
             @Override
             public void initChannel(SocketChannel ch) throws Exception {
-                ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
+                ch.pipeline().addLast(new LoggingHandler(LogLevel.WARN));
                 ch.pipeline().addLast("vdsClientIdleHandler",    new NettyTcpClientIdleHandler(0, 0, 0, TimeUnit.SECONDS));
                 ch.pipeline().addLast("vdsClientDecoder",        new NettyTcpClientDecoder());            // Decoding handler
                 ch.pipeline().addLast("vdsClientInboundHandler", new NettyTcpClientInboundHandler());     // Packet Inbound handler

+ 3 - 3
src/main/java/com/its/op/xnettcp/client/handler/NettyTcpClientIdleHandler.java

@@ -18,21 +18,21 @@ public class NettyTcpClientIdleHandler extends IdleStateHandler {
     @Override
     protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception {
         String ipAddress = NettyUtils.getRemoteIpAddress(ctx.channel());
-        log.error("channelIdle: {}", ipAddress);
+        log.warn("channelIdle: {}", ipAddress);
         // disconnect here
     }
 
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
         String ipAddress = NettyUtils.getRemoteIpAddress(ctx.channel());
-        log.error("channelActive: {}", ipAddress);
+        log.info("channelActive: {}", ipAddress);
         super.channelActive(ctx);
     }
 
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         String ipAddress = NettyUtils.getRemoteIpAddress(ctx.channel());
-        log.error("channelInactive: {}", ipAddress);
+        log.warn("channelInactive: {}", ipAddress);
         super.channelInactive(ctx);
     }
 

+ 1 - 1
src/main/java/com/its/op/xnettcp/client/handler/NettyTcpClientInboundHandler.java

@@ -9,7 +9,7 @@ public class NettyTcpClientInboundHandler extends SimpleChannelInboundHandler<Ob
 
     @Override
     protected void channelRead0(ChannelHandlerContext channelHandlerContext, Object msg) throws Exception {
-        log.error("channelRead0: {}", msg);
+        log.info("channelRead0: {}", msg);
     }
 
 }

+ 1 - 1
src/main/java/com/its/op/xnettcp/client/listener/NettyTcpClientCloseListener.java

@@ -21,7 +21,7 @@ public class NettyTcpClientCloseListener implements ChannelFutureListener {
      */
     @Override
     public void operationComplete(ChannelFuture channelFuture) throws Exception {
-        log.error("NettyTcpClientCloseListener: {}", channelFuture.channel().toString());
+        log.warn("NettyTcpClientCloseListener: {}", channelFuture.channel().toString());
         // 채널이 종료되었으므로 재 연결 스케쥴을 등록한다.
         channelFuture.channel().close();
         channelFuture.channel().eventLoop().schedule(this.client, this.client.getReconnectTime(), TimeUnit.SECONDS);

+ 2 - 2
src/main/java/com/its/op/xnettcp/client/listener/NettyTcpClientConnectListener.java

@@ -22,11 +22,11 @@ public class NettyTcpClientConnectListener implements ChannelFutureListener {
         if (!channelFuture.isSuccess()) {
             // 연결이 안되었으므로 채널을 close 한다.
             // channel 을 close 하면 NettyTcpClientCloseListener 의 이벤트가 발생한다.
-            log.error("NettyTcpClientConnectListener:  !SUCCESS, {}, cause,{}", channelFuture.channel().toString(), channelFuture.cause().toString());
+            log.warn("NettyTcpClientConnectListener:  !SUCCESS, {}, cause,{}", channelFuture.channel().toString(), channelFuture.cause().toString());
             channelFuture.channel().close();
             //channelFuture.channel().eventLoop().schedule(this.client, this.client.getReconnectTime(), TimeUnit.SECONDS);
         } else {
-            log.error("NettyTcpClientConnectListener: SUCCESS, {}", channelFuture.channel().toString());
+            log.info("NettyTcpClientConnectListener: SUCCESS, {}", channelFuture.channel().toString());
         }
 /*
         if (channelFuture.isCancelled()) {

+ 9 - 6
src/main/resources/mybatis/mapper/its/dashboard/DashboardMapper.xml

@@ -9,9 +9,10 @@
                sum(decode(cmtr_grad_cd,'LTC1', 1, 0)) as ltc1,
                sum(decode(cmtr_grad_cd,'LTC2', 1, 0)) as ltc2,
                sum(decode(cmtr_grad_cd,'LTC3', 1, 0)) as ltc3,
-               sum(decode(cmtr_grad_cd,'LTC0', 1, 0)) as ltc0
+               sum(decode(cmtr_grad_cd,'LTC0', 1, 0)) as ltc0,
+               0 as total, 0 as rate_ltc1, 0 as rate_ltc2, 0 as rate_ltc3, 0 as rate_ltc0
         from tb_link_traf_hs
-        where prcn_dt >= to_char(sysdate-1/24, 'YYYYMMDD HH24:MI:SS')
+        where prcn_dt >= to_char(sysdate-1/24, 'YYYYMMDDHH24MISS')
         group by prcn_dt, cmtr_grad_cd
         order by prcn_dt
         ]]>
@@ -23,9 +24,10 @@
                sum(decode(cmtr_grad_cd,'LTC1', 1, 0)) as ltc1,
                sum(decode(cmtr_grad_cd,'LTC2', 1, 0)) as ltc2,
                sum(decode(cmtr_grad_cd,'LTC3', 1, 0)) as ltc3,
-               sum(decode(cmtr_grad_cd,'LTC0', 1, 0)) as ltc0
+               sum(decode(cmtr_grad_cd,'LTC0', 1, 0)) as ltc0,
+               0 as total, 0 as rate_ltc1, 0 as rate_ltc2, 0 as rate_ltc3, 0 as rate_ltc0
         from tb_ifsc_traf_hs
-        where prcn_dt >= to_char(sysdate-1/24, 'YYYYMMDD HH24:MI:SS')
+        where prcn_dt >= to_char(sysdate-1/24, 'YYYYMMDDHH24MISS')
         group by prcn_dt, cmtr_grad_cd
         order by prcn_dt
         ]]>
@@ -37,9 +39,10 @@
                sum(decode(cmtr_grad_cd,'LTC1', 1, 0)) as ltc1,
                sum(decode(cmtr_grad_cd,'LTC2', 1, 0)) as ltc2,
                sum(decode(cmtr_grad_cd,'LTC3', 1, 0)) as ltc3,
-               sum(decode(cmtr_grad_cd,'LTC0', 1, 0)) as ltc0
+               sum(decode(cmtr_grad_cd,'LTC0', 1, 0)) as ltc0,
+               0 as total, 0 as rate_ltc1, 0 as rate_ltc2, 0 as rate_ltc3, 0 as rate_ltc0
         from tb_road_traf_hs
-        where prcn_dt >= to_char(sysdate-1/24, 'YYYYMMDD HH24:MI:SS')
+        where prcn_dt >= to_char(sysdate-1/24, 'YYYYMMDDHH24MISS')
         group by prcn_dt, cmtr_grad_cd
         order by prcn_dt
         ]]>