package cn.estsh.i3plus.pojo.platform.sqlpack;

import cn.estsh.i3plus.pojo.base.tool.BsonPackTool;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogException;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogOperate;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogSystem;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogTaskTime;
import com.mongodb.BasicDBObject;
import org.bson.conversions.Bson;

/**
 * @Description : Bson对象封装
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2018-11-08 13:15
 * @Modify:
 **/
public class CoreBsonPack {

    /**
     * 日志复杂查询
     *
     * @param logSystem
     * @return
     */
    public static Bson packBsonByLogSystem(SysLogSystem logSystem) {
        Bson bson = new BasicDBObject();

        bson = BsonPackTool.getNumEqualPack(logSystem.getLogLevel(), "logLevel", bson);
        bson = BsonPackTool.getNumEqualPack(logSystem.getLogModuleId(), "logModuleId", bson);
        bson = BsonPackTool.timeBuilder(logSystem.getCreateDatetime(), "createDatetime", bson, false, false);
        bson = BsonPackTool.getStringLikerPack(logSystem.getRemoteIp(), "remoteIp", bson);
        bson = BsonPackTool.getStringLikerPack(logSystem.getRequestUrl(), "requestUrl", bson);
        bson = BsonPackTool.getStringLikerPack(logSystem.getLogMethod(), "logMethod", bson);

        return bson;
    }

    /**
     * 系统操作日志
     *
     * @param logOperate
     * @return
     */
    public static Bson packBsonByLogOperate(SysLogOperate logOperate) {
        Bson bson = new BasicDBObject();

        bson = BsonPackTool.getNumEqualPack(logOperate.getOperateType(), "operateType", bson);
        bson = BsonPackTool.getNumEqualPack(logOperate.getOperateModule(), "operateModule", bson);
        bson = BsonPackTool.timeBuilder(logOperate.getCreateDatetime(), "createDatetime", bson, false, false);
        bson = BsonPackTool.getStringLikerPack(logOperate.getRemoteIp(), "remoteIp", bson);
        bson = BsonPackTool.getStringLikerPack(logOperate.getOperateMessage(), "operateMessage", bson);
        bson = BsonPackTool.getStringLikerPack(logOperate.getCreateUser(), "createUser", bson);

        return bson;
    }

    /**
     * 系统异常日志复杂查询
     *
     * @param sysLogException
     * @return
     */
    public static Bson packBsonBySysLogException(SysLogException sysLogException) {
        Bson bson = new BasicDBObject();

        bson = BsonPackTool.getNumEqualPack(sysLogException.getExcModule(), "excModule", bson);
        bson = BsonPackTool.getStringLikerPack(sysLogException.getExcMessage(), "excMessage", bson);
        bson = BsonPackTool.timeBuilder(sysLogException.getCreateDatetime(), "createDatetime", bson, false, false);

        return bson;
    }

    /**
     * 定时任务日志复杂查询
     *
     * @param sysLogTaskTime
     * @return
     */
    public static Bson packBsonByLogTaskTime(SysLogTaskTime sysLogTaskTime) {
        Bson bson = new BasicDBObject();

        bson = BsonPackTool.getStringLikerPack(sysLogTaskTime.getName(), "name", bson);
        bson = BsonPackTool.getStringLikerPack(sysLogTaskTime.getGroupName(), "groupName", bson);
        bson = BsonPackTool.timeBuilder(sysLogTaskTime.getCreateDatetime(), "createDatetime", bson, false, false);

        return bson;
    }

    /**
     * 区间
     *
     * @param colName
     * @param min
     * @param max
     * @return
     */
    public static Bson packBsonByInterval(String colName, Object min, Object max) {
        Bson bson = new BasicDBObject();

        bson = BsonPackTool.getNumBiggerPack(min, colName, bson);
        bson = BsonPackTool.getNumSmallerPack(max, colName, bson);

        return bson;
    }

    /**
     * 指定日期之后
     * @param dateTime 日期
     * @return
     */
    public static Bson packBsonByDateTimeAfter(String dateTime){
        return BsonPackTool.timeLess(dateTime, "createDatetime", null, true);
    }
}
