package com.cnd3b.restcontroller.enterprise.salerclient.mainpage;

import com.alibaba.fastjson.JSONObject;
import com.cnd3b.common.Controller;
import com.cnd3b.common.data.Rows;
import com.cnd3b.common.data.SQLFactory;

public class mainpage extends Controller {
    public mainpage(JSONObject content) {
        super(content);
    }

    /**
     * 首页简报
     *
     * @return
     */
    public String query_briefreport() {
        String fdate = content.getString("fdate");
        SQLFactory factory = new SQLFactory(this, "首页简报");
        factory.addParameter("siteid", siteid);
        factory.addParameter_in("fsaleruserid", getSubUsers());
        factory.addParameter("fdate", fdate.substring(0, 7));
        Rows rows = dbConnect.runSqlQuery(factory.getSQL());
        return getSucReturnObject().setData(rows.get(0)).saveToDataPool(1).toString();
    }

    /**
     * 三天未录入销售经销商查询
     *
     * @return
     */
    public String query_noentryforthreedays() {
        /**
         *排序条件设置
         */
        String[] sortfield = {"t1.fdays asc", "t1.fdays desc"};
        String sort = getSort(sortfield, "t1.fdays desc");

        SQLFactory factory = new SQLFactory(this, "三天未录入销售经销商查询", pageSize, pageNumber, sort);
        factory.addParameter("siteid", siteid);
        factory.addParameter_in("fsaleruserid", getSubUsers());
        Rows rows = dbConnect.runSqlQuery(factory.getSQL());
        return getSucReturnObject().setDataByPaging(rows, sortfield).setFinalDo(1, 1);
    }

    /**
     * 七天未录入销售经销商查询
     *
     * @return
     */
    public String query_noentryforsevendays() {
        /**
         *排序条件设置
         */
        String[] sortfield = {"t1.fdays asc", "t1.fdays desc"};
        String sort = getSort(sortfield, "t1.fdays desc");

        SQLFactory factory = new SQLFactory(this, "七天未录入销售经销商查询", pageSize, pageNumber, sort);
        factory.addParameter("siteid", siteid);
        factory.addParameter_in("fsaleruserid", getSubUsers());
        Rows rows = dbConnect.runSqlQuery(factory.getSQL());
        return getSucReturnObject().setDataByPaging(rows, sortfield).setFinalDo(1, 1);
    }


    /**
     * 最新访问
     *
     * @return
     */
    public String query_latestvisit() {
        SQLFactory sqlFactory = new SQLFactory(this, "最新访问查询");
        sqlFactory.addParameter("siteid", siteid);
        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
        return getSucReturnObject().setData(rows).saveToDataPool(2).toString();
    }

}
