コード例 #1
0
 public boolean validateDates(
     final DataDefinition deliveredProductDD, final Entity deliveredProduct) {
   Date productionDate = deliveredProduct.getDateField(DeliveredProductFieldsDTMF.PRODUCTION_DATE);
   Date expirationDate = deliveredProduct.getDateField(DeliveredProductFieldsDTMF.EXPIRATION_DATE);
   if (productionDate != null && expirationDate != null) {
     if (productionDate.after(expirationDate)) {
       deliveredProduct.addError(
           deliveredProductDD.getField(DeliveredProductFieldsDTMF.EXPIRATION_DATE),
           "materialFlow.error.position.expirationDate.lessThenProductionDate");
       return false;
     }
   }
   return true;
 }
コード例 #2
0
  private void scheduleOrder(final Long orderId) {
    Entity order =
        dataDefinitionService
            .get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER)
            .get(orderId);

    if (order == null) {
      return;
    }

    Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);

    if (technology == null) {
      return;
    }

    DataDefinition technologyOperationComponentDD =
        dataDefinitionService.get(
            TechnologiesConstants.PLUGIN_IDENTIFIER,
            TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT);

    List<Entity> operations =
        technologyOperationComponentDD
            .find()
            .add(
                SearchRestrictions.belongsTo(
                    TechnologyOperationComponentFields.TECHNOLOGY, technology))
            .list()
            .getEntities();

    Date orderStartDate = order.getDateField(OrderFields.START_DATE);
    for (Entity operation : operations) {
      Entity techOperCompTimeCalculation =
          operation.getBelongsToField(
              TechnologyOperationComponentFieldsTNFO.TECH_OPER_COMP_TIME_CALCULATION);

      if (techOperCompTimeCalculation == null) {
        continue;
      }

      Integer offset =
          techOperCompTimeCalculation.getIntegerField(
              TechOperCompTimeCalculationsFields.OPERATION_OFF_SET);
      Integer duration =
          techOperCompTimeCalculation.getIntegerField(
              TechOperCompTimeCalculationsFields.EFFECTIVE_OPERATION_REALIZATION_TIME);

      techOperCompTimeCalculation.setField(
          TechOperCompTimeCalculationsFields.EFFECTIVE_DATE_FROM, null);
      techOperCompTimeCalculation.setField(
          TechOperCompTimeCalculationsFields.EFFECTIVE_DATE_TO, null);

      if (offset == null || duration == null) {
        continue;
      }

      if (duration.equals(0)) {
        duration = duration + 1;
      }

      Date dateFrom = shiftsService.findDateToForOrder(orderStartDate, offset);
      if (dateFrom == null) {
        continue;
      }

      Date dateTo = shiftsService.findDateToForOrder(orderStartDate, offset + duration);
      if (dateTo == null) {
        continue;
      }

      techOperCompTimeCalculation.setField(
          TechOperCompTimeCalculationsFields.EFFECTIVE_DATE_FROM, dateFrom);
      techOperCompTimeCalculation.setField(
          TechOperCompTimeCalculationsFields.EFFECTIVE_DATE_TO, dateTo);

      techOperCompTimeCalculation.getDataDefinition().save(techOperCompTimeCalculation);
    }
  }
コード例 #3
0
  @Transactional
  public void generateRealizationTime(
      final ViewDefinitionState viewDefinitionState,
      final ComponentState state,
      final String[] args) {
    FormComponent orderForm = (FormComponent) viewDefinitionState.getComponentByReference(L_FORM);
    FieldComponent startTimeField =
        (FieldComponent) viewDefinitionState.getComponentByReference(L_START_TIME);

    if (!StringUtils.hasText((String) startTimeField.getFieldValue())) {
      startTimeField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, 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 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);

    OperationWorkTime workTime =
        operationWorkTimeService.estimateTotalWorkTimeForOrder(
            order, operationRuns, includeTpz, includeAdditionalTime, productionLine, true);

    fillWorkTimeFields(viewDefinitionState, workTime);

    order = getActualOrderWithChanges(order);

    int maxPathTime =
        orderRealizationTimeService.estimateMaxOperationTimeConsumptionForWorkstation(
            technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(),
            quantity,
            includeTpz,
            includeAdditionalTime,
            productionLine);

    if (maxPathTime > OrderRealizationTimeService.MAX_REALIZATION_TIME) {
      state.addMessage("orders.validate.global.error.RealizationTimeIsToLong", MessageType.FAILURE);

      generatedEndDateField.setFieldValue(null);
    } else {
      order.setField(OrderFieldsPS.REALIZATION_TIME, maxPathTime);

      Date startTime = order.getDateField(OrderFields.DATE_FROM);

      if (startTime == null) {
        startTimeField.addMessage(
            "orders.validate.global.error.dateFromIsNull", MessageType.FAILURE);
      } else {
        Date stopTime = shiftsService.findDateToForOrder(startTime, maxPathTime);

        if (stopTime == null) {
          orderForm.addMessage("productionScheduling.timenorms.isZero", MessageType.FAILURE, false);

          generatedEndDateField.setFieldValue(null);
        } else {
          generatedEndDateField.setFieldValue(orderRealizationTimeService.setDateToField(stopTime));

          order.setField(
              OrderFieldsPS.GENERATED_END_DATE,
              orderRealizationTimeService.setDateToField(stopTime));

          scheduleOrder(order.getId());

          isGenerated = true;
        }

        orderForm.addMessage(
            "orders.dateFrom.info.dateFromSetToFirstPossible", MessageType.INFO, false);
      }

      order = order.getDataDefinition().save(order);
      orderForm.setEntity(order);
    }

    generatedEndDateField.requestComponentUpdateState();

    if (isGenerated) {
      orderForm.addMessage("productionScheduling.info.calculationGenerated", MessageType.SUCCESS);
    }
  }