|
|
|
@ -26,6 +26,7 @@ import com.sap.me.nonconformance.NCProductionServiceInterface;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
@ -128,12 +129,8 @@ public class ShopOrderReleaseServiceImpl implements ShopOrderReleaseService {
|
|
|
|
|
customFieldsService.save(customFields);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean shopOrderRelease(String site, String user,StringBuffer message, List<ShopOrderRelease> shopOrderList) {
|
|
|
|
|
if (shopOrderList == null || shopOrderList.size() <= 0) {
|
|
|
|
|
throw new BaseException("请至少选择一笔需要下达的工单");
|
|
|
|
|
}
|
|
|
|
|
public Boolean shopOrderRelease(String site, String user,StringBuffer message,ShopOrderRelease shopOrderRelease) {
|
|
|
|
|
//工单标准服务
|
|
|
|
|
ShopOrderServiceInterface shopOrderServiceInterface = null;
|
|
|
|
|
try {
|
|
|
|
@ -141,112 +138,75 @@ public class ShopOrderReleaseServiceImpl implements ShopOrderReleaseService {
|
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
|
throw BusinessException.build("获取ME标准服务失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询工单信息
|
|
|
|
|
String shopOrder = shopOrderRelease.getShopOrder();
|
|
|
|
|
String shopOrderBo = shopOrderRelease.getShopOrderBo();
|
|
|
|
|
ShopOrder shopOrderModel = shopOrderService.getById(shopOrderBo);
|
|
|
|
|
int seq = 0;
|
|
|
|
|
boolean flag = true;
|
|
|
|
|
for (ShopOrderRelease shopOrderReleaseModel : shopOrderList) {
|
|
|
|
|
//查询工单信息
|
|
|
|
|
String shopOrder = shopOrderReleaseModel.getShopOrder();
|
|
|
|
|
String shopOrderBo = shopOrderReleaseModel.getShopOrderBo();
|
|
|
|
|
ShopOrder shopOrderModel = shopOrderService.getById(shopOrderBo);
|
|
|
|
|
if (shopOrderModel == null) {
|
|
|
|
|
flag =false;
|
|
|
|
|
message.append(seq++ % 3 == 0 ? "\n" : "| |");
|
|
|
|
|
message.append("工单[" + shopOrder + "]不存在");
|
|
|
|
|
continue;
|
|
|
|
|
// throw new BaseException("工单[" + shopOrder + "]不存在");
|
|
|
|
|
}
|
|
|
|
|
Boolean flag = true;
|
|
|
|
|
if (shopOrderModel == null) {
|
|
|
|
|
throw new BaseException("工单[" + shopOrder + "]不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验工单对应的工单BOM是否更新了组件数据
|
|
|
|
|
isUpdateBomComponent(shopOrderReleaseModel,false);
|
|
|
|
|
|
|
|
|
|
String statusBo = shopOrderModel.getStatusBo();
|
|
|
|
|
String routerBo = shopOrderModel.getPlannedRouterBo();
|
|
|
|
|
BigDecimal qtyToBuild = new BigDecimal(shopOrderModel.getQtyToBuild());
|
|
|
|
|
BigDecimal qtyReleased = new BigDecimal(shopOrderModel.getQtyReleased());
|
|
|
|
|
if (!"501".equals(StringUtils.trimHandle(statusBo))) {
|
|
|
|
|
flag =false;
|
|
|
|
|
message.append(seq++ % 3 == 0 ? "\n" : "| |");
|
|
|
|
|
message.append("工单[" +shopOrder+ "]不是可下达状态");
|
|
|
|
|
continue;
|
|
|
|
|
// throw new BaseException("工单[" +shopOrder+ "]不是可下达状态");
|
|
|
|
|
}
|
|
|
|
|
if (qtyReleased.compareTo(qtyToBuild) >= 0) {
|
|
|
|
|
flag =false;
|
|
|
|
|
message.append(seq++ % 3 == 0 ? "\n" : "| |");
|
|
|
|
|
message.append("工单[" +shopOrder+ "]没有可用下达数量");
|
|
|
|
|
continue;
|
|
|
|
|
// throw new BaseException("工单[" +shopOrder+ "]没有可用下达数量");
|
|
|
|
|
}
|
|
|
|
|
BigDecimal qtyToRelease = qtyToBuild.subtract(qtyReleased);
|
|
|
|
|
|
|
|
|
|
//查询工艺路线
|
|
|
|
|
Router routerModel = routerService.getCurrentRouter(routerBo);
|
|
|
|
|
if (routerModel == null) {
|
|
|
|
|
flag =false;
|
|
|
|
|
message.append(seq++ % 3 == 0 ? "\n" : "| |");
|
|
|
|
|
message.append("工艺路线[" +StringUtils.trimHandle(routerBo)+ "]不存在");
|
|
|
|
|
continue;
|
|
|
|
|
// throw new BaseException("工艺路线[" +StringUtils.trimHandle(routerBo)+ "]不存在");
|
|
|
|
|
}
|
|
|
|
|
routerBo = routerModel.getHandle();
|
|
|
|
|
|
|
|
|
|
//查询工艺路线详细
|
|
|
|
|
List<RouterDTO> routerList = shopOrderReleaseMapper.selectShopOrderRouter(routerBo);
|
|
|
|
|
if (routerList == null || routerList.size() <= 0) {
|
|
|
|
|
flag =false;
|
|
|
|
|
message.append(seq++ % 3 == 0 ? "\n" : "| |");
|
|
|
|
|
message.append("工艺路线[" +StringUtils.trimHandle(routerBo)+ "]主数据不完整,请确认");
|
|
|
|
|
continue;
|
|
|
|
|
// throw new BaseException("工艺路线[" +StringUtils.trimHandle(routerBo)+ "]主数据不完整,请确认");
|
|
|
|
|
}
|
|
|
|
|
// 校验工单对应的工单BOM是否更新了组件数据
|
|
|
|
|
isUpdateBomComponent(shopOrderRelease,false);
|
|
|
|
|
String statusBo = shopOrderModel.getStatusBo();
|
|
|
|
|
String routerBo = shopOrderModel.getPlannedRouterBo();
|
|
|
|
|
BigDecimal qtyToBuild = new BigDecimal(shopOrderModel.getQtyToBuild());
|
|
|
|
|
BigDecimal qtyReleased = new BigDecimal(shopOrderModel.getQtyReleased());
|
|
|
|
|
if (!"501".equals(StringUtils.trimHandle(statusBo))) {
|
|
|
|
|
throw new BaseException("工单[" +shopOrder+ "]不是可下达状态");
|
|
|
|
|
}
|
|
|
|
|
if (qtyReleased.compareTo(qtyToBuild) >= 0) {
|
|
|
|
|
throw new BaseException("工单[" +shopOrder+ "]没有可用下达数量");
|
|
|
|
|
}
|
|
|
|
|
BigDecimal qtyToRelease = qtyToBuild.subtract(qtyReleased);
|
|
|
|
|
|
|
|
|
|
//工单下达
|
|
|
|
|
ReleaseShopOrderResponse response = null;
|
|
|
|
|
try {
|
|
|
|
|
ReleaseShopOrderRequest request = new ReleaseShopOrderRequest();
|
|
|
|
|
request.setShopOrderRef(shopOrderBo);
|
|
|
|
|
request.setQuantityToRelease(qtyToRelease);
|
|
|
|
|
response = shopOrderServiceInterface.releaseShopOrder(request);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
flag=false;
|
|
|
|
|
message.append(seq++ % 3 == 0 ? "\n" : "| |");
|
|
|
|
|
message.append(e.getMessage());
|
|
|
|
|
continue;
|
|
|
|
|
//查询工艺路线
|
|
|
|
|
Router routerModel = routerService.getCurrentRouter(routerBo);
|
|
|
|
|
if (routerModel == null) {
|
|
|
|
|
throw new BaseException("工艺路线[" +StringUtils.trimHandle(routerBo)+ "]不存在");
|
|
|
|
|
}
|
|
|
|
|
routerBo = routerModel.getHandle();
|
|
|
|
|
|
|
|
|
|
//查询工艺路线详细
|
|
|
|
|
List<RouterDTO> routerList = shopOrderReleaseMapper.selectShopOrderRouter(routerBo);
|
|
|
|
|
if (routerList == null || routerList.size() <= 0) {
|
|
|
|
|
throw new BaseException("工艺路线[" +StringUtils.trimHandle(routerBo)+ "]主数据不完整,请确认");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//工单下达
|
|
|
|
|
ReleaseShopOrderResponse response = null;
|
|
|
|
|
ReleaseShopOrderRequest request = new ReleaseShopOrderRequest();
|
|
|
|
|
request.setShopOrderRef(shopOrderBo);
|
|
|
|
|
request.setQuantityToRelease(qtyToRelease);
|
|
|
|
|
try {
|
|
|
|
|
response = shopOrderServiceInterface.releaseShopOrder(request);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new BaseException(ExceptionUtil.getExceptionMsg(e));
|
|
|
|
|
}
|
|
|
|
|
// ExceptionUtil.throwException(e);
|
|
|
|
|
}
|
|
|
|
|
if (response == null) {
|
|
|
|
|
// flag =false;
|
|
|
|
|
// message.append(seq++ % 3 == 0 ? "\n" : "| |");
|
|
|
|
|
// message.append("工单下达失败:调用标准接口处理异常");
|
|
|
|
|
// continue;
|
|
|
|
|
|
|
|
|
|
if (response == null) {
|
|
|
|
|
throw new BaseException("工单下达失败:调用标准接口处理异常");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<ReleasedSfc> sfcList = response.getReleasedSfcList();
|
|
|
|
|
if (sfcList == null || sfcList.size() <= 0) {
|
|
|
|
|
List<ReleasedSfc> sfcList = response.getReleasedSfcList();
|
|
|
|
|
if (sfcList == null || sfcList.size() <= 0) {
|
|
|
|
|
throw new BaseException("工单下达失败:获取生产批次清单为空");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//组装派工数据
|
|
|
|
|
for (int i = 0 ; i < sfcList.size(); i++) {
|
|
|
|
|
ReleasedSfc releasedSfc = sfcList.get(i);
|
|
|
|
|
|
|
|
|
|
Sfc sfcModel = new Sfc();
|
|
|
|
|
sfcModel.setSfc(releasedSfc.getSfc());
|
|
|
|
|
sfcModel.setQty(releasedSfc.getQuantity().doubleValue());
|
|
|
|
|
sfcDispatch(site, user, shopOrderModel, sfcModel, routerList);
|
|
|
|
|
}//end for sfcList
|
|
|
|
|
|
|
|
|
|
//修改工单的计划工作中心
|
|
|
|
|
//工单对应多个车间,所以工单不写计划工作中心
|
|
|
|
|
/**if (StringUtils.notBlank(workCenter)) {
|
|
|
|
|
ShopOrder updateShopOrder = new ShopOrder();
|
|
|
|
|
updateShopOrder.setHandle(shopOrderBo);
|
|
|
|
|
updateShopOrder.setPlannedWorkCenterBo(workCenterBo);
|
|
|
|
|
shopOrderService.updateById(updateShopOrder);
|
|
|
|
|
}*/
|
|
|
|
|
//组装派工数据
|
|
|
|
|
for (int i = 0 ; i < sfcList.size(); i++) {
|
|
|
|
|
ReleasedSfc releasedSfc = sfcList.get(i);
|
|
|
|
|
|
|
|
|
|
Sfc sfcModel = new Sfc();
|
|
|
|
|
sfcModel.setSfc(releasedSfc.getSfc());
|
|
|
|
|
sfcModel.setQty(releasedSfc.getQuantity().doubleValue());
|
|
|
|
|
sfcDispatch(site, user, shopOrderModel, sfcModel, routerList);
|
|
|
|
|
}
|
|
|
|
|
return flag;//end for shopOrderList
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|