123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- package com.galaxis.soap.wms;
- import com.galaxis.soap.wms.obj.*;
- import lombok.SneakyThrows;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.io.FileUtils;
- import org.apache.commons.io.FilenameUtils;
- import org.apache.commons.io.IOUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.core.io.ClassPathResource;
- import javax.jws.WebService;
- import javax.xml.namespace.QName;
- import javax.xml.ws.Service;
- import java.io.File;
- import java.net.URL;
- import java.nio.charset.StandardCharsets;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.concurrent.*;
- import java.util.function.BiFunction;
- import java.util.function.Function;
- @WebService(serviceName = "WMSService", // 与接口中指定的name一致
- targetNamespace = "http://service.jztd.com", // 与接口中的命名空间一致,一般是接口的包名倒
- endpointInterface = "com.galaxis.soap.wms.WMSService"// 接口地址
- )
- @Slf4j
- public class WMSServiceImpl implements WMSService {
- private static final String errorMsg = "当前下传数据中存在多个仓库的业务数据下传失败,请检查数据,一次只能下传一个仓库的业务数据";
- private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(
- 512,
- 512,
- 1,
- TimeUnit.SECONDS,
- new LinkedBlockingQueue<>(4096)
- );
- private static final String API = "/wms/api";
- // 山西
- private static final String SX = "http://10.100.0.100:9115";
- // 重庆
- // private static final String CQ = "http://127.0.0.1:8182";
- private static final String CQ = "http://10.100.0.100:9105";
- // 广西
- private static final String GX = "http://10.100.0.100:9101";
- // 四川
- private static final String SC = "http://10.100.0.100:9106";
- // 成都
- private static final String CD = "http://10.100.0.100:9106";
- // 贵州
- private static final String GZ = "http://10.100.0.100:9102";
- // 海南
- private static final String HN = "http://10.100.0.100:9109";
- // 河南
- private static final String HEN = "http://10.0.30.225:8110";
- // 云南
- private static final String YN = "http://10.0.30.220:18999";
- // 云南D300
- private static final String YND300 = "http://10.0.30.220:28999";
- // 云南D900
- private static final String YND900 = "http://10.0.30.220:38999";
- // D112
- private static final String D112 = "http://10.0.30.225:8999";
- // 上海 D907 D107
- private static final String D907 = "http://10.0.30.225:18999";
- // D118河南一心堂康健药业有些公司
- private static final String D118 = "http://10.0.30.220:28118";
- // 天津 D117
- private static final String D117 = "http://10.0.30.218:18999";
- private static final String D908 = "http://10.100.0.100:9908";
- // 物流中心编码与WebService服务映射
- private static final ConcurrentMap<String, String> WMS_MAPPING = new ConcurrentHashMap<String, String>() {{
- put("D104", SX); // 山西鸿翔一心堂药业有限公司
- put("D103", SC); // 四川鸿翔一心堂药业有限公司
- put("D105", CQ); // 重庆鸿翔一心堂药业有限公司
- put("D107", D907); // 上海鸿翔一心堂药业有限公司
- put("D101", GX); // 广西鸿翔一心堂药业有限公司
- put("D110", HEN); // 河南鸿翔一心堂药业有限公司
- put("D115", SX); // 一心堂药业(山西)有限公司
- put("D102", GZ); // 贵州鸿翔-一心堂药业有限公司
- put("D106", CD); // 成都鸿翔一心堂药业有限公司
- put("D109", HN); // 海南鸿翔一心堂药业有限公司
- put("D301", HN); // 海南一心堂医药有限公司
- put("D100", YN); // 一心堂药业集团股份有限公司
- put("D300", YND300); // 云南鸿云药业有限公司
- put("D108", ""); // 天津鸿翔一心堂药业有限公司
- put("D900", YND900); // 一心到家科技公司(电商仓)
- put("D504", ""); // 医云医疗产业发展(云南)有限公司
- put("D112", D112); // 山西一心堂广生药业连锁有限公司
- put("D118", D118); // 河南一心堂康健药业有些公司
- put("D117", D117); // 天津一心堂乾昌药业连锁有限公司
- put("D908", D908);
- }};
- private static final ConcurrentMap<String, WMSService> SERVICE_MAPPING = new ConcurrentHashMap<>(WMS_MAPPING.size());
- @SneakyThrows
- public WMSServiceImpl() {
- // final String wsdl = IOUtils.toString(new ClassPathResource("WMSService.xml").getInputStream(), StandardCharsets.UTF_8);
- final String wsdl = IOUtils.toString(new ClassPathResource("YN_WMSService.xml.xml").getInputStream(), StandardCharsets.UTF_8);
- final String usrHome = System.getProperty("user.home");
- for (Map.Entry<String, String> entry : WMS_MAPPING.entrySet()) {
- final String bwkey = entry.getKey();
- final String host = entry.getValue();
- log.info("### {} -> {}", bwkey, host);
- if (StringUtils.isBlank(host)) {
- continue;
- }
- // URL url = new URL(host + API + "?wsdl");
- String location = host + API;
- File file = new File(FilenameUtils.concat(usrHome, bwkey + ".wsdl.xml"));
- FileUtils.writeStringToFile(file, StringUtils.replace(wsdl, "#{__location}", location), StandardCharsets.UTF_8);
- URL url = file.toURI().toURL();
- QName qName = new QName("http://service.jztd.com", "WMSService");
- Service service = Service.create(url, qName);
- service.setExecutor(EXECUTOR);
- WMSService wmsService = service.getPort(WMSService.class);
- SERVICE_MAPPING.put(bwkey, wmsService);
- }
- }
- private <P, R> List<R> distribute(final String method, List<P> params, Function<P, String> getBWKEY, BiFunction<WMSService, List<P>, List<R>> execute) {
- log.info("method={} | params={}", method, params);
- if (params == null) {
- params = new ArrayList<>();
- }
- // 拆分参数
- final Map<String, List<P>> paramsMap = new HashMap<>();
- for (P param : params) {
- paramsMap.computeIfAbsent(getBWKEY.apply(param), bwkey -> new ArrayList<>()).add(param);
- }
- // 分发数据
- Map<String, Future<List<R>>> futureMap = new HashMap<>(paramsMap.size());
- for (Map.Entry<String, List<P>> entry : paramsMap.entrySet()) {
- final String bwkey = entry.getKey();
- final List<P> list = entry.getValue();
- final WMSService wmsService = SERVICE_MAPPING.get(bwkey);
- if (wmsService == null || list == null || list.isEmpty()) {
- log.error("不能分发数据:method={} | bwkey={} | params={}", method, bwkey, list);
- continue;
- }
- Future<List<R>> future = EXECUTOR.submit(() -> {
- log.info("分发数据:method={} | bwkey={} | params={}", method, bwkey, list);
- return execute.apply(wmsService, list);
- });
- futureMap.put(bwkey, future);
- }
- // 收集返回数据
- final List<R> res = new ArrayList<>(params.size());
- for (Map.Entry<String, Future<List<R>>> entry : futureMap.entrySet()) {
- final String bwkey = entry.getKey();
- final Future<List<R>> future = entry.getValue();
- try {
- res.addAll(future.get());
- } catch (Exception e) {
- log.info("分发数据失败:method={} | bwkey={}", method, bwkey, e);
- }
- }
- return res;
- }
- @Override
- public List<DT_KUNNR_IN_RT_01> MT_KUNNR_IN_WMS01(List<DT_KUNNR_IN_01> params) {
- return distribute(
- "MT_KUNNR_IN_WMS01",
- params,
- DT_KUNNR_IN_01::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS01
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_02> MT_KUNNR_IN_WMS02(List<DT_KUNNR_IN_02> params) {
- return distribute(
- "MT_KUNNR_IN_WMS02",
- params,
- DT_KUNNR_IN_02::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS02
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_03> MT_KUNNR_IN_WMS03(List<DT_KUNNR_IN_03> params) {
- return distribute(
- "MT_KUNNR_IN_WMS03",
- params,
- DT_KUNNR_IN_03::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS03
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_04> MT_KUNNR_IN_WMS04(List<DT_KUNNR_IN_04> params) {
- return distribute(
- "MT_KUNNR_IN_WMS04",
- params,
- DT_KUNNR_IN_04::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS04
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_06> MT_KUNNR_IN_WMS06(List<DT_KUNNR_IN_06> params) {
- return distribute(
- "MT_KUNNR_IN_WMS06",
- params,
- DT_KUNNR_IN_06::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS06
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_08> MT_KUNNR_IN_WMS08(List<DT_KUNNR_IN_08> params) {
- return distribute(
- "MT_KUNNR_IN_WMS08",
- params,
- DT_KUNNR_IN_08::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS08
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_09> MT_KUNNR_IN_WMS09(List<DT_KUNNR_IN_09> params) {
- return distribute(
- "MT_KUNNR_IN_WMS09",
- params,
- DT_KUNNR_IN_09::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS09
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_14> MT_KUNNR_IN_WMS14(List<DT_KUNNR_IN_14> params) {
- return distribute(
- "MT_KUNNR_IN_WMS14",
- params,
- DT_KUNNR_IN_14::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS14
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_10_2> MT_KUNNR_IN_WMS10_2(List<DT_KUNNR_IN_10_2> params) {
- return distribute(
- "MT_KUNNR_IN_WMS10_2",
- params,
- DT_KUNNR_IN_10_2::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS10_2
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_16> MT_KUNNR_IN_WMS16(List<DT_KUNNR_IN_16> params) {
- return distribute(
- "MT_KUNNR_IN_WMS16",
- params,
- DT_KUNNR_IN_16::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS16
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_17> MT_KUNNR_IN_WMS17(List<DT_KUNNR_IN_17> params) {
- return distribute(
- "MT_KUNNR_IN_WMS17",
- params,
- DT_KUNNR_IN_17::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS17
- );
- }
- @Override
- public List<DT_KUNNR_IN_RT_18> MT_KUNNR_IN_WMS18(List<DT_KUNNR_IN_18> params) {
- return distribute(
- "MT_KUNNR_IN_WMS18",
- params,
- DT_KUNNR_IN_18::getBWKEY,
- WMSService::MT_KUNNR_IN_WMS18
- );
- }
- }
|