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

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.sunshine.SystemSetting.entity.CrmSite;
import com.sifang.modules.sys.common.entity.User;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.util.CrmUtils;
import org.springframework.stereotype.Repository;

@Repository
public class SiteCompanyInfoDao extends BaseDao<CrmSite> {

    /**
     * 获取服务商信息列表数据
     *
     * @param
     * @return
     */
    public Record getSiteCompanyData(User user) {
        StringBuffer sf = new StringBuffer();
        if (User.USER_TYPE_FWS.equals(user.getUserType())) { //服务商
            sf.append("SELECT * FROM crm_site WHERE user_id = ? and status IN('0','2') ");
            return Db.findFirst(sf.toString(), user.getId());
        } else if (User.USER_TYPE_FWSRY.equals(user.getUserType())) {//服务商人员
            String siteId = CrmUtils.getSite(user.getId());
            sf.append("SELECT * FROM `crm_site`WHERE id= ? ");
            return Db.findFirst(sf.toString(), siteId);
        }
        return null;
    }


}
