tao.mo

查询hscode代码提交

mt
2022年2月15日17:34:20
......@@ -2,13 +2,16 @@ package com.erry.iclear.dateInterface.api;
import com.erry.iclear.dateInterface.api.request.HsCodeParam;
import com.erry.iclear.dateInterface.api.response.ResultHsCode;
import com.erry.iclear.dateInterface.entity.IClearApiHsCodeLog;
import com.erry.iclear.dateInterface.service.HsCodeService;
import com.erry.iclear.dateInterface.service.IClearApiHsCodeLogService;
import com.erry.iclear.dateInterface.util.StringUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
/**
* @author Administrator
......@@ -21,6 +24,9 @@ public class HsCodeInterface {
@Autowired
HsCodeService hsCodeService;
@Autowired
IClearApiHsCodeLogService iClearApiHsCodeLogService;
@ApiOperation(value = "接收HsCode临时数据", httpMethod = "POST", notes = "ex: http://192.168.1.71:8080/hscode/hscodeRequest")
@PostMapping("/hscodeRequest")
@ResponseBody
......@@ -29,16 +35,43 @@ public class HsCodeInterface {
log.info("接收到请求数据hscode:【"+hscode.getHscode()+"】");
String appId = (String) request.getHeader("Appid");
String appkey = (String) request.getHeader("Appkey");
String timeStamp = (String) request.getHeader("TimeStamp");
String token = (String) request.getHeader("token");
if(!StringUtil.isEmpty(hscode.getHscode())){
ResultHsCode resultHsCode = hsCodeService.findHsCodeListByCode(hscode.getHscode());
return resultHsCode;
}else{
//如果没有传hscode需要限制10分钟只能只能查询一次
ResultHsCode resultHsCode = hsCodeService.findAllHsCodeList();
IClearApiHsCodeLog iclearApiHsCodeLog = new IClearApiHsCodeLog();
ResultHsCode resultHsCode = null;
long begin = System.currentTimeMillis();
try {
iclearApiHsCodeLog.setAppId(appId);
iclearApiHsCodeLog.setAppKey(appkey);
iclearApiHsCodeLog.setCreateTime(new Date());
iclearApiHsCodeLog.setCode(hscode.getHscode());
if (!StringUtil.isEmpty(hscode.getHscode())) {
resultHsCode = hsCodeService.findHsCodeListByCode(hscode.getHscode());
return resultHsCode;
} else {
//如果没有传hscode需要限制10分钟只能查询一次
boolean rs = iClearApiHsCodeLogService.findIClearApiHsCodeLog();
if(rs == true){
resultHsCode = new ResultHsCode(Boolean.FALSE,"10019","未指定hscode编码,10分钟之内只允许查询一次",null);
}else{
resultHsCode = hsCodeService.findAllHsCodeList();
}
return resultHsCode;
}
}catch(Exception ex){
log.error(ex.getMessage());
ex.printStackTrace();
resultHsCode = new ResultHsCode(Boolean.FALSE,"30101","数据查询异常",null);
return resultHsCode;
}finally {
iclearApiHsCodeLog.setReceiveResult(resultHsCode.getMsg());
iclearApiHsCodeLog.setErrorCode(resultHsCode.getCode());
iclearApiHsCodeLog.setResponseTime(new Date());
long end = System.currentTimeMillis();
iclearApiHsCodeLog.setSpendTime(end-begin);
//如果异常为hscode长度超过2000,将截取0到2000字符
if(resultHsCode.getCode().equals("30102")){
iclearApiHsCodeLog.setCode(iclearApiHsCodeLog.getCode().substring(0,2000));
}
iClearApiHsCodeLogService.saveIClearApiHsCodeLog(iclearApiHsCodeLog);
}
}
}
\ No newline at end of file
......
package com.erry.iclear.dateInterface.repository;
import com.erry.iclear.dateInterface.entity.IClearApiHsCodeLog;
import com.erry.iclear.dateInterface.entity.IClearApiLog;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
* @author Administrator
*/
@DynamicUpdate
@DynamicInsert
@Repository
@Transactional(rollbackFor = Exception.class)
public interface IClearApiHsCodeLogRepository extends JpaRepository<IClearApiHsCodeLog, Integer>, JpaSpecificationExecutor<IClearApiHsCodeLog> {
/**
*
* 根据hscode编码查询最新一条hscode信息
* @param createTime yyyy-MM-dd HH:mm
* @return
*/
@Query(nativeQuery = true,value = "select count(1) from T_ICLEAR_API_HSCODE_LOG where CREATE_TIME > ? AND (CODE IS NULL OR CODE = '')")
public Long findIClearApiHsCodeLog(String createTime);
}
......@@ -27,6 +27,11 @@ public class HsCodeService {
public ResultHsCode findHsCodeListByCode(String hscode){
ResultHsCode resultHsCode = new ResultHsCode(Boolean.FALSE,"","",null);
try{
if(hscode.length() > 2000){
resultHsCode.setCode("30102");
resultHsCode.setMsg("参数:hscode编码字段长度超过2000");
return resultHsCode;
}
String[] hscodeArrays = hscode.split(",");
if(hscodeArrays.length > 100){
resultHsCode.setCode("30100");
......
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.IClearApiHsCodeLog;
import com.erry.iclear.dateInterface.entity.IClearApiLog;
import com.erry.iclear.dateInterface.repository.IClearApiHsCodeLogRepository;
import com.erry.iclear.dateInterface.repository.IClearApiLogRepository;
import com.erry.iclear.dateInterface.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
*
* hscode请求日志
* mt
* 2022年2月15日15:46:18
*/
@Service
@Slf4j
public class IClearApiHsCodeLogService {
@Autowired
private IClearApiHsCodeLogRepository iClearApiHsCodeLogRepository;
/**
* 保存日志
* @param iClearApiHsCodeLog
*/
public IClearApiHsCodeLog saveIClearApiHsCodeLog(IClearApiHsCodeLog iClearApiHsCodeLog){
try{
return iClearApiHsCodeLogRepository.save(iClearApiHsCodeLog);
}catch (Exception e){
log.error("IClearApiHsCodeLog() error:"+ e.getMessage());
}
return null;
}
/**
* 查询日志,最近10分钟如果有查询过全量hscode则返回true
* @return
*/
public boolean findIClearApiHsCodeLog(){
boolean rs = false;
try{
Long count = iClearApiHsCodeLogRepository.findIClearApiHsCodeLog(DateUtils.getAfter10());
if(count > 0){
rs = true;
}
}catch(Exception ex){
ex.printStackTrace();
}
return rs;
}
}
......@@ -1479,9 +1479,20 @@ public class DateUtils {
return curDate.getTime();
}
/**
* 获取十分钟之前日期
*
* @return
*/
public static String getAfter10(){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE,cal.get(Calendar.MINUTE) - 10);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String dateStr = sdf.format(cal.getTime());
return dateStr;
}
public static Date timeStampToDate(long timeStamp){
return new Date(timeStamp);
}
}
}
\ No newline at end of file
......