package com.cnd3b.restcontroller.enterprise.agentclient.mainpage.workers;

import com.cnd3b.common.Controller;
import com.cnd3b.common.data.Rows;
import com.cnd3b.common.data.SQLFactory;

import com.alibaba.fastjson.JSONObject;
public class analysis extends Controller {

    public analysis(JSONObject content) {
        super(content);
    }

    /**
     * 提报信息量排名
     * @return
     */
    public String submit_analysis(){

        StringBuffer where = new StringBuffer(" 1=1 ");
        if (!fisadministrator) {
            where.append(" and (t1.createuserid is null or t1.createuserid='").append(userid).append("' or t1.createuserid in ( select fsubid from tenterprise_userdetail where siteid='").append(siteid).append("' and fparentid='").append(userid).append("' )) ");
        }

        StringBuffer where2 = new StringBuffer(" 1=1 ");
        if (content.containsKey("where")) {
            JSONObject whereObject = content.getJSONObject("where");
            if (whereObject.containsKey("fbegdate") && !"".equals(whereObject.getString("fbegdate"))) {
                where2.append(" and(");
                where2.append("convert(varchar(10),t2.createdate,120) >='").append(whereObject.getString("fbegdate")).append("' ");
                where2.append(")");
            }
            if (whereObject.containsKey("fenddate") && !"".equals(whereObject.getString("fenddate"))) {
                where2.append(" and(");
                where2.append("convert(varchar(10),t2.createdate,120) <='").append(whereObject.getString("fenddate")).append("' ");
                where2.append(")");
            }
        }

        SQLFactory queryworker = new SQLFactory(this, "统计_提报信息量排名");
        queryworker.addParameter("siteid", siteid);
        queryworker.addParameter("tagentsid", tagentsid);
        queryworker.addParameter_SQL("where", where);
        queryworker.addParameter_SQL("where2", where2);
        Rows workerrows = dbConnect.runSqlQuery(queryworker.getSQL());

        return getSucReturnObject().setData(workerrows).saveToDataPool().toString();
    }

    /**
     * 历史积分排名
     * @return
     */
    public String score_analysis(){
        StringBuffer where = new StringBuffer(" 1=1 ");
        if (!fisadministrator) {
            where.append(" and (t1.createuserid is null or t1.createuserid='").append(userid).append("' or t1.createuserid in ( select fsubid from tenterprise_userdetail where siteid='").append(siteid).append("' and fparentid='").append(userid).append("' )) ");
        }
        SQLFactory queryworker = new SQLFactory(this, "统计_历史积分排名");
        queryworker.addParameter("siteid", siteid);
        queryworker.addParameter("tagentsid", tagentsid);
        queryworker.addParameter_SQL("where", where);
        Rows workerrows = dbConnect.runSqlQuery(queryworker.getSQL());

        return getSucReturnObject().setData(workerrows).saveToDataPool().toString();
    }
}
