作者 xudada

北货更新+多线程

@@ -19,6 +19,7 @@ STYP=CARM @@ -19,6 +19,7 @@ STYP=CARM
19 grossWt=5% 19 grossWt=5%
20 station=4600329012 20 station=4600329012
21 stationsf=4600541001 21 stationsf=4600541001
  22 +stationb=4604600000
22 23
23 #\u4E8C\u7EF4\u7801\u5B58\u653E\u8DEF\u5F84\uFF0C\u9879\u76EE\u542F\u52A8\u65F6\u8BBE\u7F6E\uFF0C\u540E\u671F\u4E0D\u80FD\u66F4\u6539\u3002 24 #\u4E8C\u7EF4\u7801\u5B58\u653E\u8DEF\u5F84\uFF0C\u9879\u76EE\u542F\u52A8\u65F6\u8BBE\u7F6E\uFF0C\u540E\u671F\u4E0D\u80FD\u66F4\u6539\u3002
24 #barCode = barcode/ 25 #barCode = barcode/
@@ -5,10 +5,18 @@ import org.mybatis.spring.annotation.MapperScan; @@ -5,10 +5,18 @@ import org.mybatis.spring.annotation.MapperScan;
5 import org.springframework.boot.SpringApplication; 5 import org.springframework.boot.SpringApplication;
6 import org.springframework.boot.autoconfigure.SpringBootApplication; 6 import org.springframework.boot.autoconfigure.SpringBootApplication;
7 import org.springframework.cloud.openfeign.EnableFeignClients; 7 import org.springframework.cloud.openfeign.EnableFeignClients;
  8 +import org.springframework.context.annotation.Bean;
  9 +import org.springframework.core.task.SimpleAsyncTaskExecutor;
  10 +import org.springframework.scheduling.annotation.EnableAsync;
8 import org.springframework.scheduling.annotation.EnableScheduling; 11 import org.springframework.scheduling.annotation.EnableScheduling;
  12 +import org.springframework.scheduling.config.ScheduledTaskRegistrar;
  13 +
  14 +import java.util.concurrent.Executors;
  15 +
9 @EnableFeignClients 16 @EnableFeignClients
10 @SpringBootApplication 17 @SpringBootApplication
11 @EnableScheduling 18 @EnableScheduling
  19 +@EnableAsync
12 //不连接数据库开启服务 20 //不连接数据库开启服务
13 //@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) 21 //@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
14 //@EnableEurekaClient 22 //@EnableEurekaClient
@@ -62,4 +70,5 @@ public class AnalysisImfApplication { @@ -62,4 +70,5 @@ public class AnalysisImfApplication {
62 70
63 AnalysisRoute.analysis(message);*/ 71 AnalysisRoute.analysis(message);*/
64 } 72 }
  73 +
65 } 74 }
@@ -2,9 +2,12 @@ package com.sy.IMF; @@ -2,9 +2,12 @@ package com.sy.IMF;
2 2
3 import com.caac.imf.api.IMFClient; 3 import com.caac.imf.api.IMFClient;
4 import com.sy.bwAnalysis.AnalysisRoute; 4 import com.sy.bwAnalysis.AnalysisRoute;
  5 +import com.sy.utils.XMLThreadPoolFactory;
5 import org.apache.commons.lang.StringUtils; 6 import org.apache.commons.lang.StringUtils;
6 import org.apache.log4j.Logger; 7 import org.apache.log4j.Logger;
7 8
  9 +import java.util.concurrent.ThreadPoolExecutor;
  10 +
8 public class KAKO_Reader extends Thread{ 11 public class KAKO_Reader extends Thread{
9 protected static final Logger logger = Logger.getLogger(KAKO_Reader.class); 12 protected static final Logger logger = Logger.getLogger(KAKO_Reader.class);
10 private IMFClient client; 13 private IMFClient client;
@@ -22,13 +25,18 @@ public class KAKO_Reader extends Thread{ @@ -22,13 +25,18 @@ public class KAKO_Reader extends Thread{
22 logger.info("********读取线程状态true**********"); 25 logger.info("********读取线程状态true**********");
23 logger.info("********Client-INFO= "+client+"********"); 26 logger.info("********Client-INFO= "+client+"********");
24 Thread t =Thread.currentThread(); 27 Thread t =Thread.currentThread();
  28 + ThreadPoolExecutor threadPoolEs = XMLThreadPoolFactory.instance("kakou");
25 while(true) { 29 while(true) {
26 if (IMF_Tesk.LOGIN_OK){ 30 if (IMF_Tesk.LOGIN_OK){
27 String message = this.client.getMSG(); 31 String message = this.client.getMSG();
28 logger.info(t.toString()+"读取线程已获取到消息"); 32 logger.info(t.toString()+"读取线程已获取到消息");
29 if (message != null && StringUtils.isNotEmpty(message)) { 33 if (message != null && StringUtils.isNotEmpty(message)) {
30 // logger.info(message); 34 // logger.info(message);
31 - AnalysisRoute.analysis(message); 35 +
  36 + AnalysisRoute analysisRoute=new AnalysisRoute();
  37 + analysisRoute.setMessage(message);
  38 + threadPoolEs.execute(analysisRoute);
  39 + //AnalysisRoute.analysis(message);
32 // if(message.indexOf("<TYPE>CARM</TYPE>") > 0){ 40 // if(message.indexOf("<TYPE>CARM</TYPE>") > 0){
33 // this.client.sendMSG(); 41 // this.client.sendMSG();
34 // } 42 // }
@@ -5,6 +5,7 @@ import com.sy.logic.LiftBar; @@ -5,6 +5,7 @@ import com.sy.logic.LiftBar;
5 import com.sy.logic.LogicOperation; 5 import com.sy.logic.LogicOperation;
6 import com.sy.model.*; 6 import com.sy.model.*;
7 import com.sy.service.*; 7 import com.sy.service.*;
  8 +import org.apache.cxf.annotations.DataBinding;
8 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
9 import org.apache.log4j.PropertyConfigurator; 10 import org.apache.log4j.PropertyConfigurator;
10 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
@@ -14,9 +15,8 @@ import javax.annotation.PostConstruct; @@ -14,9 +15,8 @@ import javax.annotation.PostConstruct;
14 import java.util.Date; 15 import java.util.Date;
15 import java.util.List; 16 import java.util.List;
16 17
17 -  
18 @Component 18 @Component
19 -public class AnalysisRoute { 19 +public class AnalysisRoute implements Runnable{
20 20
21 @Autowired 21 @Autowired
22 private aironeExStockService exStockService; 22 private aironeExStockService exStockService;
@@ -58,6 +58,16 @@ public class AnalysisRoute { @@ -58,6 +58,16 @@ public class AnalysisRoute {
58 private static CommandInfoAnalysis commandInfoAnalysis = new CommandInfoAnalysis(); 58 private static CommandInfoAnalysis commandInfoAnalysis = new CommandInfoAnalysis();
59 private static ResMessageAnalysis resMessageAnalysis = new ResMessageAnalysis(); 59 private static ResMessageAnalysis resMessageAnalysis = new ResMessageAnalysis();
60 60
  61 + public String getMessage() {
  62 + return message;
  63 + }
  64 +
  65 + public void setMessage(String message) {
  66 + this.message = message;
  67 + }
  68 +
  69 + private String message;
  70 +
61 @PostConstruct 71 @PostConstruct
62 public void init(){ 72 public void init(){
63 route = this; 73 route = this;
@@ -192,6 +202,10 @@ public class AnalysisRoute { @@ -192,6 +202,10 @@ public class AnalysisRoute {
192 } 202 }
193 203
194 204
  205 + @Override
  206 + public void run() {
  207 + analysis(message);
  208 + }
195 } 209 }
196 210
197 211
@@ -52,6 +52,7 @@ public class GatherInfoAnalysis { @@ -52,6 +52,7 @@ public class GatherInfoAnalysis {
52 bean.setIcpegdatetime(info.getIc().getIcRegDatetime()); 52 bean.setIcpegdatetime(info.getIc().getIcRegDatetime());
53 bean.setIcperdaydue(info.getIc().getIcPerDayDue()); 53 bean.setIcperdaydue(info.getIc().getIcPerDayDue());
54 bean.setIcfromtype(info.getIc().getIcFormType()); 54 bean.setIcfromtype(info.getIc().getIcFormType());
  55 + bean.setGpsid(info.getIc().getGpsId());
55 return bean; 56 return bean;
56 } 57 }
57 58
@@ -54,6 +54,19 @@ public class IC { @@ -54,6 +54,19 @@ public class IC {
54 @XStreamAlias("IC_PER_DAY_DUE") 54 @XStreamAlias("IC_PER_DAY_DUE")
55 private String IcPerDayDue; 55 private String IcPerDayDue;
56 56
  57 + public String getGpsId() {
  58 + return GpsId;
  59 + }
  60 +
  61 + public void setGpsId(String gpsId) {
  62 + GpsId = gpsId;
  63 + }
  64 +
  65 + @XStreamAlias("GPS_ID")
  66 + private String GpsId;
  67 +
  68 +
  69 +
57 public String getDRICNO() { 70 public String getDRICNO() {
58 return DRICNO; 71 return DRICNO;
59 } 72 }
@@ -113,6 +113,9 @@ public class LiftBar { @@ -113,6 +113,9 @@ public class LiftBar {
113 CommandClient.Client(info, NORECORD + vaName); 113 CommandClient.Client(info, NORECORD + vaName);
114 return result; 114 return result;
115 } 115 }
  116 + /*if("4604600000".equals(info.getAreaid())){
  117 + return result;
  118 + }*/
116 /** 119 /**
117 * 车牌号,二维码,场站ID/号,通道ID/号,进出业务类型标识I/E 120 * 车牌号,二维码,场站ID/号,通道ID/号,进出业务类型标识I/E
118 * 查询是否已有此场站通道的申请 121 * 查询是否已有此场站通道的申请
@@ -149,10 +152,12 @@ public class LiftBar { @@ -149,10 +152,12 @@ public class LiftBar {
149 //对应场站进场过磅重量 152 //对应场站进场过磅重量
150 inWt=typeList.getAislewt(); 153 inWt=typeList.getAislewt();
151 } 154 }
  155 + //进出差值
152 diffVal = inWt- growssWt; 156 diffVal = inWt- growssWt;
153 } 157 }
154 //判断场站出场是否要重量校验 158 //判断场站出场是否要重量校验
155 - if(FileTool.readProperties("station").equals(list.getEndstation())||FileTool.readProperties("stationsf").equals(list.getEndstation())){ 159 + if(FileTool.readProperties("station").equals(list.getEndstation())||FileTool.readProperties("stationsf").equals(list.getEndstation())
  160 + || "4604600000".equals(list.getEndstation())){
156 checkResult=true; 161 checkResult=true;
157 }else if(!"普通货".equals(list.getCocode())){ 162 }else if(!"普通货".equals(list.getCocode())){
158 checkResult=true; 163 checkResult=true;
@@ -182,7 +187,7 @@ public class LiftBar { @@ -182,7 +187,7 @@ public class LiftBar {
182 //list.setRemark(String.format("%.1f", goodsWt)); 187 //list.setRemark(String.format("%.1f", goodsWt));
183 list.setRemark2(ve.getSelfWt()); 188 list.setRemark2(ve.getSelfWt());
184 list.setContrastflag("已进站"); 189 list.setContrastflag("已进站");
185 - logic.checkData(list); 190 + //logic.checkData(list);
186 } else { 191 } else {
187 LandRoadVe veName = logic.veService.selectByFrameNo(vaName); 192 LandRoadVe veName = logic.veService.selectByFrameNo(vaName);
188 list.setAislewt(info.getGrosswt().doubleValue()); 193 list.setAislewt(info.getGrosswt().doubleValue());
@@ -191,7 +196,7 @@ public class LiftBar { @@ -191,7 +196,7 @@ public class LiftBar {
191 list.setRemark1(String.format("%.1f", diffVal)); 196 list.setRemark1(String.format("%.1f", diffVal));
192 list.setRemark2(veName.getSelfWt()); 197 list.setRemark2(veName.getSelfWt());
193 list.setContrastflag("已出站"); 198 list.setContrastflag("已出站");
194 - logic.checkData(list); 199 + //logic.checkData(list);
195 } 200 }
196 logic.listService.updateById(list);//更新进出场申请业务表 201 logic.listService.updateById(list);//更新进出场申请业务表
197 //进出场申请业务表对应场站的卡口失效 202 //进出场申请业务表对应场站的卡口失效
@@ -224,11 +229,11 @@ public class LiftBar { @@ -224,11 +229,11 @@ public class LiftBar {
224 } 229 }
225 } 230 }
226 //最后发送通知数组 231 //最后发送通知数组
227 - try{ 232 + /*try{
228 new LiftBar().sendMessage(info.getVename(),arrive_infos); 233 new LiftBar().sendMessage(info.getVename(),arrive_infos);
229 }catch (Exception e){ 234 }catch (Exception e){
230 logger.info("新舱单发送消息异常---"+e.toString()); 235 logger.info("新舱单发送消息异常---"+e.toString());
231 - } 236 + }*/
232 } 237 }
233 }catch (Exception e){ 238 }catch (Exception e){
234 logger.info("运单分批消息异常---"+e.toString()); 239 logger.info("运单分批消息异常---"+e.toString());
@@ -86,6 +86,16 @@ public class GatherInfo { @@ -86,6 +86,16 @@ public class GatherInfo {
86 86
87 private String ordernum; 87 private String ordernum;
88 88
  89 + public String getGpsid() {
  90 + return gpsid;
  91 + }
  92 +
  93 + public void setGpsid(String gpsid) {
  94 + this.gpsid = gpsid;
  95 + }
  96 +
  97 + private String gpsid;
  98 +
89 public String getSeqno() { 99 public String getSeqno() {
90 return seqno; 100 return seqno;
91 } 101 }
  1 +package com.sy.utils;
  2 +
  3 +
  4 +import java.util.ArrayList;
  5 +import java.util.Date;
  6 +import java.util.Iterator;
  7 +import java.util.List;
  8 +import java.util.concurrent.ThreadFactory;
  9 +
  10 +public class XMLThreadFactory implements ThreadFactory {
  11 +
  12 + private int counter;
  13 + private String name;
  14 + private List<String> stats;
  15 +
  16 + public XMLThreadFactory(String name)
  17 + {
  18 + counter = 1;
  19 + this.name = name;
  20 + stats = new ArrayList<String>();
  21 + }
  22 +
  23 + @Override
  24 + public Thread newThread(Runnable runnable)
  25 + {
  26 + Thread t = new Thread(runnable, name + "-Thread_" + counter);
  27 + counter++;
  28 + stats.add(String.format("Created thread %d with name %s on %s \n", t.getId(), t.getName(), new Date()));
  29 + //log.info("Created thread id: {} with name {} on {} \n", t.getId(), t.getName(), new Date());
  30 + //log.info(getStats());
  31 + return t;
  32 + }
  33 +
  34 + public String getStats()
  35 + {
  36 + StringBuffer buffer = new StringBuffer();
  37 + Iterator<String> it = stats.iterator();
  38 + while (it.hasNext())
  39 + {
  40 + buffer.append(it.next());
  41 + }
  42 + return buffer.toString();
  43 + }
  44 +
  45 +}
  1 +package com.sy.utils;
  2 +
  3 +import java.util.concurrent.LinkedBlockingQueue;
  4 +import java.util.concurrent.ThreadPoolExecutor;
  5 +import java.util.concurrent.TimeUnit;
  6 +
  7 +public class XMLThreadPoolFactory {
  8 +
  9 + private static ThreadPoolExecutor threadPool;
  10 +
  11 + public static ThreadPoolExecutor instance(String busstype){
  12 + if (threadPool==null){
  13 + XMLThreadFactory xmlThreadFactory = new XMLThreadFactory(busstype);
  14 + threadPool = new ThreadPoolExecutor(50, 200,
  15 + 0L, TimeUnit.SECONDS,
  16 + new LinkedBlockingQueue<Runnable>(4000),
  17 + xmlThreadFactory,
  18 + new ThreadPoolExecutor.AbortPolicy());
  19 +
  20 + }
  21 + return threadPool;
  22 + }
  23 +}
@@ -2,11 +2,14 @@ package com.sy; @@ -2,11 +2,14 @@ package com.sy;
2 2
3 import com.sy.bwAnalysis.AnalysisRoute; 3 import com.sy.bwAnalysis.AnalysisRoute;
4 import com.sy.logic.LiftBar; 4 import com.sy.logic.LiftBar;
  5 +import com.sy.utils.XMLThreadPoolFactory;
5 import org.junit.Test; 6 import org.junit.Test;
6 import org.junit.runner.RunWith; 7 import org.junit.runner.RunWith;
7 import org.springframework.boot.test.context.SpringBootTest; 8 import org.springframework.boot.test.context.SpringBootTest;
8 import org.springframework.test.context.junit4.SpringRunner; 9 import org.springframework.test.context.junit4.SpringRunner;
9 10
  11 +import java.util.concurrent.ThreadPoolExecutor;
  12 +
10 @RunWith(SpringRunner.class) 13 @RunWith(SpringRunner.class)
11 @SpringBootTest 14 @SpringBootTest
12 public class AnalysisImfApplicationTests { 15 public class AnalysisImfApplicationTests {
@@ -16,7 +19,14 @@ public class AnalysisImfApplicationTests { @@ -16,7 +19,14 @@ public class AnalysisImfApplicationTests {
16 19
17 @Test 20 @Test
18 public void contextLoads() { 21 public void contextLoads() {
  22 + ThreadPoolExecutor threadPoolEs = XMLThreadPoolFactory.instance("kakou");
  23 + for(int i=0;i<10;i++){
  24 + AnalysisRoute analysisRoute=new AnalysisRoute();
  25 + analysisRoute.setMessage(message);
  26 + threadPoolEs.execute(analysisRoute);
19 AnalysisRoute.analysis(message); 27 AnalysisRoute.analysis(message);
  28 + System.out.println("--------->"+i);
  29 + }
20 30
21 LiftBar.sendData("1","aaa",true); 31 LiftBar.sendData("1","aaa",true);
22 32