| | |
| | | package org.jeecg.modules.mes.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.modules.base.entity.LineSideWarehouse; |
| | | import org.jeecg.modules.base.service.ILineSideWarehouseService; |
| | | import org.jeecg.modules.mes.entity.MesMaterialTransferRequest; |
| | | import org.jeecg.modules.mes.entity.MesProductionWorkOrder; |
| | | import org.jeecg.modules.mes.enums.MaterialTransferPublishStatus; |
| | |
| | | import org.jeecg.modules.mes.mapper.MesMaterialTransferRequestMapper; |
| | | import org.jeecg.modules.mes.service.IMesMaterialTransferRequestService; |
| | | import org.jeecg.modules.mes.service.IMesProductionWorkOrderService; |
| | | import org.jeecg.modules.sap.dto.MaterialRequestDTO; |
| | | import org.jeecg.modules.sap.request.MaterialRequest; |
| | | import org.jeecg.modules.sap.service.OrderMaterialRequestService; |
| | | import org.jeecg.modules.wms.dto.WSResponse; |
| | | import org.jeecg.modules.wms.request.WebReservationOrder; |
| | | import org.jeecg.modules.wms.service.WMSWebServiceClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @Description: 物料拉动申请 |
| | |
| | | |
| | | @Autowired |
| | | private IMesProductionWorkOrderService productionWorkOrderService; |
| | | @Autowired |
| | | private OrderMaterialRequestService orderMaterialRequestService; |
| | | @Autowired |
| | | private ILineSideWarehouseService lineSideWarehouseService; |
| | | @Autowired |
| | | private WMSWebServiceClient wmsWebServiceClient; |
| | | |
| | | @Override |
| | | public List<MesMaterialTransferRequest> queryMaterialTransferRequestByWorkOrderId(String workOrderId) { |
| | |
| | | this.getBaseMapper().insert(request); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean publish(String id) { |
| | | MesMaterialTransferRequest entity = super.getById(id); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("数据不存在,请刷新重试!"); |
| | | } |
| | | if (!MaterialTransferPublishStatus.WAIT_PUBLISH.name().equals(entity.getPublishStatus())) { |
| | | throw new JeecgBootException("数据已发布!"); |
| | | } |
| | | LineSideWarehouse warehouse = lineSideWarehouseService.getById(entity.getTargetWarehouseId()); |
| | | if (warehouse == null) { |
| | | throw new JeecgBootException("线边库不存在!"); |
| | | } |
| | | MaterialRequest request = new MaterialRequest(); |
| | | request.setMaterialNumber(entity.getMaterialNumber()); |
| | | request.setQuantity(request.getQuantity()); |
| | | request.setWarehouseCode(entity.getOriginalWarehouseId()); |
| | | try { |
| | | Map<String, Object> response = orderMaterialRequestService.orderMaterialRequest("2301", warehouse.getWarehouseCode(), Collections.singletonList(request)); |
| | | Object ztype = response.get("ztype"); |
| | | if (!"S".equals(ztype)) { |
| | | throw new JeecgBootException("调用SAP请求预留号失败!" + response.get("zmess")); |
| | | } |
| | | MaterialRequestDTO result = (MaterialRequestDTO) response.get("result"); |
| | | entity.setReservationCode(result.getO_SAP_RESV()); |
| | | entity.setPublishStatus(MaterialTransferPublishStatus.PUBLISHED.name()); |
| | | entity.setPublishTime(new Date()); |
| | | super.updateById(entity); |
| | | return true; |
| | | } catch (Exception e) { |
| | | throw new JeecgBootException("调用SAP请求预留号失败!"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean request(String id) { |
| | | MesMaterialTransferRequest entity = super.getById(id); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("数据不存在,请刷新重试!"); |
| | | } |
| | | if (!MaterialTransferPublishStatus.PUBLISHED.name().equals(entity.getPublishStatus()) || !MaterialTransferRequestStatus.WAIT_REQUEST.name().equals(entity.getRequestStatus())) { |
| | | throw new JeecgBootException("数据状态不可请求WMS!"); |
| | | } |
| | | WebReservationOrder request = new WebReservationOrder(); |
| | | request.setFactoryCode("2301"); |
| | | request.setReservationOrder(entity.getReservationCode()); |
| | | request.setTotal(entity.getSpecifiedQuantity()); |
| | | Map<String, Object> resultMap = wmsWebServiceClient.receiveReservation(request); |
| | | WSResponse result = (WSResponse) resultMap.get("result"); |
| | | if ("Y".equals(result.getErrorCode())) { |
| | | entity.setRequestStatus(MaterialTransferRequestStatus.REQUESTED.name()); |
| | | entity.setRequestTime(new Date()); |
| | | super.updateById(entity); |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public MesMaterialTransferRequest queryByReservationCode(String reservationCode) { |
| | | LambdaQueryWrapper<MesMaterialTransferRequest> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(MesMaterialTransferRequest::getReservationCode, reservationCode); |
| | | queryWrapper.eq(MesMaterialTransferRequest::getDelFlag, CommonConstant.DEL_FLAG_0); |
| | | List<MesMaterialTransferRequest> list = super.list(queryWrapper); |
| | | if (CollectionUtil.isNotEmpty(list)) { |
| | | return list.get(0); |
| | | } |
| | | return null; |
| | | } |
| | | } |