Is it possible to change mysql to jpaquery?

Viewed 50

I tried to create the mysql code in @query, but failed to validate, so i want to make this sql code exactly the same as querydsl, can someone help me put the sum and the hypothesis in the dsl query? Do you have any documentation on this? or it is not possible to do so. Thank you for your time and your help will be invaluable! I'm really trying my best to deal with this problem.

Mysql:

SELECT id_product,date,
    sum(case  
     when  action_description = "import" 
      then quantity_product
      else -quantity_product
    END) as test
     FROM testdb.warehouse_management
    inner join product
    on warehouse_management.product_id = product.id_product
    where id_product = 3 and date <= 1200
    group by id_product,date

Querydsl:

    public class ManagementRepositoryImpl implements ManagementRepositoryCustom {

    @PersistenceContext
    private EntityManager entityManager;


    @Override
    public List<StockRecoveryDTO> findTotal(Long id_product, String date){
        JPAQuery<StockRecoveryDTO> stockRecoveryDTOJPAQuery = new JPAQuery<>(entityManager);
        QManagement management = QManagement.management;
        QProduct product = QProduct.product;

        return stockRecoveryDTOJPAQuery.select(Projections.bean(StockRecoveryDTO.class,
                product.id_product,
                management.date,
                product.quantity_product,
                management.action_description,
                management.id_action,
                management.quantity))
                .from(management)
                .innerJoin(product)
                .on(management.product_id.eq(product)

DTO: package com.example.dto;

public class StockRecoveryDTO {

    private Long id_product;
    private String date;
    private int quantity_product;
    private String action_description;
    private Long id_action;
    private String quantity;
    private int total;


    public StockRecoveryDTO() {

    }

    public StockRecoveryDTO(Long id_product, String date, int quantity_product, String action_description, Long id_action, String quantity, int total) {
        this.id_product = id_product;
        this.date = date;
        this.quantity_product = quantity_product;
        this.action_description = action_description;
        this.id_action = id_action;
        this.quantity = quantity;
        this.total = total;
    }

//GETTER SETTER
0 Answers
Related