package com.sifang.modules.sunshine.SystemSetting.dao;

import com.google.common.collect.Lists;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.sunshine.SystemSetting.utils.ComUtils;
import com.sifang.modules.sunshine.SystemSetting.utils.StringUtil;
import com.sifang.modules.platform.service.OnlineRechargeService;
import com.sifang.modules.sys.common.persistence.BaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.sifang.modules.sunshine.SystemSetting.entity.CrmOrderSiteSettlementTemplate;

import java.util.List;


@Repository
public class CrmOrderSiteSettlementTemplateDao extends BaseDao<CrmOrderSiteSettlementTemplate> {

    private static final Logger logger = LoggerFactory.getLogger(OnlineRechargeService.class);
    /**
     * 获取服务商结算方案
     */
    public Record getSiteSettlementTemplate( String setviceType, String warrType,String service_step){
        StringBuilder sf = new StringBuilder();
        sf.append("SELECT a.* FROM crm_order_site_settlement_template a WHERE  a.status='0' ");
            sf.append(" AND a.service_type='"+setviceType.trim()+"'   ");
            sf.append("  AND a.warranty_type='"+warrType+"'   ");
            sf.append("  AND a.service_step='"+service_step.trim()+"'   ");
        logger.info("获取服务商结算方案:: "+sf.toString());
        Record rd = Db.findFirst(sf.toString());
        logger.info("Record : {} , charge_amount ",rd ,rd != null?rd.getBigDecimal("charge_amount"):null);
        return rd;
    }


    public List<Record> getSiteTemplateByNumber(String number,String category){
        String sql =" SELECT a.basis_type,a.charge_amount FROM crm_order_site_settlement_template a WHERE a.number=? and a.status='0'  and a.`category` = ? ";
        return Db.find(sql,number,category);
    }

}
