WMSServiceImpl.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. package com.galaxis.soap.wms;
  2. import com.galaxis.soap.wms.obj.*;
  3. import lombok.SneakyThrows;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.apache.commons.io.FileUtils;
  6. import org.apache.commons.io.FilenameUtils;
  7. import org.apache.commons.io.IOUtils;
  8. import org.apache.commons.lang3.StringUtils;
  9. import org.springframework.core.io.ClassPathResource;
  10. import javax.jws.WebService;
  11. import javax.xml.namespace.QName;
  12. import javax.xml.ws.Service;
  13. import java.io.File;
  14. import java.net.URL;
  15. import java.nio.charset.StandardCharsets;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.concurrent.*;
  21. import java.util.function.BiFunction;
  22. import java.util.function.Function;
  23. @WebService(serviceName = "WMSService", // 与接口中指定的name一致
  24. targetNamespace = "http://service.jztd.com", // 与接口中的命名空间一致,一般是接口的包名倒
  25. endpointInterface = "com.galaxis.soap.wms.WMSService"// 接口地址
  26. )
  27. @Slf4j
  28. public class WMSServiceImpl implements WMSService {
  29. private static final String errorMsg = "当前下传数据中存在多个仓库的业务数据下传失败,请检查数据,一次只能下传一个仓库的业务数据";
  30. private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(
  31. 512,
  32. 512,
  33. 1,
  34. TimeUnit.SECONDS,
  35. new LinkedBlockingQueue<>(4096)
  36. );
  37. private static final String API = "/wms/api";
  38. // 山西
  39. //private static final String SX = "http://127.0.0.1:8082";
  40. // 山西 Test
  41. // private static final String SX_TEST = "http://10.2.2.88:8082";
  42. // 重庆
  43. //private static final String CQ = "http://127.0.0.1:8182";
  44. // 重庆 test
  45. // private static final String CQ_TEST = "http://10.2.2.88:8084";
  46. // 广西
  47. // private static final String GX = "http://127.0.0.1:8282";
  48. // 广西 test
  49. // private static final String GX_TEST = "http://10.2.2.88:8083";
  50. // 四川
  51. //private static final String SC = "http://127.0.0.1:8382";
  52. // 四川 test
  53. // private static final String SC_TEST = "http://10.2.24.52:8082";
  54. // 成都
  55. //private static final String CD = "http://10.0.30.225:8106";
  56. // 成都 test
  57. // private static final String CD_TEST = "http://10.2.2.88:8085";
  58. // 贵州
  59. //private static final String GZ = "http://10.0.30.225:8102";
  60. // 贵州 test
  61. // private static final String GZ_TEST = "http://10.2.24.52:8083";
  62. // 海南
  63. // private static final String HN = "http://10.0.30.225:8109";
  64. // 海南 test
  65. // private static final String HN_TEST = "http://10.2.24.52:8084";
  66. // 河南
  67. // private static final String HEN = "http://10.0.30.225:8110";
  68. // 河南 test
  69. // private static final String HEN_TEST = "http://10.2.24.52:8085";
  70. // 云南
  71. // private static final String YN = "http://10.0.30.220:18999";
  72. // 云南pre
  73. // private static final String YN_PRE = "http://10.0.30.220:8999";
  74. // 云南 D100-pg-test
  75. private static final String YN_PG_TEST = "http://10.0.38.88:8999";
  76. // private static final String YN_PG_TEST = "http://10.0.42.210:9100";
  77. // 云南D300
  78. // private static final String YND300 = "http://10.0.30.220:28999";
  79. // 云南D300 test
  80. // private static final String YND300_TEST = "http://10.2.2.88:18999";
  81. private static final String YND300_PG_TEST = "http://10.0.42.210:9300";
  82. // 云南D900
  83. // private static final String YND900 = "http://10.2.2.88:8999";
  84. private static final String YND900_PG_TEST = "http://10.0.42.211:9900";
  85. // D112
  86. // private static final String D112 = "http://10.0.30.225:8999";
  87. // 上海 D907
  88. // private static final String D907 = "http://10.0.30.225:18999";
  89. // 天津 D117
  90. // private static final String D117 = "http://10.0.30.218:18999";
  91. // 物流中心编码与WebService服务映射
  92. private static final ConcurrentMap<String, String> WMS_MAPPING = new ConcurrentHashMap<String, String>() {{
  93. put("D104", ""); // 山西鸿翔一心堂药业有限公司
  94. put("D103", ""); // 四川鸿翔一心堂药业有限公司
  95. put("D105", ""); // 重庆鸿翔一心堂药业有限公司
  96. put("D907", ""); // 上海鸿翔一心堂药业有限公司
  97. put("D101", ""); // 广西鸿翔一心堂药业有限公司
  98. put("D110", ""); // 河南鸿翔一心堂药业有限公司
  99. put("D115", ""); // 一心堂药业(山西)有限公司
  100. put("D102", ""); // 贵州鸿翔-一心堂药业有限公司
  101. put("D106", ""); // 成都鸿翔一心堂药业有限公司
  102. put("D109", ""); // 海南鸿翔一心堂药业有限公司
  103. put("D301", ""); // 海南一心堂医药有限公司
  104. put("D100", YN_PG_TEST); // 一心堂药业集团股份有限公司
  105. put("D300", YND300_PG_TEST); // 云南鸿云药业有限公司
  106. put("D108", ""); // 天津鸿翔一心堂药业有限公司
  107. put("D900", YND900_PG_TEST); // 一心到家科技公司(电商仓)
  108. put("D504", ""); // 医云医疗产业发展(云南)有限公司
  109. put("D112", ""); // 山西一心堂广生药业连锁有限公司
  110. put("D117", ""); // 天津D117(天津一心堂乾昌药业连锁有限公司)
  111. }};
  112. private static final ConcurrentMap<String, WMSService> SERVICE_MAPPING = new ConcurrentHashMap<>(WMS_MAPPING.size());
  113. @SneakyThrows
  114. public WMSServiceImpl() {
  115. // final String wsdl = IOUtils.toString(new ClassPathResource("WMSService.xml").getInputStream(), StandardCharsets.UTF_8);
  116. final String wsdl = IOUtils.toString(new ClassPathResource("YN_WMSService.xml.xml").getInputStream(), StandardCharsets.UTF_8);
  117. final String usrHome = System.getProperty("user.home");
  118. for (Map.Entry<String, String> entry : WMS_MAPPING.entrySet()) {
  119. String bwkey = entry.getKey();
  120. String host = entry.getValue();
  121. log.info("### {} -> {}", bwkey, host);
  122. if (StringUtils.isBlank(host)) {
  123. continue;
  124. }
  125. // URL url = new URL(host + API + "?wsdl");
  126. String location = host + API;
  127. File file = new File(FilenameUtils.concat(usrHome, bwkey + ".wsdl.xml"));
  128. FileUtils.writeStringToFile(file, StringUtils.replace(wsdl, "#{__location}", location), StandardCharsets.UTF_8);
  129. URL url = file.toURI().toURL();
  130. QName qName = new QName("http://service.jztd.com", "WMSService");
  131. Service service = Service.create(url, qName);
  132. service.setExecutor(EXECUTOR);
  133. WMSService wmsService = service.getPort(WMSService.class);
  134. SERVICE_MAPPING.put(bwkey, wmsService);
  135. }
  136. }
  137. private <P, R> List<R> distribute(final String method, List<P> params, Function<P, String> getBWKEY, BiFunction<WMSService, List<P>, List<R>> execute) {
  138. log.info("method={} | params={}", method, params);
  139. if (params == null) {
  140. params = new ArrayList<>();
  141. }
  142. // 拆分参数
  143. final Map<String, List<P>> paramsMap = new HashMap<>();
  144. for (P param : params) {
  145. paramsMap.computeIfAbsent(getBWKEY.apply(param), bwkey -> new ArrayList<>()).add(param);
  146. }
  147. // 分发数据
  148. Map<String, Future<List<R>>> futureMap = new HashMap<>(paramsMap.size());
  149. for (Map.Entry<String, List<P>> entry : paramsMap.entrySet()) {
  150. final String bwkey = entry.getKey();
  151. final List<P> list = entry.getValue();
  152. final WMSService wmsService = SERVICE_MAPPING.get(bwkey);
  153. if (wmsService == null || list == null || list.isEmpty()) {
  154. log.error("不能分发数据:method={} | bwkey={} | params={}", method, bwkey, list);
  155. continue;
  156. }
  157. Future<List<R>> future = EXECUTOR.submit(() -> {
  158. log.info("分发数据:method={} | bwkey={} | params={}", method, bwkey, list);
  159. return execute.apply(wmsService, list);
  160. });
  161. futureMap.put(bwkey, future);
  162. }
  163. // 收集返回数据
  164. final List<R> res = new ArrayList<>(params.size());
  165. for (Map.Entry<String, Future<List<R>>> entry : futureMap.entrySet()) {
  166. final String bwkey = entry.getKey();
  167. final Future<List<R>> future = entry.getValue();
  168. try {
  169. res.addAll(future.get());
  170. } catch (Exception e) {
  171. log.info("分发数据失败:method={} | bwkey={}", method, bwkey, e);
  172. }
  173. }
  174. return res;
  175. }
  176. @Override
  177. public List<DT_KUNNR_IN_RT_01> MT_KUNNR_IN_WMS01(List<DT_KUNNR_IN_01> params) {
  178. return distribute(
  179. "MT_KUNNR_IN_WMS01",
  180. params,
  181. DT_KUNNR_IN_01::getBWKEY,
  182. WMSService::MT_KUNNR_IN_WMS01
  183. );
  184. }
  185. @Override
  186. public List<DT_KUNNR_IN_RT_02> MT_KUNNR_IN_WMS02(List<DT_KUNNR_IN_02> params) {
  187. return distribute(
  188. "MT_KUNNR_IN_WMS02",
  189. params,
  190. DT_KUNNR_IN_02::getBWKEY,
  191. WMSService::MT_KUNNR_IN_WMS02
  192. );
  193. }
  194. @Override
  195. public List<DT_KUNNR_IN_RT_03> MT_KUNNR_IN_WMS03(List<DT_KUNNR_IN_03> params) {
  196. return distribute(
  197. "MT_KUNNR_IN_WMS03",
  198. params,
  199. DT_KUNNR_IN_03::getBWKEY,
  200. WMSService::MT_KUNNR_IN_WMS03
  201. );
  202. }
  203. @Override
  204. public List<DT_KUNNR_IN_RT_04> MT_KUNNR_IN_WMS04(List<DT_KUNNR_IN_04> params) {
  205. return distribute(
  206. "MT_KUNNR_IN_WMS04",
  207. params,
  208. DT_KUNNR_IN_04::getBWKEY,
  209. WMSService::MT_KUNNR_IN_WMS04
  210. );
  211. }
  212. @Override
  213. public List<DT_KUNNR_IN_RT_06> MT_KUNNR_IN_WMS06(List<DT_KUNNR_IN_06> params) {
  214. return distribute(
  215. "MT_KUNNR_IN_WMS06",
  216. params,
  217. DT_KUNNR_IN_06::getBWKEY,
  218. WMSService::MT_KUNNR_IN_WMS06
  219. );
  220. }
  221. @Override
  222. public List<DT_KUNNR_IN_RT_08> MT_KUNNR_IN_WMS08(List<DT_KUNNR_IN_08> params) {
  223. return distribute(
  224. "MT_KUNNR_IN_WMS08",
  225. params,
  226. DT_KUNNR_IN_08::getBWKEY,
  227. WMSService::MT_KUNNR_IN_WMS08
  228. );
  229. }
  230. @Override
  231. public List<DT_KUNNR_IN_RT_09> MT_KUNNR_IN_WMS09(List<DT_KUNNR_IN_09> params) {
  232. return distribute(
  233. "MT_KUNNR_IN_WMS09",
  234. params,
  235. DT_KUNNR_IN_09::getBWKEY,
  236. WMSService::MT_KUNNR_IN_WMS09
  237. );
  238. }
  239. @Override
  240. public List<DT_KUNNR_IN_RT_14> MT_KUNNR_IN_WMS14(List<DT_KUNNR_IN_14> params) {
  241. return distribute(
  242. "MT_KUNNR_IN_WMS14",
  243. params,
  244. DT_KUNNR_IN_14::getBWKEY,
  245. WMSService::MT_KUNNR_IN_WMS14
  246. );
  247. }
  248. @Override
  249. public List<DT_KUNNR_IN_RT_10_2> MT_KUNNR_IN_WMS10_2(List<DT_KUNNR_IN_10_2> params) {
  250. return distribute(
  251. "MT_KUNNR_IN_WMS10_2",
  252. params,
  253. DT_KUNNR_IN_10_2::getBWKEY,
  254. WMSService::MT_KUNNR_IN_WMS10_2
  255. );
  256. }
  257. @Override
  258. public List<DT_KUNNR_IN_RT_16> MT_KUNNR_IN_WMS16(List<DT_KUNNR_IN_16> params) {
  259. return distribute(
  260. "MT_KUNNR_IN_WMS16",
  261. params,
  262. DT_KUNNR_IN_16::getBWKEY,
  263. WMSService::MT_KUNNR_IN_WMS16
  264. );
  265. }
  266. @Override
  267. public List<DT_KUNNR_IN_RT_17> MT_KUNNR_IN_WMS17(List<DT_KUNNR_IN_17> params) {
  268. return distribute(
  269. "MT_KUNNR_IN_WMS17",
  270. params,
  271. DT_KUNNR_IN_17::getBWKEY,
  272. WMSService::MT_KUNNR_IN_WMS17
  273. );
  274. }
  275. @Override
  276. public List<DT_KUNNR_IN_RT_18> MT_KUNNR_IN_WMS18(List<DT_KUNNR_IN_18> params) {
  277. return distribute(
  278. "MT_KUNNR_IN_WMS18",
  279. params,
  280. DT_KUNNR_IN_18::getBWKEY,
  281. WMSService::MT_KUNNR_IN_WMS18
  282. );
  283. }
  284. }