package com.sifang.modules.site.fittingManager.dao;

import com.sifang.modules.sunshine.fittingManager.entity.CrmSiteFittingApply;
import com.sifang.modules.sunshine.fittingManager.entity.SiteFittingApplyMsg;
import com.sifang.modules.sys.common.persistence.BaseDao;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

/**
 * @author lzp
 * @date 2019/10/11 14:28
 */
@Repository
public class SiteFittingApplyMsgDao extends BaseDao<SiteFittingApplyMsg> {

    public SiteFittingApplyMsg findByApplyId(String aid) {
        Query query = getSession().createQuery("from SiteFittingApplyMsg where fittingApplyId=:aid");
        query.setParameter("aid", aid);
        return (SiteFittingApplyMsg) query.uniqueResult();
    }


    public static SiteFittingApplyMsg getByApply(SiteFittingApplyMsgDao msgDao, CrmSiteFittingApply apply) {
        SiteFittingApplyMsg applyMsg = msgDao.findByApplyId(apply.getId());
        if (applyMsg == null) {
            applyMsg = new SiteFittingApplyMsg();
            applyMsg.setFittingApplyId(apply.getId());
            applyMsg.setSiteId(apply.getSiteId());
        }
        return applyMsg;
    }
}
