| | |
| | | package com.doumee.service.business.impl.wms; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.TypeReference; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.HttpsUtil; |
| | | import com.doumee.core.wms.model.request.*; |
| | | import com.doumee.core.wms.model.response.WmsBaseDataResponse; |
| | | import com.doumee.core.wms.model.response.WmsBaseResponse; |
| | | import com.doumee.core.wms.model.response.WmsInventoryDataResponse; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.service.business.WmsService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * WMS平台对接Service实现 |
| | |
| | | * @date 2023/11/30 15:33 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class WmsServiceImpl implements WmsService { |
| | | @Autowired |
| | | private PlatformWmsJobMapper platformWmsJobMapper; |
| | |
| | | private PlatformJobMapper platformJobMapper; |
| | | @Autowired |
| | | private PlatformWmsDetailMapper platformWmsDetailMapper; |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | | private WmsInterfaceLogMapper wmsInterfaceLogMapper; |
| | | |
| | | /** |
| | | * 入库通知任务业务处理 |
| | | * @param job 参数 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public WmsBaseResponse<WmsBaseDataResponse> orderPlatformBind(PlatformJob job) { |
| | | if(StringUtils.isBlank(job.getBillCode()) || StringUtils.isBlank(job.getPlatformWmsCode())){ |
| | | |
| | | return null; |
| | | } |
| | | int type = 0; |
| | | if(Constants.equalsInteger(job.getType(),Constants.ONE) |
| | | || Constants.equalsInteger(job.getType(),Constants.THREE)){ |
| | | //如果是装货(出库) |
| | | type =1 ; |
| | | }else if(Constants.equalsInteger(job.getType(),Constants.ZERO) |
| | | || Constants.equalsInteger(job.getType(),Constants.TWO)){ |
| | | //如果是装货(出库) |
| | | type =0 ; |
| | | }else{ |
| | | return null; |
| | | } |
| | | WmsOrderPlatformRequest param = new WmsOrderPlatformRequest(); |
| | | param.setData(new ArrayList<>()); |
| | | WmsOrderPlatformInfoRequest o = new WmsOrderPlatformInfoRequest(); |
| | | o.setCarrierBillCode(job.getBillCode()); |
| | | o.setRailwayNo(job.getPlatformWmsCode()); |
| | | param.getData().add(o); |
| | | String url = type == 0?systemDictDataBiz.queryByCode(Constants.WSM_PARAM,Constants.WMS_INBOUND_PLATFROM_URL).getCode():systemDictDataBiz.queryByCode(Constants.WSM_PARAM,Constants.WMS_OUTBOUND_PLATFROM_URL).getCode();; |
| | | String name = type ==0?"【WMS】入庫作业单分配月台":"【WMS】出库作业的分配月台"; |
| | | WmsBaseResponse<WmsBaseDataResponse> response = sendHttpRequest(url,name,JSONObject.toJSONString(param),new TypeReference< WmsBaseResponse<WmsBaseDataResponse>>(){}); |
| | | PlatformJob update = new PlatformJob(); |
| | | update.setId(job.getId()); |
| | | update.setWmsSendDate(new Date()); |
| | | update.setWmsSendNum(job.getWmsSendNum() + 1); |
| | | update.setWmsSendPlatformCode(job.getPlatformWmsCode()); |
| | | if(response!=null && response.getData() !=null |
| | | && response.getData().size()>0 && StringUtils.equals(response.getData().get(0).getSuccess(),WmsBaseResponse.CODE_SUCCESS)){ |
| | | //如果成功 |
| | | update.setWmsSendStatus(Constants.ONE); |
| | | update.setWmsSendInfo("通知WMS作业单分配月台成功"); |
| | | }else{ |
| | | //如果失败 |
| | | update.setWmsSendStatus(Constants.TWO); |
| | | update.setWmsSendInfo("通知WMS作业单分配月台失败:"+(response!=null?JSONObject.toJSONString(response):"接口调用失败")); |
| | | } |
| | | platformJobMapper.updateById(update); |
| | | return response; |
| | | |
| | | } |
| | | /** |
| | | * 入库通知任务业务处理 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public WmsBaseResponse<WmsInventoryDataResponse> getInventoryList(){ |
| | | String url = systemDictDataBiz.queryByCode(Constants.WSM_PARAM,Constants.WMS_GET_INVENTORYLIST_URL).getCode() ; |
| | | String name = "【WMS】库存查询" ; |
| | | WmsBaseResponse<WmsInventoryDataResponse> response = sendHttpRequest(url,name,JSONObject.toJSONString(new JSONObject()),new TypeReference< WmsBaseResponse<WmsInventoryDataResponse>>(){}); |
| | | if(response!=null |
| | | && response.getData() !=null |
| | | && response.getData().size()>0 |
| | | && StringUtils.equals(response.getData().get(0).getSuccess(),WmsBaseResponse.CODE_SUCCESS)){ |
| | | //如果请求成功 |
| | | |
| | | }else{ |
| | | //如果失败 |
| | | if(response ==null){ |
| | | response = new WmsBaseResponse(); |
| | | response.setData(new ArrayList<>()); |
| | | } |
| | | if(response.getData() == null){ |
| | | response.setData(new ArrayList<>()); |
| | | } |
| | | } |
| | | return response; |
| | | |
| | | } |
| | | @Override |
| | | public void saveInterfaceLog(String url,String name,String param,Integer success,String respone,int type){ |
| | | if(wmsInterfaceLogMapper ==null){ |
| | | return; |
| | | } |
| | | WmsInterfaceLog log = new WmsInterfaceLog(); |
| | | log.setCreateDate(new Date()); |
| | | log.setUrl(url); |
| | | log.setEditDate(log.getCreateDate()); |
| | | log.setPlat(Constants.ZERO); |
| | | log.setName(name); |
| | | log.setIsdeleted(Constants.ZERO); |
| | | log.setRequest(param); |
| | | log.setType(type); |
| | | log.setSuccess(success); |
| | | log.setRepose(respone); |
| | | wmsInterfaceLogMapper.insert(log); |
| | | } |
| | | |
| | | /** |
| | | * 发起wms接口请求 |
| | | * @param url |
| | | * @param name |
| | | * @param param |
| | | * @param typeReference |
| | | * @return |
| | | * @param <T> |
| | | */ |
| | | public <T> WmsBaseResponse<T> sendHttpRequest(String url, String name, String param,TypeReference<WmsBaseResponse<T>> typeReference){ |
| | | log.info("【"+name+"】================开始===="+ JSONObject.toJSONString(param)); |
| | | if ( StringUtils.isNotBlank(url)) { |
| | | String res = null; |
| | | int success = 0; |
| | | try { |
| | | Map<String,String> headers = new HashMap<>(); |
| | | res = HttpsUtil.postJson(url,param); |
| | | WmsBaseResponse result = JSONObject.parseObject(res, typeReference.getType()); |
| | | logResult(result,name); |
| | | if(result!=null && result.getData() !=null ){ |
| | | |
| | | }else{ |
| | | success =1; |
| | | } |
| | | return result; |
| | | }catch (Exception e){ |
| | | success = 1; |
| | | log.error("【"+name+"】================失败===="+ JSONObject.toJSONString(param)); |
| | | }finally { |
| | | saveInterfaceLog(url,name,param,success,res,Constants.ZERO); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | private static void logResult(WmsBaseResponse<WmsBaseDataResponse> res,String name) { |
| | | if(StringUtils.equals(res.getData().get(0).getSuccess(), WmsBaseResponse.CODE_SUCCESS)){ |
| | | log.info("【WMS接口:"+name+"】================成功====\n"+res); |
| | | }else{ |
| | | log.error("【WMS接口:"+name+"】================失败====:\n"+ res); |
| | | } |
| | | } |
| | | /** |
| | | * 入库通知任务业务处理 |
| | | * @param list 参数 |
| | |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public WmsBaseResponse inboundNotice(List<WmsInboundNoticeRequest> list) { |
| | | public WmsBaseResponse<WmsBaseDataResponse> inboundNotice(List<WmsInboundNoticeRequest> list) { |
| | | if(list ==null || list.size() ==0){ |
| | | return returnFailReuslt("请求参数不正确,参数不能为空"); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | |
| | | |
| | | private WmsBaseResponse returnSuccessReuslt(String msg) { |
| | | WmsBaseResponse response = new WmsBaseResponse(); |
| | | response.setData(new ArrayList<>()); |