Jiaqi.xu

BASF接口

package com.erry.iclear.dateInterface.api;
import com.erry.iclear.dateInterface.api.request.Basfc;
import com.erry.iclear.dateInterface.api.request.Mawb;
import com.erry.iclear.dateInterface.api.response.ResultRS;
import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.IClearApiLog;
import com.erry.iclear.dateInterface.repository.MawbAdd;
import com.erry.iclear.dateInterface.service.*;
import com.erry.iclear.dateInterface.util.DateUtils;
import com.erry.iclear.dateInterface.util.SHA256Util;
......@@ -49,7 +51,7 @@ public class CustomsDataInterface {
@PostMapping("/sendMawb")
@ResponseBody
public ResultRS sendMawb(HttpServletRequest request
,@Validated @RequestBody Mawb mawb) {
,@Validated(MawbAdd.class) @RequestBody Mawb mawb) {
log.info("接收到请求数据billNo:"+mawb.getBillNo()+" data:" + gson.toJson(mawb));
ResultRS result = new ResultRS(Boolean.FALSE,"","");
......@@ -134,6 +136,94 @@ public class CustomsDataInterface {
return result;
}
@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) {
log.info("接收到请求数据consignmentCode:"+basfc.getConsignmentCode()+" data:" + gson.toJson(basfc));
ResultRS result = new ResultRS(Boolean.FALSE,"","");
if(Objects.equals(basfc,null)){
result.setCode("-7");
result.setMsg("请求信息不能为空");
return result;
}
//1、保存请求信息,保存到iClear的 SQLServer
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.convertToIClearApiLogC(basfc,appId,appKey,new Date(Long.valueOf(timeStamp))));
basfc.setAppId(appId);
Mawb saveMawbBasfResult = null;
if(!Objects.equals(saveIClearApiLogResult,null)){
log.info("请求保存成功,msgId:"+saveIClearApiLogResult.getMsgId());
basfc.setMsgId(saveIClearApiLogResult.getMsgId());
basfc.getBasfcDetailList().forEach(d->{
d.setMsgId(saveIClearApiLogResult.getMsgId());
});
saveMawbBasfResult = mawbService.saveMawbBasf(basfc);
if(!Objects.equals(saveMawbBasfResult,null)){
log.info("请求数据运单号"+basfc.getConsignmentCode()+"保存成功,msgId:"+saveMawbBasfResult.getMsgId());
}else{
log.info("请求数据运单号"+basfc.getConsignmentCode()+"保存失败,msgId:"+saveMawbBasfResult.getMsgId());
}
}else{
log.info("请求日志保存失败,consignmentCode:"+basfc.getConsignmentCode());
}
sw.stop();
//2、TODO 校验主单
/* sw.start("checkMawb");
result=mawbService.checkMawb(mawb);
if(!result.getSuccess()){
return result;
}
sw.stop();*/
// //3、TODO 校验子单
// sw.start("checkMawbDetail");
// result=mawbDetailServicel.checkMawbDetail(mawb);
// if(!result.getSuccess()){
// return result;
// }
// sw.stop();
//4、保存运单到iclear中
sw.start("processChmConsignment");
result = chmConsignmentService.processChmConsignment(saveMawbBasfResult, timeStamp,appId);
if(!result.getSuccess()){
return result;
}
sw.stop();
//5、更新日志
sw.start("updateIClearApiLog");
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);
}
log.info("请求数据consignmentCode:"+basfc.getConsignmentCode() +" 接收结束");
sw.stop();
log.info(sw.prettyPrint());
//6、return result
result.setSuccess(Boolean.TRUE);
result.setCode("0");
return result;
}
}
......
package com.erry.iclear.dateInterface.api.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.*;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.List;
@ApiModel(value = "basfc", description = "主运单")
@Entity
@Table(name = "T_ICLEAR_API_BASFC")
@DynamicInsert
@DynamicUpdate
@Data
public class Basfc implements Serializable {
private static final long serialVersionUID = -7092144710653831972L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id", insertable = false, nullable = false)
private Long id;
@ApiModelProperty(value = "用户ID", name = "AppId", example = "BASF")
@Column(name = "APPID")
private String AppId;
@Column(name = "MSGID")
private Long msgId;
/*@ApiModelProperty(value = "权限", name = "AppKey", example = "iClearExportC")
@Column(name = "APP_KEY")
private String AppKey;*/
@ApiModelProperty(value = "加密码", name = "Secret")
@Column(name = "SECRET")
private String secret;
@ApiModelProperty(value = "运单号", name = "consignmentCode")
@Column(name = "CONSIGNMENTCODE")
@NotBlank(message="参数consignmentCode不能为空!")
private String consignmentCode;
@ApiModelProperty(value = "运单ID", name = "consignmentId", example = "运单记录的唯一ID")
@Column(name = "CONSIGNMENTID")
@NotBlank(message="参数consignmentId不能为空!")
private Long consignmentId;
@ApiModelProperty(value = "运单类型",name = "consType", example = "A/B/C/D")
@Column(name = "CONSTYPE")
@NotBlank(message = "参数consType不能为空!")
private String consType;
@ApiModelProperty(value = "发件人", name = "sender")
@Column(name = "SENDER")
@NotBlank(message = "参数sender不能为空!")
private String sender;
@ApiModelProperty(value = "发件人海关编码", name = "shipperCustomsCode")
@Column(name = "SHIPPERCUSTOMSCODE")
private String shipperCustomsCode;
@ApiModelProperty(value = "发件人社会信用证代码", name = "shipperSCC")
@Column(name = "SHIPPERSCC")
@NotBlank(message = "参数shipperSCC不能为空!")
private String shipperSCC;
@ApiModelProperty(value = "经营单位", name = "operateUnitName")
@Column(name = "OPERATEUNITNAME")
private String operateUnitName;
@ApiModelProperty(value = "经营单位海关编码", name = "operateUnitCode")
@Column(name = "OPERATEUNITCODE")
private String operateUnitCode;
@ApiModelProperty(value = "经营单位社会信用证代码", name = "operateSCC")
@Column(name = "OPERATESCC")
private String operateSCC;
@ApiModelProperty(value = "EANNo", name = "EANNo")
@Column(name = "EANNO")
private String EANNo;
@Valid
@ApiModelProperty(value = "运单明细", name = "basfcDetailList", example = "")
@OneToMany(cascade = CascadeType.PERSIST)
@JoinColumn(name = "BASFCID")
private List<BasfcDetail> basfcDetailList;
}
package com.erry.iclear.dateInterface.api.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@ApiModel(value = "basfcDetail", description = "运单明细")
@Entity
@Table(name = "T_ICLEAR_API_BASFCDETAIL")
@Data
public class BasfcDetail {
private static final long serialVersionUID = -6706944312498119267L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id", insertable = false, nullable = false)
private Long id;
@Column(name = "MSGID")
private Long msgId;
@Column(name="BASFCID")
private Long basfId;
@Column(name="CONSIGNMENTDETAILID")
@NotBlank(message="参数consignmentDetailId不能为空")
private String consignmentDetailId;
@ApiModelProperty(value = "商品编号")
@NotBlank(message="参数skuCode不能为空")
@Column(name = "SKUCODE")
private String skuCode;
@ApiModelProperty(value = "品名")
@NotBlank(message = "参数skuName不能为空")
@Column(name = "SKUNAME")
private String skuName;
@ApiModelProperty(value = "规格型号")
@NotBlank(message="参数model不能为空")
@Column(name = "MODEL")
private String model;
@ApiModelProperty(value = "第一计量单位(法定单位)")
@NotBlank(message="参数unitLegalFirst不能为空")
@Column(name = "UNITLEGALFIRST")
private String unitLegalFirst;
@ApiModelProperty(value = "第一法定数量")
@NotNull(message="参数qtyLegalFirst不能为空")
@Column(name = "QTY_LEGALFIRST")
private BigDecimal qtyLegalFirst;
@ApiModelProperty(value = "成交计量单位")
@NotBlank(message="参数knockdownUnit不能为空")
@Column(name = "KNOCKDOWNUNIT")
private String knockdownUnit;
@ApiModelProperty(value = "成交数量")
@NotNull(message="参数knockdownNumber不能为空")
@Column(name = "KNOCKDOWNNUMBER")
private BigDecimal knockdownNumber;
@ApiModelProperty(value = "第二计量单位")
@Column(name = "UNITLEGALSECOND")
private String unitLegalSecond;
@ApiModelProperty(value = "第二法定数量")
@NotNull(message="参数qtyLegalSecond不能为空")
@Column(name = "QTYLEGALSECOND")
private BigDecimal qtyLegalSecond;
@ApiModelProperty(value = "申报金额")
@NotBlank(message = "参数declaredAmount不能为空")
@Column(name = "DECLAREDAMOUNT")
private BigDecimal declaredAmount;
@ApiModelProperty(value = "币制")
@NotBlank(message="参数currency不能为空")
@Column(name = "CURRENCY")
private String currency;
@ApiModelProperty(value = "申报重量")
@NotBlank(message = "参数declaredWeight不能为空")
@Column(name = "DECLAREDWEIGHT")
private BigDecimal declaredWeight;
}
package com.erry.iclear.dateInterface.api.request;
import com.erry.iclear.dateInterface.repository.MawbAdd;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -41,12 +42,12 @@ public class Mawb implements Serializable {
@ApiModelProperty(value = "进出口标志", name = "IEFlag", example = "固定值:E")
@NotBlank(message="参数ieFlag不能为空")
@NotBlank(message="参数ieFlag不能为空", groups = {MawbAdd.class})
@Column(name = "IEFLAG")
private String ieFlag;
@ApiModelProperty(value = "报关类型", name = "Type", example = "固定值:EX")
@NotBlank(message="参数type不能为空")
@NotBlank(message="参数type不能为空", groups = {MawbAdd.class})
@Column(name = "TYPE")
private String type;
......@@ -70,12 +71,12 @@ public class Mawb implements Serializable {
private String contrNo;
@ApiModelProperty(value = "主管海关(申报地海关)", name = "customMaster", example = "固定值:0101")
@NotBlank(message="参数customMaster不能为空")
@NotBlank(message="参数customMaster不能为空", groups = {MawbAdd.class})
@Column(name = "CUSTOMMASTER")
private String customMaster;
@ApiModelProperty(value = "征免性质", name = "cutMode", example = "101")
@NotBlank(message="参数cutMode不能为空")
@NotBlank(message="参数cutMode不能为空", groups = {MawbAdd.class})
@Column(name = "CUTMODE")
private String cutMode;
......@@ -85,12 +86,12 @@ public class Mawb implements Serializable {
private String declTrnRel;
@ApiModelProperty(value = "经停港/指运港", name = "distinatePort", example = "ASM000")
@NotBlank(message="参数distinatePort不能为空")
@NotBlank(message="参数distinatePort不能为空", groups = {MawbAdd.class})
@Column(name = "DISTINATEPORT")
private String distinatePort;
@ApiModelProperty(value = "报关标志", name = "EdiId", example = "001")
@NotBlank(message="参数ediId不能为空")
@NotBlank(message="参数ediId不能为空", groups = {MawbAdd.class})
@Column(name = "EDIID")
private String ediId;
......@@ -99,27 +100,27 @@ public class Mawb implements Serializable {
private String entryId;
@ApiModelProperty(value = "运费币制", name = "feeCurr", example = "固定值:3")
@NotBlank(message="参数feeCurr不能为空")
@NotBlank(message="参数feeCurr不能为空", groups = {MawbAdd.class})
@Column(name = "FEECURR")
private String feeCurr;
@ApiModelProperty(value = "运费标记", name = "feeMark", example = "99.22")
@NotBlank(message="参数feeMark不能为空")
@NotBlank(message="参数feeMark不能为空", groups = {MawbAdd.class})
@Column(name = "FEEMARK")
private String feeMark;
@ApiModelProperty(value = "运费/率", name = "feeRate", example = "43.34358")
@NotNull(message="参数feeRate不能为空")
@NotNull(message="参数feeRate不能为空", groups = {MawbAdd.class})
@Column(name = "FEERATE")
private BigDecimal feeRate;
@ApiModelProperty(value = "毛重", name = "grossWet", example = "")
@NotNull(message="参数grossWet不能为空")
@NotNull(message="参数grossWet不能为空", groups = {MawbAdd.class})
@Column(name = "CROSSWET")
private BigDecimal grossWet;
@ApiModelProperty(value = "出入境关闭", name = "IEPort", example = "固定值:0101")
@NotBlank(message="参数iePort不能为空")
@NotBlank(message="参数iePort不能为空", groups = {MawbAdd.class})
@Column(name = "IEPORT")
private String iePort;
......@@ -128,7 +129,7 @@ public class Mawb implements Serializable {
private String inputerName;
@ApiModelProperty(value = "保险费币制", name = "insurCurr", example = "MOP")
@NotBlank(message="参数insurCurr不能为空")
@NotBlank(message="参数insurCurr不能为空", groups = {MawbAdd.class})
@Column(name = "INSURCURR")
private String insurCurr;
......@@ -137,7 +138,7 @@ public class Mawb implements Serializable {
private String insurMark;
@ApiModelProperty(value = "保险费/率", name = "insurRate", example = "")
@NotNull(message="参数insurRate不能为空")
@NotNull(message="参数insurRate不能为空", groups = {MawbAdd.class})
@Column(name = "INSURRATE")
private BigDecimal insurRate;
......@@ -146,7 +147,7 @@ public class Mawb implements Serializable {
private String manualNo;
@ApiModelProperty(value = "净重", name = "netWt", example = "")
@NotNull(message="参数netWt不能为空")
@NotNull(message="参数netWt不能为空", groups = {MawbAdd.class})
@Column(name = "NETWT")
private BigDecimal netWt;
......@@ -163,17 +164,17 @@ public class Mawb implements Serializable {
private String otherMark;
@ApiModelProperty(value = "消费使用/生产销售单位代码", name = "ownerCode", example = "Z321654987")
@NotBlank(message="参数ownerCode不能为空")
@NotBlank(message="参数ownerCode不能为空", groups = {MawbAdd.class})
@Column(name = "OWNERCODE")
private String ownerCode;
@ApiModelProperty(value = "消费使用/生产销售单位名称", name = "ownerName", example = "上海保险")
@NotBlank(message="参数ownerName不能为空")
@NotBlank(message="参数ownerName不能为空", groups = {MawbAdd.class})
@Column(name = "OWNERNAME")
private String ownerName;
@ApiModelProperty(value = "件数", name = "packNo", example = "")
@NotNull(message="参数packNo不能为空")
@NotNull(message="参数packNo不能为空", groups = {MawbAdd.class})
@Column(name = "PACKNO")
private Integer packNo;
......@@ -181,12 +182,12 @@ public class Mawb implements Serializable {
private String preEntryId;
@ApiModelProperty(value = "启运国/运抵国", name = "tradeCountry", example = "USA")
@NotBlank(message="参数tradeCountry不能为空")
@NotBlank(message="参数tradeCountry不能为空", groups = {MawbAdd.class})
@Column(name = "TRADECOUNTRY")
private String tradeCountry;
@ApiModelProperty(value = "监管方式", name = "tradeMode", example = "0200")
@NotBlank(message="参数tradeMode不能为空")
@NotBlank(message="参数tradeMode不能为空", groups = {MawbAdd.class})
@Column(name = "TRADEMODE")
private String tradeMode;
......@@ -196,7 +197,7 @@ public class Mawb implements Serializable {
private String tradeCode;
@ApiModelProperty(value = "运输方式代码", name = "trafMode", example = "1")
@NotBlank(message="参数trafMode不能为空")
@NotBlank(message="参数trafMode不能为空", groups = {MawbAdd.class})
@Column(name = "TRAFMODE")
private String trafMode;
......@@ -206,12 +207,12 @@ public class Mawb implements Serializable {
private String tradeName;
@ApiModelProperty(value = "成交方式", name = "transMode", example = "2")
@NotBlank(message="参数transMode不能为空")
@NotBlank(message="参数transMode不能为空", groups = {MawbAdd.class})
@Column(name = "TRANSMODE")
private String transMode;
@ApiModelProperty(value = "包装种类", name = "wrapType", example = "22")
@NotBlank(message="参数wrapType不能为空")
@NotBlank(message="参数wrapType不能为空", groups = {MawbAdd.class})
@Column(name = "WRAPTYPE")
private String wrapType;
......@@ -221,12 +222,12 @@ public class Mawb implements Serializable {
private String tradeCodeScc;
@ApiModelProperty(value = "消费使用/生产销售单位单位统一编码", name = "ownerCodeScc", example = "")
@NotBlank(message="参数ownerCodeScc不能为空")
@NotBlank(message="参数ownerCodeScc不能为空", groups = {MawbAdd.class})
@Column(name = "OWNERCODESCC")
private String ownerCodeScc;
@ApiModelProperty(value = "贸易国别", name = "tradeAreaCode", example = "")
@NotBlank(message="参数tradeAreaCode不能为空")
@NotBlank(message="参数tradeAreaCode不能为空", groups = {MawbAdd.class})
@Column(name = "TRADEAREACODE")
private String tradeAreaCode;
......@@ -235,7 +236,7 @@ public class Mawb implements Serializable {
private String markNo;
@ApiModelProperty(value = "入境口岸代码", name = "entyPortCode", example = "固定值:310302")
@NotBlank(message="参数entyPortCode不能为空")
@NotBlank(message="参数entyPortCode不能为空", groups = {MawbAdd.class})
@Column(name = "ENTYPORTCODE")
private String entyPortCode;
......@@ -255,10 +256,18 @@ public class Mawb implements Serializable {
private String overseasConsigneeCode;
@ApiModelProperty(value = "境外收货人名称(外文)", name = "overseasConsigneeEname", example = "")
@NotBlank(message="参数overseasConsigneeEname不能为空")
@NotBlank(message="参数overseasConsigneeEname不能为空", groups = {MawbAdd.class})
@Column(name = "OVERSEASCONSIGNEEENAME")
private String overseasConsigneeEname;
@ApiModelProperty(value = "运单ID", name = "consignmentCodeId", example = "")
@Column(name = "CONSIGNMENTCODEID")
private Long consignmentCodeId;
@ApiModelProperty(value = "EANNo", name = "EANNo", example = "")
@Column(name = "EANNO")
private String EANNo;
@Valid
@ApiModelProperty(value = "运单明细", name = "mawbDetailList", example = "")
@OneToMany(cascade = CascadeType.PERSIST)
......
package com.erry.iclear.dateInterface.api.request;
import com.erry.iclear.dateInterface.repository.MawbAdd;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -46,7 +47,7 @@ public class MawbDetail implements Serializable{
private String codeTS;
@ApiModelProperty(value = "申报单价", example = "空值")
@NotNull(message="参数declPrice不能为空")
@NotNull(message="参数declPrice不能为空", groups = {MawbAdd.class})
@Column(name = "DECLPRICE")
private BigDecimal declPrice;
......@@ -56,7 +57,7 @@ public class MawbDetail implements Serializable{
private BigDecimal declTotal;
@ApiModelProperty(value = "征免方式")
@NotBlank(message="参数dutyMode不能为空")
@NotBlank(message="参数dutyMode不能为空", groups = {MawbAdd.class})
@Column(name = "DUTYMODE")
private String dutyMode;
......@@ -94,7 +95,7 @@ public class MawbDetail implements Serializable{
private String gname;
@ApiModelProperty(value = "商品序号")
@NotBlank(message="参数gno不能为空")
@NotBlank(message="参数gno不能为空", groups = {MawbAdd.class})
@Column(name = "GNO")
private String gno;
......@@ -104,7 +105,7 @@ public class MawbDetail implements Serializable{
private BigDecimal gqty;
@ApiModelProperty(value = "原产国")
@NotBlank(message="参数originCountry不能为空")
@NotBlank(message="参数originCountry不能为空", groups = {MawbAdd.class})
@Column(name = "ORIGINCURRENTY")
private String originCountry;
......@@ -135,7 +136,7 @@ public class MawbDetail implements Serializable{
private String ciqCode;
@ApiModelProperty(value = "最终目的国(地区)")
@NotBlank(message="参数destinationCountry不能为空")
@NotBlank(message="参数destinationCountry不能为空", groups = {MawbAdd.class})
@Column(name = "DESTINATIONCOUNTRY")
private String destinationCountry;
......@@ -148,9 +149,11 @@ public class MawbDetail implements Serializable{
private String destCode;
@ApiModelProperty(value = "境内目的地/境内货源地")
@NotBlank(message="参数districtCode不能为空")
@NotBlank(message="参数districtCode不能为空", groups = {MawbAdd.class})
@Column(name = "DISTRICTCODE")
private String districtCode;
@ApiModelProperty(value = "申报重量")
@Column(name = "DECLAREDWEIGHT")
private BigDecimal declaredWeight;
}
......
......@@ -246,8 +246,8 @@ public class ChmConsignmentDetail implements Serializable {
/**
* 申报重量
* */
// @Column(name = "DECLARED_WEIGHT")
// private BigDecimal declaredWeight;
@Column(name = "DECLARED_WEIGHT")
private BigDecimal declaredWeight;
/**
* 录入品名
*/
......
package com.erry.iclear.dateInterface.repository;
public interface MawbAdd {
}
......@@ -131,6 +131,62 @@ public class ChmConsignmentDetailService {
/**
* 转换运单明细
* @param mawbDetail
* @return
*/
public ChmConsignmentDetail convertToChmConsignmentDetailBasf(MawbDetail mawbDetail,ChmConsignment chmConsignment){
ChmConsignmentDetail result = new ChmConsignmentDetail();
try{
result.setChmConsignment(chmConsignment);
//商品编号
result.setSkuCode(mawbDetail.getCodeTS());
//申报总价
result.setAmount(mawbDetail.getDeclTotal());
//第一计量单位(法定单位)
DictionaryEntries firstUnitDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getFirstUnit());
if(!Objects.equals(firstUnitDictionaryEntries,null)){
result.setUnitLegalFirstId(firstUnitDictionaryEntries);
result.setUnitLegalFirst(firstUnitDictionaryEntries.getChineseName());
}
//第一法定数量
result.setQtyLegalFirst(BigDecimal.valueOf(mawbDetail.getFirstQty().doubleValue()));
//成交计量单位
//2021年7月8日 成交单位有修改,原取值第一法定计量单位,先取值成交单位。xjq
DictionaryEntries knockdownUnitEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getGunit());
if(!Objects.equals(knockdownUnitEntries,null)){
result.setKnockdownUnitDic(knockdownUnitEntries);
result.setKnockdownUnit(knockdownUnitEntries.getChineseName());
}
//商品规格、型号
result.setModel(mawbDetail.getGmodel());
//商品名称
result.setSkuName(mawbDetail.getGname());
//成交数量
result.setKnockdownNumber(BigDecimal.valueOf(mawbDetail.getGqty().doubleValue()));
//第二计量单位
DictionaryEntries secondUnitDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getSecondUnit());
if(!Objects.equals(secondUnitDictionaryEntries,null)){
result.setUnitLegalSecondId(secondUnitDictionaryEntries);
result.setUnitLegalSecond(secondUnitDictionaryEntries.getChineseName());
}
//第二法定数量
result.setQtyLegalSecond(BigDecimal.valueOf(mawbDetail.getSecondQty().doubleValue()));
//成交币制
DictionaryEntries currencyDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM+ mawbDetail.getTradeCurr());
if(!Objects.equals(currencyDictionaryEntries,null)){
result.setCurrencyDic(currencyDictionaryEntries);
result.setCurrency(currencyDictionaryEntries.getChineseName());
}
result.setDeclaredWeight(mawbDetail.getDeclaredWeight());
result.setDetailId(mawbDetail.getDetailId());
}catch (Exception e){
log.error("convertToChmConsignmentDetailBasf() error:"+e.getMessage());
}
return result;
}
/**
* 转换运单明细
* @param detail
* @param gno
* @return
......
......@@ -224,6 +224,59 @@ public class ChmConsignmentService {
return result;
}
public ChmConsignment convertToChmConsignmentBasf(Mawb mawb,Date pushTime,String creator){
ChmConsignment result = new ChmConsignment();
try{
//运单号
result.setConsignmentCode(mawb.getBillNo());
//运单类型
DictionaryEntries consType = Constant.dictionaryEntriesCache.get(Constant.MSG_TYPE_C);
if(consType != null){
result.setConsTypeId(consType);
result.setConsType(consType.getChineseName());
}
//监管方式
/*DictionaryEntries tradeModeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.SUPERVISION_MODE+Integer.parseInt(mawb.getTradeMode()));
if(!Objects.equals(tradeModeDictionaryEntries,null)){
result.setTradeModeDic(tradeModeDictionaryEntries);
result.setTradeMode(tradeModeDictionaryEntries.getChineseName());
}*/
//境内收发货人社会信用证代码
result.setTradeCoSCC(mawb.getTradeCodeScc());
//境内发货人(经营单位编码)
result.setOperateUnitCode(mawb.getTradeCode());
//境内收发货人名称
result.setOperateUnitName(mawb.getTradeName());
//经营单位
result.setOwnerName(mawb.getOwnerName());
//经营单位海关编码
result.setOwnerCode(mawb.getOwnerCode());
//经营单位社会信用证代码
result.setOwnerCodeScc(mawb.getOwnerCodeScc());
/*//TODO 生产核销单位统一信用代码---报关形式类型
result.setTradeCoSCC(mawb.getTradeCodeScc());
//TODO 消费使用/生产销售单位单位统一编码
result.setOwnerCodeScc(mawb.getOwnerCodeScc());*/
//运单状态: C类待申报
DictionaryEntries transferWaybillStatusDictionaryEntries=Constant.dictionaryEntriesCache.get(Constant.TRANSFER_WAY_BILL_STATUS+"16");
if(!Objects.equals(transferWaybillStatusDictionaryEntries,null)){
result.setConsStatusDic(transferWaybillStatusDictionaryEntries);
result.setConsStatus(transferWaybillStatusDictionaryEntries.getChineseName());
}
//推送时间作为创建时间,可以用来校验数据的有序性,如果新的推送时间小于已有的创建时间,就不更新数据
result.setCreateTime(new Date());
result.setUpdateTime(pushTime);
result.setCreator(creator);
}catch (Exception e){
result=null;
e.printStackTrace();
log.error("convertToChmConsignmentBasf() error:"+e.getMessage());
}
return result;
}
/**
* 运单转换主单
* @return
......@@ -414,18 +467,29 @@ public class ChmConsignmentService {
ResultRS result = new ResultRS(Boolean.FALSE,null,null);
try {
Date pushTime = DateUtils.timeStampToDate(Long.valueOf(timeStamp));
ChmConsignment chmConsignment = null;
//1、将请求转换为运单
ChmConsignment chmConsignment=this.convertToChmConsignment(mawb,pushTime,creator);
if(mawb.getType().equals(Constant.MSG_TYPE_C)){
chmConsignment=this.convertToChmConsignmentBasf(mawb,pushTime,creator);
}else{
chmConsignment=this.convertToChmConsignment(mawb,pushTime,creator);
}
if(Objects.equals(chmConsignment,null)){
result.setCode("30001");
result.setMsg("数据格式不正确");
return result;
}
List<ChmConsignmentDetail> chmConsignmentDetailList = new ArrayList<>();
mawb.getMawbDetailList().forEach(detail ->{
chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetail(detail,chmConsignment));
});
ChmConsignment finalChmConsignment = chmConsignment;
if (mawb.getType().equals(Constant.MSG_TYPE_C)){
mawb.getMawbDetailList().forEach(detail ->{
chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetailBasf(detail, finalChmConsignment));
});
}else {
mawb.getMawbDetailList().forEach(detail ->{
chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetail(detail, finalChmConsignment));
});
}
chmConsignment.setChmConsignmentDetailList(chmConsignmentDetailList);
//2、校验 7天+运单 ,如果有数据并且 还未报关就更新,如果数据就插入
......
package com.erry.iclear.dateInterface.service;
import com.erry.iclear.dateInterface.api.request.Basfc;
import com.erry.iclear.dateInterface.api.request.Mawb;
import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.IClearApiLog;
......@@ -58,6 +59,29 @@ public class IClearApiLogService {
return result;
}
/**
* 创建日志
* @return
*/
public IClearApiLog convertToIClearApiLogC(Basfc basfc, String appId, String appKey, Date pushTime){
IClearApiLog result = new IClearApiLog();
try{
result.setMsgType(Constant.MSG_TYPE_C);
result.setAppId(appId);
result.setAppKey(appKey);
result.setCreateTime(new Date());
result.setPushTime(pushTime);
result.setReceiveResult(null);
result.setResponseTime(null);
result.setSpendTime(null);
result.setSendTimes(1);
result.setBillNo(basfc.getConsignmentCode());
//result.setContrNo(mawb.getContrNo());
}catch (Exception e){
log.error("convertToIClearApiLog() error:"+e.getMessage());
}
return result;
}
public void updateIClearApiLog(IClearApiLog iClearApiLog){
......
......@@ -3,21 +3,25 @@ package com.erry.iclear.dateInterface.service;
import com.arronlong.httpclientutil.HttpClientUtil;
import com.arronlong.httpclientutil.common.HttpConfig;
import com.arronlong.httpclientutil.common.HttpHeader;
import com.erry.iclear.dateInterface.api.request.Basfc;
import com.erry.iclear.dateInterface.api.request.BasfcDetail;
import com.erry.iclear.dateInterface.api.request.Mawb;
import com.erry.iclear.dateInterface.api.request.MawbDetail;
import com.erry.iclear.dateInterface.api.response.IClearCheckResponseResult;
import com.erry.iclear.dateInterface.api.response.ResultRS;
import com.erry.iclear.dateInterface.api.response.TokenResult;
import com.erry.iclear.dateInterface.entity.ChmConsignment;
import com.erry.iclear.dateInterface.entity.ChmConsignmentDetail;
import com.erry.iclear.dateInterface.repository.MawbAdd;
import com.erry.iclear.dateInterface.repository.MawbRepository;
import com.erry.iclear.dateInterface.util.JsonToJava;
import com.erry.iclear.dateInterface.util.NumberUtils;
import com.google.gson.Gson;
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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
......@@ -62,6 +66,66 @@ public class MawbService {
/**
* 保存主单Request --basfc
* @param basfc
*/
public Mawb saveMawbBasf(Basfc basfc){
Mawb result=null;
try{
log.info("saveMawb start>>>>>>>>>>>");
//运单头部信息
Mawb mawb = new Mawb();
mawb.setAppId(basfc.getAppId());
mawb.setMsgId(basfc.getMsgId());
mawb.setConsignmentCodeId(basfc.getConsignmentId());
mawb.setType(basfc.getConsType());
//TODO 记录时为同一张表,用 '-->' 记录具体存放字段(方便查看,以免误解)
//运单号-->提单号
mawb.setBillNo(basfc.getConsignmentCode());
//经营单位 --> 消费使用/生产销售单位名称
mawb.setOwnerName(basfc.getOperateUnitName());
//经营单位海关编码 --> 消费使用/生产销售单位代码
mawb.setOwnerCode(basfc.getOperateUnitCode());
//经营单位社会信用证代码 --> 消费使用/生产销售单位单位统一编码
mawb.setOwnerCodeScc(basfc.getOperateSCC());
//发件人 --> 境内收发货人名称
mawb.setTradeName(basfc.getSender());
//发件人海关编码 --> 境内收发货人编号
mawb.setTradeCode(basfc.getShipperCustomsCode());
//发件人社会信用证代码 --> 生产核销单位统一信用代码---报关形式类型
mawb.setTradeCodeScc(basfc.getShipperSCC());
mawb.setEANNo(basfc.getEANNo());
//明细
List<MawbDetail> mawbDetailList = new ArrayList<>();
if (basfc.getBasfcDetailList().size()>0){
for (BasfcDetail basfcDetail : basfc.getBasfcDetailList()){
MawbDetail mawbDetail = new MawbDetail();
mawbDetail.setDetailId(basfcDetail.getConsignmentDetailId());
mawbDetail.setGmodel(basfcDetail.getModel());
mawbDetail.setCodeTS(basfcDetail.getSkuCode());
mawbDetail.setGname(basfcDetail.getSkuName());
mawbDetail.setGqty(basfcDetail.getKnockdownNumber());
mawbDetail.setGunit(basfcDetail.getKnockdownUnit());
mawbDetail.setFirstUnit(basfcDetail.getUnitLegalFirst());
mawbDetail.setFirstQty(NumberUtils.bigDecimalToIntger(basfcDetail.getQtyLegalFirst()));
mawbDetail.setSecondQty(NumberUtils.bigDecimalToIntger(basfcDetail.getQtyLegalSecond()));
mawbDetail.setSecondUnit(basfcDetail.getUnitLegalSecond());
mawbDetail.setDeclTotal(basfcDetail.getDeclaredAmount());
mawbDetail.setTradeCurr(basfcDetail.getCurrency());
mawbDetail.setDeclaredWeight(basfcDetail.getDeclaredWeight());
mawbDetailList.add(mawbDetail);
}
}
mawb.setMawbDetailList(mawbDetailList);
result = mawbRepository.save(mawb);
log.info("saveMawb end>>>>>>>>>>>");
}catch (Exception e){
log.error("saveMawb() error:"+e.getMessage());
}
return result;
}
/**
* 校验主单
* @param mawb
* @return
......
package com.erry.iclear.dateInterface;
import com.erry.iclear.dateInterface.api.CustomsDataInterface;
import com.erry.iclear.dateInterface.api.request.Basfc;
import com.erry.iclear.dateInterface.api.request.BasfcDetail;
import com.erry.iclear.dateInterface.api.request.Mawb;
import com.erry.iclear.dateInterface.api.request.MawbDetail;
import com.erry.iclear.dateInterface.api.response.ResultRS;
import com.erry.iclear.dateInterface.repository.MawbAdd;
import com.erry.iclear.dateInterface.service.ChmConsignmentService;
import com.erry.iclear.dateInterface.service.MawbService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal;
import java.util.ArrayList;
......@@ -17,6 +24,12 @@ public class ChmConsignmentServiceTest extends IClearApiApplicationTests {
@Autowired
private ChmConsignmentService chmConsignmentService;
@Autowired
private CustomsDataInterface customsDataInterface;
@Autowired
private MawbService mawbService;
@Test
public void testProcessChmConsignment(){
......@@ -30,10 +43,57 @@ public class ChmConsignmentServiceTest extends IClearApiApplicationTests {
}
}
@Test
public void testProcessChmConsignment1(){
try{
Basfc basfc = this.createNewBasf();
Mawb mawb = mawbService.saveMawbBasf(basfc);
//Basfc basfc = this.createNewBasf();
String timeStamp = String.valueOf(new Date().getTime());
ResultRS resultRS = chmConsignmentService.processChmConsignment(mawb, timeStamp, "BASF");
System.out.println(resultRS.toString());
}catch (Exception e){
e.printStackTrace();
}
}
private Basfc createNewBasf(){
List<BasfcDetail> basfcDetailList = new ArrayList<>();
BasfcDetail basfcDetail = new BasfcDetail();
basfcDetail.setConsignmentDetailId("111");
basfcDetail.setSkuCode("");
basfcDetail.setSkuName("测试");
basfcDetail.setModel("0|0|1|||||||||");
basfcDetail.setUnitLegalFirst("035");
basfcDetail.setQtyLegalFirst(BigDecimal.valueOf(1));
basfcDetail.setKnockdownUnit("035");
basfcDetail.setKnockdownNumber(BigDecimal.valueOf(1));
basfcDetail.setUnitLegalSecond("007");
basfcDetail.setQtyLegalSecond(BigDecimal.valueOf(1));
basfcDetail.setDeclaredAmount(BigDecimal.valueOf(1));
basfcDetail.setCurrency("USD");
basfcDetail.setDeclaredWeight(BigDecimal.valueOf(1));
basfcDetailList.add(basfcDetail);
Basfc basfc = new Basfc();
basfc.setConsignmentCode("211015001");
basfc.setConsignmentId(1L);
basfc.setConsType("C");
basfc.setSender("发件人");
basfc.setShipperCustomsCode("1234567890");
basfc.setShipperSCC("123456789012345678");
basfc.setOperateUnitName("");
basfc.setOperateUnitCode("");
basfc.setOperateSCC("");
basfc.setEANNo("");
basfc.setBasfcDetailList(basfcDetailList);
return basfc;
}
private Mawb createNewMawb(){
MawbDetail d1 = new MawbDetail();
d1.setClassMark("");
d1.setCodeTS("69125472");
d1.setCodeTS("");
d1.setDeclPrice(BigDecimal.valueOf(111.123));
d1.setDeclTotal(BigDecimal.valueOf(788));
d1.setDutyMode("1");
......@@ -100,7 +160,7 @@ public class ChmConsignmentServiceTest extends IClearApiApplicationTests {
mawb.setType("EX");
mawb.setAgentCode("1111980005");
mawb.setAgentName("联邦快递(中国)有限公司");
mawb.setBillNo("202105210784");
mawb.setBillNo("211015002");
mawb.setContrNo("NO.565733");
mawb.setCustomMaster("0101");
mawb.setCutMode("101");
......