Search in sources :

Example 6 with OperationWorkTime

use of com.qcadoo.mes.operationTimeCalculations.OperationWorkTime in project mes by qcadoo.

the class OperationDurationDetailsInOrderListenersOFSPGOverrideAspect method aroundGenerateRealizationTime.

@Around("generateRealizationTimeE(viewDefinitionState, state, args)")
public void aroundGenerateRealizationTime(final ProceedingJoinPoint pjp, final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) throws Throwable {
    CheckBoxComponent component = (CheckBoxComponent) viewDefinitionState.getComponentByReference("includeOrdersForComponent");
    if (!component.isChecked()) {
        pjp.proceed();
        return;
    }
    FormComponent orderForm = (FormComponent) viewDefinitionState.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent startTimeField = (FieldComponent) viewDefinitionState.getComponentByReference(L_START_TIME);
    if (!StringUtils.hasText((String) startTimeField.getFieldValue())) {
        startTimeField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, ComponentState.MessageType.FAILURE);
        return;
    }
    FieldComponent plannedQuantityField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFields.PLANNED_QUANTITY);
    FieldComponent productionLineLookup = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFields.PRODUCTION_LINE);
    FieldComponent generatedEndDateField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFieldsPS.GENERATED_END_DATE);
    FieldComponent calculatedFinishAllOrdersField = (FieldComponent) viewDefinitionState.getComponentByReference("calculatedFinishAllOrders");
    FieldComponent calculatedStartAllOrdersField = (FieldComponent) viewDefinitionState.getComponentByReference("calculatedStartAllOrders");
    FieldComponent includeTpzField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFieldsPS.INCLUDE_TPZ);
    FieldComponent includeAdditionalTimeField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFieldsPS.INCLUDE_ADDITIONAL_TIME);
    boolean isGenerated = false;
    Entity productionLine = dataDefinitionService.get(ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE).get((Long) productionLineLookup.getFieldValue());
    Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get(orderForm.getEntity().getId());
    // copy of technology from order
    Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
    Validate.notNull(technology, "technology is null");
    BigDecimal quantity = orderRealizationTimeService.getBigDecimalFromField(plannedQuantityField.getFieldValue(), viewDefinitionState.getLocale());
    // Included in work time
    boolean includeTpz = "1".equals(includeTpzField.getFieldValue());
    boolean includeAdditionalTime = "1".equals(includeAdditionalTimeField.getFieldValue());
    final Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    productQuantitiesService.getProductComponentQuantities(technology, quantity, operationRuns);
    operationWorkTimeService.deleteOperCompTimeCalculations(order);
    OperationWorkTime workTime = operationWorkTimeService.estimateTotalWorkTimeForOrder(order, operationRuns, includeTpz, includeAdditionalTime, true);
    List<Entity> orders = getOrderAndSubOrders(order.getId());
    Map<Integer, OrdersByLevel> ordersByLevel = productionSchedulingForComponentsService.mapToOrdersByLevel(orders);
    List<Integer> keys = Lists.newArrayList(ordersByLevel.keySet());
    keys.sort(Collections.reverseOrder());
    Date orderStartDate = order.getDateField(OrderFields.START_DATE);
    Date lastDateTo = orderStartDate;
    for (Integer key : keys) {
        OrdersByLevel ords = ordersByLevel.get(key);
        Date currentDateTo = lastDateTo;
        for (Entity o : ords.getOrders()) {
            Entity t = o.getBelongsToField(OrderFields.TECHNOLOGY);
            final Map<Long, BigDecimal> oR = Maps.newHashMap();
            productQuantitiesService.getProductComponentQuantities(t, quantity, oR);
            operationWorkTimeService.estimateTotalWorkTimeForOrder(o, oR, includeTpz, includeAdditionalTime, true);
            int maxPathTime = orderRealizationTimeService.estimateMaxOperationTimeConsumptionForWorkstation(o, t.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(), quantity, includeTpz, includeAdditionalTime, productionLine);
            if (maxPathTime > OrderRealizationTimeService.MAX_REALIZATION_TIME) {
                state.addMessage("orders.validate.global.error.RealizationTimeIsToLong", ComponentState.MessageType.FAILURE);
                if (o.getId().equals(order.getId())) {
                    generatedEndDateField.setFieldValue(null);
                }
            } else {
                o.setField(OrderFieldsPS.REALIZATION_TIME, maxPathTime);
                Date startTime = o.getDateField(OrderFields.DATE_FROM);
                if (Objects.isNull(startTime)) {
                    startTime = orderStartDate;
                }
                if (startTime == null) {
                    startTimeField.addMessage("orders.validate.global.error.dateFromIsNull", ComponentState.MessageType.FAILURE);
                } else {
                    if (maxPathTime == 0) {
                        orderForm.addMessage("productionScheduling.timenorms.isZero", ComponentState.MessageType.FAILURE, false);
                        if (o.getId().equals(order.getId())) {
                            generatedEndDateField.setFieldValue(null);
                        }
                    } else {
                        lastDateTo = scheduleOperationsInOrder(o, currentDateTo);
                        isGenerated = true;
                    }
                    orderForm.addMessage("orders.dateFrom.info.dateFromSetToFirstPossible", ComponentState.MessageType.INFO, false);
                }
                o.getDataDefinition().save(o);
            }
        }
    }
    fillWorkTimeFields(viewDefinitionState, workTime);
    generatedEndDateField.requestComponentUpdateState();
    if (isGenerated) {
        order = getActualOrderWithChanges(order);
        Entity orderTimeCalculation = dataDefinitionService.get(TimeNormsConstants.PLUGIN_PRODUCTION_SCHEDULING_IDENTIFIER, TimeNormsConstants.MODEL_ORDER_TIME_CALCULATION).find().add(SearchRestrictions.belongsTo("order", order)).setMaxResults(1).uniqueResult();
        Date startTimeOrders = findCalculatedStartAllOrders(order);
        order.setField("calculatedStartAllOrders", orderRealizationTimeService.setDateToField(startTimeOrders));
        calculatedStartAllOrdersField.setFieldValue(orderRealizationTimeService.setDateToField(startTimeOrders));
        Date finishDate = orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_TO);
        generatedEndDateField.setFieldValue(orderRealizationTimeService.setDateToField(finishDate));
        calculatedFinishAllOrdersField.setFieldValue(orderRealizationTimeService.setDateToField(finishDate));
        order.setField("calculatedFinishAllOrders", orderRealizationTimeService.setDateToField(finishDate));
        order = order.getDataDefinition().save(order);
        orderForm.setEntity(order);
        orderForm.addMessage("productionScheduling.info.calculationGenerated", ComponentState.MessageType.SUCCESS);
        state.performEvent(viewDefinitionState, "reset");
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) OrdersByLevel(com.qcadoo.mes.ordersForSubproductsGeneration.productionScheduling.OrdersByLevel) BigDecimal(java.math.BigDecimal) Date(java.util.Date) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent) OperationWorkTime(com.qcadoo.mes.operationTimeCalculations.OperationWorkTime) Around(org.aspectj.lang.annotation.Around)

Example 7 with OperationWorkTime

use of com.qcadoo.mes.operationTimeCalculations.OperationWorkTime in project mes by qcadoo.

the class OperationalTaskHooks method getFinishDate.

private Date getFinishDate(Entity task, Entity technologyOperationComponent) {
    Entity order = task.getBelongsToField(OperationalTaskFields.ORDER);
    Entity workstation = task.getBelongsToField(OperationalTaskFields.WORKSTATION);
    Date startDate = task.getDateField(OperationalTaskFields.START_DATE);
    Entity parameter = parameterService.getParameter();
    boolean includeTpz = parameter.getBooleanField("includeTpzSG");
    Entity technology = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
    final Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    productQuantitiesService.getProductComponentQuantities(technology, order.getDecimalField(OrderFields.PLANNED_QUANTITY), operationRuns);
    Optional<Entity> techOperCompWorkstationTime = getTechOperCompWorkstationTime(technologyOperationComponent, workstation);
    Integer machineWorkTime;
    Integer additionalTime;
    Integer actualStaff = task.getIntegerField(OperationalTaskFields.ACTUAL_STAFF);
    int minStaff = technologyOperationComponent.getIntegerField(TechnologyOperationComponentFieldsTNFO.MIN_STAFF);
    BigDecimal staffFactor = BigDecimal.valueOf(minStaff).divide(BigDecimal.valueOf(actualStaff), numberService.getMathContext());
    if (techOperCompWorkstationTime.isPresent()) {
        OperationWorkTime operationWorkTime = operationWorkTimeService.estimateTechOperationWorkTimeForWorkstation(technologyOperationComponent, BigDecimalUtils.convertNullToZero(operationRuns.get(technologyOperationComponent.getId())), includeTpz, false, techOperCompWorkstationTime.get(), staffFactor);
        machineWorkTime = operationWorkTime.getMachineWorkTime();
        additionalTime = techOperCompWorkstationTime.get().getIntegerField(TechOperCompWorkstationTimeFields.TIME_NEXT_OPERATION);
    } else {
        OperationWorkTime operationWorkTime = operationWorkTimeService.estimateTechOperationWorkTime(technologyOperationComponent, BigDecimalUtils.convertNullToZero(operationRuns.get(technologyOperationComponent.getId())), includeTpz, false, false, staffFactor);
        machineWorkTime = operationWorkTime.getMachineWorkTime();
        additionalTime = technologyOperationComponent.getIntegerField(TechnologyOperationComponentFieldsTNFO.TIME_NEXT_OPERATION);
    }
    Entity productionLine = null;
    if (workstation != null) {
        productionLine = workstation.getBelongsToField(WorkstationFieldsPL.PRODUCTION_LINE);
    }
    Date finishDate = shiftsService.findDateToForProductionLine(startDate, machineWorkTime, productionLine);
    if (parameter.getBooleanField("includeAdditionalTimeSG")) {
        finishDate = Date.from(finishDate.toInstant().plusSeconds(additionalTime));
    }
    return finishDate;
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationWorkTime(com.qcadoo.mes.operationTimeCalculations.OperationWorkTime) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Aggregations

OperationWorkTime (com.qcadoo.mes.operationTimeCalculations.OperationWorkTime)7 Entity (com.qcadoo.model.api.Entity)7 BigDecimal (java.math.BigDecimal)7 Date (java.util.Date)5 FormComponent (com.qcadoo.view.api.components.FormComponent)4 FieldComponent (com.qcadoo.view.api.components.FieldComponent)3 Transactional (org.springframework.transaction.annotation.Transactional)3 DateTime (org.joda.time.DateTime)2 OrdersByLevel (com.qcadoo.mes.ordersForSubproductsGeneration.productionScheduling.OrdersByLevel)1 OperationProductComponentWithQuantityContainer (com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)1 GridComponent (com.qcadoo.view.api.components.GridComponent)1 LookupComponent (com.qcadoo.view.api.components.LookupComponent)1 MathContext (java.math.MathContext)1 DecimalFormat (java.text.DecimalFormat)1 ParsePosition (java.text.ParsePosition)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 Around (org.aspectj.lang.annotation.Around)1