正在显示
1 个修改的文件
包含
159 行增加
和
0 行删除
1 | +package com.sy.groovy | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON | ||
4 | +import com.alibaba.fastjson.JSONArray | ||
5 | +import com.alibaba.fastjson.JSONObject | ||
6 | +import com.sy.model.GatherInfo | ||
7 | +import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO | ||
8 | +import com.sy.model.LandBusinessTypeList | ||
9 | +import com.sy.response.ResultJson | ||
10 | +import com.sy.service.impl.GatherInfoHandle; | ||
11 | +import feign.Feign | ||
12 | +import feign.Headers | ||
13 | +import feign.Param; | ||
14 | +import feign.Request | ||
15 | +import feign.RequestLine; | ||
16 | +import feign.hystrix.FallbackFactory; | ||
17 | +import groovy.lang.Script; | ||
18 | +import org.basis.enhance.groovy.entity.ExecuteParams; | ||
19 | +import org.slf4j.Logger; | ||
20 | +import org.slf4j.LoggerFactory | ||
21 | +import org.springframework.context.ApplicationContext | ||
22 | + | ||
23 | +import java.util.stream.Collectors; | ||
24 | + | ||
25 | +/** | ||
26 | + * 单证验放 | ||
27 | + * 放行验放 | ||
28 | + */ | ||
29 | +class BillDomTransportCheck extends Script implements ChannelCheckScript { | ||
30 | + | ||
31 | + private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
32 | + | ||
33 | + @Override | ||
34 | + Boolean check(ExecuteParams executeParams) { | ||
35 | + try { | ||
36 | + String cookieUserName = "admin" | ||
37 | + String cookieUserId = "1903e605-a2e1-404d-a1a6-a749752fb030" | ||
38 | + String ServiceAdr = "http://192.168.1.63:10001" | ||
39 | + | ||
40 | + GatherInfo gatherInfo = (GatherInfo) executeParams.get("GatherInfo"); | ||
41 | + LandBusinessTypeList landBusinessTypeList = (LandBusinessTypeList) executeParams.get("ChanelFormInfo"); | ||
42 | + List<LAND_BUSINEESTYPE_LIST_INFO> listinfos = (List<LAND_BUSINEESTYPE_LIST_INFO>) executeParams.get("ChanelFormBillLists"); | ||
43 | + | ||
44 | + // 调用方法 | ||
45 | + ApplicationContext context = getContext(); | ||
46 | + // 获取容器中的bean | ||
47 | + GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class); | ||
48 | + | ||
49 | + if (listinfos!=null && !listinfos.isEmpty()){ | ||
50 | + //数组过滤,只要单证,不要其他 板箱之类 | ||
51 | + List<LAND_BUSINEESTYPE_LIST_INFO> list_infos = listinfos.stream().filter({ listInfo -> | ||
52 | + if ("B".equals(listInfo.getExt4())) { | ||
53 | + return true; | ||
54 | + } else { | ||
55 | + return false; | ||
56 | + } | ||
57 | + }).collect(Collectors.toList()); | ||
58 | + | ||
59 | + list_infos.forEach({bill-> | ||
60 | + // 创建 Feign Client | ||
61 | + //https://nmms.zzcargo.com:8443/api/wlpt-nmms-manage/trans/dom?originFlightno=&originFlightdate=&originFlightdateEnd=&originMasterwaybill=ML66158691&agentName=&transType=dom&pageNum=1&pageSize=10 | ||
62 | + MyFeignClient myFeignClient = createFeignClient(MyFeignClient, ServiceAdr,cookieUserName,cookieUserId); | ||
63 | + | ||
64 | + // 调用第三方接口 | ||
65 | + String response = myFeignClient.callThirdPartyApi(bill.getAwba(),cookieUserName,cookieUserId); | ||
66 | + logger.info("[TRANS-API-RESPONSE]-{}",response) | ||
67 | + | ||
68 | + // 处理响应结果... | ||
69 | + //返回的ResultJson实体类 | ||
70 | + JSONObject jo = JSONObject.parseObject(response); | ||
71 | + StringBuilder sb = new StringBuilder(""); | ||
72 | + if ("200".equals(jo.getString("code"))){ | ||
73 | + //获取返回列表 data->list | ||
74 | + JSONObject rData = jo.getJSONObject("data") | ||
75 | + if (rData!=null){ | ||
76 | + JSONArray rList = rData.getJSONArray("list") | ||
77 | + if (rList!=null && !rList.isEmpty()){ | ||
78 | + rList.forEach({ item -> | ||
79 | + JSONObject jsonObject = (JSONObject) item; | ||
80 | + Integer status = jsonObject.getInteger("status") | ||
81 | + String oBill = jsonObject.getString("originMasterwaybill") | ||
82 | + logger.info("[TRANS-API-RESPONSE]-单证:{},状态:{}",oBill,status) | ||
83 | + | ||
84 | + if (status>0){ | ||
85 | +// return true | ||
86 | + }else{ | ||
87 | + sb.append("转运单证[").append(bill.getAwba()).append("]核验失败,未审核通过") | ||
88 | + gatherInfoHandle.sendBw(gatherInfo,false,sb.toString(),landBusinessTypeList,listinfos); | ||
89 | + return false | ||
90 | + } | ||
91 | + }) | ||
92 | + } | ||
93 | + } | ||
94 | + }else{ | ||
95 | + logger.info("[TRANS-CHECK-FAILD]-转运单证{}核验失败",bill.getAwba()) | ||
96 | + sb.append("转运单证[").append(bill.getAwba()).append("]核验失败,API-FAILD") | ||
97 | + gatherInfoHandle.sendBw(gatherInfo,false,sb.toString(),landBusinessTypeList,listinfos); | ||
98 | + return false; | ||
99 | + } | ||
100 | + }) | ||
101 | + //这里返回验放成功,验放失败从上面返回 | ||
102 | + return true; | ||
103 | + }else{ | ||
104 | + return false; | ||
105 | + } | ||
106 | + | ||
107 | + } catch (Exception e) { | ||
108 | + e.printStackTrace(); | ||
109 | + logger.error("[CACHE-PARSE-ERROR]:", e); | ||
110 | + return false; | ||
111 | + } | ||
112 | + } | ||
113 | + | ||
114 | + @Override | ||
115 | + Object run() { | ||
116 | + return false; | ||
117 | + } | ||
118 | + | ||
119 | + | ||
120 | + // 获取spring容器 | ||
121 | + ApplicationContext getContext() { | ||
122 | + // 获取spring IOC容器 | ||
123 | + ApplicationContext context = applicationContext; | ||
124 | + return context; | ||
125 | + } | ||
126 | + | ||
127 | + private <T> T createFeignClient(Class<T> clientClass, String url,String username, String userid) { | ||
128 | + return Feign.builder() | ||
129 | + .options(new Request.Options(5000, 5000)) | ||
130 | + .requestInterceptor({ requestTemplate -> | ||
131 | + String cookieValue = "username=" + username + "; userid=" + userid; | ||
132 | + requestTemplate.header("Cookie", cookieValue); | ||
133 | + }) | ||
134 | + .target(clientClass, url); | ||
135 | + } | ||
136 | + | ||
137 | + | ||
138 | + interface MyFeignClient { | ||
139 | + @RequestLine("GET /trans/dom?originMasterwaybill={originMasterwaybill}") | ||
140 | + @Headers("Cookie: username={username}; userid={userid}") | ||
141 | + String callThirdPartyApi(@Param("originMasterwaybill") String originMasterwaybill, | ||
142 | + @Param("username") String username, | ||
143 | + @Param("userid") String userid); | ||
144 | + } | ||
145 | + | ||
146 | + class MyFallbackFactory implements FallbackFactory<MyFeignClient> { | ||
147 | + @Override | ||
148 | + public MyFeignClient create(Throwable throwable) { | ||
149 | + return new MyFeignClient() { | ||
150 | + @Override | ||
151 | + public String callThirdPartyApi(String originMasterwaybill,String username,String userid) { | ||
152 | + // 处理 fallback 逻辑... | ||
153 | + ResultJson resultJson = new ResultJson("400","访问接口出错"); | ||
154 | + return JSON.toJSONString(resultJson); | ||
155 | + } | ||
156 | + }; | ||
157 | + } | ||
158 | + } | ||
159 | +} |
-
请 注册 或 登录 后发表评论