Showing
5 changed files
with
183 additions
and
1 deletions
doc/FedEx在线申报系统API - iKnowU.docx
0 → 100644
No preview for this file type
| ... | @@ -15,7 +15,7 @@ import javax.servlet.http.HttpServletRequest; | ... | @@ -15,7 +15,7 @@ import javax.servlet.http.HttpServletRequest; |
| 15 | import java.util.Date; | 15 | import java.util.Date; |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * @author Administrator | 18 | + * @author mt |
| 19 | * /hscode/hscodeRequest | 19 | * /hscode/hscodeRequest |
| 20 | */ | 20 | */ |
| 21 | @RestController | 21 | @RestController | ... | ... |
| 1 | +package com.erry.iclear.dateInterface.api; | ||
| 2 | + | ||
| 3 | +import com.erry.iclear.dateInterface.api.request.HsCodeParam; | ||
| 4 | +import com.erry.iclear.dateInterface.api.response.ResultHsCode; | ||
| 5 | +import com.erry.iclear.dateInterface.entity.IClearApiHsCodeLog; | ||
| 6 | +import com.erry.iclear.dateInterface.enums.ErrorCodeEnum; | ||
| 7 | +import com.erry.iclear.dateInterface.service.HsCodeService; | ||
| 8 | +import com.erry.iclear.dateInterface.service.IClearApiHsCodeLogService; | ||
| 9 | +import com.erry.iclear.dateInterface.util.StringUtil; | ||
| 10 | +import io.swagger.annotations.ApiOperation; | ||
| 11 | +import lombok.extern.slf4j.Slf4j; | ||
| 12 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 13 | +import org.springframework.web.bind.annotation.*; | ||
| 14 | + | ||
| 15 | +import javax.servlet.http.HttpServletRequest; | ||
| 16 | +import java.util.Date; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * @author mt | ||
| 20 | + * /iknowU/stampQuery | ||
| 21 | + */ | ||
| 22 | +@RestController | ||
| 23 | +@RequestMapping("/iknowU") | ||
| 24 | +@Slf4j | ||
| 25 | +public class IKnowUInterface { | ||
| 26 | + | ||
| 27 | + @Autowired | ||
| 28 | + HsCodeService hsCodeService; | ||
| 29 | + | ||
| 30 | + @Autowired | ||
| 31 | + IClearApiHsCodeLogService iClearApiHsCodeLogService; | ||
| 32 | + | ||
| 33 | + @ApiOperation(value = "抠图后的公章查询", httpMethod = "POST", notes = "ex: http://192.168.1.71:8080/iknowU/stampQuery") | ||
| 34 | + @PostMapping("/stampQuery") | ||
| 35 | + @ResponseBody | ||
| 36 | + public ResultHsCode stampQuery(HttpServletRequest request | ||
| 37 | + , @RequestBody String consignmentCode) { | ||
| 38 | + log.info("接收到请求数据hscode:【"+consignmentCode+"】"); | ||
| 39 | + String appId = (String) request.getHeader("Appid"); | ||
| 40 | + String appkey = (String) request.getHeader("Appkey"); | ||
| 41 | + IClearApiHsCodeLog iclearApiHsCodeLog = new IClearApiHsCodeLog(); | ||
| 42 | + ResultHsCode resultHsCode = null; | ||
| 43 | + long begin = System.currentTimeMillis(); | ||
| 44 | + try { | ||
| 45 | + iclearApiHsCodeLog.setAppId(appId); | ||
| 46 | + iclearApiHsCodeLog.setAppKey(appkey); | ||
| 47 | + iclearApiHsCodeLog.setCreateTime(new Date()); | ||
| 48 | + iclearApiHsCodeLog.setCode(consignmentCode); | ||
| 49 | + if (!StringUtil.isEmpty(consignmentCode)) { | ||
| 50 | + resultHsCode = hsCodeService.findHsCodeListByCode(consignmentCode); | ||
| 51 | + return resultHsCode; | ||
| 52 | + } else { | ||
| 53 | + //如果没有传hscode需要限制10分钟只能查询一次 | ||
| 54 | + boolean rs = iClearApiHsCodeLogService.findIClearApiHsCodeLog(appId); | ||
| 55 | + if(rs == true){ | ||
| 56 | + resultHsCode = new ResultHsCode(Boolean.FALSE, ErrorCodeEnum.ERROR_10019.getCode(),ErrorCodeEnum.ERROR_10019.getName(),null); | ||
| 57 | + }else{ | ||
| 58 | + resultHsCode = hsCodeService.findAllHsCodeList(); | ||
| 59 | + } | ||
| 60 | + return resultHsCode; | ||
| 61 | + } | ||
| 62 | + }catch(Exception ex){ | ||
| 63 | + log.error(ex.getMessage(),ex); | ||
| 64 | + resultHsCode = new ResultHsCode(Boolean.FALSE,ErrorCodeEnum.ERROR_30101.getCode(),ErrorCodeEnum.ERROR_30101.getName(),null); | ||
| 65 | + return resultHsCode; | ||
| 66 | + }finally { | ||
| 67 | + iclearApiHsCodeLog.setReceiveResult(resultHsCode.getMsg()); | ||
| 68 | + iclearApiHsCodeLog.setErrorCode(resultHsCode.getCode()); | ||
| 69 | + iclearApiHsCodeLog.setResponseTime(new Date()); | ||
| 70 | + long end = System.currentTimeMillis(); | ||
| 71 | + iclearApiHsCodeLog.setSpendTime(end-begin); | ||
| 72 | + //如果异常为hscode长度超过2000,将截取0到2000字符 | ||
| 73 | + if(resultHsCode.getCode().equals(ErrorCodeEnum.ERROR_30102.getCode())){ | ||
| 74 | + iclearApiHsCodeLog.setCode(consignmentCode.substring(0,2000)); | ||
| 75 | + } | ||
| 76 | + iClearApiHsCodeLogService.saveIClearApiHsCodeLog(iclearApiHsCodeLog); | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | +} |
| 1 | +package com.erry.iclear.dateInterface.api.response; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.erry.iclear.dateInterface.entity.HsCode; | ||
| 5 | +import lombok.AllArgsConstructor; | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 8 | +import java.io.Serializable; | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +@Data | ||
| 12 | +@AllArgsConstructor | ||
| 13 | +public class StampResult implements Serializable { | ||
| 14 | + //成功标识 | ||
| 15 | + private Boolean success = true; | ||
| 16 | + //结果编码 | ||
| 17 | + private String code; | ||
| 18 | + //错误信息 | ||
| 19 | + private String msg; | ||
| 20 | +} |
| 1 | +package com.erry.iclear.dateInterface.util; | ||
| 2 | + | ||
| 3 | +import sun.misc.BASE64Decoder; | ||
| 4 | +import sun.misc.BASE64Encoder; | ||
| 5 | +import java.io.*; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 文件处理工具类 | ||
| 9 | + * mt | ||
| 10 | + * 2023年6月7日10:25:04 | ||
| 11 | + */ | ||
| 12 | +public class FileUtils { | ||
| 13 | + /** | ||
| 14 | + * 本地文件(图片、excel等)转换成Base64字符串 | ||
| 15 | + * @param imgPath | ||
| 16 | + * @return | ||
| 17 | + * @throws Exception | ||
| 18 | + */ | ||
| 19 | + public static String convertFileToBase64(String imgPath) throws Exception{ | ||
| 20 | + byte[] data = null; | ||
| 21 | + InputStream in = null; | ||
| 22 | + // 读取图片字节数组 | ||
| 23 | + try { | ||
| 24 | + in = new FileInputStream(imgPath); | ||
| 25 | + data = new byte[in.available()]; | ||
| 26 | + in.read(data); | ||
| 27 | + } catch (IOException e) { | ||
| 28 | + e.printStackTrace(); | ||
| 29 | + }finally { | ||
| 30 | + if(in != null){ | ||
| 31 | + in.close(); | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | + // 对字节数组进行Base64编码,得到Base64编码的字符串 | ||
| 35 | + BASE64Encoder encoder = new BASE64Encoder(); | ||
| 36 | + String base64Str = encoder.encode(data); | ||
| 37 | + return base64Str; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 将base64字符串,生成文件 | ||
| 42 | + * @param fileBase64String | ||
| 43 | + * @param filePath | ||
| 44 | + * @param fileName | ||
| 45 | + * @return | ||
| 46 | + */ | ||
| 47 | + public static File convertBase64ToFile(String fileBase64String, String filePath, String fileName) { | ||
| 48 | + BufferedOutputStream bos = null; | ||
| 49 | + FileOutputStream fos = null; | ||
| 50 | + File file = null; | ||
| 51 | + try { | ||
| 52 | + File dir = new File(filePath); | ||
| 53 | + if (!dir.exists() && dir.isDirectory()) {//判断文件目录是否存在 | ||
| 54 | + dir.mkdirs(); | ||
| 55 | + } | ||
| 56 | + BASE64Decoder decoder = new BASE64Decoder(); | ||
| 57 | + byte[] bfile = decoder.decodeBuffer(fileBase64String); | ||
| 58 | + file = new File(filePath + File.separator + fileName); | ||
| 59 | + fos = new FileOutputStream(file); | ||
| 60 | + bos = new BufferedOutputStream(fos); | ||
| 61 | + bos.write(bfile); | ||
| 62 | + return file; | ||
| 63 | + } catch (Exception e) { | ||
| 64 | + e.printStackTrace(); | ||
| 65 | + return null; | ||
| 66 | + } finally { | ||
| 67 | + if (bos != null) { | ||
| 68 | + try { | ||
| 69 | + bos.close(); | ||
| 70 | + } catch (IOException e1) { | ||
| 71 | + e1.printStackTrace(); | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + if (fos != null) { | ||
| 75 | + try { | ||
| 76 | + fos.close(); | ||
| 77 | + } catch (IOException e1) { | ||
| 78 | + e1.printStackTrace(); | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | +} |
-
Please register or login to post a comment