package com.sw.mes.yb.production.dao;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.production.entity.ProductionCircleRecipe;
import com.sw.mes.yb.production.entity.ProductionCircleWeight;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
* @Author
* @Description：
* @Date:
* @Modified By:
*/
public interface ProductionCircleWeightDao extends BaseDao<ProductionCircleWeight, Integer>{

    @Modifying
    @Transactional
    @Query(value = "UPDATE production_circle_weight SET `status`=?2 WHERE id =?1 ", nativeQuery = true)
    void updateStatus(Long id, int i);

    @Query(value = "select w.* from production_circle_dosing_list l left join production_circle_weight w on " +
            "l.weight_id = w.id where l.product_name = ?1 and l.status = 1 limit 1", nativeQuery = true)
    ProductionCircleWeight getByProductCode(String productCode);

    @Query(value = "select * from production_circle_weight where id = ?1", nativeQuery = true)
    ProductionCircleWeight getRecipeWeightById(Long id);


    @Modifying
    @Query(value = "UPDATE production_circle_weight SET `del`=?2 WHERE id =?1 ", nativeQuery = true)
	void deleteDel(Long id, int del);

    @Query(value = "select max(version) from production_circle_weight where weight_name=?1 and weight_code=?2", nativeQuery = true)
    Integer getNewestVersion(String weightName, String weightCode);

    @Query(value = "select count(1) from production_circle_weight where weight_code=?1 and weight_name=?2 and status = 1 and del=0", nativeQuery = true)
    Integer getOpenCountByCodeAndName(String weightCode, String weightName);
}
