Showing
5 changed files
with
148 additions
and
8 deletions
| ... | @@ -2,13 +2,16 @@ package com.erry.iclear.dateInterface.api; | ... | @@ -2,13 +2,16 @@ package com.erry.iclear.dateInterface.api; |
| 2 | 2 | ||
| 3 | import com.erry.iclear.dateInterface.api.request.HsCodeParam; | 3 | import com.erry.iclear.dateInterface.api.request.HsCodeParam; |
| 4 | import com.erry.iclear.dateInterface.api.response.ResultHsCode; | 4 | import com.erry.iclear.dateInterface.api.response.ResultHsCode; |
| 5 | +import com.erry.iclear.dateInterface.entity.IClearApiHsCodeLog; | ||
| 5 | import com.erry.iclear.dateInterface.service.HsCodeService; | 6 | import com.erry.iclear.dateInterface.service.HsCodeService; |
| 7 | +import com.erry.iclear.dateInterface.service.IClearApiHsCodeLogService; | ||
| 6 | import com.erry.iclear.dateInterface.util.StringUtil; | 8 | import com.erry.iclear.dateInterface.util.StringUtil; |
| 7 | import io.swagger.annotations.ApiOperation; | 9 | import io.swagger.annotations.ApiOperation; |
| 8 | import lombok.extern.slf4j.Slf4j; | 10 | import lombok.extern.slf4j.Slf4j; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.web.bind.annotation.*; | 12 | import org.springframework.web.bind.annotation.*; |
| 11 | import javax.servlet.http.HttpServletRequest; | 13 | import javax.servlet.http.HttpServletRequest; |
| 14 | +import java.util.Date; | ||
| 12 | 15 | ||
| 13 | /** | 16 | /** |
| 14 | * @author Administrator | 17 | * @author Administrator |
| ... | @@ -21,6 +24,9 @@ public class HsCodeInterface { | ... | @@ -21,6 +24,9 @@ public class HsCodeInterface { |
| 21 | @Autowired | 24 | @Autowired |
| 22 | HsCodeService hsCodeService; | 25 | HsCodeService hsCodeService; |
| 23 | 26 | ||
| 27 | + @Autowired | ||
| 28 | + IClearApiHsCodeLogService iClearApiHsCodeLogService; | ||
| 29 | + | ||
| 24 | @ApiOperation(value = "接收HsCode临时数据", httpMethod = "POST", notes = "ex: http://192.168.1.71:8080/hscode/hscodeRequest") | 30 | @ApiOperation(value = "接收HsCode临时数据", httpMethod = "POST", notes = "ex: http://192.168.1.71:8080/hscode/hscodeRequest") |
| 25 | @PostMapping("/hscodeRequest") | 31 | @PostMapping("/hscodeRequest") |
| 26 | @ResponseBody | 32 | @ResponseBody |
| ... | @@ -29,16 +35,43 @@ public class HsCodeInterface { | ... | @@ -29,16 +35,43 @@ public class HsCodeInterface { |
| 29 | log.info("接收到请求数据hscode:【"+hscode.getHscode()+"】"); | 35 | log.info("接收到请求数据hscode:【"+hscode.getHscode()+"】"); |
| 30 | String appId = (String) request.getHeader("Appid"); | 36 | String appId = (String) request.getHeader("Appid"); |
| 31 | String appkey = (String) request.getHeader("Appkey"); | 37 | String appkey = (String) request.getHeader("Appkey"); |
| 32 | - String timeStamp = (String) request.getHeader("TimeStamp"); | 38 | + IClearApiHsCodeLog iclearApiHsCodeLog = new IClearApiHsCodeLog(); |
| 33 | - String token = (String) request.getHeader("token"); | 39 | + ResultHsCode resultHsCode = null; |
| 34 | - | 40 | + long begin = System.currentTimeMillis(); |
| 35 | - if(!StringUtil.isEmpty(hscode.getHscode())){ | 41 | + try { |
| 36 | - ResultHsCode resultHsCode = hsCodeService.findHsCodeListByCode(hscode.getHscode()); | 42 | + iclearApiHsCodeLog.setAppId(appId); |
| 43 | + iclearApiHsCodeLog.setAppKey(appkey); | ||
| 44 | + iclearApiHsCodeLog.setCreateTime(new Date()); | ||
| 45 | + iclearApiHsCodeLog.setCode(hscode.getHscode()); | ||
| 46 | + if (!StringUtil.isEmpty(hscode.getHscode())) { | ||
| 47 | + resultHsCode = hsCodeService.findHsCodeListByCode(hscode.getHscode()); | ||
| 37 | return resultHsCode; | 48 | return resultHsCode; |
| 49 | + } else { | ||
| 50 | + //如果没有传hscode需要限制10分钟只能查询一次 | ||
| 51 | + boolean rs = iClearApiHsCodeLogService.findIClearApiHsCodeLog(); | ||
| 52 | + if(rs == true){ | ||
| 53 | + resultHsCode = new ResultHsCode(Boolean.FALSE,"10019","未指定hscode编码,10分钟之内只允许查询一次",null); | ||
| 38 | }else{ | 54 | }else{ |
| 39 | - //如果没有传hscode需要限制10分钟只能只能查询一次 | 55 | + resultHsCode = hsCodeService.findAllHsCodeList(); |
| 40 | - ResultHsCode resultHsCode = hsCodeService.findAllHsCodeList(); | 56 | + } |
| 41 | return resultHsCode; | 57 | return resultHsCode; |
| 42 | } | 58 | } |
| 59 | + }catch(Exception ex){ | ||
| 60 | + log.error(ex.getMessage()); | ||
| 61 | + ex.printStackTrace(); | ||
| 62 | + resultHsCode = new ResultHsCode(Boolean.FALSE,"30101","数据查询异常",null); | ||
| 63 | + return resultHsCode; | ||
| 64 | + }finally { | ||
| 65 | + iclearApiHsCodeLog.setReceiveResult(resultHsCode.getMsg()); | ||
| 66 | + iclearApiHsCodeLog.setErrorCode(resultHsCode.getCode()); | ||
| 67 | + iclearApiHsCodeLog.setResponseTime(new Date()); | ||
| 68 | + long end = System.currentTimeMillis(); | ||
| 69 | + iclearApiHsCodeLog.setSpendTime(end-begin); | ||
| 70 | + //如果异常为hscode长度超过2000,将截取0到2000字符 | ||
| 71 | + if(resultHsCode.getCode().equals("30102")){ | ||
| 72 | + iclearApiHsCodeLog.setCode(iclearApiHsCodeLog.getCode().substring(0,2000)); | ||
| 73 | + } | ||
| 74 | + iClearApiHsCodeLogService.saveIClearApiHsCodeLog(iclearApiHsCodeLog); | ||
| 75 | + } | ||
| 43 | } | 76 | } |
| 44 | } | 77 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | +package com.erry.iclear.dateInterface.repository; | ||
| 2 | + | ||
| 3 | +import com.erry.iclear.dateInterface.entity.IClearApiHsCodeLog; | ||
| 4 | +import com.erry.iclear.dateInterface.entity.IClearApiLog; | ||
| 5 | +import org.hibernate.annotations.DynamicInsert; | ||
| 6 | +import org.hibernate.annotations.DynamicUpdate; | ||
| 7 | +import org.springframework.data.jpa.repository.JpaRepository; | ||
| 8 | +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 9 | +import org.springframework.data.jpa.repository.Modifying; | ||
| 10 | +import org.springframework.data.jpa.repository.Query; | ||
| 11 | +import org.springframework.data.repository.query.Param; | ||
| 12 | +import org.springframework.stereotype.Repository; | ||
| 13 | +import org.springframework.transaction.annotation.Transactional; | ||
| 14 | + | ||
| 15 | +import java.util.Date; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * @author Administrator | ||
| 19 | + */ | ||
| 20 | +@DynamicUpdate | ||
| 21 | +@DynamicInsert | ||
| 22 | +@Repository | ||
| 23 | +@Transactional(rollbackFor = Exception.class) | ||
| 24 | +public interface IClearApiHsCodeLogRepository extends JpaRepository<IClearApiHsCodeLog, Integer>, JpaSpecificationExecutor<IClearApiHsCodeLog> { | ||
| 25 | + /** | ||
| 26 | + * | ||
| 27 | + * 根据hscode编码查询最新一条hscode信息 | ||
| 28 | + * @param createTime yyyy-MM-dd HH:mm | ||
| 29 | + * @return | ||
| 30 | + */ | ||
| 31 | + @Query(nativeQuery = true,value = "select count(1) from T_ICLEAR_API_HSCODE_LOG where CREATE_TIME > ? AND (CODE IS NULL OR CODE = '')") | ||
| 32 | + public Long findIClearApiHsCodeLog(String createTime); | ||
| 33 | +} |
| ... | @@ -27,6 +27,11 @@ public class HsCodeService { | ... | @@ -27,6 +27,11 @@ public class HsCodeService { |
| 27 | public ResultHsCode findHsCodeListByCode(String hscode){ | 27 | public ResultHsCode findHsCodeListByCode(String hscode){ |
| 28 | ResultHsCode resultHsCode = new ResultHsCode(Boolean.FALSE,"","",null); | 28 | ResultHsCode resultHsCode = new ResultHsCode(Boolean.FALSE,"","",null); |
| 29 | try{ | 29 | try{ |
| 30 | + if(hscode.length() > 2000){ | ||
| 31 | + resultHsCode.setCode("30102"); | ||
| 32 | + resultHsCode.setMsg("参数:hscode编码字段长度超过2000"); | ||
| 33 | + return resultHsCode; | ||
| 34 | + } | ||
| 30 | String[] hscodeArrays = hscode.split(","); | 35 | String[] hscodeArrays = hscode.split(","); |
| 31 | if(hscodeArrays.length > 100){ | 36 | if(hscodeArrays.length > 100){ |
| 32 | resultHsCode.setCode("30100"); | 37 | resultHsCode.setCode("30100"); | ... | ... |
| 1 | +package com.erry.iclear.dateInterface.service; | ||
| 2 | + | ||
| 3 | +import com.erry.iclear.dateInterface.api.request.Basfc; | ||
| 4 | +import com.erry.iclear.dateInterface.api.request.Mawb; | ||
| 5 | +import com.erry.iclear.dateInterface.common.Constant; | ||
| 6 | +import com.erry.iclear.dateInterface.entity.IClearApiHsCodeLog; | ||
| 7 | +import com.erry.iclear.dateInterface.entity.IClearApiLog; | ||
| 8 | +import com.erry.iclear.dateInterface.repository.IClearApiHsCodeLogRepository; | ||
| 9 | +import com.erry.iclear.dateInterface.repository.IClearApiLogRepository; | ||
| 10 | +import com.erry.iclear.dateInterface.util.DateUtils; | ||
| 11 | +import lombok.extern.slf4j.Slf4j; | ||
| 12 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 13 | +import org.springframework.stereotype.Service; | ||
| 14 | + | ||
| 15 | +import java.util.Date; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * | ||
| 19 | + * hscode请求日志 | ||
| 20 | + * mt | ||
| 21 | + * 2022年2月15日15:46:18 | ||
| 22 | + */ | ||
| 23 | +@Service | ||
| 24 | +@Slf4j | ||
| 25 | +public class IClearApiHsCodeLogService { | ||
| 26 | + @Autowired | ||
| 27 | + private IClearApiHsCodeLogRepository iClearApiHsCodeLogRepository; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 保存日志 | ||
| 31 | + * @param iClearApiHsCodeLog | ||
| 32 | + */ | ||
| 33 | + public IClearApiHsCodeLog saveIClearApiHsCodeLog(IClearApiHsCodeLog iClearApiHsCodeLog){ | ||
| 34 | + try{ | ||
| 35 | + return iClearApiHsCodeLogRepository.save(iClearApiHsCodeLog); | ||
| 36 | + }catch (Exception e){ | ||
| 37 | + log.error("IClearApiHsCodeLog() error:"+ e.getMessage()); | ||
| 38 | + } | ||
| 39 | + return null; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 查询日志,最近10分钟如果有查询过全量hscode则返回true | ||
| 44 | + * @return | ||
| 45 | + */ | ||
| 46 | + public boolean findIClearApiHsCodeLog(){ | ||
| 47 | + boolean rs = false; | ||
| 48 | + try{ | ||
| 49 | + Long count = iClearApiHsCodeLogRepository.findIClearApiHsCodeLog(DateUtils.getAfter10()); | ||
| 50 | + if(count > 0){ | ||
| 51 | + rs = true; | ||
| 52 | + } | ||
| 53 | + }catch(Exception ex){ | ||
| 54 | + ex.printStackTrace(); | ||
| 55 | + } | ||
| 56 | + return rs; | ||
| 57 | + } | ||
| 58 | +} |
| ... | @@ -1479,9 +1479,20 @@ public class DateUtils { | ... | @@ -1479,9 +1479,20 @@ public class DateUtils { |
| 1479 | return curDate.getTime(); | 1479 | return curDate.getTime(); |
| 1480 | } | 1480 | } |
| 1481 | 1481 | ||
| 1482 | + /** | ||
| 1483 | + * 获取十分钟之前日期 | ||
| 1484 | + * | ||
| 1485 | + * @return | ||
| 1486 | + */ | ||
| 1487 | + public static String getAfter10(){ | ||
| 1488 | + Calendar cal = Calendar.getInstance(); | ||
| 1489 | + cal.set(Calendar.MINUTE,cal.get(Calendar.MINUTE) - 10); | ||
| 1490 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | ||
| 1491 | + String dateStr = sdf.format(cal.getTime()); | ||
| 1492 | + return dateStr; | ||
| 1493 | + } | ||
| 1482 | 1494 | ||
| 1483 | public static Date timeStampToDate(long timeStamp){ | 1495 | public static Date timeStampToDate(long timeStamp){ |
| 1484 | return new Date(timeStamp); | 1496 | return new Date(timeStamp); |
| 1485 | } | 1497 | } |
| 1486 | - | ||
| 1487 | } | 1498 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment