package com.sifang.modules.customer.dao;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.customer.entity.CrmCustomerEntryDesign;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.common.persistence.Parameter;
import com.sifang.modules.sys.util.SqlBuilder;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CrmCustomerEntryDesignDao  extends BaseDao<CrmCustomerEntryDesign> {

    public List<CrmCustomerEntryDesign> findByEntryId(String entryId) {
        return find("from CrmCustomerEntryDesign where entryId = :p1 order by projectId asc  ", new Parameter(entryId));
    }

    public void deleteByEntryId(String entryId){
        SQLQuery sqlQuery = getSession().createSQLQuery("DELETE FROM crm_customer_entry_design WHERE entry_id=:mainId");
        sqlQuery.setParameter("mainId", entryId);
        sqlQuery.executeUpdate();
    }

    public List<CrmCustomerEntryDesign> findByEntryIdAndProjectId(String entryId,String projectId) {
        return find("from CrmCustomerEntryDesign where entryId = :p1 and projectId = :p2", new Parameter(entryId,projectId));
    }
    public CrmCustomerEntryDesign findByEntryIdAndProjectId2(String entryId,String projectId) {
        return getByHql("from CrmCustomerEntryDesign where entryId = :p1 and projectId = :p2", new Parameter(entryId,projectId));
    }
}
