出口订单推送-数据推送修改 出口仓单推送
This commit is contained in:
+113
-50
@@ -1089,67 +1089,130 @@ public class ReservationStockOutOrderApplicationService {
|
||||
int failCount = 0;
|
||||
StringBuilder failMsg = new StringBuilder();
|
||||
|
||||
|
||||
for (Long id : idList) {
|
||||
GwStockOutOrder gwStockOutOrder = new GwStockOutOrder();
|
||||
|
||||
|
||||
// 查询出库单
|
||||
ReservationStockOutOrder reservationStockOutOrder = reservationStockOutOrderMapper.selectById(id);
|
||||
if (reservationStockOutOrder == null) {
|
||||
failCount++;
|
||||
failMsg.append("id:").append(id).append("不存在;");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取货主NC编码
|
||||
Long shipperId = reservationStockOutOrder.getShipperId();
|
||||
String userNcCode = reservationStockInOrderMapper.getUserNcCode(shipperId);
|
||||
gwStockOutOrder.setBill_no(reservationStockOutOrder.getOutOrderNumber());
|
||||
gwStockOutOrder.setBill_date(reservationStockOutOrder.getDocumentDate());
|
||||
gwStockOutOrder.setIe_flag("E");
|
||||
gwStockOutOrder.setCorp_code(userNcCode);
|
||||
|
||||
// 构建主单Map
|
||||
Map<String, Object> order = new HashMap<>();
|
||||
order.put("billNo", reservationStockOutOrder.getOutOrderNumber());
|
||||
order.put("ieFlag", "E");
|
||||
order.put("billDate", reservationStockOutOrder.getDocumentDate());
|
||||
order.put("corpCode", userNcCode != null ? userNcCode : "");
|
||||
|
||||
List<ReservationOutMaterialDetail> reservationOutMaterialDetails = reservationOutMaterialDetailMapper.selectList(new LambdaQueryWrapper<ReservationOutMaterialDetail>().eq(ReservationOutMaterialDetail::getOutOrderNumber, reservationStockOutOrder.getOutOrderNumber()));
|
||||
Integer lineNum = 1;
|
||||
List<GwOutDetail> orderList = new LinkedList<>();
|
||||
for (ReservationOutMaterialDetail reservationOutMaterialDetail : reservationOutMaterialDetails) {
|
||||
GwOutDetail gwOutDetail = new GwOutDetail();
|
||||
Long materialBaseInfoId = reservationOutMaterialDetail.getMaterialBaseInfoId();
|
||||
gwOutDetail.setBill_no(gwStockOutOrder.getBill_no());
|
||||
gwOutDetail.setLine_num(lineNum);
|
||||
lineNum++;
|
||||
gwOutDetail.setItem_no(materialBaseInfoId.toString());
|
||||
gwOutDetail.setItem_name(reservationOutMaterialDetail.getMaterialName());
|
||||
MaterialBaseInfoPO materialBaseInfoPO = reservationStockInOrderMapper.getinfo(materialBaseInfoId);
|
||||
gwOutDetail.setSpec(materialBaseInfoPO.getSpecificationModel());
|
||||
gwOutDetail.setUnit(materialBaseInfoPO.getDeclarationUnit());
|
||||
gwOutDetail.setQty(reservationOutMaterialDetail.getQuantity());
|
||||
gwOutDetail.setErp_curr(materialBaseInfoPO.getCurrency());
|
||||
gwOutDetail.setErp_price(materialBaseInfoPO.getUnitPrice());
|
||||
BigDecimal unitPrice = materialBaseInfoPO.getUnitPrice();
|
||||
BigDecimal quantity = reservationOutMaterialDetail.getQuantity();
|
||||
if (unitPrice != null && quantity != null && unitPrice.compareTo(BigDecimal.ZERO) != 0&&quantity.compareTo(BigDecimal.ZERO) != 0) {
|
||||
BigDecimal Amount = unitPrice.multiply(quantity).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
gwOutDetail.setAmount(Amount);
|
||||
}
|
||||
orderList.add(gwOutDetail);
|
||||
// 查询出库物料明细
|
||||
List<ReservationOutMaterialDetail> reservationOutMaterialDetails =
|
||||
reservationOutMaterialDetailMapper.selectList(
|
||||
new LambdaQueryWrapper<ReservationOutMaterialDetail>()
|
||||
.eq(ReservationOutMaterialDetail::getOutOrderNumber, reservationStockOutOrder.getOutOrderNumber())
|
||||
);
|
||||
|
||||
Long kcId = reservationOutMaterialDetailMapper.getKcId(reservationOutMaterialDetail.getLotNo());
|
||||
String inOrderNumber = reservationOutMaterialDetailMapper.getInOrderNumber(kcId);
|
||||
String inLotNo = reservationOutMaterialDetailMapper.getInLotNo(inOrderNumber,materialBaseInfoId);
|
||||
String warehouse = reservationOutMaterialDetailMapper.getWarehouse(kcId);
|
||||
String opWhLoc = reservationOutMaterialDetailMapper.getOpWhLoc(kcId);
|
||||
Integer result = null;
|
||||
if (inLotNo != null && inLotNo.contains("-")) {
|
||||
// 截取最后一个 "-" 后面的内容(兼容多 "-" 场景)
|
||||
String numStr = inLotNo.substring(inLotNo.lastIndexOf("-") + 1);
|
||||
// 转成 Integer
|
||||
result = Integer.valueOf(numStr);
|
||||
}
|
||||
gwOutDetail.setOrder_i_no(inOrderNumber);
|
||||
gwOutDetail.setBill_i(inLotNo);
|
||||
gwOutDetail.setOrder_i_row(result);
|
||||
gwOutDetail.setBill_i_row(result);
|
||||
gwOutDetail.setWarehouse(warehouse);
|
||||
gwOutDetail.setOp_wh_loc(opWhLoc);
|
||||
if (reservationOutMaterialDetails == null || reservationOutMaterialDetails.isEmpty()) {
|
||||
failCount++;
|
||||
failMsg.append("id:").append(id).append("无物料明细;");
|
||||
continue;
|
||||
}
|
||||
gwStockOutOrder.setOrderList(orderList);
|
||||
|
||||
// 构建明细List<Map>
|
||||
List<Map<String, Object>> orderList = new ArrayList<>();
|
||||
int lineNum = 1;
|
||||
for (ReservationOutMaterialDetail detail : reservationOutMaterialDetails) {
|
||||
Map<String, Object> item = new HashMap<>();
|
||||
item.put("billNo", reservationStockOutOrder.getOutOrderNumber());
|
||||
item.put("lineNum", lineNum++);
|
||||
item.put("itemNo", detail.getMaterialBaseInfoId() != null ? detail.getMaterialBaseInfoId().toString() : "");
|
||||
item.put("itemName", detail.getMaterialName() != null ? detail.getMaterialName() : "");
|
||||
item.put("spec", detail.getSpecificationModel() != null ? detail.getSpecificationModel() : "");
|
||||
item.put("unit", detail.getDeclareUnit() != null ? detail.getDeclareUnit() : "");
|
||||
item.put("qty", detail.getQuantity());
|
||||
|
||||
// 获取物料详情
|
||||
if (detail.getMaterialBaseInfoId() != null) {
|
||||
MaterialBaseInfoPO materialBaseInfoPO = reservationStockInOrderMapper.getinfo(detail.getMaterialBaseInfoId());
|
||||
if (materialBaseInfoPO != null) {
|
||||
item.put("erpCurr", materialBaseInfoPO.getCurrency() != null ? materialBaseInfoPO.getCurrency() : "");
|
||||
item.put("erpPrice", materialBaseInfoPO.getUnitPrice());
|
||||
|
||||
// 计算金额
|
||||
BigDecimal unitPrice = materialBaseInfoPO.getUnitPrice();
|
||||
BigDecimal quantity = detail.getQuantity();
|
||||
if (unitPrice != null && quantity != null && unitPrice.compareTo(BigDecimal.ZERO) != 0 && quantity.compareTo(BigDecimal.ZERO) != 0) {
|
||||
BigDecimal amount = unitPrice.multiply(quantity).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
item.put("amount", amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 库存关联信息
|
||||
if (detail.getLotNo() != null) {
|
||||
Long kcId = reservationOutMaterialDetailMapper.getKcId(detail.getLotNo());
|
||||
if (kcId != null) {
|
||||
String inOrderNumber = reservationOutMaterialDetailMapper.getInOrderNumber(kcId);
|
||||
String inLotNo = inOrderNumber != null ? reservationOutMaterialDetailMapper.getInLotNo(inOrderNumber, detail.getMaterialBaseInfoId()) : null;
|
||||
String warehouse = reservationOutMaterialDetailMapper.getWarehouse(kcId);
|
||||
String opWhLoc = reservationOutMaterialDetailMapper.getOpWhLoc(kcId);
|
||||
|
||||
item.put("orderINo", inOrderNumber != null ? inOrderNumber : "");
|
||||
item.put("warehouse", warehouse != null ? warehouse : "");
|
||||
item.put("opWhLoc", opWhLoc != null ? opWhLoc : "");
|
||||
item.put("billI", inLotNo != null ? inLotNo : "");
|
||||
|
||||
// 处理批次号中的数字
|
||||
if (inLotNo != null && inLotNo.contains("-")) {
|
||||
String numStr = inLotNo.substring(inLotNo.lastIndexOf("-") + 1);
|
||||
try {
|
||||
Integer result = Integer.valueOf(numStr);
|
||||
item.put("orderIRow", result);
|
||||
item.put("billIRow", result);
|
||||
} catch (NumberFormatException e) {
|
||||
item.put("orderIRow", null);
|
||||
item.put("billIRow", null);
|
||||
}
|
||||
} else {
|
||||
item.put("orderIRow", null);
|
||||
item.put("billIRow", null);
|
||||
}
|
||||
} else {
|
||||
item.put("orderINo", "");
|
||||
item.put("orderIRow", null);
|
||||
item.put("warehouse", "");
|
||||
item.put("opWhLoc", "");
|
||||
item.put("billI", "");
|
||||
item.put("billIRow", null);
|
||||
}
|
||||
} else {
|
||||
item.put("orderINo", "");
|
||||
item.put("orderIRow", null);
|
||||
item.put("warehouse", "");
|
||||
item.put("opWhLoc", "");
|
||||
item.put("billI", "");
|
||||
item.put("billIRow", null);
|
||||
}
|
||||
|
||||
orderList.add(item);
|
||||
}
|
||||
order.put("orderList", orderList);
|
||||
|
||||
// 构建推送body
|
||||
List<Map<String, Object>> bodyList = new ArrayList<>();
|
||||
bodyList.add(order);
|
||||
|
||||
GwLog gwLog = new GwLog();
|
||||
gwLog.setType("出口订单");
|
||||
gwLog.setBusinessId(id);
|
||||
gwLog.setRequestBody(com.alibaba.fastjson.JSONObject.toJSONString(gwStockOutOrder));
|
||||
gwLog.setRequestBody(com.alibaba.fastjson.JSONObject.toJSONString(bodyList));
|
||||
gwLog.setResponseBody("");
|
||||
gwLog.setStatus(1);
|
||||
gwLog.setSendTime(new Date());
|
||||
@@ -1165,7 +1228,7 @@ public class ReservationStockOutOrderApplicationService {
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(PUSH_API_URL);
|
||||
StringEntity postingString = new StringEntity(com.alibaba.fastjson.JSONObject.toJSONString(gwStockOutOrder), "UTF-8");
|
||||
StringEntity postingString = new StringEntity(com.alibaba.fastjson.JSONObject.toJSONString(bodyList), "UTF-8");
|
||||
httpPost.setEntity(postingString);
|
||||
httpPost.setHeader("Content-type", "application/json");
|
||||
httpPost.setHeader("apiName", API_NAME);
|
||||
|
||||
+163
@@ -4,15 +4,18 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.mhd.common.core.domain.po.UserPo;
|
||||
import com.mhd.common.core.exception.ServiceException;
|
||||
import com.mhd.common.core.utils.StringUtils;
|
||||
import com.mhd.common.core.utils.bean.BeanUtils;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
import com.mhd.common.security.utils.SecurityUtils;
|
||||
import com.mhd.system.api.OmsServiceFeign;
|
||||
import com.mhd.system.api.SystemServiceFeign;
|
||||
import com.mhd.system.api.UserServiceFeign;
|
||||
import com.mhd.system.api.domain.BatchDetailFeignPO;
|
||||
import com.mhd.system.api.domain.GwLogDTO;
|
||||
import com.mhd.system.api.domain.StorageLocationFeignPO;
|
||||
import com.mhd.system.api.domain.cache.AssociationWarehouseCacheDO;
|
||||
import com.mhd.system.api.domain.cache.SystemServiceCacheUtil;
|
||||
@@ -21,6 +24,8 @@ import com.mhd.wms.domain.materialMoreDetail.repository.po.MaterialMoreDetailPO;
|
||||
import com.mhd.wms.domain.pickingMaterialDetail.repository.po.PickingMaterialDetailPO;
|
||||
import com.mhd.wms.domain.pickingMaterialDetail.repository.todo.PickingMaterialDetailDO;
|
||||
import com.mhd.wms.domain.pickingMaterialDetail.service.PickingMaterialDetailDomainService;
|
||||
import com.mhd.wms.domain.pickingOrder.entity.PickingOrder;
|
||||
import com.mhd.wms.domain.pickingOrder.repository.mapper.PickingOrderMapper;
|
||||
import com.mhd.wms.domain.pickingOrder.repository.po.PickingOrderPO;
|
||||
import com.mhd.wms.domain.pickingOrder.repository.todo.PickingOrderDO;
|
||||
import com.mhd.wms.domain.pickingOrder.service.PickingOrderDomainService;
|
||||
@@ -28,13 +33,22 @@ import com.mhd.wms.domain.materialGoodsRule.repository.facade.IMaterialGoodsRule
|
||||
import com.mhd.wms.domain.outMaterialDetail.repository.facade.IOutMaterialDetailService;
|
||||
import com.mhd.wms.domain.outMaterialDetail.entity.OutMaterialDetail;
|
||||
import com.mhd.wms.domain.outMaterialDetail.repository.po.OutMaterialDetailPO;
|
||||
import com.mhd.wms.domain.stockShelfOrder.entity.StockShelfOrder;
|
||||
import com.mhd.wms.util.ReceiptBatchDetailFilter;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -60,9 +74,18 @@ public class PickingOrderApplicationService {
|
||||
@Autowired
|
||||
private SystemServiceFeign systemServiceFeign;
|
||||
@Autowired
|
||||
private OmsServiceFeign omsServiceFeign;
|
||||
@Autowired
|
||||
private IMaterialGoodsRuleService materialGoodsRuleService;
|
||||
@Autowired
|
||||
private IOutMaterialDetailService outMaterialDetailService;
|
||||
@Resource
|
||||
private PickingOrderMapper pickingOrderMapper;
|
||||
|
||||
|
||||
private static final String PUSH_API_URL = "http://10.33.0.100/nagu-erp-api/transfer/pushData";
|
||||
private static final String API_NAME = "save_qnBill_i";
|
||||
private static final String VERIFY = "tjPZMT9fwhZRnv+eTXKF75QXmXzCn7phPagmoUQsvsh2ZTWDjuRxHAgcP0GZENHP";
|
||||
|
||||
|
||||
/**
|
||||
@@ -685,4 +708,144 @@ public class PickingOrderApplicationService {
|
||||
returnPickingOrderDO.setMaterialDetailList(returnPickingMaterialDetailDOList);
|
||||
return returnPickingOrderDO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public AjaxResult batchPush(List<Long> idList) {
|
||||
if (idList == null || idList.isEmpty()) {
|
||||
return AjaxResult.error("没有数据需要推送");
|
||||
}
|
||||
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
Long pushBy = loginUser != null ? loginUser.getUserid() : null;
|
||||
String pushByName = loginUser != null ? loginUser.getUsername() : null;
|
||||
Long organizationId = loginUser != null ? loginUser.getUserPo().getOrganizationId() : null;
|
||||
Long topOrganizationId = loginUser != null ? loginUser.getUserPo().getTopOrganizationId() : null;
|
||||
String organizationName = loginUser != null ? loginUser.getUserPo().getOrganizationName() : null;
|
||||
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
StringBuilder failMsg = new StringBuilder();
|
||||
|
||||
for(Long id : idList){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
List<Map<String, Object>> bodyList = new ArrayList<>();
|
||||
// bodyList.add();
|
||||
|
||||
GwLogDTO gwLogDTO = new GwLogDTO();
|
||||
gwLogDTO.setType("出口订单");
|
||||
gwLogDTO.setBusinessId(id);
|
||||
gwLogDTO.setRequestBody(com.alibaba.fastjson.JSONObject.toJSONString(bodyList));
|
||||
gwLogDTO.setResponseBody("");
|
||||
gwLogDTO.setStatus(1);
|
||||
gwLogDTO.setSendTime(new Date());
|
||||
gwLogDTO.setOrganizationId(organizationId);
|
||||
gwLogDTO.setTopOrganizationId(topOrganizationId);
|
||||
gwLogDTO.setOrganizationName(organizationName);
|
||||
gwLogDTO.setCreateBy(pushBy);
|
||||
gwLogDTO.setCreateTime(new Date());
|
||||
//gwLogMapper.insert(gwLogDTO);
|
||||
Long gwLogId = null;
|
||||
try {
|
||||
AjaxResult insertResult = omsServiceFeign.insertGwLog(gwLogDTO);
|
||||
if(insertResult !=null && "200".equals(String.valueOf(insertResult.get("code")))){
|
||||
Map<?,?>data = (Map<?,?>)insertResult.get("data");
|
||||
gwLogId = ((Number)data.get("id")).longValue();
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
log.error("保存Gwlog失败:{}",e.getMessage());
|
||||
}
|
||||
|
||||
updatePushStatus(id, 2, new Date(), pushBy,pushByName);
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(PUSH_API_URL);
|
||||
StringEntity postingString = new StringEntity(com.alibaba.fastjson.JSONObject.toJSONString(bodyList), "UTF-8");
|
||||
httpPost.setEntity(postingString);
|
||||
httpPost.setHeader("Content-type", "application/json");
|
||||
httpPost.setHeader("apiName", API_NAME);
|
||||
httpPost.setHeader("verify", VERIFY);
|
||||
|
||||
try {
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
String responseString = EntityUtils.toString(response.getEntity());
|
||||
gwLogDTO.setResponseBody(responseString);
|
||||
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
gwLogDTO.setStatus(2);
|
||||
updatePushStatus(id, 3, new Date(), pushBy,pushByName);
|
||||
successCount++;
|
||||
} else {
|
||||
gwLogDTO.setStatus(3);
|
||||
gwLogDTO.setErrorMsg(responseString);
|
||||
updatePushStatus(id, 4, new Date(), pushBy,pushByName);
|
||||
failCount++;
|
||||
failMsg.append("id:").append(id).append("失败;");
|
||||
}
|
||||
if (gwLogId != null){
|
||||
gwLogDTO.setLogId(gwLogId);
|
||||
try{
|
||||
AjaxResult updateResult = omsServiceFeign.updateGwLog(gwLogDTO);
|
||||
}catch (Exception e){
|
||||
log.error("更新GwLog失败:{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
// gwLogMapper.updateById(gwLog);
|
||||
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
gwLogDTO.setStatus(3);
|
||||
gwLogDTO.setErrorMsg(e.getMessage());
|
||||
gwLogDTO.setResponseBody("请求异常:" + e.getMessage());
|
||||
// gwLogMapper.updateById(gwLog);
|
||||
if (gwLogId != null){
|
||||
gwLogDTO.setLogId(gwLogId);
|
||||
try{
|
||||
AjaxResult updateResult = omsServiceFeign.updateGwLog(gwLogDTO);
|
||||
}catch (Exception ex){
|
||||
log.error("更新GwLog失败:{}",ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
updatePushStatus(id, 4, new Date(), pushBy,pushByName);
|
||||
failCount++;
|
||||
failMsg.append("id:").append(id).append("异常:").append(e.getMessage()).append(";");
|
||||
log.error("保税仓推送异常: id={}, error={}", id, e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (Exception e) {
|
||||
log.error("关闭httpClient异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String resultMsg = "推送完成: 成功" + successCount + "条, 失败" + failCount + "条";
|
||||
if (failCount > 0) {
|
||||
resultMsg += "[" + failMsg.toString() + "]";
|
||||
}
|
||||
return AjaxResult.success(resultMsg);
|
||||
}
|
||||
|
||||
private void updatePushStatus(Long id, Integer pushStatus, Date pushTime, Long pushBy,String pushByName) {
|
||||
PickingOrder entity = new PickingOrder();
|
||||
entity.setPickingOrderId(id);
|
||||
entity.setPushStatus(pushStatus);
|
||||
if (pushTime != null) {
|
||||
entity.setPushTime(pushTime);
|
||||
}
|
||||
if (pushBy != null) {
|
||||
entity.setPushBy(pushBy);
|
||||
}
|
||||
if (pushByName != null) {
|
||||
entity.setPushByName(pushByName);
|
||||
}
|
||||
pickingOrderMapper.updateById(entity);
|
||||
}
|
||||
}
|
||||
+13
@@ -116,4 +116,17 @@ public class PickingOrderApi extends BaseController {
|
||||
PickingOrderDO pickingOrderDO = pickingOrderAssembler.toDO(pickingOrderDTO);
|
||||
return toAjax(pickingOrderApplicationService.completePicking(pickingOrderDO));
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("批量推送")
|
||||
@PostMapping("/batchPush")
|
||||
public AjaxResult batchPush(@RequestBody List<Long> idList){
|
||||
if(idList == null || idList.isEmpty()){
|
||||
return AjaxResult.error("没有数据需要推送");
|
||||
}
|
||||
return pickingOrderApplicationService.batchPush(idList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user