作者 shenhailong

生成报文 预配 新增修改删除 海关备案编码 企业代码 tcs 编码

... ... @@ -131,5 +131,10 @@ jwt:
max-alive: 300
custom:
send-path: ./send/
#海关备案编码
custom-code: 460470678920X
org-code: 9141010070678920XJ
tcs:
mq-number: DXPENT0000460002
... ...
... ... @@ -3,10 +3,7 @@ package com.sunyo.wlpt.message.builder.controller;
import com.sunyo.wlpt.message.builder.service.MT2201Service;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.Map;
... ... @@ -23,14 +20,28 @@ public class MT2201Controller {
* @param map
* @return
*/
@RequestMapping("/creatMt2201")
@PostMapping("/creatMt2201")
@ApiOperation(value = "生成报文")
@ResponseBody
public int creatMt2201(@RequestBody Map<String, Object> map) throws IOException {
int i = mt2201Service.creatMt2201(map);
return mt2201Service.creatMt2201(map);
}
@PutMapping("/editMt2201")
@ApiOperation(value = "修改报文")
@ResponseBody
public int editMt2201(@RequestBody Map<String, Object> map) throws IOException {
return mt2201Service.editMt2201(map);
}
@PutMapping("/removeMt2201")
@ApiOperation(value = "删除报文")
@ResponseBody
public int removeMt2201(@RequestBody Map<String, Object> map) throws IOException {
return i;
return mt2201Service.removeMt2201(map);
}
}
... ...
... ... @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.Map;
... ... @@ -17,16 +18,10 @@ public class MT4201Controller {
MT4201Service mt4201Service;
@RequestMapping("/4201create")
public Boolean pffmcreate(@RequestBody Map<String, Object> map){
try {
@RequestMapping("/create4201")
public int pffmcreate(@RequestBody Map<String, Object> map) throws IOException {
return mt4201Service.pffmcreate(map);
}catch (Exception e){
e.printStackTrace();
return false;
}
}
... ...
package com.sunyo.wlpt.message.builder.service;
import com.sunyo.wlpt.base.model.NMMS_CUSTOM_MT2201;
import org.omg.CORBA.OBJECT_NOT_EXIST;
import java.io.IOException;
import java.util.Map;
... ... @@ -21,4 +22,8 @@ public interface MT2201Service {
int creatMt2201(Map<String, Object> map) throws IOException;
int editMt2201(Map<String, Object> map) throws IOException;
int removeMt2201(Map<String, Object> map) throws IOException;
}
... ...
... ... @@ -5,6 +5,6 @@ import java.util.Map;
public interface MT4201Service {
Boolean pffmcreate(Map<String, Object> map) throws IOException;
int pffmcreate(Map<String, Object> map) throws IOException;
}
... ...
... ... @@ -45,10 +45,11 @@ public class MT1201ServiceImp extends CustomXmlMaker implements MT1201Service{
hashMap.put("msessageType", msessageType);
hashMap.put("senderId", senderId);
hashMap.put("receiverID", receiverID);
if (makeXmlToFile("/manifest/MT5201.ftlx", msgId+".xml", hashMap)>0){
return 200;
}else {
return 201;
}
// if (makeXmlToFile("/manifest/MT5201.ftlx", msgId+".xml", hashMap)>0){
// return 200;
// }else {
// return 201;
// }
return 0;
}
}
... ...
... ... @@ -8,6 +8,7 @@ import com.sunyo.wlpt.base.model.NMMS_CUSTOM_MT4201;
import com.sunyo.wlpt.message.builder.service.MT2201Service;
import com.sunyo.wlpt.message.builder.util.CustomXmlMaker;
import com.tianbo.util.Date.DateUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;
... ... @@ -47,9 +48,53 @@ public class MT2201ServiceImp extends CustomXmlMaker implements MT2201Service {
return 0;
}
@Value("${custom.custom-code}")
private String customCode;
@Value("${custom.org-code}")
private String orgCode;
@Override
public int creatMt2201(Map<String, Object> map) throws IOException{
map.put("templatePath", "/manifest/MT2201.ftlx");
map.put("sendPath", "./send/add/");
return mt2201(map);
}
@Override
public int editMt2201(Map<String, Object> map) throws IOException {
map.put("templatePath", "/edit/MT2201.ftlx");
map.put("sendPath", "./send/edit/");
return mt2201(map);
}
@Override
public int removeMt2201(Map<String, Object> map) throws IOException {
String customCode = map.get("customCode").toString();
// 生成报文头部
String msgId = makeMsgID("MT2201", customCode, map.get("awba").toString());
String msessageType = "MT2201";
String senderId = makeSenderID(customCode, customCode, "");
String receiverID = customCode;
map.put("msgId", msgId);
map.put("msessageType", msessageType);
map.put("senderId", senderId);
map.put("receiverID", receiverID);
// 报文头时间 精确到毫秒
map.put("sendTime", DateUtil.getCurrentTime17());
// 舱单传输人名称
map.put("orgCode", orgCode);
// 生成报文
if (makeXmlToFile("/remove/MT2201.ftlx", msgId+".xml", map, "./send/remove/")>0){
return 1;
}else {
return 0;
}
}
public int mt2201(Map<String, Object> map) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
// 预配
NMMS_CUSTOM_MT2201 custom_mt2201 = objectMapper.convertValue(map.get("mt2201"), NMMS_CUSTOM_MT2201.class);
... ... @@ -63,19 +108,21 @@ public class MT2201ServiceImp extends CustomXmlMaker implements MT2201Service {
map.put("mt", custom_mt2201);
map.put("awbAwbinfo", awbAwbinfo);
// 生成报文头部
String msgId = makeMsgID("MT2201", "460470678920X", custom_mt2201.getAwba());
String msgId = makeMsgID("MT2201", customCode, custom_mt2201.getAwba());
String msessageType = "MT2201";
String senderId = makeSenderID(customCode, "460470678920X", "DXPENT0000460002");
String senderId = makeSenderID(customCode, customCode, "");
String receiverID = customCode;
map.put("msgId", msgId);
map.put("msessageType", msessageType);
map.put("senderId", senderId);
map.put("receiverID", receiverID);
// 舱单传输人名称
map.put("orgCode", orgCode);
// 生成报文
if (makeXmlToFile("/manifest/MT2201.ftlx", msgId+".xml", map)>0){
return 200;
if (makeXmlToFile(map.get("templatePath").toString(), msgId+".xml", map, map.get("sendPath").toString())>0){
return 1;
}else {
return 201;
return 0;
}
}
}
... ...
... ... @@ -39,11 +39,12 @@ public class MT3201ServiceImp extends CustomXmlMaker implements MT3201Service {
map.put("msessageType", msessageType);
map.put("senderId", senderId);
map.put("receiverID", receiverID);
if (makeXmlToFile("/manifest/MT3201.ftlx", msgId+".xml", map)>0){
return true;
}else {
return false;
}
// if (makeXmlToFile("/manifest/MT3201.ftlx", msgId+".xml", map)>0){
// return true;
// }else {
// return false;
// }
return null;
}
}
... ...
... ... @@ -14,7 +14,7 @@ import java.util.Map;
public class MT4201ServiceImp extends CustomXmlMaker implements MT4201Service {
@Override
public Boolean pffmcreate(Map<String, Object> map) throws IOException {
public int pffmcreate(Map<String, Object> map) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
... ... @@ -23,6 +23,7 @@ public class MT4201ServiceImp extends CustomXmlMaker implements MT4201Service {
// 关区代码
String customCode = customMt4201.getCustomcode();
// 报文头时间 精确到毫秒
map.put("sendTime", DateUtil.getCurrentTime17());
// 封装实体
... ... @@ -37,10 +38,10 @@ public class MT4201ServiceImp extends CustomXmlMaker implements MT4201Service {
map.put("msessageType", msessageType);
map.put("senderId", senderId);
map.put("receiverID", receiverID);
if (makeXmlToFile("/manifest/MT4201.ftlx", msgId+".xml", map)>0){
return true;
if (makeXmlToFile("/manifest/MT4201.ftlx", msgId+".xml", map, "./send/add/")>0){
return 1;
}else {
return false;
return 0;
}
}
}
... ...
... ... @@ -43,11 +43,11 @@ public class MT520XServiceImp extends CustomXmlMaker implements MT520XService{
hashMap.put("msessageType", msessageType);
hashMap.put("senderId", senderId);
hashMap.put("receiverID", receiverID);
if (makeXmlToFile("/manifest/MT5201.ftlx", msgId+".xml", hashMap)>0){
return true;
}else {
return false;
}
// if (makeXmlToFile("/manifest/MT5201.ftlx", msgId+".xml", hashMap)>0){
// return true;
// }else {
// return false;
// }
}else {
// 生成报文头部
... ... @@ -59,16 +59,17 @@ public class MT520XServiceImp extends CustomXmlMaker implements MT520XService{
hashMap.put("msessageType", msessageType);
hashMap.put("senderId", senderId);
hashMap.put("receiverID", receiverID);
if (makeXmlToFile("/manifest/MT5202.ftlx", msgId+".xml", hashMap)>0){
return true;
}else {
return false;
}
// if (makeXmlToFile("/manifest/MT5202.ftlx", msgId+".xml", hashMap)>0){
// return true;
// }else {
// return false;
// }
}
}catch (Exception e){
e.printStackTrace();
return false;
}
return null;
}
}
... ...
... ... @@ -47,10 +47,11 @@ public class MT8205ServiceImp extends CustomXmlMaker implements MT8205Service {
map.put("senderId", senderId);
map.put("receiverID", receiverID);
if (makeXmlToFile("/manifest/MT8205.ftlx", msgId+".xml", map)>0){
return true;
}else {
return false;
}
// if (makeXmlToFile("/manifest/MT8205.ftlx", msgId+".xml", map)>0){
// return true;
// }else {
// return false;
// }
return null;
}
}
... ...
... ... @@ -19,10 +19,10 @@ public class CustomXmlMaker {
private Configuration freemakerTemplate;
@Value("${custom.send-path}")
private static String sendPath;
private String sendPath;
@Value("${tcs.mq-number}")
private static String TCSMQNumber;
private String TCSMQNumber;
public CustomXmlMaker() {
if (freemakerTemplate==null){
... ... @@ -36,10 +36,11 @@ public class CustomXmlMaker {
* @param tplName 模板名称
* @param fileName 生成的报文名称
* @param manifestMap 数据实体
* @param sendPath 生成路径
* @return 0失败,1成功
* @throws IOException
*/
public int makeXmlToFile(String tplName,String fileName,Object manifestMap) throws IOException{
public int makeXmlToFile(String tplName,String fileName,Object manifestMap, String sendPath) throws IOException{
try {
Template template = freemakerTemplate.getTemplate(tplName);
String content = FreeMarkerTemplateUtils.processTemplateIntoString(template,manifestMap);
... ... @@ -96,7 +97,7 @@ public class CustomXmlMaker {
sb.append(customCode)
.append(ORGSN)
.append("_")
.append(TCSSN);
.append(TCSMQNumber);
return sb.toString();
}
public String makeSenderID(String customCode,String ORGSN){
... ...
<?xml version="1.0" encoding="utf-8"?>
<Manifest xmlns="urn:Declaration:datamodel:standard:CN:MT2201:1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Head>
<MessageID>${msgId}</MessageID>
<FunctionCode>5</FunctionCode>
<MessageType>${msessageType}</MessageType>
<SenderID>${senderId}</SenderID>
<ReceiverID>${receiverID}</ReceiverID>
<SendTime>${sendTime}</SendTime>
<Version>1.0</Version>
</Head>
<Declaration>
<RepresentativePerson>
<Name>${orgCode}</Name>
</RepresentativePerson>
<ExitCustomsOffice>
<ID>${mt.originstation}????</ID>
</ExitCustomsOffice>
<Carrier>
<ID>${mt.carrier}</ID>
</Carrier>
<BorderTransportMeans>
<JourneyID>${mt.carrier}${mt.flightno}/${mt.flightdate?string('yyyyMMdd')}</JourneyID>
<TypeCode>4</TypeCode>
</BorderTransportMeans>
<Consignment>
<TransportContractDocument>
<ID>${mt.awba}</ID>
<ChangeReasonCode>9999</ChangeReasonCode>
<ConditionCode>10</ConditionCode>
</TransportContractDocument>
<LoadingLocation>
<ID>${mt.originstation}/${mt.customcode}</ID>
<LoadingDate>202001210605086</LoadingDate>
</LoadingLocation>
<UnloadingLocation>
<ID>${mt.destinationstation}</ID>
</UnloadingLocation>
<TransitDestination>
<ID>$TransitDestination$</ID>
</TransitDestination>
<GoodsConsignedPlace>
<ID>${mt.originstation}</ID>
</GoodsConsignedPlace>
<TransportSplitIndicator>${mt.splitcode}</TransportSplitIndicator>
<FreightPayment>
<MethodCode>${awbAwbinfo.paymodel}</MethodCode>
</FreightPayment>
<ConsignmentPackaging>
<QuantityQuantity>${awbAwbinfo.pcs}</QuantityQuantity>
</ConsignmentPackaging>
<TotalGrossMassMeasure>${awbAwbinfo.weight}</TotalGrossMassMeasure>
<Consignee>
<Name>${awbAwbinfo.cnsnname}</Name>
<Address>
<Line>${awbAwbinfo.cnsnaddress}</Line>
<CountryCode>${awbAwbinfo.cnscountyr}</CountryCode>
</Address>
<Communication>
<ID>${awbAwbinfo.cnsntel}</ID>
</Communication>
</Consignee>
<Consignor>
<Name>${awbAwbinfo.shprname}</Name>
<Address>
<Line>${awbAwbinfo.shpraddress}</Line>
<CityName>$ConsignorCityName$</CityName>
<CountryCode>${awbAwbinfo.shprcountyr}</CountryCode>
</Address>
<Communication>
<ID>${awbAwbinfo.shprtel}</ID>
</Communication>
</Consignor>
<ConsignmentItem>
<SequenceNumeric>1</SequenceNumeric>
<ConsignmentItemPackaging>
<QuantityQuantity>${mt.piece}</QuantityQuantity>
</ConsignmentItemPackaging>
<Commodity>
<CargoDescription>${mt.goodsname}</CargoDescription>
</Commodity>
<GoodsMeasure>
<GrossMassMeasure>${mt.weight}</GrossMassMeasure>
</GoodsMeasure>
</ConsignmentItem>
</Consignment>
<AdditionalInformation>
<Reason>${reason}</Reason>
<ContactName>${contacName}</ContactName>
<ContactTel>${contacTel}</ContactTel>
</AdditionalInformation>
</Declaration>
</Manifest>
\ No newline at end of file
... ...
... ... @@ -10,10 +10,10 @@
</Head>
<Declaration>
<RepresentativePerson>
<Name>舱单书传输人名称</Name>
<Name>${orgCode}</Name>
</RepresentativePerson>
<ExitCustomsOffice>
<ID>${mt.originstation}????</ID>
<ID>${mt.originstation}</ID>
</ExitCustomsOffice>
<Carrier>
<ID>${mt.carrier}</ID>
... ... @@ -54,7 +54,6 @@
</Address>
<Communication>
<ID>${awbAwbinfo.cnsntel}</ID>
<TypeID>${awbAwbinfo.cnsrmobiletype}</TypeID>
</Communication>
</Consignee>
<Consignor>
... ... @@ -65,7 +64,6 @@
</Address>
<Communication>
<ID>${awbAwbinfo.shprtel}</ID>
<TypeID>${awbAwbinfo.shprmobiletype}</TypeID>
</Communication>
</Consignor>
<ConsignmentItem>
... ...
<?xml version="1.0" encoding="utf-8"?>
<Manifest xmlns="urn:Declaration:datamodel:standard:CN:MT2201:1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Head>
<MessageID>${msgId}</MessageID>
<FunctionCode>3</FunctionCode>
<MessageType>${msessageType}</MessageType>
<SenderID>${senderId}</SenderID>
<ReceiverID>${receiverID}</ReceiverID>
<SendTime>${sendTime}</SendTime>
<Version>1.0</Version>
</Head>
<Declaration>
<RepresentativePerson>
<Name>${orgCode}</Name>
</RepresentativePerson>
<BorderTransportMeans>
<JourneyID>${flightNo}</JourneyID>
</BorderTransportMeans>
<Consignment>
<TransportContractDocument>
<ID>${awba}</ID>
<ChangeReasonCode>9999</ChangeReasonCode>
</TransportContractDocument>
</Consignment>
<AdditionalInformation>
<Reason>${reason}</Reason>
<ContactName>${contactName}</ContactName>
<ContactTel>${contactTel}</ContactTel>
<Content>${content}</Content>
</AdditionalInformation>
</Declaration>
</Manifest>
\ No newline at end of file
... ...