Jiaqi.xu

1.BASF回执接口

2.BASF数据落地推送EXP002
3.数据落地返回code
package com.erry.iclear.dateInterface.api;
import com.alibaba.fastjson.JSON;
import com.erry.iclear.dateInterface.api.request.BasfConsignment;
import com.erry.iclear.dateInterface.api.request.BasfMawb;
import com.erry.iclear.dateInterface.api.request.Basfc;
import com.erry.iclear.dateInterface.api.request.ConsignmentCode;
import com.arronlong.httpclientutil.HttpClientUtil;
import com.arronlong.httpclientutil.common.HttpConfig;
import com.arronlong.httpclientutil.common.HttpHeader;
import com.arronlong.httpclientutil.exception.HttpProcessException;
import com.erry.iclear.dateInterface.api.request.*;
import com.erry.iclear.dateInterface.api.response.BasfResultRS;
import com.erry.iclear.dateInterface.api.response.ResultRS;
import com.erry.iclear.dateInterface.entity.ChmConsignment;
import com.erry.iclear.dateInterface.entity.DeclaredInfo;
import com.erry.iclear.dateInterface.entity.IClearApiLog;
import com.erry.iclear.dateInterface.repository.ChmConsignmentRepository;
import com.erry.iclear.dateInterface.service.*;
import com.erry.iclear.dateInterface.util.JsonToJava;
import com.erry.iclear.dateInterface.util.StringUtil;
import com.google.gson.Gson;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Header;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StopWatch;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -48,11 +54,18 @@ public class BasfDataInterface {
@Autowired
private DeclearTaskService declearTaskService;
@Autowired
private ChmConsignmentRepository chmConsignmentRepository;
@Value("${api.address.iclear-submit-url}")
String iclearCSubmitUrl;
@ApiOperation(value = "BASF推送运单数据", httpMethod = "POST", notes = "ex: http://192.168.1.75:8080/customs/sendMawbBasf")
@PostMapping("/sendMawbBasf")
@ResponseBody
public ResultRS sendMawbBasf(HttpServletRequest request
, @Validated @RequestBody Basfc basfc) {
, @Validated @RequestBody Basfc basfc) throws HttpProcessException {
log.info("接收到请求数据consignmentCode:"+basfc.getConsignmentCode()+" data:" + gson.toJson(basfc));
ResultRS result = new ResultRS(Boolean.FALSE,"","");
......@@ -115,6 +128,21 @@ public class BasfDataInterface {
return result;
}
sw.stop();
ChmConsignment chmGetId = chmConsignmentRepository.findChmConsignmentByConsignmentCode(saveIClearApiLogResult.getBillNo(), saveIClearApiLogResult.getCreateTime());
//调用IClear接口进行运单推送EXP002
String objJson = JsonToJava.toJson(chmGetId.getId());
Header[] headers = HttpHeader.custom()
.other("Content-Type", "application/json")
.build();
log.info("******************* : " + this.iclearCSubmitUrl);
//推送海关回执数据
HttpConfig config = HttpConfig.custom()
.headers(headers)
.url(this.iclearCSubmitUrl)
.encoding("utf-8")
.json(objJson);
String json = HttpClientUtil.post(config);
log.info("<<<<<<<< checkbasfMawb start >>>>>>>>>> result :" +result.getSuccess() +" iclear check response : " + json + " status : " + result.getSuccess());
//5、更新日志
......@@ -195,4 +223,64 @@ public class BasfDataInterface {
result.setCode("0");
return result;
}
@ApiOperation(value = "BASF获取回执信息", httpMethod = "POST", notes = "ex: http://192.168.1.75:8080/customs/selectChmListBasf")
@PostMapping("/selectChmListBasf")
@ResponseBody
public BasfResultRS selectChmListBasf(HttpServletRequest request
, @Validated @RequestBody ConsignmentCode consignmentCode) throws Exception {
log.info("接收到请求数据consignmentCode:"+consignmentCode.getConsignmentCode()+" data:" + gson.toJson(consignmentCode));
BasfResultRS result = new BasfResultRS(Boolean.FALSE,"","","");
//获取请求的运单号
String[] splitConsignment = StringUtil.split(consignmentCode.getConsignmentCode(),",");
if(splitConsignment.length > 20){
result.setCode("30001");
result.setMsg("请求信息不能大于20条运单");
return result;
}
if(splitConsignment.length<1){
result.setCode("-7");
result.setMsg("请求信息不能为空");
return result;
}
StopWatch sw = new StopWatch("receice mawbBasf");
sw.start("save log");
String appId=(String) request.getHeader("Appid");
String appKey=(String) request.getHeader("Appkey");
String timeStamp=(String) request.getHeader("TimeStamp");
//记录请求的运单
IClearApiLog saveIClearApiLogResult = iClearApiLogService.saveIClearApiLog(iClearApiLogService.convertToIClearApiLogCselect(consignmentCode.getConsignmentCode(),appId,appKey,new Date(Long.valueOf(timeStamp))));
//查询请求需要得运单申报信息
//List<DeclaredInfo> declaredInfos = declaredInfoService.selectDeclaredInfo(splitConsignment);
List<BasfcReceipt> chmConsignments = chmConsignmentService.getConsignmentCode(splitConsignment);
//构造返回数据
//List<BasfConsignment> basfConsignments = basfConsignmentService.basfConsignmentList(declaredInfos);
//返回申报数据
if(chmConsignments.size() > 0){
result.setSuccess(Boolean.TRUE);
result.setConsignmentList(JSON.toJSONString(chmConsignments));
result.setMsg("操作成功!");
}else{
result.setSuccess(Boolean.TRUE);
result.setMsg("操作成功,无回执数据!");
}
//更新记录的请求信息
if(!Objects.equals(saveIClearApiLogResult,null)){
saveIClearApiLogResult.setReceiveResult(result.getSuccess().toString());
saveIClearApiLogResult.setErrorCode(result.getCode());
saveIClearApiLogResult.setResponseTime(new Date());
saveIClearApiLogResult.setSpendTime(sw.getTotalTimeMillis());
iClearApiLogService.updateIClearApiLog(saveIClearApiLogResult);
}
//记录返回的申报数据记录
if(result.getSuccess()){
declearTaskService.insertChmTask(chmConsignments, saveIClearApiLogResult.getMsgId());
}
log.info("BASF回执数据请求成功!");
//6、return result
result.setSuccess(Boolean.TRUE);
result.setCode("0");
return result;
}
}
......
package com.erry.iclear.dateInterface.api.request;
import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.DictionaryEntries;
import com.erry.iclear.dateInterface.repository.DictionaryEntriesRepository;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.Serializable;
import java.util.Date;
/**
* BASF回执数据构造 xjq 2021年11月16日
*/
public class BasfcReceipt implements Serializable {
@Autowired
private DictionaryEntriesRepository dictionaryEntriesRepository;
/**
* 运单ID
*/
private Long consignmentId;
/**
* 运单号
*/
private String consignmentCode;
/**
* 运单类型
*/
private String consignmentType;
/**
* 回执状态(状态码)
*/
private String customsReceiptStatus;
/**
* 回执状态时间
*/
private Date customsReceiptTime;
public Long getConsignmentId() {
return consignmentId;
}
public void setConsignmentId(Long consignmentId) {
this.consignmentId = consignmentId;
}
public String getConsignmentCode() {
return consignmentCode;
}
public void setConsignmentCode(String consignmentCode) {
this.consignmentCode = consignmentCode;
}
public String getConsignmentType() {
return consignmentType;
}
public void setConsignmentType(String consignmentType) {
/*DictionaryEntries dictionaryEntriesByCode = dictionaryEntriesRepository.findDictionaryEntriesByCode(Constant.consType_C);
if (consignmentType.equals(dictionaryEntriesByCode.getChineseName())){
this.consignmentType = consignmentType;
}*/
this.consignmentType = "C";
}
public String getCustomsReceiptStatus() {
return customsReceiptStatus;
}
public void setCustomsReceiptStatus(String customsReceiptStatus) {
this.customsReceiptStatus = customsReceiptStatus;
}
public Date getCustomsReceiptTime() {
return customsReceiptTime;
}
public void setCustomsReceiptTime(Date customsReceiptTime) {
this.customsReceiptTime = customsReceiptTime;
}
}
......@@ -39,4 +39,12 @@ public interface ChmConsignmentRepository extends JpaSpecificationExecutor<ChmCo
*/
@Query( nativeQuery = true,value ="select * from T_CHM_CONSIGNMENT where ID = ?1 " )
public ChmConsignment findChmConsignmentById(Long id);
/**
* 根据运单号查询最新的运单(回执信息)
*/
@Query( nativeQuery = true,value = "select ID,CONSIGNMENT_CODE,CUSTOMS_RECEIPT,CONS_TYPE,CUSTOMS_RECEIPT_TIME from T_CHM_CONSIGNMENT where ID IN(\n" +
"select MAX(ID)as ID from T_CHM_CONSIGNMENT \n" +
"where CONS_TYPE_ID = ?2 and CUSTOMS_RECEIPT is not null AND CONSIGNMENT_CODE IN ?1 GROUP BY CONSIGNMENT_CODE)")
public List<Object[]> findChmByConsignmentCode(List<String> consignmentCode, Long consTypeId);
}
......
......@@ -20,6 +20,6 @@ public interface DeclaredInfoRepository extends JpaRepository<DeclaredInfo, Inte
* 根据运单号在申报数据表中查询数据
* @return
*/
@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)")
public List<DeclaredInfo> getDeclaredInfoByAll(List<String> consignmentCodeList);
@Query(nativeQuery = true, value = "select * from T_DECLARED_INFO where CONSIGNMENT_ID IN (SELECT MAX(ID)AS ID FROM T_CHM_CONSIGNMENT WHERE T_CHM_CONSIGNMENT.CONS_TYPE_ID = ?2 CONSIGNMENT_CODE IN ?1 group by CONSIGNMENT_CODE)")
public List<DeclaredInfo> getDeclaredInfoByAll(List<String> consignmentCodeList,Long consTypeId);
}
......
......@@ -143,6 +143,7 @@ public class BasfService {
String json = HttpClientUtil.post(config);
IClearCheckResponseResult iclearCheckResponseResult = JsonToJava.parseJson(json, IClearCheckResponseResult.class);
result.setSuccess(iclearCheckResponseResult.getSuccess());
result.setCode(iclearCheckResponseResult.getCode());
result.setMsg(iclearCheckResponseResult.getMessage());
log.info("<<<<<<<< checkMawb start >>>>>>>>>> mawb:"+gson.toJson(basfMawb) +" result :" +result.getSuccess() +" iclear check response : " + json + " status : " + result.getSuccess());
}catch (Exception e){
......
......@@ -2,6 +2,7 @@ package com.erry.iclear.dateInterface.service;
//import cn.hutool.core.date.DateUtil;
import com.erry.iclear.dateInterface.api.request.BasfMawb;
import com.erry.iclear.dateInterface.api.request.BasfcReceipt;
import com.erry.iclear.dateInterface.api.request.Mawb;
import com.erry.iclear.dateInterface.api.response.ResultRS;
import com.erry.iclear.dateInterface.common.Constant;
......@@ -20,6 +21,8 @@ import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -42,6 +45,9 @@ public class ChmConsignmentService {
@Autowired
private DictionaryEntriesRepository dictionaryEntriesRepository;
@Autowired
private DeclaredInfoService declaredInfoService;
/**
* 转换主单
* @return
......@@ -624,4 +630,28 @@ public class ChmConsignmentService {
result.setSuccess(Boolean.TRUE);
return result;
}
public List<BasfcReceipt> getConsignmentCode(String[] consignmentCode) throws ParseException {
DictionaryEntries consTypeC = dictionaryEntriesRepository.findDictionaryEntriesByCode(Constant.consType_C);
List<String> stringList = declaredInfoService.stringList(consignmentCode);
List<Object[]> chmByConsignmentCode = chmConsignmentRepository.findChmByConsignmentCode(stringList, consTypeC.getId());
List<BasfcReceipt> basfcReceiptList = new ArrayList<>();
if(chmByConsignmentCode.size()>0){
for (int i = 0; i < chmByConsignmentCode.size(); i++) {
Object[] objs = chmByConsignmentCode.get(i);
BasfcReceipt basfcReceipt = new BasfcReceipt();
basfcReceipt.setConsignmentId(Long.valueOf(objs[0].toString()));
basfcReceipt.setConsignmentCode(objs[1].toString());
basfcReceipt.setConsignmentType("C");
basfcReceipt.setCustomsReceiptStatus(objs[2].toString());
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
String str = objs[4].toString();
System.out.println(str);
Date date = sdf.parse(objs[4].toString());
basfcReceipt.setCustomsReceiptTime(date);
basfcReceiptList.add(basfcReceipt);
}
}
return basfcReceiptList;
}
}
......
package com.erry.iclear.dateInterface.service;
import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.DeclaredInfo;
import com.erry.iclear.dateInterface.entity.DictionaryEntries;
import com.erry.iclear.dateInterface.repository.DeclaredInfoRepository;
import com.erry.iclear.dateInterface.repository.DictionaryEntriesRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -21,16 +24,25 @@ public class DeclaredInfoService {
@Autowired
private DeclaredInfoRepository declaredInfoRepository;
@Autowired
private DictionaryEntriesRepository dictionaryEntriesRepository;
public List<DeclaredInfo> selectDeclaredInfo(String[] consignmentCode){
List<DeclaredInfo> DeclaredInfo = new ArrayList<>();
DictionaryEntries consTypeC = dictionaryEntriesRepository.findDictionaryEntriesByCode(Constant.consType_C);
List<String> consignmentCodeList = stringList(consignmentCode);
DeclaredInfo = declaredInfoRepository.getDeclaredInfoByAll(consignmentCodeList,consTypeC.getId());
return DeclaredInfo;
}
public List<String> stringList(String[] consignmentCode){
List consignmentCodeList = new ArrayList();
if(consignmentCode.length>0){
for(int i = 0; i < consignmentCode.length; i++){
consignmentCodeList.add(consignmentCode[i]);
}
}
DeclaredInfo = declaredInfoRepository.getDeclaredInfoByAll(consignmentCodeList);
return DeclaredInfo;
return consignmentCodeList;
}
}
......
package com.erry.iclear.dateInterface.service;
import com.erry.iclear.dateInterface.api.request.BasfConsignment;
import com.erry.iclear.dateInterface.api.request.BasfcReceipt;
import com.erry.iclear.dateInterface.common.BaseModel;
import com.erry.iclear.dateInterface.entity.ChmConsignment;
import com.erry.iclear.dateInterface.entity.DeclearTask;
......@@ -51,4 +52,29 @@ public class DeclearTaskService{
}
}
public void insertChmTask(List<BasfcReceipt> basfConsignments, Long logId) throws Exception {
List<DeclearTask> declareTaskList = new ArrayList<>();
try{
if (basfConsignments.size()>0){
for (BasfcReceipt basfConsignment : basfConsignments) {
DeclearTask declareTask = new DeclearTask();
declareTask.setChmsignmentId(BigDecimal.valueOf(basfConsignment.getConsignmentId()));
declareTask.setChmsignmentCode(basfConsignment.getConsignmentCode());
declareTask.setOperationTime(new Date());
declareTask.setFileType("2");
declareTask.setOperationName("root");
declareTask.setDataSource(String.valueOf(3));
declareTask.setResponseTime(new Date());
declareTask.setResponseResults("true");
declareTask.setDecelearInfoId(String.valueOf(logId));
declareTaskList.add(declareTask);
}
declareTaskRepository.saveAll(declareTaskList);
}
}catch (Exception e){
e.printStackTrace();
}
}
}
......
......@@ -84,7 +84,7 @@ public class IClearApiLogService {
}
/**
* BASF请求申报数据-添加日志 2021年11月3日 xjq
* BASF请求申报/回执数据-添加日志 2021年11月3日 xjq
* @return
*/
public IClearApiLog convertToIClearApiLogCselect(String basfc, String appId, String appKey, Date pushTime){
......
......@@ -27,8 +27,10 @@ api:
address:
#IClear校验运单地址
iclear-check-url: http://139.217.114.139:8082/chmConsignmentController/checkChmAndDetaliD
#IClearC类提交运单地址
iclear-submit-url: http://localhost:8080/chmConsignmentController/submitConsignments
#IClear校验C类运单地址
iclear-check-url-c: http://139.217.114.139:8082/chmConsignmentController/checkChmAndDetaliC
iclear-check-url-c: http://localhost:8080/chmConsignmentController/checkChmAndDetaliC
#获取token地址
token-url: https://apiuat.iclrccd-fedex.com/login
#刷新token地址
......