LostChangeController.java
15.9 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
package com.tianbo.controller.lost;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.Converter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tianbo.model.ManifestItem;
import com.tianbo.model.ManifestLostChange;
import com.tianbo.model.Sendlog;
import com.tianbo.service.ItemService;
import com.tianbo.service.LostChangeService;
import com.tianbo.service.SendLogService;
import com.tianbo.util.DateUtils;
import com.tianbo.util.json.AjaxJson;
import com.tianbo.util.json.JsonConversion;
import com.tianbo.util.xml.XmlGen;
import com.tianbo.xml.lost.AssociatedTransportDocument;
import com.tianbo.xml.lost.BorderTransportMeans;
import com.tianbo.xml.lost.Consignment;
import com.tianbo.xml.lost.TransportContractDocument;
import com.tianbo.xml.lostChange.AssociatedTransport;
import com.tianbo.xml.lostChange.ChangeBorderTransportMeans;
import com.tianbo.xml.lostChange.ChangeConsignment;
import com.tianbo.xml.lostChange.Commodity;
import com.tianbo.xml.lostChange.ConsignmentItem;
import com.tianbo.xml.lostChange.ConsignmentItemPackaging;
import com.tianbo.xml.lostChange.DeclarationXml;
import com.tianbo.xml.lostChange.GoodsMeasure;
import com.tianbo.xml.lostChange.HeadXml;
import com.tianbo.xml.lostChange.ManifestXml;
import com.tianbo.xml.lostChange.TransportContract;
@Controller
@RequestMapping("/lost/change")
public class LostChangeController {
@Autowired
private LostChangeService lostChangeService;
@Autowired
private ItemService itemService;
@Autowired
private SendLogService sendLogService;
@RequestMapping(value = {"index", ""})
public String toFlight(ModelMap model,HttpServletRequest request) {
return "lost/change/list";
}
@RequestMapping(value ="editItem")
public String editItem(ModelMap model,HttpServletRequest request) {
String id = request.getParameter("id");
if(id!=null||id!=""){
model.put("ftId", id);
}
String waybillnomaster = request.getParameter("waybillnomaster");
if(waybillnomaster!=null||waybillnomaster!=""){
model.put("waybillnomaster", waybillnomaster);
}
// ManifestItem item = itemService.selectByPrimaryKey(id);
// model.put("item", item);
return "lost/change/item";
}
@RequestMapping(value ="edit")
public String edit(ModelMap model,HttpServletRequest request) {
model.put("waybillnomaster", request.getParameter("waybillnomaster"));
model.put("ftId", request.getParameter("id"));
return "lost/change/edit";
}
@ResponseBody
@RequestMapping(value = "getList")
public String getList(HttpServletRequest request,int page,int limit){
int start = (page-1)*limit+1;
int end = page*limit;
List<ManifestLostChange> lost = lostChangeService.getList(start,end);
ManifestLostChange ft = new ManifestLostChange();
int count = lostChangeService.getCount(ft);
Map<String,Object> map = new HashMap<>();
if(!lost.isEmpty()){
map.put("code", 0);
map.put("count", count);
map.put("msg", "success");
map.put("data", lost);
}else {
map.put("code", -1);
map.put("msg", "请检查网络连接或重试");
map.put("data", "");
}
return JsonConversion.writeMapJSON(map);
}
@ResponseBody
@RequestMapping(value = "getIteamList")
public String getIteamList(HttpServletRequest request,String waybillnomaster){
Map<String,Object> map = new HashMap<>();
try {
if(waybillnomaster!=null && waybillnomaster!=""){
List<ManifestItem> ltem = itemService.getIteamList(waybillnomaster);
if(!ltem.isEmpty()){
map.put("code", 0);
map.put("msg", "success");
map.put("data", ltem);
}else {
map.put("code", 0);
map.put("msg", "success");
map.put("data", "");
}
}else{
map.put("code", 0);
map.put("msg", "success");
map.put("data", "");
}
} catch (Exception e) {
map.put("code", -1);
map.put("msg", "请检查网络连接或重试");
map.put("data", "");
e.printStackTrace();
}
return JsonConversion.writeMapJSON(map);
}
@ResponseBody
@RequestMapping(value = "selectByParam")
public String selectByParam(HttpServletRequest request,int page,int limit,String flightno,String flightdate,String waybillnomaster,String waybillnosecondary){
int start = (page-1)*limit+1;
int end = page*limit;
List<ManifestLostChange> lost = lostChangeService.selectByParam(start,end,flightno,flightdate,waybillnomaster,waybillnosecondary);
ManifestLostChange fs = new ManifestLostChange();
fs.setFlightno(flightno);
int count = lostChangeService.getCount(fs);
Map<String,Object> map = new HashMap<>();
if(!lost.isEmpty()){
map.put("code", 0);
map.put("count", count);
map.put("msg", "success");
map.put("data", lost);
}else {
map.put("code", -1);
map.put("msg", "无此条件信息");
map.put("data", "");
}
return JsonConversion.writeMapJSON(map);
}
/**
* 编辑或新增
* @param lost
* @param redirectAttributes
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
@ResponseBody
@RequestMapping(value = "editForm")
public AjaxJson editForm(ModelMap model,@RequestParam Map<String, Object> params) throws IllegalAccessException, InvocationTargetException {
ManifestLostChange lostChange = new ManifestLostChange();
DateConvert();//日期转化
BeanUtils.populate(lostChange, params);
String message = null;
AjaxJson j = new AjaxJson();
if(lostChange.getId()!=null&&lostChange.getId()!=""){ //存在ID 执行更新
try {
lostChangeService.saveorupdate(lostChange);
j.setSuccess(true);
message = "修改成功";
} catch (Exception e) {
j.setSuccess(false);
message = "修改失败";
e.printStackTrace();
}
} else {
try {
lostChangeService.saveorupdate(lostChange);
j.setSuccess(true);
message = "保存成功";
} catch (Exception e) {
j.setSuccess(false);
message = "保存失败";
e.printStackTrace();
}
}
j.setMsg(message);
return j;
}
/**
* 日期转化
*/
public void DateConvert() {
ConvertUtils.register(new Converter() {
@SuppressWarnings("rawtypes")
public Object convert(Class type, Object value) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
return simpleDateFormat.parse(value.toString());
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}, Date.class);
}
/**
* 编辑或新增
* @param lost
* @param redirectAttributes
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
@ResponseBody
@RequestMapping(value = "editItemData")
public AjaxJson editIteamData(ModelMap model,@RequestParam Map<String, Object> params) throws IllegalAccessException, InvocationTargetException {
ManifestItem ml = new ManifestItem();
BeanUtils.populate(ml, params);
String message = null;
AjaxJson j = new AjaxJson();
try {
itemService.saveorupdate(ml);
j.setSuccess(true);
message = "保存成功";
} catch (Exception e) {
j.setSuccess(false);
message = "保存失败";
e.printStackTrace();
}
j.setMsg(message);
return j;
}
/**
* 删除
* @param lost
* @param redirectAttributes
* @return
*/
@ResponseBody
@RequestMapping(value = "delItem")
public AjaxJson delItem(ModelMap model,HttpServletRequest request) {
String id = request.getParameter("id");
String message = null;
AjaxJson j = new AjaxJson();
try {
itemService.deleteByPrimaryKey(id);
j.setSuccess(true);
message = "删除成功";
} catch (Exception e) {
j.setSuccess(false);
message = "删除失败";
e.printStackTrace();
}
j.setMsg(message);
return j;
}
/**
* 删除
* @param lost
* @param redirectAttributes
* @return
*/
@ResponseBody
@RequestMapping(value = "del")
public AjaxJson delete(ModelMap model,HttpServletRequest request) {
String id = request.getParameter("id");
String message = null;
AjaxJson j = new AjaxJson();
try {
lostChangeService.deleteByPrimaryKey(id);
j.setSuccess(true);
message = "删除成功";
} catch (Exception e) {
j.setSuccess(false);
message = "删除失败";
e.printStackTrace();
}
j.setMsg(message);
return j;
}
/**
* 删除
* @param lost
* @param redirectAttributes
* @return
*/
@ResponseBody
@RequestMapping(value = "updateStatues")
public AjaxJson updateStatues(ModelMap model,HttpServletRequest request) {
String id = request.getParameter("id");
String message = null;
AjaxJson j = new AjaxJson();
try {
ManifestLostChange manifestLoad = lostChangeService.selectByPrimaryKey(id);
manifestLoad.setStatus("");
lostChangeService.updateByPrimaryKeySelective(manifestLoad);
j.setSuccess(true);
message = "修改状态成功";
} catch (Exception e) {
j.setSuccess(false);
message = "修改状态失败";
e.printStackTrace();
}
j.setMsg(message);
return j;
}
/**
* 申报
* @param lost
* @param redirectAttributes
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
@ResponseBody
@RequestMapping(value = "send")
public AjaxJson send(ModelMap model,HttpServletRequest request,@RequestParam Map<String, Object> params) throws IllegalAccessException, InvocationTargetException {
String id = request.getParameter("id");
ManifestLostChange mf = new ManifestLostChange();
DateConvert();//日期转化
BeanUtils.populate(mf, params);
List<ManifestItem> iteamList = itemService.getIteamList(mf.getWaybillnomaster());
List<ConsignmentItem> consignmentItem = new ArrayList<>();
for (ManifestItem manifestItem : iteamList) {
ConsignmentItemPackaging consignmentItemPackaging = new ConsignmentItemPackaging();
consignmentItemPackaging.setQuantityQuantity(manifestItem.getPiece()); //件数
consignmentItemPackaging.setTypeCode(manifestItem.getPackageCode()); //包装代码
GoodsMeasure goodsMeasure = new GoodsMeasure();
goodsMeasure.setGrossMassMeasure(manifestItem.getWeight()); //重量
Commodity commodity = new Commodity();
commodity.setCargoDescription(manifestItem.getDescription());//货物描述
ConsignmentItem item = new ConsignmentItem();
item.setSequenceNumeric(manifestItem.getOrderNumber());//商品序号
item.setConsignmentItemPackaging(consignmentItemPackaging);//包装项信息
item.setGoodsMeasure(goodsMeasure);//货物毛重
item.setCommodity(commodity );
consignmentItem.add(item);
}
String message = null;
AjaxJson j = new AjaxJson();
try {
//保存至sendLog表
Sendlog sendlog = new Sendlog();
sendlog.setAutoid(UUID.randomUUID().toString());
sendlog.setMessageautoid(id);
sendlog.setCreatedate(new Date());
sendlog.setMessagetype("MT8203");
sendlog.setReceiption("发送落装改配申请");
sendLogService.save(sendlog);
//生成报文并发送
ManifestXml manifestXml = new ManifestXml();
HeadXml headXml = new HeadXml();
DeclarationXml declaration = new DeclarationXml();
Consignment consign = new Consignment();
TransportContractDocument transportContractDocument = new TransportContractDocument();
AssociatedTransportDocument associatedTransportDocument = new AssociatedTransportDocument();
TransportContract transportContract= new TransportContract();
AssociatedTransport associatedTransport = new AssociatedTransport();
transportContractDocument.setId(mf.getWaybillnomaster());//改配前主单号
associatedTransportDocument.setId(mf.getWaybillnomaster()+"_"+mf.getWaybillnosecondary()); //改配前分单号
consign.setTransportContractDocument(transportContractDocument);
consign.setAssociatedTransportDocument(associatedTransportDocument);
ChangeConsignment changeConsignment = new ChangeConsignment();
transportContract.setId(mf.getCwaybillnomaster());//改配后主单号
associatedTransport.setId(mf.getCwaybillnomaster()+"_"+mf.getCwaybillnosecondary()); //改配分单号
changeConsignment.setTransportContractDocument(transportContract);
changeConsignment.setAssociatedTransportDocument(associatedTransport);
changeConsignment.setConsignmentItem(consignmentItem);
consign.setChangeConsignment(changeConsignment);
BorderTransportMeans borderTransportMeans = new BorderTransportMeans();
borderTransportMeans.setJourneyID(mf.getFlightno()+"/"+DateUtils.DateToString(mf.getFlightdate(), "yyyy-MM-dd HH:mm:ss").substring(0,10).replace("-", ""));//航次航班
ChangeBorderTransportMeans changeBorderTransportMeans = new ChangeBorderTransportMeans();
changeBorderTransportMeans.setJourneyID(mf.getCflightno()+"/"+DateUtils.DateToString(mf.getCflightdate(), "yyyy-MM-dd HH:mm:ss").substring(0,10).replace("-", ""));//航次航班
declaration.setBorderTransportMeans(borderTransportMeans);
declaration.setChangeBorderTransportMeans(changeBorderTransportMeans );
declaration.setConsignment(consign);
manifestXml.setHeadXml(headXml);
manifestXml.setDeclarationXml(declaration);
XmlGen.genLostChangeXmlAndSend(manifestXml);
j.setSuccess(true);
message = "已发送申报报文";
ManifestLostChange lost = lostChangeService.selectByPrimaryKey(id);
lost.setStatus("01");//已发送
lostChangeService.saveorupdate(lost);
} catch (Exception e) {
j.setSuccess(false);
message = "申报报文发送失败";
e.printStackTrace();
}
j.setMsg(message);
return j;
}
}