作者 xudada

北货更新+多线程

... ... @@ -19,6 +19,7 @@ STYP=CARM
grossWt=5%
station=4600329012
stationsf=4600541001
stationb=4604600000
#\u4E8C\u7EF4\u7801\u5B58\u653E\u8DEF\u5F84\uFF0C\u9879\u76EE\u542F\u52A8\u65F6\u8BBE\u7F6E\uFF0C\u540E\u671F\u4E0D\u80FD\u66F4\u6539\u3002
#barCode = barcode/
... ...
... ... @@ -5,10 +5,18 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import java.util.concurrent.Executors;
@EnableFeignClients
@SpringBootApplication
@EnableScheduling
@EnableAsync
//不连接数据库开启服务
//@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
//@EnableEurekaClient
... ... @@ -62,4 +70,5 @@ public class AnalysisImfApplication {
AnalysisRoute.analysis(message);*/
}
}
... ...
... ... @@ -2,9 +2,12 @@ package com.sy.IMF;
import com.caac.imf.api.IMFClient;
import com.sy.bwAnalysis.AnalysisRoute;
import com.sy.utils.XMLThreadPoolFactory;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import java.util.concurrent.ThreadPoolExecutor;
public class KAKO_Reader extends Thread{
protected static final Logger logger = Logger.getLogger(KAKO_Reader.class);
private IMFClient client;
... ... @@ -22,13 +25,18 @@ public class KAKO_Reader extends Thread{
logger.info("********读取线程状态true**********");
logger.info("********Client-INFO= "+client+"********");
Thread t =Thread.currentThread();
ThreadPoolExecutor threadPoolEs = XMLThreadPoolFactory.instance("kakou");
while(true) {
if (IMF_Tesk.LOGIN_OK){
String message = this.client.getMSG();
logger.info(t.toString()+"读取线程已获取到消息");
if (message != null && StringUtils.isNotEmpty(message)) {
// logger.info(message);
AnalysisRoute.analysis(message);
AnalysisRoute analysisRoute=new AnalysisRoute();
analysisRoute.setMessage(message);
threadPoolEs.execute(analysisRoute);
//AnalysisRoute.analysis(message);
// if(message.indexOf("<TYPE>CARM</TYPE>") > 0){
// this.client.sendMSG();
// }
... ...
... ... @@ -5,6 +5,7 @@ import com.sy.logic.LiftBar;
import com.sy.logic.LogicOperation;
import com.sy.model.*;
import com.sy.service.*;
import org.apache.cxf.annotations.DataBinding;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -14,9 +15,8 @@ import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.List;
@Component
public class AnalysisRoute {
public class AnalysisRoute implements Runnable{
@Autowired
private aironeExStockService exStockService;
... ... @@ -58,6 +58,16 @@ public class AnalysisRoute {
private static CommandInfoAnalysis commandInfoAnalysis = new CommandInfoAnalysis();
private static ResMessageAnalysis resMessageAnalysis = new ResMessageAnalysis();
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
private String message;
@PostConstruct
public void init(){
route = this;
... ... @@ -192,6 +202,10 @@ public class AnalysisRoute {
}
@Override
public void run() {
analysis(message);
}
}
... ...
... ... @@ -52,6 +52,7 @@ public class GatherInfoAnalysis {
bean.setIcpegdatetime(info.getIc().getIcRegDatetime());
bean.setIcperdaydue(info.getIc().getIcPerDayDue());
bean.setIcfromtype(info.getIc().getIcFormType());
bean.setGpsid(info.getIc().getGpsId());
return bean;
}
... ...
... ... @@ -54,6 +54,19 @@ public class IC {
@XStreamAlias("IC_PER_DAY_DUE")
private String IcPerDayDue;
public String getGpsId() {
return GpsId;
}
public void setGpsId(String gpsId) {
GpsId = gpsId;
}
@XStreamAlias("GPS_ID")
private String GpsId;
public String getDRICNO() {
return DRICNO;
}
... ...
... ... @@ -113,6 +113,9 @@ public class LiftBar {
CommandClient.Client(info, NORECORD + vaName);
return result;
}
/*if("4604600000".equals(info.getAreaid())){
return result;
}*/
/**
* 车牌号,二维码,场站ID/号,通道ID/号,进出业务类型标识I/E
* 查询是否已有此场站通道的申请
... ... @@ -149,10 +152,12 @@ public class LiftBar {
//对应场站进场过磅重量
inWt=typeList.getAislewt();
}
//进出差值
diffVal = inWt- growssWt;
}
//判断场站出场是否要重量校验
if(FileTool.readProperties("station").equals(list.getEndstation())||FileTool.readProperties("stationsf").equals(list.getEndstation())){
if(FileTool.readProperties("station").equals(list.getEndstation())||FileTool.readProperties("stationsf").equals(list.getEndstation())
|| "4604600000".equals(list.getEndstation())){
checkResult=true;
}else if(!"普通货".equals(list.getCocode())){
checkResult=true;
... ... @@ -182,7 +187,7 @@ public class LiftBar {
//list.setRemark(String.format("%.1f", goodsWt));
list.setRemark2(ve.getSelfWt());
list.setContrastflag("已进站");
logic.checkData(list);
//logic.checkData(list);
} else {
LandRoadVe veName = logic.veService.selectByFrameNo(vaName);
list.setAislewt(info.getGrosswt().doubleValue());
... ... @@ -191,7 +196,7 @@ public class LiftBar {
list.setRemark1(String.format("%.1f", diffVal));
list.setRemark2(veName.getSelfWt());
list.setContrastflag("已出站");
logic.checkData(list);
//logic.checkData(list);
}
logic.listService.updateById(list);//更新进出场申请业务表
//进出场申请业务表对应场站的卡口失效
... ... @@ -224,11 +229,11 @@ public class LiftBar {
}
}
//最后发送通知数组
try{
/*try{
new LiftBar().sendMessage(info.getVename(),arrive_infos);
}catch (Exception e){
logger.info("新舱单发送消息异常---"+e.toString());
}
}*/
}
}catch (Exception e){
logger.info("运单分批消息异常---"+e.toString());
... ...
... ... @@ -86,6 +86,16 @@ public class GatherInfo {
private String ordernum;
public String getGpsid() {
return gpsid;
}
public void setGpsid(String gpsid) {
this.gpsid = gpsid;
}
private String gpsid;
public String getSeqno() {
return seqno;
}
... ...
package com.sy.utils;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ThreadFactory;
public class XMLThreadFactory implements ThreadFactory {
private int counter;
private String name;
private List<String> stats;
public XMLThreadFactory(String name)
{
counter = 1;
this.name = name;
stats = new ArrayList<String>();
}
@Override
public Thread newThread(Runnable runnable)
{
Thread t = new Thread(runnable, name + "-Thread_" + counter);
counter++;
stats.add(String.format("Created thread %d with name %s on %s \n", t.getId(), t.getName(), new Date()));
//log.info("Created thread id: {} with name {} on {} \n", t.getId(), t.getName(), new Date());
//log.info(getStats());
return t;
}
public String getStats()
{
StringBuffer buffer = new StringBuffer();
Iterator<String> it = stats.iterator();
while (it.hasNext())
{
buffer.append(it.next());
}
return buffer.toString();
}
}
... ...
package com.sy.utils;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class XMLThreadPoolFactory {
private static ThreadPoolExecutor threadPool;
public static ThreadPoolExecutor instance(String busstype){
if (threadPool==null){
XMLThreadFactory xmlThreadFactory = new XMLThreadFactory(busstype);
threadPool = new ThreadPoolExecutor(50, 200,
0L, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(4000),
xmlThreadFactory,
new ThreadPoolExecutor.AbortPolicy());
}
return threadPool;
}
}
... ...
... ... @@ -2,11 +2,14 @@ package com.sy;
import com.sy.bwAnalysis.AnalysisRoute;
import com.sy.logic.LiftBar;
import com.sy.utils.XMLThreadPoolFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.concurrent.ThreadPoolExecutor;
@RunWith(SpringRunner.class)
@SpringBootTest
public class AnalysisImfApplicationTests {
... ... @@ -16,7 +19,14 @@ public class AnalysisImfApplicationTests {
@Test
public void contextLoads() {
ThreadPoolExecutor threadPoolEs = XMLThreadPoolFactory.instance("kakou");
for(int i=0;i<10;i++){
AnalysisRoute analysisRoute=new AnalysisRoute();
analysisRoute.setMessage(message);
threadPoolEs.execute(analysisRoute);
AnalysisRoute.analysis(message);
System.out.println("--------->"+i);
}
LiftBar.sendData("1","aaa",true);
... ...