use of com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto in project mes by qcadoo.
the class OrderCreationService method createTechnologyForEachOperation.
private Either<String, Entity> createTechnologyForEachOperation(OrderCreationRequest orderCreationRequest) {
Entity product = getProduct(orderCreationRequest.getProductId());
Entity parameter = parameterService.getParameter();
Entity dashboardComponentsLocation = parameter.getBelongsToField(OrderCreationService.L_DASHBOARD_COMPONENTS_LOCATION);
Entity dashboardProductsInputLocation = parameter.getBelongsToField(OrderCreationService.L_DASHBOARD_PRODUCTS_INPUT_LOCATION);
orderCreationRequest.getTechnologyOperations().sort(Comparator.comparing(TechnologyOperationDto::getNode));
String range = parameter.getStringField(L_RANGE);
Entity technology = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY).create();
technology.setField(TechnologyFields.NUMBER, technologyNameAndNumberGenerator.generateNumber(product));
technology.setField(TechnologyFields.NAME, technologyNameAndNumberGenerator.generateName(product));
technology.setField(TechnologyFields.PRODUCT, product);
technology.setField(TechnologyFields.EXTERNAL_SYNCHRONIZED, true);
technology.setField(L_RANGE, range);
technology.setField("componentsLocation", dashboardComponentsLocation);
technology.setField("productsInputLocation", dashboardProductsInputLocation);
technology.setField("typeOfProductionRecording", orderCreationRequest.getTypeOfProductionRecording());
technology = technology.getDataDefinition().save(technology);
if (!technology.isValid()) {
return Either.left(translationService.translate("basic.dashboard.orderDefinitionWizard.createTechnology.validationError", LocaleContextHolder.getLocale()));
}
Entity parent = null;
for (TechnologyOperationDto technologyOperation : orderCreationRequest.getTechnologyOperations()) {
Entity operation = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION).get(technologyOperation.getOperationId());
Entity toc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).create();
toc.setField(TechnologyOperationComponentFields.OPERATION, operation);
toc.setField(TechnologyOperationComponentFields.ENTITY_TYPE, L_OPERATION);
for (String fieldName : FIELDS_OPERATION) {
toc.setField(fieldName, operation.getField(fieldName));
}
if (operation.getField(NEXT_OPERATION_AFTER_PRODUCED_TYPE) == null) {
toc.setField(NEXT_OPERATION_AFTER_PRODUCED_TYPE, L_ALL);
}
if (operation.getField(PRODUCTION_IN_ONE_CYCLE) == null) {
toc.setField(PRODUCTION_IN_ONE_CYCLE, "1");
}
if (operation.getField(NEXT_OPERATION_AFTER_PRODUCED_QUANTITY) == null) {
toc.setField(NEXT_OPERATION_AFTER_PRODUCED_QUANTITY, "0");
}
if (Objects.isNull(parent)) {
Entity topoc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_OUT_COMPONENT).create();
topoc.setField(OperationProductOutComponentFields.QUANTITY, BigDecimal.ONE);
topoc.setField(OperationProductOutComponentFields.PRODUCT, product);
toc.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS, Lists.newArrayList(topoc));
}
List<Entity> topics = Lists.newArrayList();
for (MaterialDto material : technologyOperation.getMaterials()) {
Entity inProduct = getProduct(material.getProductId());
Entity topic = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT).create();
topic.setField(OperationProductInComponentFields.PRODUCT, inProduct);
topic.setField(OperationProductInComponentFields.QUANTITY, material.getQuantityPerUnit());
topics.add(topic);
}
toc.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS, topics);
if (Objects.nonNull(parent)) {
toc.setField(TechnologyOperationComponentFields.PARENT, parent.getId());
}
toc.setField(TechnologyOperationComponentFields.TECHNOLOGY, technology.getId());
toc = toc.getDataDefinition().save(toc);
if (Objects.nonNull(technologyOperation.getWorkstationId())) {
List<Entity> workstations = Lists.newArrayList(toc.getHasManyField(TechnologyOperationComponentFields.WORKSTATIONS));
Entity workstation = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_WORKSTATION).get(technologyOperation.getWorkstationId());
workstations.add(workstation);
toc.setField(TechnologyOperationComponentFields.WORKSTATIONS, workstations);
}
toc = toc.getDataDefinition().save(toc);
technologyOperation.setId(toc.getId());
if (toc.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).isEmpty()) {
Entity topoc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_OUT_COMPONENT).create();
topoc.setField(OperationProductOutComponentFields.QUANTITY, BigDecimal.ONE);
topoc.setField(OperationProductOutComponentFields.PRODUCT, getOrCreateProduct(operation));
topoc.setField(OperationProductOutComponentFields.OPERATION_COMPONENT, toc);
topoc.getDataDefinition().save(topoc);
}
parent = toc;
}
if (technology.isValid()) {
final StateChangeContext technologyStateChangeContext = stateChangeContextBuilder.build(technologyStateChangeAspect.getChangeEntityDescriber(), technology, TechnologyState.ACCEPTED.getStringValue());
technologyStateChangeAspect.changeState(technologyStateChangeContext);
technology = technology.getDataDefinition().get(technology.getId());
if (!technology.getStringField(TechnologyFields.STATE).equals(TechnologyStateStringValues.ACCEPTED)) {
return Either.left(translationService.translate("basic.dashboard.orderDefinitionWizard.createTechnology.acceptError", LocaleContextHolder.getLocale()));
}
technology.setField(TechnologyFields.MASTER, Boolean.TRUE);
technology.getDataDefinition().save(technology);
} else {
return Either.left(translationService.translate("basic.dashboard.orderDefinitionWizard.createTechnology.validationError", LocaleContextHolder.getLocale()));
}
return Either.right(technology);
}
use of com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto in project mes by qcadoo.
the class OrderCreationService method createOperationalTasks.
private void createOperationalTasks(Entity order, OrderCreationRequest orderCreationRequest) {
orderDetailsListeners.createOperationalTasksForOrder(order, false);
Map<Long, TechnologyOperationDto> operationsById = orderCreationRequest.getTechnologyOperations().stream().collect(Collectors.toMap(TechnologyOperationDto::getId, x -> x));
order = order.getDataDefinition().get(order.getId());
List<Entity> operationalTasks = order.getHasManyField(OrderFields.OPERATIONAL_TASKS);
for (Entity operationalTask : operationalTasks) {
Entity technologyOperationComponent = operationalTask.getBelongsToField(OperationalTaskFields.TECHNOLOGY_OPERATION_COMPONENT);
Long workstation = operationsById.get(technologyOperationComponent.getId()).getWorkstationId();
if (Objects.nonNull(workstation)) {
operationalTask.setField(OperationalTaskFields.WORKSTATION, workstation);
Entity workstationEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_WORKSTATION).get(workstation);
if (Objects.nonNull(workstationEntity.getBelongsToField(WorkstationFields.STAFF)) && technologyOperationComponent.getIntegerField(TechnologyOperationComponentFieldsTNFO.OPTIMAL_STAFF) == 1) {
operationalTask.setField(OperationalTaskFields.STAFF, workstationEntity.getBelongsToField(WorkstationFields.STAFF));
}
operationalTask.getDataDefinition().save(operationalTask);
}
}
}
use of com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto in project mes by qcadoo.
the class OrderCreationService method modifyProductionCountingQuantityForEach.
private void modifyProductionCountingQuantityForEach(Entity order, List<TechnologyOperationDto> technologyOperations) {
for (TechnologyOperationDto technologyOperation : technologyOperations) {
Entity toc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).get(technologyOperation.getId());
List<Entity> materialsFromOrderPCQ = getMaterialsFromOrder(order, toc);
List<MaterialDto> materials = technologyOperation.getMaterials();
List<MaterialDto> addedMaterials = materials.stream().filter(m -> Objects.isNull(m.getProductInId())).collect(Collectors.toList());
List<Long> technologyMaterials = materials.stream().filter(m -> Objects.nonNull(m.getProductInId())).map(MaterialDto::getProductId).collect(Collectors.toList());
Map<Long, Entity> pacqByProductId = materialsFromOrderPCQ.stream().collect(Collectors.toMap(pcq -> pcq.getBelongsToField(L_PRODUCT).getId(), pcq -> pcq));
for (Map.Entry<Long, Entity> entry : pacqByProductId.entrySet()) {
if (!technologyMaterials.contains(entry.getKey())) {
Entity pcq = entry.getValue();
pcq.getDataDefinition().delete(pcq.getId());
}
}
List<Entity> pcqs = Lists.newArrayList();
for (MaterialDto material : addedMaterials) {
Entity pcq = createProductionCoutingQuantity(order, material, toc);
pcqs.add(pcq);
}
fillFlow(pcqs, order);
pcqs.forEach(p -> p.getDataDefinition().save(p));
}
}
Aggregations