package com.yihu.hos.resource.dao;

import com.yihu.hos.resource.viewresult.RsResourceDimensionModel;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

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

/**
 * Created by chenweida on 2016/1/26.
 */
@Repository("resourceDimensionDao")
public class RsResourceDimensionDaoImpl extends SQLGeneralDAO{

    public static final String BEAN_ID = "resourceDimensionDao";

   
    public List<RsResourceDimensionModel> getDimensionByResourceId(String resourceId) throws Exception {
        String sql = "select * from rs_dimension d,rs_resource_dimension rd where d.id=rd.dimension_id and rd.resource_id='" + resourceId + "'";
        return super.queryListBySql(sql, RsResourceDimensionModel.class);
    }

   
    public Result getDimensionList(Map<String, Object> conditionMap) throws Exception {
        StringBuilder sb = new StringBuilder();
        sb.append(" from RsDimension r ");
        sb.append(" where 1=1 ");
        if (!StringUtils.isEmpty(conditionMap.get("category"))) {
            sb.append(" and r.category= '" + conditionMap.get("category") + "'  ");
        }
        else if(!StringUtils.isEmpty(conditionMap.get("name")))
        {
            sb.append(" and r.name like '%" + conditionMap.get("name") + "%'");
        }
        return super.getDataGridResult(sb.toString(), (Integer)conditionMap.get("page"), (Integer)conditionMap.get("rows"));
    }
}
