package com.sifang.modules.quality.dao;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.quality.entity.CrmInspectionRatioSet;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.util.LayuiPage;
import com.sifang.modules.sys.util.SqlBuilder;
import org.springframework.stereotype.Repository;

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

@Repository
public class CrmInspectionRatioSetDao extends BaseDao<CrmInspectionRatioSet> {


    public List<Record> getList(Map<String,String> param, LayuiPage<Record> page){
        SqlBuilder sqlBuilder=new SqlBuilder();
        sqlBuilder.line("SELECT * FROM crm_inspection_ratio_set  WHERE status='1' ");
        sqlBuilder.line(" ORDER BY update_time DESC ");
        if (page != null) {
            sqlBuilder.limit(page.getPage(), page.getLimit());
        }
        return Db.find(sqlBuilder.build(),sqlBuilder.params());
    }


    public Long getListCont(Map<String,String> param){
        SqlBuilder sqlBuilder=new SqlBuilder();
        sqlBuilder.line("SELECT count(*)  FROM crm_inspection_ratio_set WHERE status='1' ");
        return Db.queryLong(sqlBuilder.build(),sqlBuilder.params());
    }

    public Record getInspectionRatioSetById(String id) {
        SqlBuilder sqlBuilder=new SqlBuilder();
        sqlBuilder.line("  SELECT s.id ,s.cycle,s.house_num as houseNum,s.ratio,s.just,s.floating");
        sqlBuilder.line("  ,s.prop_float_wg AS propFloatWg,s.prop_float_cj as propFloatCj ");
        sqlBuilder.line("  FROM crm_inspection_ratio_set s ");
        sqlBuilder.line("  WHERE s.status='1' and s.id=? ",id);
        return Db.findFirst(sqlBuilder.build(),sqlBuilder.params());
    }

    public Record getRatioSet(){
        return Db.findFirst(" select s.cycle,s.house_num,s.ratio,s.just,s.floating,s.prop_float_wg,s.prop_float_cj from crm_inspection_ratio_set s where s.status='1' ");
    }
}
