package com.sifang.modules.changes.dao;

import com.jfinal.plugin.activerecord.Db;
import com.sifang.modules.changes.entity.CustomerEntrySupplementDetail;
import com.sifang.modules.sunshine.SystemSetting.utils.StringUtil;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.common.persistence.Parameter;
import org.springframework.stereotype.Repository;

@Repository
public class CustomerEntrySupplementDetailDao extends BaseDao<CustomerEntrySupplementDetail> {


    public CustomerEntrySupplementDetail getChangeRecordDetail(String mainId, String type){

        return getByHql("FROM CustomerEntrySupplementDetail WHERE mainId = :p1 AND changeType=:p2 ", new Parameter(mainId,type));
    }

    public CustomerEntrySupplementDetail getLatestChangeRecordDetail(String entryId){
        String latestMainId= Db.queryStr(" SELECT id FROM `crm_customer_entry_supplement` WHERE entry_id=? AND status='3' ORDER BY audit_time DESC LIMIT 1",entryId);
        if(StringUtil.isBlank(latestMainId)){
            return null;
        }
        return getByHql("FROM CustomerEntrySupplementDetail WHERE mainId = :p1 AND changeType='1' ", new Parameter(latestMainId));
    }
}
