package com.sifang.modules.changes.dao;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.changes.entity.CrmCustomerEntryTenantChangeRecordDetail;
import com.sifang.modules.customer.dao.CustomerEntryDao;
import com.sifang.modules.customer.entity.CustomerEntry;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.util.SqlBuilder;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class CrmCustomerEntryTenantChangeRecordDetailDao extends BaseDao<CrmCustomerEntryTenantChangeRecordDetail> {

    @Autowired
    private CustomerEntryDao customerEntryDao;

    public void deleteDetails(String mainId){
        SQLQuery sqlQuery = getSession().createSQLQuery("DELETE FROM crm_customer_entry_tenant_change_record_detail WHERE main_id=:mainId");
        sqlQuery.setParameter("mainId", mainId);
        sqlQuery.executeUpdate();
    }

    public List<Record> getDetails(String mainId){
        return Db.find("  SELECT * FROM `crm_customer_entry_tenant_change_record_detail` d WHERE main_id=? ORDER BY sort ASC ",mainId);
    }

}
