tao.mo

API代码提交

mt
2021年8月6日13:35:03
......@@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.validation.annotation.Validated;
import javax.persistence.*;
import javax.validation.Valid;
......@@ -117,7 +116,7 @@ public class Mawb implements Serializable {
@ApiModelProperty(value = "毛重", name = "grossWet", example = "")
@NotNull(message="参数grossWet不能为空")
@Column(name = "CROSSWET")
private Integer grossWet;
private BigDecimal grossWet;
@ApiModelProperty(value = "出入境关闭", name = "IEPort", example = "固定值:0101")
@NotBlank(message="参数iePort不能为空")
......
package com.erry.iclear.dateInterface.api.request;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.validation.annotation.Validated;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
......@@ -20,7 +18,7 @@ import java.math.BigDecimal;
@Entity
@Table(name = "T_ICLEAR_API_MAWBDETAIL")
@Data
public class MawbDetail implements Serializable {
public class MawbDetail implements Serializable{
private static final long serialVersionUID = -6706944312498119267L;
@Id
......
......@@ -33,6 +33,9 @@ public class DictionaryEntries implements Serializable {
@Column(name = "DICT_CODE")
private String dictCode;
@Column(name = "EXT2")
private String ext2;
@Column(name = "EXT3")
private String ext3;
......
......@@ -16,6 +16,6 @@ public interface DeclearTaskRepository extends JpaSpecificationExecutor<DeclearT
* 根据运单号集合+创建时间 运单
* @return
*/
@Query( nativeQuery = true,value ="SELECT * FROM T_DECLEAR_TASK WHERE FILE_TYPE = 1 AND PUSH_NUMBER < 3 AND (RESPONSE_RESULTS IS NULL OR RESPONSE_RESULTS <> '0') ORDER BY OPERATION_TIME ASC" )
@Query( nativeQuery = true,value ="SELECT TOP 10 * FROM T_DECLEAR_TASK WHERE FILE_TYPE = 1 AND PUSH_NUMBER < 3 AND (RESPONSE_RESULTS IS NULL OR RESPONSE_RESULTS <> '0') ORDER BY OPERATION_TIME ASC" )
public List<DeclearTask> findDeclearTask();
}
......
......@@ -30,7 +30,7 @@ public interface DictionaryEntriesRepository extends JpaRepository<DictionaryEn
* 查找全部DictionaryEntries
* @return
*/
@Query(nativeQuery = true, value = "select ID,CODE,CHINESE_NAME,DICT_CODE,EXT3,EXT6 from T_BI_DICTIONARY_ENTRIES where STATUS=1")
@Query(nativeQuery = true, value = "select ID,CODE,CHINESE_NAME,DICT_CODE,EXT2,EXT3,EXT6 from T_BI_DICTIONARY_ENTRIES where STATUS=1")
public List<DictionaryEntries> findAllDictionaryEntries();
}
......
......@@ -30,8 +30,8 @@ public interface ReceiptMessageRepository extends JpaSpecificationExecutor<Recei
public List<ReceiptMessage> findReceiptMessageList();
@Modifying(clearAutomatically = false)
@Query(nativeQuery = true,value = "UPDATE T_DECLEAR_TASK SET PUSH_TIME = ?1,PUSH_NUMBER = PUSH_NUMBER + 1,RESPONSE_TIME = ?2,RESPONSE_RESULTS = ?3,RESPONSE_CONTENT = ?4 WHERE FILE_TYPE = 2 AND CHMSIGNMENT_ID = ?5")
void updateDeclearTaskStatus(Date pushTime, Date responseTime, String responseResults, String responseContent, Long chmsignmentId);
@Query(nativeQuery = true,value = "UPDATE T_DECLEAR_TASK SET PUSH_TIME = ?1,PUSH_NUMBER = PUSH_NUMBER + 1,RESPONSE_TIME = ?2,RESPONSE_RESULTS = ?3,RESPONSE_CONTENT = ?4 WHERE FILE_TYPE = ?5 AND CHMSIGNMENT_ID = ?6")
void updateDeclearTaskStatus(Date pushTime, Date responseTime, String responseResults, String responseContent, String fileType, Long chmsignmentId);
}
\ No newline at end of file
......
......@@ -3,9 +3,13 @@ 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.Mawb;
import com.erry.iclear.dateInterface.api.request.MawbDetail;
import com.erry.iclear.dateInterface.api.request.ReceiptMessage;
import com.erry.iclear.dateInterface.api.response.TokenResult;
import com.erry.iclear.dateInterface.common.Constants;
import com.erry.iclear.dateInterface.entity.ChmConsignment;
import com.erry.iclear.dateInterface.entity.ChmConsignmentDetail;
import com.erry.iclear.dateInterface.entity.DeclearTask;
import com.erry.iclear.dateInterface.repository.ChmConsignmentRepository;
import com.erry.iclear.dateInterface.repository.DeclearTaskRepository;
......@@ -52,6 +56,12 @@ public class ApiService {
@Autowired
ChmConsignmentRepository consignmentRepository;
@Autowired
ChmConsignmentService consignmentService;
@Autowired
ChmConsignmentDetailService consignmentDetailService;
/**
* 获取token信息
* @return
......@@ -62,7 +72,7 @@ public class ApiService {
map.put("username", this.username);
map.put("password", this.password);
HttpConfig config = HttpConfig.custom()
.url(tokenUrl)
.url(this.tokenUrl)
.map(map)
.encoding("utf-8");
String tokenJson = HttpClientUtil.post(config);
......@@ -79,7 +89,7 @@ public class ApiService {
Map<String,Object> map = new HashMap<String,Object>();
map.put("token", token);
HttpConfig config = HttpConfig.custom()
.url(refreshTokenUrl)
.url(this.refreshTokenUrl)
.map(map)
.encoding("utf-8");
HttpClientUtil.post(config);
......@@ -92,7 +102,7 @@ public class ApiService {
*/
public void pushCustoms(String token){
//获取海关回执数据
List<ReceiptMessage> receiptMessageList = receiptMessageRepository.findReceiptMessageList();
List<ReceiptMessage> receiptMessageList = this.receiptMessageRepository.findReceiptMessageList();
this.sendCustoms(token,receiptMessageList);
}
......@@ -118,7 +128,7 @@ public class ApiService {
//推送海关回执数据
HttpConfig config = HttpConfig.custom()
.headers(headers)
.url(customsUrl)
.url(this.customsUrl)
.encoding("utf-8")
.json(objJson);
String json = HttpClientUtil.post(config);
......@@ -151,10 +161,11 @@ public class ApiService {
});
declearTaskList.forEach(declearTask -> {
//将已经推送完成的回执信息状态修改
receiptMessageRepository.updateDeclearTaskStatus(declearTask.getPushTime(),
this.receiptMessageRepository.updateDeclearTaskStatus(declearTask.getPushTime(),
declearTask.getResponseTime(),
declearTask.getResponseResults(),
declearTask.getResponseContent(),
"2",
declearTask.getChmsignmentId().longValue());
});
}
......@@ -165,19 +176,95 @@ public class ApiService {
* @throws Exception
*/
public void pushMawb(String token){
Header[] headers = HttpHeader.custom()
.other("Content-Type", "application/json")
.other("Authorization", token)
.build();
//获取海关回执数据
try{
List<DeclearTask> declearTaskList = declearTaskRepository.findDeclearTask();
/****************将Export对象转换成西门子交互实体对象****************/
//查询需要推送数据
List<Mawb> mawbList = new ArrayList<Mawb>();
List<DeclearTask> declearTaskList = this.declearTaskRepository.findDeclearTask();
declearTaskList.forEach(declearTask -> {
Long consignmentId = declearTask.getChmsignmentId().longValue();
consignmentRepository.findChmConsignmentById(consignmentId);
//查询需要推送运单数据,并且转换
ChmConsignment consignment = this.consignmentRepository.findChmConsignmentById(consignmentId);
Mawb mawb = this.consignmentService.convertToChmConsignment(consignment);
//获取需要推送运单数据,并且转换
if(consignment.getChmConsignmentDetailList() != null){
List<MawbDetail> mawbDetailList = new ArrayList<MawbDetail>();
for(int i = 0 ; i < consignment.getChmConsignmentDetailList().size() ; i++){
ChmConsignmentDetail detail = consignment.getChmConsignmentDetailList().get(i);
MawbDetail mawbDetail = this.consignmentDetailService.convertToChmConsignmentDetail(detail, String.valueOf((i + 1)));
mawbDetailList.add(mawbDetail);
}
mawb.setMawbDetailList(mawbDetailList);
}
mawbList.add(mawb);
});
this.sendMawb(token,mawbList);
}catch(Exception ex){
ex.printStackTrace();
}
}
/**
* 将完整报文发送至西门子
* @param token
* @param mawbList
*/
public void sendMawb(String token ,List<Mawb> mawbList){
Header[] headers = HttpHeader.custom()
.other("Content-Type", "application/json")
.other("Authorization", token)
.build();
List<DeclearTask> declearTaskList = new ArrayList<DeclearTask>();
mawbList.forEach(d->{
DeclearTask declearTask = new DeclearTask();
try {
//设置ID
declearTask.setChmsignmentId(BigDecimal.valueOf(d.getId()));
//推送时间
declearTask.setPushTime(new Date());
String objJson = JsonToJava.toJson(d);
//推送海关回执数据
HttpConfig config = HttpConfig.custom()
.headers(headers)
.url(this.customsUrl)
.encoding("utf-8")
.json(objJson);
String json = HttpClientUtil.post(config);
//接口响应时间
declearTask.setResponseTime(new Date());
TokenResult tokenResult = JsonToJava.parseJson(json,TokenResult.class);
if(tokenResult.getErrorcode().equals(Constants.ApiResponseKeys.SUCCESS)){
//推送成功,记录推送状态
declearTask.setResponseResults(tokenResult.getErrorcode());
declearTask.setResponseContent(tokenResult.getErrormessage());
declearTaskList.add(declearTask);
}else if(tokenResult.getErrorcode().equals(Constants.ApiResponseKeys.KEY_10004)){
//如果凭证失效,则刷新凭证
refreshToken(token);
}else{
//推送失败,记录推送状态
declearTask.setResponseResults(tokenResult.getErrorcode());
declearTask.setResponseContent(tokenResult.getErrormessage());
declearTaskList.add(declearTask);
log.info("完整报关单推送失败,推送相应码为:"+tokenResult.getErrorcode() + ",推送ID为:" + d.getId());
}
}catch(Exception ex){
//接口响应时间
declearTask.setResponseTime(new Date());
declearTask.setResponseResults("接口调用失败!");
declearTask.setResponseContent(ex.getMessage());
declearTaskList.add(declearTask);
ex.printStackTrace();
}
});
declearTaskList.forEach(declearTask -> {
//将已经推送完成的报关单状态修改
this.receiptMessageRepository.updateDeclearTaskStatus(declearTask.getPushTime(),
declearTask.getResponseTime(),
declearTask.getResponseResults(),
declearTask.getResponseContent(),
"1",
declearTask.getChmsignmentId().longValue());
});
}
}
......
......@@ -5,6 +5,7 @@ import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.*;
import com.erry.iclear.dateInterface.repository.ChmConsignmentDetailRepository;
import com.erry.iclear.dateInterface.repository.ChmConsignmentRepository;
import com.erry.iclear.dateInterface.util.NumberUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -51,7 +52,6 @@ public class ChmConsignmentDetailService {
result.setLevyTypeDic(levyTypeDictionaryEntries);
result.setLevyType(levyTypeDictionaryEntries.getChineseName());
}
//货号
//版本号
//第一计量单位(法定单位)
......@@ -60,8 +60,6 @@ public class ChmConsignmentDetailService {
result.setUnitLegalFirstId(firstUnitDictionaryEntries);
result.setUnitLegalFirst(firstUnitDictionaryEntries.getChineseName());
}
//第一法定数量
result.setQtyLegalFirst(BigDecimal.valueOf(mawbDetail.getFirstQty().doubleValue()));
//成交计量单位
......@@ -71,7 +69,6 @@ public class ChmConsignmentDetailService {
result.setKnockdownUnitDic(knockdownUnitEntries);
result.setKnockdownUnit(knockdownUnitEntries.getChineseName());
}
//商品规格、型号
result.setModel(mawbDetail.getGmodel());
//商品名称
......@@ -85,16 +82,12 @@ public class ChmConsignmentDetailService {
result.setHabitatDic(habitatDictonaryEntries);
result.setHabitat(habitatDictonaryEntries.getChineseName());
}
//第二计量单位
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()));
//成交币制
......@@ -104,7 +97,6 @@ public class ChmConsignmentDetailService {
result.setCurrency(currencyDictionaryEntries.getChineseName());
}
//用途/生产厂家
//工缴费
//最终目的国
......@@ -114,8 +106,6 @@ public class ChmConsignmentDetailService {
result.setDestinationCountry(destinationCountryDictionaryEntries.getChineseName());
}
//检验检疫编码
//申报货物英文名称
result.setContentDescription(mawbDetail.getDeclGoodsEname());
......@@ -126,27 +116,107 @@ public class ChmConsignmentDetailService {
result.setOrigplacecode(Objects.equals(origplacecodeMapping,null)?"":origplacecodeMapping.getOrigplaceName());
}
//境内目的地/境内货源地
DomesticDestinationMapping domesticDestinationDictionaryEntries = Constant.domesticDestinationMappingCache.get(mawbDetail.getDistrictCode());
if(!Objects.equals(domesticDestinationDictionaryEntries,null)){
result.setDomesticDestinationMapping(domesticDestinationDictionaryEntries);
result.setDomesticDestination(Objects.equals(destinationCountryDictionaryEntries,null)?"":destinationCountryDictionaryEntries.getChineseName());
}
result.setDetailId(mawbDetail.getDetailId());
}catch (Exception e){
log.error("convertToChmConsignmentDetail() error:"+e.getMessage());
}
return result;
}
/**
* 转换运单明细
* @param detail
* @param gno
* @return
*/
public MawbDetail convertToChmConsignmentDetail(ChmConsignmentDetail detail,String gno){
MawbDetail result = new MawbDetail();
try{
//明细ID
result.setDetailId(detail.getId().toString());
//归类标志
result.setClassMark("");
//商品编号 必须是十位,不足的后补 00
result.setCodeTS(detail.getSkuCode());
//申报单价 小数点保留4位
result.setDeclPrice(NumberUtils.bigDecimalFormat(detail.getOriRegion(),4));
//申报总价 小数点保留2位
result.setDeclTotal(NumberUtils.bigDecimalFormat(detail.getAmount(),2));
//征免方式 数字一字码,0~9
if(!Objects.equals(detail.getLevyTypeDic(),null)){
result.setDutyMode(detail.getLevyTypeDic().getExt2());
}
//货号 有值传值,无值填空值
result.setExgNo("");
//版本号 有值传值,无值填空值
result.setExgVersion("");
//第一计量单位(法定单位) 数字三字码
if(!Objects.equals(detail.getUnitLegalFirstId(),null)){
result.setFirstUnit(detail.getUnitLegalFirstId().getExt2());
}
//第一法定数量
result.setFirstQty(NumberUtils.bigDecimalToIntger(detail.getQtyLegalFirst()));
//成交计量单位 数字三字码
if(!Objects.equals(detail.getKnockdownUnitDic(),null)){
result.setGunit(detail.getKnockdownUnitDic().getExt2());
}
//商品规格、型号
result.setGmodel(detail.getModel());
//商品名称 品名必填且必须包含中文字符
result.setGname(detail.getSkuName());
//商品序号
result.setGno(gno);
//成交数量
result.setGqty(detail.getKnockdownNumber());
//原产国 英文三字码
if(!Objects.equals(detail.getHabitatDic(),null)){
result.setOriginCountry(detail.getHabitatDic().getExt3());
}
//第二计量单位 数字三字码
if(!Objects.equals(detail.getUnitLegalSecondId(),null)){
result.setSecondUnit(detail.getUnitLegalSecondId().getExt2());
}
//第二法定数量
result.setSecondQty(NumberUtils.bigDecimalToIntger(detail.getQtyLegalSecond()));
//成交币制 英文三字码
if(!Objects.equals(detail.getCurrencyDic(),null)){
result.setTradeCurr(detail.getCurrencyDic().getExt2());
}
//用途/生产厂家
result.setUseTo("");
//工缴费
result.setWorkUsd(new BigDecimal(0));
//最终目的国 英文三字码
if(!Objects.equals(detail.getDestinationCountryDic(),null)){
result.setDestinationCountry(detail.getDestinationCountryDic().getExt3());
}
//检验检疫编码
result.setCiqCode("");
//申报货物英文名称
result.setDeclGoodsEname(detail.getContentDescription());
//目的地代码 有值传值,无值填空值
if(!Objects.equals(detail.getOrigplacecodeMapping(),null)){
result.setDestCode(detail.getOrigplacecodeMapping().getOrigplaceCode());
}else{
result.setDestCode("");
}
//境内目的地/境内货源地
if(!Objects.equals(detail.getDomesticDestinationMapping(),null)){
result.setDistrictCode(detail.getDomesticDestinationMapping().getDistrictCode());
}
result.setDetailId(detail.getDetailId());
}catch (Exception e){
log.error("convertToChmConsignmentDetail() error:"+e.getMessage());
}
return result;
}
public List<ChmConsignmentDetail> findChmConsignmentDetailListByConsignmentCode(Long consignmentId){
List<ChmConsignmentDetail> result = new ArrayList<>();
......@@ -158,28 +228,19 @@ public class ChmConsignmentDetailService {
return result;
}
public void saveDetailList(List<ChmConsignmentDetail> chmConsignmentDetailList){
chmConsignmentDetailRepository.saveAll(chmConsignmentDetailList);
}
public void saveChmConsignmentDetail(ChmConsignmentDetail consignmentDetail){
chmConsignmentDetailRepository.save(consignmentDetail);
}
public void deleteChmConsignmentDetail(Long id){
chmConsignmentDetailRepository.deleteById(id);
}
public void deleteChmConsignmentDetailBatch(List<Long> idList){
chmConsignmentDetailRepository.deleteChmConsignmentDetailByChnConIdList(idList);
}
}
......
......@@ -50,7 +50,7 @@ public class IClearApiTask {
/**
* TODO 定时任务:每分钟推送: 完整报文
*/
@Scheduled(cron = "${task.pushMawbTask}")
//@Scheduled(cron = "${task.pushMawbTask}")
public void pushMawbTask(){
try{
log.info("pushMawbTask start>>>>>>>>>>>>");
......
package com.erry.iclear.dateInterface.util;
import java.math.BigDecimal;
/**
* 数值处理类
* mt
* 2021年8月5日16:31:02
*/
public class NumberUtils {
/**
* 保留两位小数(四舍五入),0.00之后有数字全部保留位0.01
* @param bdForMat
* @return
*/
public static BigDecimal bigDecimalFormat(BigDecimal bdForMat,int num){
if(bdForMat != null){
bdForMat = bdForMat.setScale(num, BigDecimal.ROUND_HALF_UP);
if(bdForMat.compareTo(BigDecimal.ZERO) == 0){
bdForMat = new BigDecimal(0.01).setScale(num,BigDecimal.ROUND_HALF_UP);
}
return bdForMat;
}
return null;
}
/**
* 将Bigdecimal转换成Integer
* @param bigDecimal
* @return
*/
public static Integer bigDecimalToIntger(BigDecimal bigDecimal){
Integer integer = new Integer(0);
if(bigDecimal != null){
integer = bigDecimal.intValue();
}
return integer;
}
}
This diff is collapsed. Click to expand it.
......@@ -111,7 +111,7 @@ public class ChmConsignmentServiceTest extends IClearApiApplicationTests {
mawb.setFeeCurr("USD");
mawb.setFeeMark("3");
mawb.setFeeRate(BigDecimal.valueOf(100.58));
mawb.setGrossWet(500);
mawb.setGrossWet(BigDecimal.valueOf(500));
mawb.setIePort("0101");
mawb.setInputerName("");
mawb.setInsurCurr("MOP");
......
......@@ -148,7 +148,7 @@ public class HttpClientTest {
mawb.setFeeCurr("USD");
mawb.setFeeMark("3");
mawb.setFeeRate(BigDecimal.valueOf(100.58));
mawb.setGrossWet(500);
mawb.setGrossWet(BigDecimal.valueOf(500));
mawb.setIePort("0101");
mawb.setInputerName("");
mawb.setInsurCurr("MOP");
......