FWBTask.java
16.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
package com.example.demo.scheduled;
import com.example.demo.model.FWBAssociatedParty;
import com.example.demo.util.XML.XMLParse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* 定时任务
*/
@Component
public class FWBTask {
private static final Logger logger = LoggerFactory.getLogger(FWBTask.class);
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Scheduled(fixedRate = 5000)
public void scheduledDemo(){
logger.info("scheduled - fixedRate - print time every 5 seconds:{}", format.format(new Date()) );
String testMsg= "<MSG>\n" +
"\t<META>\n" +
"\t\t<SNDR>TXD</SNDR>\n" +
"\t\t<DDTM>20181114040536</DDTM>\n" +
"\t\t<TYPE>DFME</TYPE>\n" +
"\t\t<STYP>FWB</STYP>\n" +
"\t\t<SEQN>4643187</SEQN>\n" +
"\t</META>\n" +
"\t<MasterConsignment>\n" +
"\t\t<ID>880-83213594</ID>\n" +
"\t\t<TypeCode>741</TypeCode>\n" +
"\t\t<NilCarriageValueIndicator>false</NilCarriageValueIndicator>\n" +
"\t\t<DeclaredValueForCarriageAmount currencyID=\"CNY\">0</DeclaredValueForCarriageAmount>\n" +
"\t\t<NilCustomsValueIndicator>true</NilCustomsValueIndicator>\n" +
"\t\t<DeclaredValueForCustomsAmount currencyID=\"CNY\">NCV</DeclaredValueForCustomsAmount>\n" +
"\t\t<NilInsuranceValueIndicator>true</NilInsuranceValueIndicator>\n" +
"\t\t<InsuranceValueAmount currencyID=\"CNY\">XXX</InsuranceValueAmount>\n" +
"\t\t<TotalChargePrepaidIndicator>true</TotalChargePrepaidIndicator>\n" +
"\t\t<WeightTotalChargeAmount currencyID=\"CNY\">502</WeightTotalChargeAmount>\n" +
"\t\t<ValuationTotalChargeAmount currencyID=\"CNY\">0.00</ValuationTotalChargeAmount>\n" +
"\t\t<TotalDisbursementPrepaidIndicator>true</TotalDisbursementPrepaidIndicator>\n" +
"\t\t<TotalPrepaidChargeAmount currencyID=\"CNY\">613.60</TotalPrepaidChargeAmount>\n" +
"\t\t<TotalCollectChargeAmount currencyID=\"CNY\">0</TotalCollectChargeAmount>\n" +
"\t\t<DestinationCurrencyTotalCollectChargeAmount currencyID=\"CNY\">0</DestinationCurrencyTotalCollectChargeAmount>\n" +
"\t\t<IncludedTareGrossWeightMeasure unitCode=\"KGM\">558.0</IncludedTareGrossWeightMeasure>\n" +
"\t\t<NetWeightMeasure/>\n" +
"\t\t<GrossVolumeMeasure unitCode=\"MTQ\">4.44</GrossVolumeMeasure>\n" +
"\t\t<TotalChargeableWeightMeasure unitCode=\"KGM\">558.0</TotalChargeableWeightMeasure>\n" +
"\t\t<ConsignmentItemQuantity>1</ConsignmentItemQuantity>\n" +
"\t\t<TotalPieceQuantity>74</TotalPieceQuantity>\n" +
"\t\t<TotalLoadedPackageQuantity>74</TotalLoadedPackageQuantity>\n" +
"\t\t<PackageInfo>编织袋</PackageInfo>\n" +
"\t\t<FreightRateTypeCode>Q</FreightRateTypeCode>\n" +
"\t\t<ConsignorParty>\n" +
"\t\t\t<PrimaryID schemeAgencyID=\"1\">HNHH</PrimaryID>\n" +
"\t\t\t<Name>河南汇海物流有限公司</Name>\n" +
"\t\t\t<AccountID>INFOSKY:NULL</AccountID>\n" +
"\t\t\t<PostalStructuredAddress>\n" +
"\t\t\t\t<StreetName>郑州</StreetName>\n" +
"\t\t\t\t<CityName>CGO</CityName>\n" +
"\t\t\t\t<CountryID>CN</CountryID>\n" +
"\t\t\t\t<SpecifiedAddressLocation/>\n" +
"\t\t\t</PostalStructuredAddress>\n" +
"\t\t\t<SpecifiedCargoAgentLocation/>\n" +
"\t\t\t<DefinedTradeContact>\n" +
"\t\t\t\t<DirectTelephoneCommunication>\n" +
"\t\t\t\t\t<CompleteNumber>CGO</CompleteNumber>\n" +
"\t\t\t\t</DirectTelephoneCommunication>\n" +
"\t\t\t</DefinedTradeContact>\n" +
"\t\t</ConsignorParty>\n" +
"\t\t<ConsigneeParty>\n" +
"\t\t\t<PrimaryID schemeAgencyID=\"2\">SK</PrimaryID>\n" +
"\t\t\t<Name>海南顺丰速运有限公司</Name>\n" +
"\t\t\t<AccountID>INFOSKY:NULL</AccountID>\n" +
"\t\t\t<PostalStructuredAddress>\n" +
"\t\t\t\t<StreetName>机场自提</StreetName>\n" +
"\t\t\t\t<CityName>HAK</CityName>\n" +
"\t\t\t\t<CountryID>CN</CountryID>\n" +
"\t\t\t\t<SpecifiedAddressLocation/>\n" +
"\t\t\t</PostalStructuredAddress>\n" +
"\t\t\t<SpecifiedCargoAgentLocation/>\n" +
"\t\t\t<DefinedTradeContact/>\n" +
"\t\t</ConsigneeParty>\n" +
"\t\t<FreightForwarderParty>\n" +
"\t\t\t<Name>CGOSA</Name>\n" +
"\t\t\t<AccountID>INFOSKY:NULL</AccountID>\n" +
"\t\t\t<PostalStructuredAddress>\n" +
"\t\t\t\t<CityName>CGO</CityName>\n" +
"\t\t\t\t<CountryID>CN</CountryID>\n" +
"\t\t\t\t<SpecifiedAddressLocation/>\n" +
"\t\t\t</PostalStructuredAddress>\n" +
"\t\t\t<SpecifiedCargoAgentLocation/>\n" +
"\t\t\t<DefinedTradeContact/>\n" +
"\t\t</FreightForwarderParty>\n" +
"\t\t<AssociatedParty>\n" +
"\t\t\t<PrimaryID/>\n" +
"\t\t\t<Name>CGO</Name>\n" +
"\t\t\t<AccountID>INFOSKY:NULL</AccountID>\n" +
"\t\t\t<RoleCode>AGT</RoleCode>\n" +
"\t\t\t<Role>Agent</Role>\n" +
"\t\t\t<PostalStructuredAddress>\n" +
"\t\t\t\t<CityName>CGO</CityName>\n" +
"\t\t\t\t<CountryID>CN</CountryID>\n" +
"\t\t\t\t<SpecifiedAddressLocation/>\n" +
"\t\t\t</PostalStructuredAddress>\n" +
"\t\t\t<SpecifiedCargoAgentLocation/>\n" +
"\t\t\t<DefinedTradeContact/>\n" +
"\t\t</AssociatedParty>\n" +
"\t\t<AssociatedParty>\n" +
"\t\t\t<PrimaryID/>\n" +
"\t\t\t<Name>CGOHA</Name>\n" +
"\t\t\t<AccountID>INFOSKY:NULL</AccountID>\n" +
"\t\t\t<RoleCode>GHA</RoleCode>\n" +
"\t\t\t<Role>Ground Handling Agent</Role>\n" +
"\t\t\t<PostalStructuredAddress>\n" +
"\t\t\t\t<CityName>CGO</CityName>\n" +
"\t\t\t\t<CountryID>CN</CountryID>\n" +
"\t\t\t\t<SpecifiedAddressLocation/>\n" +
"\t\t\t</PostalStructuredAddress>\n" +
"\t\t\t<SpecifiedCargoAgentLocation/>\n" +
"\t\t\t<DefinedTradeContact/>\n" +
"\t\t</AssociatedParty>\n" +
"\t\t<OriginLocation>\n" +
"\t\t\t<ID>CGO</ID>\n" +
"\t\t</OriginLocation>\n" +
"\t\t<FinalDestinationLocation>\n" +
"\t\t\t<ID>HAK</ID>\n" +
"\t\t</FinalDestinationLocation>\n" +
"\t\t<SpecifiedLogisticsTransportMovement>\n" +
"\t\t\t<StageCode>HU7304/Nov14</StageCode>\n" +
"\t\t\t<ModeCode>4</ModeCode>\n" +
"\t\t\t<Mode>Air Transport</Mode>\n" +
"\t\t\t<ID>HU7304</ID>\n" +
"\t\t\t<SequenceNumeric>1</SequenceNumeric>\n" +
"\t\t\t<UsedLogisticsTransportMeans/>\n" +
"\t\t\t<ArrivalEvent>\n" +
"\t\t\t\t<OccurrenceArrivalLocation>\n" +
"\t\t\t\t\t<ID>HAK</ID>\n" +
"\t\t\t\t</OccurrenceArrivalLocation>\n" +
"\t\t\t</ArrivalEvent>\n" +
"\t\t\t<DepartureEvent>\n" +
"\t\t\t\t<ScheduledOccurrenceDateTime>2018-11-14T00:00:00+08:00</ScheduledOccurrenceDateTime>\n" +
"\t\t\t\t<OccurrenceDepartureLocation>\n" +
"\t\t\t\t\t<ID>CGO</ID>\n" +
"\t\t\t\t</OccurrenceDepartureLocation>\n" +
"\t\t\t</DepartureEvent>\n" +
"\t\t</SpecifiedLogisticsTransportMovement>\n" +
"\t\t<IncludedAccountingNote>\n" +
"\t\t\t<ContentCode>20010003普通</ContentCode>\n" +
"\t\t\t<Content>20010003普通</Content>\n" +
"\t\t</IncludedAccountingNote>\n" +
"\t\t<AssociatedConsignmentCustomsProcedure/>\n" +
"\t\t<ApplicableTradeCurrencyExchange>\n" +
"\t\t\t<SourceCurrencyCode>CNY</SourceCurrencyCode>\n" +
"\t\t\t<TargetCurrencyCode>CNY</TargetCurrencyCode>\n" +
"\t\t\t<MarketID>S</MarketID>\n" +
"\t\t\t<ConversionRate>1</ConversionRate>\n" +
"\t\t</ApplicableTradeCurrencyExchange>\n" +
"\t\t<ApplicableLogisticsServiceCharge/>\n" +
"\t\t<ApplicableLogisticsAllowanceCharge>\n" +
"\t\t\t<ID>MY</ID>\n" +
"\t\t\t<Reason>燃油费</Reason>\n" +
"\t\t\t<ActualAmount currencyID=\"CNY\">111.6</ActualAmount>\n" +
"\t\t\t<PartyTypeCode>C</PartyTypeCode>\n" +
"\t\t</ApplicableLogisticsAllowanceCharge>\n" +
"\t\t<SignatoryCarrierAuthentication>\n" +
"\t\t\t<ActualDateTime>2018-11-14T04:02:00</ActualDateTime>\n" +
"\t\t\t<Signatory>牛青</Signatory>\n" +
"\t\t\t<IssueAuthenticationLocation>\n" +
"\t\t\t\t<Name>郑州</Name>\n" +
"\t\t\t</IssueAuthenticationLocation>\n" +
"\t\t</SignatoryCarrierAuthentication>\n" +
"\t\t<IncludedMasterConsignmentItem>\n" +
"\t\t\t<SequenceNumeric>1</SequenceNumeric>\n" +
"\t\t\t<TypeCode listAgencyID=\"1\">PH</TypeCode>\n" +
"\t\t\t<GrossWeightMeasure unitCode=\"KGM\">558.0</GrossWeightMeasure>\n" +
"\t\t\t<GrossVolumeMeasure unitCode=\"MTQ\">4.44</GrossVolumeMeasure>\n" +
"\t\t\t<PieceQuantity>74</PieceQuantity>\n" +
"\t\t\t<TareWeightMeasure unitCode=\"KGM\">558.0</TareWeightMeasure>\n" +
"\t\t\t<NatureIdentificationTransportCargo>\n" +
"\t\t\t\t<Identification>手机机头(无电池) 电子主板 上衣 茶叶 大枣 皮带 票证 运动鞋 背包 灯座</Identification>\n" +
"\t\t\t</NatureIdentificationTransportCargo>\n" +
"\t\t\t<OriginCountry/>\n" +
"\t\t\t<AssociatedUnitLoadTransportEquipment>\n" +
"\t\t\t\t<OperatingParty/>\n" +
"\t\t\t</AssociatedUnitLoadTransportEquipment>\n" +
"\t\t\t<TransportLogisticsPackage>\n" +
"\t\t\t\t<ItemQuantity>74</ItemQuantity>\n" +
"\t\t\t\t<LinearSpatialDimension>\n" +
"\t\t\t\t\t<Description>true</Description>\n" +
"\t\t\t\t\t<WidthMeasure unitCode=\"CMT\">40</WidthMeasure>\n" +
"\t\t\t\t\t<LengthMeasure unitCode=\"CMT\">30</LengthMeasure>\n" +
"\t\t\t\t\t<HeightMeasure unitCode=\"CMT\">50</HeightMeasure>\n" +
"\t\t\t\t</LinearSpatialDimension>\n" +
"\t\t\t</TransportLogisticsPackage>\n" +
"\t\t\t<ApplicableFreightRateServiceCharge>\n" +
"\t\t\t\t<CategoryCode>Q</CategoryCode>\n" +
"\t\t\t\t<CommodityItemID>P</CommodityItemID>\n" +
"\t\t\t\t<ChargeableWeightMeasure unitCode=\"KGM\">558.0</ChargeableWeightMeasure>\n" +
"\t\t\t\t<AppliedRate>0.9</AppliedRate>\n" +
"\t\t\t\t<AppliedAmount currencyID=\"CNY\">502</AppliedAmount>\n" +
"\t\t\t</ApplicableFreightRateServiceCharge>\n" +
"\t\t\t<SpecifiedRateCombinationPointLocation/>\n" +
"\t\t</IncludedMasterConsignmentItem>\n" +
"\t\t<ReportedStatus>\n" +
"\t\t\t<ReasonCode>FWB</ReasonCode>\n" +
"\t\t\t<EventTime>\n" +
"\t\t\t\t<OccurrenceDateTime>2018-11-14T04:03:02+08:00</OccurrenceDateTime>\n" +
"\t\t\t\t<DateTimeTypeCode>Actual</DateTimeTypeCode>\n" +
"\t\t\t</EventTime>\n" +
"\t\t\t<SpecifiedLocation>\n" +
"\t\t\t\t<ID>CGO</ID>\n" +
"\t\t\t</SpecifiedLocation>\n" +
"\t\t</ReportedStatus>\n" +
"\t</MasterConsignment>\n" +
"</MSG>";
try {
XMLParse xmlParse = new XMLParse(testMsg);
Map resoultMaps = xmlParse.getAllValuesFromXmlString();
logger.info(resoultMaps.toString());
FWBAssociatedParty fwbAssociatedParty = new FWBAssociatedParty();
fwbAssociatedParty.setAwbnumber(xmlParse.getNodeValueFromXmlString( "/MSG/MasterConsignment/ID"));
String[] flight = xmlParse.getNodeValueFromXmlString( "/MSG/MasterConsignment/SpecifiedLogisticsTransportMovement/StageCode").split("/");
String flightDep = xmlParse.getNodeValueFromXmlString( "/MSG/MasterConsignment/SpecifiedLogisticsTransportMovement/DepartureEvent/ScheduledOccurrenceDateTime");
String flight_No = flight[0]; //航班号
String flight_date=flight[1]; //航班日期年月
fwbAssociatedParty.setFlightnumber(flight_No);
//根据离港日期取航班日期年份
ZonedDateTime depZoneTime = ZonedDateTime.parse(flightDep);
String year = String.valueOf(depZoneTime.getYear());
//合并航班日期和离港年份,组成完整日期格式
flight_date = flight_date+year;
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
formatter = DateTimeFormatter.ofPattern("MMMddyyyy",Locale.ENGLISH);
LocalDate date =LocalDate.parse(flight_date,formatter);
//写入对象
fwbAssociatedParty.setFlightdate(date);
//以上关于运单的信息与航班信息已解析完成
//开始读取相同节点数组
List<Map> stype_value =xmlParse.getNodeValuesFromXmlString( "/MSG/MasterConsignment/AssociatedParty");
for (Map map :stype_value){
fwbAssociatedParty.setPrimaryid((String) map.get("PrimaryID"));
fwbAssociatedParty.setName(map.get("Name").toString());
fwbAssociatedParty.setAccountid(map.get("AccountID").toString());
fwbAssociatedParty.setRolecode(map.get("RoleCode").toString());
fwbAssociatedParty.setRole(map.get("Role").toString());
}
//
logger.info(stype_value.toString());
}catch (Exception var7){
logger.error(var7.toString());
}
}
/**
"0/5 * * * * ?" 每5秒触发
"0 0 12 * * ?" 每天中午十二点触发
"0 15 10 ? * *" 每天早上10:15触发
"0 15 10 * * ?" 每天早上10:15触发
"0 15 10 * * ? *" 每天早上10:15触发
"0 15 10 * * ? 2005" 2005年的每天早上10:15触发
"0 * 14 * * ?" 每天从下午2点开始到2点59分每分钟一次触发
"0 0/5 14 * * ?" 每天从下午2点开始到2:55分结束每5分钟一次触发
"0 0/5 14,18 * * ?" 每天的下午2点至2:55和6点至6点55分两个时间段内每5分钟一次触发
"0 0-5 14 * * ?" 每天14:00至14:05每分钟一次触发
"0 10,44 14 ? 3 WED" 三月的每周三的14:10和14:44触发
"0 15 10 ? * MON-FRI" 每个周一、周二、周三、周四、周五的10:15触发
*/
// @Scheduled(cron="0/10 * * * * ?")
// public void scheduledCronDemo(){
// logger.info("scheduled - cron - print time every 10 seconds:{}", format.format(new Date()) );
// }
}