Jiaqi.xu

BASF申报接口

1 package com.erry.iclear.dateInterface.api; 1 package com.erry.iclear.dateInterface.api;
2 2
3 +import com.alibaba.fastjson.JSON;
4 +import com.erry.iclear.dateInterface.api.request.BasfConsignment;
3 import com.erry.iclear.dateInterface.api.request.BasfMawb; 5 import com.erry.iclear.dateInterface.api.request.BasfMawb;
4 import com.erry.iclear.dateInterface.api.request.Basfc; 6 import com.erry.iclear.dateInterface.api.request.Basfc;
5 import com.erry.iclear.dateInterface.api.request.ConsignmentCode; 7 import com.erry.iclear.dateInterface.api.request.ConsignmentCode;
8 +import com.erry.iclear.dateInterface.api.response.BasfResultRS;
6 import com.erry.iclear.dateInterface.api.response.ResultRS; 9 import com.erry.iclear.dateInterface.api.response.ResultRS;
7 import com.erry.iclear.dateInterface.entity.DeclaredInfo; 10 import com.erry.iclear.dateInterface.entity.DeclaredInfo;
8 import com.erry.iclear.dateInterface.entity.IClearApiLog; 11 import com.erry.iclear.dateInterface.entity.IClearApiLog;
9 -import com.erry.iclear.dateInterface.service.BasfService; 12 +import com.erry.iclear.dateInterface.service.*;
10 -import com.erry.iclear.dateInterface.service.ChmConsignmentService;
11 -import com.erry.iclear.dateInterface.service.DeclaredInfoService;
12 -import com.erry.iclear.dateInterface.service.IClearApiLogService;
13 import com.erry.iclear.dateInterface.util.StringUtil; 13 import com.erry.iclear.dateInterface.util.StringUtil;
14 import com.google.gson.Gson; 14 import com.google.gson.Gson;
15 import io.swagger.annotations.ApiOperation; 15 import io.swagger.annotations.ApiOperation;
...@@ -42,6 +42,12 @@ public class BasfDataInterface { ...@@ -42,6 +42,12 @@ public class BasfDataInterface {
42 @Autowired 42 @Autowired
43 private DeclaredInfoService declaredInfoService; 43 private DeclaredInfoService declaredInfoService;
44 44
45 + @Autowired
46 + private BasfConsignmentService basfConsignmentService;
47 +
48 + @Autowired
49 + private DeclearTaskService declearTaskService;
50 +
45 @ApiOperation(value = "BASF推送运单数据", httpMethod = "POST", notes = "ex: http://192.168.1.75:8080/customs/sendMawbBasf") 51 @ApiOperation(value = "BASF推送运单数据", httpMethod = "POST", notes = "ex: http://192.168.1.75:8080/customs/sendMawbBasf")
46 @PostMapping("/sendMawbBasf") 52 @PostMapping("/sendMawbBasf")
47 @ResponseBody 53 @ResponseBody
...@@ -134,10 +140,10 @@ public class BasfDataInterface { ...@@ -134,10 +140,10 @@ public class BasfDataInterface {
134 @ApiOperation(value = "BASF获取申报信息", httpMethod = "POST", notes = "ex: http://192.168.1.75:8080/customs/selectDecListBasf") 140 @ApiOperation(value = "BASF获取申报信息", httpMethod = "POST", notes = "ex: http://192.168.1.75:8080/customs/selectDecListBasf")
135 @PostMapping("/selectDecListBasf") 141 @PostMapping("/selectDecListBasf")
136 @ResponseBody 142 @ResponseBody
137 - public ResultRS selectDecListBasf(HttpServletRequest request 143 + public BasfResultRS selectDecListBasf(HttpServletRequest request
138 - , @Validated @RequestBody ConsignmentCode consignmentCode) { 144 + , @Validated @RequestBody ConsignmentCode consignmentCode) throws Exception {
139 log.info("接收到请求数据consignmentCode:"+consignmentCode.getConsignmentCode()+" data:" + gson.toJson(consignmentCode)); 145 log.info("接收到请求数据consignmentCode:"+consignmentCode.getConsignmentCode()+" data:" + gson.toJson(consignmentCode));
140 - ResultRS result = new ResultRS(Boolean.FALSE,"",""); 146 + BasfResultRS result = new BasfResultRS(Boolean.FALSE,"","","");
141 //获取请求的运单号 147 //获取请求的运单号
142 String[] splitConsignment = StringUtil.split(consignmentCode.getConsignmentCode(),","); 148 String[] splitConsignment = StringUtil.split(consignmentCode.getConsignmentCode(),",");
143 if(splitConsignment.length > 20){ 149 if(splitConsignment.length > 20){
...@@ -158,20 +164,32 @@ public class BasfDataInterface { ...@@ -158,20 +164,32 @@ public class BasfDataInterface {
158 String timeStamp=(String) request.getHeader("TimeStamp"); 164 String timeStamp=(String) request.getHeader("TimeStamp");
159 //记录请求的运单 165 //记录请求的运单
160 IClearApiLog saveIClearApiLogResult = iClearApiLogService.saveIClearApiLog(iClearApiLogService.convertToIClearApiLogCselect(consignmentCode.getConsignmentCode(),appId,appKey,new Date(Long.valueOf(timeStamp)))); 166 IClearApiLog saveIClearApiLogResult = iClearApiLogService.saveIClearApiLog(iClearApiLogService.convertToIClearApiLogCselect(consignmentCode.getConsignmentCode(),appId,appKey,new Date(Long.valueOf(timeStamp))));
161 - //日志的ID放入到回执日志中对应
162 - saveIClearApiLogResult.getMsgId();
163 -
164 //查询请求需要得运单申报信息 167 //查询请求需要得运单申报信息
165 List<DeclaredInfo> declaredInfos = declaredInfoService.selectDeclaredInfo(splitConsignment); 168 List<DeclaredInfo> declaredInfos = declaredInfoService.selectDeclaredInfo(splitConsignment);
166 - if(declaredInfos.size()>0){ 169 + //构造返回数据
167 - for (int i= 0;i<declaredInfos.size();i++){ 170 + List<BasfConsignment> basfConsignments = basfConsignmentService.basfConsignmentList(declaredInfos);
168 -
169 - }
170 - }
171 //返回申报数据 171 //返回申报数据
172 + if(basfConsignments.size() > 0){
173 + result.setSuccess(Boolean.TRUE);
174 + result.setConsignmentList(JSON.toJSONString(basfConsignments));
175 + result.setMsg("操作成功!");
176 + }else{
177 + result.setSuccess(Boolean.TRUE);
178 + result.setMsg("操作成功,无申报数据!");
179 + }
172 //更新记录的请求信息 180 //更新记录的请求信息
173 - //记录返回得申报数据记录 181 + if(!Objects.equals(saveIClearApiLogResult,null)){
174 - 182 + saveIClearApiLogResult.setReceiveResult(result.getSuccess().toString());
183 + saveIClearApiLogResult.setErrorCode(result.getCode());
184 + saveIClearApiLogResult.setResponseTime(new Date());
185 + saveIClearApiLogResult.setSpendTime(sw.getTotalTimeMillis());
186 + iClearApiLogService.updateIClearApiLog(saveIClearApiLogResult);
187 + }
188 + //记录返回的申报数据记录
189 + if(result.getSuccess()){
190 + declearTaskService.insertDeclareTask(basfConsignments, saveIClearApiLogResult.getMsgId());
191 + }
192 + log.info("BASF申报数据请求成功!");
175 //6、return result 193 //6、return result
176 result.setSuccess(Boolean.TRUE); 194 result.setSuccess(Boolean.TRUE);
177 result.setCode("0"); 195 result.setCode("0");
......
1 +package com.erry.iclear.dateInterface.api.request;
2 +
3 +import java.io.Serializable;
4 +import java.util.List;
5 +
6 +/**
7 + * BASF申报数据构造 2021年11月9日 xjq
8 + */
9 +public class BasfConsignment implements Serializable {
10 + /**
11 + * 运单号
12 + */
13 + private String consignmnentCode;
14 + /**
15 + * 运单ID
16 + */
17 + private Long consignmentId;
18 + /**
19 + * 运单类型
20 + */
21 + private String consType;
22 + /**
23 + * 发件人(生产核销单位)名称
24 + */
25 + private String sender;
26 + /**
27 + * 发件人(生产核销单位)海关编码
28 + */
29 + private String shipperCustomsCode;
30 + /**
31 + * 发件人(生产核销单位)社会信用证代码
32 + */
33 + private String shipperSCC;
34 + /**
35 + * 经营单位(境内发货人)
36 + */
37 + private String operateUnitName;
38 + /**
39 + * 经营单位(境内发货人)海关编码
40 + */
41 + private String operateUnitCode;
42 + /**
43 + * 经营单位(境内发货人)社会信用证代码
44 + */
45 + private String operateSCC;
46 +
47 + /**
48 + * 运单明细(最多20条明细)
49 + */
50 + private List<ConsignmentDetail> ConsignmentList;
51 +
52 + public String getConsignmnentCode() {
53 + return consignmnentCode;
54 + }
55 +
56 + public void setConsignmnentCode(String consignmnentCode) {
57 + this.consignmnentCode = consignmnentCode;
58 + }
59 +
60 + public Long getConsignmentId() {
61 + return consignmentId;
62 + }
63 +
64 + public void setConsignmentId(Long consignmentId) {
65 + this.consignmentId = consignmentId;
66 + }
67 +
68 + public String getConsType() {
69 + return consType;
70 + }
71 +
72 + public void setConsType(String consType) {
73 + this.consType = consType;
74 + }
75 +
76 + public String getSender() {
77 + return sender;
78 + }
79 +
80 + public void setSender(String sender) {
81 + this.sender = sender;
82 + }
83 +
84 + public String getShipperCustomsCode() {
85 + return shipperCustomsCode;
86 + }
87 +
88 + public void setShipperCustomsCode(String shipperCustomsCode) {
89 + this.shipperCustomsCode = shipperCustomsCode;
90 + }
91 +
92 + public String getShipperSCC() {
93 + return shipperSCC;
94 + }
95 +
96 + public void setShipperSCC(String shipperSCC) {
97 + this.shipperSCC = shipperSCC;
98 + }
99 +
100 + public String getOperateUnitName() {
101 + return operateUnitName;
102 + }
103 +
104 + public void setOperateUnitName(String operateUnitName) {
105 + this.operateUnitName = operateUnitName;
106 + }
107 +
108 + public String getOperateUnitCode() {
109 + return operateUnitCode;
110 + }
111 +
112 + public void setOperateUnitCode(String operateUnitCode) {
113 + this.operateUnitCode = operateUnitCode;
114 + }
115 +
116 + public String getOperateSCC() {
117 + return operateSCC;
118 + }
119 +
120 + public void setOperateSCC(String operateSCC) {
121 + this.operateSCC = operateSCC;
122 + }
123 +
124 + public List<ConsignmentDetail> getConsignmentList() {
125 + return ConsignmentList;
126 + }
127 +
128 + public void setConsignmentList(List<ConsignmentDetail> consignmentList) {
129 + ConsignmentList = consignmentList;
130 + }
131 +}
1 +package com.erry.iclear.dateInterface.api.request;
2 +
3 +import java.io.Serializable;
4 +import java.math.BigDecimal;
5 +
6 +public class ConsignmentDetail implements Serializable {
7 + /**
8 + * 商品编号
9 + */
10 + private String skuCode;
11 + /**
12 + * 品名
13 + */
14 + private String skuName;
15 + /**
16 + * 规格型号
17 + */
18 + private String model;
19 + /**
20 + * 成交数量
21 + */
22 + private BigDecimal knockdownNumber;
23 + /**
24 + * 成交单位
25 + */
26 + private String knockdownUnit;
27 + /**
28 + * 第一(法定)数量
29 + */
30 + private BigDecimal qtyLegalFirst;
31 + /**
32 + * 第一(法定)计量单位
33 + */
34 + private String unitLegalFirst;
35 + /**
36 + * 第二(法定)数量
37 + */
38 + private BigDecimal qtyLegalSecond;
39 + /**
40 + * 第二(法定)计量单位
41 + */
42 + private String unitLegalSecond;
43 + /**
44 + * 申报金额
45 + */
46 + private BigDecimal declaredAmount;
47 + /**
48 + * 币制
49 + */
50 + private String currency;
51 + /**
52 + * 申报重量
53 + */
54 + private BigDecimal declaredWeight;
55 +
56 + public String getSkuCode() {
57 + return skuCode;
58 + }
59 +
60 + public void setSkuCode(String skuCode) {
61 + this.skuCode = skuCode;
62 + }
63 +
64 + public String getSkuName() {
65 + return skuName;
66 + }
67 +
68 + public void setSkuName(String skuName) {
69 + this.skuName = skuName;
70 + }
71 +
72 + public String getModel() {
73 + return model;
74 + }
75 +
76 + public void setModel(String model) {
77 + this.model = model;
78 + }
79 +
80 + public BigDecimal getKnockdownNumber() {
81 + return knockdownNumber;
82 + }
83 +
84 + public void setKnockdownNumber(BigDecimal knockdownNumber) {
85 + this.knockdownNumber = knockdownNumber;
86 + }
87 +
88 + public String getKnockdownUnit() {
89 + return knockdownUnit;
90 + }
91 +
92 + public void setKnockdownUnit(String knockdownUnit) {
93 + this.knockdownUnit = knockdownUnit;
94 + }
95 +
96 + public BigDecimal getQtyLegalFirst() {
97 + return qtyLegalFirst;
98 + }
99 +
100 + public void setQtyLegalFirst(BigDecimal qtyLegalFirst) {
101 + this.qtyLegalFirst = qtyLegalFirst;
102 + }
103 +
104 + public String getUnitLegalFirst() {
105 + return unitLegalFirst;
106 + }
107 +
108 + public void setUnitLegalFirst(String unitLegalFirst) {
109 + this.unitLegalFirst = unitLegalFirst;
110 + }
111 +
112 + public BigDecimal getQtyLegalSecond() {
113 + return qtyLegalSecond;
114 + }
115 +
116 + public void setQtyLegalSecond(BigDecimal qtyLegalSecond) {
117 + this.qtyLegalSecond = qtyLegalSecond;
118 + }
119 +
120 + public String getUnitLegalSecond() {
121 + return unitLegalSecond;
122 + }
123 +
124 + public void setUnitLegalSecond(String unitLegalSecond) {
125 + this.unitLegalSecond = unitLegalSecond;
126 + }
127 +
128 + public BigDecimal getDeclaredAmount() {
129 + return declaredAmount;
130 + }
131 +
132 + public void setDeclaredAmount(BigDecimal declaredAmount) {
133 + this.declaredAmount = declaredAmount;
134 + }
135 +
136 + public String getCurrency() {
137 + return currency;
138 + }
139 +
140 + public void setCurrency(String currency) {
141 + this.currency = currency;
142 + }
143 +
144 + public BigDecimal getDeclaredWeight() {
145 + return declaredWeight;
146 + }
147 +
148 + public void setDeclaredWeight(BigDecimal declaredWeight) {
149 + this.declaredWeight = declaredWeight;
150 + }
151 +}
1 +package com.erry.iclear.dateInterface.api.response;
2 +
3 +import lombok.AllArgsConstructor;
4 +import lombok.Data;
5 +
6 +import java.io.Serializable;
7 +
8 +/**
9 + * @author Administrator
10 + */
11 +@Data
12 +@AllArgsConstructor
13 +public class BasfResultRS implements Serializable {
14 +
15 + //成功标识
16 + private Boolean success = true;
17 + private String code;
18 +
19 + //错误信息
20 + private String msg;
21 + //Object data;
22 + private String consignmentList;
23 +
24 +}
...@@ -65,4 +65,7 @@ public class DeclearTask implements Serializable { ...@@ -65,4 +65,7 @@ public class DeclearTask implements Serializable {
65 65
66 @Column(name = "RESPONSE_CONTENT") 66 @Column(name = "RESPONSE_CONTENT")
67 private String responseContent; 67 private String responseContent;
68 +
69 + @Column(name = "DECELEAR_INFO_ID")
70 + private String decelearInfoId;
68 } 71 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -20,6 +20,6 @@ public interface DeclaredInfoRepository extends JpaRepository<DeclaredInfo, Inte ...@@ -20,6 +20,6 @@ public interface DeclaredInfoRepository extends JpaRepository<DeclaredInfo, Inte
20 * 根据运单号在申报数据表中查询数据 20 * 根据运单号在申报数据表中查询数据
21 * @return 21 * @return
22 */ 22 */
23 - @Query(nativeQuery = true, value = "select * from T_DECLARED_INFO where CONSIGNMENT_ID IN (SELECT * FROM T_CHM_CONSIGNMENT WHERE T_CHM_CONSIGNMENT.CONSIGNMENT_CODE IN ?1)") 23 + @Query(nativeQuery = true, value = "select * from T_DECLARED_INFO where CONSIGNMENT_ID IN (SELECT MAX(ID)AS ID FROM T_CHM_CONSIGNMENT WHERE CONSIGNMENT_CODE IN ?1 group by CONSIGNMENT_CODE)")
24 public List<DeclaredInfo> getDeclaredInfoByAll(List<String> consignmentCodeList); 24 public List<DeclaredInfo> getDeclaredInfoByAll(List<String> consignmentCodeList);
25 } 25 }
......
1 +package com.erry.iclear.dateInterface.service;
2 +
3 +import com.erry.iclear.dateInterface.api.request.BasfConsignment;
4 +import com.erry.iclear.dateInterface.api.request.ConsignmentDetail;
5 +import com.erry.iclear.dateInterface.entity.DeclaredInfo;
6 +import org.springframework.stereotype.Service;
7 +
8 +import java.util.ArrayList;
9 +import java.util.List;
10 +
11 +@Service
12 +public class BasfConsignmentService {
13 +
14 + public List<BasfConsignment> basfConsignmentList(List<DeclaredInfo> consignment){
15 + List<BasfConsignment> basfConsignmentList = new ArrayList<>();
16 + try{
17 + if(consignment.size()>0){
18 + String consignmentCode = null;
19 +
20 + List<ConsignmentDetail> consignmentDetails = new ArrayList<>();
21 + BasfConsignment basfConsignment = new BasfConsignment();
22 + for (DeclaredInfo declaredInfo : consignment){
23 + if(!declaredInfo.getConsignmentCode().equals(consignmentCode)) {
24 + if(consignmentCode != null){
25 + basfConsignment.setConsignmentList(consignmentDetails);
26 + consignmentDetails = new ArrayList<>();
27 + basfConsignmentList.add(basfConsignment);
28 + basfConsignment = new BasfConsignment();
29 + }
30 + consignmentCode = declaredInfo.getConsignmentCode();
31 + basfConsignment.setConsignmnentCode(declaredInfo.getConsignmentCode());
32 + basfConsignment.setConsignmentId(declaredInfo.getConsignmentId());
33 + basfConsignment.setConsType(declaredInfo.getConsType());
34 + basfConsignment.setOperateUnitName(declaredInfo.getOperateUnitName());
35 + basfConsignment.setOperateUnitCode(declaredInfo.getOperateUnitCode());
36 + basfConsignment.setOperateSCC(declaredInfo.getTradeCoSCC());
37 + basfConsignment.setSender(declaredInfo.getSender());
38 + basfConsignment.setShipperCustomsCode(declaredInfo.getOwnerCode());
39 + basfConsignment.setShipperSCC(declaredInfo.getOwnerCodeScc());
40 + }
41 + ConsignmentDetail consignmentDetail = new ConsignmentDetail();
42 + consignmentDetail.setSkuCode(declaredInfo.getSkuCode());
43 + consignmentDetail.setSkuName(declaredInfo.getModel().substring(declaredInfo.getModel().indexOf(":")+1,declaredInfo.getModel().indexOf("|")));
44 + String[] models = declaredInfo.getModel().split("\\|");
45 + String mdoel = "";
46 + for(int i = 1; i < models.length; i++){
47 + mdoel += models[i].substring(models[i].indexOf(":")+1)+"|";
48 + }
49 + consignmentDetail.setModel(mdoel);
50 + consignmentDetail.setKnockdownNumber(declaredInfo.getKnockdownNumber());
51 + consignmentDetail.setKnockdownUnit(declaredInfo.getKnockdownUnitDic().getExt2());
52 + consignmentDetail.setQtyLegalFirst(declaredInfo.getQtyLegalFirst());
53 + consignmentDetail.setUnitLegalFirst(declaredInfo.getUnitLegalFirstDic().getExt2());
54 + consignmentDetail.setQtyLegalSecond(declaredInfo.getQtyLegalSecond());
55 + consignmentDetail.setUnitLegalSecond(declaredInfo.getUnitLegalSecondDic() == null ? null : declaredInfo.getUnitLegalSecondDic().getExt2());
56 + consignmentDetail.setDeclaredAmount(declaredInfo.getDeclaredAmount());
57 + consignmentDetail.setCurrency(declaredInfo.getCurrencyDic().getExt2());
58 + consignmentDetail.setDeclaredWeight(declaredInfo.getDeclaredWeight());
59 + consignmentDetails.add(consignmentDetail);
60 + }
61 + basfConsignment.setConsignmentList(consignmentDetails);
62 + basfConsignmentList.add(basfConsignment);
63 + }
64 + }catch (Exception e){
65 + e.printStackTrace();
66 + }
67 + return basfConsignmentList;
68 + }
69 +}
1 +package com.erry.iclear.dateInterface.service;
2 +
3 +import com.erry.iclear.dateInterface.api.request.BasfConsignment;
4 +import com.erry.iclear.dateInterface.common.BaseModel;
5 +import com.erry.iclear.dateInterface.entity.ChmConsignment;
6 +import com.erry.iclear.dateInterface.entity.DeclearTask;
7 +import com.erry.iclear.dateInterface.repository.DeclearTaskRepository;
8 +import com.erry.iclear.dateInterface.util.StringUtil;
9 +import lombok.extern.slf4j.Slf4j;
10 +import org.springframework.beans.factory.annotation.Autowired;
11 +import org.springframework.stereotype.Service;
12 +
13 +import javax.transaction.Transactional;
14 +import java.math.BigDecimal;
15 +import java.util.ArrayList;
16 +import java.util.Date;
17 +import java.util.List;
18 +
19 +/**
20 + * xjq 2021年11月11日
21 + */
22 +@Service
23 +@Slf4j
24 +@Transactional(rollbackOn = Exception.class)
25 +public class DeclearTaskService{
26 +
27 + @Autowired
28 + private DeclearTaskRepository declareTaskRepository;
29 +
30 + public void insertDeclareTask(List<BasfConsignment> basfConsignments, Long logId) throws Exception {
31 + List<DeclearTask> declareTaskList = new ArrayList<>();
32 + try{
33 + if (basfConsignments.size()>0){
34 + for (BasfConsignment basfConsignment : basfConsignments) {
35 + DeclearTask declareTask = new DeclearTask();
36 + declareTask.setChmsignmentId(BigDecimal.valueOf(basfConsignment.getConsignmentId()));
37 + declareTask.setChmsignmentCode(basfConsignment.getConsignmnentCode());
38 + declareTask.setOperationTime(new Date());
39 + declareTask.setFileType("1");
40 + declareTask.setOperationName("root");
41 + declareTask.setDataSource(String.valueOf(3));
42 + declareTask.setResponseTime(new Date());
43 + declareTask.setResponseResults("true");
44 + declareTask.setDecelearInfoId(String.valueOf(logId));
45 + declareTaskList.add(declareTask);
46 + }
47 + declareTaskRepository.saveAll(declareTaskList);
48 + }
49 + }catch (Exception e){
50 + e.printStackTrace();
51 + }
52 +
53 + }
54 +}