package com.sifang.modules.sunshine.SystemSetting.dao;

import com.sifang.modules.sunshine.SystemSetting.entity.ProjectRentVariable;
import com.sifang.modules.sys.common.persistence.BaseDao;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ProjectRentVariableDao extends BaseDao<ProjectRentVariable> {


    /**
     * 清除当前项目下的方案信息
     */
    public void deleteVariable(String projectId){
        SQLQuery sqlQuery = getSession().createSQLQuery("DELETE FROM crm_project_rent_variable WHERE project_id=:projectId");
        sqlQuery.setParameter("projectId", projectId);
        sqlQuery.executeUpdate();
    }

    public int changeVariableStatus(String projectId) {
        SQLQuery sqlQuery = getSession().createSQLQuery("UPDATE `crm_project_rent_variable` d SET d.status='1' WHERE d.project_id= :projectId  ");
        sqlQuery.setParameter("projectId", projectId);
        int count = sqlQuery.executeUpdate();
        return count;
    }

    public List<ProjectRentVariable> getProjectVariable(String projectId){
        Query query = getSession().createQuery("from ProjectRentVariable where projectId=:projectId and status='0' order BY stage asc ");
        query.setParameter("projectId", projectId);
        List<ProjectRentVariable> list=query.list();
        return list;
    }

}
